Logo coherent WaveBurst  
Config Reference Guide
Logo
ReadPeriodList.C
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2019 Gabriele Vedovato
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 
19 #define PERIOD_MAX_SIZE 10
20 
21 /*
22  TString run[PERIOD_MAX_SIZE];
23  double gps_start[PERIOD_MAX_SIZE];
24  TString date_start[PERIOD_MAX_SIZE];
25  double gps_stop[PERIOD_MAX_SIZE];
26  TString date_stop[PERIOD_MAX_SIZE];
27  double interval_day[PERIOD_MAX_SIZE];
28  int obs_time_sec[PERIOD_MAX_SIZE];
29  double obs_time_day[PERIOD_MAX_SIZE];
30 
31  int nPeriod = ReadPeriodList(ifile, run, gps_start, date_start, gps_stop, date_stop,
32  interval_day, obs_time_sec, obs_time_day);
33 
34 */
35 
36 int ReadPeriodList(TString ifile, TString* run, double* gps_start, TString* date_start, double* gps_stop, TString* date_stop,
37  double* interval_day, int* obs_time_sec, double* obs_time_day) {
38 
39  CWB::Toolbox::checkFile(ifile);
40 
41  // Open chunk list
42  ifstream in;
43  in.open(ifile.Data(),ios::in);
44  if (!in.good()) {cout << "Error Opening File : " << ifile << endl;exit(1);}
45 
46  int isize=0;
47  char str[1024];
48  int fpos=0;
49  while(true) {
50  in.getline(str,1024);
51  if (!in.good()) break;
52  if(str[0] != '#') isize++;
53  }
54  cout << "size " << isize << endl;
55  in.clear(ios::goodbit);
56  in.seekg(0, ios::beg);
57  if(isize==0) {cout << "Error : File " << ifile << " is empty" << endl;exit(1);}
58  if(isize>PERIOD_MAX_SIZE) {cout << "Error : File " << ifile << " > " << PERIOD_MAX_SIZE << endl;exit(1);}
59 
60  char srun[1024];
61  char sdate_start[1024];
62  char sdate_stop[1024];
63 
64  int k=0;
65  while(true) {
66  fpos=in.tellg();
67  in.getline(str,1024);
68  if (!in.good()) break;
69  if(str[0] == '#' || str[0]=='\0') continue;
70  in.seekg(fpos, ios::beg);
71  in >> srun >> gps_start[k] >> sdate_start >> gps_stop[k] >> sdate_stop >> interval_day[k] >> obs_time_sec[k] >> obs_time_day[k];
72  if(!in.good()) break;
73  run[k]=srun;
74  date_start[k]=sdate_start;
75  date_stop[k]=sdate_stop;
76  cout << "\t" << srun << "\t" << gps_start[k] << "\t" << sdate_start << "\t" << gps_stop[k]
77  << "\t" << sdate_stop << "\t" << obs_time_sec[k] << "\t" << obs_time_day[k] << endl;
78  k++;
79  if(k>=PERIOD_MAX_SIZE) {
80  cout << "WARNING: period list exceed PERIOD_MAX_SIZE = " << PERIOD_MAX_SIZE << endl;
81  break;
82  }
83  }
84  in.close();
85 
86  return k;
87 }
int ReadPeriodList(TString ifile, TString *run, double *gps_start, TString *date_start, double *gps_stop, TString *date_stop, double *interval_day, int *obs_time_sec, double *obs_time_day)
#define PERIOD_MAX_SIZE
string run
Definition: cWB_conf.py:6