0001 function varargout = cavityon(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 if ~evalin('base','~isempty(whos(''global'',''THERING''))')
0014 error('Global variable THERING could not be found');
0015 end
0016
0017 if ~exist('THERING')
0018 global THERING
0019 end
0020
0021 global GLOBVAL
0022 if ~exist('GLOBVAL') || ~evalin('base','~isempty(whos(''global'',''GLOBVAL''))')
0023 if nargin==0
0024 error('global variable GLOBVAL does not exist. To create it, use CAVITYON(ENERGY)')
0025 else
0026 evalin('base','global GLOBVAL');
0027 GLOBVAL.E0 = varargin{1};
0028 disp('Global variable GLOBVAL was created');
0029 end
0030 else
0031 if nargin==1
0032 GLOBVAL.E0 = varargin{1};
0033 end
0034
0035 end
0036
0037 localcavindex = findcells(THERING,'Frequency');
0038
0039 if isempty(localcavindex)
0040 error('No cavities were found in the lattice');
0041 end
0042
0043 THERING = setcellstruct(THERING,'PassMethod',localcavindex, 'CavityPass');
0044
0045 disp(strcat('Cavities located at index [',num2str(localcavindex), '] were turned ON'))
0046 if nargout
0047 varargout{1}=localcavindex;
0048 end