GPLIB++
syncts.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <string>
3 #include <numeric>
4 #include "TimeSeriesData.h"
5 #include "FatalException.h"
6 #include <boost/date_time/posix_time/posix_time.hpp>
7 #include "Util.h"
8 
9 using namespace std;
10 using namespace gplib;
11 
12 string version = "$Id: syncts.cpp 1816 2009-09-07 11:28:35Z mmoorkamp $";
13 
14 /*!
15  * \addtogroup UtilProgs Utility Programs
16  *@{
17  * \file
18  * Synchronize 2 files so that they have exactly the same start time and end time. This program
19  * does not fix gaps that are only present in one file !
20  */
21 
22 int main(int argc, char *argv[])
23  {
24  string infilename1, infilename2;
25 
26  cout << "This is syncts: Synchronize the start of two time series" << endl
27  << endl;
28  cout << "Usage: syncts filename1 filename2" << endl;
29  cout << "The outputfiles will have the starttime of whatever starts later"
30  << endl;
31  cout << "They will have the same name as the input files + .sync " << endl
32  << endl;
33  cout << "This is Version: " << version << endl << endl;
34  if (argc == 3)
35  {
36  infilename1 = argv[1];
37  infilename2 = argv[2];
38  }
39  else
40  {
41  infilename1 = AskFilename("First Input Filename: ");
42  infilename2 = AskFilename("Second Input Filename: ");
43 
44  }
45  cout << "Synchronizing ... " << endl;
46  TimeSeriesData Data1, Data2;
47  try
48  {
49  Data1.GetData(infilename1);
50  Data2.GetData(infilename2);
51  cout << "Start time file 1: " << Data1.GetData().GetTime().front()
52  << endl;
53  cout << "Start time file 2: " << Data2.GetData().GetTime().front()
54  << endl << endl;
55  Synchronize(Data1.GetData(), Data2.GetData());
56  Data1.WriteAsBirrp(infilename1 + ".sync");
57  Data2.WriteAsBirrp(infilename2 + ".sync");
58  cout << "New start time file 1: " << Data1.GetData().GetTime().front()
59  << endl;
60  cout << "New start time file 2: " << Data2.GetData().GetTime().front()
61  << endl;
62  } catch (const FatalException &e)
63  {
64  cerr << e.what() << endl;
65  }
66  cout << "... done " << endl;
67  }
68 /*@}*/
TimeSeries & GetData()
return a reference to the actual object stored in the pointer
string version
Definition: syncts.cpp:12
int main()
Definition: angleavg.cpp:12
void WriteAsBirrp(std::string filename_base)
Write data to file in ascii format for birrp processing.
TimeSeriesData stores a pointer to the different components of magnetotelluric data and provides func...
void Synchronize(TimeSeries &Data1, TimeSeries &Data2)
Synchronize only works for continuous data at this point.
Definition: TimeSeries.cpp:88
ttimedata & GetTime()
Definition: TimeSeries.h:55
The basic exception class for all errors that arise in gplib.