1 | #include "madx.h" |
---|
2 | |
---|
3 | /* Temporary file: global variables |
---|
4 | these variables will be split over their respective modules... |
---|
5 | */ |
---|
6 | |
---|
7 | int debuglevel = 1; |
---|
8 | |
---|
9 | /* Global structure variables by type (alphabetic) */ |
---|
10 | |
---|
11 | struct char_array* aux_buff; /* temporary buffer for many purposes */ |
---|
12 | struct char_array* c_dum; |
---|
13 | struct char_array* c_join; |
---|
14 | struct char_array* work; |
---|
15 | struct char_array* l_wrk; |
---|
16 | |
---|
17 | struct char_array_list* char_buff; /* buffer for all sorts of strings */ |
---|
18 | |
---|
19 | struct char_p_array* tmp_p_array; /* temporary buffer for splits */ |
---|
20 | struct char_p_array* tmp_l_array; /* temporary buffer for special commands */ |
---|
21 | struct char_p_array* line_buffer; /* buffer for line expansion */ |
---|
22 | |
---|
23 | struct command* current_beam = NULL; /* current reference beam */ |
---|
24 | struct command* probe_beam = NULL; /* current beam */ |
---|
25 | struct command* options = NULL; /* current options */ |
---|
26 | struct command* plot_options = NULL; /* current plot options */ |
---|
27 | struct command* current_error = NULL; /* current error command */ |
---|
28 | struct command* current_correct = NULL; /* current correct command */ |
---|
29 | struct command* current_ibs = NULL; /* current ibs command */ |
---|
30 | struct command* current_touschek = NULL;/* current touschek command */ |
---|
31 | struct command* current_survey = NULL; /* current survey command */ |
---|
32 | struct command* current_ptc = NULL; /* current ptc command */ |
---|
33 | struct command* current_twiss = NULL; /* current twiss command */ |
---|
34 | struct command* current_command = NULL; /* current command clone */ |
---|
35 | struct command* current_gweight = NULL; /* current gweight clone */ |
---|
36 | struct command* current_weight = NULL; /* current weight clone */ |
---|
37 | struct command* current_match = NULL; /* current match comm. */ |
---|
38 | struct command* current_eopt = NULL; /* to keep eoption command */ |
---|
39 | struct command* threader_par = NULL; /* threader parameters */ |
---|
40 | |
---|
41 | struct command_list* beam_list; /* list of all beam commands */ |
---|
42 | struct command_list* beta0_list; /* list of user defined beta0s */ |
---|
43 | struct command_list* defined_commands; /* from dictionary */ |
---|
44 | struct command_list* error_select; /* current error select commands */ |
---|
45 | struct command_list* optics_select; /* current optics select commands */ |
---|
46 | struct command_list* optics_list; /* list of optics command/sequence */ |
---|
47 | struct command_list* savebeta_list; |
---|
48 | struct command_list* seqedit_select; /* current seqedit select commands */ |
---|
49 | struct command_list* save_select; /* current save select commands */ |
---|
50 | struct command_list* slice_select; /* current slice select commands */ |
---|
51 | struct command_list* stored_commands; /* list of stored commands */ |
---|
52 | struct command_list* stored_match_var; /* list of match vary commands */ |
---|
53 | struct command_list* stored_track_start;/* list of track start commands */ |
---|
54 | struct command_list* sector_select; /* current sectormap select commands */ |
---|
55 | |
---|
56 | struct command_list_list* table_deselect; /* list of table deselect lists */ |
---|
57 | struct command_list_list* table_select; /* list of all table select lists */ |
---|
58 | |
---|
59 | struct constraint_list* comm_constraints; /* for each constraint command */ |
---|
60 | struct double_array* cat_doubles; /* Polish: constant values */ |
---|
61 | struct double_array* doubles; /* doubles buffer */ |
---|
62 | struct double_array* twiss_deltas; /* for deltap loop in twiss command */ |
---|
63 | struct double_array* vary_vect; /* for matching */ |
---|
64 | struct double_array* vary_dvect; /* for matching */ |
---|
65 | struct double_array* fun_vect; /* for matching */ |
---|
66 | struct double_array* match_work[MATCH_WORK];/* work space for matching */ |
---|
67 | |
---|
68 | struct el_list* drift_list; |
---|
69 | struct el_list* element_list; |
---|
70 | struct el_list* base_type_list; |
---|
71 | struct el_list* selected_elements; |
---|
72 | |
---|
73 | struct in_buff_list* in; /* list of all active input buffers */ |
---|
74 | struct in_buff_list* pro; /* list of active processing buffers */ |
---|
75 | |
---|
76 | struct int_array* deco; /* Polish: coded expression */ |
---|
77 | struct int_array* cat; /* Polish: catgories */ |
---|
78 | struct int_array* d_var; /* Polish: variable references */ |
---|
79 | struct int_array* oper; /* Polish: operator references */ |
---|
80 | struct int_array* func; /* Polish: function references */ |
---|
81 | struct int_array* s_range; /* starts of ranges */ |
---|
82 | struct int_array* e_range; /* ends of ranges */ |
---|
83 | struct int_array* sd_range; /* starts of deselect ranges */ |
---|
84 | struct int_array* ed_range; /* ends of deselect ranges */ |
---|
85 | struct int_array* match_i_work[MATCH_WORK];/* int work space for matching */ |
---|
86 | |
---|
87 | struct in_cmd* this_cmd; /* contains command just read */ |
---|
88 | struct in_cmd* local_twiss[2] = {NULL, NULL}; |
---|
89 | struct in_cmd* embedded_twiss_cmd = NULL;/* current plot command */ |
---|
90 | |
---|
91 | struct in_cmd_list* buffered_cmds; |
---|
92 | |
---|
93 | struct macro_list* line_list; |
---|
94 | struct macro_list* macro_list; |
---|
95 | |
---|
96 | struct name_list* expr_chunks; |
---|
97 | struct name_list* occ_list; |
---|
98 | struct name_list* sxf_list; |
---|
99 | |
---|
100 | struct node* prev_node; |
---|
101 | struct node* current_node = NULL; |
---|
102 | struct node* debug_node = NULL; |
---|
103 | |
---|
104 | struct node_list* selected_ranges;/* filled by some select commands */ |
---|
105 | struct node_list* sector_ranges; /* filled by the sectormap select command */ |
---|
106 | |
---|
107 | struct sequence* current_sequ; /* pointer to currently used sequence */ |
---|
108 | struct sequence* edit_sequ; /* pointer to sequence being edited */ |
---|
109 | |
---|
110 | struct sequence_list* sequences; /* pointer to sequence list */ |
---|
111 | struct sequence_list* match_sequs;/* pointer to sequence list for match */ |
---|
112 | |
---|
113 | struct table* aperture_table; /* current aperture table */ |
---|
114 | struct table* ibs_table; /* current ibs table */ |
---|
115 | struct table* touschek_table; /* current touschek table */ |
---|
116 | struct table* summ_table; /* current twiss summary table */ |
---|
117 | struct table* twiss_table; /* current twiss table */ |
---|
118 | struct table* twiss_table_beam1; /* current twiss table beam1 */ |
---|
119 | struct table* twiss_table_beam2; /* current twiss table beam2 */ |
---|
120 | struct table* twiss_sector_table; /* used for sectormap */ |
---|
121 | struct table* ptc_twiss_summary_table;/* holds summary data after one turn */ |
---|
122 | struct table* map_table; /* added for twiss_input_table */ |
---|
123 | struct table_list* table_register; |
---|
124 | struct table_list* moments_tables = 0x0;/* tables for moments */ |
---|
125 | |
---|
126 | struct table* embedded_twiss_table;/* current twiss table */ |
---|
127 | struct table* normal_results; /* ptc table containing the selected high order functions (such as dx,qx,anhx etc.) */ |
---|
128 | |
---|
129 | struct table* errors_dipole; |
---|
130 | struct table* errors_field; |
---|
131 | struct table* errors_total; |
---|
132 | struct table* errors_read; /* table needed for IO of errors with PTC */ |
---|
133 | |
---|
134 | struct table* survey_table; /* current survey table */ |
---|
135 | struct table* corr_table; /* corrector table after orbit correction */ |
---|
136 | struct table* corr_table1; /* corrector table after orbit correction, beam 1 for two rings */ |
---|
137 | struct table* corr_table2; /* corrector table after orbit correction, beam 2 for two rings */ |
---|
138 | struct table* mon_table; /* monitor table after orbit correction */ |
---|
139 | struct table* orbit_table; /* orbit positions at monitors */ |
---|
140 | struct table* sodd_table_70; /* sodd output table detune_1_end */ |
---|
141 | struct table* sodd_table_71; /* sodd output table detune_1_all */ |
---|
142 | struct table* sodd_table_72; /* sodd output table detune_2_end */ |
---|
143 | struct table* sodd_table_73; /* sodd output table detune_2_all */ |
---|
144 | struct table* sodd_table_74; /* sodd output table distort_1_f_end */ |
---|
145 | struct table* sodd_table_75; /* sodd output table distort_1_h_end */ |
---|
146 | struct table* sodd_table_76; /* sodd output table distort_1_f_all */ |
---|
147 | struct table* sodd_table_77; /* sodd output table distort_1_h_all */ |
---|
148 | struct table* sodd_table_78; /* sodd output table distort_2_f_end */ |
---|
149 | struct table* sodd_table_79; /* sodd output table distort_2_h_end */ |
---|
150 | struct table* target_table = NULL;/* current target table */ |
---|
151 | struct table* model_table = NULL; /* current model table */ |
---|
152 | struct table* orbin_table = NULL; /* current orbit table */ |
---|
153 | |
---|
154 | |
---|
155 | struct table_list* optics_tables; /* contains optics tables from last twiss */ |
---|
156 | struct table_list* table_register;/* contains all tables */ |
---|
157 | |
---|
158 | struct table_list_list* all_table_lists; /* all table lists are entered here */ |
---|
159 | |
---|
160 | struct variable* current_variable = NULL; /* set by act_value (table access) */ |
---|
161 | struct var_list* variable_list; |
---|
162 | |
---|
163 | struct orb_cor* correct_orbit; /* information and links for orbit correction */ |
---|
164 | struct orb_cor2* correct_orbit1; /* information and links for orbit correction */ |
---|
165 | struct orb_cor2* correct_orbit2; /* information and links for orbit correction */ |
---|
166 | struct orb_cor2* correct_orbit12; /* information and links for orbit correction */ |
---|
167 | |
---|
168 | double corrl; /* global limit for orbit corrector strength */ |
---|
169 | |
---|
170 | struct table* efield_table; /* field errors in table form */ |
---|
171 | FILE* fddata; |
---|
172 | FILE* fcdata; |
---|
173 | FILE* ftdata; |
---|
174 | FILE* fgdata; |
---|
175 | |
---|
176 | struct char_p_array* sdds_pat; /* array for selected sdds patterns */ |
---|
177 | |
---|
178 | FILE* debug_file; /* for debug output */ |
---|
179 | FILE* stamp_file; /* for debug output */ |
---|
180 | FILE* out_file; /* for table output */ |
---|
181 | FILE* prt_file; /* for echo output */ |
---|
182 | FILE* sec_file = NULL; /* for sector output in "embedded" twiss */ |
---|
183 | FILE* tab_file; /* for table input */ |
---|
184 | |
---|
185 | /* Global simple variables by type */ |
---|
186 | |
---|
187 | char quote; /* current open single or double quote */ |
---|
188 | char int_format[20], /* current integer format */ |
---|
189 | float_format[20], /* current float format */ |
---|
190 | string_format[20]; /* current string format */ |
---|
191 | char var_form[1000]; /* buffer for the user-controlled formats */ |
---|
192 | char blank[] = " "; |
---|
193 | char none[] = "none"; |
---|
194 | char one_string[] = "1"; |
---|
195 | char aptwfile[FNAME_L] = "dummy"; |
---|
196 | char* aux_char_pt; /* for debug purposes */ |
---|
197 | char* exx; |
---|
198 | char* current_link_group; |
---|
199 | char* current_range; /* currently used range, or NULL */ |
---|
200 | char* title = NULL; |
---|
201 | char* match_seqs[2]; |
---|
202 | char* match_beta[2]; |
---|
203 | char* match_range[2]; |
---|
204 | char* track_filename; /* track module file name start */ |
---|
205 | char* track_fileext; /* track module file name extension */ |
---|
206 | char track_plot_filename[NAME_L] = "madx_track"; /* plot module: output postscript file name in track mode */ |
---|
207 | |
---|
208 | double pi, twopi, degrad, raddeg, e, clight, hbar; |
---|
209 | double penalty; |
---|
210 | double match_tol; |
---|
211 | double orbit0[6]; |
---|
212 | double disp0[6]; |
---|
213 | double sxf_suml = 0; |
---|
214 | double track_deltap=0; |
---|
215 | double oneturnmat[36]; |
---|
216 | double fintx_plot; /* to save the value of fintx for the reset_interpolation routine */ |
---|
217 | |
---|
218 | const double zero = 0; |
---|
219 | const double one = 1; |
---|
220 | const double two = 2; |
---|
221 | const double ten_p_3 = 1.e3; |
---|
222 | const double ten_p_6 = 1.e6; |
---|
223 | const double ten_p_9 = 1.e9; |
---|
224 | const double ten_p_12 = 1.e12; |
---|
225 | const double ten_m_3 = 1.e-3; |
---|
226 | const double ten_m_6 = 1.e-6; |
---|
227 | const double ten_m_9 = 1.e-9; |
---|
228 | const double ten_m_12 = 1.e-12; |
---|
229 | const double ten_m_15 = 1.e-15; |
---|
230 | const double ten_m_16 = 1.e-16; |
---|
231 | const double ten_m_19 = 1.e-19; |
---|
232 | |
---|
233 | int add_error_opt = 0; /* ADD error option, set with eoption */ |
---|
234 | int embedded_flag = 0; /* flag (= 1 when entering routine pro_embedded_twiss, 0 at exit) */ |
---|
235 | int min_order = 1; /* minimum required order */ |
---|
236 | int print_correct_opt = 1; /* PRINT options for orbit correction */ |
---|
237 | int debug_correct_opt = 0; /* DEBUG options for orbit correction */ |
---|
238 | int assign_start = 0; /* flag for multiple assign statements */ |
---|
239 | int aux_count = 0; /* for debug purposes */ |
---|
240 | int beam_info = -1; /* flag to print beam information once */ |
---|
241 | int c_range_end; /* node count of current range end */ |
---|
242 | int c_range_start; /* node count of current range start */ |
---|
243 | int curr_obs_points; /* current number of observation points */ |
---|
244 | int current_calls = 0; /* call counter in match */ |
---|
245 | int current_call_lim = 0; /* current call limit in match */ |
---|
246 | int current_const = 0; /* current constraint number in match */ |
---|
247 | int default_beam_saved = 0; /* flag to avoid multiple save of default beam */ |
---|
248 | int edit_is_on = 0; /* != 0 if inside current sequence edit */ |
---|
249 | int final_message = 0; /* set to 1 when end message written */ |
---|
250 | int group_is_on = 0; /* true when inside group */ |
---|
251 | int guess_flag = 0; /* != 0 if coguess read */ |
---|
252 | int in_stop = 0; /* input buffer stop flag */ |
---|
253 | int inbuf_level = 0; /* input buffer level */ |
---|
254 | int init_warn = 1; /* intialisation warning level */ |
---|
255 | int interactive; /* non-zero if interactive */ |
---|
256 | int irn_rand[NR_RAND]; /* for random generator */ |
---|
257 | int keep_tw_print; /* previous twiss print flag (match) */ |
---|
258 | int loop_cnt = 0; /* used to detect infinite loops */ |
---|
259 | int match_calls = 0; /* command call limit in match */ |
---|
260 | int match_is_on = 0; /* true when inside match command */ |
---|
261 | int match_num_beta = 0; |
---|
262 | int match_num_range = 0; |
---|
263 | int match_num_seqs = 0; |
---|
264 | int mig_strategy; /* migrad strategy (match) */ |
---|
265 | int jac_strategy; /* jacobian strategy (match) */ |
---|
266 | int jac_repeat; /* jacobian repeat (match) */ |
---|
267 | double jac_cool; /* jacobian cool factor (match) */ |
---|
268 | double jac_balance; /* jacobian balance cool factor (match) */ |
---|
269 | double jac_random; /* jacobian random factor (match) */ |
---|
270 | int jac_bisec; /* jacobian bisec factor (match) */ |
---|
271 | double jac_cond; /* jacobian svd cond. num (match) */ |
---|
272 | int new_name_count = 0; /* to make internal names */ |
---|
273 | int next_rand = 0; /* for random generator */ |
---|
274 | int plots_made = 0; /* set to 1 if plots are made */ |
---|
275 | int polish_cnt = 0; /* used to detect infinite loops */ |
---|
276 | int print_match_summary = 0;/* activate the print option in the |
---|
277 | 'mtgeti' and 'collect' routines (mtgeti->mtgetc) */ |
---|
278 | int quote_toggle = 0; /* for quote strings on input */ |
---|
279 | int return_flag = 0; /* 1 when "return" read */ |
---|
280 | int scrap_count = 0; /* running counter to make things unique */ |
---|
281 | int seqedit_install = 0; /* counter for seqedit installs */ |
---|
282 | int seqedit_move = 0; /* counter for seqedit moves */ |
---|
283 | int seqedit_remove = 0; /* counter for seqedit removes */ |
---|
284 | int sequ_is_on = 0; /* != 0 if inside current sequence decl. */ |
---|
285 | int stamp_flag = 0; /* checks for double delete when != 0 */ |
---|
286 | int start_cnt = 0; /* counter for start commands */ |
---|
287 | int start_var = 0; /* start of variables after predefined constants */ |
---|
288 | int total_const = 0; /* total no. of constraints in match */ |
---|
289 | int total_vars = 0; /* total no. of variables in match */ |
---|
290 | int track_is_on = 0; /* true when inside track command */ |
---|
291 | int track_start_cnt = 0; /* counter for track start commands */ |
---|
292 | int twiss_success = 0; /* set by twiss module to 1 if OK */ |
---|
293 | int use_count = 0; /* incremented by 1 every time use is executed */ |
---|
294 | int vary_cnt = 0; /* counter for vary commands */ |
---|
295 | int watch_flag = 0; /* produces debug output when != 0 */ |
---|
296 | |
---|
297 | int na_err, /* current no. of alignment errors */ |
---|
298 | nf_err, /* current no. of field errors */ |
---|
299 | indent = 0, /* current indentation count */ |
---|
300 | b_level = 0, /* current brace level */ |
---|
301 | sxf_elem_cnt = 0, /* element count */ |
---|
302 | tag_flag = 0, /* if > 0, tag = parent name written */ |
---|
303 | tag_cnt = 0, /* if > 0, tag = specified type code |
---|
304 | written for selected types only */ |
---|
305 | sxf_align_cnt = 0, /* element with align errors count */ |
---|
306 | sxf_field_cnt = 0, /* element with field errors count */ |
---|
307 | stop_flag = 0, /* 1 if stop condition */ |
---|
308 | occnt_add = 0, /* flag for element name modification */ |
---|
309 | b_indent[100], /* list of indents */ |
---|
310 | add_indent[] = {1, 2, 2, 4, 7, 7, 7, 7, 7, 7}; |
---|
311 | |
---|
312 | double |
---|
313 | guess_orbit[6], |
---|
314 | al_errors[ALIGN_MAX], |
---|
315 | fd_errors[FIELD_MAX]; |
---|
316 | |
---|
317 | char |
---|
318 | line[MADX_LINE_MAX], |
---|
319 | tag_type[MAX_TAG][16], |
---|
320 | tag_code[MAX_TAG][16]; |
---|
321 | |
---|
322 | time_t last_time; |
---|
323 | time_t start_time; |
---|
324 | |
---|
325 | char filenames[100][500]; |
---|
326 | int currentline[100]; |
---|
327 | |
---|
328 | double** trackstrarpositions = 0x0; /* two dimensional array with track positions*/ |
---|
329 | |
---|