Changeset 1757 for branches/alma/external/atnf/PKSIO/PKSFITSreader.cc
- Timestamp:
- 06/09/10 19:03:06 (14 years ago)
- Location:
- branches/alma
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/alma
-
Property
svn:ignore
set to
.sconf_temp
.sconsign.dblite
-
Property
svn:mergeinfo
set to
/branches/asap-3.x merged eligible
-
Property
svn:ignore
set to
-
branches/alma/external/atnf/PKSIO/PKSFITSreader.cc
r1453 r1757 2 2 //# PKSFITSreader.cc: Class to read Parkes multibeam data from a FITS file. 3 3 //#--------------------------------------------------------------------------- 4 //# Copyright (C) 2000-20065 //# Associated Universities, Inc. Washington DC, USA.4 //# livedata - processing pipeline for single-dish, multibeam spectral data. 5 //# Copyright (C) 2000-2009, Australia Telescope National Facility, CSIRO 6 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. 7 //# This file is part of livedata. 11 8 //# 12 //# This library is distributed in the hope that it will be useful, but13 //# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY14 //# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public15 //# License for more details.9 //# livedata is free software: you can redistribute it and/or modify it under 10 //# the terms of the GNU General Public License as published by the Free 11 //# Software Foundation, either version 3 of the License, or (at your option) 12 //# any later version. 16 13 //# 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. 14 //# livedata is distributed in the hope that it will be useful, but WITHOUT 15 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 17 //# more details. 20 18 //# 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 19 //# You should have received a copy of the GNU General Public License along 20 //# with livedata. If not, see <http://www.gnu.org/licenses/>. 27 21 //# 28 //# $Id$ 22 //# Correspondence concerning livedata may be directed to: 23 //# Internet email: mcalabre@atnf.csiro.au 24 //# Postal address: Dr. Mark Calabretta 25 //# Australia Telescope National Facility, CSIRO 26 //# PO Box 76 27 //# Epping NSW 1710 28 //# AUSTRALIA 29 //# 30 //# http://www.atnf.csiro.au/computing/software/livedata.html 31 //# $Id: PKSFITSreader.cc,v 19.23 2009-09-29 07:33:38 cal103 Exp $ 29 32 //#--------------------------------------------------------------------------- 30 33 //# Original: 2000/08/02, Mark Calabretta, ATNF … … 34 37 #include <atnf/PKSIO/SDFITSreader.h> 35 38 #include <atnf/PKSIO/PKSFITSreader.h> 36 #include <atnf/PKSIO/PKSMBrecord.h> 37 39 #include <atnf/PKSIO/PKSrecord.h> 40 41 #include <casa/stdio.h> 38 42 #include <casa/Arrays/Array.h> 39 43 #include <casa/BasicMath/Math.h> 40 44 #include <casa/Quanta/MVTime.h> 41 42 #include <casa/stdio.h> 45 #include <casa/Logging/LogIO.h> 43 46 44 47 //----------------------------------------------- PKSFITSreader::PKSFITSreader … … 76 79 Int PKSFITSreader::open( 77 80 const String fitsName, 81 const String antenna, 78 82 Vector<Bool> &beams, 79 83 Vector<Bool> &IFs, … … 86 90 int extraSysCal, haveBase_, *haveXPol_, haveSpectra_, nBeam, *nChan_, 87 91 nIF, *nPol_, status; 88 if ((status = cReader->open((char *)fitsName.chars(), nBeam, cBeams, nIF, 89 cIFs, nChan_, nPol_, haveXPol_, haveBase_, 90 haveSpectra_, extraSysCal))) { 92 status = cReader->open((char *)fitsName.chars(), nBeam, cBeams, nIF, cIFs, 93 nChan_, nPol_, haveXPol_, haveBase_, haveSpectra_, 94 extraSysCal); 95 //logMsg(cReader->getMsg()); 96 //cReader->clearMsg(); 97 if (status) { 91 98 return status; 92 99 } … … 138 145 Vector<Double> &antPosition, 139 146 String &obsType, 147 String &bunit, 140 148 Float &equinox, 141 149 String &dopplerFrame, 142 150 Double &mjd, 143 151 Double &refFreq, 144 Double &bandwidth ,145 String &fluxunit) 146 { 147 char datobs[32], dopplerFrame_[32], observer_[32], obsType_[32],148 project_[32], radecsys[32], telescope[32];152 Double &bandwidth) 153 { 154 char bunit_[32], datobs[32], dopplerFrame_[32], observer_[32], 155 obsType_[32], project_[32], radecsys[32], telescope[32]; 156 int status; 149 157 float equinox_; 150 158 double antPos[3], utc; 151 159 152 if (cReader->getHeader(observer_, project_, telescope, antPos, obsType_, 153 equinox_, radecsys, dopplerFrame_, datobs, utc, 154 refFreq, bandwidth)) { 160 status = cReader->getHeader(observer_, project_, telescope, antPos, 161 obsType_, bunit_, equinox_, radecsys, 162 dopplerFrame_, datobs, utc, refFreq, bandwidth); 163 //logMsg(cReader->getMsg()); 164 //cReader->clearMsg(); 165 if (status) { 155 166 return 1; 156 167 } 157 168 158 fluxunit = "";159 169 observer = trim(observer_); 160 170 project = trim(project_); … … 165 175 antPosition(2) = antPos[2]; 166 176 obsType = trim(obsType_); 177 bunit = trim(bunit_); 167 178 equinox = equinox_; 168 179 dopplerFrame = trim(dopplerFrame_); … … 188 199 double *startfreq, *endfreq; 189 200 190 Int status; 191 if (!(status = cReader->getFreqInfo(nIF, startfreq, endfreq))) { 201 Int status = cReader->getFreqInfo(nIF, startfreq, endfreq); 202 203 //logMsg(cReader->getMsg()); 204 //cReader->clearMsg(); 205 if (!status) { 192 206 startFreq.takeStorage(IPosition(1,nIF), startfreq, TAKE_OVER); 193 207 endFreq.takeStorage(IPosition(1,nIF), endfreq, TAKE_OVER); … … 209 223 const Bool getSpectra, 210 224 const Bool getXPol, 211 const Bool getFeedPos) 225 const Bool getFeedPos, 226 const Bool getPointing, 227 const Int coordSys) 212 228 { 213 229 // Apply beam selection. … … 277 293 cGetXPol = getXPol; 278 294 cGetFeedPos = getFeedPos; 295 cGetPointing = getPointing; 296 cCoordSys = coordSys; 279 297 280 298 uInt maxNChan = cReader->select(start, end, ref, cGetSpectra, cGetXPol, 281 cGetFeedPos); 299 cGetFeedPos, cGetPointing, cCoordSys); 300 //logMsg(cReader->getMsg()); 301 //cReader->clearMsg(); 282 302 283 303 delete [] end; … … 302 322 double* posns; 303 323 304 Int status; 305 if (!(status = cReader->findRange(nRow, nSel, dateSpan, utcSpan, posns))) { 324 Int status = cReader->findRange(nRow, nSel, dateSpan, utcSpan, posns); 325 //logMsg(cReader->getMsg()); 326 //cReader->clearMsg(); 327 328 if (!status) { 306 329 timeSpan.resize(2); 307 330 … … 322 345 // Read the next data record. 323 346 324 Int PKSFITSreader::read( 325 Int &scanNo, 326 Int &cycleNo, 327 Double &mjd, 328 Double &interval, 329 String &fieldName, 330 String &srcName, 331 Vector<Double> &srcDir, 332 Vector<Double> &srcPM, 333 Double &srcVel, 334 String &obsType, 335 Int &IFno, 336 Double &refFreq, 337 Double &bandwidth, 338 Double &freqInc, 339 Vector<Double> &restFreq, 340 Vector<Float> &tcal, 341 String &tcalTime, 342 Float &azimuth, 343 Float &elevation, 344 Float &parAngle, 345 Float &focusAxi, 346 Float &focusTan, 347 Float &focusRot, 348 Float &temperature, 349 Float &pressure, 350 Float &humidity, 351 Float &windSpeed, 352 Float &windAz, 353 Int &refBeam, 354 Int &beamNo, 355 Vector<Double> &direction, 356 Vector<Double> &scanRate, 357 Vector<Float> &tsys, 358 Vector<Float> &sigma, 359 Vector<Float> &calFctr, 360 Matrix<Float> &baseLin, 361 Matrix<Float> &baseSub, 362 Matrix<Float> &spectra, 363 Matrix<uChar> &flagged, 364 Complex &xCalFctr, 365 Vector<Complex> &xPol) 366 { 367 Int status; 368 369 if ((status = cReader->read(cMBrec))) { 347 Int PKSFITSreader::read(PKSrecord &pksrec) 348 { 349 Int status = cReader->read(cMBrec); 350 //logMsg(cReader->getMsg()); 351 //cReader->clearMsg(); 352 353 if (status) { 370 354 if (status != -1) { 371 355 status = 1; … … 379 363 uInt nPol = cMBrec.nPol[0]; 380 364 381 scanNo = cMBrec.scanNo; 382 cycleNo = cMBrec.cycleNo; 365 pksrec.scanNo = cMBrec.scanNo; 366 pksrec.cycleNo = cMBrec.cycleNo; 367 pksrec.polNo = cMBrec.polNo ; 383 368 384 369 // Extract MJD. 385 370 Int day, month, year; 386 sscanf(cMBrec.datobs, "%4d-%2d-%2d", &year, &month, &day); 387 mjd = MVTime(year, month, Double(day)).day() + cMBrec.utc/86400.0; 388 389 interval = cMBrec.exposure; 390 391 fieldName = trim(cMBrec.srcName); 392 srcName = fieldName; 393 srcDir(0) = cMBrec.srcRA; 394 srcDir(1) = cMBrec.srcDec; 395 srcPM(0) = 0.0; 396 srcPM(1) = 0.0; 397 srcVel = 0.0; 398 obsType = trim(cMBrec.obsType); 399 400 IFno = cMBrec.IFno[0]; 371 if ( strstr( cMBrec.datobs, "T" ) == NULL ) { 372 sscanf(cMBrec.datobs, "%4d-%2d-%2d", &year, &month, &day); 373 pksrec.mjd = MVTime(year, month, Double(day)).day() + cMBrec.utc/86400.0; 374 } 375 else { 376 Double dd, hour, min, sec ; 377 sscanf( cMBrec.datobs, "%4d-%2d-%2lfT%lf:%lf:%lf", &year, &month, &dd, &hour, &min, &sec ) ; 378 dd = dd + ( hour * 3600.0 + min * 60.0 + sec ) / 86400.0 ; 379 pksrec.mjd = MVTime(year, month, dd).day() ; 380 } 381 382 pksrec.interval = cMBrec.exposure; 383 384 pksrec.fieldName = trim(cMBrec.srcName); 385 pksrec.srcName = pksrec.fieldName; 386 387 int namelen = pksrec.srcName.length() ; 388 if ( namelen > 4 ) { 389 String srcsub = pksrec.srcName.substr( namelen-4, 4 ) ; 390 if ( srcsub.find( "_psc" ) != string::npos ) { 391 pksrec.fieldName = pksrec.srcName.substr( 0, namelen-4 ) ; 392 pksrec.srcName = pksrec.fieldName + "_ps_calon" ; 393 } 394 else if ( srcsub.find( "_pso" ) != string::npos ) { 395 pksrec.fieldName = pksrec.srcName.substr( 0, namelen-4 ) ; 396 pksrec.srcName = pksrec.fieldName + "_ps" ; 397 } 398 else if ( srcsub.find( "_prc" ) != string::npos ) { 399 pksrec.fieldName = pksrec.srcName.substr( 0, namelen-4 ) ; 400 pksrec.srcName = pksrec.fieldName + "_psr_calon" ; 401 } 402 else if ( srcsub.find( "_pro" ) != string::npos ) { 403 pksrec.fieldName = pksrec.srcName.substr( 0, namelen-4 ) ; 404 pksrec.srcName = pksrec.fieldName + "_psr" ; 405 } 406 else if ( srcsub.find( "_fsc" ) != string::npos ) { 407 pksrec.fieldName = pksrec.srcName.substr( 0, namelen-4 ) ; 408 pksrec.srcName = pksrec.fieldName + "_fs_calon" ; 409 } 410 else if ( srcsub.find( "_fso" ) != string::npos ) { 411 pksrec.fieldName = pksrec.srcName.substr( 0, namelen-4 ) ; 412 pksrec.srcName = pksrec.fieldName + "_fs" ; 413 } 414 else if ( srcsub.find( "_frc" ) != string::npos ) { 415 pksrec.fieldName = pksrec.srcName.substr( 0, namelen-4 ) ; 416 pksrec.srcName = pksrec.fieldName + "_fsr_calon" ; 417 } 418 else if ( srcsub.find( "_fro" ) != string::npos ) { 419 pksrec.fieldName = pksrec.srcName.substr( 0, namelen-4 ) ; 420 pksrec.srcName = pksrec.fieldName + "_fsr" ; 421 } 422 else if ( srcsub.find( "_nsc" ) != string::npos || srcsub.find( "_nrc" ) != string::npos ) { 423 pksrec.fieldName = pksrec.srcName.substr( 0, namelen-4 ) ; 424 pksrec.srcName = pksrec.fieldName + "_nod_calon" ; 425 } 426 else if ( srcsub.find( "_nso" ) != string::npos || srcsub.find( "_nro" ) != string::npos ) { 427 pksrec.fieldName = pksrec.srcName.substr( 0, namelen-4 ) ; 428 pksrec.srcName = pksrec.fieldName + "_nod" ; 429 } 430 } 431 432 pksrec.srcDir.resize(2); 433 pksrec.srcDir(0) = cMBrec.srcRA; 434 pksrec.srcDir(1) = cMBrec.srcDec; 435 436 pksrec.srcPM.resize(2); 437 pksrec.srcPM(0) = 0.0; 438 pksrec.srcPM(1) = 0.0; 439 pksrec.srcVel = cMBrec.srcVelocity; 440 pksrec.obsType = trim(cMBrec.obsType); 441 442 pksrec.IFno = cMBrec.IFno[0]; 401 443 Double chanWidth = fabs(cMBrec.fqDelt[0]); 402 refFreq = cMBrec.fqRefVal[0]; 403 bandwidth = chanWidth * nChan; 404 freqInc = cMBrec.fqDelt[0]; 405 //restFreq = cMBrec.restFreq; 406 restFreq.resize(1); 407 restFreq(0) = cMBrec.restFreq; 408 409 tcal.resize(nPol); 444 pksrec.refFreq = cMBrec.fqRefVal[0]; 445 pksrec.bandwidth = chanWidth * nChan; 446 pksrec.freqInc = cMBrec.fqDelt[0]; 447 pksrec.restFreq.resize(1) ; 448 pksrec.restFreq(0) = cMBrec.restFreq; 449 450 pksrec.tcal.resize(nPol); 410 451 for (uInt ipol = 0; ipol < nPol; ipol++) { 411 tcal(ipol) = cMBrec.tcal[0][ipol]; 412 } 413 tcalTime = trim(cMBrec.tcalTime); 414 azimuth = cMBrec.azimuth; 415 elevation = cMBrec.elevation; 416 parAngle = cMBrec.parAngle; 417 focusAxi = cMBrec.focusAxi; 418 focusTan = cMBrec.focusTan; 419 focusRot = cMBrec.focusRot; 420 421 temperature = cMBrec.temp; 422 pressure = cMBrec.pressure; 423 humidity = cMBrec.humidity; 424 windSpeed = cMBrec.windSpeed; 425 windAz = cMBrec.windAz; 426 427 refBeam = cMBrec.refBeam; 428 beamNo = cMBrec.beamNo; 429 430 direction(0) = cMBrec.ra; 431 direction(1) = cMBrec.dec; 432 scanRate(0) = cMBrec.raRate; 433 scanRate(1) = cMBrec.decRate; 434 435 tsys.resize(nPol); 436 sigma.resize(nPol); 437 calFctr.resize(nPol); 452 pksrec.tcal(ipol) = cMBrec.tcal[0][ipol]; 453 } 454 pksrec.tcalTime = trim(cMBrec.tcalTime); 455 pksrec.azimuth = cMBrec.azimuth; 456 pksrec.elevation = cMBrec.elevation; 457 pksrec.parAngle = cMBrec.parAngle; 458 459 pksrec.focusAxi = cMBrec.focusAxi; 460 pksrec.focusTan = cMBrec.focusTan; 461 pksrec.focusRot = cMBrec.focusRot; 462 463 pksrec.temperature = cMBrec.temp; 464 pksrec.pressure = cMBrec.pressure; 465 pksrec.humidity = cMBrec.humidity; 466 pksrec.windSpeed = cMBrec.windSpeed; 467 pksrec.windAz = cMBrec.windAz; 468 469 pksrec.refBeam = cMBrec.refBeam; 470 pksrec.beamNo = cMBrec.beamNo; 471 472 pksrec.direction.resize(2); 473 pksrec.direction(0) = cMBrec.ra; 474 pksrec.direction(1) = cMBrec.dec; 475 pksrec.pCode = cMBrec.pCode; 476 pksrec.rateAge = cMBrec.rateAge; 477 pksrec.scanRate.resize(2); 478 pksrec.scanRate(0) = cMBrec.raRate; 479 pksrec.scanRate(1) = cMBrec.decRate; 480 pksrec.paRate = cMBrec.paRate; 481 482 pksrec.tsys.resize(nPol); 483 pksrec.sigma.resize(nPol); 484 pksrec.calFctr.resize(nPol); 438 485 for (uInt ipol = 0; ipol < nPol; ipol++) { 439 tsys(ipol) = cMBrec.tsys[0][ipol]; 440 sigma(ipol) = tsys(ipol) / 0.81 / sqrt(interval * chanWidth); 441 calFctr(ipol) = cMBrec.calfctr[0][ipol]; 486 pksrec.tsys(ipol) = cMBrec.tsys[0][ipol]; 487 pksrec.sigma(ipol) = (pksrec.tsys(ipol) / 0.81) / 488 sqrt(pksrec.interval * chanWidth); 489 pksrec.calFctr(ipol) = cMBrec.calfctr[0][ipol]; 442 490 } 443 491 444 492 if (cMBrec.haveBase) { 445 baseLin.resize(2,nPol);446 baseSub.resize(9,nPol);493 pksrec.baseLin.resize(2,nPol); 494 pksrec.baseSub.resize(24,nPol); 447 495 448 496 for (uInt ipol = 0; ipol < nPol; ipol++) { 449 baseLin(0,ipol) = cMBrec.baseLin[0][ipol][0];450 baseLin(1,ipol) = cMBrec.baseLin[0][ipol][1];451 452 for (uInt j = 0; j < 9; j++) {453 baseSub(j,ipol) = cMBrec.baseSub[0][ipol][j];497 pksrec.baseLin(0,ipol) = cMBrec.baseLin[0][ipol][0]; 498 pksrec.baseLin(1,ipol) = cMBrec.baseLin[0][ipol][1]; 499 500 for (uInt j = 0; j < 24; j++) { 501 pksrec.baseSub(j,ipol) = cMBrec.baseSub[0][ipol][j]; 454 502 } 455 503 } 456 504 457 505 } else { 458 baseLin.resize(0,0);459 baseSub.resize(0,0);506 pksrec.baseLin.resize(0,0); 507 pksrec.baseSub.resize(0,0); 460 508 } 461 509 462 510 if (cGetSpectra && cMBrec.haveSpectra) { 463 spectra.resize(nChan,nPol); 464 spectra.takeStorage(IPosition(2,nChan,nPol), cMBrec.spectra[0], SHARE); 465 466 flagged.resize(nChan,nPol); 467 flagged.takeStorage(IPosition(2,nChan,nPol), cMBrec.flagged[0], SHARE); 511 pksrec.spectra.resize(nChan,nPol); 512 pksrec.spectra.takeStorage(IPosition(2,nChan,nPol), cMBrec.spectra[0], 513 SHARE); 514 515 pksrec.flagged.resize(nChan,nPol); 516 pksrec.flagged.takeStorage(IPosition(2,nChan,nPol), cMBrec.flagged[0], 517 SHARE); 468 518 469 519 } else { 470 spectra.resize(0,0);471 flagged.resize(0,0);520 pksrec.spectra.resize(0,0); 521 pksrec.flagged.resize(0,0); 472 522 } 473 523 474 524 if (cGetXPol) { 475 xCalFctr = Complex(cMBrec.xcalfctr[0][0], cMBrec.xcalfctr[0][1]); 476 xPol.resize(nChan); 477 xPol.takeStorage(IPosition(1,nChan), (Complex *)cMBrec.xpol[0], SHARE); 525 pksrec.xCalFctr = Complex(cMBrec.xcalfctr[0][0], 526 cMBrec.xcalfctr[0][1]); 527 pksrec.xPol.resize(nChan); 528 pksrec.xPol.takeStorage(IPosition(1,nChan), (Complex *)cMBrec.xpol[0], 529 SHARE); 478 530 } 479 531 … … 481 533 } 482 534 483 //-------------------------------------------------------- PKSFITSreader::read484 485 // Read the next data record, just the basics.486 487 Int PKSFITSreader::read(488 Int &IFno,489 Vector<Float> &tsys,490 Vector<Float> &calFctr,491 Matrix<Float> &baseLin,492 Matrix<Float> &baseSub,493 Matrix<Float> &spectra,494 Matrix<uChar> &flagged)495 {496 Int status;497 498 if ((status = cReader->read(cMBrec))) {499 if (status != -1) {500 status = 1;501 }502 503 return status;504 }505 506 IFno = cMBrec.IFno[0];507 508 uInt nChan = cMBrec.nChan[0];509 uInt nPol = cMBrec.nPol[0];510 511 tsys.resize(nPol);512 calFctr.resize(nPol);513 for (uInt ipol = 0; ipol < nPol; ipol++) {514 tsys(ipol) = cMBrec.tsys[0][ipol];515 calFctr(ipol) = cMBrec.calfctr[0][ipol];516 }517 518 if (cMBrec.haveBase) {519 baseLin.resize(2,nPol);520 baseSub.resize(9,nPol);521 522 for (uInt ipol = 0; ipol < nPol; ipol++) {523 baseLin(0,ipol) = cMBrec.baseLin[0][ipol][0];524 baseLin(1,ipol) = cMBrec.baseLin[0][ipol][1];525 526 for (uInt j = 0; j < 9; j++) {527 baseSub(j,ipol) = cMBrec.baseSub[0][ipol][j];528 }529 }530 531 } else {532 baseLin.resize(0,0);533 baseSub.resize(0,0);534 }535 536 if (cGetSpectra && cMBrec.haveSpectra) {537 spectra.resize(nChan,nPol);538 spectra.takeStorage(IPosition(2,nChan,nPol), cMBrec.spectra[0], SHARE);539 540 flagged.resize(nChan,nPol);541 flagged.takeStorage(IPosition(2,nChan,nPol), cMBrec.flagged[0], SHARE);542 543 } else {544 spectra.resize(0,0);545 flagged.resize(0,0);546 }547 548 return 0;549 }550 551 535 //------------------------------------------------------- PKSFITSreader::close 552 536 … … 556 540 { 557 541 cReader->close(); 542 //logMsg(cReader->getMsg()); 543 //cReader->clearMsg(); 558 544 } 559 545
Note: See TracChangeset
for help on using the changeset viewer.