casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
EarthField.h
Go to the documentation of this file.
00001 //# EarthField.h: EarthField class model claculations
00002 //# Copyright (C) 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: EarthField.h 18093 2004-11-30 17:51:10Z ddebonis $
00028 
00029 #ifndef MEASURES_EARTHFIELD_H
00030 #define MEASURES_EARTHFIELD_H
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <casa/Arrays/Vector.h>
00035 #include <casa/Quanta/MVPosition.h>
00036 
00037 namespace casa { //# NAMESPACE CASA - BEGIN
00038 
00039 //# Forward Declarations
00040 
00041 //# Constants
00042 // Length of P and Q arrays, half length of CL/SL arrays in IGRF model
00043 const Int PQ_LEN = 65;
00044 // Interval (m) for derivatives in IGRF model
00045 const Double DER_INTV = 10000;
00046 
00047 // <summary> EarthField class model calculations </summary>
00048 
00049 // <use visibility=local>
00050 
00051 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tEarthField" demos="">
00052 // </reviewed>
00053 
00054 // <prerequisite>
00055 //   <li> <linkto class=Measure>Measure</linkto> class for use
00056 //   <li> <linkto class=MeasTable>MeasTable</linkto> class for data
00057 // </prerequisite>
00058 //
00059 // <etymology>
00060 // Earth magnetic Field model
00061 // </etymology>
00062 //
00063 // <synopsis>
00064 // EarthField forms the class for Earth magnetic field calculations. It is a 
00065 // simple container with the selected model, and the mean epoch.<br>
00066 // The method is selected from one of the following:
00067 // <ul>
00068 //   <li> EarthField::STANDARD  (at 1998/05/18 the IGRF definition)
00069 //   <li> EarthField::IGRF      (IGRF reference field model)
00070 // </ul>
00071 // Epochs can be specified as the MJD (with defined constants
00072 // MeasData::MJD2000 and MeasData::MJD1950 or the actual MJD),
00073 // leading to the following constructors:
00074 // <ul>
00075 //   <li> EarthField() default; assuming IGRF and MJD2000
00076 //   <li> EarthField(method); assuming J2000 as epoch
00077 //   <li> EarthField(method, epoch) with epoch Double(MJD)
00078 // </ul>
00079 // Actual EarthField for a certain position on Earth is calculated by the () 
00080 // operator. Arguments can be:
00081 // <ul>
00082 //   <li> MVPosition: a position on Earth (in the ITRF frame)
00083 // </ul>
00084 // The returned value is a 3D vector of the field (in nT) in ITRF coordinates.
00085 // The derivative (d<sup>-1</sup>) can be obtained as well by 
00086 // derivative(MVPosition). <br>
00087 // An EarthField can be re-initialised with a different method and/or other
00088 // epoch with the <src>init()</src> functions (same format as constructors).
00089 //
00090 // To bypass the full, lengthy calculation actual returned values are calculated
00091 // using the derivative if within about 50 km (error less than about
00092 // 10<sup>-2</sup> G). A call to refresh() will re-initiate calculations
00093 // from scratch.<br>
00094 // The following details can be set with the 
00095 // <linkto class=Aipsrc>Aipsrc</linkto> mechanism:
00096 // <ul>
00097 //  <li> measures.earthfield.d_interval: approximation radius
00098 //      (km is default unit) over which a linear approximation
00099 //      is used
00100 // </ul>
00101 // The field model is assumed to be constant over the time-span the class
00102 // is used.
00103 //
00104 // The calculations are based on a routine provided by the IGRF community. See
00105 // ftp.ngdc.noaa.gov/Solid_Earth/Mainfld_Mag/Models/IAGA, routine IGRFLIB.FOR.
00106 // The values are in nT (10uG).
00107 // </synopsis>
00108 //
00109 // <example>
00110 //  <srcblock>
00111 //      EarthField mine(EarthField::STANDARD,
00112 //                      45837.0);               // define EarthField type
00113 //                                              // for 84/05/17
00114 //      MPosition pos;
00115 //      MeasTable::Observatory(pos, "WSRT");    // Obervatory position
00116 //  // Make sure correct position frame used
00117 //      MVPosition x(MPosition::Convert(pos, MPosition::ITRF)().getValue());
00118 //      MVEarthMagnetic now = mine(x);          // get EarthField
00119 //  </srcblock>
00120 // </example>
00121 //
00122 // <motivation>
00123 // To have a container (with history) for field calculations
00124 // </motivation>
00125 //
00126 // <todo asof="1998/05/18">
00127 //   <li> nothing I know off
00128 // </todo>
00129 
00130 class EarthField {
00131 
00132 public:
00133 
00134   //# Constants
00135   // Default interval to be used for linear approximation (in m)
00136   static const Double INTV;
00137 
00138   //# Enumerations
00139   // Known EarthField calculation models
00140   enum EarthFieldTypes {
00141     // Standard IGRF model
00142     IGRF,
00143     // Make the field equal to zero
00144     NONE,
00145     // Standard default model if none specified
00146     STANDARD = IGRF
00147   };
00148 
00149   //# Constructors
00150   // Default constructor, generates default J2000 EarthField identification
00151   EarthField();
00152   // Copy constructor
00153   EarthField(const EarthField &other);
00154   // Constructor with epoch in MJulian days (default is J2000) 
00155   explicit EarthField(EarthFieldTypes model, Double catepoch=51544.5);
00156   // Copy assignment
00157   EarthField &operator=(const EarthField &other);
00158   
00159   //# Destructor
00160   ~EarthField();
00161   
00162   //# Operators
00163   // Return the EarthField components. Note that the value returned has only
00164   // a lifetime as long as the EarthField container exists, and no new
00165   // derivative is asked for.
00166   const Vector<Double> &operator()(const MVPosition &pos);
00167   
00168   //# General Member Functions
00169   // Return derivatives of field (to X, Y, Z). Note that the value returned
00170   // has only a lifetime as long as the EarthField container exists, and
00171   // no new components or derivative is calculated. The returned value should
00172   // not be deleted.
00173   const Vector<Double> *derivative(const MVPosition &pos);
00174   // Re-initialise EarthField object with specified model and epoch, or
00175   // defaults STANDARD and J2000.
00176   // <group>
00177   void init();
00178   void init(EarthFieldTypes model, Double catepoch=51544.5);
00179   // </group>
00180   // Refresh calculations
00181   void refresh();
00182   
00183   private:
00184   //# Data members
00185   // Method to be used
00186   EarthFieldTypes method_p;
00187   // Fixed epoch to be used (MJD)
00188   Double fixedEpoch_p;
00189   // List of spherical components
00190   Vector<Double> agh_p;
00191   // Work arrays for calculations
00192   // <group>
00193   Vector<Double> p_p;
00194   Vector<Double> q_p;
00195   Vector<Double> cl_p;
00196   Vector<Double> sl_p;
00197   // </group>
00198   // Check position
00199   MVPosition checkPos_p;
00200   // Cached calculated field components
00201   Double pval_p[3];
00202   // Cached derivatives
00203   Double dval_p[3][3];
00204   // To reference results, and use a few in interim calculations, results are
00205   // calculated in a circular buffer.
00206   // Current result pointer
00207   Int lres_p;
00208   // Last calculation
00209   Vector<Double> result_p[4];
00210   // Interpolation interval
00211   static uInt interval_reg_p;
00212 
00213   //# Member functions
00214   // Make a copy
00215   void copy(const EarthField &other);
00216   // Create correct default fixedEpoch and catalogue field data
00217   void fillField();
00218   // Calculate EarthField for longitude and latitude and altitude (m)
00219   void calcField(const MVPosition &pos);
00220 
00221 };
00222   
00223 
00224 } //# NAMESPACE CASA - END
00225 
00226 #endif
00227 
00228