source: MML/trunk/at/atphysics/cavityon.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 1.3 KB
Line 
1function varargout = cavityon(varargin)
2%CAVITYON turns Cavities ON
3%
4% CAVITYON looks for elements that have field Frequency
5%    and sets PassMethod for them to ThinCavityPass
6% CAVITYON(ENERGY)
7%    In addition sets the E0 field of the global variable GLOBVAL
8%    to energy - design energy [eV]
9%    If GLOBVAL does not exist CAVITYON creates it
10%
11% See also CAVITYOFF, RADIATIONON, RADIATIONOFF
12
13if ~evalin('base','exist(''THERING'')') | evalin('base','isempty(whos(''global'',''THERING''))');
14   error('Global variable THERING could not be found');
15end
16
17global THERING
18
19if ~evalin('base','exist(''GLOBVAL'')') | evalin('base','isempty(whos(''global'',''GLOBVAL''))');
20    if nargin==0
21        error('global variable GLOBVAL does not exist. To create it, use CAVITYON(ENERGY)')
22    else
23        evalin('base','global GLOBVAL');
24        GLOBVAL.E0 = varargin{1};
25        disp('Global variable GLOBVAL was created');
26    end
27else
28    if nargin==1
29        GLOBVAL.E0 = varargin{1};
30    end
31   
32end
33
34localcavindex = findcells(THERING,'Frequency');
35
36if isempty(localcavindex)
37   error('No cavities were found in the lattice');
38end
39
40THERING = setcellstruct(THERING,'PassMethod',localcavindex, 'CavityPass');
41
42disp(strcat('Cavities located at index  [',num2str(localcavindex),  ']  were turned ON'))     
43if nargout
44    varargout{1}=localcavindex;
45end
Note: See TracBrowser for help on using the repository browser.