casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
GBTAntennaFile.h
Go to the documentation of this file.
00001 //# GBTAntennaFile.h: digest the FITS file holding GBT Antenna info
00002 //# Copyright (C) 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$
00028 
00029 #ifndef NRAO_GBTANTENNAFILE_H
00030 #define NRAO_GBTANTENNAFILE_H
00031 
00032 //#! Includes go here
00033 
00034 #include <nrao/FITS/GBTFITSBase.h>
00035 
00036 #include <casa/Containers/Record.h>
00037 #include <casa/Containers/SimOrdMap.h>
00038 #include <measures/Measures/MDirection.h>
00039 #include <measures/Measures/MPosition.h>
00040 #include <casa/Quanta/Quantum.h>
00041 #include <casa/Quanta/Unit.h>
00042 #include <tables/Tables/Table.h>
00043 #include <tables/Tables/TableColumn.h>
00044 #include <tables/Tables/ScalarColumn.h>
00045 #include <casa/BasicSL/String.h>
00046 
00047 #include <casa/namespace.h>
00048 //# Forward Declarations
00049 namespace casa { //# NAMESPACE CASA - BEGIN
00050 class MEpoch;
00051 template <class T> class Matrix;
00052 } //# NAMESPACE CASA - END
00053 
00054 
00055 // <summary>
00056 // GBTAntennaFile digests the FITS file holding GBT Antenna info
00057 // </summary>
00058 
00059 // <use visibility=export>
00060 
00061 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00062 // </reviewed>
00063 
00064 // <prerequisite>
00065 // </prerequisite>
00066 //
00067 // <etymology>
00068 // </etymology>
00069 //
00070 // <synopsis>
00071 // </synopsis>
00072 //
00073 // <example>
00074 // </example>
00075 //
00076 // <motivation>
00077 // </motivation>
00078 //
00079 //
00080 // <thrown>
00081 //#! A list of exceptions thrown if errors are discovered in the function.
00082 //#! This tag will appear in the body of the header file, preceding the
00083 //#! declaration of each function which throws an exception.
00084 //    <li>
00085 //    <li>
00086 // </thrown>
00087 //
00088 // <todo asof="yyyy/mm/dd">
00089 // </todo>
00090 
00091 class GBTAntennaFile : public GBTFITSBase
00092 {
00093 public:
00094 
00095     // This constructs a GBTAntennaFile that is not attached to any FITS file.
00096     // The indicated default values are returned for the function calls.
00097     GBTAntennaFile();
00098 
00099     // Construct a GBTAntennaFile attached to the indicated FITS file.
00100     // Warnings are sent to the logger if there is a problem with the file.
00101     // In such a case, the resulting object will not be attached to any
00102     // file.  In this way, such a file will be ignored and filling can
00103     // proceed - having notified the user of the problesm with that file.
00104     GBTAntennaFile(const String &antennaFile);
00105 
00106     // Copy constructor.
00107     GBTAntennaFile(const GBTAntennaFile &other);
00108 
00109     ~GBTAntennaFile();
00110 
00111     // Assignment operator, copy semantics.
00112     GBTAntennaFile &operator=(const GBTAntennaFile &other);
00113 
00114     // attach this object to a new antenna file.  If there are problems with the
00115     // file, the return value is False and appropriate warnings are sent to the
00116     // logger.  The resulting object is not attached to any file.
00117     Bool attach(const String &antennaFile);
00118 
00119     // Is this object attached to a FITS file.
00120     Bool isAttached() const {return itsAttached;}
00121 
00122     // The name of the attached FITS file.  Returns an empty string if
00123     // it is not attached.
00124     const String &file() const {return itsFileName;}
00125 
00126     // The value of the EXTNAME keyword for the ANTPOS* HDU.  This indicates 
00127     // the type of optics in use for this scan.  Possible values current include 
00128     // ANTPOSPF (prime focus), ANTPOSGR (Gregorian) and ANTPOSST (stow).  Defaults 
00129     // to an empty string if not attached.
00130     const String &opticsType() const {return itsExtname;}
00131 
00132     // The position as determined by the SITE* keywords.
00133     // This defaults to the value from MeasTable::Observatory for "GBT"
00134     const MPosition &position() const {return itsPosition;}
00135 
00136     // A record containing all of the keywords related to the pointing model.
00137     // This is all of the keywords not otherwise used plus an OPTICS_TYPE keyword
00138     // which holds the opticsType() for completeness.  Returns an empty record
00139     // if no file is attached.
00140     const Record &pointingModel() const {return itsPointingKeywords;}
00141 
00142     // compares the otherPointingModel record to this one.  Returns True if they
00143     // both contain exactly the same fields, with exactly the same types and values.
00144     Bool equalPointingModel(const RecordInterface &other) const;
00145 
00146     // The EQUINOX value, defaults to 2000.0 if not attached.  This is the equinox at
00147     // the start of the scan.
00148     Double equinox() const {return itsEquinox;}
00149 
00150     // The appropriate MDirection::Types given the RADECSYS keyword value.
00151     // Returns MDirection::DEFAULT if no file is attached as well as if
00152     // RADECSYS is "USER".  Use isUserType() to check if this is a USER 
00153     // defined coordinate system.  At this point, I don't know what to do with
00154     // such a coordinate system.
00155     MDirection::Types type() const {return itsCoordType;}
00156 
00157     // return the raw RADECSYS keyword value
00158     const String &radesys() const {return itsRadesys;}
00159 
00160     // return the raw INDICSYS keyword value
00161     const String &indicsys() const {return itsIndicsys;}
00162 
00163     // Returns TRUE if the INDICSYS keyword is "USER".
00164     Bool isUserCoordSys() const {return itsIsUser;}
00165 
00166     // Get the mean pointing values at the given time using the indicated
00167     // interval.  This finds the mean values in that interval centered on time.
00168     // Returns False if there is no table attached or if the interval falls
00169     // off of the end of the table.  In that case, the values are from
00170     // the nearest value at that particular end of the table.
00171     // If the requested interval falls completely between adjacent rows in
00172     // this table, a simple linear interpolation is used.
00173     Bool getPointing(Double time, Double interval,
00174                      MDirection &j2000, MDirection &user);
00175 
00176     // Fill the entire pointing information (RAJ2000, DECJ2000, MNT_AZ, MNT_EL,
00177     // MAJOR and MINOR, and REFRACT) to the indicated Table.  Columns are added as necessary.
00178     // The incremental storage manager is used.  The DMJD column is converted to
00179     // a TIME column of MEpoch in seconds.  Returns False if no file is attached.
00180     // Only Epochs after the last value of any TIME column in pointingTable will
00181     // be filled.
00182     Bool fillPointingTable(Table &pointingTable);
00183 
00184     // Get the mean focus values for the prime focus optics at the given
00185     // time using the indicated interval..  
00186     // Returns False if there is no table attached or if the interval falls off
00187     // the end of the table or if the optics type is not that of prime focus.
00188     // If the requested interval falls completely between adjacent rows in the
00189     // table, a simple linear interpolation is used.
00190     Bool getPrimeFocus(Double time, Double interval, Quantity &focus, Quantity &rotation,
00191                        Quantity &x);
00192 
00193     // Get the mean focus values for the gregorian optics at the given
00194     // time using the indicated interval..  
00195     // Returns False if there is no table attached or if the interval falls off
00196     // the end of the table or if the optics type is not that of prime focus.
00197     // If the requested interval falls completely between adjacent rows in the
00198     // table, a simple linear interpolation is used.
00199     Bool getGregorianFocus(Double time, Double interval, 
00200                            Quantity &xp, Quantity &yp, Quantity &zp,
00201                            Quantity &xt, Quantity &yt, Quantity &zt);
00202 
00203     // Fill the entire focus information to the indicated Table.  Columns are addded
00204     // as necessary.  The incremental storage manager is used.  The DJMD column is
00205     // converted to a TIME column of MEpoch in seconds.  Returns False if no file
00206     // is attached.  Only times after the last value of any TIME column in 
00207     // focusTable will be filled. 
00208     Bool fillFocusTable(Table &focusTable);
00209 
00210     // return the beam offset table - defauls to an empty table
00211     const Table &beamOffsetTable() const { return itsBeamOffTable ? *itsBeamOffTable : emptyTable;}
00212 
00213     // For a given physical feed number, return the corresponding offsets
00214     // srfeed1 and srfeed2, and name.  Returns -1 if that feed isn't found.
00215     Bool getFeedInfo(Int whichFeed, Double &xeloffset, Double &eloffset,
00216                      Int &srfeed1, Int &srfeed2, String &feedName) const;
00217 
00218     // how many physical feeds are present
00219     uInt nfeeds() const { return itsRowFromFeed.ndefined();}
00220 
00221     // get feed value from number, starting from 0 through (nfeeds-1), this
00222     // can be used in getFeedInfo - returns -1 if outside of the range
00223     Int getFeedValue(uInt feedNumber) const
00224     { return (feedNumber < nfeeds()) ? itsRowFromFeed.getKey(feedNumber) : -1; }
00225 
00226     // return the tracking beam name
00227     const String trckbeam() const { return itsTrckBeam;}
00228 
00229 private:
00230     //# it seems necessary to put the antenna table contents into a scratch table
00231     Table *itsTable;
00232 
00233     //# the Beam Offset table
00234     Table *itsBeamOffTable;
00235 
00236     //# and empty table, in case there is no beam offset table present
00237     Table emptyTable;
00238 
00239     //# name of Antenna file
00240     String itsFileName;
00241 
00242     //# is it attached?
00243     Bool itsAttached;
00244 
00245     //# keyword based fields
00246     String itsExtname;
00247     MPosition itsPosition;
00248     Record itsPointingKeywords;
00249     Double itsEquinox;
00250     MDirection::Types itsCoordType;
00251     Bool itsIsUser;
00252     String itsRadesys;
00253     String itsIndicsys;
00254 
00255     //# pointing columns
00256     ROScalarColumn<Double> itsDMJD, itsRAJ2000, itsDECJ2000, itsMAJOR, itsMINOR,
00257         itsMNT_AZ, itsMNT_EL, itsREFRACT;
00258     //# Units for those columns
00259     Unit itsDMJDunit, itsRAunit, itsDECunit, itsMAJORunit, itsMINORunit,
00260         itsMNT_AZunit, itsMNT_ELunit, itsREFRACTunit;
00261 
00262     //# focus columns, not all of these will be used
00263     ROScalarColumn<Double> itsFOCUS, itsROTATION, itsX, itsXP, itsYP, itsZP, 
00264         itsXT, itsYT, itsZT;
00265     //# Units for those columns
00266     Unit itsFOCUSunit, itsROTATIONunit, itsXunit, itsXPunit, itsYPunit, itsZPunit,
00267         itsXTunit, itsYTunit, itsZTunit;
00268 
00269     Double itsLastTime, itsLastInterval, itsLastStartTime, itsLastEndTime;
00270     uInt itsLastStart, itsLastEnd, itsLastReturnedStart, itsLastReturnedEnd;
00271 
00272     Double itsSecondsPerDay;
00273 
00274     SimpleOrderedMap<Int, Int> itsRowFromFeed;
00275 
00276     ScalarColumn<String> itsFeedNameCol;
00277     ScalarColumn<Double> itsXELOffCol, itsELOffCol;
00278     ScalarColumn<Int> itsSR1Col, itsSR2Col;
00279 
00280     String itsTrckBeam;
00281 
00282     // set the default values for internals
00283     void setDefaults();
00284 
00285     // digest the EXTNAME=ANTPOS* 
00286     void digestAntPosTab(FITSTable &antpostab, const String &extname);
00287 
00288     // digest the BEAM_OFFSETS table
00289     void digestBeamOffTab(FITSTable &beamofftab);
00290 
00291     // find the first and last row numbers given the
00292     // indicated time and interval - this assumes that this is attached
00293     // and that there are rows in the output table
00294     Bool findTimeRange(Double time, Double interval, uInt &startRow, uInt &endRow);
00295 
00296     // get the mean value of the indicated column over the indicate row range.
00297     // canWrap should be true if this is an angle which might go through 360/0
00298     Double getMean(ROScalarColumn<Double> &col, uInt startRow, uInt endRow,
00299                    Bool canWrap=False);
00300 
00301     // get the interpolated value of the indicated column.  Value is found assuming
00302     // a linear intepolation between the values at the low and high row with the
00303     // desired value being that at low+fraction. canWrap should be true if this
00304     // is an angle which might go through 360/0.
00305     Double getInterpolated(ROScalarColumn<Double> &col, uInt low, uInt high, 
00306                            Double fraction, Bool canWrap=False);
00307 };
00308 
00309 #endif
00310 
00311