GPLIB++
magmean.cpp
Go to the documentation of this file.
1 /*!
2  * \addtogroup UtilProgs Utility Programs
3  *@{
4  * \file
5  * This program calculates the mean magnetic time series for several MT sites. The user has to input the number of sites and the
6  * filename for each site. The program then writes a file 'magmean.out' in birrp ascii format that contains the average Hx,Hy and Hz for the input sites.
7  */
8 
9 #include <iostream>
10 #include <string>
11 #include <vector>
12 #include "TimeSeriesData.h"
13 #include "Util.h"
14 #include "convert.h"
15 
16 using namespace std;
17 using namespace gplib;
18 
19 string version = "$Id: magmean.cpp 1816 2009-09-07 11:28:35Z mmoorkamp $";
20 
21 int main(int argc, char *argv[])
22  {
23 
24  unsigned int nfiles = 0;
25 
26  cout
27  << "This is magmean: Calculate the mean magnetic time series from several stations"
28  << endl<< endl;
29  cout << "Usage: magmean" << endl;
30  cout << "There are no command line arguments, only interactive mode"
31  << endl<< endl;
32  cout << "This is Version: " << version << endl << endl;
33  cout << "How many stations: ";
34  cin >> nfiles;
35  string infilename;
36  vector<TimeSeriesData> Sites;
37  for (unsigned int i = 0; i < nfiles; ++i)
38  {
39 
40  std::string prompt = "Site File " + stringify(i+1) + " :";
41  TimeSeriesData CurrSite;
42  infilename = AskFilename(prompt);
43  CurrSite.GetData(infilename);
44  Sites.push_back(CurrSite);
45  }
46  cout << "Calculating mean ... " << endl;
47 
48  for (unsigned int i = 1; i < nfiles; ++i)
49  {
50  Sites.at(0).GetData().GetHx() += Sites.at(i).GetData().GetHx();
51  Sites.at(0).GetData().GetHy() += Sites.at(i).GetData().GetHy();
52  Sites.at(0).GetData().GetHz() += Sites.at(i).GetData().GetHz();
53  }
54  Sites.at(0).GetData().GetHx() *= 1./nfiles;
55  Sites.at(0).GetData().GetHy() *= 1./nfiles;
56  Sites.at(0).GetData().GetHz() *= 1./nfiles;
57  Sites.at(0).WriteAsBirrp("magmean.out");
58  cout << "... done " << endl;
59  }
60 /*@}*/
61 
TimeSeries & GetData()
return a reference to the actual object stored in the pointer
string version
Definition: magmean.cpp:19
int main()
Definition: angleavg.cpp:12
TimeSeriesData stores a pointer to the different components of magnetotelluric data and provides func...