1 | /****************************************************************************/ |
---|
2 | /* void read_script(const char *param_file_name, bool rd_lat) |
---|
3 | |
---|
4 | Purpose: |
---|
5 | read script written by the user. |
---|
6 | 1) User can specify lattice file name, vacuum chamber name, and bool flags such as tune |
---|
7 | tracking flag, tune shift with energy flag, etc. |
---|
8 | 2) In this function, Lattice is read, bool flags are set. |
---|
9 | |
---|
10 | Input: |
---|
11 | param_file_name user script name |
---|
12 | |
---|
13 | Output: |
---|
14 | none |
---|
15 | |
---|
16 | Return: |
---|
17 | global values and global bool flags |
---|
18 | |
---|
19 | Global variables: |
---|
20 | bool flags |
---|
21 | |
---|
22 | specific functions: |
---|
23 | Read_Lattice() |
---|
24 | |
---|
25 | Comments: |
---|
26 | Written by Jianfeng Zhang 03/2011 soleil |
---|
27 | |
---|
28 | (1) 15/10/2013 by Jianfeng Zhang @ LAL |
---|
29 | Fix the bugs of fgets(): |
---|
30 | to read lines with arbritracy length, |
---|
31 | to read the empty space at the end of the line. |
---|
32 | |
---|
33 | Remove the rontine to move the address of "line" if the |
---|
34 | contents of "line" is empty space; otherwise free() can't |
---|
35 | find the orignial address of "line". |
---|
36 | |
---|
37 | |
---|
38 | ****************************************************************************/ |
---|
39 | |
---|
40 | /* files */ |
---|
41 | |
---|
42 | char lat_file[max_str]="voidlattice"; |
---|
43 | // girder file |
---|
44 | char girder_file[max_str]; |
---|
45 | |
---|
46 | |
---|
47 | |
---|
48 | // multipole files; for soleil lattice |
---|
49 | char multipole_file[max_str]; |
---|
50 | // multipole file for soleil lattice |
---|
51 | char fic_hcorr[max_str],fic_vcorr[max_str], fic_skew[max_str]; |
---|
52 | // files to set sources of coupling; for SOLEIL lattice |
---|
53 | char virtualskewquad_file[max_str]; |
---|
54 | |
---|
55 | //errors |
---|
56 | //char fe_file[max_str]; //the same as multipole_file[max_str]???? |
---|
57 | |
---|
58 | /* COD correction */ |
---|
59 | int nwh = 56, nwv = 56; //number of singular values for SVD correction |
---|
60 | |
---|
61 | /* ID compensation */ |
---|
62 | char IDCq_name[max_str][11]; |
---|
63 | |
---|
64 | |
---|
65 | //multipole field error correction (SOLEIL based) |
---|
66 | char hcorr_file[max_str], vcorr_file[max_str]; //files with the status of hcorr/vcorr status, |
---|
67 | //to choose which correctors are used for orbit correction |
---|
68 | //default name of special elements in lattice |
---|
69 | char hcorr_name[max_str] = "", vcorr_name[max_str] = ""; |
---|
70 | char skew_quad_name[max_str] = "", bpm_name[max_str] = ""; |
---|
71 | char gs_name[max_str] = "", ge_name[max_str] = ""; |
---|
72 | |
---|
73 | #define OLD_LATTICE |
---|
74 | |
---|
75 | /* Read script */ |
---|
76 | void read_script(const char *param_file_name, bool rd_lat, long& CommNo, UserCommand UserCommandFlag[]) |
---|
77 | { |
---|
78 | |
---|
79 | |
---|
80 | char str[max_str]="voidstring", dummy[max_str]="voidstring",dummy2[max_str]="voidstring", nextpara[max_str]="voidpara"; |
---|
81 | char in[max_str]; //temporary line with preceding white space |
---|
82 | char *line = NULL; //line to store the command without preceding white space |
---|
83 | size_t len = 0; |
---|
84 | ssize_t read; |
---|
85 | char name[max_str]="voidname"; |
---|
86 | // char lat_file[max_str]="voidlattice"; |
---|
87 | char EndName[]="void"; |
---|
88 | |
---|
89 | FILE *inf; |
---|
90 | const bool prt = false; // for debugging printout each line of input file |
---|
91 | long int LineNum=0L; |
---|
92 | long int NameLen=0L; |
---|
93 | int idummy=0; |
---|
94 | char full_param_file_name[max_str]; |
---|
95 | char lat_FileName[max_str]; |
---|
96 | //bool TuneTracFlag; |
---|
97 | char *pch; |
---|
98 | |
---|
99 | |
---|
100 | // Manipulation of the parameter file |
---|
101 | strcpy(dummy, param_file_name); |
---|
102 | |
---|
103 | sprintf(full_param_file_name,"%s",dummy); |
---|
104 | if (!prt) printf("\n reading in script file: %s\n",full_param_file_name); |
---|
105 | |
---|
106 | // |
---|
107 | inf = file_read(full_param_file_name); |
---|
108 | if(inf == NULL){ |
---|
109 | printf("read_script(): Error! Read File %s Failure!\n",full_param_file_name); |
---|
110 | exit_(1); |
---|
111 | } |
---|
112 | |
---|
113 | // read parameter file, line by line |
---|
114 | while ((read = getline(&line, &len, inf)) != -1) { |
---|
115 | |
---|
116 | LineNum++; |
---|
117 | if(prt){ |
---|
118 | printf("Line # %ld \n",LineNum); |
---|
119 | printf("Retrieved line of length %zu : \n",read); |
---|
120 | cout << line << endl; |
---|
121 | } |
---|
122 | |
---|
123 | |
---|
124 | |
---|
125 | /* read the end of line symbol '\n','\r' or '\r\n' at different operation system*/ |
---|
126 | if (strstr(line, "#") == NULL && line[0] != '\n' && |
---|
127 | line[0] != '\r' && strcmp(line, "\r\n") != 0 ){ |
---|
128 | // get initial command token |
---|
129 | sscanf(line, "%s", name); |
---|
130 | //initialize the nextpara for each new command line |
---|
131 | strcpy(nextpara,"voidpara"); |
---|
132 | |
---|
133 | |
---|
134 | //find the sequence of the bool flag in user input script |
---|
135 | NameLen = strlen(name); |
---|
136 | EndName[0] = name[NameLen-4]; |
---|
137 | EndName[1] = name[NameLen-3]; |
---|
138 | EndName[2] = name[NameLen-2]; |
---|
139 | EndName[3] = name[NameLen-1]; |
---|
140 | |
---|
141 | //find the bool flag whose last 4 character are 'Flag' |
---|
142 | if(strcmp(EndName,"Flag")==0) |
---|
143 | CommNo++; |
---|
144 | |
---|
145 | |
---|
146 | /*read file names................. */ |
---|
147 | /* set file directory*/ |
---|
148 | if (strcmp("in_dir", name) == 0) |
---|
149 | sscanf(line, "%*s %s", in_dir); |
---|
150 | /* lattice file......*/ |
---|
151 | else if (strcmp("lat_file", name) == 0){ |
---|
152 | sscanf(line, "%*s %s", lat_file); |
---|
153 | sprintf(lat_FileName, "%s%s", in_dir, lat_file); |
---|
154 | if(rd_lat) { |
---|
155 | #ifdef OLD_LATTICE |
---|
156 | fprintf(stderr, "Reading lattice"); |
---|
157 | Read_Lattice(lat_FileName); |
---|
158 | #else |
---|
159 | /* fprintf(stderr, "Reading lattice with new parser\n"); |
---|
160 | sprintf(lat_FileName, "%s%s.lat", in_dir, lat_file); |
---|
161 | parse_lattice_flat(lat_FileName, "new.flat"); |
---|
162 | fprintf(stderr, "Parse the lattice into new.flat\n"); |
---|
163 | rdmfile("new.flat"); |
---|
164 | sprintf(lat_FileName, "%s%s", in_dir, lat_file); |
---|
165 | */ |
---|
166 | #endif |
---|
167 | } |
---|
168 | |
---|
169 | } |
---|
170 | |
---|
171 | /* other file names.....*/ |
---|
172 | else if (strcmp("multipole_file", name) == 0){ |
---|
173 | sscanf(line, "%*s %s", str); |
---|
174 | sprintf(multipole_file,"%s%s", in_dir, str); /* add file directory of the multipole file*/ |
---|
175 | } //virtual skew quadrupole file; for soleil lattice |
---|
176 | else if (strcmp("virtualskewquad_file", name) == 0){ |
---|
177 | sscanf(line, "%*s %s", str); |
---|
178 | sprintf(virtualskewquad_file,"%s%s", in_dir, str); /* add file directory of the multipole file*/ |
---|
179 | } |
---|
180 | |
---|
181 | /* read in bool flags */ |
---|
182 | else if (strcmp("QuadFringeOnFlag", name) == 0){ |
---|
183 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
184 | } |
---|
185 | else if (strcmp("QuadFringeOffFlag", name) == 0){ |
---|
186 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
187 | } |
---|
188 | else if (strcmp("RFvoltageFlag", name) == 0){ |
---|
189 | sscanf(line, "%*s %lf", &(UserCommandFlag[CommNo].RFvolt)); |
---|
190 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
191 | } |
---|
192 | |
---|
193 | //read chamber file flat |
---|
194 | else if (strcmp("ReadChamberFlag", name) == 0){ |
---|
195 | sscanf(line, "%*s %s", str); |
---|
196 | sprintf(UserCommandFlag[CommNo].chamber_file,"%s%s", in_dir, str); |
---|
197 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
198 | } |
---|
199 | //read field error, GENERIC command |
---|
200 | else if (strcmp("ReadfefileFlag", name) == 0){ |
---|
201 | sscanf(line, "%*s %s", str); |
---|
202 | sprintf(UserCommandFlag[CommNo].fe_file,"%s%s", in_dir, str); |
---|
203 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
204 | } |
---|
205 | //read misalignment error, then do orbit correction |
---|
206 | else if (strcmp("ReadaefileFlag", name) == 0){ |
---|
207 | sscanf(line, "%*s %s", str); |
---|
208 | sprintf(UserCommandFlag[CommNo].ae_file,"%s%s", in_dir, str); |
---|
209 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
210 | } |
---|
211 | //read multipole errors; specific for SOLEIL lattice |
---|
212 | else if (strcmp("ReadMultipoleFlag", name) == 0){ |
---|
213 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
214 | }else if (strcmp("fic_hcorr", name) == 0){// read of h-correctors for multipoles |
---|
215 | sscanf(line, "%*s %s", str); |
---|
216 | sprintf(fic_hcorr,"%s%s", in_dir, str); |
---|
217 | }else if (strcmp("fic_vcorr", name) == 0){// read of v-correctors for multipoles |
---|
218 | sscanf(line, "%*s %s", str); |
---|
219 | sprintf(fic_vcorr,"%s%s", in_dir, str); |
---|
220 | }else if (strcmp("fic_skew", name) == 0){// read of skew quads for multipoles |
---|
221 | sscanf(line, "%*s %s", str); |
---|
222 | sprintf(fic_skew,"%s%s", in_dir, str); |
---|
223 | } |
---|
224 | // for soleil lattice |
---|
225 | else if (strcmp("ReadVirtualSkewquadFlag", name) == 0){ |
---|
226 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
227 | } |
---|
228 | //print twiss parameters flag |
---|
229 | else if (strcmp("PrintTwissFlag", name) == 0){ |
---|
230 | sscanf(line, "%*s %s",nextpara); |
---|
231 | |
---|
232 | if(strcmp(nextpara,"voidpara")!=0) |
---|
233 | sscanf(line, "%*s %s", UserCommandFlag[CommNo]._PrintTwiss_twiss_file); |
---|
234 | |
---|
235 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
236 | } |
---|
237 | //print close orbit(COD) flag |
---|
238 | else if (strcmp("PrintCODFlag", name) == 0){ |
---|
239 | sscanf(line, "%*s %s",nextpara); |
---|
240 | |
---|
241 | if(strcmp(nextpara,"voidpara")!=0) |
---|
242 | sscanf(line, "%*s %s", UserCommandFlag[CommNo]._PrintCOD_cod_file); |
---|
243 | |
---|
244 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
245 | } |
---|
246 | //print the cooridinates using tracking at each element |
---|
247 | else if (strcmp("PrintTrackFlag", name) == 0){ |
---|
248 | sscanf(line, "%*s %s",nextpara); |
---|
249 | |
---|
250 | if(strcmp(nextpara,"voidpara")!=0) |
---|
251 | sscanf(line, "%*s %s %lf %lf %lf %lf %lf %lf %ld", |
---|
252 | UserCommandFlag[CommNo]._PrintTrack_track_file, |
---|
253 | &(UserCommandFlag[CommNo]._PrintTrack_x), |
---|
254 | &(UserCommandFlag[CommNo]._PrintTrack_px), |
---|
255 | &(UserCommandFlag[CommNo]._PrintTrack_y), |
---|
256 | &(UserCommandFlag[CommNo]._PrintTrack_py), |
---|
257 | &(UserCommandFlag[CommNo]._PrintTrack_delta), |
---|
258 | &(UserCommandFlag[CommNo]._PrintTrack_ctau), |
---|
259 | &(UserCommandFlag[CommNo]._PrintTrack_nmax)); |
---|
260 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
261 | } |
---|
262 | //print the cooridinates using tracking at each element |
---|
263 | else if (strcmp("PrintTrackElemFlag", name) == 0){ |
---|
264 | sscanf(line, "%*s %s",nextpara); |
---|
265 | |
---|
266 | if(strcmp(nextpara,"voidpara")!=0) |
---|
267 | sscanf(line, "%*s %s %lf %lf %lf %lf %lf %lf %ld %ld", |
---|
268 | UserCommandFlag[CommNo]._PrintTrackElem_track_file, |
---|
269 | &(UserCommandFlag[CommNo]._PrintTrackElem_x), |
---|
270 | &(UserCommandFlag[CommNo]._PrintTrackElem_px), |
---|
271 | &(UserCommandFlag[CommNo]._PrintTrackElem_y), |
---|
272 | &(UserCommandFlag[CommNo]._PrintTrackElem_py), |
---|
273 | &(UserCommandFlag[CommNo]._PrintTrackElem_delta), |
---|
274 | &(UserCommandFlag[CommNo]._PrintTrackElem_ctau), |
---|
275 | &(UserCommandFlag[CommNo]._PrintTrackElem_nelem1), |
---|
276 | &(UserCommandFlag[CommNo]._PrintTrackElem_nelem2)); |
---|
277 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
278 | } |
---|
279 | //print close orbit(COD) flag |
---|
280 | else if (strcmp("PrintGirderFlag", name) == 0){ |
---|
281 | sscanf(line, "%*s %s", girder_file); |
---|
282 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
283 | } |
---|
284 | |
---|
285 | |
---|
286 | else if (strcmp("TuneTracFlag", name) == 0){ |
---|
287 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
288 | } |
---|
289 | else if (strcmp("ChromTracFlag", name) == 0){ |
---|
290 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
291 | } |
---|
292 | // FMA |
---|
293 | else if (strcmp("FmapFlag", name) == 0){ |
---|
294 | strcpy(dummy, ""); |
---|
295 | strcpy(dummy2,""); |
---|
296 | sscanf(line, "%*s %s",nextpara); |
---|
297 | |
---|
298 | //if no definition of loss flag in the lattice file, then "dummy2" is empty string. |
---|
299 | if(strcmp(nextpara,"voidpara")!=0) |
---|
300 | sscanf(line, "%*s %s %ld %ld %ld %lf %lf %lf %s %s", |
---|
301 | UserCommandFlag[CommNo]._FmapFlag_fmap_file, |
---|
302 | &(UserCommandFlag[CommNo]._FmapFlag_nxpoint), |
---|
303 | &(UserCommandFlag[CommNo]._FmapFlag_nypoint), |
---|
304 | &(UserCommandFlag[CommNo]._FmapFlag_nturn), |
---|
305 | &(UserCommandFlag[CommNo]._FmapFlag_xmax), |
---|
306 | &(UserCommandFlag[CommNo]._FmapFlag_ymax), |
---|
307 | &(UserCommandFlag[CommNo]._FmapFlag_delta), |
---|
308 | dummy,dummy2); |
---|
309 | |
---|
310 | if(strcmp(dummy, "true") == 0) |
---|
311 | UserCommandFlag[CommNo]._FmapFlag_diffusion = true; |
---|
312 | else if(strcmp(dummy, "false") == 0) |
---|
313 | UserCommandFlag[CommNo]._FmapFlag_diffusion = false; |
---|
314 | |
---|
315 | if(strcmp(dummy2, "true") == 0) |
---|
316 | UserCommandFlag[CommNo]._FmapFlag_printloss = true; |
---|
317 | else if(strcmp(dummy2, "false") == 0) |
---|
318 | UserCommandFlag[CommNo]._FmapFlag_printloss = false; |
---|
319 | else |
---|
320 | UserCommandFlag[CommNo]._FmapFlag_printloss = false; |
---|
321 | |
---|
322 | |
---|
323 | //cout << "debug: " << line << endl; |
---|
324 | //cout << "dummy2 = " << dummy2 << " lossflag = " << UserCommandFlag[CommNo]._FmapFlag_printloss << endl; |
---|
325 | |
---|
326 | // FmapFlag = true; |
---|
327 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
328 | } |
---|
329 | // FMA dp |
---|
330 | else if (strcmp("FmapdpFlag", name) == 0){ |
---|
331 | strcpy(dummy, ""); |
---|
332 | strcpy(dummy2,""); |
---|
333 | sscanf(line, "%*s %s",nextpara); |
---|
334 | |
---|
335 | if(strcmp(nextpara,"voidpara")!=0) |
---|
336 | sscanf(line, "%*s %s %ld %ld %ld %lf %lf %lf %s %s", |
---|
337 | UserCommandFlag[CommNo]._FmapdpFlag_fmapdp_file, |
---|
338 | &(UserCommandFlag[CommNo]._FmapdpFlag_nxpoint), |
---|
339 | &(UserCommandFlag[CommNo]._FmapdpFlag_nepoint), |
---|
340 | &(UserCommandFlag[CommNo]._FmapdpFlag_nturn), |
---|
341 | &(UserCommandFlag[CommNo]._FmapdpFlag_xmax), |
---|
342 | &(UserCommandFlag[CommNo]._FmapdpFlag_emax), |
---|
343 | &(UserCommandFlag[CommNo]._FmapdpFlag_z), |
---|
344 | dummy,dummy2); |
---|
345 | |
---|
346 | if(strcmp(dummy, "true") == 0) |
---|
347 | UserCommandFlag[CommNo]._FmapdpFlag_diffusion = true; |
---|
348 | else if(strcmp(dummy, "false") == 0) |
---|
349 | UserCommandFlag[CommNo]._FmapdpFlag_diffusion = false; |
---|
350 | |
---|
351 | if(strcmp(dummy2, "true") == 0) |
---|
352 | UserCommandFlag[CommNo]._FmapdpFlag_printloss = true; |
---|
353 | else if(strcmp(dummy2, "false") == 0) |
---|
354 | UserCommandFlag[CommNo]._FmapdpFlag_printloss = false; |
---|
355 | else |
---|
356 | UserCommandFlag[CommNo]._FmapdpFlag_printloss = false; |
---|
357 | |
---|
358 | |
---|
359 | cout << "debug: " << line << endl; |
---|
360 | cout << "dummy2 = " << dummy2 << " lossflag = " << UserCommandFlag[CommNo]._FmapdpFlag_printloss << endl; |
---|
361 | |
---|
362 | // FmapdpFlag = true; |
---|
363 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
364 | } |
---|
365 | else if (strcmp("AmplitudeTuneShiftFlag", name) == 0){ |
---|
366 | sscanf(line, "%*s %s",nextpara); |
---|
367 | |
---|
368 | if(strcmp(nextpara,"voidpara")!=0) |
---|
369 | sscanf(line, "%*s %s %s %ld %ld %ld %lf %lf %lf", |
---|
370 | UserCommandFlag[CommNo]._AmplitudeTuneShift_nudx_file, |
---|
371 | UserCommandFlag[CommNo]._AmplitudeTuneShift_nudz_file, |
---|
372 | &(UserCommandFlag[CommNo]._AmplitudeTuneShift_nxpoint), |
---|
373 | &(UserCommandFlag[CommNo]._AmplitudeTuneShift_nypoint), |
---|
374 | &(UserCommandFlag[CommNo]._AmplitudeTuneShift_nturn), |
---|
375 | &(UserCommandFlag[CommNo]._AmplitudeTuneShift_xmax), |
---|
376 | &(UserCommandFlag[CommNo]._AmplitudeTuneShift_ymax), |
---|
377 | &(UserCommandFlag[CommNo]._AmplitudeTuneShift_delta)); |
---|
378 | |
---|
379 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
380 | } |
---|
381 | else if (strcmp("EnergyTuneShiftFlag", name) == 0){ |
---|
382 | sscanf(line, "%*s %s",nextpara); |
---|
383 | |
---|
384 | if(strcmp(nextpara,"voidpara")!=0) |
---|
385 | sscanf(line, "%*s %s %ld %ld %lf", |
---|
386 | UserCommandFlag[CommNo]._EnergyTuneShift_nudp_file, |
---|
387 | &(UserCommandFlag[CommNo]._EnergyTuneShift_npoint), |
---|
388 | &(UserCommandFlag[CommNo]._EnergyTuneShift_nturn), |
---|
389 | &(UserCommandFlag[CommNo]._EnergyTuneShift_deltamax)); |
---|
390 | |
---|
391 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
392 | |
---|
393 | } |
---|
394 | else if (strcmp("ErrorCouplingFlag", name) == 0){ |
---|
395 | sscanf(line, "%*s %ld %lf",&(UserCommandFlag[CommNo].err_seed),&(UserCommandFlag[CommNo].err_rms)); |
---|
396 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
397 | |
---|
398 | } |
---|
399 | else if (strcmp("ErrorCoupling2Flag", name) == 0){ |
---|
400 | sscanf(line, "%*s %ld %lf",&(UserCommandFlag[CommNo].err_seed),&(UserCommandFlag[CommNo].err_rms)); |
---|
401 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
402 | |
---|
403 | } |
---|
404 | else if (strcmp("CouplingFlag", name) == 0){ |
---|
405 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
406 | |
---|
407 | }//momentum compact factor |
---|
408 | else if (strcmp("MomentumAccFlag", name) == 0){ |
---|
409 | sscanf(line, "%*s %s",nextpara); |
---|
410 | |
---|
411 | if(strcmp(nextpara,"voidpara")!=0){ |
---|
412 | sscanf(line, "%*s %s %s %ld %ld %lf %lf %ld %lf %lf %ld %ld %lf", |
---|
413 | UserCommandFlag[CommNo]._MomentumAccFlag_momacc_file, |
---|
414 | UserCommandFlag[CommNo]._MomentumAccFlag_TrackDim, |
---|
415 | &(UserCommandFlag[CommNo]._MomentumAccFlag_istart), |
---|
416 | &(UserCommandFlag[CommNo]._MomentumAccFlag_istop), |
---|
417 | &(UserCommandFlag[CommNo]._MomentumAccFlag_deltaminp), |
---|
418 | &(UserCommandFlag[CommNo]._MomentumAccFlag_deltamaxp), |
---|
419 | &(UserCommandFlag[CommNo]._MomentumAccFlag_nstepp), |
---|
420 | &(UserCommandFlag[CommNo]._MomentumAccFlag_deltaminn), |
---|
421 | &(UserCommandFlag[CommNo]._MomentumAccFlag_deltamaxn), |
---|
422 | &(UserCommandFlag[CommNo]._MomentumAccFlag_nstepn), |
---|
423 | &(UserCommandFlag[CommNo]._MomentumAccFlag_nturn), |
---|
424 | &(UserCommandFlag[CommNo]._MomentumAccFlag_zmax)); |
---|
425 | } |
---|
426 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
427 | } |
---|
428 | |
---|
429 | // generic one, fit for 1 family of quadrupoles |
---|
430 | else if (strcmp("FitTuneFlag", name) == 0){ |
---|
431 | sscanf(line, "%*s %s %s %lf %lf",UserCommandFlag[CommNo].qf,UserCommandFlag[CommNo].qd, |
---|
432 | &(UserCommandFlag[CommNo].targetnux),&(UserCommandFlag[CommNo].targetnuz)); |
---|
433 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
434 | } |
---|
435 | // fit for 2 families,specific for the soleil lattice in which the quadrupole is cut into 2 parts |
---|
436 | else if (strcmp("FitTune4Flag", name) == 0){ |
---|
437 | sscanf(line, "%*s %s %s %s %s %lf %lf",UserCommandFlag[CommNo].qf1,UserCommandFlag[CommNo].qf2, |
---|
438 | UserCommandFlag[CommNo].qd1,UserCommandFlag[CommNo].qd2, |
---|
439 | &(UserCommandFlag[CommNo].targetnux),&(UserCommandFlag[CommNo].targetnuz)); |
---|
440 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
441 | } |
---|
442 | else if (strcmp("FitChromFlag", name) == 0){ |
---|
443 | sscanf(line, "%*s %s %s %lf %lf",UserCommandFlag[CommNo].sxm1,UserCommandFlag[CommNo].sxm2, |
---|
444 | &(UserCommandFlag[CommNo].targetksix),&(UserCommandFlag[CommNo].targetksiz)); |
---|
445 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
446 | } |
---|
447 | // else if (strcmp("GirderErrorFlag", name) == 0){ |
---|
448 | // strcpy(UserCommand[CommandNo-1],name); |
---|
449 | // // GirderErrorFlag = true; |
---|
450 | // |
---|
451 | // } |
---|
452 | // else if (strcmp("SigmaFlag", name) == 0){ |
---|
453 | // strcpy(UserCommand[CommandNo-1],name); |
---|
454 | // // SigmaFlag = true; |
---|
455 | // |
---|
456 | // } |
---|
457 | // else if (strcmp("PX2Flag", name) == 0){ |
---|
458 | // strcpy(UserCommand[CommandNo-1],name); |
---|
459 | // // PX2Flag = true; |
---|
460 | // |
---|
461 | // } |
---|
462 | else if (strcmp("InducedAmplitudeFlag", name) == 0){ |
---|
463 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
464 | } |
---|
465 | // else if (strcmp("CodeComparaisonFlag", name) == 0){ |
---|
466 | // strcpy(UserCommand[CommandNo-1],name); |
---|
467 | // // CodeComparaisonFlag = true; |
---|
468 | // |
---|
469 | // } |
---|
470 | else if (strcmp("EtaFlag", name) == 0){ |
---|
471 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
472 | }//phase space |
---|
473 | else if (strcmp("PhaseSpaceFlag", name) == 0) { |
---|
474 | sscanf(line, "%*s %s",nextpara); |
---|
475 | //if the next para is not empty, then use the user set value, otherwise use default value |
---|
476 | if(strcmp(nextpara,"voidpara") != 0){ |
---|
477 | sscanf(line, "%*s %s %s %lf %lf %lf %lf %lf %lf %ld %s", |
---|
478 | UserCommandFlag[CommNo]._Phase_phase_file, |
---|
479 | UserCommandFlag[CommNo]._Phase_Dim, |
---|
480 | &(UserCommandFlag[CommNo]._Phase_X), |
---|
481 | &(UserCommandFlag[CommNo]._Phase_Px), |
---|
482 | &(UserCommandFlag[CommNo]._Phase_Y), |
---|
483 | &(UserCommandFlag[CommNo]._Phase_Py), |
---|
484 | &(UserCommandFlag[CommNo]._Phase_delta), |
---|
485 | &(UserCommandFlag[CommNo]._Phase_ctau), |
---|
486 | &(UserCommandFlag[CommNo]._Phase_nturn), |
---|
487 | str); |
---|
488 | } |
---|
489 | //radiation damping |
---|
490 | if (strcmp(str, "true") == 0) |
---|
491 | UserCommandFlag[CommNo]._Phase_Damping = true; |
---|
492 | else if (strcmp(str, "false") == 0) |
---|
493 | UserCommandFlag[CommNo]._Phase_Damping = false; |
---|
494 | |
---|
495 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
496 | } |
---|
497 | //calculate Touschek lifetime |
---|
498 | else if (strcmp("TouschekFlag", name) == 0){ |
---|
499 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
500 | |
---|
501 | }//intra beam scattering |
---|
502 | else if (strcmp("IBSFlag", name) == 0){ |
---|
503 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
504 | }//momentum acceptance is got by tracking, then cal touschek lifetime |
---|
505 | else if (strcmp("TousTrackFlag", name) == 0){ |
---|
506 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
507 | } |
---|
508 | //bpms and h/v correctors used for orbit correction |
---|
509 | else if (strcmp("bpm_name", name) == 0){ |
---|
510 | sscanf(line, "%*s %s", bpm_name); /* the name of bpm */ |
---|
511 | } |
---|
512 | else if (strcmp("h_corr", name) == 0){ |
---|
513 | sscanf(line, "%*s %s", hcorr_name); /* the name of H corrector used for COD correction*/ |
---|
514 | } |
---|
515 | else if (strcmp("v_corr", name) == 0){ |
---|
516 | sscanf(line, "%*s %s", vcorr_name); /* the name of V corrector used for COD correction*/ |
---|
517 | } |
---|
518 | else if (strcmp("qt", name) == 0){ |
---|
519 | sscanf(line, "%*s %s", skew_quad_name); /* name of skew quadrupoles */ |
---|
520 | } |
---|
521 | else if (strcmp("gs", name) == 0){ |
---|
522 | sscanf(line, "%*s %s", gs_name); /* name of start of the girder */ |
---|
523 | } |
---|
524 | else if (strcmp("ge", name) == 0){ |
---|
525 | sscanf(line, "%*s %s", ge_name); /* name of end of the girder */ |
---|
526 | } |
---|
527 | else if (strcmp("normalcut", name) == 0){ |
---|
528 | sscanf(line, "%*s %d", &idummy); |
---|
529 | fprintf(stdout,"User value for cutting at n sigma-s the normal distributions\n"); |
---|
530 | setrancut(idummy); /* set normal cut for computation: random data are n sigma-s*/ |
---|
531 | } |
---|
532 | //flag to do orbit correction |
---|
533 | else if (strcmp("CODCorrectFlag", name) == 0){ |
---|
534 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
535 | } |
---|
536 | //set parameters for COD correction |
---|
537 | else if (strcmp("n_orbit", name) == 0){ |
---|
538 | sscanf(line, "%*s %d", &n_orbit); |
---|
539 | } |
---|
540 | else if (strcmp("nwh", name) == 0){ |
---|
541 | sscanf(line, "%*s %d", &nwh); |
---|
542 | } |
---|
543 | else if (strcmp("nwv", name) == 0){ |
---|
544 | sscanf(line, "%*s %d", &nwv); |
---|
545 | } |
---|
546 | else if (strcmp("hcorr_file", name) == 0){ |
---|
547 | sscanf(line, "%*s %s", str); |
---|
548 | sprintf(hcorr_file,"%s%s", in_dir, str); /* add file directory*/ |
---|
549 | } |
---|
550 | else if (strcmp("vcorr_file", name) == 0){ |
---|
551 | sscanf(line, "%*s %s", str); |
---|
552 | sprintf(vcorr_file,"%s%s", in_dir, str); /* add file directory*/ |
---|
553 | } |
---|
554 | //ID correction |
---|
555 | else if (strcmp("IDCorrFlag", name) == 0) |
---|
556 | strcpy(UserCommandFlag[CommNo].CommandStr,name); |
---|
557 | else if (strcmp("scl_dbetax", name) == 0)//scaling of dbetax, for ID correction |
---|
558 | sscanf(line, "%*s %lf", &scl_dbetax); |
---|
559 | else if (strcmp("scl_dbetay", name) == 0)//scaling of dbetay, for ID correction |
---|
560 | sscanf(line, "%*s %lf", &scl_dbetay); |
---|
561 | else if (strcmp("scl_dnux", name) == 0)//scaling of dnux, for ID correction |
---|
562 | sscanf(line, "%*s %lf", &scl_dnux); |
---|
563 | else if (strcmp("scl_dnuy", name) == 0)//scaling of dnuy, for ID correction |
---|
564 | sscanf(line, "%*s %lf", &scl_dnuy); |
---|
565 | else if (strcmp("scl_nux", name) == 0) //scaling of nux, for ID correction |
---|
566 | sscanf(line, "%*s %lf", &scl_nux); |
---|
567 | else if (strcmp("scl_nuy", name) == 0) //scaling of nuy, for ID correction |
---|
568 | sscanf(line, "%*s %lf", &scl_nuy); |
---|
569 | else if (strcmp("ID_step", name) == 0)//ID steps, for ID correction |
---|
570 | sscanf(line, "%*s %lf", &ID_step); |
---|
571 | else if (strcmp("N_calls", name) == 0) // ID correction parameters |
---|
572 | sscanf(line, "%*s %d", &N_calls); |
---|
573 | else if (strcmp("N_steps", name) == 0) |
---|
574 | sscanf(line, "%*s %d", &N_steps); |
---|
575 | else if (strcmp("N_Fam", name) == 0) |
---|
576 | sscanf(line, "%*s %d", &N_Fam); |
---|
577 | else if (strcmp("IDCquads", name) == 0) { |
---|
578 | sscanf(line, "%*s %s %s %s %s %s %s %s %s %s %s %s", |
---|
579 | IDCq_name[0], IDCq_name[1], IDCq_name[2], IDCq_name[3], |
---|
580 | IDCq_name[4], IDCq_name[5], IDCq_name[6], IDCq_name[7], |
---|
581 | IDCq_name[8], IDCq_name[9], IDCq_name[10]); |
---|
582 | } |
---|
583 | else{ |
---|
584 | printf("bad line in file %s, line %ld \n", full_param_file_name, LineNum); |
---|
585 | exit_(1); |
---|
586 | } |
---|
587 | } |
---|
588 | /* continue read in the line */ |
---|
589 | else |
---|
590 | continue; |
---|
591 | }//end of while loop |
---|
592 | |
---|
593 | free(line); |
---|
594 | |
---|
595 | fclose(inf); |
---|
596 | } |
---|
597 | |
---|