casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
MBFITSreader.h
Go to the documentation of this file.
00001 //#---------------------------------------------------------------------------
00002 //# MBFITSreader.h: ATNF single-dish RPFITS reader.
00003 //#---------------------------------------------------------------------------
00004 //# livedata - processing pipeline for single-dish, multibeam spectral data.
00005 //# Copyright (C) 2000-2009, Australia Telescope National Facility, CSIRO
00006 //#
00007 //# This file is part of livedata.
00008 //#
00009 //# livedata is free software: you can redistribute it and/or modify it under
00010 //# the terms of the GNU General Public License as published by the Free
00011 //# Software Foundation, either version 3 of the License, or (at your option)
00012 //# any later version.
00013 //#
00014 //# livedata is distributed in the hope that it will be useful, but WITHOUT
00015 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00016 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
00017 //# more details.
00018 //#
00019 //# You should have received a copy of the GNU General Public License along
00020 //# with livedata.  If not, see <http://www.gnu.org/licenses/>.
00021 //#
00022 //# Correspondence concerning livedata may be directed to:
00023 //#        Internet email: mcalabre@atnf.csiro.au
00024 //#        Postal address: Dr. Mark Calabretta
00025 //#                        Australia Telescope National Facility, CSIRO
00026 //#                        PO Box 76
00027 //#                        Epping NSW 1710
00028 //#                        AUSTRALIA
00029 //#
00030 //# http://www.atnf.csiro.au/computing/software/livedata.html
00031 //# $Id: MBFITSreader.h,v 19.23 2009-09-29 07:33:38 cal103 Exp $
00032 //#---------------------------------------------------------------------------
00033 //# The MBFITSreader class reads single dish RPFITS files (such as Parkes
00034 //# Multibeam MBFITS files).
00035 //#
00036 //# Original: 2000/07/28 Mark Calabretta
00037 //#---------------------------------------------------------------------------
00038 
00039 #ifndef ATNF_MBFITSREADER_H
00040 #define ATNF_MBFITSREADER_H
00041 
00042 #include <atnf/PKSIO/FITSreader.h>
00043 #include <atnf/PKSIO/MBrecord.h>
00044 
00045 using namespace std;
00046 
00047 // <summary>
00048 // ATNF single-dish RPFITS reader.
00049 // </summary>
00050 
00051 class MBFITSreader : public FITSreader
00052 {
00053   public:
00054     // Default constructor; position interpolation codes are:
00055     //   0: no interpolation,
00056     //   1: correct interpolation,
00057     //   2: pksmbfits interpolation.
00058     MBFITSreader(const int retry = 0, const int interpolate = 1);
00059 
00060     // Destructor.
00061     virtual ~MBFITSreader();
00062 
00063     // Open the RPFITS file for reading.
00064     virtual int open(
00065         char   *rpname,
00066         int    &nBeam,
00067         int*   &beams,
00068         int    &nIF,
00069         int*   &IFs,
00070         int*   &nChan,
00071         int*   &nPol,
00072         int*   &haveXPol,
00073         int    &haveBase,
00074         int    &haveSpectra,
00075         int    &extraSysCal);
00076 
00077     // Get parameters describing the data.
00078     virtual int getHeader(
00079         char   observer[32],
00080         char   project[32],
00081         char   telescope[32],
00082         double antPos[3],
00083         char   obsType[32],
00084         char   bunit[32],
00085         float  &equinox,
00086         char   radecsys[32],
00087         char   dopplerFrame[32],
00088         char   datobs[32],
00089         double &utc,
00090         double &refFreq,
00091         double &bandwidth);
00092 
00093     // Get frequency parameters for each IF.
00094     virtual int getFreqInfo(
00095         int     &nIF,
00096         double* &startFreq,
00097         double* &endFreq);
00098 
00099     // Find the range of the data selected in time and position.
00100     virtual int findRange(
00101         int    &nRow,
00102         int    &nSel,
00103         char   dateSpan[2][32],
00104         double utcSpan[2],
00105         double* &positions);
00106 
00107     // Read the next data record.
00108     virtual int read(MBrecord &record);
00109 
00110     // Close the RPFITS file.
00111     virtual void close(void);
00112 
00113   private:
00114     // RPFITSIN subroutine arguments.
00115     int   cBaseline, cFlag, cBin, cIFno, cSrcNo;
00116     float cUTC, cU, cV, cW, *cVis, *cWgt;
00117 
00118     char   cDateObs[12];
00119     int    *cBeamSel, *cChanOff, cFirst, *cIFSel, cInterp, cIntTime, cMBopen,
00120            cMopra, cNBeamSel, cNBin, cRetry, cSimulIF, cSUpos, *cXpolOff;
00121 
00122     // The data has to be bufferred to allow positions to be interpolated.
00123     int    cEOF, cEOS, cFlushBin, cFlushIF, cFlushing;
00124     double *cPosUTC;
00125     MBrecord *cBuffer;
00126 
00127     // Scan and cycle number bookkeeping.
00128     int    cCycleNo, cScanNo;
00129     double cPrevUTC;
00130 
00131     // Read the next data record from the RPFITS file.
00132     int rpget(int syscalonly, int &EOS);
00133     int rpfitsin(int &jstat);
00134 
00135     // Check and, if necessary, repair a position timestamp.
00136     int    cCode5, cNRate;
00137     double cAvRate[2];
00138     int fixw(const char *datobs, int cycleNo, int beamNo, double avRate[2],
00139              double thisRA, double thisDec, double thisUTC,
00140              double nextRA, double nextDec, float &nextUTC);
00141 
00142     // Subtract two UTCs (s).
00143     double utcDiff(double utc1, double utc2);
00144 
00145     // Compute and apply the scan rate corrected for grid convergence.
00146     double cRA0, cDec0;
00147     void  scanRate(double ra0, double dec0,
00148                    double ra1, double dec1,
00149                    double ra2, double dec2, double dt,
00150                    double &raRate, double &decRate);
00151     void applyRate(double ra0, double dec0,
00152                    double ra1, double dec1,
00153                    double raRate, double decRate, double dt,
00154                    double &ra2, double &dec2);
00155     void eulerx(double lng0, double lat0, double phi0, double theta,
00156                 double phi, double &lng1, double &lat1);
00157 };
00158 
00159 #endif