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

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