magmean.cpp

Go to the documentation of this file.
00001 /*!
00002  * \addtogroup UtilProgs Utility Programs
00003  *@{
00004  * \file
00005  * This program calculates the mean magnetic time series for several MT sites. The user has to input the number of sites and the
00006  * 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.
00007  */
00008 
00009 #include <iostream>
00010 #include <string>
00011 #include <vector>
00012 #include "TimeSeriesData.h"
00013 #include "Util.h"
00014 #include "convert.h"
00015 
00016 using namespace std;
00017 using namespace gplib;
00018 
00019 string version = "$Id: magmean.cpp 1816 2009-09-07 11:28:35Z mmoorkamp $";
00020 
00021 int main(int argc, char *argv[])
00022   {
00023 
00024     unsigned int nfiles = 0;
00025 
00026     cout
00027         << "This is magmean: Calculate the mean magnetic time series from several stations"
00028         << endl<< endl;
00029     cout << "Usage: magmean" << endl;
00030     cout << "There are no command line arguments, only interactive mode"
00031         << endl<< endl;
00032     cout << "This is Version: " << version << endl << endl;
00033     cout << "How many stations: ";
00034     cin >> nfiles;
00035     string infilename;
00036     vector<TimeSeriesData> Sites;
00037     for (unsigned int i = 0; i < nfiles; ++i)
00038       {
00039 
00040         std::string prompt = "Site File " + stringify(i+1) + " :";
00041         TimeSeriesData CurrSite;
00042         infilename = AskFilename(prompt);
00043         CurrSite.GetData(infilename);
00044         Sites.push_back(CurrSite);
00045       }
00046     cout << "Calculating mean ... " << endl;
00047 
00048     for (unsigned int i = 1; i < nfiles; ++i)
00049       {
00050         Sites.at(0).GetData().GetHx() += Sites.at(i).GetData().GetHx();
00051         Sites.at(0).GetData().GetHy() += Sites.at(i).GetData().GetHy();
00052         Sites.at(0).GetData().GetHz() += Sites.at(i).GetData().GetHz();
00053       }
00054     Sites.at(0).GetData().GetHx() *= 1./nfiles;
00055     Sites.at(0).GetData().GetHy() *= 1./nfiles;
00056     Sites.at(0).GetData().GetHz() *= 1./nfiles;
00057     Sites.at(0).WriteAsBirrp("magmean.out");
00058     cout << "... done " << endl;
00059   }
00060 /*@}*/
00061 

Generated on Tue May 4 16:52:14 2010 for GPLIB++ by  doxygen 1.5.8