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

Last change on this file was 1722, checked in by moralejo, 22 years ago
*** empty log message ***
File size: 4.0 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
23float Telescope_x = 0.;
24float Telescope_y = 0.; /* Telescope coordinates (cm) */
25
26int wobble_position = 0;
27
28int is_Random_Pointing=FALSE; /* random pointing? */
29float Random_Pointing_MaxDist; /* in metres */
30int nRepeat_Random = 1; /* nr of times a sh. is reused */
31
32long Seeds[2] = {3141592L, 2718182L};
33
34/* Other declarations */
35char whites[] = " \v\t\n\r"; /* White chars def */
36char line[LINE_MAX_LENGTH]; /* parsing buffer */
37
38/* Prototypes */
39static void CheckSignature(char *line);
40int ParseLine(FILE *parfile, /* FILE with parms */
41 const char *token_list[], /* array w/tokens */
42 int tokens, /* nr of tokens */
43 char **value_ptr); /* ptr to parm val. */
44
45/* Checks signature.
46 * It separates tokens and compare the first
47 * token with PROGRAM and the second with VERSION.
48 * Both values are stored in "version.h".
49 * Return value is set to true if check fails. */
50
51static void CheckSignature(char *line)
52{ char *cp; /* To parse signature */
53
54 if ((cp=strtok(line, whites)) == NULL || strcmp(cp, QUOTE(PROGRAM)) ||
55 (cp=strtok(NULL, whites)) == NULL || strcmp(cp, QUOTE(VERSION)))
56 FatalError(SIGN_ERROR_FTL, QUOTE(PROGRAM), QUOTE(VERSION));
57} /* end of CheckSignature */
58
59int ParseLine(FILE *parfile, /* FILE with parms */
60 const char *token_list[], /* array w/tokens */
61 int tokens, /* nr of tokens */
62 char **value_ptr) /* ptr to parm val. */
63{ int item = tokens;
64 char *cp;
65
66 do
67 { if (fgets(line, LINE_MAX_LENGTH, parfile) == NULL)
68 break;
69 else if (line[0] == '#'); /* skip comments (start with '#') */
70 else if (line[0] == '>') /* show user comments (start with '>') */
71 { if ((cp=strchr(line, '\n')) != NULL) *cp = 0;
72 puts(line); }
73 else if ((cp = strtok(line, whites)) != NULL)
74 { /* check which param it is */
75 for (item=0; item<tokens; item++)
76 if (strcmp(cp, token_list[item])==0)
77 break;
78 if (item < tokens)
79 *value_ptr = strtok(NULL, whites);
80 else Message(SKIP_TOKEN_MSG, cp); }}
81 while (item >= tokens);
82
83 return item;
84} /* end of ParseLine */
85
86FILE *geofile = NULL; /* geometry file */
87
88void init(char *filename)
89{ FILE *parfile = NULL; /* parms file */
90 extern void ParmsSwitch(FILE *parfile); /* std parsing fn */
91 extern void GeometrySwitch(FILE *geofile); /* geometry parsing fn */
92
93 /* Open file or read from stdin */
94 if (filename) parfile = fopen("filename", "r");
95 if (parfile == NULL) parfile = stdin;
96 fgets(line, LINE_MAX_LENGTH, parfile);
97
98 /* Check signature */
99 CheckSignature(line);
100
101 ParmsSwitch(parfile);
102 if (geofile) GeometrySwitch(geofile);
103 else FatalError(GEOM_NSPEC_FTL);
104
105 /* Alloc memory for CPhotons */
106 if ((CPhotons =
107 (cphoton *) malloc(NR_OF_CPHOTONS * sizeof(cphoton))) == NULL)
108 FatalError(CPHS_ALLOC_FTL, NR_OF_CPHOTONS);
109 else Log(CPHS_ALLOC_LOG, NR_OF_CPHOTONS);
110
111 /* Write signature and START_OF_RUN at the beginning of rflfile */
112 /* '\0' for backward compatibility */
113 fseek(rflfile, 0L, SEEK_SET);
114 fprintf(rflfile, "%s %s", QUOTE(PROGRAM), QUOTE(VERSION));
115
116 /* Removed by A.M. January 2003: */
117 /* fputc(0, rflfile); */
118
119 fwrite(FLAG_START_OF_RUN, SIZE_OF_FLAGS, 1, rflfile);
120
121 /* "Splashscreen" */
122 Message(RFL__START_MSG, QUOTE(PROGRAM), QUOTE(VERSION));
123} /* end of init */
Note: See TracBrowser for help on using the repository browser.