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

Last change on this file since 1602 was 1535, checked in by bigongia, 22 years ago
Version 0.6. Changed output format: added run header, changed event header, added ascii parameter files attached at the end of every output file to keep all info.
File size: 4.7 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 case energy_cuts:
131 low_Ecut = (float) atof(value_ptr);
132 value_ptr = strtok(NULL, whites);
133 if (value_ptr == NULL)
134 { Error(ENRG_LIMIT_ERR);
135 low_Ecut = 0.; }
136 else
137 { high_Ecut = (float) atof(value_ptr);
138 Message(ENRG_CUTS__MSG, low_Ecut, high_Ecut); }
139 break;
140 case seeds:
141 Seeds[0] = atol(value_ptr);
142 value_ptr = strtok(NULL, whites);
143 if (value_ptr) Seeds[1] = atol(value_ptr);
144 else
145 { Error(SEED_ERROR_ERR);
146 Seeds[0] = 3141592L; }
147 break;
148 case cer_files:
149 ReadCerfiles(parfile);
150 switch_end = TRUE;
151 default: switch_end = TRUE;
152 break; }}
153 while (!switch_end);
154
155 if (filelist == NULL)
156 FatalError(FLST_NSPEC_FTL);
157
158 /* Set random seeds */
159 setall(Seeds[0], Seeds[1]);
160 Message(SEED_SET___MSG, Seeds[0], Seeds[1]);
161
162 } /* end of ParmsSwitch */
Note: See TracBrowser for help on using the repository browser.