source: trunk/MagicSoft/Simulation/Detector/ReflectorII/init.c@ 801

Last change on this file since 801 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: 3.9 KB
Line 
1#include <stdio.h>
2#include <string.h>
3#include <stdlib.h>
4#include <math.h>
5#include "version.h"
6#include "diag.h"
7#include "init.h"
8
9/* extern declarations */
10FILE *filelist = NULL, /* filelist ptr */
11 *rflname = NULL; /* reflector (out)file */
12char cername[LINE_MAX_LENGTH]; /* current cername */
13long first_Event = 0, /* first proc. event */
14 last_Event = 1000000, /* last proc. event */
15 max_Events = 50000; /* max proc. events */
16float low_Ecut = 0.0f, /* lower Ecut (GeV) */
17 high_Ecut = 100000.0f; /* upper Ecut (GeV) */
18
19int is_Fixed_Target = FALSE; /* fixed target? */
20float fixed_Theta, /* zenith angle (rad) */
21 fixed_Phi; /* azi (0N->90E) (rad) */
22
23int is_Random_Pointing=FALSE; /* random pointing? */
24float Random_Pointing_MaxDist; /* in metres */
25int nRepeat_Random = 1; /* nr of times a sh. is reused */
26
27long Seeds[2] = {3141592L, 2718182L};
28
29/* Other declarations */
30char whites[] = " \v\t\n\r"; /* White chars def */
31char line[LINE_MAX_LENGTH]; /* parsing buffer */
32
33/* Prototypes */
34static void CheckSignature(char *line);
35int ParseLine(FILE *parfile, /* FILE with parms */
36 const char *token_list[], /* array w/tokens */
37 int tokens, /* nr of tokens */
38 char **value_ptr); /* ptr to parm val. */
39
40/* Checks signature.
41 * It separates tokens and compare the first
42 * token with PROGRAM and the second with VERSION.
43 * Both values are stored in "version.h".
44 * Return value is set to true if check fails. */
45
46static void CheckSignature(char *line)
47{ char *cp; /* To parse signature */
48
49 if ((cp=strtok(line, whites)) == NULL || strcmp(cp, QUOTE(PROGRAM)) ||
50 (cp=strtok(NULL, whites)) == NULL || strcmp(cp, QUOTE(VERSION)))
51 FatalError(SIGN_ERROR_FTL, QUOTE(PROGRAM), QUOTE(VERSION));
52} /* end of CheckSignature */
53
54int ParseLine(FILE *parfile, /* FILE with parms */
55 const char *token_list[], /* array w/tokens */
56 int tokens, /* nr of tokens */
57 char **value_ptr) /* ptr to parm val. */
58{ int item = tokens;
59 char *cp;
60
61 do
62 { if (fgets(line, LINE_MAX_LENGTH, parfile) == NULL)
63 break;
64 else if (line[0] == '#'); /* skip comments (start with '#') */
65 else if (line[0] == '>') /* show user comments (start with '>') */
66 { if ((cp=strchr(line, '\n')) != NULL) *cp = 0;
67 puts(line); }
68 else if ((cp = strtok(line, whites)) != NULL)
69 { /* check which param it is */
70 for (item=0; item<tokens; item++)
71 if (strcmp(cp, token_list[item])==0)
72 break;
73 if (item < tokens)
74 *value_ptr = strtok(NULL, whites);
75 else Message(SKIP_TOKEN_MSG, cp); }}
76 while (item >= tokens);
77
78 return item;
79} /* end of ParseLine */
80
81FILE *geofile = NULL; /* geometry file */
82
83void init(char *filename)
84{ FILE *parfile = NULL; /* parms file */
85 extern void ParmsSwitch(FILE *parfile); /* std parsing fn */
86 extern void GeometrySwitch(FILE *geofile); /* geometry parsing fn */
87
88 /* Open file or read from stdin */
89 if (filename) parfile = fopen("filename", "r");
90 if (parfile == NULL) parfile = stdin;
91 fgets(line, LINE_MAX_LENGTH, parfile);
92
93 /* Check signature */
94 CheckSignature(line);
95
96 ParmsSwitch(parfile);
97 if (geofile) GeometrySwitch(geofile);
98 else FatalError(GEOM_NSPEC_FTL);
99
100 /* Alloc memory for CPhotons */
101 if ((CPhotons =
102 (cphoton *) malloc(NR_OF_CPHOTONS * sizeof(cphoton))) == NULL)
103 FatalError(CPHS_ALLOC_FTL, NR_OF_CPHOTONS);
104 else Log(CPHS_ALLOC_LOG, NR_OF_CPHOTONS);
105
106 /* Write signature and START_OF_RUN at the beginning of rflfile */
107 /* '\0' for backward compatibility */
108 fseek(rflfile, 0L, SEEK_SET);
109 fprintf(rflfile, "%s %s", QUOTE(PROGRAM), QUOTE(VERSION));
110 fputc(0, rflfile);
111 fwrite(FLAG_START_OF_RUN, SIZE_OF_FLAGS, 1, rflfile);
112
113 /* "Splashscreen" */
114 Message(RFL__START_MSG, QUOTE(PROGRAM), QUOTE(VERSION));
115} /* end of init */
Note: See TracBrowser for help on using the repository browser.