1 | #include <stdio.h>
|
---|
2 | #include <string.h>
|
---|
3 | #include <stdlib.h>
|
---|
4 | #include <math.h>
|
---|
5 | #include "diag.h"
|
---|
6 | #include "parms.h"
|
---|
7 | #include "init.h"
|
---|
8 |
|
---|
9 | extern char whites[]; /* white chars (init) */
|
---|
10 | extern char line[]; /* parsing buf. (init) */
|
---|
11 |
|
---|
12 | char axisdev_filename[256], reflectivity_filename[256];
|
---|
13 | char geo_filename[256];
|
---|
14 | char atmosphere[256]; /* atmospheric model */
|
---|
15 |
|
---|
16 | /* Prototypes */
|
---|
17 | extern void setall(long iseed1,long iseed2); /* rnds */
|
---|
18 | static void ReadCerfiles(FILE *parfile);
|
---|
19 |
|
---|
20 | static void ReadCerfiles(FILE *parfile)
|
---|
21 | { char *value_ptr = NULL; /* ptr at parm value */
|
---|
22 | extern FILE *GetNextFile(char *cername); /* in main.c */
|
---|
23 |
|
---|
24 | filelist = parfile;
|
---|
25 | parfile = NULL;
|
---|
26 | if (fgets(line, LINE_MAX_LENGTH, filelist) == NULL ||
|
---|
27 | (value_ptr=strtok(line, whites)) == NULL)
|
---|
28 | FatalError(FLST_NSPEC_FTL);
|
---|
29 | else if (value_ptr[0] == '@')
|
---|
30 | { fclose(filelist);
|
---|
31 | if ((filelist=fopen(value_ptr+1, "r")) == NULL)
|
---|
32 | FatalError(FLST_NFND__FTL, value_ptr+1);
|
---|
33 | else if (fgets(line, LINE_MAX_LENGTH, filelist) == NULL)
|
---|
34 | FatalError(FLST_NSPEC_FTL);
|
---|
35 | value_ptr = strtok(line, whites); }
|
---|
36 |
|
---|
37 | /* Set cername and find out event number bounds */
|
---|
38 | strcpy(cername, value_ptr);
|
---|
39 | if ((value_ptr=strtok(NULL, whites)) == NULL)
|
---|
40 | { first_Event = 0;
|
---|
41 | last_Event = 1000000; }
|
---|
42 | else
|
---|
43 | { first_Event = atol(value_ptr);
|
---|
44 | value_ptr = strtok(NULL, whites);
|
---|
45 | last_Event = value_ptr ? atol(value_ptr) : 1000000; }
|
---|
46 |
|
---|
47 | /* Try to open cerfile. */
|
---|
48 |
|
---|
49 | if ((cerfile=fopen(cername, "r")) == NULL)
|
---|
50 | { Message(CERF_NFND__MSG, cername);
|
---|
51 | cerfile=GetNextFile(cername); }
|
---|
52 |
|
---|
53 | /* If no valid cerfile is found then exit */
|
---|
54 | if (cerfile == NULL)
|
---|
55 | FatalError(CERF_NSPEC_FTL);
|
---|
56 |
|
---|
57 | /* Check boundaries */
|
---|
58 | if (first_Event > last_Event)
|
---|
59 | { Error(EVTN_WRONG_ERR, first_Event, last_Event, cername);
|
---|
60 | first_Event = 0;
|
---|
61 | last_Event = 1000000; }
|
---|
62 |
|
---|
63 | } /* end of ReadCerfiles */
|
---|
64 |
|
---|
65 | void ParmsSwitch(FILE *parfile)
|
---|
66 | { char *value_ptr = NULL; /* ptr at parm value */
|
---|
67 | int switch_end = FALSE; /* bool to exit loop */
|
---|
68 | extern FILE *geofile; /* geo file (init) */
|
---|
69 | extern void SetVerbose(int vlevel); /* from diag.c */
|
---|
70 | extern int ParseLine(FILE *parfile, /* FILE with parms */
|
---|
71 | const char *token_list[], /* array w/tokens */
|
---|
72 | int tokens, /* nr of tokens */
|
---|
73 | char **value_ptr); /* ptr->parm val. */
|
---|
74 |
|
---|
75 | do
|
---|
76 | { switch(ParseLine(parfile, parms, ARRAY_SZ(parms), &value_ptr))
|
---|
77 | { case output_file:
|
---|
78 | if ((rflfile=fopen(value_ptr, "w+")) == NULL)
|
---|
79 | FatalError(OUTF_ERROR_FTL, value_ptr);
|
---|
80 | Message(OUTF_OPEN__MSG, value_ptr);
|
---|
81 | break;
|
---|
82 | case ct_file:
|
---|
83 | if ((geofile=fopen(value_ptr, "r")) == NULL)
|
---|
84 | FatalError(GEOF_ERROR_FTL, value_ptr);
|
---|
85 | else
|
---|
86 | strcpy(geo_filename, value_ptr);
|
---|
87 | Message(GEOF_OPEN__MSG, value_ptr);
|
---|
88 | break;
|
---|
89 | case axisdev_file:
|
---|
90 | strcpy(axisdev_filename, value_ptr);
|
---|
91 | break;
|
---|
92 | case reflectivity_file:
|
---|
93 | strcpy(reflectivity_filename, value_ptr);
|
---|
94 | break;
|
---|
95 | case atm_model:
|
---|
96 | strcpy(atmosphere, value_ptr);
|
---|
97 | break;
|
---|
98 | case verbose_level:
|
---|
99 | SetVerbose(atoi(value_ptr));
|
---|
100 | break;
|
---|
101 | case fixed_target:
|
---|
102 | is_Fixed_Target = TRUE;
|
---|
103 | fixed_Theta = (float) atof(value_ptr);
|
---|
104 | value_ptr = strtok(NULL, whites);
|
---|
105 | if (value_ptr == NULL)
|
---|
106 | { Error(FIXD_TARGT_ERR);
|
---|
107 | is_Fixed_Target = FALSE; }
|
---|
108 | else
|
---|
109 | { fixed_Phi = (float) atof(value_ptr);
|
---|
110 | Message(FIXD_ENABL_MSG, fixed_Theta, fixed_Phi);
|
---|
111 | fixed_Theta *= (float) (M_PI/180.);
|
---|
112 | fixed_Phi *= (float) (M_PI/180.); }
|
---|
113 | break;
|
---|
114 |
|
---|
115 | /* Added May 2002, AM: */
|
---|
116 | case telescope_position:
|
---|
117 | Telescope_x = (float) atof(value_ptr);
|
---|
118 | value_ptr = strtok(NULL, whites);
|
---|
119 | if (value_ptr == NULL)
|
---|
120 | { Error(TEL_POS_ERR);
|
---|
121 | exit(-1);}
|
---|
122 | else
|
---|
123 | { Telescope_y = (float) atof(value_ptr);
|
---|
124 | Message(TEL_POS_MSG, Telescope_x, Telescope_y);}
|
---|
125 | break;
|
---|
126 |
|
---|
127 | case max_events:
|
---|
128 | Message(MAX__EVTS__MSG, max_Events=atol(value_ptr));
|
---|
129 | break;
|
---|
130 |
|
---|
131 | /* AM, Nov 2002, added wobble option: */
|
---|
132 | case wobble_mode:
|
---|
133 | wobble_position = (int) atoi(value_ptr);
|
---|
134 | if ( (wobble_position > 1 || wobble_position < -1) &&
|
---|
135 | wobble_position != 3)
|
---|
136 | {
|
---|
137 | Message(WOBBLE_POS_ERR);
|
---|
138 | exit(-1);
|
---|
139 | }
|
---|
140 | else
|
---|
141 | {
|
---|
142 | Message(WOBBLE_POS_MSG, wobble_position);
|
---|
143 | break;
|
---|
144 | }
|
---|
145 | case energy_cuts:
|
---|
146 | low_Ecut = (float) atof(value_ptr);
|
---|
147 | value_ptr = strtok(NULL, whites);
|
---|
148 | if (value_ptr == NULL)
|
---|
149 | { Error(ENRG_LIMIT_ERR);
|
---|
150 | low_Ecut = 0.; }
|
---|
151 | else
|
---|
152 | { high_Ecut = (float) atof(value_ptr);
|
---|
153 | Message(ENRG_CUTS__MSG, low_Ecut, high_Ecut); }
|
---|
154 | break;
|
---|
155 | case seeds:
|
---|
156 | Seeds[0] = atol(value_ptr);
|
---|
157 | value_ptr = strtok(NULL, whites);
|
---|
158 | if (value_ptr) Seeds[1] = atol(value_ptr);
|
---|
159 | else
|
---|
160 | { Error(SEED_ERROR_ERR);
|
---|
161 | Seeds[0] = 3141592L; }
|
---|
162 | break;
|
---|
163 | case cer_files:
|
---|
164 | ReadCerfiles(parfile);
|
---|
165 | switch_end = TRUE;
|
---|
166 | default: switch_end = TRUE;
|
---|
167 | break; }}
|
---|
168 | while (!switch_end);
|
---|
169 |
|
---|
170 | if (filelist == NULL)
|
---|
171 | FatalError(FLST_NSPEC_FTL);
|
---|
172 |
|
---|
173 | /* Set random seeds */
|
---|
174 | setall(Seeds[0], Seeds[1]);
|
---|
175 | Message(SEED_SET___MSG, Seeds[0], Seeds[1]);
|
---|
176 |
|
---|
177 | } /* end of ParmsSwitch */
|
---|