1 | function varargout=LoadRestoreFile(varargin) |
---|
2 | %============================================================= |
---|
3 | %read saved data and load structures BPM, BL, COR, RSP, SYS from file |
---|
4 | %no graphics in this routine |
---|
5 | |
---|
6 | pathname=varargin(1); pathname=char(pathname); |
---|
7 | filename=varargin(2); filename=char(filename); |
---|
8 | auto =varargin(3); auto=char(auto); |
---|
9 | sys =varargin(4); sys=sys{1}; |
---|
10 | bpm =varargin(5); bpm=bpm{1}; |
---|
11 | bl =varargin(6); bl=bl{1}; |
---|
12 | cor =varargin(7); cor=cor{1}; |
---|
13 | rsp =varargin(8); rsp=rsp{1}; |
---|
14 | |
---|
15 | if ~strcmp(auto,'auto')==1 |
---|
16 | ans=input('Load Restore File? Y/N [Y]: ','s'); |
---|
17 | if isempty(ans) ans='n'; end |
---|
18 | if ans=='n' | ans=='N' |
---|
19 | disp('WARNING: Restore File NOT LOADED'); |
---|
20 | fclose(fid); |
---|
21 | return |
---|
22 | end |
---|
23 | end |
---|
24 | %============================================================= |
---|
25 | %execute script in save file |
---|
26 | disp(['Loading Restore file... ',filename]); |
---|
27 | |
---|
28 | %store plane |
---|
29 | plane=sys.plane; |
---|
30 | run([pathname filename]); |
---|
31 | |
---|
32 | sys.xlimax=sys.mxs; %...scaling for abcissa |
---|
33 | |
---|
34 | %load response matrices NOTE: reference orbit and corrector settings not included |
---|
35 | disp(' '); |
---|
36 | if sys.machine=='SPEAR2' |
---|
37 | trsp=ReadSPEAR2Response(sys.rspfil,'auto'); |
---|
38 | elseif sys.machine=='SPEAR3' |
---|
39 | trsp=ReadSPEAR3Response(sys.rspfil,'auto'); |
---|
40 | end |
---|
41 | %load horizontal data structure |
---|
42 | rsp(1).ntbpm=trsp(1).ntbpm; |
---|
43 | rsp(1).ib=trsp(1).ib; |
---|
44 | rsp(1).ntcor=trsp(1).ntcor; |
---|
45 | rsp(1).ic=trsp(1).ic; |
---|
46 | rsp(1).c=trsp(1).c; |
---|
47 | %load vertical data structure |
---|
48 | rsp(2).ntbpm=trsp(2).ntbpm; |
---|
49 | rsp(2).ib=trsp(2).ib; |
---|
50 | rsp(2).ibl=trsp(2).ibl; |
---|
51 | rsp(2).ntcor=trsp(2).ntcor; |
---|
52 | rsp(2).ic=trsp(2).ic; |
---|
53 | rsp(2).c=trsp(2).c; |
---|
54 | rsp(2).cp=trsp(2).cp; |
---|
55 | clear trsp; |
---|
56 | |
---|
57 | disp(' '); |
---|
58 | [trsp]=ReadSP2BResp(sys.brspfil,'auto'); |
---|
59 | clear trsp; |
---|
60 | |
---|
61 | disp(' '); |
---|
62 | if sys.machine=='SPEAR2' |
---|
63 | trsp=ReadSPEAR2Dispersion(sys.etafil,'auto'); |
---|
64 | elseif sys.machine=='SPEAR3' |
---|
65 | trsp=ReadSPEAR3Dispersion(sys.etafil,'auto'); |
---|
66 | end |
---|
67 | rsp(1).eta=trsp(1).eta; |
---|
68 | rsp(1).drf=trsp(1).drf; |
---|
69 | rsp(2).eta=trsp(2).eta; |
---|
70 | rsp(2).drf=trsp(2).drf; |
---|
71 | clear trsp; |
---|
72 | |
---|
73 | %load BPM and COR data from cell arrays |
---|
74 | |
---|
75 | %***horizontal BPM*** |
---|
76 | %BPM data: name, index, fit, weight |
---|
77 | s=size(bpmx); |
---|
78 | for ii=1:s(1) |
---|
79 | ifit=bpmx{ii}(3); |
---|
80 | wt =bpmx{ii}(4); |
---|
81 | bpm(1).ifit(ii)=ifit{1}; %convert from cell to real |
---|
82 | bpm(1).wt(ii) =wt{1}; |
---|
83 | end |
---|
84 | bpm(1).ifit=find(bpm(1).ifit); %compress fitting vector |
---|
85 | |
---|
86 | %***horizontal corrector*** |
---|
87 | %COR data: name, index, fit, weight, limit, ebpm, pbpm |
---|
88 | s=size(corx); |
---|
89 | for ii=1:s(1) |
---|
90 | ifit=corx{ii}(3); |
---|
91 | wt =corx{ii}(4); |
---|
92 | lim =corx{ii}(5); |
---|
93 | ebpm=corx{ii}(6); |
---|
94 | pbpm=corx{ii}(7); |
---|
95 | cor(1).ifit(ii)=ifit{1}; %convert from cell to real |
---|
96 | cor(1).wt(ii) =wt{1}; |
---|
97 | cor(1).lim(ii) =lim{1}; |
---|
98 | cor(1).ebpm(ii)=ebpm{1}; |
---|
99 | cor(1).pbpm(ii)=pbpm{1}; |
---|
100 | end |
---|
101 | cor(1).ifit=find(cor(1).ifit); %compress fitting vector |
---|
102 | |
---|
103 | %***vertical BPM*** |
---|
104 | %BPM data: name, index, fit, weight |
---|
105 | s=size(bpmy); |
---|
106 | for ii=1:s(1) |
---|
107 | ifit=bpmy{ii}(3); |
---|
108 | wt =bpmy{ii}(4); |
---|
109 | bpm(2).ifit(ii)=ifit{1}; %convert from cell to real |
---|
110 | bpm(2).wt(ii) =wt{1}; |
---|
111 | end |
---|
112 | bpm(2).ifit=find(bpm(2).ifit); %compress fitting vector |
---|
113 | |
---|
114 | %***vertical corrector*** |
---|
115 | %COR data: name, index, fit, weight, limit, ebpm, pbpm |
---|
116 | s=size(cory); |
---|
117 | for ii=1:s(1) |
---|
118 | ifit=cory{ii}(3); |
---|
119 | wt =cory{ii}(4); |
---|
120 | lim =cory{ii}(5); |
---|
121 | ebpm=cory{ii}(6); |
---|
122 | pbpm=cory{ii}(7); |
---|
123 | cor(2).ifit(ii)=ifit{1}; %convert from cell to real |
---|
124 | cor(2).wt(ii) =wt{1}; |
---|
125 | cor(2).lim(ii) =lim{1}; |
---|
126 | cor(2).ebpm(ii)=ebpm{1}; |
---|
127 | cor(2).pbpm(ii)=pbpm{1}; |
---|
128 | end |
---|
129 | cor(2).ifit=find(cor(2).ifit); %compress fitting vector |
---|
130 | |
---|
131 | %***vertical beamline*** |
---|
132 | %BL data: name, index, fit, weight |
---|
133 | s=size(bly); |
---|
134 | for ii=1:s(1) |
---|
135 | ifit=bly{ii}(3); |
---|
136 | wt =bly{ii}(4); |
---|
137 | bl(2).ifit(ii)=ifit{1}; %convert from cell to real |
---|
138 | bl(2).wt(ii) =wt{1}; |
---|
139 | end |
---|
140 | bl(2).ifit=sort(find(bl(2).ifit)); %compress fitting vector |
---|
141 | sys.pbpm=0; |
---|
142 | if ~isempty(bl(2).ifit) sys.pbpm=1; end %measure photon bpm data |
---|
143 | |
---|
144 | %Get BPM status, sort for avail, ifit |
---|
145 | [bpm(1).status bpm(2).status]=SPEAR2BPMCheck999(bpm(1).hndl,bpm(2).hndl); |
---|
146 | bpm(1).avail=bpm(1).status; %...if status o.k. default to available |
---|
147 | bpm(2).avail=bpm(2).status; |
---|
148 | [bpm]=SortBPMs(bpm,rsp); %status, reference orbit, response matrix, ifit |
---|
149 | |
---|
150 | %Get BL status, sort for avail, ifit |
---|
151 | %measure actual photon beam position |
---|
152 | [bl(2).iopen,bl(2).open, bl(2).iauto,bl(2).auto,bl(2).sum, bl(2).err, bl(2).cur]=... |
---|
153 | GetSPEAR2BL(sys.mode,bl(2).name,bl(2).hopen,bl(2).hauto,bl(2).hsum, bl(2).herr,bl(2).hcur,3,1); |
---|
154 | %last two entries number averages, dwell |
---|
155 | %open, auto are compressed |
---|
156 | bl(2).avail=bl(2).open; %...if beam line open default to available |
---|
157 | [bl]=SortBLs(bl,rsp) ; %open, response matrix, ifit |
---|
158 | |
---|
159 | |
---|
160 | %Get COR status, sort for avail, ifit |
---|
161 | cor(1).act=getset('GetAllCor',sys.mode,1,cor(1).dbname,cor(1).ham,cor(1).name,cor(1).iAT); %returns column cell array |
---|
162 | cor(1).ref=getset('GetAllCor',sys.mode,1,cor(1).dbname,cor(1).hac,cor(1).name,cor(1).iAT); |
---|
163 | cor(2).act=getset('GetAllCor',sys.mode,2,cor(2).dbname,cor(2).ham,cor(2).name,cor(2).iAT); %returns column cell array |
---|
164 | cor(2).ref=getset('GetAllCor',sys.mode,2,cor(2).dbname,cor(2).hac,cor(2).name,cor(2).iAT); |
---|
165 | [cor]=SortCORs(cor,rsp); |
---|
166 | |
---|
167 | clear bpmx bpmy corx cory bly |
---|
168 | |
---|
169 | disp(['Finished Loading Restore file ',filename]); |
---|
170 | |
---|
171 | %acquire orbit, load into .act field |
---|
172 | [x y]=getset('GetBPM',SYS.mode,BPM(1).dbname,BPM(1).hndl,BPM(2).hndl,BPM(1).name); %load random orbit into BPM.act |
---|
173 | BPM(1).act=x(:); %row vector to column vector |
---|
174 | BPM(2).act=y(:); |
---|
175 | |
---|
176 | %photon bpm acquisition |
---|
177 | %because feedback calls GetAct directly (not UpdateAct) |
---|
178 | if SYS.pbpm==1 |
---|
179 | [bl]=GetSP2BL(sys,bl); %acquire photon bpm data |
---|
180 | end |
---|
181 | |
---|
182 | corgui('GetAct'); |
---|
183 | sys.plane=plane; %restore file might have switched planes |
---|
184 | %respgui('SolveSystem'); |
---|
185 | [rsp]=SVDecompose(sys.plane,bpm,cor,bl,rsp); |
---|
186 | %respgui('BackSubSystem'); %computes orbit based on nsvd |
---|
187 | [bpm,bl,cor]=BackSubSystem(plane,sys,bpm,bl,cor,rsp); |
---|
188 | |
---|
189 | sys.plane=plane; |
---|
190 | |
---|
191 | varargout{1}=sys; |
---|
192 | varargout{1}=bpm; |
---|
193 | varargout{1}=bl; |
---|
194 | varargout{1}=cor; |
---|
195 | varargout{1}=rsp; |
---|