1 | //
|
---|
2 | // C++ Interface: MSWriter
|
---|
3 | //
|
---|
4 | // Description:
|
---|
5 | //
|
---|
6 | // This class is specific writer 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 <casa/OS/File.h>
|
---|
15 | #include <casa/OS/RegularFile.h>
|
---|
16 | #include <casa/OS/Directory.h>
|
---|
17 | #include <casa/OS/SymLink.h>
|
---|
18 | #include <casa/BasicSL/String.h>
|
---|
19 | #include <casa/Containers/RecordField.h>
|
---|
20 | #include <casa/Arrays/Cube.h>
|
---|
21 |
|
---|
22 | #include <tables/Tables/ExprNode.h>
|
---|
23 | #include <tables/Tables/TableDesc.h>
|
---|
24 | #include <tables/Tables/SetupNewTab.h>
|
---|
25 | #include <tables/Tables/TableIter.h>
|
---|
26 | #include <tables/Tables/RefRows.h>
|
---|
27 | #include <tables/Tables/TableRow.h>
|
---|
28 |
|
---|
29 | #include <ms/MeasurementSets/MeasurementSet.h>
|
---|
30 | #include <ms/MeasurementSets/MSColumns.h>
|
---|
31 | #include <ms/MeasurementSets/MSPolIndex.h>
|
---|
32 | #include <ms/MeasurementSets/MSDataDescIndex.h>
|
---|
33 | #include <ms/MeasurementSets/MSSourceIndex.h>
|
---|
34 |
|
---|
35 | #include "MSWriter.h"
|
---|
36 | #include "STHeader.h"
|
---|
37 | #include "STFrequencies.h"
|
---|
38 | #include "STMolecules.h"
|
---|
39 | #include "STTcal.h"
|
---|
40 |
|
---|
41 | #include <ctime>
|
---|
42 | #include <sys/time.h>
|
---|
43 |
|
---|
44 | // Boost
|
---|
45 | #include <boost/pool/object_pool.hpp>
|
---|
46 |
|
---|
47 | using namespace casa ;
|
---|
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 | }
|
---|
57 |
|
---|
58 | MSWriter::MSWriter(CountedPtr<Scantable> stable)
|
---|
59 | : table_(stable),
|
---|
60 | isTcal_(False),
|
---|
61 | isWeather_(False),
|
---|
62 | tcalSpec_(False),
|
---|
63 | tsysSpec_(False),
|
---|
64 | ptTabName_("")
|
---|
65 | {
|
---|
66 | os_ = LogIO() ;
|
---|
67 | os_.origin( LogOrigin( "MSWriter", "MSWriter()", WHERE ) ) ;
|
---|
68 | os_ << "MSWriter::MSWriter()" << LogIO::POST ;
|
---|
69 |
|
---|
70 | // initialize writer
|
---|
71 | init() ;
|
---|
72 | }
|
---|
73 |
|
---|
74 | MSWriter::~MSWriter()
|
---|
75 | {
|
---|
76 | os_.origin( LogOrigin( "MSWriter", "~MSWriter()", WHERE ) ) ;
|
---|
77 | os_ << "MSWriter::~MSWriter()" << LogIO::POST ;
|
---|
78 |
|
---|
79 | if ( mstable_ != 0 )
|
---|
80 | delete mstable_ ;
|
---|
81 | }
|
---|
82 |
|
---|
83 | bool MSWriter::write(const string& filename, const Record& rec)
|
---|
84 | {
|
---|
85 | os_.origin( LogOrigin( "MSWriter", "write()", WHERE ) ) ;
|
---|
86 | double startSec = gettimeofday_sec() ;
|
---|
87 | os_ << "start MSWriter::write() startSec=" << startSec << LogIO::POST ;
|
---|
88 |
|
---|
89 | filename_ = filename ;
|
---|
90 |
|
---|
91 | // parsing MS options
|
---|
92 | Bool overwrite = False ;
|
---|
93 | if ( rec.isDefined( "ms" ) ) {
|
---|
94 | Record msrec = rec.asRecord( "ms" ) ;
|
---|
95 | if ( msrec.isDefined( "overwrite" ) ) {
|
---|
96 | overwrite = msrec.asBool( "overwrite" ) ;
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|
100 | os_ << "Parsing MS options" << endl ;
|
---|
101 | os_ << " overwrite = " << overwrite << LogIO::POST ;
|
---|
102 |
|
---|
103 | File file( filename_ ) ;
|
---|
104 | if ( file.exists() ) {
|
---|
105 | if ( overwrite ) {
|
---|
106 | os_ << filename_ << " exists. Overwrite existing data... " << LogIO::POST ;
|
---|
107 | if ( file.isRegular() ) RegularFile(file).remove() ;
|
---|
108 | else if ( file.isDirectory() ) Directory(file).removeRecursive() ;
|
---|
109 | else SymLink(file).remove() ;
|
---|
110 | }
|
---|
111 | else {
|
---|
112 | os_ << LogIO::SEVERE << "ERROR: " << filename_ << " exists..." << LogIO::POST ;
|
---|
113 | return False ;
|
---|
114 | }
|
---|
115 | }
|
---|
116 |
|
---|
117 | // TEST
|
---|
118 | // memory allocation by boost::object_pool
|
---|
119 | // boost::object_pool<ROTableColumn> *tpoolr = new boost::object_pool<ROTableColumn> ;
|
---|
120 | // ROTableColumn *tcol = 0 ;
|
---|
121 | //
|
---|
122 |
|
---|
123 | // set up MS
|
---|
124 | setupMS() ;
|
---|
125 |
|
---|
126 | // subtables
|
---|
127 | // OBSERVATION
|
---|
128 | fillObservation() ;
|
---|
129 |
|
---|
130 | // ANTENNA
|
---|
131 | fillAntenna() ;
|
---|
132 |
|
---|
133 | // PROCESSOR
|
---|
134 | fillProcessor() ;
|
---|
135 |
|
---|
136 | // SOURCE
|
---|
137 | fillSource() ;
|
---|
138 |
|
---|
139 | // WEATHER
|
---|
140 | if ( isWeather_ )
|
---|
141 | fillWeather() ;
|
---|
142 |
|
---|
143 | // MAIN
|
---|
144 | // Iterate over several ids
|
---|
145 | Vector<uInt> processedFreqId( 0 ) ;
|
---|
146 | Int defaultFieldId = 0 ;
|
---|
147 |
|
---|
148 | // row based
|
---|
149 | TableRow row( *mstable_ ) ;
|
---|
150 | TableRecord &trec = row.record() ;
|
---|
151 | NoticeTarget *dataRF = 0 ;
|
---|
152 | if ( useFloatData_ )
|
---|
153 | dataRF = new RecordFieldPtr< Array<Float> >( trec, "FLOAT_DATA" ) ;
|
---|
154 | else if ( useData_ )
|
---|
155 | dataRF = new RecordFieldPtr< Array<Complex> >( trec, "DATA" ) ;
|
---|
156 | RecordFieldPtr< Array<Bool> > flagRF( trec, "FLAG" ) ;
|
---|
157 | RecordFieldPtr<Bool> flagrowRF( trec, "FLAG_ROW" ) ;
|
---|
158 | RecordFieldPtr<Double> timeRF( trec, "TIME" ) ;
|
---|
159 | RecordFieldPtr<Double> timecRF( trec, "TIME_CENTROID" ) ;
|
---|
160 | RecordFieldPtr<Double> intervalRF( trec, "INTERVAL" ) ;
|
---|
161 | RecordFieldPtr<Double> exposureRF( trec, "EXPOSURE" ) ;
|
---|
162 | RecordFieldPtr< Array<Float> > weightRF( trec, "WEIGHT" ) ;
|
---|
163 | RecordFieldPtr< Array<Float> > sigmaRF( trec, "SIGMA" ) ;
|
---|
164 | RecordFieldPtr<Int> ddidRF( trec, "DATA_DESC_ID" ) ;
|
---|
165 | RecordFieldPtr<Int> stateidRF( trec, "STATE_ID" ) ;
|
---|
166 | RecordFieldPtr< Array<Bool> > flagcatRF( trec, "FLAG_CATEGORY" ) ;
|
---|
167 |
|
---|
168 | // OBSERVATION_ID is always 0
|
---|
169 | RecordFieldPtr<Int> intRF( trec, "OBSERVATION_ID" ) ;
|
---|
170 | *intRF = 0 ;
|
---|
171 |
|
---|
172 | // ANTENNA1 and ANTENNA2 are always 0
|
---|
173 | intRF.attachToRecord( trec, "ANTENNA1" ) ;
|
---|
174 | *intRF = 0 ;
|
---|
175 | intRF.attachToRecord( trec, "ANTENNA2" ) ;
|
---|
176 | *intRF = 0 ;
|
---|
177 |
|
---|
178 | // ARRAY_ID is tentatively set to 0
|
---|
179 | intRF.attachToRecord( trec, "ARRAY_ID" ) ;
|
---|
180 | *intRF = 0 ;
|
---|
181 |
|
---|
182 | // PROCESSOR_ID is tentatively set to 0
|
---|
183 | intRF.attachToRecord( trec, "PROCESSOR_ID" ) ;
|
---|
184 | *intRF = 0 ;
|
---|
185 |
|
---|
186 | // UVW is always [0,0,0]
|
---|
187 | RecordFieldPtr< Array<Double> > uvwRF( trec, "UVW" ) ;
|
---|
188 | *uvwRF = Vector<Double>( 3, 0.0 ) ;
|
---|
189 |
|
---|
190 | //
|
---|
191 | // ITERATION: FIELDNAME
|
---|
192 | //
|
---|
193 | TableIterator iter0( table_->table(), "FIELDNAME" ) ;
|
---|
194 | while( !iter0.pastEnd() ) {
|
---|
195 | //Table t0( iter0.table() ) ;
|
---|
196 | Table t0 = iter0.table() ;
|
---|
197 | ROTableColumn sharedCol( t0, "FIELDNAME" ) ;
|
---|
198 | String fieldName = sharedCol.asString( 0 ) ;
|
---|
199 | // tcol = tpoolr->construct( t0, "FIELDNAME" ) ;
|
---|
200 | // String fieldName = tcol->asString( 0 ) ;
|
---|
201 | // tpoolr->destroy( tcol ) ;
|
---|
202 | sharedCol.attach( t0, "SRCNAME" ) ;
|
---|
203 | String srcName = sharedCol.asString( 0 ) ;
|
---|
204 | // tcol = tpoolr->construct( t0, "SRCNAME" ) ;
|
---|
205 | // String srcName = tcol->asString( 0 ) ;
|
---|
206 | // tpoolr->destroy( tcol ) ;
|
---|
207 | sharedCol.attach( t0, "TIME" ) ;
|
---|
208 | Double minTime = (Double)sharedCol.asdouble( 0 ) * 86400.0 ; // day->sec
|
---|
209 | // tcol = tpoolr->construct( t0, "TIME" ) ;
|
---|
210 | // Double minTime = (Double)(tcol->asdouble( 0 )) * 86400.0 ; // day -> sec
|
---|
211 | // tpoolr->destroy( tcol ) ;
|
---|
212 | ROArrayColumn<Double> scanRateCol( t0, "SCANRATE" ) ;
|
---|
213 | //Vector<Double> scanRate = scanRateCol.getColumn()[0] ;
|
---|
214 | Vector<Double> scanRate = scanRateCol( 0 ) ;
|
---|
215 | String::size_type pos = fieldName.find( "__" ) ;
|
---|
216 | Int fieldId = -1 ;
|
---|
217 | if ( pos != String::npos ) {
|
---|
218 | os_ << "fieldName.substr( pos+2 )=" << fieldName.substr( pos+2 ) << LogIO::POST ;
|
---|
219 | fieldId = String::toInt( fieldName.substr( pos+2 ) ) ;
|
---|
220 | fieldName = fieldName.substr( 0, pos ) ;
|
---|
221 | }
|
---|
222 | else {
|
---|
223 | os_ << "use default field id" << LogIO::POST ;
|
---|
224 | fieldId = defaultFieldId ;
|
---|
225 | defaultFieldId++ ;
|
---|
226 | }
|
---|
227 | os_ << "fieldId" << fieldId << ": " << fieldName << LogIO::POST ;
|
---|
228 |
|
---|
229 | // FIELD_ID
|
---|
230 | intRF.attachToRecord( trec, "FIELD_ID" ) ;
|
---|
231 | *intRF = fieldId ;
|
---|
232 |
|
---|
233 | //
|
---|
234 | // ITERATION: BEAMNO
|
---|
235 | //
|
---|
236 | TableIterator iter1( t0, "BEAMNO" ) ;
|
---|
237 | while( !iter1.pastEnd() ) {
|
---|
238 | Table t1 = iter1.table() ;
|
---|
239 | // tcol = tpoolr->construct( t1, "BEAMNO" ) ;
|
---|
240 | // uInt beamNo = tcol->asuInt( 0 ) ;
|
---|
241 | // tpoolr->destroy( tcol ) ;
|
---|
242 | sharedCol.attach( t1, "BEAMNO" ) ;
|
---|
243 | uInt beamNo = sharedCol.asuInt( 0 ) ;
|
---|
244 | os_ << "beamNo = " << beamNo << LogIO::POST ;
|
---|
245 |
|
---|
246 | // FEED1 and FEED2
|
---|
247 | intRF.attachToRecord( trec, "FEED1" ) ;
|
---|
248 | *intRF = beamNo ;
|
---|
249 | intRF.attachToRecord( trec, "FEED2" ) ;
|
---|
250 | *intRF = beamNo ;
|
---|
251 |
|
---|
252 | //
|
---|
253 | // ITERATION: SCANNO
|
---|
254 | //
|
---|
255 | TableIterator iter2( t1, "SCANNO" ) ;
|
---|
256 | while( !iter2.pastEnd() ) {
|
---|
257 | Table t2 = iter2.table() ;
|
---|
258 | // tcol = tpoolr->construct( t2, "SCANNO" ) ;
|
---|
259 | // uInt scanNo = tcol->asuInt( 0 ) ;
|
---|
260 | // tpoolr->destroy( tcol ) ;
|
---|
261 | sharedCol.attach( t2, "SCANNO" ) ;
|
---|
262 | uInt scanNo = sharedCol.asuInt( 0 ) ;
|
---|
263 | os_ << "scanNo = " << scanNo << LogIO::POST ;
|
---|
264 |
|
---|
265 | // SCAN_NUMBER
|
---|
266 | // MS: 1-based
|
---|
267 | // Scantable: 0-based
|
---|
268 | intRF.attachToRecord( trec, "SCAN_NUMBER" ) ;
|
---|
269 | *intRF = scanNo + 1 ;
|
---|
270 |
|
---|
271 | //
|
---|
272 | // ITERATION: IFNO
|
---|
273 | //
|
---|
274 | TableIterator iter3( t2, "IFNO" ) ;
|
---|
275 | while( !iter3.pastEnd() ) {
|
---|
276 | Table t3 = iter3.table() ;
|
---|
277 | // tcol = tpoolr->construct( t3, "IFNO" ) ;
|
---|
278 | // uInt ifNo = tcol->asuInt( 0 ) ;
|
---|
279 | // tpoolr->destroy( tcol ) ;
|
---|
280 | sharedCol.attach( t3, "IFNO" ) ;
|
---|
281 | uInt ifNo = sharedCol.asuInt( 0 ) ;
|
---|
282 | os_ << "ifNo = " << ifNo << LogIO::POST ;
|
---|
283 | // tcol = tpoolr->construct( t3, "FREQ_ID" ) ;
|
---|
284 | // uInt freqId = tcol->asuInt( 0 ) ;
|
---|
285 | // tpoolr->destroy( tcol ) ;
|
---|
286 | sharedCol.attach( t3, "FREQ_ID" ) ;
|
---|
287 | uInt freqId = sharedCol.asuInt( 0 ) ;
|
---|
288 | os_ << "freqId = " << freqId << LogIO::POST ;
|
---|
289 | Int subscan = 1 ; // 1-base
|
---|
290 | //
|
---|
291 | // ITERATION: SRCTYPE
|
---|
292 | //
|
---|
293 | TableIterator iter4( t3, "SRCTYPE" ) ;
|
---|
294 | while( !iter4.pastEnd() ) {
|
---|
295 | Table t4 = iter4.table() ;
|
---|
296 | // tcol = tpoolr->construct( t4, "SRCTYPE" ) ;
|
---|
297 | // uInt srcType = tcol->asInt( 0 ) ;
|
---|
298 | // tpoolr->destroy( tcol ) ;
|
---|
299 | sharedCol.attach( t4, "SRCTYPE" ) ;
|
---|
300 | Int srcType = sharedCol.asInt( 0 ) ;
|
---|
301 | Int stateId = addState( srcType, subscan ) ;
|
---|
302 | *stateidRF = stateId ;
|
---|
303 | //
|
---|
304 | // ITERATION: CYCLENO and TIME
|
---|
305 | //
|
---|
306 | Block<String> cols( 2 ) ;
|
---|
307 | cols[0] = "CYCLENO" ;
|
---|
308 | cols[1] = "TIME" ;
|
---|
309 | TableIterator iter5( t4, cols ) ;
|
---|
310 | while( !iter5.pastEnd() ) {
|
---|
311 | Table t5 = iter5.table().sort("POLNO") ;
|
---|
312 | //sharedCol.attach( t5, "CYCLENO" ) ;
|
---|
313 | //uInt cycleNo = sharedCol.asuInt( 0 ) ;
|
---|
314 | Int nrow = t5.nrow() ;
|
---|
315 | os_ << "nrow = " << nrow << LogIO::POST ;
|
---|
316 |
|
---|
317 | Vector<Int> polnos( nrow ) ;
|
---|
318 | indgen( polnos, 0 ) ;
|
---|
319 | Int polid = addPolarization( polnos ) ;
|
---|
320 | os_ << "polid = " << polid << LogIO::POST ;
|
---|
321 |
|
---|
322 | // DATA/FLOAT_DATA
|
---|
323 | ROArrayColumn<Float> specCol( t5, "SPECTRA" ) ;
|
---|
324 | ROArrayColumn<uChar> flagCol( t5, "FLAGTRA" ) ;
|
---|
325 | uInt nchan = specCol( 0 ).size() ;
|
---|
326 | IPosition cellshape( 2, nrow, nchan ) ;
|
---|
327 | if ( useFloatData_ ) {
|
---|
328 | // FLOAT_DATA
|
---|
329 | Matrix<Float> dataArr( cellshape ) ;
|
---|
330 | Matrix<Bool> flagArr( cellshape ) ;
|
---|
331 | Vector<Bool> tmpB ;
|
---|
332 | for ( Int ipol = 0 ; ipol < nrow ; ipol++ ) {
|
---|
333 | dataArr.row( ipol ) = specCol( ipol ) ;
|
---|
334 | tmpB.reference( flagArr.row( ipol ) ) ;
|
---|
335 | convertArray( tmpB, flagCol( ipol ) ) ;
|
---|
336 | }
|
---|
337 | //*(*((RecordFieldPtr< Array<Float> > *)dataRF)) = dataArr ;
|
---|
338 | ((RecordFieldPtr< Array<Float> > *)dataRF)->define( dataArr ) ;
|
---|
339 |
|
---|
340 | // FLAG
|
---|
341 | //*flagRF = flagArr ;
|
---|
342 | flagRF.define( flagArr ) ;
|
---|
343 | }
|
---|
344 | else if ( useData_ ) {
|
---|
345 | // DATA
|
---|
346 | // assume nrow = 4
|
---|
347 | Matrix<Complex> dataArr( cellshape ) ;
|
---|
348 | Vector<Float> zeroIm( nchan, 0 ) ;
|
---|
349 | Matrix<Float> dummy( IPosition( 2, 2, nchan ) ) ;
|
---|
350 | dummy.row( 0 ) = specCol( 0 ) ;
|
---|
351 | dummy.row( 1 ) = zeroIm ;
|
---|
352 | dataArr.row( 0 ) = RealToComplex( dummy ) ;
|
---|
353 | dummy.row( 0 ) = specCol( 1 ) ;
|
---|
354 | dataArr.row( 3 ) = RealToComplex( dummy ) ;
|
---|
355 | dummy.row( 0 ) = specCol( 2 ) ;
|
---|
356 | dummy.row( 1 ) = specCol( 3 ) ;
|
---|
357 | dataArr.row( 1 ) = RealToComplex( dummy ) ;
|
---|
358 | dataArr.row( 2 ) = conj( dataArr.row( 1 ) ) ;
|
---|
359 | //*(*((RecordFieldPtr< Array<Complex> > *)dataRF)) = dataArr ;
|
---|
360 | ((RecordFieldPtr< Array<Complex> > *)dataRF)->define( dataArr ) ;
|
---|
361 |
|
---|
362 |
|
---|
363 | // FLAG
|
---|
364 | Matrix<Bool> flagArr( cellshape ) ;
|
---|
365 | Vector<Bool> tmpB ;
|
---|
366 | tmpB.reference( flagArr.row( 0 ) ) ;
|
---|
367 | convertArray( tmpB, flagCol( 0 ) ) ;
|
---|
368 | tmpB.reference( flagArr.row( 3 ) ) ;
|
---|
369 | convertArray( tmpB, flagCol( 3 ) ) ;
|
---|
370 | tmpB.reference( flagArr.row( 1 ) ) ;
|
---|
371 | convertArray( tmpB, ( flagCol( 2 ) | flagCol( 3 ) ) ) ;
|
---|
372 | flagArr.row( 2 ) = flagArr.row( 1 ) ;
|
---|
373 | //*flagRF = flagArr ;
|
---|
374 | flagRF.define( flagArr ) ;
|
---|
375 | }
|
---|
376 |
|
---|
377 | // FLAG_ROW
|
---|
378 | // tcol = tpoolr->construct( t5, "FLAGROW" ) ;
|
---|
379 | sharedCol.attach( t5, "FLAGROW" ) ;
|
---|
380 | Vector<uInt> flagRowArr( nrow ) ;
|
---|
381 | for ( Int irow = 0 ; irow < nrow ; irow++ )
|
---|
382 | flagRowArr[irow] = sharedCol.asuInt( irow ) ;
|
---|
383 | // flagRowArr[irow] = tcol->asuInt( irow ) ;
|
---|
384 | // tpoolr->destroy( tcol ) ;
|
---|
385 | *flagrowRF = anyNE( flagRowArr, (uInt)0 ) ;
|
---|
386 |
|
---|
387 | // TIME and TIME_CENTROID
|
---|
388 | // tcol = tpoolr->construct( t5, "TIME" ) ;
|
---|
389 | // Double mTimeV = (Double)(tcol->asdouble(0)) * 86400.0 ; // day->sec
|
---|
390 | // tpoolr->destroy( tcol ) ;
|
---|
391 | sharedCol.attach( t5, "TIME" ) ;
|
---|
392 | Double mTimeV = (Double)sharedCol.asdouble( 0 ) * 86400.0 ; // day -> sec
|
---|
393 | *timeRF = mTimeV ;
|
---|
394 | *timecRF = mTimeV ;
|
---|
395 |
|
---|
396 | // INTERVAL and EXPOSURE
|
---|
397 | // tcol = tpoolr->construct( t5, "INTERVAL" ) ;
|
---|
398 | // Double interval = (Double)(tcol->asdouble( 0 )) ;
|
---|
399 | // tpoolr->destroy( tcol ) ;
|
---|
400 | sharedCol.attach( t5, "INTERVAL" ) ;
|
---|
401 | Double interval = (Double)sharedCol.asdouble( 0 ) ;
|
---|
402 | *intervalRF = interval ;
|
---|
403 | *exposureRF = interval ;
|
---|
404 |
|
---|
405 | // WEIGHT and SIGMA
|
---|
406 | // always 1 at the moment
|
---|
407 | Vector<Float> wArr( nrow, 1.0 ) ;
|
---|
408 | // *weightRF = wArr ;
|
---|
409 | // *sigmaRF = wArr ;
|
---|
410 | weightRF.define( wArr ) ;
|
---|
411 | sigmaRF.define( wArr ) ;
|
---|
412 |
|
---|
413 | // add DATA_DESCRIPTION row
|
---|
414 | Int ddid = addDataDescription( polid, ifNo ) ;
|
---|
415 | os_ << "ddid = " << ddid << LogIO::POST ;
|
---|
416 | *ddidRF = ddid ;
|
---|
417 |
|
---|
418 | // for SYSCAL table
|
---|
419 | // tcol = tpoolr->construct( t5, "TCAL_ID" ) ;
|
---|
420 | sharedCol.attach( t5, "TCAL_ID" ) ;
|
---|
421 | Vector<uInt> tcalIdArr( nrow ) ;
|
---|
422 | for ( Int irow = 0 ; irow < nrow ; irow++ )
|
---|
423 | tcalIdArr[irow] = sharedCol.asuInt( irow ) ;
|
---|
424 | // tcalIdArr[irow] = tcol->asuInt( irow ) ;
|
---|
425 | // tpoolr->destroy( tcol ) ;
|
---|
426 | os_ << "tcalIdArr = " << tcalIdArr << LogIO::POST ;
|
---|
427 | String key = String::toString( tcalIdArr[0] ) ;
|
---|
428 | if ( !tcalIdRec_.isDefined( key ) ) {
|
---|
429 | tcalIdRec_.define( key, tcalIdArr ) ;
|
---|
430 | tcalRowRec_.define( key, t5.rowNumbers() ) ;
|
---|
431 | }
|
---|
432 | else {
|
---|
433 | Vector<uInt> pastrows = tcalRowRec_.asArrayuInt( key ) ;
|
---|
434 | tcalRowRec_.define( key, concatenateArray( pastrows, t5.rowNumbers() ) ) ;
|
---|
435 | }
|
---|
436 |
|
---|
437 | // fill STATE_ID
|
---|
438 | //ROScalarColumn<Int> srcTypeCol( t5, "SRCTYPE" ) ;
|
---|
439 | //Int srcType = srcTypeCol( 0 ) ;
|
---|
440 | //Int stateId = addState( srcType, subscan ) ;
|
---|
441 | //*stateidRF = stateId ;
|
---|
442 |
|
---|
443 | // for POINTING table
|
---|
444 | if ( ptTabName_ == "" ) {
|
---|
445 | ROArrayColumn<Double> dirCol( t5, "DIRECTION" ) ;
|
---|
446 | Vector<Double> dir = dirCol( 0 ) ;
|
---|
447 | dirCol.attach( t5, "SCANRATE" ) ;
|
---|
448 | Vector<Double> rate = dirCol( 0 ) ;
|
---|
449 | Matrix<Double> msDir( 2, 1 ) ;
|
---|
450 | msDir.column( 0 ) = dir ;
|
---|
451 | if ( anyNE( rate, 0.0 ) ) {
|
---|
452 | msDir.resize( 2, 2 ) ;
|
---|
453 | msDir.column( 1 ) = rate ;
|
---|
454 | }
|
---|
455 | addPointing( fieldName, mTimeV, interval, msDir ) ;
|
---|
456 | }
|
---|
457 |
|
---|
458 | // FLAG_CATEGORY is tentatively set
|
---|
459 | //*flagcatRF = Cube<Bool>( nrow, nchan, 1, False ) ;
|
---|
460 | flagcatRF.define( Cube<Bool>( nrow, nchan, 1, False ) ) ;
|
---|
461 |
|
---|
462 | // add row
|
---|
463 | mstable_->addRow( 1, True ) ;
|
---|
464 | row.put( mstable_->nrow()-1 ) ;
|
---|
465 |
|
---|
466 | iter5.next() ;
|
---|
467 | }
|
---|
468 |
|
---|
469 | iter4.next() ;
|
---|
470 | }
|
---|
471 |
|
---|
472 | // add SPECTRAL_WINDOW row
|
---|
473 | if ( allNE( processedFreqId, freqId ) ) {
|
---|
474 | uInt vsize = processedFreqId.size() ;
|
---|
475 | processedFreqId.resize( vsize+1, True ) ;
|
---|
476 | processedFreqId[vsize] = freqId ;
|
---|
477 | addSpectralWindow( ifNo, freqId ) ;
|
---|
478 | }
|
---|
479 |
|
---|
480 | iter3.next() ;
|
---|
481 | }
|
---|
482 |
|
---|
483 | iter2.next() ;
|
---|
484 | }
|
---|
485 |
|
---|
486 | // add FEED row
|
---|
487 | addFeed( beamNo ) ;
|
---|
488 |
|
---|
489 | iter1.next() ;
|
---|
490 | }
|
---|
491 |
|
---|
492 | // add FIELD row
|
---|
493 | addField( fieldId, fieldName, srcName, minTime, scanRate ) ;
|
---|
494 |
|
---|
495 | iter0.next() ;
|
---|
496 | }
|
---|
497 |
|
---|
498 | // delete tpoolr ;
|
---|
499 | delete dataRF ;
|
---|
500 |
|
---|
501 | // SYSCAL
|
---|
502 | if ( isTcal_ )
|
---|
503 | fillSysCal() ;
|
---|
504 |
|
---|
505 | // replace POINTING table with original one if exists
|
---|
506 | if ( ptTabName_ != "" ) {
|
---|
507 | delete mstable_ ;
|
---|
508 | mstable_ = 0 ;
|
---|
509 | Table newPtTab( ptTabName_, Table::Old ) ;
|
---|
510 | newPtTab.copy( filename_+"/POINTING", Table::New ) ;
|
---|
511 | }
|
---|
512 |
|
---|
513 | double endSec = gettimeofday_sec() ;
|
---|
514 | os_ << "end MSWriter::write() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
515 |
|
---|
516 | return True ;
|
---|
517 | }
|
---|
518 |
|
---|
519 | void MSWriter::init()
|
---|
520 | {
|
---|
521 | // os_.origin( LogOrigin( "MSWriter", "init()", WHERE ) ) ;
|
---|
522 | double startSec = gettimeofday_sec() ;
|
---|
523 | os_ << "start MSWriter::init() startSec=" << startSec << LogIO::POST ;
|
---|
524 |
|
---|
525 | // access to scantable
|
---|
526 | header_ = table_->getHeader() ;
|
---|
527 |
|
---|
528 | // FLOAT_DATA? or DATA?
|
---|
529 | if ( header_.npol > 2 ) {
|
---|
530 | useFloatData_ = False ;
|
---|
531 | useData_ = True ;
|
---|
532 | }
|
---|
533 | else {
|
---|
534 | useFloatData_ = True ;
|
---|
535 | useData_ = False ;
|
---|
536 | }
|
---|
537 |
|
---|
538 | // polarization type
|
---|
539 | polType_ = header_.poltype ;
|
---|
540 | if ( polType_ == "" )
|
---|
541 | polType_ = "stokes" ;
|
---|
542 | else if ( polType_.find( "linear" ) != String::npos )
|
---|
543 | polType_ = "linear" ;
|
---|
544 | else if ( polType_.find( "circular" ) != String::npos )
|
---|
545 | polType_ = "circular" ;
|
---|
546 | else if ( polType_.find( "stokes" ) != String::npos )
|
---|
547 | polType_ = "stokes" ;
|
---|
548 | else if ( polType_.find( "linpol" ) != String::npos )
|
---|
549 | polType_ = "linpol" ;
|
---|
550 | else
|
---|
551 | polType_ = "notype" ;
|
---|
552 |
|
---|
553 | // Check if some subtables are exists
|
---|
554 | if ( table_->tcal().table().nrow() != 0 ) {
|
---|
555 | ROTableColumn col( table_->tcal().table(), "TCAL" ) ;
|
---|
556 | if ( col.isDefined( 0 ) ) {
|
---|
557 | os_ << "nrow=" << table_->tcal().table().nrow() << ": TCAL table exists" << LogIO::POST ;
|
---|
558 | isTcal_ = True ;
|
---|
559 | }
|
---|
560 | else {
|
---|
561 | os_ << "no TCAL rows" << LogIO::POST ;
|
---|
562 | }
|
---|
563 | }
|
---|
564 | else {
|
---|
565 | os_ << "no TCAL rows" << LogIO::POST ;
|
---|
566 | }
|
---|
567 | if ( table_->weather().table().nrow() != 0 ) {
|
---|
568 | ROTableColumn col( table_->weather().table(), "TEMPERATURE" ) ;
|
---|
569 | if ( col.isDefined( 0 ) ) {
|
---|
570 | os_ << "nrow=" << table_->weather().table().nrow() << ": WEATHER table exists" << LogIO::POST ;
|
---|
571 | isWeather_ =True ;
|
---|
572 | }
|
---|
573 | else {
|
---|
574 | os_ << "no WEATHER rows" << LogIO::POST ;
|
---|
575 | }
|
---|
576 | }
|
---|
577 | else {
|
---|
578 | os_ << "no WEATHER rows" << LogIO::POST ;
|
---|
579 | }
|
---|
580 |
|
---|
581 | // Are TCAL_SPECTRUM and TSYS_SPECTRUM necessary?
|
---|
582 | if ( isTcal_ && header_.nchan != 1 ) {
|
---|
583 | // examine TCAL subtable
|
---|
584 | Table tcaltab = table_->tcal().table() ;
|
---|
585 | ROArrayColumn<Float> tcalCol( tcaltab, "TCAL" ) ;
|
---|
586 | for ( uInt irow = 0 ; irow < tcaltab.nrow() ; irow++ ) {
|
---|
587 | if ( tcalCol( irow ).size() != 1 )
|
---|
588 | tcalSpec_ = True ;
|
---|
589 | }
|
---|
590 | // examine spectral data
|
---|
591 | TableIterator iter0( table_->table(), "IFNO" ) ;
|
---|
592 | while( !iter0.pastEnd() ) {
|
---|
593 | Table t0( iter0.table() ) ;
|
---|
594 | ROArrayColumn<Float> sharedFloatArrCol( t0, "SPECTRA" ) ;
|
---|
595 | uInt len = sharedFloatArrCol( 0 ).size() ;
|
---|
596 | if ( len != 1 ) {
|
---|
597 | sharedFloatArrCol.attach( t0, "TSYS" ) ;
|
---|
598 | if ( sharedFloatArrCol( 0 ).size() != 1 )
|
---|
599 | tsysSpec_ = True ;
|
---|
600 | }
|
---|
601 | iter0.next() ;
|
---|
602 | }
|
---|
603 | }
|
---|
604 |
|
---|
605 | // check if reference for POINTING table exists
|
---|
606 | const TableRecord &rec = table_->table().keywordSet() ;
|
---|
607 | if ( rec.isDefined( "POINTING" ) ) {
|
---|
608 | ptTabName_ = rec.asString( "POINTING" ) ;
|
---|
609 | if ( !Table::isReadable( ptTabName_ ) ) {
|
---|
610 | ptTabName_ = "" ;
|
---|
611 | }
|
---|
612 | }
|
---|
613 |
|
---|
614 | double endSec = gettimeofday_sec() ;
|
---|
615 | os_ << "end MSWriter::init() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
616 | }
|
---|
617 |
|
---|
618 | void MSWriter::setupMS()
|
---|
619 | {
|
---|
620 | // os_.origin( LogOrigin( "MSWriter", "setupMS()", WHERE ) ) ;
|
---|
621 | double startSec = gettimeofday_sec() ;
|
---|
622 | os_ << "start MSWriter::setupMS() startSec=" << startSec << LogIO::POST ;
|
---|
623 |
|
---|
624 | TableDesc msDesc = MeasurementSet::requiredTableDesc() ;
|
---|
625 | if ( useFloatData_ )
|
---|
626 | MeasurementSet::addColumnToDesc( msDesc, MSMainEnums::FLOAT_DATA, 2 ) ;
|
---|
627 | else if ( useData_ )
|
---|
628 | MeasurementSet::addColumnToDesc( msDesc, MSMainEnums::DATA, 2 ) ;
|
---|
629 |
|
---|
630 | SetupNewTable newtab( filename_, msDesc, Table::New ) ;
|
---|
631 |
|
---|
632 | mstable_ = new MeasurementSet( newtab ) ;
|
---|
633 |
|
---|
634 | // create subtables
|
---|
635 | TableDesc antennaDesc = MSAntenna::requiredTableDesc() ;
|
---|
636 | SetupNewTable antennaTab( mstable_->antennaTableName(), antennaDesc, Table::New ) ;
|
---|
637 | mstable_->rwKeywordSet().defineTable( MeasurementSet::keywordName( MeasurementSet::ANTENNA ), Table( antennaTab ) ) ;
|
---|
638 |
|
---|
639 | TableDesc dataDescDesc = MSDataDescription::requiredTableDesc() ;
|
---|
640 | SetupNewTable dataDescTab( mstable_->dataDescriptionTableName(), dataDescDesc, Table::New ) ;
|
---|
641 | mstable_->rwKeywordSet().defineTable( MeasurementSet::keywordName( MeasurementSet::DATA_DESCRIPTION ), Table( dataDescTab ) ) ;
|
---|
642 |
|
---|
643 | TableDesc dopplerDesc = MSDoppler::requiredTableDesc() ;
|
---|
644 | SetupNewTable dopplerTab( mstable_->dopplerTableName(), dopplerDesc, Table::New ) ;
|
---|
645 | mstable_->rwKeywordSet().defineTable( MeasurementSet::keywordName( MeasurementSet::DOPPLER ), Table( dopplerTab ) ) ;
|
---|
646 |
|
---|
647 | TableDesc feedDesc = MSFeed::requiredTableDesc() ;
|
---|
648 | SetupNewTable feedTab( mstable_->feedTableName(), feedDesc, Table::New ) ;
|
---|
649 | mstable_->rwKeywordSet().defineTable( MeasurementSet::keywordName( MeasurementSet::FEED ), Table( feedTab ) ) ;
|
---|
650 |
|
---|
651 | TableDesc fieldDesc = MSField::requiredTableDesc() ;
|
---|
652 | SetupNewTable fieldTab( mstable_->fieldTableName(), fieldDesc, Table::New ) ;
|
---|
653 | mstable_->rwKeywordSet().defineTable( MeasurementSet::keywordName( MeasurementSet::FIELD ), Table( fieldTab ) ) ;
|
---|
654 |
|
---|
655 | TableDesc flagCmdDesc = MSFlagCmd::requiredTableDesc() ;
|
---|
656 | SetupNewTable flagCmdTab( mstable_->flagCmdTableName(), flagCmdDesc, Table::New ) ;
|
---|
657 | mstable_->rwKeywordSet().defineTable( MeasurementSet::keywordName( MeasurementSet::FLAG_CMD ), Table( flagCmdTab ) ) ;
|
---|
658 |
|
---|
659 | TableDesc freqOffsetDesc = MSFreqOffset::requiredTableDesc() ;
|
---|
660 | SetupNewTable freqOffsetTab( mstable_->freqOffsetTableName(), freqOffsetDesc, Table::New ) ;
|
---|
661 | mstable_->rwKeywordSet().defineTable( MeasurementSet::keywordName( MeasurementSet::FREQ_OFFSET ), Table( freqOffsetTab ) ) ;
|
---|
662 |
|
---|
663 | TableDesc historyDesc = MSHistory::requiredTableDesc() ;
|
---|
664 | SetupNewTable historyTab( mstable_->historyTableName(), historyDesc, Table::New ) ;
|
---|
665 | mstable_->rwKeywordSet().defineTable( MeasurementSet::keywordName( MeasurementSet::HISTORY ), Table( historyTab ) ) ;
|
---|
666 |
|
---|
667 | TableDesc observationDesc = MSObservation::requiredTableDesc() ;
|
---|
668 | SetupNewTable observationTab( mstable_->observationTableName(), observationDesc, Table::New ) ;
|
---|
669 | mstable_->rwKeywordSet().defineTable( MeasurementSet::keywordName( MeasurementSet::OBSERVATION ), Table( observationTab ) ) ;
|
---|
670 |
|
---|
671 | TableDesc pointingDesc = MSPointing::requiredTableDesc() ;
|
---|
672 | SetupNewTable pointingTab( mstable_->pointingTableName(), pointingDesc, Table::New ) ;
|
---|
673 | mstable_->rwKeywordSet().defineTable( MeasurementSet::keywordName( MeasurementSet::POINTING ), Table( pointingTab ) ) ;
|
---|
674 |
|
---|
675 | TableDesc polarizationDesc = MSPolarization::requiredTableDesc() ;
|
---|
676 | SetupNewTable polarizationTab( mstable_->polarizationTableName(), polarizationDesc, Table::New ) ;
|
---|
677 | mstable_->rwKeywordSet().defineTable( MeasurementSet::keywordName( MeasurementSet::POLARIZATION ), Table( polarizationTab ) ) ;
|
---|
678 |
|
---|
679 | TableDesc processorDesc = MSProcessor::requiredTableDesc() ;
|
---|
680 | SetupNewTable processorTab( mstable_->processorTableName(), processorDesc, Table::New ) ;
|
---|
681 | mstable_->rwKeywordSet().defineTable( MeasurementSet::keywordName( MeasurementSet::PROCESSOR ), Table( processorTab ) ) ;
|
---|
682 |
|
---|
683 | TableDesc sourceDesc = MSSource::requiredTableDesc() ;
|
---|
684 | MSSource::addColumnToDesc( sourceDesc, MSSourceEnums::TRANSITION, 1 ) ;
|
---|
685 | MSSource::addColumnToDesc( sourceDesc, MSSourceEnums::REST_FREQUENCY, 1 ) ;
|
---|
686 | MSSource::addColumnToDesc( sourceDesc, MSSourceEnums::SYSVEL, 1 ) ;
|
---|
687 | SetupNewTable sourceTab( mstable_->sourceTableName(), sourceDesc, Table::New ) ;
|
---|
688 | mstable_->rwKeywordSet().defineTable( MeasurementSet::keywordName( MeasurementSet::SOURCE ), Table( sourceTab ) ) ;
|
---|
689 |
|
---|
690 | TableDesc spwDesc = MSSpectralWindow::requiredTableDesc() ;
|
---|
691 | SetupNewTable spwTab( mstable_->spectralWindowTableName(), spwDesc, Table::New ) ;
|
---|
692 | mstable_->rwKeywordSet().defineTable( MeasurementSet::keywordName( MeasurementSet::SPECTRAL_WINDOW ), Table( spwTab ) ) ;
|
---|
693 |
|
---|
694 | TableDesc stateDesc = MSState::requiredTableDesc() ;
|
---|
695 | SetupNewTable stateTab( mstable_->stateTableName(), stateDesc, Table::New ) ;
|
---|
696 | mstable_->rwKeywordSet().defineTable( MeasurementSet::keywordName( MeasurementSet::STATE ), Table( stateTab ) ) ;
|
---|
697 |
|
---|
698 | // TODO: add TCAL_SPECTRUM and TSYS_SPECTRUM if necessary
|
---|
699 | TableDesc sysCalDesc = MSSysCal::requiredTableDesc() ;
|
---|
700 | MSSysCal::addColumnToDesc( sysCalDesc, MSSysCalEnums::TCAL, 2 ) ;
|
---|
701 | MSSysCal::addColumnToDesc( sysCalDesc, MSSysCalEnums::TSYS, 2 ) ;
|
---|
702 | if ( tcalSpec_ )
|
---|
703 | MSSysCal::addColumnToDesc( sysCalDesc, MSSysCalEnums::TCAL_SPECTRUM, 2 ) ;
|
---|
704 | if ( tsysSpec_ )
|
---|
705 | MSSysCal::addColumnToDesc( sysCalDesc, MSSysCalEnums::TSYS_SPECTRUM, 2 ) ;
|
---|
706 | SetupNewTable sysCalTab( mstable_->sysCalTableName(), sysCalDesc, Table::New ) ;
|
---|
707 | mstable_->rwKeywordSet().defineTable( MeasurementSet::keywordName( MeasurementSet::SYSCAL ), Table( sysCalTab ) ) ;
|
---|
708 |
|
---|
709 | TableDesc weatherDesc = MSWeather::requiredTableDesc() ;
|
---|
710 | MSWeather::addColumnToDesc( weatherDesc, MSWeatherEnums::TEMPERATURE ) ;
|
---|
711 | MSWeather::addColumnToDesc( weatherDesc, MSWeatherEnums::PRESSURE ) ;
|
---|
712 | MSWeather::addColumnToDesc( weatherDesc, MSWeatherEnums::REL_HUMIDITY ) ;
|
---|
713 | MSWeather::addColumnToDesc( weatherDesc, MSWeatherEnums::WIND_SPEED ) ;
|
---|
714 | MSWeather::addColumnToDesc( weatherDesc, MSWeatherEnums::WIND_DIRECTION ) ;
|
---|
715 | SetupNewTable weatherTab( mstable_->weatherTableName(), weatherDesc, Table::New ) ;
|
---|
716 | mstable_->rwKeywordSet().defineTable( MeasurementSet::keywordName( MeasurementSet::WEATHER ), Table( weatherTab ) ) ;
|
---|
717 |
|
---|
718 | mstable_->initRefs() ;
|
---|
719 |
|
---|
720 | double endSec = gettimeofday_sec() ;
|
---|
721 | os_ << "end MSWriter::setupMS() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
722 | }
|
---|
723 |
|
---|
724 | void MSWriter::fillObservation()
|
---|
725 | {
|
---|
726 | double startSec = gettimeofday_sec() ;
|
---|
727 | os_ << "start MSWriter::fillObservation() startSec=" << startSec << LogIO::POST ;
|
---|
728 |
|
---|
729 | // only 1 row
|
---|
730 | mstable_->observation().addRow( 1, True ) ;
|
---|
731 | MSObservationColumns msObsCols( mstable_->observation() ) ;
|
---|
732 | msObsCols.observer().put( 0, header_.observer ) ;
|
---|
733 | // tentatively put antennaname (from ANTENNA subtable)
|
---|
734 | String hAntennaName = header_.antennaname ;
|
---|
735 | String::size_type pos = hAntennaName.find( "//" ) ;
|
---|
736 | String telescopeName ;
|
---|
737 | if ( pos != String::npos ) {
|
---|
738 | telescopeName = hAntennaName.substr( 0, pos ) ;
|
---|
739 | }
|
---|
740 | else {
|
---|
741 | pos = hAntennaName.find( "@" ) ;
|
---|
742 | telescopeName = hAntennaName.substr( 0, pos ) ;
|
---|
743 | }
|
---|
744 | os_ << "telescopeName = " << telescopeName << LogIO::POST ;
|
---|
745 | msObsCols.telescopeName().put( 0, telescopeName ) ;
|
---|
746 | msObsCols.project().put( 0, header_.project ) ;
|
---|
747 | //ScalarMeasColumn<MEpoch> timeCol( table_->table().sort("TIME"), "TIME" ) ;
|
---|
748 | Table sortedtable = table_->table().sort("TIME") ;
|
---|
749 | ScalarMeasColumn<MEpoch> timeCol( sortedtable, "TIME" ) ;
|
---|
750 | Vector<MEpoch> trange( 2 ) ;
|
---|
751 | trange[0] = timeCol( 0 ) ;
|
---|
752 | trange[1] = timeCol( table_->nrow()-1 ) ;
|
---|
753 | msObsCols.timeRangeMeas().put( 0, trange ) ;
|
---|
754 |
|
---|
755 | double endSec = gettimeofday_sec() ;
|
---|
756 | os_ << "end MSWriter::fillObservation() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
757 | }
|
---|
758 |
|
---|
759 | void MSWriter::fillAntenna()
|
---|
760 | {
|
---|
761 | double startSec = gettimeofday_sec() ;
|
---|
762 | os_ << "start MSWriter::fillAntenna() startSec=" << startSec << LogIO::POST ;
|
---|
763 |
|
---|
764 | // only 1 row
|
---|
765 | mstable_->antenna().addRow( 1, True ) ;
|
---|
766 | MSAntennaColumns msAntCols( mstable_->antenna() ) ;
|
---|
767 |
|
---|
768 | String hAntennaName = header_.antennaname ;
|
---|
769 | String::size_type pos = hAntennaName.find( "//" ) ;
|
---|
770 | String antennaName ;
|
---|
771 | String stationName ;
|
---|
772 | if ( pos != String::npos ) {
|
---|
773 | hAntennaName = hAntennaName.substr( pos+2 ) ;
|
---|
774 | }
|
---|
775 | pos = hAntennaName.find( "@" ) ;
|
---|
776 | if ( pos != String::npos ) {
|
---|
777 | antennaName = hAntennaName.substr( 0, pos ) ;
|
---|
778 | stationName = hAntennaName.substr( pos+1 ) ;
|
---|
779 | }
|
---|
780 | else {
|
---|
781 | antennaName = hAntennaName ;
|
---|
782 | stationName = hAntennaName ;
|
---|
783 | }
|
---|
784 | os_ << "antennaName = " << antennaName << LogIO::POST ;
|
---|
785 | os_ << "stationName = " << stationName << LogIO::POST ;
|
---|
786 |
|
---|
787 | msAntCols.name().put( 0, antennaName ) ;
|
---|
788 | msAntCols.station().put( 0, stationName ) ;
|
---|
789 |
|
---|
790 | os_ << "antennaPosition = " << header_.antennaposition << LogIO::POST ;
|
---|
791 |
|
---|
792 | msAntCols.position().put( 0, header_.antennaposition ) ;
|
---|
793 |
|
---|
794 | double endSec = gettimeofday_sec() ;
|
---|
795 | os_ << "end MSWriter::fillAntenna() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
796 | }
|
---|
797 |
|
---|
798 | void MSWriter::fillProcessor()
|
---|
799 | {
|
---|
800 | double startSec = gettimeofday_sec() ;
|
---|
801 | os_ << "start MSWriter::fillProcessor() startSec=" << startSec << LogIO::POST ;
|
---|
802 |
|
---|
803 | // only add empty 1 row
|
---|
804 | MSProcessor msProc = mstable_->processor() ;
|
---|
805 | msProc.addRow( 1, True ) ;
|
---|
806 |
|
---|
807 | double endSec = gettimeofday_sec() ;
|
---|
808 | os_ << "end MSWriter::fillProcessor() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
809 | }
|
---|
810 |
|
---|
811 | void MSWriter::fillSource()
|
---|
812 | {
|
---|
813 | double startSec = gettimeofday_sec() ;
|
---|
814 | os_ << "start MSWriter::fillSource() startSec=" << startSec << LogIO::POST ;
|
---|
815 |
|
---|
816 | // access to MS SOURCE subtable
|
---|
817 | MSSource msSrc = mstable_->source() ;
|
---|
818 |
|
---|
819 | // access to MOLECULE subtable
|
---|
820 | STMolecules stm = table_->molecules() ;
|
---|
821 |
|
---|
822 | Int srcId = 0 ;
|
---|
823 | Vector<Double> restFreq ;
|
---|
824 | Vector<String> molName ;
|
---|
825 | Vector<String> fMolName ;
|
---|
826 |
|
---|
827 | // row based
|
---|
828 | TableRow row( msSrc ) ;
|
---|
829 | TableRecord &rec = row.record() ;
|
---|
830 | RecordFieldPtr<Int> srcidRF( rec, "SOURCE_ID" ) ;
|
---|
831 | RecordFieldPtr<String> nameRF( rec, "NAME" ) ;
|
---|
832 | RecordFieldPtr< Array<Double> > srcpmRF( rec, "PROPER_MOTION" ) ;
|
---|
833 | RecordFieldPtr< Array<Double> > srcdirRF( rec, "DIRECTION" ) ;
|
---|
834 | RecordFieldPtr<Int> numlineRF( rec, "NUM_LINES" ) ;
|
---|
835 | RecordFieldPtr< Array<Double> > restfreqRF( rec, "REST_FREQUENCY" ) ;
|
---|
836 | RecordFieldPtr< Array<Double> > sysvelRF( rec, "SYSVEL" ) ;
|
---|
837 | RecordFieldPtr< Array<String> > transitionRF( rec, "TRANSITION" ) ;
|
---|
838 | RecordFieldPtr<Double> timeRF( rec, "TIME" ) ;
|
---|
839 | RecordFieldPtr<Double> intervalRF( rec, "INTERVAL" ) ;
|
---|
840 | RecordFieldPtr<Int> spwidRF( rec, "SPECTRAL_WINDOW_ID" ) ;
|
---|
841 |
|
---|
842 | //
|
---|
843 | // ITERATION: SRCNAME
|
---|
844 | //
|
---|
845 | TableIterator iter0( table_->table(), "SRCNAME" ) ;
|
---|
846 | while( !iter0.pastEnd() ) {
|
---|
847 | //Table t0( iter0.table() ) ;
|
---|
848 | Table t0 = iter0.table() ;
|
---|
849 |
|
---|
850 | // get necessary information
|
---|
851 | ROScalarColumn<String> srcNameCol( t0, "SRCNAME" ) ;
|
---|
852 | String srcName = srcNameCol( 0 ) ;
|
---|
853 | ROArrayColumn<Double> sharedDArrRCol( t0, "SRCPROPERMOTION" ) ;
|
---|
854 | Vector<Double> srcPM = sharedDArrRCol( 0 ) ;
|
---|
855 | sharedDArrRCol.attach( t0, "SRCDIRECTION" ) ;
|
---|
856 | Vector<Double> srcDir = sharedDArrRCol( 0 ) ;
|
---|
857 | ROScalarColumn<Double> srcVelCol( t0, "SRCVELOCITY" ) ;
|
---|
858 | Double srcVel = srcVelCol( 0 ) ;
|
---|
859 |
|
---|
860 | // NAME
|
---|
861 | *nameRF = srcName ;
|
---|
862 |
|
---|
863 | // SOURCE_ID
|
---|
864 | *srcidRF = srcId ;
|
---|
865 |
|
---|
866 | // PROPER_MOTION
|
---|
867 | *srcpmRF = srcPM ;
|
---|
868 |
|
---|
869 | // DIRECTION
|
---|
870 | *srcdirRF = srcDir ;
|
---|
871 |
|
---|
872 | //
|
---|
873 | // ITERATION: MOLECULE_ID
|
---|
874 | //
|
---|
875 | TableIterator iter1( t0, "MOLECULE_ID" ) ;
|
---|
876 | while( !iter1.pastEnd() ) {
|
---|
877 | //Table t1( iter1.table() ) ;
|
---|
878 | Table t1 = iter1.table() ;
|
---|
879 |
|
---|
880 | // get necessary information
|
---|
881 | ROScalarColumn<uInt> molIdCol( t1, "MOLECULE_ID" ) ;
|
---|
882 | uInt molId = molIdCol( 0 ) ;
|
---|
883 | stm.getEntry( restFreq, molName, fMolName, molId ) ;
|
---|
884 |
|
---|
885 | uInt numFreq = restFreq.size() ;
|
---|
886 |
|
---|
887 | // NUM_LINES
|
---|
888 | *numlineRF = numFreq ;
|
---|
889 |
|
---|
890 | // REST_FREQUENCY
|
---|
891 | *restfreqRF = restFreq ;
|
---|
892 |
|
---|
893 | // TRANSITION
|
---|
894 | //*transitionRF = fMolName ;
|
---|
895 | Vector<String> transition ;
|
---|
896 | if ( fMolName.size() != 0 ) {
|
---|
897 | transition = fMolName ;
|
---|
898 | }
|
---|
899 | else if ( molName.size() != 0 ) {
|
---|
900 | transition = molName ;
|
---|
901 | }
|
---|
902 | else {
|
---|
903 | transition.resize( numFreq ) ;
|
---|
904 | transition = "" ;
|
---|
905 | }
|
---|
906 | *transitionRF = transition ;
|
---|
907 |
|
---|
908 | // SYSVEL
|
---|
909 | Vector<Double> sysvelArr( numFreq, srcVel ) ;
|
---|
910 | *sysvelRF = sysvelArr ;
|
---|
911 |
|
---|
912 | //
|
---|
913 | // ITERATION: IFNO
|
---|
914 | //
|
---|
915 | TableIterator iter2( t1, "IFNO" ) ;
|
---|
916 | while( !iter2.pastEnd() ) {
|
---|
917 | //Table t2( iter2.table() ) ;
|
---|
918 | Table t2 = iter2.table() ;
|
---|
919 | uInt nrow = msSrc.nrow() ;
|
---|
920 |
|
---|
921 | // get necessary information
|
---|
922 | ROScalarColumn<uInt> ifNoCol( t2, "IFNO" ) ;
|
---|
923 | uInt ifno = ifNoCol( 0 ) ; // IFNO = SPECTRAL_WINDOW_ID
|
---|
924 | Double midTime ;
|
---|
925 | Double interval ;
|
---|
926 | getValidTimeRange( midTime, interval, t2 ) ;
|
---|
927 |
|
---|
928 | // fill SPECTRAL_WINDOW_ID
|
---|
929 | *spwidRF = ifno ;
|
---|
930 |
|
---|
931 | // fill TIME, INTERVAL
|
---|
932 | *timeRF = midTime ;
|
---|
933 | *intervalRF = interval ;
|
---|
934 |
|
---|
935 | // add row
|
---|
936 | msSrc.addRow( 1, True ) ;
|
---|
937 | row.put( nrow ) ;
|
---|
938 |
|
---|
939 | iter2.next() ;
|
---|
940 | }
|
---|
941 |
|
---|
942 | iter1.next() ;
|
---|
943 | }
|
---|
944 |
|
---|
945 | // increment srcId if SRCNAME changed
|
---|
946 | srcId++ ;
|
---|
947 |
|
---|
948 | iter0.next() ;
|
---|
949 | }
|
---|
950 |
|
---|
951 | double endSec = gettimeofday_sec() ;
|
---|
952 | os_ << "end MSWriter::fillSource() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
953 | }
|
---|
954 |
|
---|
955 | void MSWriter::fillWeather()
|
---|
956 | {
|
---|
957 | double startSec = gettimeofday_sec() ;
|
---|
958 | os_ << "start MSWriter::fillWeather() startSec=" << startSec << LogIO::POST ;
|
---|
959 |
|
---|
960 | // access to MS WEATHER subtable
|
---|
961 | MSWeather msw = mstable_->weather() ;
|
---|
962 |
|
---|
963 | // access to WEATHER subtable
|
---|
964 | Table stw = table_->weather().table() ;
|
---|
965 | uInt nrow = stw.nrow() ;
|
---|
966 |
|
---|
967 | if ( nrow == 0 )
|
---|
968 | return ;
|
---|
969 |
|
---|
970 | msw.addRow( nrow, True ) ;
|
---|
971 | MSWeatherColumns mswCols( msw ) ;
|
---|
972 |
|
---|
973 | // ANTENNA_ID is always 0
|
---|
974 | Vector<Int> antIdArr( nrow, 0 ) ;
|
---|
975 | mswCols.antennaId().putColumn( antIdArr ) ;
|
---|
976 |
|
---|
977 | // fill weather status
|
---|
978 | ROScalarColumn<Float> sharedFloatCol( stw, "TEMPERATURE" ) ;
|
---|
979 | mswCols.temperature().putColumn( sharedFloatCol ) ;
|
---|
980 | sharedFloatCol.attach( stw, "PRESSURE" ) ;
|
---|
981 | mswCols.pressure().putColumn( sharedFloatCol ) ;
|
---|
982 | sharedFloatCol.attach( stw, "HUMIDITY" ) ;
|
---|
983 | mswCols.relHumidity().putColumn( sharedFloatCol ) ;
|
---|
984 | sharedFloatCol.attach( stw, "WINDSPEED" ) ;
|
---|
985 | mswCols.windSpeed().putColumn( sharedFloatCol ) ;
|
---|
986 | sharedFloatCol.attach( stw, "WINDAZ" ) ;
|
---|
987 | mswCols.windDirection().putColumn( sharedFloatCol ) ;
|
---|
988 |
|
---|
989 | // fill TIME and INTERVAL
|
---|
990 | Double midTime ;
|
---|
991 | Double interval ;
|
---|
992 | Vector<Double> intervalArr( nrow, 0.0 ) ;
|
---|
993 | TableIterator iter( table_->table(), "WEATHER_ID" ) ;
|
---|
994 | while( !iter.pastEnd() ) {
|
---|
995 | //Table tab( iter.table() ) ;
|
---|
996 | Table tab = iter.table() ;
|
---|
997 |
|
---|
998 | ROScalarColumn<uInt> widCol( tab, "WEATHER_ID" ) ;
|
---|
999 | uInt wid = widCol( 0 ) ;
|
---|
1000 |
|
---|
1001 | getValidTimeRange( midTime, interval, tab ) ;
|
---|
1002 | mswCols.time().put( wid, midTime ) ;
|
---|
1003 | intervalArr[wid] = interval ;
|
---|
1004 |
|
---|
1005 | iter.next() ;
|
---|
1006 | }
|
---|
1007 | mswCols.interval().putColumn( intervalArr ) ;
|
---|
1008 |
|
---|
1009 | double endSec = gettimeofday_sec() ;
|
---|
1010 | os_ << "end MSWriter::fillWeather() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
1011 | }
|
---|
1012 |
|
---|
1013 | void MSWriter::fillSysCal()
|
---|
1014 | {
|
---|
1015 | double startSec = gettimeofday_sec() ;
|
---|
1016 | os_ << "start MSWriter::fillSysCal() startSec=" << startSec << LogIO::POST ;
|
---|
1017 |
|
---|
1018 | //tcalIdRec_.print( cout ) ;
|
---|
1019 |
|
---|
1020 | // access to MS SYSCAL subtable
|
---|
1021 | MSSysCal mssc = mstable_->sysCal() ;
|
---|
1022 |
|
---|
1023 | // access to TCAL subtable
|
---|
1024 | Table stt = table_->tcal().table() ;
|
---|
1025 | uInt nrow = stt.nrow() ;
|
---|
1026 |
|
---|
1027 | // access to MAIN table
|
---|
1028 | Block<String> cols( 6 ) ;
|
---|
1029 | cols[0] = "TIME" ;
|
---|
1030 | cols[1] = "TCAL_ID" ;
|
---|
1031 | cols[2] = "TSYS" ;
|
---|
1032 | cols[3] = "BEAMNO" ;
|
---|
1033 | cols[4] = "IFNO" ;
|
---|
1034 | cols[5] = "INTERVAL" ;
|
---|
1035 | Table tab = table_->table().project( cols ) ;
|
---|
1036 |
|
---|
1037 | if ( nrow == 0 )
|
---|
1038 | return ;
|
---|
1039 |
|
---|
1040 | nrow = tcalIdRec_.nfields() ;
|
---|
1041 |
|
---|
1042 | Double midTime ;
|
---|
1043 | Double interval ;
|
---|
1044 | String timeStr ;
|
---|
1045 |
|
---|
1046 | // row base
|
---|
1047 | TableRow row( mssc ) ;
|
---|
1048 | TableRecord &trec = row.record() ;
|
---|
1049 | RecordFieldPtr<Int> antennaRF( trec, "ANTENNA_ID" ) ;
|
---|
1050 | RecordFieldPtr<Int> feedRF( trec, "FEED_ID" ) ;
|
---|
1051 | RecordFieldPtr<Int> spwRF( trec, "SPECTRAL_WINDOW_ID" ) ;
|
---|
1052 | RecordFieldPtr<Double> timeRF( trec, "TIME" ) ;
|
---|
1053 | RecordFieldPtr<Double> intervalRF( trec, "INTERVAL" ) ;
|
---|
1054 | RecordFieldPtr< Array<Float> > tsysRF( trec, "TSYS" ) ;
|
---|
1055 | RecordFieldPtr< Array<Float> > tcalRF( trec, "TCAL" ) ;
|
---|
1056 | RecordFieldPtr< Array<Float> > tsysspRF ;
|
---|
1057 | RecordFieldPtr< Array<Float> > tcalspRF ;
|
---|
1058 | if ( tsysSpec_ )
|
---|
1059 | tsysspRF.attachToRecord( trec, "TSYS_SPECTRUM" ) ;
|
---|
1060 | if ( tcalSpec_ )
|
---|
1061 | tcalspRF.attachToRecord( trec, "TCAL_SPECTRUM" ) ;
|
---|
1062 |
|
---|
1063 | // ANTENNA_ID is always 0
|
---|
1064 | *antennaRF = 0 ;
|
---|
1065 |
|
---|
1066 | Table sortedstt = stt.sort( "ID" ) ;
|
---|
1067 | ROArrayColumn<Float> tcalCol( sortedstt, "TCAL" ) ;
|
---|
1068 | ROTableColumn idCol( sortedstt, "ID" ) ;
|
---|
1069 | ROArrayColumn<Float> tsysCol( tab, "TSYS" ) ;
|
---|
1070 | ROTableColumn tcalidCol( tab, "TCAL_ID" ) ;
|
---|
1071 | ROTableColumn timeCol( tab, "TIME" ) ;
|
---|
1072 | ROTableColumn intervalCol( tab, "INTERVAL" ) ;
|
---|
1073 | ROTableColumn beamnoCol( tab, "BEAMNO" ) ;
|
---|
1074 | ROTableColumn ifnoCol( tab, "IFNO" ) ;
|
---|
1075 | for ( uInt irow = 0 ; irow < nrow ; irow++ ) {
|
---|
1076 | double t1 = gettimeofday_sec() ;
|
---|
1077 | Vector<uInt> ids = tcalIdRec_.asArrayuInt( irow ) ;
|
---|
1078 | os_ << "ids = " << ids << LogIO::POST ;
|
---|
1079 | uInt npol = ids.size() ;
|
---|
1080 | Vector<uInt> rows = tcalRowRec_.asArrayuInt( irow ) ;
|
---|
1081 | os_ << "rows = " << rows << LogIO::POST ;
|
---|
1082 | Vector<Double> atime( rows.nelements() ) ;
|
---|
1083 | Vector<Double> ainterval( rows.nelements() ) ;
|
---|
1084 | Vector<uInt> atcalid( rows.nelements() ) ;
|
---|
1085 | for( uInt jrow = 0 ; jrow < rows.nelements() ; jrow++ ) {
|
---|
1086 | atime[jrow] = (Double)timeCol.asdouble( rows[jrow] ) ;
|
---|
1087 | ainterval[jrow] = (Double)intervalCol.asdouble( rows[jrow] ) ;
|
---|
1088 | atcalid[jrow] = tcalidCol.asuInt( rows[jrow] ) ;
|
---|
1089 | }
|
---|
1090 | Vector<Float> dummy = tsysCol( rows[0] ) ;
|
---|
1091 | Matrix<Float> tsys( npol,dummy.nelements() ) ;
|
---|
1092 | tsys.row( 0 ) = dummy ;
|
---|
1093 | for ( uInt jrow = 1 ; jrow < npol ; jrow++ )
|
---|
1094 | tsys.row( jrow ) = tsysCol( rows[jrow] ) ;
|
---|
1095 |
|
---|
1096 | // FEED_ID
|
---|
1097 | *feedRF = beamnoCol.asuInt( rows[0] ) ;
|
---|
1098 |
|
---|
1099 | // SPECTRAL_WINDOW_ID
|
---|
1100 | *spwRF = ifnoCol.asuInt( rows[0] ) ;
|
---|
1101 |
|
---|
1102 | // TIME and INTERVAL
|
---|
1103 | getValidTimeRange( midTime, interval, atime, ainterval ) ;
|
---|
1104 | *timeRF = midTime ;
|
---|
1105 | *intervalRF = interval ;
|
---|
1106 |
|
---|
1107 | // TCAL and TSYS
|
---|
1108 | Matrix<Float> tcal ;
|
---|
1109 | Table t ;
|
---|
1110 | if ( idCol.asuInt( ids[0] ) == ids[0] ) {
|
---|
1111 | os_ << "sorted at irow=" << irow << " ids[0]=" << ids[0] << LogIO::POST ;
|
---|
1112 | Vector<Float> dummyC = tcalCol( ids[0] ) ;
|
---|
1113 | tcal.resize( npol, dummyC.size() ) ;
|
---|
1114 | tcal.row( 0 ) = dummyC ;
|
---|
1115 | }
|
---|
1116 | else {
|
---|
1117 | os_ << "NOT sorted at irow=" << irow << " ids[0]=" << ids[0] << LogIO::POST ;
|
---|
1118 | t = stt( stt.col("ID") == ids[0] ) ;
|
---|
1119 | Vector<Float> dummyC = tcalCol( 0 ) ;
|
---|
1120 | tcal.resize( npol, dummyC.size() ) ;
|
---|
1121 | tcal.row( 0 ) = dummyC ;
|
---|
1122 | }
|
---|
1123 | if ( npol == 2 ) {
|
---|
1124 | if ( idCol.asuInt( ids[1] ) == ids[1] ) {
|
---|
1125 | os_ << "sorted at irow=" << irow << " ids[1]=" << ids[1] << LogIO::POST ;
|
---|
1126 | tcal.row( 1 ) = tcalCol( ids[1] ) ;
|
---|
1127 | }
|
---|
1128 | else {
|
---|
1129 | os_ << "NOT sorted at irow=" << irow << " ids[1]=" << ids[1] << LogIO::POST ;
|
---|
1130 | t = stt( stt.col("ID") == ids[1] ) ;
|
---|
1131 | tcalCol.attach( t, "TCAL" ) ;
|
---|
1132 | tcal.row( 1 ) = tcalCol( 1 ) ;
|
---|
1133 | }
|
---|
1134 | }
|
---|
1135 | else if ( npol == 3 ) {
|
---|
1136 | if ( idCol.asuInt( ids[2] ) == ids[2] )
|
---|
1137 | tcal.row( 1 ) = tcalCol( ids[2] ) ;
|
---|
1138 | else {
|
---|
1139 | t = stt( stt.col("ID") == ids[2] ) ;
|
---|
1140 | tcalCol.attach( t, "TCAL" ) ;
|
---|
1141 | tcal.row( 1 ) = tcalCol( 0 ) ;
|
---|
1142 | }
|
---|
1143 | if ( idCol.asuInt( ids[1] ) == ids[1] )
|
---|
1144 | tcal.row( 2 ) = tcalCol( ids[1] ) ;
|
---|
1145 | else {
|
---|
1146 | t = stt( stt.col("ID") == ids[1] ) ;
|
---|
1147 | tcalCol.attach( t, "TCAL" ) ;
|
---|
1148 | tcal.row( 2 ) = tcalCol( 0 ) ;
|
---|
1149 | }
|
---|
1150 | }
|
---|
1151 | else if ( npol == 4 ) {
|
---|
1152 | if ( idCol.asuInt( ids[2] ) == ids[2] )
|
---|
1153 | tcal.row( 1 ) = tcalCol( ids[2] ) ;
|
---|
1154 | else {
|
---|
1155 | t = stt( stt.col("ID") == ids[2] ) ;
|
---|
1156 | tcalCol.attach( t, "TCAL" ) ;
|
---|
1157 | tcal.row( 1 ) = tcalCol( 0 ) ;
|
---|
1158 | }
|
---|
1159 | if ( idCol.asuInt( ids[3] ) == ids[3] )
|
---|
1160 | tcal.row( 2 ) = tcalCol( ids[3] ) ;
|
---|
1161 | else {
|
---|
1162 | t = stt( stt.col("ID") == ids[3] ) ;
|
---|
1163 | tcalCol.attach( t, "TCAL" ) ;
|
---|
1164 | tcal.row( 2 ) = tcalCol( 0 ) ;
|
---|
1165 | }
|
---|
1166 | if ( idCol.asuInt( ids[1] ) == ids[1] )
|
---|
1167 | tcal.row( 2 ) = tcalCol( ids[1] ) ;
|
---|
1168 | else {
|
---|
1169 | t = stt( stt.col("ID") == ids[1] ) ;
|
---|
1170 | tcalCol.attach( t, "TCAL" ) ;
|
---|
1171 | tcal.row( 3 ) = tcalCol( 0 ) ;
|
---|
1172 | }
|
---|
1173 | }
|
---|
1174 | if ( tcalSpec_ ) {
|
---|
1175 | // put TCAL_SPECTRUM
|
---|
1176 | //*tcalspRF = tcal ;
|
---|
1177 | tcalspRF.define( tcal ) ;
|
---|
1178 | // set TCAL (mean of TCAL_SPECTRUM)
|
---|
1179 | Matrix<Float> tcalMean( npol, 1 ) ;
|
---|
1180 | for ( uInt iid = 0 ; iid < npol ; iid++ ) {
|
---|
1181 | tcalMean( iid, 0 ) = mean( tcal.row(iid) ) ;
|
---|
1182 | }
|
---|
1183 | // put TCAL
|
---|
1184 | *tcalRF = tcalMean ;
|
---|
1185 | }
|
---|
1186 | else {
|
---|
1187 | // put TCAL
|
---|
1188 | *tcalRF = tcal ;
|
---|
1189 | }
|
---|
1190 |
|
---|
1191 | if ( tsysSpec_ ) {
|
---|
1192 | // put TSYS_SPECTRUM
|
---|
1193 | //*tsysspRF = tsys ;
|
---|
1194 | tsysspRF.define( tsys ) ;
|
---|
1195 | // set TSYS (mean of TSYS_SPECTRUM)
|
---|
1196 | Matrix<Float> tsysMean( npol, 1 ) ;
|
---|
1197 | for ( uInt iid = 0 ; iid < npol ; iid++ ) {
|
---|
1198 | tsysMean( iid, 0 ) = mean( tsys.row(iid) ) ;
|
---|
1199 | }
|
---|
1200 | // put TSYS
|
---|
1201 | *tsysRF = tsysMean ;
|
---|
1202 | }
|
---|
1203 | else {
|
---|
1204 | // put TSYS
|
---|
1205 | *tsysRF = tsys ;
|
---|
1206 | }
|
---|
1207 |
|
---|
1208 | // add row
|
---|
1209 | mssc.addRow( 1, True ) ;
|
---|
1210 | row.put( mssc.nrow()-1 ) ;
|
---|
1211 |
|
---|
1212 | double t2 = gettimeofday_sec() ;
|
---|
1213 | os_ << irow << "th loop elapsed time = " << t2-t1 << "sec" << LogIO::POST ;
|
---|
1214 | }
|
---|
1215 |
|
---|
1216 | double endSec = gettimeofday_sec() ;
|
---|
1217 | os_ << "end MSWriter::fillSysCal() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
1218 | }
|
---|
1219 |
|
---|
1220 | void MSWriter::addFeed( Int id )
|
---|
1221 | {
|
---|
1222 | double startSec = gettimeofday_sec() ;
|
---|
1223 | os_ << "start MSWriter::addFeed() startSec=" << startSec << LogIO::POST ;
|
---|
1224 |
|
---|
1225 | // add row
|
---|
1226 | MSFeed msFeed = mstable_->feed() ;
|
---|
1227 | msFeed.addRow( 1, True ) ;
|
---|
1228 | Int nrow = msFeed.nrow() ;
|
---|
1229 | Int numReceptors = 2 ;
|
---|
1230 | Vector<String> polType( numReceptors ) ;
|
---|
1231 | Matrix<Double> beamOffset( 2, numReceptors ) ;
|
---|
1232 | beamOffset = 0.0 ;
|
---|
1233 | Vector<Double> receptorAngle( numReceptors, 0.0 ) ;
|
---|
1234 | if ( polType_ == "linear" ) {
|
---|
1235 | polType[0] = "X" ;
|
---|
1236 | polType[1] = "Y" ;
|
---|
1237 | }
|
---|
1238 | else if ( polType_ == "circular" ) {
|
---|
1239 | polType[0] = "R" ;
|
---|
1240 | polType[1] = "L" ;
|
---|
1241 | }
|
---|
1242 | else {
|
---|
1243 | polType[0] = "X" ;
|
---|
1244 | polType[1] = "Y" ;
|
---|
1245 | }
|
---|
1246 | Matrix<Complex> polResponse( numReceptors, numReceptors, 0.0 ) ;
|
---|
1247 | for ( Int i = 0 ; i < numReceptors ; i++ )
|
---|
1248 | polResponse( i, i ) = 0.0 ;
|
---|
1249 |
|
---|
1250 | MSFeedColumns msFeedCols( mstable_->feed() ) ;
|
---|
1251 |
|
---|
1252 | msFeedCols.feedId().put( nrow-1, id ) ;
|
---|
1253 | msFeedCols.antennaId().put( nrow-1, 0 ) ;
|
---|
1254 | msFeedCols.numReceptors().put( nrow-1, numReceptors ) ;
|
---|
1255 | msFeedCols.polarizationType().put( nrow-1, polType ) ;
|
---|
1256 | msFeedCols.beamOffset().put( nrow-1, beamOffset ) ;
|
---|
1257 | msFeedCols.receptorAngle().put( nrow-1, receptorAngle ) ;
|
---|
1258 | msFeedCols.polResponse().put( nrow-1, polResponse ) ;
|
---|
1259 |
|
---|
1260 | double endSec = gettimeofday_sec() ;
|
---|
1261 | os_ << "end MSWriter::addFeed() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
1262 | }
|
---|
1263 |
|
---|
1264 | void MSWriter::addSpectralWindow( Int spwid, Int freqid )
|
---|
1265 | {
|
---|
1266 | double startSec = gettimeofday_sec() ;
|
---|
1267 | os_ << "start MSWriter::addSpectralWindow() startSec=" << startSec << LogIO::POST ;
|
---|
1268 |
|
---|
1269 | // add row
|
---|
1270 | MSSpectralWindow msSpw = mstable_->spectralWindow() ;
|
---|
1271 | while( (Int)msSpw.nrow() <= spwid ) {
|
---|
1272 | msSpw.addRow( 1, True ) ;
|
---|
1273 | }
|
---|
1274 |
|
---|
1275 | MSSpWindowColumns msSpwCols( msSpw ) ;
|
---|
1276 |
|
---|
1277 | STFrequencies stf = table_->frequencies() ;
|
---|
1278 |
|
---|
1279 | // MEAS_FREQ_REF
|
---|
1280 | msSpwCols.measFreqRef().put( spwid, stf.getFrame( True ) ) ;
|
---|
1281 |
|
---|
1282 | Double refpix ;
|
---|
1283 | Double refval ;
|
---|
1284 | Double inc ;
|
---|
1285 | stf.getEntry( refpix, refval, inc, (uInt)freqid ) ;
|
---|
1286 |
|
---|
1287 | // NUM_CHAN
|
---|
1288 | Int nchan = (Int)(refpix * 2) ;
|
---|
1289 | msSpwCols.numChan().put( spwid, nchan ) ;
|
---|
1290 |
|
---|
1291 | // TOTAL_BANDWIDTH
|
---|
1292 | Double bw = nchan * inc ;
|
---|
1293 | msSpwCols.totalBandwidth().put( spwid, bw ) ;
|
---|
1294 |
|
---|
1295 | // REF_FREQUENCY
|
---|
1296 | Double refFreq = refval - refpix * inc ;
|
---|
1297 | msSpwCols.refFrequency().put( spwid, refFreq ) ;
|
---|
1298 |
|
---|
1299 | // NET_SIDEBAND
|
---|
1300 | // tentative: USB->0, LSB->1
|
---|
1301 | Int netSideband = 0 ;
|
---|
1302 | if ( inc < 0 )
|
---|
1303 | netSideband = 1 ;
|
---|
1304 | msSpwCols.netSideband().put( spwid, netSideband ) ;
|
---|
1305 |
|
---|
1306 | // RESOLUTION, CHAN_WIDTH, EFFECTIVE_BW
|
---|
1307 | Vector<Double> sharedDoubleArr( nchan, inc ) ;
|
---|
1308 | msSpwCols.resolution().put( spwid, sharedDoubleArr ) ;
|
---|
1309 | msSpwCols.chanWidth().put( spwid, sharedDoubleArr ) ;
|
---|
1310 | msSpwCols.effectiveBW().put( spwid, sharedDoubleArr ) ;
|
---|
1311 |
|
---|
1312 | // CHAN_FREQ
|
---|
1313 | indgen( sharedDoubleArr, refFreq, inc ) ;
|
---|
1314 | msSpwCols.chanFreq().put( spwid, sharedDoubleArr ) ;
|
---|
1315 |
|
---|
1316 | double endSec = gettimeofday_sec() ;
|
---|
1317 | os_ << "end MSWriter::addSpectralWindow() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
1318 | }
|
---|
1319 |
|
---|
1320 | void MSWriter::addField( Int fid, String fieldname, String srcname, Double t, Vector<Double> rate )
|
---|
1321 | {
|
---|
1322 | double startSec = gettimeofday_sec() ;
|
---|
1323 | os_ << "start MSWriter::addField() startSec=" << startSec << LogIO::POST ;
|
---|
1324 |
|
---|
1325 | MSField msField = mstable_->field() ;
|
---|
1326 | while( (Int)msField.nrow() <= fid ) {
|
---|
1327 | msField.addRow( 1, True ) ;
|
---|
1328 | }
|
---|
1329 | MSFieldColumns msFieldCols( msField ) ;
|
---|
1330 |
|
---|
1331 | // Access to SOURCE table
|
---|
1332 | MSSource msSrc = mstable_->source() ;
|
---|
1333 |
|
---|
1334 | // fill target row
|
---|
1335 | msFieldCols.name().put( fid, fieldname ) ;
|
---|
1336 | msFieldCols.time().put( fid, t ) ;
|
---|
1337 | Int numPoly = 0 ;
|
---|
1338 | if ( anyNE( rate, 0.0 ) )
|
---|
1339 | numPoly = 1 ;
|
---|
1340 | msFieldCols.numPoly().put( fid, numPoly ) ;
|
---|
1341 | MSSourceIndex msSrcIdx( msSrc ) ;
|
---|
1342 | Int srcId = -1 ;
|
---|
1343 | Vector<Int> srcIdArr = msSrcIdx.matchSourceName( srcname ) ;
|
---|
1344 | if ( srcIdArr.size() != 0 ) {
|
---|
1345 | srcId = srcIdArr[0] ;
|
---|
1346 | MSSource msSrcSel = msSrc( msSrc.col("SOURCE_ID") == srcId ) ;
|
---|
1347 | ROMSSourceColumns msSrcCols( msSrcSel ) ;
|
---|
1348 | Vector<Double> srcDir = msSrcCols.direction()( 0 ) ;
|
---|
1349 | Matrix<Double> srcDirA( IPosition( 2, 2, 1+numPoly ) ) ;
|
---|
1350 | os_ << "srcDirA = " << srcDirA << LogIO::POST ;
|
---|
1351 | os_ << "sliced srcDirA = " << srcDirA.column( 0 ) << LogIO::POST ;
|
---|
1352 | srcDirA.column( 0 ) = srcDir ;
|
---|
1353 | os_ << "srcDirA = " << srcDirA << LogIO::POST ;
|
---|
1354 | if ( numPoly != 0 )
|
---|
1355 | srcDirA.column( 1 ) = rate ;
|
---|
1356 | msFieldCols.phaseDir().put( fid, srcDirA ) ;
|
---|
1357 | msFieldCols.referenceDir().put( fid, srcDirA ) ;
|
---|
1358 | msFieldCols.delayDir().put( fid, srcDirA ) ;
|
---|
1359 | }
|
---|
1360 | msFieldCols.sourceId().put( fid, srcId ) ;
|
---|
1361 |
|
---|
1362 | double endSec = gettimeofday_sec() ;
|
---|
1363 | os_ << "end MSWriter::addField() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
1364 | }
|
---|
1365 |
|
---|
1366 | void MSWriter::addPointing( String &name, Double &me, Double &interval, Matrix<Double> &dir )
|
---|
1367 | {
|
---|
1368 | double startSec = gettimeofday_sec() ;
|
---|
1369 | os_ << "start MSWriter::addPointing() startSec=" << startSec << LogIO::POST ;
|
---|
1370 |
|
---|
1371 | // access to POINTING subtable
|
---|
1372 | MSPointing msp = mstable_->pointing() ;
|
---|
1373 | uInt nrow = msp.nrow() ;
|
---|
1374 |
|
---|
1375 | // add row
|
---|
1376 | msp.addRow( 1, True ) ;
|
---|
1377 |
|
---|
1378 | // fill row
|
---|
1379 | TableRow row( msp ) ;
|
---|
1380 | TableRecord &rec = row.record() ;
|
---|
1381 | RecordFieldPtr<Int> antennaRF( rec, "ANTENNA_ID" ) ;
|
---|
1382 | *antennaRF = 0 ;
|
---|
1383 | RecordFieldPtr<Int> numpolyRF( rec, "NUM_POLY" ) ;
|
---|
1384 | *numpolyRF = dir.ncolumn() ;
|
---|
1385 | RecordFieldPtr<Double> timeRF( rec, "TIME" ) ;
|
---|
1386 | *timeRF = me ;
|
---|
1387 | RecordFieldPtr<Double> toriginRF( rec, "TIME_ORIGIN" ) ;
|
---|
1388 | *toriginRF = me ;
|
---|
1389 | RecordFieldPtr<Double> intervalRF( rec, "INTERVAL" ) ;
|
---|
1390 | *intervalRF = interval ;
|
---|
1391 | RecordFieldPtr<String> nameRF( rec, "NAME" ) ;
|
---|
1392 | *nameRF = name ;
|
---|
1393 | RecordFieldPtr<Bool> trackRF( rec, "TRACKING" ) ;
|
---|
1394 | *trackRF = True ;
|
---|
1395 | RecordFieldPtr< Array<Double> > dirRF( rec, "DIRECTION" ) ;
|
---|
1396 | *dirRF = dir ;
|
---|
1397 | RecordFieldPtr< Array<Double> > targetRF( rec, "TARGET" ) ;
|
---|
1398 | *dirRF = dir ;
|
---|
1399 | row.put( nrow ) ;
|
---|
1400 |
|
---|
1401 | double endSec = gettimeofday_sec() ;
|
---|
1402 | os_ << "end MSWriter::addPointing() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
1403 | }
|
---|
1404 |
|
---|
1405 | Int MSWriter::addPolarization( Vector<Int> polnos )
|
---|
1406 | {
|
---|
1407 | double startSec = gettimeofday_sec() ;
|
---|
1408 | os_ << "start MSWriter::addPolarization() startSec=" << startSec << LogIO::POST ;
|
---|
1409 |
|
---|
1410 | os_ << "polnos = " << polnos << LogIO::POST ;
|
---|
1411 | MSPolarization msPol = mstable_->polarization() ;
|
---|
1412 | uInt nrow = msPol.nrow() ;
|
---|
1413 |
|
---|
1414 | // only 1 POLARIZATION row for 1 scantable
|
---|
1415 | if ( nrow > 0 )
|
---|
1416 | return 0 ;
|
---|
1417 |
|
---|
1418 | Vector<Int> corrType = toCorrType( polnos ) ;
|
---|
1419 |
|
---|
1420 | ROArrayColumn<Int> corrtCol( msPol, "CORR_TYPE" ) ;
|
---|
1421 | Matrix<Int> corrTypeArr = corrtCol.getColumn() ;
|
---|
1422 | Int polid = -1 ;
|
---|
1423 | for ( uInt irow = 0 ; irow < nrow ; irow++ ) {
|
---|
1424 | if ( allEQ( corrType, corrTypeArr.column( irow ) ) ) {
|
---|
1425 | polid = irow ;
|
---|
1426 | break ;
|
---|
1427 | }
|
---|
1428 | }
|
---|
1429 |
|
---|
1430 | if ( polid == -1 ) {
|
---|
1431 | MSPolarizationColumns msPolCols( msPol ) ;
|
---|
1432 |
|
---|
1433 | // add row
|
---|
1434 | msPol.addRow( 1, True ) ;
|
---|
1435 | polid = (Int)nrow ;
|
---|
1436 |
|
---|
1437 | // CORR_TYPE
|
---|
1438 | msPolCols.corrType().put( nrow, corrType ) ;
|
---|
1439 |
|
---|
1440 | // NUM_CORR
|
---|
1441 | uInt npol = corrType.size() ;
|
---|
1442 | msPolCols.numCorr().put( nrow, npol ) ;
|
---|
1443 |
|
---|
1444 | // CORR_PRODUCT
|
---|
1445 | Matrix<Int> corrProd( 2, npol, -1 ) ;
|
---|
1446 | if ( npol == 1 ) {
|
---|
1447 | corrProd = 0 ;
|
---|
1448 | }
|
---|
1449 | else if ( npol == 2 ) {
|
---|
1450 | corrProd.column( 0 ) = 0 ;
|
---|
1451 | corrProd.column( 1 ) = 1 ;
|
---|
1452 | }
|
---|
1453 | else {
|
---|
1454 | corrProd.column( 0 ) = 0 ;
|
---|
1455 | corrProd.column( 3 ) = 1 ;
|
---|
1456 | corrProd( 0,1 ) = 0 ;
|
---|
1457 | corrProd( 1,1 ) = 1 ;
|
---|
1458 | corrProd( 0,2 ) = 1 ;
|
---|
1459 | corrProd( 1,2 ) = 0 ;
|
---|
1460 | }
|
---|
1461 | msPolCols.corrProduct().put( nrow, corrProd ) ;
|
---|
1462 | }
|
---|
1463 |
|
---|
1464 | double endSec = gettimeofday_sec() ;
|
---|
1465 | os_ << "end MSWriter::addPolarization() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
1466 |
|
---|
1467 | return polid ;
|
---|
1468 | }
|
---|
1469 |
|
---|
1470 | Int MSWriter::addDataDescription( Int polid, Int spwid )
|
---|
1471 | {
|
---|
1472 | double startSec = gettimeofday_sec() ;
|
---|
1473 | os_ << "start MSWriter::addDataDescription() startSec=" << startSec << LogIO::POST ;
|
---|
1474 |
|
---|
1475 | MSDataDescription msDataDesc = mstable_->dataDescription() ;
|
---|
1476 | uInt nrow = msDataDesc.nrow() ;
|
---|
1477 |
|
---|
1478 | // only 1 POLARIZATION_ID for 1 scantable
|
---|
1479 | Int ddid = -1 ;
|
---|
1480 | ROScalarColumn<Int> spwCol( msDataDesc, "SPECTRAL_WINDOW_ID" ) ;
|
---|
1481 | Vector<Int> spwIds = spwCol.getColumn() ;
|
---|
1482 | //ROScalarColumn<Int> polCol( msDataDesc, "POLARIZATION_ID" ) ;
|
---|
1483 | //Vector<Int> polIds = polCol.getColumn() ;
|
---|
1484 | for ( uInt irow = 0 ; irow < nrow ; irow++ ) {
|
---|
1485 | //if ( spwid == spwIds[irow] && polid == polIds[irow] ) {
|
---|
1486 | if ( spwid == spwIds[irow] ) {
|
---|
1487 | ddid = irow ;
|
---|
1488 | break ;
|
---|
1489 | }
|
---|
1490 | }
|
---|
1491 | os_ << "ddid = " << ddid << LogIO::POST ;
|
---|
1492 |
|
---|
1493 |
|
---|
1494 | if ( ddid == -1 ) {
|
---|
1495 | msDataDesc.addRow( 1, True ) ;
|
---|
1496 | MSDataDescColumns msDataDescCols( msDataDesc ) ;
|
---|
1497 | msDataDescCols.polarizationId().put( nrow, polid ) ;
|
---|
1498 | msDataDescCols.spectralWindowId().put( nrow, spwid ) ;
|
---|
1499 | ddid = (Int)nrow ;
|
---|
1500 | }
|
---|
1501 |
|
---|
1502 | double endSec = gettimeofday_sec() ;
|
---|
1503 | os_ << "end MSWriter::addDataDescription() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
1504 |
|
---|
1505 | return ddid ;
|
---|
1506 | }
|
---|
1507 |
|
---|
1508 | Int MSWriter::addState( Int st, Int &subscan )
|
---|
1509 | {
|
---|
1510 | double startSec = gettimeofday_sec() ;
|
---|
1511 | os_ << "start MSWriter::addState() startSec=" << startSec << LogIO::POST ;
|
---|
1512 |
|
---|
1513 | // access to STATE subtable
|
---|
1514 | MSState msState = mstable_->state() ;
|
---|
1515 | uInt nrow = msState.nrow() ;
|
---|
1516 |
|
---|
1517 | String obsMode ;
|
---|
1518 | Bool isSignal ;
|
---|
1519 | Double tnoise ;
|
---|
1520 | Double tload ;
|
---|
1521 | queryType( st, obsMode, isSignal, tnoise, tload ) ;
|
---|
1522 | os_ << "obsMode = " << obsMode << " isSignal = " << isSignal << LogIO::POST ;
|
---|
1523 |
|
---|
1524 | Int idx = -1 ;
|
---|
1525 | ROScalarColumn<String> obsModeCol( msState, "OBS_MODE" ) ;
|
---|
1526 | //ROScalarColumn<Bool> sigCol( msState, "SIG" ) ;
|
---|
1527 | //ROScalarColumn<Bool> refCol( msState, "REF" ) ;
|
---|
1528 | ROScalarColumn<Int> subscanCol( msState, "SUB_SCAN" ) ;
|
---|
1529 | // Vector<String> obsModeArr = obsModeCol.getColumn() ;
|
---|
1530 | // Vector<Bool> sigArr = sigCol.getColumn() ;
|
---|
1531 | // Vector<Bool> refArr = refCol.getColumn() ;
|
---|
1532 | // Vector<Int> subscanArr = subscanCol.getColumn() ;
|
---|
1533 | for ( uInt irow = 0 ; irow < nrow ; irow++ ) {
|
---|
1534 | if ( obsModeCol(irow) == obsMode
|
---|
1535 | //&& sigCol(irow) == isSignal
|
---|
1536 | //&& refCol(irow) != isSignal
|
---|
1537 | && subscanCol(irow) == subscan ) {
|
---|
1538 | // if ( obsModeArr[irow] == obsMode
|
---|
1539 | // && sigArr[irow] == isSignal
|
---|
1540 | // && refArr[irow] != isSignal
|
---|
1541 | // && subscanArr[irow] == subscan ) {
|
---|
1542 | idx = irow ;
|
---|
1543 | break ;
|
---|
1544 | }
|
---|
1545 | }
|
---|
1546 | if ( idx == -1 ) {
|
---|
1547 | msState.addRow( 1, True ) ;
|
---|
1548 | TableRow row( msState ) ;
|
---|
1549 | TableRecord &rec = row.record() ;
|
---|
1550 | RecordFieldPtr<String> obsmodeRF( rec, "OBS_MODE" ) ;
|
---|
1551 | *obsmodeRF = obsMode ;
|
---|
1552 | RecordFieldPtr<Bool> sigRF( rec, "SIG" ) ;
|
---|
1553 | *sigRF = isSignal ;
|
---|
1554 | RecordFieldPtr<Bool> refRF( rec, "REF" ) ;
|
---|
1555 | *refRF = !isSignal ;
|
---|
1556 | RecordFieldPtr<Int> subscanRF( rec, "SUB_SCAN" ) ;
|
---|
1557 | *subscanRF = subscan ;
|
---|
1558 | RecordFieldPtr<Double> noiseRF( rec, "CAL" ) ;
|
---|
1559 | *noiseRF = tnoise ;
|
---|
1560 | RecordFieldPtr<Double> loadRF( rec, "LOAD" ) ;
|
---|
1561 | *loadRF = tload ;
|
---|
1562 | row.put( nrow ) ;
|
---|
1563 | // ScalarColumn<String> obsModeCol( msState, "OBS_MODE" ) ;
|
---|
1564 | // obsModeCol.put( nrow, obsMode ) ;
|
---|
1565 | // ScalarColumn<Bool> sharedBCol( msState, "SIG" ) ;
|
---|
1566 | // sharedBCol.put( nrow, isSignal ) ;
|
---|
1567 | // sharedBCol.attach( msState, "REF" ) ;
|
---|
1568 | // sharedBCol.put( nrow, !isSignal ) ;
|
---|
1569 | // ScalarColumn<Int> subscanCol( msState, "SUB_SCAN" ) ;
|
---|
1570 | // subscanCol.put( nrow, subscan ) ;
|
---|
1571 | idx = nrow ;
|
---|
1572 | }
|
---|
1573 | subscan++ ;
|
---|
1574 |
|
---|
1575 | double endSec = gettimeofday_sec() ;
|
---|
1576 | os_ << "end MSWriter::addState() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
1577 |
|
---|
1578 | return idx ;
|
---|
1579 | }
|
---|
1580 |
|
---|
1581 | Vector<Int> MSWriter::toCorrType( Vector<Int> polnos )
|
---|
1582 | {
|
---|
1583 | double startSec = gettimeofday_sec() ;
|
---|
1584 | os_ << "start MSWriter::toCorrType() startSec=" << startSec << LogIO::POST ;
|
---|
1585 |
|
---|
1586 | uInt npol = polnos.size() ;
|
---|
1587 | Vector<Int> corrType( npol, Stokes::Undefined ) ;
|
---|
1588 |
|
---|
1589 | if ( npol == 4 ) {
|
---|
1590 | if ( polType_ == "linear" ) {
|
---|
1591 | for ( uInt ipol = 0 ; ipol < npol ; ipol++ ) {
|
---|
1592 | if ( polnos[ipol] == 0 )
|
---|
1593 | corrType[ipol] = Stokes::XX ;
|
---|
1594 | else if ( polnos[ipol] == 1 )
|
---|
1595 | corrType[ipol] = Stokes::XY ;
|
---|
1596 | else if ( polnos[ipol] == 2 )
|
---|
1597 | corrType[ipol] = Stokes::YX ;
|
---|
1598 | else if ( polnos[ipol] == 3 )
|
---|
1599 | corrType[ipol] = Stokes::YY ;
|
---|
1600 | }
|
---|
1601 | }
|
---|
1602 | else if ( polType_ == "circular" ) {
|
---|
1603 | for ( uInt ipol = 0 ; ipol < npol ; ipol++ ) {
|
---|
1604 | if ( polnos[ipol] == 0 )
|
---|
1605 | corrType[ipol] = Stokes::RR ;
|
---|
1606 | else if ( polnos[ipol] == 1 )
|
---|
1607 | corrType[ipol] = Stokes::RL ;
|
---|
1608 | else if ( polnos[ipol] == 2 )
|
---|
1609 | corrType[ipol] = Stokes::LR ;
|
---|
1610 | else if ( polnos[ipol] == 3 )
|
---|
1611 | corrType[ipol] = Stokes::LL ;
|
---|
1612 | }
|
---|
1613 | }
|
---|
1614 | else if ( polType_ == "stokes" ) {
|
---|
1615 | for ( uInt ipol = 0 ; ipol < npol ; ipol++ ) {
|
---|
1616 | if ( polnos[ipol] == 0 )
|
---|
1617 | corrType[ipol] = Stokes::I ;
|
---|
1618 | else if ( polnos[ipol] == 1 )
|
---|
1619 | corrType[ipol] = Stokes::Q ;
|
---|
1620 | else if ( polnos[ipol] == 2 )
|
---|
1621 | corrType[ipol] = Stokes::U ;
|
---|
1622 | else if ( polnos[ipol] == 3 )
|
---|
1623 | corrType[ipol] = Stokes::V ;
|
---|
1624 | }
|
---|
1625 | }
|
---|
1626 | }
|
---|
1627 | else if ( npol == 2 ) {
|
---|
1628 | if ( polType_ == "linear" ) {
|
---|
1629 | for ( uInt ipol = 0 ; ipol < npol ; ipol++ ) {
|
---|
1630 | if ( polnos[ipol] == 0 )
|
---|
1631 | corrType[ipol] = Stokes::XX ;
|
---|
1632 | else if ( polnos[ipol] == 1 )
|
---|
1633 | corrType[ipol] = Stokes::YY ;
|
---|
1634 | }
|
---|
1635 | }
|
---|
1636 | else if ( polType_ == "circular" ) {
|
---|
1637 | for ( uInt ipol = 0 ; ipol < npol ; ipol++ ) {
|
---|
1638 | if ( polnos[ipol] == 0 )
|
---|
1639 | corrType[ipol] = Stokes::RR ;
|
---|
1640 | else if ( polnos[ipol] == 1 )
|
---|
1641 | corrType[ipol] = Stokes::LL ;
|
---|
1642 | }
|
---|
1643 | }
|
---|
1644 | else if ( polType_ == "stokes" ) {
|
---|
1645 | for ( uInt ipol = 0 ; ipol < npol ; ipol++ ) {
|
---|
1646 | if ( polnos[ipol] == 0 )
|
---|
1647 | corrType[ipol] = Stokes::I ;
|
---|
1648 | else if ( polnos[ipol] == 1 )
|
---|
1649 | corrType[ipol] = Stokes::V ;
|
---|
1650 | }
|
---|
1651 | }
|
---|
1652 | else if ( polType_ == "linpol" ) {
|
---|
1653 | for ( uInt ipol = 0 ; ipol < npol ; ipol++ ) {
|
---|
1654 | if ( polnos[ipol] == 1 )
|
---|
1655 | corrType[ipol] = Stokes::Plinear ;
|
---|
1656 | else if ( polnos[ipol] == 2 )
|
---|
1657 | corrType[ipol] = Stokes::Pangle ;
|
---|
1658 | }
|
---|
1659 | }
|
---|
1660 | }
|
---|
1661 | else if ( npol == 1 ) {
|
---|
1662 | if ( polType_ == "linear" )
|
---|
1663 | corrType[0] = Stokes::XX ;
|
---|
1664 | else if ( polType_ == "circular" )
|
---|
1665 | corrType[0] = Stokes::RR ;
|
---|
1666 | else if ( polType_ == "stokes" )
|
---|
1667 | corrType[0] = Stokes::I ;
|
---|
1668 | }
|
---|
1669 |
|
---|
1670 | double endSec = gettimeofday_sec() ;
|
---|
1671 | os_ << "end MSWriter::toCorrType() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
1672 |
|
---|
1673 | return corrType ;
|
---|
1674 | }
|
---|
1675 |
|
---|
1676 | void MSWriter::getValidTimeRange( Double &me, Double &interval, Table &tab )
|
---|
1677 | {
|
---|
1678 | double startSec = gettimeofday_sec() ;
|
---|
1679 | os_ << "start MSWriter::getVaridTimeRange() startSec=" << startSec << LogIO::POST ;
|
---|
1680 |
|
---|
1681 | // sort table
|
---|
1682 | //Table stab = tab.sort( "TIME" ) ;
|
---|
1683 |
|
---|
1684 | ROScalarColumn<Double> timeCol( tab, "TIME" ) ;
|
---|
1685 | Vector<Double> timeArr = timeCol.getColumn() ;
|
---|
1686 | Double minTime ;
|
---|
1687 | Double maxTime ;
|
---|
1688 | minMax( minTime, maxTime, timeArr ) ;
|
---|
1689 | Double midTime = 0.5 * ( minTime + maxTime ) * 86400.0 ;
|
---|
1690 | // unit for TIME
|
---|
1691 | // Scantable: "d"
|
---|
1692 | // MS: "s"
|
---|
1693 | me = midTime ;
|
---|
1694 | interval = ( maxTime - minTime ) * 86400.0 ;
|
---|
1695 |
|
---|
1696 | double endSec = gettimeofday_sec() ;
|
---|
1697 | os_ << "end MSWriter::getValidTimeRange() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
1698 | }
|
---|
1699 |
|
---|
1700 | void MSWriter::getValidTimeRange( Double &me, Double &interval, Vector<Double> &atime, Vector<Double> &ainterval )
|
---|
1701 | {
|
---|
1702 | double startSec = gettimeofday_sec() ;
|
---|
1703 | os_ << "start MSWriter::getVaridTimeRange() startSec=" << startSec << LogIO::POST ;
|
---|
1704 |
|
---|
1705 | // sort table
|
---|
1706 | //Table stab = tab.sort( "TIME" ) ;
|
---|
1707 |
|
---|
1708 | Double minTime ;
|
---|
1709 | Double maxTime ;
|
---|
1710 | minMax( minTime, maxTime, atime ) ;
|
---|
1711 | Double midTime = 0.5 * ( minTime + maxTime ) * 86400.0 ;
|
---|
1712 | // unit for TIME
|
---|
1713 | // Scantable: "d"
|
---|
1714 | // MS: "s"
|
---|
1715 | me = midTime ;
|
---|
1716 | interval = ( maxTime - minTime ) * 86400.0 + mean( ainterval ) ;
|
---|
1717 |
|
---|
1718 | double endSec = gettimeofday_sec() ;
|
---|
1719 | os_ << "end MSWriter::getValidTimeRange() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
1720 | }
|
---|
1721 |
|
---|
1722 | //void MSWriter::queryType( Int type, String &stype, Bool &b )
|
---|
1723 | void MSWriter::queryType( Int type, String &stype, Bool &b, Double &t, Double &l )
|
---|
1724 | {
|
---|
1725 | double startSec = gettimeofday_sec() ;
|
---|
1726 | os_ << "start MSWriter::queryType() startSec=" << startSec << LogIO::POST ;
|
---|
1727 |
|
---|
1728 | switch ( type ) {
|
---|
1729 | case SrcType::PSON:
|
---|
1730 | stype = "POSITION_SWITCH.OBSERVE_TARGET.ON_SOURCE" ;
|
---|
1731 | b = True ;
|
---|
1732 | t = 0.0 ;
|
---|
1733 | l = 0.0 ;
|
---|
1734 | break ;
|
---|
1735 | case SrcType::PSOFF:
|
---|
1736 | stype = "POSITION_SWITCH.OBSERVE_TARGET.OFF_SOURCE" ;
|
---|
1737 | b = False ;
|
---|
1738 | t = 0.0 ;
|
---|
1739 | l = 0.0 ;
|
---|
1740 | break ;
|
---|
1741 | case SrcType::NOD:
|
---|
1742 | stype = "NOD.OBSERVE_TARGET.ON_SOURCE" ;
|
---|
1743 | b = True ;
|
---|
1744 | t = 0.0 ;
|
---|
1745 | l = 0.0 ;
|
---|
1746 | break ;
|
---|
1747 | case SrcType::FSON:
|
---|
1748 | stype = "FREQUENCY_SWITCH.OBSERVE_TARGET.ON_SOURCE" ;
|
---|
1749 | b = True ;
|
---|
1750 | t = 0.0 ;
|
---|
1751 | l = 0.0 ;
|
---|
1752 | break ;
|
---|
1753 | case SrcType::FSOFF:
|
---|
1754 | stype = "FREQUENCY_SWITCH.OBSERVE_TARGET.ON_SOURCE" ;
|
---|
1755 | b = False ;
|
---|
1756 | t = 0.0 ;
|
---|
1757 | l = 0.0 ;
|
---|
1758 | break ;
|
---|
1759 | case SrcType::SKY:
|
---|
1760 | stype = "UNSPECIFIED.CALIBRATE_TEMPERATURE.OFF_SOURCE" ;
|
---|
1761 | b = False ;
|
---|
1762 | t = 0.0 ;
|
---|
1763 | l = 1.0 ;
|
---|
1764 | break ;
|
---|
1765 | case SrcType::HOT:
|
---|
1766 | stype = "UNSPECIFIED.CALIBRATE_TEMPERATURE.OFF_SOURCE" ;
|
---|
1767 | b = False ;
|
---|
1768 | t = 0.0 ;
|
---|
1769 | l = 1.0 ;
|
---|
1770 | break ;
|
---|
1771 | case SrcType::WARM:
|
---|
1772 | stype = "UNSPECIFIED.CALIBRATE_TEMPERATURE.OFF_SOURCE" ;
|
---|
1773 | t = 0.0 ;
|
---|
1774 | b = False ;
|
---|
1775 | l = 1.0 ;
|
---|
1776 | break ;
|
---|
1777 | case SrcType::COLD:
|
---|
1778 | stype = "UNSPECIFIED.CALIBRATE_TEMPERATURE.OFF_SOURCE" ;
|
---|
1779 | b = False ;
|
---|
1780 | t = 0.0 ;
|
---|
1781 | l = 1.0 ;
|
---|
1782 | break ;
|
---|
1783 | case SrcType::PONCAL:
|
---|
1784 | stype = "POSITION_SWITCH.CALIBRATE_TEMPERATURE.ON_SOURCE" ;
|
---|
1785 | b = True ;
|
---|
1786 | t = 1.0 ;
|
---|
1787 | l = 0.0 ;
|
---|
1788 | break ;
|
---|
1789 | case SrcType::POFFCAL:
|
---|
1790 | stype = "POSITION_SWITCH.CALIBRATE_TEMPERATURE.OFF_SOURCE" ;
|
---|
1791 | b = False ;
|
---|
1792 | t = 1.0 ;
|
---|
1793 | l = 0.0 ;
|
---|
1794 | break ;
|
---|
1795 | case SrcType::NODCAL:
|
---|
1796 | stype = "NOD.CALIBRATE_TEMPERATURE.ON_SOURCE" ;
|
---|
1797 | b = True ;
|
---|
1798 | t = 1.0 ;
|
---|
1799 | l = 0.0 ;
|
---|
1800 | break ;
|
---|
1801 | case SrcType::FONCAL:
|
---|
1802 | stype = "FREQUENCY_SWITCH.CALIBRATE_TEMPERATURE.ON_SOURCE" ;
|
---|
1803 | b = True ;
|
---|
1804 | t = 1.0 ;
|
---|
1805 | l = 0.0 ;
|
---|
1806 | break ;
|
---|
1807 | case SrcType::FOFFCAL:
|
---|
1808 | stype = "FREQUENCY_SWITCH.CALIBRATE_TEMPERATURE.OFF_SOURCE" ;
|
---|
1809 | b = False ;
|
---|
1810 | t = 1.0 ;
|
---|
1811 | l = 0.0 ;
|
---|
1812 | break ;
|
---|
1813 | case SrcType::FSLO:
|
---|
1814 | stype = "FREQUENCY_SWITCH.OBSERVE_TARGET.ON_SOURCE" ;
|
---|
1815 | b = True ;
|
---|
1816 | t = 0.0 ;
|
---|
1817 | l = 0.0 ;
|
---|
1818 | break ;
|
---|
1819 | case SrcType::FLOOFF:
|
---|
1820 | stype = "FREQUENCY_SWITCH.OBSERVE_TARGET.OFF_SOURCE" ;
|
---|
1821 | b = False ;
|
---|
1822 | t = 0.0 ;
|
---|
1823 | l = 0.0 ;
|
---|
1824 | break ;
|
---|
1825 | case SrcType::FLOSKY:
|
---|
1826 | stype = "FREQUENCY_SWITCH.CALIBRATE_TEMPERATURE.OFF_SOURCE" ;
|
---|
1827 | b = False ;
|
---|
1828 | t = 0.0 ;
|
---|
1829 | l = 1.0 ;
|
---|
1830 | break ;
|
---|
1831 | case SrcType::FLOHOT:
|
---|
1832 | stype = "FREQUENCY_SWITCH.CALIBRATE_TEMPERATURE.OFF_SOURCE" ;
|
---|
1833 | b = False ;
|
---|
1834 | t = 0.0 ;
|
---|
1835 | l = 1.0 ;
|
---|
1836 | break ;
|
---|
1837 | case SrcType::FLOWARM:
|
---|
1838 | stype = "FREQUENCY_SWITCH.CALIBRATE_TEMPERATURE.OFF_SOURCE" ;
|
---|
1839 | b = False ;
|
---|
1840 | t = 0.0 ;
|
---|
1841 | l = 1.0 ;
|
---|
1842 | break ;
|
---|
1843 | case SrcType::FLOCOLD:
|
---|
1844 | stype = "FREQUENCY_SWITCH.CALIBRATE_TEMPERATURE.OFF_SOURCE" ;
|
---|
1845 | b = False ;
|
---|
1846 | t = 0.0 ;
|
---|
1847 | l = 1.0 ;
|
---|
1848 | break ;
|
---|
1849 | case SrcType::FSHI:
|
---|
1850 | stype = "FREQUENCY_SWITCH.OBSERVE_TARGET.ON_SOURCE" ;
|
---|
1851 | b = True ;
|
---|
1852 | t = 0.0 ;
|
---|
1853 | l = 0.0 ;
|
---|
1854 | break ;
|
---|
1855 | case SrcType::FHIOFF:
|
---|
1856 | stype = "FREQUENCY_SWITCH.CALIBRATE_TEMPERATURE.OFF_SOURCE" ;
|
---|
1857 | b = False ;
|
---|
1858 | t = 0.0 ;
|
---|
1859 | l = 0.0 ;
|
---|
1860 | break ;
|
---|
1861 | case SrcType::FHISKY:
|
---|
1862 | stype = "FREQUENCY_SWITCH.CALIBRATE_TEMPERATURE.OFF_SOURCE" ;
|
---|
1863 | b = False ;
|
---|
1864 | t = 0.0 ;
|
---|
1865 | l = 1.0 ;
|
---|
1866 | break ;
|
---|
1867 | case SrcType::FHIHOT:
|
---|
1868 | stype = "FREQUENCY_SWITCH.CALIBRATE_TEMPERATURE.OFF_SOURCE" ;
|
---|
1869 | b = False ;
|
---|
1870 | t = 0.0 ;
|
---|
1871 | l = 1.0 ;
|
---|
1872 | break ;
|
---|
1873 | case SrcType::FHIWARM:
|
---|
1874 | stype = "FREQUENCY_SWITCH.CALIBRATE_TEMPERATURE.OFF_SOURCE" ;
|
---|
1875 | b = False ;
|
---|
1876 | t = 0.0 ;
|
---|
1877 | l = 1.0 ;
|
---|
1878 | break ;
|
---|
1879 | case SrcType::FHICOLD:
|
---|
1880 | stype = "FREQUENCY_SWITCH.CALIBRATE_TEMPERATURE.OFF_SOURCE" ;
|
---|
1881 | b = False ;
|
---|
1882 | t = 0.0 ;
|
---|
1883 | l = 1.0 ;
|
---|
1884 | break ;
|
---|
1885 | case SrcType::SIG:
|
---|
1886 | stype = "UNSPECIFIED.OBSERVE_TARGET.ON_SOURCE" ;
|
---|
1887 | b = True ;
|
---|
1888 | t = 0.0 ;
|
---|
1889 | l = 0.0 ;
|
---|
1890 | break ;
|
---|
1891 | case SrcType::REF:
|
---|
1892 | stype = "UNSPECIFIED.OBSERVE_TARGET.ON_SOURCE" ;
|
---|
1893 | b = False ;
|
---|
1894 | t = 0.0 ;
|
---|
1895 | l = 0.0 ;
|
---|
1896 | break ;
|
---|
1897 | default:
|
---|
1898 | stype = "UNSPECIFIED" ;
|
---|
1899 | b = True ;
|
---|
1900 | t = 0.0 ;
|
---|
1901 | l = 0.0 ;
|
---|
1902 | break ;
|
---|
1903 | }
|
---|
1904 |
|
---|
1905 | double endSec = gettimeofday_sec() ;
|
---|
1906 | os_ << "end MSWriter::queryType() endSec=" << endSec << " (" << endSec-startSec << "sec)" << LogIO::POST ;
|
---|
1907 | }
|
---|
1908 | }
|
---|