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$ 00028 00029 #ifndef CASA_MVEPOCH_H 00030 #define CASA_MVEPOCH_H 00031 00032 00033 //# Includes 00034 #include <casacore/casa/aips.h> 00035 #include <casacore/casa/Arrays/Vector.h> 00036 #include <casacore/casa/Quanta/Quantum.h> 00037 #include <casacore/casa/Quanta/MeasValue.h> 00038 00039 namespace casacore { //# NAMESPACE CASACORE - 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 static const Unit unitDay; 00145 00146 // Tell me your type 00147 // <group> 00148 virtual uInt type() const; 00149 static void assure(const MeasValue &in); 00150 // </group> 00151 00152 // Adjust the time to its constituent parts. The returned result is always 1.0 00153 // <group> 00154 virtual void adjust(); 00155 virtual void adjust(Double &res); 00156 // </group> 00157 00158 // Get value in days 00159 Double get() const; 00160 00161 // Get value with units 00162 // <group> 00163 Quantity getTime() const; 00164 Quantity getTime(const Unit &unit) const; 00165 // </group> 00166 00167 // Get value of integer days 00168 Double getDay() const; 00169 00170 // Get fraction of days 00171 Double getDayFraction() const; 00172 00173 // Print a value 00174 virtual void print(ostream &os) const; 00175 00176 // Clone a value 00177 virtual MeasValue *clone() const; 00178 00179 // Get the value in internal units 00180 virtual Vector<Double> getVector() const; 00181 // Set the value from internal units (set 0 for empty vector) 00182 virtual void putVector(const Vector<Double> &in); 00183 // Get the internal value as a <src>Vector<Quantity></src>. Usable in 00184 // records. The getXRecordValue() gets additional information for records. 00185 // Note that the Vectors could be empty. 00186 // <group> 00187 virtual Vector<Quantum<Double> > getRecordValue() const; 00188 // </group> 00189 // Set the internal value if correct values and dimensions 00190 virtual Bool putValue(const Vector<Quantum<Double> > &in); 00191 00192 private: 00193 //# Data members 00194 // Whole days 00195 // Note that if higher precision is needed, the splitting could be in 00196 // 0.001 days and fractions thereof 00197 Double wday; 00198 // Fraction of days 00199 Double frday; 00200 00201 //# Member functions 00202 // Make days from quantity 00203 Double makeDay(const Quantity &in) const; 00204 // Add time from days 00205 void addTime(Double in); 00206 }; 00207 00208 //# Global functions 00209 00210 00211 } //# NAMESPACE CASACORE - END 00212 00213 #endif