Changeset 1452 for trunk/external/atnf/PKSIO/PKSFITSreader.cc
- Timestamp:
- 11/19/08 20:41:16 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/external/atnf/PKSIO/PKSFITSreader.cc
r1427 r1452 25 25 //# Charlottesville, VA 22903-2475 USA 26 26 //# 27 //# $Id: PKSFITSreader.cc,v 19. 14 2008-06-26 02:07:21cal103 Exp $27 //# $Id: PKSFITSreader.cc,v 19.21 2008-11-17 06:54:25 cal103 Exp $ 28 28 //#--------------------------------------------------------------------------- 29 29 //# Original: 2000/08/02, Mark Calabretta, ATNF 30 30 //#--------------------------------------------------------------------------- 31 31 32 #include <atnf/PKSIO/PKSmsg.h> 32 33 #include <atnf/PKSIO/MBFITSreader.h> 33 34 #include <atnf/PKSIO/SDFITSreader.h> 34 35 #include <atnf/PKSIO/PKSFITSreader.h> 35 #include <atnf/PKSIO/PKSMBrecord.h> 36 36 #include <atnf/PKSIO/PKSrecord.h> 37 38 #include <casa/stdio.h> 37 39 #include <casa/Arrays/Array.h> 38 40 #include <casa/BasicMath/Math.h> 39 41 #include <casa/Quanta/MVTime.h> 40 41 #include <casa/stdio.h>42 42 43 43 //----------------------------------------------- PKSFITSreader::PKSFITSreader … … 50 50 const Bool interpolate) 51 51 { 52 c FITSMBrec.setNIFs(1);52 cMBrec.setNIFs(1); 53 53 54 54 if (fitsType == "SDFITS") { … … 57 57 cReader = new MBFITSreader(retry, interpolate ? 1 : 0); 58 58 } 59 60 // By default, messages are written to stderr. 61 initMsg(); 59 62 } 60 63 … … 67 70 close(); 68 71 delete cReader; 72 } 73 74 //------------------------------------------------------ PKSFITSreader::setMsg 75 76 // Set message disposition. If fd is non-zero messages will be written 77 // to that file descriptor, else stored for retrieval by getMsg(). 78 79 Int PKSFITSreader::setMsg(FILE *fd) 80 { 81 PKSmsg::setMsg(fd); 82 cReader->setMsg(fd); 83 84 return 0; 69 85 } 70 86 … … 83 99 Bool &haveSpectra) 84 100 { 101 clearMsg(); 102 85 103 int extraSysCal, haveBase_, *haveXPol_, haveSpectra_, nBeam, *nChan_, 86 104 nIF, *nPol_, status; 87 if ((status = cReader->open((char *)fitsName.chars(), nBeam, cBeams, nIF, 88 cIFs, nChan_, nPol_, haveXPol_, haveBase_, 89 haveSpectra_, extraSysCal))) { 105 status = cReader->open((char *)fitsName.chars(), nBeam, cBeams, nIF, cIFs, 106 nChan_, nPol_, haveXPol_, haveBase_, haveSpectra_, 107 extraSysCal); 108 logMsg(cReader->getMsg()); 109 cReader->clearMsg(); 110 if (status) { 90 111 return status; 91 112 } … … 146 167 char bunit_[32], datobs[32], dopplerFrame_[32], observer_[32], 147 168 obsType_[32], project_[32], radecsys[32], telescope[32]; 169 int status; 148 170 float equinox_; 149 171 double antPos[3], utc; 150 172 151 if (cReader->getHeader(observer_, project_, telescope, antPos, obsType_, 152 bunit_, equinox_, radecsys, dopplerFrame_, 153 datobs, utc, refFreq, bandwidth)) { 173 status = cReader->getHeader(observer_, project_, telescope, antPos, 174 obsType_, bunit_, equinox_, radecsys, 175 dopplerFrame_, datobs, utc, refFreq, bandwidth); 176 logMsg(cReader->getMsg()); 177 cReader->clearMsg(); 178 if (status) { 154 179 return 1; 155 180 } … … 187 212 double *startfreq, *endfreq; 188 213 189 Int status; 190 if (!(status = cReader->getFreqInfo(nIF, startfreq, endfreq))) { 214 Int status = cReader->getFreqInfo(nIF, startfreq, endfreq); 215 216 logMsg(cReader->getMsg()); 217 cReader->clearMsg(); 218 if (!status) { 191 219 startFreq.takeStorage(IPosition(1,nIF), startfreq, TAKE_OVER); 192 220 endFreq.takeStorage(IPosition(1,nIF), endfreq, TAKE_OVER); … … 208 236 const Bool getSpectra, 209 237 const Bool getXPol, 210 const Bool getFeedPos)238 const Int coordSys) 211 239 { 212 240 // Apply beam selection. … … 275 303 cGetSpectra = getSpectra; 276 304 cGetXPol = getXPol; 277 c GetFeedPos = getFeedPos;305 cCoordSys = coordSys; 278 306 279 307 uInt maxNChan = cReader->select(start, end, ref, cGetSpectra, cGetXPol, 280 cGetFeedPos); 308 cCoordSys); 309 logMsg(cReader->getMsg()); 310 cReader->clearMsg(); 281 311 282 312 delete [] end; … … 301 331 double* posns; 302 332 303 Int status; 304 if (!(status = cReader->findRange(nRow, nSel, dateSpan, utcSpan, posns))) { 333 Int status = cReader->findRange(nRow, nSel, dateSpan, utcSpan, posns); 334 logMsg(cReader->getMsg()); 335 cReader->clearMsg(); 336 337 if (!status) { 305 338 timeSpan.resize(2); 306 339 … … 321 354 // Read the next data record. 322 355 323 Int PKSFITSreader::read(MBrecord &MBrec) 324 { 325 Int status; 326 327 if ((status = cReader->read(cFITSMBrec))) { 356 Int PKSFITSreader::read(PKSrecord &pksrec) 357 { 358 Int status = cReader->read(cMBrec); 359 logMsg(cReader->getMsg()); 360 cReader->clearMsg(); 361 362 if (status) { 328 363 if (status != -1) { 329 364 status = 1; … … 334 369 335 370 336 uInt nChan = c FITSMBrec.nChan[0];337 uInt nPol = c FITSMBrec.nPol[0];338 339 MBrec.scanNo = cFITSMBrec.scanNo;340 MBrec.cycleNo = cFITSMBrec.cycleNo;371 uInt nChan = cMBrec.nChan[0]; 372 uInt nPol = cMBrec.nPol[0]; 373 374 pksrec.scanNo = cMBrec.scanNo; 375 pksrec.cycleNo = cMBrec.cycleNo; 341 376 342 377 // Extract MJD. 343 378 Int day, month, year; 344 sscanf(c FITSMBrec.datobs, "%4d-%2d-%2d", &year, &month, &day);345 MBrec.mjd = MVTime(year, month, Double(day)).day() + cFITSMBrec.utc/86400.0;346 347 MBrec.interval = cFITSMBrec.exposure;348 349 MBrec.fieldName = trim(cFITSMBrec.srcName);350 MBrec.srcName = MBrec.fieldName;351 352 MBrec.srcDir.resize(2);353 MBrec.srcDir(0) = cFITSMBrec.srcRA;354 MBrec.srcDir(1) = cFITSMBrec.srcDec;355 356 MBrec.srcPM.resize(2);357 MBrec.srcPM(0) = 0.0;358 MBrec.srcPM(1) = 0.0;359 MBrec.srcVel = 0.0;360 MBrec.obsType = trim(cFITSMBrec.obsType);361 362 MBrec.IFno = cFITSMBrec.IFno[0];363 Double chanWidth = fabs(c FITSMBrec.fqDelt[0]);364 MBrec.refFreq = cFITSMBrec.fqRefVal[0];365 MBrec.bandwidth = chanWidth * nChan;366 MBrec.freqInc = cFITSMBrec.fqDelt[0];367 MBrec.restFreq = cFITSMBrec.restFreq;368 369 MBrec.tcal.resize(nPol);379 sscanf(cMBrec.datobs, "%4d-%2d-%2d", &year, &month, &day); 380 pksrec.mjd = MVTime(year, month, Double(day)).day() + cMBrec.utc/86400.0; 381 382 pksrec.interval = cMBrec.exposure; 383 384 pksrec.fieldName = trim(cMBrec.srcName); 385 pksrec.srcName = pksrec.fieldName; 386 387 pksrec.srcDir.resize(2); 388 pksrec.srcDir(0) = cMBrec.srcRA; 389 pksrec.srcDir(1) = cMBrec.srcDec; 390 391 pksrec.srcPM.resize(2); 392 pksrec.srcPM(0) = 0.0; 393 pksrec.srcPM(1) = 0.0; 394 pksrec.srcVel = 0.0; 395 pksrec.obsType = trim(cMBrec.obsType); 396 397 pksrec.IFno = cMBrec.IFno[0]; 398 Double chanWidth = fabs(cMBrec.fqDelt[0]); 399 pksrec.refFreq = cMBrec.fqRefVal[0]; 400 pksrec.bandwidth = chanWidth * nChan; 401 pksrec.freqInc = cMBrec.fqDelt[0]; 402 pksrec.restFreq = cMBrec.restFreq; 403 404 pksrec.tcal.resize(nPol); 370 405 for (uInt ipol = 0; ipol < nPol; ipol++) { 371 MBrec.tcal(ipol) = cFITSMBrec.tcal[0][ipol]; 372 } 373 MBrec.tcalTime = trim(cFITSMBrec.tcalTime); 374 MBrec.azimuth = cFITSMBrec.azimuth; 375 MBrec.elevation = cFITSMBrec.elevation; 376 MBrec.parAngle = cFITSMBrec.parAngle; 377 MBrec.focusAxi = cFITSMBrec.focusAxi; 378 MBrec.focusTan = cFITSMBrec.focusTan; 379 MBrec.focusRot = cFITSMBrec.focusRot; 380 381 MBrec.temperature = cFITSMBrec.temp; 382 MBrec.pressure = cFITSMBrec.pressure; 383 MBrec.humidity = cFITSMBrec.humidity; 384 MBrec.windSpeed = cFITSMBrec.windSpeed; 385 MBrec.windAz = cFITSMBrec.windAz; 386 387 MBrec.refBeam = cFITSMBrec.refBeam; 388 MBrec.beamNo = cFITSMBrec.beamNo; 389 390 MBrec.direction.resize(2); 391 MBrec.direction(0) = cFITSMBrec.ra; 392 MBrec.direction(1) = cFITSMBrec.dec; 393 394 MBrec.scanRate.resize(2); 395 MBrec.scanRate(0) = cFITSMBrec.raRate; 396 MBrec.scanRate(1) = cFITSMBrec.decRate; 397 MBrec.rateAge = cFITSMBrec.rateAge; 398 MBrec.rateson = cFITSMBrec.rateson; 399 400 MBrec.tsys.resize(nPol); 401 MBrec.sigma.resize(nPol); 402 MBrec.calFctr.resize(nPol); 406 pksrec.tcal(ipol) = cMBrec.tcal[0][ipol]; 407 } 408 pksrec.tcalTime = trim(cMBrec.tcalTime); 409 pksrec.azimuth = cMBrec.azimuth; 410 pksrec.elevation = cMBrec.elevation; 411 pksrec.parAngle = cMBrec.parAngle; 412 413 pksrec.focusAxi = cMBrec.focusAxi; 414 pksrec.focusTan = cMBrec.focusTan; 415 pksrec.focusRot = cMBrec.focusRot; 416 417 pksrec.temperature = cMBrec.temp; 418 pksrec.pressure = cMBrec.pressure; 419 pksrec.humidity = cMBrec.humidity; 420 pksrec.windSpeed = cMBrec.windSpeed; 421 pksrec.windAz = cMBrec.windAz; 422 423 pksrec.refBeam = cMBrec.refBeam; 424 pksrec.beamNo = cMBrec.beamNo; 425 426 pksrec.direction.resize(2); 427 pksrec.direction(0) = cMBrec.ra; 428 pksrec.direction(1) = cMBrec.dec; 429 pksrec.pCode = cMBrec.pCode; 430 pksrec.rateAge = cMBrec.rateAge; 431 pksrec.scanRate.resize(2); 432 pksrec.scanRate(0) = cMBrec.raRate; 433 pksrec.scanRate(1) = cMBrec.decRate; 434 pksrec.paRate = cMBrec.paRate; 435 436 pksrec.tsys.resize(nPol); 437 pksrec.sigma.resize(nPol); 438 pksrec.calFctr.resize(nPol); 403 439 for (uInt ipol = 0; ipol < nPol; ipol++) { 404 MBrec.tsys(ipol) = cFITSMBrec.tsys[0][ipol];405 MBrec.sigma(ipol) = (MBrec.tsys(ipol) / 0.81) /406 sqrt(MBrec.interval * chanWidth);407 MBrec.calFctr(ipol) = cFITSMBrec.calfctr[0][ipol];408 } 409 410 if (c FITSMBrec.haveBase) {411 MBrec.baseLin.resize(2,nPol);412 MBrec.baseSub.resize(9,nPol);440 pksrec.tsys(ipol) = cMBrec.tsys[0][ipol]; 441 pksrec.sigma(ipol) = (pksrec.tsys(ipol) / 0.81) / 442 sqrt(pksrec.interval * chanWidth); 443 pksrec.calFctr(ipol) = cMBrec.calfctr[0][ipol]; 444 } 445 446 if (cMBrec.haveBase) { 447 pksrec.baseLin.resize(2,nPol); 448 pksrec.baseSub.resize(9,nPol); 413 449 414 450 for (uInt ipol = 0; ipol < nPol; ipol++) { 415 MBrec.baseLin(0,ipol) = cFITSMBrec.baseLin[0][ipol][0];416 MBrec.baseLin(1,ipol) = cFITSMBrec.baseLin[0][ipol][1];451 pksrec.baseLin(0,ipol) = cMBrec.baseLin[0][ipol][0]; 452 pksrec.baseLin(1,ipol) = cMBrec.baseLin[0][ipol][1]; 417 453 418 454 for (uInt j = 0; j < 9; j++) { 419 MBrec.baseSub(j,ipol) = cFITSMBrec.baseSub[0][ipol][j];455 pksrec.baseSub(j,ipol) = cMBrec.baseSub[0][ipol][j]; 420 456 } 421 457 } 422 458 423 459 } else { 424 MBrec.baseLin.resize(0,0);425 MBrec.baseSub.resize(0,0);426 } 427 428 if (cGetSpectra && c FITSMBrec.haveSpectra) {429 MBrec.spectra.resize(nChan,nPol);430 MBrec.spectra.takeStorage(IPosition(2,nChan,nPol), cFITSMBrec.spectra[0],460 pksrec.baseLin.resize(0,0); 461 pksrec.baseSub.resize(0,0); 462 } 463 464 if (cGetSpectra && cMBrec.haveSpectra) { 465 pksrec.spectra.resize(nChan,nPol); 466 pksrec.spectra.takeStorage(IPosition(2,nChan,nPol), cMBrec.spectra[0], 431 467 SHARE); 432 468 433 MBrec.flagged.resize(nChan,nPol);434 MBrec.flagged.takeStorage(IPosition(2,nChan,nPol), cFITSMBrec.flagged[0],469 pksrec.flagged.resize(nChan,nPol); 470 pksrec.flagged.takeStorage(IPosition(2,nChan,nPol), cMBrec.flagged[0], 435 471 SHARE); 436 472 437 473 } else { 438 MBrec.spectra.resize(0,0);439 MBrec.flagged.resize(0,0);474 pksrec.spectra.resize(0,0); 475 pksrec.flagged.resize(0,0); 440 476 } 441 477 442 478 if (cGetXPol) { 443 MBrec.xCalFctr = Complex(cFITSMBrec.xcalfctr[0][0],444 c FITSMBrec.xcalfctr[0][1]);445 MBrec.xPol.resize(nChan);446 MBrec.xPol.takeStorage(IPosition(1,nChan), (Complex *)cFITSMBrec.xpol[0],479 pksrec.xCalFctr = Complex(cMBrec.xcalfctr[0][0], 480 cMBrec.xcalfctr[0][1]); 481 pksrec.xPol.resize(nChan); 482 pksrec.xPol.takeStorage(IPosition(1,nChan), (Complex *)cMBrec.xpol[0], 447 483 SHARE); 448 484 } … … 451 487 } 452 488 453 //-------------------------------------------------------- PKSFITSreader::read454 455 // Read the next data record, just the basics.456 457 Int PKSFITSreader::read(458 Int &IFno,459 Vector<Float> &tsys,460 Vector<Float> &calFctr,461 Matrix<Float> &baseLin,462 Matrix<Float> &baseSub,463 Matrix<Float> &spectra,464 Matrix<uChar> &flagged)465 {466 Int status;467 468 if ((status = cReader->read(cFITSMBrec))) {469 if (status != -1) {470 status = 1;471 }472 473 return status;474 }475 476 IFno = cFITSMBrec.IFno[0];477 478 uInt nChan = cFITSMBrec.nChan[0];479 uInt nPol = cFITSMBrec.nPol[0];480 481 tsys.resize(nPol);482 calFctr.resize(nPol);483 for (uInt ipol = 0; ipol < nPol; ipol++) {484 tsys(ipol) = cFITSMBrec.tsys[0][ipol];485 calFctr(ipol) = cFITSMBrec.calfctr[0][ipol];486 }487 488 if (cFITSMBrec.haveBase) {489 baseLin.resize(2,nPol);490 baseSub.resize(9,nPol);491 492 for (uInt ipol = 0; ipol < nPol; ipol++) {493 baseLin(0,ipol) = cFITSMBrec.baseLin[0][ipol][0];494 baseLin(1,ipol) = cFITSMBrec.baseLin[0][ipol][1];495 496 for (uInt j = 0; j < 9; j++) {497 baseSub(j,ipol) = cFITSMBrec.baseSub[0][ipol][j];498 }499 }500 501 } else {502 baseLin.resize(0,0);503 baseSub.resize(0,0);504 }505 506 if (cGetSpectra && cFITSMBrec.haveSpectra) {507 spectra.resize(nChan,nPol);508 spectra.takeStorage(IPosition(2,nChan,nPol), cFITSMBrec.spectra[0],509 SHARE);510 511 flagged.resize(nChan,nPol);512 flagged.takeStorage(IPosition(2,nChan,nPol), cFITSMBrec.flagged[0],513 SHARE);514 515 } else {516 spectra.resize(0,0);517 flagged.resize(0,0);518 }519 520 return 0;521 }522 523 489 //------------------------------------------------------- PKSFITSreader::close 524 490 … … 528 494 { 529 495 cReader->close(); 496 logMsg(cReader->getMsg()); 497 cReader->clearMsg(); 530 498 } 531 499
Note: See TracChangeset
for help on using the changeset viewer.