casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
MVEpoch.h
Go to the documentation of this file.
00001 //# MVEpoch.h: a class for high precision time
00002 //# Copyright (C) 1996,1997,1998,1999,2000
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //#
00027 //# $Id: MVEpoch.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $
00028 
00029 #ifndef CASA_MVEPOCH_H
00030 #define CASA_MVEPOCH_H
00031 
00032 
00033 //# Includes
00034 #include <casa/aips.h>
00035 #include <casa/Arrays/Vector.h>
00036 #include <casa/Quanta/Quantum.h>
00037 #include <casa/Quanta/MeasValue.h>
00038 
00039 namespace casa { //# NAMESPACE CASA - BEGIN
00040 
00041 //# Forward Declarations
00042 class Unit;
00043 
00044 // <summary> A class for high precision time </summary>
00045 
00046 // <use visibility=export>
00047 
00048 // <reviewed reviewer="tcornwel" date="1996/02/22" tests="tMeasMath" demos="">
00049 // </reviewed>
00050 
00051 // <prerequisite>
00052 //  <li> <linkto class=MeasValue>MeasValue</linkto> class
00053 // </prerequisite>
00054 //
00055 // <etymology>
00056 // MVEpoch from Measure, Value and Epoch
00057 // </etymology>
00058 //
00059 // <synopsis>
00060 // MVEpoch is a class for high precision (10<sup>-16</sup> s) epochs over a
00061 // period of 6*10<sup>10</sup> a.<br>
00062 // MVEpochs can be compared, a time interval can be added or subtracted, and
00063 // the time difference can be found.
00064 // The following constructors:
00065 // <ul>
00066 //   <li> <src>MVEpoch()</src> default; assuming 0
00067 //   <li> <src>MVEpoch(Double)</src> with time given in days
00068 //   <li> <src>MVEpoch(Double, Double=0)</src> with times given in days
00069 //   <li> <src>MVEpoch(Quantity, Quantity=0)</src> with times given
00070 //   <li> <src>MVEpoch(Quantum<Vector<Double> >)</src> with times given
00071 //   <li> <src>MVEpoch(Vector<Double>)</src> with times in days
00072 //   <li> <src>MVEpoch(Vector<Quantity>)</src> with times
00073 // </ul>
00074 // </synopsis>
00075 //
00076 // <example>
00077 // See <linkto class=MEpoch>MEpoch</linkto>
00078 // </example>
00079 //
00080 // <motivation>
00081 // To have high precision timing
00082 // </motivation>
00083 //
00084 // <todo asof="1996/02/04">
00085 //   <li> A proper high precision time, including multiplication etc should
00086 //              be considered. E.g. a multi-byte number with 6 bytes day
00087 //              and 8 bytes fractional day.
00088 // </todo>
00089 
00090 class MVEpoch : public MeasValue {
00091 
00092 public:
00093   
00094   //# Friends
00095   
00096   //# Constructors
00097   // Default constructor, generates default 0 epoch
00098   MVEpoch();
00099   // Copy constructor
00100   MVEpoch(const MVEpoch &other);
00101   // Constructor with time in days
00102   // <group>
00103   MVEpoch(Double inday, Double infrac=0);
00104   MVEpoch(const Vector<Double> &inday);
00105   // </group>
00106   // Constructor with Quantities
00107   // <group>
00108   MVEpoch(const Quantity &in);
00109   MVEpoch(const Quantity &in1, const Quantity &in2);
00110   MVEpoch(const Quantum<Vector<Double> > &in);
00111   MVEpoch(const Vector<Quantity> &in);
00112   // </group>
00113   
00114   //# Destructor
00115   ~MVEpoch();
00116   
00117   //# Operators
00118   // Copy assignment
00119   MVEpoch &operator=(const MVEpoch &other);
00120   
00121   // Add times
00122   // <group>
00123   MVEpoch &operator+=(const MVEpoch &other);
00124   MVEpoch operator+(const MVEpoch &other) const;
00125   // </group>
00126   
00127   // Difference times
00128   // <group>
00129   MVEpoch &operator-=(const MVEpoch &other);
00130   MVEpoch operator-(const MVEpoch &other) const;
00131   // </group>
00132   
00133   // Comparisons
00134   // <group>
00135   Bool operator==(const MVEpoch &other) const;
00136   Bool operator!=(const MVEpoch &other) const;
00137   Bool near(const MVEpoch &other, Double tol = 1e-13) const;
00138   Bool nearAbs(const MVEpoch &other, Double tol = 1e-13) const;
00139   // </group>
00140   
00141   //# General Member Functions
00142   // Constants
00143   static const Double secInDay;
00144   
00145   // Tell me your type
00146   // <group>
00147   virtual uInt type() const;
00148   static void assure(const MeasValue &in);
00149   // </group>
00150   
00151   // Adjust the time to its constituent parts. The returned result is always 1.0
00152   // <group>
00153   virtual void adjust();
00154   virtual void adjust(Double &res);
00155   // </group>
00156   
00157   // Get value in days
00158   Double get() const;
00159   
00160   // Get value with units
00161   // <group>
00162   Quantity getTime() const;
00163   Quantity getTime(const Unit &unit) const;
00164   // </group>
00165   
00166   // Get value of integer days
00167   Double getDay() const;
00168   
00169   // Get fraction of days
00170   Double getDayFraction() const;
00171 
00172   // Print a value
00173   virtual void print(ostream &os) const;
00174   
00175   // Clone a value
00176   virtual MeasValue *clone() const;
00177 
00178   // Get the value in internal units
00179   virtual Vector<Double> getVector() const;
00180   // Set the value from internal units (set 0 for empty vector)
00181   virtual void putVector(const Vector<Double> &in);
00182   // Get the internal value as a <src>Vector<Quantity></src>. Usable in
00183   // records. The getXRecordValue() gets additional information for records.
00184   // Note that the Vectors could be empty.
00185   // <group>
00186   virtual Vector<Quantum<Double> > getRecordValue() const;
00187   // </group>
00188   // Set the internal value if correct values and dimensions
00189   virtual Bool putValue(const Vector<Quantum<Double> > &in);
00190   
00191 private:
00192   //# Data members
00193   // Whole days
00194   // Note that if higher precision is needed, the splitting could be in
00195   // 0.001 days and fractions thereof
00196   Double wday;
00197   // Fraction of days
00198   Double frday;
00199   
00200   //# Member functions
00201   // Make days from quantity
00202   Double makeDay(const Quantity &in) const;
00203   // Add time from days
00204   void addTime(Double in);
00205 };
00206 
00207 //# Global functions
00208 
00209 
00210 } //# NAMESPACE CASA - END
00211 
00212 #endif