Logo coherent WaveBurst  
Config Reference Guide
Logo
ConvertChunkList.C
Go to the documentation of this file.
1 #define CHUNK_MAX_SIZE 100
2 
3 // this macro converts Chunk_List.lst format
4 // O3 1 1238166018 1238787954
5 // to Chunk_List.txt format
6 // O3 1 1238166018 1238787954 7.16 days Apr 01 15:00 - Apr 08 19:45
7 
8 // input file = Chunk_List.lst
9 // output file = Chunk_List.txt
10 
11 int ConvertChunkList(TString ifile) {
12 
13  CWB::Toolbox::checkFile(ifile);
14 
15  // Open chunk list
16  ifstream in;
17  in.open(ifile.Data(),ios::in);
18  if (!in.good()) {cout << "Error Opening File : " << ifile << endl;exit(1);}
19 
20  int isize=0;
21  char str[1024];
22  int fpos=0;
23  while(true) {
24  in.getline(str,1024);
25  if (!in.good()) break;
26  if(str[0] != '#') isize++;
27  }
28  in.clear(ios::goodbit);
29  in.seekg(0, ios::beg);
30  if(isize==0) {cout << "Error : File " << ifile << " is empty" << endl;exit(1);}
31  if(isize>CHUNK_MAX_SIZE) {cout << "Error : File " << ifile << " > " << CHUNK_MAX_SIZE << endl;exit(1);}
32 
33  char run[CHUNK_MAX_SIZE][256];
34  int chunk[CHUNK_MAX_SIZE];
35  double start[CHUNK_MAX_SIZE];
36  double stop[CHUNK_MAX_SIZE];
37 
38  cout.precision(10);
39 
40  TString ofile = ifile;
41  ofile.ReplaceAll(".lst",".txt");
42 
43  ofstream out;
44  out.open(ofile.Data());
45  if (!out.good()) {cout << "Error Opening File : " << ofile << endl;exit(1);}
46 
47  int k=0;
48  while(true) {
49  // IN -> O3 1 1238166018 1238787954
50  in >> run[k] >> chunk[k] >> start[k] >> stop[k];
51  if(!in.good()) break;
52  if(run[k][0]=='#') continue;
53 // cout << run[k] << "\t" << chunk[k] << "\t" << start[k] << "\t" << stop[k] << endl;
54  double days = (stop[k]-start[k])/(24.*3600.);
55  wat::Time sdate(start[k]);
56  wat::Time edate(stop[k]);
57 
58  TString month[12] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
59 
60  char sout[1024];
61  // OUT -> O3 1 1238166018 1238787954 7.16 days Apr 01 15:00 - Apr 08 19:45
62  sprintf(sout,"%s %d %d %d %.2f days %s %02d %02d:%02d - %s %02d %02d:%02d",run[k],chunk[k],int(start[k]),int(stop[k]),days,
63  month[sdate.GetMonth()-1].Data(),sdate.GetDay(),sdate.GetHour(),sdate.GetMinute(),
64  month[edate.GetMonth()-1].Data(),edate.GetDay(),edate.GetHour(),edate.GetMinute());
65 
66  cout << sout << endl;
67  out << sout << endl;
68 
69  k++;
70  }
71  in.close();
72  out.close();
73 
74  exit(0);
75 }
#define CHUNK_MAX_SIZE
int ConvertChunkList(TString ifile)
string run
Definition: cWB_conf.py:6