casa
$Rev:20696$
|
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: FitsIDItoMS.h 21069 2011-05-06 13:59:44Z gervandiepen $ 00027 //# Mod 2010: DP 00028 00029 #ifndef MS_FITSIDITOMS_H 00030 #define MS_FITSIDITOMS_H 00031 00032 #include <casa/aips.h> 00033 #include <fits/FITS/hdu.h> 00034 #include <tables/Tables/Table.h> // 00035 #include <tables/Tables/TableDesc.h> // 00036 #include <tables/Tables/TableRecord.h> // 00037 #include <tables/Tables/TableColumn.h> // 00038 #include <casa/Containers/SimOrdMap.h> // 00039 #include <casa/Arrays/Vector.h> 00040 #include <casa/Arrays/Matrix.h> 00041 #include <casa/Containers/Block.h> 00042 #include <casa/Logging/LogIO.h> 00043 #include <measures/Measures/MFrequency.h> 00044 #include <ms/MeasurementSets/MeasurementSet.h> 00045 #include <casa/BasicSL/String.h> 00046 namespace casa { //# NAMESPACE CASA - 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 00152 void fillSpectralWindowTable(); 00153 00154 // fix up the EPOCH MEASURE_REFERENCE keywords 00155 void fixEpochReferences(); 00156 00157 //update the Polarization table 00158 void updateTables(const String& tabName); 00159 00160 00161 // 00162 // Get an appropriate TableDesc (this is the same TableDesc used 00163 // to construct any Table objects returned by this class. 00164 // 00165 const TableDesc& getDescriptor(); 00166 00167 // 00168 // Return the Table keywords (this is the same TableRecord used in 00169 // any Table objects returned by this class. 00170 // 00171 TableRecord& getKeywords(); 00172 00173 // 00174 // Get a Table with a single row, the current row of the FITS 00175 // table. The returned Table is a Scratch table. The standard 00176 // BinaryTableExtension manipulation functions are available to 00177 // position the FITS input at the desired location. 00178 // 00179 const Table &thisRow(); 00180 00181 // 00182 // Get a Table with a single row, the next row of the FITS table. 00183 // The returned Table is a Scratch table. The FITS input is 00184 // positioned to the next row and the values translated and 00185 // returned in a Table object. 00186 // 00187 const Table &nextRow(); 00188 00189 // Get the version of the archived MS. 00190 Float msVersion() const 00191 { return itsVersion; } 00192 00193 // Read all the data from the FITS file and create the MeasurementSet. Throws 00194 // an exception when it has severe trouble interpreting the FITS file. 00195 // Returns False if it encounters an unsupported extension. 00196 Bool readFitsFile(const String& msFile); 00197 00198 //is this the first UV_DATA extension 00199 Bool isfirstMain(){return firstMain;} 00200 00201 protected: 00202 // Read the axis info, throws an exception if required axes are missing. 00203 void getAxisInfo(); 00204 00205 // Set up the MeasurementSet, including StorageManagers and fixed columns. 00206 // If useTSM is True, the Tiled Storage Manager will be used to store 00207 // DATA, FLAG and WEIGHT_SPECTRUM 00208 void setupMeasurementSet(const String& MSFileName, Bool useTSM=True, 00209 Bool mainTbl=False); 00210 00211 // Fill the main table from the Primary group data 00212 void fillMSMainTable(const String& MSFileName, Int& nField, Int& nSpW); 00213 00214 private: 00215 // 00216 //# Data Members 00217 // 00218 00219 // The scratch table containing the current row 00220 Table itsCurRowTab; 00221 00222 // The number of elements for each column of the 00223 // BinaryTableExtension 00224 Vector<Int> itsNelem; 00225 00226 // For each column: is it an array? 00227 Vector<Bool> itsIsArray; 00228 00229 // Table keyword set 00230 TableRecord itsKwSet; 00231 00232 // Table descriptor for construction 00233 TableDesc itsTableDesc; 00234 00235 // Table info 00236 TableInfo itsTableInfo; 00237 00238 // The MS version. 00239 Float itsVersion; 00240 00241 // 00242 // Buffer for storing the MSK's, MS-specific FITS keywords. 00243 // 00244 uInt itsNrMSKs; 00245 Vector<String> itsMSKC; 00246 Vector<String> itsMSKN; 00247 Vector<String> itsMSKV; 00248 Vector<Bool> itsgotMSK; 00249 00250 00251 FitsInput &infile_p; 00252 String msFile_p; 00253 Vector<Int> nPixel_p,corrType_p; 00254 Block<Int> corrIndex_p; 00255 Matrix<Int> corrProduct_p; 00256 Vector<String> coordType_p; 00257 Vector<Double> refVal_p, refPix_p, delta_p; 00258 static String array_p; 00259 String object_p,timsys_p; 00260 Double epoch_p; 00261 static Double rdate; 00262 Int nAnt_p; 00263 Vector<Double> receptorAngle_p; 00264 MFrequency::Types freqsys_p; 00265 Double restfreq_p; 00266 LogIO* itsLog; 00267 Int nIF_p; 00268 Double startTime_p; 00269 Double lastTime_p; 00270 Int itsObsType; 00271 MeasurementSet ms_p; 00272 MSColumns* msc_p; 00273 static Bool firstMain; 00274 Bool uv_data_hasWeights_p; 00275 Bool weightKwPresent_p; 00276 Bool weightypKwPresent_p; 00277 String weightyp_p; 00278 Matrix<Float> weightsFromKW_p; 00279 static SimpleOrderedMap<Int,Int> antIdFromNo; 00280 00281 // 00282 //# Member Functions 00283 // 00284 00285 // Fill in each row as needed 00286 void fillRow(); 00287 00288 // Build part of the keywords of the itsCurRowTab 00289 void convertKeywords(); 00290 00291 // Convert FITS field descriptions to TableColumn descriptions. 00292 void describeColumns(); 00293 00294 // Convert the MS-specific keywords in the FITS binary table. 00295 void convertMSKeywords(); 00296 }; 00297 00298 00299 } //# NAMESPACE CASA - END 00300 00301 #endif 00302 00303