1 | function varargout = restoreorbit(varargin) |
---|
2 | %RESTOREORBIT - Reads saved data from file |
---|
3 | %load structures sys, bpm, cor, rsp for return |
---|
4 | %no graphics in this routine |
---|
5 | % |
---|
6 | % INPUTS |
---|
7 | % 1. Directory name |
---|
8 | % 2. Filename |
---|
9 | % 3. 'auto' - for non interactif |
---|
10 | % 4. SYS structure |
---|
11 | % 5. BPM structure |
---|
12 | % 6. COR structutre |
---|
13 | % 7. RSP strucutre |
---|
14 | % |
---|
15 | % See also soleilrestore, readwrite, orbgui('SaveSet'), orbgui('SaveSystem') |
---|
16 | |
---|
17 | % |
---|
18 | % Written by William J. Corbett |
---|
19 | % Modified by Laurent S. Nadolski |
---|
20 | |
---|
21 | %% Get input arguments |
---|
22 | |
---|
23 | DirSpec = char(varargin(1)); |
---|
24 | FileName= char(varargin(2)); |
---|
25 | auto = char(varargin(3)); |
---|
26 | sys = varargin{4}; |
---|
27 | bpm = varargin{5}; |
---|
28 | cor = varargin{6}; |
---|
29 | rsp = varargin{7}; |
---|
30 | |
---|
31 | %================================= |
---|
32 | %% check automatic file load request |
---|
33 | %================================= |
---|
34 | if ~strcmp(auto,'auto') == 1 |
---|
35 | answer = input('Load Restore File? Y/N [Y]: ','s'); |
---|
36 | if isempty(answer), answer ='n'; end |
---|
37 | if answer =='n' || answer == 'N' |
---|
38 | disp('WARNING: Restore File NOT LOADED'); |
---|
39 | fclose(fid); |
---|
40 | return |
---|
41 | end |
---|
42 | end |
---|
43 | |
---|
44 | %=========================== |
---|
45 | %% execute script in save file |
---|
46 | %=========================== |
---|
47 | disp([' Loading restore file... ', FileName]); |
---|
48 | |
---|
49 | %save file is a script - contains sys, bpm, cor, rsp, bpmx, bpmz, corx, |
---|
50 | %corz |
---|
51 | run([DirSpec FileName]); |
---|
52 | |
---|
53 | if ~strcmpi(filetype,'Restore') |
---|
54 | disp(['Warning: improper file specification - ' upper(filetype)]); |
---|
55 | return |
---|
56 | else |
---|
57 | clear filetype |
---|
58 | end |
---|
59 | |
---|
60 | sys.xlimax = sys.maxs; %...scaling for abcissa |
---|
61 | |
---|
62 | %========================================================= |
---|
63 | %% load BPM to Corrector response matrices |
---|
64 | %========================================================= |
---|
65 | |
---|
66 | % automatically load golden response |
---|
67 | temp = getbpmresp('struct'); |
---|
68 | |
---|
69 | % Transform to orbit format |
---|
70 | rsp = response2rsp(temp,rsp); |
---|
71 | |
---|
72 | % read golden eta function (HW, frequency units) |
---|
73 | rsp(1).eta = getphysdata(bpm(1).AOFamily,'Dispersion'); |
---|
74 | rsp(2).eta = getphysdata(bpm(2).AOFamily,'Dispersion'); |
---|
75 | |
---|
76 | %======================================================================= |
---|
77 | %% load BPM and COR data from cell arrays acquired while running save file |
---|
78 | %======================================================================= |
---|
79 | %horizontal BPM |
---|
80 | for ii = 1 : size(bpmx,1), |
---|
81 | bpm(1).ifit(ii) = bpmx{ii}{3}; %convert from cell to real |
---|
82 | bpm(1).wt(ii) = bpmx{ii}{4}; |
---|
83 | bpm(1).etawt(ii)= bpmx{ii}{5}; |
---|
84 | end |
---|
85 | bpm(1).ifit = find(bpm(1).ifit); %compress fitting vector |
---|
86 | |
---|
87 | %horizontal corrector |
---|
88 | for ii = 1:size(corx,1), |
---|
89 | cor(1).ifit(ii)=corx{ii}{3}; %convert from cell to real |
---|
90 | cor(1).wt(ii) =corx{ii}{4}; |
---|
91 | end |
---|
92 | cor(1).ifit = find(cor(1).ifit); %compress fitting vector |
---|
93 | |
---|
94 | %vertical BPM |
---|
95 | for ii = 1:size(bpmz,1), |
---|
96 | bpm(2).ifit(ii) = bpmz{ii}{3}; %convert from cell to real |
---|
97 | bpm(2).wt(ii) = bpmz{ii}{4}; |
---|
98 | bpm(2).etawt(ii) = bpmz{ii}{5}; |
---|
99 | end |
---|
100 | bpm(2).ifit = find(bpm(2).ifit); %compress fitting vector |
---|
101 | |
---|
102 | %vertical corrector |
---|
103 | for ii = 1:size(corz,1), |
---|
104 | cor(2).ifit(ii) = corz{ii}{3}; %convert from cell to real |
---|
105 | cor(2).wt(ii) = corz{ii}{4}; |
---|
106 | end |
---|
107 | cor(2).ifit = find(cor(2).ifit); %compress fitting vector |
---|
108 | |
---|
109 | %========================================================== |
---|
110 | %% load corrector limits and response matrix kicks via AO |
---|
111 | %========================================================== |
---|
112 | AO = getao; |
---|
113 | |
---|
114 | %good = find(getfamilydata(cor(1).AOFamily,'Status')); |
---|
115 | cor(1).lim = abs(AO.(cor(1).AOFamily).Setpoint.Range(:,1)); %corrector limits |
---|
116 | %cor(1).lim = cor(1).lim(good); |
---|
117 | cor(1).ebpm=AO.(cor(1).AOFamily).Setpoint.DeltaRespMat; %kicks for response matrix |
---|
118 | %cor(1).ebpm = cor(1).ebpm(good); |
---|
119 | |
---|
120 | cor(2).lim =abs(AO.(cor(2).AOFamily).Setpoint.Range(:,1)); |
---|
121 | %cor(2).lim = cor(2).lim(good); |
---|
122 | cor(2).ebpm=AO.(cor(2).AOFamily).Setpoint.DeltaRespMat; |
---|
123 | %cor(2).ebpm = cor(2).ebpm(good); |
---|
124 | |
---|
125 | disp([' Finished loading restore file... ',FileName]); |
---|
126 | |
---|
127 | varargout{1} = sys; |
---|
128 | varargout{2} = bpm; |
---|
129 | varargout{3} = cor; |
---|
130 | varargout{4} = rsp; |
---|