|
1 | 1 | function create_lattice_matfile(filename) |
2 | 2 | % Creates a .mat file AT lattice compatible with ATIP. |
3 | 3 | % If a filename is given that file will be updated to ATIP standard. Otherwise |
4 | | -% THERING is taken from either of the 'RING' or 'THERING' global variables, |
5 | | -% with 'THERING' taking priority. If a filename is not passed the updated lattice |
6 | | -% will be stored in 'lattice.mat'. |
| 4 | +% ATIP_RING is initially taken from 'THERING' global variable and save as |
| 5 | +% 'lattice.mat'. |
7 | 6 | if ~(nargin == 0) |
8 | | - load(filename, 'THERING'); |
| 7 | + load(filename, 'ATIP_RING'); |
9 | 8 | end |
10 | | - if ~exist('THERING', 'var') |
| 9 | + if ~exist('ATIP_RING', 'var') |
11 | 10 | global THERING; |
12 | | - if isempty(THERING) |
13 | | - global RING; |
14 | | - if isempty(RING) |
15 | | - disp('Both RING and THERING are empty, try running storageringinit(Ringmode). Exiting with error.'); |
| 11 | + ATIP_RING = THERING; |
| 12 | + if isempty(ATIP_RING) |
| 13 | + disp('THERING global variable is empty, try running storageringinit(Ringmode). Exiting with error.'); |
16 | 14 | exit(1) |
17 | | - else |
18 | | - THERING = RING; |
19 | | - disp('THERING is empty, using RING.'); |
20 | | - end |
21 | 15 | else |
22 | | - disp('Using global THERING and modifying it in place.'); |
| 16 | + disp('Using global THERING and saving it to global ATIP_RING.'); |
23 | 17 | end |
24 | 18 | else |
25 | | - disp('Using global THERING and modifying it in place.'); |
| 19 | + disp('Using loaded ATIP_RING from file.'); |
26 | 20 | end |
27 | | - fprintf('Initial THERING has dimensions: %s\n', mat2str(size(THERING))) |
| 21 | + fprintf('Initial lattice has dimensions: %s\n', mat2str(size(ATIP_RING))) |
28 | 22 | % Correct dimension order if necessary. |
29 | | - if size(THERING, 1) == 1 |
30 | | - THERING = permute(THERING, [2 1]); |
| 23 | + if size(ATIP_RING, 1) == 1 |
| 24 | + ATIP_RING = permute(ATIP_RING, [2 1]); |
31 | 25 | end |
32 | 26 | % Correct classes and pass methods. |
33 | | - for x = 1:length(THERING) |
34 | | - if strcmp(THERING{x, 1}.FamName, 'BPM10') |
| 27 | + for x = 1:length(ATIP_RING) |
| 28 | + if strcmp(ATIP_RING{x, 1}.FamName, 'BPM10') |
35 | 29 | % Wouldn't be correctly classed by class guessing otherwise. |
36 | | - THERING{x, 1}.Class = 'Monitor'; |
37 | | - elseif (strcmp(THERING{x, 1}.FamName, 'HSTR') || strcmp(THERING{x, 1}.FamName, 'VSTR')) |
38 | | - THERING{x, 1}.Class = 'Corrector'; |
39 | | - elseif (strcmp(THERING{x, 1}.FamName, 'HTRIM') || strcmp(THERING{x, 1}.FamName, 'VTRIM')) |
40 | | - THERING{x, 1}.Class = 'Corrector'; |
| 30 | + ATIP_RING{x, 1}.Class = 'Monitor'; |
| 31 | + elseif (strcmp(ATIP_RING{x, 1}.FamName, 'HSTR') || strcmp(ATIP_RING{x, 1}.FamName, 'VSTR')) |
| 32 | + ATIP_RING{x, 1}.Class = 'Corrector'; |
| 33 | + elseif (strcmp(ATIP_RING{x, 1}.FamName, 'HTRIM') || strcmp(ATIP_RING{x, 1}.FamName, 'VTRIM')) |
| 34 | + ATIP_RING{x, 1}.Class = 'Corrector'; |
41 | 35 | end |
42 | 36 |
|
43 | | - if isfield(THERING{x, 1}, 'Class') |
44 | | - if strcmp(THERING{x, 1}.Class, 'SEXT') |
45 | | - THERING{x, 1}.Class = 'Sextupole'; |
| 37 | + if isfield(ATIP_RING{x, 1}, 'Class') |
| 38 | + if strcmp(ATIP_RING{x, 1}.Class, 'SEXT') |
| 39 | + ATIP_RING{x, 1}.Class = 'Sextupole'; |
46 | 40 | end |
47 | 41 | end |
48 | 42 |
|
49 | | - if strcmp(THERING{x, 1}.PassMethod, 'GWigSymplecticPass') |
50 | | - THERING{x, 1}.Class = 'Wiggler'; |
| 43 | + if strcmp(ATIP_RING{x, 1}.PassMethod, 'GWigSymplecticPass') |
| 44 | + ATIP_RING{x, 1}.Class = 'Wiggler'; |
51 | 45 | end |
52 | 46 | end |
53 | 47 |
|
54 | | - % Remove elements. Done this way because the size of THERING changes |
| 48 | + % Remove elements. Done this way because the size of ATIP_RING changes |
55 | 49 | % during the loop. |
56 | 50 | y = 1; |
57 | | - while y < length(THERING) |
| 51 | + while y < length(ATIP_RING) |
58 | 52 | % The data within the deleted elements is not needed |
59 | | - if strcmp(THERING{y, 1}.FamName, 'HSTR') && THERING{y, 1}.Length == 0 && (strcmp(THERING{y-1, 1}.Class, 'Sextupole') || strcmp(THERING{y-1, 1}.Class, 'Multipole')) |
60 | | - THERING(y, :) = []; % Delete hstrs that are preceded by a sextupole or multipole. |
61 | | - elseif strcmp(THERING{y, 1}.FamName, 'VSTR') && THERING{y, 1}.Length == 0 && (strcmp(THERING{y-1, 1}.Class, 'Sextupole') || strcmp(THERING{y-1, 1}.Class, 'Multipole')) |
62 | | - THERING(y, :) = []; % Delete vstrs that are preceded by a sextupole or multipole. |
| 53 | + if strcmp(ATIP_RING{y, 1}.FamName, 'HSTR') && ATIP_RING{y, 1}.Length == 0 && (strcmp(ATIP_RING{y-1, 1}.Class, 'Sextupole') || strcmp(ATIP_RING{y-1, 1}.Class, 'Multipole')) |
| 54 | + ATIP_RING(y, :) = []; % Delete hstrs that are preceded by a sextupole or multipole. |
| 55 | + elseif strcmp(ATIP_RING{y, 1}.FamName, 'VSTR') && ATIP_RING{y, 1}.Length == 0 && (strcmp(ATIP_RING{y-1, 1}.Class, 'Sextupole') || strcmp(ATIP_RING{y-1, 1}.Class, 'Multipole')) |
| 56 | + ATIP_RING(y, :) = []; % Delete vstrs that are preceded by a sextupole or multipole. |
63 | 57 | else |
64 | 58 | y = y + 1; |
65 | 59 | end |
66 | 60 | end |
67 | 61 |
|
68 | | - if isfield(THERING{1, 1}, 'TwissData') |
69 | | - THERING{1, 1} = rmfield(THERING{1, 1}, 'TwissData'); |
| 62 | + if isfield(ATIP_RING{1, 1}, 'TwissData') |
| 63 | + ATIP_RING{1, 1} = rmfield(ATIP_RING{1, 1}, 'TwissData'); |
70 | 64 | end |
71 | 65 |
|
72 | | - fprintf('Converted THERING has dimensions: %s\n', mat2str(size(THERING))) |
| 66 | + fprintf('Converted ATIP_RING has dimensions: %s\n', mat2str(size(ATIP_RING))) |
73 | 67 | if nargin == 0 |
74 | | - save('lattice.mat', 'THERING'); |
| 68 | + save('lattice.mat', 'ATIP_RING'); |
75 | 69 | else |
76 | | - save(filename, 'THERING'); |
| 70 | + save(filename, 'ATIP_RING'); |
77 | 71 | end |
78 | 72 | end |
0 commit comments