Logo coherent WaveBurst  
Config Reference Guide
Logo
ReadChunkList.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 CHUNK_MAX_SIZE 100
20 
21 
22 int ReadChunkList(TString ifile, int* chunk=NULL, double* start=NULL, double* stop=NULL) {
23 
24  CWB::Toolbox::checkFile(ifile);
25 
26  // Open chunk list
27  ifstream in;
28  in.open(ifile.Data(),ios::in);
29  if (!in.good()) {cout << "Error Opening File : " << ifile << endl;exit(1);}
30 
31  int isize=0;
32  char str[1024];
33  int fpos=0;
34  while(true) {
35  in.getline(str,1024);
36  if (!in.good()) break;
37  if(str[0] != '#') isize++;
38  }
39 // cout << "size " << isize << endl;
40  in.clear(ios::goodbit);
41  in.seekg(0, ios::beg);
42  if(isize==0) {cout << "Error : File " << ifile << " is empty" << endl;exit(1);}
43  if(isize>CHUNK_MAX_SIZE) {cout << "Error : File " << ifile << " > " << CHUNK_MAX_SIZE << endl;exit(1);}
44 
45 // int chunk[CHUNK_MAX_SIZE];
46 // double start[CHUNK_MAX_SIZE];
47 // double stop[CHUNK_MAX_SIZE];
48  if(chunk==NULL) chunk = new int[CHUNK_MAX_SIZE];
49  if(start==NULL) start = new double[CHUNK_MAX_SIZE];
50  if(stop==NULL) stop = new double[CHUNK_MAX_SIZE];
51 
52  char note[CHUNK_MAX_SIZE][256];
53  double days[CHUNK_MAX_SIZE];
54  char bmon[CHUNK_MAX_SIZE][256];
55  int bday[CHUNK_MAX_SIZE];
56  char emon[CHUNK_MAX_SIZE][256];
57  int eday[CHUNK_MAX_SIZE];
58 
59  char sdummy[256];
60 
61  double LH_coincident_days = 0;
62 
63  cout.precision(10);
64 
65  int k=0;
66  while(true) {
67  // O2 22 1187312718 1187740818 3.5 days Aug 21 00:00 - Aug 26 00:00
68  //in >> note[k] >> chunk[k] >> start[k] >> stop[k] >> days[k] >> sdummy >> bmon[k] >> bday[k] >> sdummy >> emon[k] >> eday[k];
69  in >> note[k] >> chunk[k] >> start[k] >> stop[k] >> days[k] >> sdummy >> bmon[k] >> bday[k] >> sdummy >> sdummy >> emon[k] >> eday[k] >> sdummy;
70  if(!in.good()) break;
71  if(note[k][0]=='#') continue;
72  cout << "\t" << chunk[k] << "\t" << start[k] << "\t" << stop[k] << "\t" << days[k] << "\t"
73  << " days\t" << bmon[k] << " " << bday[k] << " - " << emon[k] << " " << eday[k] << "\t\t" << note[k] << endl;
74  LH_coincident_days += days[k];
75  k++;
76  }
77  in.close();
78 
79  cout << endl;
80  cout << "LH_coincident_days = " << LH_coincident_days << endl;
81  cout << endl;
82 
83 // exit(0);
84 
85  return k;
86 }
int ReadChunkList(TString ifile, int *chunk=NULL, double *start=NULL, double *stop=NULL)
Definition: ReadChunkList.C:22
#define CHUNK_MAX_SIZE
Definition: ReadChunkList.C:19