1 | #include "madx.h" |
---|
2 | |
---|
3 | int |
---|
4 | get_option(char* str) |
---|
5 | { |
---|
6 | /* This function is called by fortran to get option of a command */ |
---|
7 | int i; // , k; not used |
---|
8 | mycpy(c_dum->c, str); |
---|
9 | if (options != NULL |
---|
10 | && (i = name_list_pos(c_dum->c, options->par_names)) > -1) |
---|
11 | return options->par->parameters[i]->double_value; // (k = not used |
---|
12 | else if (strcmp(c_dum->c, "warn") == 0) return init_warn; |
---|
13 | else return 0; |
---|
14 | } |
---|
15 | |
---|
16 | void |
---|
17 | set_option(char* str, int* opt) |
---|
18 | /* sets an (old or new) option with name "str", |
---|
19 | value *opt (0 flase, 1 true) */ |
---|
20 | { |
---|
21 | int i, k; //, j not used |
---|
22 | char* bc; |
---|
23 | mycpy(c_dum->c, str); bc = permbuff(c_dum->c); |
---|
24 | if ((i = name_list_pos(bc, options->par_names)) < 0) |
---|
25 | { |
---|
26 | add_to_name_list(bc, 0, options->par_names); // j = not used |
---|
27 | if ((k = options->par->curr) == options->par->max) |
---|
28 | grow_command_parameter_list(options->par); |
---|
29 | options->par->parameters[options->par->curr++] |
---|
30 | = new_command_parameter(bc, 0); |
---|
31 | options->par->parameters[k]->double_value = *opt; |
---|
32 | } |
---|
33 | else options->par->parameters[i]->double_value = *opt; |
---|
34 | } |
---|
35 | |
---|
36 | void |
---|
37 | set_defaults(char* string) /* reset options, beam etc. to defaults */ |
---|
38 | { |
---|
39 | int i, pos; |
---|
40 | struct command* beam_clone; |
---|
41 | |
---|
42 | if ((pos = name_list_pos(string, defined_commands->list)) > -1) |
---|
43 | { |
---|
44 | if (strcmp(string, "option") == 0) |
---|
45 | { |
---|
46 | if (options != NULL) delete_command(options); |
---|
47 | options = clone_command(defined_commands->commands[pos]); |
---|
48 | } |
---|
49 | else if (strcmp(string, "set") == 0) |
---|
50 | store_set(defined_commands->commands[pos], 0); |
---|
51 | else if (strcmp(string, "setplot") == 0) |
---|
52 | { |
---|
53 | if (plot_options != NULL) delete_command(plot_options); |
---|
54 | plot_options = clone_command(defined_commands->commands[pos]); |
---|
55 | } |
---|
56 | else if (strcmp(string, "threader") == 0) |
---|
57 | { |
---|
58 | if (threader_par != NULL) delete_command(threader_par); |
---|
59 | threader_par = clone_command(defined_commands->commands[pos]); |
---|
60 | } |
---|
61 | else if (strcmp(string, "beam") == 0) |
---|
62 | { |
---|
63 | if (current_beam == NULL) |
---|
64 | current_beam = clone_command(defined_commands->commands[pos]); |
---|
65 | beam_clone = clone_command(defined_commands->commands[pos]); |
---|
66 | for (i = 0; i < beam_clone->par_names->curr; i++) |
---|
67 | beam_clone->par_names->inform[i] = 1; /* mark as "read" */ |
---|
68 | update_beam(beam_clone); |
---|
69 | delete_command(beam_clone); |
---|
70 | } |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|