%Visualising 1D Quantum Scattering v2.0
%Chris Muktar
%chrismuktar@hotmail.com
%http://chris.chriscentral.com
%This program uses an algorithm developed by John L Richardson, 
%vas detailed in his paper
%'Visualising Quantum Scattering on the CM-2 Supercomputer'
%Computer Physics Communications 63 (1991)
%_________________________________________
%Adding A New Potential
%To add you own potential, you must edit the program. Have a
%look at the code under function V(). You may also need to modify the 
%presets menu.
%_________________________________________
%LICENSE
%The license is open for you to do as you please with this program, 
%although I would appreciate the credit
%if you modify and redistribute this program . Credit to Richardson's 
% paper should be preserved.
%_________________________________________
%Change-log:
% File was modified to remove antiquated graphics commands
% by R. L. Herman, UNCW 10/21/2015
%v2.0 GUI added
%v1.1 Various bugfixes
%_________________________________________

function varargout = quantumscatter(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @quantumscatter_OpeningFcn, ...
                   'gui_OutputFcn',  @quantumscatter_OutputFcn, ...
                   'gui_LayoutFcn',  @quantumscatter_LayoutFcn, ...
                   'gui_Callback',   []);
if nargin & isstr(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn2(gui_State, varargin{:});
else
    gui_mainfcn2(gui_State, varargin{:});
end

function quantumscatter_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
handles.presets=[[1 2100 250];[1 0 2000];[1 -5100 250]; ... 
    [1 100000000000 250];[1 20000 2000]];
set(handles.ipe,'String',handles.presets(1,1));
set(handles.rpe,'String',handles.presets(1,2));
set(handles.duration,'String',handles.presets(1,3));
handles.hbar=1;
c=200;
handles.a=1/200;
handles.m=100;
handles.vx=1.5;
handles.E=1/2*handles.m*handles.vx^2;
handles.dt= 0.3 * handles.m * 1/(199)^2/handles.hbar;
epsilon=(handles.dt*handles.hbar/(handles.m*handles.a^2));
A=(1+exp(-i*epsilon))/2;
B=(1-exp(-i*epsilon))/2;
M=[[A,B];[B,A]];
even=kron(eye(c/2,c/2),M);
odd=even(1:198,1:198);
odd=[zeros(1,198);odd;zeros(1,198)];
odd=[zeros(200,1) odd zeros(200,1)];
odd(1,1)=A;
odd(1,200)=B;
odd(200,1)=B;
odd(200,200)=A;
even=sparse(even);
odd=sparse(odd);
handles.even=even;
handles.odd=odd;
set(handles.preset,'Value',1)
guidata(hObject, handles);
preset_Callback(hObject, eventdata, handles);

function varargout = quantumscatter_OutputFcn(hObject, eventdata, handles)

varargout{1} = handles.output;

function pf_CreateFcn(hObject, eventdata, handles)

if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor', ... 
        get(0,'defaultUicontrolBackgroundColor'));
end

function pf_Callback(hObject, eventdata, handles)

function preset_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor', ... 
        get(0,'defaultUicontrolBackgroundColor'));
end

function preset_Callback(hObject, eventdata, handles)
    set(handles.ipe,'String',handles.presets(get(handles.preset, ... 
        'Value'),1));
    set(handles.rpe,'String',handles.presets(get(handles.preset, ... 
        'Value'),2));
    set(handles.duration,'String',handles.presets(get(handles.preset, ...
        'Value'),3));
    initscenario(hObject, eventdata, handles);

function ipe_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor', ... 
        get(0,'defaultUicontrolBackgroundColor'));
end

function ipe_Callback(hObject, eventdata, handles)
    initscenario(hObject, eventdata, handles);

function rpe_CreateFcn(hObject, eventdata, handles)

if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor', ... 
        get(0,'defaultUicontrolBackgroundColor'));
end

function rpe_Callback(hObject, eventdata, handles)
initscenario(hObject, eventdata, handles);
function duration_CreateFcn(hObject, eventdata, handles)

if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor', ... 
        get(0,'defaultUicontrolBackgroundColor'));
end

function duration_Callback(hObject, eventdata, handles)

function startpause_Callback(hObject, eventdata, handles)
    handles=rmfield(handles,'history');
    guidata(hObject, handles);
    handles=initscenario(hObject, eventdata, handles);
    set(handles.startpause,'String','Calculating...');
    set(handles.startpause,'Enable','off');
    set(handles.movieslider,'Enable','Off');
    for j=2:str2num(get(handles.duration,'String'))
        handles.history=[handles.history, ...  
            handles.multiplier*handles.history(1:200,j-1)];
        set(handles.startpause,'String', ... 
            [num2str(double(int8(j/str2num(get(handles.duration, ... 
            'String'))*100))),'%']);
    end
    makepst(hObject, eventdata, handles);
    set(handles.startpause,'String','Caclulate');
    set(handles.startpause,'Enable','on');
    set(handles.playbutton,'Enable','on');
    set(handles.movieslider,'Enable','On');
%    playbutton_Callback(hObject, eventdata, handles);
    guidata(hObject, handles);

function psi=psio(s,K,xo,a)
for x=1:1/a
    psi(x,1)=exp(-(a*(x-xo/a))^2/(2*(s)^2)+i*K*(a*x-xo));
end

function vout = v(a,E,x,w,mode,rpe)
for i=1:1/a

    switch mode
        case {1} %+ve wall
            x=0.5;
            w=0.05;
            if (i*a>x && i*a<(x+w))
                vout(i)=rpe*E;
            else
                vout(i)=0;
            end           
        case {2} % no barrier
            vout(i)=0;
        case {3} %negative well
            x=0.5;
            w=0.1;
            if (i*a>x && i*a<(x+w))
                vout(i)=rpe*E;
            else
                vout(i)=0;
            end  
        case {4} %infinite square well pattern maker
            if (i*a>x && i*a<(x+w)) || i*a>0.55
                vout(i)=rpe*E;
            else
                vout(i)=0;
            end
        case {5} %sho
            vout(i)=((i-.5/a))^2/(1/a)^2*rpe*E;
    end
end  

function now=plotnow(out,V,E,a,handles)
%    if m/2==int32(m/2); %plot once every 2 steps
        axes(handles.anima)
        now=plot([abs(out.*out) real(out) V'/(2*E)]); %,'erasemode','xor');
        axis([0 1/a -1.5 1.5])
        xlabel('Lattice Point')
        ylabel('\Re(\Psi) (Green) |\Psi|^2 (Blue) V(x) (Red)')
        drawnow
       %fname=sprintf('%d/m%d',scenario,m) %enable these two lines to dump
        
        %print(fname, '-r600', '-depsc');
%    end  
function makepst(hObject, eventdata, handles)
    plotdata=abs(handles.history).^2;
    h=figure(2); %3d plot the history
    set(h,'name','3D Probability Space Time');
    h=surf(plotdata);
    axis tight
    shading interp
    set(figure(2),'Color','White');
    xlabel('Time Step');
    ylabel('Lattice Position');
    zlabel('Probability Density |\Psi|^2');
    drawnow
%    fname=sprintf('%d/3d',scenario);
   % print(fname, '-r600', '-depsc');
    
    b=figure(3);
    set(b,'name','Probability Space Time');
    b=surf(plotdata);
    set(figure(3),'Color','White');
    axis tight
    xlabel('Time Step');
    ylabel('Lattice Position');
    shading interp
    view([0 90]);
 %   fname=sprintf('%d/slice',scenario);
   % print(fname, '-r600', '-depsc');

function handles=initscenario(hObject, eventdata, handles)
    handles.psi=psio(1/12,sqrt(2*handles.m*handles. ... 
        E*str2num(get(handles.ipe,'String')))/handles.hbar,0.3,handles.a);
    handles.V=v(handles.a,handles.E*handles.dt/handles.hbar,0,1/24, ... 
        get(handles.preset,'Value'),  str2num(get(handles.rpe,'String')));
    etov=exp(-i*handles.dt/handles.hbar*handles.V);
    etov=sparse(diag(etov));
    handles.multiplier=handles.even*handles.odd*etov*handles.odd ... 
        *handles.even;
    handles.history=handles.multiplier*handles.psi;
    plotnow(handles.psi,handles.V,handles.E,handles.a,handles);
    guidata(hObject, handles);
    initscenario=handles;
%    size(handles.history)

% --- Executes during object creation, after setting all properties.
function movieslider_CreateFcn(hObject, eventdata, handles)

usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor', ... 
        get(0,'defaultUicontrolBackgroundColor'));
end

% --- Executes on slider movement.
function movieslider_Callback(hObject, eventdata, handles)
    s=size(handles.history);
    j=int32(s(2)*get(handles.movieslider,'Value'));
    if j==0
        j=1;
    end
    plotnow(handles.history(1:200,j),handles.V,handles.E,handles.a,handles);

% --- Executes on button press in playbutton.
function playbutton_Callback(hObject, eventdata, handles)
    s=size(handles.history);
    st=double(int32((s(2)*get(handles.movieslider,'Value'))));
    if st==0
        st=1;
    end
    set(handles.playbutton,'Enable','off');
    for j=st:s(2)
        plotnow(handles.history(1:200,j),handles.V,handles.E,handles.a,handles);
        set(handles.movieslider,'Value',j/s(2));
    end
    set(handles.playbutton,'Enable','on');

function aboutbutton_Callback(hObject, eventdata, handles)
    about_export;


% --- Creates and returns a handle to the GUI figure. 
function h1 = quantumscatter_LayoutFcn(policy)
% policy - create a new figure or use a singleton. 'new' or 'reuse'.

persistent hsingleton;
if strcmpi(policy, 'reuse') & ishandle(hsingleton)
    h1 = hsingleton;
    return;
end

h1 = figure(...
'Units','characters',...
'PaperUnits',get(0,'defaultfigurePaperUnits'),...
'BackingStore','off',...
'Color',[0.831372549019608 0.815686274509804 0.784313725490196],...
'Colormap',[0 0 0.5625;0 0 0.625;0 0 0.6875;0 0 0.75;0 0 0.8125;0 0 0.875;0 0 0.9375;0 0 1;0 0.0625 1;0 0.125 1;0 0.1875 1;0 0.25 1;0 0.3125 1;0 0.375 1;0 0.4375 1;0 0.5 1;0 0.5625 1;0 0.625 1;0 0.6875 1;0 0.75 1;0 0.8125 1;0 0.875 1;0 0.9375 1;0 1 1;0.0625 1 1;0.125 1 0.9375;0.1875 1 0.875;0.25 1 0.8125;0.3125 1 0.75;0.375 1 0.6875;0.4375 1 0.625;0.5 1 0.5625;0.5625 1 0.5;0.625 1 0.4375;0.6875 1 0.375;0.75 1 0.3125;0.8125 1 0.25;0.875 1 0.1875;0.9375 1 0.125;1 1 0.0625;1 1 0;1 0.9375 0;1 0.875 0;1 0.8125 0;1 0.75 0;1 0.6875 0;1 0.625 0;1 0.5625 0;1 0.5 0;1 0.4375 0;1 0.375 0;1 0.3125 0;1 0.25 0;1 0.1875 0;1 0.125 0;1 0.0625 0;1 0 0;0.9375 0 0;0.875 0 0;0.8125 0 0;0.75 0 0;0.6875 0 0;0.625 0 0;0.5625 0 0],...
'IntegerHandle','off',...
'InvertHardcopy',get(0,'defaultfigureInvertHardcopy'),...
'MenuBar','none',...
'Name','One Dimensional Quantum Scatter',...
'NumberTitle','off',...
'PaperPosition',get(0,'defaultfigurePaperPosition'),...
'PaperSize',[20.98404194812 29.67743169791],...
'PaperType',get(0,'defaultfigurePaperType'),...
'Position',[36.4 30.1538461538462 135.4 26.6153846153846],...
'Renderer',get(0,'defaultfigureRenderer'),...
'RendererMode','manual',...
'BusyAction','cancel',...
'HandleVisibility','callback',...
'Tag','figure1',...
'UserData',zeros(1,0));

setappdata(h1, 'GUIDEOptions', struct(...
'active_h', 3.250006e+002, ...
'taginfo', struct(...
'figure', 2, ...
'edit', 6, ...
'listbox', 2, ...
'popupmenu', 2, ...
'text', 8, ...
'pushbutton', 6, ...
'axes', 8, ...
'slider', 3), ...
'override', 1, ...
'release', 13, ...
'resize', 'simple', ...
'accessibility', 'callback', ...
'mfile', 1, ...
'callbacks', 1, ...
'singleton', 1, ...
'syscolorfig', 1, ...
'lastSavedFile', 'C:\MATLAB6p5\work\cm2\gui2.m'));


h2 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'Position',[0.0457902511078287 0.916184971098266 0.0472673559822747 0.0404624277456647],...
'String','Preset',...
'Style','text',...
'Tag','text1');


h3 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'Position',[0.295420974889217 0.916184971098266 0.144756277695716 0.0404624277456647],...
'String','Initial Particle Energy',...
'Style','text',...
'Tag','text3');


h4 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'Position',[0.468242245199409 0.916184971098266 0.217134416543575 0.0404624277456647],...
'String','Relative Potential Energy',...
'Style','text',...
'Tag','text4');


h5 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'Position',[0.661742983751846 0.916184971098266 0.103397341211226 0.0404624277456647],...
'String','Time Duration',...
'Style','text',...
'Tag','text5');


h6 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'BackgroundColor',[1 1 1],...
'Callback','quantumscatter(''preset_Callback'',gcbo,[],guidata(gcbo))',...
'ListboxTop',0,...
'Position',[0.0457902511078287 0.846820809248555 0.234859675036928 0.0635838150289017],...
'String',{ 'Step' 'No Potential' 'Well' 'Infinite Square Well' 'Simple Harmonic Oscillator' },...
'Style','popupmenu',...
'Value',1,...
'CreateFcn','quantumscatter(''preset_CreateFcn'',gcbo,[],guidata(gcbo))',...
'Tag','preset');


h7 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'BackgroundColor',[1 1 1],...
'Callback','quantumscatter(''ipe_Callback'',gcbo,[],guidata(gcbo))',...
'ListboxTop',0,...
'Position',[0.295420974889217 0.855491329479769 0.0753323485967504 0.0549132947976879],...
'String',{ 'Edit Text' },...
'Style','edit',...
'CreateFcn','quantumscatter(''ipe_CreateFcn'',gcbo,[],guidata(gcbo))',...
'Tag','ipe');


h8 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'BackgroundColor',[1 1 1],...
'Callback','quantumscatter(''rpe_Callback'',gcbo,[],guidata(gcbo))',...
'ListboxTop',0,...
'Position',[0.468242245199409 0.852601156069364 0.069423929098966 0.0549132947976879],...
'String',{ 'Edit Text' },...
'Style','edit',...
'CreateFcn','quantumscatter(''rpe_CreateFcn'',gcbo,[],guidata(gcbo))',...
'Tag','rpe');


h9 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'BackgroundColor',[1 1 1],...
'Callback','quantumscatter(''duration_Callback'',gcbo,[],guidata(gcbo))',...
'ListboxTop',0,...
'Position',[0.667651403249631 0.84971098265896 0.069423929098966 0.0549132947976879],...
'String',{ 'Edit Text' },...
'Style','edit',...
'CreateFcn','quantumscatter(''duration_CreateFcn'',gcbo,[],guidata(gcbo))',...
'Tag','duration');


h10 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'Callback','quantumscatter(''startpause_Callback'',gcbo,[],guidata(gcbo))',...
'ListboxTop',0,...
'Position',[0.865583456425406 0.858381502890173 0.0974889217134417 0.0606936416184971],...
'String','Calculate',...
'Tag','startpause');


h11 = axes(...
'Parent',h1,...
'CameraPosition',[0.5 0.5 9.16025403784439],...
'CameraPositionMode',get(0,'defaultaxesCameraPositionMode'),...
'Color',get(0,'defaultaxesColor'),...
'ColorOrder',get(0,'defaultaxesColorOrder'),...
'Position',[0.0945347119645495 0.315028901734104 0.868537666174298 0.459537572254335],...
'XColor',get(0,'defaultaxesXColor'),...
'YColor',get(0,'defaultaxesYColor'),...
'ZColor',get(0,'defaultaxesZColor'),...
'Tag','anima');


h12 = get(h11,'title');

set(h12,...
'Parent',h11,...
'Color',[0 0 0],...
'HorizontalAlignment','center',...
'Position',[0.499149659863946 1.04088050314465 1.00005459937205],...
'VerticalAlignment','bottom',...
'HandleVisibility','off');

h13 = get(h11,'xlabel');

set(h13,...
'Parent',h11,...
'Color',[0 0 0],...
'HorizontalAlignment','center',...
'Position',[0.499149659863946 -0.147798742138365 1.00005459937205],...
'VerticalAlignment','cap',...
'HandleVisibility','off');

h14 = get(h11,'ylabel');

set(h14,...
'Parent',h11,...
'Color',[0 0 0],...
'HorizontalAlignment','center',...
'Position',[-0.048469387755102 0.493710691823899 1.00005459937205],...
'Rotation',90,...
'VerticalAlignment','bottom',...
'HandleVisibility','off');

h15 = get(h11,'zlabel');

set(h15,...
'Parent',h11,...
'Color',[0 0 0],...
'HorizontalAlignment','right',...
'Position',[-0.10969387755102 1.4811320754717 1.00005459937205],...
'HandleVisibility','off',...
'Visible','off');

h16 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'BackgroundColor',[0.9 0.9 0.9],...
'Callback','quantumscatter(''movieslider_Callback'',gcbo,[],guidata(gcbo))',...
'Enable','off',...
'ListboxTop',0,...
'Position',[0.03397341211226 0.132947976878613 0.929098966026588 0.0635838150289017],...
'String',{ '' },...
'Style','slider',...
'CreateFcn','quantumscatter(''movieslider_CreateFcn'',gcbo,[],guidata(gcbo))',...
'Tag','movieslider');


h17 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'Callback','quantumscatter(''playbutton_Callback'',gcbo,[],guidata(gcbo))',...
'Enable','off',...
'ListboxTop',0,...
'Position',[0.865583456425406 0.0491329479768786 0.0974889217134417 0.0606936416184971],...
'String','Play',...
'BusyAction','cancel',...
'Tag','playbutton');


h18 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'Callback','quantumscatter(''aboutbutton_Callback'',gcbo,[],guidata(gcbo))',...
'ListboxTop',0,...
'Position',[0.0310192023633678 0.0491329479768786 0.152141802067947 0.0606936416184971],...
'String','About',...
'Tag','aboutbutton');



hsingleton = h1;


% --- Handles default GUIDE GUI creation and callback dispatch
function varargout = gui_mainfcn(gui_State, varargin)


%   GUI_MAINFCN provides these command line APIs for dealing with GUIs
%
%      QUANTUMSCATTER, by itself, creates a new QUANTUMSCATTER or raises the existing
%      singleton*.
%
%      H = QUANTUMSCATTER returns the handle to a new QUANTUMSCATTER or the handle to
%      the existing singleton*.
%
%      QUANTUMSCATTER('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in QUANTUMSCATTER.M with the given input arguments.
%
%      QUANTUMSCATTER('Property','Value',...) creates a new QUANTUMSCATTER or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before untitled_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to untitled_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".

%   Copyright 1984-2002 The MathWorks, Inc.
%   $Revision: 1.4 $ $Date: 2002/05/31 21:44:31 $

gui_StateFields =  {'gui_Name'
                    'gui_Singleton'
                    'gui_OpeningFcn'
                    'gui_OutputFcn'
                    'gui_LayoutFcn'
                    'gui_Callback'};
gui_Mfile = '';
for i=1:length(gui_StateFields)
    if ~isfield(gui_State, gui_StateFields{i})
        error('Could not find field %s in the gui_State struct in GUI M-file %s', gui_StateFields{i}, gui_Mfile);        
    elseif isequal(gui_StateFields{i}, 'gui_Name')
        gui_Mfile = [getfield(gui_State, gui_StateFields{i}), '.m'];
    end
end

numargin = length(varargin);

if numargin == 0
    % QUANTUMSCATTER
    % create the GUI
    gui_Create = 1;
elseif numargin > 3 & ischar(varargin{1}) & ishandle(varargin{2})
    % QUANTUMSCATTER('CALLBACK',hObject,eventData,handles,...)
    gui_Create = 0;
else
    % QUANTUMSCATTER(...)
    % create the GUI and hand varargin to the openingfcn
    gui_Create = 1;
end

if gui_Create == 0
    varargin{1} = gui_State.gui_Callback;
    if nargout
        [varargout{1:nargout}] = feval(varargin{:});
    else
        feval(varargin{:});
    end
else
    if gui_State.gui_Singleton
        gui_SingletonOpt = 'reuse';
    else
        gui_SingletonOpt = 'new';
    end
    
    % Open fig file with stored settings.  Note: This executes all component
    % specific CreateFunctions with an empty HANDLES structure.
    
    % Do feval on layout code in m-file if it exists
    if ~isempty(gui_State.gui_LayoutFcn)
        gui_hFigure = feval(gui_State.gui_LayoutFcn, gui_SingletonOpt);
    else
        gui_hFigure = local_openfig2(gui_State.gui_Name, gui_SingletonOpt);            
        % If the figure has InGUIInitialization it was not completely created
        % on the last pass.  Delete this handle and try again.
        if isappdata(gui_hFigure, 'InGUIInitialization')
            delete(gui_hFigure);
            gui_hFigure = local_openfig2(gui_State.gui_Name, gui_SingletonOpt);            
        end
    end
    
    % Set flag to indicate starting GUI initialization
    setappdata(gui_hFigure,'InGUIInitialization',1);

    % Fetch GUIDE Application options
    gui_Options = getappdata(gui_hFigure,'GUIDEOptions');
    
    if ~isappdata(gui_hFigure,'GUIOnScreen')
        % Adjust background color
        if gui_Options.syscolorfig 
            set(gui_hFigure,'Color', get(0,'DefaultUicontrolBackgroundColor'));
        end

        % Generate HANDLES structure and store with GUIDATA
        guidata(gui_hFigure, guihandles(gui_hFigure));
    end
    
    % If user specified 'Visible','off' in p/v pairs, don't make the figure
    % visible.
    gui_MakeVisible = 1;
    for ind=1:2:length(varargin)
        if length(varargin) == ind
            break;
        end
        len1 = min(length('visible'),length(varargin{ind}));
        len2 = min(length('off'),length(varargin{ind+1}));
        if ischar(varargin{ind}) & ischar(varargin{ind+1}) & ...
                strncmpi(varargin{ind},'visible',len1) & len2 > 1
            if strncmpi(varargin{ind+1},'off',len2)
                gui_MakeVisible = 0;
            elseif strncmpi(varargin{ind+1},'on',len2)
                gui_MakeVisible = 1;
            end
        end
    end
    
    % Check for figure param value pairs
    for index=1:2:length(varargin)
        if length(varargin) == index
            break;
        end
        try, set(gui_hFigure, varargin{index}, varargin{index+1}), catch, break, end
    end

    % If handle visibility is set to 'callback', turn it on until finished
    % with OpeningFcn
    gui_HandleVisibility = get(gui_hFigure,'HandleVisibility');
    if strcmp(gui_HandleVisibility, 'callback')
        set(gui_hFigure,'HandleVisibility', 'on');
    end
    
    feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
    
    if ishandle(gui_hFigure)
        % Update handle visibility
        set(gui_hFigure,'HandleVisibility', gui_HandleVisibility);
        
        % Make figure visible
        if gui_MakeVisible
            set(gui_hFigure, 'Visible', 'on')
            if gui_Options.singleton 
                setappdata(gui_hFigure,'GUIOnScreen', 1);
            end
        end

        % Done with GUI initialization
        rmappdata(gui_hFigure,'InGUIInitialization');
    end
    
    % If handle visibility is set to 'callback', turn it on until finished with
    % OutputFcn
    if ishandle(gui_hFigure)
        gui_HandleVisibility = get(gui_hFigure,'HandleVisibility');
        if strcmp(gui_HandleVisibility, 'callback')
            set(gui_hFigure,'HandleVisibility', 'on');
        end
        gui_Handles = guidata(gui_hFigure);
    else
        gui_Handles = [];
    end
    
    if nargout
        [varargout{1:nargout}] = feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);
    else
        feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);
    end
    
    if ishandle(gui_hFigure)
        set(gui_hFigure,'HandleVisibility', gui_HandleVisibility);
    end
end    

function gui_hFigure = local_openfig(name, singleton)
if nargin('openfig') == 3 
    gui_hFigure = openfig(name, singleton, 'auto');
else
    % OPENFIG did not accept 3rd input argument until R13,
    % toggle default figure visible to prevent the figure
    % from showing up too soon.
    gui_OldDefaultVisible = get(0,'defaultFigureVisible');
    set(0,'defaultFigureVisible','off');
    gui_hFigure = openfig(name, singleton);
    set(0,'defaultFigureVisible',gui_OldDefaultVisible);
end

function varargout = about_export(varargin)
% ABOUT_EXPORT M-file for about_export.fig
%      ABOUT_EXPORT, by itself, creates a new ABOUT_EXPORT or raises the existing
%      singleton*.
%
%      H = ABOUT_EXPORT returns the handle to a new ABOUT_EXPORT or the handle to
%      the existing singleton*.
%
%      ABOUT_EXPORT('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in ABOUT_EXPORT.M with the given input arguments.
%
%      ABOUT_EXPORT('Property','Value',...) creates a new ABOUT_EXPORT or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before about_export_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to about_export_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help about_export

% Last Modified by GUIDE v2.5 16-Jun-2004 15:29:24

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @about_export_OpeningFcn, ...
                   'gui_OutputFcn',  @about_export_OutputFcn, ...
                   'gui_LayoutFcn',  @about_export_LayoutFcn, ...
                   'gui_Callback',   []);
if nargin & isstr(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn2(gui_State, varargin{:});
else
    gui_mainfcn2(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before about_export is made visible.
function about_export_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to about_export (see VARARGIN)

% Choose default command line output for about_export
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes about_export wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = about_export_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Creates and returns a handle to the GUI figure. 
function h1 = about_export_LayoutFcn(policy)
% policy - create a new figure or use a singleton. 'new' or 'reuse'.

persistent hsingleton;
if strcmpi(policy, 'reuse') & ishandle(hsingleton)
    h1 = hsingleton;
    return;
end

h1 = figure(...
'Units','characters',...
'PaperUnits',get(0,'defaultfigurePaperUnits'),...
'Color',[0.831372549019608 0.815686274509804 0.784313725490196],...
'Colormap',[0 0 0.5625;0 0 0.625;0 0 0.6875;0 0 0.75;0 0 0.8125;0 0 0.875;0 0 0.9375;0 0 1;0 0.0625 1;0 0.125 1;0 0.1875 1;0 0.25 1;0 0.3125 1;0 0.375 1;0 0.4375 1;0 0.5 1;0 0.5625 1;0 0.625 1;0 0.6875 1;0 0.75 1;0 0.8125 1;0 0.875 1;0 0.9375 1;0 1 1;0.0625 1 1;0.125 1 0.9375;0.1875 1 0.875;0.25 1 0.8125;0.3125 1 0.75;0.375 1 0.6875;0.4375 1 0.625;0.5 1 0.5625;0.5625 1 0.5;0.625 1 0.4375;0.6875 1 0.375;0.75 1 0.3125;0.8125 1 0.25;0.875 1 0.1875;0.9375 1 0.125;1 1 0.0625;1 1 0;1 0.9375 0;1 0.875 0;1 0.8125 0;1 0.75 0;1 0.6875 0;1 0.625 0;1 0.5625 0;1 0.5 0;1 0.4375 0;1 0.375 0;1 0.3125 0;1 0.25 0;1 0.1875 0;1 0.125 0;1 0.0625 0;1 0 0;0.9375 0 0;0.875 0 0;0.8125 0 0;0.75 0 0;0.6875 0 0;0.625 0 0;0.5625 0 0],...
'IntegerHandle','off',...
'InvertHardcopy',get(0,'defaultfigureInvertHardcopy'),...
'MenuBar','none',...
'Name','About Visualising 1D Quantum Scatter',...
'NumberTitle','off',...
'PaperPosition',get(0,'defaultfigurePaperPosition'),...
'PaperSize',[20.98404194812 29.67743169791],...
'PaperType',get(0,'defaultfigurePaperType'),...
'Position',[103.8 47.0000000000001 69.4 14.4615384615385],...
'Renderer',get(0,'defaultfigureRenderer'),...
'RendererMode','manual',...
'Resize','off',...
'WindowStyle','modal',...
'HandleVisibility','callback',...
'Tag','figure1',...
'UserData',zeros(1,0));

setappdata(h1, 'GUIDEOptions', struct(...
'active_h', 3.280055e+002, ...
'taginfo', struct(...
'figure', 2, ...
'pushbutton', 2, ...
'text', 3), ...
'override', 0, ...
'release', 13, ...
'resize', 'none', ...
'accessibility', 'callback', ...
'mfile', 1, ...
'callbacks', 1, ...
'singleton', 1, ...
'syscolorfig', 1, ...
'lastSavedFile', 'C:\MATLAB6p5\work\cm2\about.m'));


h2 = uicontrol(...
'Parent',h1,...
'Units','characters',...
'FontSize',12,...
'FontWeight','bold',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'Position',[2.4 11.4615384615385 59.2 2.07692307692308],...
'String','Visualising 1D Quantum Scattering',...
'Style','text',...
'Tag','text1');


h3 = uicontrol(...
'Parent',h1,...
'Units','characters',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'Position',[2.4 0.615384615384615 63 10.3846153846154],...
'String',{ 'Chris Muktar' 'http://chris.chriscentral.com' 'chrismuktar@hotmail.com' '' 'This program uses an algorithm developed by John L Richardson,' 'as defined in the paper' 'Visualising Quantum Scattering on the CM-2 Supercomputer' 'Computer Physics Communications 63 (1991)' },...
'Style','text',...
'Tag','text2');



hsingleton = h1;


% --- Handles default GUIDE GUI creation and callback dispatch
function varargout = gui_mainfcn2(gui_State, varargin)


%   GUI_MAINFCN provides these command line APIs for dealing with GUIs
%
%      ABOUT_EXPORT, by itself, creates a new ABOUT_EXPORT or raises the existing
%      singleton*.
%
%      H = ABOUT_EXPORT returns the handle to a new ABOUT_EXPORT or the handle to
%      the existing singleton*.
%
%      ABOUT_EXPORT('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in ABOUT_EXPORT.M with the given input arguments.
%
%      ABOUT_EXPORT('Property','Value',...) creates a new ABOUT_EXPORT or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before untitled_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to untitled_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".

%   Copyright 1984-2002 The MathWorks, Inc.
%   $Revision: 1.4 $ $Date: 2002/05/31 21:44:31 $

gui_StateFields =  {'gui_Name'
                    'gui_Singleton'
                    'gui_OpeningFcn'
                    'gui_OutputFcn'
                    'gui_LayoutFcn'
                    'gui_Callback'};
gui_Mfile = '';
for i=1:length(gui_StateFields)
    if ~isfield(gui_State, gui_StateFields{i})
        error('Could not find field %s in the gui_State struct in GUI M-file %s', gui_StateFields{i}, gui_Mfile);        
    elseif isequal(gui_StateFields{i}, 'gui_Name')
        gui_Mfile = [getfield(gui_State, gui_StateFields{i}), '.m'];
    end
end

numargin = length(varargin);

if numargin == 0
    % ABOUT_EXPORT
    % create the GUI
    gui_Create = 1;
elseif numargin > 3 & ischar(varargin{1}) & ishandle(varargin{2})
    % ABOUT_EXPORT('CALLBACK',hObject,eventData,handles,...)
    gui_Create = 0;
else
    % ABOUT_EXPORT(...)
    % create the GUI and hand varargin to the openingfcn
    gui_Create = 1;
end

if gui_Create == 0
    varargin{1} = gui_State.gui_Callback;
    if nargout
        [varargout{1:nargout}] = feval(varargin{:});
    else
        feval(varargin{:});
    end
else
    if gui_State.gui_Singleton
        gui_SingletonOpt = 'reuse';
    else
        gui_SingletonOpt = 'new';
    end
    
    % Open fig file with stored settings.  Note: This executes all component
    % specific CreateFunctions with an empty HANDLES structure.
    
    % Do feval on layout code in m-file if it exists
    if ~isempty(gui_State.gui_LayoutFcn)
        gui_hFigure = feval(gui_State.gui_LayoutFcn, gui_SingletonOpt);
    else
        gui_hFigure = local_openfig2(gui_State.gui_Name, gui_SingletonOpt);            
        % If the figure has InGUIInitialization it was not completely created
        % on the last pass.  Delete this handle and try again.
        if isappdata(gui_hFigure, 'InGUIInitialization')
            delete(gui_hFigure);
            gui_hFigure = local_openfig2(gui_State.gui_Name, gui_SingletonOpt);            
        end
    end
    
    % Set flag to indicate starting GUI initialization
    setappdata(gui_hFigure,'InGUIInitialization',1);

    % Fetch GUIDE Application options
    gui_Options = getappdata(gui_hFigure,'GUIDEOptions');
    
    if ~isappdata(gui_hFigure,'GUIOnScreen')
        % Adjust background color
        if gui_Options.syscolorfig 
            set(gui_hFigure,'Color', get(0,'DefaultUicontrolBackgroundColor'));
        end

        % Generate HANDLES structure and store with GUIDATA
        guidata(gui_hFigure, guihandles(gui_hFigure));
    end
    
    % If user specified 'Visible','off' in p/v pairs, don't make the figure
    % visible.
    gui_MakeVisible = 1;
    for ind=1:2:length(varargin)
        if length(varargin) == ind
            break;
        end
        len1 = min(length('visible'),length(varargin{ind}));
        len2 = min(length('off'),length(varargin{ind+1}));
        if ischar(varargin{ind}) & ischar(varargin{ind+1}) & ...
                strncmpi(varargin{ind},'visible',len1) & len2 > 1
            if strncmpi(varargin{ind+1},'off',len2)
                gui_MakeVisible = 0;
            elseif strncmpi(varargin{ind+1},'on',len2)
                gui_MakeVisible = 1;
            end
        end
    end
    
    % Check for figure param value pairs
    for index=1:2:length(varargin)
        if length(varargin) == index
            break;
        end
        try, set(gui_hFigure, varargin{index}, varargin{index+1}), catch, break, end
    end

    % If handle visibility is set to 'callback', turn it on until finished
    % with OpeningFcn
    gui_HandleVisibility = get(gui_hFigure,'HandleVisibility');
    if strcmp(gui_HandleVisibility, 'callback')
        set(gui_hFigure,'HandleVisibility', 'on');
    end
    
    feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
    
    if ishandle(gui_hFigure)
        % Update handle visibility
        set(gui_hFigure,'HandleVisibility', gui_HandleVisibility);
        
        % Make figure visible
        if gui_MakeVisible
            set(gui_hFigure, 'Visible', 'on')
            if gui_Options.singleton 
                setappdata(gui_hFigure,'GUIOnScreen', 1);
            end
        end

        % Done with GUI initialization
        rmappdata(gui_hFigure,'InGUIInitialization');
    end
    
    % If handle visibility is set to 'callback', turn it on until finished with
    % OutputFcn
    if ishandle(gui_hFigure)
        gui_HandleVisibility = get(gui_hFigure,'HandleVisibility');
        if strcmp(gui_HandleVisibility, 'callback')
            set(gui_hFigure,'HandleVisibility', 'on');
        end
        gui_Handles = guidata(gui_hFigure);
    else
        gui_Handles = [];
    end
    
    if nargout
        [varargout{1:nargout}] = feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);
    else
        feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);
    end
    
    if ishandle(gui_hFigure)
        set(gui_hFigure,'HandleVisibility', gui_HandleVisibility);
    end
end    

function gui_hFigure = local_openfig2(name, singleton)
if nargin('openfig') == 3 
    gui_hFigure = openfig(name, singleton, 'auto');
else
    % OPENFIG did not accept 3rd input argument until R13,
    % toggle default figure visible to prevent the figure
    % from showing up too soon.
    gui_OldDefaultVisible = get(0,'defaultFigureVisible');
    set(0,'defaultFigureVisible','off');
    gui_hFigure = openfig(name, singleton);
    set(0,'defaultFigureVisible',gui_OldDefaultVisible);
end

% *************** Erors fixed *******************************
% Warning: The EraseMode property is no longer supported and will error in
% a future release. Use the ANIMATEDLINE function for animating lines and 
% points instead of EraseMode 'none'. Removing instances of EraseMode set 
% to 'normal', 'xor', and 'background' has minimal impact. 
% > In quantumscatter>plotnow at 190

% Warning: File: quantumscatter.m Line: 874 Column: 22
%Function with duplicate name "gui_mainfcn" cannot be called. 
%Warning: File: quantumscatter.m Line: 1051 Column: 24
%Function with duplicate name "local_openfig" cannot be called. 
