Logo coherent WaveBurst  
Config Reference Guide
Logo
ConvertEventList.C
Go to the documentation of this file.
1 #define GW_MAX_SIZE 1000
2 
3 // this macro converts GW.lst format
4 // IN -> S190326b 1237605877.39
5 // to GW.txt format
6 // OUT -> S190326b - Mar 26 03:24
7 // to GW.C format
8 // OUT -> O3_BBH_NAME[0]="S190519bj"; O3_BBH_GPS[0]=1242315362.38;
9 
10 // input file = Chunk_List.lst
11 // output file = Chunk_List.txt
12 
13 int ConvertEventList(TString ifile, TString run="O3") {
14 
15  CWB::Toolbox::checkFile(ifile);
16 
17  // Open chunk list
18  ifstream in;
19  in.open(ifile.Data(),ios::in);
20  if (!in.good()) {cout << "Error Opening File : " << ifile << endl;exit(1);}
21 
22  int isize=0;
23  char str[1024];
24  int fpos=0;
25  while(true) {
26  in.getline(str,1024);
27  if (!in.good()) break;
28  if(str[0] != '#') isize++;
29  }
30  in.clear(ios::goodbit);
31  in.seekg(0, ios::beg);
32  if(isize==0) {cout << "Error : File " << ifile << " is empty" << endl;exit(1);}
33  if(isize>GW_MAX_SIZE) {cout << "Error : File " << ifile << " > " << GW_MAX_SIZE << endl;exit(1);}
34 
35  char name[GW_MAX_SIZE][256];
36  double time[GW_MAX_SIZE];
37 
38  cout.precision(10);
39 
40  TString ofile_txt = ifile;
41  ofile_txt.ReplaceAll(".lst",".txt");
42 
43  TString ofile_C = ifile;
44  ofile_C.ReplaceAll(".lst",".C");
45 
46  ofstream out_txt;
47  out_txt.open(ofile_txt.Data());
48  if (!out_txt.good()) {cout << "Error Opening File : " << ofile_txt << endl;exit(1);}
49 
50 // ofstream out_C;
51 // out_C.open(ofile_C.Data());
52 // if (!out_C.good()) {cout << "Error Opening File : " << ofile_C << endl;exit(1);}
53 
54  int k=0;
55  char dummy[256];
56  while(true) {
57  // IN -> S190326b 1237605877.39
58  in >> name[k] >> time[k];
59  if(!in.good()) break;
60  if(name[k][0]=='#') continue;
61  wat::Time sdate(time[k]);
62 
63  TString month[12] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
64 
65  // OUT -> S190326b - Mar 26 03:24
66  char sout_txt[1024];
67  sprintf(sout_txt,"%s - %s %02d %02d:%02d",name[k],
68  month[sdate.GetMonth()-1].Data(),sdate.GetDay(),sdate.GetHour(),sdate.GetMinute());
69 
70  // OUT -> O3_BBH_NAME[0]="S190519bj"; O3_BBH_GPS[0]=1242315362.38;
71 // char sout_C[1024];
72 // sprintf(sout_C," %s_BBH_NAME[%d]=\"%s\";\t%s_BBH_GPS[%d]=%.2f;\t// %s %02d %02d:%02d",run.Data(),k,name[k],run.Data(),k,time[k],
73 // month[sdate.GetMonth()-1].Data(),sdate.GetDay(),sdate.GetHour(),sdate.GetMinute());
74 
75  cout << sout_txt << endl;
76  out_txt << sout_txt << endl;
77 // out_C << sout_C << endl;
78 
79  k++;
80  }
81  in.close();
82  out_txt.close();
83 // out_C.close();
84 
85  exit(0);
86 }
int ConvertEventList(TString ifile, TString run="O3")
#define GW_MAX_SIZE
par[0] name
string run
Definition: cWB_conf.py:6