Logo coherent WaveBurst  
Library Reference Guide
Logo
MergeSegments.C
Go to the documentation of this file.
1 //
2 // Merge Segments
3 // this macro read a list of start stop segments from a file
4 // and merge the overlapping segments
5 // Example :
6 // root -b -l 'MergeSegments.C("ifile.txt","ofile.txt")'
7 //
8 // Author : Gabriele Vedovato
9 
10 
12 
13  // --------------------------------------------------------------
14  // Open file segment list
15  // --------------------------------------------------------------
16  ifstream in;
17  in.open(ifile.Data(),ios::in);
18  if (!in.good()) {cout << "Error Opening File : " << ifile << endl;gSystem->Exit(1);}
19  cout << "input file list : " << ifile << endl;
20 
21  char str[1024];
22  int fpos=0;
23  int index=0;
24  double start;
25  double stop;
27  vector<waveSegment> iseg;
28  while (1) {
29  fpos=in.tellg();
30  in.getline(str,1024);
31  if(str[0] == '#') continue;
32  in.seekg(fpos, ios::beg);
33 
34  in >> start >> stop;
35  if (!in.good()) break;
36  fpos=in.tellg();
37  in.seekg(fpos+1, ios::beg);
38 
39  seg.index=index++; seg.start=start; seg.stop=stop; iseg.push_back(seg);
40  }
41 
42  in.close();
43 
44 // cout << "List of input segments" << endl;
45 // for(int n=0;n<iseg.size();n++) cout << n << " " << iseg[n].start << " " << iseg[n].stop << endl;
46 
47  // --------------------------------------------------------------
48  // merge segments
49  // --------------------------------------------------------------
50  vector<waveSegment> oseg = CWB::Toolbox::unionSegments(iseg);
51 
52 // cout << "List of output segments" << endl;
53 // for(int n=0;n<oseg.size();n++) cout << n << " " << oseg[n].start << " " << oseg[n].stop << endl;
54 
55  // --------------------------------------------------------------
56  // Write output file segment list
57  // --------------------------------------------------------------
58  ofstream out;
59  out.open(ofile.Data(),ios::out);
60  out.precision(16);
61  for(int n=0;n<oseg.size();n++) {
62  out << oseg[n].start << " " << oseg[n].stop << endl;
63  }
64  out.close();
65 
66  cout << "output file list : " << ofile << endl;
67 
68  exit(0);
69 }
70 
char ofile[1024]
double start
Definition: network.hh:55
int n
Definition: cwb_net.C:28
vector< waveSegment > oseg
TString("c")
ofstream out
Definition: cwb_merge.C:214
static vector< waveSegment > unionSegments(vector< waveSegment > &ilist)
Definition: Toolbox.cc:119
void MergeSegments(TString ifile, TString ofile)
Definition: MergeSegments.C:11
char str[1024]
TFile * ifile
waveSegment seg
int index
Definition: network.hh:54
vector< waveSegment > iseg
ifstream in
wavearray< int > index
double stop
Definition: network.hh:56
exit(0)