TimeSeries.h

Go to the documentation of this file.
00001 #ifndef CTIMSERIES_H
00002 #define CTIMSERIES_H
00003 #include "FatalException.h"
00004 #include "TimeSeriesComponent.h"
00005 #include <boost/date_time/posix_time/posix_time_types.hpp>
00006 #include <vector>
00007 
00008 namespace gplib
00009   {
00010     /** \addtogroup mttools MT data analysis, processing and inversion */
00011     /* @{ */
00012 
00013     //! This class is the base class for all classes dealing with MT time series
00014     class TimeSeries
00015       {
00016     public:
00017       //! We use the boost library time functionality for time types and store the time for each point in a vector
00018       typedef boost::posix_time::ptime ttime;
00019       typedef std::vector<ttime> ttimedata;
00020     protected:
00021       //! The data for the north-south magnetic field
00022       TimeSeriesComponent Hx;
00023       //! The data for the east-west magnetic field
00024       TimeSeriesComponent Hy;
00025       //! The data for the vertical magnetic field
00026       TimeSeriesComponent Hz;
00027       //! The data for the north-south electric field
00028       TimeSeriesComponent Ex;
00029       //! The data for the east-west electric field
00030       TimeSeriesComponent Ey;
00031       //! The time associated with each data point
00032       ttimedata t;
00033     public:
00034       //! Access function for Hx, returns reference for efficiency
00035       TimeSeriesComponent &GetHx()
00036         {
00037           return Hx;
00038         }
00039       TimeSeriesComponent &GetHy()
00040         {
00041           return Hy;
00042         }
00043       TimeSeriesComponent &GetHz()
00044         {
00045           return Hz;
00046         }
00047       TimeSeriesComponent &GetEx()
00048         {
00049           return Ex;
00050         }
00051       TimeSeriesComponent &GetEy()
00052         {
00053           return Ey;
00054         }
00055       ttimedata &GetTime()
00056         {
00057           return t;
00058         }
00059       //! Return the size of the time series, throws if one of the components has a different size
00060       size_t Size();
00061       /*! Declaration for GetData() that reads data from
00062        * a file. This is intended for use with external data, such as
00063        * recorded data, or synthetic data from external programs.
00064        */
00065       virtual void GetData(const std::string filename) = 0;
00066       /*! The abstract declaration for a method that writes the data to
00067        * a file. Therefore no version without a filename is present
00068        */
00069       virtual void WriteData(const std::string filename) = 0;
00070       //! The samplerate is stored in each component, we just return the samplerate of Hx assuming they are all equal
00071       double GetSamplerate()
00072         {
00073           const double samplerate = Hx.GetSamplerate();
00074           if (samplerate != Hy.GetSamplerate() || samplerate
00075               != Hz.GetSamplerate() || samplerate != Ex.GetSamplerate()
00076               || samplerate != Ey.GetSamplerate())
00077             throw FatalException("Samplerate is not equal for all components");
00078           return samplerate;
00079         }
00080       TimeSeries();
00081       virtual ~TimeSeries();
00082       TimeSeries& operator=(const TimeSeries &source);
00083       //! Multiply all components by a constant factor
00084       TimeSeries& operator*=(const double &factor);
00085       //! Add a constant shift to all components
00086       TimeSeries& operator+=(const double &shift);
00087       //! Erase data between startindex and endindex
00088       void erase(const int startindex, const int endindex);
00089       //friend void Synchronize(TimeSeries &Data1, TimeSeries &Data2);
00090       };
00091 
00092     /*! Synchronize two Objects containing MT data so that they have the same start time
00093      */
00094     void Synchronize(TimeSeries &Data1, TimeSeries &Data2);
00095   /* @} */
00096   }
00097 #endif

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