casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
MeasIERS.h
Go to the documentation of this file.
00001 //# MeasIERS.h: Interface to IERS tables
00002 //# Copyright (C) 1996,1997,1999,2000,2002,2007
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 //# $Id: MeasIERS.h 21130 2011-10-18 07:39:05Z gervandiepen $
00027 
00028 #ifndef MEASURES_MEASIERS_H
00029 #define MEASURES_MEASIERS_H
00030 
00031 //# Includes
00032 #include <casa/aips.h>
00033 #include <tables/Tables/Table.h>
00034 #include <tables/Tables/TableRow.h>
00035 #include <tables/Tables/TableRecord.h>
00036 #include <casa/Containers/RecordField.h>
00037 #include <casa/OS/Mutex.h>
00038 
00039 namespace casa { //# NAMESPACE CASA - BEGIN
00040 
00041 //# Forward Declarations
00042 class String;
00043 
00044 // <summary> Interface to IERS tables </summary>
00045 
00046 // <use visibility=local>
00047 
00048 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tMeasMath" demos="">
00049 // </reviewed>
00050 
00051 // <prerequisite>
00052 //   <li> <linkto class=MeasTable>MeasTable</linkto>
00053 // </prerequisite>
00054 //
00055 // <etymology>
00056 // From Measure and IERS
00057 // </etymology>
00058 //
00059 // <synopsis>
00060 // MeasIERS is the interface class to the IERS data.
00061 // It has only static memebers.<br>
00062 // It has a member (<src>getTable()</src>) to open and check IERS
00063 // (and other Measures related Tables) type tables.
00064 // Tables are found using the aipsrc 
00065 // (using <src>measures.<table>.directory</src>, or <src>measures.directory</src>)
00066 // mechanism. If not provided they are assumed to reside in standard places
00067 // (i.e. they are looked for in (udir in following normally given by
00068 // program as ephemerides or geodetic) '.', './data', '~/aips++/data/udir',
00069 // '$AIPSROOT/data/udir', '~/aips++/code/trial/apps/measures',
00070 // '$AIPSROOT/data/udir' (last two only ad interim)). They are also looked
00071 // for in <src>data/{ephemerides,geodetic}</src> (root and user aips++).
00072 //
00073 // If an explicit Table object is given the lookup is bypassed, and the Table
00074 // provided is used. The table should still be named.
00075 //
00076 // Tables are assumed to have the
00077 // VS_VERSION, VS_DATE, VS_CREATE and VS_TYPE keywords, and be of type IERS,
00078 // else an exception will be thrown.<br>
00079 // The <src>get()</src> method will obtain data from measured and predicted
00080 // Earth Orientation Parameters IERS tables (i.e. the <src>IERSeop97</src> and
00081 // the <src>IERSpredict</src> tables. If not forced, the data is taken from
00082 // the measured table if possible. Only if forced (see below), or if data is
00083 // not (yet) available in measured the predicted values are used. A warning
00084 // message is (once) issued if values are not available at all.
00085 // 
00086 // MeasIERS looks at some <linkto class=Aipsrc>Aipsrc</linkto>
00087 // values to determine actions:
00088 // <ul>
00089 //  <li> measures.measiers.b_notable : Do not use IERS tables to convert measures
00090 //  <li> measures.measiers.b_forcepredict : Use values from prediction tables
00091 //      even if Measured table asked by program.
00092 //  <li> measures.measiers.d_predicttime : Use values from prediction tables if
00093 //      (now - time) less than value given (default 5) (days)
00094 // </ul>
00095 // These values can be set in aipsrc as well as using 
00096 // <linkto class=AipsrcValue>AipsrcValue</linkto> set() methods.
00097 // <note>
00098 //      A message is Logged (once) if an IERS table cannot be found.
00099 //      A message is logged (once) if a date outside the range in
00100 //      the Tables is asked for. 
00101 // </note>
00102 // <thrown>
00103 //     <li> AipsError if table opened has wrong format or otherwise corrupted.
00104 // </thrown>
00105 // </synopsis>
00106 //
00107 // <example>
00108 // See the <src>dUTC()</src> method in 
00109 // <linkto class=MeasTable>MeasTable</linkto> for an example of the
00110 // <src>getTable</src> method; and the <src>polarMotion()</src> method for
00111 // an example of <src>get()</src>.
00112 // 
00113 // </example>
00114 //
00115 // <motivation>
00116 // To use the IERS data for time and nutation calculations
00117 // </motivation>
00118 //
00119 // <todo asof="1997/07/02">
00120 // </todo>
00121 
00122 class MeasIERS {        
00123 
00124 public:
00125   //# Typedefs
00126   // Define the function pointer to be called to close files
00127   typedef void (*CLOSEFUN) ();
00128 
00129   //# Constants
00130   static const Double INTV;
00131   
00132   //# Enumerations
00133   // Types of known data
00134   enum Types {
00135     // MJD (must be first in list)
00136     MJD,
00137     // Polar motion x
00138     X,
00139     // Polar motion y
00140     Y,
00141     // UT1-UTC
00142     dUT1,
00143     // Length of Day
00144     LOD,
00145     // dPsi
00146     dPsi,
00147     // dEpsilon
00148     dEps,
00149     // Polar motion x error
00150     DX,
00151     // Polar motion y error
00152     DY,
00153     // UT1-UTC error
00154     DdUT1,
00155     // Length of Day error
00156     DLOD,
00157     // dPsi error
00158     DdPsi,
00159     // dEpsilon error
00160     DdEps,
00161     // Number of types
00162     N_Types};
00163   
00164   // Types of files
00165   enum Files {
00166     // Measured EOP values
00167     MEASURED,
00168     // Predicted EOP values
00169     PREDICTED,
00170     // # of known types
00171     N_Files,
00172     // Default
00173     DEFAULT = MEASURED };
00174   
00175   //# General Member Functions
00176   // Get the value from an IERS table, interpolated for date(in MJD).
00177   // The file can be PREDICTED or MEASURED, the type as given in enum.
00178   static Bool get(Double &returnValue,
00179                   MeasIERS::Files file, 
00180                   MeasIERS::Types type,
00181                   Double date);
00182 
00183   // Find and open table tab, using the rc variable, the dir and the name.
00184   // An rfn list gives the N row field names to be used
00185   // Returned are an open table, the table keywordset (kws), a row record,
00186   // pointers (rfp) to row data, the table version (vs), dt, and, directly,
00187   // whether or not it was successful.
00188   // Lookup for name is bypassed if the Table address tabin is provided.
00189   // <thrown>
00190   //  <li> AipsError if missing VS_ keywords, columns, or they type is not IERS.
00191   // </thrown>
00192   static Bool getTable(Table &table, TableRecord &kws, ROTableRow &row,
00193                        RORecordFieldPtr<Double> rfp[],
00194                        String &vs, Double &dt,
00195                        Int N, const String rfn[],
00196                        const String &name,
00197                        const String &rc, const String &dir,
00198                        const Table *tabin = 0);
00199 
00200   // Find and open table tab, using the rc variable, the dir and the name.
00201   // reqcols gives the names (in order) of the columns which must be present.
00202   // optcols gives the names of columns which should be added, in order after
00203   // reqcols, if they are present.
00204   // Returned are an open table, the table keywordset (kws), a row record,
00205   // pointers (rfp) to row data, the table version (vs), dt, and, directly,
00206   // whether or not it was successful.  optcols is set to the optional columns
00207   // that were found.
00208   // Lookup for name is bypassed if the Table address tabin is provided.
00209   // <thrown>
00210   //  <li> AipsError if missing VS_ keywords, required columns, or the type is not IERS.
00211   // </thrown>
00212   static Bool getTable(Table &table, TableRecord &kws, ROTableRow &row,
00213                        Vector<RORecordFieldPtr<Double> >& rfp,
00214                        String &vs, Double &dt,
00215                        const Vector<String>& reqcols,
00216                        Vector<String>& optcols,
00217                        const String &name,
00218                        const String &rc, const String &dir,
00219                        const Table *tabin = 0);
00220 
00221   // A helper function for getTable() which is conceivably usable outside it,
00222   // for finding a table in the same way, but not requiring it to fit the IERS
00223   // mold.
00224   // Finds a Table for tab, by looking in tabin, rc, dir, and name.
00225   // Returns whether or not it was successful.
00226   static Bool findTab(Table& tab, const Table *tabin, const String &rc,
00227                       const String &dir, const String &name);
00228 
00229   // Notify that a table has successfully been opened with getTable()
00230   static void openNote(CLOSEFUN fun);
00231 
00232   // Make sure all static tables are closed that were opened with getTable
00233   // (like JPL, IERS). This is the preferred way to close the
00234   // Measures related data tables.
00235   static void closeTables();
00236 
00237   // Close the set of IERS tables only
00238   static void closeMeas();
00239 
00240 private:
00241   
00242   //# Constructors
00243   // Default constructor, NOT defined
00244   MeasIERS();
00245   
00246   // Copy assign, NOT defined
00247   MeasIERS &operator=(const MeasIERS &other);
00248   
00249   //# Destructor
00250   //  Destructor, NOT defined and not declared to stop warning
00251   // ~MeasIERS();
00252   
00253   //# General member functions
00254   // Initialise tables
00255   static Bool initMeas(MeasIERS::Files which);
00256   // Fill Table lines
00257   static Bool fillMeas(MeasIERS::Files which, Double utf);
00258 
00259   // A helper function for getTable() which is not likely usable outside it.
00260   // Sets dt and vs (the table version), and checks that 
00261   //  ks has VS_DATE, VS_VERSION, VS_CREATE, and VS_TYPE,
00262   //  and that tab's type is IERS in its info.
00263   // Returns whether or not it was successful.
00264   static Bool handle_keywords(Double &dt, String &vs,
00265                               const TableRecord& ks, const Table& tab);
00266 
00267   //# Data members
00268   // Measured data read
00269   static volatile Bool measFlag[N_Files];
00270   // Current date
00271   static Double dateNow;
00272   // Open tables
00273   static Table t[N_Files];
00274   // Row descriptions
00275   static ROTableRow row[N_Files];
00276   // Field pointers
00277   static RORecordFieldPtr<Double> rfp[N_Files][MeasIERS::N_Types];
00278   // First (-1) MJD in list
00279   static Int mjd0[N_Files];
00280   // Last MJD in list
00281   static Int mjdl[N_Files];
00282   // Last read data (measlow - predictlow - meashigh - predicthigh)
00283   static Double ldat[2*N_Files][N_Types];
00284   // Message given
00285   static Bool msgDone;
00286   // File names
00287   static const String tp[N_Files];
00288   // Check prediction interval
00289   static uInt predicttime_reg;
00290   // Use no table
00291   static uInt notable_reg;
00292   // Force prediction
00293   static uInt forcepredict_reg;
00294   // Size of close notification list
00295   static uInt sizeNote;
00296   // Tables notifying that they should be closed
00297   static CLOSEFUN *toclose;
00298   // Number of close notifications
00299   static uInt nNote;
00300   // Mutex for thread-safety.
00301   static Mutex theirMutex;
00302 };
00303 
00304 //# Inline Implementations
00305 
00306 
00307 } //# NAMESPACE CASA - END
00308 
00309 #endif