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