PTensorMTStation.cpp

Go to the documentation of this file.
00001 #include "PTensorMTStation.h"
00002 #include <fstream>
00003 #include <iomanip>
00004 #include "FatalException.h"
00005 
00006 using namespace std;
00007 
00008 namespace gplib
00009   {
00010     PTensorMTStation::PTensorMTStation()
00011       {
00012       }
00013 
00014     PTensorMTStation::~PTensorMTStation()
00015       {
00016       }
00017 
00018     PTensorMTStation &PTensorMTStation::operator=(const MTStation &MTData)
00019       {
00020         Tensor.clear(); // clear old data
00021         const unsigned int nfrequencies = MTData.GetMTData().size();
00022         Tensor.reserve(nfrequencies);
00023         for (unsigned int i = 0; i < nfrequencies; ++i)
00024           {
00025             Tensor.push_back(PTensorMTData(MTData.at(i).GetFrequency(),
00026                 MTData.at(i).GetPhi11(), MTData.at(i).GetPhi12(),
00027                 MTData.at(i).GetPhi21(), MTData.at(i).GetPhi22(), 0.0, 0.0,
00028                 0.0, 0.0));
00029           }
00030         return *this;
00031       }
00032 
00033     const trealdata PTensorMTStation::GetFrequencies() const
00034       {
00035         trealdata temp(Tensor.size());
00036         transform(Tensor.begin(), Tensor.end(), temp.begin(), mem_fun_ref(
00037             &PTensorMTData::GetFrequency));
00038         return temp;
00039       }
00040 
00041     void PTensorMTStation::GetData(const std::string &filename)
00042       {
00043         ifstream infile(filename.c_str());
00044         Tensor.clear();
00045         double period, phi11, phi12, phi21, phi22, dphi11, dphi12, dphi21,
00046             dphi22;
00047         while (infile.good())
00048           {
00049             infile >> period >> phi11 >> dphi11 >> phi12 >> dphi12 >> phi21
00050                 >> dphi21 >> phi22 >> dphi22;
00051             if (infile.good())
00052               {
00053                 Tensor.push_back(PTensorMTData(1. / period, phi11, phi12,
00054                     phi21, phi22, dphi11, dphi12, dphi21, dphi22));
00055               }
00056           }
00057         if (Tensor.size() < 1)
00058           throw FatalException("Ptensor file does not exist or is empty !");
00059       }
00060 
00061     void PTensorMTStation::WriteData(const std::string &filename)
00062       {
00063         ofstream outfile((filename + ".ptensor").c_str());
00064         const unsigned int nfreq = Tensor.size();
00065         for (unsigned int i = 0; i < nfreq; ++i)
00066           {
00067             outfile << 1. / Tensor.at(i).GetFrequency() << " ";
00068             outfile << Tensor.at(i).GetPhi11() << " "
00069                 << Tensor.at(i).GetdPhi11() << " ";
00070             outfile << Tensor.at(i).GetPhi12() << " "
00071                 << Tensor.at(i).GetdPhi12() << " ";
00072             outfile << Tensor.at(i).GetPhi21() << " "
00073                 << Tensor.at(i).GetdPhi21() << " ";
00074             outfile << Tensor.at(i).GetPhi22() << " "
00075                 << Tensor.at(i).GetdPhi22() << endl;
00076           }
00077       }
00078   }

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