Importmiriad.h

Go to the documentation of this file.
00001 //# Importmiriad: miriad dataset to MeasurementSet conversion
00002 //# Copyright (C) 1997,2000,2001,2002,2013,2015
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This program is free software; you can redistribute it and/or modify
00006 //# it under the terms of the GNU General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or
00008 //# (at your option) any later version.
00009 //#
00010 //# This program is distributed in the hope that it will be useful,
00011 //# but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 //# GNU General Public License for more details.
00014 //# 
00015 //# You should have received a copy of the GNU General Public License
00016 //# along with this program; if not, write to the Free Software
00017 //# Foundation, Inc., 675 Masve, Cambridge, MA 02139, USA.
00018 //#
00019 
00020 #ifndef MIRIAD_IMPORTMIRIAD_H
00021 #define MIRIAD_IMPORTMIRIAD_H
00022 
00023 //#Includes
00024 
00025 #include <casa/Inputs/Input.h>
00026 #include <casa/OS/File.h>
00027 #include <casa/Utilities/GenSort.h>
00028 
00029 #include <casa/Arrays/Cube.h>
00030 #include <casa/Arrays/Matrix.h>
00031 #include <casa/Arrays/Vector.h>
00032 #include <casa/Arrays/ArrayMath.h>
00033 #include <casa/Arrays/ArrayUtil.h>
00034 #include <casa/Arrays/ArrayLogical.h>
00035 #include <casa/Arrays/MatrixMath.h>
00036 
00037 #include <measures/Measures.h>
00038 #include <measures/Measures/MPosition.h>
00039 #include <measures/Measures/MeasData.h>
00040 #include <measures/Measures/Stokes.h>
00041 
00042 #include <tables/Tables.h>
00043 #include <tables/Tables/TableInfo.h>
00044 
00045 #include <ms/MeasurementSets.h> 
00046 
00047 #include <mirlib/maxdimc.h>
00048 #include <mirlib/miriad.h>
00049 
00050 #include <casa/namespace.h>
00051 namespace casa { //# NAMESPACE CASA - BEGIN
00052 
00053 
00054 // MIRIAD dataset MeasurementSet filler. Derived from carmafiller.
00055 //
00056 // Despite that this program is written in C++ and uses classes, it is
00057 // really a set of routines manipulating a huge common block.....
00058 //
00059 // Acknowledgement: this program was originally cloned off uvfitsfiller.cc
00060 //                  whose code is now in MSFitsInput.cc
00061 //                  Ray Plante wrote the other filler, with which we had
00062 //                  some cross talk
00063 // 
00064 //
00065 // Limitations, Caveats and Remaining ToDo's
00066 //    - does not apply the various (miriad) complex gain corrections
00067 //      (uvcat and friends should be used for that in miriad, it would be
00068 //      silly to duplicate that code here)
00069 //    - this code won't run if Double!=double or Float!=float or Int!=int
00070 //      On some future 64bit machines this may cause problems?
00071 //    - CARMA type arrays when dishes are not the same size
00072 //    - do not mix arrays from different telescopes (e.g. BIMA and ATCA)
00073 //      but it should handle different configurations (ARRAYs) of the same
00074 //      instrument
00075 //    - handle multiple array configuration datasets that were UVCAT'ed
00076 //      (needs to count antennae up at each array configuration)
00077 //    - true miriad storage manager ?
00078 //
00079 //    - check UV override, is that being handled transparently?
00080 //
00081 //    - spectral windows layout  (code present, fix table access descriptors) 
00082 //      CHECK: what happens if e.g. uvcat does some line= preprocessing
00083 //    - correct restfreq's in source tables that relate to the spectral windows
00084 //      (this code currently coredumps)
00085 //    - make win=,narrow=,wide=0 cause non of them to be written in that selection
00086 //    - add weather table
00087 //    - although no more wides are written, there is a way to make a small MS
00088 //      from the wides only by preprocessing in miriad, but conceivably
00089 //      could be done here as well??  -- except the narrow= keyword seems to write
00090 //      files that suffer from the Table array conformance error
00091 //
00092 //      Todo: to deal with multiple zoom setups (freq changes), we need
00093 //      to track which spectral windows each source appears to make a proper
00094 //      source table indexed by source id and spw id
00095 
00096 
00097 //  History:
00098 //   Spring 1997:   written (cloned off uvfitsfiller)          Peter Teuben
00099 //   July 1997:     Y2K, fixed table-interface                          PJT
00100 //   Dec 1997:      fixed wideband only data (e.g. uvgen)               PJT
00101 //   ???            somebody fixed up this code for some new release    ???
00102 //   May 2000:      fixed up for various new AIPS++ conventions         PJT
00103 //                  and added multi-source & field                      PJT
00104 //   Sep 2000:      development now on linux, converted to OldMS        PJT
00105 //   Dec 2000:      Conversion to MS (MS2)                              PJT
00106 //                  typical compile time: (P600/256M/15MBps HD: 36")
00107 //                  typical 3c273 conversion time:  2.6" (5.3->11.3 MB)
00108 //                  Cf. that to "uvio" processing time, which runs at disk I/O
00109 //                  speed (15 MB/s on the beforementioned laptop)
00110 //   Jan-Feb 2001:  window layout, restfreq's and various things to get 
00111 //                  msmultiscale to work; added some syscal support     PJT
00112 //   April 2001:    final cleanup for the 1.5 AIPS++ release -          PJT
00113 //                  [note that from this moment on bimafiller is for
00114 //                   experimental use and deprecated, the new version
00115 //                   will be called 'mirfiller'
00116 //   Oct 2001:      mirlib changed location
00117 //   Sep 2009:      revived in CASA, added various tables for CARMA
00118 //                  also renamed from bimafiller to carmafiller
00119 //   Sep 2011:      initial release
00120 //   Mar 2013:      Rename to importmiriad and make it work for ATCA 
00121 //                  CABB data (more channels, windows and 4 pols)       MHW
00122 //   May 2014:      Fix some compiler warnings, add TOPO option         MHW
00123 //   Jul 2015:      Cope with data with changing freq setups,e.g.,
00124 //                  CABB zoom data with multiple sources                MHW
00125 //   Jan 2016       Turn from standalone app into tool+task             MHW
00126 
00127 // a placeholder for the MIRIAD spectral window configuration
00128 // see also the MIRIAD programmers guide, and its appendix on UV Variables 
00129 // for CARMA we have MAXWIN = MAXWIDE (16 normally, 6 in 2006-2009, more later)
00130 // narrow band (plus MAXWIDE space to point into the wide band data too)
00131 
00132 typedef struct window {     // CASA defines everything mid-band mid-interval
00133   int    nspect;                   // number of valid windows (<=MAXWIN, typically 16)
00134   int    nschan[MAXWIN+MAXWIDE];   // number of channels in a window
00135   int    ischan[MAXWIN+MAXWIDE];   // starting channel of a window (1-based)
00136   double sdf[MAXWIN+MAXWIDE];      // channel separation 
00137   double sfreq[MAXWIN+MAXWIDE];    // frequency of first channel in window (doppler changes)
00138   double restfreq[MAXWIN+MAXWIDE]; // rest freq, if appropriate
00139   char   code[MAXWIN+MAXWIDE];     // code to CASA identification (N, W or S; S not used anymore)
00140 
00141   // wide band (for CARMA these are the spectral window averages - i.e. nspect=nwide)
00142   int    nwide;                    // number of wide band channels
00143   float  wfreq[MAXWIDE];           // freq
00144   float  wwidth[MAXWIDE];          // width
00145   // ifchain for ATCA
00146   int    chain[MAXWIN+MAXWIDE];    // if conversion chain
00147 
00148 
00149 } WINDOW;
00150 
00151 //  the maximum number of fields in mosaicing observations, careful, miriad
00152 //  often has a smaller value, like 64 or 128.
00153 #ifndef MAXFIELD
00154 # define MAXFIELD  10000
00155 #endif
00156 
00157 #ifndef MAXMSG
00158 # define MAXMSG 256
00159 #endif
00160 
00161 #ifndef MAXFSET
00162 # define MAXFSET 100
00163 #endif
00164 
00165 // a helper class 
00166 
00167 class Importmiriad
00168 {
00169   // This is an implementation helper class used to store 'local' data
00170   // during the filling process.
00171 public:
00172   // Create from a miriad dataset (a directory)
00173   Importmiriad(String& infile, Int debug=0, 
00174               Bool Qtsys=False,
00175               Bool Qarrays=False,
00176               Bool Qlinecal=False);
00177 
00178   // Standard destructor
00179   ~Importmiriad();
00180   
00181   // Check some of the contents of the data and header read
00182   void checkInput(Block<Int>& spw, Block<Int>& wide);
00183 
00184   // Debug output level
00185   Bool Debug(int level);
00186 
00187   // Set up the MeasurementSet, including StorageManagers and fixed columns.
00188   // If useTSM is True, the Tiled Storage Manager will be used to store
00189   // DATA, FLAG and WEIGHT_SPECTRUM
00190   void setupMeasurementSet(const String& MSFileName, Bool useTSM=True);
00191 
00192   // Fill the main table by reading in all the visibilities
00193   void fillMSMainTable();
00194 
00195   // Make an Antenna Table (can be called incrementally now)
00196   void fillAntennaTable();
00197 
00198   // Make a Syscal Table (can be called incrementally)
00199   void fillSyscalTable();
00200 
00201   // fill Spectralwindow table 
00202   void fillSpectralWindowTable(String vel);
00203 
00204   // fill Field table 
00205   void fillFieldTable();
00206 
00207   // fill Source table 
00208   void fillSourceTable();
00209 
00210   // fill the Feed table with minimal info needed for synthesis processing
00211   void fillFeedTable();
00212 
00213   // Fill the Observation and History (formerly ObsLog) tables
00214   void fillObsTables();
00215 
00216   // fix up the EPOCH MEASURE_REFERENCE keywords using the value found
00217   // in the (last) AN table - check if miriad really needs it
00218   void fixEpochReferences();
00219 
00220   void Tracking(int record);
00221   void check_window();
00222   Bool compareWindows(WINDOW& w1, WINDOW& w2);
00223   void Error(char *msg);
00224   void Warning(char *msg);
00225   void show();
00226   void close();
00227 
00228 private:
00229   String                 infile_p;     // filename
00230   Int                    uv_handle_p;  // miriad handle 
00231   MeasurementSet         ms_p;         // the MS itself
00232   MSColumns             *msc_p;        // handy pointer to the columns in an MS  
00233   Int                    debug_p;      // debug level
00234   String                 array_p, 
00235                          project_p, 
00236                          object_p, 
00237                          telescope_p, 
00238                          observer_p, 
00239                          version_p,
00240                          timsys_p;
00241   Vector<Int>            nPixel_p, corrType_p, corrIndex_p;
00242   Matrix<Int>            corrProduct_p;
00243   Double                 epoch_p;
00244   MDirection::Types      epochRef_p;
00245   Int                    nArray_p;      // number of arrays (nAnt_p.nelements())
00246   Block<Int>             nAnt_p;        // number of antennas per array
00247   Block<Vector<Double> > receptorAngle_p;
00248   Vector<Double>         arrayXYZ_p;    // needs to be made with 3 elements
00249   Vector<Double>         ras_p, decs_p; // ra/dec for source list (source_p)
00250   Vector<String>         source_p,      // list of source names (?? object_p ??)
00251                          purpose_p;     // purpose of this source 
00252   LogIO                  os_p;          // logger
00253 
00254 
00255   // the following variables are for miriad, hence not Double/Int/Float
00256   // thus the code may have to be fixed on machines where these do not
00257   // agree ... may need special access code to get those into CASA
00258   // types on 64 bit machines??
00259 
00260   double preamble[5], first_time;
00261   int    ifield, nfield, npoint, nsource;     // both dra/ddec should become Vector's
00262   float  dra[MAXFIELD], ddec[MAXFIELD];       // offset in radians
00263   double ra[MAXFIELD], dec[MAXFIELD];
00264   int    field[MAXFIELD];                     // source index
00265   int    fcount[MAXFIELD];
00266   float  dra_p=0, ddec_p=0;
00267   int    pol_p[4];
00268   char   message[MAXMSG];
00269 
00270 
00271   // The following items more or less follow the uv variables in a dataset
00272   Int    nants_p, nants_offset_p, nchan_p, nwide_p, npol_p;
00273   Double antpos[3*MAXANT];
00274   Float  phasem1[MAXANT];
00275   Double ra_p, dec_p;       // current pointing center RA,DEC at EPOCH 
00276   Float  inttime_p, jyperk_p;
00277   Double freq_p;            // rest frequency of the primary line
00278   Int    mount_p;
00279   Double time_p;            // current MJD time
00280   Double timeFirst_p;       // First MJD time encountered
00281 
00282   // MIRIAD spectral window definition
00283   Int    freqSet_p,nFreqSet_p,ddid_p;
00284   WINDOW win[MAXFSET];  // allow for 16 different frequency setups
00285   
00286   Bool   Qtsys_p;    /* tsys weight's */
00287   Bool   Qarrays_p;  /* write separate arrays */
00288   Bool   Qlinecal_p; /* do linecal */
00289   Bool   keep[MAXWIN+MAXWIDE]; // keep this window for output to MS
00290 
00291   // Data buffers.... again in MIRIAD format
00292   
00293   float  data[2*MAXCHAN], wdata[2*MAXCHAN];     // 2*MAXCHAN since (Re,Im) pairs complex numbers
00294   int    flags[MAXCHAN], wflags[MAXCHAN];
00295   float  systemp[MAXANT*MAXWIDE];
00296   int    zero_tsys;
00297 
00298   // Counters
00299   int    nvis;
00300 };
00301 } // Namespace CASA - END
00302 
00303 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1