casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
MCBase.h
Go to the documentation of this file.
00001 //# MCBase.h: Base for specific measure conversions
00002 //# Copyright (C) 1995,1996,1997,1998
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: MCBase.h 21130 2011-10-18 07:39:05Z gervandiepen $
00028 
00029 #ifndef MEASURES_MCBASE_H
00030 #define MEASURES_MCBASE_H
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 
00035 namespace casa { //# NAMESPACE CASA - BEGIN
00036 
00037 //# Forward Declarations
00038 class MeasValue;
00039 class MCBase;
00040 class MRBase;
00041 class MConvertBase;
00042 class String;
00043 
00044 //# Typedefs
00045 
00046 // <summary>  Base for specific measure conversions </summary>
00047 
00048 // <use visibility=local>
00049 
00050 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tMeasure" demos="">
00051 // </reviewed>
00052 
00053 // <prerequisite>
00054 //   <li> <linkto class=Measure>Measure</linkto> class
00055 //   <li> <linkto class=MConvertBase>MConvertBase</linkto>: conversion engine
00056 // </prerequisite>
00057 //
00058 // <etymology>
00059 // Measure, Conversion and Base
00060 // </etymology>
00061 //
00062 // <synopsis>
00063 // MCBase forms the base for the individual state machines doing actual
00064 // conversions between frames. (see e.g. <linkto class=MCEpoch>MCEpoch</linkto>)
00065 //
00066 // It also has a static routine to calculate the state transition table based
00067 // on a list of transitions. The makeState() method find the shortest route
00068 // (weighted if necessary) for a given list of state transitions. 
00069 //
00070 // The user of the Measure classes has no direct interaction with this class.
00071 // </synopsis>
00072 //
00073 // <example>
00074 // Convert (with all steps explicit) a UTC to an IAT time.
00075 // <srcblock>
00076 //      #include <measures/Measures.h>
00077 //      #include <measures/Measures/MCEpoch.h>
00078 //      cout << "TAI for UTC = MJD(50237.29): " <<
00079 //              MEpoch::Convert(MEpoch(MVEpoch(Quantity(50237.29, "d")),
00080 //                                     MEpoch::Ref(MEpoch::UTC)),
00081 //                              MEpoch::Ref(MEpoch::TAI))() <<
00082 //              endl;
00083 // </srcblock>
00084 // To get a static state transition matrix:
00085 // <srcblock>
00086 //      static Bool made = False;               // set not yet done
00087 //      enum types {                            // states
00088 //              A=0, B, C, D, E, ntyp };
00089 //      enum routes {                           // routes
00090 //              A_B, B_C, B_D, C_D, C_E,
00091 //              D_C, C_B, B_A, D_B, E_C, nrout };
00092 //      static uInt list [nrout][3] = {         // description. The third number
00093 //              {A, B, 0},                      // is a penalty hop to weight
00094 //              {B, C, 0},                      // against using this route
00095 //              {B, D, 0},
00096 //              {C, D, 0},
00097 //              {C, E, 0},
00098 //              {D, C, 0},
00099 //              {C, B, 0},
00100 //              {B, A, 0},
00101 //              {D, B, 0},
00102 //              {E, C, 0} };
00103 //      static uInt state[ntyp][ntyp];  // the resultant transition matrix
00104 //                                      // diagonal == nrout
00105 //      // Make the state machine
00106 //      MCBase::makeState(state[0], ntyp, nrout, routes);
00107 //      made = True;
00108 // </srcblock>
00109 // </example>
00110 //
00111 // <motivation>
00112 //      To have specific conversion bases
00113 // </motivation>
00114 //
00115 // <todo asof="1998/09/21">
00116 //      <li> Nothing I know
00117 // </todo>
00118 
00119 class MCBase {
00120 
00121 public:
00122   
00123   //# Typedefs
00124   
00125   //# Constructors
00126   
00127   //# Destructor
00128   virtual ~MCBase();
00129   
00130   //# Operators
00131 
00132   //# Enumerations
00133   // Each derived class should have a list of routines to be called:
00134   enum Routes {
00135     N_Routes};
00136   
00137   //# Member functions
00138   // All these functions are called by Measure::Convert classes only
00139   // <group>  
00140   // Create conversion state machine list
00141   virtual void getConvert(MConvertBase &mc,
00142                           const MRBase &inref,
00143                           const MRBase &outref) = 0;
00144   
00145   // Create help structures for Measure conversion routines
00146   virtual void initConvert(uInt which, MConvertBase &mc) = 0;
00147   
00148   // Delete the pointers used in the MeasConvert help structure cache
00149   virtual void clearConvert() = 0;
00150   
00151   // Routine to convert a Measure from one reference frame to another
00152   virtual void doConvert(MeasValue &in,
00153                          MRBase &inref,
00154                          MRBase &outref,
00155                          const MConvertBase &mc) = 0;
00156   // </group>
00157 
00158 protected:
00159   // The following routines create a state transition matrix from a list
00160   // of all defined transitions. It uses the following information:
00161   // <ul>
00162   //  <li> nrout: the number of transitions; numbered 0, ...
00163   //  <li> ntyp: the number of states
00164   //  <li> list: a [nrout][3] list of input and output transition type of
00165   //            transition and a penalty hop number (<100)
00166   //  <li> state: a [ntyp][ntyp] transition matrix with diagonal elements set
00167   //            to nrout.
00168   // </ul>
00169   // <group>
00170   // Routine to make the transition table if necessary
00171   static void makeState(uInt *state,
00172                         const uInt ntyp, const uInt nrout,
00173                         const uInt list[][3]);
00174   // Return a fromatted String with matrix information (based on < 100 types)
00175   static String showState(uInt *state,
00176                           const uInt ntyp, const uInt nrout,
00177                           const uInt list[][3]);
00178 private:
00179   // Routine to find the shortest route between two points 
00180   static Bool findState(uInt &len, uInt *state, uInt *mcnt, Bool &okall,
00181                         Bool *visit, const uInt *tcnt, const uInt *tree,
00182                         const uInt &in, const uInt &out,
00183                         const uInt ntyp, const uInt nrout,
00184                         const uInt list[][3]);
00185   // </group>
00186 
00187 };
00188 
00189 
00190 } //# NAMESPACE CASA - END
00191 
00192 #endif