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

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