source: trunk/MagicSoft/Simulation/Detector/ReflectorII/parms.c@ 1679

Last change on this file since 1679 was 1614, checked in by bigongia, 22 years ago
*** empty log message ***
File size: 5.0 KB
Line 
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
9extern char whites[]; /* white chars (init) */
10extern char line[]; /* parsing buf. (init) */
11
12char axisdev_filename[256], reflectivity_filename[256];
13char geo_filename[256];
14
15/* Prototypes */
16extern void setall(long iseed1,long iseed2); /* rnds */
17static void ReadCerfiles(FILE *parfile);
18
19static void ReadCerfiles(FILE *parfile)
20{ char *value_ptr = NULL; /* ptr at parm value */
21 extern FILE *GetNextFile(char *cername); /* in main.c */
22
23 filelist = parfile;
24 parfile = NULL;
25 if (fgets(line, LINE_MAX_LENGTH, filelist) == NULL ||
26 (value_ptr=strtok(line, whites)) == NULL)
27 FatalError(FLST_NSPEC_FTL);
28 else if (value_ptr[0] == '@')
29 { fclose(filelist);
30 if ((filelist=fopen(value_ptr+1, "r")) == NULL)
31 FatalError(FLST_NFND__FTL, value_ptr+1);
32 else if (fgets(line, LINE_MAX_LENGTH, filelist) == NULL)
33 FatalError(FLST_NSPEC_FTL);
34 value_ptr = strtok(line, whites); }
35
36 /* Set cername and find out event number bounds */
37 strcpy(cername, value_ptr);
38 if ((value_ptr=strtok(NULL, whites)) == NULL)
39 { first_Event = 0;
40 last_Event = 1000000; }
41 else
42 { first_Event = atol(value_ptr);
43 value_ptr = strtok(NULL, whites);
44 last_Event = value_ptr ? atol(value_ptr) : 1000000; }
45
46 /* Try to open cerfile. */
47
48 if ((cerfile=fopen(cername, "r")) == NULL)
49 { Message(CERF_NFND__MSG, cername);
50 cerfile=GetNextFile(cername); }
51
52 /* If no valid cerfile is found then exit */
53 if (cerfile == NULL)
54 FatalError(CERF_NSPEC_FTL);
55
56 /* Check boundaries */
57 if (first_Event > last_Event)
58 { Error(EVTN_WRONG_ERR, first_Event, last_Event, cername);
59 first_Event = 0;
60 last_Event = 1000000; }
61
62 } /* end of ReadCerfiles */
63
64void ParmsSwitch(FILE *parfile)
65{ char *value_ptr = NULL; /* ptr at parm value */
66 int switch_end = FALSE; /* bool to exit loop */
67 extern FILE *geofile; /* geo file (init) */
68 extern void SetVerbose(int vlevel); /* from diag.c */
69 extern void SetAtmModel(char *model); /* from atm.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 SetAtmModel(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 */
Note: See TracBrowser for help on using the repository browser.