Skip to content

Commit 6388498

Browse files
committed
Update create_lattice to use ATIP_RING instead of RING
I also had to regenerate the three mat files so that they store the variable ATIP_RING instead of RING
1 parent 660c852 commit 6388498

File tree

2 files changed

+35
-41
lines changed

2 files changed

+35
-41
lines changed

src/atip/rings/48.mat

-55 Bytes
Binary file not shown.
Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,72 @@
11
function create_lattice_matfile(filename)
22
% Creates a .mat file AT lattice compatible with ATIP.
33
% 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'.
76
if ~(nargin == 0)
8-
load(filename, 'THERING');
7+
load(filename, 'ATIP_RING');
98
end
10-
if ~exist('THERING', 'var')
9+
if ~exist('ATIP_RING', 'var')
1110
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.');
1614
exit(1)
17-
else
18-
THERING = RING;
19-
disp('THERING is empty, using RING.');
20-
end
2115
else
22-
disp('Using global THERING and modifying it in place.');
16+
disp('Using global THERING and saving it to global ATIP_RING.');
2317
end
2418
else
25-
disp('Using global THERING and modifying it in place.');
19+
disp('Using loaded ATIP_RING from file.');
2620
end
27-
fprintf('Initial THERING has dimensions: %s\n', mat2str(size(THERING)))
21+
fprintf('Initial lattice has dimensions: %s\n', mat2str(size(ATIP_RING)))
2822
% 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]);
3125
end
3226
% 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')
3529
% 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';
4135
end
4236

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';
4640
end
4741
end
4842

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';
5145
end
5246
end
5347

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
5549
% during the loop.
5650
y = 1;
57-
while y < length(THERING)
51+
while y < length(ATIP_RING)
5852
% 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.
6357
else
6458
y = y + 1;
6559
end
6660
end
6761

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');
7064
end
7165

72-
fprintf('Converted THERING has dimensions: %s\n', mat2str(size(THERING)))
66+
fprintf('Converted ATIP_RING has dimensions: %s\n', mat2str(size(ATIP_RING)))
7367
if nargin == 0
74-
save('lattice.mat', 'THERING');
68+
save('lattice.mat', 'ATIP_RING');
7569
else
76-
save(filename, 'THERING');
70+
save(filename, 'ATIP_RING');
7771
end
7872
end

0 commit comments

Comments
 (0)