GPLIB++
exchangecomp.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <vector>
4 #include <iterator>
5 #include "TimeSeriesData.h"
6 
7 using namespace std;
8 using namespace gplib;
9 
10 string version = "$Id: exchangecomp.cpp 1816 2009-09-07 11:28:35Z mmoorkamp $";
11 
12 int main(int argc, char *argv[])
13  {
14  TimeSeriesData TsData;
15 
16  string mtufilename, compfilename;
17  cout
18  << "This is exchangecomp: Exchange one component of MTU file by contents of ascii file"
19  << endl << endl;
20  cout
21  << " Output will have the same name as MTU Input with '.rep' appended "
22  << endl << endl;
23  cout << " This is Version: " << version << endl << endl;
24 
25  cout << "Mtu filename: ";
26  cin >> mtufilename;
27  TsData.GetData(mtufilename);
28 
29  cout << "Component filename: ";
30  cin >> compfilename;
31  vector<double> compdata;
32  ifstream compfile(compfilename.c_str());
33  copy(istream_iterator<double> (compfile), istream_iterator<double> (),
34  back_inserter(compdata));
35  if (compdata.size() != TsData.GetData().GetEx().GetData().size())
36  {
37  std::cerr << "Number of points incompatible !";
38  return 100;
39  }
40  int compindex;
41  cout << "Enter target component number (Ex,Ey,Hx,Hy): ";
42  cin >> compindex;
43  std::vector<double>::iterator outit;
44  switch (compindex)
45  {
46  case 1:
47  outit = TsData.GetData().GetEx().GetData().begin();
48  break;
49  case 2:
50  outit = TsData.GetData().GetEy().GetData().begin();
51  break;
52  case 3:
53  outit = TsData.GetData().GetHx().GetData().begin();
54  break;
55  case 4:
56  outit = TsData.GetData().GetHy().GetData().begin();
57  break;
58  default:
59  std::cerr << "Invalid component selection !";
60  return 100;
61  break;
62  }
63  copy(compdata.begin(), compdata.end(), outit);
64  TsData.WriteAsMtu(mtufilename + ".rep");
65  }
std::vector< double > & GetData()
Access for data vector, for ease of use and efficiency we return a reference.
TimeSeries & GetData()
return a reference to the actual object stored in the pointer
TimeSeriesComponent & GetEx()
Definition: TimeSeries.h:47
int main(int argc, char *argv[])
TimeSeriesComponent & GetHy()
Definition: TimeSeries.h:39
void WriteAsMtu(std::string filename_base)
Write data to file in Phoenix MTU format.
string version
TimeSeriesData stores a pointer to the different components of magnetotelluric data and provides func...
TimeSeriesComponent & GetEy()
Definition: TimeSeries.h:51
TimeSeriesComponent & GetHx()
Access function for Hx, returns reference for efficiency.
Definition: TimeSeries.h:35