1 | #include "madx.h" |
---|
2 | |
---|
3 | static void |
---|
4 | fill_twiss_header_ptc(struct table* t, double ptc_deltap) |
---|
5 | /* puts beam parameters etc. at start of twiss table */ |
---|
6 | { |
---|
7 | int i, h_length = 39+3+1+1+6+4; /* change when adding header lines ! - last 6 for the closed orbit */ |
---|
8 | double dtmp; |
---|
9 | /* struct table* s; */ |
---|
10 | char tmp[16]; |
---|
11 | |
---|
12 | // int returnStatus; // not used |
---|
13 | int row; |
---|
14 | |
---|
15 | if (t == NULL) return; |
---|
16 | /* ATTENTION: if you add header lines, augment h_length accordingly */ |
---|
17 | if (t->header == NULL) t->header = new_char_p_array(h_length); |
---|
18 | strcpy(tmp, t->org_sequ->name); |
---|
19 | sprintf(c_dum->c, v_format("@ SEQUENCE %%%02ds \"%s\""), |
---|
20 | strlen(tmp),stoupper(tmp)); |
---|
21 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
22 | i = get_string("beam", "particle", tmp); |
---|
23 | sprintf(c_dum->c, v_format("@ PARTICLE %%%02ds \"%s\""), |
---|
24 | i, stoupper(tmp)); |
---|
25 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
26 | dtmp = get_value("beam", "mass"); |
---|
27 | sprintf(c_dum->c, v_format("@ MASS %%le %F"), dtmp); |
---|
28 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
29 | dtmp = get_value("beam", "charge"); |
---|
30 | sprintf(c_dum->c, v_format("@ CHARGE %%le %F"), dtmp); |
---|
31 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
32 | dtmp = get_value("beam", "energy"); |
---|
33 | sprintf(c_dum->c, v_format("@ ENERGY %%le %F"), dtmp); |
---|
34 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
35 | dtmp = get_value("beam", "pc"); |
---|
36 | sprintf(c_dum->c, v_format("@ PC %%le %F"), dtmp); |
---|
37 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
38 | dtmp = get_value("beam", "gamma"); |
---|
39 | sprintf(c_dum->c, v_format("@ GAMMA %%le %F"), dtmp); |
---|
40 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
41 | dtmp = get_value("beam", "kbunch"); |
---|
42 | sprintf(c_dum->c, v_format("@ KBUNCH %%le %F"), dtmp); |
---|
43 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
44 | dtmp = get_value("beam", "bcurrent"); |
---|
45 | sprintf(c_dum->c, v_format("@ BCURRENT %%le %F"), dtmp); |
---|
46 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
47 | dtmp = get_value("beam", "sige"); |
---|
48 | sprintf(c_dum->c, v_format("@ SIGE %%le %F"), dtmp); |
---|
49 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
50 | dtmp = get_value("beam", "sigt"); |
---|
51 | sprintf(c_dum->c, v_format("@ SIGT %%le %F"), dtmp); |
---|
52 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
53 | dtmp = get_value("beam", "npart"); |
---|
54 | sprintf(c_dum->c, v_format("@ NPART %%le %F"), dtmp); |
---|
55 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
56 | dtmp = get_value("beam", "ex"); |
---|
57 | sprintf(c_dum->c, v_format("@ EX %%le %F"), dtmp); |
---|
58 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
59 | dtmp = get_value("beam", "ey"); |
---|
60 | sprintf(c_dum->c, v_format("@ EY %%le %F"), dtmp); |
---|
61 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
62 | dtmp = get_value("beam", "et"); |
---|
63 | sprintf(c_dum->c, v_format("@ ET %%le %F"), dtmp); |
---|
64 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
65 | sprintf(c_dum->c, v_format("@ DELTAP %%le %F"), ptc_deltap); |
---|
66 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
67 | |
---|
68 | /* one-turn information gets computed iff ptc_twiss_summary set to 1 in madx_ptc_twiss.f90 */ |
---|
69 | if (get_option("ptc_twiss_summary") != zero){ |
---|
70 | |
---|
71 | /* now retreive all pieces of information from the ptc_twiss*/ |
---|
72 | |
---|
73 | row = 1; /* this particular table has only one row filled-in */ |
---|
74 | |
---|
75 | /* length of the machine */ |
---|
76 | double_from_table_row("ptc_twiss_summary","length",&row,&dtmp); // returnStatus = not used |
---|
77 | /* returnStatus should always be equal to zero */ |
---|
78 | sprintf(c_dum->c, v_format("@ LENGTH %%le %F"), dtmp); |
---|
79 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
80 | |
---|
81 | |
---|
82 | /* momentum compaction factor, phase-slip factor and energy transition */ |
---|
83 | double_from_table_row("ptc_twiss_summary","alpha_c", &row, &dtmp); // returnStatus = not used |
---|
84 | /* returnStatus should always be equal to zero */ |
---|
85 | sprintf(c_dum->c, v_format("@ ALPHA_C %%le %F"), dtmp); |
---|
86 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
87 | |
---|
88 | /* momentum compaction factor first order derivative w.r.t delta-p/p */ |
---|
89 | double_from_table_row("ptc_twiss_summary","alpha_c_p", &row, &dtmp); // returnStatus = not used |
---|
90 | sprintf(c_dum->c, v_format("@ ALPHA_C_P %%le %F"),dtmp); |
---|
91 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
92 | |
---|
93 | |
---|
94 | /* WARNING when restoring the following two lines don't forget to replace 39+1 by 39+2 for h_length */ |
---|
95 | /* momentum compaction factor second order derivative w.r.t delta-p/p */ |
---|
96 | /* uncomment the following once computation of alpha_c_p2 is reliable */ |
---|
97 | double_from_table_row("ptc_twiss_summary","alpha_c_p2", &row, &dtmp); // returnStatus = not used |
---|
98 | sprintf(c_dum->c, v_format("@ ALPHA_C_P2 %%le %F"),dtmp); |
---|
99 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
100 | |
---|
101 | /* WARNING when restoring the following two lines don't forget to replace 39+2 by 39+3 for h_length */ |
---|
102 | /* momentum compaction factor third order derivative w.r.t delta-p/p */ |
---|
103 | /* uncomment the following once computation of alpha_c_p3 is reliable */ |
---|
104 | double_from_table_row("ptc_twiss_summary","alpha_c_p3", &row, &dtmp); // returnStatus = not used |
---|
105 | sprintf(c_dum->c, v_format("@ ALPHA_C_P3 %%le %F"),dtmp); |
---|
106 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
107 | |
---|
108 | double_from_table_row("ptc_twiss_summary","eta_c", &row, &dtmp); // returnStatus = not used |
---|
109 | sprintf(c_dum->c, v_format("@ ETA_C %%le %F"), dtmp); |
---|
110 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
111 | |
---|
112 | double_from_table_row("ptc_twiss_summary","gamma_tr", &row, &dtmp); // returnStatus = not used |
---|
113 | sprintf(c_dum->c, v_format("@ GAMMA_TR %%le %F"), dtmp); |
---|
114 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
115 | |
---|
116 | /* tunes and chromaticities */ |
---|
117 | double_from_table_row("ptc_twiss_summary","q1", &row, &dtmp); // returnStatus = not used |
---|
118 | sprintf(c_dum->c, v_format("@ Q1 %%le %F"), dtmp); |
---|
119 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
120 | |
---|
121 | double_from_table_row("ptc_twiss_summary","q2", &row, &dtmp); // returnStatus = not used |
---|
122 | sprintf(c_dum->c, v_format("@ Q2 %%le %F"), dtmp); |
---|
123 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
124 | |
---|
125 | double_from_table_row("ptc_twiss_summary","dq1", &row, &dtmp); // returnStatus = not used |
---|
126 | sprintf(c_dum->c, v_format("@ DQ1 %%le %F"), dtmp); |
---|
127 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
128 | |
---|
129 | double_from_table_row("ptc_twiss_summary","dq2", &row, &dtmp); // returnStatus = not used |
---|
130 | sprintf(c_dum->c, v_format("@ DQ2 %%le %F"), dtmp); |
---|
131 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
132 | |
---|
133 | /* 26 november 2009 */ |
---|
134 | double_from_table_row("ptc_twiss_summary","qs", &row, &dtmp); // returnStatus = not used |
---|
135 | sprintf(c_dum->c, v_format("@ QS %%le %F"), dtmp); |
---|
136 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
137 | |
---|
138 | |
---|
139 | /* extremas of the beta-function */ |
---|
140 | double_from_table_row("ptc_twiss_summary","beta_x_min", &row, &dtmp); // returnStatus = not used |
---|
141 | sprintf(c_dum->c, v_format("@ BETA_X_MIN %%le %F"), dtmp); |
---|
142 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
143 | |
---|
144 | double_from_table_row("ptc_twiss_summary","beta_x_max", &row, &dtmp); // returnStatus = not used |
---|
145 | sprintf(c_dum->c, v_format("@ BETA_X_MAX %%le %F"), dtmp); |
---|
146 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
147 | |
---|
148 | double_from_table_row("ptc_twiss_summary","beta_y_min", &row, &dtmp); // returnStatus = not used |
---|
149 | sprintf(c_dum->c, v_format("@ BETA_Y_MIN %%le %F"), dtmp); |
---|
150 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
151 | |
---|
152 | double_from_table_row("ptc_twiss_summary","beta_y_max", &row, &dtmp); // returnStatus = not used |
---|
153 | sprintf(c_dum->c, v_format("@ BETA_Y_MAX %%le %F"), dtmp); |
---|
154 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
155 | |
---|
156 | /* now for the 6 closed orbits */ |
---|
157 | double_from_table_row("ptc_twiss_summary","orbit_x", &row, &dtmp); // returnStatus = not used |
---|
158 | sprintf(c_dum->c, v_format("@ ORBIT_X %%le %F"),dtmp); |
---|
159 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
160 | |
---|
161 | double_from_table_row("ptc_twiss_summary","orbit_px", &row, &dtmp); // returnStatus = not used |
---|
162 | sprintf(c_dum->c, v_format("@ ORBIT_PX %%le %F"),dtmp); |
---|
163 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
164 | |
---|
165 | double_from_table_row("ptc_twiss_summary","orbit_y", &row, &dtmp); // returnStatus = not used |
---|
166 | sprintf(c_dum->c, v_format("@ ORBIT_Y %%le %F"),dtmp); |
---|
167 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
168 | |
---|
169 | double_from_table_row("ptc_twiss_summary","orbit_py", &row, &dtmp); // returnStatus = not used |
---|
170 | sprintf(c_dum->c, v_format("@ ORBIT_PY %%le %F"),dtmp); |
---|
171 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
172 | |
---|
173 | double_from_table_row("ptc_twiss_summary","orbit_pt", &row, &dtmp); // returnStatus = not used |
---|
174 | sprintf(c_dum->c, v_format("@ ORBIT_PT %%le %F"),dtmp); |
---|
175 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
176 | |
---|
177 | double_from_table_row("ptc_twiss_summary","orbit_-cT", &row, &dtmp); // returnStatus = not used |
---|
178 | sprintf(c_dum->c, v_format("@ ORBIT_-CT %%le %F"),dtmp); |
---|
179 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
180 | |
---|
181 | /* orbits RMS */ |
---|
182 | double_from_table_row("ptc_twiss_summary","xcorms", &row, &dtmp); // returnStatus = not used |
---|
183 | sprintf(c_dum->c, v_format("@ XCORMS %%le %F"),dtmp); |
---|
184 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
185 | |
---|
186 | double_from_table_row("ptc_twiss_summary","pxcorms", &row, &dtmp); // returnStatus = not used |
---|
187 | sprintf(c_dum->c, v_format("@ PXCORMS %%le %F"),dtmp); |
---|
188 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
189 | |
---|
190 | double_from_table_row("ptc_twiss_summary","ycorms", &row, &dtmp); // returnStatus = not used |
---|
191 | sprintf(c_dum->c, v_format("@ YCORMS %%le %F"),dtmp); |
---|
192 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
193 | |
---|
194 | double_from_table_row("ptc_twiss_summary","pycorms", &row, &dtmp); // returnStatus = not used |
---|
195 | sprintf(c_dum->c, v_format("@ PYCORMS %%le %F"),dtmp); |
---|
196 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
197 | |
---|
198 | /* orbits MAX */ |
---|
199 | double_from_table_row("ptc_twiss_summary","xcomax", &row, &dtmp); // returnStatus = not used |
---|
200 | sprintf(c_dum->c, v_format("@ XCOMAX %%le %F"),dtmp); |
---|
201 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
202 | |
---|
203 | double_from_table_row("ptc_twiss_summary","pxcomax", &row, &dtmp); // returnStatus = not used |
---|
204 | sprintf(c_dum->c, v_format("@ PXCOMAX %%le %F"),dtmp); |
---|
205 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
206 | |
---|
207 | double_from_table_row("ptc_twiss_summary","ycomax", &row, &dtmp); // returnStatus = not used |
---|
208 | sprintf(c_dum->c, v_format("@ YCOMAX %%le %F"),dtmp); |
---|
209 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
210 | |
---|
211 | double_from_table_row("ptc_twiss_summary","pycomax", &row, &dtmp); // returnStatus = not used |
---|
212 | sprintf(c_dum->c, v_format("@ PYCOMAX %%le %F"),dtmp); |
---|
213 | t->header->p[t->header->curr++] = tmpbuff(c_dum->c); |
---|
214 | |
---|
215 | } |
---|
216 | } |
---|
217 | |
---|
218 | static int |
---|
219 | pro_ptc_select_checkpushtable(struct in_cmd* cmd, struct int_array** tabnameIA, struct int_array** colnameIA) |
---|
220 | { |
---|
221 | struct command_parameter_list* c_parameters= cmd->clone->par; |
---|
222 | struct name_list* c_parnames = cmd->clone->par_names; |
---|
223 | struct table* aTable = 0x0; |
---|
224 | int pos = 0; |
---|
225 | char* tablename = 0x0; |
---|
226 | char* columnname = 0x0; |
---|
227 | |
---|
228 | |
---|
229 | /*extracts column specified by the user*/ |
---|
230 | pos = name_list_pos("column", c_parnames); |
---|
231 | if (pos < 0) |
---|
232 | { |
---|
233 | printf("mad_ptc.c: pro_ptc_select: column parameter does not exist.\n"); |
---|
234 | return 5; |
---|
235 | } |
---|
236 | |
---|
237 | columnname = c_parameters->parameters[pos]->string; |
---|
238 | if ( columnname == 0x0 ) |
---|
239 | { |
---|
240 | /* warning("mad_ptc.c: pro_ptc_select: Column name is empty: ", "ignored");*/ |
---|
241 | return 6; |
---|
242 | } |
---|
243 | |
---|
244 | *colnameIA = new_int_array(1+strlen(columnname)); |
---|
245 | conv_char(columnname,*colnameIA); |
---|
246 | |
---|
247 | |
---|
248 | /*extracts table specified by the user*/ |
---|
249 | pos = name_list_pos("table", c_parnames); |
---|
250 | if (pos < 0) |
---|
251 | { |
---|
252 | printf("mad_ptc.c: pro_ptc_select: table parameter does not exist.\n"); |
---|
253 | return 1; |
---|
254 | } |
---|
255 | |
---|
256 | tablename = c_parameters->parameters[pos]->string; |
---|
257 | if ( tablename == 0x0 ) |
---|
258 | { |
---|
259 | return -1;/*This means that table name was not specified at all*/ |
---|
260 | } |
---|
261 | if ( tablename[0] == 0 ) |
---|
262 | { |
---|
263 | return -1; /*This means that table name was not specified at all*/ |
---|
264 | } |
---|
265 | pos = name_list_pos(tablename, table_register->names); |
---|
266 | if (pos < 0) |
---|
267 | { |
---|
268 | printf("mad_ptc.c: pro_ptc_select: table <<%s>> does not exist: Create table first\n",tablename); |
---|
269 | return 3; |
---|
270 | } |
---|
271 | |
---|
272 | aTable = table_register->tables[pos]; |
---|
273 | if (aTable == 0x0) |
---|
274 | { |
---|
275 | printf("mad_ptc.c: pro_ptc_select: table <<%s>> is NULL: \n",tablename); |
---|
276 | return 4; |
---|
277 | } |
---|
278 | |
---|
279 | |
---|
280 | /*checks if the specified column exists*/ |
---|
281 | pos = name_list_pos(columnname,aTable->columns); |
---|
282 | if (pos < 0) |
---|
283 | { |
---|
284 | error("mad_ptc.c: pro_ptc_select","Can not find column named <<%s>> in table <<%s>>.", |
---|
285 | columnname,aTable->name); |
---|
286 | return 7; |
---|
287 | } |
---|
288 | |
---|
289 | pos = name_list_pos("name",aTable->columns); |
---|
290 | if (pos < 0) |
---|
291 | { |
---|
292 | warning("mad_ptc.c: pro_ptc_selectaTable->name: There is no column named <<name>> in table <<%s>>.",aTable->name); |
---|
293 | return 8; |
---|
294 | } |
---|
295 | |
---|
296 | /*so none of the columns is filled */ |
---|
297 | aTable->org_cols = aTable->num_cols; |
---|
298 | |
---|
299 | |
---|
300 | *tabnameIA = new_int_array(1+strlen(tablename)); |
---|
301 | conv_char(tablename,*tabnameIA); |
---|
302 | |
---|
303 | return 0; |
---|
304 | } |
---|
305 | |
---|
306 | // public interface |
---|
307 | |
---|
308 | int |
---|
309 | minimum_acceptable_order(void) |
---|
310 | { |
---|
311 | return min_order; |
---|
312 | } |
---|
313 | |
---|
314 | int |
---|
315 | select_ptc_idx(void) |
---|
316 | { |
---|
317 | struct table* t; |
---|
318 | int pos; |
---|
319 | |
---|
320 | if ((pos = name_list_pos("normal_results", table_register->names)) > -1) |
---|
321 | { |
---|
322 | t = table_register->tables[pos]; |
---|
323 | return t->curr; |
---|
324 | } |
---|
325 | else |
---|
326 | return pos; |
---|
327 | } |
---|
328 | |
---|
329 | void |
---|
330 | ptc_track_end(void) |
---|
331 | { |
---|
332 | int i; |
---|
333 | struct node* c_node; |
---|
334 | if (track_is_on == 0) |
---|
335 | { |
---|
336 | warning("ptc_track_end: no PTC_TRACK command seen yet", "ignored"); |
---|
337 | return; |
---|
338 | } |
---|
339 | for (i = 0; i < stored_track_start->curr; i++) |
---|
340 | stored_track_start->commands[i] = |
---|
341 | delete_command(stored_track_start->commands[i]); |
---|
342 | stored_track_start->curr = 0; |
---|
343 | c_node = current_sequ->ex_start; |
---|
344 | while(c_node != NULL) /* clean observation points */ |
---|
345 | { |
---|
346 | c_node->obs_point = 0; |
---|
347 | c_node->obs_orbit = delete_double_array(c_node->obs_orbit); |
---|
348 | if (c_node == current_sequ->ex_end) break; |
---|
349 | c_node = c_node->next; |
---|
350 | } |
---|
351 | curr_obs_points = 1; |
---|
352 | track_is_on = 0; |
---|
353 | } |
---|
354 | |
---|
355 | void |
---|
356 | ptc_track_observe(struct in_cmd* cmd) |
---|
357 | { |
---|
358 | struct name_list* nl = cmd->clone->par_names; |
---|
359 | struct command_parameter_list* pl = cmd->clone->par; |
---|
360 | struct node* nodes[2]; |
---|
361 | int pos; |
---|
362 | |
---|
363 | pos = name_list_pos("place", nl); |
---|
364 | if (get_ex_range(pl->parameters[pos]->string, current_sequ, nodes)) |
---|
365 | { |
---|
366 | nodes[0]->obs_point = ++curr_obs_points; |
---|
367 | printf("obs_points: %d \n",curr_obs_points); |
---|
368 | } |
---|
369 | else |
---|
370 | { |
---|
371 | warning("ptc_track_observe: unknown place,", "ignored"); |
---|
372 | return; |
---|
373 | } |
---|
374 | } |
---|
375 | /*________________________________________________________________*/ |
---|
376 | void |
---|
377 | ptc_putbeambeam(struct in_cmd* cmd) |
---|
378 | { |
---|
379 | /*Installs beam beam interaction on a given integration step*/ |
---|
380 | /*might be defined by global s or element name and local s*/ |
---|
381 | |
---|
382 | (void)cmd; |
---|
383 | w_ptc_putbeambeam_(); |
---|
384 | } |
---|
385 | |
---|
386 | |
---|
387 | /*________________________________________________________________*/ |
---|
388 | void |
---|
389 | ptc_dumpmaps(struct in_cmd* cmd) |
---|
390 | /*Dumps PTC map for each element in the current sequence*/ |
---|
391 | { |
---|
392 | (void)cmd; |
---|
393 | w_ptc_dumpmaps_(); |
---|
394 | } |
---|
395 | |
---|
396 | void |
---|
397 | ptc_oneturnmap(struct in_cmd* cmd) |
---|
398 | { |
---|
399 | (void)cmd; |
---|
400 | } |
---|
401 | |
---|
402 | void |
---|
403 | pro_ptc_twiss(void) |
---|
404 | /* controls ptc_twiss module */ |
---|
405 | { |
---|
406 | struct command* keep_beam = current_beam; |
---|
407 | struct name_list* nl = current_twiss->par_names; |
---|
408 | struct command_parameter_list* pl = current_twiss->par; |
---|
409 | struct int_array* tarr; |
---|
410 | int ptc_twiss_summary = 0 ; /* set to 1 when a summary-table is filled-in */ |
---|
411 | struct int_array* summary_tarr; /* to pass summary-table name to Fortran */ |
---|
412 | struct node *nodes[2], *use_range[2]; |
---|
413 | double ptc_deltap; |
---|
414 | char *filename = NULL, *table_name; |
---|
415 | char *summary_filename = NULL, *summary_table_name; /* for summary table */ |
---|
416 | int j,l ,pos, w_file,beta_def; |
---|
417 | int w_file_summary; /* toggle to write the summary table into a file */ |
---|
418 | /* |
---|
419 | start command decoding |
---|
420 | */ |
---|
421 | use_range[0] = current_sequ->range_start; |
---|
422 | use_range[1] = current_sequ->range_end; |
---|
423 | |
---|
424 | if ((pos = name_list_pos("range", nl)) > -1 && nl->inform[pos]) |
---|
425 | { |
---|
426 | if (get_sub_range(pl->parameters[pos]->string, current_sequ, nodes)) |
---|
427 | { |
---|
428 | current_sequ->range_start = nodes[0]; |
---|
429 | current_sequ->range_end = nodes[1]; |
---|
430 | } |
---|
431 | else warning("illegal range ignored:", pl->parameters[pos]->string); |
---|
432 | } |
---|
433 | for (j = 0; j < current_sequ->n_nodes; j++) |
---|
434 | { |
---|
435 | if (current_sequ->all_nodes[j] == current_sequ->range_start) break; |
---|
436 | } |
---|
437 | |
---|
438 | if (attach_beam(current_sequ) == 0) |
---|
439 | fatal_error("PTC_TWISS - sequence without beam:", current_sequ->name); |
---|
440 | |
---|
441 | pos = name_list_pos("table", nl); |
---|
442 | if(nl->inform[pos]) /* table name specified - overrides save */ |
---|
443 | { |
---|
444 | table_name = pl->parameters[pos]->string; |
---|
445 | if (table_name == NULL) |
---|
446 | { |
---|
447 | table_name = pl->parameters[pos]->call_def->string; |
---|
448 | } |
---|
449 | } |
---|
450 | else |
---|
451 | { |
---|
452 | /*strcpy(table_name,"ptc_twiss");*/ |
---|
453 | table_name = "ptc_twiss"; |
---|
454 | } |
---|
455 | |
---|
456 | /* --- */ |
---|
457 | /* do the same as above for the table holding summary data after one-turn */ |
---|
458 | pos = name_list_pos("summary_table",nl); |
---|
459 | if (nl->inform[pos]){ /* summary-table's name specified */ |
---|
460 | summary_table_name = pl->parameters[pos]->string; |
---|
461 | if (summary_table_name == NULL){ |
---|
462 | summary_table_name = pl->parameters[pos]->call_def->string; |
---|
463 | } |
---|
464 | } |
---|
465 | else { |
---|
466 | summary_table_name = "ptc_twiss_summary"; |
---|
467 | } |
---|
468 | /* --- */ |
---|
469 | |
---|
470 | pos = name_list_pos("file", nl); |
---|
471 | if (nl->inform[pos]) |
---|
472 | { |
---|
473 | if ((filename = pl->parameters[pos]->string) == NULL) |
---|
474 | { |
---|
475 | if (pl->parameters[pos]->call_def != NULL) |
---|
476 | filename = pl->parameters[pos]->call_def->string; |
---|
477 | } |
---|
478 | if (filename == NULL) filename = permbuff("dummy"); |
---|
479 | w_file = 1; |
---|
480 | } |
---|
481 | else w_file = 0; |
---|
482 | |
---|
483 | /* --- */ |
---|
484 | /* do the same as above for the file to hold the summary-table */ |
---|
485 | pos = name_list_pos("summary_file",nl); |
---|
486 | if (nl->inform[pos]){ |
---|
487 | if ((summary_filename = pl->parameters[pos]->string) == NULL){ |
---|
488 | if (pl->parameters[pos]->call_def != NULL) |
---|
489 | summary_filename = pl->parameters[pos]->call_def->string; |
---|
490 | } |
---|
491 | if (summary_filename == NULL) summary_filename = permbuff("dummy"); |
---|
492 | w_file_summary = 1; |
---|
493 | } |
---|
494 | else w_file_summary = 0; |
---|
495 | |
---|
496 | /* |
---|
497 | end of command decoding |
---|
498 | */ |
---|
499 | if ((beta_def = twiss_input(current_twiss)) < 0) |
---|
500 | { |
---|
501 | if (beta_def == -1) warning("unknown beta0,", "Twiss ignored"); |
---|
502 | else if (beta_def == -2) |
---|
503 | warning("betx or bety missing,", "Twiss ignored"); |
---|
504 | /* set_variable("twiss_tol", &tol_keep); */ |
---|
505 | return; |
---|
506 | } |
---|
507 | |
---|
508 | set_option("twiss_inval", &beta_def); |
---|
509 | adjust_beam(); |
---|
510 | probe_beam = clone_command(current_beam); |
---|
511 | ptc_deltap = get_value(current_command->name,"deltap"); |
---|
512 | adjust_probe(ptc_deltap); /* sets correct gamma, beta, etc. */ |
---|
513 | adjust_rfc(); /* sets freq in rf-cavities from probe */ |
---|
514 | l = strlen(table_name); |
---|
515 | tarr = new_int_array(l+1); |
---|
516 | conv_char(table_name, tarr); |
---|
517 | |
---|
518 | twiss_table = make_table(table_name, "twiss", twiss_table_cols, |
---|
519 | twiss_table_types, current_sequ->n_nodes); |
---|
520 | |
---|
521 | twiss_table->dynamic = 1; |
---|
522 | add_to_table_list(twiss_table, table_register); |
---|
523 | current_sequ->tw_table = twiss_table; |
---|
524 | twiss_table->org_sequ = current_sequ; |
---|
525 | twiss_table->curr= 0; |
---|
526 | current_node = current_sequ->ex_start; |
---|
527 | /* w_ptc_twiss_(tarr->i); */ |
---|
528 | |
---|
529 | /* --- */ |
---|
530 | /* create additional table to hold summary data after one-turn */ |
---|
531 | /* such as momentum compaction factor, tune and chromaticities */ |
---|
532 | l = strlen(summary_table_name); /* reuse of l */ |
---|
533 | summary_tarr = new_int_array(l+1); |
---|
534 | conv_char(summary_table_name, summary_tarr); |
---|
535 | |
---|
536 | ptc_twiss_summary_table = make_table(summary_table_name, "twiss summary", |
---|
537 | ptc_twiss_summary_table_cols, ptc_twiss_summary_table_types, |
---|
538 | 5); /* only one row would be enough */ |
---|
539 | /* 18 january 2010 static table - ptc_twiss_summary_table->dynamic = 1; */ |
---|
540 | /* actually static for time-being */ |
---|
541 | add_to_table_list( ptc_twiss_summary_table, table_register ); |
---|
542 | /* --- */ |
---|
543 | |
---|
544 | w_ptc_twiss_(tarr->i,summary_tarr->i); |
---|
545 | |
---|
546 | /* upon completion of the Fortran ptc_twiss call ... */ |
---|
547 | |
---|
548 | fill_twiss_header_ptc(twiss_table,ptc_deltap); |
---|
549 | if (w_file) out_table(table_name, twiss_table, filename); |
---|
550 | |
---|
551 | /* --- */ |
---|
552 | if (w_file_summary) out_table(summary_table_name, ptc_twiss_summary_table, |
---|
553 | summary_filename); |
---|
554 | /* --- */ |
---|
555 | |
---|
556 | /* cleanup */ |
---|
557 | current_beam = keep_beam; |
---|
558 | probe_beam = delete_command(probe_beam); |
---|
559 | current_sequ->range_start = use_range[0]; |
---|
560 | current_sequ->range_end = use_range[1]; |
---|
561 | delete_int_array(tarr); |
---|
562 | |
---|
563 | /* --- */ |
---|
564 | delete_int_array(summary_tarr); |
---|
565 | /* --- */ |
---|
566 | |
---|
567 | /* For the time-being, summary data are only available in case of a closed machine */ |
---|
568 | ptc_twiss_summary = get_option("ptc_twiss_summary"); |
---|
569 | if (ptc_twiss_summary) { |
---|
570 | print_table(ptc_twiss_summary_table); |
---|
571 | } |
---|
572 | } |
---|
573 | |
---|
574 | void |
---|
575 | pro_ptc_create_layout(void) |
---|
576 | /* controls ptc_create_layout module */ |
---|
577 | { |
---|
578 | // int pos; not used |
---|
579 | struct command* keep_beam = current_beam; |
---|
580 | if (attach_beam(current_sequ) == 0) |
---|
581 | fatal_error("ptc_create_layout - sequence without beam:", current_sequ->name); |
---|
582 | adjust_beam(); |
---|
583 | probe_beam = clone_command(current_beam); |
---|
584 | |
---|
585 | if (name_list_pos("errors_dipole", table_register->names) <= -1) // (pos = not used |
---|
586 | { |
---|
587 | errors_dipole = make_table("errors_dipole", "efield", efield_table_cols, |
---|
588 | efield_table_types, 10000); |
---|
589 | add_to_table_list(errors_dipole, table_register); |
---|
590 | } |
---|
591 | else |
---|
592 | { |
---|
593 | reset_count("errors_dipole"); |
---|
594 | } |
---|
595 | |
---|
596 | if (name_list_pos("errors_field", table_register->names) <= -1) // (pos = not used |
---|
597 | { |
---|
598 | errors_field = make_table("errors_field", "efield", efield_table_cols, |
---|
599 | efield_table_types, 10000); |
---|
600 | add_to_table_list(errors_field, table_register); |
---|
601 | } |
---|
602 | else |
---|
603 | { |
---|
604 | reset_count("errors_field"); |
---|
605 | } |
---|
606 | |
---|
607 | if (name_list_pos("errors_total", table_register->names) <= -1) // (pos = not used |
---|
608 | { |
---|
609 | errors_total = make_table("errors_total", "efield", efield_table_cols, |
---|
610 | efield_table_types, 10000); |
---|
611 | add_to_table_list(errors_total, table_register); |
---|
612 | } |
---|
613 | else |
---|
614 | { |
---|
615 | reset_count("errors_total"); |
---|
616 | } |
---|
617 | |
---|
618 | w_ptc_create_layout_(); |
---|
619 | /* cleanup */ |
---|
620 | current_beam = keep_beam; |
---|
621 | probe_beam = delete_command(probe_beam); |
---|
622 | } |
---|
623 | |
---|
624 | void |
---|
625 | pro_ptc_read_errors(void) |
---|
626 | /* controls ptc_read_errors module */ |
---|
627 | { |
---|
628 | struct command* keep_beam = current_beam; |
---|
629 | if (attach_beam(current_sequ) == 0) |
---|
630 | fatal_error("ptc_read_errors - sequence without beam:", current_sequ->name); |
---|
631 | adjust_beam(); |
---|
632 | probe_beam = clone_command(current_beam); |
---|
633 | |
---|
634 | w_ptc_read_errors_(); |
---|
635 | /* cleanup */ |
---|
636 | current_beam = keep_beam; |
---|
637 | probe_beam = delete_command(probe_beam); |
---|
638 | } |
---|
639 | |
---|
640 | void |
---|
641 | pro_ptc_refresh_k(void) |
---|
642 | /* controls ptc_refresh_k module */ |
---|
643 | { |
---|
644 | struct command* keep_beam = current_beam; |
---|
645 | if (attach_beam(current_sequ) == 0) |
---|
646 | fatal_error("ptc_refresh_k - sequence without beam:", current_sequ->name); |
---|
647 | adjust_beam(); |
---|
648 | probe_beam = clone_command(current_beam); |
---|
649 | |
---|
650 | w_ptc_refresh_k_(); |
---|
651 | /* cleanup */ |
---|
652 | current_beam = keep_beam; |
---|
653 | probe_beam = delete_command(probe_beam); |
---|
654 | } |
---|
655 | |
---|
656 | void |
---|
657 | select_ptc_normal(struct in_cmd* cmd) |
---|
658 | /* sets up all columns of the table normal_results except the last one (value) */ |
---|
659 | { |
---|
660 | struct name_list* nl; |
---|
661 | struct command_parameter_list* pl; |
---|
662 | struct table* t; |
---|
663 | int pos; |
---|
664 | int i, j, jj, curr; |
---|
665 | int skew, mynorder,myn1,myn2,mynres,indexa[4][1000]; |
---|
666 | char* order_list; |
---|
667 | int min_req_order; |
---|
668 | double order[4],n1,n2,n3,n4; |
---|
669 | |
---|
670 | nl = this_cmd->clone->par_names; |
---|
671 | pl = this_cmd->clone->par; |
---|
672 | if (log_val("clear", cmd->clone)) |
---|
673 | { |
---|
674 | min_order = 1; |
---|
675 | min_req_order = 1; |
---|
676 | mynres = 0; |
---|
677 | skew = 0; |
---|
678 | reset_count("normal_results"); |
---|
679 | /* if ((pos = name_list_pos("normal_results", table_register->names)) > -1) delete_table(table_register->tables[pos]);*/ |
---|
680 | return; |
---|
681 | } |
---|
682 | if ((pos = name_list_pos("normal_results", table_register->names)) <= -1) |
---|
683 | { |
---|
684 | /* initialise table */ |
---|
685 | normal_results = make_table("normal_results", "normal_res", normal_res_cols, |
---|
686 | normal_res_types, MAX_ROWS); |
---|
687 | normal_results->dynamic = 1; |
---|
688 | add_to_table_list(normal_results, table_register); |
---|
689 | reset_count("normal_results"); |
---|
690 | pos = name_list_pos("normal_results", table_register->names); |
---|
691 | min_order = 1; |
---|
692 | min_req_order = 1; |
---|
693 | } |
---|
694 | t = table_register->tables[pos]; |
---|
695 | |
---|
696 | /* initialise order array */ |
---|
697 | order[0] = zero; |
---|
698 | order[1] = zero; |
---|
699 | order[2] = zero; |
---|
700 | order[3] = zero; |
---|
701 | if (t->curr == t->max) grow_table(t); |
---|
702 | |
---|
703 | for (j = 0; j < PTC_NAMES_L; j++) |
---|
704 | { |
---|
705 | /* Treat each ptc variable */ |
---|
706 | |
---|
707 | pos = name_list_pos(names[j], nl); |
---|
708 | if (pos > -1 && nl->inform[pos]) |
---|
709 | { |
---|
710 | curr = pl->parameters[pos]->m_string->curr; |
---|
711 | if (curr > 4) |
---|
712 | printf("Too many values for the attribute %s. Only the first four are retained.\n",names[j]); |
---|
713 | for (i = 0; i < curr; i++) |
---|
714 | { |
---|
715 | order_list = pl->parameters[pos]->m_string->p[i]; |
---|
716 | order[i] = atoi(order_list); |
---|
717 | } |
---|
718 | |
---|
719 | if (j == 10 || j == 11) |
---|
720 | { |
---|
721 | min_req_order = order[0]+order[1]+order[2]; |
---|
722 | mynres = 0; |
---|
723 | skew = 0; |
---|
724 | mynorder = (int)order[0]; |
---|
725 | if (mynorder < 0) skew = 1; |
---|
726 | mynorder = abs(mynorder); |
---|
727 | myn1 = (int)order[1]; |
---|
728 | myn2 = (int)order[2]; |
---|
729 | min_req_order = mynorder; |
---|
730 | res_index_(&skew, &mynorder, &myn1, &myn2, &indexa[0][0], &mynres); |
---|
731 | if (mynres > 0) |
---|
732 | { |
---|
733 | if (j == 10) |
---|
734 | { |
---|
735 | for (jj = 0; jj < mynres; jj++) |
---|
736 | { |
---|
737 | n1 = (double)indexa[0][jj]; |
---|
738 | n2 = (double)indexa[1][jj]; |
---|
739 | n3 = (double)indexa[2][jj]; |
---|
740 | n4 = (double)indexa[3][jj]; |
---|
741 | string_to_table_curr("normal_results", "name", "hamc"); |
---|
742 | double_to_table_curr("normal_results", "order1", &n1); |
---|
743 | double_to_table_curr("normal_results", "order2", &n2); |
---|
744 | double_to_table_curr("normal_results", "order3", &n3); |
---|
745 | double_to_table_curr("normal_results", "order4", &n4); |
---|
746 | augment_count("normal_results"); |
---|
747 | string_to_table_curr("normal_results", "name", "hams"); |
---|
748 | double_to_table_curr("normal_results", "order1", &n1); |
---|
749 | double_to_table_curr("normal_results", "order2", &n2); |
---|
750 | double_to_table_curr("normal_results", "order3", &n3); |
---|
751 | double_to_table_curr("normal_results", "order4", &n4); |
---|
752 | augment_count("normal_results"); |
---|
753 | string_to_table_curr("normal_results", "name", "hama"); |
---|
754 | double_to_table_curr("normal_results", "order1", &n1); |
---|
755 | double_to_table_curr("normal_results", "order2", &n2); |
---|
756 | double_to_table_curr("normal_results", "order3", &n3); |
---|
757 | double_to_table_curr("normal_results", "order4", &n4); |
---|
758 | augment_count("normal_results"); |
---|
759 | } |
---|
760 | string_to_table_curr("normal_results", "name", "haml"); |
---|
761 | double_to_table_curr("normal_results", "order1", &order[0]); |
---|
762 | double_to_table_curr("normal_results", "order2", &order[1]); |
---|
763 | double_to_table_curr("normal_results", "order3", &order[2]); |
---|
764 | double_to_table_curr("normal_results", "order4", &order[3]); |
---|
765 | n1 = (double)mynres; |
---|
766 | double_to_table_curr("normal_results", "value", &n1); |
---|
767 | augment_count("normal_results"); |
---|
768 | } |
---|
769 | if (j == 11) |
---|
770 | { |
---|
771 | for (jj = 0; jj < mynres; jj++) |
---|
772 | { |
---|
773 | n1 = (double)indexa[0][jj]; |
---|
774 | n2 = (double)indexa[1][jj]; |
---|
775 | n3 = (double)indexa[2][jj]; |
---|
776 | n4 = (double)indexa[3][jj]; |
---|
777 | string_to_table_curr("normal_results", "name", "gnfc"); |
---|
778 | double_to_table_curr("normal_results", "order1", &n1); |
---|
779 | double_to_table_curr("normal_results", "order2", &n2); |
---|
780 | double_to_table_curr("normal_results", "order3", &n3); |
---|
781 | double_to_table_curr("normal_results", "order4", &n4); |
---|
782 | augment_count("normal_results"); |
---|
783 | string_to_table_curr("normal_results", "name", "gnfs"); |
---|
784 | double_to_table_curr("normal_results", "order1", &n1); |
---|
785 | double_to_table_curr("normal_results", "order2", &n2); |
---|
786 | double_to_table_curr("normal_results", "order3", &n3); |
---|
787 | double_to_table_curr("normal_results", "order4", &n4); |
---|
788 | augment_count("normal_results"); |
---|
789 | string_to_table_curr("normal_results", "name", "gnfa"); |
---|
790 | double_to_table_curr("normal_results", "order1", &n1); |
---|
791 | double_to_table_curr("normal_results", "order2", &n2); |
---|
792 | double_to_table_curr("normal_results", "order3", &n3); |
---|
793 | double_to_table_curr("normal_results", "order4", &n4); |
---|
794 | augment_count("normal_results"); |
---|
795 | } |
---|
796 | string_to_table_curr("normal_results", "name", "gnfu"); |
---|
797 | double_to_table_curr("normal_results", "order1", &order[0]); |
---|
798 | double_to_table_curr("normal_results", "order2", &order[1]); |
---|
799 | double_to_table_curr("normal_results", "order3", &order[2]); |
---|
800 | double_to_table_curr("normal_results", "order4", &order[3]); |
---|
801 | n1 = (double)mynres; |
---|
802 | double_to_table_curr("normal_results", "value", &n1); |
---|
803 | augment_count("normal_results"); |
---|
804 | } |
---|
805 | } |
---|
806 | } |
---|
807 | else |
---|
808 | { |
---|
809 | if(((strcmp(names[j], "dq1") == zero)|| (strcmp(names[j], "dq2") == zero)) && order[0] == zero) order[0]=one; |
---|
810 | string_to_table_curr("normal_results", "name", names[j]); |
---|
811 | double_to_table_curr("normal_results", "order1", &order[0]); |
---|
812 | double_to_table_curr("normal_results", "order2", &order[1]); |
---|
813 | double_to_table_curr("normal_results", "order3", &order[2]); |
---|
814 | double_to_table_curr("normal_results", "order4", &order[3]); |
---|
815 | augment_count("normal_results"); |
---|
816 | if(j == 12) |
---|
817 | { |
---|
818 | min_req_order = 1; |
---|
819 | } |
---|
820 | else |
---|
821 | { |
---|
822 | min_req_order = order[0]+order[1]+order[2]; |
---|
823 | if (j >= 8) min_req_order += order[0]+order[1]; |
---|
824 | if (j >= 6) min_req_order += 1; |
---|
825 | } |
---|
826 | } |
---|
827 | if (min_order < min_req_order) min_order = min_req_order; |
---|
828 | } |
---|
829 | } |
---|
830 | if (debuglevel > 2) |
---|
831 | { |
---|
832 | printf("The minimum required order is %d \n--------------------------------\n",min_order); |
---|
833 | } |
---|
834 | } |
---|
835 | |
---|
836 | void |
---|
837 | pro_ptc_trackline(struct in_cmd* cmd) |
---|
838 | { |
---|
839 | /*Does PTC tracking taking to the account acceleration */ |
---|
840 | /*it is basically wrapper to subroutine ptc_trackline() in madx_ptc_trackline.f90*/ |
---|
841 | |
---|
842 | int pos, one; |
---|
843 | struct name_list* nl = cmd->clone->par_names; |
---|
844 | struct command_parameter_list* pl = cmd->clone->par; |
---|
845 | int parexist = -1; |
---|
846 | double value = 0; |
---|
847 | int ivalue = 0; |
---|
848 | |
---|
849 | struct command* keep_beam = current_beam; |
---|
850 | |
---|
851 | if (attach_beam(current_sequ) == 0) |
---|
852 | fatal_error("PTC_TRACKLINE - sequence without beam:", current_sequ->name); |
---|
853 | |
---|
854 | |
---|
855 | pos = name_list_pos("file", nl); |
---|
856 | |
---|
857 | if (nl->inform[pos]) |
---|
858 | { |
---|
859 | set_option("track_dump", &one); |
---|
860 | } |
---|
861 | |
---|
862 | if ((track_filename = pl->parameters[pos]->string) == NULL) |
---|
863 | { |
---|
864 | if (pl->parameters[pos]->call_def != NULL) |
---|
865 | { |
---|
866 | track_filename = pl->parameters[pos]->call_def->string; |
---|
867 | } |
---|
868 | else |
---|
869 | { |
---|
870 | track_filename = permbuff("dummy"); |
---|
871 | } |
---|
872 | } |
---|
873 | track_filename = permbuff(track_filename); |
---|
874 | track_fileext = NULL; |
---|
875 | pos = name_list_pos("extension", nl); |
---|
876 | |
---|
877 | if ((track_fileext = pl->parameters[pos]->string) == NULL) |
---|
878 | { |
---|
879 | if (pl->parameters[pos]->call_def != NULL) |
---|
880 | { |
---|
881 | track_fileext = pl->parameters[pos]->call_def->string; |
---|
882 | } |
---|
883 | if (track_fileext == NULL) |
---|
884 | { |
---|
885 | track_fileext = permbuff("\0"); |
---|
886 | } |
---|
887 | } |
---|
888 | |
---|
889 | track_fileext = permbuff(track_fileext); |
---|
890 | |
---|
891 | if (command_par_value("everystep",cmd->clone) != 0) |
---|
892 | { |
---|
893 | printf("Enforcing onetable=true, current is %f\n", command_par_value("onetable",cmd->clone)); |
---|
894 | set_command_par_value("onetable", cmd->clone, 1.0); |
---|
895 | printf("Now is %f\n", command_par_value("onetable",cmd->clone)); |
---|
896 | } |
---|
897 | |
---|
898 | |
---|
899 | parexist = command_par_value2("onetable",cmd->clone,&value); |
---|
900 | |
---|
901 | if (parexist) |
---|
902 | { |
---|
903 | ivalue = (int)value; |
---|
904 | set_option("onetable", &ivalue); |
---|
905 | } |
---|
906 | |
---|
907 | |
---|
908 | adjust_beam(); |
---|
909 | probe_beam = clone_command(current_beam); |
---|
910 | adjust_rfc(); /* sets freq in rf-cavities from probe */ |
---|
911 | |
---|
912 | |
---|
913 | track_tables_create(cmd); |
---|
914 | |
---|
915 | |
---|
916 | if (command_par_value("everystep",cmd->clone) != 0) |
---|
917 | { |
---|
918 | /*printf("Calling PTC track line every step\n");*/ |
---|
919 | w_ptc_track_everystep_(&curr_obs_points); |
---|
920 | } |
---|
921 | else |
---|
922 | { |
---|
923 | /*printf("Calling STD PTC track line\n");*/ |
---|
924 | w_ptc_trackline_(&curr_obs_points); |
---|
925 | } |
---|
926 | |
---|
927 | track_tables_dump(); |
---|
928 | |
---|
929 | /* cleanup */ |
---|
930 | current_beam = keep_beam; |
---|
931 | probe_beam = delete_command(probe_beam); |
---|
932 | |
---|
933 | } |
---|
934 | |
---|
935 | void |
---|
936 | pro_ptc_enforce6d(struct in_cmd* cmd) |
---|
937 | { |
---|
938 | /*Does PTC tracking taking to the account acceleration */ |
---|
939 | /*it is basically wrapper to subroutine ptc_trackline() in madx_ptc_trackline.f90*/ |
---|
940 | double switchvalue; |
---|
941 | struct name_list* nl; |
---|
942 | int flag; |
---|
943 | |
---|
944 | if (cmd == 0x0) |
---|
945 | { |
---|
946 | warning("pro_ptc_enforce6d:","Command is null!!!"); |
---|
947 | return; |
---|
948 | } |
---|
949 | |
---|
950 | if (cmd->clone == 0x0) |
---|
951 | { |
---|
952 | error("pro_ptc_enforce6d","Command Definintion is null!!!"); |
---|
953 | return; |
---|
954 | } |
---|
955 | |
---|
956 | nl = cmd->clone->par_names; |
---|
957 | |
---|
958 | /*DEBUG LEVEL SWITCH*/ |
---|
959 | if ( name_list_pos("flag", nl) >=0 ) |
---|
960 | { |
---|
961 | command_par_value2("flag", cmd->clone, &switchvalue); |
---|
962 | flag = (int)switchvalue; |
---|
963 | w_ptc_enforce6d_(&flag); |
---|
964 | } |
---|
965 | else |
---|
966 | { |
---|
967 | printf("flag is not present\n"); |
---|
968 | } |
---|
969 | } |
---|
970 | |
---|
971 | void |
---|
972 | pro_ptc_setswitch(struct in_cmd* cmd) |
---|
973 | { |
---|
974 | /*Does PTC tracking taking to the account acceleration */ |
---|
975 | /*it is basically wrapper to subroutine ptc_trackline() in madx_ptc_trackline.f90*/ |
---|
976 | int i; |
---|
977 | double switchvalue; |
---|
978 | struct name_list* nl; |
---|
979 | |
---|
980 | if (cmd == 0x0) |
---|
981 | { |
---|
982 | warning("pro_ptc_setswitch:","Command is null!!!"); |
---|
983 | return; |
---|
984 | } |
---|
985 | |
---|
986 | if (cmd->clone == 0x0) |
---|
987 | { |
---|
988 | printf("pro_ptc_setswitch: Command Definintion is null!!!\n"); |
---|
989 | return; |
---|
990 | } |
---|
991 | |
---|
992 | if (match_is_on == kMatch_PTCknobs) |
---|
993 | { |
---|
994 | madx_mpk_setsetswitch(cmd); |
---|
995 | return; |
---|
996 | } |
---|
997 | |
---|
998 | nl = cmd->clone->par_names; |
---|
999 | |
---|
1000 | /*DEBUG LEVEL SWITCH*/ |
---|
1001 | if ( name_list_pos("debuglevel", nl) >=0 ) |
---|
1002 | { |
---|
1003 | command_par_value2("debuglevel", cmd->clone, &switchvalue); |
---|
1004 | debuglevel = (int)switchvalue; |
---|
1005 | w_ptc_setdebuglevel_(&debuglevel); |
---|
1006 | } |
---|
1007 | else |
---|
1008 | { |
---|
1009 | printf("debuglevel is not present\n"); |
---|
1010 | } |
---|
1011 | |
---|
1012 | |
---|
1013 | /*ACCELERATION SWITCH*/ |
---|
1014 | if ( name_list_pos("maxacceleration", nl) >=0 ) |
---|
1015 | { |
---|
1016 | command_par_value2("maxacceleration", cmd->clone, &switchvalue); |
---|
1017 | if (debuglevel > 0) printf("maxaccel is found and its value is %f\n", switchvalue); |
---|
1018 | i = (int)switchvalue; |
---|
1019 | w_ptc_setaccel_method_(&i); |
---|
1020 | } |
---|
1021 | else |
---|
1022 | { |
---|
1023 | if (debuglevel > 0) printf("maxaccel is not present\n"); |
---|
1024 | } |
---|
1025 | |
---|
1026 | |
---|
1027 | /*EXACT SWITCH*/ |
---|
1028 | if ( name_list_pos("exact_mis", nl) >=0 ) |
---|
1029 | { |
---|
1030 | command_par_value2("exact_mis", cmd->clone, &switchvalue); |
---|
1031 | if (debuglevel > 0) printf("exact_mis is found and its value is %f\n", switchvalue); |
---|
1032 | i = (int)switchvalue; |
---|
1033 | w_ptc_setexactmis_(&i); |
---|
1034 | } |
---|
1035 | else |
---|
1036 | { |
---|
1037 | if (debuglevel > 0) printf("exact_mis is not present\n"); |
---|
1038 | } |
---|
1039 | |
---|
1040 | |
---|
1041 | /*radiation SWITCH*/ |
---|
1042 | if ( name_list_pos("radiation", nl) >=0 ) |
---|
1043 | { |
---|
1044 | command_par_value2("radiation", cmd->clone, &switchvalue); |
---|
1045 | if (debuglevel > 0) printf("radiation is found and its value is %f\n", switchvalue); |
---|
1046 | i = (int)switchvalue; |
---|
1047 | w_ptc_setradiation_(&i); |
---|
1048 | } |
---|
1049 | else |
---|
1050 | { |
---|
1051 | if (debuglevel > 0) printf("radiation is not present\n"); |
---|
1052 | } |
---|
1053 | |
---|
1054 | /*fringe SWITCH*/ |
---|
1055 | if ( name_list_pos("fringe", nl) >=0 ) |
---|
1056 | { |
---|
1057 | command_par_value2("fringe", cmd->clone, &switchvalue); |
---|
1058 | if (debuglevel > 0) printf("fringe is found and its value is %f\n", switchvalue); |
---|
1059 | i = (int)switchvalue; |
---|
1060 | w_ptc_setfringe_(&i); |
---|
1061 | } |
---|
1062 | else |
---|
1063 | { |
---|
1064 | if (debuglevel > 0) printf("fringe is not present\n"); |
---|
1065 | } |
---|
1066 | |
---|
1067 | |
---|
1068 | |
---|
1069 | /*totalpath SWITCH*/ |
---|
1070 | if ( name_list_pos("totalpath", nl) >=0 ) |
---|
1071 | { |
---|
1072 | command_par_value2("totalpath", cmd->clone, &switchvalue); |
---|
1073 | if (debuglevel > 0) printf("totalpath is found and its value is %f\n", switchvalue); |
---|
1074 | i = (int)switchvalue; |
---|
1075 | w_ptc_settotalpath_(&i); |
---|
1076 | } |
---|
1077 | else |
---|
1078 | { |
---|
1079 | if (debuglevel > 0) printf("totalpath is not present\n"); |
---|
1080 | } |
---|
1081 | |
---|
1082 | |
---|
1083 | /*TIME SWITCH*/ |
---|
1084 | if ( name_list_pos("time", nl) >=0 ) |
---|
1085 | { |
---|
1086 | command_par_value2("time", cmd->clone, &switchvalue); |
---|
1087 | if (debuglevel > 0) printf("time is found and its value is %f\n", switchvalue); |
---|
1088 | i = (int)switchvalue; |
---|
1089 | w_ptc_settime_(&i); |
---|
1090 | } |
---|
1091 | else |
---|
1092 | { |
---|
1093 | if (debuglevel > 0) printf("time is not present\n"); |
---|
1094 | } |
---|
1095 | |
---|
1096 | /*NOCAVITY SWITCH*/ |
---|
1097 | if ( name_list_pos("nocavity", nl) >=0 ) |
---|
1098 | { |
---|
1099 | command_par_value2("nocavity", cmd->clone, &switchvalue); |
---|
1100 | if (debuglevel > 0) printf("nocavity is found and its value is %f\n", switchvalue); |
---|
1101 | i = (int)switchvalue; |
---|
1102 | w_ptc_setnocavity_(&i); |
---|
1103 | } |
---|
1104 | else |
---|
1105 | { |
---|
1106 | if (debuglevel > 0) printf("nocavity is not present\n"); |
---|
1107 | } |
---|
1108 | |
---|
1109 | if (debuglevel > 0) printf("obs_points pro_ptc_setswitch Done\n"); |
---|
1110 | } |
---|
1111 | |
---|
1112 | void |
---|
1113 | pro_ptc_printparametric(struct in_cmd* cmd) |
---|
1114 | { |
---|
1115 | struct command_parameter_list* c_parameters= cmd->clone->par; |
---|
1116 | struct name_list* c_parnames = cmd->clone->par_names; |
---|
1117 | int pos = 0; |
---|
1118 | |
---|
1119 | char* filename = 0x0; |
---|
1120 | struct int_array* filenameIA = 0x0; |
---|
1121 | static int zeroint = 0; |
---|
1122 | int* filep = 0x0; |
---|
1123 | |
---|
1124 | pos = name_list_pos("filename", c_parnames); |
---|
1125 | if (pos < 0) |
---|
1126 | { |
---|
1127 | |
---|
1128 | filep = &zeroint; |
---|
1129 | } |
---|
1130 | else |
---|
1131 | { |
---|
1132 | filename = c_parameters->parameters[pos]->string; |
---|
1133 | if ( filename == 0x0 ) |
---|
1134 | { |
---|
1135 | filep = &zeroint; |
---|
1136 | } |
---|
1137 | else |
---|
1138 | { |
---|
1139 | filenameIA = new_int_array(1+strlen(filename)); |
---|
1140 | conv_char(filename,filenameIA); |
---|
1141 | filep = filenameIA->i; |
---|
1142 | } |
---|
1143 | } |
---|
1144 | |
---|
1145 | pos = name_list_pos("format", c_parnames); |
---|
1146 | if (pos < 0) |
---|
1147 | { |
---|
1148 | printf("mad_ptc.c: pro_ptc_printparametric: format parameter does not exist.\n"); |
---|
1149 | return; |
---|
1150 | } |
---|
1151 | |
---|
1152 | w_ptc_writeparresults_(filep); |
---|
1153 | |
---|
1154 | delete_int_array(filenameIA); |
---|
1155 | } |
---|
1156 | |
---|
1157 | void |
---|
1158 | pro_ptc_printframes(struct in_cmd* cmd) |
---|
1159 | { |
---|
1160 | struct command_parameter_list* c_parameters= cmd->clone->par; |
---|
1161 | struct name_list* c_parnames = cmd->clone->par_names; |
---|
1162 | int pos = 0; |
---|
1163 | |
---|
1164 | char* filename = 0x0; |
---|
1165 | struct int_array* filenameIA = 0x0; |
---|
1166 | char* format = 0x0; |
---|
1167 | /* |
---|
1168 | * Piotr.Skowronski@cern.ch |
---|
1169 | * Routine that writes coordinates of magnets from PTC |
---|
1170 | * either as text or ROOT macro which executed gives 3d image of the layout |
---|
1171 | * Requires one parameter: filename |
---|
1172 | */ |
---|
1173 | pos = name_list_pos("file", c_parnames); |
---|
1174 | if (pos < 0) |
---|
1175 | { |
---|
1176 | printf("mad_ptc.c: pro_ptc_printframes: file parameter does not exist.\n"); |
---|
1177 | return; |
---|
1178 | } |
---|
1179 | |
---|
1180 | filename = c_parameters->parameters[pos]->string; |
---|
1181 | if ( filename == 0x0 ) |
---|
1182 | { |
---|
1183 | warning("mad_ptc.c: pro_ptc_printframes: no file name: ", "ignored"); |
---|
1184 | return; |
---|
1185 | } |
---|
1186 | |
---|
1187 | |
---|
1188 | pos = name_list_pos("format", c_parnames); |
---|
1189 | if (pos < 0) |
---|
1190 | { |
---|
1191 | printf("mad_ptc.c: pro_ptc_printframes: format parameter does not exist.\n"); |
---|
1192 | return; |
---|
1193 | } |
---|
1194 | |
---|
1195 | format = c_parameters->parameters[pos]->string; |
---|
1196 | printf("mad_ptc.c: pro_ptc_printframes: format is %s.\n", format); |
---|
1197 | |
---|
1198 | filenameIA = new_int_array(1+strlen(filename)); |
---|
1199 | |
---|
1200 | conv_char(filename,filenameIA); |
---|
1201 | |
---|
1202 | |
---|
1203 | if (strcmp(format,"rootmacro") == 0) |
---|
1204 | { |
---|
1205 | w_ptc_printlayout_rootm_(filenameIA->i); |
---|
1206 | } |
---|
1207 | else |
---|
1208 | { |
---|
1209 | w_ptc_printframes_(filenameIA->i); |
---|
1210 | } |
---|
1211 | |
---|
1212 | delete_int_array(filenameIA); |
---|
1213 | } |
---|
1214 | |
---|
1215 | void |
---|
1216 | pro_ptc_export_xml(struct in_cmd* cmd) |
---|
1217 | { |
---|
1218 | struct command_parameter_list* c_parameters= cmd->clone->par; |
---|
1219 | struct name_list* c_parnames = cmd->clone->par_names; |
---|
1220 | int pos = 0; |
---|
1221 | char* filename = 0x0; |
---|
1222 | struct int_array* filenameIA = 0x0; |
---|
1223 | /* char* format = 0x0; */ |
---|
1224 | |
---|
1225 | pos = name_list_pos("file", c_parnames); |
---|
1226 | if (pos < 0) |
---|
1227 | { |
---|
1228 | /* should never enter here */ |
---|
1229 | printf("mad_ptc.c: pro_ptc_export_xml: file parameter does not exist.\n"); |
---|
1230 | return; |
---|
1231 | } |
---|
1232 | |
---|
1233 | filename = c_parameters->parameters[pos]->string; |
---|
1234 | printf("will write to file %s\n",filename); |
---|
1235 | |
---|
1236 | if ( filename == 0x0 ) |
---|
1237 | { |
---|
1238 | warning("mad_ptc.c: pro_ptc_export_xml: no file name: ", "ignored"); |
---|
1239 | return; |
---|
1240 | } |
---|
1241 | |
---|
1242 | filenameIA = new_int_array(1+strlen(filename)); |
---|
1243 | |
---|
1244 | conv_char(filename,filenameIA); |
---|
1245 | |
---|
1246 | w_ptc_export_xml_(filenameIA->i); |
---|
1247 | |
---|
1248 | delete_int_array(filenameIA); |
---|
1249 | } |
---|
1250 | |
---|
1251 | void |
---|
1252 | pro_ptc_eplacement(struct in_cmd* cmd) |
---|
1253 | {/* |
---|
1254 | Sets a parameter |
---|
1255 | */ |
---|
1256 | struct command_parameter_list* c_parameters= cmd->clone->par; |
---|
1257 | struct name_list* c_parnames = cmd->clone->par_names; |
---|
1258 | int pos = 0; |
---|
1259 | int k = 0; |
---|
1260 | struct node* nodes[2]={0x0,0x0}; |
---|
1261 | struct node* anode=0x0; |
---|
1262 | char* element; |
---|
1263 | int refframe=0;/*0 global, 1 current position, 2 end face if the previous element*/ |
---|
1264 | |
---|
1265 | |
---|
1266 | pos = name_list_pos("refframe", c_parnames); |
---|
1267 | if (pos < 0) |
---|
1268 | { |
---|
1269 | printf("mad_ptc.c: pro_ptc_eplacement: refframe parameter does not exist.\n"); |
---|
1270 | return; |
---|
1271 | } |
---|
1272 | |
---|
1273 | if ( c_parnames->inform[pos] != 0 ) |
---|
1274 | { |
---|
1275 | /*if it is zero it is not specified*/ |
---|
1276 | |
---|
1277 | if ( c_parameters->parameters[pos]->string == 0x0 ) |
---|
1278 | { |
---|
1279 | warning("mad_ptc.c: pro_ptc_eplacement: string describing refframe is null: ", "using default"); |
---|
1280 | refframe = 0; |
---|
1281 | } |
---|
1282 | else |
---|
1283 | { |
---|
1284 | /*printf("refframe is %s.\n", c_parameters->parameters[pos]->string );*/ |
---|
1285 | |
---|
1286 | if ( strcmp(c_parameters->parameters[pos]->string,"current") == 0 ) |
---|
1287 | { |
---|
1288 | refframe = 1; |
---|
1289 | } |
---|
1290 | |
---|
1291 | if ( strcmp(c_parameters->parameters[pos]->string,"previouselement") == 0 ) |
---|
1292 | { |
---|
1293 | refframe = 2; |
---|
1294 | } |
---|
1295 | } |
---|
1296 | } |
---|
1297 | |
---|
1298 | |
---|
1299 | pos = name_list_pos("range", c_parnames); |
---|
1300 | if (pos < 0) |
---|
1301 | { |
---|
1302 | printf("mad_ptc.c: pro_ptc_eplacement: range parameter does not exist.\n"); |
---|
1303 | return; |
---|
1304 | } |
---|
1305 | |
---|
1306 | if ( c_parnames->inform[pos] == 0 ) |
---|
1307 | { |
---|
1308 | printf("mad_ptc.c: pro_ptc_eplacement: inform for range is 0.\n"); |
---|
1309 | return; |
---|
1310 | } |
---|
1311 | |
---|
1312 | element = c_parameters->parameters[pos]->string; |
---|
1313 | if ( element == 0x0 ) |
---|
1314 | { |
---|
1315 | warning("mad_ptc.c: pro_ptc_eplacement: no element name: ", "ignored"); |
---|
1316 | return; |
---|
1317 | } |
---|
1318 | |
---|
1319 | |
---|
1320 | k = get_ex_range(element, current_sequ, nodes); |
---|
1321 | if ( k != 1) |
---|
1322 | { |
---|
1323 | if (k > 1) |
---|
1324 | { |
---|
1325 | warningnew("pro_ptc_eplacement","More then one element correstponds to the range <<%s>>.",element); |
---|
1326 | seterrorflag(1,"pro_ptc_eplacement","More then one element correstponds to the range"); |
---|
1327 | return; |
---|
1328 | } |
---|
1329 | else |
---|
1330 | { |
---|
1331 | warningnew("pro_ptc_eplacement","Element <<%s>> not found",element); |
---|
1332 | seterrorflag(1,"pro_ptc_eplacement","Element not found"); |
---|
1333 | return; |
---|
1334 | } |
---|
1335 | } |
---|
1336 | |
---|
1337 | |
---|
1338 | |
---|
1339 | pos = 0; |
---|
1340 | anode=current_sequ->range_start; |
---|
1341 | while(anode) |
---|
1342 | { |
---|
1343 | /*printf("%d: Comparing %#x %s with %#x %s \n",pos, nodes[0], nodes[0]->name, anode, anode->name);*/ |
---|
1344 | if ( nodes[0] == anode ) |
---|
1345 | { |
---|
1346 | /*printf("Element is at pos %d !\n",pos);*/ |
---|
1347 | break; |
---|
1348 | } |
---|
1349 | |
---|
1350 | if (anode == current_sequ->range_end) |
---|
1351 | { |
---|
1352 | warningnew("pro_ptc_eplacement","Reached the end of sequence - Element <<%s>> not found",element); |
---|
1353 | return; |
---|
1354 | } |
---|
1355 | |
---|
1356 | anode = anode->next; |
---|
1357 | pos++; /*before if because fortran numerates from 1*/ |
---|
1358 | |
---|
1359 | } |
---|
1360 | w_ptc_eplacement_(&pos,&refframe); |
---|
1361 | } |
---|
1362 | |
---|
1363 | void |
---|
1364 | pro_ptc_varyknob(struct in_cmd* cmd) |
---|
1365 | {/* |
---|
1366 | Sets a variable based on parameter |
---|
1367 | */ |
---|
1368 | |
---|
1369 | if (match_is_on != kMatch_PTCknobs) |
---|
1370 | { |
---|
1371 | warningnew("pro_ptc_varyknob","Match with ptcknobs is not active, command ignored"); |
---|
1372 | return; |
---|
1373 | } |
---|
1374 | |
---|
1375 | madx_mpk_addvariable(cmd); |
---|
1376 | |
---|
1377 | } |
---|
1378 | |
---|
1379 | void |
---|
1380 | pro_ptc_knob(struct in_cmd* cmd) |
---|
1381 | {/* |
---|
1382 | Sets a parameter |
---|
1383 | */ |
---|
1384 | struct command_parameter_list* c_parameters= cmd->clone->par; |
---|
1385 | struct name_list* c_parnames = cmd->clone->par_names; |
---|
1386 | int pos = 0; |
---|
1387 | |
---|
1388 | char* element = 0x0; |
---|
1389 | struct int_array* elementIA = 0x0; |
---|
1390 | char* initialp = 0x0; |
---|
1391 | struct int_array* initialpIA = 0x0; |
---|
1392 | char* p = 0x0; |
---|
1393 | |
---|
1394 | pos = name_list_pos("element", c_parnames); |
---|
1395 | if (pos < 0) |
---|
1396 | { |
---|
1397 | printf("mad_ptc.c: pro_ptc_knob: element parameter does not exist.\n"); |
---|
1398 | return; |
---|
1399 | } |
---|
1400 | element = c_parameters->parameters[pos]->string; |
---|
1401 | |
---|
1402 | pos = name_list_pos("initial", c_parnames); |
---|
1403 | if (pos < 0) |
---|
1404 | { |
---|
1405 | printf("mad_ptc.c: pro_ptc_knob: initial parameter does not exist.\n"); |
---|
1406 | return; |
---|
1407 | } |
---|
1408 | |
---|
1409 | initialp = c_parameters->parameters[pos]->string; |
---|
1410 | |
---|
1411 | if ( (element == 0x0) && (initialp == 0x0) ) |
---|
1412 | { |
---|
1413 | warning("mad_ptc.c: pro_ptc_knob: no element name neither initial pareter specified: ", |
---|
1414 | "command ignored"); |
---|
1415 | return; |
---|
1416 | } |
---|
1417 | |
---|
1418 | if (initialp) |
---|
1419 | { |
---|
1420 | mycpy(c_dum->c, initialp); |
---|
1421 | |
---|
1422 | stolower(c_dum->c); |
---|
1423 | |
---|
1424 | initialpIA = new_int_array(1+strlen(c_dum->c)); |
---|
1425 | |
---|
1426 | conv_char(c_dum->c,initialpIA); |
---|
1427 | |
---|
1428 | w_ptc_addknob_i_(initialpIA->i); |
---|
1429 | |
---|
1430 | delete_int_array(initialpIA); |
---|
1431 | |
---|
1432 | } |
---|
1433 | else |
---|
1434 | { |
---|
1435 | mycpy(c_dum->c, element); |
---|
1436 | |
---|
1437 | if (command_par_value("exactmatch",cmd->clone) != 0) |
---|
1438 | { |
---|
1439 | p = strstr(c_dum->c,"["); |
---|
1440 | if (p) |
---|
1441 | { |
---|
1442 | *p = ':'; |
---|
1443 | p = strstr(c_dum->c,"]"); |
---|
1444 | if (p == 0x0) |
---|
1445 | { |
---|
1446 | warningnew("mad_ptc.c: pro_ptc_knob:","element %s is bady defned. Commnad ignored.",element); |
---|
1447 | return; |
---|
1448 | } |
---|
1449 | *p=0; |
---|
1450 | } |
---|
1451 | else |
---|
1452 | { /*assume it is the first element*/ |
---|
1453 | p = &(c_dum->c[strlen(c_dum->c)]); |
---|
1454 | p[0]=':'; |
---|
1455 | p[1]='1'; |
---|
1456 | p[2]= 0; |
---|
1457 | } |
---|
1458 | |
---|
1459 | } |
---|
1460 | stoupper(c_dum->c); |
---|
1461 | |
---|
1462 | elementIA = new_int_array(1+strlen(c_dum->c)); |
---|
1463 | |
---|
1464 | conv_char(c_dum->c,elementIA); |
---|
1465 | |
---|
1466 | w_ptc_addknob_(elementIA->i); |
---|
1467 | |
---|
1468 | delete_int_array(elementIA); |
---|
1469 | } |
---|
1470 | } |
---|
1471 | |
---|
1472 | void |
---|
1473 | pro_ptc_setknobvalue(struct in_cmd* cmd) |
---|
1474 | {/* |
---|
1475 | Sets a parameter value |
---|
1476 | */ |
---|
1477 | struct command_parameter_list* c_parameters= cmd->clone->par; |
---|
1478 | struct name_list* c_parnames = cmd->clone->par_names; |
---|
1479 | int pos = 0; |
---|
1480 | |
---|
1481 | char* element = 0x0; |
---|
1482 | struct int_array* elementIA = 0x0; |
---|
1483 | |
---|
1484 | pos = name_list_pos("element", c_parnames); |
---|
1485 | if (pos < 0) |
---|
1486 | { |
---|
1487 | printf("mad_ptc.c: pro_ptc_knob: element parameter does not exist.\n"); |
---|
1488 | return; |
---|
1489 | } |
---|
1490 | |
---|
1491 | element = c_parameters->parameters[pos]->string; |
---|
1492 | if ( element == 0x0 ) |
---|
1493 | { |
---|
1494 | warning("mad_ptc.c: pro_ptc_knob: no element name: ", "ignored"); |
---|
1495 | return; |
---|
1496 | } |
---|
1497 | mycpy(c_dum->c, element); |
---|
1498 | |
---|
1499 | stoupper(c_dum->c); |
---|
1500 | |
---|
1501 | elementIA = new_int_array(1+strlen(c_dum->c)); |
---|
1502 | |
---|
1503 | conv_char(c_dum->c,elementIA); |
---|
1504 | |
---|
1505 | w_ptc_setknobvalue_(elementIA->i); |
---|
1506 | |
---|
1507 | delete_int_array(elementIA); |
---|
1508 | |
---|
1509 | |
---|
1510 | } |
---|
1511 | |
---|
1512 | void |
---|
1513 | pro_ptc_setfieldcomp(struct in_cmd* cmd) |
---|
1514 | {/* |
---|
1515 | Sets a parameter value |
---|
1516 | */ |
---|
1517 | struct command_parameter_list* c_parameters= cmd->clone->par; |
---|
1518 | struct name_list* c_parnames = cmd->clone->par_names; |
---|
1519 | int pos = 0; |
---|
1520 | int k = 0; |
---|
1521 | struct node* nodes[2]={0x0,0x0}; |
---|
1522 | struct node* anode=0x0; |
---|
1523 | char* element; |
---|
1524 | |
---|
1525 | |
---|
1526 | |
---|
1527 | pos = name_list_pos("element", c_parnames); |
---|
1528 | if (pos < 0) |
---|
1529 | { |
---|
1530 | printf("mad_ptc.c: pro_ptc_setfieldcomp: range parameter does not exist.\n"); |
---|
1531 | return; |
---|
1532 | } |
---|
1533 | |
---|
1534 | if ( c_parnames->inform[pos] == 0 ) |
---|
1535 | { |
---|
1536 | printf("mad_ptc.c: pro_ptc_setfieldcomp: inform for range is 0.\n"); |
---|
1537 | return; |
---|
1538 | } |
---|
1539 | |
---|
1540 | element = c_parameters->parameters[pos]->string; |
---|
1541 | if ( element == 0x0 ) |
---|
1542 | { |
---|
1543 | warning("mad_ptc.c: pro_ptc_setfieldcomp: no element name: ", "ignored"); |
---|
1544 | return; |
---|
1545 | } |
---|
1546 | |
---|
1547 | |
---|
1548 | k = get_range(element, current_sequ, nodes); |
---|
1549 | if ( k != 1) |
---|
1550 | { |
---|
1551 | if (k > 1) |
---|
1552 | { |
---|
1553 | warningnew("pro_ptc_setfieldcomp","More then one element correstponds to the range <<%s>>.",element); |
---|
1554 | seterrorflag(1,"pro_ptc_setfieldcomp","More then one element correstponds to the range"); |
---|
1555 | return; |
---|
1556 | } |
---|
1557 | else |
---|
1558 | { |
---|
1559 | warningnew("pro_ptc_setfieldcomp","Element <<%s>> not found",element); |
---|
1560 | seterrorflag(1,"pro_ptc_setfieldcomp","Element not found"); |
---|
1561 | return; |
---|
1562 | } |
---|
1563 | } |
---|
1564 | |
---|
1565 | |
---|
1566 | |
---|
1567 | pos = 0; |
---|
1568 | anode=current_sequ->range_start; |
---|
1569 | while( anode != 0x0 ) |
---|
1570 | { |
---|
1571 | if ( nodes[0] == current_sequ->nodes->nodes[pos] ) |
---|
1572 | { |
---|
1573 | /* printf("Element is at pos %d !\n",pos);*/ |
---|
1574 | break; |
---|
1575 | } |
---|
1576 | |
---|
1577 | if (current_sequ->nodes->nodes[pos] == current_sequ->range_end) |
---|
1578 | { |
---|
1579 | warningnew("pro_ptc_setfieldcomp","Reached the end of sequence - Element <<%s>> not found",element); |
---|
1580 | return; |
---|
1581 | } |
---|
1582 | pos++; /*before if because fortran numerates from 1*/ |
---|
1583 | } |
---|
1584 | |
---|
1585 | w_ptc_setfieldcomp_(&pos); |
---|
1586 | |
---|
1587 | } |
---|
1588 | |
---|
1589 | void |
---|
1590 | pro_ptc_select(struct in_cmd* cmd) |
---|
1591 | {/* |
---|
1592 | processes ptc_select command |
---|
1593 | it directs ptc_twiss to store given QUANTITY in a named TABLE's COLUMN |
---|
1594 | Then, it these values are accessible for other MAD-X modules for calculations. |
---|
1595 | The most important one is the matching module. |
---|
1596 | */ |
---|
1597 | |
---|
1598 | char* monomial = 0x0; |
---|
1599 | |
---|
1600 | int element = 0; |
---|
1601 | int* tablep = 0; |
---|
1602 | int* columnp = 0; |
---|
1603 | static int zeroint = 0;/*if there is no column name or table name these are passed as null strings */ |
---|
1604 | struct int_array* tabnameIA = 0x0;/*string passing to fortran is tricky*/ |
---|
1605 | struct int_array* colnameIA = 0x0;/*and is done via integer arrays*/ |
---|
1606 | struct int_array* monoIA = 0x0; |
---|
1607 | |
---|
1608 | monomial = command_par_string("monomial",cmd->clone); |
---|
1609 | |
---|
1610 | if (monomial == 0x0) |
---|
1611 | { |
---|
1612 | warning("mad_ptc.c: pro_ptc_select: monomial is NULL ", "ignored"); |
---|
1613 | return; |
---|
1614 | } |
---|
1615 | |
---|
1616 | monoIA = new_int_array(1+strlen(monomial)); |
---|
1617 | conv_char(monomial,monoIA); |
---|
1618 | |
---|
1619 | element = command_par_value("polynomial",cmd->clone); |
---|
1620 | |
---|
1621 | pro_ptc_select_checkpushtable(cmd,&tabnameIA,&colnameIA); |
---|
1622 | |
---|
1623 | if ( tabnameIA ) |
---|
1624 | { |
---|
1625 | tablep = tabnameIA->i; |
---|
1626 | } |
---|
1627 | else |
---|
1628 | { |
---|
1629 | tablep = &zeroint; |
---|
1630 | } |
---|
1631 | |
---|
1632 | if ( colnameIA ) |
---|
1633 | { |
---|
1634 | columnp = colnameIA->i; |
---|
1635 | } |
---|
1636 | else |
---|
1637 | { |
---|
1638 | columnp = &zeroint; |
---|
1639 | } |
---|
1640 | |
---|
1641 | w_ptc_addpush_(tablep,columnp,&element,monoIA->i); |
---|
1642 | |
---|
1643 | delete_int_array(tabnameIA); |
---|
1644 | delete_int_array(colnameIA); |
---|
1645 | delete_int_array(monoIA); |
---|
1646 | |
---|
1647 | } |
---|
1648 | |
---|
1649 | int |
---|
1650 | pro_ptc_moments(struct in_cmd* cmd) |
---|
1651 | { |
---|
1652 | int no = command_par_value("no", cmd->clone); |
---|
1653 | |
---|
1654 | w_ptc_moments_(&no); |
---|
1655 | |
---|
1656 | return 1; |
---|
1657 | } |
---|
1658 | |
---|
1659 | int |
---|
1660 | pro_ptc_select_moment(struct in_cmd* cmd) |
---|
1661 | { |
---|
1662 | /*adds a moment or more moments to the list |
---|
1663 | if parametric switch is present they will be stored also as Taylor Series*/ |
---|
1664 | |
---|
1665 | int pos, tablepos; |
---|
1666 | int i, j; |
---|
1667 | int mdefi[6]; |
---|
1668 | char* mdefin, *pchar; |
---|
1669 | char tablename[48]; |
---|
1670 | char colname[9]; |
---|
1671 | int clen = 0; |
---|
1672 | struct int_array* tabIA = 0x0; |
---|
1673 | struct int_array* mdefIA = 0x0; |
---|
1674 | struct command_parameter_list* c_parameters= cmd->clone->par; |
---|
1675 | struct name_list* c_parnames = cmd->clone->par_names; |
---|
1676 | int parametric = 0; |
---|
1677 | int int_arr[100]; |
---|
1678 | |
---|
1679 | |
---|
1680 | tablepos = name_list_pos("table", c_parnames); |
---|
1681 | if ( tablepos < 0) |
---|
1682 | { |
---|
1683 | printf("Weired: table parameter is not defined\n"); |
---|
1684 | return 1; |
---|
1685 | } |
---|
1686 | |
---|
1687 | pchar = c_parameters->parameters[tablepos]->string; |
---|
1688 | if ( pchar == 0x0 ) |
---|
1689 | { |
---|
1690 | strcpy(tablename,"moments"); |
---|
1691 | } |
---|
1692 | else if ( pchar[0] == 0 ) |
---|
1693 | { |
---|
1694 | strcpy(tablename,"moments"); |
---|
1695 | } |
---|
1696 | else |
---|
1697 | { |
---|
1698 | strcpy(tablename,pchar); |
---|
1699 | } |
---|
1700 | |
---|
1701 | tabIA = new_int_array(1+strlen(tablename)); |
---|
1702 | conv_char(tablename,tabIA); |
---|
1703 | |
---|
1704 | pos = name_list_pos("moment_s", c_parnames); |
---|
1705 | if ( pos < 0) |
---|
1706 | { |
---|
1707 | printf("Weired: moments parameter is not defined\n"); |
---|
1708 | return 1; |
---|
1709 | } |
---|
1710 | |
---|
1711 | if (c_parnames->inform[pos]) |
---|
1712 | { |
---|
1713 | for (j = 0; j < c_parameters->parameters[pos]->m_string->curr; j++) |
---|
1714 | { |
---|
1715 | strcpy(colname,"mu000000"); |
---|
1716 | |
---|
1717 | mdefin = c_parameters->parameters[pos]->m_string->p[j]; |
---|
1718 | |
---|
1719 | /*printf("String no %d is %s\n", j, mdefin);*/ |
---|
1720 | |
---|
1721 | clen = strlen(mdefin); |
---|
1722 | |
---|
1723 | /*the loop below decodes string monomial to integer monomial */ |
---|
1724 | for (i = 0; i< 6; i++) |
---|
1725 | { |
---|
1726 | if (clen > i) |
---|
1727 | { |
---|
1728 | mdefi[i] = mdefin[i] - '0'; |
---|
1729 | colname[2+i] = mdefin[i]; |
---|
1730 | } |
---|
1731 | else |
---|
1732 | { |
---|
1733 | mdefi[i] = 0; |
---|
1734 | } |
---|
1735 | } |
---|
1736 | |
---|
1737 | |
---|
1738 | mdefIA = new_int_array(9);/*size + "mu" + 6charnumbers*/ |
---|
1739 | conv_char(colname,mdefIA); |
---|
1740 | |
---|
1741 | w_ptc_addmoment_(&(mdefi[0]),&(mdefi[1]),&(mdefi[2]),&(mdefi[3]),&(mdefi[4]),&(mdefi[5]), |
---|
1742 | tabIA->i, mdefIA->i, ¶metric); |
---|
1743 | |
---|
1744 | delete_int_array(mdefIA); |
---|
1745 | |
---|
1746 | } |
---|
1747 | } |
---|
1748 | |
---|
1749 | |
---|
1750 | pos = name_list_pos("moment", c_parnames); |
---|
1751 | /*i is dummy... we know there is no strings or doubles */ |
---|
1752 | comm_para_("moment", &pos, &i, &i, int_arr, 0x0, 0x0, 0x0); |
---|
1753 | |
---|
1754 | if (pos > 6) pos = 6; |
---|
1755 | /*if there is something and it is not only one zero */ |
---|
1756 | if ( (pos >= 0) && !((pos == 1) && (int_arr[0] == 0)) ) |
---|
1757 | { |
---|
1758 | |
---|
1759 | for (i=0;i<pos;i++) |
---|
1760 | { |
---|
1761 | if (int_arr[i] < 0) break; |
---|
1762 | |
---|
1763 | mdefi[i] = int_arr[i]; |
---|
1764 | } |
---|
1765 | |
---|
1766 | for (i=pos; i<6;i++) |
---|
1767 | { |
---|
1768 | mdefi[i] = 0; |
---|
1769 | } |
---|
1770 | |
---|
1771 | tablepos = name_list_pos("column", c_parnames); |
---|
1772 | if ( tablepos < 0) |
---|
1773 | { |
---|
1774 | printf("Weired: column parameter is not defined\n"); |
---|
1775 | return 1; |
---|
1776 | } |
---|
1777 | |
---|
1778 | tablename[0] = 0; |
---|
1779 | pchar = c_parameters->parameters[tablepos]->string; |
---|
1780 | if ( pchar != 0x0 ) |
---|
1781 | { |
---|
1782 | if ( pchar[0] != 0 ) |
---|
1783 | { |
---|
1784 | strcpy(tablename,pchar); |
---|
1785 | } |
---|
1786 | |
---|
1787 | } |
---|
1788 | |
---|
1789 | if (tablename[0] == 0) |
---|
1790 | { |
---|
1791 | sprintf(tablename,"mu_%d_%d_%d_%d_%d_%d", |
---|
1792 | mdefi[0],mdefi[1],mdefi[2],mdefi[3],mdefi[4],mdefi[5]); |
---|
1793 | printf("pro_ptc_select_moment: Column name not provied, generated one is %s",tablename); |
---|
1794 | } |
---|
1795 | |
---|
1796 | mdefIA = new_int_array(1+strlen(tablename)); |
---|
1797 | |
---|
1798 | conv_char(tablename,mdefIA); |
---|
1799 | w_ptc_addmoment_(&(mdefi[0]),&(mdefi[1]),&(mdefi[2]),&(mdefi[3]),&(mdefi[4]),&(mdefi[5]), |
---|
1800 | tabIA->i, mdefIA->i, ¶metric); |
---|
1801 | |
---|
1802 | delete_int_array(mdefIA); |
---|
1803 | } |
---|
1804 | |
---|
1805 | |
---|
1806 | |
---|
1807 | delete_int_array(tabIA); |
---|
1808 | |
---|
1809 | return 0; |
---|
1810 | } |
---|
1811 | |
---|
1812 | int |
---|
1813 | makemomentstables(void) |
---|
1814 | { |
---|
1815 | static const int maxtables = 100; |
---|
1816 | char* tables[100]; /*tables[maxtables];*/ |
---|
1817 | struct name_list* cols[100]; /*cols[maxtables][maxcols];*/ |
---|
1818 | struct table* t; |
---|
1819 | char tabname[20]; |
---|
1820 | char colname[17]; |
---|
1821 | int nmom; |
---|
1822 | int i,j; // ,k; not used |
---|
1823 | |
---|
1824 | |
---|
1825 | memset(tables,0x0,maxtables*sizeof(char*)); |
---|
1826 | |
---|
1827 | |
---|
1828 | nmom = w_ptc_getnmoments_(); |
---|
1829 | for (i = 1; i <= nmom; i++) |
---|
1830 | { |
---|
1831 | w_ptc_getmomentstabcol_(&i, tabname, colname); |
---|
1832 | /*printf(" mom %d: %s %s\n",i, tabname, colname);*/ |
---|
1833 | |
---|
1834 | for(j=0; tables[j] != 0x0 ;j++) |
---|
1835 | { |
---|
1836 | if ((strcmp(tables[j],tabname) == 0)) break; |
---|
1837 | } |
---|
1838 | /*printf(" index of this table is %d \n",j);*/ |
---|
1839 | |
---|
1840 | if (tables[j] == 0x0) |
---|
1841 | { |
---|
1842 | tables[j] = (char*)mycalloc("makemomentstables",strlen(tabname) + 1, sizeof(char)); |
---|
1843 | strcpy(tables[j],tabname); |
---|
1844 | cols[j] = new_name_list("columns", 15); |
---|
1845 | add_to_name_list(permbuff("name"),3,cols[j]); |
---|
1846 | add_to_name_list(permbuff("s"),2,cols[j]); |
---|
1847 | } |
---|
1848 | |
---|
1849 | add_to_name_list(permbuff(colname),2,cols[j]); // k = not used |
---|
1850 | |
---|
1851 | } |
---|
1852 | |
---|
1853 | if (moments_tables) |
---|
1854 | { |
---|
1855 | myfree("",moments_tables->tables); |
---|
1856 | delete_name_list(moments_tables->names); |
---|
1857 | myfree("",moments_tables); |
---|
1858 | } |
---|
1859 | |
---|
1860 | moments_tables = new_table_list(10); |
---|
1861 | |
---|
1862 | for(j=0; tables[j] != 0x0 ;j++) |
---|
1863 | { |
---|
1864 | /*printf("Making table %s\n",tables[j]);*/ |
---|
1865 | |
---|
1866 | t = new_table(tables[j], "usermoments", current_sequ->n_nodes, cols[j]); |
---|
1867 | t->org_cols = cols[j]->curr; |
---|
1868 | /*print_table(t);*/ |
---|
1869 | add_to_table_list(t, table_register); |
---|
1870 | add_to_table_list(t, moments_tables); |
---|
1871 | } |
---|
1872 | |
---|
1873 | |
---|
1874 | /* make_table("moments", "twiss", twiss_table_cols, |
---|
1875 | twiss_table_types, current_sequ->n_nodes); */ |
---|
1876 | return 0; |
---|
1877 | } |
---|
1878 | |
---|
1879 | void |
---|
1880 | augmentcountmomtabs(double* s) |
---|
1881 | { |
---|
1882 | int i; |
---|
1883 | struct table* t; |
---|
1884 | |
---|
1885 | if (moments_tables == 0x0) |
---|
1886 | { |
---|
1887 | warning("augmentcountmomtabs","moments_tables is NULL\n"); |
---|
1888 | return; |
---|
1889 | } |
---|
1890 | |
---|
1891 | for ( i = 0; i < moments_tables->curr; i++) |
---|
1892 | { |
---|
1893 | t = moments_tables->tables[i]; |
---|
1894 | t->s_cols[0][t->curr] = tmpbuff(current_node->name); |
---|
1895 | t->d_cols[1][t->curr] = *s; |
---|
1896 | if (t->num_cols > t->org_cols) add_vars_to_table(t); |
---|
1897 | if (++t->curr == t->max) grow_table(t); |
---|
1898 | } |
---|
1899 | } |
---|
1900 | |
---|
1901 | void |
---|
1902 | pro_ptc_script(struct in_cmd* cmd) |
---|
1903 | {/* |
---|
1904 | processes ptc_script command |
---|
1905 | it directs ptc_twiss to store given QUANTITY in a named TABLE's COLUMN |
---|
1906 | Then, it these values are accessible for other MAD-X modules for calculations. |
---|
1907 | The most important one is the matching module. |
---|
1908 | */ |
---|
1909 | |
---|
1910 | struct command_parameter_list* c_parameters= cmd->clone->par; |
---|
1911 | struct name_list* c_parnames = cmd->clone->par_names; |
---|
1912 | int pos = 0; |
---|
1913 | char* scriptname = 0x0; |
---|
1914 | struct int_array* scriptnameIA = 0x0;/*string passing to fortran is tricky*/ |
---|
1915 | |
---|
1916 | /*extracts table specified by the user*/ |
---|
1917 | pos = name_list_pos("file", c_parnames); |
---|
1918 | if (pos < 0) |
---|
1919 | { |
---|
1920 | printf("mad_ptc.c: pro_ptc_script: file parameter does not exist.\n"); |
---|
1921 | return; |
---|
1922 | } |
---|
1923 | |
---|
1924 | scriptname = c_parameters->parameters[pos]->string; |
---|
1925 | if ( scriptname == 0x0 ) |
---|
1926 | { |
---|
1927 | warning("mad_ptc.c: pro_ptc_script: no script name: ", "ignored"); |
---|
1928 | return; |
---|
1929 | } |
---|
1930 | |
---|
1931 | scriptnameIA = new_int_array(1+strlen(scriptname)); |
---|
1932 | conv_char(scriptname,scriptnameIA); |
---|
1933 | |
---|
1934 | w_ptc_script_(scriptnameIA->i);/*calls the fortran*/ |
---|
1935 | |
---|
1936 | delete_int_array(scriptnameIA); |
---|
1937 | |
---|
1938 | } |
---|
1939 | |
---|
1940 | void |
---|
1941 | pro_ptc_open_gino(struct in_cmd* cmd) |
---|
1942 | { |
---|
1943 | /* |
---|
1944 | processes ptc_open_gino command |
---|
1945 | */ |
---|
1946 | |
---|
1947 | struct command_parameter_list* c_parameters= cmd->clone->par; |
---|
1948 | struct name_list* c_parnames = cmd->clone->par_names; |
---|
1949 | int pos = 0; |
---|
1950 | char* scriptname = 0x0; |
---|
1951 | struct int_array* scriptnameIA = 0x0;/*string passing to fortran is tricky*/ |
---|
1952 | |
---|
1953 | pos = name_list_pos("command", c_parnames); |
---|
1954 | scriptname = c_parameters->parameters[pos]->string; |
---|
1955 | if ( scriptname == 0x0 ) |
---|
1956 | { |
---|
1957 | warning("mad_ptc.c: pro_ptc_open_gino: no script name: ", "ignored"); |
---|
1958 | return; |
---|
1959 | } |
---|
1960 | |
---|
1961 | scriptnameIA = new_int_array(1+strlen(scriptname)); |
---|
1962 | conv_char(scriptname,scriptnameIA); |
---|
1963 | |
---|
1964 | w_ptc_open_gino_(scriptnameIA->i);/*calls the fortran*/ |
---|
1965 | |
---|
1966 | delete_int_array(scriptnameIA); |
---|
1967 | |
---|
1968 | } |
---|
1969 | |
---|
1970 | void |
---|
1971 | pro_ptc_track(struct in_cmd* cmd) |
---|
1972 | { |
---|
1973 | int k=0, pos, one = 1; |
---|
1974 | struct name_list* nl = cmd->clone->par_names; |
---|
1975 | struct command_parameter_list* pl = cmd->clone->par; |
---|
1976 | /* char rout_name[] = "ptc_track"; */ |
---|
1977 | int npart = stored_track_start->curr; |
---|
1978 | struct table* t; |
---|
1979 | /* int turns = command_par_value("turns", cmd->clone); */ |
---|
1980 | |
---|
1981 | track_is_on = 1; |
---|
1982 | puts("enter PTC_TRACK module"); |
---|
1983 | if (current_sequ == NULL || current_sequ->ex_start == NULL) |
---|
1984 | { |
---|
1985 | warning("sequence not active,", "TRACK ignored"); |
---|
1986 | return; |
---|
1987 | } |
---|
1988 | if (attach_beam(current_sequ) == 0) |
---|
1989 | fatal_error("TRACK - sequence without beam:", current_sequ->name); |
---|
1990 | if ((k = get_value(current_command->name,"onepass")) != 0) |
---|
1991 | fprintf(prt_file, "one pass is on\n"); |
---|
1992 | /* |
---|
1993 | if ((k = get_value(current_command->name,"damp")) != 0) |
---|
1994 | fprintf(prt_file, "damp is on\n"); |
---|
1995 | set_option("damp", &k); |
---|
1996 | if ((k = get_value(current_command->name,"quantum")) != 0) |
---|
1997 | fprintf(prt_file, "quantum is on\n"); |
---|
1998 | set_option("quantum", &k); |
---|
1999 | */ |
---|
2000 | set_option("onepass", &k); |
---|
2001 | if ((k = get_value(current_command->name,"aperture")) != 0) |
---|
2002 | fprintf(prt_file, "aperture tracking is on\n"); |
---|
2003 | set_option("aperture", &k); |
---|
2004 | k = get_value(current_command->name,"dump"); |
---|
2005 | set_option("track_dump", &k); |
---|
2006 | k = get_value(current_command->name,"onetable"); |
---|
2007 | set_option("onetable", &k); |
---|
2008 | track_deltap=get_value(current_command->name,"deltap"); |
---|
2009 | set_variable("track_deltap", &track_deltap); |
---|
2010 | if(track_deltap != 0) fprintf(prt_file, v_format("track_deltap: %F\n"), |
---|
2011 | track_deltap); |
---|
2012 | pos = name_list_pos("file", nl); |
---|
2013 | if (nl->inform[pos]) set_option("track_dump", &one); |
---|
2014 | if ((track_filename = pl->parameters[pos]->string) == NULL) |
---|
2015 | { |
---|
2016 | if (pl->parameters[pos]->call_def != NULL) |
---|
2017 | track_filename = pl->parameters[pos]->call_def->string; |
---|
2018 | else track_filename = permbuff("dummy"); |
---|
2019 | } |
---|
2020 | track_filename = permbuff(track_filename); |
---|
2021 | track_fileext = NULL; |
---|
2022 | pos = name_list_pos("extension", nl); |
---|
2023 | if ((track_fileext = pl->parameters[pos]->string) == NULL) |
---|
2024 | { |
---|
2025 | if (pl->parameters[pos]->call_def != NULL) |
---|
2026 | track_fileext = pl->parameters[pos]->call_def->string; |
---|
2027 | if (track_fileext == NULL) track_fileext = permbuff("\0"); |
---|
2028 | } |
---|
2029 | track_fileext = permbuff(track_fileext); |
---|
2030 | |
---|
2031 | if (npart == 0) |
---|
2032 | { |
---|
2033 | warning("track_run: no START command seen yet", "ignored"); |
---|
2034 | return; |
---|
2035 | } |
---|
2036 | track_tables_create(cmd); |
---|
2037 | printf("obs_points ptc_track: %d \n",curr_obs_points); |
---|
2038 | w_ptc_track_(&curr_obs_points); |
---|
2039 | t = table_register->tables[name_list_pos("tracksumm", table_register->names)]; |
---|
2040 | if (get_option("info")) print_table(t); |
---|
2041 | if (get_option("track_dump")) track_tables_dump(); |
---|
2042 | fprintf(prt_file, "\n***** end of ptc_run *****\n"); |
---|
2043 | } |
---|
2044 | |
---|