casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
MFrequency.h
Go to the documentation of this file.
00001 //# MFrequency.h: A Measure: wave characteristics
00002 //# Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003
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: MFrequency.h 21298 2012-12-07 14:53:03Z gervandiepen $
00028 
00029 #ifndef MEASURES_MFREQUENCY_H
00030 #define MEASURES_MFREQUENCY_H
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <measures/Measures/MeasBase.h>
00035 #include <measures/Measures/MeasRef.h>
00036 #include <casa/Quanta/MVFrequency.h>
00037 
00038 namespace casa { //# NAMESPACE CASA - BEGIN
00039 
00040 //# Forward Declarations
00041 class MFrequency;
00042 class MCFrequency;
00043 class MDoppler;
00044 class MVDoppler;
00045 template <class M> class MeasConvert;
00046 template <class M> class ArrayMeasColumn;
00047 template <class M> class ScalarMeasColumn;
00048 
00049 //# Typedefs
00050 
00051 // <summary>
00052 // A Measure: wave characteristics
00053 // </summary>
00054 
00055 // <use visibility=export>
00056 
00057 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tMeasure" demos="">
00058 // </reviewed>
00059 
00060 // <prerequisite>
00061 //   <li> <linkto class=Measure>Measure</linkto> class 
00062 //   <li> <linkto class = MRadialVelocity>MRadialVelocity</linkto> class
00063 //              for some other background.
00064 // </prerequisite>
00065 //
00066 // <etymology>
00067 // </etymology>
00068 //
00069 // <synopsis>
00070 // MFrequency is a derived Measure class for wave characteristics.<br>
00071 // An MFrequency can be generated from a simple value (or an
00072 // <linkto class=MVFrequency>MFrequency</linkto> object), which is then
00073 // interpreted as a frequency in Hz, and a reference, with an LSRK type
00074 // as default.<br>
00075 // It can also be generated from a Quantity, where the interpretation
00076 // depends on the dimensionality of the Quantity:
00077 // <ul>
00078 // <li> time (e.g. s): period
00079 // <li> frequency (e.g. Hz): frequency
00080 // <li> angular frequency (e.g. arcmin/s): angular frequency
00081 // <li> length (e.g. cm): wavelength
00082 // <li> inverse length (e.g. mm<sup>-1</sup>): wave number
00083 // <li> energy (e.g. J.s): energy (i.e. <em>h.nu</em>)
00084 // <li> momentum (e.g. kg.m): <em>m.c/h</em>
00085 // </ul>
00086 // The different reference types of a frequency are:
00087 // <ul>
00088 //  <li> MFrequency::REST -- Rest frequency
00089 //  <li> MFrequency::LSRD -- Local Standard of Rest (J2000) -- as the
00090 //              dynamical definition (IAU, [9,12,7] km/s in galactic
00091 //              coordinates)
00092 //  <li> MFrequency::LSRK -- LSR as a kinematical (radio) definition --
00093 //              20.0 km/s in direction ra,dec = [270,+30] deg (B1900.0)
00094 //  <li> MFrequency::BARY -- Barycentric (J2000)
00095 //  <li> MFrequency::GEO --- Geocentric
00096 //  <li> MFrequency::TOPO -- Topocentric
00097 //  <li> MFrequency::GALACTO -- Galacto centric (with rotation of 220 km/s
00098 //              in direction l,b = [90,0] deg.
00099 //  <li> MFrequency::LGROUP -- Local group velocity -- 308km/s towards
00100 //               l,b = [105,-7] deg (F. Ghigo)
00101 //  <li> MFrequency::CMB -- CMB velocity -- 369.5km/s towards
00102 //              l,b = [264.4, 48.4] deg (F. Ghigo)
00103 //  <li> MFrequency::DEFAULT = LSRK
00104 // </ul>
00105 // <p>
00106 // Conversion between the different types is done with the standard
00107 // <linkto class=MeasConvert>MeasConvert</linkto> class 
00108 // (<src>MFrequency::Convert</src> in this case). 
00109 // Some of the conversions are only possible if frame information has been 
00110 // filled in. The following frame information is necessary if a conversion
00111 // goes to or from the (different) specified types:
00112 // <ul>
00113 //  <li><em>Radial Velocity</em>: REST
00114 //  <li><em>Epoch</em>: TOPO, GEO
00115 //  <li><em>Position</em>: TOPO
00116 //  <li><em>Direction</em> all
00117 // </ul>
00118 // <br>
00119 // An MFrequency can be created from an
00120 // <linkto class=MDoppler>MDoppler</linkto> (and a rest frequency, (the
00121 // <linkto class=QC>QC</linkto> class contains at least <src>QC::HI</src>))
00122 // by the <src>fromDoppler()</src> member. It can be converted to an MDoppler
00123 // with the <src>toDoppler()</src>. Comparable methods will be available
00124 // for <linkto class=MFrequency>MFrequency</linkto> as 
00125 // <src>toRadial()</src> and <src>fromRadial</src>.<br>
00126 // If the Doppler shift is known (e.g. from another spectral line), the
00127 // REST frequency can be determined with the <src>toREST()</src> member.
00128 // <note role=caution> Conversion between the different frequencies can,
00129 // due to relativistic effects, only be done approximately for very high
00130 // (order c) radial velocities (shifted frequencies). A better approach
00131 // would be to start from radial velocities and a rest frequency.
00132 // </note>
00133 // </synopsis>
00134 //
00135 // <example>
00136 // Get the Doppler shift for an oberved HI frequency of 1380 MHz
00137 // <srcblock>
00138 //      cout << "Redshift for 1380 MHz: " <<
00139 //              MDoppler::Convert( MFrequency( Quantity(1380., "MHz"),
00140 //                                             MFrequency::TOPO).toDoppler(QC::HI),
00141 //                                 MDoppler::Z)() << endl;
00142 // </srcblock>                             
00143 // </example>
00144 //
00145 // <motivation>
00146 // </motivation>
00147 //
00148 // <todo asof="2003/03/03">
00149 // </todo>
00150 
00151 class MFrequency : public MeasBase<MVFrequency, MeasRef<MFrequency> > {
00152 
00153  public:
00154   //# Friends
00155   // Conversion of data
00156   friend class MeasConvert<MFrequency>;
00157 
00158   //# Enumerations
00159   // Types of known MFrequencies
00160   // <note role=warning> The order defines the order in the translation
00161   // matrix FromTo
00162   // in the getConvert routine. Do not change the order without
00163   // changing the array. Additions should be made before N_types, and
00164   // an additional row and column should be coded in FromTo, and
00165   // in showType().</note>
00166   enum Types {
00167     REST,
00168     LSRK,
00169     LSRD, 
00170     BARY,
00171     GEO,
00172     TOPO,
00173     GALACTO,
00174     LGROUP,
00175     CMB,
00176     N_Types,
00177     // Defaults
00178     DEFAULT=LSRK,
00179     // Synonyms
00180     LSR=LSRK };
00181 
00182   //# Typedefs
00183   // Measure value container for this class (i.e. MFrequency::MVType)
00184   typedef MVFrequency MVType;
00185   // Measure conversion routines for this class (i.e. MFrequency::MCType)
00186   typedef MCFrequency MCType;
00187   // Measure reference (i.e. MFrequency::Ref)
00188   typedef MeasRef<MFrequency> Ref;
00189   // Measure conversion use (i.e. MFrequency::Convert)
00190   typedef MeasConvert<MFrequency> Convert;
00191   // Measure table Columns (e.g., MFrequency::ScalarColumn)
00192   typedef ScalarMeasColumn<MFrequency> ScalarColumn;
00193   typedef ArrayMeasColumn<MFrequency> ArrayColumn;
00194   // Reference enum Types (included originally for gcc 2.95)  
00195   typedef WHATEVER_SUN_TYPEDEF(MFrequency) Types Types;
00196 
00197   //# Constructors
00198   // <note role=tip> In the following constructors and other functions, all 
00199   // <em>MeasRef</em> can be replaced with simple <src>Measure::TYPE</src>
00200   // where no offsets or frames are needed in the reference. </note>
00201   // Default constructor; generates a zero rest frequency
00202   MFrequency();
00203   // Create from data and reference
00204   // <group>
00205   MFrequency(const MVFrequency &dt);
00206   MFrequency(const MVFrequency &dt, const MFrequency::Ref &rf);
00207   MFrequency(const MVFrequency &dt, MFrequency::Types rf);
00208   MFrequency(const Quantity &dt);
00209   MFrequency(const Quantity &dt, const MFrequency::Ref &rf);
00210   MFrequency(const Quantity &dt, MFrequency::Types rf);
00211   MFrequency(const Measure *dt);
00212   MFrequency(const MeasValue *dt);
00213   // </group>
00214   
00215   //# Destructor
00216   virtual ~MFrequency();
00217   
00218   //# Operators
00219   
00220   //# General Member Functions
00221   // Tell me your type
00222   // <group>
00223   virtual const String &tellMe() const;
00224   static const String &showMe();
00225   virtual uInt type() const;
00226   static void assure(const Measure &in);
00227   // </group>
00228   // Translate reference code. The uInt version has a check for valid codes
00229   // (i.e. it is a safe cast).
00230   // <thrown>
00231   //   <li> AipsError in the uInt interface if illegal code given
00232   // </thrown>
00233   // <group>
00234   static MFrequency::Types castType(uInt tp);
00235   static const String &showType(MFrequency::Types tp);
00236   static const String &showType(uInt tp);
00237   // </group>
00238   // Translate string to reference code
00239   // <group>
00240   static Bool getType(MFrequency::Types &tp, const String &in);
00241   Bool giveMe(MFrequency::Ref &mr, const String &in);
00242   // </group>
00243   // Set the offset in the reference (False if non-matching Measure)
00244   virtual Bool setOffset(const Measure &in);
00245   // Set the reference type to the specified String. False if illegal
00246   // string, reference set to DEFAULT.
00247   virtual Bool setRefString(const String &in);
00248   // Get the default reference type
00249   virtual const String &getDefaultType() const;
00250   // Get a list of all known reference codes. nall returns the number in list,
00251   // nextra the number of specials (like planets) that should be at 
00252   // end of list). typ returns the list of corresponding types.
00253   // <group>
00254   virtual const String* allTypes(Int &nall, Int &nextra,
00255                                  const uInt *&typ) const;
00256   static const String* allMyTypes(Int &nall, Int &nextra,
00257                                   const uInt *&typ);
00258   // </group>
00259   // Check if all internal tables of types (both enum and String) are 
00260   // complete and correct. This function is called automatically if and when
00261   // necessary.
00262   // <thrown>
00263   //   <li> AipsError if a (programming) error in the types.
00264   // </thrown>
00265   // <group> 
00266   virtual void checkTypes() const;
00267   static void checkMyTypes();
00268   // </group>
00269   // Get the reference type (for records, including codes like R_)
00270   virtual String getRefString() const;
00271   // Get my type (as Register)
00272   static uInt myType();
00273   
00274   // Get frequency in specified units
00275   Quantity get(const Unit &un) const;
00276   
00277   // Make a Doppler velocity from the frequency and the specified rest frequency
00278   // <group>
00279   MDoppler toDoppler(const MVFrequency &rest);
00280   MDoppler toDoppler(const MVFrequency &rest) const;
00281   // </group>
00282   // Local use only
00283   static MDoppler toDoppler(const Measure &in, const MVFrequency &rest);
00284   // Make a frequency from the Doppler velocity and the specified rest frequency
00285   // (default reference type LSRK)
00286   // <group>
00287   static MFrequency fromDoppler(const MDoppler &dop,
00288                                 const MVFrequency &rest);
00289   static MFrequency fromDoppler(const MDoppler &dop,
00290                                 const MVFrequency &rest,
00291                                 MFrequency::Types type);
00292   // For internal use only
00293   static MFrequency fromDoppler(const Measure &dop,
00294                                 const MVFrequency &rest,
00295                                 MFrequency::Types type);
00296   // </group>
00297   
00298   // Make a rest frequency using a Doppler velocity
00299   MFrequency toRest(const MDoppler &dop);
00300   // For local use only
00301   static MFrequency toRest(const Measure &in, const Measure &dop);
00302   
00303   // Make a copy
00304   // <group>
00305   virtual Measure *clone() const;
00306   // </group>
00307   
00308  private:
00309   //# Enumerations
00310   
00311   //# Data
00312   
00313   //# Member functions
00314   
00315 };
00316 
00317 
00318 } //# NAMESPACE CASA - END
00319 
00320 #endif