[1974] | 1 | //
|
---|
| 2 | // C++ Interface: MSFiller
|
---|
| 3 | //
|
---|
| 4 | // Description:
|
---|
| 5 | //
|
---|
| 6 | // This class is specific filler for MS format
|
---|
| 7 | //
|
---|
| 8 | // Takeshi Nakazato <takeshi.nakazato@nao.ac.jp>, (C) 2010
|
---|
| 9 | //
|
---|
| 10 | // Copyright: See COPYING file that comes with this distribution
|
---|
| 11 | //
|
---|
| 12 | //
|
---|
| 13 |
|
---|
| 14 | #include <iostream>
|
---|
| 15 | #include <map>
|
---|
| 16 |
|
---|
| 17 | #include <tables/Tables/ExprNode.h>
|
---|
| 18 | #include <tables/Tables/TableIter.h>
|
---|
[1987] | 19 | #include <tables/Tables/TableColumn.h>
|
---|
[1974] | 20 | #include <tables/Tables/ScalarColumn.h>
|
---|
| 21 | #include <tables/Tables/ArrayColumn.h>
|
---|
[1987] | 22 | #include <tables/Tables/TableParse.h>
|
---|
[2002] | 23 | #include <tables/Tables/TableRow.h>
|
---|
[1974] | 24 |
|
---|
[2002] | 25 | #include <casa/Containers/RecordField.h>
|
---|
[1974] | 26 | #include <casa/Logging/LogIO.h>
|
---|
| 27 | #include <casa/Arrays/Slicer.h>
|
---|
| 28 | #include <casa/Quanta/MVTime.h>
|
---|
[1987] | 29 | #include <casa/OS/Path.h>
|
---|
[1974] | 30 |
|
---|
| 31 | #include <measures/Measures/Stokes.h>
|
---|
| 32 | #include <measures/Measures/MEpoch.h>
|
---|
[1987] | 33 | #include <measures/Measures/MCEpoch.h>
|
---|
| 34 | #include <measures/Measures/MFrequency.h>
|
---|
| 35 | #include <measures/Measures/MCFrequency.h>
|
---|
| 36 | #include <measures/Measures/MPosition.h>
|
---|
| 37 | #include <measures/Measures/MCPosition.h>
|
---|
| 38 | #include <measures/Measures/MDirection.h>
|
---|
| 39 | #include <measures/Measures/MCDirection.h>
|
---|
| 40 | #include <measures/Measures/MeasConvert.h>
|
---|
[1974] | 41 | #include <measures/TableMeasures/ScalarMeasColumn.h>
|
---|
[1987] | 42 | #include <measures/TableMeasures/ArrayMeasColumn.h>
|
---|
| 43 | #include <measures/TableMeasures/ScalarQuantColumn.h>
|
---|
| 44 | #include <measures/TableMeasures/ArrayQuantColumn.h>
|
---|
[1974] | 45 |
|
---|
[2021] | 46 | #include <ms/MeasurementSets/MSAntennaIndex.h>
|
---|
| 47 |
|
---|
[1974] | 48 | #include <atnf/PKSIO/SrcType.h>
|
---|
| 49 |
|
---|
| 50 | #include "MSFiller.h"
|
---|
| 51 | #include "STHeader.h"
|
---|
| 52 |
|
---|
[1988] | 53 | #include <ctime>
|
---|
| 54 | #include <sys/time.h>
|
---|
| 55 |
|
---|
[2017] | 56 | using namespace casa ;
|
---|
| 57 | using namespace std ;
|
---|
| 58 |
|
---|
| 59 | namespace asap {
|
---|
| 60 | double MSFiller::gettimeofday_sec()
|
---|
[1988] | 61 | {
|
---|
| 62 | struct timeval tv ;
|
---|
| 63 | gettimeofday( &tv, NULL ) ;
|
---|
| 64 | return tv.tv_sec + (double)tv.tv_usec*1.0e-6 ;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
[1974] | 67 | MSFiller::MSFiller( casa::CountedPtr<Scantable> stable )
|
---|
| 68 | : table_( stable ),
|
---|
[1987] | 69 | tablename_( "" ),
|
---|
[1974] | 70 | antenna_( -1 ),
|
---|
[2021] | 71 | antennaStr_(""),
|
---|
[1974] | 72 | getPt_( False ),
|
---|
| 73 | isFloatData_( False ),
|
---|
| 74 | isData_( False ),
|
---|
| 75 | isDoppler_( False ),
|
---|
| 76 | isFlagCmd_( False ),
|
---|
| 77 | isFreqOffset_( False ),
|
---|
| 78 | isHistory_( False ),
|
---|
| 79 | isProcessor_( False ),
|
---|
| 80 | isSysCal_( False ),
|
---|
[1993] | 81 | isWeather_( False ),
|
---|
| 82 | colTsys_( "TSYS_SPECTRUM" ),
|
---|
| 83 | colTcal_( "TCAL_SPECTRUM" )
|
---|
[1974] | 84 | {
|
---|
| 85 | os_ = LogIO() ;
|
---|
| 86 | os_.origin( LogOrigin( "MSFiller", "MSFiller()", WHERE ) ) ;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | MSFiller::~MSFiller()
|
---|
| 90 | {
|
---|
| 91 | os_.origin( LogOrigin( "MSFiller", "~MSFiller()", WHERE ) ) ;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | bool MSFiller::open( const std::string &filename, const casa::Record &rec )
|
---|
| 95 | {
|
---|
| 96 | os_.origin( LogOrigin( "MSFiller", "open()", WHERE ) ) ;
|
---|
[2004] | 97 | // double startSec = gettimeofday_sec() ;
|
---|
| 98 | // os_ << "start MSFiller::open() startsec=" << startSec << LogIO::POST ;
|
---|
[1974] | 99 | //os_ << " filename = " << filename << endl ;
|
---|
| 100 |
|
---|
| 101 | // parsing MS options
|
---|
| 102 | if ( rec.isDefined( "ms" ) ) {
|
---|
| 103 | Record msrec = rec.asRecord( "ms" ) ;
|
---|
| 104 | if ( msrec.isDefined( "getpt" ) ) {
|
---|
| 105 | getPt_ = msrec.asBool( "getpt" ) ;
|
---|
| 106 | }
|
---|
| 107 | if ( msrec.isDefined( "antenna" ) ) {
|
---|
| 108 | if ( msrec.type( msrec.fieldNumber( "antenna" ) ) == TpInt ) {
|
---|
| 109 | antenna_ = msrec.asInt( "antenna" ) ;
|
---|
| 110 | }
|
---|
| 111 | else {
|
---|
[2021] | 112 | //antenna_ = atoi( msrec.asString( "antenna" ).c_str() ) ;
|
---|
| 113 | antennaStr_ = msrec.asString( "antenna" ) ;
|
---|
[1974] | 114 | }
|
---|
| 115 | }
|
---|
| 116 | else {
|
---|
| 117 | antenna_ = 0 ;
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 |
|
---|
[1987] | 121 | MeasurementSet *tmpMS = new MeasurementSet( filename, Table::Old ) ;
|
---|
| 122 | //mstable_ = (*tmpMS)( tmpMS->col("ANTENNA1") == antenna_
|
---|
| 123 | // && tmpMS->col("ANTENNA1") == tmpMS->col("ANTENNA2") ) ;
|
---|
| 124 | tablename_ = tmpMS->tableName() ;
|
---|
[2021] | 125 | if ( antenna_ == -1 && antennaStr_.size() > 0 ) {
|
---|
| 126 | MSAntennaIndex msAntIdx( tmpMS->antenna() ) ;
|
---|
| 127 | Vector<Int> id = msAntIdx.matchAntennaName( antennaStr_ ) ;
|
---|
| 128 | if ( id.size() > 0 )
|
---|
| 129 | antenna_ = id[0] ;
|
---|
| 130 | }
|
---|
[2025] | 131 |
|
---|
| 132 | os_ << "Parsing MS options" << endl ;
|
---|
| 133 | os_ << " getPt = " << getPt_ << endl ;
|
---|
| 134 | os_ << " antenna = " << antenna_ << endl ;
|
---|
| 135 | os_ << " antennaStr = " << antennaStr_ << LogIO::POST ;
|
---|
| 136 |
|
---|
[1987] | 137 | mstable_ = MeasurementSet( (*tmpMS)( tmpMS->col("ANTENNA1") == antenna_
|
---|
| 138 | && tmpMS->col("ANTENNA1") == tmpMS->col("ANTENNA2") ) ) ;
|
---|
| 139 | // stringstream ss ;
|
---|
| 140 | // ss << "SELECT FROM $1 WHERE ANTENNA1 == ANTENNA2 && ANTENNA1 == " << antenna_ ;
|
---|
| 141 | // String taql( ss.str() ) ;
|
---|
| 142 | // mstable_ = MeasurementSet( tableCommand( taql, *tmpMS ) ) ;
|
---|
| 143 | delete tmpMS ;
|
---|
[1974] | 144 |
|
---|
| 145 | // check which data column exists
|
---|
[1987] | 146 | isFloatData_ = mstable_.tableDesc().isColumn( "FLOAT_DATA" ) ;
|
---|
| 147 | isData_ = mstable_.tableDesc().isColumn( "DATA" ) ;
|
---|
[1974] | 148 |
|
---|
[2004] | 149 | // double endSec = gettimeofday_sec() ;
|
---|
| 150 | // os_ << "end MSFiller::open() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
[1974] | 151 | return true ;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | void MSFiller::fill()
|
---|
| 155 | {
|
---|
| 156 | os_.origin( LogOrigin( "MSFiller", "fill()", WHERE ) ) ;
|
---|
[2004] | 157 | // double startSec = gettimeofday_sec() ;
|
---|
| 158 | // os_ << "start MSFiller::fill() startSec=" << startSec << LogIO::POST ;
|
---|
[1974] | 159 |
|
---|
[2004] | 160 | // double time0 = gettimeofday_sec() ;
|
---|
| 161 | // os_ << "start init fill: " << time0 << LogIO::POST ;
|
---|
[1990] | 162 |
|
---|
[1974] | 163 | // Initialize header
|
---|
| 164 | STHeader sdh ;
|
---|
| 165 | sdh.nchan = 0 ;
|
---|
| 166 | sdh.npol = 0 ;
|
---|
| 167 | sdh.nif = 0 ;
|
---|
| 168 | sdh.nbeam = 0 ;
|
---|
| 169 | sdh.observer = "" ;
|
---|
| 170 | sdh.project = "" ;
|
---|
| 171 | sdh.obstype = "" ;
|
---|
| 172 | sdh.antennaname = "" ;
|
---|
| 173 | sdh.antennaposition.resize( 0 ) ;
|
---|
| 174 | sdh.equinox = 0.0 ;
|
---|
| 175 | sdh.freqref = "" ;
|
---|
| 176 | sdh.reffreq = -1.0 ;
|
---|
| 177 | sdh.bandwidth = 0.0 ;
|
---|
| 178 | sdh.utc = 0.0 ;
|
---|
| 179 | sdh.fluxunit = "" ;
|
---|
| 180 | sdh.epoch = "" ;
|
---|
| 181 | sdh.poltype = "" ;
|
---|
| 182 |
|
---|
| 183 | // check if optional table exists
|
---|
[1987] | 184 | //const TableRecord msrec = tablesel_.keywordSet() ;
|
---|
| 185 | const TableRecord msrec = mstable_.keywordSet() ;
|
---|
[1974] | 186 | isDoppler_ = msrec.isDefined( "DOPPLER" ) ;
|
---|
[2004] | 187 | if ( isDoppler_ )
|
---|
| 188 | if ( mstable_.doppler().nrow() == 0 )
|
---|
| 189 | isDoppler_ = False ;
|
---|
[1974] | 190 | isFlagCmd_ = msrec.isDefined( "FLAG_CMD" ) ;
|
---|
[2004] | 191 | if ( isFlagCmd_ )
|
---|
| 192 | if ( mstable_.flagCmd().nrow() == 0 )
|
---|
| 193 | isFlagCmd_ = False ;
|
---|
[1974] | 194 | isFreqOffset_ = msrec.isDefined( "FREQ_OFFSET" ) ;
|
---|
[2004] | 195 | if ( isFreqOffset_ )
|
---|
| 196 | if ( mstable_.freqOffset().nrow() == 0 )
|
---|
| 197 | isFreqOffset_ = False ;
|
---|
[1974] | 198 | isHistory_ = msrec.isDefined( "HISTORY" ) ;
|
---|
[2004] | 199 | if ( isHistory_ )
|
---|
| 200 | if ( mstable_.history().nrow() == 0 )
|
---|
| 201 | isHistory_ = False ;
|
---|
[1974] | 202 | isProcessor_ = msrec.isDefined( "PROCESSOR" ) ;
|
---|
[2004] | 203 | if ( isProcessor_ )
|
---|
| 204 | if ( mstable_.processor().nrow() == 0 )
|
---|
| 205 | isProcessor_ = False ;
|
---|
[1974] | 206 | isSysCal_ = msrec.isDefined( "SYSCAL" ) ;
|
---|
[2004] | 207 | if ( isSysCal_ )
|
---|
| 208 | if ( mstable_.sysCal().nrow() == 0 )
|
---|
| 209 | isSysCal_ = False ;
|
---|
[1974] | 210 | isWeather_ = msrec.isDefined( "WEATHER" ) ;
|
---|
[2004] | 211 | if ( isWeather_ )
|
---|
| 212 | if ( mstable_.weather().nrow() == 0 )
|
---|
| 213 | isWeather_ = False ;
|
---|
| 214 |
|
---|
[1974] | 215 | // Access to MS subtables
|
---|
[1987] | 216 | MSField fieldtab = mstable_.field() ;
|
---|
| 217 | MSPolarization poltab = mstable_.polarization() ;
|
---|
| 218 | MSDataDescription ddtab = mstable_.dataDescription() ;
|
---|
| 219 | MSObservation obstab = mstable_.observation() ;
|
---|
| 220 | MSSource srctab = mstable_.source() ;
|
---|
| 221 | MSSpectralWindow spwtab = mstable_.spectralWindow() ;
|
---|
| 222 | MSSysCal caltab = mstable_.sysCal() ;
|
---|
[1974] | 223 | if ( caltab.nrow() == 0 )
|
---|
| 224 | isSysCal_ = False ;
|
---|
[1993] | 225 | else {
|
---|
| 226 | if ( !caltab.tableDesc().isColumn( colTcal_ ) )
|
---|
| 227 | colTcal_ = "TCAL" ;
|
---|
| 228 | if ( !caltab.tableDesc().isColumn( colTsys_ ) )
|
---|
| 229 | colTsys_ = "TSYS" ;
|
---|
| 230 | }
|
---|
[2004] | 231 | // colTcal_ = "TCAL" ;
|
---|
| 232 | // colTsys_ = "TSYS" ;
|
---|
[1987] | 233 | MSPointing pointtab = mstable_.pointing() ;
|
---|
| 234 | if ( mstable_.weather().nrow() == 0 )
|
---|
[1974] | 235 | isWeather_ = False ;
|
---|
[1987] | 236 | MSState stattab = mstable_.state() ;
|
---|
| 237 | MSAntenna anttab = mstable_.antenna() ;
|
---|
[1974] | 238 |
|
---|
[1987] | 239 | // TEST
|
---|
| 240 | // memory allocation by boost::object_pool
|
---|
| 241 | boost::object_pool<ROTableColumn> *tpoolr = new boost::object_pool<ROTableColumn> ;
|
---|
| 242 | //
|
---|
[1974] | 243 |
|
---|
[1987] | 244 | // SUBTABLES: FREQUENCIES
|
---|
[1974] | 245 | table_->frequencies().setFrame( "LSRK" ) ;
|
---|
| 246 | table_->frequencies().setFrame( "LSRK", True ) ;
|
---|
| 247 |
|
---|
| 248 | // SUBTABLES: WEATHER
|
---|
[2004] | 249 | fillWeather() ;
|
---|
[1974] | 250 |
|
---|
| 251 | // SUBTABLES: FOCUS
|
---|
| 252 | fillFocus() ;
|
---|
| 253 |
|
---|
| 254 | // SUBTABLES: TCAL
|
---|
[2004] | 255 | fillTcal( tpoolr ) ;
|
---|
[1974] | 256 |
|
---|
| 257 | // SUBTABLES: FIT
|
---|
| 258 | //fillFit() ;
|
---|
| 259 |
|
---|
| 260 | // SUBTABLES: HISTORY
|
---|
| 261 | //fillHistory() ;
|
---|
| 262 |
|
---|
[1987] | 263 | // shared pointers
|
---|
| 264 | ROTableColumn *tcolr ;
|
---|
| 265 |
|
---|
[1974] | 266 | // MAIN
|
---|
| 267 | // Iterate over several ids
|
---|
| 268 | map<Int, uInt> ifmap ; // (IFNO, FREQ_ID) pair
|
---|
[1987] | 269 | ROArrayQuantColumn<Double> *sharedQDArrCol = new ROArrayQuantColumn<Double>( anttab, "POSITION" ) ;
|
---|
| 270 | Vector< Quantum<Double> > antpos = (*sharedQDArrCol)( antenna_ ) ;
|
---|
| 271 | delete sharedQDArrCol ;
|
---|
[1974] | 272 | MPosition mp( MVPosition( antpos ), MPosition::ITRF ) ;
|
---|
[1990] | 273 | if ( getPt_ ) {
|
---|
| 274 | //pointtab = pointtab( pointtab.col("ANTENNA_ID")==antenna_ ).sort("TIME") ;
|
---|
| 275 | pointtab = MSPointing( pointtab( pointtab.col("ANTENNA_ID")==antenna_ ).sort("TIME") ) ;
|
---|
| 276 | }
|
---|
[1987] | 277 | tcolr = tpoolr->construct( anttab, "STATION" ) ;
|
---|
| 278 | String stationName = tcolr->asString( antenna_ ) ;
|
---|
| 279 | tpoolr->destroy( tcolr ) ;
|
---|
| 280 | tcolr = tpoolr->construct( anttab, "NAME" ) ;
|
---|
| 281 | String antennaName = tcolr->asString( antenna_ ) ;
|
---|
| 282 | tpoolr->destroy( tcolr ) ;
|
---|
| 283 | sdh.antennaposition.resize( 3 ) ;
|
---|
| 284 | for ( int i = 0 ; i < 3 ; i++ )
|
---|
| 285 | sdh.antennaposition[i] = antpos[i].getValue( "m" ) ;
|
---|
| 286 | String telescopeName = "" ;
|
---|
| 287 |
|
---|
[2021] | 288 | // double time1 = gettimeofday_sec() ;
|
---|
| 289 | // os_ << "end fill init: " << time1 << " (" << time1-time0 << "sec)" << LogIO::POST ;
|
---|
[1990] | 290 |
|
---|
[2002] | 291 | // row based
|
---|
| 292 | Table &stab = table_->table() ;
|
---|
| 293 | TableRow row( stab ) ;
|
---|
| 294 | TableRecord &trec = row.record() ;
|
---|
| 295 | RecordFieldPtr< Array<Float> > spRF( trec, "SPECTRA" ) ;
|
---|
| 296 | RecordFieldPtr< Array<uChar> > ucarrRF( trec, "FLAGTRA" ) ;
|
---|
| 297 | RecordFieldPtr<Double> timeRF( trec, "TIME" ) ;
|
---|
| 298 | RecordFieldPtr< Array<Float> > tsysRF( trec, "TSYS" ) ;
|
---|
| 299 | RecordFieldPtr<Double> intervalRF( trec, "INTERVAL" ) ;
|
---|
| 300 | RecordFieldPtr< Array<Double> > dirRF( trec, "DIRECTION" ) ;
|
---|
| 301 | RecordFieldPtr<Float> azRF( trec, "AZIMUTH" ) ;
|
---|
| 302 | RecordFieldPtr<Float> elRF( trec, "ELEVATION" ) ;
|
---|
| 303 | RecordFieldPtr< Array<Double> > scrRF( trec, "SCANRATE" ) ;
|
---|
| 304 | RecordFieldPtr<uInt> cycleRF( trec, "CYCLENO" ) ;
|
---|
| 305 | RecordFieldPtr<uInt> flrRF( trec, "FLAGROW" ) ;
|
---|
| 306 | RecordFieldPtr<uInt> tcalidRF( trec, "TCAL_ID" ) ;
|
---|
| 307 | RecordFieldPtr<uInt> widRF( trec, "WEATHER_ID" ) ;
|
---|
| 308 | RecordFieldPtr<uInt> polnoRF( trec, "POLNO" ) ;
|
---|
| 309 |
|
---|
| 310 |
|
---|
| 311 | // REFBEAMNO
|
---|
| 312 | RecordFieldPtr<Int> intRF( trec, "REFBEAMNO" ) ;
|
---|
| 313 | *intRF = 0 ;
|
---|
| 314 |
|
---|
| 315 | // FIT_ID
|
---|
| 316 | intRF.attachToRecord( trec, "FIT_ID" ) ;
|
---|
| 317 | *intRF = -1 ;
|
---|
| 318 |
|
---|
| 319 | // OPACITY
|
---|
| 320 | RecordFieldPtr<Float> floatRF( trec, "OPACITY" ) ;
|
---|
| 321 | *floatRF = 0.0 ;
|
---|
| 322 |
|
---|
[1978] | 323 | //
|
---|
| 324 | // ITERATION: OBSERVATION_ID
|
---|
| 325 | //
|
---|
[1987] | 326 | TableIterator iter0( mstable_, "OBSERVATION_ID" ) ;
|
---|
[1974] | 327 | while( !iter0.pastEnd() ) {
|
---|
[2021] | 328 | // time0 = gettimeofday_sec() ;
|
---|
| 329 | // os_ << "start 0th iteration: " << time0 << LogIO::POST ;
|
---|
[1987] | 330 | Table t0 = iter0.table() ;
|
---|
| 331 | tcolr = tpoolr->construct( t0, "OBSERVATION_ID" ) ;
|
---|
| 332 | Int obsId = tcolr->asInt( 0 ) ;
|
---|
| 333 | tpoolr->destroy( tcolr ) ;
|
---|
| 334 | if ( sdh.observer == "" ) {
|
---|
| 335 | tcolr = tpoolr->construct( obstab, "OBSERVER" ) ;
|
---|
| 336 | sdh.observer = tcolr->asString( obsId ) ;
|
---|
| 337 | tpoolr->destroy( tcolr ) ;
|
---|
| 338 | }
|
---|
| 339 | if ( sdh.project == "" ) {
|
---|
| 340 | tcolr = tpoolr->construct( obstab, "PROJECT" ) ;
|
---|
| 341 | sdh.observer = tcolr->asString( obsId ) ;
|
---|
| 342 | tpoolr->destroy( tcolr ) ;
|
---|
| 343 | }
|
---|
| 344 | ROArrayMeasColumn<MEpoch> *tmpMeasCol = new ROArrayMeasColumn<MEpoch>( obstab, "TIME_RANGE" ) ;
|
---|
| 345 | MEpoch me = (*tmpMeasCol)( obsId )( IPosition(1,0) ) ;
|
---|
| 346 | delete tmpMeasCol ;
|
---|
[1974] | 347 | if ( sdh.utc == 0.0 ) {
|
---|
[2035] | 348 | sdh.utc = me.get( "d" ).getValue() ;
|
---|
[1974] | 349 | }
|
---|
[1987] | 350 | if ( telescopeName == "" ) {
|
---|
| 351 | tcolr = tpoolr->construct( obstab, "TELESCOPE_NAME" ) ;
|
---|
[2025] | 352 | telescopeName = tcolr->asString( obsId ) ;
|
---|
[1987] | 353 | tpoolr->destroy( tcolr ) ;
|
---|
| 354 | }
|
---|
[1978] | 355 | Int nbeam = 0 ;
|
---|
[2021] | 356 | // time1 = gettimeofday_sec() ;
|
---|
| 357 | // os_ << "end 0th iteration init: " << time1 << " (" << time1-time0 << "sec)" << LogIO::POST ;
|
---|
[1974] | 358 | //
|
---|
| 359 | // ITERATION: FEED1
|
---|
| 360 | //
|
---|
| 361 | TableIterator iter1( t0, "FEED1" ) ;
|
---|
| 362 | while( !iter1.pastEnd() ) {
|
---|
[2021] | 363 | // time0 = gettimeofday_sec() ;
|
---|
| 364 | // os_ << "start 1st iteration: " << time0 << LogIO::POST ;
|
---|
[1987] | 365 | Table t1 = iter1.table() ;
|
---|
| 366 | // assume FEED1 == FEED2
|
---|
| 367 | tcolr = tpoolr->construct( t1, "FEED1" ) ;
|
---|
| 368 | Int feedId = tcolr->asInt( 0 ) ;
|
---|
| 369 | tpoolr->destroy( tcolr ) ;
|
---|
[1974] | 370 | nbeam++ ;
|
---|
[2002] | 371 |
|
---|
| 372 | // BEAMNO
|
---|
| 373 | RecordFieldPtr<uInt> uintRF( trec, "BEAMNO" ) ;
|
---|
| 374 | *uintRF = feedId ;
|
---|
| 375 |
|
---|
| 376 | // FOCUS_ID
|
---|
| 377 | uintRF.attachToRecord( trec, "FOCUS_ID" ) ;
|
---|
| 378 | *uintRF = 0 ;
|
---|
| 379 |
|
---|
[2021] | 380 | // time1 = gettimeofday_sec() ;
|
---|
| 381 | // os_ << "end 1st iteration init: " << time1 << " (" << time1-time0 << "sec)" << LogIO::POST ;
|
---|
[1974] | 382 | //
|
---|
| 383 | // ITERATION: FIELD_ID
|
---|
| 384 | //
|
---|
| 385 | TableIterator iter2( t1, "FIELD_ID" ) ;
|
---|
| 386 | while( !iter2.pastEnd() ) {
|
---|
[2021] | 387 | // time0 = gettimeofday_sec() ;
|
---|
| 388 | // os_ << "start 2nd iteration: " << time0 << LogIO::POST ;
|
---|
[1987] | 389 | Table t2 = iter2.table() ;
|
---|
| 390 | tcolr = tpoolr->construct( t2, "FIELD_ID" ) ;
|
---|
| 391 | Int fieldId = tcolr->asInt( 0 ) ;
|
---|
| 392 | tpoolr->destroy( tcolr ) ;
|
---|
| 393 | tcolr = tpoolr->construct( fieldtab, "SOURCE_ID" ) ;
|
---|
| 394 | Int srcId = tcolr->asInt( fieldId ) ;
|
---|
| 395 | tpoolr->destroy( tcolr ) ;
|
---|
| 396 | tcolr = tpoolr->construct( fieldtab, "NAME" ) ;
|
---|
| 397 | String fieldName = tcolr->asString( fieldId ) + "__" + String::toString(fieldId) ;
|
---|
| 398 | tpoolr->destroy( tcolr ) ;
|
---|
[2004] | 399 | ROArrayMeasColumn<MDirection> *delayDirCol = new ROArrayMeasColumn<MDirection>( fieldtab, "DELAY_DIR" ) ;
|
---|
| 400 | Vector<MDirection> delayDir = (*delayDirCol)( fieldId ) ;
|
---|
| 401 | delete delayDirCol ;
|
---|
| 402 | Vector<Double> defaultScanrate( 2, 0.0 ) ;
|
---|
| 403 | Vector<Double> defaultDir = delayDir[0].getAngle( "rad" ).getValue() ;
|
---|
| 404 | if ( delayDir.nelements() > 1 )
|
---|
| 405 | defaultScanrate = delayDir[1].getAngle( "rad" ).getValue() ;
|
---|
| 406 |
|
---|
[2002] | 407 |
|
---|
| 408 | // FIELDNAME
|
---|
| 409 | RecordFieldPtr<String> strRF( trec, "FIELDNAME" ) ;
|
---|
| 410 | *strRF = fieldName ;
|
---|
| 411 |
|
---|
| 412 |
|
---|
[2021] | 413 | // time1 = gettimeofday_sec() ;
|
---|
| 414 | // os_ << "end 2nd iteration init: " << time1 << " (" << time1-time0 << "sec)" << LogIO::POST ;
|
---|
[1974] | 415 | //
|
---|
| 416 | // ITERATION: DATA_DESC_ID
|
---|
| 417 | //
|
---|
| 418 | TableIterator iter3( t2, "DATA_DESC_ID" ) ;
|
---|
| 419 | while( !iter3.pastEnd() ) {
|
---|
[2021] | 420 | // time0 = gettimeofday_sec() ;
|
---|
| 421 | // os_ << "start 3rd iteration: " << time0 << LogIO::POST ;
|
---|
[1987] | 422 | Table t3 = iter3.table() ;
|
---|
| 423 | tcolr = tpoolr->construct( t3, "DATA_DESC_ID" ) ;
|
---|
| 424 | Int ddId = tcolr->asInt( 0 ) ;
|
---|
| 425 | tpoolr->destroy( tcolr ) ;
|
---|
| 426 | tcolr = tpoolr->construct( ddtab, "POLARIZATION_ID" ) ;
|
---|
| 427 | Int polId = tcolr->asInt( ddId ) ;
|
---|
| 428 | tpoolr->destroy( tcolr ) ;
|
---|
| 429 | tcolr = tpoolr->construct( ddtab, "SPECTRAL_WINDOW_ID" ) ;
|
---|
| 430 | Int spwId = tcolr->asInt( ddId ) ;
|
---|
| 431 | tpoolr->destroy( tcolr ) ;
|
---|
[2004] | 432 | // TODO: This must be updated if writer will be replaced from STWriter to MSWriter
|
---|
| 433 | sdh.nif = max( sdh.nif, spwId ) ;
|
---|
[2002] | 434 |
|
---|
| 435 | // IFNO
|
---|
| 436 | uintRF.attachToRecord( trec, "IFNO" ) ;
|
---|
| 437 | *uintRF = (uInt)spwId ;
|
---|
| 438 |
|
---|
[1974] | 439 | // polarization information
|
---|
[1987] | 440 | tcolr = tpoolr->construct( poltab, "NUM_CORR" ) ;
|
---|
| 441 | Int npol = tcolr->asInt( polId ) ;
|
---|
| 442 | tpoolr->destroy( tcolr ) ;
|
---|
| 443 | ROArrayColumn<Int> *roArrICol = new ROArrayColumn<Int>( poltab, "CORR_TYPE" ) ;
|
---|
| 444 | Vector<Int> corrtype = (*roArrICol)( polId ) ;
|
---|
| 445 | delete roArrICol ;
|
---|
[2021] | 446 | // os_ << "npol = " << npol << LogIO::POST ;
|
---|
| 447 | // os_ << "corrtype = " << corrtype << LogIO::POST ;
|
---|
[1993] | 448 | sdh.npol = max( sdh.npol, npol ) ;
|
---|
[1974] | 449 | if ( sdh.poltype == "" ) sdh.poltype = getPolType( corrtype[0] ) ;
|
---|
| 450 | // source information
|
---|
[2033] | 451 | // os_ << "srcId = " << srcId << ", spwId = " << spwId << LogIO::POST ;
|
---|
[2004] | 452 | MSSource srctabSel = srctab( srctab.col("SOURCE_ID") == srcId && srctab.col("SPECTRAL_WINDOW_ID") == spwId ) ;
|
---|
| 453 | if ( srctabSel.nrow() == 0 ) {
|
---|
| 454 | srctabSel = srctab( srctab.col("SOURCE_ID") == srcId && srctab.col("SPECTRAL_WINDOW_ID") == -1 ) ;
|
---|
| 455 | }
|
---|
[2033] | 456 | String srcName( "" ) ;
|
---|
| 457 | Vector<Double> srcPM( 2, 0.0 ) ;
|
---|
| 458 | Vector<Double> srcDir( 2, 0.0 ) ;
|
---|
| 459 | MDirection md ;
|
---|
| 460 | Int numLines = 0 ;
|
---|
| 461 | ROArrayColumn<Double> *roArrDCol = 0 ;
|
---|
| 462 | if ( srctabSel.nrow() > 0 ) {
|
---|
| 463 | // source name
|
---|
| 464 | tcolr = tpoolr->construct( srctabSel, "NAME" ) ;
|
---|
| 465 | srcName = tcolr->asString( 0 ) ;
|
---|
| 466 | tpoolr->destroy( tcolr ) ;
|
---|
[2002] | 467 |
|
---|
[2033] | 468 | // source proper motion
|
---|
| 469 | roArrDCol = new ROArrayColumn<Double>( srctabSel, "PROPER_MOTION" ) ;
|
---|
| 470 | srcPM = (*roArrDCol)( 0 ) ;
|
---|
| 471 | delete roArrDCol ;
|
---|
| 472 |
|
---|
| 473 | // source direction
|
---|
| 474 | roArrDCol = new ROArrayColumn<Double>( srctabSel, "DIRECTION" ) ;
|
---|
| 475 | srcDir = (*roArrDCol)( 0 ) ;
|
---|
| 476 | delete roArrDCol ;
|
---|
| 477 |
|
---|
| 478 | // source direction as MDirection object
|
---|
| 479 | ROScalarMeasColumn<MDirection> *tmpMeasCol = new ROScalarMeasColumn<MDirection>( srctabSel, "DIRECTION" ) ;
|
---|
| 480 | md = (*tmpMeasCol)( 0 ) ;
|
---|
| 481 | delete tmpMeasCol ;
|
---|
| 482 |
|
---|
| 483 | // number of lines
|
---|
| 484 | tcolr = tpoolr->construct( srctabSel, "NUM_LINES" ) ;
|
---|
[2059] | 485 | numLines = tcolr->asInt( 0 ) ;
|
---|
[2033] | 486 | tpoolr->destroy( tcolr ) ;
|
---|
| 487 |
|
---|
| 488 | }
|
---|
| 489 | else {
|
---|
| 490 | md = MDirection( Quantum<Double>(0.0,Unit("rad")), Quantum<Double>(0.0,Unit("rad")) ) ;
|
---|
| 491 | }
|
---|
| 492 |
|
---|
[2002] | 493 | // SRCNAME
|
---|
| 494 | strRF.attachToRecord( trec, "SRCNAME" ) ;
|
---|
| 495 | *strRF = srcName ;
|
---|
| 496 |
|
---|
[2033] | 497 | // os_ << "srcName = " << srcName << LogIO::POST ;
|
---|
[2002] | 498 |
|
---|
| 499 | // SRCPROPERMOTION
|
---|
| 500 | RecordFieldPtr< Array<Double> > darrRF( trec, "SRCPROPERMOTION" ) ;
|
---|
| 501 | *darrRF = srcPM ;
|
---|
| 502 |
|
---|
[1974] | 503 | //os_ << "srcPM = " << srcPM << LogIO::POST ;
|
---|
[2002] | 504 |
|
---|
| 505 | // SRCDIRECTION
|
---|
| 506 | darrRF.attachToRecord( trec, "SRCDIRECTION" ) ;
|
---|
| 507 | *darrRF = srcDir ;
|
---|
| 508 |
|
---|
[1974] | 509 | //os_ << "srcDir = " << srcDir << LogIO::POST ;
|
---|
[2021] | 510 |
|
---|
[1974] | 511 | // for MOLECULES subtable
|
---|
[2021] | 512 | // os_ << "numLines = " << numLines << LogIO::POST ;
|
---|
| 513 |
|
---|
[1974] | 514 | Vector<Double> restFreqs( numLines, 0.0 ) ;
|
---|
| 515 | Vector<String> transitionName( numLines, "" ) ;
|
---|
[2021] | 516 | Vector<Double> sysVels ;
|
---|
| 517 | Double sysVel = 0.0 ;
|
---|
[1974] | 518 | if ( numLines != 0 ) {
|
---|
[1987] | 519 | if ( srctabSel.tableDesc().isColumn( "REST_FREQUENCY" ) ) {
|
---|
| 520 | sharedQDArrCol = new ROArrayQuantColumn<Double>( srctabSel, "REST_FREQUENCY" ) ;
|
---|
| 521 | Array< Quantum<Double> > qRestFreqs = (*sharedQDArrCol)( 0 ) ;
|
---|
| 522 | delete sharedQDArrCol ;
|
---|
| 523 | for ( int i = 0 ; i < numLines ; i++ ) {
|
---|
| 524 | restFreqs[i] = qRestFreqs( IPosition( 1, i ) ).getValue( "Hz" ) ;
|
---|
| 525 | }
|
---|
[1974] | 526 | }
|
---|
[2033] | 527 | // os_ << "restFreqs = " << restFreqs << LogIO::POST ;
|
---|
[1974] | 528 | if ( srctabSel.tableDesc().isColumn( "TRANSITION" ) ) {
|
---|
[2004] | 529 | ROArrayColumn<String> transitionCol( srctabSel, "TRANSITION" ) ;
|
---|
| 530 | if ( transitionCol.isDefined( 0 ) )
|
---|
| 531 | transitionName = transitionCol( 0 ) ;
|
---|
| 532 | //os_ << "transitionNameCol.nrow() = " << transitionCol.nrow() << LogIO::POST ;
|
---|
[1974] | 533 | }
|
---|
[2021] | 534 | if ( srctabSel.tableDesc().isColumn( "SYSVEL" ) ) {
|
---|
| 535 | roArrDCol = new ROArrayColumn<Double>( srctabSel, "SYSVEL" ) ;
|
---|
| 536 | sysVels = (*roArrDCol)( 0 ) ;
|
---|
| 537 | delete roArrDCol ;
|
---|
| 538 | }
|
---|
| 539 | if ( !sysVels.empty() ) {
|
---|
| 540 | //os_ << "sysVels.shape() = " << sysVels.shape() << LogIO::POST ;
|
---|
| 541 | // NB: assume all SYSVEL values are the same
|
---|
| 542 | sysVel = sysVels( IPosition(1,0) ) ;
|
---|
| 543 | }
|
---|
[1974] | 544 | }
|
---|
[2021] | 545 |
|
---|
| 546 | // SRCVELOCITY
|
---|
| 547 | RecordFieldPtr<Double> doubleRF( trec, "SRCVELOCITY" ) ;
|
---|
| 548 | *doubleRF = sysVel ;
|
---|
| 549 |
|
---|
| 550 | // os_ << "sysVel = " << sysVel << LogIO::POST ;
|
---|
| 551 |
|
---|
[1974] | 552 | uInt molId = table_->molecules().addEntry( restFreqs, transitionName, transitionName ) ;
|
---|
[2002] | 553 |
|
---|
| 554 | // MOLECULE_ID
|
---|
| 555 | uintRF.attachToRecord( trec, "MOLECULE_ID" ) ;
|
---|
| 556 | *uintRF = molId ;
|
---|
| 557 |
|
---|
[1974] | 558 | // spectral setup
|
---|
| 559 | MeasFrame mf( me, mp, md ) ;
|
---|
[1987] | 560 | tcolr = tpoolr->construct( spwtab, "MEAS_FREQ_REF" ) ;
|
---|
| 561 | MFrequency::Types freqRef = MFrequency::castType((uInt)(tcolr->asInt(spwId))) ;
|
---|
| 562 | tpoolr->destroy( tcolr ) ;
|
---|
| 563 | tcolr = tpoolr->construct( spwtab, "NUM_CHAN" ) ;
|
---|
| 564 | Int nchan = tcolr->asInt( spwId ) ;
|
---|
| 565 | tpoolr->destroy( tcolr ) ;
|
---|
[1974] | 566 | Bool even = False ;
|
---|
| 567 | if ( (nchan/2)*2 == nchan ) even = True ;
|
---|
[1993] | 568 | sdh.nchan = max( sdh.nchan, nchan ) ;
|
---|
[1987] | 569 | ROScalarQuantColumn<Double> *tmpQuantCol = new ROScalarQuantColumn<Double>( spwtab, "TOTAL_BANDWIDTH" ) ;
|
---|
| 570 | Double totbw = (*tmpQuantCol)( spwId ).getValue( "Hz" ) ;
|
---|
| 571 | delete tmpQuantCol ;
|
---|
[1993] | 572 | sdh.bandwidth = max( sdh.bandwidth, totbw ) ;
|
---|
[1974] | 573 | if ( sdh.freqref == "" )
|
---|
| 574 | //sdh.freqref = MFrequency::showType( freqRef ) ;
|
---|
| 575 | sdh.freqref = "LSRK" ;
|
---|
| 576 | if ( sdh.reffreq == -1.0 ) {
|
---|
[1987] | 577 | tmpQuantCol = new ROScalarQuantColumn<Double>( spwtab, "REF_FREQUENCY" ) ;
|
---|
| 578 | Quantum<Double> qreffreq = (*tmpQuantCol)( spwId ) ;
|
---|
| 579 | delete tmpQuantCol ;
|
---|
[1974] | 580 | if ( freqRef == MFrequency::LSRK ) {
|
---|
| 581 | sdh.reffreq = qreffreq.getValue("Hz") ;
|
---|
| 582 | }
|
---|
| 583 | else {
|
---|
| 584 | MFrequency::Convert tolsr( freqRef, MFrequency::Ref( MFrequency::LSRK, mf ) ) ;
|
---|
| 585 | sdh.reffreq = tolsr( qreffreq ).get("Hz").getValue() ;
|
---|
| 586 | }
|
---|
| 587 | }
|
---|
| 588 | Int refchan = nchan / 2 ;
|
---|
| 589 | IPosition refip( 1, refchan ) ;
|
---|
[2027] | 590 | //Double refpix = 0.5*(nchan-1) ;
|
---|
| 591 | Double refpix = 0.5*(nchan) ;
|
---|
[1974] | 592 | Double refval = 0.0 ;
|
---|
[1987] | 593 | sharedQDArrCol = new ROArrayQuantColumn<Double>( spwtab, "CHAN_WIDTH" ) ;
|
---|
| 594 | Double increment = (*sharedQDArrCol)( spwId )( refip ).getValue( "Hz" ) ;
|
---|
| 595 | delete sharedQDArrCol ;
|
---|
[2033] | 596 | // os_ << "nchan = " << nchan << " refchan = " << refchan << "(even=" << even << ") refpix = " << refpix << LogIO::POST ;
|
---|
[1987] | 597 | sharedQDArrCol = new ROArrayQuantColumn<Double>( spwtab, "CHAN_FREQ" ) ;
|
---|
| 598 | Vector< Quantum<Double> > chanFreqs = (*sharedQDArrCol)( spwId ) ;
|
---|
| 599 | delete sharedQDArrCol ;
|
---|
[1974] | 600 | if ( freqRef == MFrequency::LSRK ) {
|
---|
| 601 | if ( even ) {
|
---|
| 602 | IPosition refip0( 1, refchan-1 ) ;
|
---|
| 603 | Double refval0 = chanFreqs(refip0).getValue("Hz") ;
|
---|
| 604 | Double refval1 = chanFreqs(refip).getValue("Hz") ;
|
---|
| 605 | refval = 0.5 * ( refval0 + refval1 ) ;
|
---|
| 606 | }
|
---|
| 607 | else {
|
---|
| 608 | refval = chanFreqs(refip).getValue("Hz") ;
|
---|
| 609 | }
|
---|
| 610 | }
|
---|
| 611 | else {
|
---|
| 612 | MFrequency::Convert tolsr( freqRef, MFrequency::Ref( MFrequency::LSRK, mf ) ) ;
|
---|
| 613 | if ( even ) {
|
---|
| 614 | IPosition refip0( 1, refchan-1 ) ;
|
---|
| 615 | Double refval0 = chanFreqs(refip0).getValue("Hz") ;
|
---|
| 616 | Double refval1 = chanFreqs(refip).getValue("Hz") ;
|
---|
| 617 | refval = 0.5 * ( refval0 + refval1 ) ;
|
---|
| 618 | refval = tolsr( refval ).get("Hz").getValue() ;
|
---|
| 619 | }
|
---|
| 620 | else {
|
---|
| 621 | refval = tolsr( chanFreqs(refip) ).get("Hz").getValue() ;
|
---|
| 622 | }
|
---|
| 623 | }
|
---|
| 624 | uInt freqId = table_->frequencies().addEntry( refpix, refval, increment ) ;
|
---|
| 625 | if ( ifmap.find( spwId ) == ifmap.end() ) {
|
---|
| 626 | ifmap.insert( pair<Int, uInt>(spwId,freqId) ) ;
|
---|
| 627 | //os_ << "added to ifmap: (" << spwId << "," << freqId << ")" << LogIO::POST ;
|
---|
| 628 | }
|
---|
[2002] | 629 |
|
---|
| 630 | // FREQ_ID
|
---|
| 631 | uintRF.attachToRecord( trec, "FREQ_ID" ) ;
|
---|
| 632 | *uintRF = freqId ;
|
---|
| 633 |
|
---|
[1974] | 634 | // for TSYS and TCAL
|
---|
[2004] | 635 | Vector<MEpoch> scTime ;
|
---|
| 636 | Vector<Double> scInterval ;
|
---|
| 637 | ROArrayColumn<Float> scTsysCol ;
|
---|
| 638 | MSSysCal caltabsel ;
|
---|
| 639 | if ( isSysCal_ ) {
|
---|
| 640 | caltabsel = caltab( caltab.col("ANTENNA_ID") == antenna_ && caltab.col("FEED_ID") == feedId && caltab.col("SPECTRAL_WINDOW_ID") == spwId ).sort("TIME") ;
|
---|
| 641 | ROScalarMeasColumn<MEpoch> scTimeCol( caltabsel, "TIME" ) ;
|
---|
| 642 | scTime.resize( caltabsel.nrow() ) ;
|
---|
| 643 | for ( uInt irow = 0 ; irow < caltabsel.nrow() ; irow++ )
|
---|
| 644 | scTime[irow] = scTimeCol( irow ) ;
|
---|
| 645 | ROScalarColumn<Double> *scIntervalCol = new ROScalarColumn<Double>( caltabsel, "INTERVAL" ) ;
|
---|
| 646 | scInterval = scIntervalCol->getColumn() ;
|
---|
| 647 | delete scIntervalCol ;
|
---|
| 648 | scTsysCol.attach( caltabsel, colTsys_ ) ;
|
---|
| 649 | }
|
---|
[2021] | 650 | // time1 = gettimeofday_sec() ;
|
---|
| 651 | // os_ << "end 3rd iteration init: " << time1 << " (" << time1-time0 << "sec)" << LogIO::POST ;
|
---|
[1974] | 652 | //
|
---|
| 653 | // ITERATION: SCAN_NUMBER
|
---|
| 654 | //
|
---|
| 655 | TableIterator iter4( t3, "SCAN_NUMBER" ) ;
|
---|
| 656 | while( !iter4.pastEnd() ) {
|
---|
[2021] | 657 | // time0 = gettimeofday_sec() ;
|
---|
| 658 | // os_ << "start 4th iteration: " << time0 << LogIO::POST ;
|
---|
[1987] | 659 | Table t4 = iter4.table() ;
|
---|
| 660 | tcolr = tpoolr->construct( t4, "SCAN_NUMBER" ) ;
|
---|
| 661 | Int scanNum = tcolr->asInt( 0 ) ;
|
---|
| 662 | tpoolr->destroy( tcolr ) ;
|
---|
[2002] | 663 |
|
---|
| 664 | // SCANNO
|
---|
| 665 | uintRF.attachToRecord( trec, "SCANNO" ) ;
|
---|
| 666 | *uintRF = scanNum - 1 ;
|
---|
| 667 |
|
---|
[2021] | 668 | // time1 = gettimeofday_sec() ;
|
---|
| 669 | // os_ << "end 4th iteration init: " << time1 << " (" << time1-time0 << "sec)" << LogIO::POST ;
|
---|
[1974] | 670 | //
|
---|
| 671 | // ITERATION: STATE_ID
|
---|
| 672 | //
|
---|
| 673 | TableIterator iter5( t4, "STATE_ID" ) ;
|
---|
| 674 | while( !iter5.pastEnd() ) {
|
---|
[2033] | 675 | // time0 = gettimeofday_sec() ;
|
---|
| 676 | // os_ << "start 5th iteration: " << time0 << LogIO::POST ;
|
---|
[1987] | 677 | Table t5 = iter5.table() ;
|
---|
| 678 | tcolr = tpoolr->construct( t5, "STATE_ID" ) ;
|
---|
| 679 | Int stateId = tcolr->asInt( 0 ) ;
|
---|
| 680 | tpoolr->destroy( tcolr ) ;
|
---|
| 681 | tcolr = tpoolr->construct( stattab, "OBS_MODE" ) ;
|
---|
| 682 | String obstype = tcolr->asString( stateId ) ;
|
---|
| 683 | tpoolr->destroy( tcolr ) ;
|
---|
[1974] | 684 | if ( sdh.obstype == "" ) sdh.obstype = obstype ;
|
---|
| 685 |
|
---|
| 686 | Int nrow = t5.nrow() ;
|
---|
[2033] | 687 | // time1 = gettimeofday_sec() ;
|
---|
| 688 | // os_ << "end 5th iteration init: " << time1 << " (" << time1-time0 << "sec)" << LogIO::POST ;
|
---|
[2002] | 689 |
|
---|
[2004] | 690 | uInt cycle = 0 ;
|
---|
| 691 |
|
---|
[2002] | 692 | Cube<Float> spArr ;
|
---|
| 693 | Cube<Bool> flArr ;
|
---|
[1974] | 694 | if ( isFloatData_ ) {
|
---|
[2002] | 695 | ROArrayColumn<Bool> mFlagCol( t5, "FLAG" ) ;
|
---|
[1974] | 696 | ROArrayColumn<Float> mFloatDataCol( t5, "FLOAT_DATA" ) ;
|
---|
[2002] | 697 | spArr = mFloatDataCol.getColumn() ;
|
---|
| 698 | flArr = mFlagCol.getColumn() ;
|
---|
[1974] | 699 | if ( sdh.fluxunit == "" ) {
|
---|
[2002] | 700 | const TableRecord &dataColKeys = mFloatDataCol.keywordSet() ;
|
---|
[1974] | 701 | if ( dataColKeys.isDefined( "UNIT" ) )
|
---|
| 702 | sdh.fluxunit = dataColKeys.asString( "UNIT" ) ;
|
---|
| 703 | }
|
---|
| 704 | }
|
---|
| 705 | else if ( isData_ ) {
|
---|
[2002] | 706 | spArr.resize( npol, nchan, nrow ) ;
|
---|
[2004] | 707 | flArr.resize( npol, nchan, nrow ) ;
|
---|
[2002] | 708 | ROArrayColumn<Bool> mFlagCol( t5, "FLAG" ) ;
|
---|
[1974] | 709 | ROArrayColumn<Complex> mDataCol( t5, "DATA" ) ;
|
---|
[1987] | 710 | for ( Int irow = 0 ; irow < nrow ; irow++ ) {
|
---|
| 711 | Bool crossOK = False ;
|
---|
| 712 | Matrix<Complex> sp = mDataCol( irow ) ;
|
---|
[2002] | 713 | Matrix<Bool> fl = mFlagCol( irow ) ;
|
---|
[2004] | 714 | Matrix<Float> spxy = spArr.xyPlane( irow ) ;
|
---|
| 715 | Matrix<Bool> flxy = flArr.xyPlane( irow ) ;
|
---|
[1987] | 716 | for ( Int ipol = 0 ; ipol < npol ; ipol++ ) {
|
---|
| 717 | if ( corrtype[ipol] == Stokes::XY || corrtype[ipol] == Stokes::YX
|
---|
| 718 | || corrtype[ipol] == Stokes::RL || corrtype[ipol] == Stokes::LR ) {
|
---|
| 719 | if ( !crossOK ) {
|
---|
[2004] | 720 | spxy.row( ipol ) = real( sp.row( ipol ) ) ;
|
---|
| 721 | flxy.row( ipol ) = fl.row( ipol ) ;
|
---|
[2002] | 722 | if ( corrtype[ipol] == Stokes::XY || corrtype[ipol] == Stokes::RL ) {
|
---|
[2004] | 723 | spxy.row( ipol+1 ) = imag( sp.row( ipol ) ) ;
|
---|
| 724 | flxy.row( ipol+1 ) = fl.row( ipol ) ;
|
---|
[2002] | 725 | }
|
---|
| 726 | else {
|
---|
[2004] | 727 | spxy.row( ipol+1 ) = imag( conj( sp.row( ipol ) ) ) ;
|
---|
| 728 | flxy.row( ipol+1 ) = fl.row( ipol ) ;
|
---|
[2002] | 729 | }
|
---|
[2004] | 730 | crossOK = True ;
|
---|
[1974] | 731 | }
|
---|
| 732 | }
|
---|
[1987] | 733 | else {
|
---|
[2004] | 734 | spxy.row( ipol ) = real( sp.row( ipol ) ) ;
|
---|
| 735 | flxy.row( ipol ) = fl.row( ipol ) ;
|
---|
[1987] | 736 | }
|
---|
[1974] | 737 | }
|
---|
[1987] | 738 | }
|
---|
[1974] | 739 | if ( sdh.fluxunit == "" ) {
|
---|
[2002] | 740 | const TableRecord &dataColKeys = mDataCol.keywordSet() ;
|
---|
[1974] | 741 | if ( dataColKeys.isDefined( "UNIT" ) )
|
---|
[2002] | 742 | sdh.fluxunit = dataColKeys.asString( "UNIT" ) ;
|
---|
| 743 | }
|
---|
[1974] | 744 | }
|
---|
[1987] | 745 | ROScalarMeasColumn<MEpoch> *mTimeCol = new ROScalarMeasColumn<MEpoch>( t5, "TIME" ) ;
|
---|
[2002] | 746 | Block<MEpoch> mTimeB( nrow ) ;
|
---|
| 747 | for ( Int irow = 0 ; irow < nrow ; irow++ )
|
---|
| 748 | mTimeB[irow] = (*mTimeCol)( irow ) ;
|
---|
| 749 | ROTableColumn *mIntervalCol = tpoolr->construct( t5, "INTERVAL" ) ;
|
---|
| 750 | ROTableColumn *mFlagRowCol = tpoolr->construct( t5, "FLAG_ROW" ) ;
|
---|
| 751 | Block<Int> sysCalIdx( nrow, -1 ) ;
|
---|
| 752 | if ( isSysCal_ ) {
|
---|
[2017] | 753 | getSysCalTime( scTime, scInterval, mTimeB, sysCalIdx ) ;
|
---|
[1974] | 754 | }
|
---|
[2002] | 755 | delete mTimeCol ;
|
---|
| 756 | Matrix<Float> defaulttsys( npol, 1, 1.0 ) ;
|
---|
| 757 | Int srcType = getSrcType( stateId, tpoolr ) ;
|
---|
| 758 | uInt diridx = 0 ;
|
---|
| 759 | MDirection::Types dirType ;
|
---|
| 760 | uInt wid = 0 ;
|
---|
| 761 | Int pidx = 0 ;
|
---|
| 762 | Bool crossOK = False ;
|
---|
| 763 | Block<uInt> polnos( npol, 99 ) ;
|
---|
| 764 | for ( Int ipol = 0 ; ipol < npol ; ipol++ ) {
|
---|
| 765 | Block<uInt> p = getPolNo( corrtype[ipol] ) ;
|
---|
| 766 | if ( p.size() > 1 ) {
|
---|
| 767 | if ( crossOK ) continue ;
|
---|
| 768 | else {
|
---|
| 769 | polnos[pidx] = p[0] ;
|
---|
| 770 | pidx++ ;
|
---|
| 771 | polnos[pidx] = p[1] ;
|
---|
| 772 | pidx++ ;
|
---|
| 773 | crossOK = True ;
|
---|
[1974] | 774 | }
|
---|
| 775 | }
|
---|
[2002] | 776 | else {
|
---|
| 777 | polnos[pidx] = p[0] ;
|
---|
| 778 | pidx++ ;
|
---|
| 779 | }
|
---|
[1974] | 780 | }
|
---|
[2002] | 781 |
|
---|
| 782 | // SRCTYPE
|
---|
| 783 | intRF.attachToRecord( trec, "SRCTYPE" ) ;
|
---|
| 784 | *intRF = srcType ;
|
---|
[1974] | 785 |
|
---|
[2002] | 786 | for ( Int irow = 0 ; irow < nrow ; irow++ ) {
|
---|
| 787 | // CYCLENO
|
---|
| 788 | *cycleRF = cycle ;
|
---|
[1987] | 789 |
|
---|
[2002] | 790 | // FLAGROW
|
---|
| 791 | *flrRF = (uInt)mFlagRowCol->asBool( irow ) ;
|
---|
| 792 |
|
---|
| 793 | // SPECTRA, FLAG
|
---|
| 794 | Matrix<Float> sp = spArr.xyPlane( irow ) ;
|
---|
| 795 | Matrix<Bool> flb = flArr.xyPlane( irow ) ;
|
---|
| 796 | Matrix<uChar> fl( flb.shape() ) ;
|
---|
| 797 | convertArray( fl, flb ) ;
|
---|
| 798 |
|
---|
| 799 | // TIME
|
---|
[2004] | 800 | *timeRF = mTimeB[irow].get("d").getValue() ;
|
---|
[2002] | 801 |
|
---|
| 802 | // INTERVAL
|
---|
| 803 | *intervalRF = (Double)(mIntervalCol->asdouble( irow )) ;
|
---|
| 804 |
|
---|
| 805 | // TSYS
|
---|
| 806 | Matrix<Float> tsys ;
|
---|
| 807 | if ( sysCalIdx[irow] != -1 )
|
---|
| 808 | tsys = scTsysCol( irow ) ;
|
---|
| 809 | else
|
---|
| 810 | tsys = defaulttsys ;
|
---|
| 811 |
|
---|
| 812 | // TCAL_ID
|
---|
[2004] | 813 | Block<uInt> tcalids( npol, 0 ) ;
|
---|
| 814 | if ( sysCalIdx[irow] != -1 ) {
|
---|
| 815 | tcalids = getTcalId( feedId, spwId, scTime[sysCalIdx[irow]] ) ;
|
---|
[1987] | 816 | }
|
---|
| 817 |
|
---|
[2002] | 818 | // WEATHER_ID
|
---|
| 819 | if ( isWeather_ )
|
---|
| 820 | wid = getWeatherId( wid, mTimeB[irow].get("s").getValue() ) ;
|
---|
| 821 | *widRF = wid ;
|
---|
| 822 |
|
---|
[1987] | 823 |
|
---|
[2002] | 824 | // DIRECTION, AZEL, SCANRATE
|
---|
| 825 | if ( getPt_ ) {
|
---|
[1974] | 826 | Vector<Double> dir ;
|
---|
| 827 | Vector<Double> scanrate ;
|
---|
| 828 | String refString ;
|
---|
[2002] | 829 | diridx = getDirection( diridx, dir, scanrate, refString, pointtab, mTimeB[irow].get("s").getValue() ) ;
|
---|
[1974] | 830 | MDirection::getType( dirType, refString ) ;
|
---|
[2002] | 831 | mf.resetEpoch( mTimeB[irow] ) ;
|
---|
[1974] | 832 | mf.resetDirection( MDirection( MVDirection(dir), dirType ) ) ;
|
---|
| 833 | if ( refString == "J2000" ) {
|
---|
[2002] | 834 | *dirRF = dir ;
|
---|
[1974] | 835 | MDirection::Convert toazel( dirType, MDirection::Ref( MDirection::AZEL, mf ) ) ;
|
---|
| 836 | Vector<Double> azel = toazel( dir ).getAngle("rad").getValue() ;
|
---|
[2002] | 837 | *azRF = (Float)azel(0) ;
|
---|
| 838 | *elRF = (Float)azel(1) ;
|
---|
[1974] | 839 | }
|
---|
| 840 | else if ( refString(0,4) == "AZEL" ) {
|
---|
[2002] | 841 | *azRF = (Float)dir(0) ;
|
---|
| 842 | *elRF = (Float)dir(1) ;
|
---|
[1974] | 843 | MDirection::Convert toj2000( dirType, MDirection::Ref( MDirection::J2000, mf ) ) ;
|
---|
| 844 | Vector<Double> newdir = toj2000( dir ).getAngle("rad").getValue() ;
|
---|
[2002] | 845 | *dirRF = newdir ;
|
---|
[1974] | 846 | }
|
---|
| 847 | else {
|
---|
| 848 | MDirection::Convert toazel( dirType, MDirection::Ref( MDirection::AZEL, mf ) ) ;
|
---|
| 849 | Vector<Double> azel = toazel( dir ).getAngle("rad").getValue() ;
|
---|
| 850 | MDirection::Convert toj2000( dirType, MDirection::Ref( MDirection::J2000, mf ) ) ;
|
---|
| 851 | Vector<Double> newdir = toj2000( dir ).getAngle("rad").getValue() ;
|
---|
[2002] | 852 | *dirRF = newdir ;
|
---|
| 853 | *azRF = (Float)azel(0) ;
|
---|
| 854 | *elRF = (Float)azel(1) ;
|
---|
[1974] | 855 | }
|
---|
| 856 | if ( scanrate.size() != 0 ) {
|
---|
[2002] | 857 | *scrRF = scanrate ;
|
---|
[1974] | 858 | }
|
---|
| 859 | else {
|
---|
[2002] | 860 | *scrRF = defaultScanrate ;
|
---|
[1974] | 861 | }
|
---|
| 862 | }
|
---|
[2002] | 863 | else {
|
---|
| 864 | String ref = md.getRefString() ;
|
---|
[2004] | 865 | //Vector<Double> defaultDir = srcDir ;
|
---|
[2002] | 866 | MDirection::getType( dirType, "J2000" ) ;
|
---|
| 867 | if ( ref != "J2000" ) {
|
---|
| 868 | ROScalarMeasColumn<MEpoch> tmCol( pointtab, "TIME" ) ;
|
---|
| 869 | mf.resetEpoch( tmCol( 0 ) ) ;
|
---|
| 870 | MDirection::Convert toj2000( dirType, MDirection::Ref( MDirection::J2000, mf ) ) ;
|
---|
| 871 | defaultDir = toj2000( defaultDir ).getAngle("rad").getValue() ;
|
---|
[1974] | 872 | }
|
---|
[2002] | 873 | mf.resetEpoch( mTimeB[irow] ) ;
|
---|
| 874 | MDirection::Convert toazel( dirType, MDirection::Ref( MDirection::AZEL, mf ) ) ;
|
---|
| 875 | Vector<Double> azel = toazel( defaultDir ).getAngle("rad").getValue() ;
|
---|
| 876 | *azRF = (Float)azel(0) ;
|
---|
| 877 | *elRF = (Float)azel(1) ;
|
---|
| 878 | *dirRF = defaultDir ;
|
---|
| 879 | *scrRF = defaultScanrate ;
|
---|
[1974] | 880 | }
|
---|
| 881 |
|
---|
[2002] | 882 | // Polarization dependent things
|
---|
| 883 | for ( Int ipol = 0 ; ipol < npol ; ipol++ ) {
|
---|
| 884 | // POLNO
|
---|
| 885 | *polnoRF = polnos[ipol] ;
|
---|
[1987] | 886 |
|
---|
[2019] | 887 | //*spRF = sp.row( ipol ) ;
|
---|
| 888 | //*ucarrRF = fl.row( ipol ) ;
|
---|
| 889 | //*tsysRF = tsys.row( ipol ) ;
|
---|
| 890 | spRF.define( sp.row( ipol ) ) ;
|
---|
| 891 | ucarrRF.define( fl.row( ipol ) ) ;
|
---|
| 892 | tsysRF.define( tsys.row( ipol ) ) ;
|
---|
[2002] | 893 | *tcalidRF = tcalids[ipol] ;
|
---|
[1987] | 894 |
|
---|
[2002] | 895 | // Commit row
|
---|
| 896 | stab.addRow() ;
|
---|
| 897 | row.put( stab.nrow()-1 ) ;
|
---|
[1987] | 898 | }
|
---|
[2004] | 899 |
|
---|
| 900 | cycle++ ;
|
---|
[1987] | 901 | }
|
---|
[2002] | 902 | tpoolr->destroy( mIntervalCol ) ;
|
---|
| 903 | tpoolr->destroy( mFlagRowCol ) ;
|
---|
[1987] | 904 |
|
---|
[2033] | 905 | // time1 = gettimeofday_sec() ;
|
---|
| 906 | // os_ << "end 5th iteration: " << time1 << " (" << time1-time0 << "sec)" << LogIO::POST ;
|
---|
[1974] | 907 |
|
---|
| 908 | iter5.next() ;
|
---|
| 909 | }
|
---|
[1978] | 910 |
|
---|
| 911 |
|
---|
[1974] | 912 | iter4.next() ;
|
---|
| 913 | }
|
---|
[1978] | 914 |
|
---|
| 915 |
|
---|
[1974] | 916 | iter3.next() ;
|
---|
| 917 | }
|
---|
[1978] | 918 |
|
---|
[1990] | 919 |
|
---|
[1974] | 920 | iter2.next() ;
|
---|
| 921 | }
|
---|
[1978] | 922 |
|
---|
| 923 |
|
---|
[1974] | 924 | iter1.next() ;
|
---|
| 925 | }
|
---|
| 926 | if ( sdh.nbeam < nbeam ) sdh.nbeam = nbeam ;
|
---|
[1978] | 927 |
|
---|
[1974] | 928 | iter0.next() ;
|
---|
| 929 | }
|
---|
| 930 |
|
---|
[1987] | 931 |
|
---|
| 932 | delete tpoolr ;
|
---|
| 933 |
|
---|
| 934 |
|
---|
[1978] | 935 | // Table Keywords
|
---|
[2004] | 936 | // TODO: This must be updated if writer will be replaced from STWriter to MSWriter
|
---|
| 937 | // sdh.nif = ifmap.size() ;
|
---|
| 938 | sdh.nif++ ;
|
---|
[1987] | 939 | if ( ( telescopeName == "" ) || ( antennaName == telescopeName ) ) {
|
---|
[1974] | 940 | sdh.antennaname = antennaName ;
|
---|
| 941 | }
|
---|
| 942 | else {
|
---|
| 943 | sdh.antennaname = telescopeName + "//" + antennaName ;
|
---|
| 944 | }
|
---|
| 945 | if ( stationName != "" ) {
|
---|
| 946 | sdh.antennaname += "@" + stationName ;
|
---|
| 947 | }
|
---|
[1987] | 948 | ROArrayColumn<Double> pdirCol( pointtab, "DIRECTION" ) ;
|
---|
| 949 | String dirref = pdirCol.keywordSet().asRecord("MEASINFO").asString("Ref") ;
|
---|
[1974] | 950 | if ( dirref == "AZELGEO" || dirref == "AZEL" ) {
|
---|
| 951 | dirref = "J2000" ;
|
---|
| 952 | }
|
---|
| 953 | sscanf( dirref.chars()+1, "%f", &sdh.equinox ) ;
|
---|
| 954 | sdh.epoch = "UTC" ;
|
---|
| 955 | if (sdh.freqref == "TOPO") {
|
---|
| 956 | sdh.freqref = "TOPOCENT";
|
---|
| 957 | } else if (sdh.freqref == "GEO") {
|
---|
| 958 | sdh.freqref = "GEOCENTR";
|
---|
| 959 | } else if (sdh.freqref == "BARY") {
|
---|
| 960 | sdh.freqref = "BARYCENT";
|
---|
| 961 | } else if (sdh.freqref == "GALACTO") {
|
---|
| 962 | sdh.freqref = "GALACTOC";
|
---|
| 963 | } else if (sdh.freqref == "LGROUP") {
|
---|
| 964 | sdh.freqref = "LOCALGRP";
|
---|
| 965 | } else if (sdh.freqref == "CMB") {
|
---|
| 966 | sdh.freqref = "CMBDIPOL";
|
---|
| 967 | } else if (sdh.freqref == "REST") {
|
---|
| 968 | sdh.freqref = "SOURCE";
|
---|
| 969 | }
|
---|
| 970 | table_->setHeader( sdh ) ;
|
---|
[1987] | 971 |
|
---|
| 972 | // save path to POINTING table
|
---|
[2022] | 973 | // 2011/3/2 TN
|
---|
| 974 | // So far, path to original POINTING table is always stored
|
---|
| 975 | // since sd tasks and regressions don't support getpt control
|
---|
| 976 | //if ( !getPt_ ) {
|
---|
[1987] | 977 | Path datapath( tablename_ ) ;
|
---|
| 978 | String pTabName = datapath.absoluteName() + "/POINTING" ;
|
---|
[1990] | 979 | stab.rwKeywordSet().define( "POINTING", pTabName ) ;
|
---|
[2022] | 980 | //}
|
---|
[1987] | 981 |
|
---|
| 982 | // for GBT
|
---|
[2024] | 983 | if ( antennaName.contains( "GBT" ) ) {
|
---|
[1987] | 984 | String goTabName = datapath.absoluteName() + "/GBT_GO" ;
|
---|
[1990] | 985 | stab.rwKeywordSet().define( "GBT_GO", goTabName ) ;
|
---|
[1987] | 986 | }
|
---|
[2022] | 987 |
|
---|
| 988 | // for MS created from ASDM
|
---|
| 989 | //mstable_.keywordSet().print(cout) ;
|
---|
| 990 | const TableRecord &msKeys = mstable_.keywordSet() ;
|
---|
| 991 | uInt nfields = msKeys.nfields() ;
|
---|
| 992 | for ( uInt ifield = 0 ; ifield < nfields ; ifield++ ) {
|
---|
| 993 | String name = msKeys.name( ifield ) ;
|
---|
| 994 | //os_ << "name = " << name << LogIO::POST ;
|
---|
| 995 | if ( name.find( "ASDM" ) != String::npos ) {
|
---|
| 996 | String asdmpath = msKeys.asTable( ifield ).tableName() ;
|
---|
| 997 | os_ << "ASDM table: " << asdmpath << LogIO::POST ;
|
---|
| 998 | stab.rwKeywordSet().define( name, asdmpath ) ;
|
---|
| 999 | }
|
---|
| 1000 | }
|
---|
| 1001 |
|
---|
[2004] | 1002 | // double endSec = gettimeofday_sec() ;
|
---|
| 1003 | // os_ << "end MSFiller::fill() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
[1974] | 1004 | }
|
---|
| 1005 |
|
---|
| 1006 | void MSFiller::close()
|
---|
| 1007 | {
|
---|
[1987] | 1008 | //tablesel_.closeSubTables() ;
|
---|
[1974] | 1009 | mstable_.closeSubTables() ;
|
---|
[1987] | 1010 | //tablesel_.unlock() ;
|
---|
[1974] | 1011 | mstable_.unlock() ;
|
---|
| 1012 | }
|
---|
| 1013 |
|
---|
[1987] | 1014 | Int MSFiller::getSrcType( Int stateId, boost::object_pool<ROTableColumn> *tpool )
|
---|
[1974] | 1015 | {
|
---|
[2004] | 1016 | // double startSec = gettimeofday_sec() ;
|
---|
| 1017 | // os_ << "start MSFiller::getSrcType() startSec=" << startSec << LogIO::POST ;
|
---|
[1974] | 1018 |
|
---|
| 1019 | MSState statetab = mstable_.state() ;
|
---|
[1987] | 1020 | ROTableColumn *sharedCol ;
|
---|
| 1021 | sharedCol = tpool->construct( statetab, "OBS_MODE" ) ;
|
---|
| 1022 | String obsMode = sharedCol->asString( stateId ) ;
|
---|
| 1023 | tpool->destroy( sharedCol ) ;
|
---|
| 1024 | sharedCol = tpool->construct( statetab, "SIG" ) ;
|
---|
| 1025 | Bool sig = sharedCol->asBool( stateId ) ;
|
---|
| 1026 | tpool->destroy( sharedCol ) ;
|
---|
| 1027 | sharedCol = tpool->construct( statetab, "REF" ) ;
|
---|
| 1028 | Bool ref = sharedCol->asBool( stateId ) ;
|
---|
| 1029 | tpool->destroy( sharedCol ) ;
|
---|
| 1030 | sharedCol = tpool->construct( statetab, "CAL" ) ;
|
---|
| 1031 | Double cal = (Double)(sharedCol->asdouble( stateId )) ;
|
---|
| 1032 | tpool->destroy( sharedCol ) ;
|
---|
[1974] | 1033 | //os_ << "OBS_MODE = " << obsMode << LogIO::POST ;
|
---|
| 1034 |
|
---|
| 1035 | // determine separator
|
---|
| 1036 | String sep = "" ;
|
---|
[2039] | 1037 | String tmpStr = obsMode.substr( 0, obsMode.find_first_of( "," ) ) ;
|
---|
[2049] | 1038 | //os_ << "tmpStr = " << tmpStr << LogIO::POST ;
|
---|
[2039] | 1039 | //if ( obsMode.find( ":" ) != String::npos ) {
|
---|
| 1040 | if ( tmpStr.find( ":" ) != String::npos ) {
|
---|
[1974] | 1041 | sep = ":" ;
|
---|
| 1042 | }
|
---|
[2039] | 1043 | //else if ( obsMode.find( "." ) != String::npos ) {
|
---|
| 1044 | else if ( tmpStr.find( "." ) != String::npos ) {
|
---|
[1974] | 1045 | sep = "." ;
|
---|
| 1046 | }
|
---|
[2039] | 1047 | //else if ( obsMode.find( "_" ) != String::npos ) {
|
---|
| 1048 | else if ( tmpStr.find( "_" ) != String::npos ) {
|
---|
| 1049 | sep = "_" ;
|
---|
| 1050 | }
|
---|
[2049] | 1051 | //os_ << "separator = " << sep << LogIO::POST ;
|
---|
[2028] | 1052 |
|
---|
[1974] | 1053 | // determine SRCTYPE
|
---|
| 1054 | Int srcType = SrcType::NOTYPE ;
|
---|
| 1055 | if ( sep == ":" ) {
|
---|
| 1056 | // sep == ":"
|
---|
| 1057 | //
|
---|
| 1058 | // GBT case
|
---|
| 1059 | //
|
---|
| 1060 | // obsMode1=Nod
|
---|
| 1061 | // NOD
|
---|
| 1062 | // obsMode1=OffOn
|
---|
| 1063 | // obsMode2=PSWITCHON: PSON
|
---|
| 1064 | // obsMode2=PSWITCHOFF: PSOFF
|
---|
| 1065 | // obsMode1=??
|
---|
| 1066 | // obsMode2=FSWITCH:
|
---|
| 1067 | // SIG=1: FSON
|
---|
| 1068 | // REF=1: FSOFF
|
---|
[1987] | 1069 | // Calibration scan if CAL != 0
|
---|
[1974] | 1070 | Int epos = obsMode.find_first_of( sep ) ;
|
---|
| 1071 | Int nextpos = obsMode.find_first_of( sep, epos+1 ) ;
|
---|
| 1072 | String obsMode1 = obsMode.substr( 0, epos ) ;
|
---|
| 1073 | String obsMode2 = obsMode.substr( epos+1, nextpos-epos-1 ) ;
|
---|
| 1074 | if ( obsMode1 == "Nod" ) {
|
---|
| 1075 | srcType = SrcType::NOD ;
|
---|
| 1076 | }
|
---|
| 1077 | else if ( obsMode1 == "OffOn" ) {
|
---|
| 1078 | if ( obsMode2 == "PSWITCHON" ) srcType = SrcType::PSON ;
|
---|
| 1079 | if ( obsMode2 == "PSWITCHOFF" ) srcType = SrcType::PSOFF ;
|
---|
| 1080 | }
|
---|
| 1081 | else {
|
---|
| 1082 | if ( obsMode2 == "FSWITCH" ) {
|
---|
| 1083 | if ( sig ) srcType = SrcType::FSON ;
|
---|
| 1084 | if ( ref ) srcType = SrcType::FSOFF ;
|
---|
| 1085 | }
|
---|
| 1086 | }
|
---|
[1987] | 1087 | if ( cal > 0.0 ) {
|
---|
| 1088 | if ( srcType == SrcType::NOD )
|
---|
| 1089 | srcType = SrcType::NODCAL ;
|
---|
| 1090 | else if ( srcType == SrcType::PSON )
|
---|
| 1091 | srcType = SrcType::PONCAL ;
|
---|
| 1092 | else if ( srcType == SrcType::PSOFF )
|
---|
| 1093 | srcType = SrcType::POFFCAL ;
|
---|
| 1094 | else if ( srcType == SrcType::FSON )
|
---|
| 1095 | srcType = SrcType::FONCAL ;
|
---|
| 1096 | else if ( srcType == SrcType::FSOFF )
|
---|
| 1097 | srcType = SrcType::FOFFCAL ;
|
---|
| 1098 | else
|
---|
| 1099 | srcType = SrcType::CAL ;
|
---|
| 1100 | }
|
---|
[1974] | 1101 | }
|
---|
| 1102 | else if ( sep == "." ) {
|
---|
| 1103 | // sep == "."
|
---|
| 1104 | //
|
---|
[2039] | 1105 | // ALMA & EVLA case (MS via ASDM) before3.1
|
---|
[1974] | 1106 | //
|
---|
| 1107 | // obsMode1=CALIBRATE_*
|
---|
| 1108 | // obsMode2=ON_SOURCE: PONCAL
|
---|
| 1109 | // obsMode2=OFF_SOURCE: POFFCAL
|
---|
| 1110 | // obsMode1=OBSERVE_TARGET
|
---|
| 1111 | // obsMode2=ON_SOURCE: PON
|
---|
| 1112 | // obsMode2=OFF_SOURCE: POFF
|
---|
[2028] | 1113 | string substr[2] ;
|
---|
| 1114 | int numSubstr = split( obsMode, substr, 2, "," ) ;
|
---|
| 1115 | //os_ << "numSubstr = " << numSubstr << LogIO::POST ;
|
---|
| 1116 | //for ( int i = 0 ; i < numSubstr ; i++ )
|
---|
| 1117 | //os_ << "substr[" << i << "] = " << substr[i] << LogIO::POST ;
|
---|
| 1118 | String obsType( substr[0] ) ;
|
---|
| 1119 | //os_ << "obsType = " << obsType << LogIO::POST ;
|
---|
| 1120 | Int epos = obsType.find_first_of( sep ) ;
|
---|
| 1121 | Int nextpos = obsType.find_first_of( sep, epos+1 ) ;
|
---|
| 1122 | String obsMode1 = obsType.substr( 0, epos ) ;
|
---|
| 1123 | String obsMode2 = obsType.substr( epos+1, nextpos-epos-1 ) ;
|
---|
[2035] | 1124 | //os_ << "obsMode1 = " << obsMode1 << LogIO::POST ;
|
---|
| 1125 | //os_ << "obsMode2 = " << obsMode2 << LogIO::POST ;
|
---|
[1974] | 1126 | if ( obsMode1.find( "CALIBRATE_" ) == 0 ) {
|
---|
| 1127 | if ( obsMode2 == "ON_SOURCE" ) srcType = SrcType::PONCAL ;
|
---|
| 1128 | if ( obsMode2 == "OFF_SOURCE" ) srcType = SrcType::POFFCAL ;
|
---|
| 1129 | }
|
---|
| 1130 | else if ( obsMode1 == "OBSERVE_TARGET" ) {
|
---|
| 1131 | if ( obsMode2 == "ON_SOURCE" ) srcType = SrcType::PSON ;
|
---|
| 1132 | if ( obsMode2 == "OFF_SOURCE" ) srcType = SrcType::PSOFF ;
|
---|
| 1133 | }
|
---|
| 1134 | }
|
---|
[2039] | 1135 | else if ( sep == "_" ) {
|
---|
| 1136 | // sep == "_"
|
---|
| 1137 | //
|
---|
| 1138 | // ALMA & EVLA case (MS via ASDM) after 3.2
|
---|
| 1139 | //
|
---|
| 1140 | // obsMode1=CALIBRATE_*
|
---|
| 1141 | // obsMode2=ON_SOURCE: PONCAL
|
---|
| 1142 | // obsMode2=OFF_SOURCE: POFFCAL
|
---|
| 1143 | // obsMode1=OBSERVE_TARGET
|
---|
| 1144 | // obsMode2=ON_SOURCE: PON
|
---|
| 1145 | // obsMode2=OFF_SOURCE: POFF
|
---|
| 1146 | string substr[2] ;
|
---|
| 1147 | int numSubstr = split( obsMode, substr, 2, "," ) ;
|
---|
[2041] | 1148 | //os_ << "numSubstr = " << numSubstr << LogIO::POST ;
|
---|
[2039] | 1149 | //for ( int i = 0 ; i < numSubstr ; i++ )
|
---|
| 1150 | //os_ << "substr[" << i << "] = " << substr[i] << LogIO::POST ;
|
---|
| 1151 | String obsType( substr[0] ) ;
|
---|
| 1152 | //os_ << "obsType = " << obsType << LogIO::POST ;
|
---|
| 1153 | string substr2[4] ;
|
---|
| 1154 | int numSubstr2 = split( obsType, substr2, 4, sep ) ;
|
---|
| 1155 | //Int epos = obsType.find_first_of( sep ) ;
|
---|
| 1156 | //Int nextpos = obsType.find_first_of( sep, epos+1 ) ;
|
---|
| 1157 | //String obsMode1 = obsType.substr( 0, epos ) ;
|
---|
| 1158 | //String obsMode2 = obsType.substr( epos+1, nextpos-epos-1 ) ;
|
---|
| 1159 | String obsMode1( substr2[0] ) ;
|
---|
| 1160 | String obsMode2( substr2[2] ) ;
|
---|
| 1161 | //os_ << "obsMode1 = " << obsMode1 << LogIO::POST ;
|
---|
| 1162 | //os_ << "obsMode2 = " << obsMode2 << LogIO::POST ;
|
---|
| 1163 | if ( obsMode1.find( "CALIBRATE" ) == 0 ) {
|
---|
| 1164 | if ( obsMode2 == "ON" ) srcType = SrcType::PONCAL ;
|
---|
| 1165 | if ( obsMode2 == "OFF" ) srcType = SrcType::POFFCAL ;
|
---|
| 1166 | }
|
---|
| 1167 | else if ( obsMode1 == "OBSERVE" ) {
|
---|
| 1168 | if ( obsMode2 == "ON" ) srcType = SrcType::PSON ;
|
---|
| 1169 | if ( obsMode2 == "OFF" ) srcType = SrcType::PSOFF ;
|
---|
| 1170 | }
|
---|
| 1171 | }
|
---|
[1974] | 1172 | else {
|
---|
| 1173 | if ( sig ) srcType = SrcType::SIG ;
|
---|
| 1174 | if ( ref ) srcType = SrcType::REF ;
|
---|
| 1175 | }
|
---|
| 1176 |
|
---|
| 1177 | //os_ << "srcType = " << srcType << LogIO::POST ;
|
---|
[2004] | 1178 | // double endSec = gettimeofday_sec() ;
|
---|
| 1179 | // os_ << "end MSFiller::getSrcType() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
[1974] | 1180 | return srcType ;
|
---|
| 1181 | }
|
---|
| 1182 |
|
---|
[2002] | 1183 | //Vector<uInt> MSFiller::getPolNo( Int corrType )
|
---|
| 1184 | Block<uInt> MSFiller::getPolNo( Int corrType )
|
---|
[1974] | 1185 | {
|
---|
[2004] | 1186 | // double startSec = gettimeofday_sec() ;
|
---|
| 1187 | // os_ << "start MSFiller::getPolNo() startSec=" << startSec << LogIO::POST ;
|
---|
[2002] | 1188 | Block<uInt> polno( 1 ) ;
|
---|
[1974] | 1189 |
|
---|
| 1190 | if ( corrType == Stokes::I || corrType == Stokes::RR || corrType == Stokes::XX ) {
|
---|
| 1191 | polno = 0 ;
|
---|
| 1192 | }
|
---|
| 1193 | else if ( corrType == Stokes::Q || corrType == Stokes::LL || corrType == Stokes::YY ) {
|
---|
| 1194 | polno = 1 ;
|
---|
| 1195 | }
|
---|
| 1196 | else if ( corrType == Stokes::U ) {
|
---|
| 1197 | polno = 2 ;
|
---|
| 1198 | }
|
---|
| 1199 | else if ( corrType == Stokes::V ) {
|
---|
| 1200 | polno = 3 ;
|
---|
| 1201 | }
|
---|
| 1202 | else if ( corrType == Stokes::RL || corrType == Stokes::XY || corrType == Stokes::LR || corrType == Stokes::RL ) {
|
---|
| 1203 | polno.resize( 2 ) ;
|
---|
| 1204 | polno[0] = 2 ;
|
---|
| 1205 | polno[1] = 3 ;
|
---|
| 1206 | }
|
---|
| 1207 | else if ( corrType == Stokes::Plinear ) {
|
---|
| 1208 | polno[0] = 1 ;
|
---|
| 1209 | }
|
---|
| 1210 | else if ( corrType == Stokes::Pangle ) {
|
---|
| 1211 | polno[0] = 2 ;
|
---|
| 1212 | }
|
---|
| 1213 | else {
|
---|
| 1214 | polno = 99 ;
|
---|
| 1215 | }
|
---|
| 1216 | //os_ << "polno = " << polno << LogIO::POST ;
|
---|
[2004] | 1217 | // double endSec = gettimeofday_sec() ;
|
---|
| 1218 | // os_ << "end MSFiller::getPolNo() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
[1974] | 1219 |
|
---|
| 1220 | return polno ;
|
---|
| 1221 | }
|
---|
| 1222 |
|
---|
| 1223 | String MSFiller::getPolType( Int corrType )
|
---|
| 1224 | {
|
---|
[2004] | 1225 | // double startSec = gettimeofday_sec() ;
|
---|
| 1226 | // os_ << "start MSFiller::getPolType() startSec=" << startSec << LogIO::POST ;
|
---|
[1974] | 1227 | String poltype = "" ;
|
---|
| 1228 |
|
---|
| 1229 | if ( corrType == Stokes::I || corrType == Stokes::Q || corrType == Stokes::U || corrType == Stokes::V )
|
---|
| 1230 | poltype = "stokes" ;
|
---|
| 1231 | else if ( corrType == Stokes::XX || corrType == Stokes::YY || corrType == Stokes::XY || corrType == Stokes::YX )
|
---|
| 1232 | poltype = "linear" ;
|
---|
| 1233 | else if ( corrType == Stokes::RR || corrType == Stokes::LL || corrType == Stokes::RL || corrType == Stokes::LR )
|
---|
| 1234 | poltype = "circular" ;
|
---|
| 1235 | else if ( corrType == Stokes::Plinear || corrType == Stokes::Pangle )
|
---|
| 1236 | poltype = "linpol" ;
|
---|
| 1237 |
|
---|
[2004] | 1238 | // double endSec = gettimeofday_sec() ;
|
---|
| 1239 | // os_ << "end MSFiller::getPolType() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
[1974] | 1240 | return poltype ;
|
---|
| 1241 | }
|
---|
| 1242 |
|
---|
| 1243 | void MSFiller::fillWeather()
|
---|
| 1244 | {
|
---|
[2004] | 1245 | // double startSec = gettimeofday_sec() ;
|
---|
| 1246 | // os_ << "start MSFiller::fillWeather() startSec=" << startSec << LogIO::POST ;
|
---|
| 1247 |
|
---|
| 1248 | if ( !isWeather_ ) {
|
---|
| 1249 | // add dummy row
|
---|
| 1250 | table_->weather().table().addRow(1,True) ;
|
---|
| 1251 | return ;
|
---|
| 1252 | }
|
---|
| 1253 |
|
---|
[1987] | 1254 | Table mWeather = mstable_.weather() ;
|
---|
| 1255 | //Table mWeatherSel = mWeather( mWeather.col("ANTENNA_ID") == antenna_ ).sort("TIME") ;
|
---|
| 1256 | Table mWeatherSel( mWeather( mWeather.col("ANTENNA_ID") == antenna_ ).sort("TIME") ) ;
|
---|
[1974] | 1257 | //os_ << "mWeatherSel.nrow() = " << mWeatherSel.nrow() << LogIO::POST ;
|
---|
| 1258 | if ( mWeatherSel.nrow() == 0 ) {
|
---|
[2025] | 1259 | os_ << "No rows with ANTENNA_ID = " << antenna_ << " in WEATHER table, Try -1..." << LogIO::POST ;
|
---|
[1987] | 1260 | mWeatherSel = Table( MSWeather( mWeather( mWeather.col("ANTENNA_ID") == -1 ) ) ) ;
|
---|
[1974] | 1261 | if ( mWeatherSel.nrow() == 0 ) {
|
---|
| 1262 | os_ << "No rows in WEATHER table" << LogIO::POST ;
|
---|
| 1263 | }
|
---|
| 1264 | }
|
---|
[1987] | 1265 | uInt wnrow = mWeatherSel.nrow() ;
|
---|
[1974] | 1266 | //os_ << "wnrow = " << wnrow << LogIO::POST ;
|
---|
| 1267 |
|
---|
| 1268 | if ( wnrow == 0 )
|
---|
| 1269 | return ;
|
---|
| 1270 |
|
---|
| 1271 | Table wtab = table_->weather().table() ;
|
---|
| 1272 | wtab.addRow( wnrow ) ;
|
---|
| 1273 |
|
---|
[1987] | 1274 | ScalarColumn<Float> *fCol ;
|
---|
| 1275 | ROScalarColumn<Float> *sharedFloatCol ;
|
---|
| 1276 | if ( mWeatherSel.tableDesc().isColumn( "TEMPERATURE" ) ) {
|
---|
| 1277 | fCol = new ScalarColumn<Float>( wtab, "TEMPERATURE" ) ;
|
---|
| 1278 | sharedFloatCol = new ROScalarColumn<Float>( mWeatherSel, "TEMPERATURE" ) ;
|
---|
| 1279 | fCol->putColumn( *sharedFloatCol ) ;
|
---|
| 1280 | delete sharedFloatCol ;
|
---|
| 1281 | delete fCol ;
|
---|
| 1282 | }
|
---|
| 1283 | if ( mWeatherSel.tableDesc().isColumn( "PRESSURE" ) ) {
|
---|
| 1284 | fCol = new ScalarColumn<Float>( wtab, "PRESSURE" ) ;
|
---|
| 1285 | sharedFloatCol = new ROScalarColumn<Float>( mWeatherSel, "PRESSURE" ) ;
|
---|
| 1286 | fCol->putColumn( *sharedFloatCol ) ;
|
---|
| 1287 | delete sharedFloatCol ;
|
---|
| 1288 | delete fCol ;
|
---|
| 1289 | }
|
---|
| 1290 | if ( mWeatherSel.tableDesc().isColumn( "REL_HUMIDITY" ) ) {
|
---|
| 1291 | fCol = new ScalarColumn<Float>( wtab, "HUMIDITY" ) ;
|
---|
| 1292 | sharedFloatCol = new ROScalarColumn<Float>( mWeatherSel, "REL_HUMIDITY" ) ;
|
---|
| 1293 | fCol->putColumn( *sharedFloatCol ) ;
|
---|
| 1294 | delete sharedFloatCol ;
|
---|
| 1295 | delete fCol ;
|
---|
| 1296 | }
|
---|
| 1297 | if ( mWeatherSel.tableDesc().isColumn( "WIND_SPEED" ) ) {
|
---|
| 1298 | fCol = new ScalarColumn<Float>( wtab, "WINDSPEED" ) ;
|
---|
| 1299 | sharedFloatCol = new ROScalarColumn<Float>( mWeatherSel, "WIND_SPEED" ) ;
|
---|
| 1300 | fCol->putColumn( *sharedFloatCol ) ;
|
---|
| 1301 | delete sharedFloatCol ;
|
---|
| 1302 | delete fCol ;
|
---|
| 1303 | }
|
---|
| 1304 | if ( mWeatherSel.tableDesc().isColumn( "WIND_DIRECTION" ) ) {
|
---|
| 1305 | fCol = new ScalarColumn<Float>( wtab, "WINDAZ" ) ;
|
---|
| 1306 | sharedFloatCol = new ROScalarColumn<Float>( mWeatherSel, "WIND_DIRECTION" ) ;
|
---|
| 1307 | fCol->putColumn( *sharedFloatCol ) ;
|
---|
| 1308 | delete sharedFloatCol ;
|
---|
| 1309 | delete fCol ;
|
---|
| 1310 | }
|
---|
[1974] | 1311 | ScalarColumn<uInt> idCol( wtab, "ID" ) ;
|
---|
[1987] | 1312 | for ( uInt irow = 0 ; irow < wnrow ; irow++ )
|
---|
| 1313 | idCol.put( irow, irow ) ;
|
---|
[1974] | 1314 |
|
---|
[1987] | 1315 | ROScalarQuantColumn<Double> tqCol( mWeatherSel, "TIME" ) ;
|
---|
| 1316 | ROScalarColumn<Double> tCol( mWeatherSel, "TIME" ) ;
|
---|
| 1317 | String tUnit = tqCol.getUnits() ;
|
---|
| 1318 | mwTime_ = tCol.getColumn() ;
|
---|
[1974] | 1319 | if ( tUnit == "d" )
|
---|
| 1320 | mwTime_ *= 86400.0 ;
|
---|
[1987] | 1321 | tqCol.attach( mWeatherSel, "INTERVAL" ) ;
|
---|
| 1322 | tCol.attach( mWeatherSel, "INTERVAL" ) ;
|
---|
| 1323 | String iUnit = tqCol.getUnits() ;
|
---|
| 1324 | mwInterval_ = tCol.getColumn() ;
|
---|
[1974] | 1325 | if ( iUnit == "d" )
|
---|
| 1326 | mwInterval_ *= 86400.0 ;
|
---|
| 1327 | //os_ << "mwTime[0] = " << mwTime_[0] << " mwInterval[0] = " << mwInterval_[0] << LogIO::POST ;
|
---|
[2004] | 1328 | // double endSec = gettimeofday_sec() ;
|
---|
| 1329 | // os_ << "end MSFiller::fillWeather() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
[1974] | 1330 | }
|
---|
| 1331 |
|
---|
| 1332 | void MSFiller::fillFocus()
|
---|
| 1333 | {
|
---|
[2004] | 1334 | // double startSec = gettimeofday_sec() ;
|
---|
| 1335 | // os_ << "start MSFiller::fillFocus() startSec=" << startSec << LogIO::POST ;
|
---|
[1974] | 1336 | // tentative
|
---|
| 1337 | Table tab = table_->focus().table() ;
|
---|
| 1338 | tab.addRow( 1 ) ;
|
---|
| 1339 | ScalarColumn<uInt> idCol( tab, "ID" ) ;
|
---|
| 1340 | idCol.put( 0, 0 ) ;
|
---|
[2004] | 1341 | // double endSec = gettimeofday_sec() ;
|
---|
| 1342 | // os_ << "end MSFiller::fillFocus() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
[1974] | 1343 | }
|
---|
| 1344 |
|
---|
[2002] | 1345 | void MSFiller::fillTcal( boost::object_pool<ROTableColumn> *tpoolr )
|
---|
[1974] | 1346 | {
|
---|
[2004] | 1347 | // double startSec = gettimeofday_sec() ;
|
---|
| 1348 | // os_ << "start MSFiller::fillTcal() startSec=" << startSec << LogIO::POST ;
|
---|
[1987] | 1349 |
|
---|
[2004] | 1350 | if ( !isSysCal_ ) {
|
---|
| 1351 | // add dummy row
|
---|
[2025] | 1352 | os_ << "No SYSCAL rows" << LogIO::POST ;
|
---|
[2004] | 1353 | table_->tcal().table().addRow(1,True) ;
|
---|
[2021] | 1354 | Vector<Float> defaultTcal( 1, 1.0 ) ;
|
---|
| 1355 | ArrayColumn<Float> tcalCol( table_->tcal().table(), "TCAL" ) ;
|
---|
| 1356 | tcalCol.put( 0, defaultTcal ) ;
|
---|
[2004] | 1357 | return ;
|
---|
| 1358 | }
|
---|
| 1359 |
|
---|
[1987] | 1360 | Table sctab = mstable_.sysCal() ;
|
---|
[1974] | 1361 | if ( sctab.nrow() == 0 ) {
|
---|
[2025] | 1362 | os_ << "No SYSCAL rows" << LogIO::POST ;
|
---|
[1974] | 1363 | return ;
|
---|
| 1364 | }
|
---|
[1987] | 1365 | Table sctabsel( sctab( sctab.col("ANTENNA_ID") == antenna_ ) ) ;
|
---|
[1974] | 1366 | if ( sctabsel.nrow() == 0 ) {
|
---|
[2025] | 1367 | os_ << "No SYSCAL rows" << LogIO::POST ;
|
---|
[1974] | 1368 | return ;
|
---|
| 1369 | }
|
---|
[1987] | 1370 | ROArrayColumn<Float> *tmpTcalCol = new ROArrayColumn<Float>( sctabsel, "TCAL" ) ;
|
---|
| 1371 | uInt npol = tmpTcalCol->shape( 0 )(0) ;
|
---|
| 1372 | delete tmpTcalCol ;
|
---|
[1974] | 1373 | //os_ << "fillTcal(): npol = " << npol << LogIO::POST ;
|
---|
| 1374 | Table tab = table_->tcal().table() ;
|
---|
| 1375 | ArrayColumn<Float> tcalCol( tab, "TCAL" ) ;
|
---|
[1987] | 1376 | ROTableColumn *sharedCol ;
|
---|
[1974] | 1377 | uInt oldnr = 0 ;
|
---|
| 1378 | uInt newnr = 0 ;
|
---|
[2002] | 1379 | TableRow row( tab ) ;
|
---|
| 1380 | TableRecord &trec = row.record() ;
|
---|
| 1381 | RecordFieldPtr<uInt> idRF( trec, "ID" ) ;
|
---|
| 1382 | RecordFieldPtr<String> timeRF( trec, "TIME" ) ;
|
---|
| 1383 | RecordFieldPtr< Array<Float> > tcalRF( trec, "TCAL" ) ;
|
---|
[1974] | 1384 | TableIterator iter0( sctabsel, "FEED_ID" ) ;
|
---|
| 1385 | while( !iter0.pastEnd() ) {
|
---|
[1987] | 1386 | Table t0 = iter0.table() ;
|
---|
[1988] | 1387 | sharedCol = tpoolr->construct( t0, "FEED_ID" ) ;
|
---|
[1987] | 1388 | Int feedId = sharedCol->asInt( 0 ) ;
|
---|
[1988] | 1389 | tpoolr->destroy( sharedCol ) ;
|
---|
[1974] | 1390 | TableIterator iter1( t0, "SPECTRAL_WINDOW_ID" ) ;
|
---|
| 1391 | while( !iter1.pastEnd() ) {
|
---|
[1988] | 1392 | Table t1 = iter1.table() ;
|
---|
| 1393 | sharedCol = tpoolr->construct( t1, "SPECTRAL_WINDOW_ID" ) ;
|
---|
[1987] | 1394 | Int spwId = sharedCol->asInt( 0 ) ;
|
---|
[1988] | 1395 | tpoolr->destroy( sharedCol ) ;
|
---|
[2002] | 1396 | tmpTcalCol = new ROArrayColumn<Float>( t1, colTcal_ ) ;
|
---|
| 1397 | ROScalarQuantColumn<Double> scTimeCol( t1, "TIME" ) ;
|
---|
| 1398 | Vector<uInt> idminmax( 2, oldnr ) ;
|
---|
| 1399 | for ( uInt irow = 0 ; irow < t1.nrow() ; irow++ ) {
|
---|
| 1400 | String sTime = MVTime( scTimeCol(irow) ).string( MVTime::YMD ) ;
|
---|
| 1401 | *timeRF = sTime ;
|
---|
[1988] | 1402 | uInt idx = oldnr ;
|
---|
[2002] | 1403 | Matrix<Float> subtcal = (*tmpTcalCol)( irow ) ;
|
---|
[1988] | 1404 | for ( uInt ipol = 0 ; ipol < npol ; ipol++ ) {
|
---|
[2002] | 1405 | *idRF = idx++ ;
|
---|
[2019] | 1406 | //*tcalRF = subtcal.row( ipol ) ;
|
---|
| 1407 | tcalRF.define( subtcal.row( ipol ) ) ;
|
---|
[2002] | 1408 |
|
---|
| 1409 | // commit row
|
---|
| 1410 | tab.addRow() ;
|
---|
| 1411 | row.put( tab.nrow()-1 ) ;
|
---|
| 1412 |
|
---|
| 1413 | newnr++ ;
|
---|
[1974] | 1414 | }
|
---|
[2002] | 1415 | idminmax[0] = oldnr ;
|
---|
[1988] | 1416 | idminmax[1] = newnr - 1 ;
|
---|
| 1417 | oldnr = newnr ;
|
---|
| 1418 |
|
---|
[1990] | 1419 | String key = keyTcal( feedId, spwId, sTime ) ;
|
---|
[1988] | 1420 | tcalrec_.define( key, idminmax ) ;
|
---|
[1974] | 1421 | }
|
---|
[2002] | 1422 | delete tmpTcalCol ;
|
---|
[1974] | 1423 | iter1++ ;
|
---|
| 1424 | }
|
---|
| 1425 | iter0++ ;
|
---|
| 1426 | }
|
---|
| 1427 |
|
---|
| 1428 | //tcalrec_.print( std::cout ) ;
|
---|
[2004] | 1429 | // double endSec = gettimeofday_sec() ;
|
---|
| 1430 | // os_ << "end MSFiller::fillTcal() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
[1974] | 1431 | }
|
---|
| 1432 |
|
---|
| 1433 | uInt MSFiller::getWeatherId( uInt idx, Double wtime )
|
---|
| 1434 | {
|
---|
[2004] | 1435 | // double startSec = gettimeofday_sec() ;
|
---|
| 1436 | // os_ << "start MSFiller::getWeatherId() startSec=" << startSec << LogIO::POST ;
|
---|
[1974] | 1437 | uInt nrow = mwTime_.size() ;
|
---|
[2019] | 1438 | if ( nrow < 2 )
|
---|
[1974] | 1439 | return 0 ;
|
---|
| 1440 | uInt wid = nrow ;
|
---|
| 1441 | for ( uInt i = idx ; i < nrow-1 ; i++ ) {
|
---|
| 1442 | Double tStart = mwTime_[i]-0.5*mwInterval_[i] ;
|
---|
| 1443 | // use of INTERVAL column is problematic
|
---|
| 1444 | // since there are "blank" time of weather monitoring
|
---|
| 1445 | //Double tEnd = tStart + mwInterval_[i] ;
|
---|
| 1446 | Double tEnd = mwTime_[i+1]-0.5*mwInterval_[i+1] ;
|
---|
| 1447 | //os_ << "tStart = " << tStart << " dtEnd = " << tEnd-tStart << " dwtime = " << wtime-tStart << LogIO::POST ;
|
---|
| 1448 | if ( wtime >= tStart && wtime <= tEnd ) {
|
---|
| 1449 | wid = i ;
|
---|
| 1450 | break ;
|
---|
| 1451 | }
|
---|
| 1452 | }
|
---|
| 1453 | if ( wid == nrow ) {
|
---|
| 1454 | uInt i = nrow - 1 ;
|
---|
| 1455 | Double tStart = mwTime_[i-1]+0.5*mwInterval_[i-1] ;
|
---|
| 1456 | Double tEnd = mwTime_[i]+0.5*mwInterval_[i] ;
|
---|
| 1457 | //os_ << "tStart = " << tStart << " dtEnd = " << tEnd-tStart << " dwtime = " << wtime-tStart << LogIO::POST ;
|
---|
| 1458 | if ( wtime >= tStart && wtime <= tEnd )
|
---|
[2021] | 1459 | wid = i-1 ;
|
---|
| 1460 | else
|
---|
[1974] | 1461 | wid = i ;
|
---|
| 1462 | }
|
---|
| 1463 |
|
---|
| 1464 | //if ( wid == nrow )
|
---|
| 1465 | //os_ << LogIO::WARN << "Couldn't find correct WEATHER_ID for time " << wtime << LogIO::POST ;
|
---|
| 1466 |
|
---|
[2004] | 1467 | // double endSec = gettimeofday_sec() ;
|
---|
| 1468 | // os_ << "end MSFiller::getWeatherId() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
[1974] | 1469 | return wid ;
|
---|
| 1470 | }
|
---|
| 1471 |
|
---|
[2017] | 1472 | void MSFiller::getSysCalTime( Vector<MEpoch> &scTime, Vector<Double> &scInterval, Block<MEpoch> &tcol, Block<Int> &tidx )
|
---|
[1974] | 1473 | {
|
---|
[2004] | 1474 | // double startSec = gettimeofday_sec() ;
|
---|
| 1475 | // os_ << "start MSFiller::getSysCalTime() startSec=" << startSec << LogIO::POST ;
|
---|
| 1476 |
|
---|
| 1477 | if ( !isSysCal_ )
|
---|
| 1478 | return ;
|
---|
| 1479 |
|
---|
[2017] | 1480 | uInt nrow = tidx.nelements() ;
|
---|
[2002] | 1481 | if ( scTime.nelements() == 0 )
|
---|
[1993] | 1482 | return ;
|
---|
[2019] | 1483 | else if ( scTime.nelements() == 1 ) {
|
---|
| 1484 | tidx[0] = 0 ;
|
---|
| 1485 | return ;
|
---|
| 1486 | }
|
---|
[2002] | 1487 | uInt scnrow = scTime.nelements() ;
|
---|
[1974] | 1488 | uInt idx = 0 ;
|
---|
| 1489 | const Double half = 0.5e0 ;
|
---|
[2003] | 1490 | // execute binary search
|
---|
| 1491 | idx = binarySearch( scTime, tcol[0].get( "s" ).getValue() ) ;
|
---|
| 1492 | if ( idx != 0 )
|
---|
| 1493 | idx -= 1 ;
|
---|
[1974] | 1494 | for ( uInt i = 0 ; i < nrow ; i++ ) {
|
---|
[2002] | 1495 | Double t = tcol[i].get( "s" ).getValue() ;
|
---|
[2017] | 1496 | Double tsc = scTime[0].get( "s" ).getValue() ;
|
---|
| 1497 | if ( t < tsc ) {
|
---|
| 1498 | tidx[i] = 0 ;
|
---|
| 1499 | continue ;
|
---|
| 1500 | }
|
---|
[1974] | 1501 | for ( uInt j = idx ; j < scnrow-1 ; j++ ) {
|
---|
[2002] | 1502 | Double tsc1 = scTime[j].get( "s" ).getValue() ;
|
---|
| 1503 | Double dt1 = scInterval[j] ;
|
---|
| 1504 | Double tsc2 = scTime[j+1].get( "s" ).getValue() ;
|
---|
| 1505 | Double dt2 = scInterval[j+1] ;
|
---|
[1974] | 1506 | if ( t > tsc1-half*dt1 && t <= tsc2-half*dt2 ) {
|
---|
[2002] | 1507 | tidx[i] = j ;
|
---|
[1974] | 1508 | idx = j ;
|
---|
| 1509 | break ;
|
---|
| 1510 | }
|
---|
| 1511 | }
|
---|
[2017] | 1512 | if ( tidx[i] == -1 ) {
|
---|
[2022] | 1513 | // Double tsc = scTime[scnrow-1].get( "s" ).getValue() ;
|
---|
| 1514 | // Double dt = scInterval[scnrow-1] ;
|
---|
[2017] | 1515 | // if ( t <= tsc+0.5*dt ) {
|
---|
| 1516 | // tidx[i] = scnrow-1 ;
|
---|
| 1517 | // }
|
---|
| 1518 | tidx[i] = scnrow-1 ;
|
---|
[1974] | 1519 | }
|
---|
| 1520 | }
|
---|
[2004] | 1521 | // double endSec = gettimeofday_sec() ;
|
---|
| 1522 | // os_ << "end MSFiller::getSysCalTime() endSec=" << endSec << " (" << endSec-startSec << "sec) scnrow = " << scnrow << " tcol.nelements = " << tcol.nelements() << LogIO::POST ;
|
---|
[1993] | 1523 | return ;
|
---|
[1974] | 1524 | }
|
---|
| 1525 |
|
---|
[2004] | 1526 | Block<uInt> MSFiller::getTcalId( Int fid, Int spwid, MEpoch &t )
|
---|
| 1527 | {
|
---|
[2002] | 1528 | // double startSec = gettimeofday_sec() ;
|
---|
[2004] | 1529 | // os_ << "start MSFiller::getTcalId() startSec=" << startSec << LogIO::POST ;
|
---|
| 1530 | //if ( table_->tcal().table().nrow() == 0 ) {
|
---|
| 1531 | if ( !isSysCal_ ) {
|
---|
[1988] | 1532 | os_ << "No TCAL rows" << LogIO::POST ;
|
---|
[2002] | 1533 | Block<uInt> tcalids( 0 ) ;
|
---|
[1988] | 1534 | return tcalids ;
|
---|
| 1535 | }
|
---|
[2004] | 1536 | //String sctime = MVTime( Quantum<Double>(t,"s") ).string(MVTime::YMD) ;
|
---|
| 1537 | String sctime = MVTime( t.getValue() ).string(MVTime::YMD) ;
|
---|
[1990] | 1538 | String key = keyTcal( fid, spwid, sctime ) ;
|
---|
[1988] | 1539 | if ( !tcalrec_.isDefined( key ) ) {
|
---|
[1974] | 1540 | os_ << "No TCAL rows" << LogIO::POST ;
|
---|
[2002] | 1541 | Block<uInt> tcalids( 0 ) ;
|
---|
[1974] | 1542 | return tcalids ;
|
---|
| 1543 | }
|
---|
[1988] | 1544 | Vector<uInt> ids = tcalrec_.asArrayuInt( key ) ;
|
---|
| 1545 | uInt npol = ids[1] - ids[0] + 1 ;
|
---|
[2002] | 1546 | Block<uInt> tcalids( npol ) ;
|
---|
[1988] | 1547 | tcalids[0] = ids[0] ;
|
---|
| 1548 | tcalids[1] = ids[1] ;
|
---|
| 1549 | for ( uInt ipol = 2 ; ipol < npol ; ipol++ )
|
---|
| 1550 | tcalids[ipol] = ids[0] + ipol - 1 ;
|
---|
| 1551 |
|
---|
[2004] | 1552 | // double endSec = gettimeofday_sec() ;
|
---|
| 1553 | // os_ << "end MSFiller::getTcalId() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
[1974] | 1554 | return tcalids ;
|
---|
| 1555 | }
|
---|
| 1556 |
|
---|
[1987] | 1557 | uInt MSFiller::getDirection( uInt idx, Vector<Double> &dir, Vector<Double> &srate, String &ref, MSPointing &tab, Double t )
|
---|
[1974] | 1558 | {
|
---|
[2004] | 1559 | // double startSec = gettimeofday_sec() ;
|
---|
| 1560 | // os_ << "start MSFiller::getDirection() startSec=" << startSec << LogIO::POST ;
|
---|
[1974] | 1561 | // assume that cols is sorted by TIME
|
---|
| 1562 | Bool doInterp = False ;
|
---|
[1987] | 1563 | //uInt nrow = cols.nrow() ;
|
---|
| 1564 | uInt nrow = tab.nrow() ;
|
---|
[1974] | 1565 | if ( nrow == 0 )
|
---|
| 1566 | return 0 ;
|
---|
[1987] | 1567 | ROScalarMeasColumn<MEpoch> tcol( tab, "TIME" ) ;
|
---|
| 1568 | ROArrayMeasColumn<MDirection> dmcol( tab, "DIRECTION" ) ;
|
---|
| 1569 | ROArrayColumn<Double> dcol( tab, "DIRECTION" ) ;
|
---|
[2003] | 1570 | // binary search if idx == 0
|
---|
| 1571 | if ( idx == 0 ) {
|
---|
| 1572 | uInt nrowb = 75000 ;
|
---|
[2004] | 1573 | if ( nrow > nrowb ) {
|
---|
[2003] | 1574 | uInt nblock = nrow / nrowb + 1 ;
|
---|
| 1575 | for ( uInt iblock = 0 ; iblock < nblock ; iblock++ ) {
|
---|
[2004] | 1576 | uInt high = min( nrowb, nrow-iblock*nrowb ) ;
|
---|
[2003] | 1577 |
|
---|
| 1578 | if ( tcol( high-1 ).get( "s" ).getValue() < t ) {
|
---|
[2004] | 1579 | idx = iblock * nrowb ;
|
---|
[2003] | 1580 | continue ;
|
---|
| 1581 | }
|
---|
| 1582 |
|
---|
| 1583 | Vector<MEpoch> tarr( high ) ;
|
---|
| 1584 | for ( uInt irow = 0 ; irow < high ; irow++ ) {
|
---|
[2004] | 1585 | tarr[irow] = tcol( iblock*nrowb+irow ) ;
|
---|
[2003] | 1586 | }
|
---|
| 1587 |
|
---|
| 1588 | uInt bidx = binarySearch( tarr, t ) ;
|
---|
| 1589 |
|
---|
[2004] | 1590 | idx = iblock * nrowb + bidx ;
|
---|
[2003] | 1591 | break ;
|
---|
| 1592 | }
|
---|
| 1593 | }
|
---|
| 1594 | else {
|
---|
| 1595 | Vector<MEpoch> tarr( nrow ) ;
|
---|
| 1596 | for ( uInt irow = 0 ; irow < nrow ; irow++ ) {
|
---|
| 1597 | tarr[irow] = tcol( irow ) ;
|
---|
| 1598 | }
|
---|
| 1599 | idx = binarySearch( tarr, t ) ;
|
---|
| 1600 | }
|
---|
| 1601 | }
|
---|
[1974] | 1602 | // ensure that tcol(idx) < t
|
---|
| 1603 | //os_ << "tcol(idx) = " << tcol(idx).get("s").getValue() << " t = " << t << " diff = " << tcol(idx).get("s").getValue()-t << endl ;
|
---|
| 1604 | while ( tcol(idx).get("s").getValue() > t && idx > 0 )
|
---|
| 1605 | idx-- ;
|
---|
| 1606 | //os_ << "idx = " << idx << LogIO::POST ;
|
---|
| 1607 |
|
---|
| 1608 | // index search
|
---|
| 1609 | for ( uInt i = idx ; i < nrow ; i++ ) {
|
---|
| 1610 | Double tref = tcol( i ).get( "s" ).getValue() ;
|
---|
| 1611 | if ( tref == t ) {
|
---|
| 1612 | idx = i ;
|
---|
| 1613 | break ;
|
---|
| 1614 | }
|
---|
| 1615 | else if ( tref > t ) {
|
---|
| 1616 | if ( i == 0 ) {
|
---|
| 1617 | idx = i ;
|
---|
| 1618 | }
|
---|
| 1619 | else {
|
---|
| 1620 | idx = i-1 ;
|
---|
| 1621 | doInterp = True ;
|
---|
| 1622 | }
|
---|
| 1623 | break ;
|
---|
| 1624 | }
|
---|
| 1625 | else {
|
---|
| 1626 | idx = nrow - 1 ;
|
---|
| 1627 | }
|
---|
| 1628 | }
|
---|
| 1629 | //os_ << "searched idx = " << idx << LogIO::POST ;
|
---|
| 1630 |
|
---|
| 1631 | //os_ << "dmcol(idx).shape() = " << dmcol(idx).shape() << LogIO::POST ;
|
---|
| 1632 | IPosition ip( dmcol(idx).shape().nelements(), 0 ) ;
|
---|
| 1633 | //os_ << "ip = " << ip << LogIO::POST ;
|
---|
| 1634 | ref = dmcol(idx)(ip).getRefString() ;
|
---|
| 1635 | //os_ << "ref = " << ref << LogIO::POST ;
|
---|
| 1636 | if ( doInterp ) {
|
---|
| 1637 | //os_ << "do interpolation" << LogIO::POST ;
|
---|
| 1638 | //os_ << "dcol(idx).shape() = " << dcol(idx).shape() << LogIO::POST ;
|
---|
| 1639 | Double tref0 = tcol(idx).get("s").getValue() ;
|
---|
| 1640 | Double tref1 = tcol(idx+1).get("s").getValue() ;
|
---|
[1987] | 1641 | Matrix<Double> mdir0 = dcol( idx ) ;
|
---|
| 1642 | Matrix<Double> mdir1 = dcol( idx+1 ) ;
|
---|
| 1643 | Vector<Double> dir0 = mdir0.column( 0 ) ;
|
---|
[1974] | 1644 | //os_ << "dir0 = " << dir0 << LogIO::POST ;
|
---|
[1987] | 1645 | Vector<Double> dir1 = mdir1.column( 0 ) ;
|
---|
[1974] | 1646 | //os_ << "dir1 = " << dir1 << LogIO::POST ;
|
---|
| 1647 | Double dt0 = t - tref0 ;
|
---|
| 1648 | Double dt1 = tref1 - t ;
|
---|
| 1649 | dir.reference( (dt0*dir1+dt1*dir0)/(dt0+dt1) ) ;
|
---|
[1987] | 1650 | if ( mdir0.ncolumn() > 1 ) {
|
---|
| 1651 | if ( dt0 >= dt1 )
|
---|
| 1652 | srate.reference( mdir0.column( 1 ) ) ;
|
---|
| 1653 | else
|
---|
| 1654 | srate.reference( mdir1.column( 1 ) ) ;
|
---|
[1974] | 1655 | }
|
---|
| 1656 | //os_ << "dir = " << dir << LogIO::POST ;
|
---|
| 1657 | }
|
---|
| 1658 | else {
|
---|
| 1659 | //os_ << "no interpolation" << LogIO::POST ;
|
---|
[1987] | 1660 | Matrix<Double> mdir0 = dcol( idx ) ;
|
---|
| 1661 | dir.reference( mdir0.column( 0 ) ) ;
|
---|
| 1662 | if ( mdir0.ncolumn() > 1 )
|
---|
| 1663 | srate.reference( mdir0.column( 1 ) ) ;
|
---|
[1974] | 1664 | }
|
---|
| 1665 |
|
---|
[2004] | 1666 | // double endSec = gettimeofday_sec() ;
|
---|
| 1667 | // os_ << "end MSFiller::getDirection() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
[1974] | 1668 | return idx ;
|
---|
| 1669 | }
|
---|
| 1670 |
|
---|
[1990] | 1671 | String MSFiller::keyTcal( Int feedid, Int spwid, String stime )
|
---|
| 1672 | {
|
---|
| 1673 | String sfeed = "FEED" + String::toString( feedid ) ;
|
---|
| 1674 | String sspw = "SPW" + String::toString( spwid ) ;
|
---|
| 1675 | return sfeed+":"+sspw+":"+stime ;
|
---|
| 1676 | }
|
---|
| 1677 |
|
---|
[2003] | 1678 | uInt MSFiller::binarySearch( Vector<MEpoch> &timeList, Double target )
|
---|
| 1679 | {
|
---|
| 1680 | Int low = 0 ;
|
---|
| 1681 | Int high = timeList.nelements() ;
|
---|
| 1682 | uInt idx = 0 ;
|
---|
| 1683 |
|
---|
| 1684 | while ( low <= high ) {
|
---|
| 1685 | idx = (Int)( 0.5 * ( low + high ) ) ;
|
---|
| 1686 | Double t = timeList[idx].get( "s" ).getValue() ;
|
---|
| 1687 | if ( t < target )
|
---|
| 1688 | low = idx + 1 ;
|
---|
| 1689 | else if ( t > target )
|
---|
| 1690 | high = idx - 1 ;
|
---|
| 1691 | else
|
---|
| 1692 | return idx ;
|
---|
| 1693 | }
|
---|
| 1694 |
|
---|
| 1695 | idx = max( 0, min( low, high ) ) ;
|
---|
| 1696 |
|
---|
| 1697 | return idx ;
|
---|
| 1698 |
|
---|
| 1699 | }
|
---|
| 1700 |
|
---|
[1974] | 1701 | } ;
|
---|
| 1702 |
|
---|