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/PKSMS2writer.cc

    r1399 r1452  
    22//# PKSMS2writer.cc: Class to write Parkes multibeam data to a measurementset.
    33//#---------------------------------------------------------------------------
    4 //# Copyright (C) 2000-2007
     4//# Copyright (C) 2000-2008
    55//# Associated Universities, Inc. Washington DC, USA.
    66//#
     
    2626//#                        Charlottesville, VA 22903-2475 USA
    2727//#
    28 //# $Id: PKSMS2writer.cc,v 19.12 2007/11/12 03:37:56 cal103 Exp $
     28//# $Id: PKSMS2writer.cc,v 19.14 2008-11-17 06:56:13 cal103 Exp $
    2929//#---------------------------------------------------------------------------
    3030
     31#include <atnf/PKSIO/PKSrecord.h>
    3132#include <atnf/PKSIO/PKSMS2writer.h>
    3233
     
    5455PKSMS2writer::PKSMS2writer()
    5556{
     57  cPKSMS = 0x0;
     58
     59  // By default, messages are written to stderr.
     60  initMsg();
    5661}
    5762
     
    8489        const Bool   haveBase)
    8590{
     91  if (cPKSMS) {
     92    logMsg("ERROR: Output MS already open, close it first.");
     93    return 1;
     94  }
     95
     96  // Clear the message stack.
     97  clearMsg();
     98
    8699  // Open a MS table.
    87100  TableDesc pksDesc = MS::requiredTableDesc();
     
    369382
    370383Int PKSMS2writer::write(
    371         const Int             scanNo,
    372         const Int             cycleNo,
    373         const Double          mjd,
    374         const Double          interval,
    375         const String          fieldName,
    376         const String          srcName,
    377         const Vector<Double>  srcDir,
    378         const Vector<Double>  srcPM,
    379         const Double          srcVel,
    380         const String          obsMode,
    381         const Int             IFno,
    382         const Double          refFreq,
    383         const Double          bandwidth,
    384         const Double          freqInc,
    385         const Double          restFreq,
    386         const Vector<Float>   tcal,
    387         const String          tcalTime,
    388         const Float           azimuth,
    389         const Float           elevation,
    390         const Float           parAngle,
    391         const Float           focusAxi,
    392         const Float           focusTan,
    393         const Float           focusRot,
    394         const Float           temperature,
    395         const Float           pressure,
    396         const Float           humidity,
    397         const Float           windSpeed,
    398         const Float           windAz,
    399         const Int             refBeam,
    400         const Int             beamNo,
    401         const Vector<Double>  direction,
    402         const Vector<Double>  scanRate,
    403         const Vector<Float>   tsys,
    404         const Vector<Float>   sigma,
    405         const Vector<Float>   calFctr,
    406         const Matrix<Float>   baseLin,
    407         const Matrix<Float>   baseSub,
    408         const Matrix<Float>   &spectra,
    409         const Matrix<uChar>   &flagged,
    410         const Complex         xCalFctr,
    411         const Vector<Complex> &xPol)
     384        const PKSrecord &pksrec)
    412385{
    413386  // Extend the time range in the OBSERVATION subtable.
    414387  Vector<Double> timerange(2);
    415388  cObservationCols->timeRange().get(0, timerange);
    416   Double time = mjd*86400.0;
     389  Double time = pksrec.mjd*86400.0;
    417390  if (timerange(0) == 0.0) {
    418391    timerange(0) = time;
     
    421394  cObservationCols->timeRange().put(0, timerange);
    422395
    423   Int iIF = IFno - 1;
     396  Int iIF = pksrec.IFno - 1;
    424397  Int nChan = cNChan(iIF);
    425398  Int nPol  = cNPol(iIF);
     
    427400  // IFno is the 1-relative row number in the DATA_DESCRIPTION,
    428401  // SPECTRAL_WINDOW, and POLARIZATION subtables.
    429   if (Int(cDataDescription.nrow()) < IFno) {
     402  if (Int(cDataDescription.nrow()) < pksrec.IFno) {
    430403    // Add a new entry to each subtable.
    431     addDataDescriptionEntry(IFno);
    432     addSpectralWindowEntry(IFno, nChan, refFreq, bandwidth, freqInc);
    433     addPolarizationEntry(IFno, nPol);
     404    addDataDescriptionEntry(pksrec.IFno);
     405    addSpectralWindowEntry(pksrec.IFno, nChan, pksrec.refFreq,
     406      pksrec.bandwidth, pksrec.freqInc);
     407    addPolarizationEntry(pksrec.IFno, nPol);
    434408  }
    435409
    436410  // Find or add the source to the SOURCE subtable.
    437   Int srcId = addSourceEntry(srcName, srcDir, srcPM, restFreq, srcVel);
    438 
    439   // Find or add the obsMode to the STATE subtable.
    440   Int stateId = addStateEntry(obsMode);
     411  Int srcId = addSourceEntry(pksrec.srcName, pksrec.srcDir, pksrec.srcPM,
     412    pksrec.restFreq, pksrec.srcVel);
     413
     414  // Find or add the obsType to the STATE subtable.
     415  Int stateId = addStateEntry(pksrec.obsType);
    441416
    442417  // FIELD subtable.
    443   Int fieldId = addFieldEntry(fieldName, time, direction, scanRate, srcId);
     418  Vector<Double> scanRate(2);
     419  scanRate(0) = pksrec.scanRate(0);
     420  scanRate(1) = pksrec.scanRate(1);
     421  Int fieldId = addFieldEntry(pksrec.fieldName, time, pksrec.direction,
     422    scanRate, srcId);
    444423
    445424  // POINTING subtable.
    446   addPointingEntry(time, interval, fieldName, direction, scanRate);
     425  addPointingEntry(time, pksrec.interval, pksrec.fieldName, pksrec.direction,
     426    scanRate);
    447427
    448428  // SYSCAL subtable.
    449   addSysCalEntry(beamNo, iIF, time, interval, tcal, tsys);
     429  addSysCalEntry(pksrec.beamNo, iIF, time, pksrec.interval, pksrec.tcal,
     430    pksrec.tsys);
    450431
    451432  // Handle weather information.
     
    453434  Int nWeather = wTime.nrow();
    454435  if (nWeather == 0 || time > wTime(nWeather-1)) {
    455     addWeatherEntry(time, interval, pressure, humidity, temperature);
     436    addWeatherEntry(time, pksrec.interval, pksrec.pressure, pksrec.humidity,
     437      pksrec.temperature);
    456438  }
    457439
     
    465447  cMSCols->antenna1().put(irow, 0);
    466448  cMSCols->antenna2().put(irow, 0);
    467   cMSCols->feed1().put(irow, beamNo-1);
    468   cMSCols->feed2().put(irow, beamNo-1);
     449  cMSCols->feed1().put(irow, pksrec.beamNo-1);
     450  cMSCols->feed2().put(irow, pksrec.beamNo-1);
    469451  cMSCols->dataDescId().put(irow, iIF);
    470452  cMSCols->processorId().put(irow, 0);
     
    472454
    473455  // Non-key attributes.
    474   cMSCols->interval().put(irow, interval);
    475   cMSCols->exposure().put(irow, interval);
     456  cMSCols->interval().put(irow, pksrec.interval);
     457  cMSCols->exposure().put(irow, pksrec.interval);
    476458  cMSCols->timeCentroid().put(irow, time);
    477   cMSCols->scanNumber().put(irow, scanNo);
     459  cMSCols->scanNumber().put(irow, pksrec.scanNo);
    478460  cMSCols->arrayId().put(irow, 0);
    479461  cMSCols->observationId().put(irow, 0);
     
    485467  // Baseline fit parameters.
    486468  if (cHaveBase) {
    487     cBaseLinCol->put(irow, baseLin);
    488 
    489     if (baseSub.nrow() == 9) {
    490       cBaseSubCol->put(irow, baseSub);
     469    cBaseLinCol->put(irow, pksrec.baseLin);
     470
     471    if (pksrec.baseSub.nrow() == 9) {
     472      cBaseSubCol->put(irow, pksrec.baseSub);
    491473
    492474    } else {
    493475      Matrix<Float> tmp(9, 2, 0.0f);
    494476      for (Int ipol = 0; ipol < nPol; ipol++) {
    495         for (uInt j = 0; j < baseSub.nrow(); j++) {
    496           tmp(j,ipol) = baseSub(j,ipol);
     477        for (uInt j = 0; j < pksrec.baseSub.nrow(); j++) {
     478          tmp(j,ipol) = pksrec.baseSub(j,ipol);
    497479        }
    498480      }
     
    506488  for (Int ipol = 0; ipol < nPol; ipol++) {
    507489    for (Int ichan = 0; ichan < nChan; ichan++) {
    508       tmpData(ipol,ichan) = spectra(ichan,ipol);
    509       tmpFlag(ipol,ichan) = flagged(ichan,ipol);
     490      tmpData(ipol,ichan) = pksrec.spectra(ichan,ipol);
     491      tmpFlag(ipol,ichan) = pksrec.flagged(ichan,ipol);
    510492    }
    511493  }
    512494
    513   cCalFctrCol->put(irow, calFctr);
     495  cCalFctrCol->put(irow, pksrec.calFctr);
    514496  cMSCols->floatData().put(irow, tmpData);
    515497  cMSCols->flag().put(irow, tmpFlag);
     
    517499  // Cross-polarization spectra.
    518500  if (cHaveXPol(iIF)) {
    519     cXCalFctrCol->put(irow, xCalFctr);
    520     cMSCols->data().put(irow, xPol);
    521   }
    522 
    523   cMSCols->sigma().put(irow, sigma);
     501    cXCalFctrCol->put(irow, pksrec.xCalFctr);
     502    cMSCols->data().put(irow, pksrec.xPol);
     503  }
     504
     505  cMSCols->sigma().put(irow, pksrec.sigma);
    524506
    525507  Vector<Float> weight(1, 1.0f);
     
    586568  cSysCal          = MSSysCal();
    587569  cWeather         = MSWeather();
     570
    588571  // Release the main table.
    589   delete cPKSMS; cPKSMS=0;
     572  delete cPKSMS;
     573  cPKSMS = 0x0;
    590574}
    591575
     
    984968
    985969Int PKSMS2writer::addStateEntry(
    986         const String obsMode)
     970        const String obsType)
    987971{
    988972  // Look for an entry in the STATE subtable.
    989973  for (uInt n = 0; n < cStateCols->nrow(); n++) {
    990     if (cStateCols->obsMode()(n) == obsMode) {
     974    if (cStateCols->obsMode()(n) == obsType) {
    991975      return n;
    992976    }
     
    998982
    999983  // Data.
    1000   if (obsMode.contains("RF")) {
     984  if (obsType.contains("RF")) {
    1001985    cStateCols->sig().put(n, False);
    1002986    cStateCols->ref().put(n, True);
    1003   } else if (!obsMode.contains("PA")) {
     987  } else if (!obsType.contains("PA")) {
    1004988    // Signal and reference are both false for "paddle" data.
    1005989    cStateCols->sig().put(n, True);
     
    1010994  cStateCols->cal().put(n, 0.0);
    1011995  cStateCols->subScan().put(n, 0);
    1012   cStateCols->obsMode().put(n, obsMode);
     996  cStateCols->obsMode().put(n, obsType);
    1013997
    1014998  // Flags.
Note: See TracChangeset for help on using the changeset viewer.