//=////////////////////////////////////////////////////////////////////// //= //= readparam //= //= @file readparam.cxx //= @desc Reading of parameters file //= @author J C Gonzalez //= @email gonzalez@mppmu.mpg.de //= @date Thu May 7 16:24:22 1998 //= //=---------------------------------------------------------------------- //= //= Created: Thu May 7 16:24:22 1998 //= Author: Jose Carlos Gonzalez //= Purpose: Program for reflector simulation //= Notes: See files README for details //= //=---------------------------------------------------------------------- //= //= $RCSfile: readparam.cxx,v $ //= $Revision: 1.1.1.1 $ //= $Author: harald $ //= $Date: 1999-10-29 07:00:33 $ //= //=////////////////////////////////////////////////////////////////////// // @T \newpage //!@section Source code of |readparam.cxx|. /*!@" This section describes briefly the source code for the file |readparam.cxx|. All the defines it uses are located in the files |readparam.h| and |atm.h|. In the first one we can see the definitions of the commands available for the parameters file. We will describe these commands later on. Please, note that this program is still in development, and more commands will be added soon. @"*/ //!@subsection Includes and Global variables definition. /*!@" All the defines are located in the file |readparam.h|. @"*/ //!@{ #include "readparam.h" //!@} //!@subsection Definition of global variables. /*!@" Here we define the global variables where the values from the parameters file are stored. @"*/ //!@{ //@: list of paths to get data from static char **Paths_list; //@: number of paths static int Num_of_paths = 1; //@: output filename static char Output_filename[PATH_MAX_LENGTH]; //@: name of the CT def. file static char CT_filename[PATH_MAX_LENGTH]; //@: verbosity static VerboseLevel verbose = VERBOSE_DEFAULT; //@: fixed target zenith angle (theta) static float fixed_Theta; //@: fixed target zenith angle (theta) static float fixed_Phi; //@: lower limits for the energy of the showers to be used static float low_Ecut = 0.0; //@: lower limits for the energy of the showers to be used static float high_Ecut = 100000.0; //@: are we using fixed target? static int is_Fixed_Target = FALSE; //@: maximum number of events to read static int max_Events = 50000; //@: range of events to read static int first_Event=0, last_Event=1000000; //@: random seeds static long int Seeds[2] = {3141592L, 2718182L}; //@: flag: blocking? static int Block=0; //@: flag: random pointing? static int Random_Pointing = FALSE; //@: flag: random pointing maximum distance static float Random_Pointing_MaxDist; //@: flag: do we read from STDIN? static int Data_From_STDIN = FALSE; //@: flag: do we write to STDOUT? static int Data_To_STDOUT = FALSE; //!@} /*!@" Here we define the global variables where the parameters of a parallel beam of light will be stored. @"*/ //!@{ static int pb_ParallelBeam = FALSE; static int pb_ParallelBeamPM = FALSE; static float pb_Theta, pb_Phi, pb_X, pb_Y; static float pb_Height; static float pb_LengthX, pb_LengthY, pb_NX, pb_NY; static float pb_Scale; static char pb_Filename[40]; //!@} //!@subsection The function |readparam()|. //!--------------------------------------------------------------------- // @name creadparam // // @desc read parameters from the stdin / parameters file // // @var *filename Name of the parameters file (NULL->STDIN) // // @date Mon Sep 14 13:27:56 MET DST 1998 //---------------------------------------------------------------------- // @function //!@{ void readparam(char * filename) { char sign[] = GLUE_postp( PROGRAM, VERSION ); // initialize sign char line[LINE_MAX_LENGTH]; // line to get from the stdin char token[ITEM_MAX_LENGTH]; // a single token char atm[ATM_NAME_MAX_LENGTH]; // name of the atm. model from stdin int i, j; // dummy counters ifstream ifile; // use cin or ifile (reading from STDIN or from parameters file? if ( filename != NULL ) ifile.open( filename ); // get signature if ( filename != NULL ) ifile.getline(line, LINE_MAX_LENGTH); else cin.getline(line, LINE_MAX_LENGTH); line[strlen(SIGNATURE)] = '\0'; strcpy(line, sign); if (strcmp(sign, SIGNATURE) != 0) { cerr << "ERROR: Signature of parameters file is not correct\n"; cerr << '"' << sign << '"' << '\n'; cerr << "should be: " << SIGNATURE << '\n'; exit(1); } // loop till the "end" directive is reached int is_end = FALSE; while (! is_end) { // get line from file or stdin if ( filename != NULL ) ifile.getline(line, LINE_MAX_LENGTH); else cin.getline(line, LINE_MAX_LENGTH); // skip comments (start with '#') if (line[0] == '#') continue; // show user comments (start with '>') if (line[0] == '>') { cout << line << endl << flush; continue; } // look for each item at the beginning of the line for (i=0; i<=end_file; i++) if (strstr(line, ITEM_NAMES[i]) == line) break; // if it is not a valid line, just ignore it if (i == end_file+1) { cerr << "Skipping unknown token in [" << line << "]\n"; continue; } // case block for each directive switch ( i ) { case data_paths: // beginning of the list of valid paths // get number of paths to read sscanf(line, "%s %d", token, &Num_of_paths); if ( verbose == TRUE ) cout << Num_of_paths << " path(s) will be used.\n"; // allocate memory for paths list Paths_list = (char**)malloc(Num_of_paths * sizeof(char*)); for (i=0; i no blocking) // // @return Block value // // @date Wed Nov 25 13:21:00 MET 1998 //---------------------------------------------------------------------- // @function //!@{ int get_block(void) { return ( Block ); } //!@} //!--------------------------------------------------------------------- // @name get_data_from_stdin // // @desc get whether we will read the data from the STDIN // // @return TRUE: we get data from STDIN; FALSE: oth. // // @date Wed Nov 25 13:21:00 MET 1998 //---------------------------------------------------------------------- // @function //!@{ int get_data_from_stdin(void) { return ( Data_From_STDIN ); } //!@} //!--------------------------------------------------------------------- // @name get_data_to_stdout // // @desc get whether we will write the output data to the STDOUT // // @return TRUE: we put data into the STDOUT; FALSE: oth. // // @date Wed Nov 25 13:21:00 MET 1998 //---------------------------------------------------------------------- // @function //!@{ int get_data_to_stdout(void) { return ( Data_To_STDOUT ); } //!@} //!--------------------------------------------------------------------- // @name get_random_pointing // // @desc get whether random pointing is selected // // @return TRUE: we use a random pointing // // @date Wed Nov 25 13:21:00 MET 1998 //---------------------------------------------------------------------- // @function //!@{ int get_random_pointing(float *maxdist) { *maxdist = Random_Pointing_MaxDist; return ( Random_Pointing ); } //!@} //=------------------------------------------------------------ //!@subsection Log of this file. //!@{ // // $Log: not supported by cvs2svn $ // Revision 1.13 1999/10/05 11:06:38 gonzalez // Sep. 1999 // // Revision 1.12 1999/03/24 16:33:00 gonzalez // REFLECTOR 1.1: Release // // Revision 1.11 1999/01/21 16:03:37 gonzalez // Only small modifications // // Revision 1.10 1999/01/19 18:07:18 gonzalez // Bugs in STDIN-STDOUT version corrected. // // Revision 1.9 1999/01/14 17:35:46 gonzalez // Both reading from STDIN (data_from_stdin) and // writing to STDOUT (data_to_STDOUT) working. // // Revision 1.8 1999/01/13 12:41:11 gonzalez // THIS IS A WORKING (last?) VERSION // // Revision 1.7 1998/12/15 10:47:24 gonzalez // RELEASE-1.0 // //!@} //=EOF