zavg.cpp
Go to the documentation of this file.00001 #include <iostream>
00002 #include <iomanip>
00003 #include "MTStationList.h"
00004
00005 using namespace std;
00006 using namespace gplib;
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 int main()
00018 {
00019 MTStationList MTSites;
00020
00021 string infilename;
00022
00023 string version = "$Id: zavg.cpp 1836 2009-11-27 12:17:24Z mmoorkamp $";
00024 cout << endl << endl;
00025 cout << "Program " << version << endl;
00026 cout << "Average MT responses from a list of file " << endl;
00027 cout << "The average response will be written in a file called avg.mtt "
00028 << endl;
00029 cout << "List filename:";
00030 cin >> infilename;
00031 double xxweights = 0;
00032 double xyweights = 0;
00033 double yxweights = 0;
00034 double yyweights = 0;
00035
00036 MTSites.GetData(infilename);
00037 MTStation AvgSite(MTSites.at(0).GetMTData().size());
00038 AvgSite.SetFrequencies(MTSites.at(0).GetFrequencies());
00039 const size_t nfreq = MTSites.at(0).GetFrequencies().size();
00040 const size_t nsites = MTSites.GetList().size();
00041 const double errorfloor = 0.02;
00042 const double absolutemin = 1e-4;
00043 for (size_t j = 0; j < nfreq; ++j)
00044 {
00045 xxweights = 0;
00046 xyweights = 0;
00047 yxweights = 0;
00048 yyweights = 0;
00049 dcomp currzxx = 0;
00050 dcomp currzxy = 0;
00051 dcomp currzyx = 0;
00052 dcomp currzyy = 0;
00053 for (size_t i = 0; i < nsites; ++i)
00054 {
00055 double minweight = max(
00056 abs(MTSites.at(i).GetMTData().at(j).GetZxx()) * errorfloor,
00057 absolutemin);
00058 double currweight = 1. / pow(max(
00059 MTSites.at(i).GetMTData().at(j).GetdZxx(), minweight), 2);
00060 currzxx += MTSites.at(i).GetMTData().at(j).GetZxx() * currweight;
00061 xxweights += currweight;
00062
00063 minweight = max(abs(MTSites.at(i).GetMTData().at(j).GetZxy())
00064 * errorfloor, absolutemin);
00065 currweight = 1. / pow(max(
00066 MTSites.at(i).GetMTData().at(j).GetdZxy(), minweight), 2);
00067 currzxy += MTSites.at(i).GetMTData().at(j).GetZxy() * currweight;
00068 xyweights += currweight;
00069
00070 minweight = max(abs(MTSites.at(i).GetMTData().at(j).GetZyx())
00071 * errorfloor, absolutemin);
00072 currweight = 1. / pow(max(
00073 MTSites.at(i).GetMTData().at(j).GetdZyx(), minweight), 2);
00074 currzyx += MTSites.at(i).GetMTData().at(j).GetZyx() * currweight;
00075 yxweights += currweight;
00076
00077 minweight = max(abs(MTSites.at(i).GetMTData().at(j).GetZyy())
00078 * errorfloor, absolutemin);
00079 currweight = 1. / pow(max(
00080 MTSites.at(i).GetMTData().at(j).GetdZyy(), minweight), 2);
00081 currzyy += MTSites.at(i).GetMTData().at(j).GetZyy() * currweight;
00082 yyweights += currweight;
00083 }
00084 AvgSite.SetMTData().at(j).SetZxx() = currzxx / xxweights;
00085 AvgSite.SetMTData().at(j).SetZxy() = currzxy / xyweights;
00086 AvgSite.SetMTData().at(j).SetZyx() = currzyx / yxweights;
00087 AvgSite.SetMTData().at(j).SetZyy() = currzyy / yyweights;
00088 AvgSite.SetMTData().at(j).SetErrors(sqrt(1. / xxweights), sqrt(1.
00089 / xyweights), sqrt(1. / yxweights), sqrt(1. / yyweights));
00090 }
00091
00092 AvgSite.WriteAsMtt("avg");
00093 }
00094
00095