BirrpAsciiFormat.cpp

Go to the documentation of this file.
00001 #include "BirrpAsciiFormat.h"
00002 #include "MtuFormat.h"
00003 #include <fstream>
00004 #include <iomanip>
00005 #include <iostream>
00006 #include <CFatalException.h>
00007 #include <boost/cast.hpp>
00008 
00009 using namespace std;
00010 BirrpAsciiFormat::BirrpAsciiFormat()
00011   {
00012   }
00013 BirrpAsciiFormat::~BirrpAsciiFormat()
00014   {
00015   }
00016 
00017 
00018 void BirrpAsciiFormat::GetData(const std::string filename)
00019   {
00020     ifstream infile(filename.c_str());
00021     double currex, currey, currhx, currhy, currhz; // the current samples in the file
00022     const double birrp_samplerate = 1.0; //arbitrary sampling rate, birrp format does not contain rate
00023     // the birrp format does not store time information, so we set an arbitrary start time
00024     TimeSeries::ttime basetime(boost::gregorian::date(2004, 1, 1),
00025         boost::posix_time::time_duration(12, 0, 0));
00026     while (infile.good())
00027       {
00028         infile.precision(15);
00029         infile >> currex >> currey >> currhx >> currhy >> currhz;
00030         if (infile.good())
00031           {
00032             Ex.GetData().push_back(currex);
00033             Ey.GetData().push_back(currey);
00034             Hx.GetData().push_back(currhx);
00035             Hy.GetData().push_back(currhy);
00036             Hz.GetData().push_back(currhz);
00037             t.push_back(basetime);
00038             basetime += boost::posix_time::seconds(boost::numeric_cast<int>(
00039                 birrp_samplerate)); // we assume an arbitrary sampling rate of 1 second
00040           }
00041       }
00042     //if we didn't stop because the file ended
00043     if (!infile.eof())
00044       {
00045         throw CFatalException("Problem reading from file: " + filename);
00046       }
00047     Hx.SetSamplerate(birrp_samplerate); //we set the samplerate for each component, this value is arbitrary, but we don't have information
00048     Hy.SetSamplerate(birrp_samplerate);
00049     Hz.SetSamplerate(birrp_samplerate);
00050     Ex.SetSamplerate(birrp_samplerate);
00051     Ey.SetSamplerate(birrp_samplerate);
00052   }
00053 
00054 void BirrpAsciiFormat::WriteData(const std::string filename)
00055   {
00056     ofstream outfile(filename.c_str());
00057     TimeSeriesComponent::tdatait exit, eyit, hxit, hyit, hzit;
00058     //if any of the components has a different number of points throw and error
00059     const size_t exsize = Size();
00060 
00061 
00062 
00063     exit = Ex.GetData().begin();
00064     eyit = Ey.GetData().begin();
00065     hxit = Hx.GetData().begin();
00066     hyit = Hy.GetData().begin();
00067     hzit = Hz.GetData().begin();
00068     // write a simple ascii file with 5 values in one row
00069     while (exit != Ex.GetData().end())
00070       {
00071         outfile.precision(8);
00072         outfile << setw(20) << *exit << " ";
00073         outfile << setw(20) << *eyit << " ";
00074         outfile << setw(20) << *hxit << " ";
00075         outfile << setw(20) << *hyit << " ";
00076         outfile << setw(20) << *hzit << endl;
00077         exit++;
00078         eyit++;
00079         hzit++;
00080         hyit++;
00081         hxit++;
00082       }
00083   }
00084 
00085 BirrpAsciiFormat& BirrpAsciiFormat::operator=(BirrpAsciiFormat& source)
00086   {
00087     if (this != &source)
00088       {
00089         this->TimeSeries::operator=(source);
00090       }
00091     return *this;
00092   }
00093 
00094 BirrpAsciiFormat& BirrpAsciiFormat::operator=(MtuFormat& source)
00095   {
00096 
00097     this->TimeSeries::operator=(source);
00098     return *this;
00099   }
00100 
00101 BirrpAsciiFormat& BirrpAsciiFormat::operator=(TimeSeries& source)
00102   {
00103 
00104     this->TimeSeries::operator=(source);
00105     return *this;
00106   }

Generated on Fri Jul 4 15:30:20 2008 for GPLIB++ by  doxygen 1.5.5