summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--axial/L_.m23
-rw-r--r--axial/R_.m24
-rw-r--r--axial/beamplot.m81
-rw-r--r--axial/beamradius.m28
-rw-r--r--axial/cav.m136
-rw-r--r--axial/elems.m12
-rw-r--r--axial/fdie.m22
-rw-r--r--axial/free.m22
-rw-r--r--axial/lens.m21
-rw-r--r--axial/lensplot.m116
-rw-r--r--axial/mirr.m21
-rw-r--r--axial/prop.m32
-rw-r--r--axial/prop2.m27
-rw-r--r--axial/q_.m29
-rw-r--r--axial/sdie.m25
-rw-r--r--axial/slab.m17
-rw-r--r--axial/w0_.m22
-rw-r--r--axial/w_.m23
-rw-r--r--coatings/coatingRT.m229
-rw-r--r--coatings/coatingRTnew.m225
-rw-r--r--coatings/prerequisits.txt5
-rw-r--r--examples/A_beam_visualization_script.m601
-rw-r--r--examples/A_beam_visualization_script_support/beam_propagate_llo_asbuilt.m439
-rw-r--r--examples/A_beam_visualization_script_support/beam_visualize_asbuilt.m591
-rw-r--r--examples/Airy1Dplot.m23
-rw-r--r--examples/AiryIplot.m43
-rw-r--r--examples/Hermite_demo.m73
-rw-r--r--examples/LGIplot.m37
-rw-r--r--examples/Laguerre_demo.m97
-rw-r--r--examples/NRIplot.m24
-rw-r--r--examples/fourier_optics_demonstration.m198
-rw-r--r--examples/gaussian_topview.m56
-rw-r--r--examples/unstable_cavity.m151
-rw-r--r--misc/fresnel2.m29
-rw-r--r--misc/fresneliso.m56
-rw-r--r--misc/incomplete/Hermite_Orthogonality.nb147
-rw-r--r--misc/incomplete/Hermite_overlap.m17
-rw-r--r--misc/incomplete/optics_code.txt8
-rw-r--r--misc/incomplete/prop_fft1.m2
-rw-r--r--misc/r2f/CVI_BICC_BK7_r2f_index.txt34
-rw-r--r--misc/r2f/CVI_BICC_SIO2_r2f_index.txt28
-rw-r--r--misc/r2f/CVI_BICX_BK7_r2f_index.txt105
-rw-r--r--misc/r2f/CVI_BICX_SIO2_r2f_index.txt62
-rw-r--r--misc/r2f/CVI_PLCC_BK7_r2f_index.txt52
-rw-r--r--misc/r2f/CVI_PLCC_SIO2_r2f_index.txt58
-rw-r--r--misc/r2f/CVI_PLCX_BK7_r2f_index.txt150
-rw-r--r--misc/r2f/CVI_PLCX_SIO2_r2f_index.txt104
-rw-r--r--misc/r2f/f2r.m130
-rw-r--r--misc/r2f/r2f.m130
-rw-r--r--opticstrain/demo_optics.txt28
-rw-r--r--opticstrain/demo_optics.xlsxbin0 -> 10651 bytes
-rw-r--r--opticstrain/opticstrain help.docxbin0 -> 16272 bytes
-rw-r--r--opticstrain/opticstrain help.pdfbin0 -> 243444 bytes
-rw-r--r--opticstrain/opticstrain.m349
-rw-r--r--sharedfiles/dispmat.m51
-rw-r--r--sharedfiles/fact.m10
-rw-r--r--sharedfiles/figtext.m61
-rw-r--r--sharedfiles/figtext3D.m71
-rw-r--r--sharedfiles/plothorline.m101
-rw-r--r--sharedfiles/plotvertline.m102
-rw-r--r--sharedfiles/reverse.m5
-rw-r--r--sharedfiles/scalemarker.m32
-rw-r--r--transverse/AiryE.m74
-rw-r--r--transverse/AiryI.m25
-rw-r--r--transverse/AiryI_Fraunhofer.m33
-rw-r--r--transverse/HermiteGaussianE.m134
-rw-r--r--transverse/LaguerreGaussianE.m189
-rw-r--r--transverse/LaguerrePoly.m24
-rw-r--r--transverse/NewtonRingsI.m64
-rw-r--r--transverse/SimpleGaussian.m54
-rw-r--r--transverse/SimpleGaussian_rdep.m82
-rw-r--r--transverse/complexLaguerreGaussianE.m197
-rw-r--r--transverse/decompose.m174
-rw-r--r--transverse/fitgaussianbeamrad.m19
-rw-r--r--transverse/hermitepoly.m18
-rw-r--r--transverse/overlap.m83
-rw-r--r--transverse/polarmesh.m92
-rw-r--r--transverse/recompose.m83
78 files changed, 6740 insertions, 0 deletions
diff --git a/axial/L_.m b/axial/L_.m
new file mode 100644
index 0000000..351af31
--- /dev/null
+++ b/axial/L_.m
@@ -0,0 +1,23 @@
+%---------------------------------------------------------------
+% Given the q-factor and wavelength of a beam, this function
+% returns the position and size of the waist.
+%
+% SYNTAX: [L <,w0>]=L_(q <,lambda>);
+% <...> indicates optional arguments
+%
+% q = q-factor of the beam at the position where R and w are to
+% be found. q can be a vector
+% lambda = wavelength. Can be a vector or scalar.
+%
+% If both q and lambda are vectors, they must be the same size.
+%
+%---------------------------------------------------------------
+% SYNTAX: [L <,w0>]=L_(q <,lambda>);
+%---------------------------------------------------------------
+
+function [L,w0]=L_(q,varargin);
+
+if nargin>=2, lambda=varargin{1}; else lambda=1064e-9; end
+
+w0=sqrt(-lambda/pi./imag(1./q));
+L=-real(q).*ones(size(w0)); \ No newline at end of file
diff --git a/axial/R_.m b/axial/R_.m
new file mode 100644
index 0000000..1691656
--- /dev/null
+++ b/axial/R_.m
@@ -0,0 +1,24 @@
+%---------------------------------------------------------------
+% Returns the phasefront radius of curvature and the beam width
+% given the q factor of a Gaussian beam and the wavelength.
+%
+% SYNTAX: [R <,w>]=R_(q <,lambda>);
+% <...> indicates optional arguments
+%
+% q = q-factor of the beam at the position where R and w are to
+% be found. q can be a vector
+% lambda = wavelength. Can be a vector or scalar.
+%
+% If both q and lambda are vectors, they must be the same size.
+% If w is requested as an output, lambda must be supplied.
+%
+%---------------------------------------------------------------
+% SYNTAX: [R <,w>]=R_(q,<,lambda>);
+%---------------------------------------------------------------
+
+function [Rout,wout]=R_(q,varargin)
+
+if nargin>=2, lambda=varargin{1}; else lambda=1064e-9; end
+
+wout=sqrt(lambda/pi .* imag(q).*(1+real(q).^2./imag(q).^2));
+Rout=real(q).*(1+imag(q).^2./real(q).^2).*ones(size(wout)); \ No newline at end of file
diff --git a/axial/beamplot.m b/axial/beamplot.m
new file mode 100644
index 0000000..5c3349d
--- /dev/null
+++ b/axial/beamplot.m
@@ -0,0 +1,81 @@
+% Accepts the q factor of a Gaussian beam and plots the 1/e^2 intensity envelope.
+%
+% SYNTAX: [handle,xend,yend]=beamplot(q,z,<,x,y,theta,n,lambda,...
+% attitudes,plotsuppress>);
+%
+% INPUT ARGUMENTS:
+% q = Gaussian beam complex radius of curvature "q".
+% If q is a vector, a beam is plotted for each element.
+% z = vector along beam axis over which to plot the envelope
+% x,y = position of the point at which q is specified, default=0,0.
+% theta = rotation of optic axis counterclockwise relative to x-axis,
+% defaul=0 (degrees)
+% n = index of medium in which the beam propagates
+% lambda = wavelength, default=1064 nm or 4.189e-5 inches
+% plotsuppress = set to 1 to suppress plotting, default 0.
+%
+% OUTPUT ARGUMENTS:
+% handle = handle of the trace plotted
+% xend,yend = position of the end of the optic axis over which the beam
+% was plotted.
+%
+% Last Modified: June 23, 2004 by Andri M. Gretarsson.
+%
+%--------------------------------------------------------------------------------
+% SYNTAX: [handle,xend,yend]=beamplot(q,z,<,x,y,theta,n,lambda,plotsuppress>);
+%--------------------------------------------------------------------------------
+
+function [handle,xend,yend]=beamplot(q,z,varargin)
+
+if nargin>=3, x=varargin{1}; else x=0; end
+if nargin>=4, y=varargin{2}; else y=0; end
+if nargin>=5, theta=varargin{3}*pi/180; else theta=0; end
+if nargin>=6, n=varargin{4}; else n=1; end
+if nargin>=7, lambda=varargin{5}; else lambda=1064e-9; end
+if nargin>=9, plotsuppress=varargin{7}; else plotsuppress=0; end
+
+if size(z,1)>size(z,2)
+ z=transpose(z);
+end
+if size(q,1)<size(q,2)
+ q=transpose(q);
+end
+lambda=lambda/n;
+w0=sqrt(imag(q).*lambda/pi);
+L=-real(q).*ones(size(w0));
+
+w_upper=zeros(length(L),length(z)); w_lower=w_upper; xend=zeros(length(L)); yend=xend;
+handle=zeros(2,length(L)); plotcolors=colormap;
+
+for s=1:length(L)
+ w_upper=w0(s)*sqrt(1+(lambda*(z-L(s))/pi/w0(s)^2).^2);
+ w_lower=w_upper;
+
+ upperenv=[z;w_upper];
+ lowerenv=[z;-w_lower];
+ rotmat=[[cos(theta), -sin(theta)];[sin(theta), cos(theta)]];
+ rotupperenv=rotmat*upperenv;
+ rotupperenv(1,:)=rotupperenv(1,:)+x;
+ rotupperenv(2,:)=rotupperenv(2,:)+y;
+ rotlowerenv=rotmat*lowerenv;
+ rotlowerenv(1,:)=rotlowerenv(1,:)+x;
+ rotlowerenv(2,:)=rotlowerenv(2,:)+y;
+
+ xend=max(z)*cos(theta)+x;
+ yend=max(z)*sin(theta)+y;
+
+ if plotsuppress~=1
+ if s==1,
+ orighold=get(gca,'nextplot');
+ handle(:,s)=plot(rotupperenv(1,:),rotupperenv(2,:),'b-',rotlowerenv(1,:),rotlowerenv(2,:),'b-');
+ set(handle(:,s),'color',plotcolors(mod(s,end)+1,:));
+ else
+ set(gca,'nextplot','add');
+ handle(:,s)=plot(rotupperenv(1,:),rotupperenv(2,:),'b-',rotlowerenv(1,:),rotlowerenv(2,:),'b-');
+ set(handle(:,s),'color',plotcolors(mod(s,end)+1,:));
+ end
+ if s==length(L)
+ set(gca,'nextplot',orighold);
+ end
+ end
+end \ No newline at end of file
diff --git a/axial/beamradius.m b/axial/beamradius.m
new file mode 100644
index 0000000..c5befc2
--- /dev/null
+++ b/axial/beamradius.m
@@ -0,0 +1,28 @@
+% Returns the field radius of the beam at any point z along a Gaussian beam
+%
+% SYNTAX: [w,R,zR]=beamradius([w0,z0,lambda],z);
+%
+% w0 = waist size
+% z0 = position of waist
+% lambda = wavelength
+%
+% w = spot size (field radius) at z
+% R = curvature of phasefront at z
+% zR = Raleigh length.
+%
+%-------------------------------------------------------------------
+% SYNTAX: [w,R,zR]=beamradius([w0,z0,lambda],z);
+%-------------------------------------------------------------------
+
+function [w,R,zR]=beamradius(params,z)
+
+w0=params(1); % beam (field) width at waist [meters]
+z0=params(2); % waist position [meters]
+lambda=params(3); % wavelength [meters]
+zR=pi*w0^2/lambda; % Raleigh length [meters]
+
+w=w0.*sqrt(1+((z-z0)/zR).^2); % beam width at z [meters]
+
+if nargout>=2
+ R=z.*(1+(zR./z).^2); % beam phasefront curvature at z
+end \ No newline at end of file
diff --git a/axial/cav.m b/axial/cav.m
new file mode 100644
index 0000000..9e2fe34
--- /dev/null
+++ b/axial/cav.m
@@ -0,0 +1,136 @@
+function [qrefl,qtrans,qcav,prefl,ptrans,pcav]=cav(qin,l,m,lambda,L,R1,R2,r1,r2,l1,l2,n_iter,varargin)
+% Propagates a Gaussian beam through a cavity.
+% The function returns the q-factors of the reflected beam, the transmitted
+% beam and the cavity beam at the first mirror. Also returns the reflected,
+% transmitted and intracavity field amplitudes. (Notation: prefl,ptrans,pcav
+% refer to the complex field amplitudes from each bounce, not power. Thus the
+% total transmitted power, for example, is Ptransmitted = epsilon0*abs(sum(ptrans))^2.
+%
+% AUTHOR: Andri M. Gretarsson, 2003.
+% LAST MODIFIED: 2007 by AMG.
+%
+% SYNTAX: [qrefl,qtrans,qcav,prefl,ptrans,pcav]=...
+% cav(qin,l,m,lambda,L,R1,R2,r1,r2,l1,l2,n_iter <,n,Lmirr,pin>);
+%
+% INPUT VARIABLES
+% ---------------
+% R1,R2 = Radii of curvature of the end mirrors. Positive if mirror is
+% concave as seen from inside the cavity, negative otherwise.
+% (Sides facing outwards are assumed to be flat.) R1 corresponds
+% to the input mirror and R2 to the end mirror.
+%
+% FIGURE:
+%
+% Input beam Input mirror End Mirror Transmitted beam
+% -----------------|(==============)|- - - - - - - - - - -
+% Cavity beam
+%
+% Note: Reflected beam is in same location as the Input beam but
+% travels in the opposite direction (away from the cavity).
+%
+% L = Cavity length
+% l,m = TEM_lm Gaussian mode incidnet on the cavity.
+% lambda = wavelength
+% qin = q of the incoming beam immediately before the input optic
+% outward facing side (assumed flat).
+% r1 = Reflectoin coefficient (fraction of field _amplitude_ reflected) of input mirror.
+% r2 = Reflection coefficient of end mirror.
+% l1 = Loss coefficient for a single pass through the input mirror.
+% (Fraction of field _amplitude_ lost.)
+% l2 = Loss coefficient for a single pass through the end mirror.
+% (Fraction of field _amplitude_ lost.)
+% n_iter = Number of iterations (cavity traversals) to calculate.
+% n = Optional: 1x3 vector of indices of ref. of: mirror substrates,
+% cavity medium, external medium.
+% Default is n=[1.46,1,1].
+% Lmirr = Optional: 1x2 vector of mirror thicknesses (on the optic
+% axis). First value corresponds to the input mirror, second to
+% the end mirror. Default: Lmirr=[0,0].
+% pin = Amplitude factor of the beam entering the cavity
+%
+% NOTES: In the current version, antireflective coatings on the outside
+% faces (flat faces) of the mirrors are assumed to be perfect. This could
+% be improved in future versions. Also, the reflectivity and transmissivity
+% of the coatings are assumed to be the same for light incident from
+% either the substrate side or cavity side of the coating. Clearly, this
+% could be improved also.
+%
+%--------------------------------------------------------------------------
+% SYNTAX: [qrefl,qtrans,qcav,prefl,ptrans,pcav]=...
+% cav(qin,l,m,lambda,L,R1,R2,r1,r2,l1,l2,n_iter <,n,Lmirr,pin>);
+%--------------------------------------------------------------------------
+
+if ( nargin>=13 && ~isempty(varargin{1}) ), n=varargin{1}; else n=[1.46,1,1]; end
+if ( nargin>=14 && ~isempty(varargin{2}) ), Lmirr=varargin{2}; else Lmirr=[0,0]; end
+if ( nargin>=15 && ~isempty(varargin{3}) ), pin=varargin{3}; else pin=1; end
+
+nsubs=n(1);
+ncav=n(2);
+noutside=n(3);
+L1=Lmirr(1);
+L2=Lmirr(2);
+
+% Variable initialization
+t1 = sqrt(1-r1^2-l1^2);
+t2 = sqrt(1-r2^2-l2^2);
+qrefl = zeros(n_iter,1); qcav = zeros(n_iter,1); qtrans = zeros(n_iter,1);
+prefl = zeros(n_iter,1); pcav = zeros(n_iter,1); ptrans = zeros(n_iter,1);
+% #cav -> immediately inside input mirror travelling towards end mirror
+% #refl -> immediately outside input mirror (outside cavity) travelling towards laser
+% #trans-> immediately outside end mirror (outside cavity) travelling away from cavity
+
+% Note the poor notation for field amplitudes throughout: prefl, pcav,
+% etc. The letter p does NOT mean power in this case!
+
+% Commonly used quantitites
+freeL = free(L,ncav);
+freeL1 = free(L1,nsubs);
+freeL2 = free(L2,nsubs);
+mirrR1 = mirr(R1); % input mirror
+mirrR2 = mirr(R2); % end mirror
+% mirrR1phase=exp(i*2*pi*(nsubs*L1/lambda-floor(nsubs*L1/lambda)));
+% mirrR2phase=exp(i*2*pi*(nsubs*L2/lambda-floor(nsubs*L2/lambda)));
+% tripphase=exp(i*2*pi*(ncav*L/lambda-floor(ncav*L/lambda)));
+mirrR1phase=exp(i*2*pi*(nsubs*L1/lambda));
+mirrR2phase=exp(i*2*pi*(nsubs*L2/lambda));
+tripphase=exp(i*2*pi*(ncav*L/lambda));
+
+% Prompt reflection
+[qrefl(1),prefl(1)]= prop(qin,...
+ fdie(nsubs,noutside)*freeL1*mirr(-R1)*freeL1*fdie(noutside,nsubs),...
+ [l,m],-r1*mirrR1phase^2*pin);
+
+qcav(1)=i*1; pcav(1)=0;
+qtrans(1)=i*1; pcav(1)=0;
+
+% First entry into cavity
+[qcav(2),pcav(2)] = prop(qin,...
+ sdie(-R1,nsubs,ncav)*freeL1*fdie(noutside,nsubs),...
+ [l,m],t1*mirrR1phase*pin);
+
+% First transmission through end mirror
+[qtrans(2),ptrans(2)] = prop(qcav(2),...
+ fdie(nsubs,noutside)*freeL2*sdie(R2,ncav,nsubs)*freeL,...
+ [l,m],t2*tripphase*mirrR2phase*pcav(2));
+
+% First round trip leakage through input mirror
+[qrefl(2),prefl(2)] = prop(qcav(2),...
+ fdie(nsubs,noutside)*freeL1*sdie(R1,ncav,nsubs)*freeL*mirrR2*freeL,...
+ [l,m],t1*r2*mirrR1phase*tripphase^2*pcav(2));
+
+for s = 3:n_iter+2
+
+ [qcav(s),pcav(s)] = prop(qcav(s-1),...
+ mirrR1*freeL*mirrR2*freeL,...
+ [l,m],r1*r2*tripphase^2*pcav(s-1));
+
+ [qtrans(s),ptrans(s)] = prop(qcav(s),...
+ fdie(nsubs,noutside)*freeL2*sdie(R2,ncav,nsubs)*freeL,...
+ [l,m], t2*tripphase*mirrR2phase*pcav(s));
+
+ [qrefl(s),prefl(s)] = prop(qcav(s),...
+ fdie(nsubs,noutside)*freeL1*sdie(R1,ncav,nsubs)*freeL*mirrR2*freeL,...
+ [l,m],t1*r2*mirrR1phase*tripphase^2*pcav(s));
+
+
+end
diff --git a/axial/elems.m b/axial/elems.m
new file mode 100644
index 0000000..3de81ef
--- /dev/null
+++ b/axial/elems.m
@@ -0,0 +1,12 @@
+%----------------------------------------------------------------
+% Returns the elements of the ABCD matrix supplied.
+%
+% SYNTAX: [A,B,C,D]=elems(abcd);
+%----------------------------------------------------------------
+
+function [A,B,C,D]=elems(abcd)
+
+A=abcd(1,1);
+B=abcd(1,2);
+C=abcd(2,1);
+D=abcd(2,2); \ No newline at end of file
diff --git a/axial/fdie.m b/axial/fdie.m
new file mode 100644
index 0000000..e36475d
--- /dev/null
+++ b/axial/fdie.m
@@ -0,0 +1,22 @@
+%----------------------------------------------------------------
+% Returns the ABCD matrix for propagation through a flat
+% dielectric interface.
+%
+% SYNTAX: abcd=fdie(n1,n2);
+%
+% n1 = index of refraction of material being left
+% n2 = index of refraction of material being entered
+%
+% abcd = | 1 0 |
+% | 0 n1/n2 |
+%
+%----------------------------------------------------------------
+% SYNTAX: abcd=fdie(n1,n2);
+%----------------------------------------------------------------
+
+function abcd=fdie(n1,n2)
+
+abcd=[
+ 1 0
+ 0 n1/n2
+]; \ No newline at end of file
diff --git a/axial/free.m b/axial/free.m
new file mode 100644
index 0000000..68f9beb
--- /dev/null
+++ b/axial/free.m
@@ -0,0 +1,22 @@
+%---------------------------------------------------------------
+% Returns the ABCD matrix for free space propagation.
+%
+% SYNTAX: abcd=free(L);
+% <...> indicates optional argument
+%
+% L = distance to propagate.
+% n = index of refraction. Default is 1.
+%
+% abcd = |1 L|
+% |0 1 |
+%
+%---------------------------------------------------------------
+% SYNTAX: abcd=free(L);
+%---------------------------------------------------------------
+
+function abcd=free(L,varargin)
+
+abcd=[
+ 1 L
+ 0 1
+];
diff --git a/axial/lens.m b/axial/lens.m
new file mode 100644
index 0000000..a75b2f4
--- /dev/null
+++ b/axial/lens.m
@@ -0,0 +1,21 @@
+%---------------------------------------------------------------
+% Returns the ABCD matrix for propagation through a thin lens.
+%
+% SYNTAX: abcd=lens(f);
+%
+%
+% f = lens focal length
+%
+% abcd = | 1 0 |
+% |-1/f 1 |
+%
+%---------------------------------------------------------------
+% SYNTAX: abcd=lens(f);
+%---------------------------------------------------------------
+
+function abcd=lens(f)
+
+abcd=[
+ 1 0
+ -1/f 1
+]; \ No newline at end of file
diff --git a/axial/lensplot.m b/axial/lensplot.m
new file mode 100644
index 0000000..a8f438d
--- /dev/null
+++ b/axial/lensplot.m
@@ -0,0 +1,116 @@
+%------------------------------------------------------------------------
+% Draws a representation of a lens at the position and angle specified.
+%
+% SYNTAX: [handle,texthandle,pos,rotpos]
+% =lensplot(d <,t,x,y,theta,lambda,label,labelpos,suppress>);
+%
+% INPUT ARGUMENTS:
+% d = diameter of the lens. The lens radius of curvature is assumed
+% to be essentially infinite (1e30).
+% d can also be passed as a 2-element vector d=[diameter,radius],
+% where the first element is the lens diameter and the second
+% is the radius of curvature of the lens surface.
+% t = additional lens thickness (same units as the diameter)
+% x,y = x,y - position offset, default=0,0.
+% theta = rotation of optic axis counterclockwise relative to x-axis,
+% defaul=0
+% lambda = wavelength, default=1064 nm
+% label = string with which to label the lens, default is ''.
+% labelpos = 0 to put label at bottom, 1 to put label at top, default 0
+% suppress = set to 1 to suppress plotting, default 0.
+%
+% OUTPUT ARGUMENTS:
+% handle = handle of the trace plotted
+% texthandle= handle of the text label if supplied (otherwise -1)
+% pos = 2xn matrix. Second row is lens face height, first row is
+% the corresponding position along the optic axis, measured
+% from the point at which q is specified.
+% rotpos = 2xn matrix. x,y coordinates of the lens trace,
+% first row corresponds to x coord's, second row to y coord's.
+%
+% Last Modified: Dec. 10, 2003 by Andri M. Gretarsson.
+%
+%-------------------------------------------------------------------------
+% SYNTAX: [handle,texthandle,pos,rotpos]
+% =lensplot(d <,t,x,y,theta,lambda,label,labelpos,suppress>);
+%-------------------------------------------------------------------------
+
+function [handle,texthandle]=lensplot(d,varargin)
+
+if size(d,2)>1, Rlens=d(2); else Rlens=1e30; end
+if nargin>=2, t=varargin{1}; else t=0; end
+if nargin>=3, x=varargin{2}; else x=0; end
+if nargin>=4, y=varargin{3}; else y=0; end
+if nargin>=5, theta=varargin{4}*pi/180; else theta=0; end
+if nargin>=6, lambda=varargin{5}; else lambda=1064e-9; end
+if nargin>=7, label=varargin{6}; else label=''; end
+if nargin>=8, labelpos=varargin{7}; else labelpos=0; end
+if nargin>=9, suppress=varargin{8}; else suppress=0; end
+
+lensheight=d(1)/2;
+phimax=asin(lensheight/Rlens);
+phi=-phimax:phimax/100:phimax;
+if Rlens>=0
+ curvethickness=abs(Rlens-Rlens*cos(phimax));
+ xleftside=Rlens*(cos(phimax)-cos(phi))+curvethickness;
+ xrightside=-Rlens*(cos(phimax)-cos(phi))+curvethickness+t;
+ xtop=[max(xleftside),min(xrightside)];
+ xbottom=[max(xleftside),min(xrightside)];
+ xcenter=t/2+curvethickness;
+else
+ curvethickness=abs(Rlens-Rlens*cos(phimax));
+ xleftside=Rlens*(cos(phimax)-cos(phi));
+ xrightside=-Rlens*(cos(phimax)-cos(phi))+t+2*curvethickness;
+ xtop=[min(xleftside),max(xrightside)];
+ xbottom=[min(xleftside),max(xrightside)];
+ xcenter=curvethickness+t/2;
+end
+yleftside=Rlens*sin(phi);
+yrightside=yleftside;
+
+rightside=[xrightside;yrightside];
+leftside=[xleftside;yleftside];
+top=[xtop;[max(yleftside),max(yrightside)]];
+bottom=[xbottom;[min(yleftside),min(yrightside)]];
+
+rotmat=[[cos(theta), -sin(theta)];[sin(theta), cos(theta)]];
+rotrightside=rotmat*(rightside-[ones(size(rightside(1,:)))*xcenter;zeros(size(rightside(2,:)))]);
+rotleftside=rotmat*(leftside-[ones(size(rightside(1,:)))*xcenter;zeros(size(rightside(2,:)))]);
+rottop=rotmat*(top-[ones(size(top(1,:)))*xcenter;zeros(size(top(2,:)))]);
+rotbottom=rotmat*(bottom-[ones(size(bottom(1,:)))*xcenter;zeros(size(bottom(2,:)))]);
+
+rotrightside(1,:)=rotrightside(1,:)+x+xcenter;
+rotrightside(2,:)=rotrightside(2,:)+y;
+rotleftside(1,:)=rotleftside(1,:)+x+xcenter;
+rotleftside(2,:)=rotleftside(2,:)+y;
+rottop(1,:)=rottop(1,:)+x+xcenter;
+rottop(2,:)=rottop(2,:)+y;
+rotbottom(1,:)=rotbottom(1,:)+x+xcenter;
+rotbottom(2,:)=rotbottom(2,:)+y;
+
+switch labelpos
+case 2,
+ augmentedlabel=[' ',label];
+ xtextpos=max(rotrightside(1,:));
+ ytextpos=( min(rotrightside(2,:)) + max(rotrightside(2,:)) )/2;
+case 0,
+ augmentedlabel=strvcat(' ',label); %#ok<VCAT>
+ xtextpos=max(rotrightside(1,:));
+ ytextpos=min(rotrightside(2,:));
+case 1,
+ augmentedlabel=strvcat(label,' '); %#ok<VCAT>
+ xtextpos=max(rotrightside(1,:));
+ ytextpos=max(rotrightside(2,:));
+end
+
+if suppress~=1
+ handle=plot(rotrightside(1,:),rotrightside(2,:),'k-',...
+ rotleftside(1,:),rotleftside(2,:),'k-',...
+ rottop(1,:),rottop(2,:),'k-',...
+ rotbottom(1,:),rotbottom(2,:),'k-');
+ if ~isempty(label)
+ texthandle=text(xtextpos,ytextpos,augmentedlabel);
+ else
+ texthandle=-1;
+ end
+end \ No newline at end of file
diff --git a/axial/mirr.m b/axial/mirr.m
new file mode 100644
index 0000000..35d7a92
--- /dev/null
+++ b/axial/mirr.m
@@ -0,0 +1,21 @@
+%----------------------------------------------------------------
+% Returns the ABCD matrix for reflection from a spherical mirror.
+%
+% SYNTAX: abcd=mirr(R);
+% <...> indicates optional argument
+%
+% R = mirror radius of curvature
+%
+% abcd = | 1 0 |
+% |-2/R 1 |
+%
+%----------------------------------------------------------------
+% SYNTAX: abcd=mirr(R);
+%----------------------------------------------------------------
+
+function abcd=mirr(R)
+
+abcd=[
+ 1 0
+ -2/R 1
+]; \ No newline at end of file
diff --git a/axial/prop.m b/axial/prop.m
new file mode 100644
index 0000000..1c7dd15
--- /dev/null
+++ b/axial/prop.m
@@ -0,0 +1,32 @@
+function [q,p]=prop(q1,abcd,varargin)
+% Propagates a Gaussian beam. [q,p]=prop(q1,abcd <,[l,m],p1>);
+%--------------------------------------------------------------------
+% Propagates a Gaussian beam with complex radius of curvature q1
+% and amplitude factor p1 (optional), according to the ABCD matrix
+% supplied.
+%
+% Returns the new complex beam radius q=(A*q1+B)/(C*q1+D) and the
+% new amplitude factor p = 1/(A+B/q1)^(1+l+m) by which the field is
+% multiplied. (See eqn 4.7.30 in Principles of Lasers by O. Svelto.)
+% If q1 is a vector q and p will be vectors of the same size.
+%
+% For a Hermite Gaussian l,m are the mode designators.
+% For a Laguerre Gaussian l=2p and m is the usual m.
+%
+% SYNTAX: [q,p]=prop(q1,abcd <,[l,m],p1>);
+% <...> indicates optional arguments
+%--------------------------------------------------------------------
+
+if ( nargin>=3 && ~isempty(varargin{1}) ), mode=varargin{1}; else mode=[0,0]; end
+if nargin>=4, p1=varargin{2}; else p1=ones(size(q1)); end
+
+A=abcd(1,1);
+B=abcd(1,2);
+C=abcd(2,1);
+D=abcd(2,2);
+
+ell=mode(1);
+emm=mode(2);
+
+q = (A*q1 + B)./(C*q1 + D);
+p = p1.*exp(i*angle(1./(A+B./q1).^(1+ell+emm))); \ No newline at end of file
diff --git a/axial/prop2.m b/axial/prop2.m
new file mode 100644
index 0000000..eaa4db6
--- /dev/null
+++ b/axial/prop2.m
@@ -0,0 +1,27 @@
+%--------------------------------------------------------------------
+% Propagates a Gaussian beam with complex radius of curvature q1
+% using the ABCD parameters supplied. Returns the new q and the
+% new amplitude factor p = 1/(A+B/q1)^(1+l+m) by which the field is
+% multiplied. (See eqn 4.7.30 in Principles of Lasers by O. Svelto.)
+% If q1 is a vector or matrix, q and p will be vectors or matrixes
+% of the same size. If the ABCD parameters are vectors or matrixes
+% (while q1 is a scalar) then q an d p will be vectors or matrixes
+% of the same size. This last feature is the main difference
+% between this function and "prop.m".
+%
+% For a Hermite Gaussian l,m are the mode designators.
+% For a Laguerre Gaussian l=2p and m is the usual m.
+%
+% SYNTAX: [q,p]=prop2(q1,A,B,C,D,<,[l,m]>);
+% <...> indicates optional arguments
+%--------------------------------------------------------------------
+
+function [q,p]=prop2(q1,A,B,C,D,varargin)
+
+if nargin>=6, mode=varargin{1}; else mode=[0,0]; end
+
+ell=mode(1);
+emm=mode(2);
+
+q = (A*q1 + B)./(C*q1 + D);
+p = 1./(A+B./q1).^(1+ell+emm); \ No newline at end of file
diff --git a/axial/q_.m b/axial/q_.m
new file mode 100644
index 0000000..be678d4
--- /dev/null
+++ b/axial/q_.m
@@ -0,0 +1,29 @@
+%---------------------------------------------------------------
+% Returns the q-factor of a Gaussian beam given the spot size,
+% phasefront radius of curvature and wavelength.
+%
+% SYNTAX: qfactor=q_(w,R <,lambda>);
+%
+% w = 1/e Field radius
+% R = Radius of curvature of phasefront
+% lambda = wavelength
+%
+% Any one of w, R and lambda may be a vectors or scalars.
+% If more than one of w, R and lambda is a vector, all
+% vectors supplied must be the same size. w, R and lambda must
+% all be in the same units.
+%
+%--------------------------------------------------------------
+% SYNTAX: qfactor=q_(w,R <,lambda>);
+%--------------------------------------------------------------
+
+function qfactor=q_(w,R,varargin)
+
+if nargin>=3, lambda=varargin{1}; else lambda=1064e-9; end
+
+
+if R~=Inf
+ qfactor=pi*w.^2.*R./(pi*w.^2-1i.*R.*lambda);
+else
+ qfactor=1i*pi*w.^2./lambda;
+end \ No newline at end of file
diff --git a/axial/sdie.m b/axial/sdie.m
new file mode 100644
index 0000000..17f5235
--- /dev/null
+++ b/axial/sdie.m
@@ -0,0 +1,25 @@
+%----------------------------------------------------------------
+% Returns the ABCD matrix for propagation througe a spherical
+% dielectric interface.
+%
+% SYNTAX: abcd=sdie(R,n1,n2);
+%
+% R = Interface radius of curvature. R is positive when the
+% the interface curves toward the direction from which
+% the beam comes, negative otherwise.
+% n1 = index of refraction of material being left
+% n2 = index of refraction of material being entered
+%
+% abcd = | 1 0 |
+% | -(n1-n2)/n2/R n1/n2 |
+%
+%----------------------------------------------------------------
+% SYNTAX: abcd=sdie(R,n1,n2);
+%----------------------------------------------------------------
+
+function abcd=sdie(R,n1,n2)
+
+abcd=[
+ 1 0
+ -(n1-n2)/n2/R n1/n2
+]; \ No newline at end of file
diff --git a/axial/slab.m b/axial/slab.m
new file mode 100644
index 0000000..8fd067a
--- /dev/null
+++ b/axial/slab.m
@@ -0,0 +1,17 @@
+function abcd=slab(n1,n2,L)
+% Returns the ABCD matrix for propagation through a slab (window)
+%----------------------------------------------------------------
+% Returns the ABCD matrix for propagation through a slab (window)
+% with index of refraction n2. Index of external medium is n1.
+%
+% SYNTAX: abcd=slab(n1,n2,L);
+%
+% n1 = index of refraction of external material
+% n2 = index of refraction of slab material
+% L = Thickness of slab
+%
+%----------------------------------------------------------------
+% SYNTAX: abcd=fdie(n1,n2,L);
+%----------------------------------------------------------------
+
+abcd=fdie(n2,n1)*free(L,n2)*fdie(n1,n2); \ No newline at end of file
diff --git a/axial/w0_.m b/axial/w0_.m
new file mode 100644
index 0000000..9c1003f
--- /dev/null
+++ b/axial/w0_.m
@@ -0,0 +1,22 @@
+%---------------------------------------------------------------
+% Given the q-factor and wavelength of a beam, this function
+% returns the size of the waist assuming free space
+% propagation.
+%
+% SYNTAX: w0=w0_(q <,lambda>);
+%
+% q = q-factor of the beam at the position where R and w are to
+% be found. q can be a vector
+% lambda = wavelength. Can be a vector or scalar.
+%
+% If both q and lambda are vectors, they must be the same size.
+%
+%---------------------------------------------------------------
+% SYNTAX: w0=w0_(q <,lambda>);
+%---------------------------------------------------------------
+
+function w0=w0_(q ,varargin);
+
+if nargin>=2, lambda=varargin{1}; else lambda=1064e-9; end
+
+w0=sqrt(imag(q).*lambda/pi);
diff --git a/axial/w_.m b/axial/w_.m
new file mode 100644
index 0000000..6d4a2d4
--- /dev/null
+++ b/axial/w_.m
@@ -0,0 +1,23 @@
+%---------------------------------------------------------------
+% Returns the beam width given the q factor and wavelength
+% of a Gaussian beam. Note that q and lambda are assumed
+% to have the same units.
+%
+% SYNTAX: w=w_(q <,lambda>);
+%
+% q = q-factor of the beam at the position where R and w are to
+% be found. q can be a vector
+% lambda = wavelength. Can be a vector or scalar.
+%
+% If both q and lambda are vectors, they must be the same size.
+%
+%---------------------------------------------------------------
+% SYNTAX: w=w_(q <,lambda>);
+%---------------------------------------------------------------
+
+function wout=w_(q,varargin)
+
+if nargin>=2, lambda=varargin{1}; else lambda=1064e-9; end
+
+wout=sqrt(lambda/pi .* imag(q).*(1+real(q).^2./imag(q).^2));
+
diff --git a/coatings/coatingRT.m b/coatings/coatingRT.m
new file mode 100644
index 0000000..915e82b
--- /dev/null
+++ b/coatings/coatingRT.m
@@ -0,0 +1,229 @@
+% Coating reflectivity and transmittivity.
+%--------------------------------------------------------------------------
+%
+% Front end code for "multidiel.m" by Orfanidis.
+%
+% Returns the reflectivity (fractional reflected power) and transmittivity
+% (fractional transmitted power) of a periodic, multilayer dielectric
+% coating as a function of the coating parameters and input beam properties
+% (incident wavelength, polarization, angle of incidence, etc.)
+%
+% To use coatingRT.m, the function multidiel.m by Orfanidis must be in your
+% matlab path. The function multidiel.m is available on the mathworks website
+% in the package ewa.zip from Orfanidis:
+% http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=4456
+%
+% AUTHOR: Andri M. Gretarsson, 6/2007.
+% LAST UPDATED: 7/2009 by AMG
+%
+% SYNTAX: [R,T,anginc] = coatingRT(nH,nL,N,lambda,lambda0,pol,...
+% <nreflecs,Lprotect,nprotect,nb,anginc,LH,LL>)
+%
+% OR (if the first two arg's are vectors):
+%
+% SYNTAX: [R,T,anginc] = coatingRT(n,L,[],lambda,lambda0,pol,...
+% <nreflecs,Lprotect,nprotect,nb,anginc>)
+%
+% where n is a vector of [incident medium index, the coating layer indices of refraction, substrate index]
+% and L is a vector of length length(n)-2 containing the coating layer OPTICAL thicknesses
+% (in units of lambda0). In other words the arguments are in the same format as the first two argument
+% of multidiel.m
+%
+% INPUT VARIABLES
+% ---------------
+% nH = index of refraction of the high-index coating layers (e.g. Ta2O5) OR vector
+% of layer indices
+% nL = index of refraction of the high-index coating layers (e.g. SiO2) OR vector
+% of layer OPTICAL thicknesses
+% N = number of coating layer pairs
+% lambda = (1xN vector) incident wavelength in nanometers. This is the wavelength
+% of the light that is actually hitting the coating. Note: Units are
+% nanometers.
+% lambda0 = center wavelength in nm. This is the wavelength of
+% light in terms of which the layer thicknesses are specified. For
+% a high-reflective coating with quarter-wave layers, the center
+% wavelength is usually also the wavelength of maximum reflectivity. (Hence
+% the term "center wavelength.") Note: Units are nanometers.
+% pol = polarization of the incident light, should be 'te' for
+% s-polarization or 'tm' for p-polarization. ('te' stands for
+% "transverse-electric." In other words, the electric field is
+% transverse to the plane of incidence.) It's also OK to specify 'p' or
+% 's' as these are translated to 'tm' and 'te' respectively.
+% nreflecs = This should usually be 0. Setting this to a higher number
+% causes the function to add in that number of _secondary_
+% reflections from the back surface of the sample (assumed to be
+% uncoated).
+% Lprotect = OPTICAL thickness (in terms of lambda0) of any protective coating layer laid
+% down on top of the coating. Usually, the topmost periodic layer
+% is a low index layer (usually SiO2). However, the topmost layer is
+% usually a diffeent thickness layer (e.g. 1/2 wavelength thick) rather than a 1/4
+% wavelength layer like the others.
+% This is accounted for in this code by setting Lprotect to 1/4,
+% and nprotect=nL. In other words the 1/2 wavelength topmost
+% layer is constructed as two 1/4 wavelength layers (the periodic
+% layer and the protective layer) each with the same index of
+% refraction. And these are indeed the default values for Lprotect
+% and nprotect. Default: Lprotect=1/4.
+% nprotect = Index of refraction of any additional coating layer laid down
+% to protect the periodic coating. Default: nprotect=nL.
+% nb = Index of refraction of the substrate. Default: nb=1.46 (silica).
+% anginc = 1xM vector of incidence angles in radians. Default is 500
+% evenly spaced angles between zero and pi/2.
+% LH = OPTICAL thickness in terms of lambda0 of the high index layers if not 1/4.
+% Default: LH=1/4.
+% LL = OPTICAL thickness in terms of lambda0 of the low index layers if not 1/4.
+% Default: LL=1/4.
+%
+% OUTPUT VARIABLES
+% ----------------
+% R, T = MxN matrix of Reflectivity and Transmissivity (fractional reflected or
+% transmitted _power_). R and T are vectors of size(anginc).
+% lambda_mesh = This is the lambda mesh needed to plot R or T as a surface
+% anginc_mesh = This is the anginc mesh needed to plot R or T as a surface
+% r = The amplitude reflectance (R = r x r*).
+%
+%
+% EXAMPLE 1 (R as a function of incident angle and wavelength)
+% ---------
+% lambda = [199:3:1201]*1e-9;
+% lambda0 = 1064e-9;
+% anginc = [0:0.5:90]*pi/180;
+% [R,T,lambda_mesh,anginc_mesh,r] = coatingRT(2.02,1.46,15,lambda,lambda0,'tm',...
+% 0,0,0,1.46,anginc);
+% h=pcolor(lambda_mesh*1e9,anginc_mesh*180/pi,R);
+% set(h,'edgecolor','none');
+% colorbar;
+% caxis([0 1]);
+%
+%
+% EXAMPLE 2 (R as a function of incident angle at lambda=900 nm)
+% ---------
+% lambda = 900e-9;
+% lambda0 = 1064e-9;
+% anginc = [0:0.1:90]*pi/180;
+% [R,T,lambda,anginc,r] = coatingRT(2.02,1.46,15,lambda,lambda0,'tm',...
+% 0,0,0,1.46,anginc);
+% plot(anginc*180/pi,R);
+%
+%
+% EXAMPLE 3 (R as a function of wavelength at an incident angle of 70 degrees)
+% ---------
+% lambda_in = [500:0.1:1300]*1e-9;
+% lambda0 = 1064e-9;
+% anginc_in = 70*pi/180;
+% [Rp,Tp,lambda,anginc] = coatingRT(2.02,1.46,15,lambda_in,lambda0,'tm',...
+% 0,0,0,1.46,anginc_in);
+% [Rs,Ts,lambda,anginc,r] = coatingRT(2.02,1.46,15,lambda_in,lambda0,'te',...
+% 0,0,0,1.46,anginc_in);
+% plot(lambda*1e9,Rp,lambda*1e9,Rs);
+% axis([500 1300 0 1.1]);
+%
+%
+% EXAMPLE 4 (R as a function of wavelength at normal incidence with an succession of irregular coatings)
+% ---------
+% for s=1:25
+% n=[1,repmat([2.0+0.2*rand(1,1),1.5+0.2*rand(1,1)],1,15),1.46];
+% L=0.25+[0.1*rand(1,30)];
+% lambda_in = [500:0.1:1300]*1e-9;
+% lambda0 = 900e-9;
+% anginc_in = 0;
+% [Rp,Tp,lambda,anginc] = coatingRT(n,L,[],lambda_in,lambda0,'tm',5,[],[],[],anginc_in);
+% plot(lambda*1e9,Rp);
+% axis([500 1300 0 1.1]);
+% drawnow
+% pause(0.1)
+% end
+%
+% % EXAMPLE 5 (R from a simple uncoated glass surface as a function of incident angle at lambda=632 nm)
+% ---------
+% lambda = 632e-9;
+% lambda0 = 1064e-9;
+% anginc = [0:0.1:90]*pi/180;
+% [R,T,lambda,anginc,r] = coatingRT([1 1.5],[],[],lambda,lambda0,'p',...
+% [],[],[],[],anginc);
+% plot(anginc*180/pi,R); set(gca,'xlim',[0 90]); shg;
+%
+%--------------------------------------------------------------------------
+% SYNTAX: [R,T,lambda_mesh,anginc_mesh,r] = coatingRT(nH,nL,N,lambda,...
+% lambda0,pol <,nreflecs,Lprotect,nprotect,nb,anginc,LH,LL>)
+%--------------------------------------------------------------------------
+
+
+function [R,T,lambda_mesh,anginc_mesh,r] = coatingRT(nH,nL,N,lambda,lambda0,pol,varargin)
+
+m=6; n=1;
+if nargin>=m+n, nreflecs=varargin{n}; else nreflecs=0; end; n=n+1;
+if nargin>=m+n, Lprotect=varargin{n}; else Lprotect=0; end; n=n+1;
+if nargin>=m+n, nprotect=varargin{n}; else nprotect=nL; end; n=n+1;
+if nargin>=m+n, nb=varargin{n}; else nb=1.46; end; n=n+1;
+if nargin>=m+n, anginc=varargin{n}; else anginc=linspace(0,90,500)*pi/180; end; n=n+1;
+if nargin>=m+n, LH=varargin{n}; else LH=1/4; end; n=n+1; % OPTICAL thicknesses of the layers in units of lambda0,
+if nargin>=m+n, LL=varargin{n}; else LL=1/4; end; n=n+1; % where lambda0 is the design wavelength in units of nm
+
+na = 1; % refractive index of medium outside the sample (usually air or vacuum);
+
+if strcmp(pol,'p')|strcmp(pol,'P')
+ pol='tm';
+elseif strcmp(pol,'s')|strcmp(pol,'S')
+ pol='te';
+elseif strcmp(pol,'tm')|strcmp(pol,'te')
+else
+ error('Polarization string was not understood. Should be ''te'' or ''tm''.');
+end
+
+if length(nH)>1
+ n_in=nH;
+ n_out=reverse(n_in);
+ L_in=nL;
+ L_out=reverse(L_in);
+ na=n_in(1);
+ nb=n_in(end);
+else
+ coating=repmat([nL,nH], 1, N);
+ L_in = (coating==nL)*LL + (coating==nH)*LH; % lengths of the layers in order as seen entering sample
+ if Lprotect~=0;
+ L_in=[Lprotect,L_in];
+ coating=[nprotect,coating];
+ end
+ L_out= reverse(L_in); % lengths of the layers in order as seen exiting sample
+ n_in = [na,coating,nb]; % indices for the layers in order as seen entering sample
+ n_out = reverse(n_in); % indices for the layers in order as seen exiting sample
+end
+
+angincg=asin(na*sin(anginc)/nb); %Snell's law
+r_in=zeros(length(anginc),length(lambda));
+r_out=zeros(length(anginc),length(lambda));
+R_in=zeros(length(anginc),length(lambda));
+R_out=zeros(length(anginc),length(lambda));
+R_g=zeros(length(anginc),1); %Fresnel Eqn's don't depend on lambda explicitly, so neither does R_g
+R=zeros(length(anginc),length(lambda));
+[r_gs r_gp]=fresnel(nb,na,angincg*180/pi); % nb is the "left hand" medium in the call to fresnel because the beam is inside the sample
+R_gs=r_gs.*conj(r_gs);
+R_gp=r_gp.*conj(r_gp);
+
+
+for s=1:length(anginc)
+ r_in(s,:)=multidiel(n_in,L_in,lambda/lambda0,anginc(s)*180/pi,pol);
+ r_out(s,:)=multidiel(n_out,L_out,lambda/lambda0,angincg(s)*180/pi,pol);
+ R_in(s,:)=(r_in(s,:).*conj(r_in(s,:)));
+ R_out(s,:)=(r_out(s,:).*conj(r_out(s,:)));
+ if strcmp(pol,'te'), R_g(s)=R_gs(s); else R_g(s)=R_gp(s); end
+ if strcmp(pol,'te'), r_g(s)=r_gs(s); else r_g(s)=r_gp(s); end
+ if nreflecs~=0
+ k=R_out(s,:)*R_g(s);
+ % next line is sum from 0 to nreflecs internally reflecting light beams
+ % NOTE: nreflecs = 2 is equivalent the having 3 beams in total reflected
+ % from the sample (primary reflection + 2 secondary reflections).
+ R(s,:)=R_in(s,:) + ( 1-R_in(s,:) ) * R_g(s) .* (1-k.^nreflecs)./( 1-k ) .* ( 1-R_out(s,:) );
+ if nargout==5,
+ warning('The amplitude reflection coefficient, r, does not include the effect of internal bounces. (Not yet implemented).');
+ end
+ r(s,:)=r_in(s,:);
+ else
+ R(s,:)=R_in(s,:);
+ r(s,:)=r_in(s,:);
+ end
+end
+
+T=1-R;
+[lambda_mesh,anginc_mesh]=meshgrid(lambda,anginc);
diff --git a/coatings/coatingRTnew.m b/coatings/coatingRTnew.m
new file mode 100644
index 0000000..4ce14ef
--- /dev/null
+++ b/coatings/coatingRTnew.m
@@ -0,0 +1,225 @@
+% Coating reflectivity and transmittivity.
+%--------------------------------------------------------------------------
+%
+% Front end code for "multidiel.m" by Orfanidis.
+%
+% Returns the reflectivity (fractional reflected power) and transmittivity
+% (fractional transmitted power) of a periodic, multilayer dielectric
+% coating as a function of the coating parameters and input beam properties
+% (incident wavelength, polarization, angle of incidence, etc.)
+%
+% To use coatingRT.m, the function multidiel.m by Orfanidis must be in your
+% matlab path. The function multidiel.m is available on the mathworks website
+% in the package ewa.zip from Orfanidis:
+% http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=4456
+%
+% AUTHOR: Andri M. Gretarsson, 6/2007.
+% LAST UPDATED: 7/2009 by AMG
+%
+% SYNTAX: [R,T,anginc] = coatingRT(nH,nL,N,lambda,lambda0,pol,...
+% <nreflecs,Lprotect,nprotect,nb,anginc,LH,LL>)
+%
+% OR (if the first two arg's are vectors):
+%
+% SYNTAX: [R,T,anginc] = coatingRT(n,L,[],lambda,lambda0,pol,...
+% <nreflecs,Lprotect,nprotect,nb,anginc>)
+%
+% where n is a vector of [incident medium index, the coating layer indices of refraction, substrate index]
+% and L is a vector of length length(n)-2 containing the coating layer OPTICAL thicknesses
+% (in units of lambda0). In other words the arguments are in the same format as the first two argument
+% of multidiel.m
+%
+% INPUT VARIABLES
+% ---------------
+% nH = index of refraction of the high-index coating layers (e.g. Ta2O5) OR vector
+% of layer indices
+% nL = index of refraction of the high-index coating layers (e.g. SiO2) OR vector
+% of physical layer thicknesses
+% N = number of coating layers
+% lambda = (1xN vector) incident wavelength in nanometers. This is the wavelength
+% of the light that is actually hitting the coating. Note: Units
+% must be the same as those specifying the layer thicknesses (e.g. either
+% meters or nanometers but not a mixture of the two!)
+% pol = polarization of the incident light, should be 'te' for
+% s-polarization or 'tm' for p-polarization. ('te' stands for
+% "transverse-electric." In other words, the electric field is
+% transverse to the plane of incidence.) It's also OK to specify 'p' or
+% 's' as these are translated to 'tm' and 'te' respectively.
+% nreflecs = This should usually be 0. Setting this to a higher number
+% causes the function to add in that number of _secondary_
+% reflections from the back surface of the sample (assumed to be
+% uncoated).
+% Lprotect = OPTICAL thickness (in terms of lambda0) of any protective coating layer laid
+% down on top of the coating. Usually, the topmost periodic layer
+% is a low index layer (usually SiO2). However, the topmost layer is
+% usually a diffeent thickness layer (e.g. 1/2 wavelength thick) rather than a 1/4
+% wavelength layer like the others.
+% This is accounted for in this code by setting Lprotect to 1/4,
+% and nprotect=nL. In other words the 1/2 wavelength topmost
+% layer is constructed as two 1/4 wavelength layers (the periodic
+% layer and the protective layer) each with the same index of
+% refraction. And these are indeed the default values for Lprotect
+% and nprotect. Default: Lprotect=1/4.
+% nprotect = Index of refraction of any additional coating layer laid down
+% to protect the periodic coating. Default: nprotect=nL.
+% nb = Index of refraction of the substrate. Default: nb=1.46 (silica).
+% anginc = 1xM vector of incidence angles in radians. Default is 500
+% evenly spaced angles between zero and pi/2.
+% LH = Actual physical thicknesses of the high index layers. Default is
+% 1064e-9/4/2.2 nanometers. (Quarter wavelength at 1064 nm of tantala.)
+% LL = Actual physical thicknesses of the low index layers.
+% 1064e-9/4/1.46 nanometers. (Quarter wavelength at 1064 nm of silica.)
+%
+% OUTPUT VARIABLES
+% ----------------
+% R, T = MxN matrix of Reflectivity and Transmissivity (fractional reflected or
+% transmitted _power_). R and T are vectors of size(anginc).
+% lambda_mesh = This is the lambda mesh needed to plot R or T as a surface
+% anginc_mesh = This is the anginc mesh needed to plot R or T as a surface
+% r = The amplitude reflectance (R = r x r*).
+%
+%
+% EXAMPLE 1 (R as a function of incident angle and wavelength for a tantala/silica 15 layer coating)
+% ---------
+% lambda = [199:3:1201]*1e-9;
+% anginc = [0:0.5:90]*pi/180;
+% [R,T,lambda_mesh,anginc_mesh,r] = coatingRTnew(2.2,1.46,15,lambda,'tm',...
+% 0,0,0,1.46,anginc,1.21e-7,1.82e-7);
+% h=pcolor(lambda_mesh*1e9,anginc_mesh*180/pi,R);
+% set(h,'edgecolor','none');
+% colorbar;
+% caxis([0 1]);
+%
+%
+% EXAMPLE 2 (R as a function of incident angle at lambda=900 nm)
+% ---------
+% lambda = 900e-9;
+% lambda0 = 1064e-9;
+% anginc = [0:0.1:90]*pi/180;
+% [R,T,lambda,anginc,r] = coatingRTnew(2.2,1.46,15,lambda,'tm',...
+% 0,0,0,1.46,anginc,1.21e-7,1.82e-7);
+% plot(anginc*180/pi,R);
+%
+%
+% EXAMPLE 3 (R as a function of wavelength at an incident angle of 70 degrees)
+% ---------
+% lambda_in = [500:0.1:1300]*1e-9;
+% anginc_in = 70*pi/180;
+% [Rp,Tp,lambda,anginc] = coatingRTnew(2.2,1.46,15,lambda_in,'tm',...
+% 0,0,0,1.46,anginc_in,1.21e-7,1.82e-7);
+% [Rs,Ts,lambda,anginc] = coatingRTnew(2.2,1.46,15,lambda_in,'te',...
+% 0,0,0,1.46,anginc_in,1.21e-7,1.82e-7);
+% plot(lambda*1e9,Rp,lambda*1e9,Rs);
+% axis([500 1300 0 1.1]);
+%
+%
+% EXAMPLE 4 (R as a function of wavelength at normal incidence from an irregular coating)
+% ---------
+% for s=1:25
+% n=[1,repmat([2.0+0.2*rand(1,1),1.5+0.2*rand(1,1)],1,15),1.46];
+% L=repmat([1/2.2 1/1.46]*0.25*850e-9,1,15)+[0.1e-7*randn(1,30)];
+% anginc_in = 0;
+% [Rp,Tp,lambda,anginc] = coatingRTnew(n,L,[],lambda_in,'tm',5,[],[],[],anginc_in);
+% plot(lambda*1e9,Rp);
+% axis([500 1300 0 1.1]);
+% drawnow
+% pause(0.1)
+% end
+%
+% % EXAMPLE 5 (R from a simple uncoated glass surface as a function of incident angle at lambda=632 nm)
+% ---------
+% lambda = 632e-9;
+% anginc = [0:0.1:90]*pi/180;
+% [R,T,lambda,anginc,r] = coatingRTnew([1 1.5],[],[],lambda,'p',...
+% [],[],[],[],anginc);
+% plot(anginc*180/pi,R); set(gca,'xlim',[0 90]); shg;
+%
+%--------------------------------------------------------------------------
+% SYNTAX: [R,T,lambda_mesh,anginc_mesh,r] = coatingRT(nH,nL,N,lambda,...
+% pol <,nreflecs,Lprotect,nprotect,nb,anginc,LH,LL>)
+%--------------------------------------------------------------------------
+
+
+function [R,T,lambda_mesh,anginc_mesh,r] = coatingRTnew(nH,nL,N,lambda,pol,varargin)
+lambda0=1064e-9;
+m=5; n=1;
+if nargin>=m+n, nreflecs=varargin{n}; else nreflecs=0; end; n=n+1;
+if nargin>=m+n, Lprotect=varargin{n}; else Lprotect=0; end; n=n+1;
+if nargin>=m+n, nprotect=varargin{n}; else nprotect=nL; end; n=n+1;
+if nargin>=m+n, nb=varargin{n}; else nb=1.46; end; n=n+1;
+if nargin>=m+n, anginc=varargin{n}; else anginc=linspace(0,90,500)*pi/180; end; n=n+1;
+if nargin>=m+n, LH=varargin{n}; else LH=lambda0/4/2.2; end; n=n+1; % Actual physical thicknesses of the high index layers.
+if nargin>=m+n, LL=varargin{n}; else LL=lambda0/4/1.46; end; n=n+1; % Actual physical thicknesses of the low index layers.
+na = 1; % refractive index of medium outside the sample (usually air or vacuum);
+
+
+if strcmp(pol,'p')|strcmp(pol,'P')
+ pol='tm';
+elseif strcmp(pol,'s')|strcmp(pol,'S')
+ pol='te';
+elseif strcmp(pol,'tm')|strcmp(pol,'te')
+else
+ error('Polarization string was not understood. Should be ''te'',''tm'',''p'', or ''s''.');
+end
+
+if length(nH)>1
+ n_in=nH;
+ n_out=reverse(n_in);
+ L_in=nL;
+ if length(n_in)>2
+ L_in=L_in.*n_in(2:end-1)/lambda0; % convert actual thicknesses to optical thickensses in terms of lambda0;
+ end
+ L_out=reverse(L_in);
+ na=n_in(1);
+ nb=n_in(end);
+else
+ coating=repmat([nL,nH], 1, N);
+ L_in = (coating==nL)*LL + (coating==nH)*LH; % lengths of the layers in order as seen entering sample
+ if Lprotect~=0;
+ L_in=[Lprotect,L_in];
+ coating=[nprotect,coating];
+ end
+ n_in = [na,coating,nb]; % indices for the layers in order as seen entering sample
+ n_out = reverse(n_in); % indices for the layers in order as seen exiting sample
+ L_in=L_in.*n_in(2:end-1)/lambda0; % convert actual thicknesses to optical thickensses in terms of lambda0;
+
+ L_out= reverse(L_in); % lengths of the layers in order as seen exiting sample
+end
+
+angincg=asin(na*sin(anginc)/nb); %Snell's law
+r_in=zeros(length(anginc),length(lambda));
+r_out=zeros(length(anginc),length(lambda));
+R_in=zeros(length(anginc),length(lambda));
+R_out=zeros(length(anginc),length(lambda));
+R_g=zeros(length(anginc),1); %Fresnel Eqn's don't depend on lambda explicitly, so neither does R_g
+R=zeros(length(anginc),length(lambda));
+[r_gs r_gp]=fresnel(nb,na,angincg*180/pi); % nb is the "left hand" medium in the call to fresnel because the beam is inside the sample
+R_gs=r_gs.*conj(r_gs);
+R_gp=r_gp.*conj(r_gp);
+
+
+for s=1:length(anginc)
+ r_in(s,:)=multidiel(n_in,L_in,lambda/lambda0,anginc(s)*180/pi,pol);
+ r_out(s,:)=multidiel(n_out,L_out,lambda/lambda0,angincg(s)*180/pi,pol);
+ R_in(s,:)=(r_in(s,:).*conj(r_in(s,:)));
+ R_out(s,:)=(r_out(s,:).*conj(r_out(s,:)));
+ if strcmp(pol,'te'), R_g(s)=R_gs(s); else R_g(s)=R_gp(s); end
+ if strcmp(pol,'te'), r_g(s)=r_gs(s); else r_g(s)=r_gp(s); end
+ if nreflecs~=0
+ k=R_out(s,:)*R_g(s);
+ % next line is sum from 0 to nreflecs internally reflecting light beams
+ % NOTE: nreflecs = 2 is equivalent the having 3 beams in total reflected
+ % from the sample (primary reflection + 2 secondary reflections).
+ R(s,:)=R_in(s,:) + ( 1-R_in(s,:) ) * R_g(s) .* (1-k.^nreflecs)./( 1-k ) .* ( 1-R_out(s,:) );
+ if nargout==5,
+ warning('The amplitude reflection coefficient, r, does not include the effect of internal bounces. (Not yet implemented).');
+ end
+ r(s,:)=r_in(s,:);
+ else
+ R(s,:)=R_in(s,:);
+ r(s,:)=r_in(s,:);
+ end
+end
+
+T=1-R;
+[lambda_mesh,anginc_mesh]=meshgrid(lambda,anginc);
diff --git a/coatings/prerequisits.txt b/coatings/prerequisits.txt
new file mode 100644
index 0000000..1900f1b
--- /dev/null
+++ b/coatings/prerequisits.txt
@@ -0,0 +1,5 @@
+To use coatingRT.m, the function multidiel.m by Orfanidis must be in your matlab path.
+
+multidiel.m is available on the mathworks website in the package ewa.zip from Orfanidis:
+
+http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=4456 \ No newline at end of file
diff --git a/examples/A_beam_visualization_script.m b/examples/A_beam_visualization_script.m
new file mode 100644
index 0000000..e58da4c
--- /dev/null
+++ b/examples/A_beam_visualization_script.m
@@ -0,0 +1,601 @@
+% This is a fairly elaborate example of how to use the beam visualization
+% tools and beam propagation tools in the "axial" subdirectory. Basically,
+% the functions in the "axial" subdirectory implement an ABCD matrix
+% propagation environment. The functions beamplot.m and lensplot.m are
+% simple examples of visualization tools used to fair effect by this
+% script. This script propagates the main laser beam at the LIGO Livingston
+% observatory from the modecleaner to the various output ports using the
+% ABCD approximation. Then a figure is drawn with the various beam paths
+% illustrated.
+
+%----------------------------------------------------------------------------------------------
+% VARIABLE CONTROL
+
+var_mcwaist=0; % Allow (1) or disallow (0) beam width variation at MC waist
+var_rmwidth=0; % Allow (1) or disallow (0) beam width variation insided PRM (at RM)
+var_deltaMMT2pos=1; % Allow (1) or disallow (0) MMT2 position variation
+
+postmc_power=3; % Input power [Watts]
+%----------------------------------------------------------------------------------------------
+fontsize=0.01;
+figure(1);
+
+for s=1:1
+switch s
+case 1
+ wmc=0.01; % MC waist width [inches] (only used if var_mcwaist=1)
+ wrm=4.8/2.54; % PRM beam width specified at RM [inches] (only used if var_rmwidth=1)
+ deltaMMT2pos=3.18; % MMT2, distance from design position [inches] pos. value lengthens telescope (only used if var_deltaMMT2pos=1)
+ linestyle='-';
+ linecolor='b';
+case 2
+ wmc=0.03;
+ wrm=4.8/2.54;
+ deltaMMT2pos=1.5;
+ linestyle='-';
+ linecolor='r';
+case 3
+ wmc=0.06413;
+ wrm=4.8/2.54;
+ deltaMMT2pos=3.18;
+ linestyle='-';
+ linecolor='g';
+end
+
+beam_propagate_llo_asbuilt;
+
+%-----------------------------------------------------------------------------
+% INPUT BEAM
+%-----------------------------------------------------------------------------
+x=0; y=86;
+resolution=5000;
+
+propdist=52-1.48;
+[h,x,y]=beamplot(qMCwaist,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_smalloptic,0,x,y,0,1064e-9/0.0254,'MMT1');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=533.55;
+[h,x,y]=beamplot(qMMT1FF,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_smalloptic,0,x,y,0,1064e-9/0.0254,'MMT2');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=565.99;
+[h,x,y]=beamplot(qMMT2FF,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_largeoptic,0,x,y,0,1064e-9/0.0254,'MMT3');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=637.41;
+[h,x,y]=beamplot(qMMT3FF,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_largeoptic,0,x,y,0,1064e-9/0.0254,'RM');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=173.13;
+[h,x,y]=beamplot(qRMFF,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_largeoptic,0,x,y,0,1064e-9/0.0254,'BS');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=191.40;
+[h,x,y]=beamplot(qBSFF,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_largeoptic,0,x,y,0,1064e-9/0.0254,'ITM');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+%propdist=157284.7/10;
+%[h,x,y]=beamplot(qITMXFF,[0:propdist/resolution:propdist],x,y); hold on;
+%set(h,'Color',linecolor);
+%set(h,'LineStyle',linestyle);
+%[h,th]=lensplot(qd_largeoptic,0,x,y,0,1064e-9/0.0254,'ETM');
+%set(th,'FontUnits','normalized','FontSize',fontsize);
+
+
+%-----------------------------------------------------------------------------
+% REFL
+%-----------------------------------------------------------------------------
+
+% REFL In vac
+x=0; y=73;
+resolution=5000;
+
+[h,th]=lensplot(d_largeoptic,0,x,y,0,1064e-9/0.0254,'RM');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=637.41;
+[h,x,y]=beamplot(qRMrear,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_largeoptic,0,x,y,0,1064e-9/0.0254,'MMT3');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=565.99;
+[h,x,y]=beamplot(qMMT3FFreturning,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_smalloptic,0,x,y,0,1064e-9/0.0254,'MMT2',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=533.55;
+[h,x,y]=beamplot(qMMT2FFreturning,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_smalloptic,0,x,y,0,1064e-9/0.0254,'MMT1',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=17.21-1.48;
+[h,x,y]=beamplot(qMMT1FFreturning,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_faraday,0,x,y,0,1064e-9/0.0254,'Faraday',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=60.8;
+[h,x,y]=beamplot(qFaradayreturning,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'viewport',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+% REFL Table, common path
+propdist=43;
+[h,x,y]=beamplot(qREFLviewport,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'1.1m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+xcommon=x; ycommon=y;
+
+% REFL Table, 62 MHz LSC path
+x=xcommon; y=ycommon;
+
+propdist=40.25;
+[h,x,y]=beamplot(qREFLL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2/25.4,0,x,y,0,1064e-9/0.0254,'60 MHz PD',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+% REFL Table, 25 MHz LSC path
+x=xcommon; y=ycommon-4;
+
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'1.1m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=30.4;
+[h,x,y]=beamplot(qREFLL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(1,0,x,y,0,1064e-9/0.0254,'~180 mm',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=6.5;
+[h,x,y]=beamplot(qREFLL2,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2/25.4,0,x,y,0,1064e-9/0.0254,'25 MHz PD',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+% REFL Table, camera path
+x=xcommon; y=ycommon-8;
+
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'1.1m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=27;
+[h,x,y]=beamplot(qREFLL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(5/25.4,0,x,y,0,1064e-9/0.0254,'Camera',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+% REFL Table, WFS3 path
+x=xcommon; y=ycommon-12;
+
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'1.1m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=72.15;
+[h,x,y]=beamplot(qREFLL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(1,0,x,y,0,1064e-9/0.0254,'401 mm',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=20.75;
+[h,x,y]=beamplot(qREFLL3,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(1,0,x,y,0,1064e-9/0.0254,'-50 mm',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=4.75;
+[h,x,y]=beamplot(qREFLL4,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(10/25.4,0,x,y,0,1064e-9/0.0254,'WFS3',2);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+
+% REFL Table, WFS4 path
+x=xcommon; y=ycommon-16;
+
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'1.1m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=65.55;
+[h,x,y]=beamplot(qREFLL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(1,0,x,y,0,1064e-9/0.0254,'~1 m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=37.75;
+[h,x,y]=beamplot(qREFLL5,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(10/25.4,0,x,y,0,1064e-9/0.0254,'WFS4',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+
+%-----------------------------------------------------------------------------
+% AS
+%-----------------------------------------------------------------------------
+
+% AS in vac
+x=0; y=59;
+resolution=5000;
+
+[h,th]=lensplot(d_largeoptic,0,x,y,0,1064e-9/0.0254,'BS');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=172.85;
+[h,x,y]=beamplot(qBSRFreturning,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_OT1,0,x,y,0,1064e-9/0.0254,'ASOT1');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=52.2;
+[h,x,y]=beamplot(qASOT1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_OT2,0,x,y,0,1064e-9/0.0254,'ASOT2',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=76.97;
+[h,x,y]=beamplot(qASOT2,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_faraday,0,x,y,0,1064e-9/0.0254,'Faraday',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=84.09;
+[h,x,y]=beamplot(qASFaraday,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'viewport',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+% AS Table, LSC (detect) path
+xlsc=x; ylsc=y;
+
+propdist=86;
+[h,x,y]=beamplot(qASviewport,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'1.1 m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+xlsc=x; ylsc=y;
+
+propdist=53.05;
+[h,x,y]=beamplot(qASL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(1,0,x,y,0,1064e-9/0.0254,'229 mm',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=20.75;
+[h,x,y]=beamplot(qASL2,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2/25.4,0,x,y,0,1064e-9/0.0254,'Detection PD',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+% AS Table, Acquire path
+x=xlsc; y=ylsc-4;
+
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'1.1 m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=40.59;
+[h,x,y]=beamplot(qASL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2/25.4,0,x,y,0,1064e-9/0.0254,'Acquisition PD',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+% AS Table, Camera path
+
+x=xlsc; y=ylsc-8;
+
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'1.1 m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=53.8;
+[h,x,y]=beamplot(qASL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(5/25.4,0,x,y,0,1064e-9/0.0254,'Camera',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+
+% AS Table, WFS1 path
+
+x=xlsc; y=ylsc-12;
+
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'1.1 m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=39.55;
+[h,x,y]=beamplot(qASL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(1,0,x,y,0,1064e-9/0.0254,'-76 mm',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=14.25;
+[h,x,y]=beamplot(qASL3,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(10/25.4,0,x,y,0,1064e-9/0.0254,'WFS1',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+%-----------------------------------------------------------------------------
+% POB
+%-----------------------------------------------------------------------------
+
+% POB in vac
+x=0; y=38;
+resolution=1000;
+
+[h,th]=lensplot(d_largeoptic,0,x,y,0,1064e-9/0.0254,'BS');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=525.97;
+[h,x,y]=beamplot(qBSFFexiting,[0:propdist/resolution:propdist],x,y,0); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_OT1,0,x,y,0,1064e-9/0.0254,'POBOT1');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=52.2;
+[h,x,y]=beamplot(qPOBOT1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_OT2,0,x,y,0,1064e-9/0.0254,'POBOT2',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=133.85;
+[h,x,y]=beamplot(qPOBOT2,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'viewport',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+
+% POB lsc path
+
+propdist=82;
+[h,x,y]=beamplot(qPOBviewport,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'0.69 m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+xlsc=x; ylsc=y;
+
+propdist=26.75;
+[h,x,y]=beamplot(qPOBL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2/25.4,0,x,y,0,1064e-9/0.0254,'POB PD',2);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+
+% POB SPOB path
+
+x=xlsc; y=ylsc-4;
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'0.57 m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=38.5;
+[h,x,y]=beamplot(qPOBL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(1,0,x,y,0,1064e-9/0.0254,'50 mm',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=2.7;
+[h,x,y]=beamplot(qPOBL2,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(0.1/25.4,0,x,y,0,1064e-9/0.0254,'1811',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+%-----------------------------------------------------------------------------
+% POX
+%-----------------------------------------------------------------------------
+
+x=0; y=24;
+resolution=1000;
+
+[h,th]=lensplot(d_largeoptic,0,x,y,0,1064e-9/0.0254,'ITMX');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=358.77;
+[h,x,y]=beamplot(qITMXRF,[0:propdist/resolution:propdist],x,y,0); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_OT1,0,x,y,0,1064e-9/0.0254,'POXOT1');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=52.2;
+[h,x,y]=beamplot(qPOXOT1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_OT2,0,x,y,0,1064e-9/0.0254,'POXOT2',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=150.35;
+[h,x,y]=beamplot(qPOXOT2,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'viewport',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=88.5;
+[h,x,y]=beamplot(qPOXviewport,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'0.69 m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=27;
+[h,x,y]=beamplot(qPOXL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2/25.4,0,x,y,0,1064e-9/0.0254,'POX PD',2);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+%-----------------------------------------------------------------------------
+% POY
+%-----------------------------------------------------------------------------
+
+% POY in vac
+x=0; y=10;
+resolution=1000;
+
+[h,th]=lensplot(d_largeoptic,0,x,y,0,1064e-9/0.0254,'ITMY');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=326.22;
+[h,x,y]=beamplot(qITMYRF,[0:propdist/resolution:propdist],x,y,0); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_OT1,0,x,y,0,1064e-9/0.0254,'POYOT1');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=52.2;
+[h,x,y]=beamplot(qPOYOT1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_OT2,0,x,y,0,1064e-9/0.0254,'POYOT2',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=95.97;
+[h,x,y]=beamplot(qPOYOT2,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'viewport',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+% POY Table, common path
+
+propdist=41;
+[h,x,y]=beamplot(qPOYviewport,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'1.1 m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+xcommon=x; ycommon=y;
+
+%POY Table, WFS2 path
+x=xcommon; y=ycommon;
+
+%propdist=40.25;
+%[h,x,y]=beamplot(qPOYL1,[0:propdist/resolution:propdist],x,y); hold on;
+%set(h,'Color',linecolor);
+%set(h,'LineStyle',linestyle);
+%[h,th]=lensplot(1,0,x,y,0,1064e-9/0.0254,'-76.3 mm',1);
+%set(th,'FontUnits','normalized','FontSize',fontsize);
+
+%propdist=29.7;
+%[h,x,y]=beamplot(qPOYL2,[0:propdist/resolution:propdist],x,y); hold on;
+%set(h,'Color',linecolor);
+%set(h,'LineStyle',linestyle);
+%[h,th]=lensplot(1,0,x,y,0,1064e-9/0.0254,'~220 mm',0);
+%set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=72.95;
+[h,x,y]=beamplot(qPOYL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(10/25.4,0,x,y,0,1064e-9/0.0254,'WFS2',2);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+% POY Table, video camera path
+
+x=xcommon; y=ycommon-4;
+
+%[h,th]=lensplot(1,0,x,y,0,1064e-9/0.0254,'-76.3 mm',0);
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'1.1 m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+%propdist=28.75;
+propdist=57.75;
+%[h,x,y]=beamplot(qPOYL2,[0:propdist/resolution:propdist],x,y); hold on;
+[h,x,y]=beamplot(qPOYL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(5/25.4,0,x,y,0,1064e-9/0.0254,'Camera',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+% POY Table, phasecamera path
+x=xcommon; y=ycommon-8;
+
+%[h,th]=lensplot(1,0,x,y,0,1064e-9/0.0254,'-76.3 mm',0);
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'1.1 m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+%propdist=28.75;
+propdist=69;
+%[h,x,y]=beamplot(qPOYL2,[0:propdist/resolution:propdist],x,y); hold on;
+[h,x,y]=beamplot(qPOYL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(0.1/25.4,0,x,y,0,1064e-9/0.0254,'1811',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+
+end
+
+[h,th]=scalemarker(1800,15,393.70,'10 m','h');
+set(th,'FontUnits','normalized','FontSize',0.03);
+[h,th]=scalemarker(2000,20,3.9370,'0.1 m','v');
+set(th,'FontUnits','normalized','FontSize',0.03);
+set(gcf,'Color','w');
+set(gcf,'NumberTitle','off');
+set(gcf,'Name','LLO beams');
+xlabel('Inches');
+ylabel('Inches');
+set(gca,'Visible','on');
+set(gca,'YLim',[0 95]);
+set(gca,'XLim',[-100,2400]);
+set(gca,'Box','on');
+set(gca,'Visible','on');
+%title('Input and output beams');
+hold off;
+
diff --git a/examples/A_beam_visualization_script_support/beam_propagate_llo_asbuilt.m b/examples/A_beam_visualization_script_support/beam_propagate_llo_asbuilt.m
new file mode 100644
index 0000000..cfb8eb6
--- /dev/null
+++ b/examples/A_beam_visualization_script_support/beam_propagate_llo_asbuilt.m
@@ -0,0 +1,439 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% This is a beam propagation calculation for LLO. The script is normally run in %
+% standalone mode where all quantities take either the "as built" or design %
+% values (set variable "asbuilt" to 1 to get the as built design). By specifying%
+% "standalone=0" the script assumes that the mc waist size and/or beam width at %
+% the recycling mirror are already specified. To use beam_visualize.m set %
+% standalone to zero. %
+% %
+% In-vacuum distances obtained from CAD drawing D970610-A.dwg unless otherwise %
+% noted. Distances on the output tables (outside the vacuum) were measured with %
+% a measuring tape to 0.25" accuracty. %
+% Radii of curvature were obtained from design documents unless otherwise %
+% indicated. %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+standalone=1;
+
+if standalone
+ postmc_power=3; % Watts
+ var_mcwaist=0;
+ var_rmwidth=0;
+ var_deltaMMT2pos=1; deltaMMT2pos=3.180;
+end
+
+faraday_thermlensdata=[%input power[W] FL[m] (values from IOO final design document, fig. 37)
+ 1 600/0.0254
+ 2 350/0.0254
+ 3 225/0.0254
+ 3.2 200/0.0254
+ 4.1 150/0.0254
+ 5 113/0.0254
+ 10 57/0.0254
+ 13 50/0.0254
+ 20 30/0.0254
+];
+faradaylens=interp1(faraday_thermlensdata(:,1),faraday_thermlensdata(:,2),[0:0.1:20],'spline');
+% lookup table for the faraday lens where the nth row gives the estimated
+% induced focal length of the faraday in inches for n/10 Watts of incident power.
+
+faraday_f=faradaylens(round(postmc_power*10)); % Thermally induced focal length of the faraday
+
+
+%-------------------------------------------------------------------------------
+% Reflection matrixes for curved optics (suspended optics not listed are flat)
+%-------------------------------------------------------------------------------
+
+lambda=1064e-9/0.0254;
+
+RM=mirr(6.213e5);
+RMrear=fdie(1.45,1)*free(3.63,1.45)*mirr(-6.213e5)*free(3.63,1.45)*fdie(1,1.45);
+RMlens=sdie(-6.213e5,1.45,1)*free(3.63,1.45)*fdie(1,1.45);
+BSlens=slab(1.90,1.45,6);
+ITMX=mirr(5.811e5);
+ITMXrear=fdie(1.45,1)*free(3.83,1.45)*mirr(-5.811e5)*free(3.83,1.45)*fdie(1,1.45);
+ITMY=mirr(5.717e5);
+ITMYrear=fdie(1.45,1)*free(3.83,1.45)*mirr(-5.717e5)*free(3.83,1.45)*fdie(1,1.45);
+ITMXlens=sdie(-5.811e5,1.45,1)*free(3.83,1.45)*fdie(1,1.45);
+ITMYlens=sdie(-5.717e5,1.45,1)*free(3.83,1.45)*fdie(1,1.45);
+ETMX=mirr(3.437e5);
+ETMY=mirr(3.433e5);
+
+MC2=mirr(679.1);
+MMT1=mirr(266.1);
+MMT2=mirr(124.4);
+MMT3=mirr(990.6);
+OT1=mirr(119.2); % off axis parabolic
+OT2=mirr(-14.90); % off axis parabolic
+
+%mirror diameters:
+d_smalloptic=2.36; % active area (60 mm)
+d_largeoptic=9.84;
+d_OT1=8;
+d_OT2=3.15;
+d_faraday=0.472; % clear aperture (12 mm)
+
+
+%------------------------------------------------------------------------------
+% Lenses on tables (focal lengths are in inches)
+%------------------------------------------------------------------------------
+
+ASL1=lens(45.11); % first lens, 2" diameter (at bottom of periscope)
+ASL2=lens(9.02); % second lens in LSC detect path (going to ASPD2 and ASPD3)
+ASL3=lens(-3.00); % in WFS1 path immediately before WFS1
+
+POBL1=lens(27.07); % first lens, 2" diameter (at bottom of periscope)
+POBL2=lens(1.97); % lens immediately before SPOB (1811) PD
+
+REFLL1=lens(45.11); % Immediately following REFL periscope
+REFLL2=lens(7); % immediately before 25 MHz LSC PD (lens is mismarked, this f is a guess)
+REFLL3=lens(15.79); % first lens in WFS3 path
+REFLL4=lens(-1.97); % second lens in WFS3 path
+REFLL5=lens(15); % only lens in WFS4 path
+
+POYL1=lens(45.11); % on POY periscope
+POYL2=lens(-3.00); % second lens in POY path on table
+POYL3=lens(8.5); % lens right before the WFS3 head (lens is not marked, this is
+ % a guess based on imaging the room lights, i.e. the distance from
+ % the floor at which the room lights are focused. The lights are
+ % about 20 meters overhead.
+POXL1=lens(27.07); % Immediately following POX periscope
+
+%------------------------------------------------------------------------------
+% Free space propagation matrixes for interoptic and transoptic distances.
+% In vacuum distances are accurate to about 0.1 inch. Distances outside of
+% vacuum are accurate to 0.25 inches unless otherwise specified.
+%------------------------------------------------------------------------------
+
+%MCrefl
+MCwaist_MC1FF=free(3.74);
+MC1FF_MC1RF=free(1.10,1.45);
+MC1RF_MCreflviewport=free(75.92);
+
+%MCtrans
+MCwaist_MC3FF=free(3.74);
+MC3FF_MC3RF=free(1.10,1.45);
+MC3RF_SMFF=free(20.47);
+SMFF_SMRF=free(1.14,1.45);
+SMRF_MCtransviewport=free(99.91);
+
+%MMT
+SMFF_MMT1FF=lens(faraday_f)*free(27.03-1.48);
+ % CAD drawing D970610-A.dwg. Additive pathlength correction is for optical path in faraday (2 polarizers+faraday TGG crystal, each 0.8 in thick).
+if ~var_deltaMMT2pos
+ MMT1FF_MMT2FF=free(533.55); % CAD drawing D970610-A.dwg
+ MMT2FF_MMT3FF=free(565.99); % CAD drawing D970610-A.dwg
+else
+ MMT1FF_MMT2FF=free(533.55+deltaMMT2pos); % CAD drawing D970610-A.dwg
+ MMT2FF_MMT3FF=free(565.99+deltaMMT2pos);
+end
+MMT3FF_RMRF=free(637.41); % CAD drawing D970610-A.dwg
+MMT1FF_Faraday=lens(faraday_f)*free(17.21-1.48); %Additive pathlength correction is for optical path in faraday (2 polarizers+faraday TGG crystal, each 0.8 in thick).
+
+%REFL
+Faraday_REFLviewport=free(60.8);
+
+REFLviewport_REFLL1=free(43);
+REFLL1_REFLL2=free(30.4);
+REFLL2_REFLPD1=free(6.5);
+REFLL1_REFLPD2=free(40.25);
+REFLL1_REFLL3=free(76.5);
+REFLL3_REFLL4=free(21.5);
+REFLL4_WFS3=free(5.25);
+REFLL1_REFLL5=free(70.75);
+REFLL5_WFS4=free(39.5);
+REFLL1_REFLcam=free(27);
+
+%Recycling Cavity
+RMFF_BSFF=free(173.13);
+BSRF_ITMXRF=free(186.12);
+BSFF_ITMYRF=free(177.09);
+
+RMFF_ITMXFF=free(368.35); %measured
+RMFF_ITMYFF=free(354.49); %measured
+
+%Arm Cavities
+ITMXFF_ETMXFF=free(157284.7); %measured
+ITMYFF_ETMYFF=free(157283.5); %measured
+
+
+%AS
+BSRF_ASOT1=free(172.85);
+OT1_OT2=free(52.2);
+ASOT2_ASFaraday=free(76.97);
+ASFaraday_ASviewport=free(84.09);
+
+ASviewport_ASL1=free(86);
+ASL1_ASL2=free(53.05);
+ASL2_ASPD=free(20.75);
+ASL1_ASacquirePD=free(40.59);
+ASL1_AScam=free(53.8);
+ASL1_ASL3=free(39.55);
+ASL3_WFS1=free(14.25);
+
+%POB
+BSFF_POBOT1=free(525.97);
+POBOT2_POBviewport=free(133.85);
+
+POBviewport_POBL1=free(82);
+POBL1_POBPD=free(26.75);
+POBL1_POBL2=free(38.5);
+POBL2_SPOBPD=free(2.7);
+
+%POX
+ITMXRF_POXOT1=free(358.77);
+POXOT2_POXviewport=free(150.35);
+POXviewport_POXL1=free(48+7+25+8.5); % viewport to periscope top distance of 48" has uncertainty of +/- 3".
+POXL1_POXPD=free(27);
+
+%POY
+ITMYRF_POYOT1=free(326.22);
+POYOT2_POYviewport=free(95.97);
+
+POYviewport_POYL1=free(41);
+POYL1_POYcam=free(57.75);
+POYL1_WFS2=free(72.95);
+POYL1_PhasecameraPD=free(64);
+%POYL1_POYL2=free(40.25); % After removal of second lens (Feb/Mar 'O4) these were commented out
+%POYL2_POYcam=free(17.5);
+%POYL2_POYL3=free(29.7);
+%POYL3_WFS2=free(3);
+%POYL2_PhasecameraPD=free(28.75);
+
+
+%--------------------------------------------------------
+% MC
+%--------------------------------------------------------
+
+if ~var_mcwaist
+ qMCwaist=q_(0.06413,1e30,lambda);
+else
+ qMCwaist=q_(wmc,1e30,lambda);
+end
+
+qMCreflvac=prop(qMCwaist,... % MC waist to MC Refl viewport
+ MC1RF_MCreflviewport*...
+ MC1FF_MC1RF*...
+ MCwaist_MC1FF...
+ );
+
+qMCtransvac=prop(qMCwaist,... % MC waist to MC Trans viewport
+ SMRF_MCtransviewport.*...
+ SMFF_SMRF*...
+ MC3RF_SMFF*...
+ MC3FF_MC3RF*...
+ MCwaist_MC3FF...
+ );
+
+
+%--------------------------------------------------------
+% MMT
+%--------------------------------------------------------
+
+qMMT1FF=prop(qMCwaist,...
+ MMT1*...
+ SMFF_MMT1FF*...
+ MC3RF_SMFF*...
+ MC3FF_MC3RF*...
+ MCwaist_MC3FF...
+ );
+
+qMMT2FF=prop(qMMT1FF,...
+ MMT2*...
+ MMT1FF_MMT2FF...
+ );
+
+qMMT3FF=prop(qMMT2FF,...
+ MMT3*...
+ MMT2FF_MMT3FF...
+ );
+
+qRMRFincident=prop(qMMT3FF,MMT3FF_RMRF);
+
+if ~var_rmwidth
+ qRMFF=prop(qRMRFincident,RMlens);
+else
+ qRMFF=q_(wrm,1e30);
+end
+
+
+%--------------------------------------------------------
+% REFL
+%--------------------------------------------------------
+
+qRMrear=prop(qRMRFincident,RMrear);
+
+qMMT3FFreturning=prop(qRMrear,...
+ MMT3*...
+ MMT3FF_RMRF...
+ );
+
+qMMT2FFreturning=prop(qMMT3FFreturning,...
+ MMT2*...
+ MMT2FF_MMT3FF...
+ );
+
+
+qMMT1FFreturning=prop(qMMT2FFreturning,...
+ MMT1*...
+ MMT1FF_MMT2FF...
+ );
+
+qFaradayreturning=prop(qMMT1FFreturning,MMT1FF_Faraday);
+
+qREFLviewport=prop(qFaradayreturning,Faraday_REFLviewport);
+
+qREFLL1=prop(qREFLviewport,REFLL1*REFLviewport_REFLL1);
+qREFLL2=prop(qREFLL1,REFLL2*REFLL1_REFLL2);
+qREFLPD1=prop(qREFLL2,REFLL2_REFLPD1);
+qREFLPD2=prop(qREFLL1,REFLL1_REFLPD2);
+
+qREFLL3=prop(qREFLL1,REFLL3*REFLL1_REFLL3);
+qREFLL4=prop(qREFLL3,REFLL4*REFLL3_REFLL4);
+qWFS3=prop(qREFLL4,REFLL4_WFS3);
+qREFLL5=prop(qREFLL1,REFLL5*REFLL1_REFLL5);
+qWFS4=prop(qREFLL5,REFLL5_WFS4);
+
+qREFLcam=prop(qREFLL1,REFLL1_REFLcam);
+
+
+%--------------------------------------------------------
+% Recycling cavity
+%--------------------------------------------------------
+
+qBSFF=prop(qRMFF,RMFF_BSFF);
+
+qBSRF=prop(qBSFF,BSlens);
+
+qITMXRF=prop(qRMFF,...
+ BSRF_ITMXRF*...
+ BSlens*...
+ RMFF_BSFF...
+ );
+
+qITMXFF=prop(qITMXRF,ITMXlens);
+
+qITMYRF=prop(qRMFF,...
+ BSFF_ITMYRF*...
+ RMFF_BSFF...
+ );
+
+qITMYFF=prop(qITMYRF,ITMYlens);
+
+
+%--------------------------------------------------------
+% Arm Cavities
+%--------------------------------------------------------
+
+qETMXFF=prop(qITMXFF,ITMXFF_ETMXFF);
+qETMYFF=prop(qITMYFF,ITMYFF_ETMYFF);
+
+
+%--------------------------------------------------------
+% POB
+%--------------------------------------------------------
+
+qBSFFexiting=prop(qBSFF,...
+ BSlens*...
+ BSlens...
+ );
+
+qPOBOT1=prop(qBSFFexiting,...
+ OT1*...
+ BSFF_POBOT1...
+ );
+
+qPOBOT2=prop(qPOBOT1,...
+ OT2*...
+ OT1_OT2...
+ );
+
+qPOBviewport=prop(qPOBOT2,POBOT2_POBviewport);
+
+qPOBL1=prop(qPOBviewport,POBL1*POBviewport_POBL1);
+qPOBPD=prop(qPOBL1,POBL1_POBPD);
+
+qPOBL2=prop(qPOBL1,POBL2*POBL1_POBL2);
+qSPOBPD=prop(qPOBL2,POBL2_SPOBPD);
+
+
+%--------------------------------------------------------
+% AS
+%--------------------------------------------------------
+
+qBSRFreturning=prop(qBSRF,...
+ BSRF_ITMXRF*...
+ ITMXrear*...
+ BSRF_ITMXRF...
+ );
+
+qASOT1=prop(qBSRFreturning,...
+ OT1*...
+ BSRF_ASOT1...
+ );
+
+qASOT2=prop(qASOT1,...
+ OT2*...
+ OT1_OT2...
+ );
+qASFaraday=prop(qASOT2,ASOT2_ASFaraday);
+
+qASviewport=prop(qASFaraday,ASFaraday_ASviewport);
+
+qASL1=prop(qASviewport,ASL1*ASviewport_ASL1);
+qASL2=prop(qASL1,ASL2*ASL1_ASL2);
+qASPD=prop(qASL2,ASL2_ASPD);
+
+qASacquirePD=prop(qASL1,ASL1_ASacquirePD);
+
+qAScam=prop(qASL1,ASL1_AScam);
+
+qASL3=prop(qASL1,ASL3*ASL1_ASL3);
+qWFS1=prop(qASL3,ASL3_WFS1);
+
+
+%--------------------------------------------------------
+% POX
+%--------------------------------------------------------
+
+qPOXOT1=prop(qITMXRF,...
+ OT1*...
+ ITMXRF_POXOT1...
+ );
+
+qPOXOT2=prop(qPOXOT1,...
+ OT2*...
+ OT1_OT2...
+ );
+
+qPOXviewport=prop(qPOXOT2,POXOT2_POXviewport);
+
+qPOXL1=prop(qPOXviewport,POXviewport_POXL1);
+
+qPOXPD=prop(qPOXL1,POXL1_POXPD);
+
+%--------------------------------------------------------
+% POY
+%--------------------------------------------------------
+
+qPOYOT1=prop(qITMYRF,...
+ OT1*...
+ ITMYRF_POYOT1...
+ );
+
+qPOYOT2=prop(qPOYOT1,...
+ OT2*...
+ OT1_OT2...
+ );
+
+qPOYviewport=prop(qPOYOT2,POYOT2_POYviewport);
+
+qPOYL1=prop(qPOYviewport,POYL1*POYviewport_POYL1);
+qWFS2=prop(qPOYL1,POYL1_WFS2);
+qphasecamera=prop(qPOYL1,POYL1_PhasecameraPD);
+
+%qPOYL2=prop(qPOYL1,POYL2*POYL1_POYL2);
+%qPOYL3=prop(qPOYL2,POYL3*POYL2_POYL3);
+%qWFS2=prop(qPOYL3,POYL3_WFS2);
+
+%qPhasecamera=prop(qPOYL2,POYL2_PhasecameraPD);
diff --git a/examples/A_beam_visualization_script_support/beam_visualize_asbuilt.m b/examples/A_beam_visualization_script_support/beam_visualize_asbuilt.m
new file mode 100644
index 0000000..87f4055
--- /dev/null
+++ b/examples/A_beam_visualization_script_support/beam_visualize_asbuilt.m
@@ -0,0 +1,591 @@
+%----------------------------------------------------------------------------------------------
+% VARIABLE CONTROL
+
+var_mcwaist=0; % Allow (1) or disallow (0) beam width variation at MC waist
+var_rmwidth=0; % Allow (1) or disallow (0) beam width variation insided PRM (at RM)
+var_deltaMMT2pos=1; % Allow (1) or disallow (0) MMT2 position variation
+
+postmc_power=3; % Input power [Watts]
+%----------------------------------------------------------------------------------------------
+fontsize=0.01;
+figure(1);
+
+for s=1:1
+switch s
+case 1
+ wmc=0.01; % MC waist width [inches] (only used if var_mcwaist=1)
+ wrm=4.8/2.54; % PRM beam width specified at RM [inches] (only used if var_rmwidth=1)
+ deltaMMT2pos=3.18; % MMT2, distance from design position [inches] pos. value lengthens telescope (only used if var_deltaMMT2pos=1)
+ linestyle='-';
+ linecolor='b';
+case 2
+ wmc=0.03;
+ wrm=4.8/2.54;
+ deltaMMT2pos=1.5;
+ linestyle='-';
+ linecolor='r';
+case 3
+ wmc=0.06413;
+ wrm=4.8/2.54;
+ deltaMMT2pos=3.18;
+ linestyle='-';
+ linecolor='g';
+end
+
+beam_propagate_llo_asbuilt;
+
+%-----------------------------------------------------------------------------
+% INPUT BEAM
+%-----------------------------------------------------------------------------
+x=0; y=86;
+resolution=5000;
+
+propdist=52-1.48;
+[h,x,y]=beamplot(qMCwaist,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_smalloptic,0,x,y,0,1064e-9/0.0254,'MMT1');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=533.55;
+[h,x,y]=beamplot(qMMT1FF,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_smalloptic,0,x,y,0,1064e-9/0.0254,'MMT2');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=565.99;
+[h,x,y]=beamplot(qMMT2FF,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_largeoptic,0,x,y,0,1064e-9/0.0254,'MMT3');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=637.41;
+[h,x,y]=beamplot(qMMT3FF,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_largeoptic,0,x,y,0,1064e-9/0.0254,'RM');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=173.13;
+[h,x,y]=beamplot(qRMFF,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_largeoptic,0,x,y,0,1064e-9/0.0254,'BS');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=191.40;
+[h,x,y]=beamplot(qBSFF,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_largeoptic,0,x,y,0,1064e-9/0.0254,'ITM');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+%propdist=157284.7/10;
+%[h,x,y]=beamplot(qITMXFF,[0:propdist/resolution:propdist],x,y); hold on;
+%set(h,'Color',linecolor);
+%set(h,'LineStyle',linestyle);
+%[h,th]=lensplot(qd_largeoptic,0,x,y,0,1064e-9/0.0254,'ETM');
+%set(th,'FontUnits','normalized','FontSize',fontsize);
+
+
+%-----------------------------------------------------------------------------
+% REFL
+%-----------------------------------------------------------------------------
+
+% REFL In vac
+x=0; y=73;
+resolution=5000;
+
+[h,th]=lensplot(d_largeoptic,0,x,y,0,1064e-9/0.0254,'RM');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=637.41;
+[h,x,y]=beamplot(qRMrear,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_largeoptic,0,x,y,0,1064e-9/0.0254,'MMT3');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=565.99;
+[h,x,y]=beamplot(qMMT3FFreturning,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_smalloptic,0,x,y,0,1064e-9/0.0254,'MMT2',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=533.55;
+[h,x,y]=beamplot(qMMT2FFreturning,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_smalloptic,0,x,y,0,1064e-9/0.0254,'MMT1',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=17.21-1.48;
+[h,x,y]=beamplot(qMMT1FFreturning,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_faraday,0,x,y,0,1064e-9/0.0254,'Faraday',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=60.8;
+[h,x,y]=beamplot(qFaradayreturning,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'viewport',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+% REFL Table, common path
+propdist=43;
+[h,x,y]=beamplot(qREFLviewport,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'1.1m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+xcommon=x; ycommon=y;
+
+% REFL Table, 62 MHz LSC path
+x=xcommon; y=ycommon;
+
+propdist=40.25;
+[h,x,y]=beamplot(qREFLL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2/25.4,0,x,y,0,1064e-9/0.0254,'60 MHz PD',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+% REFL Table, 25 MHz LSC path
+x=xcommon; y=ycommon-4;
+
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'1.1m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=30.4;
+[h,x,y]=beamplot(qREFLL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(1,0,x,y,0,1064e-9/0.0254,'~180 mm',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=6.5;
+[h,x,y]=beamplot(qREFLL2,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2/25.4,0,x,y,0,1064e-9/0.0254,'25 MHz PD',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+% REFL Table, camera path
+x=xcommon; y=ycommon-8;
+
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'1.1m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=27;
+[h,x,y]=beamplot(qREFLL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(5/25.4,0,x,y,0,1064e-9/0.0254,'Camera',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+% REFL Table, WFS3 path
+x=xcommon; y=ycommon-12;
+
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'1.1m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=72.15;
+[h,x,y]=beamplot(qREFLL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(1,0,x,y,0,1064e-9/0.0254,'401 mm',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=20.75;
+[h,x,y]=beamplot(qREFLL3,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(1,0,x,y,0,1064e-9/0.0254,'-50 mm',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=4.75;
+[h,x,y]=beamplot(qREFLL4,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(10/25.4,0,x,y,0,1064e-9/0.0254,'WFS3',2);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+
+% REFL Table, WFS4 path
+x=xcommon; y=ycommon-16;
+
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'1.1m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=65.55;
+[h,x,y]=beamplot(qREFLL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(1,0,x,y,0,1064e-9/0.0254,'~1 m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=37.75;
+[h,x,y]=beamplot(qREFLL5,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(10/25.4,0,x,y,0,1064e-9/0.0254,'WFS4',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+
+%-----------------------------------------------------------------------------
+% AS
+%-----------------------------------------------------------------------------
+
+% AS in vac
+x=0; y=59;
+resolution=5000;
+
+[h,th]=lensplot(d_largeoptic,0,x,y,0,1064e-9/0.0254,'BS');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=172.85;
+[h,x,y]=beamplot(qBSRFreturning,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_OT1,0,x,y,0,1064e-9/0.0254,'ASOT1');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=52.2;
+[h,x,y]=beamplot(qASOT1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_OT2,0,x,y,0,1064e-9/0.0254,'ASOT2',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=76.97;
+[h,x,y]=beamplot(qASOT2,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_faraday,0,x,y,0,1064e-9/0.0254,'Faraday',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=84.09;
+[h,x,y]=beamplot(qASFaraday,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'viewport',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+% AS Table, LSC (detect) path
+xlsc=x; ylsc=y;
+
+propdist=86;
+[h,x,y]=beamplot(qASviewport,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'1.1 m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+xlsc=x; ylsc=y;
+
+propdist=53.05;
+[h,x,y]=beamplot(qASL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(1,0,x,y,0,1064e-9/0.0254,'229 mm',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=20.75;
+[h,x,y]=beamplot(qASL2,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2/25.4,0,x,y,0,1064e-9/0.0254,'Detection PD',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+% AS Table, Acquire path
+x=xlsc; y=ylsc-4;
+
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'1.1 m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=40.59;
+[h,x,y]=beamplot(qASL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2/25.4,0,x,y,0,1064e-9/0.0254,'Acquisition PD',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+% AS Table, Camera path
+
+x=xlsc; y=ylsc-8;
+
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'1.1 m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=53.8;
+[h,x,y]=beamplot(qASL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(5/25.4,0,x,y,0,1064e-9/0.0254,'Camera',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+
+% AS Table, WFS1 path
+
+x=xlsc; y=ylsc-12;
+
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'1.1 m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=39.55;
+[h,x,y]=beamplot(qASL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(1,0,x,y,0,1064e-9/0.0254,'-76 mm',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=14.25;
+[h,x,y]=beamplot(qASL3,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(10/25.4,0,x,y,0,1064e-9/0.0254,'WFS1',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+%-----------------------------------------------------------------------------
+% POB
+%-----------------------------------------------------------------------------
+
+% POB in vac
+x=0; y=38;
+resolution=1000;
+
+[h,th]=lensplot(d_largeoptic,0,x,y,0,1064e-9/0.0254,'BS');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=525.97;
+[h,x,y]=beamplot(qBSFFexiting,[0:propdist/resolution:propdist],x,y,0); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_OT1,0,x,y,0,1064e-9/0.0254,'POBOT1');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=52.2;
+[h,x,y]=beamplot(qPOBOT1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_OT2,0,x,y,0,1064e-9/0.0254,'POBOT2',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=133.85;
+[h,x,y]=beamplot(qPOBOT2,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'viewport',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+
+% POB lsc path
+
+propdist=82;
+[h,x,y]=beamplot(qPOBviewport,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'0.69 m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+xlsc=x; ylsc=y;
+
+propdist=26.75;
+[h,x,y]=beamplot(qPOBL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2/25.4,0,x,y,0,1064e-9/0.0254,'POB PD',2);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+
+% POB SPOB path
+
+x=xlsc; y=ylsc-4;
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'0.57 m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=38.5;
+[h,x,y]=beamplot(qPOBL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(1,0,x,y,0,1064e-9/0.0254,'50 mm',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=2.7;
+[h,x,y]=beamplot(qPOBL2,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(0.1/25.4,0,x,y,0,1064e-9/0.0254,'1811',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+%-----------------------------------------------------------------------------
+% POX
+%-----------------------------------------------------------------------------
+
+x=0; y=24;
+resolution=1000;
+
+[h,th]=lensplot(d_largeoptic,0,x,y,0,1064e-9/0.0254,'ITMX');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=358.77;
+[h,x,y]=beamplot(qITMXRF,[0:propdist/resolution:propdist],x,y,0); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_OT1,0,x,y,0,1064e-9/0.0254,'POXOT1');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=52.2;
+[h,x,y]=beamplot(qPOXOT1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_OT2,0,x,y,0,1064e-9/0.0254,'POXOT2',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=150.35;
+[h,x,y]=beamplot(qPOXOT2,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'viewport',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=88.5;
+[h,x,y]=beamplot(qPOXviewport,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'0.69 m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=27;
+[h,x,y]=beamplot(qPOXL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2/25.4,0,x,y,0,1064e-9/0.0254,'POX PD',2);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+%-----------------------------------------------------------------------------
+% POY
+%-----------------------------------------------------------------------------
+
+% POY in vac
+x=0; y=10;
+resolution=1000;
+
+[h,th]=lensplot(d_largeoptic,0,x,y,0,1064e-9/0.0254,'ITMY');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=326.22;
+[h,x,y]=beamplot(qITMYRF,[0:propdist/resolution:propdist],x,y,0); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_OT1,0,x,y,0,1064e-9/0.0254,'POYOT1');
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=52.2;
+[h,x,y]=beamplot(qPOYOT1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(d_OT2,0,x,y,0,1064e-9/0.0254,'POYOT2',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=95.97;
+[h,x,y]=beamplot(qPOYOT2,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'viewport',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+% POY Table, common path
+
+propdist=41;
+[h,x,y]=beamplot(qPOYviewport,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'1.1 m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+xcommon=x; ycommon=y;
+
+%POY Table, WFS2 path
+x=xcommon; y=ycommon;
+
+%propdist=40.25;
+%[h,x,y]=beamplot(qPOYL1,[0:propdist/resolution:propdist],x,y); hold on;
+%set(h,'Color',linecolor);
+%set(h,'LineStyle',linestyle);
+%[h,th]=lensplot(1,0,x,y,0,1064e-9/0.0254,'-76.3 mm',1);
+%set(th,'FontUnits','normalized','FontSize',fontsize);
+
+%propdist=29.7;
+%[h,x,y]=beamplot(qPOYL2,[0:propdist/resolution:propdist],x,y); hold on;
+%set(h,'Color',linecolor);
+%set(h,'LineStyle',linestyle);
+%[h,th]=lensplot(1,0,x,y,0,1064e-9/0.0254,'~220 mm',0);
+%set(th,'FontUnits','normalized','FontSize',fontsize);
+
+propdist=72.95;
+[h,x,y]=beamplot(qPOYL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(10/25.4,0,x,y,0,1064e-9/0.0254,'WFS2',2);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+% POY Table, video camera path
+
+x=xcommon; y=ycommon-4;
+
+%[h,th]=lensplot(1,0,x,y,0,1064e-9/0.0254,'-76.3 mm',0);
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'1.1 m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+%propdist=28.75;
+propdist=57.75;
+%[h,x,y]=beamplot(qPOYL2,[0:propdist/resolution:propdist],x,y); hold on;
+[h,x,y]=beamplot(qPOYL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(5/25.4,0,x,y,0,1064e-9/0.0254,'Camera',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+% POY Table, phasecamera path
+x=xcommon; y=ycommon-8;
+
+%[h,th]=lensplot(1,0,x,y,0,1064e-9/0.0254,'-76.3 mm',0);
+[h,th]=lensplot(2,0,x,y,0,1064e-9/0.0254,'1.1 m',0);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+%propdist=28.75;
+propdist=69;
+%[h,x,y]=beamplot(qPOYL2,[0:propdist/resolution:propdist],x,y); hold on;
+[h,x,y]=beamplot(qPOYL1,[0:propdist/resolution:propdist],x,y); hold on;
+set(h,'Color',linecolor);
+set(h,'LineStyle',linestyle);
+[h,th]=lensplot(0.1/25.4,0,x,y,0,1064e-9/0.0254,'1811',1);
+set(th,'FontUnits','normalized','FontSize',fontsize);
+
+
+end
+
+[h,th]=scalemarker(1800,15,393.70,'10 m','h');
+set(th,'FontUnits','normalized','FontSize',0.03);
+[h,th]=scalemarker(2000,20,3.9370,'0.1 m','v');
+set(th,'FontUnits','normalized','FontSize',0.03);
+set(gcf,'Color','w');
+set(gcf,'NumberTitle','off');
+set(gcf,'Name','LLO beams');
+xlabel('Inches');
+ylabel('Inches');
+set(gca,'Visible','on');
+set(gca,'YLim',[0 95]);
+set(gca,'XLim',[-100,2400]);
+set(gca,'Box','on');
+set(gca,'Visible','on');
+%title('Input and output beams');
+hold off;
+
diff --git a/examples/Airy1Dplot.m b/examples/Airy1Dplot.m
new file mode 100644
index 0000000..d4967d0
--- /dev/null
+++ b/examples/Airy1Dplot.m
@@ -0,0 +1,23 @@
+% Illustrates the use of AiryI.m
+% Plots the field intensity of a TEM00 mode gaussian after passing through an aperture
+% of width a.
+
+lambda=10.6e-6;
+a=0.005;
+F=0.2;
+w0=a/sqrt(pi*F);
+figure
+rmax=2*a;
+nradialpts=300;
+r=[0:rmax/nradialpts:sqrt(rmax)].^2;
+for n=1:16
+ L=n*25*a;
+ subplot(4,4,n);
+ z=AiryI([a,w0,L,lambda,2],r);
+ plot([-reverse(r),r],[reverse(z),z],'w');
+ set(gca,'Visible','off');
+ set(gcf,'Color','black');
+ %axis([-1.1*rmax 1.1*rmax 0 2.5]);
+ pause(0.1);
+end
+shg; \ No newline at end of file
diff --git a/examples/AiryIplot.m b/examples/AiryIplot.m
new file mode 100644
index 0000000..a58742e
--- /dev/null
+++ b/examples/AiryIplot.m
@@ -0,0 +1,43 @@
+% Illustrates the use of AiryI.m
+% Plots field intensity of a TEM00 mode after clipping at an aperture. 16 beam cross
+% sections are calculated starting in the near field ending in the far field
+% (takes some time to run).
+
+lambda=10.6e-6;
+a=0.005;
+F=0.2;
+w0=a/sqrt(pi*F);
+
+rmax=a;
+nradialpts=50;
+nthetapts=36;
+
+for n=1:16
+ L=n*25*a;
+ %thetaoffset=20*pi/180;
+
+ rseed=[0:rmax/nradialpts:sqrt(rmax)].^2;
+ thetaseed=[0:360/nthetapts:360]*pi/180;
+
+ [theta,r]=meshgrid(thetaseed,rseed);
+
+ [x,y]=pol2cart(theta,r);
+
+ subplot(4,4,n);
+
+ z=AiryI([a,w0,L,lambda,4],r);
+ h=pcolor(x,y,z); hold on;
+ %h_contours=contour(x,y,sqrt(x.^2+y.^2),[0.02,0.02],'r');
+ colormap(bone);
+ set(h,'EdgeColor','none');
+ set(h,'FaceColor','interp');
+ set(gca,'Visible','off');
+ set(gcf,'Color','black');
+ axis square
+ set(gca,'XLim',[-rmax rmax]);
+ set(gca,'YLim',[-rmax rmax]);
+ %set(gca,'ZLim',[0 2.5]);
+ hold off
+ drawnow;
+end
+shg; \ No newline at end of file
diff --git a/examples/Hermite_demo.m b/examples/Hermite_demo.m
new file mode 100644
index 0000000..59966d9
--- /dev/null
+++ b/examples/Hermite_demo.m
@@ -0,0 +1,73 @@
+% Illustrates the use of HermiteGaussianE.m, decompose.m and recompose.m by
+% defining an off-center Guassian beam (Fig. 1, Col. 1) and recomposing it
+% in a basis of Hermite Gaussians defined about the center on the figure.
+% The recomposed beam is shown in Fig. 1, Col. 2, where we have used the
+% first 40 Hermite Gaussian (TEM_mn) modes. Figure 1, Col. 3 shows the
+% difference between the recomposed beam and the original. Figure 2 shows
+% the magnitude of the coefficients of the TEM_(l,m) mode in the
+% decomposition.
+
+clear domain;
+screensize=0.1;
+npts=75;
+x=(-screensize:2*screensize/(npts-1):screensize);
+y=x;
+w=0.022;
+R=-1e3;
+deltax=1/sqrt(2)*w;
+deltay=0*w;
+wfactor=1;
+lambda=1.064e-6;
+ploton=[1,1];
+n=40;
+
+[xmesh,ymesh]=meshgrid(x,y);
+domain(:,:,1)=xmesh; domain(:,:,2)=ymesh;
+q=q_(w,R,lambda);
+%zin=exp(-(xmesh.^2+ymesh.^2)/2/q);
+zin=HermiteGaussianE([0,0,q_(w*wfactor,R,lambda),lambda],xmesh+deltax,ymesh+deltay);
+[coeffs,tmat]=decompose(zin,domain,'hg',n,[q,lambda,1e-6]);
+disp(' ');
+dispmat(abs(coeffs));
+zout=recompose(domain,'hg',coeffs,[q,lambda]);
+
+if ploton(1)==1
+ figure(1);
+ subplot(331);
+ h=pcolor(xmesh,ymesh,abs(zin).^2); set(h,'edgecolor','none'); axis square; colorbar; drawnow; shg;
+ title('original intensity');
+ subplot(332);
+ h=pcolor(xmesh,ymesh,abs(zout).^2); set(h,'edgecolor','none'); axis square; colorbar; drawnow; shg;
+ title('recomposed');
+ subplot(333);
+ h=pcolor(xmesh,ymesh,abs(zout).^2-abs(zin).^2); set(h,'edgecolor','none'); axis square; colorbar; drawnow; shg;
+ title('difference');
+ subplot(334);
+ h=pcolor(xmesh,ymesh,real(zin)); set(h,'edgecolor','none'); axis square; colorbar; drawnow; shg;
+ title('original real part');
+ subplot(335);
+ h=pcolor(xmesh,ymesh,real(zout)); set(h,'edgecolor','none'); axis square; colorbar; drawnow; shg;
+ title('recomposed');
+ subplot(336);
+ h=pcolor(xmesh,ymesh,real(zout)-real(zin)); set(h,'edgecolor','none'); axis square; colorbar; drawnow; shg;
+ title('difference');
+ subplot(337);
+ h=pcolor(xmesh,ymesh,imag(zin)); set(h,'edgecolor','none'); axis square; colorbar; drawnow; shg;
+ title('original imaginary part')
+ subplot(338);
+ h=pcolor(xmesh,ymesh,imag(zout)); set(h,'edgecolor','none'); axis square; colorbar; drawnow; shg;
+ title('recomposed')
+ subplot(339);
+ h=pcolor(xmesh,ymesh,imag(zout)-imag(zin)); set(h,'edgecolor','none'); axis square; colorbar; drawnow; shg;
+ title('difference');
+end
+
+if length(ploton)>=2 && ploton(2)==1
+ figure(2);
+ ls=(0:size(coeffs,1)-1);
+ ms=(0:size(coeffs,2)-1);
+ h=pcolor(ls,ms,log10(abs(coeffs.'))); axis square; colorbar; drawnow; shg;
+ title('Log_{10} of coefficients of the modes in the decomposition');
+ xlabel('l');
+ ylabel('m');
+end \ No newline at end of file
diff --git a/examples/LGIplot.m b/examples/LGIplot.m
new file mode 100644
index 0000000..4ed244c
--- /dev/null
+++ b/examples/LGIplot.m
@@ -0,0 +1,37 @@
+% Illustrates the use of LaguerreGaussianE.m by plotting the
+% first 16 Laguerre-Gaussian modes (p,m)=([0:3],[0:3]).
+
+pnumbers=[0:3];
+mnumbers=[0:3];
+pmax=max(pnumbers);
+mmax=max(mnumbers);
+
+w=1;
+R=1e6;
+n=4;
+
+for p=0:pmax
+for m=0:mmax
+
+nrad=240;
+ntheta=240;
+rseed=linspace(0,sqrt(n*w),nrad).^2;
+thetaseed=linspace(0,360,ntheta)*pi/180;
+
+[theta,r]=meshgrid(thetaseed,rseed);
+
+[x,y]=pol2cart(theta,r);
+
+subplot(pmax+1,mmax+1,p*(mmax+1)+m+1)
+h=pcolor(x,y,abs(LaguerreGaussianE([p,m,q_(w,R),1e-6],r,theta,'pol')+LaguerreGaussianE([p,-m,q_(w,R),1e-6],r,theta,'pol')).^2);
+colormap('bone')
+set(gca,'Visible','off');
+set(gcf,'Color','black');
+shading interp;
+%figtext(4.3,-0.7,['(',num2str(p),',',num2str(m),')'],8);
+axis square
+hold off
+shg;
+
+end
+end \ No newline at end of file
diff --git a/examples/Laguerre_demo.m b/examples/Laguerre_demo.m
new file mode 100644
index 0000000..f9d541a
--- /dev/null
+++ b/examples/Laguerre_demo.m
@@ -0,0 +1,97 @@
+% Illustrates the use of LaguerreGaussianE.m, decompose.m and recompose.m by
+% defining an off-center Guassian beam (Fig. 1, Col. 1) and recomposing it
+% in a basis of Laguerre Gaussians defined about the center on the figure.
+% The recomposed beam is shown in Fig. 1, Col. 2, where we have used the
+% first 40 Laguerre Gaussian modes. Figure 1, Col. 3 shows the
+% difference between the recomposed beam and the original. Figure 2 shows
+% the magnitude of the coefficients of the various modes in the
+% decomposition.
+
+
+ploton=[1 1];
+overlaponly=0; showfigure=0;
+
+clear domain;
+
+screensize=0.1;
+nptsr=50;
+nptstheta=100;
+accuracy=0.001;
+n=400;
+
+[rmesh,thetamesh,xmesh,ymesh]=polarmesh([0,screensize,nptsr],[0 2*pi nptstheta],'lin');
+domain(:,:,1)=rmesh; domain(:,:,2)=thetamesh;
+
+w=0.02;
+R=-1e3;
+lambda=1.064e-6;
+q=q_(w,R,lambda);
+
+deltax=1.5*w;
+deltay=1.5*w;
+wfactor=1;
+
+if overlaponly
+ z1=LaguerreGaussianE([0,2,q_(w,R,lambda),lambda],xmesh,ymesh,'cart');
+ z2=LaguerreGaussianE([0,2,q_(w,R,lambda),lambda],xmesh,ymesh,'cart');
+ a=overlap(z1,conj(z2),domain,rmesh) %#ok<NOPTS>
+ if showfigure
+ figure(1);
+ subplot(221); h=pcolor(xmesh,ymesh,abs(z1).^2); shg; colorbar; axis square; set(h,'edgecolor','none');
+ subplot(222); h=pcolor(xmesh,ymesh,abs(z2).^2); shg; colorbar; axis square; set(h,'edgecolor','none');
+ subplot(223); h=pcolor(xmesh,ymesh,angle(z1)); shg; colorbar; axis square; set(h,'edgecolor','none');
+ subplot(224); h=pcolor(xmesh,ymesh,angle(z2)); shg; colorbar; axis square; set(h,'edgecolor','none');
+ end
+ return
+end
+
+zin=LaguerreGaussianE([0,0,q_(w*wfactor,R,lambda),lambda],xmesh+deltax,ymesh+deltay,'cart');
+[coeffs,tmat]=decompose(zin,domain,'lg',n,[q,lambda,accuracy]);
+disp(' '); disp('horizontal');
+dispmat(abs(coeffs(:,:,1)));
+disp(' '); disp('vertical')
+dispmat(abs(coeffs(:,:,2)));
+zout=recompose(domain,'lg',coeffs,[q,lambda,accuracy]);
+
+
+if ploton(1)==1
+ figure(1);
+ subplot(331);
+ h=pcolor(xmesh,ymesh,abs(zin).^2); set(h,'edgecolor','none'); axis square; colorbar; drawnow; shg;
+ title('original intensity');
+ subplot(332);
+ h=pcolor(xmesh,ymesh,abs(zout).^2); set(h,'edgecolor','none'); axis square; colorbar; drawnow; shg;
+ title('recomposed');
+ subplot(333);
+ h=pcolor(xmesh,ymesh,abs(zout).^2-abs(zin).^2); set(h,'edgecolor','none'); axis square; colorbar; drawnow; shg;
+ title('difference');
+ subplot(334);
+ h=pcolor(xmesh,ymesh,real(zin)); set(h,'edgecolor','none'); axis square; colorbar; drawnow; shg;
+ title('original real part');
+ subplot(335);
+ h=pcolor(xmesh,ymesh,real(zout)); set(h,'edgecolor','none'); axis square; colorbar; drawnow; shg;
+ title('recomposed');
+ subplot(336);
+ h=pcolor(xmesh,ymesh,real(zout)-real(zin)); set(h,'edgecolor','none'); axis square; colorbar; drawnow; shg;
+ title('difference');
+ subplot(337);
+ h=pcolor(xmesh,ymesh,imag(zin)); set(h,'edgecolor','none'); axis square; colorbar; drawnow; shg;
+ title('original imaginary part')
+ subplot(338);
+ h=pcolor(xmesh,ymesh,imag(zout)); set(h,'edgecolor','none'); axis square; colorbar; drawnow; shg;
+ title('recomposed');
+ subplot(339);
+ h=pcolor(xmesh,ymesh,imag(zout)-imag(zin)); set(h,'edgecolor','none'); axis square; colorbar; drawnow; shg;
+ title('difference');
+end
+
+if length(ploton)>=2 && ploton(2)==1
+ figure(2);
+ coeffplotmat=[coeffs(:,end:-1:2,2),coeffs(:,:,1)];
+ ps=(-size(coeffs(:,:,2),1)+1:size(coeffs(:,:,1),1)-1);
+ ms=(0:size(coeffs(:,:,2))-1);
+ [psmesh,msmesh]=meshgrid(ps,ms);
+ h=pcolor(psmesh,msmesh,log10(abs(coeffplotmat))); axis square; colorbar; drawnow; shg;
+ title('Log_{10} of coefficients of the modes in the decomposition');
+ xlabel('m'); ylabel('p');
+ end \ No newline at end of file
diff --git a/examples/NRIplot.m b/examples/NRIplot.m
new file mode 100644
index 0000000..3d77fc1
--- /dev/null
+++ b/examples/NRIplot.m
@@ -0,0 +1,24 @@
+% Illustrates the use of NewtonsRingsI by plotting Newton's rings
+
+thetaoffset=20*pi/180;
+
+rseed=[0:0.001:sqrt(0.1)].^2;
+thetaseed=[0:1:360]*pi/180;
+
+[theta,r]=meshgrid(thetaseed,rseed);
+
+[x,y]=pol2cart(theta,r);
+
+subplot(111);
+
+h=pcolor(x,y,NewtonRingsI([0.01,100,14e3,-.1e3,1,1,1.024e-6,thetaoffset],r)); hold on
+%h_contours=contour(x,y,sqrt(x.^2+y.^2),[0.02,0.02],'r');
+colormap('bone');
+set(h,'EdgeColor','none');
+set(h,'FaceColor','interp');
+set(gca,'Visible','off');
+set(gcf,'Color','black');
+%figtext(4.3,-0.7,['(',num2str(p),',',num2str(m),')'],8);
+axis square
+hold off
+shg;
diff --git a/examples/fourier_optics_demonstration.m b/examples/fourier_optics_demonstration.m
new file mode 100644
index 0000000..36abeb2
--- /dev/null
+++ b/examples/fourier_optics_demonstration.m
@@ -0,0 +1,198 @@
+% FOURIER OPTICS DEMONSTRATION
+%
+% Calculates the field intensity on a screen due to diffraction in the Fresnel
+% approximation using the Fourier transform method. The field u(x,y) in the source plane
+% is a highly concave sperical phase front (ROC=5 mm) incident on a pair of rectangular
+% apertures. The field u'(x',y') in the "field plane" is calculated via Fourier transform.
+%
+% You can change the parameters below (e.g. roc, w, a, b, d) to investigate the effect of
+% changing the slit positions and widths.
+% ---------------------------------------------------------------------------------------------------------------------
+
+
+%% The first part of the code is intended to be modified by the user to change the physical and
+% computational parameters
+
+% Physical Parameters
+% -------------------
+c = 3e8; % speed of light in meters per second
+epsilon0 = 8.854e-12; % vacuum permittivity in Farads per meter (SI units)
+lambda = 633e-9; % optical wavelength in meters
+
+% Source plane
+% ------------
+xmax=0.002; ymax=xmax; % size of source plane = [-xmax,xmax]*[symax,symax] meters
+Nx = 2^nextpow2(512); Ny = 2^nextpow2(Nx); % number of points in source plane grid = Nx*Ny
+dx = 2*xmax/(Nx-1); dy=2*ymax/(Ny-1); % interpixel distances (sampling intervals) in the source plane (meters)
+x = repmat( ((0:Nx-1)-floor(Nx/2)) *dx, Ny,1); % source plane points (in scaled distance) at which to evaluate the source field
+y = repmat( ((0:Ny-1)-floor(Ny/2)).'*dy, 1,Nx); % source plane points (in scaled distance) at which to evaluate the source field
+
+
+% ABCD Matrix Components
+% ----------------------
+% Here assumed to be for a free-space/lens/free-space system (f=Inf corresponds to no lens)
+L1 = 1e-3;
+L2 = 999e-3;
+f = Inf;
+%f = -10e-3; % Uncomment this line to see an example of Fresnel (near-field) diffraction
+
+M = [[1 L2];[0 1]] * [[1 0];[-1/f 1]] * [[1 L1];[0 1]];
+disp('M = ');
+dispmat(M);
+
+AA = M(1,1); BB = M(1,2); CC = M(2,1); DD = M(2,2);
+
+% Aperture
+% --------
+% Field amplitude is non-zero at these values of x, y (i.e. where it passes through the aperture))
+% The apertures are defined as logical matrixes that are used to index the source field
+% distribution, i.e. Usource(~aperture)=0; UIsource(aperture)= <something nonzero>.
+
+a = 100*1e-6;
+wideslit = abs(x)<a & abs(y)<8*a;
+
+a = 25*1e-6;
+narrowslit = abs(x)<a & abs(y)<16*a;
+
+a=20*1e-6; % slit width a and interslit distance d (center to center, in meters)
+d=8*a; % f=Inf, roc=Inf; w=Inf; gives classic Fraunhofer fringes.
+sixslits = (abs(x+3*d)<a | abs(x+2*d)<a | abs(x+d)<a | abs(x)<a | abs(x-d)<a | abs(x-2*d)<a | abs(x-3*d)<a) & abs(y)<16*a;
+
+a = 200*1e-6; % length of side of equilateral triangle (in meters)
+triangle = (y<sqrt(3)*x+a/2/sqrt(3)) & (y<-sqrt(3)*x+a/2/sqrt(3))& (y>-a/2/sqrt(3));
+
+a=150e-6;
+circle = x.^2+y.^2 < a^2;
+
+aperture = narrowslit; % Choose one of singleslit, sixslits, circle, or triangle
+
+
+% Source Field
+% ------------
+% Here, the field is assumed to be due to a Gaussian beam of width "w" and phasefront radius of curv. "roc" incident on the aperture.
+roc = 0.5; % radius of curvature of phasefront at source plane, in meters
+w = 500e-6; % Gaussian beam width (meters)
+I0 = 1e6; % (cycle averaged) maximum intensity of the light in source plane in watts per meter^2
+E0 = sqrt(2*I0/c/epsilon0); % field amplitude in the source plane in Newtons/Coulomb.
+k=2*pi/lambda; %
+r=sqrt(x.^2+y.^2); % radius from center of aperture
+Upreap = E0*exp(-r.^2/w^2).*exp(1i*k*r.^2/2/roc)... % field amplitude of beam incident on the source plane aperture
+ .* exp(1i*0*pi/4*randn(size(x))); % (diverging beam if roc is positive). Possible incoherent phase (this line).
+Usource = Upreap; Usource(~aperture)=0; % source plane field amplitude will be zero everywhere except in the aperture
+Isource = epsilon0*c/2*abs(Usource).^2; % Intensity of the field in the source plane (W/m^2)
+
+
+
+
+
+
+
+%% ==========================================================================================================================
+% |+|+|+|+| THE COMPUTATION OCCURS BETWEEN THIS LINE AND THE ONE LIKE IT BELOW |+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|
+% ==========================================================================================================================
+
+% Change of variablesa and variable initialization
+% ------------------------------------------------
+
+% h, below is a scale factor to change from the physical units (meters) to new units in which all physical lengths are scaled
+% by h=1/sqrt(L*lambda). In the new units, the Fresnel integral becomes a pure Fourier transform multiplied by a phase factor.
+% We now scale all physical lengths to the new units before performing the fourier tranform.
+h = sqrt(1/BB/lambda); % scaling factor
+
+dX=h*dx; dY=h*dy; % source plane spatial sampling (pixel) intervals in the new units
+X = h*x; % source plane points (in scaled distance) at which to evaluate the source field
+Y = h*y; % source plane points (in scaled distance) at which to evaluate the source field
+
+dF = 1/dX/Nx; dG=1/dY/Ny; % corresponding spatial sampling interval in field plane after fft2
+F=repmat(([0:Nx-1]-floor(Nx/2)) *dF,Ny,1); % Field plane, x-domain (in scaled length)
+G=repmat(([0:Ny-1]-floor(Ny/2)).'*dG,1,Nx); % Field plane, y-domain (in scaled length)
+df=dF/h; dg=dG/h; % field plane sampling intervals (in meters)
+f = F/h; g = G/h; % Field plane, x and y-domains (in meters)
+
+% Perform 2D FFT on and scale correctly
+% -------------------------------------
+Ufield = -1i/lambda/BB*exp(1i*pi*DD*((F).^2+(G).^2))... % * * * * * * HERE IT IS ! * * * * * * * * *
+ .*fftshift( fft2( exp(1i*pi*AA*(X.^2+Y.^2)).*Usource )*dx*dy );
+Ifield = epsilon0*c/2*abs(Ufield).^2; % get the intensity
+
+% =========================================================================================================================
+% |+|+|+|+| EVERYTHING BELOW THIS LINE IS JUST FLUFF |+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|
+% =========================================================================================================================
+
+
+
+
+
+
+
+%% Report statistics of the calculation and Check energy conservation
+% ------------------------------------------------------------------
+% The total power in the source plane is the same as in the field plane. As a
+% (non-exhaustive) check that things are scaled correctly, check that the total diffracted
+% power is approximately equal to the power in the source plane.
+
+inpow = trapz(trapz(Isource))*dx*dx;
+outpow = trapz(trapz(Ifield))*df*dg;
+
+disp(' ');
+disp('--------------------------------------------------------------------------');
+disp(['Source plane pixel size: dx*dy = ',num2str(1e6*dx,'%0.2f'),' * ',num2str(1e6*dy,'%0.2f'),' microns^2.']);
+disp(['Source plane size: x*y = ',num2str(1e6*2*xmax,'%0.1f'),' * ',num2str(1e6*2*ymax,'%0.1f'),' microns^2']);
+disp(['Field plane pixel size: df*dg = ',num2str(1e3*df,'%0.2f'),' * ',num2str(1e3*dg,'%0.2f'),' mm^2.']);
+disp(['Field plane size: f*g = ',num2str(1e3*2*(f(end)-f(1)),'%0.1f'),' * ',num2str(1e3*2*(g(end)-g(1)),'%0.1f'),' mm^2']);
+disp(' ');
+disp(['Power in the source plane: Pin = ',num2str(inpow*1000),' mW']);
+disp(['Power in the field plane: Pout = ',num2str(outpow*1000),' mW']);
+disp('---------------------------------------------------------------------------');
+
+disp(' ');
+
+% Make a red colormap to use to display the laser beam intesity
+% -------------------------------------------------------------
+cb=colormap('bone'); % use the values in column one of the 'bone' colormap
+cmred=[cb(:,2)*1, cb(:,2)*0.2, cb(:,2)*0.1]; % as the columns of the new colormap but scale them separately
+
+% Display source plane field amplitude (Fig. 1)
+% ---------------------------------------------
+figure(1); % open a figure window
+ax1 = pcolor(x*1e6,y*1e6,Isource/1000); % plot the intensity in mW/mm^2 the source plane as a fn of x,y (in microns)
+xlabel('x ({\mu}m)'); % label the axes
+ylabel('y ({\mu}m)');
+axis square % make the figure display both axes to the same scale (no stretching)
+set(ax1,'linestyle','none');
+caxis([min([max(Isource(aperture))*0.9,...
+ min(Isource(aperture))]),max(Isource(aperture))]/1200);
+% colormap('jet');
+colormap(cmred);
+shading interp;
+aperturemat=zeros(Nx,Ny); % construct a matrix representing the aperture so that we can superimpose
+aperturemat(aperture)=1e-15; % a contour plot of the aperture onto the intensity plot of the source field
+hold on;
+[tmp cont1]=contour(x*1e6,...
+ y*1e6,aperturemat,[0.5e-15,0.5e-15]); % Shows contours of the edge of the aperture
+set(cont1,'color',[1 1 1]*0.5);
+cbar1=colorbar;
+ylabel(cbar1,'Intensity (mW/mm^2)');
+hold off;
+title(['Source Plane Intensity']);
+
+% Display field plane field amplitude (Fig. 2)
+% ---------------------------------------------
+figure(2);
+ax2 = pcolor(f*1e6,g*1e6,(Ifield/1000)); % plot the intensity in the field plane as a fn of physical field plane locations (in mm)
+view(2); % If "surf" is substituted for "pcolor", this plot can be rotated from the top-view orientation
+shading interp;
+xlabel('x ({\mu}m)'); % label the axes
+ylabel('y ({\mu}m)');
+axis square
+axis tight % make the figure display both axes to the same scale (no stretching)
+set(ax2,'linestyle','none');
+caxis(([min(min(Ifield))/12000 (max(max(Ifield)))/1250]));
+title(['Diffracted Intensity in the Field Plane']);
+colormap('jet');
+%colormap(cmred);
+cbar2=colorbar;
+ylabel(cbar2,'Intensity (mW/mm^2)');
+% hold on;
+% contour(f*1e3,g*1e3,abs(Ifield)./max(max(abs(Ifield))),1/exp(2));
+% hold off; \ No newline at end of file
diff --git a/examples/gaussian_topview.m b/examples/gaussian_topview.m
new file mode 100644
index 0000000..27958a1
--- /dev/null
+++ b/examples/gaussian_topview.m
@@ -0,0 +1,56 @@
+% Illustrates the use of SimpleGaussian.m by plotting interesting features
+% of a TEM_00 Hermite Gaussian beam. In Figure 1, the script plots
+% the amplitude and phase of a TEM_00 beam near the focus. The amplitude
+% of the two quadratures amplitude*sin(phase) and amplitude*cos(phase) are
+% shown in a Figure 2.
+
+z=[-0.2:0.003:0.2];
+r=[-1e-3:6e-6:1e-3];
+lambda=1e-6;
+w01=100e-6;
+w02=200e-6;
+
+dr=5e-5;
+
+[E1,w1,R1,phi1,zr]=SimpleGaussian([w01,lambda],z,r);
+theta1=angle(E1);
+I1=E1.*conj(E1);
+Inorm1=I1;
+zpts=size(I1,1);
+rpts=size(I1,2);
+for s=1:zpts
+ Inorm1(s,:)=I1(s,:)./max(I1(s,:));%I1(s,pos(r,0,1));
+end
+
+figure(1);
+subplot(121);
+h1=pcolor(r,z,sqrt(Inorm1)); set(h1,'EdgeColor','none'); hold on;
+caxis([0 1]);
+sidebar=colorbar;
+contour(r,z,sqrt(Inorm1),1,'w','linewidth',2);
+title('amplitude');
+hold off;
+subplot(122);
+h2=pcolor(r,z,theta1); set(h2,'EdgeColor','none'); hold on;
+title('phase (and 1/e envelope)');
+caxis([-pi pi]);
+sidebar=colorbar('ytick',[-2*pi,-3*pi/2,-pi,-pi/2,0,pi/2,pi,3*pi/2,2*pi],...
+ 'yticklabel',{'-2pi','-3pi/2','-pi','-pi/2','0','pi/2','pi','3pi/2','2pi'});
+contour(r,z,sqrt(Inorm1),1,'w','linewidth',2);
+hold off;
+
+figure(2);
+subplot(121);
+h1=pcolor(r,z,Inorm1.*cos(theta1)); set(h1,'EdgeColor','none'); hold on;
+sidebar=colorbar;
+contour(r,z,sqrt(Inorm1),1,'w','linewidth',1);
+caxis([-1.0 1.0]);
+title('I phase and 1/e amplitude envelope');
+hold off;
+subplot(122);
+h2=pcolor(r,z,Inorm1.*sin(theta1)); set(h2,'EdgeColor','none'); hold on;
+sidebar=colorbar;
+contour(r,z,sqrt(Inorm1),1,'w','linewidth',1);
+caxis([-1.0 1.0]);
+title('Q phase and 1/e amplitude envelope');
+hold off;
diff --git a/examples/unstable_cavity.m b/examples/unstable_cavity.m
new file mode 100644
index 0000000..cf7afb6
--- /dev/null
+++ b/examples/unstable_cavity.m
@@ -0,0 +1,151 @@
+% Illustrates the use of cav.m by modeling a marginally stable optical cavity.
+%------------------------------------------------------------------------------------
+% PROGRAM NAME: unstable_cavity
+% AUTHOR: Andri M. Gretarsson
+% DATE: Aug. 24, 2004
+%
+% SYNTAX: unstable_cavity
+%
+% Uses cav.m to model the fields inside and outside a marginally unstable linear cavity
+% The example is based on the LIGO Livingston recycling cavity in its cold state.
+% In the 1D mode, the output is a set of 9 graphs showing the
+% the field inside the cavity and in reflection as a function of length around a resonance.
+% Due to the marginally stable nature of the cavity in this example, we get interesing
+% structure in the fields. The program runs as a script rather than a function and
+% numerous parameters can be set near the beginning of the script. These are:
+%
+% R1, R2 - the radii of curvature of the input and end cavity mirrors
+% r1, r2 - the amplitude reflection coefficients of the two mirrors
+% l1, l2 - the amplitude loss coefficients of the two mirrors
+% L0 - the cavity length
+% lambda - the optical wavelength
+% l_in, m_in - Hermite-Gaussian mode numbers for the input light (referred to
+% the basis set by qin (see next line).
+% qin - the complex radius of curvature of the input light
+% npts - for a 1D calculation, the number of points in the calculation, for a 2D
+% calculation the number of grid points is npts^2
+% twoD - Whether the calculation should be done in 1D (cross section) or 2D. The 2D
+% form is significantly slower. To improve running speeds it may be a good
+% idea to reduce npts. NOTE: It will help to maximize the figure window and
+% rerun the program to improve visibility in the 1D mode.
+%
+% INPUT ARGUMENTS: none
+% OUTPUT ARGUMENTS: none
+% Last Updated: June 30, 2007 by AMG
+%
+%------------------------------------------------------------------------------------
+% SYNTAX: unstable_cavity
+%------------------------------------------------------------------------------------
+
+% Mirror properties
+Ritmx=-14.76e3; % ITMx radius of curvature [meters]
+Ritmy=-14.52e3; % ITMy radius of curvature [meters]
+Rrm=20.78e3; % RM radius of curvature [meters]
+R1=Rrm;
+R2=(Ritmx+Ritmy)/2/1.45; % 1.45 is due to the index of refraction
+r1=sqrt(0.9725); % Measured reflectance coefficients assuming 150ppm loss in ITMs.
+r2=sqrt(0.9731); % see: http://www.ligo-la.caltech.edu/ilog/pub/ilog.cgi?group=detector&date_to_view=08/19/2003&anchor_to_scroll_to=2003:08:25:10:47:28-rana
+%r1=sqrt(1-0.027); % nominal from COC (Helena Armandula) webpage
+%r2=sqrt(1-0.0288);
+%r1=0.96; % test
+l1=0;%sqrt(150e-6); % ITM loss (nominal)
+l2=0;%sqrt(150e-6); % ITM loss (nominal)
+L0=9.2;
+
+% Incident light
+lambda=1.064e-6;
+l_in=0;
+m_in=0;
+[qin,pin]=prop(q_(0.03875,7.1e3,lambda),free(L0),[l_in,m_in]); % Input beam is matched to arms so use arm cavity beam at ITMx to get q value.
+%[qin,pin]=prop(q_(0.03685,-6.9564e3,lambda),free(L0),[l_in,m_in]);
+win=w_(qin,lambda);
+
+% Plot domain
+twoD=0;
+if twoD
+ npts=9;
+ xseed=[-2*win:win/npts:2*win];
+ yseed=xseed';
+ [x,y]=meshgrid(xseed,yseed);
+ thecolormap='bone';
+else
+ npts=200;
+ xseed=[-2.5*win:win/npts:2.5*win];
+ x=xseed;
+ y=zeros(size(x));
+end
+
+
+zin=HermiteGaussianE([l_in,m_in,qin,lambda(1),pin],x,y);
+
+
+n_bounces=70;
+n_lengths=9;
+lowerdL=-15e-9; upperdL=15e-9;
+deltaL=[lowerdL:(upperdL-lowerdL)/(n_lengths-1):upperdL];
+Pcoherent_out=zeros(n_lengths,1);
+for s=1:n_lengths
+ L=round(L0/lambda)*lambda+deltaL(s); % Cavity length
+
+ [qrefl,qtrans,qcav,prefl,ptrans,pcav]=...
+ cav(qin,l_in,m_in,lambda,L,R1,R2,r1,r2,l1,l2,n_bounces,[1.46,1,1,],[0,0]);
+
+ zrefl=HermiteGaussianE([l_in * ones(size(qrefl)),m_in * ones(size(qrefl)),...
+ qrefl,lambda(1) * ones(size(qrefl)),prefl],x,y);
+ zcav=HermiteGaussianE([l_in * ones(size(qcav)),m_in * ones(size(qcav)),...
+ qcav,lambda(1) * ones(size(qcav)),pcav],x,y);
+ ztrans=HermiteGaussianE([l_in * ones(size(qtrans)),m_in * ones(size(qtrans)),...
+ qtrans,lambda(1) * ones(size(qtrans)),ptrans],x,y);
+ if length(size(zcav))==3
+ zsumrefl=sum(zrefl,3);
+ zsumcav=sum(zcav,3);
+ zsumtrans=sum(ztrans,3);
+ else
+ zsumrefl=sum(zrefl,2);
+ zsumcav=sum(zcav,2);
+ zsumtrans=sum(ztrans,2);
+ end
+
+ if ~twoD
+ interpdom=[min(xseed):(max(xseed)-min(xseed))/999:max(xseed)];
+ dx_interp=interpdom(2)-interpdom(1);
+ if s==1
+ inputintens_interp=interp1(x,abs(zin).^2,interpdom,'spline');
+ inputpower=sum(inputintens_interp*dx_interp.*abs(interpdom)*pi);
+ end
+ cavintens_interp=interp1(x,abs(zsumcav).^2,interpdom,'spline');
+ cavpower=sum(cavintens_interp*dx_interp.*abs(interpdom)*pi);
+ reflintens_interp=interp1(x,abs(zsumrefl).^2,interpdom,'spline');
+ reflpower=sum(reflintens_interp*dx_interp.*abs(interpdom)*pi);
+ transintens_interp=interp1(x,abs(zsumtrans).^2,interpdom,'spline');
+ transpower=sum(transintens_interp*dx_interp.*abs(interpdom)*pi);
+ Pcoherent_out(s)=reflpower+transpower;
+ end
+
+ if twoD
+ figure(1);
+ subplot(3,3,s); h=pcolor(x,y,abs(zsumcav)); % h=pcolor(x,y,abs(zsumcav).*cos(angle(zsumcav)));
+ set(h,'EdgeColor','none'); axis square;
+ colormap(thecolormap); %colorbar;
+ set(h,'EdgeColor','none'); set(h,'FaceColor','interp');
+ set(gca,'Visible','off'); set(gcf,'Color','black');
+ set(gca,'Zlim',[-35 35]);
+ drawnow;
+ h=figtext3D(3,1,10,['\Delta{L}: ',num2str(deltaL(s)*1e9,'%0.3g'),' nm'],10);
+ set(h,'color','white');
+ shg;
+ else
+ figure(1); subplot(3,3,s);
+ set(gcf,'Color','default');
+ plot(x*100,zin.*conj(zin),'m--','linewidth',2); hold on;
+ h=plot(x*100,zsumrefl.*conj(zsumrefl),'-',x*100,zsumcav.*conj(zsumcav),'-');
+ set(h,'linewidth',2);
+ legend('input','refl','cav');
+ drawnow; hold off;
+ xlabel('cm'); ylabel('intensity');
+ figtext(0.5,9,['\Delta{L}: ',num2str(deltaL(s)*1e9,'%0.3g'),' nm'],8);
+ figtext(0.5,7.5,['P_{cav}/P_{in} = ',num2str(cavpower,'%0.2g')],8);
+ shg;
+ end
+
+end \ No newline at end of file
diff --git a/misc/fresnel2.m b/misc/fresnel2.m
new file mode 100644
index 0000000..a674cec
--- /dev/null
+++ b/misc/fresnel2.m
@@ -0,0 +1,29 @@
+% Returns the reflectivities as a function of incident angle. rs and rp are
+% NxM matrixes, each row corresponds to a particular wavelength and each column
+% to a particular angle (i.e. wavelength is labeled by N and angle by M).
+%
+% na = Nx1, Nx2 or Nx3 matrix of indexes of the medium on the near side of the interface (i.e. the ambient medium).
+% May be given as a 1xm vector (m=1,2,3) if nb does not change with na.
+% na(N,1), na(N,2) and na(N,3) are the isotropic indices as defined in Orfanidi's function fresnel.m
+% (which is called by this function). The firstindex would often label the indices at different wavelengths.% nb = Nx1, Nx2 or Nx3 matrix of indexes of the medium on the far side of the interface.
+% May be given as a 1xm vector (m=1,2,3) if na does not change with nb.
+% nb(N,1), nb(N,2) and nb(N,3) are the isotropic indices as defined in Orfanidi's function fresnel.m
+% (which is called by this function). The firstindex would often label the indices at different wavelengths.
+% theta = vector of angles of incidence in degrees.
+%
+% Relies on the function fresnel.m by Orfanidis which must be in the path.
+% If only 1-D matrixes are needed and the medium is isotropic, use fresneliso.m instead. It is much faster.
+
+function [rs rp]=fresnel2(na,nb,theta)
+
+if size(na,1)==1
+ na=repmat(na,size(nb));
+elseif size(nb,1)==1
+ nb=repmat(nb,size(na));
+end
+
+rs=zeros(size(nb,1),length(theta)); rp=rs;
+
+for s=1:size(nb,1)
+ [rs(s,:) rp(s,:)]=fresnel(na(s,:),nb(s,:),theta);
+end \ No newline at end of file
diff --git a/misc/fresneliso.m b/misc/fresneliso.m
new file mode 100644
index 0000000..fd9ee02
--- /dev/null
+++ b/misc/fresneliso.m
@@ -0,0 +1,56 @@
+% fresneliso.m - Fresnel reflection coefficients for isotropic media with either indices _or_ lambda as vectors
+%
+% Usage: [rs,rp] = fresnel(na,nb,theta)
+%
+% na,nb = refractive indices of left and right media. May be vectors if lambda is not.
+% theta = incident angle(s) in degrees. May be a vector if na and nb are vectors.
+% rs,rp = reflection coefficients for p and s polarizations
+%
+% Modified by Andri M. Gretarsson from fresnel.m written by Orfanidi. August 2008.
+
+function [rs,rp] = fresnel(na,nb,theta)
+
+if nargin==0, help fresnel; return; end
+
+if length(na)==1
+ na=ones(size(nb))*na;
+elseif length(nb)==1
+ nb=ones(size(na));
+end
+theta = pi*theta/180;
+
+if length(nb) == 1
+ Na = 1./sqrt(cos(theta).^2/na^2 + sin(theta).^2/na^2);
+ xe = (na*sin(theta)).^2; % used for s-pol
+ xm = (Na.*sin(theta)).^2; % used for p-pol
+
+ rs = (na*cos(theta) - sqrt(nb^2 - xe)) ./ ...
+ (na*cos(theta) + sqrt(nb^2 - xe));
+
+ if na==nb,
+ rp = (na - nb) / (na + nb) * ones(1,length(theta));
+ else
+ rp = (na*na * sqrt(nb^2 - xm) - nb*nb * sqrt(na^2 - xm)) ./ ...
+ (na*na * sqrt(nb^2 - xm) + nb*nb * sqrt(na^2 - xm));
+ end
+elseif length(theta) == 1
+ Na = 1./sqrt(cos(theta)^2./na.^2 + sin(theta)^2./na.^2);
+ xe = (na*sin(theta)).^2; % used for s-pol
+ xm = (Na*sin(theta)).^2; % used for p-pol
+
+ rs = (na*cos(theta) - sqrt(nb.^2 - xe)) ./ ...
+ (na*cos(theta) + sqrt(nb.^2 - xe));
+
+ if na==nb,
+ rp = (na - nb) ./ (na + nb);
+ else
+ rp = (na.*na .* sqrt(nb.^2 - xm) - nb.*nb .* sqrt(na.^2 - xm)) ./ ...
+ (na.*na .* sqrt(nb.^2 - xm) + nb.*nb .* sqrt(na.^2 - xm));
+ end
+
+else
+ error('Either na and nb must have length 1 _or_ theta must have length 1.');
+end
+
+
+
diff --git a/misc/incomplete/Hermite_Orthogonality.nb b/misc/incomplete/Hermite_Orthogonality.nb
new file mode 100644
index 0000000..07c4501
--- /dev/null
+++ b/misc/incomplete/Hermite_Orthogonality.nb
@@ -0,0 +1,147 @@
+(************** Content-type: application/mathematica **************
+ CreatedBy='Mathematica 5.0'
+
+ Mathematica-Compatible Notebook
+
+This notebook can be used with any Mathematica-compatible
+application, such as Mathematica, MathReader or Publicon. The data
+for the notebook starts with the line containing stars above.
+
+To get the notebook into a Mathematica-compatible application, do
+one of the following:
+
+* Save the data starting with the line of stars above into a file
+ with a name ending in .nb, then open the file inside the
+ application;
+
+* Copy the data starting with the line of stars above to the
+ clipboard, then use the Paste menu command inside the application.
+
+Data for notebooks contains only printable 7-bit ASCII and can be
+sent directly in email or through ftp in text mode. Newlines can be
+CR, LF or CRLF (Unix, Macintosh or MS-DOS style).
+
+NOTE: If you modify the data for this notebook not in a Mathematica-
+compatible application, you must delete the line below containing
+the word CacheID, otherwise Mathematica-compatible applications may
+try to use invalid cache data.
+
+For more information on notebooks and Mathematica-compatible
+applications, contact Wolfram Research:
+ web: http://www.wolfram.com
+ email: info@wolfram.com
+ phone: +1-217-398-0700 (U.S.)
+
+Notebook reader applications are available free of charge from
+Wolfram Research.
+*******************************************************************)
+
+(*CacheID: 232*)
+
+
+(*NotebookFileLineBreakTest
+NotebookFileLineBreakTest*)
+(*NotebookOptionsPosition[ 2986, 97]*)
+(*NotebookOutlinePosition[ 3685, 120]*)
+(* CellTagsIndexPosition[ 3641, 116]*)
+(*WindowFrame->Normal*)
+
+
+
+Notebook[{
+Cell[BoxData[
+ \(Clear[x, y, n1, n2, m1, m2]\)], "Input"],
+
+Cell[CellGroupData[{
+
+Cell[BoxData[{
+ \(u1[n1_, x_] = \
+ HermiteH[n1, \(\@2\) \((x)\)/\((w)\)]\ *\
+ Exp[\(-\[ImaginaryI]\) \(k\ \((x)\)^2\)\/\(2\ R\)\ - \ \
+\((x)\)^2\/\((w)\)^2]\ *\ \((2/\[Pi])\)\^\(1/4\)/\((2^n1\ \(n1!\)\ \
+w)\)\^\(1/2\)\n\), "\n",
+ \(\(u2[n2_, x_] = \
+ HermiteH[n2, \(\@2\) x/w]\ *\
+ Exp[\(-\[ImaginaryI]\) \(k\ x^2\)\/\(2\ R\)\ - \
+ x^2\/w^2]*\((2/\[Pi])\)\^\(1/4\)/\((2^n2\ \(n2!\)\ \
+w)\)\^\(1/2\);\)\)}], "Input"],
+
+Cell[BoxData[
+ \(\(\[ExponentialE]\^\(\(-\(\(\[ImaginaryI]\ k\ x\^2\)\/\(2\ R\)\)\) - \
+x\^2\/w\^2\)\ \((2\/\[Pi])\)\^\(1/4\)\ HermiteH[n1, \(\@2\ \
+x\)\/w]\)\/\@\(2\^n1\ w\ \(n1!\)\)\)], "Output"]
+}, Open ]],
+
+Cell[CellGroupData[{
+
+Cell[BoxData[
+ \(Simplify[
+ Integrate[
+ Conjugate[u1[1, x]]*
+ u2[1, x], {x, \(-\[Infinity]\), \[Infinity]}], {b > 0, a > 0,
+ k > 0, R > 0, w > 0}]\)], "Input"],
+
+Cell[BoxData[
+ \(1\)], "Output"]
+}, Open ]],
+
+Cell[CellGroupData[{
+
+Cell[BoxData[{
+ \(\(n = {1, 2, 3, 4, 5};\)\), "\n",
+ \(2^\((n - 1)\)\ \(n!\)\)}], "Input"],
+
+Cell[BoxData[
+ \({1, 4, 24, 192, 1920}\)], "Output"]
+}, Open ]]
+},
+FrontEndVersion->"5.0 for Microsoft Windows",
+ScreenRectangle->{{0, 1600}, {0, 1111}},
+WindowSize->{749, 819},
+WindowMargins->{{221, Automatic}, {Automatic, 94}},
+Background->RGBColor[0.988235, 0.996078, 0.686275]
+]
+
+(*******************************************************************
+Cached data follows. If you edit this Notebook file directly, not
+using Mathematica, you must remove the line containing CacheID at
+the top of the file. The cache data will then be recreated when
+you save this file from within Mathematica.
+*******************************************************************)
+
+(*CellTagsOutline
+CellTagsIndex->{}
+*)
+
+(*CellTagsIndex
+CellTagsIndex->{}
+*)
+
+(*NotebookFileOutline
+Notebook[{
+Cell[1754, 51, 60, 1, 35, "Input"],
+
+Cell[CellGroupData[{
+Cell[1839, 56, 470, 10, 205, "Input"],
+Cell[2312, 68, 200, 3, 74, "Output"]
+}, Open ]],
+
+Cell[CellGroupData[{
+Cell[2549, 76, 191, 5, 61, "Input"],
+Cell[2743, 83, 35, 1, 34, "Output"]
+}, Open ]],
+
+Cell[CellGroupData[{
+Cell[2815, 89, 97, 2, 61, "Input"],
+Cell[2915, 93, 55, 1, 34, "Output"]
+}, Open ]]
+}
+]
+*)
+
+
+
+(*******************************************************************
+End of Mathematica Notebook file.
+*******************************************************************)
+
diff --git a/misc/incomplete/Hermite_overlap.m b/misc/incomplete/Hermite_overlap.m
new file mode 100644
index 0000000..22c854a
--- /dev/null
+++ b/misc/incomplete/Hermite_overlap.m
@@ -0,0 +1,17 @@
+function cAB=Hermite_overlap(paramsA,paramsB)
+
+lA=params(:,1);
+mA=params(:,2);
+qA=params(:,3);
+lambda=paramsA(:,4);
+
+lB=params(:,1);
+mB=params(:,2);
+qB=params(:,3);
+
+
+q0A=i*imag(qA);
+q0B=i*imag(qB);
+
+
+
diff --git a/misc/incomplete/optics_code.txt b/misc/incomplete/optics_code.txt
new file mode 100644
index 0000000..f9b40d5
--- /dev/null
+++ b/misc/incomplete/optics_code.txt
@@ -0,0 +1,8 @@
+
+By specifying the reflection coefficient at each cavity mirror
+as an external function, we can couple cavities together. The reflection function can include
+an input field such as from an input beam or an attached cavity.
+
+
+
+
diff --git a/misc/incomplete/prop_fft1.m b/misc/incomplete/prop_fft1.m
new file mode 100644
index 0000000..5ec7cf1
--- /dev/null
+++ b/misc/incomplete/prop_fft1.m
@@ -0,0 +1,2 @@
+% Uses a 1 dimensional fourier transform to propagate an axially symmetric field.
+function prop_fft1(); \ No newline at end of file
diff --git a/misc/r2f/CVI_BICC_BK7_r2f_index.txt b/misc/r2f/CVI_BICC_BK7_r2f_index.txt
new file mode 100644
index 0000000..db98963
--- /dev/null
+++ b/misc/r2f/CVI_BICC_BK7_r2f_index.txt
@@ -0,0 +1,34 @@
+%R.O.C. f for 1064nm
+%[mm] [mm]
+5.5 -5.1
+8.6 -8.2
+10.8 -10.3
+12.7 -12.2
+20.9 -20.3
+23.4 -22.9
+26.1 -25.4
+26.1 -25.4
+26.1 -25.4
+26.4 -25.7
+51.8 -50.8
+51.8 -50.8
+77.6 -76.3
+103.4 -101.7
+103.4 -101.6
+103.4 -101.7
+129.1 -127.1
+154.9 -152.3
+206.4 -203.3
+206.4 -203.3
+206.4 -203.3
+309.4 -305.3
+309.4 -305.0
+309.4 -305.3
+412.4 -407.0
+412.4 -406.7
+412.4 -407.0
+515.8 -509.0
+515.8 -508.7
+618.4 -610.3
+618.4 -610.0
+618.4 -610.3
diff --git a/misc/r2f/CVI_BICC_SIO2_r2f_index.txt b/misc/r2f/CVI_BICC_SIO2_r2f_index.txt
new file mode 100644
index 0000000..2209be6
--- /dev/null
+++ b/misc/r2f/CVI_BICC_SIO2_r2f_index.txt
@@ -0,0 +1,28 @@
+%R.O.C. f for 1064nm
+%[mm] [mm]
+20.9 -22.9
+1030.5 -1145.9
+1030.5 -1145.9
+26.1 -28.7
+1030.5 -1145.6
+36.4 -40.1
+51.8 -57.3
+51.8 -57.3
+51.8 -57.3
+72.5 -80.3
+77.6 -85.9
+103.4 -114.5
+103.4 -114.6
+154.9 -171.7
+154.9 -172.3
+206.4 -229.2
+206.4 -229.5
+257.9 -286.8
+257.9 -286.8
+412.4 -458.3
+412.4 -458.3
+515.8 -573.6
+515.8 -573.2
+515.8 -573.6
+618.4 -687.3
+257.9 -286.5
diff --git a/misc/r2f/CVI_BICX_BK7_r2f_index.txt b/misc/r2f/CVI_BICX_BK7_r2f_index.txt
new file mode 100644
index 0000000..beec1a5
--- /dev/null
+++ b/misc/r2f/CVI_BICX_BK7_r2f_index.txt
@@ -0,0 +1,105 @@
+%R.O.C. f for 1064nm
+%[mm] [mm]
+9.4 10.1
+9.8 10.1
+9.7 10.2
+12.5 13.2
+14.4 15.3
+14.9 15.2
+17.4 18.2
+18.8 19.3
+19.7 20.3
+21.4 22.3
+25.2 25.4
+25.2 25.4
+25.5 25.8
+25.0 25.4
+25.1 25.8
+24.2 25.4
+23.9 25.4
+24.5 25.8
+25.3 25.4
+29.8 30.5
+34.9 35.6
+35.6 35.5
+38.1 38.7
+37.0 38.7
+40.2 40.7
+51.0 50.7
+51.0 50.8
+50.7 50.8
+50.6 50.8
+50.6 50.8
+49.3 50.9
+48.9 50.8
+48.9 50.8
+51.2 50.9
+49.3 51.6
+61.3 60.9
+61.0 61.0
+60.4 61.0
+61.8 61.3
+63.4 64.5
+76.8 76.2
+76.6 76.3
+76.6 76.3
+76.1 76.2
+76 76.3
+75.4 76.2
+77.3 77.0
+77.3 77.4
+76.5 77.5
+7.7 8.2
+76.9 81.7
+81.8 81.3
+80.8 81.3
+92.0 91.5
+102.7 101.7
+102.6 101.7
+102.4 101.8
+102.1 101.7
+102.1 101.7
+101.6 101.6
+101.6 101.6
+128.4 127.1
+128.8 127.5
+128.2 127.2
+128.2 127.2
+128.0 127.1
+127.7 127.1
+127.5 127.0
+128.4 127.1
+150.0 149.7
+154.0 152.7
+153.7 152.7
+153.4 152.5
+190.0 188.7
+205.7 203.3
+205.7 203.4
+205.6 203.5
+205.6 203.5
+205.4 203.4
+205.2 203.6
+205.2 203.3
+205.7 203.3
+206.6 205.3
+257.1 254.2
+256.8 254.2
+308.5 304.8
+308.5 304.8
+308.5 305.2
+360.0 355.8
+360.0 355.9
+411.5 406.5
+411.5 406.7
+514.6 508.2
+514.6 508.3
+514.6 508.4
+617.6 610.0
+1029.8 1016.7
+1029.8 1016.7
+1029.8 1016.7
+2006.6 1981.6
+2060 2033.4
+2060.0 2033.2
+2060.0 2033.2
diff --git a/misc/r2f/CVI_BICX_SIO2_r2f_index.txt b/misc/r2f/CVI_BICX_SIO2_r2f_index.txt
new file mode 100644
index 0000000..ac88b8d
--- /dev/null
+++ b/misc/r2f/CVI_BICX_SIO2_r2f_index.txt
@@ -0,0 +1,62 @@
+%R.O.C. f for 1064nm
+%[mm] [mm]
+76.9 85.9
+14.4 17.1
+17.4 20.5
+19.7 22.8
+19.1 22.8
+21.4 25.0
+25.2 28.6
+25.0 28.6
+23.9 28.4
+25.5 29.0
+29.8 34.3
+35.6 40.0
+35.4 40.0
+35.2 40.0
+38.1 43.5
+51.1 57.2
+51.0 57.2
+50.6 57.2
+49.3 57.0
+48.9 57.0
+61.4 68.7
+61.0 68.6
+64.4 72.7
+76.8 85.9
+76.6 85.9
+76.1 85.8
+75.5 85.8
+75.4 85.8
+91.2 102.9
+102.7 114.6
+102.4 114.5
+102.4 114.3
+102.1 114.5
+308.5 343.8
+102.5 114.5
+101.6 114.4
+514.6 572.7
+572.7 637.3
+1029.8 1145.6
+1029.8 1145.6
+1029.8 1145.6
+2060.0 2291.1
+2060.0 2291.1
+103.4 115.3
+103.1 116.3
+128.4 143.2
+128.2 143.1
+128.0 143.2
+127.5 143.0
+127.9 143.1
+128.7 144.3
+154.0 171.7
+153.7 171.7
+153.4 171.8
+205.7 229.1
+205.6 229.1
+205.6 229.1
+205.4 229.0
+205.2 229.1
+256.8 286.3
diff --git a/misc/r2f/CVI_PLCC_BK7_r2f_index.txt b/misc/r2f/CVI_PLCC_BK7_r2f_index.txt
new file mode 100644
index 0000000..0135840
--- /dev/null
+++ b/misc/r2f/CVI_PLCC_BK7_r2f_index.txt
@@ -0,0 +1,52 @@
+%R.O.C. f for 1064nm
+%[mm] [mm]
+103.4 -204.1
+128.8 -254.2
+128.8 -254.2
+130.8 -258.2
+207.7 -410.0
+257.5 -508.3
+257.5 -508.3
+309.1 -610.1
+309.1 -610.1
+10.3 -20.3
+12.9 -25.5
+25.8 -50.9
+12.9 -25.5
+25.8 -50.9
+15.5 -30.6
+25.8 -50.9
+15.5 -30.6
+25.8 -50.9
+15.5 -30.6
+26.2 -51.7
+19.6 -38.7
+30.94 -61.0
+25.8 -50.9
+38.6 -76.2
+38.6 -76.2
+38.6 -76.2
+38.6 -76.2
+38.6 -76.2
+51.5 -101.7
+51.5 -101.7
+51.5 -101.7
+51.5 -101.7
+51.5 -101.7
+51.5 -101.7
+51.5 -101.7
+64.4 -127.1
+64.4 -127.1
+64.4 -127.1
+64.4 -127.1
+77.3 -152.6
+77.3 -152.6
+77.3 -152.6
+77.3 -152.6
+90.8 -179.2
+103.0 -203.3
+103.0 -203.3
+103.0 -203.3
+103.0 -203.3
+103.0 -203.3
+103.0 -203.3
diff --git a/misc/r2f/CVI_PLCC_SIO2_r2f_index.txt b/misc/r2f/CVI_PLCC_SIO2_r2f_index.txt
new file mode 100644
index 0000000..655560c
--- /dev/null
+++ b/misc/r2f/CVI_PLCC_SIO2_r2f_index.txt
@@ -0,0 +1,58 @@
+%R.O.C. f for 1064nm
+%[mm] [mm]
+12.9 -28.7
+493.0 -1096.5
+10.3 -22.9
+11.2 -24.9
+12.9 -28.7
+13.1 -29.1
+15.5 -34.5
+19.6 -43.6
+20.6 -45.8
+25.8 -57.4
+25.8 -57.4
+25.8 -57.4
+25.8 -57.4
+25.8 -57.4
+25.8 -57.4
+38.6 -85.8
+38.6 -85.8
+39.2 -87.2
+39.2 -87.2
+51.5 -114.5
+51.5 -114.5
+51.5 -114.5
+51.5 -114.5
+51.5 -114.5
+51.5 -114.5
+64.4 -143
+64.4 -143.2
+64.4 -143.2
+64.4 -143.2
+64.4 -143.2
+77.3 -171.9
+77.3 -171.9
+77.3 -171.9
+77.3 -171.9
+103.0 -229.1
+103.0 -229.1
+103.0 -229.1
+128.8 -286.5
+128.8 -286.5
+154.5 -343.6
+154.5 -343.6
+180.3 -401.0
+180.3 -401.0
+206.6 -459.5
+206.6 -459.5
+257.5 -572.7
+257.5 -572.7
+309.1 -687.5
+309.1 -687.5
+412.1 -916.5
+515.1 -1145.6
+515.1 -1145.6
+515.1 -1145.6
+772.6 -1718.3
+772.6 -1718.3
+772.6 -1718.3
diff --git a/misc/r2f/CVI_PLCX_BK7_r2f_index.txt b/misc/r2f/CVI_PLCX_BK7_r2f_index.txt
new file mode 100644
index 0000000..12440da
--- /dev/null
+++ b/misc/r2f/CVI_PLCX_BK7_r2f_index.txt
@@ -0,0 +1,150 @@
+%R.O.C. f for 1064nm
+%[mm] [mm]
+9.3 18.4
+10.3 20.3
+11.3 22.3
+8.8 17.4
+9.3 18.4
+10.3 20.3
+13.1 25.9
+51.5 101.7
+206 406.6
+1.8 3.6
+3.1 6.1
+5.2 10.3
+5.2 10.3
+6.4 12.6
+7.7 15.2
+7.7 15.2
+12.9 25.5
+12.9 25.5
+12.9 25.5
+12.9 25.5
+12.9 25.5
+15.5 30.6
+15.5 30.6
+16 31.6
+16.5 32.6
+16.5 32.6
+18 35.5
+18 35.5
+18 35.5
+18 35.5
+18 35.5
+19.6 38.7
+20.6 40.7
+20.6 40.7
+20.6 40.7
+25.8 50.9
+25.8 50.9
+25.8 50.9
+25.8 50.9
+25.8 50.9
+25.8 50.9
+25.6 50.5
+25.8 50.9
+30.9 61
+30.9 61
+30.9 61
+30.9 61
+32.5 64.1
+32.7 64.5
+36.1 71.3
+36.1 71.3
+38.6 76.2
+38.6 76.2
+38.6 76.2
+38.6 76.2
+38.6 76.2
+38.6 76.2
+39.2 77.4
+39.2 77.4
+41.2 81.3
+41.2 81.3
+43.8 86.5
+46.2 91.2
+51.5 101.7
+51.5 101.7
+51.5 101.7
+51.5 101.7
+51.5 101.7
+51.5 101.7
+54.1 106.8
+56.7 111.9
+61.8 122
+64.4 127.1
+64.4 127.1
+64.4 127.1
+64.4 127.1
+65.4 129.1
+65.4 129.1
+65.4 129.1
+67 132.2
+69.5 137.2
+72.1 142.3
+77.3 152.6
+77.3 152.6
+77.3 152.6
+77.3 152.6
+77.3 152.6
+78.5 154.9
+78.5 154.9
+82.4 162.6
+82.4 162.6
+87.6 172.9
+91.2 180
+103 203.3
+103 203.3
+103 203.3
+103 203.3
+103 203.3
+103 203.3
+128.8 254.2
+128.8 254.2
+128.8 254.2
+128.8 254.2
+129.6 255.8
+130.8 258.2
+138.4 271.3
+154.5 305
+178.5 352.3
+180.3 355.9
+180.3 355.9
+180.3 355.9
+185 365.2
+206 406.6
+206.7 408
+238.4 470.6
+250 493.5
+257.5 508.3
+257.5 508.3
+257.5 508.3
+257.5 508.3
+309.1 610.1
+309.1 610.1
+309.1 610.1
+360.6 711.8
+360.6 711.8
+386.6 762.5
+386.6 762.5
+412.1 813.4
+412.1 813.4
+463.5 914.9
+463.5 914.9
+515.1 1016.7
+515.1 1016.7
+515.1 1016.7
+772.6 1525
+772.6 1525
+1030.2 2033.4
+1030.2 2033.4
+1545 3049.5
+1545 3049.5
+2060 4066
+2060 4066
+2575 5082.6
+2575 5082.6
+3863 7624.8
+3863 7624.8
+5151 10167.1
+5151 10167.1
diff --git a/misc/r2f/CVI_PLCX_SIO2_r2f_index.txt b/misc/r2f/CVI_PLCX_SIO2_r2f_index.txt
new file mode 100644
index 0000000..ab57e02
--- /dev/null
+++ b/misc/r2f/CVI_PLCX_SIO2_r2f_index.txt
@@ -0,0 +1,104 @@
+%R.O.C. f for 1064nm
+%[mm] [mm]
+1.5 3.3
+3.1 6.9
+4.1 9.1
+5.2 11.6
+7.7 17.1
+9.3 20.7
+12.9 28.7
+12.9 28.7
+12.9 28.7
+16.0 35.6
+18.0 40.0
+20.6 45.8
+25.8 57.4
+25.8 57.4
+30.9 68.7
+30.9 68.7
+51.5 114.5
+51.5 114.5
+64.4 143.2
+64.4 143.2
+64.4 143.2
+64.4 143.2
+65.4 145.5
+65.4 145.5
+67.0 149.0
+72.1 160.4
+72.1 160.4
+77.3 171.9
+77.3 171.9
+77.3 171.9
+77.3 171.9
+82.4 183.3
+91.2 202.8
+101.0 224.6
+103.0 229.1
+103.0 229.1
+128.8 286.5
+130.8 290.9
+154.5 343.6
+180.3 401.0
+206.0 458.2
+1030.2 2291.2
+1545.0 3436.2
+2060.0 4581.5
+2575.0 5726.9
+3863.0 8591.5
+5151.0 11456.1
+5.2 11.6
+6.4 14.2
+7.7 17.1
+10.3 22.9
+12.9 28.7
+12.9 28.7
+13.1 29.1
+18.0 40.0
+19.6 43.6
+20.6 45.8
+25.8 57.4
+25.8 57.4
+30.9 68.7
+30.9 68.7
+33.7 75.0
+33.7 75.0
+38.6 85.8
+38.6 85.8
+38.6 85.8
+38.6 85.8
+41.2 91.6
+41.2 91.6
+45.8 101.9
+46.4 103.2
+51.5 114.5
+51.5 114.5
+51.5 114.5
+51.5 114.5
+61.8 137.4
+64.4 143.2
+100.0 222.4
+103.0 229.1
+103.0 229.1
+103.0 229.1
+128.8 286.5
+154.5 343.6
+154.5 343.6
+180.3 401.0
+257.5 572.7
+257.5 572.7
+257.5 572.7
+309.1 687.5
+306.0 680.6
+309.1 687.5
+309.1 687.5
+360.6 802.0
+360.6 802.0
+515.1 1145.6
+515.1 1145.6
+515.1 1145.6
+772.6 1718.3
+1030.2 2291.2
+1545.0 3436.2
+2060.0 4581.5
+2575.0 5726.9
diff --git a/misc/r2f/f2r.m b/misc/r2f/f2r.m
new file mode 100644
index 0000000..27b6e1c
--- /dev/null
+++ b/misc/r2f/f2r.m
@@ -0,0 +1,130 @@
+%---------------------------------------------------------------------------
+% SYNTAX: R=f2r(f <,lenstype>)
+% <...> indicates optional arguments
+%
+%
+% Uses a lookup table or a formula to obtain the focal length of a
+% spherical lens for 1064 nm light from the radius of curvature.
+%
+%
+%
+% INTPUT ARGUMENTS:
+% f = focal length of the lens [mm]
+% lenstype = Defines the source to use for the conversion. Can be on of
+% the following:
+%
+% cvi_plcx_bk7 -- CVI corp. plano-convex, BK7 lenses
+% cvi_bicx_bk7 -- CVI corp. bi-convex, BK7 lenses
+% cvi_plcc_bk7 -- CVI corp. plano-concave, BK7 lenses
+% cvi_bicc_bk7 -- CVI corp. bi-concave, bK7 lenses
+% cvi_plcx_sio2 -- CVI corp. plano-convex, Fused Silica lenses
+% cvi_bicx_sio2 -- CVI corp. bi-convex, Fused Silica lenses
+% cvi_plcc_sio2 -- CVI corp. plano-concave, Fused Silica lenses
+% cvi_bicc_sio2 -- CVI corp. bi-concave, Fused Silica lenses
+% default -- uses the formula R=2f.
+%
+% OUTPUT ARGUMENTS:
+% R = radius of curvature [mm]
+%
+%---------------------------------------------------------------------------
+% SYNTAX: f=f2r(f <,lenstype>)
+%-------------------------------------------------------------------------------
+
+function R=f2r(f,varargin);
+
+if nargin>=2, lenstype=varargin{1}; else lenstype='default'; end
+
+switch lower(lenstype)
+ case 'default'
+ R=f/2;
+ case 'cvi_plcx_bk7'
+ rawdata=load('CVI_PLCX_bK7_r2f_index.txt');
+ [data(:,1),sortorder]=sort(rawdata(:,2)); % f now in 1st col, in ascending order
+ data(:,2)=rawdata(sortorder',1); % R in 2nd column
+ [posn,exactmatch]=pos(data(:,1),f);
+ f_found=data(posn,1);
+ R=data(posn,2);
+ if ~exactmatch
+ disp(['f is not found in the catalog table. Closest f is ',num2str(f_found),' mm.']);
+ end
+ disp(['f = ',num2str(f_found),' -> R = ',num2str(R),' mm.']);
+ case 'cvi_bicx_bk7'
+ rawdata=load('CVI_BICX_BK7_r2f_index.txt');
+ [data(:,1),sortorder]=sort(rawdata(:,2)); % f now in 1st col, in ascending order
+ data(:,2)=rawdata(sortorder',1); % R in 2nd column
+ [posn,exactmatch]=pos(data(:,1),f);
+ f_found=data(posn,1);
+ R=data(posn,2);
+ if ~exactmatch
+ disp(['f is not found in the catalog table. Closest f is ',num2str(f_found),' mm.']);
+ end
+ disp(['f = ',num2str(f_found),' -> R = ',num2str(R),' mm.']);
+ case 'cvi_plcc_bk7'
+ rawdata=load('CVI_PLCC_bK7_r2f_index.txt');
+ [data(:,1),sortorder]=sort(rawdata(:,2)); % f now in 1st col, in ascending order
+ data(:,2)=rawdata(sortorder',1); % R in 2nd column
+ [posn,exactmatch]=pos(data(:,1),f);
+ f_found=data(posn,1);
+ R=data(posn,2);
+ if ~exactmatch
+ disp(['f is not found in the catalog table. Closest f is ',num2str(f_found),' mm.']);
+ end
+ disp(['f = ',num2str(f_found),' -> R = ',num2str(R),' mm.']);
+ case 'cvi_bicc_bk7'
+ rawdata=load('CVI_BICC_BK7_r2f_index.txt');
+ [data(:,1),sortorder]=sort(rawdata(:,2)); % f now in 1st col, in ascending order
+ data(:,2)=rawdata(sortorder',1); % R in 2nd column
+ [posn,exactmatch]=pos(data(:,1),f);
+ f_found=data(posn,1);
+ R=data(posn,2);
+ if ~exactmatch
+ disp(['f is not found in the catalog table. Closest f is ',num2str(f_found),' mm.']);
+ end
+ disp(['f = ',num2str(f_found),' -> R = ',num2str(R),' mm.']);
+ case 'cvi_plcx_sio2'
+ rawdata=load('CVI_PLCX_SIO2_r2f_index.txt');
+ [data(:,1),sortorder]=sort(rawdata(:,2)); % f now in 1st col, in ascending order
+ data(:,2)=rawdata(sortorder',1); % R in 2nd column
+ [posn,exactmatch]=pos(data(:,1),f);
+ f_found=data(posn,1);
+ R=data(posn,2);
+ if ~exactmatch
+ disp(['f is not found in the catalog table. Closest f is ',num2str(f_found),' mm.']);
+ end
+ disp(['f = ',num2str(f_found),' -> R = ',num2str(R),' mm.']);
+ case 'cvi_bicx_sio2'
+ rawdata=load('CVI_BICX_SIO2_r2f_index.txt');
+ [data(:,1),sortorder]=sort(rawdata(:,2)); % f now in 1st col, in ascending order
+ data(:,2)=rawdata(sortorder',1); % R in 2nd column
+ [posn,exactmatch]=pos(data(:,1),f);
+ f_found=data(posn,1);
+ R=data(posn,2);
+ if ~exactmatch
+ disp(['f is not found in the catalog table. Closest f is ',num2str(f_found),' mm.']);
+ end
+ disp(['f = ',num2str(f_found),' -> R = ',num2str(R),' mm.']);
+ case 'cvi_plcc_sio2'
+ rawdata=load('CVI_PLCC_SIO2_r2f_index.txt');
+ [data(:,1),sortorder]=sort(rawdata(:,2)); % f now in 1st col, in ascending order
+ data(:,2)=rawdata(sortorder',1); % R in 2nd column
+ [posn,exactmatch]=pos(data(:,1),f);
+ f_found=data(posn,1);
+ R=data(posn,2);
+ if ~exactmatch
+ disp(['f is not found in the catalog table. Closest f is ',num2str(f_found),' mm.']);
+ end
+ disp(['f = ',num2str(f_found),' -> R = ',num2str(R),' mm.']);
+ case 'cvi_bicc_sio2'
+ rawdata=load('CVI_BICC_SIO2_r2f_index.txt');
+ [data(:,1),sortorder]=sort(rawdata(:,2)); % f now in 1st col, in ascending order
+ data(:,2)=rawdata(sortorder',1); % R in 2nd column
+ [posn,exactmatch]=pos(data(:,1),f);
+ f_found=data(posn,1);
+ R=data(posn,2);
+ if ~exactmatch
+ disp(['f is not found in the catalog table. Closest f is ',num2str(f_found),' mm.']);
+ end
+ otherwise
+ error('lenstype not recognized');
+ end
+end \ No newline at end of file
diff --git a/misc/r2f/r2f.m b/misc/r2f/r2f.m
new file mode 100644
index 0000000..8d6fcdf
--- /dev/null
+++ b/misc/r2f/r2f.m
@@ -0,0 +1,130 @@
+%---------------------------------------------------------------------------
+% SYNTAX: f=r2f(R <,lenstype>)
+% <...> indicates optional arguments
+%
+%
+% Uses a lookup table or a formula to obtain the focal length of a
+% spherical lens for 1064 nm light from the radius of curvature.
+%
+%
+%
+% INTPUT ARGUMENTS:
+% R = radius of curvature [mm]
+% lenstype = Defines the source to use for the conversion. Can be on of
+% the following:
+%
+% cvi_plcx_bk7 -- CVI corp. plano-convex, BK7 lenses
+% cvi_bicx_bk7 -- CVI corp. bi-convex, BK7 lenses
+% cvi_plcc_bk7 -- CVI corp. plano-concave, BK7 lenses
+% cvi_bicc_bk7 -- CVI corp. bi-concave, bK7 lenses
+% cvi_plcx_sio2 -- CVI corp. plano-convex, Fused Silica lenses
+% cvi_bicx_sio2 -- CVI corp. bi-convex, Fused Silica lenses
+% cvi_plcc_sio2 -- CVI corp. plano-concave, Fused Silica lenses
+% cvi_bicc_sio2 -- CVI corp. bi-concave, Fused Silica lenses
+% default -- uses the formula R=2f.
+%
+% OUTPUT ARGUMENTS:
+% f = focal length of the lens [mm]
+%
+%---------------------------------------------------------------------------
+% SYNTAX: f=r2f(R <,lenstype>)
+%-------------------------------------------------------------------------------
+
+function f=r2f(R,varargin);
+
+if nargin>=2, lenstype=varargin{1}; else lenstype='default'; end
+
+switch lower(lenstype)
+ case 'default'
+ f=2*R;
+ case 'cvi_plcx_bk7'
+ rawdata=load('CVI_PLCX_bK7_r2f_index.txt');
+ [data(:,1),sortorder]=sort(rawdata(:,1)); % R now in 1st col, in ascending order
+ data(:,2)=rawdata(sortorder',2); % f in 2nd column
+ [posn,exactmatch]=pos(data(:,1),R);
+ Rfound=data(posn,1);
+ f=data(posn,2);
+ if ~exactmatch
+ disp(['R is not found in the catalog table. Closest R is ',num2str(Rfound),' mm.']);
+ end
+ disp(['R = ',num2str(Rfound),' -> R = ',num2str(f),' mm.']);
+ case 'cvi_bicx_bk7'
+ rawdata=load('CVI_BICX_BK7_r2f_index.txt');
+ [data(:,1),sortorder]=sort(rawdata(:,1)); % R now in 1st col, in ascending order
+ data(:,2)=rawdata(sortorder',2); % f in 2nd column
+ [posn,exactmatch]=pos(data(:,1),R);
+ Rfound=data(posn,1);
+ f=data(posn,2);
+ if ~exactmatch
+ disp(['R is not found in the catalog table. Closest R is ',num2str(Rfound),' mm.']);
+ end
+ disp(['R = ',num2str(Rfound),' -> R = ',num2str(f),' mm.']);
+ case 'cvi_plcc_bk7'
+ rawdata=load('CVI_PLCC_bK7_r2f_index.txt');
+ [data(:,1),sortorder]=sort(rawdata(:,1)); % R now in 1st col, in ascending order
+ data(:,2)=rawdata(sortorder',2); % f in 2nd column
+ [posn,exactmatch]=pos(data(:,1),R);
+ Rfound=data(posn,1);
+ f=data(posn,2);
+ if ~exactmatch
+ disp(['R is not found in the catalog table. Closest R is ',num2str(Rfound),' mm.']);
+ end
+ disp(['R = ',num2str(Rfound),' -> R = ',num2str(f),' mm.']);
+ case 'cvi_bicc_bk7'
+ rawdata=load('CVI_BICC_BK7_r2f_index.txt');
+ [data(:,1),sortorder]=sort(rawdata(:,1)); % R now in 1st col, in ascending order
+ data(:,2)=rawdata(sortorder',2); % f in 2nd column
+ [posn,exactmatch]=pos(data(:,1),R);
+ Rfound=data(posn,1);
+ f=data(posn,2);
+ if ~exactmatch
+ disp(['R is not found in the catalog table. Closest R is ',num2str(Rfound),' mm.']);
+ end
+ disp(['R = ',num2str(Rfound),' -> R = ',num2str(f),' mm.']);
+ case 'cvi_plcx_sio2'
+ rawdata=load('CVI_PLCX_SIO2_r2f_index.txt');
+ [data(:,1),sortorder]=sort(rawdata(:,1)); % R now in 1st col, in ascending order
+ data(:,2)=rawdata(sortorder',2); % f in 2nd column
+ [posn,exactmatch]=pos(data(:,1),R);
+ Rfound=data(posn,1);
+ f=data(posn,2);
+ if ~exactmatch
+ disp(['R is not found in the catalog table. Closest R is ',num2str(Rfound),' mm.']);
+ end
+ disp(['R = ',num2str(Rfound),' -> R = ',num2str(f),' mm.']);
+ case 'cvi_bicx_sio2'
+ rawdata=load('CVI_BICX_SIO2_r2f_index.txt');
+ [data(:,1),sortorder]=sort(rawdata(:,1)); % R now in 1st col, in ascending order
+ data(:,2)=rawdata(sortorder',2); % f in 2nd column
+ [posn,exactmatch]=pos(data(:,1),R);
+ Rfound=data(posn,1);
+ f=data(posn,2);
+ if ~exactmatch
+ disp(['R is not found in the catalog table. Closest R is ',num2str(Rfound),' mm.']);
+ end
+ disp(['R = ',num2str(Rfound),' -> R = ',num2str(f),' mm.']);
+ case 'cvi_plcc_sio2'
+ rawdata=load('CVI_PLCC_SIO2_r2f_index.txt');
+ [data(:,1),sortorder]=sort(rawdata(:,1)); % R now in 1st col, in ascending order
+ data(:,2)=rawdata(sortorder',2); % f in 2nd column
+ [posn,exactmatch]=pos(data(:,1),R);
+ Rfound=data(posn,1);
+ f=data(posn,2);
+ if ~exactmatch
+ disp(['R is not found in the catalog table. Closest R is ',num2str(Rfound),' mm.']);
+ end
+ disp(['R = ',num2str(Rfound),' -> R = ',num2str(f),' mm.']);
+ case 'cvi_bicc_sio2'
+ rawdata=load('CVI_BICC_SIO2_r2f_index.txt');
+ [data(:,1),sortorder]=sort(rawdata(:,1)); % R now in 1st col, in ascending order
+ data(:,2)=rawdata(sortorder',2); % f in 2nd column
+ [posn,exactmatch]=pos(data(:,1),R);
+ Rfound=data(posn,1);
+ f=data(posn,2);
+ if ~exactmatch
+ disp(['R is not found in the catalog table. Closest R is ',num2str(Rfound),' mm.']);
+ end
+ otherwise
+ error('lenstype not recognized');
+ end
+end \ No newline at end of file
diff --git a/opticstrain/demo_optics.txt b/opticstrain/demo_optics.txt
new file mode 100644
index 0000000..28ed4f8
--- /dev/null
+++ b/opticstrain/demo_optics.txt
@@ -0,0 +1,28 @@
+% Scatterometer Optics Chain Model
+% Author: A. Gretarsson, Jan. 2010.
+% Length Unit: millimeters
+%
+% Position Optic Values Program Control
+%
+0 index 1
+0 lambda 0.001064 pref
+0 q 0 80.8243
+0 opticdiam 12.5
+0 mode 0 0
+740.8 lens 200
+924.8 lens -100 profile
+1349.8 cavityR 800 -1.8748e-4 Inf 1000 0.9487 0.9899 push profile
+1349.8 cavityT profile
+1349.8 cavityI profile
+2500 lens -250
+2700 window 1.46 30 push
+3000 beamstop
+%
+2770 cavityT 200 0 Inf 1000 0.9 0.99 down pop
+3300 lens 50
+3500 beamstop
+%
+2500 lens 100 up up pop
+2600 lens 300
+2800 lens 100
+3500 beamstop
diff --git a/opticstrain/demo_optics.xlsx b/opticstrain/demo_optics.xlsx
new file mode 100644
index 0000000..0c02768
--- /dev/null
+++ b/opticstrain/demo_optics.xlsx
Binary files differ
diff --git a/opticstrain/opticstrain help.docx b/opticstrain/opticstrain help.docx
new file mode 100644
index 0000000..c75e348
--- /dev/null
+++ b/opticstrain/opticstrain help.docx
Binary files differ
diff --git a/opticstrain/opticstrain help.pdf b/opticstrain/opticstrain help.pdf
new file mode 100644
index 0000000..de1d0ff
--- /dev/null
+++ b/opticstrain/opticstrain help.pdf
Binary files differ
diff --git a/opticstrain/opticstrain.m b/opticstrain/opticstrain.m
new file mode 100644
index 0000000..6d9ef0e
--- /dev/null
+++ b/opticstrain/opticstrain.m
@@ -0,0 +1,349 @@
+function opticstrain(filename)
+% Models the paraxial propagation of TEM beams through an optics train specified in a text file
+%-------------------------------------------------------------------------
+% PROGRAM NAME: opticstrain
+% AUTHOR: Andri M. Gretarsson
+% UPDATES: AMG -- First complete version 1/8/2010
+%
+% SYNTAX: opticstrain(filename)
+%
+% DESCRIPTION:
+%
+% The Matlab program opticstrain.m plots the width of a Gaussian beam as a
+% function of propagation distance. The location and type of optics
+% encountered are listed in a control file with four columns: Optic location (z),
+% Type of optic, Optic parameters, Program control commands. The locations z
+% of all optics are specified with respect to the same origin. All lengths
+% should be specified in the same units as the beam parameter
+% (complex curvature) q. For example, if q is specified in millimeters,
+% so must z, and all other length parameters.
+%
+% See the file "opticstrain help.pdf" for further details.
+%
+% INPUT VARIABLES:
+% filename = name of the control file that specifies the optics chain.
+%
+% OUTPUT VARIABLES: none
+%
+% EXAMPLE: opticstrain('demo_optics.xlsx');
+%
+%-------------------------------------------------------------------------
+% SYNTAX: opticstrain(filename)
+%-------------------------------------------------------------------------
+
+% Parse the input file and if not .txt file then convert to a text file.
+[pathstr, name, ext] = fileparts(filename);
+if strcmp(ext,'.xls') || strcmp(ext,'.xlsx')
+ disp('Converting MSExcel file to text format.');
+ xls2txt(filename);
+else
+ if ~strcmp(ext,'.txt')
+ error('Filename extension must be ''.xls'', ''.xlsx'', or ''.txt''');
+ end
+end
+controlfile=[filename(1:end-length(ext)),'.txt'];
+cf=fopen(controlfile);
+
+
+% Default values of optic parameters changeable via the control file
+mode=[0,0]; % Hermite-Gaussian, TEM_00
+q=29.5262i; % Collimated beam (e.g. w=1 mm if lambda=1064 nm)
+lambda=1.064e-3; % mm (1.064 microns expressed in millimeters)
+zobj=0; % location of optic
+a=1; % amplitude of beam
+n_med=1; % index of propagation medium (usually air)
+lensdiam=25.4; % default diameter of all optics in train
+
+
+% Default values of program control parameters changeable via the control file
+profiledisp=0;
+
+% Values for internal program parameters
+num_bounces=150; % # bounces in cavity used to calculate cav. behavior
+npts=300; % #
+nxpts=500;
+yoffset=0; % y-position of optic centers in the optics train figure
+zoffset=0; % z-...
+linespacing=1.25; % Spacing between optics train branches in units of lensdiam
+ctemp=[0;0;Inf;Inf;0;0;0;0;1.46;n_med;n_med;0;0]; % defaults for cavity in case length(values)<12 when cavity is called
+
+% Initialize variables
+xdom=linspace(-lensdiam/4,lensdiam/4,nxpts);
+linefeed=(max(xdom)-min(xdom))*linespacing;
+try close(1); end
+trainfig=figure(1); % open a new optics train figure
+fignum=1;
+controlkey={}; % structure stores the control command strings
+bd=0; % branch depth
+zstore=[]; qstore=[]; % heap for storing the beam parameters
+linenum=0; commandnum=0; % used in parsing the command file and command strings
+
+cline=fgetl(cf); % get the first control file line
+while cline ~= -1
+ linenum=linenum+1;
+ cline=strtrim(cline); % remove spaces
+ if ~isempty(cline) && cline(1)~='%' % ignore empty lines and lines starting with '%'
+ commandnum=commandnum+1;
+
+ % PARSE THE CONTROL FILE INPUT LINE
+ cline(cline==','|cline==';')=' '; % Replace punctuation with spaces
+ oldz=zobj; % oldz is the position of the last optic
+ [zobj n ee nn]=sscanf(cline,'%f'); cline=cline(nn:end); % zobj is the pos. of the current optic
+ [object n ee nn]=sscanf(cline,'%s',1); cline=cline(nn:end); % get type of optic
+ [values n ee nn]=sscanf(cline,'%f'); cline=cline(nn:end); % get optic parameters
+ temp=' ';
+ if oldz==zobj, k=length(controlkey); else k=0; controlkey={}; end % all control keys at same z-location are used simultaneously
+ while ~isempty(temp) % Parse control commands into cell string array
+ k=k+1;
+ [temp n ee nn]=sscanf(cline,'%s',1); cline=cline(nn:end); % read in next string (spaces are separators) and then remove it from the line
+ if ~isempty(temp), controlkey(k,1)={temp}; end %#ok<AGROW> %Then store the control key in the control key structure
+ end
+
+ % PARSE CONTROL KEY TO GET PROGRAM ACTIONS REQUESTED
+ if sum(strcmp(controlkey,'profile')),profiledisp=1; % look for the word "profile" in the control key list
+ else profiledisp=0; end
+ if sum(strcmp(controlkey,'pref')), a=1; end % "pref"
+ yoffset=yoffset-sum(strcmp(controlkey,'down'))*linefeed; % "down"
+ yoffset=yoffset+sum(strcmp(controlkey,'up'))*linefeed; % "up"
+ if sum(strcmp(controlkey,'pop')) % "pop" ("push" is handled at the end of this loop)
+ q=qstore(:,bd);
+ oldz=zstore(:,bd);
+ bd=bd-1;
+ qstore=qstore(:,1:bd);
+ zstore=zstore(:,1:bd);
+ end
+
+ % PERFORM ACTIONS APPROPRIATE TO THE OPTIC SPECIFIED
+
+ % lambda
+ if strcmp(object,'lambda'), lambda=values;
+
+ % mode
+ elseif strcmp(object,'mode'), mode=values;
+
+ %lens diameter set
+ elseif strcmp(object,'opticdiam'), lensdiam=values;
+
+ % q set
+ elseif strcmp(object,'q'), q=values(1)+i*values(2);
+
+ % index set
+ elseif strcmp(object,'index')||strcmp(object,'nmedium') , n_med=values;
+
+ % lens
+ elseif strcmp(object,'lens'),
+ if length(values)>1, lensdiam=values(2); end
+ figure(trainfig); hold on;
+ if ~isempty(oldz) % when a previous optic was present in figure
+ zdom=linspace(0,abs(zobj-oldz),npts); % domain over which to plot beam
+ beamplot(q,zdom,oldz,yoffset,0,n_med,lambda); % oldz is the zoffset (z-origin) for the beam plotting.
+ plot([zdom(1),zdom(end)]+oldz,[0,0]+yoffset,'k:');
+ [q,a]=prop(q,free(zobj-oldz),mode,a); % update the beam parameters to reach the new optic
+ end
+ lensplot([lensdiam values(1)/2],5,zobj,yoffset); % draw the new optic
+ xlabel('z'); ylabel('r');
+ [q,a]=prop(q,lens(values(1)),mode,a); % uptdate the beam param's to propagate through the new optic
+
+
+ % mirror
+ elseif strcmp(object,'mirr'), [q,a]=prop(q,mirr(values)*free(zobj-oldz),mode,a);
+ if length(values)>1, lensdiam=values(2); end
+ figure(trainfig); hold on;
+ if ~isempty(oldz)
+ zdom=linspace(0,abs(zobj-oldz),npts);
+ beamplot(q,zdom,oldz,yoffset,0,n_med,lambda);
+ plot([zdom(1),zdom(end)]+oldz,[0,0]+yoffset,'k:');
+ plot([zdom(1),zdom(end)]+oldz,[0,0]+yoffset,'k:');
+ [q,a]=prop(q,free(zobj-oldz),mode,a);
+ end
+ lensplot(lensdiam,0,zobj,yoffset);
+ xlabel('z'); ylabel('r');
+ [q,a]=prop(q,lens(values(1)),mode,a);
+
+
+ % window
+ elseif strcmp(object,'window')
+ zdomwin=linspace(0,values(2),npts);
+ if ~isempty(oldz)
+ zdom=linspace(0,abs(zobj-oldz),npts);
+ beamplot(q,zdom,oldz,yoffset,0,n_med,lambda);
+ plot([zdom(1),zdom(end)]+oldz,[0,0]+yoffset,'k:');
+ [q,a]=prop(q,free(zobj-oldz),mode,a);
+ end
+ [q,a]=prop(q,fdie(n_med,values(1)),mode,a);
+ beamplot(q,zdomwin,zobj,yoffset,0,values(1),lambda);
+ [q,a]=prop(q,fdie(values(1),n_med)*free(values(2)),mode,a);
+ plot([zdomwin(1),zdomwin(end)]+zobj,[0,0]+yoffset,'k:');
+ xlabel('z'); ylabel('r');
+ plot([zobj zobj],[-lensdiam/2 lensdiam/2]+yoffset,'k-');
+ plot([zobj+values(2) zobj+values(2)],[-lensdiam/2 lensdiam/2]+yoffset,'k-');
+ plot([zobj zobj+values(2)],[lensdiam/2 lensdiam/2]+yoffset,'k-');
+ plot([zobj zobj+values(2)],[-lensdiam/2 -lensdiam/2]+yoffset,'k-');
+ zobj=zobj+values(2);
+
+ % beamstop
+ elseif strcmp(object,'beamstop')
+ zdom=linspace(0,abs(zobj-oldz),npts);
+ if ~isempty(oldz)
+ beamplot(q,zdom,oldz,yoffset,0,n_med,lambda);
+ plot([zdom(1),zdom(end)]+oldz,[0,0]+yoffset,'k:');
+ [q,a]=prop(q,free(zobj-oldz),mode,a);
+ end
+ xlabel('z'); ylabel('r');
+ plot([zobj zobj],[-lensdiam/2 lensdiam/2]+yoffset,'k-');
+
+ % cavity
+ elseif strcmp(object(1:end-1),'cavity')||strcmp(object,'cavity')
+ if ~isempty(values) % if no values submitted, use zcav, qrefl, qinside and qtrans from last cavity call
+ zcav=zobj;
+ cvals=[values;ctemp(length(values)+1:end)]; % use default values for cavity parameters not specified
+ L=round(cvals(1)/lambda)*lambda+cvals(2); % round cavity length to an integer number of wavelengths and add dL
+ figure(trainfig); hold on;
+ if ~isempty(oldz)
+ zdom=linspace(0,abs(zcav-oldz),npts);
+ beamplot(q,zdom,oldz,yoffset,0,n_med,lambda);
+ plot([zdom(1),zdom(end)]+oldz,[0,0]+yoffset,'k:');
+ end
+ lensplot(lensdiam,0,zcav,yoffset);
+ lensplot(lensdiam,0,zcav+L,yoffset);
+ plot([zcav, zcav+L],[0,0]+yoffset,'k:');
+ xlabel('z'); ylabel('r');
+ if ~isempty(oldz)
+ [q,a]=prop(q,free(zcav-oldz),mode,a);
+ end
+ [qrefl,qtrans,qinside,arefl,atrans,ainside]=...
+ cav(q,mode(1),mode(2),lambda,L,cvals(3),cvals(4),...
+ cvals(5),cvals(6),cvals(7),cvals(8),num_bounces,...
+ [cvals(9),cvals(10),cvals(11)],[cvals(12),cvals(13)],a);
+ zin=HermiteGaussianE([mode(1),mode(2),... % field profile of input beam to the cavity
+ q,lambda,a],xdom);
+ pin=trapz(xdom,abs(zin).^2);
+ uno=ones(size(qrefl));
+ else
+ zobj=zcav; % if no cavity parameters revert to the z of the last cavity results (qref, qtrans, etc. still in memory)
+ end
+
+ % cavityI
+ if strcmp(object,'cavityI')
+ qinputbeam=prop(q,sdie(cvals(3),cvals(9),cvals(10))*...
+ free(cvals(12))*fdie(cvals(11),cvals(9)),mode,a);
+ q=sum(qinside.*ainside)./sum(ainside);
+ a=sum(ainside);
+ aa=ainside; qq=qinside; % contains params for _each_ traversal in cavity. Used during plotting.
+ zobjnew=zcav+cvals(12);
+
+ % cavityR
+ elseif strcmp(object,'cavityR')
+ qinputbeam=q;
+ a=sum(arefl);
+ aa=arefl; qq=qrefl; zobjnew=zcav;
+
+ % cavityI
+ else q=sum(qtrans.*atrans)./sum(atrans);
+ qinputbeam=prop(q,sdie(cvals(4),cvals(10),cvals(9))*... % end mirror
+ free(cvals(13))*fdie(cvals(9),cvals(11))*...
+ free(L)*... % cavity traversal
+ sdie(cvals(3),cvals(9),cvals(10))*free(cvals(12))*... % input mirror
+ fdie(cvals(11),cvals(9)),mode,a);
+ a=sum(atrans);
+ aa=atrans; qq=qtrans; zobjnew=zcav+L+cvals(12)+cvals(13);
+ end
+
+ if profiledisp % cavity profile display must be handled separately due to use of qq, etc.
+ fignum=fignum+1;
+ figure(fignum);
+ z=sum(nan2zero(HermiteGaussianE([mode(1)*uno,mode(2)*uno,...
+ qq,lambda*uno,aa],xdom)),2);
+ p=trapz(xdom,abs(z).^2);
+ trunclogic=abs(xdom)<2.5*w_(qq(1),lambda); xdomtrunc=xdom(trunclogic);
+ ztrunc=z(trunclogic); zintrunc=zin(trunclogic);
+ ang=(unwrap(angle([zintrunc,ztrunc])));ang=ang-ang(round(size(ang,1)/2),1);
+ ang(:,2)=ang(:,2)-floor(ang(round(size(ang,1)/2),2)/2/pi)*2*pi;
+ [hax,h1,h2]=plotyy(xdom,abs([z,zin]).^2,xdomtrunc,ang);
+ set(hax(2),'xaxislocation','top'); fighandle=get(hax(1),'parent');
+ set(h1,'linewidth',2); set(h2,'linestyle',':');
+ axchil=get(hax(1),'children');
+ set(hax(1),'children',axchil(end:-1:1),'color','none','box','off');
+ set(hax(2),'color','w');
+ figchil=get(fighandle,'children'); set(fighandle,'children',figchil(end:-1:1));
+ xlabel('Radial position'); ylabel('Intensity (power/area)');
+ hleg1=legend(hax(1),'Input Intens.','Intensity',2);
+ hleg2=legend(hax(2),'Input Phase','Phase',1);
+ origfont=get(hax(2),'fontname');
+ set(get(hax(2),'Ylabel'),'String','Phase (radians)')
+ ypiticks(hax(2),-250:1:250);
+ set(hleg1,'color','w'); set(hleg2,'color','w','fontname',origfont);
+ if length(num2str(zobj,'%0.2f'))>=9,
+ figtext(0.5,1.5,['z = ',num2str(zobjnew,'%0.2e')]);
+ else
+ figtext(0.5,1.5,['z = ',num2str(zobjnew,'%0.2f')]);
+ end
+ figtext(0.5,1,['P/P_{in} = ',num2str(p/pin,'%0.2g')]);
+ hold off;
+ end
+ figure(trainfig); hold on;
+ zdom=linspace(0,abs(L),npts);
+ h=beamplot(qinside(2:end),zdom,zcav,yoffset,0,n_med,lambda); hold on;
+ cc=colormap; set(h,'color',cc(1,:));
+ lensplot(lensdiam,0,zcav,yoffset);
+ if ~isempty(oldz)
+ plot([zdom(1),zdom(end)]+oldz,[0,0]+yoffset,'k:');
+ end
+
+
+ zobj=zobjnew;
+
+ % optic not recognized
+ else error(['Optic in line ',num2str(linenum),...
+ ' of the control file ''',controlfile,...
+ ''' was not recognized. Check syntax.']);
+ end
+
+ % DISPLAY BEAM PROFILE (for all optics other than "cavity")
+ if profiledisp && ~(strcmp(object(1:end-1),'cavity')||strcmp(object,'cavity'))
+ fignum=fignum+1; figure(fignum);
+ z=nan2zero(HermiteGaussianE([mode(1),mode(2),q,lambda,a],xdom));
+ p=trapz(xdom,abs(z).^2);
+ trunclogic=abs(xdom)<2.5*w_(q(1),lambda); xdomtrunc=xdom(trunclogic);
+ ztrunc=z(trunclogic);
+ ang=(unwrap(angle(ztrunc))); ang=ang-ang(round(size(ang,1)/2),1);
+ ang=ang-floor(ang(round(size(ang,1)/2))/2/pi)*2*pi;
+ [hax,h1,h2]=plotyy(xdom,abs(z).^2,xdomtrunc,ang);
+ set(hax(2),'xaxislocation','top'); fighandle=get(hax(1),'parent');
+ set(h1,'linewidth',2); set(h2,'linestyle',':');
+ axchil=get(hax(1),'children');
+ set(hax(1),'color','none','box','off');
+ set(hax(2),'color','w');
+ figchil=get(fighandle,'children'); set(fighandle,'children',figchil(end:-1:1));
+ xlabel('Radial position'); ylabel('Intensity (power/area)');
+ hleg1=legend(hax(1),'Intensity',2);
+ hleg2=legend(hax(2),'Phase',1);
+ origfont=get(hax(2),'fontname');
+ set(get(hax(2),'Ylabel'),'String','Phase (radians)')
+ ypiticks(hax(2),-250:1:250);
+ set(hleg1,'color','w'); set(hleg2,'color','w','fontname',origfont);
+ if length(num2str(zobj,'%0.2f'))>=9,
+ figtext(0.5,1.5,['z = ',num2str(zobj,'%0.2e')]);
+ else
+ figtext(0.5,1.5,['z = ',num2str(zobj,'%0.2f')]);
+ end
+ hold off;
+ end
+
+ % PARSE CONTROL KEY for program actions to be performed after beam propagation calculation.
+ % Store (push) onto the stack the z-location in the beam.
+ if sum(strcmp(controlkey,'push'))
+ bd=bd+1;
+ qstore(:,bd)=q;
+ zstore(:,bd)=zobj;
+ end
+
+ end
+ cline=fgetl(cf);
+end
+
+% Clean up
+try fclose(cf); end
+figure(trainfig); hold off;
+
+
diff --git a/sharedfiles/dispmat.m b/sharedfiles/dispmat.m
new file mode 100644
index 0000000..8b57818
--- /dev/null
+++ b/sharedfiles/dispmat.m
@@ -0,0 +1,51 @@
+%---------------------------------------------------------------
+% Displays a numeric matrix in a more readable format than
+% the one with which Matlab normally displays matrixes.
+% If filename is specified, then the matrix is written to
+% a text file. If specified, the format can be controlled
+% via the format argument which has the same form as the
+% FORMAT argument in sprintf.
+%
+% SYNTAX: dispmat(matrix <,filename,format,writeflag>);
+%
+%---------------------------------------------------------------
+% SYNTAX: dispmat(matrix<,format,filename,writeflag>);
+%---------------------------------------------------------------
+
+function dispmat(matrix,varargin);
+
+errorstate=0;
+if nargin==1
+ disp(num2str(matrix));
+end
+if nargin>=4, writeflag=varargin{3}; else writeflag='w'; end
+
+if nargin>=3
+ filename=varargin{2};
+ fid=fopen(filename,writeflag);
+ if ~isempty(varargin{1})
+ format=varargin{1};
+ for s=1:size(matrix,1)
+ matrow=num2str(matrix(s,:),format);
+ fprintf(fid,'%s\n',matrow);
+ end
+ else
+ for s=1:size(matrix,1)
+ matrow=num2str(matrix(s,:));
+ fprintf(fid,'%s\n',matrow);
+ end
+ end
+ fclose(fid);
+ errorstate=fid;
+end
+
+if nargin==2
+ format=varargin{1};
+ for s=1:size(matrix,1)
+ matrow=num2str(matrix(s,:),format);
+ fprintf('%s\n',matrow);
+ end
+ end
+end
+
+
diff --git a/sharedfiles/fact.m b/sharedfiles/fact.m
new file mode 100644
index 0000000..b7f7cb2
--- /dev/null
+++ b/sharedfiles/fact.m
@@ -0,0 +1,10 @@
+% Vector form of factorial.
+% For some reason the function "factorial" can't act on vectors.
+% 6/24/03
+
+function y=fact(x);
+
+y=[];
+for s=1:length(x)
+ y(s)=factorial(x(s));
+end \ No newline at end of file
diff --git a/sharedfiles/figtext.m b/sharedfiles/figtext.m
new file mode 100644
index 0000000..e828f16
--- /dev/null
+++ b/sharedfiles/figtext.m
@@ -0,0 +1,61 @@
+%---------------------------------------------------------------
+% PROGRAM: figtext
+% DATE: 4/15/03
+% AUTHOR: Andri M. Gretarsson
+%
+% SYNTAX: [xcoord,ycoord,h]=figtext(x,y,textstring <,fontsize>);
+% or h=figtext3D(x,y,textstring <,fontsize>);
+%
+% arguments in <...> are optional
+%
+% Writes the text in the string textstring to the current figure
+% at the location given by x,y. The location is specified on a
+% 10x10 grid with x=0, y=0 corresponding to the lower left hand
+% corner of the figure. The font size of the text can be optionally
+% specified (in points) by supplying the argument fontsize.
+% [xcoord,ycoord] returns the value of the axes coordinates at
+% the position specified by x,y. The third output argument h, is
+% the handle to the text written to the figure.
+%
+% Last updated: 4/15/03 by AMG
+%
+%----------------------------------------------------------------
+% SYNTAX: [xcoord,ycoord,h]=figtext(x,y,textstring <,fontsize>);
+% or h=figtext(x,y,textstring <,fontsize>);
+%----------------------------------------------------------------
+
+function varargout=figtext(x,y,textstring,varargin);
+
+xlim=get(gca,'XLim');
+ylim=get(gca,'Ylim');
+xlen=xlim(2)-xlim(1);
+ylen=ylim(2)-ylim(1);
+ndiv=10;
+
+xscale=get(gca,'XScale');
+yscale=get(gca,'YScale');
+
+if xscale(1:3)=='log'
+ xcoord=10^(log10(xlim(1))+x/ndiv*(log10(xlim(2))-log10(xlim(1))));
+else
+ xcoord=xlim(1)+x/ndiv*xlen;
+end
+if yscale(1:3)=='log'
+ ycoord=10^(log10(ylim(1))+y/ndiv*(log10(ylim(2))-log10(ylim(1))));
+else
+ ycoord=ylim(1)+y/ndiv*ylen;
+end
+
+if nargin>=4
+ h=text(xcoord,ycoord,textstring,'FontSize',varargin{1});
+else
+ h=text(xcoord,ycoord,textstring);
+end
+
+if nargout>1
+ varargout{1}=xcoord;
+ varargout{2}=ycoord;
+ varargout{4}=h;
+else
+ varargout{1}=h;
+end \ No newline at end of file
diff --git a/sharedfiles/figtext3D.m b/sharedfiles/figtext3D.m
new file mode 100644
index 0000000..a905704
--- /dev/null
+++ b/sharedfiles/figtext3D.m
@@ -0,0 +1,71 @@
+% A function for writing text to 3D graphs in a simple way.
+%--------------------------------------------------------------------------
+% PROGRAM: figtext
+% DATE: 4/15/03
+% AUTHOR: Andri M. Gretarsson
+%
+% SYNTAX: [xcoord,ycoord,zcoord,h]=figtext3D(x,y,z,textstring <,fontsize>);
+% or h=figtext3D(x,y,z,textstring <,fontsize>);
+%
+% arguments in <...> are optional
+%
+% Writes the text in the string textstring to the current figure
+% at the location given by x,y. The location is specified on a
+% 10x10 grid with x=0, y=0 corresponding to the lower left hand
+% corner of the figure. The font size of the text can be optionally
+% specified (in points) by supplying the argument fontsize.
+% [xcoord,ycoord] returns the value of the axes coordinates at
+% the position specified by x,y. The third output argument h, is
+% the handle to the text written to the figure.
+%
+% Last updated: 4/15/03 by AMG
+%
+%---------------------------------------------------------------------------
+% SYNTAX: [xcoord,ycoord,zcoord,h]=figtext3D(x,y,z,textstring <,fontsize>);
+% or h=figtext3D(x,y,z,textstring <,fontsize>);
+%---------------------------------------------------------------------------
+
+function varargout=figtext3D(x,y,z,textstring,varargin);
+
+xlim=get(gca,'XLim');
+ylim=get(gca,'Ylim');
+zlim=get(gca,'Zlim');
+xlen=xlim(2)-xlim(1);
+ylen=ylim(2)-ylim(1);
+zlen=zlim(2)-zlim(1);
+ndiv=10;
+
+xscale=get(gca,'XScale');
+yscale=get(gca,'YScale');
+zscale=get(gca,'ZScale');
+
+if xscale(1:3)=='log'
+ xcoord=10^(log10(xlim(1))+x/ndiv*(log10(xlim(2))-log10(xlim(1))));
+else
+ xcoord=xlim(1)+x/ndiv*xlen;
+end
+if yscale(1:3)=='log'
+ ycoord=10^(log10(ylim(1))+y/ndiv*(log10(ylim(2))-log10(ylim(1))));
+else
+ ycoord=ylim(1)+y/ndiv*ylen;
+end
+if zscale(1:3)=='log'
+ zcoord=10^(log10(zlim(1))+z/ndiv*(log10(zlim(2))-log10(zlim(1))));
+else
+ zcoord=zlim(1)+z/ndiv*zlen;
+end
+
+if nargin>=5
+ h=text(xcoord,ycoord,zcoord,textstring,'FontSize',varargin{1});
+else
+ h=text(xcoord,ycoord,zcoord,textstring);
+end
+
+if nargout>1
+ varargout{1}=xcoord;
+ varargout{2}=ycoord;
+ varargout{3}=zcoord;
+ varargout{4}=h;
+else
+ varargout{1}=h;
+end \ No newline at end of file
diff --git a/sharedfiles/plothorline.m b/sharedfiles/plothorline.m
new file mode 100644
index 0000000..ea9f9d6
--- /dev/null
+++ b/sharedfiles/plothorline.m
@@ -0,0 +1,101 @@
+%------------------------------------------------------------------------------
+% PROGRAM NAME: Plot horizontal lines
+% FILE: plotvertline.m
+% AUTHOR: Andri M. Gretarsson
+% DATE: 02/03/03
+%
+% SYNTAX: linehandles=plothorline(y,xmin,xmax <,marker,plotstyle>)
+%
+% Plots horizontal lines at the positions listed in the vector y. The vertical
+% lines extend from xmin to xmax and are ploted with the markerstyle and
+% color defined by marker if specified (same syntax as the marker in matlab's
+% built in function plot. Exits with hold set to off. If plotstyle is specified
+% then the plotstyle will be linear-linear, lin-log, log-lin or log-log,
+% depending on whether plotstyle is 'plot', 'semilogx', 'semilogy', or 'loglog'.
+%
+% If 'marker' is a string whose first character is an apostrophe ('),
+% the marker string in interpreted literally as part of the command, as in:
+% eval(['plot([xmin xmax],[y(i) y(i)],',marker,')']);
+%
+% If the first character of marker is not an apostrophe, the marker string is
+% just inserted into the command as usual without using eval, namely:
+% plot([xmin xmax],[y(i) y(i)],marker).
+%
+% Thus, for example:
+% marker = '''b-'',''LineWidth'',2' results in the plot command
+% plot(x,y,'b-','LineWidth',2) being evaluated.
+%
+% marker = 'b-' has the same effect as marker = '''b-''', namely
+% plot(x,y,'b-'), in the first case directly via plot(x,y,'b-') and
+% in the second case via eval(['plot(x,y,',marker,')']).
+%
+% If xmin=0 and xmax=0, then ymin and ymax are obtained from the current
+% axes.
+%
+% LAST UPDATED: 03/13/03
+%
+%-------------------------------------------------------------------------------
+% SYNTAX: linehandles=plothorline(y,xmin,xmax <,marker,plotstyle>)
+%-------------------------------------------------------------------------------
+
+function linehandles=plothorline(y,xmin,xmax,varargin);
+
+if nargin>=4, marker=varargin{1}; else marker='b-'; end
+if nargin>=5,
+ plotstyle=varargin{2};
+else plotstyle='plot';
+end
+if xmin==0 & xmax==0
+ range=get(gca,'XLim');
+ xmin=range(1);
+ xmax=range(2);
+end
+
+NextPlot_current=get(gca,'NextPlot'); % Get the original 'hold' state
+
+h=zeros(length(y),1);
+
+if plotstyle(1)=='p'
+ for i=1:length(y)
+ if marker(1)==''''
+ eval(['h(i)=plot([xmin xmax],[y(i) y(i)],',marker,')']); hold on;
+ else
+ h(i)=plot([xmin xmax],[y(i) y(i)],marker); hold on;
+ end
+ end
+else
+if plotstyle(1)=='l'
+ for i=1:length(y)
+ if marker(1)==''''
+ eval(['h(i)=loglog([xmin xmax],[y(i) y(i)],',marker,')']); hold on;
+ else
+ h(i)=loglog([xmin xmax],[y(i) y(i)],marker); hold on;
+ end
+ end
+else
+if (length(plotstyle)==8 &plotstyle(8)=='x')
+ for i=1:length(y)
+ if marker(1)==''''
+ eval(['h(i)=semilogx([xmin xmax],[y(i) y(i)],',marker,')']); hold on;
+ else
+ h(i)=semilogx([xmin xmax],[y(i) y(i)],marker); hold on;
+ end
+ end
+else
+if (length(plotstyle)==8 &plotstyle(8)=='y')
+ for i=1:length(y)
+ if marker(1)==''''
+ eval(['h(i)=semilogy([xmin xmax],[y(i) y(i)],',marker,')']); hold on;
+ else
+ h(i)=semilogy([xmin xmax],[y(i) y(i)],marker); hold on;
+ end
+ end
+end;end;end;end;
+
+if NextPlot_current(1)=='r' % reset to the original 'hold' state
+ set(gca,'NextPlot','replace')
+else
+ set(gca,'NextPlot','add');
+end
+
+linehandles=h; \ No newline at end of file
diff --git a/sharedfiles/plotvertline.m b/sharedfiles/plotvertline.m
new file mode 100644
index 0000000..aff512a
--- /dev/null
+++ b/sharedfiles/plotvertline.m
@@ -0,0 +1,102 @@
+%------------------------------------------------------------------------------
+% PROGRAM NAME: Plot vertical lines
+% FILE: plotvertline.m
+% AUTHOR: Andri M. Gretarsson
+% DATE: 02/03/03
+%
+% SYNTAX: linehandles=plotvertline(x,ymin,ymax <,marker,plotstyle>)
+%
+% Plots vertical lines at the positions listed in the vector x. The vertical
+% lines extend from ymin to ymax and are ploted with the markerstyle and
+% color defined by marker if specified (same syntax as the marker in matlab's
+% built in function plot. Exits with hold set to off. If plotstyle is specified
+% then the plotstyle will be linear-linear, lin-log, log-lin or log-log,
+% depending on whether plotstyle is 'plot', 'semilogx', 'semilogy', or 'loglog'.
+%
+% If 'marker' is a string whose first character is an apostrophe ('),
+% the marker string in interpreted literally as part of the command, as in:
+% eval(['plot([xmin xmax],[y(i) y(i)],',marker,')']);
+%
+% If the first character of marker is not an apostrophe, the marker string is
+% just inserted into the command as usual without using eval, namely:
+% plot([xmin xmax],[y(i) y(i)],marker).
+%
+% Thus, for example:
+% marker = '''b-'',''LineWidth'',2' results in the plot command
+% plot(x,y,'b-','LineWidth',2) being evaluated.
+%
+% marker = 'b-' has the same effect as marker = '''b-''', namely
+% plot(x,y,'b-'), in the first case directly via plot(x,y,'b-') and
+% in the second case via eval(['plot(x,y,',marker,')']).
+%
+% If ymin=0 and ymax=0, then ymin and ymax are obtained from the current
+% axes, and the function draws a line from the bottom to the top of the
+% current graph.
+%
+% LAST UPDATED: 03/13/03
+%
+%-------------------------------------------------------------------------------
+% SYNTAX: linehandles=plotvertline(y,xmin,xmax <,marker,plotstyle>)
+%-------------------------------------------------------------------------------
+
+function linehandles=plotvertline(x,ymin,ymax,varargin);
+
+if nargin>=4, marker=varargin{1}; else marker='b-'; end
+if nargin>=5,
+ plotstyle=varargin{2};
+else plotstyle='plot';
+end
+if ymin==0 & ymax==0
+ range=get(gca,'YLim');
+ ymin=range(1);
+ ymax=range(2);
+end
+
+NextPlot_current=get(gca,'NextPlot'); % Get the original 'hold' state
+
+h=zeros(length(x),1);
+
+if plotstyle(1)=='p'
+ for i=1:length(x)
+ if marker(1)==''''
+ eval(['h(i)=plot([x(i) x(i)],[ymin ymax],',marker,')']); hold on;
+ else
+ h(i)=plot([x(i) x(i)],[ymin ymax],marker); hold on;
+ end
+ end
+else
+if plotstyle(1)=='l'
+ for i=1:length(x)
+ if marker(1)==''''
+ eval(['h(i)=loglog([x(i) x(i)],[ymin ymax],',marker,')']); hold on;
+ else
+ h(i)=loglog([x(i) x(i)],[ymin ymax],marker); hold on;
+ end
+ end
+else
+if (length(plotstyle)==8 &plotstyle(8)=='x')
+ for i=1:length(x)
+ if marker(1)==''''
+ eval(['h(i)=semilogx([x(i) x(i)],[ymin ymax],',marker,')']); hold on;
+ else
+ h(i)=semilogx([x(i) x(i)],[ymin ymax],marker); hold on;
+ end
+ end
+else
+if (length(plotstyle)==8 &plotstyle(8)=='y')
+ for i=1:length(x)
+ if marker(1)==''''
+ eval(['h(i)=semilogy([x(i) x(i)],[ymin ymax],',marker,')']); hold on;
+ else
+ h(i)=semilogy([x(i) x(i)],[ymin ymax],marker); hold on;
+ end
+ end
+end;end;end;end;
+
+if NextPlot_current(1)=='r' % reset to the original 'hold' state
+ set(gca,'NextPlot','replace')
+else
+ set(gca,'NextPlot','add');
+end
+
+linehandles=h; \ No newline at end of file
diff --git a/sharedfiles/reverse.m b/sharedfiles/reverse.m
new file mode 100644
index 0000000..010529b
--- /dev/null
+++ b/sharedfiles/reverse.m
@@ -0,0 +1,5 @@
+% Reverses the positions of the elements of a vector
+
+function r=reverse(v);
+
+r=v([length(v):-1:1]); \ No newline at end of file
diff --git a/sharedfiles/scalemarker.m b/sharedfiles/scalemarker.m
new file mode 100644
index 0000000..88556cb
--- /dev/null
+++ b/sharedfiles/scalemarker.m
@@ -0,0 +1,32 @@
+% Puts a scale marker ("scale bar") on a plot at position (x,y). The length of the
+% marker is set by markerlength. The string textlabel usually contains the
+% "real life" length the marker is supposed to represent. The final optional
+% argument is the orientation. It should be 'h' for horizontal (default) or 'v'
+% for vertical.
+
+function [h,th]=scalemarker(x,y,markerlength,textlabel,varargin);
+
+
+if nargin>=5, orientation=varargin{1}; else orientation='h'; end
+
+xlimits=get(gca,'XLim');
+ylimits=get(gca,'YLim');
+xrange=abs(diff(xlimits));
+yrange=abs(diff(ylimits));
+
+if orientation=='h'
+ x1=x-markerlength/2;
+ x2=x+markerlength/2;
+ y1=y-yrange/90;
+ y2=y+yrange/90;
+ h=plot([x1 x2],[y y],'k-',[x1 x1],[y1 y2],'k-',[x2 x2],[y1 y2],'k-');
+ th=text(x1,y2+yrange/75,[' ',textlabel]);
+else
+ x1=x-xrange/120;
+ x2=x+xrange/120;
+ y1=y-markerlength/2;
+ y2=y+markerlength/2;
+ h=plot([x x],[y1 y2],'k-',[x1 x2],[y1 y1],'k-',[x1 x2],[y2 y2],'k-');
+ th=text(x2,y1,strvcat(textlabel,' ',' '));
+end
+
diff --git a/transverse/AiryE.m b/transverse/AiryE.m
new file mode 100644
index 0000000..b03b5ed
--- /dev/null
+++ b/transverse/AiryE.m
@@ -0,0 +1,74 @@
+%---------------------------------------------------------------
+% PROGRAM: AiryE
+% AUTHOR: Andri M. Gretarsson
+% DATE: 8/7/03
+%
+%
+% SYNTAX: E=AiryE([a,w0,L,lambda <,N>],r);
+% <,...> indicates optional argument
+%
+% Returns the Field of an Airy disk as a function of radius. The waist
+% of the beam is assumed to be at the aperture.
+%
+% a = radius of aperture
+% w0 = radius of Gaussian beam at aperture
+% L = propagation distance (axially) from aperture
+% lambda = wavelength
+% N = order to which to carry the calculation
+%
+% Last updated: 8/7/03 by AMG
+%
+%---------------------------------------------------------------
+%% SYNTAX: E=AiryE([a,w0,L,lambda <,N>],r);
+%---------------------------------------------------------------
+
+function E=AiryE(params,r)
+
+a=params(1);
+w0=params(2);
+L=params(3);
+lambda=params(4);
+if length(params)>=5, Norders=params(5); else Norders=2; end
+if Norders<1, Norders=1; end
+
+%N=a^2/L/lambda;
+%q0=i*pi*w0.^2/lambda;
+%q=q0+L;
+%E=q0/q .* exp(-i*pi*N*(r./a).^2) .* ( 1 - exp(-i*pi*N-a^2/w0^2) .* besselj(0,2*pi*N*r./a) );
+
+k=2*pi/lambda;
+F=(a/w0)^2/pi;
+R=sqrt(r.^2+L^2);
+eta=pi*F/a^2-i*k/2./R;
+gamma=-k.*r./R;
+
+
+Sum1=0;
+Sum2=0;
+for m=0:Norders-1
+ Sum1=Sum1+(-gamma/2/a./eta).^m .* besselj(m,a.*gamma);
+ Sum2=Sum2+(gamma/2/a./eta).^m + besselj(1-m,a*gamma);
+end
+
+
+A = -i*k*L/2./eta./R.^2 .* exp(-i*k.*R);
+B = exp(-gamma.^2/4./eta) - exp(-eta*a^2) .* Sum1;
+C = gamma/a./eta.*exp(-gamma.^2/4./eta) - 2*exp(-eta*a^2) .* Sum2;
+
+E= sqrt(2)/pi/w0 * A .* (B + (i*a*r./R.^2).*C);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/transverse/AiryI.m b/transverse/AiryI.m
new file mode 100644
index 0000000..d3eb610
--- /dev/null
+++ b/transverse/AiryI.m
@@ -0,0 +1,25 @@
+%---------------------------------------------------------------
+% PROGRAM: AiryI
+% AUTHOR: Andri M. Gretarsson
+% DATE: 8/7/03
+%
+%
+% SYNTAX: I=AiryI([a,w0,L,lambda <,N>],r);
+% <,...> indicates optional argument
+%
+% Returns the intensity of an Airy disk as a function of radius
+%
+% a = radius of aperture
+% w0 = radius of Gaussian beam at aperture
+% L = propagation distance (axially) from aperture
+% lambda = wavelength
+% N = order to which to carry the calculation
+% Last updated: 8/7/03 by AMG
+%
+%---------------------------------------------------------------
+%% SYNTAX: I=AiryI([a,w0,L,lambda <,N>],r);
+%---------------------------------------------------------------
+
+function I=AiryI(params,r);
+
+I=AiryE(params,r).*conj(AiryE(params,r)); \ No newline at end of file
diff --git a/transverse/AiryI_Fraunhofer.m b/transverse/AiryI_Fraunhofer.m
new file mode 100644
index 0000000..d0a55e2
--- /dev/null
+++ b/transverse/AiryI_Fraunhofer.m
@@ -0,0 +1,33 @@
+%---------------------------------------------------------------
+% PROGRAM: AiryI_Fraunhofer
+% AUTHOR: Andri M. Gretarsson
+% DATE: 1/30/06
+%
+%
+% SYNTAX: I=AiryI([a,L,lambda],r);
+% <,...> indicates optional argument
+%
+% Returns the intensity of an Airy disk as a function of radius
+% in the Fraunhofer (small aperture) and paraxial (small angle)
+% limits.
+%
+% a = radius of aperture
+% L = propagation distance (axially) from aperture
+% lambda = wavelength
+%
+% Last updated: 1/30/06 by AMG
+%---------------------------------------------------------------
+%% SYNTAX: I=AiryI_Fraunhofer([a,L,lambda],r);
+%---------------------------------------------------------------
+
+function I=AiryI(params,r);
+
+a=params(1);
+L=params(2);
+lambda=params(3);
+k=2*pi/lambda;
+
+r=(r==0)*lambda/1000+r; %Gives the limit of Bessel(1,r)/r as r->0 (can't evaluate BesselJ(1,0)/0).
+I=(2*BesselJ(1,k*a*r/L)./(k*a*r./L)).^2;
+
+%I is normalized to the intensity in the center. \ No newline at end of file
diff --git a/transverse/HermiteGaussianE.m b/transverse/HermiteGaussianE.m
new file mode 100644
index 0000000..ced8f6f
--- /dev/null
+++ b/transverse/HermiteGaussianE.m
@@ -0,0 +1,134 @@
+function z=HermiteGaussianE(params,x,varargin)
+% Returns the complex field amplitude of a single polarization Hermite-Gaussian mode.
+%----------------------------------------------------------------------------------------------
+% PROGRAM: HermiteGaussianE
+% AUTHOR: Andri M. Gretarsson
+% DATE: 6/26/03
+%
+% SYNTAX: z=HermiteGaussianE([l,m,q <,lambda,a>],x <,y>);
+% <...> indicates optional arguments
+%
+% Returns the complex field amplitude of a single polarization Hermite-Gaussian mode.
+% The domain of the function is specified in cartesian coordinates x,y.
+% If the input argument a is not specified or is equal to 1, the area under the
+% surface z(x,y) is equal to 1. If z=z(x), i.e. the one dimensional form is being used,
+% then the area under the surface formed by rotating z(x) around the z axis equals 1.
+% In short the functions are normalized and form an orthonormal basis wrt. the inner
+% product formed by multiplying two HermiteE's together and integrating over area.
+% The formula is taken from "Principles of Lasers" by Orazio Svelto, 4th ed. Section 5.5.1.3.
+%
+% Note that it is possible to specify the parameters l,m,q,a,lambda as column vectors. In that case,
+% the matrix returned z, will be a stack of 2D matrixes (i.e. a 3D matrix), where successive 2D matrixes
+% in the stack (i.e. successive layers of the 3D matrix) correpsond to successive rows of the
+% l,m,q,a,lambda columns
+%
+% INPUT ARGUMENTS:
+% ----------------
+% l,m = Hermite Gaussian mode numbers (integers, positive or zero). Can be a scalar or a column vector.
+% q = complex radius of curvature of the beam (1/q = 1/R + i*lambda/pi/w^2).
+% Can be a scalar or a column vector.
+% a = complex amplitude (includes phase, e.g. for a beam that
+% has been propageted with an ABCD matrix a = 1/(A + [B/q1])^(1+l+m) ).
+% See for example, O. Svelto, Principles of Lasers 4th ed. eqn. 4.7.30.
+% Can be a scalar or a column vector.
+% lambda = Wavelength of the light. Can be a scalar or a column vector. Default is 1064e-9;
+% x = x position vector or a 2D matrix generated by meshgrid.
+% y = y position vector or a 2D matrix generated by meshgrid.
+% If y is not specified then the default y is used:
+% if x is 1D, y=zeros(size(x)). If x is 2D, y=x.
+%
+% OUTPUT ARGUMENTS:
+% -----------------
+% z(i,j) = Complex field of the Hermite Gaussian mode with parameters l,m,... at
+% ( x(i,j),y(i,j) ). May be a vector or a matrix depending on whether
+% x and y are vectors or matrixes. If in addition, l,m,q,... are columns,
+% then z(i,j,k) will correspond to the complex field amplitude of the
+% Hermite Gaussian mode corresponding to the parameters l(k),m(k),...
+%
+% NOTES:
+% ------
+% If x and y are not vectors but matrixes generated by
+% the matlab function meshgrid, then the output variable z
+% is a matrix rather than a vector. The matrix form allows
+% the function HermiteGaussianE to have a plane as it's domain
+% rather than a curve.
+%
+% If the parameters l,m,q,p,lambda are equal length column vectors rather
+% than scalars, z is a size(x)*length(lambda) matrix. E.g. if size(x) is n*n
+% then each level z(:,:,k) is a 2D field of a Hermite Gaussian with
+% the parameters given by [l(k),m(k),q(k),lambda(k),a(k)].
+%
+% EXAMPLE 1 (2D : two TEM modes):
+% w=[0.001; 0.001];
+% xseed=[-3*max(w):max(w)/30:3*max(w)]; yseed=xseed';
+% [x,y]=meshgrid(xseed,yseed);
+% lambda = [1.064e-6 ; 1.064e-6];
+% R = [-30 ; -30];
+% q = (1./R - i* lambda./pi./w.^2).^(-1); a=[1;1];
+% l=[1;2]; m=[0;2];
+% E=HermiteGaussianE([l,m,q,lambda,a],x,y);
+% subplot(2,1,1); h1=pcolor(x,y,abs(E(:,:,1))); set(h1,'EdgeColor','none'); axis square;
+% subplot(2,1,2); h2=pcolor(x,y,abs(E(:,:,2))); set(h2,'EdgeColor','none'); axis square; shg;
+%
+% EXAMPLE 2 (1D : four TEM modes):
+% w=[1,2,3,4].'; x=[-10:0.001:10]; lambda=[1,1,1,1].'*656e-9; R=[1,1,1,1].'*1000;
+% q = (1./R - i* lambda./pi./w.^2).^(-1); a=[1,1,1,1].'; l = [0,1,2,3].'; m=[0,0,0,0].';
+% E=HermiteGaussianE([l,m,q,lambda,a],x); I=E.*conj(E); phi=angle(E);
+% plot(x,I(:,1),x,I(:,2),x,I(:,3),x,I(:,4));
+%
+% Last updated: July 18, 2004 by AMG
+%----------------------------------------------------------------------------------------------
+%% SYNTAX: z=HermiteGaussianE([l,m,q <,lambda,a>],x <,y>);
+%----------------------------------------------------------------------------------------------
+
+defaultcoord2=0;
+if nargin>=3, y=varargin{1}; else defaultcoord2=1; end
+
+if min(size(x))==1
+ if size(x,1)<size(x,2), x=x'; end %make x and y columnar
+ if defaultcoord2
+ y=zeros(size(x));
+ else
+ if size(y,1)<size(y,2), y=y'; end
+ end
+
+end
+
+if min(size(x)) > 1
+ z=zeros(size(x,1),size(x,2),size(params,1)); % need this since zeros(size(y),10) gives a 2D matrix even if y is 2D! (Matlab feature.)
+ if defaultcoord2, y=transpose(x); end
+else
+ z=zeros(length(x),size(params,1));
+end
+
+l=params(:,1);
+m=params(:,2);
+q=params(:,3);
+if size(params,2)>=4
+ lambda=params(:,4);
+else
+ lambda=1064e-9;
+end
+if size(params,2)>=5
+ a=params(:,5);
+else
+ a=ones(size(q));
+end
+
+w=w_(q,lambda);
+
+if min(size(x))>=2 % x is a matrix (2D array)
+ for u=1:size(params,1)
+ z(:,:,u) = a(u)...
+ .* sqrt((2/pi))/2^((l(u)+m(u))/2)/sqrt(factorial(l(u))*factorial(m(u)))/w(u)...
+ .* hermitepoly(l(u),sqrt(2).*x/w(u)).*hermitepoly(m(u),sqrt(2).*y/w(u))...
+ .* exp( -i*2*pi/lambda(u)*(x.^2+y.^2)/2/q(u) ) ;
+ end
+else
+ for u=1:size(params,1) % x is a vector (1D array)
+ z(:,u) = a(u)...
+ .* sqrt((2/pi))/2^((l(u)+m(u))/2)/sqrt(factorial(l(u))*factorial(m(u)))/w(u)...
+ .* hermitepoly(l(u),sqrt(2).*x/w(u)).*hermitepoly(m(u),sqrt(2).*y/w(u))...
+ .* exp( -i*2*pi/lambda(u)*(x.^2+y.^2)/2/q(u) );
+ end
+end
diff --git a/transverse/LaguerreGaussianE.m b/transverse/LaguerreGaussianE.m
new file mode 100644
index 0000000..f95985d
--- /dev/null
+++ b/transverse/LaguerreGaussianE.m
@@ -0,0 +1,189 @@
+%----------------------------------------------------------------------------------------------
+% PROGRAM: LaguerreGaussianE
+% AUTHOR: Andri M. Gretarsson
+% DATE: 6/26/03
+%
+% SYNTAX: z=LaguerreGaussianE([p,m,q <,lambda,a>],r <,theta,coordtype>);
+% <...> indicates optional arguments
+%
+% Returns the complex field amplitude of a Laguerre-Gaussian mode as a function
+% of polar coordinates r and theta. Formula adapted from A. E. Siegman,
+% "Lasers" 1st ed. eqn. 64 in Ch. 16. I leave out the gouy phase
+% factor since it is meaningless except as a relative phase difference
+% between axially separated parts of the same beam. In other words it
+% only appears when propagating the beam. The function prop.m does
+% both the q transformation and supplies the appropriate gouy phase.
+% This factor and other phase and amplitude factors can be included via the
+% complex argument a if desired. Finally, this function can also be called
+% with cartesian coordinates.
+%
+%
+% INPUT ARGUMENTS:
+% ----------------
+% p,m = Laguerre Gaussian mode numbers (column vector)
+% q = complex radius of curvature of the beam (column vector)
+% lambda= Wavelength of the light (column vector)
+% a = complex prefactor ( includes gouy phase, e.g. for a LG beam that
+% has been propageted with an ABCD matrix a = 1/(A + [B/q1])^(1+2p+m) ).
+% (column vector).
+% r = radial position vector (or matrix generated by meshgrid)
+% theta = azimuthal position vector (or matrix generated by meshgrid).
+% If r is 1D and theta is not specified the default theta is used,
+% theta=zeros(size(r)). If r is a 2D mesh theta must also be specified.
+% The function polarmesh.m can be usefule for generating the r and
+% theta meshes.
+% coordtype = (string) label for the type of coordinates supplied in r and theta. If
+% this argument is not specified or is equal to 'pol', r and theta are assumed
+% to be polar coordinates (r,theta) as described above. If on the other
+% hand coordtype='cart' then r is assumed to be the cartesian x coordinate
+% and theta the cartesian y coordinate. This can be useful e.g. if one wants to
+% specify an x or y shift in the position of the mode. (See for example
+% Laguerre_demo.m). coordtype is normally the 8th input argument but can
+% be specified as the 7th input argument instead if the default y is desired
+% (y=transpose(x)).
+%
+% OUTPUT ARGUMENTS:
+% -----------------
+% z(i,j)= Complex field of the Laguerre Gaussian mode at
+% ( r(i,j),theta(i,j) ). May be a vector or
+% a matrix depending on whether r and theta
+% are vectors or matrixes.
+%
+%
+% NOTES:
+% ------
+% If r and theta are not vectors but matrixes generated by
+% the matlab function meshgrid, then the output variable z
+% is a matrix rather than a vector. The matrix form allows
+% the function HermiteGaussianE to have a plane as it's domain
+% rather than a curve.
+%
+% If the parameters p,m,q,p,lambda are equal length column vectors rather
+% than scalars z is a size(r)*length(lambda) matrix. E.g. if size(r) is n*n
+% then each level z(:,:,k) is a 2D field of a Laguerre Gaussian with
+% the parameters given by [l(k),m(k),q(k),lambda(k),a(k)].
+%
+% EXAMPLE 1 (2D, polar domain):
+% w=[0.001; 0.001];
+% rseed=[0*max(w):max(w)/30:3*max(w)]; thetaseed=[0:360]*pi/180;
+% [r,theta]=meshgrid(rseed,thetaseed);
+% lambda = [1.064e-6 ; 1.064e-6];
+% R = [-30 ; -30];
+% q = (1./R - i* lambda./pi./w.^2).^(-1); a=[1;1];
+% p=[1;2]; m=[0;2];
+% E=LaguerreGaussianE([p,m,q,lambda,a],r,theta)+LaguerreGaussianE([p,-m,q,lambda,a],r,theta);
+% [x,y]=pol2cart(theta,r); colormap(bone);
+% subplot(2,1,1); h1=pcolor(x,y,abs(E(:,:,1))); set(h1,'EdgeColor','none'); axis square;
+% subplot(2,1,2); h2=pcolor(x,y,abs(E(:,:,2))); set(h2,'EdgeColor','none'); axis square; shg;
+%
+% EXAMPLE 2 (1D, cartesian domain, default y):
+% w=[1,2,3,4].'; x=[-10:0.001:10]; lambda=[1,1,1,1].'*656e-9; R=[1,1,1,1].'*1000;
+% q = (1./R - i* lambda./pi./w.^2).^(-1); a=[1,1,1,1].'; p = [0,1,2,3].'; m=[0,0,0,0].';
+% E=LaguerreGaussianE([p,m,q,lambda,a],x,'cart'); I=E.*conj(E); phi=angle(E);
+% plot(x,I(:,1),x,I(:,2),x,I(:,3),x,I(:,4));
+%
+% Last updated: July 18, 2004 by AMG
+%----------------------------------------------------------------------------------------------
+%% SYNTAX: z=LaguerreGaussianE([p,m,q <,lambda,a>],r <,theta,coordtype>);
+%----------------------------------------------------------------------------------------------
+
+function z=LaguerreGaussianE(params,r,varargin);
+
+if nargin>=3
+ if isstr(varargin{1})
+ if strcmp(varargin{1},'cart') % use cartesian coordinates
+ defaultcoord2=1;
+ cartesianflag=1;
+ else % use polar coordinates with the default theta
+ defaultcoord2=1;
+ cartesianflag=0;
+ end
+ else % use polar coordinates with the specified theta
+ defaultcoord2=0;
+ cartesianflag=0;
+ theta=varargin{1};
+ end
+else % use polar coordinates with the default theta
+ defaultcoord2=1;
+ cartesianflag=0;
+end
+
+if nargin>=4
+ defautlcoord2=0;
+ if isstr(varargin{2}) & strcmp(varargin{2},'cart')
+ cartesianflag=1; % use cartesian coordinates with specified y
+ else % use polar coordinates with the specified theta
+ cartesianflag=0;
+ end
+end
+
+
+if cartesianflag % cartesian (x,y) domain supplied
+ x=r;
+ if min(size(x))==1 % map is 2->1 on a cartesian domain
+ if size(x,1)<size(x,2), x=x'; end % make x and y columnar
+ if defaultcoord2
+ y=zeros(size(x));
+ else
+ y=theta;
+ if size(y,1)<size(y,2), y=y'; end
+ end
+ end
+ if min(size(x)) > 1 % map is 2->2 on a cartesian domain
+ if defaultcoord2
+ y=transpose(x);
+ else
+ y=theta;
+ end
+ z=zeros(size(x,1),size(x,2),size(params,1)); % need this since zeros(size(y),10) gives a 2D matrix even if y is 2D! (Matlab feature.)
+ else
+ z=zeros(size(x),size(params,1));
+ end
+ [theta,r]=cart2pol(x,y); % convert to polar coords for calculation
+else % polar (r,theta) domain supplied
+ if min(size(r))==1 % map is 2->1 on a polar domain
+ if size(r,1)<size(r,2), r=r.'; end % make r columnar
+ if defaultcoord2 % make theta columnar
+ theta=zeros(size(r)); % default 1D theta is zero
+ else
+ if size(theta,1)<size(theta,2), theta=theta.'; end
+ end
+ else % otherwise assume r and theta are already in meshgrid format
+ z=zeros(size(r,1),size(r,2),size(params,1)); % need this since zeros(size(r),10) gives a 2D matrix even if y is 2D! (Matlab feature.)
+ end
+end
+
+
+p=params(:,1);
+m=params(:,2);
+signm=sign(m);
+m=abs(m);
+q=params(:,3);
+if size(params,2)>=4
+ lambda=params(:,4);
+else
+ lambda=1064e-9;
+end
+if size(params,2)>=5
+ a=params(:,5);
+else
+ a=ones(size(q));
+end
+
+w=w_(q,lambda);
+
+if min(size(r))>=2
+ for u=1:size(params,1)
+ z(:,:,u) = a(u)...
+ .* sqrt(2*factorial(p(u))/(1+(m(u)==0))/pi/(factorial( m(u)+p(u) )))/w(u)...
+ .* (sqrt(2)*r/w(u)).^m(u) .*exp(1i*signm(u)*m(u).*theta).* LaguerrePoly([p(u),m(u)],2*r.^2/w(u).^2)...
+ .* exp( -1i*2*pi/lambda(u)*r.^2/2/q(u));
+ end
+else
+ for u=1:size(params,1)
+ z(:,u) = a(u)...
+ .* sqrt(2*factorial(p(u))/(1+(m(u)==0))/pi/(factorial( m(u)+p(u) )))/w(u)...
+ .* (sqrt(2)*r/w(u)).^m(u) .* exp(i*signm(u)*m(u).*theta).* LaguerrePoly([p(u),m(u)],2*r.^2/w(u).^2)...
+ .* exp( -1i*2*pi/lambda(u)*r.^2/2/q(u));
+ end
+end
diff --git a/transverse/LaguerrePoly.m b/transverse/LaguerrePoly.m
new file mode 100644
index 0000000..b29d3d0
--- /dev/null
+++ b/transverse/LaguerrePoly.m
@@ -0,0 +1,24 @@
+%-----------------------------------
+% Associated Laguerre Polynomial
+% (See e.g. Arfken section 13.2)
+%
+% SYNTAX y=Lnk([n,k],x)
+%-----------------------------------
+
+function y=LaguerrePoly(params,x)
+
+n=params(1);
+k=params(2);
+
+m=[0:n];
+
+a=factorial(n+k)*ones(1,length(m));
+b=factorial(n-m);
+c=factorial(k+m);
+d=factorial(m);
+e=(-1).^m;
+
+y=zeros(size(x));
+for s=1:n+1;
+ y = y + a(s) ./ b(s) ./ c(s) ./ d(s) .* e(s) .* x.^m(s);
+end
diff --git a/transverse/NewtonRingsI.m b/transverse/NewtonRingsI.m
new file mode 100644
index 0000000..961495b
--- /dev/null
+++ b/transverse/NewtonRingsI.m
@@ -0,0 +1,64 @@
+%---------------------------------------------------------------
+% PROGRAM: NRI
+% AUTHOR: Andri M. Gretarsson
+% DATE: 8/5/03
+%
+%
+% SYNTAX: z=NwetonRingsI([w1,w2,R1,R2,P1,P2,lambda,deltaphi],r);
+%
+% Returns the intensity of a set of Newton's rings as a function
+% of the radial coordinate R. (See e.g. Fundamentals of Physical Optics
+% by Jenkins and White, 1st ed. Section 4.4). The Newton's rings are
+% generated by the interference of two coaxial beams with different radii
+% of curvature and/or width.
+%
+% w1 = 1/e field amplitude radius of the 1st of the interfering beams
+% w2 = 1/e field amplitude radius of the 2nd of the interfering beams
+% R1 = Radius of curvature of the phasefront of the 1st of the interfering beams
+% R2 = Radius of curvature of the phasefront of the 2nd of the interfering beams
+% P1 = Radius of curvature of the phasefront of the 2nd of the interfering beams
+% P2 = Radius of curvature of the phasefront of the 2nd of the interfering beams
+% lambda = Radius of curvature of the phasefront of the 2nd of the interfering beams
+% deltaphi = Radius of curvature of the phasefront of the 2nd of the interfering beams
+% z(k) = Intensity of the interference pattern at radiusr(k).
+%
+% If x and y are not vectors but matrixes generated by
+% the matlab function meshgrid, then the output variable z
+% is a matrix rather than a vector. The matrix form allows
+% the function to have a plane as it's domain rather than
+% a curve. To generate a plane domain one uses meshgrid.
+%
+% EXAMPLE: thetaoffset=20*pi/180;
+% rseed=[0:0.01:sqrt(0.3)].^2;
+% thetaseed=[0:1:360]*pi/180;
+% [theta,r]=meshgrid(thetaseed,rseed);
+% [x,y]=pol2cart(theta,r);
+% h=pcolor(x,y,NewtonRingsI([0.01,100,2e3,1e99,1,1,1.024e-6,thetaoffset],r));
+% colormap('bone');
+% set(h,'EdgeColor','none');
+% set(h,'FaceColor','interp');
+% set(gca,'Visible','off');
+% set(gcf,'Color','black');
+% axis square
+% shg;
+%
+% Last updated: 8/5/03 by AMG
+%
+%---------------------------------------------------------------
+%% SYNTAX: z=NewtonRingsI([w1,w2,R1,R2,P1,P2,lambda,deltaphi],r);
+%---------------------------------------------------------------
+
+function z=NewtonRingsI(params,r)
+
+w1=params(1);
+w2=params(2);
+R1=params(3);
+R2=params(4);
+P1=params(5);
+P2=params(6);
+lambda=params(7);
+deltaphi=params(8);
+a=1/2/R1-1/2/R2;
+
+z = exp(-r.^2/w1).*exp(-r.^2/w2).*...
+ ( sin( (a/2/lambda)* r.^2 - deltaphi) ).^2 + abs(P1-P2); \ No newline at end of file
diff --git a/transverse/SimpleGaussian.m b/transverse/SimpleGaussian.m
new file mode 100644
index 0000000..327f11e
--- /dev/null
+++ b/transverse/SimpleGaussian.m
@@ -0,0 +1,54 @@
+%---------------------------------------------------------------
+% Field of the TEM00 Gaussian mode as a function of distance
+% from waist and axial distance. (See e.g. Orazio Svelto,
+% Principles of Lasers, 4th ed. page 152, Eqn's 4.715a-4.717c)
+%
+% SYNTAX: [E,w,R,phi,zR]=SimpleGaussian([w0,lambda],z,r);
+%
+% INPUT ARGUMENTS:
+% w0 = Gaussian field radius at waist
+% z = axial distance from waist
+% lambda = wavelength
+%
+% z = distance from waist (Nx1 vector)
+% r = distance from beam axis (Nx1 vector)
+%
+% OUTPUT ARGUMENTS:
+% E = complex electric field normalized to the field
+% amplitude at the center of the waist
+% w = width of the beam (radius at which the field amplitude
+% falls to 1/e of it's value on the beam axis
+% R = Radius of curvature of phasefront
+% phi = Guoy phase
+% zR = Raleigh range
+%
+%---------------------------------------------------------------
+% SYNTAX: [E,w,R,phi,zR]=SimpleGaussian([w0,lambda],z,r);
+%---------------------------------------------------------------
+
+function [E,w,R,phi,zR]=SimpleGaussian(params,z,r);
+
+w0=params(1); %Beam field width at waist
+lambda=params(2); %Wavelength
+
+higherorder=0;
+if length(params)>=3,
+ l=params(3);
+ m=params(4);
+ higherorder=1;
+end
+
+E=zeros(length(z),length(r));
+w=zeros(length(z),1);
+R=zeros(length(z),1);
+phi=zeros(length(z),1);
+
+if higherorder==0
+ for s=1:length(z)
+ [E(s,:),w(s),R(s),phi(s),zR]=SimpleGaussian_rdep([w0,z(s),lambda],r);
+ end
+else
+ for s=1:length(z)
+ [E(s,:),w(s),R(s),phi(s),zR]=SimpleGaussian_rdep([w0,z(s),lambda,0,l,m],r);
+ end
+end \ No newline at end of file
diff --git a/transverse/SimpleGaussian_rdep.m b/transverse/SimpleGaussian_rdep.m
new file mode 100644
index 0000000..ab81f21
--- /dev/null
+++ b/transverse/SimpleGaussian_rdep.m
@@ -0,0 +1,82 @@
+%---------------------------------------------------------------
+% Field of the TEMnm Gaussian mode as a function of radial
+% distance from beam axis.
+%
+% SYNTAX: E=SimpleGaussian_rdep([w0,z,lambda,n,m],x,y);
+%
+% INPUT ARGUMENTS:
+% w0 = Gaussian field radius at waist
+% z = distance from beam axis
+% lambda = wavelength
+%
+% r = distance from beam axis (Nx1 vector)
+% n = horizontal mode number
+% m = vertical mode number
+%
+% OUTPUT ARGUMENTS:
+% E = complex electric field normalized to the field
+% amplitude at the center of the waist
+% w = width of the beam (radius at which the field amplitude
+% falls to 1/e of it's value on the beam axis
+% R = Radius of curvature of phasefront
+% phi = Guoy phase
+% zR = Raleigh range
+%
+%---------------------------------------------------------------
+% SYNTAX: E=SimpleGaussian_rdep([w0,z,lambda,twoD,n,m],x,y);
+%---------------------------------------------------------------
+
+function [E,w,R,phi,zR]=SimpleGaussian_rdep(params,x,varargin);
+
+if abs(params(2))<=1e-99, params(2)=1e-99; end
+ %Prevents divide by zero error at waist
+
+if nargin>=3
+ y=varargin{1};
+else
+ y=zeros(size(x));
+end
+higherorder=0;
+
+w0=params(1); %Beam field width at waist
+z=params(2); %Distance from beam axis
+if length(params)>=4
+ twoD=params(4);
+else
+ twoD=0;
+end
+if length(params)>=5 %Will be calculating higher order mode
+ l=params(5);
+ m=params(6);
+ higherorder=1;
+end
+
+
+lambda=params(3); %Wavelength
+k=2*pi/lambda; %Wavenumber
+zR=pi*w0^2/lambda; %Raleigh range
+
+w=w0*sqrt(1+(z/zR)^2); %Beam (field) width
+R=z*(1+(zR/z)^2); %Radius of curvature
+phi=atan(z/zR); %Guoy phase
+
+if twoD~=1
+ if higherorder~=1
+ E = (w0/w) * exp(-(x.^2+y.^2)/w^2) .* exp(-i*k*(x.^2+y.^2)/2/R) * exp( i*phi);
+ else
+ E = (w0/w) * hermitepoly(l,sqrt(2)*x/w) .* hermitepoly(m,sqrt(2)*y/w)...
+ .*exp(-(x.^2+y.^2)/w^2) .* exp(-i*k*(x.^2+y.^2)/2/R) * exp(i*(1+l+m)*phi);
+ end
+else
+ E=zeros(length(y),length(x));
+ if higherorder~=1
+ for s=1:length(y)
+ E(s,:) = (w0/w) * exp(-(x.^2+y(s).^2)/w^2) .* exp(-i*k*(x.^2+y(s).^2)/2/R) * exp( i*phi);
+ end
+ else
+ for s=1:length(y)
+ E(s,:) = (w0/w) * hermitepoly(l,sqrt(2)*x/w) .* hermitepoly(m,sqrt(2)*y(s)/w)...
+ .*exp(-(x.^2+y(s).^2)/w^2) .* exp(-i*k*(x.^2+y(s).^2)/2/R) * exp(i*(1+l+m)*phi);
+ end
+ end
+end
diff --git a/transverse/complexLaguerreGaussianE.m b/transverse/complexLaguerreGaussianE.m
new file mode 100644
index 0000000..e6dd73e
--- /dev/null
+++ b/transverse/complexLaguerreGaussianE.m
@@ -0,0 +1,197 @@
+%----------------------------------------------------------------------------------------------
+% PROGRAM: LaguerreGaussianE
+% AUTHOR: Andri M. Gretarsson
+% DATE: 6/26/03
+%
+% SYNTAX: z=LaguerreGaussianE([p,m,q <,lambda,a>],r <,theta,coordtype>);
+% <...> indicates optional arguments
+%
+% Returns the complex field amplitude of a Laguerre-Gaussian mode as a function
+% of polar coordinates r and theta. Formula adapted from A. E. Siegman,
+% "Lasers" 1st ed. eqn. 64 in Ch. 16. I leave out the gouy phase
+% factor since it is meaningless except as a relative phase difference
+% between axially separated parts of the same beam. In other words it
+% only appears when propagating the beam. The function prop.m does
+% both the q transformation and supplies the appropriate gouy phase.
+% This factor and other phase and amplitude factors can be included via the
+% complex argument a if desired. Finally, this function can also be called
+% with cartesian coordinates.
+%
+%
+% INPUT ARGUMENTS:
+% ----------------
+% p,m = Laguerre Gaussian mode numbers (column vector)
+% q = complex radius of curvature of the beam (column vector)
+% lambda= Wavelength of the light (column vector)
+% a = complex prefactor ( includes gouy phase, e.g. for a LG beam that
+% has been propageted with an ABCD matrix a = 1/(A + [B/q1])^(1+2p+m) ).
+% (column vector).
+% r = radial position vector (or matrix generated by meshgrid)
+% theta = azimuthal position vector (or matrix generated by meshgrid).
+% If r is 1D and theta is not specified the default theta is used,
+% theta=zeros(size(r)). If r is a 2D mesh theta must also be specified.
+% The function polarmesh.m can be usefule for generating the r and
+% theta meshes.
+% coordtype = (string) label for the type of coordinates supplied in r and theta. If
+% this argument is not specified or is equal to 'pol', r and theta are assumed
+% to be polar coordinates (r,theta) as described above. If on the other
+% hand coordtype='cart' then r is assumed to be the cartesian x coordinate
+% and theta the cartesian y coordinate. This can be useful e.g. if one wants to
+% specify an x or y shift in the position of the mode. (See for example
+% Laguerre_demo.m). coordtype is normally the 8th input argument but can
+% be specified as the 7th input argument instead if the default y is desired
+% (y=transpose(x)).
+%
+% OUTPUT ARGUMENTS:
+% -----------------
+% z(i,j)= Complex field of the Laguerre Gaussian mode at
+% ( r(i,j),theta(i,j) ). May be a vector or
+% a matrix depending on whether r and theta
+% are vectors or matrixes.
+%
+%
+% NOTES:
+% ------
+% If r and theta are not vectors but matrixes generated by
+% the matlab function meshgrid, then the output variable z
+% is a matrix rather than a vector. The matrix form allows
+% the function HermiteGaussianE to have a plane as it's domain
+% rather than a curve.
+%
+% If the parameters p,m,q,p,lambda are equal length column vectors rather
+% than scalars z is a size(r)*length(lambda) matrix. E.g. if size(r) is n*n
+% then each level z(:,:,k) is a 2D field of a Laguerre Gaussian with
+% the parameters given by [l(k),m(k),q(k),lambda(k),a(k)].
+%
+% EXAMPLE 1 (2D, polar domain):
+% w=[0.001; 0.001];
+% rseed=[0*max(w):max(w)/30:3*max(w)]; thetaseed=[0:360]*pi/180;
+% [r,theta]=meshgrid(rseed,thetaseed);
+% lambda = [1.064e-6 ; 1.064e-6];
+% R = [-30 ; -30];
+% q = (1./R - i* lambda./pi./w.^2).^(-1); a=[1;1];
+% p=[1;2]; m=[0;2];
+% E=LaguerreGaussianE([p,m,q,lambda,a],r,theta)+LaguerreGaussianE([p,-m,q,lambda,a],r,theta);
+% [x,y]=pol2cart(theta,r); colormap(bone);
+% subplot(2,1,1); h1=pcolor(x,y,abs(E(:,:,1))); set(h1,'EdgeColor','none'); axis square;
+% subplot(2,1,2); h2=pcolor(x,y,abs(E(:,:,2))); set(h2,'EdgeColor','none'); axis square; shg;
+%
+% EXAMPLE 2 (1D, cartesian domain, default y):
+% w=[1,2,3,4].'; x=[-10:0.001:10]; lambda=[1,1,1,1].'*656e-9; R=[1,1,1,1].'*1000;
+% q = (1./R - i* lambda./pi./w.^2).^(-1); a=[1,1,1,1].'; p = [0,1,2,3].'; m=[0,0,0,0].';
+% E=LaguerreGaussianE([p,m,q,lambda,a],x,'cart'); I=E.*conj(E); phi=angle(E);
+% plot(x,I(:,1),x,I(:,2),x,I(:,3),x,I(:,4));
+%
+% Last updated: July 18, 2004 by AMG
+%----------------------------------------------------------------------------------------------
+%% SYNTAX: z=LaguerreGaussianE([p,m,q <,lambda,a>],r <,theta,coordtype>);
+%----------------------------------------------------------------------------------------------
+
+function z=LaguerreGaussianE(params,r,varargin);
+
+if nargin>=3
+ if isstr(varargin{1})
+ if strcmp(varargin{1},'cart') % use cartesian coordinates
+ defaultcoord2=1;
+ cartesianflag=1;
+ else % use polar coordinates with the default theta
+ defaultcoord2=1;
+ cartesianflag=0;
+ end
+ else % use polar coordinates with the specified theta
+ defaultcoord2=0;
+ cartesianflag=0;
+ theta=varargin{1};
+ end
+else % use polar coordinates with the default theta
+ defaultcoord2=1;
+ cartesianflag=0;
+end
+
+if nargin>=4
+ defautlcoord2=0;
+ if isstr(varargin{2}) & strcmp(varargin{2},'cart')
+ cartesianflag=1; % use cartesian coordinates with specified y
+ else % use polar coordinates with the specified theta
+ cartesianflag=0;
+ end
+end
+
+
+if cartesianflag % cartesian (x,y) domain supplied
+ x=r;
+ if min(size(x))==1 % map is 2->1 on a cartesian domain
+ if size(x,1)<size(x,2), x=x'; end % make x and y columnar
+ if defaultcoord2
+ y=zeros(size(x));
+ else
+ y=theta;
+ if size(y,1)<size(y,2), y=y'; end
+ end
+ end
+ if min(size(x)) > 1 % map is 2->2 on a cartesian domain
+ if defaultcoord2
+ y=transpose(x);
+ else
+ y=theta;
+ end
+ z=zeros(size(x,1),size(x,2),size(params,1)); % need this since zeros(size(y),10) gives a 2D matrix even if y is 2D! (Matlab feature.)
+ else
+ z=zeros(size(x),size(params,1));
+ end
+ [theta,r]=cart2pol(x,y); % convert to polar coords for calculation
+else % polar (r,theta) domain supplied
+ if min(size(r))==1 % map is 2->1 on a polar domain
+ if size(r,1)<size(r,2), r=r.'; end % make r columnar
+ if defaultcoord2 % make theta columnar
+ theta=zeros(size(r)); % default 1D theta is zero
+ else
+ if size(theta,1)<size(theta,2), theta=theta.'; end
+ end
+ else % otherwise assume r and theta are already in meshgrid format
+ z=zeros(size(r,1),size(r,2),size(params,1)); % need this since zeros(size(r),10) gives a 2D matrix even if y is 2D! (Matlab feature.)
+ end
+end
+
+
+p=params(:,1);
+m=params(:,2);
+signm=sign(m);
+m=abs(m);
+q=params(:,3);
+if size(params,2)>=4
+ lambda=params(:,4);
+else
+ lambda=1064e-9;
+end
+if size(params,2)>=5
+ a=params(:,5);
+else
+ a=ones(size(q));
+end
+
+w=w_(q,lambda);
+
+if min(size(r))>=2
+ for u=1:size(params,1)
+ z(:,:,u) = a(u)...
+ .* sqrt(2*factorial(p(u))/(1+(m(u)==0))/pi/(factorial( m(u)+p(u) )))/w(u)...
+ .* (sqrt(2)*r/w(u)).^m(u) .*exp(1i*signm(u)*m(u).*theta).* LaguerrePoly([p(u),m(u)],2*r.^2/w(u).^2)...
+ .* exp( -1i*2*pi/lambda(u)*r.^2/2/q(u))
+ + a(u)...
+ .* sqrt(2*factorial(p(u))/(1+((-m(u))==0))/pi/(factorial( (-m(u))+p(u) )))/w(u)...
+ .* (sqrt(2)*r/w(u)).^(-m(u)) .*exp(1i*signm(u)*(-m(u)).*theta).* LaguerrePoly([p(u),(-m(u))],2*r.^2/w(u).^2)...
+ .* exp( -1i*2*pi/lambda(u)*r.^2/2/q(u));
+ end
+else
+ for u=1:size(params,1)
+ z(:,u) = a(u)...
+ .* sqrt(2*factorial(p(u))/(1+(m(u)==0))/pi/(factorial( m(u)+p(u) )))/w(u)...
+ .* (sqrt(2)*r/w(u)).^m(u) .*exp(1i*signm(u)*m(u).*theta).* LaguerrePoly([p(u),m(u)],2*r.^2/w(u).^2)...
+ .* exp( -1i*2*pi/lambda(u)*r.^2/2/q(u))
+ + a(u)...
+ .* sqrt(2*factorial(p(u))/(1+((-m(u))==0))/pi/(factorial( (-m(u))+p(u) )))/w(u)...
+ .* (sqrt(2)*r/w(u)).^(-m(u)) .*exp(1i*signm(u)*(-m(u)).*theta).* LaguerrePoly([p(u),(-m(u))],2*r.^2/w(u).^2)...
+ .* exp( -1i*2*pi/lambda(u)*r.^2/2/q(u));
+ end
+end
diff --git a/transverse/decompose.m b/transverse/decompose.m
new file mode 100644
index 0000000..e9b583a
--- /dev/null
+++ b/transverse/decompose.m
@@ -0,0 +1,174 @@
+%----------------------------------------------------------------------------------------------
+% PROGRAM: decompose
+% AUTHOR: Andri M. Gretarsson
+% DATE: 7/10/04
+%
+% SYNTAX: [coeffs,tmat]=decompose(z1,domain,type,terms,[q <,lambda,accuracy>]);
+% <...> indicates optional arguments
+%
+% Calculates the coefficients of the decomposition of the function z1 into
+% Hermite Gaussian modes or Laguerre Gaussian modes.
+%
+% INPUT ARGUMENTS:
+% ----------------
+% z1 = The values of the function to be decomposed. 2D (nxn) matrix
+% domain = the domain values at which the values in z1 are specified.
+% The domain is a nxmx2 array where domain(:,:,1) and
+% domain(:,:,2) are the x and y meshes corresponding to the
+% values in z1. (These meshes are often generated using meshgrid.m.)
+% type = 'hg' for a Hermite Gaussian mode decomposition
+% 'lg' for a Laguerre Gaussian mode decomposition
+% terms = This argument can be specified either as a scalar or as a matrix.
+% If it is specified as a scalar, it indicates the number of
+% terms out to which to calculate the decomposition. Since the
+% Hermite and Laguerre bases are two dimensional and are specified
+% by a 2D argument (l,m) or (p,m), default rules are applied to
+% decide exactly which terms to calculate. The output
+% matrix tmat indicates what terms were calculated.
+%
+% When terms is specified as a matrix, it indicates exactly which
+% terms to calculate. For Hermite Gaussian modes (type='hg')
+% terms is a LxM matrix where a 1 in the (i,j)th entry indicates
+% that the term TEM(l,m)=(i-1,j-1) will be calculated. A zero
+% indicates it will not be calculated. For example:
+%
+% 1 0 0
+% terms = 0 1 0
+% 0 1 0
+%
+% indicates that the coefficients of the Hermite Gaussian modes
+% (0,0), (1,1) and (2,1) will be calculated but no others.
+%
+% For Laguerre Gaussian modes (type='lg') the terms matrix is
+% interpreted similarly. However, since the (p,m) mode can
+% have either positive or negative m terms the terms matrix is now
+% a PxMx2 matrix, where terms(:,:,1) indicates which positive-m
+% terms to calculate and terms(:,:,2) indicates which negative-m
+% terms to calculate. However, note that since m=0 must not
+% be duplicated, the first column in terms(:,:,2) is always zero.
+% Thus for example:
+%
+% 1 0 0
+% terms(:,:,1) = 0 1 0
+% 0 1 0
+%
+% 0 0 0
+% terms(:,:,2) = 0 1 0
+% 0 1 1
+%
+% indicates that the coefficients of the Laguerre Gaussian modes
+% (0,0), (1,1), (2,1), (1,-1), (2,-1) and (2,-2) will be calculated.
+%
+% q = the complex radius of curvature "q" of the Gaussian basis.
+% lambda = wavelength of the light in the Gaussian basis. Default is 1.064 microns
+% accuracy = only calculate the coefficients of the decomposition to the
+% specified accuracy. Actually rounds each result to the nearest
+% increment of accuracy. For example, if accuracy=0.3, then a coefficient
+% of 1.54 would be rounded to 1.5 while a coefficient of 1.56 would be
+% rounded to 1.8. Accuracy of 0 applies no rounding. Specifying
+% accuracy other than "0" does not speed up the calculation.
+%
+% OUTPUT ARGUMENTS:
+% -----------------
+% coeffs = the coefficients of the terms in the expansion. coeffs is a matrix
+% the same size a tmat.
+% tmat = coefficient request matrix. Often this would be specified by the user
+% by the input argument "terms", in other words tmat=terms. However, as explained
+% under the definition of the input argument terms, this function
+% allows the user to specify only how many terms he wants, in other words terms can be
+% a scalar and not a matrix. In this case tmat must be calculated according to
+% default rules. In this case it is convenient to have the terms request matrix
+% as an output argument. Each entry in the coefficient request matrix tmat correspond
+% to a particular term of the expansion (as explained above). If the tmat(i,j) is 1,
+% the coefficient of that term is calculated and returned in coeffs(i,j). If tmat(i,j)
+% is 0, the corresponding coefficient was not calculated and coeffs(i,j) is set to 0
+% regardless of whether the contribution of that term to z1 is really zero.
+%
+% EXAMPLE 1 (Hermite Gaussian, only number of terms specified):
+% [x,y]=meshgrid([-pi/2:0.1:pi/2],[-pi/2:0.1:pi/2]); z1=cos(sqrt(x.^2+y.^2));
+% clear domain; domain(:,:,1)=x; domain(:,:,2)=y;
+% w=pi/4; R=1e3; lambda=1e-6; q=(1./R - i* lambda./pi./w.^2).^(-1);
+% [coeffs,tmat]=decompose(z1,domain,'hg',140,[q,lambda,1e-6])
+% z1recomposed=recompose(domain,'hg',coeffs,[q,lambda,1e-6]);
+% subplot(3,1,1); h=pcolor(x,y,abs(z1).^2); set(h,'EdgeColor','none'); axis square; colorbar
+% subplot(3,1,2); h=pcolor(x,y,abs(z1recomposed).^2); set(h,'EdgeColor','none'); axis square; colorbar
+% subplot(3,1,3); h=pcolor(x,y,abs(z1).^2-abs(z1recomposed).^2); set(h,'EdgeColor','none'); axis square; colorbar; shg;
+%
+% Last updated: July 18, 2004 by AMG
+%----------------------------------------------------------------------------------------------
+% SYNTAX: [coeffs,tmat]=decompose(z1,domain,type,terms,[q <,lambda,accuracy>]);
+%----------------------------------------------------------------------------------------------
+function [coeffs,tmat]=decompose(z1,domain,type,terms,params)
+
+% HERMITE GAUSSIAN EXPANSION --------------------------------------------------------------------------
+if strcmpi(type,'hg')
+ q=params(1);
+ if length(params)>=2, lambda=params(2); else lambda=1.064e-6; end
+ if length(params)>=3, accuracy=params(3); else accuracy=1e-4; end
+
+ if size(terms,1)==1 && size(terms,2)==1 % Make terms request matrix
+ n=ceil(sqrt(terms));
+ tmat=ones(n,n);
+ if n^2>terms
+ tmat(end,end-ceil((n^2-terms)/2)+1:end)=0;
+ tmat(end-floor((n^2-terms)/2):end-1,end)=0;
+ end
+ else
+ tmat=terms;
+ end
+ coeffs=zeros(size(tmat));
+ for s=1:size(tmat,1) % Calculate the coefficients
+ l=s-1;
+ for t=1:size(tmat,2)
+ m=t-1;
+ if tmat(s,t)==1
+ z2=HermiteGaussianE([l,m,q,lambda],domain(:,:,1),domain(:,:,2));
+ coeffs(s,t)=overlap(z1,conj(z2),domain,1,accuracy);
+ else
+ coeffs(s,t)=0;
+ end
+ end
+ end
+
+% LAGUERRE GAUSSIAN EXPANSION --------------------------------------------------------------------------
+elseif strcmpi(type,'lg')
+ q=params(1);
+ if length(params)>=2, lambda=params(2); else lambda=1.064e-6; end
+ if length(params)>=3, accuracy=params(3); else accuracy=1e-4; end
+ if size(terms,1)==1 && size(terms,2)==1 % Make terms request matrix
+ n=ceil( (1+sqrt(1+8*terms))/4 );
+ tmat=ones(n,n,2); tmat(:,1,2)=0;
+ ndiff=2*n^2-n-terms;
+ if ndiff>0
+ rdiff=ceil(ndiff/2); ldiff=floor(ndiff/2);
+ tmat(end,end-ceil(rdiff/2)+1:end,1)=0;
+ tmat(end-floor(rdiff/2):end-1,end,1)=0;
+ tmat(end,end-ceil(ldiff/2)+1:end,2)=0;
+ tmat(end-floor(ldiff/2):end-1,end,2)=0;
+ end
+ %disp(' '); dispmat(tmat(:,:,1)); disp(' '); dispmat(tmat(:,:,2)); disp(' '); disp(num2str(sum(sum(sum(tmat)))));
+ else
+ tmat=terms;
+ end
+ clear coeffs;
+ coeffs(:,:,1)=zeros(size(tmat,1),size(tmat,2));
+ coeffs(:,:,2)=zeros(size(tmat,1),size(tmat,2));
+ for s=1:size(tmat,1) % Calculate the coefficients
+ p=s-1;
+ for t=1:size(tmat,2)
+ m=t-1;
+ if tmat(s,t,1)==1 % coeff requested
+ z2=LaguerreGaussianE([p,m,q,lambda],domain(:,:,1),domain(:,:,2),'pol');
+ coeffs(s,t,1)=overlap(z1,conj(z2),domain,domain(:,:,1),accuracy);
+ else
+ coeffs(s,t,1)=0;
+ end
+ if tmat(s,t,2)==1 % coeff requested
+ z2=LaguerreGaussianE([p,-m,q,lambda],domain(:,:,1),domain(:,:,2),'pol');
+ coeffs(s,t,2)=overlap(z1,conj(z2),domain,domain(:,:,1),accuracy);
+ else
+ coeffs(s,t,2)=0;
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/transverse/fitgaussianbeamrad.m b/transverse/fitgaussianbeamrad.m
new file mode 100644
index 0000000..65e3cdb
--- /dev/null
+++ b/transverse/fitgaussianbeamrad.m
@@ -0,0 +1,19 @@
+% Fits beamwidth versus position data to a Gaussian beam profile
+function f=fitgaussianbeamrad(z,w,lambda,varargin)
+
+if nargin>3, startparams=varargin{1};
+else
+ w0=1e-3;
+ z0=0;
+ startparams=[w0,z0];
+end
+if nargin>4, displayoptions=varargin{2}; else displayoptions=[1 0 0]; end
+
+f=genfit(z,w,startparams,@beamrad,'nonlin',displayoptions);
+
+
+function w=beamrad(params,z)
+w=beamradius([params,lambda],z); % Want 1/e^2 Power radius
+end
+
+end \ No newline at end of file
diff --git a/transverse/hermitepoly.m b/transverse/hermitepoly.m
new file mode 100644
index 0000000..43b77d6
--- /dev/null
+++ b/transverse/hermitepoly.m
@@ -0,0 +1,18 @@
+%-----------------------------------
+% Hermite Polynomial
+% (See e.g. Arfken section 13.1)
+%
+% SYNTAX y=hermitepoly(n,x)
+%-----------------------------------
+
+function y=hermitepoly(n,x)
+
+m=[0:floor(n/2)];
+
+a=factorial(n-2*m);
+b=factorial(m);
+
+y=zeros(size(x));
+for s=1:length(m)
+ y = y + factorial(n) ./ a(s) ./ b(s) .* (-1).^m(s) * (2*x).^(n-2*m(s));
+end
diff --git a/transverse/overlap.m b/transverse/overlap.m
new file mode 100644
index 0000000..f464303
--- /dev/null
+++ b/transverse/overlap.m
@@ -0,0 +1,83 @@
+%----------------------------------------------------------------------------------------------
+% PROGRAM: overlap
+% AUTHOR: Andri M. Gretarsson
+% DATE: 7/10/04
+%
+% SYNTAX: coeff=overlap(z1,z2,domain <,metric,accuracy>)
+% <...> indicates optional arguments
+%
+% Calculates the overlap integral of the two functions specified.
+%
+% INPUT ARGUMENTS:
+% ----------------
+% z1 = The values of the first function. Can be a 1D vector or a 2D matrix
+% z2 = The values of the second function. z1 and z2 must be the same size.
+% domain = the domain values at which z1 and z2 are specified. If z1 and z2 are 1D
+% then domain is a nx2 matrix specifying one x,y pair for each value in z1
+% and z2. If z1 and z2 are 2D then domain is a nxmx2 array where
+% domain(:,:,1) and domain(:,:,2) are the x and y meshes corresponding
+% to the values in z1 and z2. These meshes are often generated using meshgrid.m.
+% metric = value, vector or matrix by which to multiply the elemental line or area dl or dS.
+% For example, in 2D polar coordinates the elemental area is dS=r*dr*dtheta so
+% metric should be specified as r.
+% accuracy = round results to the nearest increment of accuracy. For example, if
+% accuracy=0.3, then coeff 1.54 would be rounded to 1.5 while coeff=1.56 would be
+% rounded to 1.8.
+%
+% OUTPUT ARGUMENTS:
+% -----------------
+% coeff = the numerical result of the overlap integral.
+%
+% EXAMPLE 1 (cartesian):
+% [x,y]=meshgrid([0:0.01:2*pi],[0:0.01:2*pi]);
+% clear domain; domain(:,:,1)=x; domain(:,:,2)=y;
+% z1=sin(x+y); z2=sin(x+y);
+% coeff=overlap(z1,z2,domain,1,0.0001)
+% z1=sin(x+y); z2=cos(x+y);
+% coeff=overlap(z1,z2,domain,1,0.0001)
+%
+% EXAMPLE 2 (polar):
+% [r,theta]=meshgrid([0.01:0.01:1],[0:0.5:360]*pi/180);
+% clear domain; domain(:,:,1)=r; domain(:,:,2)=theta;
+% z1=r; z2=theta;
+% subplot(1,3,1); [x,y]=pol2cart(theta,r); h=pcolor(x,y,z1); set(h,'EdgeColor','none'); axis square;
+% subplot(1,3,2); [x,y]=pol2cart(theta,r); h=pcolor(x,y,z2); set(h,'EdgeColor','none'); axis square;
+% subplot(1,3,3); [x,y]=pol2cart(theta,r); h=pcolor(x,y,z1.*z2); set(h,'EdgeColor','none'); axis square;
+% coeff=overlap(z1,z2,domain,r,0.0001)
+%
+% Last updated: July 18, 2004 by AMG
+%----------------------------------------------------------------------------------------------
+% SYNTAX: coeff=overlap(z1,z2,domain <,metric,accuracy>)
+%----------------------------------------------------------------------------------------------
+function coeff=overlap(z1,z2,domain,varargin)
+
+if nargin>=4;
+ metric=varargin{1};
+ if size(metric)==size(z1)
+ metric=metric(2:end,2:end);
+ end
+else
+ metric=1;
+end
+if nargin>=5; accuracy=varargin{2}; else accuracy=0; end
+if size(z1)~=size(z2), error('z1 and z2 must have same size'); end
+
+if min(size(z1))==1 & min(size(domain))==1 % 1D plot along axis
+ dl=metric.*(domain(2:end)-domain(1:end-1));
+ coeff=sum(z1(2:end).*z2(2:end).*dl)/2;
+end
+if min(size(z1))==1 & size(domain,2)==2 % 1D plot along arbitrary axis
+ dl=metric.*sqrt((domain(2:end,1)-domain(1:end-1,1)).^2 + (domain(2:end,2)-domain(1:end-1,2)).^2);
+ coeff=sum(z1(2:end).*z2(2:end).*dl)/2;
+end
+if min(size(z1))>= 2 % 2D plot over xy plane
+ coord1=domain(:,:,1); coord2=domain(:,:,2);
+ dcoord1=diff(coord1,1,2); dcoord1=dcoord1(2:end,:);
+ dcoord2=diff(coord2,1,1); dcoord2=dcoord2(:,2:end);
+ dS = metric.*dcoord1.*dcoord2;
+ coeff=sum(sum(z1(2:end,2:end).*z2(2:end,2:end).*dS));
+end
+
+if accuracy~=0
+ coeff=round(coeff/accuracy)*accuracy;
+end \ No newline at end of file
diff --git a/transverse/polarmesh.m b/transverse/polarmesh.m
new file mode 100644
index 0000000..914c3e0
--- /dev/null
+++ b/transverse/polarmesh.m
@@ -0,0 +1,92 @@
+%----------------------------------------------------------------------------------------------
+% PROGRAM: polarmesh
+% AUTHOR: Andri M. Gretarsson
+% DATE: 7/10/04
+%
+% SYNTAX: [rmesh,thetamesh,xmesh,ymesh]=polarmesh(r <,theta,rspacing>);
+% <...> indicates optional arguments
+%
+% Simplified way of generating arbitrary polar meshes.
+%
+% INPUT ARGUMENTS:
+% ----------------
+% r = specification for the r mesh. If r is a 1x3 vector the entries are assumed
+% to indicate r_start, r_end and n_rpts (number of r=const curves) and a set
+% of equally spaced or square spaced r=const mesh curves are generated. If r is
+% nx1, each entry is assumed to be a constant for which to generate an r=const
+% curve in the mesh. If r is 2D (nxn, where n>1) it is assumed to be already
+% in mesh form. In this case theta must be specified in mesh form and the
+% function does no more than pol2cart.
+% theta = specification for the theta mesh. If it is left blank the default theta is
+% used (a mesh with 1 line per theta from 0 to 360). If theta is 1x3, the
+% values are assumed to be [theta_start,theta_end,n_thetapts] and are used to
+% generate a set of n_thetapts equally spaced theta=const curves in the mesh.
+% If theta is [nx1] the one mesh curve is generated for each entry at the
+% specified angle.
+% rspacing = 'lin' for linear spacing of the r mesh
+% 'sqr' for r-line spacing proportional to r^2.
+%
+% OUTPUT ARGUMENTS:
+% -----------------
+% rmesh,thetamesh = r and theta meshes expressed in polar coordinates
+% xmesh,ymesh = the r and theta meshes expressed in cartesian coordinates.
+%
+% Last updated: July 18, 2004 by AMG
+%----------------------------------------------------------------------------------------------
+% SYNTAX: [rmesh,thetamesh,xmesh,ymesh]=polarmesh(r <,theta,rspacing>);
+%----------------------------------------------------------------------------------------------
+function [rmesh,thetamesh,xmesh,ymesh]=polarmesh(r,varargin)
+
+if nargin>=2, theta=varargin{1}; defaulttheta=0; else defaulttheta=1; end
+if nargin>=3 && strcmp(varargin{2},'rsqr'), linflag=0; else linflag=1; end
+
+if min(size(r))==1 % r is 1D
+ if size(r,1)==1 && size(r,2)==3 % r=[r_start,r_end,rpts]
+ if linflag % linear r-spacing for mesh
+ rseed=(r(1):(r(2)-r(1))/(r(3)-1):r(2)).';
+ else % r-spacing proportional to r^2
+ rseed=(sqrt(r(1)):(sqrt(r(2))-sqrt(r(1)))/(r(3)-1):sqrt(r(2))).'.^2;
+ end
+ if defaulttheta==1 % default theta
+ thetaseed=(0:1:360).'*pi/180;
+ [thetamesh,rmesh]=meshgrid(thetaseed,rseed); % I like r to be arranged in the first position (r,theta)
+ thetamesh=transpose(thetamesh); % rather than (theta,r) so for consistency with (xmesh,ymesh)
+ rmesh=transpose(rmesh); % rmesh must have identical rows and thetamesh identical columns
+ else % not default theta
+ if size(theta,1)==1 && size(theta,2)==3 % theta =[theta_start,theta_end,theta_pts]
+ thetaseed=(theta(1):(theta(2)-theta(1))/(theta(3)-1):theta(2)).';
+ [thetamesh,rmesh]=meshgrid(thetaseed,rseed);
+ thetamesh=transpose(thetamesh);
+ rmesh=transpose(rmesh);
+ else % theta lines specified
+ [thetamesh,rmesh]=meshgrid(theta,rseed);
+ thetamesh=transpose(thetamesh);
+ rmesh=transpose(rmesh);
+ end
+ end
+ else % r lines specified
+ if size(r,1)<size(r,2), r=r.'; end % make r columnar
+ if defaulttheta==1 % default theta
+ thetaseed=(0:1:360).'*pi/180;
+ [thetamesh,rmesh]=meshgrid(thetaseed,r);
+ thetamesh=transpose(thetamesh);
+ rmesh=transpose(rmesh);
+ else % not default theta
+ if size(theta,1)==1 && size(theta,2)==3 % theta =[theta_start,theta_end,theta_pts]
+ thetaseed=(theta(1):(theta(2)-theta(1))/(theta(3)-1):theta(2)).';
+ [thetamesh,rmesh]=meshgrid(thetaseed,r);
+ thetamesh=transpose(thetamesh);
+ rmesh=transpose(rmesh);
+ else % theta lines specified
+ [thetamesh,rmesh]=meshgrid(theta,r); % theta and r must be the same length
+ thetamesh=transpose(thetamesh);
+ rmesh=transpose(rmesh);
+ end
+ end
+ end
+else
+ thetamesh = theta; % r and theta are already mesh grids
+ rmesh=r; % (and are the same size)
+end
+
+[xmesh,ymesh]=pol2cart(thetamesh,rmesh); \ No newline at end of file
diff --git a/transverse/recompose.m b/transverse/recompose.m
new file mode 100644
index 0000000..0e23794
--- /dev/null
+++ b/transverse/recompose.m
@@ -0,0 +1,83 @@
+%----------------------------------------------------------------------------------------------
+% PROGRAM: recompose
+% AUTHOR: Andri M. Gretarsson
+% DATE: 7/10/04
+%
+% SYNTAX: z=recompose(domain,type,coeffs,[q <,lambda,accuracy>]);
+% <...> indicates optional arguments
+%
+% Calculates the complex field amplitude resulting from summing the specified terms of
+% a Hermite or Laguerre Gaussian mode expansion.
+%
+% INPUT ARGUMENTS:
+% ----------------
+% domain = the domain over which to do the recomposition. domain is a NxMx2 matrix
+% where domain(:,:,1) is the x mesh and domain(:,:,2) is the y mesh
+% (or r mesh and theta mesh respectively in the case of a Laguerre Gaussian
+% mode expansion).
+% type = 'hg' for a Hermite Gaussian mode expansion, and 'lg' for a Laguerre
+% Gaussian mode expansion.
+% coeffs = the matrix of coefficients in the same form as returned by decompose.m
+% q = the complex radius of curvature "q" of the Gaussian basis.
+% lambda = wavelength of the light in the Gaussian basis. Default is 1.064 microns
+% accuracy = only calculate the coefficients of the decomposition to th
+% specified accuracy. For example, if accuracy=0.3, then coeffs(i,j)= 1.4
+% would be rounded to 1.3.
+%
+% OUTPUT ARGUMENTS:
+% -----------------
+% z(i,j) = Resultant complex field of the recomposed modes at over the domain.
+%
+% Last updated: July 18, 2004 by AMG
+%----------------------------------------------------------------------------------------------
+% SYNTAX: z=recompose(domain,type,coeffs,[q <,lambda,accuracy>]);
+%----------------------------------------------------------------------------------------------
+
+function z=recompose(domain,type,coeffs,params)
+
+z=zeros(size(domain(:,:,1)));
+% HERMITE GAUSSIAN EXPANSION --------------------------------------------------------------------------
+if strcmpi(type,'hg')
+ q=params(1);
+ if length(params)>=2, lambda=params(2); else lambda=1.064e-6; end
+ if length(params)>=3, accuracy=params(3); else accuracy=1e-4; end
+ for s=1:size(coeffs,1)
+ l=s-1;
+ for t=1:size(coeffs,2)
+ m=t-1;
+ if abs(coeffs(s,t))>accuracy
+ z=z+HermiteGaussianE([l,m,q,lambda,coeffs(s,t)],domain(:,:,1),domain(:,:,2));
+ else
+ coeffs(s,t)=0;
+ end
+ end
+ end
+
+% LAGUERRE GAUSSIAN EXPANSION --------------------------------------------------------------------------
+elseif strcmpi(type,'lg')
+ q=params(1);
+ if length(params)>=2, lambda=params(2); else lambda=1.064e-6; end
+ if length(params)>=3, accuracy=params(3); else accuracy=1e-4; end
+ for s=1:size(coeffs,1)
+ p=s-1;
+ for t=1:size(coeffs,2)
+ m=t-1;
+ if abs(coeffs(s,t,1))>accuracy
+ z=z+LaguerreGaussianE([p,m,q,lambda,coeffs(s,t,1)],domain(:,:,1),domain(:,:,2));
+ else
+ coeffs(s,t,1)=0;
+ end
+ end
+ end
+ for s=1:size(coeffs,1)
+ p=s-1;
+ for t=2:size(coeffs,2) % skip terms with m=0
+ m=t-1;
+ if abs(coeffs(s,t,2))>accuracy
+ z=z+LaguerreGaussianE([p,-m,q,lambda,coeffs(s,t,2)],domain(:,:,1),domain(:,:,2));
+ else
+ coeffs(s,t,2)=0;
+ end
+ end
+ end
+end \ No newline at end of file