ptavg.cpp

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <iomanip>
00003 #include <fstream>
00004 #include "MTStationList.h"
00005 #include "PTensorMTStation.h"
00006 #include "VecMat.h"
00007 #include "statutils.h"
00008 
00009 using namespace std;
00010 using namespace gplib;
00011 
00012 /*!
00013  * \addtogroup UtilProgs Utility Programs
00014  *@{
00015  * \file
00016  * Average the phase tensor elements from a number of MT files, each datum is weighted equally.
00017  * This program is mainly used as an attempt to get average 1D (isotropic or anisotropic) responses
00018  * for a region from a number of measurements.
00019  */
00020 
00021 int main()
00022   {
00023     MTStationList MTSites;
00024     PTensorMTStation PTStation;
00025     string infilename;
00026 
00027     string version = "$Id: ptavg.cpp 1836 2009-11-27 12:17:24Z mmoorkamp $";
00028     cout << endl << endl;
00029     cout << "Program " << version << endl;
00030     cout << "Average MT phase tensor elements from a list of files  " << endl;
00031     cout
00032         << "The average phase tensor will be written in a file called avg.ptensor "
00033         << endl;
00034     cout << "List filename:";
00035     cin >> infilename;
00036 
00037     MTSites.GetData(infilename);
00038     const size_t nfreq = MTSites.at(0).GetFrequencies().size();
00039     const size_t nsites = MTSites.GetList().size();
00040     const double errorfloor = 0.02;
00041     const double absolutemin = 1e-4; // have to find a better solution to avoid strong weighting of 0 values
00042     for (size_t j = 0; j < nfreq; ++j)
00043       {
00044         gplib::rvec xxvalues(nsites);
00045         gplib::rvec xyvalues(nsites);
00046         gplib::rvec yxvalues(nsites);
00047         gplib::rvec yyvalues(nsites);
00048 
00049         for (size_t i = 0; i < nsites; ++i)
00050           {
00051             xxvalues(i) = MTSites.at(i).GetMTData().at(j).GetPhi11();
00052             xyvalues(i) = MTSites.at(i).GetMTData().at(j).GetPhi12();
00053             yxvalues(i) = MTSites.at(i).GetMTData().at(j).GetPhi21();
00054             yyvalues(i) = MTSites.at(i).GetMTData().at(j).GetPhi22();
00055 
00056           }
00057         double phi11 = Mean(xxvalues.begin(), xxvalues.end());
00058         double phi12 = Mean(xyvalues.begin(), xyvalues.end());
00059         double phi21 = Mean(yxvalues.begin(), yxvalues.end());
00060         double phi22 = Mean(yyvalues.begin(), yyvalues.end());
00061 
00062         double varphi11 = Variance(xxvalues.begin(), xxvalues.end());
00063         double varphi12 = Variance(xyvalues.begin(), xyvalues.end());
00064         double varphi21 = Variance(yxvalues.begin(), yxvalues.end());
00065         double varphi22 = Variance(yyvalues.begin(), yyvalues.end());
00066 
00067         PTStation.GetTensor().push_back(PTensorMTData(
00068             MTSites.at(0).GetFrequencies().at(j), phi11, phi12, phi21, phi22,
00069             sqrt(varphi11), sqrt(varphi12), sqrt(varphi21), sqrt(varphi22)));
00070       }
00071     PTStation.WriteData("avg.ptensor");
00072   }
00073 /*@}*/
00074 

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