| 1 | //=//////////////////////////////////////////////////////////////////////
|
|---|
| 2 | //=
|
|---|
| 3 | //= srreadparam
|
|---|
| 4 | //=
|
|---|
| 5 | //= @file srreadparam.cxx
|
|---|
| 6 | //= @desc Reading of parameters file
|
|---|
| 7 | //= @author O Blanch Bigas
|
|---|
| 8 | //= @email blanch@ifae.es
|
|---|
| 9 | //= @date Wed Feb 21 17:43:07 CET 2001
|
|---|
| 10 | //=
|
|---|
| 11 | //=----------------------------------------------------------------------
|
|---|
| 12 | //=
|
|---|
| 13 | //= Created: Wed Feb 21 17:43:07 CET 2001
|
|---|
| 14 | //= Author: Oscar Blanch Bigas
|
|---|
| 15 | //= Purpose: Program for star response simulation
|
|---|
| 16 | //= Notes: See files README for details
|
|---|
| 17 | //=
|
|---|
| 18 | //=----------------------------------------------------------------------
|
|---|
| 19 | //=
|
|---|
| 20 | //= $RCSfile: srreadparam.cxx,v $
|
|---|
| 21 | //= $Revision: 1.1 $
|
|---|
| 22 | //= $Author: magicsol $
|
|---|
| 23 | //= $Date: 2001-02-23 10:13:44 $
|
|---|
| 24 | //=
|
|---|
| 25 | //=//////////////////////////////////////////////////////////////////////
|
|---|
| 26 |
|
|---|
| 27 | // @T \newpage
|
|---|
| 28 |
|
|---|
| 29 | //!@section Source code of |srreadparam.cxx|.
|
|---|
| 30 |
|
|---|
| 31 | /*!@"
|
|---|
| 32 |
|
|---|
| 33 | This section describes briefly the source code for the file
|
|---|
| 34 | |srreadparam.cxx|. This file is very closely related to the file
|
|---|
| 35 | |readparams.cxx| from the |reflector| program. Actually, this later
|
|---|
| 36 | file was the ancestror of the file you are looking at.
|
|---|
| 37 |
|
|---|
| 38 | All the defines it uses are located in the file |srreadparam.h|. In
|
|---|
| 39 | the first one we can see the definitions of the commands available
|
|---|
| 40 | for the parameters file. We describe these commands in a later
|
|---|
| 41 | section.
|
|---|
| 42 |
|
|---|
| 43 | @"*/
|
|---|
| 44 |
|
|---|
| 45 | //!@subsection Includes and Global variables definition.
|
|---|
| 46 |
|
|---|
| 47 | /*!@"
|
|---|
| 48 |
|
|---|
| 49 | All the defines are located in the file {\tt srreadparam.h}.
|
|---|
| 50 |
|
|---|
| 51 | @"*/
|
|---|
| 52 |
|
|---|
| 53 | //!@{
|
|---|
| 54 |
|
|---|
| 55 | #include "srreadparam.h"
|
|---|
| 56 |
|
|---|
| 57 | //!@}
|
|---|
| 58 |
|
|---|
| 59 | //!@subsection Definition of global variables.
|
|---|
| 60 |
|
|---|
| 61 | /*!@"
|
|---|
| 62 |
|
|---|
| 63 | Here we define the global variables where the values from the
|
|---|
| 64 | parameters file are stored.
|
|---|
| 65 |
|
|---|
| 66 | @"*/
|
|---|
| 67 |
|
|---|
| 68 | //!@{
|
|---|
| 69 |
|
|---|
| 70 | static char Database_path[PATH_MAX_LENGTH]; //@< path to store the database
|
|---|
| 71 | static float Simulated_Phe_l = 0.0; //@< lower limit for phe loop
|
|---|
| 72 | static float Simulated_Phe_u = 50.0; //@< higher limit for phe loop
|
|---|
| 73 | static float Simulated_Phe_p = 0.1; //@< precision for phe loop
|
|---|
| 74 | //!@}
|
|---|
| 75 |
|
|---|
| 76 | //!@subsection The function |readparam()|.
|
|---|
| 77 |
|
|---|
| 78 | //!-----------------------------------------------------------
|
|---|
| 79 | // @name srreadparam
|
|---|
| 80 | //
|
|---|
| 81 | // @desc read parameters from the stdin / parameters file
|
|---|
| 82 | //
|
|---|
| 83 | // @var *filename Name of the parameters file (NULL->STDIN)
|
|---|
| 84 | //
|
|---|
| 85 | // @date Wed Feb 21 17:43:07 CET 2001
|
|---|
| 86 | //------------------------------------------------------------
|
|---|
| 87 | // @function
|
|---|
| 88 |
|
|---|
| 89 | //!@{
|
|---|
| 90 | void
|
|---|
| 91 | readparam(char * filename)
|
|---|
| 92 | {
|
|---|
| 93 | char line[LINE_MAX_LENGTH]; //@< line to get from the stdin
|
|---|
| 94 | char token[ITEM_MAX_LENGTH]; //@< a single token
|
|---|
| 95 | int i; //@< dummy counters
|
|---|
| 96 | ifstream ifile;
|
|---|
| 97 |
|
|---|
| 98 | ifile.open( filename );
|
|---|
| 99 |
|
|---|
| 100 | // loop till the "end" directive is reached
|
|---|
| 101 | int is_end = FALSE;
|
|---|
| 102 | while (! is_end) {
|
|---|
| 103 |
|
|---|
| 104 | // get line from file or stdin
|
|---|
| 105 | if ( filename != NULL )
|
|---|
| 106 | ifile.getline(line, LINE_MAX_LENGTH);
|
|---|
| 107 | else
|
|---|
| 108 | cin.getline(line, LINE_MAX_LENGTH);
|
|---|
| 109 |
|
|---|
| 110 | // skip comments (start with '#')
|
|---|
| 111 | if (line[0] == '#')
|
|---|
| 112 | continue;
|
|---|
| 113 |
|
|---|
| 114 | // show user comments (start with '>')
|
|---|
| 115 | if (line[0] == '>') {
|
|---|
| 116 | cout << line << endl << flush;
|
|---|
| 117 | continue;
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | // look for each item at the beginning of the line
|
|---|
| 121 | for (i=0; i<=end_file; i++)
|
|---|
| 122 | if (strstr(line, ITEM_NAMES[i]) == line)
|
|---|
| 123 | break;
|
|---|
| 124 |
|
|---|
| 125 | // if it is not a valid line, just ignore it
|
|---|
| 126 | if (i == end_file+1) {
|
|---|
| 127 | cerr << "Skipping unknown token in [" << line << "]\n";
|
|---|
| 128 | continue;
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | // case block for each directive
|
|---|
| 132 | switch ( i ) {
|
|---|
| 133 |
|
|---|
| 134 | case database_path: //@< name of the output path
|
|---|
| 135 |
|
|---|
| 136 | // get the path for the outcoming database
|
|---|
| 137 | sscanf(line, "%s %s", token, Database_path);
|
|---|
| 138 |
|
|---|
| 139 | break;
|
|---|
| 140 |
|
|---|
| 141 | case simulated_phe: //@< limits for the phe loop
|
|---|
| 142 |
|
|---|
| 143 | // get energy range
|
|---|
| 144 | sscanf(line, "%s %f %f %f", token, &Simulated_Phe_l, &Simulated_Phe_u,
|
|---|
| 145 | &Simulated_Phe_p);
|
|---|
| 146 |
|
|---|
| 147 | break;
|
|---|
| 148 |
|
|---|
| 149 | case end_file: //@< end of the parameters file
|
|---|
| 150 |
|
|---|
| 151 | // show a short message
|
|---|
| 152 | is_end = TRUE;
|
|---|
| 153 |
|
|---|
| 154 | break;
|
|---|
| 155 |
|
|---|
| 156 | } // switch ( i )
|
|---|
| 157 |
|
|---|
| 158 | } // while (! is_end)
|
|---|
| 159 |
|
|---|
| 160 | // after the loop is finished, return to the main function
|
|---|
| 161 | return;
|
|---|
| 162 | }
|
|---|
| 163 | //!@}
|
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 | //!-----------------------------------------------------------
|
|---|
| 167 | // @name get_database_path
|
|---|
| 168 | //
|
|---|
| 169 | // @desc get name of the ouput path
|
|---|
| 170 | //
|
|---|
| 171 | // @return Name of the output path
|
|---|
| 172 | //
|
|---|
| 173 | // @date Wed Feb 21 17:57:19 CET 2001
|
|---|
| 174 | //------------------------------------------------------------
|
|---|
| 175 | // @function
|
|---|
| 176 |
|
|---|
| 177 | //!@{
|
|---|
| 178 | char *
|
|---|
| 179 | get_database_path(void)
|
|---|
| 180 | {
|
|---|
| 181 | return (Database_path);
|
|---|
| 182 | }
|
|---|
| 183 | //!@}
|
|---|
| 184 |
|
|---|
| 185 | //!-----------------------------------------------------------
|
|---|
| 186 | // @name get_simulated_phe
|
|---|
| 187 | //
|
|---|
| 188 | // @desc return limits for the phe loop
|
|---|
| 189 | //
|
|---|
| 190 | // @var *lphe Lower limit in the phe loop
|
|---|
| 191 | // @var *uphe Higher limit in the phe loop
|
|---|
| 192 | // @var *pphe Precision in the phe loop
|
|---|
| 193 | // @return void
|
|---|
| 194 | //
|
|---|
| 195 | // @date Wed Feb 21 18:04:03 CET 2001
|
|---|
| 196 | //------------------------------------------------------------
|
|---|
| 197 | // @function
|
|---|
| 198 |
|
|---|
| 199 | //!@{
|
|---|
| 200 | void
|
|---|
| 201 | get_simulated_phe(float *lphe, float *uphe, float *pphe)
|
|---|
| 202 | {
|
|---|
| 203 | *lphe = Simulated_Phe_l;
|
|---|
| 204 | *uphe = Simulated_Phe_u;
|
|---|
| 205 | *pphe = Simulated_Phe_p;
|
|---|
| 206 | }
|
|---|
| 207 | //!@}
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 | //=------------------------------------------------------------
|
|---|
| 211 | //!@subsection Log of this file.
|
|---|
| 212 |
|
|---|
| 213 | //!@{
|
|---|
| 214 | //
|
|---|
| 215 | // $Log: not supported by cvs2svn $
|
|---|
| 216 | //!@}
|
|---|
| 217 |
|
|---|
| 218 | //=EOF
|
|---|