Ignore:
Timestamp:
06/09/10 19:03:06 (14 years ago)
Author:
Kana Sugimoto
Message:

New Development: Yes

JIRA Issue: Yes (CAS-2211)

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: ASAP 3.0.0 interface changes

Test Programs:

Put in Release Notes: Yes

Module(s): all the CASA sd tools and tasks are affected.

Description: Merged ATNF-ASAP 3.0.0 developments to CASA (alma) branch.

Note you also need to update casa/code/atnf.


Location:
branches/alma
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/alma

  • branches/alma/external/atnf/PKSIO/PKSMS2reader.cc

    r1453 r1757  
    22//# PKSMS2reader.cc: Class to read Parkes Multibeam data from a v2 MS.
    33//#---------------------------------------------------------------------------
    4 //# Copyright (C) 2000-2006
    5 //# 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
    66//#
    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.
    118//#
    12 //# This library is distributed in the hope that it will be useful, but
    13 //# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    14 //# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
    15 //# 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.
    1613//#
    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.
    2018//#
    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/>.
    2721//#
    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: PKSMS2reader.cc,v 19.23 2009-09-29 07:33:38 cal103 Exp $
    2932//#---------------------------------------------------------------------------
    3033//# Original: 2000/08/03, Mark Calabretta, ATNF
    3134//#---------------------------------------------------------------------------
    32 
    3335
    3436// AIPS++ includes.
     
    4143#include <casa/Quanta/MVAngle.h>
    4244#include <casa/BasicMath/Math.h>
     45#include <casa/Logging/LogIO.h>
     46#include <casa/Utilities/Sort.h>
    4347#include <measures/Measures/MeasConvert.h>
    4448#include <measures/Measures/MEpoch.h>
     
    4852// Parkes includes.
    4953#include <atnf/pks/pks_maths.h>
     54#include <atnf/PKSIO/PKSrecord.h>
    5055#include <atnf/PKSIO/PKSMS2reader.h>
    5156
     
    7378Int PKSMS2reader::open(
    7479        const String msName,
     80        const String antenna,
    7581        Vector<Bool> &beams,
    7682        Vector<Bool> &IFs,
     
    9197
    9298  cPKSMS  = MeasurementSet(msName);
     99
     100  // data selection by antenna
     101  if ( antenna.length() == 0 ) {
     102    cAntId.resize( 1 ) ;
     103    cAntId[0] = 0 ;
     104  }
     105  else {
     106    setupAntennaList( antenna ) ;
     107    if ( cAntId.size() > 1 ) {
     108      LogIO os( LogOrigin( "PKSMS2reader", "open()", WHERE ) ) ;
     109      os << LogIO::WARN << "PKSMS2reader is not ready for multiple antenna selection. Use first antenna id " << cAntId[0] << "."<< LogIO::POST ;
     110      Int tmp = cAntId[0] ;
     111      cAntId.resize( 1 ) ;
     112      cAntId[0] = tmp ;
     113    }
     114    stringstream ss ;
     115    ss << "SELECT FROM $1 WHERE ANTENNA1 == ANTENNA2 && ANTENNA1 IN [" ;
     116    for ( uInt i = 0 ; i < cAntId.size() ; i++ ) {
     117      ss << cAntId[i] ;
     118      if ( i == cAntId.size()-1 ) {
     119        ss << "]" ;
     120      }
     121      else {
     122        ss << "," ;
     123      }
     124    }
     125    string taql = ss.str() ;
     126    //cerr << "taql = " << taql << endl ;
     127    cPKSMS = MeasurementSet( tableCommand( taql, cPKSMS ) ) ;
     128  }
     129
    93130  // taql access to the syscal table
    94131  cHaveSysCal = False;
     
    97134  }
    98135
     136  // Lock the table for read access.
     137  cPKSMS.lock(False);
     138
    99139  cIdx    = 0;
    100140  lastmjd = 0.0;
    101141  cNRow   = cPKSMS.nrow();
    102142  cMSopen = True;
    103 
    104   // Lock the table for read access.
    105   cPKSMS.lock(False);
    106143
    107144  // Main MS table and subtable column access.
     
    140177  cSigStateCol.reference(stateCols.sig());
    141178  cRefStateCol.reference(stateCols.ref());
     179
    142180  cDataDescIdCol.reference(msCols.dataDescId());
    143181  cSpWinIdCol.reference(dataDescCols.spectralWindowId());
    144182  cChanFreqCol.reference(spWinCols.chanFreq());
     183  cTotBWCol.reference(spWinCols.totalBandwidth());
    145184
    146185  cWeatherTimeCol.reference(weatherCols.time());
     
    151190  cBeamNoCol.reference(msCols.feed1());
    152191  cPointingCol.reference(pointingCols.direction());
     192  cPointingTimeCol.reference(pointingCols.time());
    153193  cSigmaCol.reference(msCols.sigma());
    154194  cNumReceptorCol.reference(feedCols.numReceptors());
     
    182222  cHaveDataCol = False;
    183223  cHaveCorrectedDataCol = False;
    184   //String telName = antennaCols.name()(0);
    185224  ROMSObservationColumns observationCols(cPKSMS.observation());
    186   String telName = observationCols.telescopeName()(0);
    187   //cATF = (telName.contains("DA41") || telName.contains("DV01"));
    188   cATF = telName.contains("ATF");
     225  //String telName = observationCols.telescopeName()(0);
     226  cTelName = observationCols.telescopeName()(0);
     227  //cATF = cTelName.contains("ATF");
     228  //cOSF = cTelName.contains("OSF");
     229  //cALMA = cTelName.contains("ALMA");
     230  cALMA = cTelName.contains("ATF")||cTelName.contains("OSF")||
     231           cTelName.contains("ALMA");
    189232
    190233  if (cHaveDataCol = cPKSMS.isColumn(MSMainEnums::DATA)) {
    191     if (cATF) {
     234    if (cALMA) {
    192235      //try to read a single baseline interferometeric data
    193236      //and treat it as single dish data
     
    204247  }
    205248  cFlagCol.reference(msCols.flag());
    206 
    207 
    208   if (cGetXPol = (cPKSMS.isColumn(MSMainEnums::DATA) && (!cATF))) {
     249  cFlagRowCol.reference(msCols.flagRow());
     250
     251  if (cGetXPol = (cPKSMS.isColumn(MSMainEnums::DATA) && (!cALMA))) {
    209252    if ((cHaveXCalFctr = cPKSMS.tableDesc().isColumn("XCALFCTR"))) {
    210253      cXCalFctrCol.attach(cPKSMS, "XCALFCTR");
     
    228271  //uInt nIF = dataDescCols.nrow();
    229272  uInt nIF =spWinCols.nrow();
     273  Vector<Int> spWinIds = cSpWinIdCol.getColumn() ;
    230274  IFs.resize(nIF);
    231275  IFs = True;
     276  for ( Int ispw = 0 ; ispw < nIF ; ispw++ ) {
     277    if ( allNE( ispw, spWinIds ) ) {
     278      IFs(ispw) = False ;
     279    }
     280  }
    232281
    233282  // Number of polarizations and channels in each IF.
    234   ROScalarColumn<Int> spWinIdCol(dataDescCols.spectralWindowId());
    235283  ROScalarColumn<Int> numChanCol(spWinCols.numChan());
    236284
     
    241289  nPol.resize(nIF);
    242290  for (uInt iIF = 0; iIF < nIF; iIF++) {
    243     nChan(iIF) = numChanCol(spWinIdCol(iIF));
    244     nPol(iIF)  = numPolCol(polIdCol(iIF));
     291    if ( IFs(iIF) ) {
     292      nChan(iIF) = numChanCol(cSpWinIdCol(iIF)) ;
     293      nPol(iIF) = numPolCol(polIdCol(iIF)) ;
     294    }
     295    else {
     296      nChan(iIF) = 0 ;
     297      nPol(iIF) = 0 ;
     298    }
    245299  }
    246300
     
    249303  haveXPol = False;
    250304
    251   if (cGetXPol && !(cATF)) {
     305  if (cGetXPol && !(cALMA)) {
    252306    for (Int irow = 0; irow < cNRow; irow++) {
    253307      if (cDataCol.isDefined(irow)) {
     
    298352        String &antName,
    299353        Vector<Double> &antPosition,
    300         String &obsMode,
     354        // before merge...
     355        //String &obsMode,
     356        String &obsType,
     357        String &bunit,
    301358        Float  &equinox,
    302359        String &dopplerFrame,
    303360        Double &mjd,
    304361        Double &refFreq,
    305         Double &bandwidth,
    306         String &fluxunit)
     362        Double &bandwidth)
    307363{
    308364  if (!cMSopen) {
     
    317373  // Antenna name and ITRF coordinates.
    318374  ROMSAntennaColumns antennaCols(cPKSMS.antenna());
    319   antName = antennaCols.name()(0);
    320   antPosition = antennaCols.position()(0);
     375  //antName = antennaCols.name()(0);
     376  antName = antennaCols.name()(cAntId[0]);
     377  if (cALMA) {
     378     antName = cTelName + "-" + antName;
     379  }
     380  //antPosition = antennaCols.position()(0);
     381  antPosition = antennaCols.position()(cAntId[0]);
    321382
    322383  // Observation type.
    323384  if (cObsModeCol.nrow()) {
    324     obsMode = cObsModeCol(0);
    325     if (obsMode == "\0") obsMode = "RF";
     385    obsType = cObsModeCol(0);
     386    if (obsType == "\0") obsType = "RF";
    326387  } else {
    327     obsMode = "RF";
    328   }
    329 
    330   fluxunit = "";
     388    obsType = "RF";
     389  }
     390
     391  bunit = "";
    331392  if (cHaveDataCol) {
    332393    const TableRecord& keywordSet2
    333394       = cDataCol.columnDesc().keywordSet();
    334395    if(keywordSet2.isDefined("UNIT")) {
    335       fluxunit = keywordSet2.asString("UNIT");
     396      bunit = keywordSet2.asString("UNIT");
    336397    }
    337398  } else {
     
    339400       = cFloatDataCol.columnDesc().keywordSet();
    340401    if(keywordSet.isDefined("UNIT")) {
    341       fluxunit = keywordSet.asString("UNIT");
     402      bunit = keywordSet.asString("UNIT");
    342403    }
    343404  }
     
    354415  String dirref = pointingCols.direction().keywordSet().asRecord("MEASINFO").
    355416                    asString("Ref");
     417  cDirRef = dirref;
     418  if (dirref =="AZELGEO" || dirref == "AZEL") {
     419     dirref = "J2000";
     420  }
    356421  sscanf(dirref.chars()+1, "%f", &equinox);
    357422
     
    422487        const Bool getSpectra,
    423488        const Bool getXPol,
    424         const Bool getFeedPos)
     489        const Bool getFeedPos,
     490        const Bool getPointing,
     491        const Int  coordSys)
    425492{
    426493  if (!cMSopen) {
     
    504571  cGetFeedPos = False;
    505572
     573  // Get Pointing data (for MS)
     574  cGetPointing = getPointing;
     575
     576  // Coordinate system?  (Only equatorial available.)
     577  cCoordSys = 0;
     578
    506579  return maxNChan;
    507580}
     
    555628// Read the next data record.
    556629
     630/**
    557631Int PKSMS2reader::read(
    558632        Int             &scanNo,
     
    595669        Matrix<Float>   &spectra,
    596670        Matrix<uChar>   &flagged,
     671        uInt            &flagrow,
    597672        Complex         &xCalFctr,
    598673        Vector<Complex> &xPol)
     674**/
     675Int PKSMS2reader::read(PKSrecord &pksrec)
    599676{
     677  LogIO os( LogOrigin( "PKSMS2reader", "read()", WHERE ) ) ;
     678
    600679  if (!cMSopen) {
    601680    return 1;
     
    627706  // Renumerate scan no. Here still is 1-based
    628707  //scanNo = cScanNoCol(cIdx) - cScanNoCol(0) + 1;
    629   scanNo = cScanNoCol(cIdx);
    630  
    631   if (scanNo != cScanNo) {
     708  //scanNo = cScanNoCol(cIdx);
     709  pksrec.scanNo = cScanNoCol(cIdx);
     710
     711  if (pksrec.scanNo != cScanNo) {
    632712    // Start of new scan.
    633     cScanNo  = scanNo;
     713    cScanNo  = pksrec.scanNo;
    634714    cCycleNo = 1;
    635715    cTime    = cTimeCol(cIdx);
     
    637717
    638718  Double time = cTimeCol(cIdx);
    639   mjd      = time/86400.0;
    640   interval = cIntervalCol(cIdx);
     719  pksrec.mjd      = time/86400.0;
     720  pksrec.interval = cIntervalCol(cIdx);
    641721
    642722  // Reconstruct the integration cycle number; due to small latencies the
    643723  // integration time is usually slightly less than the time between cycles,
    644724  // resetting cTime will prevent the difference from accumulating.
    645   cCycleNo += nint((time - cTime)/interval);
    646   cycleNo = cCycleNo;
    647   cTime   = time;
     725  cCycleNo += nint((time - cTime)/pksrec.interval);
     726  pksrec.cycleNo = cCycleNo;
     727  cTime = time;
    648728
    649729  Int fieldId = cFieldIdCol(cIdx);
    650   fieldName = cFieldNameCol(fieldId);
     730  pksrec.fieldName = cFieldNameCol(fieldId);
    651731
    652732  Int srcId = cSrcIdCol(fieldId);
     
    656736  for (uInt irow = 0; irow < cSrcId2Col.nrow(); irow++) {
    657737    if (cSrcId2Col(irow) == srcId) {
    658       srcName = cSrcNameCol(irow);
    659     }
    660   }
    661 
    662   srcDir  = cSrcDirCol(srcId);
    663   srcPM   = cSrcPMCol(srcId);
     738      //srcName = cSrcNameCol(irow);
     739      pksrec.srcName = cSrcNameCol(irow);
     740    }
     741  }
     742
     743  pksrec.srcDir  = cSrcDirCol(srcId);
     744  pksrec.srcPM   = cSrcPMCol(srcId);
    664745
    665746  // Systemic velocity.
    666   if (!cHaveSrcVel || cATF) {
    667     srcVel = 0.0f;
     747  if (!cHaveSrcVel || cALMA) {
     748    pksrec.srcVel = 0.0f;
    668749  } else {
    669     srcVel = cSrcVelCol(srcId)(IPosition(1,0));
     750    pksrec.srcVel = cSrcVelCol(srcId)(IPosition(1,0));
    670751  }
    671752
    672753  ROMSAntennaColumns antennaCols(cPKSMS.antenna());
    673   String telescope = antennaCols.name()(0);
     754  //String telescope = antennaCols.name()(0);
     755  String telescope = antennaCols.name()(cAntId[0]);
    674756  Bool cGBT = telescope.contains("GBT");
     757  //Bool cPM = telescope.contains("PM"); // ACA TP antenna
     758  //Bool cDV = telescope.contains("DV"); // VERTEX
     759  //Bool cCM = telescope.contains("CM"); // ACA 7m antenna
     760  //Bool cALMA = cPM || cDV || cCM ;
    675761  // Observation type.
    676762  // check if State Table exist
     
    680766  StateNRow=cObsModeCol.nrow();
    681767  if (Table::isReadable(cPKSMS.stateTableName())) {
    682         obsMode = " ";
     768        pksrec.obsType = " ";
    683769    if (StateNRow > 0) {
    684770      stateId = cStateIdCol(cIdx);
    685771      if (stateId == -1) {
    686         //obsMode = " ";
     772        //pksrec.obsType = " ";
    687773      } else {
    688         obsMode = cObsModeCol(stateId);
     774        pksrec.obsType = cObsModeCol(stateId);
    689775        Bool sigState =cSigStateCol(stateId);
    690776        Bool refState =cRefStateCol(stateId);
    691777        //DEBUG
    692         //cerr <<"stateid="<<stateId<<" obsmode="<<obsMode<<endl;
     778        //cerr <<"stateid="<<stateId<<" obsmode="<<pksrec.obsType<<endl;
    693779        if (cGBT) {
    694           // split the obsMode string and append a proper label
     780          // split the obsType string and append a proper label
    695781          // (these are GBT specific)
    696           int epos = obsMode.find_first_of(':');
    697           int nextpos = obsMode.find_first_of(':',epos+1);
    698           string obsMode1 = obsMode.substr(0,epos);
    699           string obsMode2 = obsMode.substr(epos+1,nextpos-epos-1);
     782          int epos = pksrec.obsType.find_first_of(':');
     783          int nextpos = pksrec.obsType.find_first_of(':',epos+1);
     784          string obsMode1 = pksrec.obsType.substr(0,epos);
     785          string obsMode2 = pksrec.obsType.substr(epos+1,nextpos-epos-1);
    700786     
    701787          //cerr <<"obsMode2= "<<obsMode2<<endl;
    702           if (!srcName.contains("_ps")
    703               &&!srcName.contains("_psr")
    704               &&!srcName.contains("_nod")
    705               &&!srcName.contains("_fs")
    706               &&!srcName.contains("_fsr")) {
     788          if (!pksrec.srcName.contains("_ps")
     789              &&!pksrec.srcName.contains("_psr")
     790              &&!pksrec.srcName.contains("_nod")
     791              &&!pksrec.srcName.contains("_fs")
     792              &&!pksrec.srcName.contains("_fsr")) {
    707793            // if Nod mode observation , append '_nod'
    708794            if (obsMode1 == "Nod") {
    709               srcName.append("_nod");
     795              //pksrec.srcName.append("_nod");
     796              pksrec.srcType = SrcType::NOD ;
    710797            } else if (obsMode1 == "OffOn") {
    711798            // for GBT position switch observations (OffOn or OnOff)
    712               if (obsMode2 == "PSWITCHON") srcName.append("_ps");
    713               if (obsMode2 == "PSWITCHOFF") srcName.append("_psr");
     799              //if (obsMode2 == "PSWITCHON") pksrec.srcName.append("_ps");
     800              //if (obsMode2 == "PSWITCHOFF") pksrec.srcName.append("_psr");
     801              if (obsMode2 == "PSWITCHON") pksrec.srcType = SrcType::PSON ;
     802              if (obsMode2 == "PSWITCHOFF") pksrec.srcType = SrcType::PSOFF ;
    714803            } else {
    715804              if (obsMode2 == "FSWITCH") {
    716805              // for GBT frequency switch mode
    717                 if (sigState) srcName.append("_fs");
    718                 if (refState) srcName.append("_fsr");
     806                //if (sigState) pksrec.srcName.append("_fs");
     807                //if (refState) pksrec.srcName.append("_fsr");
     808                if (sigState) pksrec.srcType = SrcType::FSON ;
     809                if (refState) pksrec.srcType = SrcType::FSOFF ;
    719810              }
    720811            }
    721812          }
    722813        }
     814        else if (cALMA) {
     815          // ALMA tag
     816          // split the obsType string and append a proper label
     817          string substr[1] ;
     818          int numSubstr = split( pksrec.obsType, substr, 1, "," );
     819          String obsType = String( substr[0] );
     820          int epos = obsType.find_first_of('.');
     821          int nextpos = obsType.find_first_of('.',epos+1);
     822          string obsMode1 = obsType.substr(0,epos);
     823          string obsMode2 = obsType.substr(epos+1,nextpos-epos-1);
     824     
     825          //cerr <<"obsMode2= "<<obsMode2<<endl;
     826          // Current OBS_MODE format:
     827          //
     828          //     ON: OBSERVE_TARGET.ON_SOURCE
     829          //    OFF: OBSERVE_TARGET.OFF_SOURCE
     830          //
     831          if (obsMode1 == "OBSERVE_TARGET") {
     832            //if (obsMode2 == "ON_SOURCE") pksrec.srcName.append("_pson");
     833            //if (obsMode2 == "OFF_SOURCE") pksrec.srcName.append("_psoff");
     834            if (obsMode2 == "ON_SOURCE") pksrec.srcType = SrcType::PSON ;
     835            if (obsMode2 == "OFF_SOURCE") pksrec.srcType = SrcType::PSOFF ;
     836          }
     837        }
    723838      }
    724839    }
     
    733848  }
    734849  if (cGBT) {
    735     if (Cal > 0 && !srcName.contains("_calon")) {
    736       srcName.append("_calon");
    737     }
    738   }
    739 
    740   IFno = iIF + 1;
     850    if (Cal > 0 && !pksrec.srcName.contains("_calon")) {
     851      //pksrec.srcName.append("_calon");
     852      if ( pksrec.srcType == SrcType::NOD )
     853        pksrec.srcType = SrcType::NODCAL ;
     854      else if ( pksrec.srcType == SrcType::PSON )
     855        pksrec.srcType = SrcType::PONCAL ;
     856      else if ( pksrec.srcType == SrcType::PSOFF )
     857        pksrec.srcType = SrcType::POFFCAL ;
     858      else if ( pksrec.srcType == SrcType::FSON )
     859        pksrec.srcType = SrcType::FONCAL ;
     860      else if ( pksrec.srcType == SrcType::FSOFF )
     861        pksrec.srcType = SrcType::FOFFCAL ;
     862      else
     863        pksrec.srcName.append("_calon");
     864    }
     865  }
     866
     867  pksrec.IFno = iIF + 1;
    741868  Int nChan = abs(cEndChan(iIF) - cStartChan(iIF)) + 1;
    742869 
    743870  // Minimal handling on continuum data.
    744871  Vector<Double> chanFreq = cChanFreqCol(iIF);
     872  pksrec.nchan = nChan;
    745873  if (nChan == 1) {
    746     freqInc  = chanFreq(0);
    747     refFreq  = chanFreq(0);
    748     restFreq = 0.0f;
     874    //pksrec.freqInc  = chanFreq(0);
     875    pksrec.freqInc  = cTotBWCol(iIF);
     876    pksrec.refFreq  = chanFreq(0);
     877    pksrec.restFreq.resize(1);
     878    pksrec.restFreq[0] = 0.0f;
    749879  } else {
    750880 
    751881    if (cStartChan(iIF) <= cEndChan(iIF)) {
    752       freqInc = chanFreq(1) - chanFreq(0);
     882      pksrec.freqInc = chanFreq(1) - chanFreq(0);
    753883    } else {
    754       freqInc = chanFreq(0) - chanFreq(1);
    755     }
    756     refFreq  = chanFreq(cRefChan(iIF)-1);
     884      pksrec.freqInc = chanFreq(0) - chanFreq(1);
     885    }
     886
     887    pksrec.refFreq  = chanFreq(cRefChan(iIF)-1);
     888
    757889    Bool HaveSrcRestFreq= cSrcRestFrqCol.isDefined(srcId);
    758890    if (HaveSrcRestFreq) {
    759891      //restFreq = cSrcRestFrqCol(srcId)(IPosition(1,0));
    760       restFreq = cSrcRestFrqCol(srcId);
     892      //restFreq = cSrcRestFrqCol(srcId);
     893      pksrec.restFreq = cSrcRestFrqCol(srcId);
    761894    } else {
    762       restFreq = 0.0f;
    763     }
    764   }
    765   bandwidth = abs(freqInc * nChan);
    766 
    767   tcal.resize(cNPol(iIF));
    768   tcal      = 0.0f;
    769   tcalTime  = "";
    770   //azimuth   = 0.0f;
    771   //elevation = 0.0f;
    772   parAngle  = 0.0f;
    773   focusAxi  = 0.0f;
    774   focusTan  = 0.0f;
    775   focusRot  = 0.0f;
     895      pksrec.restFreq.resize(1);
     896      pksrec.restFreq[0] = 0.0f;
     897    }
     898  }
     899  //pksrec.bandwidth = abs(pksrec.freqInc * nChan);
     900  pksrec.bandwidth = abs(cTotBWCol(0));
     901
     902  pksrec.tcal.resize(cNPol(iIF));
     903  pksrec.tcal      = 0.0f;
     904  pksrec.tcalTime  = "";
     905//  pksrec.azimuth   = 0.0f;
     906//  pksrec.elevation = 0.0f;
     907  pksrec.parAngle  = 0.0f;
     908
     909  pksrec.focusAxi  = 0.0f;
     910  pksrec.focusTan  = 0.0f;
     911  pksrec.focusRot  = 0.0f;
    776912
    777913  // Find the appropriate entry in the WEATHER subtable.
     
    787923    }
    788924  }
     925
    789926  if (weatherIdx < 0 || !cHaveWeatherTab) {
    790927    // No appropriate WEATHER entry.
    791     pressure    = 0.0f;
    792     humidity    = 0.0f;
    793     temperature = 0.0f;
     928    pksrec.temperature = 0.0f;
     929    pksrec.pressure    = 0.0f;
     930    pksrec.humidity    = 0.0f;
    794931  } else {
    795     pressure    = cPressureCol(weatherIdx);
    796     humidity    = cHumidityCol(weatherIdx);
    797     temperature = cTemperatureCol(weatherIdx);
    798   }
    799 
    800   windSpeed = 0.0f;
    801   windAz    = 0.0f;
    802 
    803   refBeam = 0;
    804   beamNo  = ibeam + 1;
    805 
    806   //Matrix<Double> pointingDir = cPointingCol(fieldId);
    807   //pointingDir = cPointingCol(fieldId);
    808   //direction = pointingDir.column(0);
    809   //uInt ncols = pointingDir.ncolumn();
    810   //if (ncols == 1) {
    811   //  scanRate = 0.0f;
    812   //} else {
    813   //  scanRate  = pointingDir.column(1);
    814   //}
    815 
     932    pksrec.temperature = cTemperatureCol(weatherIdx);
     933    pksrec.pressure    = cPressureCol(weatherIdx);
     934    pksrec.humidity    = cHumidityCol(weatherIdx);
     935  }
     936
     937  pksrec.windSpeed = 0.0f;
     938  pksrec.windAz    = 0.0f;
     939
     940  pksrec.refBeam = 0;
     941  pksrec.beamNo  = ibeam + 1;
     942
     943  //pointing/azel
     944  MVPosition mvpos(antennaCols.position()(cAntId[0]));
     945  MPosition mp(mvpos);
     946  Quantum<Double> qt(time,"s");
     947  MVEpoch mvt(qt);
     948  MEpoch me(mvt);
     949  MeasFrame frame(mp, me);
     950  MDirection md;
     951  pksrec.pCode = 0;
     952  pksrec.rateAge = 0.0f;
     953  pksrec.paRate = 0.0f;
     954  if (cGetPointing) {
     955    //cerr << "get pointing data ...." << endl;
     956    ROScalarColumn<Int> pAntIdCol ;
     957    ROScalarColumn<Double> psTimeCol ;
     958    Table ptTable = cPKSMS.pointing() ;
     959    MSPointing selPtTab( ptTable( ptTable.col("ANTENNA_ID") == cAntId[0] ) ) ;
     960    pAntIdCol.attach( selPtTab, "ANTENNA_ID" ) ;
     961    Vector<Int> antIds = pAntIdCol.getColumn() ;
     962    psTimeCol.attach( selPtTab, "TIME" ) ;
     963    Vector<Double> pTimes = psTimeCol.getColumn();
     964    Bool doInterp = False ;
     965    Int PtIdx=-1;
     966    for (PtIdx = pTimes.nelements()-1; PtIdx >= 0; PtIdx--) {
     967      if ( pTimes[PtIdx] == time ) {
     968        break ;
     969      }
     970      else if ( pTimes[PtIdx] < time ) {
     971        if ( PtIdx != pTimes.nelements()-1 ) {
     972          doInterp = True ;
     973        }
     974        break ;
     975      }
     976    }
     977    if ( PtIdx == -1 ) {
     978      PtIdx = 0 ;
     979    }
     980    //cerr << "got index=" << PtIdx << endl;
     981    Matrix<Double> pointingDir = cPointingCol(PtIdx);
     982    ROMSPointingColumns PtCols( selPtTab ) ;
     983    Vector<Double> pointingDirVec ;
     984    if ( doInterp ) {
     985      Double dt1 = time - pTimes[PtIdx] ;
     986      Double dt2 = pTimes[PtIdx+1] - time ;
     987      Vector<Double> dirVec1 = pointingDir.column(0) ;
     988      Matrix<Double> pointingDir2 = cPointingCol(PtIdx+1) ;
     989      Vector<Double> dirVec2 = pointingDir2.column(0) ;
     990      pointingDirVec = (dt1*dirVec2+dt2*dirVec1)/(dt1+dt2) ;
     991      Vector<MDirection> vmd1(1) ;
     992      Vector<MDirection> vmd2(1) ;
     993      PtCols.directionMeasCol().get(PtIdx,vmd1) ;
     994      Vector<Double> angle1 = vmd1(0).getAngle().getValue("rad") ;
     995      PtCols.directionMeasCol().get(PtIdx+1,vmd2) ;
     996      Vector<Double> angle2 = vmd2(0).getAngle().getValue("rad") ;
     997      Vector<Double> angle = (dt1*angle2+dt2*angle1)/(dt1+dt2) ;
     998      Quantum< Vector<Double> > qangle( angle, "rad" ) ;
     999      String typeStr = vmd1(0).getRefString() ;
     1000      //cerr << "vmd1.getRefString()=" << typeStr << endl ;
     1001      MDirection::Types mdType ;
     1002      MDirection::getType( mdType, typeStr ) ;
     1003      //cerr << "mdType=" << mdType << endl ;
     1004      md = MDirection( qangle, mdType ) ;
     1005      //cerr << "md=" << md.getAngle().getValue("rad") << endl ;
     1006    }
     1007    else {
     1008      pointingDirVec = pointingDir.column(0) ;
     1009      Vector<MDirection> vmd(1);
     1010      PtCols.directionMeasCol().get(PtIdx,vmd);
     1011      md = vmd[0];
     1012    }
     1013    // put J2000 coordinates in "direction"
     1014    if (cDirRef =="J2000") {
     1015      pksrec.direction = pointingDirVec ;
     1016    }
     1017    else {
     1018      pksrec.direction =
     1019        MDirection::Convert(md, MDirection::Ref(MDirection::J2000,
     1020                                                frame)
     1021                            )().getAngle("rad").getValue();
     1022     
     1023    }
     1024    uInt ncols = pointingDir.ncolumn();
     1025    pksrec.scanRate.resize(2);
     1026    if (ncols == 1) {
     1027      pksrec.scanRate = 0.0f;
     1028    } else {
     1029      pksrec.scanRate(0) = pointingDir.column(1)(0);
     1030      pksrec.scanRate(1) = pointingDir.column(1)(1);
     1031    }
     1032  }
     1033  else {
    8161034  // Get direction from FIELD table
    8171035  // here, assume direction to be the field direction not pointing
    818   Matrix<Double> delayDir = cFieldDelayDirCol(fieldId);
    819   direction = delayDir.column(0);
    820   uInt ncols = delayDir.ncolumn();
    821   if (ncols == 1) {
    822     scanRate = 0.0f;
    823   } else {
    824     scanRate  = delayDir.column(1);
    825   }
    826 
     1036    Matrix<Double> delayDir = cFieldDelayDirCol(fieldId);
     1037    pksrec.direction = delayDir.column(0);
     1038    uInt ncols = delayDir.ncolumn();
     1039    pksrec.scanRate.resize(2);
     1040    if (ncols == 1) {
     1041      pksrec.scanRate = 0.0f;
     1042    } else {
     1043      pksrec.scanRate(0)  = delayDir.column(1)(0);
     1044      pksrec.scanRate(1)  = delayDir.column(1)(1);
     1045    }
     1046  }
    8271047  // caluculate azimuth and elevation
    8281048  // first, get the reference frame
     1049 /**
    8291050  MVPosition mvpos(antennaCols.position()(0));
    8301051  MPosition mp(mvpos);
     
    8331054  MEpoch me(mvt);
    8341055  MeasFrame frame(mp, me);
     1056  **/
    8351057  //
    8361058  ROMSFieldColumns fldCols(cPKSMS.field());
    8371059  Vector<MDirection> vmd(1);
    838   MDirection md;
     1060  //MDirection md;
    8391061  fldCols.delayDirMeasCol().get(fieldId,vmd);
    8401062  md = vmd[0];
     
    8471069                            )().getAngle("rad").getValue();
    8481070  //cerr<<"azel="<<azel<<endl;
    849   azimuth = azel[0];
    850   elevation = azel[1];
     1071  pksrec.azimuth = azel[0];
     1072  pksrec.elevation = azel[1];
    8511073
    8521074  // Get Tsys assuming that entries in the SYSCAL table match the main table.
     
    8581080  }
    8591081  if (cHaveTsys) {
    860     cTsysCol.get(cIdx, tsys, True);
     1082    cTsysCol.get(cIdx, pksrec.tsys, True);
    8611083  } else {
    8621084    Int numReceptor;
    8631085    cNumReceptorCol.get(0, numReceptor);
    864     tsys.resize(numReceptor);
    865     tsys = 1.0f;
    866   }
    867   cSigmaCol.get(cIdx, sigma, True);
     1086    pksrec.tsys.resize(numReceptor);
     1087    pksrec.tsys = 1.0f;
     1088  }
     1089  cSigmaCol.get(cIdx, pksrec.sigma, True);
    8681090
    8691091  //get Tcal if available
     
    8751097    if (nTcalColRow > 0) { 
    8761098    // find tcal match with the data with the data time stamp
    877       Double mjds = mjd*(24*3600);
     1099      Double mjds = pksrec.mjd*(24*3600);
    8781100      Double dtcalTime;
    879       if ( mjd > lastmjd || cIdx==0 ) {
     1101      if ( pksrec.mjd > lastmjd || cIdx==0 ) {
    8801102        //Table tmptab = cSysCalTab(near(cSysCalTab.col("TIME"),mjds));
    8811103        tmptab = cSysCalTab(near(cSysCalTab.col("TIME"),mjds), nrws);
     
    8981120      ROScalarColumn<Double> tcalTimeCol(tmptab2, "TIME");
    8991121      if (syscalrow==0) {
    900         cerr<<"Cannot find any matching Tcal at/near the data timestamp."
    901            << " Set Tcal=0.0"<<endl;
     1122        os << LogIO::NORMAL
     1123           <<"Cannot find any matching Tcal at/near the data timestamp."
     1124           << " Set Tcal=0.0" << LogIO::POST ;
    9021125      } else {
    903         tcalCol.get(0, tcal);
     1126        tcalCol.get(0, pksrec.tcal);
    9041127        tcalTimeCol.get(0,dtcalTime);
    905         tcalTime = MVTime(dtcalTime/(24*3600)).string(MVTime::YMD);
     1128        pksrec.tcalTime = MVTime(dtcalTime/(24*3600)).string(MVTime::YMD);
    9061129        //DEBUG
    9071130        //cerr<<"cIdx:"<<cIdx<<" tcal="<<tcal<<" tcalTime="<<tcalTime<<endl;
     
    9101133      }
    9111134    }
    912     lastmjd = mjd;
     1135    lastmjd = pksrec.mjd;
    9131136  }
    9141137
    9151138  // Calibration factors (if available).
    916   calFctr.resize(cNPol(iIF));
     1139  pksrec.calFctr.resize(cNPol(iIF));
    9171140  if (cHaveCalFctr) {
    918     cCalFctrCol.get(cIdx, calFctr);
     1141    cCalFctrCol.get(cIdx, pksrec.calFctr);
    9191142  } else {
    920     calFctr = 0.0f;
     1143    pksrec.calFctr = 0.0f;
    9211144  }
    9221145
    9231146  // Baseline parameters (if available).
    9241147  if (cHaveBaseLin) {
    925     baseLin.resize(2,cNPol(iIF));
    926     cBaseLinCol.get(cIdx, baseLin);
    927 
    928     baseSub.resize(9,cNPol(iIF));
    929     cBaseSubCol.get(cIdx, baseSub);
     1148    pksrec.baseLin.resize(2,cNPol(iIF));
     1149    cBaseLinCol.get(cIdx, pksrec.baseLin);
     1150
     1151    pksrec.baseSub.resize(24,cNPol(iIF));
     1152    cBaseSubCol.get(cIdx, pksrec.baseSub);
    9301153
    9311154  } else {
    932     baseLin.resize(0,0);
    933     baseSub.resize(0,0);
    934   }
     1155    pksrec.baseLin.resize(0,0);
     1156    pksrec.baseSub.resize(0,0);
     1157  }
     1158
     1159
    9351160  // Get spectral data.
    9361161  if (cGetSpectra) {
     
    9601185    // Transpose spectra.
    9611186    Int nPol = tmpData.nrow();
    962     spectra.resize(nChan, nPol);
    963     flagged.resize(nChan, nPol);
     1187    pksrec.spectra.resize(nChan, nPol);
     1188    pksrec.flagged.resize(nChan, nPol);
    9641189    if (cEndChan(iIF) >= cStartChan(iIF)) {
    9651190      // Simple transposition.
    9661191      for (Int ipol = 0; ipol < nPol; ipol++) {
    9671192        for (Int ichan = 0; ichan < nChan; ichan++) {
    968           spectra(ichan,ipol) = tmpData(ipol,ichan);
    969           flagged(ichan,ipol) = tmpFlag(ipol,ichan);
     1193          pksrec.spectra(ichan,ipol) = tmpData(ipol,ichan);
     1194          pksrec.flagged(ichan,ipol) = tmpFlag(ipol,ichan);
    9701195        }
    9711196      }
     
    9761201      for (Int ipol = 0; ipol < nPol; ipol++) {
    9771202        for (Int ichan = 0; ichan < nChan; ichan++, jchan--) {
    978           spectra(ichan,ipol) = tmpData(ipol,jchan);
    979           flagged(ichan,ipol) = tmpFlag(ipol,jchan);
     1203          pksrec.spectra(ichan,ipol) = tmpData(ipol,jchan);
     1204          pksrec.flagged(ichan,ipol) = tmpFlag(ipol,jchan);
    9801205        }
    9811206      }
    9821207    }
     1208
     1209    // Row-based flagging info. (True:1, False:0)
     1210    pksrec.flagrow = (cFlagRowCol(cIdx) ? 1 : 0);
    9831211  }
    9841212
     
    9891217
    9901218    if (cHaveXCalFctr) {
    991       cXCalFctrCol.get(cIdx, xCalFctr);
     1219      cXCalFctrCol.get(cIdx, pksrec.xCalFctr);
    9921220    } else {
    993       xCalFctr = Complex(0.0f, 0.0f);
    994     }
    995 
    996     if(!cATF) {
    997       cDataCol.get(cIdx, xPol, True);
     1221      pksrec.xCalFctr = Complex(0.0f, 0.0f);
     1222    }
     1223
     1224    if(!cALMA) {
     1225      cDataCol.get(cIdx, pksrec.xPol, True);
    9981226
    9991227      if (cEndChan(iIF) < cStartChan(iIF)) {
     
    10011229        Int jchan = nChan - 1;
    10021230        for (Int ichan = 0; ichan < nChan/2; ichan++, jchan--) {
    1003           ctmp = xPol(ichan);
    1004           xPol(ichan) = xPol(jchan);
    1005           xPol(jchan) = ctmp;
     1231          ctmp = pksrec.xPol(ichan);
     1232          pksrec.xPol(ichan) = pksrec.xPol(jchan);
     1233          pksrec.xPol(jchan) = ctmp;
    10061234        }
    10071235      }
     
    10971325    cBaseLinCol.get(cIdx, baseLin);
    10981326
    1099     baseSub.resize(9,cNPol(iIF));
     1327    baseSub.resize(24,cNPol(iIF));
    11001328    cBaseSubCol.get(cIdx, baseSub);
    11011329
     
    11581386  cMSopen = False;
    11591387}
     1388
     1389//-------------------------------------------------------- PKSMS2reader::splitAntenanSelectionString
     1390
     1391// split antenna selection string
     1392// delimiter is ','
     1393
     1394Vector<String> PKSMS2reader::splitAntennaSelectionString( const String s )
     1395{
     1396  Char delim = ',' ;
     1397  Int n = s.freq( delim ) + 1 ;
     1398  Vector<String> antlist ;
     1399  string sl[n] ;
     1400  Int numSubstr = split( s, sl, n, "," );
     1401  antlist.resize( numSubstr ) ;
     1402  for ( Int i = 0 ; i < numSubstr ; i++ ) {
     1403    antlist[i] = String( sl[i] ) ;
     1404    antlist[i].trim() ;
     1405  }
     1406  //cerr << "antlist = " << antlist << endl ;
     1407  return antlist ;
     1408}
     1409
     1410//-------------------------------------------------------- PKSMS2reader::setupAntennaList
     1411
     1412// Fill cAntenna and cAntId
     1413
     1414void PKSMS2reader::setupAntennaList( const String s )
     1415{
     1416  LogIO os( LogOrigin( "PKSMS2reader", "setupAntennaList()", WHERE ) ) ;
     1417  //cerr << "antenna specification: " << s << endl ;
     1418  ROMSAntennaColumns antennaCols(cPKSMS.antenna());
     1419  ROScalarColumn<String> antNames = antennaCols.name();
     1420  Int nrow = antNames.nrow() ;
     1421  Vector<String> antlist = splitAntennaSelectionString( s ) ;
     1422  Int len = antlist.size() ;
     1423  Vector<Int> AntId( len ) ;
     1424  Regex re( "[0-9]+" ) ;
     1425  for ( Int i = 0 ; i < len ; i++ ) {
     1426    if ( antlist[i].matches( re ) ) {
     1427      AntId[i] = atoi( antlist[i].c_str() ) ;
     1428      if ( AntId[i] >= nrow ) {
     1429        os << LogIO::SEVERE << "Antenna index out of range: " << AntId[i] << LogIO::EXCEPTION ;
     1430      }
     1431    }
     1432    else {
     1433      AntId[i] = -1 ;
     1434      for ( uInt j = 0 ; j < antNames.nrow() ; j++ ) {
     1435        if ( antlist[i] == antNames(j) ) {
     1436          AntId[i] = j ;
     1437          break ;
     1438        }
     1439      }
     1440      if ( AntId[i] == -1 ) {
     1441        os << LogIO::SEVERE << "Specified antenna name not found: " << antlist[i] << LogIO::EXCEPTION ;
     1442      }
     1443    }
     1444  }
     1445  //cerr << "AntId = " << AntId << endl ;
     1446  vector<Int> uniqId ;
     1447  uniqId.push_back( AntId(0) ) ;
     1448  for ( uInt i = 1 ; i < AntId.size() ; i++ ) {
     1449    if ( count(uniqId.begin(),uniqId.end(),AntId[i]) == 0 ) {
     1450      uniqId.push_back( AntId[i] ) ;
     1451    }
     1452  }
     1453  Vector<Int> newAntId( uniqId ) ;
     1454  cAntId.assign( newAntId ) ;
     1455  //cerr << "cAntId = " << cAntId << endl ;
     1456}
Note: See TracChangeset for help on using the changeset viewer.