source: trunk/MagicSoft/Simulation/Detector/Reflector/readparam.cxx@ 9223

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