source: branches/hpc34/external-alma/atnf/PKSIO/NRODataset.cc@ 2593

Last change on this file since 2593 was 2590, checked in by Takeshi Nakazato, 12 years ago

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: Describe your changes here...

In NROReader::getScanInfo, replaced a loop using casa::Vector<T>::iteratorSTL
with direct data access.

In NRODataset::getSpectrum, optimized operation and a few bug fixes.


File size: 23.0 KB
Line 
1//#---------------------------------------------------------------------------
2//# NRODataset.cc: Base class for NRO dataset.
3//#---------------------------------------------------------------------------
4//# Copyright (C) 2000-2006
5//# Associated Universities, Inc. Washington DC, USA.
6//#
7//# This library is free software; you can redistribute it and/or modify it
8//# under the terms of the GNU Library General Public License as published by
9//# the Free Software Foundation; either version 2 of the License, or (at your
10//# option) any later version.
11//#
12//# This library is distributed in the hope that it will be useful, but WITHOUT
13//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15//# License for more details.
16//#
17//# You should have received a copy of the GNU Library General Public License
18//# along with this library; if not, write to the Free Software Foundation,
19//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
20//#
21//# Correspondence concerning AIPS++ should be addressed as follows:
22//# Internet email: aips2-request@nrao.edu.
23//# Postal address: AIPS++ Project Office
24//# National Radio Astronomy Observatory
25//# 520 Edgemont Road
26//# Charlottesville, VA 22903-2475 USA
27//#
28//# $Id$
29//#---------------------------------------------------------------------------
30//# Original: 2009/02/27, Takeshi Nakazato, NAOJ
31//#---------------------------------------------------------------------------
32
33#include <atnf/PKSIO/NRODataset.h>
34#include <casa/OS/Time.h>
35#include <scimath/Mathematics/InterpolateArray1D.h>
36
37#include <measures/Measures/MeasConvert.h>
38#include <measures/Measures/MCFrequency.h>
39#include <measures/Measures/MFrequency.h>
40#include <measures/Measures/MPosition.h>
41#include <measures/Measures/MEpoch.h>
42#include <measures/Measures/MDirection.h>
43
44#include <math.h>
45#include <fstream>
46
47//#include <casa/namespace.h>
48
49using namespace std ;
50
51//
52// NRODataset
53//
54// Base class for NRO dataset.
55//
56
57// constructor
58NRODataset::NRODataset( string name )
59{
60 LogIO os( LogOrigin( "NRODataset", "NRODataset()", WHERE ) ) ;
61
62 // memory allocation
63 initialize() ;
64
65 filename_ = name ;
66 fp_ = NULL ;
67 scanNum_ = 0 ;
68 rowNum_ = 0 ;
69 scanLen_ = 0 ;
70 dataLen_ = 0 ;
71 dataid_ = -1 ;
72
73 // endian matches
74 same_ = -1 ;
75
76 // Record for frequency setting
77 frec_ = Record() ;
78}
79
80// destructor
81NRODataset::~NRODataset()
82{
83 // release memory
84 releaseRecord() ;
85
86 // close file
87 close() ;
88}
89
90// data initialization
91void NRODataset::initialize()
92{
93 datasize_ = sizeof( char ) * 8 // LOFIL
94 + sizeof( char ) * 8 // VER
95 + sizeof( char ) * 16 // GROUP
96 + sizeof( char ) * 16 // PROJ
97 + sizeof( char ) * 24 // SCHED
98 + sizeof( char ) * 40 // OBSVR
99 + sizeof( char ) * 16 // LOSTM
100 + sizeof( char ) * 16 // LOETM
101 + sizeof( int ) * 2 // ARYNM, NSCAN
102 + sizeof( char ) * 120 // TITLE
103 + sizeof( char ) * 16 // OBJ
104 + sizeof( char ) * 8 // EPOCH
105 + sizeof( double ) * 4 // RA0, DEC0, GLNG0, GLAT0
106 + sizeof( int ) * 2 // NCALB, SCNCD
107 + sizeof( char ) * 120 // SCMOD
108 + sizeof( double ) // URVEL
109 + sizeof( char ) * 4 // VREF
110 + sizeof( char ) * 4 // VDEF
111 + sizeof( char ) * 8 // SWMOD
112 + sizeof( double ) * 8 // FRQSW, DBEAM, MLTOF, CMTQ, CMTE, CMTSOM, CMTNODE, CMTI
113 + sizeof( char ) * 24 // CMTTM
114 + sizeof( double ) * 6 // SBDX, SBDY, SBDZ1, SBDZ2, DAZP, DELP
115 + sizeof( int ) * 4 // CHBIND, NUMCH, CHMIN, CHMAX
116 + sizeof( double ) * 3 // ALCTM, IPTIM, PA
117 + sizeof( int ) * 3 // SCNLEN, SBIND, IBIT
118 + sizeof( char ) * 8 ; // SITE
119
120 // NRODataRecord
121 record_ = new NRODataRecord() ;
122 record_->LDATA = NULL ;
123}
124
125void NRODataset::convertEndian( int &value )
126{
127 char volatile *first = reinterpret_cast<char volatile *>( &value ) ;
128 char volatile *last = first + sizeof( int ) ;
129 std::reverse( first, last ) ;
130}
131
132void NRODataset::convertEndian( float &value )
133{
134 char volatile *first = reinterpret_cast<char volatile *>( &value ) ;
135 char volatile *last = first + sizeof( float ) ;
136 std::reverse( first, last ) ;
137}
138
139void NRODataset::convertEndian( double &value )
140{
141 char volatile *first = reinterpret_cast<char volatile *>( &value ) ;
142 char volatile *last = first + sizeof( double ) ;
143 std::reverse( first, last ) ;
144}
145
146int NRODataset::readHeader( char *v, int size )
147{
148 if ( (int)( fread( v, 1, size, fp_ ) ) != size ) {
149 return -1 ;
150 }
151 return 0 ;
152}
153
154int NRODataset::readHeader( int &v, int b )
155{
156 if ( fread( &v, 1, sizeof(int), fp_ ) != sizeof(int) ) {
157 return -1 ;
158 }
159
160 if ( b == 0 )
161 convertEndian( v ) ;
162
163 return 0 ;
164}
165
166int NRODataset::readHeader( float &v, int b )
167{
168 if ( fread( &v, 1, sizeof(float), fp_ ) != sizeof(float) ) {
169 return -1 ;
170 }
171
172 if ( b == 0 )
173 convertEndian( v ) ;
174
175 return 0 ;
176}
177
178int NRODataset::readHeader( double &v, int b )
179{
180 if ( fread( &v, 1, sizeof(double), fp_ ) != sizeof(double) ) {
181 return -1 ;
182 }
183
184 if ( b == 0 )
185 convertEndian( v ) ;
186
187 return 0 ;
188}
189
190void NRODataset::convertEndian( NRODataRecord *r )
191{
192 convertEndian( r->ISCAN ) ;
193 convertEndian( r->DSCX ) ;
194 convertEndian( r->DSCY ) ;
195 convertEndian( r->SCX ) ;
196 convertEndian( r->SCY ) ;
197 convertEndian( r->PAZ ) ;
198 convertEndian( r->PEL ) ;
199 convertEndian( r->RAZ ) ;
200 convertEndian( r->REL ) ;
201 convertEndian( r->XX ) ;
202 convertEndian( r->YY ) ;
203 convertEndian( r->TEMP ) ;
204 convertEndian( r->PATM ) ;
205 convertEndian( r->PH2O ) ;
206 convertEndian( r->VWIND ) ;
207 convertEndian( r->DWIND ) ;
208 convertEndian( r->TAU ) ;
209 convertEndian( r->TSYS ) ;
210 convertEndian( r->BATM ) ;
211 convertEndian( r->LINE ) ;
212 for ( int i = 0 ; i < 4 ; i++ )
213 convertEndian( r->IDMY1[i] ) ;
214 convertEndian( r->VRAD ) ;
215 convertEndian( r->FREQ0 ) ;
216 convertEndian( r->FQTRK ) ;
217 convertEndian( r->FQIF1 ) ;
218 convertEndian( r->ALCV ) ;
219 for ( int i = 0 ; i < 2 ; i++ )
220 for ( int j = 0 ; j < 2 ; j++ )
221 convertEndian( r->OFFCD[i][j] ) ;
222 convertEndian( r->IDMY0 ) ;
223 convertEndian( r->IDMY2 ) ;
224 convertEndian( r->DPFRQ ) ;
225 convertEndian( r->SFCTR ) ;
226 convertEndian( r->ADOFF ) ;
227}
228
229void NRODataset::releaseRecord()
230{
231 if ( record_ ) {
232 if ( record_->LDATA != NULL ) {
233 delete record_->LDATA ;
234 record_->LDATA = NULL ;
235 }
236 delete record_ ;
237 record_ = NULL ;
238 }
239 dataid_ = -1 ;
240}
241
242// Get specified scan
243NRODataRecord *NRODataset::getRecord( int i )
244{
245 LogIO os( LogOrigin( "NRODataset", "getRecord()", WHERE ) ) ;
246
247 // DEBUG
248 //cout << "NRODataset::getRecord() Start " << i << endl ;
249 //
250 if ( i < 0 || i >= rowNum_ ) {
251 //cerr << "NRODataset::getRecord() data index out of range." << endl ;
252 os << LogIO::SEVERE << "data index " << i << " out of range. return NULL." << LogIO::POST ;
253 return NULL ;
254 }
255
256 if ( i == dataid_ ) {
257 return record_ ;
258 }
259
260 // DEBUG
261 //cout << "NRODataset::getData() Get new dataset" << endl ;
262 //
263 // read data
264 int status = fillRecord( i ) ;
265 if ( status == 0 ) {
266 dataid_ = i ;
267 }
268 else {
269 //cerr << "NRODataset::getRecord() error while reading data " << i << endl ;
270 os << LogIO::SEVERE << "error while reading data " << i << ". return NULL." << LogIO::POST ;
271 dataid_ = -1 ;
272 return NULL ;
273 }
274
275 return record_ ;
276}
277
278int NRODataset::fillRecord( int i )
279{
280 LogIO os( LogOrigin( "NRODataset", "fillRecord()", WHERE ) ) ;
281
282 int status = 0 ;
283
284 status = open() ;
285 if ( status != 0 )
286 return status ;
287
288
289 // fill NRODataset
290 int offset = getDataSize() + scanLen_ * i ;
291 // DEBUG
292 //cout << "NRODataset::fillRecord() offset (header) = " << offset << endl ;
293 //cout << "NRODataset::fillRecord() sizeof(NRODataRecord) = " << sizeof( NRODataRecord ) << " byte" << endl ;
294 fseek( fp_, offset, SEEK_SET ) ;
295 if ( (int)fread( record_, 1, SCAN_HEADER_SIZE, fp_ ) != SCAN_HEADER_SIZE ) {
296 //cerr << "Failed to read scan header: " << i << endl ;
297 os << LogIO::SEVERE << "Failed to read scan header for " << i << "th row." << LogIO::POST ;
298 return -1 ;
299 }
300 if ( (int)fread( record_->LDATA, 1, dataLen_, fp_ ) != dataLen_ ) {
301 //cerr << "Failed to read spectral data: " << i << endl ;
302 os << LogIO::SEVERE << "Failed to read spectral data for " << i << "th row." << LogIO::POST ;
303 return -1 ;
304 }
305
306 if ( same_ == 0 ) {
307 convertEndian( record_ ) ;
308 }
309
310 // DWIND unit conversion (deg -> rad)
311 record_->DWIND = record_->DWIND * M_PI / 180.0 ;
312
313 return status ;
314}
315
316// open
317int NRODataset::open()
318{
319 int status = 0 ;
320
321 if ( fp_ == NULL ) {
322 if ( (fp_ = fopen( filename_.c_str(), "rb" )) == NULL )
323 status = -1 ;
324 else
325 status = 0 ;
326 }
327
328 return status ;
329}
330
331// close
332void NRODataset::close()
333{
334 // DEBUG
335 //cout << "NRODataset::close() close file" << endl ;
336 //
337 if ( fp_ != NULL )
338 fclose( fp_ ) ;
339 fp_ = NULL ;
340}
341
342// get spectrum
343vector< vector<double> > NRODataset::getSpectrum()
344{
345 vector< vector<double> > spec(rowNum_);
346
347 for ( int i = 0 ; i < rowNum_ ; i++ ) {
348 spec[i] = getSpectrum( i ) ;
349 }
350
351 return spec ;
352}
353
354vector<double> NRODataset::getSpectrum( int i )
355{
356 LogIO os( LogOrigin( "NRODataset", "getSpectrum", WHERE ) ) ;
357
358 // DEBUG
359 //cout << "NRODataset::getSpectrum() start process (" << i << ")" << endl ;
360 //
361 // size of spectrum is not chmax_ but dataset_->getNCH() after binding
362 const int nchan = NUMCH ;
363 vector<double> bspec( nchan, 0.0 ) ; // spectrum "after" binding
364 // DEBUG
365 //cout << "NRODataset::getSpectrum() nchan = " << nchan << " chmax_ = " << chmax_ << endl ;
366 //
367
368 NRODataRecord *record = getRecord( i ) ;
369
370 const int bit = IBIT ; // fixed to 12 bit
371 double scale = record->SFCTR ;
372 // DEBUG
373 //cout << "NRODataset::getSpectrum() scale = " << scale << endl ;
374 //
375 double offset = record->ADOFF ;
376 // DEBUG
377 //cout << "NRODataset::getSpectrum() offset = " << offset << endl ;
378 //
379 if ( ( scale == 0.0 ) && ( offset == 0.0 ) ) {
380 //cerr << "NRODataset::getSpectrum() zero spectrum (" << i << ")" << endl ;
381 return bspec ;
382 }
383 unsigned char *cdata = (unsigned char *)record->LDATA ;
384 vector<double> mscale = MLTSCF ;
385 double dscale = mscale[getIndex( i )] ;
386 int cbind = CHBIND ;
387 int chmin = CHMIN ;
388
389 // char -> int
390 int *ispec = new int[chmax_] ;
391 int *int_p = ispec ;
392
393 static const int shift_right[] = {
394 4, 0
395 };
396 static const int start_pos[] = {
397 0, 1
398 };
399 static const int incr[] = {
400 0, 3
401 };
402 int j = 0 ;
403 for ( int i = 0 ; i < chmax_ ; i++ ) {
404 int ivalue = 0 ;
405 if ( bit == 12 ) { // 12 bit qunatization
406 const int ialt = i & 1 ;
407 const int idx = j + start_pos[ialt];
408 const unsigned tmp = unsigned(cdata[idx]) << 8 | cdata[idx + 1];
409 ivalue = int((tmp >> shift_right[ialt]) & 0xFFF);
410 j += incr[ialt];
411 }
412
413 if ( ( ivalue < 0 ) || ( ivalue > 4096 ) ) {
414 //cerr << "NRODataset::getSpectrum() ispec[" << i << "] is out of range" << endl ;
415 os << LogIO::SEVERE << "ispec[" << i << "] is out of range" << LogIO::EXCEPTION ;
416 delete ispec ;
417 return bspec ;
418 }
419 // DEBUG
420 //cout << "NRODataset::getSpectrum() ispec[" << i << "] = " << ispec[i] << endl ;
421 //
422 *int_p = ivalue ;
423 int_p++ ;
424 }
425
426 double *const spec = new double[ chmax_ ] ; // spectrum "before" binding
427 // int -> double
428 int_p = ispec ;
429 double *double_p = spec ;
430 for ( int i = 0 ; i < chmax_ ; i++ ) {
431 *double_p = (double)( (*int_p) * scale + offset ) * dscale ;
432 // DEBUG
433 //cout << "NRODataset::getSpectrum() spec[" << i << "] = " << spec[i] << endl ;
434 //
435 int_p++ ;
436 double_p++ ;
437 }
438 delete ispec ;
439
440 // channel binding
441 if ( cbind != 1 ) {
442 double_p = &(spec[chmin]) ;
443 for ( vector<double>::iterator i = bspec.begin() ;
444 i != bspec.end() ; i++ ) {
445 double sum0 = 0 ;
446 double sum1 = 0 ;
447 for ( int j = 0 ; j < cbind ; j++ ) {
448 sum0 += *double_p ;
449 sum1 += 1.0 ;
450 double_p++ ;
451 }
452 *i = sum0 / sum1 ;
453 i++ ;
454 // DEBUG
455 //cout << "NRODataset::getSpectrum() bspec[" << i << "] = " << bspec[i] << endl ;
456 //
457 }
458 }
459 else {
460 double_p = spec ;
461 for ( vector<double>::iterator i = bspec.begin() ;
462 i != bspec.end() ; i++ ) {
463 *i = *double_p ;
464 double_p++ ;
465 }
466 }
467 delete[] spec;
468
469 // DEBUG
470 //cout << "NRODataset::getSpectrum() end process" << endl ;
471 //
472
473 return bspec ;
474}
475
476int NRODataset::getIndex( int irow )
477{
478 // DEBUG
479 //cout << "NRODataset::getIndex() start" << endl ;
480 //
481 NRODataRecord *record = getRecord( irow ) ;
482 string str = record->ARRYT ;
483 // DEBUG
484 //cout << "NRODataset::getIndex() str = " << str << endl ;
485 //
486 string substr = str.substr( 1, 2 ) ;
487 unsigned int index = (unsigned int)(atoi( substr.c_str() ) - 1) ;
488 // DEBUG
489 //cout << "NRODataset::getIndex() irow = " << irow << " index = " << index << endl ;
490 //
491
492 // DEBUG
493 //cout << "NRODataset::getIndex() end" << endl ;
494 //
495 return index ;
496}
497
498int NRODataset::getPolarizationNum()
499{
500 // DEBUG
501 //cout << "NRODataset::getPolarizationNum() start process" << endl ;
502 //
503 int npol = 0 ;
504
505 vector<string> type( 2 ) ;
506 type[0] = "CIRC" ;
507 type[1] = "LINR" ;
508 vector<double> crot ;
509 vector<double> lagl ;
510 //vector<int> ntype( 2, 0 ) ;
511
512 unsigned int imax = rowNum_ ;
513 for ( unsigned int i = 0 ; i < imax ; i++ ) {
514 int index = getIndex( i ) ;
515 // DEBUG
516 //cout <<"NRODataset::getPolarizationNum() index = " << index << endl ;
517 //
518 if ( POLTP[index] == type[0] ) {
519 if( count( crot.begin(), crot.end(), POLDR[index] ) != 0 ) {
520 crot.push_back( POLDR[index] ) ;
521 npol++ ;
522 }
523 //ntype[0] = 1 ;
524 }
525 else if ( POLTP[index] == type[1] ) {
526 if ( count( lagl.begin(), lagl.end(), POLAN[index] ) != 0 ) {
527 lagl.push_back( POLAN[index] ) ;
528 npol++ ;
529 }
530 //ntype[1] = 1 ;
531 }
532 }
533
534 if ( npol == 0 )
535 npol = 1 ;
536
537 // DEBUG
538 //cout << "NRODataset::getPolarizationNum() end process" << endl ;
539 //
540
541 return npol ;
542}
543
544vector<double> NRODataset::getStartIntTime()
545{
546 vector<double> times ;
547 for ( int i = 0 ; i < rowNum_ ; i++ ) {
548 times.push_back( getStartIntTime( i ) ) ;
549 }
550 return times ;
551}
552
553double NRODataset::getStartIntTime( int i )
554{
555 NRODataRecord *record = getRecord( i ) ;
556
557 char *t = record->LAVST ;
558 return getMJD( t ) ;
559}
560
561double NRODataset::getMJD( char *time )
562{
563 // TODO: should be checked which time zone the time depends on
564 // 2008/11/14 Takeshi Nakazato
565 string strStartTime( time ) ;
566 string strYear = strStartTime.substr( 0, 4 ) ;
567 string strMonth = strStartTime.substr( 4, 2 ) ;
568 string strDay = strStartTime.substr( 6, 2 ) ;
569 string strHour = strStartTime.substr( 8, 2 ) ;
570 string strMinute = strStartTime.substr( 10, 2 ) ;
571 string strSecond = strStartTime.substr( 12, strStartTime.size() - 12 ) ;
572 unsigned int year = atoi( strYear.c_str() ) ;
573 unsigned int month = atoi( strMonth.c_str() ) ;
574 unsigned int day = atoi( strDay.c_str() ) ;
575 unsigned int hour = atoi( strHour.c_str() ) ;
576 unsigned int minute = atoi( strMinute.c_str() ) ;
577 double second = atof( strSecond.c_str() ) ;
578 Time t( year, month, day, hour, minute, second ) ;
579
580 return t.modifiedJulianDay() ;
581}
582
583double NRODataset::getScanTime( int i )
584{
585 double startTime = getStartIntTime( i ) ;
586 double interval = getIPTIM() / 86400.0 ; // [sec]->[day]
587 return startTime+0.5*interval ;
588}
589
590vector<bool> NRODataset::getIFs()
591{
592 vector<bool> v ;
593 vector< vector<double> > fref ;
594 vector< vector<double> > chcal = CHCAL ;
595 vector<double> f0cal = F0CAL ;
596 vector<double> beres = BERES ;
597 for ( int i = 0 ; i < rowNum_ ; i++ ) {
598 vector<double> f( 4, 0 ) ;
599 uInt index = getIndex( i ) ;
600 f[0] = chcal[index][0] ;
601 f[1] = f0cal[index] ;
602 f[2] = beres[index] ;
603 if ( f[0] != 0. ) {
604 f[1] = f[1] - f[0] * f[2] ;
605 }
606 NRODataRecord *record = getRecord( i ) ;
607 f[3] = record->FREQ0 ;
608 if ( v.size() == 0 ) {
609 v.push_back( True ) ;
610 fref.push_back( f ) ;
611 }
612 else {
613 bool b = true ;
614 int fsize = fref.size() ;
615 for ( int j = 0 ; j < fsize ; j++ ) {
616 if ( fref[j][1] == f[1] && fref[j][2] == f[2] && fref[j][3] == f[3] ) {
617 b = false ;
618 }
619 }
620 if ( b ) {
621 v.push_back( True ) ;
622 fref.push_back( f ) ;
623 }
624 }
625 }
626
627
628 // DEBUG
629 //cout << "NRODataset::getIFs() number of IF is " << v.size() << endl ;
630 //
631
632 return v ;
633}
634
635vector<double> NRODataset::getFrequencies( int i )
636{
637 // return value
638 // v[0] reference channel
639 // v[1] reference frequency
640 // v[2] frequency increment
641 vector<double> v( 3, 0.0 ) ;
642
643 NRODataRecord *record = getRecord( i ) ;
644 string arryt = string( record->ARRYT ) ;
645 uInt ib = getArrayId( arryt ) ;
646 string rxname = getRX()[0] ;
647 string key = arryt ;
648 if ( rxname.find("MULT2") != string::npos )
649 key = "BEARS" ;
650
651 if ( frec_.isDefined( key ) ) {
652 // frequency for the array is already calculated
653 Vector<Double> f = frec_.asArrayDouble( key ) ;
654 Double *f_p = f.data() ;
655 for ( int i = 0 ; i < 3 ; i++ )
656 v[i] = (double)(f_p[i]) ;
657 return v ;
658 }
659
660 //int ia = -1 ;
661 bool isAOS = false ;
662 //cout << "NRODataset::getFrequencies() record->ARRYT=" << record->ARRYT << endl ;
663 //cout << "NRODataset::getFrequencies() ib = " << ib << endl ;
664
665 if ( arryt[0] == 'W' || arryt[0] == 'U' || arryt[0] == 'H' )
666 isAOS = true ;
667
668 Bool isUSB ;
669 if ( record->FQIF1 > 0 )
670 isUSB = True ; // USB
671 else
672 isUSB = False ; // LSB
673
674 int ivdef = -1 ;
675 if ( (getVDEF()).compare( 0, 3, "RAD" ) == 0 )
676 ivdef = 0 ;
677 else if ( (getVDEF()).compare( 0, 3, "OPT" ) == 0 )
678 ivdef = 1 ;
679 // DEBUG
680 //cout << "NRODataset::getFrequencies() ivdef = " << ivdef << endl ;
681 //
682 double vel = getURVEL() + record->VRAD ;
683 double cvel = 2.99792458e8 ; // speed of light [m/s]
684 double fq0 = record->FREQ0 ;
685 //double fq0 = record->FQTRK ;
686
687 int ncal = getNFCAL()[ib] ;
688 double cw = 0.0 ;
689 vector<double> fqcal = getFQCAL()[ib] ;
690 vector<double> chcal = getCHCAL()[ib] ;
691 double f0cal = getF0CAL()[ib] ;
692 Vector<Double> freqs( ncal, fq0-f0cal ) ;
693
694 double factor = vel / cvel ;
695 if ( ivdef == 0 )
696 factor = 1.0 / ( 1.0 - factor ) ;
697 for ( int ii = 0 ; ii < ncal ; ii++ ) {
698 freqs[ii] += fqcal[ii] ;
699 if ( ivdef == 0 ) {
700 freqs[ii] = freqs[ii] * factor + record->FQTRK * ( 1.0 - factor ) ;
701 }
702 else if ( ivdef == 1 ) {
703 freqs[ii] = freqs[ii] * ( 1.0 + factor ) - record->FQTRK * factor ;
704 }
705
706 //ofstream ofs("freqs.txt",ios::out|ios::app) ;
707 //ofs << setprecision(16) ;
708 //ofs << i << " " << record->ARRYT << " " << chcal[ii] << " " << freqs[ii] << " " << record->ISCAN << " " << fqcal[ii] << " " << f0cal << " " << record->FQTRK << " " << vel << endl ;
709 //ofs.close() ;
710
711 }
712
713 if ( isAOS ) {
714 // regridding
715 while ( ncal < (int)chcal.size() ) {
716 chcal.pop_back() ;
717 }
718 Vector<Double> xin( chcal ) ;
719 Vector<Double> yin( freqs ) ;
720 int nchan = getNUMCH() ;
721 Vector<Double> xout( nchan ) ;
722 indgen( xout ) ;
723 Vector<Double> yout ;
724 InterpolateArray1D<Double, Double>::interpolate( yout, xout, xin, yin, InterpolateArray1D<Double,Double>::cubic ) ;
725 Double bw = abs( yout[nchan-1] - yout[0] ) ;
726 bw += 0.5 * abs( yout[nchan-1] - yout[nchan-2] + yout[1] - yout[0] ) ;
727 Double dz = bw / (Double) nchan ;
728 if ( yout[0] > yout[1] )
729 dz = - dz ;
730 v[0] = 0 ;
731 v[1] = yout[0] ;
732 v[2] = dz ;
733 }
734 else {
735
736 cw = ( freqs[1] - freqs[0] )
737 / ( chcal[1] - chcal[0] ) ;
738
739 if ( isUSB ) {
740 // channel frequency inversion
741 cw *= -1.0 ;
742 Double tmp = freqs[1] ;
743 freqs[1] = freqs[0] ;
744 freqs[0] = tmp ;
745 }
746
747 v[0] = chcal[0] - 1 ; // 0-base
748 v[1] = freqs[0] ;
749 v[2] = cw ;
750 }
751
752 if ( refFreq_[ib] == 0.0 )
753 refFreq_[ib] = v[1] ;
754
755 // register frequency setting to Record
756 Vector<Double> f( v ) ;
757 frec_.define( key, f ) ;
758
759 return v ;
760}
761
762uInt NRODataset::getArrayId( string type )
763{
764 string sbeamno = type.substr( 1, type.size()-1 ) ;
765 uInt ib = atoi( sbeamno.c_str() ) - 1 ;
766 return ib ;
767}
768
769void NRODataset::show()
770{
771 LogIO os( LogOrigin( "NRODataset", "show()", WHERE ) ) ;
772
773 os << LogIO::NORMAL << "------------------------------------------------------------" << endl ;
774 os << LogIO::NORMAL << "Number of scan = " << scanNum_ << endl ;
775 os << LogIO::NORMAL << "Number of data record = " << rowNum_ << endl ;
776 os << LogIO::NORMAL << "Length of data record = " << scanLen_ << " bytes" << endl ;
777 os << LogIO::NORMAL << "Allocated memory for spectral data = " << dataLen_ << " bytes" << endl ;
778 os << LogIO::NORMAL << "Max number of channel = " << chmax_ << endl ;
779 os << LogIO::NORMAL << "------------------------------------------------------------" << endl ;
780 os.post() ;
781
782}
783
784double NRODataset::toLSR( double v, double t, double x, double y )
785{
786 double vlsr ;
787
788 // get epoch
789 double tcent = t + 0.5*getIPTIM()/86400.0 ;
790 MEpoch me( Quantity( tcent, "d" ), MEpoch::UTC ) ;
791
792 // get antenna position
793 MPosition mp ;
794 if ( SITE.find( "45" ) != string::npos ) {
795 // 45m telescope
796 Double posx = -3.8710235e6 ;
797 Double posy = 3.4281068e6 ;
798 Double posz = 3.7240395e6 ;
799 mp = MPosition( MVPosition( posx, posy, posz ),
800 MPosition::ITRF ) ;
801 }
802 else {
803 // ASTE
804 Vector<Double> pos( 2 ) ;
805 pos[0] = -67.7031 ;
806 pos[1] = -22.9717 ;
807 Double sitealt = 4800.0 ;
808 mp = MPosition( MVPosition( Quantity( sitealt, "m" ),
809 Quantum< Vector<Double> >( pos, "deg" ) ),
810 MPosition::WGS84 ) ;
811 }
812
813 // get direction
814 MDirection md ;
815 if ( SCNCD == 0 ) {
816 // RADEC
817 if ( EPOCH == "B1950" ) {
818 md = MDirection( Quantity( Double(x), "rad" ), Quantity( Double(y), "rad" ),
819 MDirection::B1950 ) ;
820 }
821 else {
822 md = MDirection( Quantity( Double(x), "rad" ), Quantity( Double(y), "rad" ),
823 MDirection::J2000 ) ;
824 }
825 }
826 else if ( SCNCD == 1 ) {
827 // LB
828 md = MDirection( Quantity( Double(x), "rad" ), Quantity( Double(y), "rad" ),
829 MDirection::GALACTIC ) ;
830 }
831 else {
832 // AZEL
833 md = MDirection( Quantity( Double(x), "rad" ), Quantity( Double(y), "rad" ),
834 MDirection::AZEL ) ;
835 }
836
837 // to LSR
838 MeasFrame mf( me, mp, md ) ;
839 MFrequency::Convert tolsr( MFrequency::TOPO, MFrequency::Ref( MFrequency::LSRK, mf ) ) ;
840 vlsr = (double)(tolsr( Double(v) ).get( "Hz" ).getValue()) ;
841
842 return vlsr ;
843}
844
845uInt NRODataset::getPolNo( int i )
846{
847 int idx = getIndex( i ) ;
848// cout << "HORN[" << idx << "]=" << HORN[idx]
849// << ", RX[" << idx << "]=" << RX[idx] << endl ;
850 return polNoFromRX( RX[idx].c_str() ) ;
851}
852
853uInt NRODataset::polNoFromRX( const char *rx )
854{
855 uInt polno = 0 ;
856 // 2012/03/15 TN
857 // T100H/V is multi-polarization receiver which is installed
858 // on NRO 45m telescope. Here, POLNO is assigned as follows:
859 //
860 // POLNO=0: T100H
861 // 1: T100V
862 //
863 // For other receivers, POLNO is always 0.
864 if ( strncmp( rx, "T100V", 5 ) == 0 )
865 polno = 1 ;
866 return polno ;
867}
Note: See TracBrowser for help on using the repository browser.