casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ArrayTime.h
Go to the documentation of this file.
00001 /*
00002  * ALMA - Atacama Large Millimeter Array
00003  * (c) European Southern Observatory, 2002
00004  * (c) Associated Universities Inc., 2002
00005  * Copyright by ESO (in the framework of the ALMA collaboration),
00006  * Copyright by AUI (in the framework of the ALMA collaboration),
00007  * All rights reserved.
00008  * 
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  * 
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY, without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Lesser General Public License for more details.
00018  * 
00019  * You should have received a copy of the GNU Lesser General Public
00020  * License along with this library; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00022  * MA 02111-1307  USA
00023  *
00024  * File ArrayTime.h
00025  */
00026 
00027 #ifndef ArrayTime_CLASS
00028 #define ArrayTime_CLASS
00029 
00030 #include <stdint.h>
00031 #include <string>
00032 using std::string;
00033 
00034 #include <vector>
00035 using std::vector;
00036 
00037 #include <Interval.h> 
00038 #include <UTCCorrection.h>
00039 
00040 #ifndef WITHOUT_ACS
00041 #include <asdmIDLTypesC.h>
00042 using asdmIDLTypes::IDLArrayTime;
00043 #endif
00044 
00045 #include "EndianStream.h"
00046 using asdm::EndianOSStream;
00047 using asdm::EndianIStream;
00048 
00049 namespace asdm {
00050 
00094 class ArrayTime : public Interval {
00095 
00096 public:
00097 
00098         // Useful constants
00099         const static int numberSigDigitsInASecond                                       = 9;
00100         const static int64_t unitsInASecond                                             = 1000000000LL;
00101         const static int64_t unitsInADayL                                               = 86400000000000LL;
00102         const static double unitsInADay ;       
00103         const static double unitsInADayDiv100 ;         
00104         const static double julianDayOfBase ;   
00105         const static int64_t julianDayOfBaseInUnitsInADayDiv100         = 2073600432000000000LL;
00106 
00107         static  bool isLeapYear(int year);
00108         static  double getMJD(double jd);
00109         static  double getJD(double mjd);
00110         static  ArrayTime add(const ArrayTime &time, const Interval &interval);
00111         static  ArrayTime sub(const ArrayTime &time, const Interval &interval) ;
00112         static  ArrayTime getArrayTime(StringTokenizer &t) ;
00113 
00121         ArrayTime();
00122 
00133         ArrayTime (const string &s); 
00134 
00140         ArrayTime(const ArrayTime &t);
00141 #ifndef WITHOUT_ACS 
00142 
00147         ArrayTime (const IDLArrayTime &t);
00148 #endif 
00149 
00160         ArrayTime(int year, int month, double day); 
00161 
00174         ArrayTime(int year, int month, int day, int hour, int minute, double second);
00175 
00181         ArrayTime(double modifiedJulianDay);
00182 
00189         ArrayTime(int modifiedJulianDay, double secondsInADay);
00190 
00197         ArrayTime(int64_t nanoseconds);
00198 
00204         double getJD() const; 
00205 
00211         double getMJD() const; 
00212 
00213 /*
00214         double getJDI() const; 
00215         double getMJDI() const; 
00216 */
00217 
00218 #ifndef WITHOUT_ACS
00219         IDLArrayTime toIDLArrayTime() const; 
00220 #endif
00221         string toFITS() const; 
00222         
00223                         
00227         void toBin(EndianOSStream& eoss);
00228 
00234         static void toBin(const vector<ArrayTime>& arrayTime,  EndianOSStream& eoss);
00235         
00241         static void toBin(const vector<vector<ArrayTime> >& arrayTime,  EndianOSStream& eoss);
00242         
00248         static void toBin(const vector<vector<vector<ArrayTime> > >& arrayTime,  EndianOSStream& eoss);
00249 
00256         static ArrayTime fromBin(EndianIStream& eis);
00257         
00264          static vector<ArrayTime> from1DBin(EndianIStream & eis);
00265          
00272          static vector<vector<ArrayTime> > from2DBin(EndianIStream & eis);
00273          
00280          static vector<vector<vector<ArrayTime> > > from3DBin(EndianIStream & eis);     
00281                 
00282         int *getDateTime() const; 
00283         double getTimeOfDay() const; 
00284         int getDayOfWeek() const; 
00285         int getDayOfYear() const; 
00286         string timeOfDayToString() const;
00287         double getLocalSiderealTime(double longitudeInHours) const; 
00288         double getGreenwichMeanSiderealTime() const; 
00289 
00290         static double unitToJD(int64_t unit);
00291         static double unitToMJD(int64_t unit);
00292         static int64_t jdToUnit(double jd);
00293         static int64_t mjdToUnit(double mjd);
00294 
00295         static double utcCorrection(double jd); 
00296 
00297 private:
00298 
00299         static int64_t init(int year, int month, double day);
00300         static int64_t init(int year, int month, int day, int hour, int minute, double second);
00301         int64_t FITSString(string t) const;
00302 
00303 /*
00304         static const int numberSigDigitsInASecond;
00305         static const int64_t unitsInASecond;
00306         static const int64_t unitsInADayL;
00307         static const double unitsInADay;
00308         static const double unitsInADayDiv100;
00309         static const double julianDayOfBase;
00310         static const int64_t julianDayOfBaseInUnitsInADayDiv100;
00311 */
00312         static const UTCCorrection *UTCCorrectionTable;
00313         static const UTCCorrection UTCLast;
00314 
00315 };
00316 
00317 /*
00318 inline double ArrayTime::getJDI() const {return getJD();}
00319 inline double ArrayTime::getMJDI()const  {return getMJD();}
00320 */
00321 } // End namespace asdm
00322 
00323 #endif /* ArrayTime_CLASS */