- Timestamp:
- 02/28/11 18:50:34 (14 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/MSWriter.cpp
r1987 r2016 17 17 #include <casa/OS/SymLink.h> 18 18 #include <casa/BasicSL/String.h> 19 #include <casa/Containers/RecordField.h> 20 #include <casa/Arrays/Cube.h> 19 21 20 22 #include <tables/Tables/ExprNode.h> … … 23 25 #include <tables/Tables/TableIter.h> 24 26 #include <tables/Tables/RefRows.h> 27 #include <tables/Tables/TableRow.h> 25 28 26 29 #include <ms/MeasurementSets/MeasurementSet.h> … … 36 39 #include "STTcal.h" 37 40 41 #include <ctime> 42 #include <sys/time.h> 43 44 // Boost 45 #include <boost/pool/object_pool.hpp> 46 38 47 using namespace casa ; 39 40 namespace asap 41 { 48 using namespace std ; 49 50 namespace asap { 51 double MSWriter::gettimeofday_sec() 52 { 53 struct timeval tv ; 54 gettimeofday( &tv, NULL ) ; 55 return tv.tv_sec + (double)tv.tv_usec*1.0e-6 ; 56 } 42 57 43 58 MSWriter::MSWriter(CountedPtr<Scantable> stable) 44 : table_(stable) 59 : table_(stable), 60 ptTabName_("") 45 61 { 46 62 os_ = LogIO() ; … … 56 72 os_.origin( LogOrigin( "MSWriter", "~MSWriter()", WHERE ) ) ; 57 73 os_ << "MSWriter::~MSWriter()" << LogIO::POST ; 74 75 if ( mstable_ != 0 ) 76 delete mstable_ ; 58 77 } 59 78 … … 61 80 { 62 81 os_.origin( LogOrigin( "MSWriter", "write()", WHERE ) ) ; 63 os_ << "MSWriter::write()" << LogIO::POST ; 82 double startSec = gettimeofday_sec() ; 83 os_ << "start MSWriter::write() startSec=" << startSec << LogIO::POST ; 64 84 65 85 filename_ = filename ; … … 91 111 } 92 112 113 // TEST 114 // memory allocation by boost::object_pool 115 // boost::object_pool<ROTableColumn> *tpoolr = new boost::object_pool<ROTableColumn> ; 116 // ROTableColumn *tcol = 0 ; 117 // 118 93 119 // set up MS 94 120 setupMS() ; … … 114 140 Vector<uInt> processedFreqId( 0 ) ; 115 141 Int defaultFieldId = 0 ; 142 143 // row based 144 TableRow row( *mstable_ ) ; 145 TableRecord &trec = row.record() ; 146 NoticeTarget *dataRF = 0 ; 147 if ( useFloatData_ ) 148 dataRF = new RecordFieldPtr< Array<Float> >( trec, "FLOAT_DATA" ) ; 149 else if ( useData_ ) 150 dataRF = new RecordFieldPtr< Array<Complex> >( trec, "DATA" ) ; 151 RecordFieldPtr< Array<Bool> > flagRF( trec, "FLAG" ) ; 152 RecordFieldPtr<Bool> flagrowRF( trec, "FLAG_ROW" ) ; 153 RecordFieldPtr<Double> timeRF( trec, "TIME" ) ; 154 RecordFieldPtr<Double> timecRF( trec, "TIME_CENTROID" ) ; 155 RecordFieldPtr<Double> intervalRF( trec, "INTERVAL" ) ; 156 RecordFieldPtr<Double> exposureRF( trec, "EXPOSURE" ) ; 157 RecordFieldPtr< Array<Float> > weightRF( trec, "WEIGHT" ) ; 158 RecordFieldPtr< Array<Float> > sigmaRF( trec, "SIGMA" ) ; 159 RecordFieldPtr<Int> ddidRF( trec, "DATA_DESC_ID" ) ; 160 RecordFieldPtr<Int> stateidRF( trec, "STATE_ID" ) ; 161 162 163 // OBSERVATION_ID is always 0 164 RecordFieldPtr<Int> intRF( trec, "OBSERVATION_ID" ) ; 165 *intRF = 0 ; 166 167 // ANTENNA1 and ANTENNA2 are always 0 168 intRF.attachToRecord( trec, "ANTENNA1" ) ; 169 *intRF = 0 ; 170 intRF.attachToRecord( trec, "ANTENNA2" ) ; 171 *intRF = 0 ; 172 173 // ARRAY_ID is tentatively set to 0 174 intRF.attachToRecord( trec, "ARRAY_ID" ) ; 175 *intRF = 0 ; 176 177 // PROCESSOR_ID is tentatively set to 0 178 intRF.attachToRecord( trec, "PROCESSOR_ID" ) ; 179 *intRF = 0 ; 180 181 // UVW is always [0,0,0] 182 RecordFieldPtr< Array<Double> > uvwRF( trec, "UVW" ) ; 183 *uvwRF = Vector<Double>( 3, 0.0 ) ; 184 116 185 // 117 186 // ITERATION: FIELDNAME 118 187 // 119 Int added0 = 0 ;120 Int current0 = mstable_->nrow() ;121 188 TableIterator iter0( table_->table(), "FIELDNAME" ) ; 122 189 while( !iter0.pastEnd() ) { 123 Table t0( iter0.table() ) ; 124 ROScalarColumn<String> sharedStrCol( t0, "FIELDNAME" ) ; 125 String fieldName = sharedStrCol( 0 ) ; 126 sharedStrCol.attach( t0, "SRCNAME" ) ; 127 String srcName = sharedStrCol( 0 ) ; 128 ROScalarColumn<Double> timeCol( t0, "TIME" ) ; 129 Double minTime = min( timeCol.getColumn() ) ; 190 //Table t0( iter0.table() ) ; 191 Table t0 = iter0.table() ; 192 ROTableColumn sharedCol( t0, "FIELDNAME" ) ; 193 String fieldName = sharedCol.asString( 0 ) ; 194 // tcol = tpoolr->construct( t0, "FIELDNAME" ) ; 195 // String fieldName = tcol->asString( 0 ) ; 196 // tpoolr->destroy( tcol ) ; 197 sharedCol.attach( t0, "SRCNAME" ) ; 198 String srcName = sharedCol.asString( 0 ) ; 199 // tcol = tpoolr->construct( t0, "SRCNAME" ) ; 200 // String srcName = tcol->asString( 0 ) ; 201 // tpoolr->destroy( tcol ) ; 202 sharedCol.attach( t0, "TIME" ) ; 203 Double minTime = (Double)sharedCol.asdouble( 0 ) * 86400.0 ; // day->sec 204 // tcol = tpoolr->construct( t0, "TIME" ) ; 205 // Double minTime = (Double)(tcol->asdouble( 0 )) * 86400.0 ; // day -> sec 206 // tpoolr->destroy( tcol ) ; 130 207 ROArrayColumn<Double> scanRateCol( t0, "SCANRATE" ) ; 131 Vector<Double> scanRate = scanRateCol.getColumn()[0] ; 208 //Vector<Double> scanRate = scanRateCol.getColumn()[0] ; 209 Vector<Double> scanRate = scanRateCol( 0 ) ; 132 210 String::size_type pos = fieldName.find( "__" ) ; 133 211 Int fieldId = -1 ; … … 143 221 } 144 222 os_ << "fieldId" << fieldId << ": " << fieldName << LogIO::POST ; 223 224 // FIELD_ID 225 intRF.attachToRecord( trec, "FIELD_ID" ) ; 226 *intRF = fieldId ; 227 145 228 // 146 229 // ITERATION: BEAMNO 147 230 // 148 Int added1 = 0 ;149 Int current1 = mstable_->nrow() ;150 231 TableIterator iter1( t0, "BEAMNO" ) ; 151 232 while( !iter1.pastEnd() ) { 152 Table t1( iter1.table() ) ; 153 ROScalarColumn<uInt> beamNoCol( t1, "BEAMNO" ) ; 154 uInt beamNo = beamNoCol( 0 ) ; 233 Table t1 = iter1.table() ; 234 // tcol = tpoolr->construct( t1, "BEAMNO" ) ; 235 // uInt beamNo = tcol->asuInt( 0 ) ; 236 // tpoolr->destroy( tcol ) ; 237 sharedCol.attach( t1, "BEAMNO" ) ; 238 uInt beamNo = sharedCol.asuInt( 0 ) ; 155 239 os_ << "beamNo = " << beamNo << LogIO::POST ; 240 241 // FEED1 and FEED2 242 intRF.attachToRecord( trec, "FEED1" ) ; 243 *intRF = beamNo ; 244 intRF.attachToRecord( trec, "FEED2" ) ; 245 *intRF = beamNo ; 246 156 247 // 157 248 // ITERATION: SCANNO 158 249 // 159 Int added2 = 0 ;160 Int current2 = mstable_->nrow() ;161 250 TableIterator iter2( t1, "SCANNO" ) ; 162 251 while( !iter2.pastEnd() ) { 163 Table t2( iter2.table() ) ; 164 ROScalarColumn<uInt> scanNoCol( t2, "SCANNO" ) ; 165 uInt scanNo = scanNoCol( 0 ) ; 252 Table t2 = iter2.table() ; 253 // tcol = tpoolr->construct( t2, "SCANNO" ) ; 254 // uInt scanNo = tcol->asuInt( 0 ) ; 255 // tpoolr->destroy( tcol ) ; 256 sharedCol.attach( t2, "SCANNO" ) ; 257 uInt scanNo = sharedCol.asuInt( 0 ) ; 166 258 os_ << "scanNo = " << scanNo << LogIO::POST ; 259 260 // SCAN_NUMBER 261 // MS: 1-based 262 // Scantable: 0-based 263 intRF.attachToRecord( trec, "SCAN_NUMBER" ) ; 264 *intRF = scanNo + 1 ; 265 167 266 // 168 267 // ITERATION: IFNO 169 268 // 170 Int added3 = 0 ;171 Int current3 = mstable_->nrow() ;172 269 TableIterator iter3( t2, "IFNO" ) ; 173 270 while( !iter3.pastEnd() ) { 174 Table t3( iter3.table() ) ; 175 ROScalarColumn<uInt> ifNoCol( t3, "IFNO" ) ; 176 uInt ifNo = ifNoCol( 0 ) ; 271 Table t3 = iter3.table() ; 272 // tcol = tpoolr->construct( t3, "IFNO" ) ; 273 // uInt ifNo = tcol->asuInt( 0 ) ; 274 // tpoolr->destroy( tcol ) ; 275 sharedCol.attach( t3, "IFNO" ) ; 276 uInt ifNo = sharedCol.asuInt( 0 ) ; 177 277 os_ << "ifNo = " << ifNo << LogIO::POST ; 178 ROScalarColumn<uInt> freqIdCol( t3, "FREQ_ID" ) ; 179 uInt freqId = freqIdCol( 0 ) ; 278 // tcol = tpoolr->construct( t3, "FREQ_ID" ) ; 279 // uInt freqId = tcol->asuInt( 0 ) ; 280 // tpoolr->destroy( tcol ) ; 281 sharedCol.attach( t3, "FREQ_ID" ) ; 282 uInt freqId = sharedCol.asuInt( 0 ) ; 180 283 os_ << "freqId = " << freqId << LogIO::POST ; 181 Int subscan = 0 ;284 Int subscan = 1 ; // 1-base 182 285 // 183 // ITERATION: CYCLENO286 // ITERATION: SRCTYPE 184 287 // 185 Int added4 = 0 ; 186 Int current4 = mstable_->nrow() ; 187 TableIterator iter4( t3, "CYCLENO" ) ; 288 TableIterator iter4( t3, "SRCTYPE" ) ; 188 289 while( !iter4.pastEnd() ) { 189 Table t4( iter4.table() ) ; 290 Table t4 = iter4.table() ; 291 // tcol = tpoolr->construct( t4, "SRCTYPE" ) ; 292 // uInt srcType = tcol->asInt( 0 ) ; 293 // tpoolr->destroy( tcol ) ; 294 sharedCol.attach( t4, "SRCTYPE" ) ; 295 Int srcType = sharedCol.asInt( 0 ) ; 296 Int stateId = addState( srcType, subscan ) ; 297 *stateidRF = stateId ; 190 298 // 191 // ITERATION: TIME299 // ITERATION: CYCLENO and TIME 192 300 // 193 Int added5 = 0 ; 194 Int current5 = mstable_->nrow() ; 195 TableIterator iter5( t4, "TIME" ) ; 301 Block<String> cols( 2 ) ; 302 cols[0] = "CYCLENO" ; 303 cols[1] = "TIME" ; 304 TableIterator iter5( t4, cols ) ; 196 305 while( !iter5.pastEnd() ) { 197 Table t5( iter5.table().sort("POLNO") ) ; 198 Int prevnr = mstable_->nrow() ; 306 Table t5 = iter5.table() ; 307 //sharedCol.attach( t5, "CYCLENO" ) ; 308 //uInt cycleNo = sharedCol.asuInt( 0 ) ; 199 309 Int nrow = t5.nrow() ; 200 310 os_ << "nrow = " << nrow << LogIO::POST ; 201 202 // add row203 mstable_->addRow( 1, True ) ;204 311 205 312 Vector<Int> polnos( nrow ) ; … … 207 314 Int polid = addPolarization( polnos ) ; 208 315 os_ << "polid = " << polid << LogIO::POST ; 209 // 210 // LOOP: POLNO 211 // 316 317 // DATA/FLOAT_DATA 212 318 ROArrayColumn<Float> specCol( t5, "SPECTRA" ) ; 213 319 ROArrayColumn<uChar> flagCol( t5, "FLAGTRA" ) ; 214 ROScalarColumn<uInt> flagRowCol( t5, "FLAGROW" ) ;215 320 uInt nchan = specCol( 0 ).size() ; 216 IPosition newshape( 2,1,nchan ) ;217 321 IPosition cellshape( 2, nrow, nchan ) ; 218 322 if ( useFloatData_ ) { 219 323 // FLOAT_DATA 220 Array<Float> dataArr( cellshape ) ; 221 Array<Bool> flagArr( cellshape ) ; 324 Matrix<Float> dataArr( cellshape ) ; 325 Matrix<Bool> flagArr( cellshape ) ; 326 Vector<uChar> tmpUC ; 327 Vector<Bool> tmpB ; 222 328 for ( Int ipol = 0 ; ipol < nrow ; ipol++ ) { 223 Slicer slicer( Slice(ipol), Slice(0,nchan,1) ) ; 224 dataArr( slicer ) = specCol( ipol ).reform( newshape ) ; 225 Array<uChar> tmpUC = flagCol( ipol ).reform( newshape ) ; 226 Array<Bool> tmpB( tmpUC.shape() ) ; 227 //convertArray( flagArr( slicer ), flagCol( ipol ).reform( newshape ) ) ; 329 dataArr.row( ipol ) = specCol( ipol ) ; 330 tmpUC = flagCol( ipol ) ; 331 tmpB = flagArr.row( ipol ) ; 228 332 convertArray( tmpB, tmpUC ) ; 229 flagArr( slicer ) = tmpB ;230 333 } 231 ArrayColumn<Float> msDataCol( *mstable_, "FLOAT_DATA" ) ; 232 msDataCol.put( prevnr, dataArr ) ; 334 *(*((RecordFieldPtr< Array<Float> > *)dataRF)) = dataArr ; 233 335 234 336 // FLAG 235 ArrayColumn<Bool> msFlagCol( *mstable_, "FLAG" ) ; 236 msFlagCol.put( prevnr, flagArr ) ; 337 *flagRF = flagArr ; 237 338 } 238 339 else if ( useData_ ) { 239 340 // DATA 240 341 // assume nrow = 4 241 Array<Complex> dataArr( cellshape ) ;342 Matrix<Complex> dataArr( cellshape ) ; 242 343 Vector<Float> zeroIm( nchan, 0 ) ; 243 Array<Float> dummy( IPosition( 2, 2, nchan ) ) ; 244 Slicer slicer0( Slice(0), Slice(0,nchan,1) ) ; 245 Slicer slicer1( Slice(1), Slice(0,nchan,1) ) ; 246 Slicer slicer2( Slice(2), Slice(0,nchan,1) ) ; 247 Slicer slicer3( Slice(3), Slice(0,nchan,1) ) ; 248 dummy( slicer0 ) = specCol( 0 ).reform( newshape ) ; 249 dummy( slicer1 ) = zeroIm.reform( newshape ) ; 250 dataArr( slicer0 ) = RealToComplex( dummy ) ; 251 dummy( slicer0 ) = specCol( 1 ).reform( newshape ) ; 252 dataArr( slicer3 ) = RealToComplex( dummy ) ; 253 dummy( slicer0 ) = specCol( 2 ).reform( newshape ) ; 254 dummy( slicer1 ) = specCol( 3 ).reform( newshape ) ; 255 dataArr( slicer1 ) = RealToComplex( dummy ) ; 256 dataArr( slicer2 ) = conj( RealToComplex( dummy ) ) ; 257 ArrayColumn<Complex> msDataCol( *mstable_, "DATA" ) ; 258 msDataCol.put( prevnr, dataArr ) ; 259 344 Matrix<Float> dummy( IPosition( 2, 2, nchan ) ) ; 345 dummy.row( 0 ) = specCol( 0 ) ; 346 dummy.row( 1 ) = zeroIm ; 347 dataArr.row( 0 ) = RealToComplex( dummy ) ; 348 dummy.row( 0 ) = specCol( 1 ) ; 349 dataArr.row( 3 ) = RealToComplex( dummy ) ; 350 dummy.row( 0 ) = specCol( 2 ) ; 351 dummy.row( 1 ) = specCol( 3 ) ; 352 dataArr.row( 1 ) = RealToComplex( dummy ) ; 353 dataArr.row( 2 ) = conj( dataArr.row( 1 ) ) ; 354 *(*((RecordFieldPtr< Array<Complex> > *)dataRF)) = dataArr ; 355 356 260 357 // FLAG 261 Array<Bool> flagArr( cellshape ) ;262 Array<uChar> tmpUC = flagCol( 0 ).reform( newshape) ;263 Array<Bool> tmpB( tmpUC.shape()) ;358 Matrix<Bool> flagArr( cellshape ) ; 359 Matrix<uChar> tmpUC = flagCol( 0 ) ; 360 Matrix<Bool> tmpB = flagArr.row( 0 ) ; 264 361 convertArray( tmpB, tmpUC ) ; 265 flagArr( slicer0 ) = tmpB;266 tmp UC = flagCol( 3 ).reform( newshape) ;362 tmpUC = flagCol( 3 ) ; 363 tmpB = flagArr.row( 3 ) ; 267 364 convertArray( tmpB, tmpUC ) ; 268 flagArr( slicer3 ) = tmpB ; 269 Vector<uChar> bitOr = flagCol( 2 ) | flagCol( 3 ) ; 270 tmpUC = bitOr.reform( newshape ) ; 365 tmpUC = flagCol( 2 ) | flagCol( 3 ) ; 366 tmpB = flagArr.row( 1 ) ; 271 367 convertArray( tmpB, tmpUC ) ; 272 flagArr( slicer1 ) = tmpB ; 273 flagArr( slicer2 ) = tmpB ; 274 ArrayColumn<Bool> msFlagCol( *mstable_, "FLAG" ) ; 275 msFlagCol.put( prevnr, flagArr ) ; 368 tmpB = flagArr.row( 2 ) ; 369 convertArray( tmpB, tmpUC ) ; 370 *flagRF = flagArr ; 276 371 } 277 372 278 373 // FLAG_ROW 279 ScalarColumn<Bool> msFlagRowCol( *mstable_, "FLAG_ROW" ) ; 280 msFlagRowCol.put( prevnr, anyNE( flagRowCol.getColumn(), (uInt)0 ) ) ; 374 // tcol = tpoolr->construct( t5, "FLAGROW" ) ; 375 sharedCol.attach( t5, "FLAGROW" ) ; 376 Vector<uInt> flagRowArr( nrow ) ; 377 for ( Int irow = 0 ; irow < nrow ; irow++ ) 378 flagRowArr[irow] = sharedCol.asuInt( irow ) ; 379 // flagRowArr[irow] = tcol->asuInt( irow ) ; 380 // tpoolr->destroy( tcol ) ; 381 *flagrowRF = anyNE( flagRowArr, (uInt)0 ) ; 281 382 282 383 // TIME and TIME_CENTROID 283 ROScalarMeasColumn<MEpoch> timeCol( t5, "TIME" ) ; 284 MEpoch mTime = timeCol( 0 ) ; 285 ScalarMeasColumn<MEpoch> msTimeCol( *mstable_, "TIME" ) ; 286 msTimeCol.put( prevnr, mTime ) ; 287 msTimeCol.attach( *mstable_, "TIME_CENTROID" ) ; 288 msTimeCol.put( prevnr, mTime ) ; 384 // tcol = tpoolr->construct( t5, "TIME" ) ; 385 // Double mTimeV = (Double)(tcol->asdouble(0)) * 86400.0 ; // day->sec 386 // tpoolr->destroy( tcol ) ; 387 sharedCol.attach( t5, "TIME" ) ; 388 Double mTimeV = (Double)sharedCol.asdouble( 0 ) * 86400.0 ; // day -> sec 389 *timeRF = mTimeV ; 390 *timecRF = mTimeV ; 289 391 290 392 // INTERVAL and EXPOSURE 291 ROScalarColumn<Double> intervalCol( t5, "INTERVAL" ) ; 292 Double interval = intervalCol( 0 ) ; 293 ScalarColumn<Double> msIntervalCol( *mstable_, "INTERVAL" ) ; 294 msIntervalCol.put( prevnr, interval ) ; 295 msIntervalCol.attach( *mstable_, "EXPOSURE" ) ; 296 msIntervalCol.put( prevnr, interval ) ; 297 393 // tcol = tpoolr->construct( t5, "INTERVAL" ) ; 394 // Double interval = (Double)(tcol->asdouble( 0 )) ; 395 // tpoolr->destroy( tcol ) ; 396 sharedCol.attach( t5, "INTERVAL" ) ; 397 Double interval = (Double)sharedCol.asdouble( 0 ) ; 398 *intervalRF = interval ; 399 *exposureRF = interval ; 400 298 401 // WEIGHT and SIGMA 299 402 // always 1 at the moment 300 403 Vector<Float> wArr( nrow, 1.0 ) ; 301 ArrayColumn<Float> wArrCol( *mstable_, "WEIGHT" ) ; 302 wArrCol.put( prevnr, wArr ) ; 303 wArrCol.attach( *mstable_, "SIGMA" ) ; 304 wArrCol.put( prevnr, wArr ) ; 404 *weightRF = wArr ; 405 *sigmaRF = wArr ; 305 406 306 407 // add DATA_DESCRIPTION row 307 408 Int ddid = addDataDescription( polid, ifNo ) ; 308 409 os_ << "ddid = " << ddid << LogIO::POST ; 309 ScalarColumn<Int> ddIdCol( *mstable_, "DATA_DESC_ID" ) ; 310 ddIdCol.put( prevnr, ddid ) ; 410 *ddidRF = ddid ; 311 411 312 412 // for SYSCAL table 313 ROScalarColumn<uInt> tcalIdCol( t5, "TCAL_ID" ) ; 314 Vector<uInt> tcalIdArr = tcalIdCol.getColumn() ; 413 // tcol = tpoolr->construct( t5, "TCAL_ID" ) ; 414 sharedCol.attach( t5, "TCAL_ID" ) ; 415 Vector<uInt> tcalIdArr( nrow ) ; 416 for ( Int irow = 0 ; irow < nrow ; irow++ ) 417 tcalIdArr[irow] = sharedCol.asuInt( irow ) ; 418 // tcalIdArr[irow] = tcol->asuInt( irow ) ; 419 // tpoolr->destroy( tcol ) ; 315 420 os_ << "tcalIdArr = " << tcalIdArr << LogIO::POST ; 316 421 String key = String::toString( tcalIdArr[0] ) ; 317 if ( !tcalIdRec_.isDefined( key ) ) {422 if ( !tcalIdRec_.isDefined( key ) ) //{ 318 423 tcalIdRec_.define( key, tcalIdArr ) ; 424 // tcalRowRec_.define( key, t5.rowNumbers() ) ; 425 // } 426 // else { 427 // Vector<uInt> pastrows = tcalRowRec_.asArrayuInt( key ) ; 428 // tcalRowRec_.define( concatenateArray( pastrows, t5.rowNumbers() ) ) ; 429 // } 430 431 // fill STATE_ID 432 //ROScalarColumn<Int> srcTypeCol( t5, "SRCTYPE" ) ; 433 //Int srcType = srcTypeCol( 0 ) ; 434 //Int stateId = addState( srcType, subscan ) ; 435 //*stateidRF = stateId ; 436 437 // for POINTING table 438 if ( ptTabName_ == "" ) { 439 ROArrayColumn<Double> dirCol( t5, "DIRECTION" ) ; 440 Vector<Double> dir = dirCol( 0 ) ; 441 dirCol.attach( t5, "SCANRATE" ) ; 442 Vector<Double> rate = dirCol( 0 ) ; 443 Matrix<Double> msDir( 2, 1 ) ; 444 msDir.column( 0 ) = dir ; 445 if ( anyNE( rate, 0.0 ) ) { 446 msDir.resize( 2, 2 ) ; 447 msDir.column( 1 ) = rate ; 448 } 449 addPointing( fieldName, mTimeV, interval, msDir ) ; 319 450 } 320 451 321 // fill STATE_ID 322 ROScalarColumn<Int> srcTypeCol( t5, "SRCTYPE" ) ; 323 Int srcType = srcTypeCol( 0 ) ; 324 Int stateId = addState( srcType, subscan ) ; 325 ScalarColumn<Int> msStateIdCol( *mstable_, "STATE_ID" ) ; 326 msStateIdCol.put( prevnr, stateId ) ; 327 328 // for POINTING table 329 Matrix<Double> msDir( 2, 2 ) ; 330 ROArrayColumn<Double> dirCol( t5, "DIRECTION" ) ; 331 msDir.column( 0 ) = dirCol( 0 ) ; 332 dirCol.attach( t5, "SCANRATE" ) ; 333 msDir.column( 1 ) = dirCol( 0 ) ; 334 addPointing( fieldName, mTime, interval, msDir ) ; 335 336 added5 += 1 ; 337 os_ << "added5 = " << added5 << " current5 = " << current5 << LogIO::POST ; 452 // FLAG_CATEGORY is tentatively set 453 RecordFieldPtr< Array<Bool> > flagcatRF( trec, "FLAG_CATEGORY" ) ; 454 *flagcatRF = Cube<Bool>( nrow, nchan, 1, False ) ; 455 456 // add row 457 mstable_->addRow( 1, True ) ; 458 row.put( mstable_->nrow()-1 ) ; 459 338 460 iter5.next() ; 339 461 } 340 462 341 added4 += added5 ;342 os_ << "added4 = " << added4 << " current4 = " << current4 << LogIO::POST ;343 463 iter4.next() ; 344 464 } … … 352 472 } 353 473 354 added3 += added4 ;355 os_ << "added3 = " << added3 << " current3 = " << current3 << LogIO::POST ;356 474 iter3.next() ; 357 475 } 358 476 359 // SCAN_NUMBER360 // MS: 1-based361 // Scantable: 0-based362 RefRows rows3( current3, current3+added3-1 ) ;363 Vector<Int> scanNum( added3, scanNo+1 ) ;364 ScalarColumn<Int> scanNumCol( *mstable_, "SCAN_NUMBER" ) ;365 scanNumCol.putColumnCells( rows3, scanNum ) ;366 367 added2 += added3 ;368 os_ << "added2 = " << added2 << " current2 = " << current2 << LogIO::POST ;369 477 iter2.next() ; 370 478 } 371 372 // FEED1 and FEED2373 RefRows rows2( current2, current2+added2-1 ) ;374 Vector<Int> feedId( added2, beamNo ) ;375 ScalarColumn<Int> feedCol( *mstable_, "FEED1" ) ;376 feedCol.putColumnCells( rows2, feedId ) ;377 feedCol.attach( *mstable_, "FEED2" ) ;378 feedCol.putColumnCells( rows2, feedId ) ;379 479 380 480 // add FEED row 381 481 addFeed( beamNo ) ; 382 482 383 added1 += added2 ;384 os_ << "added1 = " << added1 << " current1 = " << current1 << LogIO::POST ;385 483 iter1.next() ; 386 484 } 387 485 388 // FIELD_ID389 RefRows rows1( current1, current1+added1-1 ) ;390 Vector<Int> fieldIds( added1, fieldId ) ;391 ScalarColumn<Int> fieldIdCol( *mstable_, "FIELD_ID" ) ;392 fieldIdCol.putColumnCells( rows1, fieldIds ) ;393 394 486 // add FIELD row 395 487 addField( fieldId, fieldName, srcName, minTime, scanRate ) ; 396 488 397 added0 += added1 ;398 os_ << "added0 = " << added0 << " current0 = " << current0 << LogIO::POST ;399 489 iter0.next() ; 400 490 } 401 491 402 // OBSERVATION_ID is always 0 403 ScalarColumn<Int> sharedIntCol( *mstable_, "OBSERVATION_ID" ) ; 404 Vector<Int> sharedIntArr( added0, 0 ) ; 405 sharedIntCol.putColumn( sharedIntArr ) ; 406 407 // ANTENNA1 and ANTENNA2 are always 0 408 sharedIntArr = 0 ; 409 sharedIntCol.attach( *mstable_, "ANTENNA1" ) ; 410 sharedIntCol.putColumn( sharedIntArr ) ; 411 sharedIntCol.attach( *mstable_, "ANTENNA2" ) ; 412 sharedIntCol.putColumn( sharedIntArr ) ; 413 414 // ARRAY_ID is tentatively set to 0 415 sharedIntArr = 0 ; 416 sharedIntCol.attach( *mstable_, "ARRAY_ID" ) ; 417 sharedIntCol.putColumn( sharedIntArr ) ; 418 419 // PROCESSOR_ID is tentatively set to 0 420 sharedIntArr = 0 ; 421 sharedIntCol.attach( *mstable_, "PROCESSOR_ID" ) ; 422 sharedIntCol.putColumn( sharedIntArr ) ; 423 492 // delete tpoolr ; 493 delete dataRF ; 424 494 425 495 // SYSCAL 426 496 fillSysCal() ; 427 497 498 // replace POINTING table with original one if exists 499 if ( ptTabName_ != "" ) { 500 delete mstable_ ; 501 mstable_ = 0 ; 502 Table newPtTab( ptTabName_, Table::Old ) ; 503 newPtTab.copy( filename_+"/POINTING", Table::New ) ; 504 } 505 506 double endSec = gettimeofday_sec() ; 507 os_ << "end MSWriter::write() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ; 508 428 509 return True ; 429 510 } … … 432 513 { 433 514 // os_.origin( LogOrigin( "MSWriter", "init()", WHERE ) ) ; 434 os_ << "MSWriter::init()" << LogIO::POST ; 515 double startSec = gettimeofday_sec() ; 516 os_ << "start MSWriter::init() startSec=" << startSec << LogIO::POST ; 435 517 436 518 // access to scantable … … 487 569 } 488 570 } 571 572 // check if reference for POINTING table exists 573 const TableRecord &rec = table_->table().keywordSet() ; 574 if ( rec.isDefined( "POINTING" ) ) { 575 ptTabName_ = rec.asString( "POINTING" ) ; 576 if ( !Table::isReadable( ptTabName_ ) ) { 577 ptTabName_ = "" ; 578 } 579 } 580 581 double endSec = gettimeofday_sec() ; 582 os_ << "end MSWriter::init() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ; 489 583 } 490 584 … … 492 586 { 493 587 // os_.origin( LogOrigin( "MSWriter", "setupMS()", WHERE ) ) ; 494 os_ << "MSWriter::setupMS()" << LogIO::POST ; 588 double startSec = gettimeofday_sec() ; 589 os_ << "start MSWriter::setupMS() startSec=" << startSec << LogIO::POST ; 495 590 496 591 TableDesc msDesc = MeasurementSet::requiredTableDesc() ; … … 590 685 mstable_->initRefs() ; 591 686 687 double endSec = gettimeofday_sec() ; 688 os_ << "end MSWriter::setupMS() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ; 592 689 } 593 690 594 691 void MSWriter::fillObservation() 595 692 { 596 os_ << "set up OBSERVATION subtable" << LogIO::POST ; 693 double startSec = gettimeofday_sec() ; 694 os_ << "start MSWriter::fillObservation() startSec=" << startSec << LogIO::POST ; 695 597 696 // only 1 row 598 697 mstable_->observation().addRow( 1, True ) ; … … 620 719 trange[1] = timeCol( table_->nrow()-1 ) ; 621 720 msObsCols.timeRangeMeas().put( 0, trange ) ; 721 722 double endSec = gettimeofday_sec() ; 723 os_ << "end MSWriter::fillObservation() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ; 622 724 } 623 725 624 726 void MSWriter::fillAntenna() 625 727 { 626 os_ << "set up ANTENNA subtable" << LogIO::POST ; 728 double startSec = gettimeofday_sec() ; 729 os_ << "start MSWriter::fillAntenna() startSec=" << startSec << LogIO::POST ; 730 627 731 // only 1 row 628 732 mstable_->antenna().addRow( 1, True ) ; … … 654 758 655 759 msAntCols.position().put( 0, header_.antennaposition ) ; 760 761 double endSec = gettimeofday_sec() ; 762 os_ << "end MSWriter::fillAntenna() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ; 656 763 } 657 764 658 765 void MSWriter::fillProcessor() 659 766 { 660 os_ << "set up PROCESSOR subtable" << LogIO::POST ; 767 double startSec = gettimeofday_sec() ; 768 os_ << "start MSWriter::fillProcessor() startSec=" << startSec << LogIO::POST ; 661 769 662 770 // only add empty 1 row 663 771 MSProcessor msProc = mstable_->processor() ; 664 772 msProc.addRow( 1, True ) ; 773 774 double endSec = gettimeofday_sec() ; 775 os_ << "end MSWriter::fillProcessor() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ; 665 776 } 666 777 667 778 void MSWriter::fillSource() 668 779 { 669 os_ << "set up SOURCE subtable" << LogIO::POST;670 671 780 double startSec = gettimeofday_sec() ; 781 os_ << "start MSWriter::fillSource() startSec=" << startSec << LogIO::POST ; 782 672 783 // access to MS SOURCE subtable 673 784 MSSource msSrc = mstable_->source() ; … … 680 791 Vector<String> molName ; 681 792 Vector<String> fMolName ; 793 794 // row based 795 TableRow row( msSrc ) ; 796 TableRecord &rec = row.record() ; 797 RecordFieldPtr<Int> srcidRF( rec, "SOURCE_ID" ) ; 798 RecordFieldPtr<String> nameRF( rec, "NAME" ) ; 799 RecordFieldPtr< Array<Double> > srcpmRF( rec, "PROPER_MOTION" ) ; 800 RecordFieldPtr< Array<Double> > srcdirRF( rec, "DIRECTION" ) ; 801 RecordFieldPtr<Int> numlineRF( rec, "NUM_LINES" ) ; 802 RecordFieldPtr< Array<Double> > restfreqRF( rec, "REST_FREQUENCY" ) ; 803 RecordFieldPtr< Array<Double> > sysvelRF( rec, "SYSVEL" ) ; 804 RecordFieldPtr< Array<String> > transitionRF( rec, "TRANSITION" ) ; 805 RecordFieldPtr<Double> timeRF( rec, "TIME" ) ; 806 RecordFieldPtr<Double> intervalRF( rec, "INTERVAL" ) ; 807 RecordFieldPtr<Int> spwidRF( rec, "SPECTRAL_WINDOW_ID" ) ; 808 682 809 // 683 810 // ITERATION: SRCNAME 684 811 // 685 Int added0 = 0 ;686 Int current0 = msSrc.nrow() ;687 812 TableIterator iter0( table_->table(), "SRCNAME" ) ; 688 813 while( !iter0.pastEnd() ) { 689 Table t0( iter0.table() ) ; 814 //Table t0( iter0.table() ) ; 815 Table t0 = iter0.table() ; 690 816 691 817 // get necessary information … … 699 825 Double srcVel = srcVelCol( 0 ) ; 700 826 827 // NAME 828 *nameRF = srcName ; 829 830 // SOURCE_ID 831 *srcidRF = srcId ; 832 833 // PROPER_MOTION 834 *srcpmRF = srcPM ; 835 836 // DIRECTION 837 *srcdirRF = srcDir ; 838 701 839 // 702 840 // ITERATION: MOLECULE_ID 703 841 // 704 Int added1 = 0 ;705 Int current1 = msSrc.nrow() ;706 842 TableIterator iter1( t0, "MOLECULE_ID" ) ; 707 843 while( !iter1.pastEnd() ) { 708 Table t1( iter1.table() ) ; 844 //Table t1( iter1.table() ) ; 845 Table t1 = iter1.table() ; 709 846 710 847 // get necessary information … … 713 850 stm.getEntry( restFreq, molName, fMolName, molId ) ; 714 851 852 uInt numFreq = restFreq.size() ; 853 854 // NUM_LINES 855 *numlineRF = numFreq ; 856 857 // REST_FREQUENCY 858 *restfreqRF = restFreq ; 859 860 // TRANSITION 861 *transitionRF = fMolName ; 862 863 // SYSVEL 864 Vector<Double> sysvelArr( numFreq, srcVel ) ; 865 *sysvelRF = sysvelArr ; 866 715 867 // 716 868 // ITERATION: IFNO 717 869 // 718 Int added2 = 0 ;719 Int current2 = msSrc.nrow() ;720 870 TableIterator iter2( t1, "IFNO" ) ; 721 871 while( !iter2.pastEnd() ) { 722 Table t2( iter2.table() ) ; 723 uInt prevnr = msSrc.nrow() ; 872 //Table t2( iter2.table() ) ; 873 Table t2 = iter2.table() ; 874 uInt nrow = msSrc.nrow() ; 724 875 725 876 // get necessary information 726 877 ROScalarColumn<uInt> ifNoCol( t2, "IFNO" ) ; 727 878 uInt ifno = ifNoCol( 0 ) ; // IFNO = SPECTRAL_WINDOW_ID 728 MEpoch midTimeMeas;879 Double midTime ; 729 880 Double interval ; 730 getValidTimeRange( midTimeMeas, interval, t2 ) ; 881 getValidTimeRange( midTime, interval, t2 ) ; 882 883 // fill SPECTRAL_WINDOW_ID 884 *spwidRF = ifno ; 885 886 // fill TIME, INTERVAL 887 *timeRF = midTime ; 888 *intervalRF = interval ; 731 889 732 890 // add row 733 891 msSrc.addRow( 1, True ) ; 734 735 // fill SPECTRAL_WINDOW_ID 736 ScalarColumn<Int> sSpwIdCol( msSrc, "SPECTRAL_WINDOW_ID" ) ; 737 sSpwIdCol.put( prevnr, ifno ) ; 738 739 // fill TIME, INTERVAL 740 ScalarMeasColumn<MEpoch> sTimeMeasCol( msSrc, "TIME" ) ; 741 sTimeMeasCol.put( prevnr, midTimeMeas ) ; 742 ScalarColumn<Double> sIntervalCol( msSrc, "INTERVAL" ) ; 743 sIntervalCol.put( prevnr, interval ) ; 744 745 added2++ ; 892 row.put( nrow ) ; 893 746 894 iter2.next() ; 747 895 } 748 896 749 // fill NUM_LINES, REST_FREQUENCY, TRANSITION, SYSVEL750 RefRows rows2( current2, current2+added2-1 ) ;751 uInt numFreq = restFreq.size() ;752 Vector<Int> numLines( added2, numFreq ) ;753 ScalarColumn<Int> numLinesCol( msSrc, "NUM_LINES" ) ;754 numLinesCol.putColumnCells( rows2, numLines ) ;755 if ( numFreq != 0 ) {756 Array<Double> rf( IPosition( 2, numFreq, added2 ) ) ;757 Array<String> trans( IPosition( 2, numFreq, added2 ) ) ;758 Array<Double> srcVelArr( IPosition( 2, numFreq, added2 ), srcVel ) ;759 for ( uInt ifreq = 0 ; ifreq < numFreq ; ifreq++ ) {760 Slicer slice( Slice(ifreq),Slice(0,added2,1) ) ;761 rf( slice ) = restFreq[ifreq] ;762 String transStr = fMolName[ifreq] ;763 if ( transStr.size() == 0 ) {764 transStr = molName[ifreq] ;765 }766 trans( slice ) = transStr ;767 }768 ArrayColumn<Double> sharedDArrCol( msSrc, "REST_FREQUENCY" ) ;769 sharedDArrCol.putColumnCells( rows2, rf ) ;770 sharedDArrCol.attach( msSrc, "SYSVEL" ) ;771 sharedDArrCol.putColumnCells( rows2, srcVelArr ) ;772 ArrayColumn<String> transCol( msSrc, "TRANSITION" ) ;773 transCol.putColumnCells( rows2, trans ) ;774 }775 776 added1 += added2 ;777 897 iter1.next() ; 778 898 } 779 780 // fill NAME, SOURCE_ID781 RefRows rows1( current1, current1+added1-1 ) ;782 Vector<String> nameArr( added1, srcName ) ;783 Vector<Int> srcIdArr( added1, srcId ) ;784 ScalarColumn<String> sNameCol( msSrc, "NAME" ) ;785 ScalarColumn<Int> srcIdCol( msSrc, "SOURCE_ID" ) ;786 sNameCol.putColumnCells( rows1, nameArr ) ;787 srcIdCol.putColumnCells( rows1, srcIdArr ) ;788 789 // fill DIRECTION, PROPER_MOTION790 Array<Double> srcPMArr( IPosition( 2, 2, added1 ) ) ;791 Array<Double> srcDirArr( IPosition( 2, 2, added1 ) ) ;792 for ( uInt i = 0 ; i < 2 ; i++ ) {793 Slicer slice( Slice(i),Slice(0,added1,1) ) ;794 srcPMArr( slice ) = srcPM[i] ;795 srcDirArr( slice ) = srcDir[i] ;796 }797 ArrayColumn<Double> sharedDArrCol( msSrc, "DIRECTION" ) ;798 sharedDArrCol.putColumnCells( rows1, srcDirArr ) ;799 sharedDArrCol.attach( msSrc, "PROPER_MOTION" ) ;800 sharedDArrCol.putColumnCells( rows1, srcPMArr ) ;801 802 // fill TIME, INTERVAL803 899 804 900 // increment srcId if SRCNAME changed 805 901 srcId++ ; 806 902 807 added0 += added1 ;808 903 iter0.next() ; 809 904 } 905 906 double endSec = gettimeofday_sec() ; 907 os_ << "end MSWriter::fillSource() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ; 810 908 } 811 909 812 910 void MSWriter::fillWeather() 813 911 { 814 os_ << "set up WEATHER subtable" << LogIO::POST ; 912 double startSec = gettimeofday_sec() ; 913 os_ << "start MSWriter::fillWeather() startSec=" << startSec << LogIO::POST ; 815 914 816 915 // access to MS WEATHER subtable … … 844 943 845 944 // fill TIME and INTERVAL 846 MEpochme ;945 Double midTime ; 847 946 Double interval ; 848 947 Vector<Double> intervalArr( nrow, 0.0 ) ; 849 948 TableIterator iter( table_->table(), "WEATHER_ID" ) ; 850 949 while( !iter.pastEnd() ) { 851 Table tab( iter.table() ) ; 950 //Table tab( iter.table() ) ; 951 Table tab = iter.table() ; 852 952 853 953 ROScalarColumn<uInt> widCol( tab, "WEATHER_ID" ) ; 854 954 uInt wid = widCol( 0 ) ; 855 955 856 getValidTimeRange( m e, interval, tab ) ;857 mswCols.time Meas().put( wid,me ) ;956 getValidTimeRange( midTime, interval, tab ) ; 957 mswCols.time().put( wid, midTime ) ; 858 958 intervalArr[wid] = interval ; 859 959 … … 861 961 } 862 962 mswCols.interval().putColumn( intervalArr ) ; 963 964 double endSec = gettimeofday_sec() ; 965 os_ << "end MSWriter::fillWeather() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ; 863 966 } 864 967 865 968 void MSWriter::fillSysCal() 866 969 { 867 os_ << "set up SYSCAL subtable" << LogIO::POST ; 868 869 tcalIdRec_.print( cout ) ; 970 double startSec = gettimeofday_sec() ; 971 os_ << "start MSWriter::fillSysCal() startSec=" << startSec << LogIO::POST ; 972 973 //tcalIdRec_.print( cout ) ; 870 974 871 975 // access to MS SYSCAL subtable … … 873 977 874 978 // access to TCAL subtable 875 STTcal stt = table_->tcal() ; 876 uInt nrow = stt.table().nrow() ; 979 Table stt = table_->tcal().table() ; 980 uInt nrow = stt.nrow() ; 981 982 // access to MAIN table 983 // Table tab = table_->table() ; 984 Block<String> cols( 5 ) ; 985 cols[0] = "TIME" ; 986 cols[1] = "TCAL_ID" ; 987 cols[2] = "TSYS" ; 988 cols[3] = "BEAMNO" ; 989 cols[4] = "IFNO" ; 990 Table tab = table_->table().project( cols ) ; 877 991 878 992 if ( nrow == 0 ) … … 881 995 nrow = tcalIdRec_.nfields() ; 882 996 883 MEpoch me ; 997 os_ << "fillSysCal() nrow = " << nrow << LogIO::POST ; 998 999 Double midTime ; 884 1000 Double interval ; 885 1001 String timeStr ; 886 // 887 // ITERATION: BEAMNO 888 // 889 Int added0 = 0 ; 890 Int current0 = mssc.nrow() ; 891 TableIterator iter0( table_->table(), "BEAMNO" ) ; 892 while( !iter0.pastEnd() ) { 893 Table t0( iter0.table() ) ; 894 ROScalarColumn<uInt> beamNoCol( t0, "BEAMNO" ) ; 895 uInt beamNo = beamNoCol( 0 ) ; 896 // 897 // ITERATION: IFNO 898 // 899 Int added1 = 0 ; 900 Int current1 = mssc.nrow() ; 901 TableIterator iter1( t0, "IFNO" ) ; 902 while( !iter1.pastEnd() ) { 903 Table t1( iter1.table() ) ; 904 ROScalarColumn<uInt> ifNoCol( t1, "IFNO" ) ; 905 uInt ifNo = ifNoCol( 0 ) ; 906 uInt prevnr = mssc.nrow() ; 907 908 // 909 // LOOP: TCAL_ID 910 // 911 Int added2 = 0 ; 912 Int current2 = mssc.nrow() ; 913 for ( uInt irow = 0 ; irow < nrow ; irow++ ) { 914 Vector<uInt> ids = tcalIdRec_.asArrayuInt( irow ) ; 915 uInt npol = ids.size() ; 916 Table tsel = t1( t1.col("TCAL_ID").in(ids) ) ; 917 os_ << "nrow = " << tsel.nrow() << "@TCAL_ID " << tcalIdRec_.asArrayuInt(irow) << " beamno " << beamNo << "ifno " << ifNo << LogIO::POST ; 918 if ( tsel.nrow() != 0 ) { 919 uInt idx = current2 + added2 ; 920 921 // TIME and INTERVAL 922 mssc.addRow( 1, True ) ; 923 getValidTimeRange( me, interval, t1 ) ; 924 os_ << "me = " << me.get("s").getValue() << " interval = " << interval << LogIO::POST ; 925 ScalarMeasColumn<MEpoch> timeMeasCol( mssc, "TIME" ) ; 926 timeMeasCol.put( idx, me ) ; 927 ScalarColumn<Double> intervalCol( mssc, "INTERVAL" ) ; 928 intervalCol.put( idx, interval ) ; 929 930 // TCAL and TSYS 931 Array<Float> tcal ; 932 Array<Float> tsys ; 933 Vector<Float> dummyC ; 934 stt.getEntry( timeStr, dummyC, ids[0] ) ; 935 os_ << "dummyC[0] = " << dummyC[0] << LogIO::POST ; 936 uInt nchanC = dummyC.size() ; 937 os_ << "nchanC = " << nchanC << LogIO::POST ; 938 tcal.resize( IPosition(2,npol,nchanC) ) ; 939 IPosition shapeC( 2, 1, nchanC ) ; 940 tcal( Slicer(Slice(0),Slice(0,nchanC,1)) ) = dummyC.reform( shapeC ) ; 941 Table tsel1 = tsel( tsel.col("TCAL_ID") == ids[0] ) ; 942 ROArrayColumn<Float> tsysCol( tsel1, "TSYS" ) ; 943 Vector<Float> dummyS = tsysCol( 0 ) ; 944 os_ << "dummyS[0] = " << dummyS[0] << LogIO::POST ; 945 uInt nchanS = dummyS.size() ; 946 os_ << "nchanS = " << nchanS << LogIO::POST ; 947 IPosition shapeS( 2, 1, nchanS ) ; 948 tsys.resize( IPosition(2,npol,nchanS) ) ; 949 tsys( Slicer(Slice(0),Slice(0,nchanS,1)) ) = dummyS.reform( shapeS ) ; 950 os_ << "tsys = " << tsys << LogIO::POST ; 951 for ( uInt iid = 1 ; iid < npol ; iid++ ) { 952 // get TCAL and TSYS 953 stt.getEntry( timeStr, dummyC, ids[iid] ) ; 954 tcal( Slicer(Slice(iid),Slice(0,nchanC,1)) ) = dummyC.reform( shapeC ) ; 955 tsel1 = tsel( tsel.col("TCAL_ID") == ids[iid] ) ; 956 tsysCol.attach( tsel1, "TSYS" ) ; 957 tsys( Slicer(Slice(iid),Slice(0,nchanS,1)) ) = tsysCol( 0 ).reform( shapeS ) ; 958 } 959 os_ << "tsys = " << tsys << LogIO::POST ; 960 ArrayColumn<Float> sharedFloatArrCol ; 961 if ( tcalSpec_ ) { 962 // put TCAL_SPECTRUM 963 sharedFloatArrCol.attach( mssc, "TCAL_SPECTRUM" ) ; 964 sharedFloatArrCol.put( idx, tcal ) ; 965 // set TCAL (mean of TCAL_SPECTRUM) 966 Vector<Float> tcalMean( npol ) ; 967 for ( uInt iid = 0 ; iid < npol ; iid++ ) { 968 tcalMean[iid] = mean( tcal(Slicer(Slice(iid),Slice(0,nchanC,1))) ) ; 969 } 970 tcal.assign( tcalMean.reform(IPosition(2,npol,1)) ) ; 971 } 972 os_ << "tcal = " << tcal << LogIO::POST ; 973 // put TCAL 974 sharedFloatArrCol.attach( mssc, "TCAL" ) ; 975 sharedFloatArrCol.put( idx, tcal ) ; 976 977 if ( tsysSpec_ ) { 978 // put TSYS_SPECTRUM 979 sharedFloatArrCol.attach( mssc, "TSYS_SPECTRUM" ) ; 980 sharedFloatArrCol.put( idx, tsys ) ; 981 // set TSYS (mean of TSYS_SPECTRUM) 982 Vector<Float> tsysMean( npol ) ; 983 for ( uInt iid = 0 ; iid < npol ; iid++ ) { 984 tsysMean[iid] = mean( tsys(Slicer(Slice(iid),Slice(0,nchanS,1))) ) ; 985 } 986 tsys.assign( tsysMean.reform(IPosition(2,npol,1)) ) ; 987 } 988 os_ << "tsys = " << tsys << LogIO::POST ; 989 // put TSYS 990 sharedFloatArrCol.attach( mssc, "TSYS" ) ; 991 sharedFloatArrCol.put( idx, tsys ) ; 992 993 added2++ ; 994 } 1002 1003 // row base 1004 TableRow row( mssc ) ; 1005 TableRecord &trec = row.record() ; 1006 RecordFieldPtr<Int> antennaRF( trec, "ANTENNA_ID" ) ; 1007 RecordFieldPtr<Int> feedRF( trec, "FEED_ID" ) ; 1008 RecordFieldPtr<Int> spwRF( trec, "SPECTRAL_WINDOW_ID" ) ; 1009 RecordFieldPtr<Double> timeRF( trec, "TIME" ) ; 1010 RecordFieldPtr<Double> intervalRF( trec, "INTERVAL" ) ; 1011 RecordFieldPtr< Array<Float> > tsysRF( trec, "TSYS" ) ; 1012 RecordFieldPtr< Array<Float> > tcalRF( trec, "TCAL" ) ; 1013 RecordFieldPtr< Array<Float> > tsysspRF ; 1014 RecordFieldPtr< Array<Float> > tcalspRF ; 1015 if ( tsysSpec_ ) 1016 tsysspRF.attachToRecord( trec, "TSYS_SPECTRUM" ) ; 1017 if ( tcalSpec_ ) 1018 tcalspRF.attachToRecord( trec, "TCAL_SPECTRUM" ) ; 1019 1020 // ANTENNA_ID is always 0 1021 *antennaRF = 0 ; 1022 1023 Table sortedstt = stt.sort( "ID" ) ; 1024 ROArrayColumn<Float> tcalCol( sortedstt, "TCAL" ) ; 1025 ROTableColumn idCol( sortedstt, "ID" ) ; 1026 ROArrayColumn<Float> tsysCol ; 1027 //Block<Bool> rowmask( tab.nrow(), True ) ; 1028 //Table tab2 = tab( rowmask ) ; 1029 for ( uInt irow = 0 ; irow < nrow ; irow++ ) { 1030 double t1 = gettimeofday_sec() ; 1031 Vector<uInt> ids = tcalIdRec_.asArrayuInt( irow ) ; 1032 os_ << "ids = " << ids << LogIO::POST ; 1033 uInt npol = ids.size() ; 1034 Table tsel = tab( tab.col("TCAL_ID").in(ids) ) ; 1035 //Table tsel = tab( tab.col("TCAL_ID").in(ids) ).sort( "TCAL_ID" ) ; 1036 //Table tsel = tab2( tab2.col("TCAL_ID").in(ids) ).sort( "TCAL_ID" ) ; 1037 uInt nrowsel = tsel.nrow() ; 1038 //Vector<uInt> selectedcols = tsel.rowNumbers() ; 1039 Vector<uInt> selectedcols = tsel.rowNumbers( tab, True ) ; 1040 os_ << "selectedcols = " << selectedcols << LogIO::POST ; 1041 Block<Bool> rowmask( tab.nrow(), True ) ; 1042 for ( uInt icol = 0 ; icol < selectedcols.nelements() ; icol++ ) 1043 rowmask[selectedcols[icol]] = False ; 1044 //tab2 = tab( rowmask ) ; 1045 tab = tab( rowmask ) ; 1046 os_ << "tab.nrow() = " << tab.nrow() << LogIO::POST ; 1047 tsel = tsel.sort( "TCAL_ID" ) ; 1048 1049 // FEED_ID 1050 ROScalarColumn<uInt> uintCol( tsel, "BEAMNO" ) ; 1051 *feedRF = uintCol( 0 ) ; 1052 1053 // SPECTRAL_WINDOW_ID 1054 uintCol.attach( tsel, "IFNO" ) ; 1055 *spwRF = uintCol( 0 ) ; 1056 1057 // TIME and INTERVAL 1058 Table tsel1 = tsel( tsel.col("TCAL_ID") == ids[0] ) ; 1059 os_ << "tsel.nrow = " << tsel.nrow() << " tsel1.nrow = " << tsel1.nrow() << LogIO::POST ; 1060 getValidTimeRange( midTime, interval, tsel1 ) ; 1061 *timeRF = midTime ; 1062 *intervalRF = interval ; 1063 1064 // TCAL and TSYS 1065 Matrix<Float> tcal ; 1066 Table t ; 1067 if ( idCol.asuInt( ids[0] ) == ids[0] ) { 1068 os_ << "sorted at irow=" << irow << " ids[0]=" << ids[0] << LogIO::POST ; 1069 Vector<Float> dummyC = tcalCol( ids[0] ) ; 1070 tcal.resize( npol, dummyC.size() ) ; 1071 tcal.row( 0 ) = dummyC ; 1072 } 1073 else { 1074 os_ << "NOT sorted at irow=" << irow << " ids[0]=" << ids[0] << LogIO::POST ; 1075 t = stt( stt.col("ID") == ids[0] ) ; 1076 Vector<Float> dummyC = tcalCol( 0 ) ; 1077 tcal.resize( npol, dummyC.size() ) ; 1078 tcal.row( 0 ) = dummyC ; 1079 } 1080 tsysCol.attach( tsel, "TSYS" ) ; 1081 Vector<Float> dummyS = tsysCol( 0 ) ; 1082 Matrix<Float> tsys( npol, dummyS.size() ) ; 1083 tsys.row( 0 ) = dummyS ; 1084 // get TSYS and TCAL 1085 if ( npol == 2 ) { 1086 if ( idCol.asuInt( ids[1] ) == ids[1] ) { 1087 os_ << "sorted at irow=" << irow << " ids[1]=" << ids[1] << LogIO::POST ; 1088 tcal.row( 1 ) = tcalCol( ids[1] ) ; 995 1089 } 996 997 // SPECTRAL_WINDOW_ID 998 RefRows rows2( current2, current2+added2-1 ) ; 999 ScalarColumn<Int> spwIdCol( mssc, "SPECTRAL_WINDOW_ID" ) ; 1000 Vector<Int> ifNoArr( added2, ifNo ) ; 1001 spwIdCol.putColumnCells( rows2, ifNoArr ) ; 1002 1003 added1 += added2 ; 1004 iter1.next() ; 1090 else { 1091 os_ << "NOT sorted at irow=" << irow << " ids[1]=" << ids[1] << LogIO::POST ; 1092 t = stt( stt.col("ID") == ids[1] ) ; 1093 tcalCol.attach( t, "TCAL" ) ; 1094 tcal.row( 1 ) = tcalCol( 1 ) ; 1095 } 1096 tsys.row( 1 ) = tsysCol( nrowsel-1 ) ; 1097 } 1098 else if ( npol == 3 ) { 1099 if ( idCol.asuInt( ids[2] ) == ids[2] ) 1100 tcal.row( 1 ) = tcalCol( ids[2] ) ; 1101 else { 1102 t = stt( stt.col("ID") == ids[2] ) ; 1103 tcalCol.attach( t, "TCAL" ) ; 1104 tcal.row( 1 ) = tcalCol( 0 ) ; 1105 } 1106 if ( idCol.asuInt( ids[1] ) == ids[1] ) 1107 tcal.row( 2 ) = tcalCol( ids[1] ) ; 1108 else { 1109 t = stt( stt.col("ID") == ids[1] ) ; 1110 tcalCol.attach( t, "TCAL" ) ; 1111 tcal.row( 2 ) = tcalCol( 0 ) ; 1112 } 1113 tsys.row( 1 ) = tsysCol( nrowsel/npol ) ; 1114 tsys.row( 2 ) = tsysCol( nrowsel-1 ) ; 1115 } 1116 else if ( npol == 4 ) { 1117 if ( idCol.asuInt( ids[2] ) == ids[2] ) 1118 tcal.row( 1 ) = tcalCol( ids[2] ) ; 1119 else { 1120 t = stt( stt.col("ID") == ids[2] ) ; 1121 tcalCol.attach( t, "TCAL" ) ; 1122 tcal.row( 1 ) = tcalCol( 0 ) ; 1123 } 1124 if ( idCol.asuInt( ids[3] ) == ids[3] ) 1125 tcal.row( 2 ) = tcalCol( ids[3] ) ; 1126 else { 1127 t = stt( stt.col("ID") == ids[3] ) ; 1128 tcalCol.attach( t, "TCAL" ) ; 1129 tcal.row( 2 ) = tcalCol( 0 ) ; 1130 } 1131 if ( idCol.asuInt( ids[1] ) == ids[1] ) 1132 tcal.row( 2 ) = tcalCol( ids[1] ) ; 1133 else { 1134 t = stt( stt.col("ID") == ids[1] ) ; 1135 tcalCol.attach( t, "TCAL" ) ; 1136 tcal.row( 3 ) = tcalCol( 0 ) ; 1137 } 1138 tsys.row( 1 ) = tsysCol( nrowsel/3 ) ; 1139 tsys.row( 2 ) = tsys.row( 1 ) ; 1140 tsys.row( 3 ) = tsysCol( nrowsel-1 ) ; 1141 } 1142 if ( tcalSpec_ ) { 1143 // put TCAL_SPECTRUM 1144 *tcalspRF = tcal ; 1145 // set TCAL (mean of TCAL_SPECTRUM) 1146 Matrix<Float> tcalMean( npol, 1 ) ; 1147 for ( uInt iid = 0 ; iid < npol ; iid++ ) { 1148 tcalMean( iid, 0 ) = mean( tcal.row(iid) ) ; 1149 } 1150 // put TCAL 1151 *tcalRF = tcalMean ; 1152 } 1153 else { 1154 // put TCAL 1155 *tcalRF = tcal ; 1005 1156 } 1006 1157 1007 // FEED_ID 1008 RefRows rows1( current1, current1+added1-1 ) ; 1009 Vector<Int> beamNoArr( added1, beamNo ) ; 1010 ScalarColumn<Int> feedIdCol( mssc, "FEED_ID" ) ; 1011 feedIdCol.putColumnCells( rows1, beamNoArr ) ; 1012 1013 added0 += added1 ; 1014 iter0.next() ; 1015 } 1016 1017 // ANTENNA_ID 1018 Vector<Int> id( added0, 0 ) ; 1019 ScalarColumn<Int> antennaIdCol( mssc, "ANTENNA_ID" ) ; 1020 antennaIdCol.putColumn( id ) ; 1158 if ( tsysSpec_ ) { 1159 // put TSYS_SPECTRUM 1160 *tsysspRF = tsys ; 1161 // set TSYS (mean of TSYS_SPECTRUM) 1162 Matrix<Float> tsysMean( npol, 1 ) ; 1163 for ( uInt iid = 0 ; iid < npol ; iid++ ) { 1164 tsysMean( iid, 0 ) = mean( tsys.row(iid) ) ; 1165 } 1166 // put TSYS 1167 *tsysRF = tsysMean ; 1168 } 1169 else { 1170 // put TSYS 1171 *tsysRF = tsys ; 1172 } 1173 1174 // add row 1175 mssc.addRow( 1, True ) ; 1176 row.put( mssc.nrow()-1 ) ; 1177 1178 double t2 = gettimeofday_sec() ; 1179 os_ << irow << "th loop elapsed time = " << t2-t1 << "sec" << LogIO::POST ; 1180 } 1021 1181 1182 double endSec = gettimeofday_sec() ; 1183 os_ << "end MSWriter::fillSysCal() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ; 1022 1184 } 1023 1185 1024 1186 void MSWriter::addFeed( Int id ) 1025 1187 { 1026 os_ << "set up FEED subtable" << LogIO::POST ; 1188 double startSec = gettimeofday_sec() ; 1189 os_ << "start MSWriter::addFeed() startSec=" << startSec << LogIO::POST ; 1027 1190 1028 1191 // add row … … 1035 1198 msFeedCols.feedId().put( nrow-1, id ) ; 1036 1199 msFeedCols.antennaId().put( nrow-1, 0 ) ; 1200 1201 double endSec = gettimeofday_sec() ; 1202 os_ << "end MSWriter::addFeed() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ; 1037 1203 } 1038 1204 1039 1205 void MSWriter::addSpectralWindow( Int spwid, Int freqid ) 1040 1206 { 1041 os_ << "set up SPECTRAL_WINDOW subtable" << LogIO::POST ; 1207 double startSec = gettimeofday_sec() ; 1208 os_ << "start MSWriter::addSpectralWindow() startSec=" << startSec << LogIO::POST ; 1042 1209 1043 1210 // add row … … 1060 1227 1061 1228 // NUM_CHAN 1062 Int nchan = refpix * 2;1229 Int nchan = (Int)(refpix * 2) ; 1063 1230 msSpwCols.numChan().put( spwid, nchan ) ; 1064 1231 … … 1087 1254 indgen( sharedDoubleArr, refFreq, inc ) ; 1088 1255 msSpwCols.chanFreq().put( spwid, sharedDoubleArr ) ; 1256 1257 double endSec = gettimeofday_sec() ; 1258 os_ << "end MSWriter::addSpectralWindow() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ; 1089 1259 } 1090 1260 1091 1261 void MSWriter::addField( Int fid, String fieldname, String srcname, Double t, Vector<Double> rate ) 1092 1262 { 1093 os_ << "set up FIELD subtable" << LogIO::POST ; 1263 double startSec = gettimeofday_sec() ; 1264 os_ << "start MSWriter::addField() startSec=" << startSec << LogIO::POST ; 1094 1265 1095 1266 MSField msField = mstable_->field() ; … … 1117 1288 ROMSSourceColumns msSrcCols( msSrcSel ) ; 1118 1289 Vector<Double> srcDir = msSrcCols.direction()( 0 ) ; 1119 Array<Double> srcDirA( IPosition( 2, 2, 1+numPoly ) ) ;1290 Matrix<Double> srcDirA( IPosition( 2, 2, 1+numPoly ) ) ; 1120 1291 os_ << "srcDirA = " << srcDirA << LogIO::POST ; 1121 os_ << "sliced srcDirA = " << srcDirA ( Slicer( Slice(0,2,1), Slice(0) )) << LogIO::POST ;1122 srcDirA ( Slicer( Slice(0,2,1), Slice(0) ) ) = srcDir.reform( IPosition(2,2,1) );1292 os_ << "sliced srcDirA = " << srcDirA.column( 0 ) << LogIO::POST ; 1293 srcDirA.column( 0 ) = srcDir ; 1123 1294 os_ << "srcDirA = " << srcDirA << LogIO::POST ; 1124 1295 if ( numPoly != 0 ) 1125 srcDirA ( Slicer( Slice(0,2,1), Slice(1) )) = rate ;1296 srcDirA.column( 1 ) = rate ; 1126 1297 msFieldCols.phaseDir().put( fid, srcDirA ) ; 1127 1298 msFieldCols.referenceDir().put( fid, srcDirA ) ; … … 1129 1300 } 1130 1301 msFieldCols.sourceId().put( fid, srcId ) ; 1131 } 1132 1133 void MSWriter::addPointing( String &name, MEpoch &me, Double &interval, Matrix<Double> &dir ) 1134 { 1135 os_ << "set up POINTING subtable" << LogIO::POST ; 1302 1303 double endSec = gettimeofday_sec() ; 1304 os_ << "end MSWriter::addField() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ; 1305 } 1306 1307 void MSWriter::addPointing( String &name, Double &me, Double &interval, Matrix<Double> &dir ) 1308 { 1309 double startSec = gettimeofday_sec() ; 1310 os_ << "start MSWriter::addPointing() startSec=" << startSec << LogIO::POST ; 1136 1311 1137 1312 // access to POINTING subtable … … 1143 1318 1144 1319 // fill row 1145 MSPointingColumns mspCols( msp ) ; 1146 mspCols.antennaId().put( nrow, 0 ) ; 1147 mspCols.timeMeas().put( nrow, me ) ; 1148 mspCols.interval().put( nrow, interval ) ; 1149 mspCols.name().put( nrow, name ) ; 1150 mspCols.numPoly().put( nrow, 1 ) ; 1151 mspCols.timeOriginMeas().put( nrow, me ) ; 1152 mspCols.direction().put( nrow, dir ) ; 1153 mspCols.target().put( nrow, dir ) ; 1154 mspCols.tracking().put( nrow, True ) ; 1320 TableRow row( msp ) ; 1321 TableRecord &rec = row.record() ; 1322 RecordFieldPtr<Int> antennaRF( rec, "ANTENNA_ID" ) ; 1323 *antennaRF = 0 ; 1324 RecordFieldPtr<Int> numpolyRF( rec, "NUM_POLY" ) ; 1325 *numpolyRF = dir.ncolumn() ; 1326 RecordFieldPtr<Double> timeRF( rec, "TIME" ) ; 1327 *timeRF = me ; 1328 RecordFieldPtr<Double> toriginRF( rec, "TIME_ORIGIN" ) ; 1329 *toriginRF = me ; 1330 RecordFieldPtr<Double> intervalRF( rec, "INTERVAL" ) ; 1331 *intervalRF = interval ; 1332 RecordFieldPtr<String> nameRF( rec, "NAME" ) ; 1333 *nameRF = name ; 1334 RecordFieldPtr<Bool> trackRF( rec, "TRACKING" ) ; 1335 *trackRF = True ; 1336 RecordFieldPtr< Array<Double> > dirRF( rec, "DIRECTION" ) ; 1337 *dirRF = dir ; 1338 RecordFieldPtr< Array<Double> > targetRF( rec, "TARGET" ) ; 1339 *dirRF = dir ; 1340 row.put( nrow ) ; 1341 1342 double endSec = gettimeofday_sec() ; 1343 os_ << "end MSWriter::addPointing() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ; 1155 1344 } 1156 1345 1157 1346 Int MSWriter::addPolarization( Vector<Int> polnos ) 1158 1347 { 1159 os_ << "set up POLARIZATION subtable" << LogIO::POST ; 1348 double startSec = gettimeofday_sec() ; 1349 os_ << "start MSWriter::addPolarization() startSec=" << startSec << LogIO::POST ; 1160 1350 1161 1351 os_ << "polnos = " << polnos << LogIO::POST ; 1162 1352 MSPolarization msPol = mstable_->polarization() ; 1163 1353 uInt nrow = msPol.nrow() ; 1354 1355 // only 1 POLARIZATION row for 1 scantable 1356 if ( nrow > 0 ) 1357 return 1 ; 1164 1358 1165 1359 Vector<Int> corrType = toCorrType( polnos ) ; 1166 os_ << "corrType = " << corrType << LogIO::POST ;1167 1360 1168 MSPolarizationIndex msPolIdx( msPol ) ; 1169 Vector<Int> polids = msPolIdx.matchCorrType( corrType ) ; 1170 os_ << "polids = " << polids << LogIO::POST ; 1171 1361 ROArrayColumn<Int> corrtCol( msPol, "CORR_TYPE" ) ; 1362 Matrix<Int> corrTypeArr = corrtCol.getColumn() ; 1172 1363 Int polid = -1 ; 1173 1174 if ( polids.size() == 0 ) { 1364 for ( uInt irow = 0 ; irow < nrow ; irow++ ) { 1365 if ( allEQ( corrType, corrTypeArr.column( irow ) ) ) { 1366 polid = irow ; 1367 break ; 1368 } 1369 } 1370 1371 if ( polid == -1 ) { 1372 MSPolarizationColumns msPolCols( msPol ) ; 1373 1175 1374 // add row 1176 1375 msPol.addRow( 1, True ) ; 1177 1376 polid = (Int)nrow ; 1178 1377 1179 MSPolarizationColumns msPolCols( msPol ) ;1180 1181 1378 // CORR_TYPE 1182 1379 msPolCols.corrType().put( nrow, corrType ) ; … … 1203 1400 corrProd( 1,2 ) = 0 ; 1204 1401 } 1205 msPolCols.corrProduct().put( nrow, corrProd ) ; 1206 1207 } 1208 else { 1209 polid = polids[0] ; 1210 } 1402 msPolCols.corrProduct().put( nrow, corrProd ) ; 1403 } 1404 1405 double endSec = gettimeofday_sec() ; 1406 os_ << "end MSWriter::addPolarization() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ; 1211 1407 1212 1408 return polid ; … … 1215 1411 Int MSWriter::addDataDescription( Int polid, Int spwid ) 1216 1412 { 1217 os_ << "set up DATA_DESCRIPTION subtable" << LogIO::POST ; 1413 double startSec = gettimeofday_sec() ; 1414 os_ << "start MSWriter::addDataDescription() startSec=" << startSec << LogIO::POST ; 1218 1415 1219 1416 MSDataDescription msDataDesc = mstable_->dataDescription() ; 1220 1417 uInt nrow = msDataDesc.nrow() ; 1221 1418 1222 MSDataDescIndex msDataDescIdx( msDataDesc ) ; 1223 1224 Vector<Int> ddids = msDataDescIdx.matchSpwIdAndPolznId( spwid, polid ) ; 1225 os_ << "ddids = " << ddids << LogIO::POST ; 1226 1419 // only 1 POLARIZATION_ID for 1 scantable 1227 1420 Int ddid = -1 ; 1228 if ( ddids.size() == 0 ) { 1421 ROScalarColumn<Int> spwCol( msDataDesc, "SPECTRAL_WINDOW_ID" ) ; 1422 Vector<Int> spwIds = spwCol.getColumn() ; 1423 //ROScalarColumn<Int> polCol( msDataDesc, "POLARIZATION_ID" ) ; 1424 //Vector<Int> polIds = polCol.getColumn() ; 1425 for ( uInt irow = 0 ; irow < nrow ; irow++ ) { 1426 //if ( spwid == spwIds[irow] && polid == polIds[irow] ) { 1427 if ( spwid == spwIds[irow] ) { 1428 ddid = irow ; 1429 break ; 1430 } 1431 } 1432 os_ << "ddid = " << ddid << LogIO::POST ; 1433 1434 1435 if ( ddid == -1 ) { 1229 1436 msDataDesc.addRow( 1, True ) ; 1230 1437 MSDataDescColumns msDataDescCols( msDataDesc ) ; … … 1233 1440 ddid = (Int)nrow ; 1234 1441 } 1235 else { 1236 ddid = ddids[0];1237 }1442 1443 double endSec = gettimeofday_sec() ; 1444 os_ << "end MSWriter::addDataDescription() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ; 1238 1445 1239 1446 return ddid ; … … 1242 1449 Int MSWriter::addState( Int st, Int &subscan ) 1243 1450 { 1244 os_ << "set up STATE subtable" << LogIO::POST ; 1451 double startSec = gettimeofday_sec() ; 1452 os_ << "start MSWriter::addState() startSec=" << startSec << LogIO::POST ; 1245 1453 1246 1454 // access to STATE subtable … … 1250 1458 String obsMode ; 1251 1459 Bool isSignal ; 1252 queryType( st, obsMode, isSignal ) ; 1460 Double tnoise ; 1461 Double tload ; 1462 queryType( st, obsMode, isSignal, tnoise, tload ) ; 1253 1463 os_ << "obsMode = " << obsMode << " isSignal = " << isSignal << LogIO::POST ; 1254 1464 1255 MSState msStatSel = msState( msState.col("OBS_MODE")==obsMode1256 && msState.col("SIG")==isSignal1257 && msState.col("REF")!=isSignal1258 && msState.col("SUB_SCAN") == subscan ) ;1259 uInt nrowSel = msStatSel.nrow() ;1260 1261 1465 Int idx = -1 ; 1262 if ( nrowSel == 0 ) { 1466 ROScalarColumn<String> obsModeCol( msState, "OBS_MODE" ) ; 1467 //ROScalarColumn<Bool> sigCol( msState, "SIG" ) ; 1468 //ROScalarColumn<Bool> refCol( msState, "REF" ) ; 1469 ROScalarColumn<Int> subscanCol( msState, "SUB_SCAN" ) ; 1470 // Vector<String> obsModeArr = obsModeCol.getColumn() ; 1471 // Vector<Bool> sigArr = sigCol.getColumn() ; 1472 // Vector<Bool> refArr = refCol.getColumn() ; 1473 // Vector<Int> subscanArr = subscanCol.getColumn() ; 1474 for ( uInt irow = 0 ; irow < nrow ; irow++ ) { 1475 if ( obsModeCol(irow) == obsMode 1476 //&& sigCol(irow) == isSignal 1477 //&& refCol(irow) != isSignal 1478 && subscanCol(irow) == subscan ) { 1479 // if ( obsModeArr[irow] == obsMode 1480 // && sigArr[irow] == isSignal 1481 // && refArr[irow] != isSignal 1482 // && subscanArr[irow] == subscan ) { 1483 idx = irow ; 1484 break ; 1485 } 1486 } 1487 if ( idx == -1 ) { 1263 1488 msState.addRow( 1, True ) ; 1264 ScalarColumn<String> obsModeCol( msState, "OBS_MODE" ) ; 1265 obsModeCol.put( nrow, obsMode ) ; 1266 ScalarColumn<Bool> sharedBCol( msState, "SIG" ) ; 1267 sharedBCol.put( nrow, isSignal ) ; 1268 sharedBCol.attach( msState, "REF" ) ; 1269 sharedBCol.put( nrow, !isSignal ) ; 1270 ScalarColumn<Int> subscanCol( msState, "SUB_SCAN" ) ; 1271 subscanCol.put( nrow, subscan ) ; 1489 TableRow row( msState ) ; 1490 TableRecord &rec = row.record() ; 1491 RecordFieldPtr<String> obsmodeRF( rec, "OBS_MODE" ) ; 1492 *obsmodeRF = obsMode ; 1493 RecordFieldPtr<Bool> sigRF( rec, "SIG" ) ; 1494 *sigRF = isSignal ; 1495 RecordFieldPtr<Bool> refRF( rec, "REF" ) ; 1496 *refRF = !isSignal ; 1497 RecordFieldPtr<Int> subscanRF( rec, "SUB_SCAN" ) ; 1498 *subscanRF = subscan ; 1499 RecordFieldPtr<Double> noiseRF( rec, "CAL" ) ; 1500 *noiseRF = tnoise ; 1501 RecordFieldPtr<Double> loadRF( rec, "LOAD" ) ; 1502 *loadRF = tload ; 1503 row.put( nrow ) ; 1504 // ScalarColumn<String> obsModeCol( msState, "OBS_MODE" ) ; 1505 // obsModeCol.put( nrow, obsMode ) ; 1506 // ScalarColumn<Bool> sharedBCol( msState, "SIG" ) ; 1507 // sharedBCol.put( nrow, isSignal ) ; 1508 // sharedBCol.attach( msState, "REF" ) ; 1509 // sharedBCol.put( nrow, !isSignal ) ; 1510 // ScalarColumn<Int> subscanCol( msState, "SUB_SCAN" ) ; 1511 // subscanCol.put( nrow, subscan ) ; 1272 1512 idx = nrow ; 1273 1513 } 1274 else {1275 ScalarColumn<String> obsModeCol( msState, "OBS_MODE" ) ;1276 ScalarColumn<Bool> sigCol( msState, "SIG" ) ;1277 ScalarColumn<Bool> refCol( msState, "REF" ) ;1278 ScalarColumn<Int> subscanCol( msState, "SUB_SCAN" ) ;1279 for ( uInt irow = 0 ; irow < nrow ; irow++ ) {1280 if ( obsModeCol(irow) == obsMode1281 && sigCol(irow) == isSignal1282 && refCol(irow) != isSignal1283 && subscanCol(irow) == subscan ) {1284 idx = irow ;1285 break ;1286 }1287 }1288 }1289 1514 subscan++ ; 1515 1516 double endSec = gettimeofday_sec() ; 1517 os_ << "end MSWriter::addState() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ; 1518 1290 1519 return idx ; 1291 1520 } … … 1293 1522 Vector<Int> MSWriter::toCorrType( Vector<Int> polnos ) 1294 1523 { 1524 double startSec = gettimeofday_sec() ; 1525 os_ << "start MSWriter::toCorrType() startSec=" << startSec << LogIO::POST ; 1526 1295 1527 uInt npol = polnos.size() ; 1296 1528 Vector<Int> corrType( npol, Stokes::Undefined ) ; … … 1377 1609 } 1378 1610 1611 double endSec = gettimeofday_sec() ; 1612 os_ << "end MSWriter::toCorrType() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ; 1613 1379 1614 return corrType ; 1380 1615 } 1381 1616 1382 void MSWriter::getValidTimeRange( MEpoch &me, Double &interval, Table &tab ) 1383 { 1384 ROScalarMeasColumn<MEpoch> timeMeasCol( tab, "TIME" ) ; 1617 void MSWriter::getValidTimeRange( Double &me, Double &interval, Table &tab ) 1618 { 1619 double startSec = gettimeofday_sec() ; 1620 os_ << "start MSWriter::getVaridTimeRange() startSec=" << startSec << LogIO::POST ; 1621 1622 // sort table 1623 //Table stab = tab.sort( "TIME" ) ; 1624 1385 1625 ROScalarColumn<Double> timeCol( tab, "TIME" ) ; 1386 String refStr = timeMeasCol( 0 ).getRefString() ;1387 1626 Vector<Double> timeArr = timeCol.getColumn() ; 1388 MEpoch::Types meType ;1389 MEpoch::getType( meType, refStr ) ;1390 Unit tUnit = timeMeasCol.measDesc().getUnits()( 0 ) ;1391 1627 Double minTime ; 1392 1628 Double maxTime ; 1393 1629 minMax( minTime, maxTime, timeArr ) ; 1394 Double midTime = 0.5 * ( minTime + maxTime ) ; 1395 me = MEpoch( Quantity( midTime, tUnit ), meType ) ; 1396 interval = Quantity( maxTime-minTime, tUnit ).getValue( "s" ) ; 1397 } 1398 1399 void MSWriter::queryType( Int type, String &stype, Bool &b ) 1400 { 1630 Double midTime = 0.5 * ( minTime + maxTime ) * 86400.0 ; 1631 // unit for TIME 1632 // Scantable: "d" 1633 // MS: "s" 1634 me = midTime ; 1635 interval = ( maxTime - minTime ) * 86400.0 ; 1636 1637 double endSec = gettimeofday_sec() ; 1638 os_ << "end MSWriter::getValidTimeRange() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ; 1639 } 1640 1641 //void MSWriter::queryType( Int type, String &stype, Bool &b ) 1642 void MSWriter::queryType( Int type, String &stype, Bool &b, Double &t, Double &l ) 1643 { 1644 double startSec = gettimeofday_sec() ; 1645 os_ << "start MSWriter::queryType() startSec=" << startSec << LogIO::POST ; 1646 1401 1647 switch ( type ) { 1402 1648 case SrcType::PSON: 1403 1649 stype = "POSITION_SWITCH.OBSERVE_TARGET.ON_SOURCE" ; 1404 1650 b = True ; 1651 t = 0.0 ; 1652 l = 0.0 ; 1405 1653 break ; 1406 1654 case SrcType::PSOFF: 1407 1655 stype = "POSITION_SWITCH.OBSERVE_TARGET.OFF_SOURCE" ; 1408 1656 b = False ; 1657 t = 0.0 ; 1658 l = 0.0 ; 1409 1659 break ; 1410 1660 case SrcType::NOD: 1411 1661 stype = "NOD.OBSERVE_TARGET.ON_SOURCE" ; 1412 1662 b = True ; 1663 t = 0.0 ; 1664 l = 0.0 ; 1413 1665 break ; 1414 1666 case SrcType::FSON: 1415 1667 stype = "FREQUENCY_SWITCH.OBSERVE_TARGET.ON_SOURCE" ; 1416 1668 b = True ; 1669 t = 0.0 ; 1670 l = 0.0 ; 1417 1671 break ; 1418 1672 case SrcType::FSOFF: 1419 1673 stype = "FREQUENCY_SWITCH.OBSERVE_TARGET.ON_SOURCE" ; 1420 1674 b = False ; 1675 t = 0.0 ; 1676 l = 0.0 ; 1421 1677 break ; 1422 1678 case SrcType::SKY: 1423 1679 stype = "UNSPECIFIED.CALIBRATE_TEMPERATURE.OFF_SOURCE" ; 1424 1680 b = False ; 1681 t = 0.0 ; 1682 l = 1.0 ; 1425 1683 break ; 1426 1684 case SrcType::HOT: 1427 1685 stype = "UNSPECIFIED.CALIBRATE_TEMPERATURE.OFF_SOURCE" ; 1428 1686 b = False ; 1687 t = 0.0 ; 1688 l = 1.0 ; 1429 1689 break ; 1430 1690 case SrcType::WARM: 1431 1691 stype = "UNSPECIFIED.CALIBRATE_TEMPERATURE.OFF_SOURCE" ; 1692 t = 0.0 ; 1432 1693 b = False ; 1433 break ; 1694 l = 1.0 ; 1695 break ; 1434 1696 case SrcType::COLD: 1435 1697 stype = "UNSPECIFIED.CALIBRATE_TEMPERATURE.OFF_SOURCE" ; 1436 1698 b = False ; 1699 t = 0.0 ; 1700 l = 1.0 ; 1437 1701 break ; 1438 1702 case SrcType::PONCAL: 1439 1703 stype = "POSITION_SWITCH.CALIBRATE_TEMPERATURE.ON_SOURCE" ; 1440 1704 b = True ; 1705 t = 1.0 ; 1706 l = 0.0 ; 1441 1707 break ; 1442 1708 case SrcType::POFFCAL: 1443 1709 stype = "POSITION_SWITCH.CALIBRATE_TEMPERATURE.OFF_SOURCE" ; 1444 1710 b = False ; 1711 t = 1.0 ; 1712 l = 0.0 ; 1445 1713 break ; 1446 1714 case SrcType::NODCAL: 1447 1715 stype = "NOD.CALIBRATE_TEMPERATURE.ON_SOURCE" ; 1448 1716 b = True ; 1717 t = 1.0 ; 1718 l = 0.0 ; 1449 1719 break ; 1450 1720 case SrcType::FONCAL: 1451 1721 stype = "FREQUENCY_SWITCH.CALIBRATE_TEMPERATURE.ON_SOURCE" ; 1452 1722 b = True ; 1723 t = 1.0 ; 1724 l = 0.0 ; 1453 1725 break ; 1454 1726 case SrcType::FOFFCAL: 1455 1727 stype = "FREQUENCY_SWITCH.CALIBRATE_TEMPERATURE.OFF_SOURCE" ; 1456 1728 b = False ; 1729 t = 1.0 ; 1730 l = 0.0 ; 1457 1731 break ; 1458 1732 case SrcType::FSLO: 1459 1733 stype = "FREQUENCY_SWITCH.OBSERVE_TARGET.ON_SOURCE" ; 1460 1734 b = True ; 1735 t = 0.0 ; 1736 l = 0.0 ; 1461 1737 break ; 1462 1738 case SrcType::FLOOFF: 1463 1739 stype = "FREQUENCY_SWITCH.OBSERVE_TARGET.OFF_SOURCE" ; 1464 1740 b = False ; 1741 t = 0.0 ; 1742 l = 0.0 ; 1465 1743 break ; 1466 1744 case SrcType::FLOSKY: 1467 1745 stype = "FREQUENCY_SWITCH.CALIBRATE_TEMPERATURE.OFF_SOURCE" ; 1468 1746 b = False ; 1747 t = 0.0 ; 1748 l = 1.0 ; 1469 1749 break ; 1470 1750 case SrcType::FLOHOT: 1471 1751 stype = "FREQUENCY_SWITCH.CALIBRATE_TEMPERATURE.OFF_SOURCE" ; 1472 1752 b = False ; 1753 t = 0.0 ; 1754 l = 1.0 ; 1473 1755 break ; 1474 1756 case SrcType::FLOWARM: 1475 1757 stype = "FREQUENCY_SWITCH.CALIBRATE_TEMPERATURE.OFF_SOURCE" ; 1476 1758 b = False ; 1759 t = 0.0 ; 1760 l = 1.0 ; 1477 1761 break ; 1478 1762 case SrcType::FLOCOLD: 1479 1763 stype = "FREQUENCY_SWITCH.CALIBRATE_TEMPERATURE.OFF_SOURCE" ; 1480 1764 b = False ; 1765 t = 0.0 ; 1766 l = 1.0 ; 1481 1767 break ; 1482 1768 case SrcType::FSHI: 1483 1769 stype = "FREQUENCY_SWITCH.OBSERVE_TARGET.ON_SOURCE" ; 1484 1770 b = True ; 1771 t = 0.0 ; 1772 l = 0.0 ; 1485 1773 break ; 1486 1774 case SrcType::FHIOFF: 1487 1775 stype = "FREQUENCY_SWITCH.CALIBRATE_TEMPERATURE.OFF_SOURCE" ; 1488 1776 b = False ; 1777 t = 0.0 ; 1778 l = 0.0 ; 1489 1779 break ; 1490 1780 case SrcType::FHISKY: 1491 1781 stype = "FREQUENCY_SWITCH.CALIBRATE_TEMPERATURE.OFF_SOURCE" ; 1492 1782 b = False ; 1783 t = 0.0 ; 1784 l = 1.0 ; 1493 1785 break ; 1494 1786 case SrcType::FHIHOT: 1495 1787 stype = "FREQUENCY_SWITCH.CALIBRATE_TEMPERATURE.OFF_SOURCE" ; 1496 1788 b = False ; 1789 t = 0.0 ; 1790 l = 1.0 ; 1497 1791 break ; 1498 1792 case SrcType::FHIWARM: 1499 1793 stype = "FREQUENCY_SWITCH.CALIBRATE_TEMPERATURE.OFF_SOURCE" ; 1500 1794 b = False ; 1795 t = 0.0 ; 1796 l = 1.0 ; 1501 1797 break ; 1502 1798 case SrcType::FHICOLD: 1503 1799 stype = "FREQUENCY_SWITCH.CALIBRATE_TEMPERATURE.OFF_SOURCE" ; 1504 1800 b = False ; 1801 t = 0.0 ; 1802 l = 1.0 ; 1505 1803 break ; 1506 1804 case SrcType::SIG: 1507 1805 stype = "UNSPECIFIED.OBSERVE_TARGET.ON_SOURCE" ; 1508 1806 b = True ; 1807 t = 0.0 ; 1808 l = 0.0 ; 1509 1809 break ; 1510 1810 case SrcType::REF: 1511 1811 stype = "UNSPECIFIED.OBSERVE_TARGET.ON_SOURCE" ; 1512 1812 b = False ; 1813 t = 0.0 ; 1814 l = 0.0 ; 1513 1815 break ; 1514 1816 default: 1515 1817 stype = "UNSPECIFIED" ; 1516 1818 b = True ; 1517 break ; 1518 } 1519 } 1520 } 1819 t = 0.0 ; 1820 l = 0.0 ; 1821 break ; 1822 } 1823 1824 double endSec = gettimeofday_sec() ; 1825 os_ << "end MSWriter::queryType() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ; 1826 } 1827 } -
trunk/src/MSWriter.h
r1977 r2016 71 71 void addSpectralWindow( casa::Int spwid, casa::Int freqid ) ; 72 72 void addField( casa::Int fid, casa::String fieldname, casa::String srcname, casa::Double t, casa::Vector<casa::Double> scanrate ) ; 73 void addPointing( casa::String &name, casa:: MEpoch&me, casa::Double &interval, casa::Matrix<casa::Double> &dir ) ;73 void addPointing( casa::String &name, casa::Double &me, casa::Double &interval, casa::Matrix<casa::Double> &dir ) ; 74 74 casa::Int addPolarization( casa::Vector<casa::Int> polnos ) ; 75 75 casa::Int addDataDescription( casa::Int polid, casa::Int spwid ) ; … … 78 78 // utility 79 79 casa::Vector<casa::Int> toCorrType( casa::Vector<casa::Int> polnos ) ; 80 void getValidTimeRange( casa::MEpoch &me, casa::Double &interval, casa::Table &tab ) ; 81 void queryType( casa::Int type, casa::String &stype, casa::Bool &b ) ; 80 void getValidTimeRange( casa::Double &me, casa::Double &interval, casa::Table &tab ) ; 81 //void queryType( casa::Int type, casa::String &stype, casa::Bool &b ) ; 82 void queryType( casa::Int type, casa::String &stype, casa::Bool &b, casa::Double &t, Double &l ) ; 83 84 // tool for HPC 85 double gettimeofday_sec() ; 82 86 83 87 casa::CountedPtr<Scantable> table_ ; 84 88 STHeader header_ ; 85 casa::CountedPtr<casa::MeasurementSet> mstable_ ; 89 //casa::CountedPtr<casa::MeasurementSet> mstable_ ; 90 casa::MeasurementSet *mstable_ ; 86 91 87 92 casa::Bool useFloatData_ ; … … 89 94 casa::Bool tcalSpec_ ; 90 95 casa::Bool tsysSpec_ ; 96 97 casa::String ptTabName_ ; 91 98 92 99 casa::String polType_ ; … … 97 104 98 105 casa::Record tcalIdRec_ ; 106 casa::Record tcalRowRec_ ; 99 107 100 108 MSWriter();
Note:
See TracChangeset
for help on using the changeset viewer.