00001 //# FITSIDItoMS.h: Convert a FITS-IDI binary table to an AIPS++ Table. 00002 //# Copyright (C) 1995,1996,2000,2001 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 //# $Id$ 00027 //# Mod 2010: DP 00028 00029 #ifndef MS_FITSIDITOMS_H 00030 #define MS_FITSIDITOMS_H 00031 00032 #include <casacore/casa/aips.h> 00033 #include <casacore/fits/FITS/hdu.h> 00034 #include <casacore/tables/Tables/Table.h> // 00035 #include <casacore/tables/Tables/TableDesc.h> // 00036 #include <casacore/tables/Tables/TableRecord.h> // 00037 #include <casacore/tables/Tables/TableColumn.h> // 00038 #include <casacore/casa/Containers/SimOrdMap.h> // 00039 #include <casacore/casa/Arrays/Vector.h> 00040 #include <casacore/casa/Arrays/Matrix.h> 00041 #include <casacore/casa/Containers/Block.h> 00042 #include <casacore/casa/Logging/LogIO.h> 00043 #include <casacore/measures/Measures/MFrequency.h> 00044 #include <casacore/ms/MeasurementSets/MeasurementSet.h> 00045 #include <casacore/casa/BasicSL/String.h> 00046 namespace casacore { //# NAMESPACE CASACORE - BEGIN 00047 00048 class MSColumns; 00049 class FitsInput; 00050 00051 00052 // <summary> 00053 // FITSIDItoMS converts a FITS-IDI file to a CASA Measurement Set 00054 // </summary> 00055 00056 // <use visibility=export> 00057 00058 // <reviewed reviewer="" date="" tests=""> 00059 00060 // <prerequisite> 00061 //# Classes you should understand before using this one. 00062 // <li> FitsInput 00063 // <li> HeaderDataUnit 00064 // <li> BinaryTableExtension 00065 // <li> Tables module 00066 // </prerequisite> 00067 00068 // <etymology> 00069 00070 // FITSIDItoMS inherits from the FITS BinaryTableExtension class and 00071 // its primary use is to convert such an object to a CASA Table. 00072 // This explains it's use but not its name. A better name should be 00073 // found. 00074 00075 // </etymology> 00076 00077 // <synopsis> 00078 // The class starts with an already existing FitsInput object, which 00079 // should be set at a BinaryTableExtension HDU. Member functions 00080 // provide a TableDesc appropriate for the FITS data (to help in 00081 // constructing a CASA Table compatible with the 00082 // BinaryTableExtension), a Table containing the current row of FITS 00083 // data and a Table containing the next row of FITS data (which can be 00084 // used to step through the FitsInput, copying each row using the 00085 // RowCopier class), and a Table containin the entire FITS binary 00086 // table from the current row to the end of the table. 00087 // </synopsis> 00088 00089 // <motivation> 00090 // We need a way to get FITS-IDI data (typically from VLBI observations) into CASA. 00091 // </motivation> 00092 00093 // <example> 00094 // Open a FitsInput from a disk file, if the HDU is a 00095 // BinaryTableExtension, then instantiate a MSBinaryTable object and 00096 // get the entire table. A fair amount of error checking has been 00097 // eliminated from this example. 00098 // <srcblock> 00099 // FitsInput infits("myFITSFile", FITS::Disk); 00100 // switch (infits.hdutype()) { 00101 // case FITS::BinaryTableHDU: 00102 // MSBinaryTable bintab(infits); 00103 // Table tab = bintab.fullTable("myTable"); 00104 // break; 00105 // } 00106 // </srcblock> 00107 // There would obviously be other cases to the switch to deal with any 00108 // other HDUs (e.g. skip them via infits.skip_hdu()). The Table 00109 // destructor would write "myTable" to disk. 00110 // </example> 00111 00112 // <todo> 00113 // 00114 // </todo> 00115 00116 class FITSIDItoMS1 : public BinaryTableExtension 00117 { 00118 public: 00119 00120 // 00121 // The only constructor is from a FitsInput. 00122 // 00123 00124 FITSIDItoMS1(FitsInput& in, const Int& obsType=0, const Bool& initFirstMain=True); 00125 00126 ~FITSIDItoMS1(); 00127 00128 // 00129 // Get the full table, using the supplied arguments to construct 00130 // the table. The table will contain all data from the current 00131 // row to the end of the BinarTableExtension. 00132 // 00133 00134 Table oldfullTable(const String& tabName); 00135 00136 00137 // Fill the Observation and ObsLog tables 00138 void fillObsTables(); 00139 00140 // Read a binary table extension of type ANTENNA and create an antenna table 00141 //void fillAntennaTable(BinaryTable& bt); 00142 void fillAntennaTable(); 00143 00144 // fill the Feed table with minimal info needed for synthesis processing 00145 void fillFeedTable(); 00146 00147 //fill the Field table 00148 //void fillFieldTable(Int nField); 00149 void fillFieldTable(); 00150 00151 //fill the Spectral Window table with the content of FREQUENCY 00152 void fillSpectralWindowTable(); 00153 00154 //fill the optional Correlator Model table with the content of INTERFEROMETER_MODEL 00155 Bool fillCorrelatorModelTable(); 00156 00157 //fill the optional SysCal table with the content of SYSTEM_TEMPERATURE 00158 Bool fillSysCalTable(); 00159 00160 //fill the optional FlagCmd table with the content of FLAG 00161 Bool fillFlagCmdTable(); 00162 00163 //fill the optional Weather table with the content of WEATHER 00164 Bool fillWeatherTable(); 00165 00166 //store the information from the GAIN_CURVE table in a calibration table 00167 Bool handleGainCurve(); 00168 00169 //store the information from the PHASE-CAL table in a calibration table 00170 Bool handlePhaseCal(); 00171 00172 //store the information from the MODEL_COMPS table 00173 Bool handleModelComps(); 00174 00175 // fix up the EPOCH MEASURE_REFERENCE keywords 00176 void fixEpochReferences(); 00177 00178 //update the Polarization table 00179 void updateTables(const String& tabName); 00180 00181 00182 // 00183 // Get an appropriate TableDesc (this is the same TableDesc used 00184 // to construct any Table objects returned by this class. 00185 // 00186 const TableDesc& getDescriptor(); 00187 00188 // 00189 // Return the Table keywords (this is the same TableRecord used in 00190 // any Table objects returned by this class. 00191 // 00192 TableRecord& getKeywords(); 00193 00194 // 00195 // Get a Table with a single row, the current row of the FITS 00196 // table. The returned Table is a Scratch table. The standard 00197 // BinaryTableExtension manipulation functions are available to 00198 // position the FITS input at the desired location. 00199 // 00200 const Table &thisRow(); 00201 00202 // 00203 // Get a Table with a single row, the next row of the FITS table. 00204 // The returned Table is a Scratch table. The FITS input is 00205 // positioned to the next row and the values translated and 00206 // returned in a Table object. 00207 // 00208 const Table &nextRow(); 00209 00210 // Get the version of the archived MS. 00211 Float msVersion() const 00212 { return itsVersion; } 00213 00214 // Read all the data from the FITS file and create the MeasurementSet. Throws 00215 // an exception when it has severe trouble interpreting the FITS file. 00216 // Returns False if it encounters an unsupported extension. 00217 Bool readFitsFile(const String& msFile); 00218 00219 //is this the first UV_DATA extension 00220 Bool isfirstMain(){return firstMain;} 00221 00222 protected: 00223 // Read the axis info, throws an exception if required axes are missing. 00224 void getAxisInfo(); 00225 00226 // Set up the MeasurementSet, including StorageManagers and fixed columns. 00227 // If useTSM is True, the Tiled Storage Manager will be used to store 00228 // DATA, FLAG and WEIGHT_SPECTRUM 00229 void setupMeasurementSet(const String& MSFileName, Bool useTSM=True, 00230 Bool mainTbl=False, Bool addCorrMod=False, 00231 Bool addSyscal=False, Bool addWeather=False); 00232 00233 // Fill the main table from the Primary group data 00234 void fillMSMainTable(const String& MSFileName, Int& nField, Int& nSpW); 00235 00236 private: 00237 // 00238 //# Data Members 00239 // 00240 00241 // The scratch table containing the current row 00242 Table itsCurRowTab; 00243 00244 // The number of elements for each column of the 00245 // BinaryTableExtension 00246 Vector<Int> itsNelem; 00247 00248 // For each column: is it an array? 00249 Vector<Bool> itsIsArray; 00250 00251 // Table keyword set 00252 TableRecord itsKwSet; 00253 00254 // Table descriptor for construction 00255 TableDesc itsTableDesc; 00256 00257 // Table info 00258 TableInfo itsTableInfo; 00259 00260 // The MS version. 00261 Float itsVersion; 00262 00263 // 00264 // Buffer for storing the MSK's, MS-specific FITS keywords. 00265 // 00266 uInt itsNrMSKs; 00267 Vector<String> itsMSKC; 00268 Vector<String> itsMSKN; 00269 Vector<String> itsMSKV; 00270 Vector<Bool> itsgotMSK; 00271 00272 00274 String msFile_p; 00275 Vector<Int> nPixel_p,corrType_p; 00276 Block<Int> corrIndex_p; 00277 Matrix<Int> corrProduct_p; 00278 Vector<String> coordType_p; 00279 Vector<Double> refVal_p, refPix_p, delta_p; 00280 static String array_p; 00281 String object_p,timsys_p; 00282 Double epoch_p; 00283 static Double rdate; 00284 Int nAnt_p; 00285 Vector<Double> receptorAngle_p; 00286 MFrequency::Types freqsys_p; 00287 Double restfreq_p; 00288 LogIO* itsLog; 00290 Double startTime_p; 00291 Double lastTime_p; 00292 Int itsObsType; 00293 MeasurementSet ms_p; 00294 MSColumns* msc_p; 00295 static Bool firstMain; 00296 static Bool firstSyscal; 00297 static Bool firstWeather; 00298 Bool weather_hasWater_p; 00299 Bool weather_hasElectron_p; 00300 Bool uv_data_hasWeights_p; 00301 Bool weightKwPresent_p; 00302 Bool weightypKwPresent_p; 00303 String weightyp_p; 00304 Matrix<Float> weightsFromKW_p; 00305 static SimpleOrderedMap<Int,Int> antIdFromNo; 00306 00307 // 00308 //# Member Functions 00309 // 00310 00311 // Fill in each row as needed 00312 void fillRow(); 00313 00314 // Build part of the keywords of the itsCurRowTab 00315 void convertKeywords(); 00316 00317 // Convert FITS field descriptions to TableColumn descriptions. 00318 void describeColumns(); 00319 00320 // Convert the MS-specific keywords in the FITS binary table. 00321 void convertMSKeywords(); 00322 }; 00323 00324 00325 } //# NAMESPACE CASACORE - END 00326 00327 #endif 00328 00329