casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
MeasFrame.h
Go to the documentation of this file.
00001 //# MeasFrame.h: Container for Measure frame
00002 //# Copyright (C) 1996-2003,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: MeasFrame.h 20615 2009-06-09 02:16:01Z Malte.Marquarding $
00027 
00028 #ifndef MEASURES_MEASFRAME_H
00029 #define MEASURES_MEASFRAME_H
00030 
00031 //# Includes
00032 #include <casa/aips.h>
00033 #include <casa/Arrays/Vector.h>
00034 #include <measures/Measures/Measure.h>
00035 #include <casa/iosfwd.h>
00036 
00037 namespace casa { //# NAMESPACE CASA - BEGIN
00038 
00039 //# Forward Declarations
00040 class MVEpoch;
00041 class MVPosition;
00042 class MVDirection;
00043 class MVRadialVelocity;
00044 class MeasComet;
00045 class FrameRep;
00046 class MCFrame;
00047 template <class T> class Vector;
00048 template <class Qtype> class Quantum;
00049 
00050 // <summary> Container for Measure frame </summary>
00051 
00052 // <use visibility=export>
00053 
00054 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tMeasure" demos="">
00055 // </reviewed>
00056 
00057 // <prerequisite>
00058 // <li> <linkto class=Measure>Measure</linkto> class
00059 // <li> <linkto class=MeasRef>MeasRef</linkto> class
00060 // </prerequisite>
00061 //
00062 // <etymology>
00063 // From Measure and Frame
00064 // </etymology>
00065 //
00066 // <synopsis>
00067 // Measurements are made in a reference frame (epoch, position, direction,
00068 // ...).<br>
00069 // The class is a container for the reference frame Measures (MEpoch etc).
00070 // Since a frame will possibly be used by many different Measures, it behaves
00071 // as a smart pointer, with reference rather than copy characteristics.
00072 // Since it caches all its operations, it is advisable to have a 'global'
00073 // MeasFrame across an execution, resetting (or setting) its values
00074 // when appropriate. The frame can also contain other related information. At
00075 // the moment the orbit of a solar system body (MeasComet) can be set.
00076 // In future the planetary ephemeris used (e.g. DE205) and environmental
00077 // information like refraction data will be added.
00078 //
00079 // A MeasFrame is constructed by setting the appropriate Measures, either in
00080 // a constructor, or with a set(). The input to the constructors and set are
00081 // Measures.<br>
00082 //
00083 // Inside the frames automatic conversion to the most appropriate usage of
00084 // its values is done (e.g. time to TBD time, position to astronomical
00085 // longitude). These conversions are done only if an explicit
00086 // Measure::Convert was used that needed information, e.g. the following
00087 // code:
00088 // <srcblock>
00089 //      MeasFrame frame(obser);   // obser is an MPosition
00090 //      MEpoch::Convert conv(MEpoch(12345), MEpoch::Ref(MEpoch::LAST,obser));
00091 //      MEpoch last = conv();
00092 // </srcblock>
00093 // will set-up a state machine to convert UTC(default) to LAST in conv; the
00094 // next call will do the actual conversion. During this conversion, the
00095 // astronomical longitude (among others) will be needed to convert to
00096 // local sidereal time. conv will ask (getLong()) this from the frame, which
00097 // will calculate it (including possible other conversions) from the
00098 // observatory's position specified in a frame. Any calculation done will be
00099 // cached (e.g. a Nutation calculation in this case for dpsi), and used in
00100 // subsequent conversions using the same frame.<br>
00101 // Furthermore, a frame will often be regularly updated (e.g. coordinate
00102 // conversion for a series of times). To make use of cached information, and
00103 // to speed up as much as possible, <src>reset...()</src> functions are 
00104 // available. These reset functions accept the same range of input parameter
00105 // types as the <linkto class=MeasConvert>MeasConvert</linkto> () operator,
00106 // and will keep any determined conversion machines and related information
00107 // intact, only recalculating whatever is necessary.<br>
00108 // The actual frame calculations and interrogations are done in a separate
00109 // <linkto class=MCFrame>MCFrame</linkto> hidden class, which attaches itself
00110 // to MeasFrame when and if necessary (see there if you are really curious).<br>.
00111 // get...() functions can return frame measures. Only when the frame has been
00112 // attached to a calculating machine *MCFrame) are these values available.
00113 // This attachment is done if the frame has been actively used by a
00114 // Measure::Convert engine, or if explicitly done by the
00115 // <src>MCFrame::make(MeasFrame &)</src> static method.
00116 // <note role=caution> An explicit (or implicit) call to MCFrame::make will
00117 // load the whole conversion machinery (including Tables) into your
00118 // linked module).</note><br>
00119 // <linkto class=Aipsrc>Aipsrc keywords</linkto> can be used for additional
00120 // (highly specialised) additional internal conversion parameters.
00121 // </synopsis>
00122 //
00123 // <example>
00124 // <srcblock>
00125 //      MEpoch my_epoch(Quantity(MeasData::MJDB1950,"d")); // an epoch
00126 //      MeasFrame frame(my_epoch);      // used in a frame
00127 // </srcblock>
00128 // </example>
00129 //
00130 // <motivation>
00131 // To separate the frame definition from the measure type
00132 // </motivation>
00133 //
00134 // <todo asof="1997/04/16">
00135 // </todo>
00136 
00137 class MeasFrame {
00138 
00139  public:
00140   
00141   //# Friends
00142   // Output a frame
00143   friend ostream &operator<<(ostream &os, MeasFrame &mf);
00144   // Machinery
00145   // <group>
00146   friend class MCFrame;
00147   friend Bool MCFrameGetdbl(void *dmf, uInt tp, Double &result);
00148   friend Bool MCFrameGetmvdir(void *dmf, uInt tp, MVDirection &result);
00149   friend Bool MCFrameGetmvpos(void *dmf, uInt tp, MVPosition &result);
00150   friend Bool MCFrameGetuint(void *dmf, uInt tp, uInt &result);
00151   // </group>
00152 
00153   //# Enumerations
00154   // Enumeration for the different farme entries possible. This can be used
00155   // to find out if a certain conversion needs the frame. It will be
00156   // used in a registration/notify environment to enable bypassing of
00157   // some new conversion settings.
00158   enum FrameTypes {
00159     EPOCH       = 1,
00160     POSITION    = 2,
00161     DIRECTION   = 4,
00162     VELOCITY    = 8,
00163     COMET       = 16 };
00164 
00165   //# Constructors
00166   // Default constructor
00167   MeasFrame();
00168   // Construct frame with specified measures
00169   // <thrown>
00170   //   <li> AipsError if a non-frame Measure
00171   // </thrown>
00172   // <group>
00173   MeasFrame(const Measure &meas1);
00174   MeasFrame(const Measure &meas1, const Measure &meas2);
00175   MeasFrame(const Measure &meas1, const Measure &meas2,
00176             const Measure &meas3);
00177   // </group>
00178   // Copy constructor (reference semantics)
00179   MeasFrame(const MeasFrame &other);
00180   // Copy assignment (reference semantics)
00181   MeasFrame &operator=(const MeasFrame &other);
00182   // Destructor
00183   ~MeasFrame();
00184   
00185   //# Operators
00186   // Comparisons
00187   // <group>
00188   Bool operator==(const MeasFrame &other) const;
00189   Bool operator!=(const MeasFrame &other) const;
00190   // </group>
00191   
00192   //# General member functions
00193   // Test if empty (i.e. no measure filled in)
00194   Bool empty() const;
00195   
00196   // Set frame elements
00197   // <thrown>
00198   //   <li> AipsError if a non-frame Measure
00199   //   <li> AipsError if illegal or non-existant MeasComet given
00200   // </thrown>
00201   // <group>
00202   void set(const Measure &meas1);
00203   void set(const Measure &meas1, const Measure &meas2);
00204   void set(const Measure &meas1, const Measure &meas2,
00205            const Measure &meas3);
00206   void set(const MeasComet &meas);
00207   // </group>
00208   // Reset a frame element and its cached derived values.
00209   // <thrown>
00210   //   <li> AipsError if the specific Measure not yet present in frame
00211   // </thrown>
00212   // <group>
00213   void resetEpoch(Double val);
00214   void resetEpoch(const Vector<Double> &val);
00215   void resetEpoch(const Quantum<Double> &val);
00216   void resetEpoch(const Quantum<Vector<Double> > &val);
00217   void resetEpoch(const MVEpoch &val);
00218   void resetEpoch(const Measure &val);
00219   void resetPosition(const Vector<Double> &val);
00220   void resetPosition(const Quantum<Vector<Double> > &val);
00221   void resetPosition(const MVPosition &val);
00222   void resetPosition(const Measure &val);
00223   void resetDirection(const Vector<Double> &val);
00224   void resetDirection(const Quantum<Vector<Double> > &val);
00225   void resetDirection(const MVDirection &val);
00226   void resetDirection(const Measure &val);
00227   void resetRadialVelocity(const Vector<Double> &val);
00228   void resetRadialVelocity(const Quantum<Vector<Double> > &val);
00229   void resetRadialVelocity(const MVRadialVelocity &val);
00230   void resetRadialVelocity(const Measure &val);
00231   void resetComet(const MeasComet &val);
00232   // </group>
00233   
00234   // Get the epoch pointer (0 if not present)
00235   const Measure* epoch() const;
00236   // Get the position pointer (0 if not present)
00237   const Measure* position() const;
00238   // Get the direction pointer (0 if not present)
00239   const Measure* direction() const;
00240   // Get the radial velocity pointer (0 if not present)
00241   const Measure* radialVelocity() const;
00242   // Get the comet pointer (0 if not present)
00243   const MeasComet* comet() const;
00244   // Get data from frame. Only available if appropriate measures are set,
00245   // and the frame is in a calculating state.
00246   // <group>
00247   // Get TDB in days
00248   Bool getTDB(Double &tdb) const;
00249   // Get UT1 in days
00250   Bool getUT1(Double &tdb) const;
00251   // Get TT in days
00252   Bool getTT(Double &tdb) const;
00253   // Get the ITRF longitude (in rad)
00254   Bool getLong(Double &tdb) const;
00255   // Get the ITRF latitude (in rad)
00256   Bool getLat(Double &tdb) const;
00257   // Get the position
00258   Bool getITRF(MVPosition &tdb) const;
00259   // Get the geocentric position (in m)
00260   Bool getRadius(Double &tdb) const;
00261   // Get the geodetic latitude
00262   Bool getLatGeo(Double &tdb) const;
00263   // Get the LAST (in days)
00264   Bool getLAST(Double &tdb) const;
00265   // Get the LAST (in rad)
00266   Bool getLASTr(Double &tdb) const;
00267   // Get J2000 coordinates (direction cosines) and its longitude/latitude (rad)
00268   // <group>
00269   Bool getJ2000(MVDirection &tdb) const;
00270   Bool getJ2000Long(Double &tdb) const;
00271   Bool getJ2000Lat(Double &tdb) const;
00272   // </group>
00273   // Get B1950 coordinates (direction cosines)
00274   // <group>
00275   Bool getB1950(MVDirection &tdb) const;
00276   Bool getB1950Long(Double &tdb) const;
00277   Bool getB1950Lat(Double &tdb) const;
00278   // </group>
00279   // Get apparent coordinates (direction cosines)
00280   // <group>
00281   Bool getApp(MVDirection &tdb) const;
00282   Bool getAppLong(Double &tdb) const;
00283   Bool getAppLat(Double &tdb) const;
00284   // </group>
00285   // Get LSR radial velocity (m/s)
00286   Bool getLSR(Double &tdb) const;
00287   // Get the comet table reference type
00288   Bool getCometType(uInt &tdb) const;
00289   // Get the comet coordinates
00290   Bool getComet(MVPosition &tdb) const;
00291   // </group>
00292   
00293 private:
00294   
00295   //# Data
00296   // Representation of MeasFrame
00297   FrameRep *rep;
00298   
00299   //# Member functions
00300   // Create an instance of the MeasFrame class
00301   void create();
00302   // Fill a MeasFrame element
00303   // <group>
00304   void fill(const Measure *in);
00305   void fill(const MeasComet *in);
00306   // </group>
00307   // Make full Epoch
00308   void makeEpoch();
00309   // Make full Position
00310   void makePosition();
00311   // Make full Direction
00312   void makeDirection();
00313   // Make full RadialVelocity
00314   void makeRadialVelocity();
00315   // Make full Comet
00316   void makeComet();
00317   // Throw reset error
00318   void errorReset(const String &txt);
00319   // Lock the frame to make sure deletion occurs when needed
00320   void lock(uInt &locker);
00321   // Unlock the frame
00322   void unlock(const uInt locker);
00323 };
00324 
00325 //# Global functions
00326 // <summary> Global functions </summary>
00327 // <group name=Output>
00328 // Output a frame
00329 ostream &operator<<(ostream &os, MeasFrame &mf);
00330 // </group>
00331 
00332 
00333 } //# NAMESPACE CASA - END
00334 
00335 #endif