source: branches/start/MagicSoft/Simulation/Detector/Reflector/readparam.cxx@ 18752

Last change on this file since 18752 was 292, checked in by harald, 25 years ago
This is the startpoint for the futher development of the Reflector program of Jose Carlos. For all developments use this CVS-controlled directory.
File size: 20.5 KB
Line 
1//=//////////////////////////////////////////////////////////////////////
2//=
3//= readparam
4//=
5//= @file readparam.cxx
6//= @desc Reading of parameters file
7//= @author J C Gonzalez
8//= @email gonzalez@mppmu.mpg.de
9//= @date Thu May 7 16:24:22 1998
10//=
11//=----------------------------------------------------------------------
12//=
13//= Created: Thu May 7 16:24:22 1998
14//= Author: Jose Carlos Gonzalez
15//= Purpose: Program for reflector simulation
16//= Notes: See files README for details
17//=
18//=----------------------------------------------------------------------
19//=
20//= $RCSfile: readparam.cxx,v $
21//= $Revision: 1.1.1.1 $
22//= $Author: harald $
23//= $Date: 1999-10-29 07:00:33 $
24//=
25//=//////////////////////////////////////////////////////////////////////
26
27// @T \newpage
28
29//!@section Source code of |readparam.cxx|.
30
31/*!@"
32
33 This section describes briefly the source code for the file
34 |readparam.cxx|. All the defines it uses are located in the files
35 |readparam.h| and |atm.h|. In the first one we can see the
36 definitions of the commands available for the parameters file. We
37 will describe these commands later on. Please, note that this
38 program is still in development, and more commands will be added
39 soon.
40
41 @"*/
42
43//!@subsection Includes and Global variables definition.
44
45/*!@"
46
47 All the defines are located in the file |readparam.h|.
48
49 @"*/
50
51//!@{
52
53#include "readparam.h"
54
55//!@}
56
57//!@subsection Definition of global variables.
58
59/*!@"
60
61 Here we define the global variables where the values from the
62 parameters file are stored.
63
64 @"*/
65
66//!@{
67
68//@: list of paths to get data from
69static char **Paths_list;
70
71//@: number of paths
72static int Num_of_paths = 1;
73
74//@: output filename
75static char Output_filename[PATH_MAX_LENGTH];
76
77//@: name of the CT def. file
78static char CT_filename[PATH_MAX_LENGTH];
79
80//@: verbosity
81static VerboseLevel verbose = VERBOSE_DEFAULT;
82
83//@: fixed target zenith angle (theta)
84static float fixed_Theta;
85
86//@: fixed target zenith angle (theta)
87static float fixed_Phi;
88
89//@: lower limits for the energy of the showers to be used
90static float low_Ecut = 0.0;
91
92//@: lower limits for the energy of the showers to be used
93static float high_Ecut = 100000.0;
94
95//@: are we using fixed target?
96static int is_Fixed_Target = FALSE;
97
98//@: maximum number of events to read
99static int max_Events = 50000;
100
101//@: range of events to read
102static int first_Event=0, last_Event=1000000;
103
104//@: random seeds
105static long int Seeds[2] = {3141592L, 2718182L};
106
107//@: flag: blocking?
108static int Block=0;
109
110//@: flag: random pointing?
111static int Random_Pointing = FALSE;
112
113//@: flag: random pointing maximum distance
114static float Random_Pointing_MaxDist;
115
116//@: flag: do we read from STDIN?
117static int Data_From_STDIN = FALSE;
118
119//@: flag: do we write to STDOUT?
120static int Data_To_STDOUT = FALSE;
121
122//!@}
123
124/*!@"
125
126 Here we define the global variables where the parameters of a
127 parallel beam of light will be stored.
128
129 @"*/
130
131//!@{
132
133static int pb_ParallelBeam = FALSE;
134static int pb_ParallelBeamPM = FALSE;
135static float pb_Theta, pb_Phi, pb_X, pb_Y;
136static float pb_Height;
137static float pb_LengthX, pb_LengthY, pb_NX, pb_NY;
138static float pb_Scale;
139static char pb_Filename[40];
140
141//!@}
142
143//!@subsection The function |readparam()|.
144
145//!---------------------------------------------------------------------
146// @name creadparam
147//
148// @desc read parameters from the stdin / parameters file
149//
150// @var *filename Name of the parameters file (NULL->STDIN)
151//
152// @date Mon Sep 14 13:27:56 MET DST 1998
153//----------------------------------------------------------------------
154// @function
155
156//!@{
157void
158readparam(char * filename)
159{
160 char sign[] = GLUE_postp( PROGRAM, VERSION ); // initialize sign
161 char line[LINE_MAX_LENGTH]; // line to get from the stdin
162 char token[ITEM_MAX_LENGTH]; // a single token
163 char atm[ATM_NAME_MAX_LENGTH]; // name of the atm. model from stdin
164 int i, j; // dummy counters
165 ifstream ifile;
166
167 // use cin or ifile (reading from STDIN or from parameters file?
168 if ( filename != NULL )
169 ifile.open( filename );
170
171 // get signature
172 if ( filename != NULL )
173 ifile.getline(line, LINE_MAX_LENGTH);
174 else
175 cin.getline(line, LINE_MAX_LENGTH);
176 line[strlen(SIGNATURE)] = '\0';
177 strcpy(line, sign);
178 if (strcmp(sign, SIGNATURE) != 0) {
179 cerr << "ERROR: Signature of parameters file is not correct\n";
180 cerr << '"' << sign << '"' << '\n';
181 cerr << "should be: " << SIGNATURE << '\n';
182 exit(1);
183 }
184
185 // loop till the "end" directive is reached
186 int is_end = FALSE;
187 while (! is_end) {
188
189 // get line from file or stdin
190 if ( filename != NULL )
191 ifile.getline(line, LINE_MAX_LENGTH);
192 else
193 cin.getline(line, LINE_MAX_LENGTH);
194
195 // skip comments (start with '#')
196 if (line[0] == '#')
197 continue;
198
199 // show user comments (start with '>')
200 if (line[0] == '>') {
201 cout << line << endl << flush;
202 continue;
203 }
204
205 // look for each item at the beginning of the line
206 for (i=0; i<=end_file; i++)
207 if (strstr(line, ITEM_NAMES[i]) == line)
208 break;
209
210 // if it is not a valid line, just ignore it
211 if (i == end_file+1) {
212 cerr << "Skipping unknown token in [" << line << "]\n";
213 continue;
214 }
215
216 // case block for each directive
217 switch ( i ) {
218
219 case data_paths: // beginning of the list of valid paths
220
221 // get number of paths to read
222 sscanf(line, "%s %d", token, &Num_of_paths);
223
224 if ( verbose == TRUE )
225 cout << Num_of_paths << " path(s) will be used.\n";
226
227 // allocate memory for paths list
228 Paths_list = (char**)malloc(Num_of_paths * sizeof(char*));
229 for (i=0; i<Num_of_paths; i++)
230 Paths_list[i] = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
231
232 // read each single path
233 for (i=0; i<Num_of_paths; i++) {
234
235 if ( filename != NULL )
236 ifile.getline(Paths_list[i], PATH_MAX_LENGTH);
237 else
238 cin.getline(Paths_list[i], PATH_MAX_LENGTH);
239
240 // remove empty spaces at the end
241 for (j=0; j<strlen(Paths_list[i]); j++) {
242 if (Paths_list[i][j] == ' ') {
243 Paths_list[i][j] = '\0';
244 break;
245 }
246 }
247
248 // show the path
249 if ( verbose == TRUE )
250 cout << '[' << Paths_list[i] << ']' << '\n';
251 }
252
253 break;
254
255 case output_file: // name of the output file
256
257 // get the name of the output_file from the line
258 sscanf(line, "%s %s", token, Output_filename);
259
260 break;
261
262 case ct_file: // name of the telescope file
263
264 // get the name of the ct_file from the line
265 sscanf(line, "%s %s", token, CT_filename);
266
267 break;
268
269 case verbose_level: // verbose level 0-4
270
271 // get the verbose level
272 sscanf(line, "%s %d", token, &verbose);
273
274 break;
275
276 case atm_model: // name of the atmospheric model
277
278 // get the name of the atm_model from the line
279 sscanf(line, "%s %s", token, atm);
280 // set the name and the number of the model with the functions
281 // defined in atm.h
282 set_atm_mod( conv_atm_mod( atm ) );
283
284 break;
285
286 case fixed_target: // we use a fixed target
287
288 // get fixed target's coordinates (is degrees)
289 sscanf(line, "%s %f %f", token, &fixed_Theta, &fixed_Phi);
290
291 // convert them to radians
292 fixed_Theta *= DEG2RAD;
293 fixed_Phi *= DEG2RAD;
294 is_Fixed_Target = TRUE;
295
296 break;
297
298 case max_events: // maximum number of events
299
300 // get the number of events
301 sscanf(line, "%s %d", token, &max_Events);
302
303 break;
304
305 case range_events: // maximum number of events
306
307 // get the number of events
308 sscanf(line, "%s %d %d", token, &first_Event, &last_Event);
309 max_Events = 1000000;
310
311 break;
312
313 case energy_cuts: // range of energies allowed
314
315 // get the cuts
316 sscanf(line, "%s %f %f", token, &low_Ecut, &high_Ecut);
317
318 break;
319
320 case parallel_beam: // parallel beam of light
321
322 // get the parameters of the beam
323 sscanf(line, "%s %f %f %f %f %f %f %f %f %f", token,
324 &pb_Theta, &pb_Phi,
325 &pb_X, &pb_Y,
326 &pb_LengthX, &pb_LengthY,
327 &pb_NX, &pb_NY, &pb_Height );
328
329 pb_Theta = RAD(pb_Theta);
330 pb_Phi = RAD(pb_Phi);
331
332 pb_ParallelBeam = TRUE;
333 pb_ParallelBeamPM = FALSE;
334
335 Num_of_paths = 1;
336 strcpy( Paths_list[0], "." );
337
338 break;
339
340 case pm_parallel_beam: // parallel beam of light out of a pixmap
341
342 // get the parameters of the beam
343 sscanf(line, "%s %s %f %f", token,
344 pb_Filename, &pb_Scale, &pb_Height);
345
346 pb_ParallelBeam = TRUE;
347 pb_ParallelBeamPM = TRUE;
348
349 Num_of_paths = 1;
350 strcpy( Paths_list[0], "." );
351
352 break;
353
354 case seeds: // values of seeds for random numbers
355
356 // get seeds
357 sscanf(line, "%s %ld %ld", token, &Seeds[0], &Seeds[1]);
358
359 break;
360
361
362 case random_pointing: // uses a random CT pointing for each shower
363
364 // set flag
365 Random_Pointing = TRUE;
366 sscanf(line, "%s %f %ld %ld", token,
367 &Random_Pointing_MaxDist, &Seeds[0], &Seeds[1]);
368
369 cerr << "random_pointing: " << Random_Pointing_MaxDist << ' ';
370 Random_Pointing_MaxDist = RAD(Random_Pointing_MaxDist);
371 cerr << Random_Pointing_MaxDist << " radians \n";
372
373 break;
374
375
376 case block: // analyzes data in blocks
377
378 // get block value
379 sscanf(line, "%s %d", token, &Block);
380
381 break;
382
383 case data_from_stdin: // analyzes data in blocks
384
385 // set flag
386 Data_From_STDIN = TRUE;
387
388 // set other parameters
389 Num_of_paths = 1;
390 strcpy( Paths_list[0], TMP_STDIN_DIR );
391
392 break;
393
394 case data_to_stdout: // analyzes data in blocks
395
396 // set flag
397 Data_To_STDOUT = TRUE;
398
399 break;
400
401 case end_file: // end of the parameters file
402
403 // show a short message
404 is_end = TRUE;
405
406 break;
407
408 } // switch ( i )
409
410 } // while (! is_end)
411
412 if ( filename != NULL ) {
413 ifile.close();
414 }
415
416 // after the loop is finished, return to the main function
417 return;
418}
419//!@}
420
421
422//!---------------------------------------------------------------------
423// @name get_num_of_paths
424//
425// @desc get number of defined paths
426//
427// @date Sat Jun 27 05:58:56 MET DST 1998
428//----------------------------------------------------------------------
429// @function
430
431//!@{
432int
433get_num_of_paths(void)
434{
435 return (Num_of_paths);
436}
437//!@}
438
439
440//!---------------------------------------------------------------------
441// @name get_path_name
442//
443// @desc get path name number "i" from the list of paths
444//
445// @var i number of path name to return
446//
447// @return i-th path name
448//
449// @date Sat Jun 27 05:58:56 MET DST 1998
450//----------------------------------------------------------------------
451// @function
452
453//!@{
454char *
455get_path_name(int i)
456{
457 return (Paths_list[i]);
458}
459//!@}
460
461
462//!---------------------------------------------------------------------
463// @name get_output_filename
464//
465// @desc get name of the output file
466//
467// @return output file name
468//
469// @date Sat Jun 27 05:58:56 MET DST 1998
470//----------------------------------------------------------------------
471// @function
472
473//!@{
474char *
475get_output_filename(void)
476{
477 return (Output_filename);
478}
479//!@}
480
481
482//!---------------------------------------------------------------------
483// @name get_ct_filename
484//
485// @desc get name of CT definition file
486//
487// @return CT definition file name
488//
489// @date Sat Jun 27 05:58:56 MET DST 1998
490//----------------------------------------------------------------------
491// @function
492
493//!@{
494char *
495get_ct_filename(void)
496{
497 return (CT_filename);
498}
499//!@}
500
501
502//!---------------------------------------------------------------------
503// @name get_verbose
504//
505// @desc get the "verbose" status
506//
507// @return Verbosity level
508//
509// @date Sat Jun 27 05:58:56 MET DST 1998
510//
511//----------------------------------------------------------------------
512// @function
513
514//!@{
515int
516get_verbose(void)
517{
518 return (verbose);
519}
520//!@}
521
522
523//!---------------------------------------------------------------------
524// @name get_fixed_target
525//
526// @desc get fixed target's coordinates
527//
528// @var *theta returned fixed theta
529// @var *phi returned fixed phi
530//
531// @return TRUE if fixed target is selected; FALSE othw.
532//
533// @date Sat Jun 27 05:58:56 MET DST 1998
534//----------------------------------------------------------------------
535// @function
536
537//!@{
538int
539get_fixed_target(float *theta, float *phi)
540{
541 if ( is_Fixed_Target == FALSE )
542 return (FALSE);
543 *theta = fixed_Theta;
544 *phi = fixed_Phi;
545 return(TRUE);
546}
547//!@}
548
549
550//!---------------------------------------------------------------------
551// @name get_max_events
552//
553// @desc get max events number
554//
555// @return Maximum number of events to read
556//
557// @date Sat Jun 27 05:58:56 MET DST 1998
558//----------------------------------------------------------------------
559// @function
560
561//!@{
562int
563get_max_events(void)
564{
565 return( max_Events );
566}
567//!@}
568
569
570//!---------------------------------------------------------------------
571// @name get_range_events
572//
573// @desc get range of events
574//
575// @var *a returned first event number to read
576// @var *b returned last event number to read
577//
578// @date Sat Jun 27 05:58:56 MET DST 1998
579//----------------------------------------------------------------------
580// @function
581
582//!@{
583void
584get_range_events(int *a, int *b)
585{
586 *a = first_Event;
587 *b = last_Event;
588}
589//!@}
590
591
592//!---------------------------------------------------------------------
593// @name get_energy_cuts
594//
595// @desc get energy cuts (lowest/highest energy allowed)
596//
597// @var *low returned lower edge of energy range
598// @var *high returned lower edge of energy range
599//
600// @date Sat Jun 27 05:58:56 MET DST 1998
601//----------------------------------------------------------------------
602// @function
603
604//!@{
605void
606get_energy_cuts(float *low, float *high)
607{
608 *low = low_Ecut;
609 *high = high_Ecut;
610}
611//!@}
612
613
614//!---------------------------------------------------------------------
615// @name get_parallel_beam
616//
617// @desc get parallel beam parameters
618//
619// @var *pb_theta returned zenith angle of the parallel beam
620// @var *pb_phi returned aximuth angle of the parallel beam
621// @var *pb_x returned x coordinate of the center
622// @var *pb_y returned y coordinate of the center
623// @var *pb_lengthx returned length of the square in the ground
624// @var *pb_lengthy returned width of the square in the ground
625// @var *pb_nx returned number of rows to generate
626// @var *pb_ny returned number of columns to generate
627// @var *pb_height returned height of the point-like source
628//
629// @date Sat Jun 27 05:58:56 MET DST 1998
630//----------------------------------------------------------------------
631// @function
632
633//!@{
634void
635get_parallel_beam(float *pb_theta, float *pb_phi,
636 float *pb_x, float *pb_y,
637 float *pb_lengthx, float *pb_lengthy,
638 float *pb_nx, float *pb_ny, float *pb_height)
639{
640
641 *pb_theta = pb_Theta;
642 *pb_phi = pb_Phi;
643 *pb_x = pb_X;
644 *pb_y = pb_Y;
645 *pb_lengthx = pb_LengthX;
646 *pb_lengthy = pb_LengthY;
647 *pb_nx = pb_NX;
648 *pb_ny = pb_NY;
649 *pb_height = pb_Height;
650
651 return;
652}
653//!@}
654
655
656//!---------------------------------------------------------------------
657// @name is_parallel_beam
658//
659// @desc should I use a parallel beam of light
660//
661// @return TRUE: we are generating a parallel beam of light
662//
663// @date Sat Jun 27 05:58:56 MET DST 1998
664//----------------------------------------------------------------------
665// @function
666
667//!@{
668int
669is_parallel_beam(void)
670{
671 return( pb_ParallelBeam );
672}
673//!@}
674
675
676//!---------------------------------------------------------------------
677// @name get_parallel_beam_pm
678//
679// @desc get parallel beam PM parameters
680//
681// @var *pb_scale returned scale to be applied to the pixmap
682// @var *pb_height returned height were the pixmap is located
683//
684// @return filename of the pixmap
685//
686// @date Sat Jun 27 05:58:56 MET DST 1998
687//----------------------------------------------------------------------
688// @function
689
690//!@{
691char *
692get_parallel_beam_pm(float *pb_scale, float *pb_height)
693{
694 *pb_scale = pb_Scale;
695
696 return(pb_Filename);
697}
698//!@}
699
700
701//!---------------------------------------------------------------------
702// @name is_parallel_beam_pm
703//
704// @desc should I use a parallel beam of light(from pixmap)
705//
706// @return TRUE: we are generating a parallel beam of light from a pixmap
707//
708// @date Sat Jun 27 05:58:56 MET DST 1998
709//----------------------------------------------------------------------
710// @function
711
712//!@{
713int
714is_parallel_beam_pm(void)
715{
716 return( pb_ParallelBeamPM );
717}
718
719
720//!---------------------------------------------------------------------
721// @name get_seeds
722//
723// @desc are we going to count the islands ?
724//
725// @var n number of seed to get
726//
727// @return n-th random seed
728//
729// @date Mon Sep 14 13:27:56 MET DST 1998
730//----------------------------------------------------------------------
731// @function
732
733//!@{
734long int
735get_seeds(int n)
736{
737 return ( Seeds[n] );
738}
739//!@}
740
741
742//!---------------------------------------------------------------------
743// @name get_block
744//
745// @desc get the block size (=0 -> no blocking)
746//
747// @return Block value
748//
749// @date Wed Nov 25 13:21:00 MET 1998
750//----------------------------------------------------------------------
751// @function
752
753//!@{
754int
755get_block(void)
756{
757 return ( Block );
758}
759//!@}
760
761
762//!---------------------------------------------------------------------
763// @name get_data_from_stdin
764//
765// @desc get whether we will read the data from the STDIN
766//
767// @return TRUE: we get data from STDIN; FALSE: oth.
768//
769// @date Wed Nov 25 13:21:00 MET 1998
770//----------------------------------------------------------------------
771// @function
772
773//!@{
774int
775get_data_from_stdin(void)
776{
777 return ( Data_From_STDIN );
778}
779//!@}
780
781
782//!---------------------------------------------------------------------
783// @name get_data_to_stdout
784//
785// @desc get whether we will write the output data to the STDOUT
786//
787// @return TRUE: we put data into the STDOUT; FALSE: oth.
788//
789// @date Wed Nov 25 13:21:00 MET 1998
790//----------------------------------------------------------------------
791// @function
792
793//!@{
794int
795get_data_to_stdout(void)
796{
797 return ( Data_To_STDOUT );
798}
799//!@}
800
801
802//!---------------------------------------------------------------------
803// @name get_random_pointing
804//
805// @desc get whether random pointing is selected
806//
807// @return TRUE: we use a random pointing
808//
809// @date Wed Nov 25 13:21:00 MET 1998
810//----------------------------------------------------------------------
811// @function
812
813//!@{
814int
815get_random_pointing(float *maxdist)
816{
817 *maxdist = Random_Pointing_MaxDist;
818 return ( Random_Pointing );
819}
820//!@}
821
822
823//=------------------------------------------------------------
824//!@subsection Log of this file.
825
826//!@{
827//
828// $Log: not supported by cvs2svn $
829// Revision 1.13 1999/10/05 11:06:38 gonzalez
830// Sep. 1999
831//
832// Revision 1.12 1999/03/24 16:33:00 gonzalez
833// REFLECTOR 1.1: Release
834//
835// Revision 1.11 1999/01/21 16:03:37 gonzalez
836// Only small modifications
837//
838// Revision 1.10 1999/01/19 18:07:18 gonzalez
839// Bugs in STDIN-STDOUT version corrected.
840//
841// Revision 1.9 1999/01/14 17:35:46 gonzalez
842// Both reading from STDIN (data_from_stdin) and
843// writing to STDOUT (data_to_STDOUT) working.
844//
845// Revision 1.8 1999/01/13 12:41:11 gonzalez
846// THIS IS A WORKING (last?) VERSION
847//
848// Revision 1.7 1998/12/15 10:47:24 gonzalez
849// RELEASE-1.0
850//
851//!@}
852
853//=EOF
Note: See TracBrowser for help on using the repository browser.