0001 function setlocodata(CommandInput, FileName)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 global THERING
0035
0036 if nargin < 1
0037
0038 ModeCell = {'Nominal - Set Gain=1 & Rolls=0 in the model', 'SetGains - Set gains/rolls from a LOCO file','Symmetrize - Symmetry correction of the lattice', 'CorrectCoupling - Coupling correction of the lattice', 'SetModel - Set the model from a LOCO file','LOCO2Model - Set the model from a LOCO file (also does a SetGains)', 'see "help setlocodata" for more details'};
0039 [ModeNumber, OKFlag] = listdlg('Name','Soleil','PromptString', ...
0040 'Select the proper set LOCO data command:', ...
0041 'SelectionMode','single', 'ListString', ModeCell, 'ListSize', [500 200]);
0042 if OKFlag ~= 1
0043 fprintf(' setlocodata cancelled\n');
0044 return
0045 end
0046 if ModeNumber == 1
0047 CommandInput = 'Nominal';
0048 elseif ModeNumber == 2
0049 CommandInput = 'SetGains';
0050 elseif ModeNumber == 3
0051 CommandInput = 'Symmetrize';
0052 elseif ModeNumber == 4
0053 CommandInput = 'CorrectCoupling';
0054 elseif ModeNumber == 5
0055 CommandInput = 'SetModel';
0056 elseif ModeNumber == 6
0057 CommandInput = 'LOCO2Model';
0058 elseif ModeNumber == 7
0059 help setlocodata;
0060 return
0061 end
0062 end
0063
0064
0065 if nargin < 2
0066
0067
0068 FileName = getfamilydata('OpsData','LOCOFile');
0069 end
0070
0071
0072
0073 BPMxDeviceList = family2dev('BPMx');
0074 BPMxDeviceListTotal = family2dev('BPMx',0);
0075
0076 BPMzDeviceList = family2dev('BPMz');
0077 BPMzDeviceListTotal = family2dev('BPMz',0);
0078
0079 HCORDeviceList = family2dev('HCOR');
0080 HCORDeviceListTotal = family2dev('HCOR',0);
0081 VCORDeviceList = family2dev('VCOR');
0082 VCORDeviceListTotal = family2dev('VCOR',0);
0083
0084
0085 if any(strcmpi(CommandInput, 'Nominal'))
0086 fprintf(' Using nominal BPM and corrector Gain=1 and Roll=0\n');
0087
0088
0089 AO = getao;
0090
0091
0092 AO.BPMx.Gain = ones(size(BPMxDeviceListTotal,1),1);
0093 AO.BPMz.Gain = ones(size(BPMzDeviceListTotal,1),1);
0094 AO.BPMx.Roll = zeros(size(BPMxDeviceListTotal,1),1);
0095 AO.BPMz.Roll = zeros(size(BPMzDeviceListTotal,1),1);
0096 AO.BPMx.Crunch = zeros(size(BPMxDeviceListTotal,1),1);
0097 AO.BPMz.Crunch = zeros(size(BPMzDeviceListTotal,1),1);
0098
0099 AO.HCOR.Gain = ones(size(HCORDeviceListTotal,1),1);
0100 AO.VCOR.Gain = ones(size(VCORDeviceListTotal,1),1);
0101 AO.HCOR.Roll = zeros(size(HCORDeviceListTotal,1),1);
0102 AO.VCOR.Roll = zeros(size(VCORDeviceListTotal,1),1);
0103
0104
0105
0106 setatfield('BPMx', 'GCR', [AO.BPMx.Gain AO.BPMz.Gain AO.BPMx.Crunch AO.BPMx.Roll], BPMxDeviceListTotal);
0107
0108
0109
0110
0111
0112 setatfield('HCOR', 'Roll', 0*AO.HCOR.Roll, HCORDeviceListTotal, 1, 2);
0113 setatfield('VCOR', 'Roll', 0*AO.VCOR.Roll, VCORDeviceListTotal, 1, 1);
0114
0115
0116 setatfield('HCOR', 'Roll', AO.HCOR.Roll, HCORDeviceListTotal, 1, 1);
0117 setatfield('VCOR', 'Roll', AO.VCOR.Roll, VCORDeviceListTotal, 1, 2);
0118
0119 setao(AO);
0120
0121
0122 elseif any(strcmpi(CommandInput, 'SetGains'))
0123
0124 if isempty(FileName) || strcmp(FileName, '.')
0125 if isempty(FileName)
0126 [FileName, DirectoryName] = uigetfile('*.mat', 'LOCO Output File Name?', [getfamilydata('Directory','DataRoot'), 'LOCO', filesep]);
0127 else
0128 [FileName, DirectoryName] = uigetfile('*.mat', 'LOCO Output File Name?');
0129 end
0130 drawnow;
0131 if isequal(FileName,0) || isequal(DirectoryName,0)
0132 fprintf(' setlocodata canceled\n');
0133 return
0134 end
0135 FileName = [DirectoryName FileName];
0136 end
0137
0138
0139 setlocodata('Nominal');
0140
0141 AO = getao;
0142
0143
0144 fprintf(' Setting BPM and corrector gains and rolls based on %s.\n', FileName);
0145 load(FileName);
0146
0147
0148
0149 try
0150 BPMxDeviceList = LocoMeasData.HBPM.DeviceList;
0151 BPMzDeviceList = LocoMeasData.VBPM.DeviceList;
0152 HCORDeviceList = LocoMeasData.HCOR.DeviceList;
0153 VCORDeviceList = LocoMeasData.VCOR.DeviceList;
0154 catch
0155
0156 BPMxDeviceList = LocoMeasData.(BPMxFamily).DeviceList;
0157 BPMzDeviceList = LocoMeasData.(BPMzFamily).DeviceList;
0158 HCORDeviceList = LocoMeasData.(HCORFamily).DeviceList;
0159 VCORDeviceList = LocoMeasData.(VCORFamily).DeviceList;
0160 end
0161
0162
0163
0164 i = findrowindex(BPMxDeviceList, BPMxDeviceListTotal);
0165 for j = 1:length(BPMData(end).HBPMGain)
0166 MLOCO = [BPMData(end).HBPMGain(j) BPMData(end).HBPMCoupling(j)
0167 BPMData(end).VBPMCoupling(j) BPMData(end).VBPMGain(j) ];
0168
0169 [AO.(BPMxFamily).Gain(i(j),:), AO.(BPMzFamily).Gain(i(j),:), AO.(BPMxFamily).Crunch(i(j),:), AO.(BPMxFamily).Roll(i(j),:)] = loco2gcr(MLOCO);
0170 end
0171 AO.(BPMzFamily).Roll = AO.(BPMxFamily).Roll;
0172 AO.(BPMzFamily).Crunch = AO.(BPMxFamily).Crunch;
0173
0174 if ~isreal(AO.(BPMxFamily).Gain)
0175 error('Horizontal BPM gain is complex.');
0176 end
0177 if ~isreal(AO.(BPMzFamily).Gain)
0178 error('Vertical BPM gain is complex.');
0179 end
0180 if ~isreal(AO.(BPMxFamily).Crunch)
0181 error('BPM Crunch is complex.');
0182 end
0183 if ~isreal(AO.(BPMxFamily).Roll)
0184 error('BPM roll is complex.');
0185 end
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201 i = findrowindex(HCORDeviceList, HCORDeviceListTotal);
0202
0203 HCORGainOldLOCO = LocoMeasData.HCORGain .* cos(LocoMeasData.HCORRoll);
0204 HCORGainLOCO = HCORGainOldLOCO .* CMData(end).HCORKicks ./ CMData(1).HCORKicks;
0205 HCORCouplingLOCO = HCORGainLOCO .* CMData(end).HCORCoupling;
0206
0207
0208 AO.(HCORFamily).Roll(i) = atan(HCORCouplingLOCO ./ abs(HCORGainLOCO));
0209 AO.(HCORFamily).Gain(i) = sign(HCORGainLOCO) .* sqrt(HCORCouplingLOCO.^2 + HCORGainLOCO.^2);
0210
0211
0212
0213 i = findrowindex(VCORDeviceList, VCORDeviceListTotal);
0214
0215 VCORGainOldLOCO = LocoMeasData.VCORGain .* cos(LocoMeasData.VCORRoll);
0216 VCORGainLOCO = VCORGainOldLOCO .* CMData(end).VCORKicks ./ CMData(1).VCORKicks;
0217 VCORCouplingLOCO = VCORGainLOCO .* CMData(end).VCORCoupling;
0218
0219
0220 AO.(VCORFamily).Roll(i) = atan(-VCORCouplingLOCO ./ abs(VCORGainLOCO));
0221 AO.(VCORFamily).Gain(i) = sign(VCORGainLOCO) .* sqrt(VCORCouplingLOCO.^2 + VCORGainLOCO.^2);
0222
0223
0224
0225 setatfield(BPMxFamily, 'GCR', [AO.(BPMxFamily).Gain AO.(BPMzFamily).Gain AO.(BPMxFamily).Crunch AO.(BPMxFamily).Roll], BPMxDeviceListTotal);
0226
0227
0228
0229
0230
0231 setatfield(HCORFamily, 'Roll', 0*AO.(HCORFamily).Roll, HCORDeviceListTotal, 1, 2);
0232 setatfield(VCORFamily, 'Roll', 0*AO.(VCORFamily).Roll, VCORDeviceListTotal, 1, 1);
0233
0234
0235 setatfield(HCORFamily, 'Roll', AO.(HCORFamily).Roll, HCORDeviceListTotal, 1, 1);
0236 setatfield(VCORFamily, 'Roll', AO.(VCORFamily).Roll, VCORDeviceListTotal, 1, 2);
0237
0238
0239
0240
0241 setao(AO);
0242
0243
0244 elseif any(strcmpi(CommandInput, 'SetModel'))
0245
0246 error(' Function not complete. Look at the ALS setlocodata for an example.');
0247
0248 elseif any(strcmpi(CommandInput, 'SetMachine'))
0249
0250 if isempty(FileName) || strcmp(FileName, '.')
0251 if isempty(FileName)
0252 [FileName, DirectoryName] = uigetfile('*.mat', 'LOCO Output File Name?', [getfamilydata('Directory','DataRoot'), 'LOCO', filesep]);
0253 else
0254 [FileName, DirectoryName] = uigetfile('*.mat', 'LOCO Output File Name?');
0255 end
0256 drawnow;
0257 if isequal(FileName,0) || isequal(DirectoryName,0)
0258 fprintf(' setlocodata canceled\n');
0259 return
0260 end
0261 FileName = [DirectoryName FileName];
0262 end
0263
0264
0265 load(FileName);
0266
0267
0268
0269 error('You need to edit here with your parameter setting program!')
0270
0271 le = length(FitParameters);
0272
0273 QFscale(1:6) = FitParameters(1).Values(1)/FitParameters(le).Values(1);
0274 QFscale(7:28) = FitParameters(1).Values(2:23)./FitParameters(le).Values(2:23);
0275 QDscale(1:6) = FitParameters(1).Values(24)/FitParameters(le).Values(24);
0276 QDscale(7:28) = FitParameters(1).Values(25:46)./FitParameters(le).Values(25:46);
0277 QFCscale = FitParameters(1).Values(47)/FitParameters(le).Values(47);
0278 QDXscale = FitParameters(1).Values(48)/FitParameters(le).Values(48);
0279 QFXscale = FitParameters(1).Values(49)/FitParameters(le).Values(49);
0280 QDYscale = FitParameters(1).Values(50)/FitParameters(le).Values(50);
0281 QFYscale = FitParameters(1).Values(51)/FitParameters(le).Values(51);
0282 QDZscale = FitParameters(1).Values(52)/FitParameters(le).Values(52);
0283 QFZscale = FitParameters(1).Values(53)/FitParameters(le).Values(53);
0284
0285 QFnew = QFscale'.*getsp('QF');
0286 QDnew = QDscale'.*getsp('QD');
0287 QFCnew = QFCscale*getsp('QFC');
0288 QDXnew = QDXscale*getsp('QDX');
0289 QFXnew = QFXscale*getsp('QFX');
0290 QDYnew = QDYscale*getsp('QDY');
0291 QFYnew = QFYscale*getsp('QFY');
0292 QDZnew = QDZscale*getsp('QDZ');
0293 QFZnew = QFZscale*getsp('QFZ');
0294
0295
0296 setsp('QF', QFnew);
0297 setsp('QD', QDnew);
0298 setsp('QFC', QFCnew);
0299
0300 setsp('QFX', QFXnew);
0301 setsp('QFY', QFYnew);
0302 setsp('QFZ', QFZnew);
0303
0304 setsp('QDX', QDXnew);
0305 setsp('QDY', QDYnew);
0306 setsp('QDZ', QDZnew);
0307
0308
0309 elseif any(strcmpi(CommandInput, 'CorrectCoupling'))
0310
0311 if isempty(FileName) || strcmp(FileName, '.')
0312 if isempty(FileName)
0313 [FileName, DirectoryName] = uigetfile('*.mat', 'LOCO Output File Name?', [getfamilydata('Directory','DataRoot'), 'LOCO', filesep]);
0314 else
0315 [FileName, DirectoryName] = uigetfile('*.mat', 'LOCO Output File Name?');
0316 end
0317 drawnow;
0318 if isequal(FileName,0) || isequal(DirectoryName,0)
0319 fprintf(' setlocodata canceled\n');
0320 return
0321 end
0322 FileName = [DirectoryName FileName];
0323 end
0324
0325
0326
0327 load(FileName);
0328
0329 NQT = size(family2dev('QT'),1);
0330 fprintf(' Correcting the coupling based on LOCO file %s.\n', FileName);
0331 fprintf(' It is assumed that the QT are in FitParameters.Values(end-%d:end)\n', NQT-1);
0332
0333 QT = FitParameters(end).Values(end-(NQT-1):end);
0334
0335
0336 MachineConfig = LocoMeasData.MachineConfig;
0337 setpv(MachineConfig.QT.Setpoint);
0338
0339 QThw = physics2hw('QT', 'Setpoint', -QT);
0340
0341
0342 if any(abs(MachineConfig.QT.Setpoint.Data+QThw)>maxsp('QT'))
0343 error('At least one of the QT would go beyond it''s limit ... aborting coupling correction');
0344 end
0345
0346
0347 stepsp('QT', QThw);
0348
0349
0350 CorrectFlag = questdlg('Keep the new skew quadrupole setpoints or return to the old values?','SETLOCOGAINS(''CorrectCoupling'')','Keep this lattice','Restore Old Lattice','Keep this lattice');
0351 if strcmpi(CorrectFlag, 'Restore Old Lattice') || isempty(CorrectFlag)
0352 fprintf(' Changing the skew quadrupole magnets back to the original setpoints.\n');
0353 stepsp('QT', QThw);
0354 end
0355
0356
0357 elseif any(strcmpi(CommandInput, 'LOCO2Model'))
0358
0359
0360
0361
0362
0363
0364 if isempty(FileName) || strcmp(FileName, '.')
0365 if isempty(FileName)
0366 [FileName, DirectoryName] = uigetfile('*.mat', 'LOCO Output File Name?', [getfamilydata('Directory','DataRoot'), 'LOCO', filesep]);
0367 else
0368 [FileName, DirectoryName] = uigetfile('*.mat', 'LOCO Output File Name?');
0369 end
0370 drawnow;
0371 if isequal(FileName,0) || isequal(DirectoryName,0)
0372 fprintf(' setlocodata canceled\n');
0373 return
0374 end
0375 FileName = [DirectoryName FileName];
0376 end
0377
0378
0379
0380 load(FileName);
0381
0382
0383
0384
0385 global THERING
0386
0387 for i = 1:length(FitParameters(end).Params)
0388 RINGData = locosetlatticeparam(RINGData, FitParameters(end).Params{i}, FitParameters(end).Values(i));
0389 end
0390 THERING = RINGData.Lattice;
0391
0392
0393
0394
0395
0396
0397
0398 setlocodata('SetGains', FileName);
0399
0400 else
0401
0402 error(' ');
0403
0404 end