[1757] | 1 | //#--------------------------------------------------------------------------- |
---|
| 2 | //# NROReader.cc: Base class for NRO headerdata. |
---|
| 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: 2008/10/30, Takeshi Nakazato, NAOJ |
---|
| 31 | //#--------------------------------------------------------------------------- |
---|
| 32 | |
---|
| 33 | #include <atnf/PKSIO/NROReader.h> |
---|
| 34 | #include <atnf/PKSIO/NRO45Reader.h> |
---|
| 35 | #include <atnf/PKSIO/ASTEReader.h> |
---|
| 36 | #include <atnf/PKSIO/ASTEFXReader.h> |
---|
| 37 | #include <atnf/PKSIO/NRO45FITSReader.h> |
---|
| 38 | #include <atnf/PKSIO/NROOTFDataset.h> |
---|
| 39 | #include <atnf/PKSIO/ASTEDataset.h> |
---|
| 40 | |
---|
[2200] | 41 | #include <measures/Measures/MEpoch.h> |
---|
| 42 | #include <measures/Measures/MPosition.h> |
---|
[1757] | 43 | #include <measures/Measures/MDirection.h> |
---|
| 44 | #include <measures/Measures/MCDirection.h> |
---|
[2200] | 45 | #include <measures/Measures/MeasFrame.h> |
---|
[1757] | 46 | #include <measures/Measures/MeasConvert.h> |
---|
| 47 | |
---|
[2761] | 48 | #include <casa/Logging/LogIO.h> |
---|
[1757] | 49 | #include <casa/IO/RegularFileIO.h> |
---|
| 50 | #include <casa/OS/File.h> |
---|
| 51 | #include <casa/OS/Time.h> |
---|
| 52 | |
---|
| 53 | #include <stdio.h> |
---|
| 54 | #include <string> |
---|
| 55 | #include <iomanip> |
---|
| 56 | |
---|
| 57 | using namespace std ; |
---|
| 58 | |
---|
| 59 | // |
---|
| 60 | // getNROReader |
---|
| 61 | // |
---|
| 62 | // Return an appropriate NROReader for a NRO 45m and ASTE dataset. |
---|
| 63 | // |
---|
| 64 | NROReader *getNROReader( const String filename, |
---|
| 65 | String &datatype ) |
---|
| 66 | { |
---|
| 67 | LogIO os( LogOrigin( "", "getNROReader()", WHERE ) ) ; |
---|
| 68 | |
---|
| 69 | // Check accessibility of the input. |
---|
| 70 | File inFile( filename ) ; |
---|
| 71 | if ( !inFile.exists() ) { |
---|
| 72 | datatype = filename + " not found." ; |
---|
| 73 | return 0 ; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | if ( !inFile.isReadable() ) { |
---|
| 77 | datatype = filename + " is not readable." ; |
---|
| 78 | return 0 ; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | // Determine the type of input. |
---|
| 82 | NROReader *reader = 0; |
---|
| 83 | if ( inFile.isRegular() ) { |
---|
| 84 | FILE *file ; |
---|
| 85 | file = fopen( filename.c_str(), "r" ) ; |
---|
| 86 | // read LOFIL0 |
---|
| 87 | char buf[9]; |
---|
| 88 | fread( buf, 4, 1, file ) ; |
---|
| 89 | buf[4] = '\0' ; |
---|
| 90 | // DEBUG |
---|
| 91 | //os << LogIO::NORMAL << "getNROReader:: buf = " << String(buf) << LogIO::POST ; |
---|
| 92 | // |
---|
| 93 | if ( string( buf ) == "XTEN" ) { |
---|
| 94 | // FITS data |
---|
| 95 | datatype = "NRO 45m FITS" ; |
---|
| 96 | reader = new NRO45FITSReader( filename ) ; |
---|
| 97 | } |
---|
| 98 | else if ( string( buf ) == "RW-F") { |
---|
| 99 | // ASTE-FX data |
---|
| 100 | datatype = "ASTE-FX"; |
---|
| 101 | reader = new ASTEFXReader( filename ); |
---|
| 102 | } else { |
---|
| 103 | // otherwise, read SITE0 |
---|
| 104 | NRODataset *d = new NROOTFDataset( filename ) ; |
---|
| 105 | int size = d->getDataSize() - 188 ; |
---|
| 106 | delete d ; |
---|
| 107 | fseek( file, size, SEEK_SET ) ; |
---|
| 108 | fread( buf, 8, 1, file ) ; |
---|
| 109 | buf[8] = '\0' ; |
---|
| 110 | // DEBUG |
---|
| 111 | //cout << "getNROReader:: buf = " << buf << endl ; |
---|
| 112 | // |
---|
| 113 | if ( string( buf ) == "NRO" ) { |
---|
| 114 | // NRO 45m data |
---|
| 115 | datatype = "NRO 45m OTF" ; |
---|
| 116 | reader = new NRO45Reader( filename ); |
---|
| 117 | } |
---|
| 118 | else { |
---|
| 119 | d = new ASTEDataset( filename ) ; |
---|
| 120 | size = d->getDataSize() - 188 ; |
---|
| 121 | delete d ; |
---|
| 122 | fseek( file, size, SEEK_SET ) ; |
---|
| 123 | fread( buf, 8, 1, file ) ; |
---|
| 124 | buf[8] = '\0' ; |
---|
| 125 | // DEBUG |
---|
| 126 | //cout << "getNROReader:: buf = " << buf << endl ; |
---|
| 127 | // |
---|
| 128 | if ( string( buf ) == "ASTE" ) { |
---|
| 129 | // ASTE data |
---|
| 130 | datatype = "ASTE" ; |
---|
| 131 | reader = new ASTEReader( filename ) ; |
---|
| 132 | } |
---|
| 133 | else { |
---|
| 134 | datatype = "UNRECOGNIZED INPUT FORMAT"; |
---|
| 135 | } |
---|
| 136 | } |
---|
| 137 | } |
---|
| 138 | fclose( file ) ; |
---|
| 139 | } else { |
---|
| 140 | datatype = "UNRECOGNIZED INPUT FORMAT"; |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | // DEBUG |
---|
| 144 | os << LogIO::NORMAL << "Data format of " << filename << ": " << datatype << LogIO::POST ; |
---|
| 145 | // |
---|
| 146 | |
---|
| 147 | // return reader if exists |
---|
| 148 | if ( reader ) { |
---|
| 149 | reader->read() ; |
---|
| 150 | return reader ; |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | return 0 ; |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | |
---|
| 157 | // |
---|
| 158 | // getNROReader |
---|
| 159 | // |
---|
| 160 | // Search a list of directories for a NRO 45m and ASTE dataset and return an |
---|
| 161 | // appropriate NROReader for it. |
---|
| 162 | // |
---|
| 163 | NROReader* getNROReader( const String name, |
---|
| 164 | const Vector<String> directories, |
---|
| 165 | int &iDir, |
---|
| 166 | String &datatype ) |
---|
| 167 | { |
---|
| 168 | int nDir = directories.size(); |
---|
| 169 | for ( iDir = 0; iDir < nDir; iDir++ ) { |
---|
| 170 | string inName = directories[iDir] + "/" + name; |
---|
| 171 | NROReader *reader = getNROReader( inName, datatype ) ; |
---|
| 172 | |
---|
| 173 | if (reader != 0) { |
---|
| 174 | return reader; |
---|
| 175 | } |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | iDir = -1; |
---|
| 179 | return 0; |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | |
---|
| 183 | //---------------------------------------------------------------------- |
---|
| 184 | // constructor |
---|
[2643] | 185 | NROReader::NROReader( string name ) |
---|
| 186 | : dataset_( NULL ), |
---|
| 187 | srcdir_( 0 ), |
---|
[2761] | 188 | msrcdir_( 0 ), |
---|
| 189 | freqRefFromVREF_( false ) // import frequency as REST |
---|
[2643] | 190 | { |
---|
[1757] | 191 | // initialization |
---|
| 192 | filename_ = name ; |
---|
[2643] | 193 | coord_ = -1 ; |
---|
[1757] | 194 | } |
---|
| 195 | |
---|
| 196 | // destructor |
---|
| 197 | NROReader::~NROReader() |
---|
| 198 | { |
---|
| 199 | } |
---|
| 200 | |
---|
[2780] | 201 | // Read data header |
---|
| 202 | Int NROReader::read() |
---|
| 203 | { |
---|
| 204 | LogIO os( LogOrigin( "NROReader", "read()", WHERE ) ) ; |
---|
| 205 | |
---|
| 206 | int status = 0 ; |
---|
| 207 | |
---|
| 208 | // initialize Dataset object |
---|
| 209 | initDataset(); |
---|
| 210 | |
---|
| 211 | // fill Dataset |
---|
| 212 | status = dataset_->fillHeader() ; |
---|
| 213 | |
---|
| 214 | if ( status != 0 ) { |
---|
| 215 | os << LogIO::SEVERE << "Failed to fill data header." << LogIO::EXCEPTION ; |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | return status ; |
---|
| 219 | } |
---|
| 220 | |
---|
[2761] | 221 | // set frequency reference frame |
---|
| 222 | void NROReader::setFreqRefFromVREF( bool fromVREF ) |
---|
| 223 | { |
---|
| 224 | os_.origin( LogOrigin( "NROReader", "setFreqRefFromVREF", WHERE ) ) ; |
---|
| 225 | os_ << ((fromVREF) ? "Take frequency reference frame from VREF" : |
---|
| 226 | "Use frequency reference frame REST") << LogIO::POST ; |
---|
| 227 | |
---|
| 228 | freqRefFromVREF_ = fromVREF ; |
---|
| 229 | } |
---|
| 230 | |
---|
[1757] | 231 | // get spectrum |
---|
| 232 | vector< vector<double> > NROReader::getSpectrum() |
---|
| 233 | { |
---|
| 234 | return dataset_->getSpectrum() ; |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | Int NROReader::getPolarizationNum() |
---|
| 238 | { |
---|
| 239 | return dataset_->getPolarizationNum() ; |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | double NROReader::getStartTime() |
---|
| 243 | { |
---|
| 244 | //char *startTime = dataset_->getLOSTM() ; |
---|
| 245 | string startTime = dataset_->getLOSTM() ; |
---|
| 246 | //cout << "getStartTime() startTime = " << startTime << endl ; |
---|
| 247 | return getMJD( startTime ) ; |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | double NROReader::getEndTime() |
---|
| 251 | { |
---|
| 252 | //char *endTime = dataset_->getLOETM() ; |
---|
| 253 | string endTime = dataset_->getLOETM() ; |
---|
| 254 | return getMJD( endTime ) ; |
---|
| 255 | } |
---|
| 256 | |
---|
| 257 | vector<double> NROReader::getStartIntTime() |
---|
| 258 | { |
---|
| 259 | return dataset_->getStartIntTime() ; |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | double NROReader::getMJD( char *time ) |
---|
| 263 | { |
---|
| 264 | // TODO: should be checked which time zone the time depends on |
---|
| 265 | // 2008/11/14 Takeshi Nakazato |
---|
| 266 | string strStartTime = string( time ) ; |
---|
| 267 | string strYear = strStartTime.substr( 0, 4 ) ; |
---|
| 268 | string strMonth = strStartTime.substr( 4, 2 ) ; |
---|
| 269 | string strDay = strStartTime.substr( 6, 2 ) ; |
---|
| 270 | string strHour = strStartTime.substr( 8, 2 ) ; |
---|
| 271 | string strMinute = strStartTime.substr( 10, 2 ) ; |
---|
| 272 | string strSecond = strStartTime.substr( 12, strStartTime.size() - 12 ) ; |
---|
| 273 | uInt year = atoi( strYear.c_str() ) ; |
---|
| 274 | uInt month = atoi( strMonth.c_str() ) ; |
---|
| 275 | uInt day = atoi( strDay.c_str() ) ; |
---|
| 276 | uInt hour = atoi( strHour.c_str() ) ; |
---|
| 277 | uInt minute = atoi( strMinute.c_str() ) ; |
---|
| 278 | double second = atof( strSecond.c_str() ) ; |
---|
| 279 | Time t( year, month, day, hour, minute, second ) ; |
---|
| 280 | |
---|
| 281 | return t.modifiedJulianDay() ; |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | double NROReader::getMJD( string strStartTime ) |
---|
| 285 | { |
---|
| 286 | // TODO: should be checked which time zone the time depends on |
---|
| 287 | // 2008/11/14 Takeshi Nakazato |
---|
| 288 | string strYear = strStartTime.substr( 0, 4 ) ; |
---|
| 289 | string strMonth = strStartTime.substr( 4, 2 ) ; |
---|
| 290 | string strDay = strStartTime.substr( 6, 2 ) ; |
---|
| 291 | string strHour = strStartTime.substr( 8, 2 ) ; |
---|
| 292 | string strMinute = strStartTime.substr( 10, 2 ) ; |
---|
| 293 | string strSecond = strStartTime.substr( 12, strStartTime.size() - 12 ) ; |
---|
| 294 | uInt year = atoi( strYear.c_str() ) ; |
---|
| 295 | uInt month = atoi( strMonth.c_str() ) ; |
---|
| 296 | uInt day = atoi( strDay.c_str() ) ; |
---|
| 297 | uInt hour = atoi( strHour.c_str() ) ; |
---|
| 298 | uInt minute = atoi( strMinute.c_str() ) ; |
---|
| 299 | double second = atof( strSecond.c_str() ) ; |
---|
| 300 | Time t( year, month, day, hour, minute, second ) ; |
---|
| 301 | |
---|
| 302 | return t.modifiedJulianDay() ; |
---|
| 303 | } |
---|
| 304 | |
---|
| 305 | vector<Bool> NROReader::getIFs() |
---|
| 306 | { |
---|
| 307 | return dataset_->getIFs() ; |
---|
| 308 | } |
---|
| 309 | |
---|
| 310 | vector<Bool> NROReader::getBeams() |
---|
| 311 | { |
---|
| 312 | vector<Bool> v ; |
---|
| 313 | vector<int> arry = dataset_->getARRY() ; |
---|
| 314 | for ( uInt i = 0 ; i < arry.size() ; i++ ) { |
---|
| 315 | if ( arry[i] != 0 ) { |
---|
| 316 | v.push_back( True ) ; |
---|
| 317 | } |
---|
| 318 | } |
---|
| 319 | |
---|
| 320 | // DEBUG |
---|
| 321 | //cout << "NROReader::getBeams() number of beam is " << v.size() << endl ; |
---|
| 322 | // |
---|
| 323 | |
---|
| 324 | return v ; |
---|
| 325 | } |
---|
| 326 | |
---|
| 327 | // Get SRCDIRECTION in RADEC(J2000) |
---|
| 328 | Vector<Double> NROReader::getSourceDirection() |
---|
| 329 | { |
---|
[2643] | 330 | if ( msrcdir_.nelements() == 2 ) |
---|
| 331 | return msrcdir_ ; |
---|
[1757] | 332 | |
---|
[2643] | 333 | srcdir_.resize( 2 ) ; |
---|
| 334 | srcdir_[0] = Double( dataset_->getRA0() ) ; |
---|
| 335 | srcdir_[1] = Double( dataset_->getDEC0() ) ; |
---|
[1757] | 336 | char epoch[5] ; |
---|
| 337 | strncpy( epoch, (dataset_->getEPOCH()).c_str(), 5 ) ; |
---|
| 338 | if ( strncmp( epoch, "B1950", 5 ) == 0 ) { |
---|
| 339 | // convert to J2000 value |
---|
| 340 | MDirection result = |
---|
[2643] | 341 | MDirection::Convert( MDirection( Quantity( srcdir_[0], "rad" ), |
---|
| 342 | Quantity( srcdir_[1], "rad" ), |
---|
[1757] | 343 | MDirection::Ref( MDirection::B1950 ) ), |
---|
| 344 | MDirection::Ref( MDirection::J2000 ) ) () ; |
---|
[2643] | 345 | msrcdir_ = result.getAngle().getValue() ; |
---|
| 346 | if ( msrcdir_[0] < 0.0 && srcdir_[0] >= 0.0 ) |
---|
| 347 | msrcdir_[0] = 2.0 * M_PI + msrcdir_[0] ; |
---|
[1757] | 348 | //cout << "NROReader::getSourceDirection() SRCDIRECTION convert from (" |
---|
| 349 | //<< srcra << "," << srcdec << ") B1950 to (" |
---|
| 350 | //<< v( 0 ) << ","<< v( 1 ) << ") J2000" << endl ; |
---|
[2643] | 351 | //LogIO os( LogOrigin( "NROReader", "getSourceDirection()", WHERE ) ) ; |
---|
[2261] | 352 | //os << LogIO::NORMAL << "SRCDIRECTION convert from (" |
---|
| 353 | // << srcra << "," << srcdec << ") B1950 to (" |
---|
| 354 | // << v( 0 ) << ","<< v( 1 ) << ") J2000" << LogIO::POST ; |
---|
[1757] | 355 | } |
---|
| 356 | else if ( strncmp( epoch, "J2000", 5 ) == 0 ) { |
---|
[2643] | 357 | msrcdir_.reference( srcdir_ ) ; |
---|
[1757] | 358 | } |
---|
[2643] | 359 | |
---|
| 360 | return msrcdir_ ; |
---|
[1757] | 361 | } |
---|
| 362 | |
---|
| 363 | // Get DIRECTION in RADEC(J2000) |
---|
| 364 | Vector<Double> NROReader::getDirection( int i ) |
---|
| 365 | { |
---|
[2643] | 366 | Vector<Double> v( 2 ) ; |
---|
[2766] | 367 | const NRODataRecord *record = dataset_->getRecord( i ) ; |
---|
[1757] | 368 | char epoch[5] ; |
---|
| 369 | strncpy( epoch, (dataset_->getEPOCH()).c_str(), 5 ) ; |
---|
| 370 | int icoord = dataset_->getSCNCD() ; |
---|
[2643] | 371 | double scantime = dataset_->getScanTime( i ) ; |
---|
| 372 | initConvert( icoord, scantime, epoch ) ; |
---|
| 373 | v[0]= Double( record->SCX ) ; |
---|
| 374 | v[1] = Double( record->SCY ) ; |
---|
| 375 | if ( converter_.null() ) |
---|
| 376 | // no conversion |
---|
| 377 | return v ; |
---|
| 378 | else { |
---|
| 379 | Vector<Double> v2 = (*converter_)( v ).getAngle().getValue() ; |
---|
| 380 | if ( v2[0] < 0.0 && v[0] >= 0.0 ) |
---|
| 381 | v2[0] = 2.0 * M_PI + v2[0] ; |
---|
| 382 | return v2 ; |
---|
[1757] | 383 | } |
---|
[2643] | 384 | } |
---|
| 385 | |
---|
| 386 | void NROReader::initConvert( int icoord, double t, char *epoch ) |
---|
| 387 | { |
---|
| 388 | if ( icoord == 0 && strncmp( epoch, "J2000", 5 ) == 0 ) |
---|
| 389 | // no conversion |
---|
| 390 | return ; |
---|
| 391 | |
---|
| 392 | if ( converter_.null() || icoord != coord_ ) { |
---|
| 393 | LogIO os( LogOrigin( "NROReader", "initConvert()", WHERE ) ) ; |
---|
| 394 | coord_ = icoord ; |
---|
| 395 | if ( coord_ == 0 ) { |
---|
| 396 | // RADEC (B1950) -> RADEC (J2000) |
---|
| 397 | os << "Creating converter from RADEC (B1950) to RADEC (J2000)" << LogIO::POST ; |
---|
| 398 | converter_ = new MDirection::Convert( MDirection::B1950, |
---|
| 399 | MDirection::J2000 ) ; |
---|
[1757] | 400 | } |
---|
[2643] | 401 | else if ( coord_ == 1 ) { |
---|
| 402 | // LB -> RADEC (J2000) |
---|
| 403 | os << "Creating converter from GALACTIC to RADEC (J2000)" << LogIO::POST ; |
---|
| 404 | converter_ = new MDirection::Convert( MDirection::GALACTIC, |
---|
| 405 | MDirection::J2000 ) ; |
---|
[1757] | 406 | } |
---|
[2643] | 407 | else { |
---|
| 408 | // coord_ == 2 |
---|
| 409 | // AZEL -> RADEC (J2000) |
---|
| 410 | os << "Creating converter from AZEL to RADEC (J2000)" << LogIO::POST ; |
---|
| 411 | if ( mf_.null() ) { |
---|
| 412 | mf_ = new MeasFrame() ; |
---|
| 413 | vector<double> antpos = getAntennaPosition() ; |
---|
| 414 | Vector<Quantity> qantpos( 3 ) ; |
---|
| 415 | for ( int ip = 0 ; ip < 3 ; ip++ ) |
---|
| 416 | qantpos[ip] = Quantity( antpos[ip], "m" ) ; |
---|
[2761] | 417 | mp_ = MPosition( MVPosition( qantpos ), MPosition::ITRF ) ; |
---|
| 418 | mf_->set( mp_ ) ; |
---|
[2643] | 419 | } |
---|
| 420 | converter_ = new MDirection::Convert( MDirection::AZEL, |
---|
| 421 | MDirection::Ref(MDirection::J2000, |
---|
| 422 | *mf_ ) ) ; |
---|
| 423 | } |
---|
[1757] | 424 | } |
---|
| 425 | |
---|
[2643] | 426 | if ( coord_ == 2 ) { |
---|
[2761] | 427 | me_ = MEpoch( Quantity( t, "d" ), MEpoch::UTC ) ; |
---|
| 428 | mf_->set( me_ ) ; |
---|
[2643] | 429 | } |
---|
[1757] | 430 | } |
---|
| 431 | |
---|
| 432 | int NROReader::getHeaderInfo( Int &nchan, |
---|
| 433 | Int &npol, |
---|
| 434 | Int &nif, |
---|
| 435 | Int &nbeam, |
---|
| 436 | String &observer, |
---|
| 437 | String &project, |
---|
| 438 | String &obstype, |
---|
| 439 | String &antname, |
---|
| 440 | Vector<Double> &antpos, |
---|
| 441 | Float &equinox, |
---|
| 442 | String &freqref, |
---|
| 443 | Double &reffreq, |
---|
| 444 | Double &bw, |
---|
| 445 | Double &utc, |
---|
| 446 | String &fluxunit, |
---|
| 447 | String &epoch, |
---|
| 448 | String &poltype ) |
---|
| 449 | { |
---|
| 450 | nchan = dataset_->getNUMCH() ; |
---|
| 451 | //cout << "nchan = " << nchan << endl ; |
---|
| 452 | npol = getPolarizationNum() ; |
---|
| 453 | //cout << "npol = " << npol << endl ; |
---|
| 454 | observer = dataset_->getOBSVR() ; |
---|
| 455 | //cout << "observer = " << observer << endl ; |
---|
| 456 | project = dataset_->getPROJ() ; |
---|
| 457 | //cout << "project = " << project << endl ; |
---|
| 458 | obstype = dataset_->getSWMOD() ; |
---|
| 459 | //cout << "obstype = " << obstype << endl ; |
---|
| 460 | antname = dataset_->getSITE() ; |
---|
| 461 | //cout << "antname = " << antname << endl ; |
---|
| 462 | // TODO: should be investigated antenna position since there are |
---|
| 463 | // no corresponding information in the header |
---|
| 464 | // 2008/11/13 Takeshi Nakazato |
---|
| 465 | // |
---|
| 466 | // INFO: tentative antenna posiiton is obtained for NRO 45m from ITRF website |
---|
| 467 | // 2008/11/26 Takeshi Nakazato |
---|
| 468 | vector<double> pos = getAntennaPosition() ; |
---|
| 469 | antpos = pos ; |
---|
| 470 | //cout << "antpos = " << antpos << endl ; |
---|
| 471 | string eq = dataset_->getEPOCH() ; |
---|
[2200] | 472 | // if ( eq.compare( 0, 5, "B1950" ) == 0 ) |
---|
| 473 | // equinox = 1950.0 ; |
---|
| 474 | // else if ( eq.compare( 0, 5, "J2000" ) == 0 ) |
---|
| 475 | // equinox = 2000.0 ; |
---|
| 476 | // equinox is always 2000.0 |
---|
| 477 | equinox = 2000.0 ; |
---|
[1757] | 478 | //cout << "equinox = " << equinox << endl ; |
---|
| 479 | string vref = dataset_->getVREF() ; |
---|
| 480 | if ( vref.compare( 0, 3, "LSR" ) == 0 ) { |
---|
| 481 | if ( vref.size() == 3 ) { |
---|
| 482 | vref.append( "K" ) ; |
---|
| 483 | } |
---|
| 484 | else { |
---|
| 485 | vref[3] = 'K' ; |
---|
| 486 | } |
---|
| 487 | } |
---|
[2761] | 488 | else if ( vref.compare( 0, 3, "GAL" ) == 0 ) { |
---|
| 489 | vref = "GALACTO" ; |
---|
| 490 | } |
---|
| 491 | else if (vref.compare( 0, 3, "HEL" ) == 0 ) { |
---|
| 492 | os_.origin( LogOrigin( "NROReader", "getHeaderInfo", WHERE ) ) ; |
---|
| 493 | os_ << LogIO::WARN << "Heliocentric frame is not supported. Use Barycentric frame instead." << LogIO::POST ; |
---|
| 494 | vref = "BARY" ; |
---|
| 495 | } |
---|
[1868] | 496 | //freqref = vref ; |
---|
[2198] | 497 | //freqref = "LSRK" ; |
---|
[2761] | 498 | //freqref = "REST" ; |
---|
| 499 | freqref = freqRefFromVREF_ ? vref : "REST" ; |
---|
[1757] | 500 | //cout << "freqref = " << freqref << endl ; |
---|
[2766] | 501 | const NRODataRecord *record = dataset_->getRecord( 0 ) ; |
---|
[2761] | 502 | reffreq = record->FREQ0 ; // rest frequency |
---|
| 503 | |
---|
[1757] | 504 | //cout << "reffreq = " << reffreq << endl ; |
---|
| 505 | bw = dataset_->getBEBW()[0] ; |
---|
| 506 | //cout << "bw = " << bw << endl ; |
---|
| 507 | utc = getStartTime() ; |
---|
| 508 | //cout << "utc = " << utc << endl ; |
---|
| 509 | fluxunit = "K" ; |
---|
| 510 | //cout << "fluxunit = " << fluxunit << endl ; |
---|
| 511 | epoch = "UTC" ; |
---|
| 512 | //cout << "epoch = " << epoch << endl ; |
---|
| 513 | string poltp = dataset_->getPOLTP()[0] ; |
---|
| 514 | //cout << "poltp = '" << poltp << "'" << endl ; |
---|
| 515 | if ( poltp == "" || poltp[0] == ' ' ) |
---|
| 516 | //poltp = "None" ; |
---|
| 517 | poltp = "linear" ; // if no polarization type specified, set to "linear" |
---|
| 518 | //else if ( strcmp( poltp, "LINR" ) == 0 ) |
---|
| 519 | else if ( poltp.compare( 0, 1, "LINR", 0, 1 ) == 0 ) |
---|
| 520 | poltp = "linear" ; |
---|
| 521 | //else if ( strcmp( poltp, "CIRL" ) == 0 ) |
---|
| 522 | else if ( poltp.compare( 0, 1, "CIRL", 0, 1 ) == 0 ) |
---|
| 523 | poltp = "circular" ; |
---|
| 524 | poltype = poltp ; |
---|
| 525 | //cout << "poltype = " << poltype << endl ; |
---|
| 526 | |
---|
[2154] | 527 | //vector<Bool> ifs = getIFs() ; |
---|
| 528 | //nif = ifs.size() ; |
---|
| 529 | nif = getNumIF() ; |
---|
[1757] | 530 | //cout << "nif = " << nif << endl ; |
---|
| 531 | |
---|
[2154] | 532 | //vector<Bool> beams = getBeams() ; |
---|
| 533 | //nbeam = beams.size() ; |
---|
| 534 | nbeam = getNumBeam() ; |
---|
[1757] | 535 | //cout << "nbeam = " << nbeam << endl ; |
---|
| 536 | |
---|
| 537 | return 0 ; |
---|
| 538 | } |
---|
| 539 | |
---|
| 540 | string NROReader::getScanType( int i ) |
---|
| 541 | { |
---|
[2766] | 542 | const NRODataRecord *record = dataset_->getRecord( i ) ; |
---|
[1757] | 543 | string s = record->SCANTP ; |
---|
| 544 | |
---|
| 545 | return s ; |
---|
| 546 | } |
---|
| 547 | |
---|
| 548 | int NROReader::getScanInfo( int irow, |
---|
| 549 | uInt &scanno, |
---|
| 550 | uInt &cycleno, |
---|
[2201] | 551 | uInt &ifno, |
---|
[1757] | 552 | uInt &beamno, |
---|
| 553 | uInt &polno, |
---|
| 554 | vector<double> &freqs, |
---|
| 555 | Vector<Double> &restfreq, |
---|
| 556 | uInt &refbeamno, |
---|
| 557 | Double &scantime, |
---|
| 558 | Double &interval, |
---|
| 559 | String &srcname, |
---|
| 560 | String &fieldname, |
---|
[2289] | 561 | Vector<Float> &spectra, |
---|
| 562 | Vector<uChar> &flagtra, |
---|
| 563 | Vector<Float> &tsys, |
---|
| 564 | Vector<Double> &direction, |
---|
[1757] | 565 | Float &azimuth, |
---|
| 566 | Float &elevation, |
---|
| 567 | Float ¶ngle, |
---|
| 568 | Float &opacity, |
---|
| 569 | uInt &tcalid, |
---|
| 570 | Int &fitid, |
---|
| 571 | uInt &focusid, |
---|
| 572 | Float &temperature, |
---|
| 573 | Float &pressure, |
---|
| 574 | Float &humidity, |
---|
| 575 | Float &windvel, |
---|
| 576 | Float &winddir, |
---|
| 577 | Double &srcvel, |
---|
[2761] | 578 | Vector<Double> &/*propermotion*/, |
---|
[1757] | 579 | Vector<Double> &srcdir, |
---|
[2761] | 580 | Vector<Double> &/*scanrate*/ ) |
---|
[1757] | 581 | { |
---|
[2289] | 582 | static const IPosition oneByOne( 1, 1 ); |
---|
| 583 | |
---|
[1757] | 584 | // DEBUG |
---|
| 585 | //cout << "NROReader::getScanInfo() irow = " << irow << endl ; |
---|
| 586 | // |
---|
| 587 | NRODataRecord *record = dataset_->getRecord( irow ) ; |
---|
| 588 | |
---|
| 589 | // scanno |
---|
| 590 | scanno = (uInt)(record->ISCAN) ; |
---|
| 591 | //cout << "scanno = " << scanno << endl ; |
---|
| 592 | |
---|
| 593 | // cycleno |
---|
| 594 | cycleno = 0 ; |
---|
| 595 | //cout << "cycleno = " << cycleno << endl ; |
---|
| 596 | |
---|
[2201] | 597 | // beamno and ifno |
---|
[2158] | 598 | string rxname = dataset_->getRX()[0] ; |
---|
| 599 | if ( rxname.find("MULT2") != string::npos ) { |
---|
| 600 | string arryt = string( record->ARRYT ) ; |
---|
[2777] | 601 | beamno = dataset_->getSortedArrayId( arryt ) ; |
---|
[2201] | 602 | ifno = 0 ; |
---|
[2158] | 603 | } |
---|
| 604 | else { |
---|
| 605 | beamno = 0 ; |
---|
[2201] | 606 | string arryt = string( record->ARRYT ) ; |
---|
[2777] | 607 | ifno = dataset_->getSortedArrayId( arryt ) ; |
---|
[2158] | 608 | } |
---|
[1757] | 609 | //cout << "beamno = " << beamno << endl ; |
---|
| 610 | |
---|
| 611 | // polno |
---|
[2434] | 612 | polno = dataset_->getPolNo( irow ) ; |
---|
[1757] | 613 | //cout << "polno = " << polno << endl ; |
---|
| 614 | |
---|
| 615 | // freqs (for IFNO and FREQ_ID) |
---|
| 616 | //freqs = getFrequencies( irow ) ; |
---|
| 617 | freqs = dataset_->getFrequencies( irow ) ; |
---|
| 618 | //cout << "freqs = [" << freqs[0] << ", " << freqs[1] << ", " << freqs[2] << "]" << endl ; |
---|
| 619 | |
---|
[2761] | 620 | if ( freqRefFromVREF_ ) { |
---|
| 621 | freqs = shiftFrequency( freqs, |
---|
| 622 | dataset_->getURVEL(), |
---|
| 623 | dataset_->getVDEF() ) ; |
---|
| 624 | } |
---|
| 625 | |
---|
[1757] | 626 | // restfreq (for MOLECULE_ID) |
---|
[2289] | 627 | restfreq.resize( oneByOne ) ; |
---|
| 628 | restfreq[0] = record->FREQ0 ; |
---|
[1757] | 629 | //cout << "restfreq = " << rf << endl ; |
---|
| 630 | |
---|
| 631 | // refbeamno |
---|
| 632 | refbeamno = 0 ; |
---|
| 633 | //cout << "refbeamno = " << refbeamno << endl ; |
---|
| 634 | |
---|
| 635 | // scantime |
---|
[2156] | 636 | //scantime = Double( dataset_->getStartIntTime( irow ) ) ; |
---|
| 637 | scantime = Double( dataset_->getScanTime( irow ) ) ; |
---|
[1757] | 638 | //cout << "scantime = " << scantime << endl ; |
---|
| 639 | |
---|
| 640 | // interval |
---|
| 641 | interval = Double( dataset_->getIPTIM() ) ; |
---|
| 642 | //cout << "interval = " << interval << endl ; |
---|
| 643 | |
---|
| 644 | // srcname |
---|
| 645 | srcname = String( dataset_->getOBJ() ) ; |
---|
| 646 | //cout << "srcname = " << srcname << endl ; |
---|
| 647 | |
---|
| 648 | // fieldname |
---|
| 649 | fieldname = String( dataset_->getOBJ() ) ; |
---|
| 650 | //cout << "fieldname = " << fieldname << endl ; |
---|
| 651 | |
---|
| 652 | // spectra |
---|
| 653 | vector<double> spec = dataset_->getSpectrum( irow ) ; |
---|
[2289] | 654 | spectra.resize( spec.size() ) ; |
---|
[2761] | 655 | //int index = 0 ; |
---|
[2643] | 656 | Bool b ; |
---|
| 657 | Float *fp = spectra.getStorage( b ) ; |
---|
| 658 | Float *wp = fp ; |
---|
| 659 | for ( vector<double>::iterator i = spec.begin() ; |
---|
| 660 | i != spec.end() ; i++ ) { |
---|
| 661 | *wp = *i ; |
---|
| 662 | wp++ ; |
---|
[1757] | 663 | } |
---|
[2643] | 664 | spectra.putStorage( fp, b ) ; |
---|
[1757] | 665 | //cout << "spec.size() = " << spec.size() << endl ; |
---|
| 666 | |
---|
| 667 | // flagtra |
---|
[2489] | 668 | bool setValue = !( flagtra.nelements() == spectra.nelements() ) ; |
---|
| 669 | if ( setValue ) { |
---|
| 670 | //cout << "flagtra resized. reset values..." << endl ; |
---|
[2643] | 671 | flagtra.resize( spectra.nelements() ) ; |
---|
[2489] | 672 | flagtra.set( 0 ) ; |
---|
| 673 | } |
---|
[1757] | 674 | //cout << "flag.size() = " << flag.size() << endl ; |
---|
| 675 | |
---|
| 676 | // tsys |
---|
[2289] | 677 | tsys.resize( oneByOne ) ; |
---|
| 678 | tsys[0] = record->TSYS ; |
---|
[1757] | 679 | //cout << "tsys[0] = " << tsys[0] << endl ; |
---|
| 680 | |
---|
| 681 | // direction |
---|
| 682 | direction = getDirection( irow ) ; |
---|
| 683 | //cout << "direction = [" << direction[0] << ", " << direction[1] << "]" << endl ; |
---|
| 684 | |
---|
| 685 | // azimuth |
---|
| 686 | azimuth = record->RAZ ; |
---|
| 687 | //cout << "azimuth = " << azimuth << endl ; |
---|
| 688 | |
---|
| 689 | // elevation |
---|
| 690 | elevation = record->REL ; |
---|
| 691 | //cout << "elevation = " << elevation << endl ; |
---|
| 692 | |
---|
| 693 | // parangle |
---|
| 694 | parangle = 0.0 ; |
---|
| 695 | //cout << "parangle = " << parangle << endl ; |
---|
| 696 | |
---|
| 697 | // opacity |
---|
| 698 | opacity = 0.0 ; |
---|
| 699 | //cout << "opacity = " << opacity << endl ; |
---|
| 700 | |
---|
| 701 | // tcalid |
---|
| 702 | tcalid = 0 ; |
---|
| 703 | //cout << "tcalid = " << tcalid << endl ; |
---|
| 704 | |
---|
| 705 | // fitid |
---|
| 706 | fitid = -1 ; |
---|
| 707 | //cout << "fitid = " << fitid << endl ; |
---|
| 708 | |
---|
| 709 | // focusid |
---|
| 710 | focusid = 0 ; |
---|
| 711 | //cout << "focusid = " << focusid << endl ; |
---|
| 712 | |
---|
| 713 | // temperature (for WEATHER_ID) |
---|
| 714 | temperature = Float( record->TEMP ) ; |
---|
| 715 | //cout << "temperature = " << temperature << endl ; |
---|
| 716 | |
---|
| 717 | // pressure (for WEATHER_ID) |
---|
| 718 | pressure = Float( record->PATM ) ; |
---|
| 719 | //cout << "pressure = " << pressure << endl ; |
---|
| 720 | |
---|
| 721 | // humidity (for WEATHER_ID) |
---|
| 722 | humidity = Float( record->PH2O ) ; |
---|
| 723 | //cout << "humidity = " << humidity << endl ; |
---|
| 724 | |
---|
| 725 | // windvel (for WEATHER_ID) |
---|
| 726 | windvel = Float( record->VWIND ) ; |
---|
| 727 | //cout << "windvel = " << windvel << endl ; |
---|
| 728 | |
---|
| 729 | // winddir (for WEATHER_ID) |
---|
| 730 | winddir = Float( record->DWIND ) ; |
---|
| 731 | //cout << "winddir = " << winddir << endl ; |
---|
| 732 | |
---|
| 733 | // srcvel |
---|
| 734 | srcvel = dataset_->getURVEL() ; |
---|
| 735 | //cout << "srcvel = " << srcvel << endl ; |
---|
| 736 | |
---|
| 737 | // propermotion |
---|
[2289] | 738 | // do nothing |
---|
[1757] | 739 | |
---|
| 740 | // srcdir |
---|
| 741 | srcdir = getSourceDirection() ; |
---|
| 742 | //cout << "srcdir = [" << srcdir[0] << ", " << srcdir[1] << endl ; |
---|
| 743 | |
---|
| 744 | // scanrate |
---|
[2289] | 745 | // do nothing |
---|
[1757] | 746 | |
---|
| 747 | return 0 ; |
---|
| 748 | } |
---|
| 749 | |
---|
| 750 | Int NROReader::getRowNum() |
---|
| 751 | { |
---|
| 752 | return dataset_->getRowNum() ; |
---|
| 753 | } |
---|
[2761] | 754 | |
---|
| 755 | vector<double> NROReader::shiftFrequency( const vector<double> &f, |
---|
| 756 | const double &v, |
---|
| 757 | const string &vdef ) |
---|
| 758 | { |
---|
| 759 | vector<double> r( f ) ; |
---|
| 760 | double factor = v / 2.99792458e8 ; |
---|
| 761 | if ( vdef.compare( 0, 3, "RAD" ) == 0 ) { |
---|
| 762 | factor = 1.0 / ( 1.0 + factor ) ; |
---|
| 763 | r[1] *= factor ; |
---|
| 764 | r[2] *= factor ; |
---|
| 765 | } |
---|
| 766 | else if ( vdef.compare( 0, 3, "OPT" ) == 0 ) { |
---|
| 767 | factor += 1.0 ; |
---|
| 768 | r[1] *= factor ; |
---|
| 769 | r[2] *= factor ; |
---|
| 770 | } |
---|
| 771 | else { |
---|
| 772 | cout << "vdef=" << vdef << " is not supported." << endl; |
---|
| 773 | } |
---|
| 774 | return r ; |
---|
| 775 | } |
---|