TimeSeries.h

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

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