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

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