Ignore:
Timestamp:
11/19/08 20:41:16 (16 years ago)
Author:
Malte Marquarding
Message:

update from livedata CVS

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/external/atnf/PKSIO/PKSFITSreader.cc

    r1427 r1452  
    2525//#                        Charlottesville, VA 22903-2475 USA
    2626//#
    27 //# $Id: PKSFITSreader.cc,v 19.14 2008-06-26 02:07:21 cal103 Exp $
     27//# $Id: PKSFITSreader.cc,v 19.21 2008-11-17 06:54:25 cal103 Exp $
    2828//#---------------------------------------------------------------------------
    2929//# Original: 2000/08/02, Mark Calabretta, ATNF
    3030//#---------------------------------------------------------------------------
    3131
     32#include <atnf/PKSIO/PKSmsg.h>
    3233#include <atnf/PKSIO/MBFITSreader.h>
    3334#include <atnf/PKSIO/SDFITSreader.h>
    3435#include <atnf/PKSIO/PKSFITSreader.h>
    35 #include <atnf/PKSIO/PKSMBrecord.h>
    36 
     36#include <atnf/PKSIO/PKSrecord.h>
     37
     38#include <casa/stdio.h>
    3739#include <casa/Arrays/Array.h>
    3840#include <casa/BasicMath/Math.h>
    3941#include <casa/Quanta/MVTime.h>
    40 
    41 #include <casa/stdio.h>
    4242
    4343//----------------------------------------------- PKSFITSreader::PKSFITSreader
     
    5050        const Bool   interpolate)
    5151{
    52   cFITSMBrec.setNIFs(1);
     52  cMBrec.setNIFs(1);
    5353
    5454  if (fitsType == "SDFITS") {
     
    5757    cReader = new MBFITSreader(retry, interpolate ? 1 : 0);
    5858  }
     59
     60  // By default, messages are written to stderr.
     61  initMsg();
    5962}
    6063
     
    6770  close();
    6871  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
     79Int PKSFITSreader::setMsg(FILE *fd)
     80{
     81  PKSmsg::setMsg(fd);
     82  cReader->setMsg(fd);
     83
     84  return 0;
    6985}
    7086
     
    8399        Bool   &haveSpectra)
    84100{
     101  clearMsg();
     102
    85103  int    extraSysCal, haveBase_, *haveXPol_, haveSpectra_, nBeam, *nChan_,
    86104         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) {
    90111    return status;
    91112  }
     
    146167  char   bunit_[32], datobs[32], dopplerFrame_[32], observer_[32],
    147168         obsType_[32], project_[32], radecsys[32], telescope[32];
     169  int    status;
    148170  float  equinox_;
    149171  double antPos[3], utc;
    150172
    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) {
    154179    return 1;
    155180  }
     
    187212  double *startfreq, *endfreq;
    188213
    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) {
    191219    startFreq.takeStorage(IPosition(1,nIF), startfreq, TAKE_OVER);
    192220    endFreq.takeStorage(IPosition(1,nIF), endfreq, TAKE_OVER);
     
    208236        const Bool getSpectra,
    209237        const Bool getXPol,
    210         const Bool getFeedPos)
     238        const Int  coordSys)
    211239{
    212240  // Apply beam selection.
     
    275303  cGetSpectra = getSpectra;
    276304  cGetXPol    = getXPol;
    277   cGetFeedPos = getFeedPos;
     305  cCoordSys   = coordSys;
    278306
    279307  uInt maxNChan = cReader->select(start, end, ref, cGetSpectra, cGetXPol,
    280                                   cGetFeedPos);
     308                                  cCoordSys);
     309  logMsg(cReader->getMsg());
     310  cReader->clearMsg();
    281311
    282312  delete [] end;
     
    301331  double* posns;
    302332
    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) {
    305338    timeSpan.resize(2);
    306339
     
    321354// Read the next data record.
    322355
    323 Int PKSFITSreader::read(MBrecord &MBrec)
    324 {
    325   Int status;
    326 
    327   if ((status = cReader->read(cFITSMBrec))) {
     356Int PKSFITSreader::read(PKSrecord &pksrec)
     357{
     358  Int status = cReader->read(cMBrec);
     359  logMsg(cReader->getMsg());
     360  cReader->clearMsg();
     361
     362  if (status) {
    328363    if (status != -1) {
    329364      status = 1;
     
    334369
    335370
    336   uInt nChan = cFITSMBrec.nChan[0];
    337   uInt nPol  = cFITSMBrec.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;
    341376
    342377  // Extract MJD.
    343378  Int day, month, year;
    344   sscanf(cFITSMBrec.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(cFITSMBrec.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);
    370405  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);
    403439  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 (cFITSMBrec.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);
    413449
    414450    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];
    417453
    418454      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];
    420456      }
    421457    }
    422458
    423459  } else {
    424     MBrec.baseLin.resize(0,0);
    425     MBrec.baseSub.resize(0,0);
    426   }
    427 
    428   if (cGetSpectra && cFITSMBrec.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],
    431467      SHARE);
    432468
    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],
    435471      SHARE);
    436472
    437473  } 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);
    440476  }
    441477
    442478  if (cGetXPol) {
    443     MBrec.xCalFctr = Complex(cFITSMBrec.xcalfctr[0][0],
    444                              cFITSMBrec.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],
    447483      SHARE);
    448484  }
     
    451487}
    452488
    453 //-------------------------------------------------------- PKSFITSreader::read
    454 
    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 
    523489//------------------------------------------------------- PKSFITSreader::close
    524490
     
    528494{
    529495  cReader->close();
     496  logMsg(cReader->getMsg());
     497  cReader->clearMsg();
    530498}
    531499
Note: See TracChangeset for help on using the changeset viewer.