function gbprop(action); %GBPROP Demonstrates the propagation of Gaussian Beams. % Victor Jones, 3-5-98 % For reference purposes here is a list of storage locations: % set(gcf,'UserData',[tasAxes lasAxes]) - i.e. pair of axes handles % set(tasAxes,'UserData',cntlHndl) - i.e. array of uicontro handles % set(lasAxes,'UserData',[z; q]) - i.e. a position-q value array % set(0,'UserData',region) % set(cntlHndl(1),'Value','current region') % set(cntlHndl(2),'Value','current region') % set(cntlHndl(3),'UserData',plotHndl) % set(cntlHndl(8),'Value',device spec) % set(cntlHndl(10),''Value'',b) where b is the button of origin % set(cntlHndl(10),'String','last entered value') % set(cntlHndl(10),'UserData','position of beam minimum'); % set(cntlHndl(12),'String','last entered value') % set(cntlHndl(12),'UserData','Fresnel length'); % set(cntlHndl(14),'String','last entered value') % set(cntlHndl(14),'UserData','beam wavelength'); if nargin<1, action='initialize'; end; %=================================== if strcmp(action,'initialize'), set(0,'UserData',[]); % Definition of transverse axes space tasTop = 0.98; tasBottom = 0.35; tasLeft = 0.02; tasRight = 0.65; tasPos = [tasLeft tasBottom tasRight-tasLeft tasTop-tasBottom]; % Definition of longitudinal axes space lasTop = tasBottom - 0.04; lasBottom = 0; lasLeft = tasLeft; lasRight = 1.0; lasPos = [lasLeft lasBottom lasRight-lasLeft lasTop-lasBottom]; % Create a figure with two axes objects figNumber = figure( ... 'Name','Gaussian Beam Demo', ... 'NumberTitle','off', ... 'Color',[0.9 0.9 0.9],... 'Units','normal',... 'Position',[0.15 0.15 0.75 0.75],... 'Visible','off'); tasAxes = subplot('Position',tasPos); set(tasAxes,... 'Box','on',... 'Units','normalized', ... 'NextPlot','add',... 'XTick',[],'YTick',[],'ZTick',[], ... 'Visible','on'); lasAxes = subplot('Position',lasPos); set(lasAxes,... 'Box','on',... 'Units','normalized',... 'Color',[0 0 0],... 'NextPlot','add',... 'XTick',[],'YTick',[],'ZTick',[],... 'Visible','on'); set(gcf,'UserData',[tasAxes lasAxes]) % Definition of data entry space desTop = tasTop; desBottom = tasBottom; desLeft = tasRight + 0.02; desRight = lasRight; desPos = [desLeft desBottom desRight-desLeft desTop-desBottom]; frmBorder = 0.015; cntlTop = desTop - frmBorder; cntlWid = 0.14; cntlHt = 0.08; cntlSpacing = 0.02; % Create a frame for the data entry space set(gcf,'CurrentAxes',tasAxes); frmHndl = uicontrol( ... 'Style','frame', ... 'Units','normalized', ... 'Position',desPos, ... 'BackgroundColor',[0.5 0.5 0.5]); %==================================== % Create the "Initialize beam" control button cntlNumber = 1; yPos = cntlTop-(round(cntlNumber./2)-1)*(cntlHt+cntlSpacing); if rem(cntlNumber,2) == 0 xPos = desRight - frmBorder - cntlWid; else xPos = desLeft + frmBorder; end labelStr = 'Initialize beam'; callbackStr = [... 'axes = get(gcf,''UserData'');',... 'cntlHndl = get(axes(1),''UserData'');',... 'set(cntlHndl(1),''Value'',1),',... 'set(cntlHndl(10),''Value'',1);',... 'gbprop(''get info_1'')']; cntlPos = [xPos yPos-cntlHt cntlWid cntlHt]; cntlHndl(cntlNumber) = uicontrol( ... 'Style','pushbutton', ... 'Units','normalized', ... 'String',labelStr, ... 'Position',cntlPos, ... 'Callback',callbackStr); %==================================== % Create the "Add device" control button cntlNumber = 2; yPos = cntlTop-(round(cntlNumber./2)-1)*(cntlHt+cntlSpacing); if rem(cntlNumber,2) == 0 xPos = desRight - frmBorder - cntlWid; else xPos = desLeft + frmBorder; end labelStr = 'Add device'; callbackStr = [... 'axes = get(gcf,''UserData'');',... 'cntlHndl = get(axes(1),''UserData'');',... 'set(cntlHndl(1),''Value'',1),',... 'set(cntlHndl(10),''Value'',2);',... 'gbprop(''get device'');']; cntlPos = [xPos yPos-cntlHt cntlWid cntlHt]; cntlHndl(cntlNumber) = uicontrol( ... 'Style','pushbutton', ... 'Units','normalized', ... 'String',labelStr, ... 'Position',cntlPos, ... 'Callback',callbackStr); %==================================== % Create the "Launch beam" control button cntlNumber = 3; yPos = cntlTop-(round(cntlNumber./2)-1)*(cntlHt+cntlSpacing); if rem(cntlNumber,2) == 0 xPos = desRight - frmBorder - cntlWid; else xPos = desLeft + frmBorder; end labelStr = 'Launch again'; callbackStr = [... 'axes = get(gcf,''UserData'');',... 'cntlHndl = get(axes(1),''UserData'');',... 'set(cntlHndl(1),''Value'',1),',... 'set(cntlHndl(10),''Value'',3);',... 'gbprop(''las plot'')']; cntlPos = [xPos yPos-cntlHt cntlWid cntlHt]; cntlHndl(cntlNumber) = uicontrol( ... 'Style','pushbutton', ... 'Units','normalized', ... 'String',labelStr, ... 'Position',cntlPos, ... 'Callback',callbackStr); %==================================== % Create an "Remove device" control button cntlNumber = 4; yPos = cntlTop-(round(cntlNumber./2)-1)*(cntlHt+cntlSpacing); if rem(cntlNumber,2) == 0 xPos = desRight - frmBorder - cntlWid; else xPos = desLeft + frmBorder; end labelStr = 'Remove device'; callbackStr = [... 'axes = get(gcf,''UserData'');',... 'cntlHndl = get(axes(1),''UserData'');',... 'set(cntlHndl(10),''Value'',4);',... 'set(gcf,''WindowButtonDownFcn'',''gbprop(''''kill device'''')'');']; cntlPos = [xPos yPos-cntlHt cntlWid cntlHt]; cntlHndl(cntlNumber) = uicontrol( ... 'Style','pushbutton', ... 'Units','normalized', ... 'String',labelStr, ... 'Position',cntlPos, ... 'Callback',callbackStr); %==================================== % Create an "Profile beam" control button cntlNumber = 5; yPos = cntlTop-(round(cntlNumber./2)-1)*(cntlHt+cntlSpacing); if rem(cntlNumber,2) == 0 xPos = desRight - frmBorder - cntlWid; else xPos = desLeft + frmBorder; end labelStr = 'Profile beam'; callbackStr = [... 'axes = get(gcf,''UserData'');',... 'cntlHndl = get(axes(1),''UserData'');',... 'set(cntlHndl(1),''Value'',1),',... 'set(cntlHndl(10),''Value'',5);',... 'gbprop(''get info_1'')']; cntlPos = [xPos yPos-cntlHt cntlWid cntlHt]; cntlHndl(cntlNumber) = uicontrol( ... 'Style','pushbutton', ... 'Units','normalized', ... 'String',labelStr, ... 'Position',cntlPos, ... 'Callback',callbackStr); %==================================== % Create the "Reset" control button cntlNumber = 6; yPos = cntlTop-(round(cntlNumber./2)-1)*(cntlHt+cntlSpacing); if rem(cntlNumber,2) == 0 xPos = desRight - frmBorder - cntlWid; else xPos = desLeft + frmBorder; end labelStr = 'Reset'; callbackStr=[... 'delete(gcf);',... 'gbprop(''initialize'')']; cntlPos = [xPos yPos-cntlHt cntlWid cntlHt]; cntlHndl(cntlNumber) = uicontrol( ... 'Style','pushbutton', ... 'Units','normalized', ... 'Position',cntlPos, ... 'String',labelStr, ... 'Callback',callbackStr); %==================================== % Create the "Device entry" static text control cntlNumber = 7; cntlHndl(cntlNumber) = uicontrol( ... 'Style','text', ... 'Units','normalized', ... 'Visible','off',... 'BackgroundColor',[0.5 0.5 0.5],... 'FontWeight','bold',... 'ForegroundColor',[1 1 1],... 'HorizontalAlignment','Left'); %==================================== % Create "Popup" control cntlNumber = 8; popupStr = [... 'positive lens|'... 'negative lens|plane mirror|'... 'concave mirror|convex mirror|'... 'grin rod']; callbackStr = [... 'A = get(gcf,''UserData'');',... 'cntlHndl = get(A(1),''UserData'');',... 'set(cntlHndl(12),''Value'',8);',... 'gbprop(''get info_1'')']; cntlHndl(cntlNumber) = uicontrol( ... 'Style','popup', ... 'Units','normalized', ... 'Visible','off',... 'String',popupStr, ... 'FontSize',[12],... 'Position',cntlPos, ... 'Callback',callbackStr); %==================================== % Create the "First entry" static text control cntlNumber = 9; cntlHndl(cntlNumber) = uicontrol( ... 'Style','text', ... 'Units','normalized', ... 'Visible','off',... 'HorizontalAlignment','Left',... 'BackgroundColor',[1 1 1]); %==================================== % Create the "First entry" editable text control cntlNumber = 10; cntlHndl(cntlNumber) = uicontrol( ... 'Style','edit', ... 'Units','normalized', ... 'HorizontalAlignment','Right',... 'Visible','off',... 'BackgroundColor',[1 1 1]); %==================================== % Create the "Second entry" static text control cntlNumber = 11; cntlHndl(cntlNumber) = uicontrol( ... 'Style','text', ... 'Units','normalized', ... 'Visible','off',... 'HorizontalAlignment','Left',... 'BackgroundColor',[1 1 1]); %==================================== % Create the "Second entry" editable text control cntlNumber = 12; cntlHndl(cntlNumber) = uicontrol( ... 'Style','edit', ... 'Units','normalized', ... 'HorizontalAlignment','Right',... 'Visible','off',... 'BackgroundColor',[1 1 1]); %==================================== % Create the "Third entry" static text control cntlNumber = 13; cntlHndl(cntlNumber) = uicontrol( ... 'Style','text', ... 'Units','normalized', ... 'HorizontalAlignment','Left',... 'Visible','off',... 'BackgroundColor',[1 1 1]); %==================================== % Create the "Third entry" editable text control cntlNumber = 14; cntlHndl(cntlNumber) = uicontrol( ... 'Style','edit', ... 'Units','normalized', ... 'HorizontalAlignment','Right',... 'Visible','off',... 'BackgroundColor',[1 1 1],'Max', 1); %==================================== % Create the "Data entry" static text control cntlNumber = 9; cntlHndl(cntlNumber) = uicontrol( ... 'Style','text', ... 'Units','normalized', ... 'Visible','off'); %==================================== % The CLOSE button uicontrol( ... 'Style','push', ... 'Units','normalized', ... 'Position',[desRight-frmBorder-cntlWid... desBottom+frmBorder cntlWid cntlHt], ... 'String','Close', ... 'Callback','close(gcf)'); % Save all of these handles for future use set(gca,'UserData',cntlHndl); % and make an initial presentation set(gcf,'Visible','on'); %=================================== elseif strcmp(action,'get device') axes = get(gcf,'UserData'); cntlHndl = get(axes(1),'UserData'); cntlPos = get(cntlHndl(5),'Position'); Pos_1 = cntlPos - [0 cntlPos(4)+0.04 0 0]; Pos_2 = Pos_1 + [cntlPos(3)+0.02 0 0 0]; set(cntlHndl(7),... 'String','Select a device',... 'Position',Pos_1,... 'Visible','on'); set(cntlHndl(8),... 'Position',Pos_2,... 'Visible','on',... 'CallBack','gbprop(''get info_1'')'); %=================================== elseif strcmp(action,'kill device') axes = get(gcf,'UserData'); cntlHndl = get(axes(1),'UserData'); region = get(0,'UserData'); maxIndex = size(region,2); set(gco,'Selected','on'); for index = 2:2:maxIndex-1 if gco == region(index).pictHndl break end end set(cntlHndl(2),'Value',index); gbprop('get info_1'); %=================================== elseif strcmp(action,'get info_1') axes = get(gcf,'UserData'); xLim = get(axes(2),'XLim'); cntlHndl = get(axes(1),'UserData'); Pos_A = get(cntlHndl(5),'Position'); Pos_B = get(cntlHndl(6),'Position'); Pos_1 = [Pos_A(1) (Pos_A(1)-0.9*Pos_A(4))... 1.55*Pos_A(3) 0.7*Pos_A(4)]; Pos_2 = [Pos_B(1)+Pos_B(3)-0.6*Pos_B(3) Pos_1(2)... 0.6*Pos_B(3) 0.5*Pos_B(4)]; % Next action varies with button origin switch get(cntlHndl(10),'Value') case 1 % 'Initialize beam' button instrStr = 'Enter the position (cm) of the minimum beam width'; numStr = sprintf('%2.1f',xLim(1)); callStr = 'gbprop(''get info_2'')'; case 2 % 'Add device' button xDim = xLim(2) - xLim(1); set(cntlHndl(7),'Visible','off'); set(cntlHndl(8),'Visible','off'); gbprop('mouse meter on'); callStr = 'gbprop(''get info_2'')'; switch get(cntlHndl(8),'Value') case 1 instrStr = 'Where is the positive lens located?'; numStr = sprintf('%2.1f',10*fix(xDim./20)); case 2 instrStr = 'Where is the negative lens located?'; numStr = sprintf('%2.1f',10*fix(xDim./20)); case 3 instrStr = 'Where is the plane mirror located?'; numStr = sprintf('%2.1f',10*fix(xDim./20)); callStr ='gbprop(''make space'')'; case 4 instrStr = 'Where is the concave mirror located?'; numStr = sprintf('%2.1f',10*fix(xDim./20)); case 5 numStr = sprintf('%2.1f',10*fix(xDim./20)); instrStr = 'Where is the convex mirror located?'; case 6 numStr = sprintf('%2.1f',xLim(1)); instrStr = 'Where does the "grin rod" region start?'; end case 4 % 'Remove device' button set(gcf,'WindowButtonDownFcn','default'); instrStr = 'Remove the selected device?'; numStr = 'yes'; callStr ='gbprop(''make space'')'; case 5 % 'Profile beam' button gbprop('mouse meter on'); instrStr = 'Where do you want to profile?'; callStr = 'gbprop(''tas plot'')'; numStr = sprintf('%2.1f',0); end set(cntlHndl(9),... 'BackgroundColor',[0.5 0.5 0.5],... 'ForegroundColor',[1 1 1],... 'String',instrStr,... 'HorizontalAlignment','Left',... 'Visible','on',... 'Position',Pos_1); set(cntlHndl(10),... 'HorizontalAlignment','Right',... 'CallBack',callStr,... 'Visible','on',... 'Position',Pos_2,... 'String',numStr) set(cntlHndl(1),'Value',2); %=================================== elseif strcmp(action,'get info_2') axes = get(gcf,'UserData'); set(gcf,'CurrentAxes',axes(2)); cntlHndl = get(axes(1),'UserData'); cntlPos = get(cntlHndl(5),'Position'); Pos_A = get(cntlHndl(9),'Position'); Pos_B = get(cntlHndl(10),'Position'); Pos_1 = [Pos_A(1) Pos_A(2)-Pos_A(4)-0.01... Pos_A(3) Pos_A(4)]; Pos_2 = [Pos_B(1) Pos_1(2) Pos_B(3) Pos_B(4)]; % Next action varies with button of origin switch get(cntlHndl(10),'Value') case 1 % 'Initialize beam' button gbprop('mouse meter off'); callStr = 'gbprop(''get info_3'')' ; instrStr = 'Enter a value for the minimum beam width (cm)'; numStr = sprintf('%2.1f',20); case 2 % 'Add device' button callStr = 'gbprop(''make space'')' ; gbprop('mouse meter off'); xLim = get(axes(2),'XLim'); xDim = xLim(2) - xLim(1); switch get(cntlHndl(8),'Value') case 1 instrStr = 'What is the focal length of the lens?'; numStr = sprintf('%2.1f',10*fix(xDim./100)); case 2 instrStr = 'What is the focal length of the lens?'; numStr = sprintf('%2.1f',-10*fix(xDim./100)); case 4 instrStr = 'What is the focal length of the mirror?'; numStr = sprintf('%2.1f',10*fix(xDim./100)); case 5 instrStr = 'What is the focal length of the mirror?'; numStr = sprintf('%2.1f',-10*fix(xDim./100)); case 6 gbprop('mouse meter on'); instrStr = 'Where does the "grin rod" region end?'; numStr = sprintf('%2.1f',10*fix(xLim(2)./10)); callStr = 'gbprop(''get info_3'')'; end end set(cntlHndl(11),... 'BackgroundColor',[0.5 0.5 0.5],... 'ForegroundColor',[1 1 1],... 'String',instrStr,... 'HorizontalAlignment','Left',... 'Visible','on',... 'Position',Pos_1); set(cntlHndl(12),... 'HorizontalAlignment','Right',... 'CallBack',callStr,... 'Visible','on',... 'Position',Pos_2,... 'String',numStr ) set(cntlHndl(1),'Value',3); %=================================== elseif strcmp(action,'get info_3') gbprop('mouse meter off'); axes = get(gcf,'UserData'); set(gcf,'CurrentAxes',axes(2)); cntlHndl = get(axes(1),'UserData'); callStr = 'gbprop(''make space'')'; Pos_A = get(cntlHndl(11),'Position'); Pos_B = get(cntlHndl(12),'Position'); Pos_1 = [Pos_A(1) Pos_A(2)-Pos_A(4)-0.01... Pos_A(3) Pos_A(4)]; Pos_2 = [Pos_B(1) Pos_1(2) Pos_B(3) Pos_B(4)]; % Next action varies with button of origin switch get(cntlHndl(10),'Value') case 1 % 'Initialize beam' button instrStr = 'Enter a value for the wavelength (cm)'; numStr = sprintf('%2.1f',1); case 2 % 'Add device' button if get(cntlHndl(8),'Value') == 6 gbprop('mouse meter on'); xLim = get(axes(2),'XLim'); xDim = xLim(2) - xLim(1); instrStr = 'What is the spatial period of the grin rod'; numStr = sprintf('%2.1f',20*round(xDim./100)); end end set(cntlHndl(13),... 'BackgroundColor',[0.5 0.5 0.5],... 'ForegroundColor',[1 1 1],... 'String',instrStr,... 'HorizontalAlignment','Left',... 'Visible','on',... 'Position',Pos_1); set(cntlHndl(14),... 'HorizontalAlignment','Right',... 'CallBack',callStr,... 'Visible','on',... 'Position',Pos_2,... 'String',numStr ) set(cntlHndl(1),'Value',4); %=================================== elseif strcmp(action,'button motion')|strcmp(action,'button up') axes = get(gcf,'UserData'); set(gcf,'CurrentAxes',axes(2)); yLim = get(gca,'YLim'); cntlHndl = get(axes(1),'UserData'); pt=get(gca,'CurrentPoint'); if pt(1,2)yLim(1) set(gcf,'Pointer','crosshair'); if get(cntlHndl(1),'Value') == 2 set(cntlHndl(10),... 'String',sprintf('%2.1f',pt(1,1))); elseif get(cntlHndl(1),'Value') == 3 set(cntlHndl(12),... 'String',sprintf('%2.1f',pt(1,1))); end else set(gcf,'Pointer','arrow'); end if strcmp(action,'button up') set(gcf,... 'Pointer','arrow',... 'WindowButtonMotionFcn','default'); end %=================================== elseif strcmp(action,'make space') gbprop('mouse meter off'); axes = get(gcf,'UserData'); tasAxes = axes(1); lasAxes = axes(2); cntlHndl = get(tasAxes,'UserData'); % Erase all of the data dialogs i = 0:7; set(cntlHndl(7 + i),'Visible','off'); % Next action varies with button of origin switch get(cntlHndl(10),'Value') case 1 % 'Initialize beam' button set(cntlHndl(10),'UserData',... str2num(get(cntlHndl(10),'String'))); % Calculate and save the Fresnel length W = str2num(get(cntlHndl(12),'String')); lamda = str2num(get(cntlHndl(14),'String')); set(cntlHndl(14),'UserData',lamda); L = (pi*W.^2)./lamda; set(cntlHndl(12),'UserData',L); set(lasAxes,... 'XLim',[0 8*L],... 'YLim',[-8*W 8*W]); % Initialize propagation space region(1) = struct(... 'name','free space',... 'position',get(lasAxes,'XLim'),... 'parameter',[],... 'pictHndl',[]); set(0,'UserData',region); gbprop('las plot'); case 2 % 'Add device' button xLim = get(lasAxes,'XLim'); yLim = get(lasAxes,'YLim'); region = get(0,'UserData'); maxIndex = size(region,2); devPos = str2num(get(cntlHndl(10),'String')); endPos = devPos; % We need to make sure space is free for the device for index = 1:maxIndex if strcmp(region(index).name,'grin rod') if devPos >= region(index).position(1) &... devPos <= region(index).position(2) error('The device overlaps a GRIN rod!'); gbprop('get info_1'); end end end switch get(cntlHndl(8),'Value') case 1 rgnName = 'pos lens'; rgnParam = str2num(get(cntlHndl(12),'String')); case 2 rgnName = 'neg lens'; rgnParam = str2num(get(cntlHndl(12),'String')); case 3 rgnName = 'pln mirr'; rgnParam = []; case 4 rgnName = 'concv mirr'; rgnParam = str2num(get(cntlHndl(12),'String')); case 5 rgnName = 'convx mirr'; rgnParam = str2num(get(cntlHndl(12),'String')); case 6 rgnName = 'grin rod'; endPos = str2num(get(cntlHndl(12),'String')); rgnParam = str2num(get(cntlHndl(14),'String')); for index = 2:2:maxIndex-1 if region(index).position(1) >= devPos &... region(index).position(2) <= endPos error('The GRIN rod overlaps another device'); gbprop('get info_1'); end end end % Now we start sort out the order of things % First we get the starting positions in order switch maxIndex case 1 region(3) = region(1); region(2).position = [devPos endPos]; region(1).position(2) = devPos; region(3).position(1) = endPos; nuIndex = 2; case 3 region(5) = region(3); if devPos > region(2).position(1) region(4).position = [devPos endPos]; region(3).position(2) = devPos; region(5).position(1) = endPos; nuIndex = 4; else region(4) = region(2); region(2).position = [devPos endPos]; region(1).position(2) = devPos; region(3).position(1) = endPos; region(3).position(2) = region(4).position(1); nuIndex = 2; end otherwise for nuIndex = 2:2:maxIndex-1 if devPos < region(nuIndex).position(1) break end end if nuIndex == maxIndex-1 nuIndex = maxIndex + 1; region(nuIndex+1) = region(nuIndex-1); region(nuIndex).position = [devPos endPos]; region(nuIndex-1).position(2) = devPos; region(nuIndex+1).position(1) = endPos; else for i = nuIndex:maxIndex region(maxIndex+nuIndex-i+2)... = region(maxIndex+nuIndex-i); end region(nuIndex).position = [devPos endPos]; region(nuIndex-1).position(2) = devPos; region(nuIndex+1).position(1) = endPos; region(nuIndex+1).position(2) =... region(nuIndex+2).position(1); end end region(nuIndex).name = rgnName; region(nuIndex).parameter = rgnParam; set(cntlHndl(2),'Value',nuIndex); set(0,'UserData',region); gbprop('device plot'); case 4 % 'Remove device' button devNum = get(cntlHndl(2),'Value'); region = get(0,'UserData'); maxIndex = size(region,2); if strcmp(get(cntlHndl(10),'String'),'yes') pictHndl = region(devNum).pictHndl; for index = devNum+2:maxIndex region(index-2) = region(index); end region(devNum-1).position(2) =... region(devNum).position(1); region = region(1:maxIndex-2); delete(pictHndl); else set(region(devNum).pictHndl,'Selected','off'); end set(0,'UserData',region); end %=================================== elseif strcmp(action,'las plot') axes = get(gcf,'UserData'); tasAxes = axes(1); lasAxes = axes(2); cntlHndl = get(tasAxes,'UserData'); L = get(cntlHndl(12),'UserData'); z0 = get(cntlHndl(10),'UserData'); maxPts = 201; xLim = get(lasAxes,'XLim'); yLim = get(lasAxes,'YLim'); xDim = xLim(2) - xLim(1); xDiff = xDim/(maxPts - 1); ticNum = xDim./L - 1; % Action varies with button origin switch get(cntlHndl(10),'Value') case 1 % 'Initialize beam' button X=linspace(0,xDim,ticNum+2); for n =4:3*(ticNum+2) x(n)=X(round((n+1)./3)); if rem(n,3)==2 y(n)=yLim(2)/20; else y(n)=0; end end plot(x,y,'w') index = 1:maxPts; z = xDiff*(index - 1); q = (z - z0) + j*L; case 3 % 'Launch beam' button delete(get(cntlHndl(3),'UserData')); region = get(0,'UserData'); maxRgn = size(region,2); m =1; n = 1; bakProp = 1; q(1) = -z0 + j*L; z(1) = 0; while n <= maxRgn, if bakProp < 0 while z(m) > region(n).position(1), z(m+1) = z(m) - xDiff; q(m+1) = q(m) + xDiff; m = m + 1; end n = n - 1; else while z(m) < region(n).position(2), z(m+1) = z(m) + xDiff; q(m+1) = q(m) + xDiff; m = m + 1; end n = n + 1; end if n >= maxRgn | n <= 0 break end switch region(n).name case {'pos lens', 'neg lens'} z(m+1) = z(m); q(m+1) = q(m)./(1-q(m)./region(n).parameter); m = m + 1; n = n + 1; case 'pln mirr' z(m+1) = z(m); q(m+1) = q(m); m = m + 1; n = n - 1; bakProp = -bakProp; case {'concv mirr', 'convx mirr'} z(m+1) = z(m); q(m+1) = q(m)./(1-q(m)./region(n).parameter); m = m + 1; n = n - 1; bakProp = -bakProp; case 'grin rod' fac1 = 2*pi./region(n).parameter; fac2 = tan(fac1*xDiff); while z(m) < region(n).position(2), z(m+1) = z(m) + xDiff; q(m+1) = (q(m)+fac2./fac1)./(-fac1*fac2*q(m)+1); m = m + 1; end n = n + 1; end end maxPts = size(z,2); end set(gca,'UserData',[z; q]); % Save data array for transverse plots lamda = get(cntlHndl(14),'UserData'); qInv = 1./q; W = sqrt(-lamda./(pi*imag(qInv))); F = (pi*L./lamda)./8; % Aspect ratio factor plotHndl(1) = plot(z,W,'r-','LineWidth',[2]); plotHndl(2) = plot(z,-W,'r-','LineWidth',[2]); tic = 1; index = 1; while tic <= ticNum+1 & get(cntlHndl(10),'Value') == 1 while 1, if z(index) > rem(z0,L) + (tic-1)*L break end index = index + 1; end if real(qInv(index-1)) ~= 0 R = 1./real(qInv(index-1)); m = 1:10; y = (m-1)*W(index)/9; if R > 0 x = z(index-1)-F*(R-sqrt(R.^2-y.^2)); else x = z(index-1)-F*(R+sqrt(R.^2-y.^2)); end next = size(plotHndl,2); plotHndl(next+1) = plot(x,y,'g'); plotHndl(next+2) = plot(x,-y,'g'); end tic = tic + 1; end set(cntlHndl(3),'UserData',plotHndl); % Save for erase %=================================== elseif strcmp(action,'device plot') axes = get(gcf,'UserData'); tasAxes = axes(1); lasAxes = axes(2); cntlHndl = get(tasAxes,'UserData'); xLim = get(lasAxes,'XLim'); yLim = get(lasAxes,'YLim'); xDim = xLim(2) - xLim(1); region = get(0,'UserData'); set(gcf,'CurrentAxes',lasAxes); devPos = str2num(get(cntlHndl(10),'String')); devParam = str2num(get(cntlHndl(14),'String')); devNum = get(cntlHndl(2),'Value'); D=xDim./50; R=xDim./6; H=1.9*yLim(1); switch get(cntlHndl(8),'Value') case 1 x1=devPos+linspace(-D,0,20); y1=H*real(sqrt(1-((x1-devPos+D)./R-1).^2)); x2=devPos+linspace(0,D,20); y2=H*real(sqrt(1-((x2-devPos-D)./R+1).^2)); x3=devPos+linspace(D,0,20); y3=-H*real(sqrt(1-((x3-devPos-D)./R+1).^2)); x4=devPos+linspace(0,-D,20); y4=-H*real(sqrt(1-((x4-devPos+D)./R-1).^2));; shape=[[y1; x1] [y2; x2] [y3;x3] [y4;x4]]; case 2 x1=devPos+linspace(-D,0,20); y1=H*sqrt(1-((-x1+devPos)./R-1).^2); x2=devPos+linspace(0,-D,20); y2=-H*sqrt(1-((-x2+devPos)./R-1).^2);; x3=devPos+linspace(D,0,20); y3=-H*sqrt(1-((-x3+devPos)./R+1).^2); x4=devPos+linspace(0,D,20); y4=H*sqrt(1-((-x4+devPos)./R+1).^2); x0=devPos+D; y0=H*sqrt(1-(D./R-1).^2); shape=[[y0; x0] [y1; x1] [y2; x2] [y3;x3] [y4;x4]]; case 3 x0=devPos-D./6; y0=H./2; x1=devPos+D./6; shape=[[y0; x0] [y0; x1] [-y0; x1] [-y0;x0] [y0;x0]]; case 4 x0=devPos-D; y0=H*sqrt(1-(D./R-1).^2); x1=devPos+linspace(-D,0,20); y1=H*sqrt(1-((-x1+devPos)./R-1).^2); x2=devPos+linspace(0,-D,20); y2=-H*sqrt(1-((-x2+devPos)./R-1).^2);; shape=[[y1; x1] [y2; x2]... [-y1; x1+D./3] [-y2; x2+D./3]]; case 5 x0=devPos+D; y0=H*sqrt(1-(D./R-1).^2); x3=devPos+linspace(D,0,20); y3=-H*sqrt(1-((-x3+devPos)./R+1).^2); x4=devPos+linspace(0,D,20); y4=H*sqrt(1-((-x4+devPos)./R+1).^2); shape=[[y3; x3] [y4; x4]... [-y3; x3+D./3] [-y4;x4+D./3]]; case 6 endPos = str2num(get(cntlHndl(12),'String')); x0=devPos; y0=H./2; x1=endPos; shape=[[y0; x0] [y0; x1] [-y0; x1] [-y0;x0] [y0;x0]]; end region(devNum).pictHndl = patch(shape(2,:),shape(1,:),'c','EdgeColor','c'); set(0,'UserData',region); %=================================== elseif strcmp(action,'tas plot') axes = get(gcf,'UserData'); tasAxes = axes(1); lasAxes = axes(2); cntlHndl = get(tasAxes,'UserData'); lasData = get(lasAxes,'UserData'); for i = 0:7 set(cntlHndl(7 + i),'Visible','off'); end set(gcf,'CurrentAxes',tasAxes); set(gca,'View',[30 30]); z = lasData(1,:); q = lasData(2,:); maxIndex = size(z,2); for i = 1:maxIndex if z(i) > str2num(get(cntlHndl(10),'String')) break; end end qInv = 1./q(i); W=sqrt(-1./imag(qInv)); x = linspace(-2*W,2*W,30); y = x; [X,Y] = meshgrid(x,y); Z=exp(imag(qInv)*(X.^2 + Y.^2)); surf(X,Y,Z) %=================================== elseif strcmp(action,'mouse meter on') set(gcf,... 'Pointer','crosshair',... 'WindowButtonUpFcn','gbprop(''button up'')',... 'WindowButtonMotionFcn','gbprop(''button motion'')'); %=================================== elseif strcmp(action,'mouse meter off') set(gcf,... 'Pointer','arrow',... 'WindowButtonUpFcn','default',... 'WindowButtonMotionFcn','default'); %=================================== end % if strcmp(action, ...