Changeset 1987


Ignore:
Timestamp:
02/02/11 13:15:19 (13 years ago)
Author:
Takeshi Nakazato
Message:

New Development: No

JIRA Issue: Yes CAS-2718

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No?

Module(s): Module Names change impacts.

Description: Describe your changes here...

Improved MSFiller/MSWriter.
Changed Scantable::get_antennaName() to fit with MSFiller/MSWriter.


Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/MSFiller.cpp

    r1978 r1987  
    1717#include <tables/Tables/ExprNode.h>
    1818#include <tables/Tables/TableIter.h>
     19#include <tables/Tables/TableColumn.h>
    1920#include <tables/Tables/ScalarColumn.h>
    2021#include <tables/Tables/ArrayColumn.h>
     22#include <tables/Tables/RefRows.h>
     23#include <tables/Tables/TableParse.h>
    2124#include <tables/Tables/RefRows.h>
    2225
     
    2528#include <casa/Arrays/Slicer.h>
    2629#include <casa/Quanta/MVTime.h>
     30#include <casa/OS/Path.h>
    2731
    2832#include <measures/Measures/Stokes.h>
    2933#include <measures/Measures/MEpoch.h>
     34#include <measures/Measures/MCEpoch.h>
     35#include <measures/Measures/MFrequency.h>
     36#include <measures/Measures/MCFrequency.h>
     37#include <measures/Measures/MPosition.h>
     38#include <measures/Measures/MCPosition.h>
     39#include <measures/Measures/MDirection.h>
     40#include <measures/Measures/MCDirection.h>
     41#include <measures/Measures/MeasConvert.h>
    3042#include <measures/TableMeasures/ScalarMeasColumn.h>
     43#include <measures/TableMeasures/ArrayMeasColumn.h>
     44#include <measures/TableMeasures/ScalarQuantColumn.h>
     45#include <measures/TableMeasures/ArrayQuantColumn.h>
    3146
    3247#include <atnf/PKSIO/SrcType.h>
     
    4156MSFiller::MSFiller( casa::CountedPtr<Scantable> stable )
    4257  : table_( stable ),
     58    tablename_( "" ),
    4359    antenna_( -1 ),
    4460    getPt_( False ),
     
    6581{
    6682  os_.origin( LogOrigin( "MSFiller", "open()", WHERE ) ) ;
     83  //os_ << "start MSFiller::open()" << LogIO::POST ;
    6784  //os_ << "   filename = " << filename << endl ;
    68   //rec.print( os_.output(), 25, "      " ) ;
    69   //os_ << LogIO::POST ;
    7085
    7186  // parsing MS options
    72   //Int antenna = 0 ;
    73   //Bool getPt = False;
    74 
    7587  if ( rec.isDefined( "ms" ) ) {
    7688    Record msrec = rec.asRecord( "ms" ) ;
     
    95107  os_ << "   antenna = " << antenna_ << LogIO::POST ;
    96108
    97   mstable_ = MeasurementSet( filename, Table::Old ) ;
     109  MeasurementSet *tmpMS = new MeasurementSet( filename, Table::Old ) ;
     110  //mstable_ = (*tmpMS)( tmpMS->col("ANTENNA1") == antenna_
     111  //                     && tmpMS->col("ANTENNA1") == tmpMS->col("ANTENNA2") ) ;
     112  tablename_ = tmpMS->tableName() ;
     113  mstable_ = MeasurementSet( (*tmpMS)( tmpMS->col("ANTENNA1") == antenna_
     114                                       && tmpMS->col("ANTENNA1") == tmpMS->col("ANTENNA2") ) ) ;
     115//   stringstream ss ;
     116//   ss << "SELECT FROM $1 WHERE ANTENNA1 == ANTENNA2 && ANTENNA1 == " << antenna_ ;
     117//   String taql( ss.str() ) ;
     118//   mstable_ = MeasurementSet( tableCommand( taql, *tmpMS ) ) ;
     119  delete tmpMS ;
    98120
    99121  // check which data column exists
    100   isFloatData_ = mstable_.isColumn( MSMainEnums::FLOAT_DATA ) ;
    101   isData_ = mstable_.isColumn( MSMainEnums::DATA ) ;
    102 
     122  isFloatData_ = mstable_.tableDesc().isColumn( "FLOAT_DATA" ) ;
     123  isData_ = mstable_.tableDesc().isColumn( "DATA" ) ;
     124
     125  //os_ << "end MSFiller::open()" << LogIO::POST ;
    103126  return true ;
    104127}
     
    107130{
    108131  os_.origin( LogOrigin( "MSFiller", "fill()", WHERE ) ) ;
    109 
    110   tablesel_ = mstable_( mstable_.col("ANTENNA1") == mstable_.col("ANTENNA2") 
    111                         && mstable_.col("ANTENNA1") == antenna_ ) ;
     132  //os_ << "start MSFiller::fill()" << LogIO::POST ;
    112133
    113134  // Initialize header
     
    132153 
    133154  // check if optional table exists
    134   const TableRecord msrec = tablesel_.keywordSet() ;
     155  //const TableRecord msrec = tablesel_.keywordSet() ;
     156  const TableRecord msrec = mstable_.keywordSet() ;
    135157  isDoppler_ = msrec.isDefined( "DOPPLER" ) ;
    136158  isFlagCmd_ = msrec.isDefined( "FLAG_CMD" ) ;
     
    142164 
    143165  // Access to MS subtables
    144   MSField fieldtab = tablesel_.field() ;
    145   MSPolarization poltab = tablesel_.polarization() ;
    146   MSDataDescription ddtab = tablesel_.dataDescription() ;
    147   MSObservation obstab = tablesel_.observation() ;
    148   MSSource srctab = tablesel_.source() ;
    149   MSSpectralWindow spwtab = tablesel_.spectralWindow() ;
    150   MSSysCal caltab = tablesel_.sysCal() ;
     166  MSField fieldtab = mstable_.field() ;
     167  MSPolarization poltab = mstable_.polarization() ;
     168  MSDataDescription ddtab = mstable_.dataDescription() ;
     169  MSObservation obstab = mstable_.observation() ;
     170  MSSource srctab = mstable_.source() ;
     171  MSSpectralWindow spwtab = mstable_.spectralWindow() ;
     172  MSSysCal caltab = mstable_.sysCal() ;
    151173  if ( caltab.nrow() == 0 )
    152174    isSysCal_ = False ;
    153   MSPointing pointtab = tablesel_.pointing() ;
    154   MSWeather weathertab = tablesel_.weather() ;
    155   if ( weathertab.nrow() == 0 )
     175  MSPointing pointtab = mstable_.pointing() ;
     176  if ( mstable_.weather().nrow() == 0 )
    156177    isWeather_ = False ;
    157 
    158 //   os_ << "isDoppler_ = " << isDoppler_ << endl
    159 //       << "isFlagCmd_ = " << isFlagCmd_ << endl
    160 //       << "isFreqOffset_ = " << isFreqOffset_ << endl
    161 //       << "isHistory_ = " << isHistory_ << endl
    162 //       << "isProcessor_ = " << isProcessor_ << endl
    163 //       << "isSysCal_ = " << isSysCal_ << endl
    164 //       << "isWeather_ = " << isWeather_ << LogIO::POST ;
    165 
    166  // SUBTABLES: FREQUENCIES
    167   //fillFrequencies() ;
     178  MSState stattab = mstable_.state() ;
     179  MSAntenna anttab = mstable_.antenna() ;
     180
     181  // TEST
     182  // memory allocation by boost::object_pool
     183  boost::object_pool<ROTableColumn> *tpoolr = new boost::object_pool<ROTableColumn> ;
     184  boost::object_pool<TableColumn> *tpoolw = new boost::object_pool<TableColumn> ;
     185  //
     186
     187  // SUBTABLES: FREQUENCIES
    168188  table_->frequencies().setFrame( "LSRK" ) ;
    169189  table_->frequencies().setFrame( "LSRK", True ) ;
     
    178198  // SUBTABLES: TCAL
    179199  if ( isSysCal_ )
    180     fillTcal() ;
    181 
    182   // SUBTABLES: MOLECULES
    183   //fillMolecules() ;
     200    fillTcal( tpoolr ) ;
    184201
    185202  // SUBTABLES: FIT
     
    189206  //fillHistory() ;
    190207
     208  // shared pointers
     209  ROTableColumn *tcolr ;
     210  TableColumn *tcolw ;
     211
     212  // Scantable columns
     213  Table stab = table_->table() ;
     214  TableColumn *scannoCol = tpoolw->construct( stab, "SCANNO" ) ;
     215  TableColumn *cyclenoCol = tpoolw->construct( stab, "CYCLENO" ) ;
     216  TableColumn *beamnoCol = tpoolw->construct( stab, "BEAMNO" ) ;
     217  TableColumn *ifnoCol = tpoolw->construct( stab, "IFNO" ) ;
     218  TableColumn *polnoCol = tpoolw->construct( stab, "POLNO" ) ;
     219  TableColumn *freqidCol = tpoolw->construct( stab, "FREQ_ID" ) ;
     220  TableColumn *molidCol = tpoolw->construct( stab, "MOLECULE_ID" ) ;
     221  TableColumn *flagrowCol = tpoolw->construct( stab, "FLAGROW" ) ;
     222  ScalarMeasColumn<MEpoch> *timeCol = new ScalarMeasColumn<MEpoch>( stab, "TIME" ) ;
     223  TableColumn *intervalCol = tpoolw->construct( stab, "INTERVAL" ) ;
     224  TableColumn *srcnameCol = tpoolw->construct( stab, "SRCNAME" ) ;
     225  TableColumn *srctypeCol = tpoolw->construct( stab, "SRCTYPE" ) ;
     226  TableColumn *fieldnameCol = tpoolw->construct( stab, "SRCNAME" ) ;
     227  ArrayColumn<Float> *spCol = new ArrayColumn<Float>( stab, "SPECTRA" ) ;
     228  ArrayColumn<uChar> *flCol = new ArrayColumn<uChar>( stab, "FLAGTRA" ) ;
     229  ArrayColumn<Float> *tsysCol = new ArrayColumn<Float>( stab, "TSYS" ) ;
     230  ArrayColumn<Double> *dirCol = new ArrayColumn<Double>( stab, "DIRECTION" ) ;
     231  TableColumn *azCol = tpoolw->construct( stab, "AZIMUTH" ) ;
     232  TableColumn *elCol = tpoolw->construct( stab, "ELEVATION" ) ;
     233  TableColumn *tcalidCol = tpoolw->construct( stab, "TCAL_ID" ) ;
     234  TableColumn *focusidCol = tpoolw->construct( stab, "FOCUS_ID" ) ;
     235  TableColumn *weatheridCol = tpoolw->construct( stab, "WEATHER_ID" ) ;
     236  ArrayColumn<Double> *srcpmCol = new ArrayColumn<Double>( stab, "SRCPROPERMOTION" ) ;
     237  ArrayColumn<Double> *srcdirCol = new ArrayColumn<Double>( stab, "SRCDIRECTION" ) ;
     238  TableColumn *srcvelCol = tpoolw->construct( stab, "SRCVELOCITY" ) ;
     239  ArrayColumn<Double> *scanrateCol = new ArrayColumn<Double>( stab, "SCANRATE" ) ;
     240 
    191241  // MAIN
    192242  // Iterate over several ids
    193243  Int oldnr = table_->nrow() ;
    194244  map<Int, uInt> ifmap ; // (IFNO, FREQ_ID) pair
    195   ROMSAntennaColumns antCols( mstable_.antenna() ) ;
    196   Vector< Quantum<Double> > antpos = antCols.positionQuant()(antenna_) ;
     245  ROArrayQuantColumn<Double> *sharedQDArrCol = new ROArrayQuantColumn<Double>( anttab, "POSITION" ) ;
     246  Vector< Quantum<Double> > antpos = (*sharedQDArrCol)( antenna_ ) ;
     247  delete sharedQDArrCol ;
    197248  MPosition mp( MVPosition( antpos ), MPosition::ITRF ) ;
    198   MSPointing potabsel = pointtab( pointtab.col("ANTENNA_ID")==antenna_ ).sort("TIME") ;
    199   String stationName = antCols.station()(antenna_) ;
    200   ROMSPointingColumns pointCols( potabsel ) ;
    201   String telescopeName ;
     249  //pointtab = pointtab( pointtab.col("ANTENNA_ID")==antenna_ ).sort("TIME") ;
     250  pointtab = MSPointing( pointtab( pointtab.col("ANTENNA_ID")==antenna_ ).sort("TIME") ) ;
     251  tcolr = tpoolr->construct( anttab, "STATION" ) ;
     252  String stationName = tcolr->asString( antenna_ ) ;
     253  tpoolr->destroy( tcolr ) ;
     254  tcolr = tpoolr->construct( anttab, "NAME" ) ;
     255  String antennaName = tcolr->asString( antenna_ ) ;
     256  tpoolr->destroy( tcolr ) ;
     257  sdh.antennaposition.resize( 3 ) ;
     258  for ( int i = 0 ; i < 3 ; i++ )
     259    sdh.antennaposition[i] = antpos[i].getValue( "m" ) ;
     260  String telescopeName = "" ;
     261
    202262  //
    203263  // ITERATION: OBSERVATION_ID
     
    205265  Int added0 = 0 ;
    206266  Int current0 = table_->nrow() ;
    207   TableIterator iter0( tablesel_, "OBSERVATION_ID" ) ;
     267  TableIterator iter0( mstable_, "OBSERVATION_ID" ) ;
    208268  while( !iter0.pastEnd() ) {
    209     MeasurementSet t0( iter0.table() ) ;
    210     ROScalarColumn<Int> mObsIdCol( t0, "OBSERVATION_ID" ) ;
    211     Int obsId = mObsIdCol( 0 ) ;
    212     ROMSObservationColumns obsCols( obstab ) ;
    213     if ( sdh.observer == "" ) sdh.observer = obsCols.observer()(obsId) ;
    214     if ( sdh.project == "" ) sdh.project = obsCols.project()(obsId) ;
    215     MEpoch me = obsCols.timeRangeMeas()(obsId)(IPosition(1,0)) ;
     269    Table t0 = iter0.table() ;
     270    tcolr = tpoolr->construct( t0, "OBSERVATION_ID" ) ;
     271    Int obsId = tcolr->asInt( 0 ) ;
     272    tpoolr->destroy( tcolr ) ;
     273    if ( sdh.observer == "" ) {
     274      tcolr = tpoolr->construct( obstab, "OBSERVER" ) ;
     275      sdh.observer = tcolr->asString( obsId ) ;
     276      tpoolr->destroy( tcolr ) ;
     277    }
     278    if ( sdh.project == "" ) {
     279      tcolr = tpoolr->construct( obstab, "PROJECT" ) ;
     280      sdh.observer = tcolr->asString( obsId ) ;
     281      tpoolr->destroy( tcolr ) ;
     282    }
     283    ROArrayMeasColumn<MEpoch> *tmpMeasCol = new ROArrayMeasColumn<MEpoch>( obstab, "TIME_RANGE" ) ;
     284    MEpoch me = (*tmpMeasCol)( obsId )( IPosition(1,0) ) ;
     285    delete tmpMeasCol ;
    216286    if ( sdh.utc == 0.0 ) {
    217       Quantum<Double> startTime = obsCols.timeRangeQuant()(obsId)(IPosition(1,0)) ;
    218       sdh.utc = startTime.getValue( "s" ) ;
    219     }
    220     telescopeName = obsCols.telescopeName()(obsId) ;
     287      sdh.utc = me.get( "s" ).getValue() ;
     288    }
     289    if ( telescopeName == "" ) {
     290      tcolr = tpoolr->construct( obstab, "TELESCOPE_NAME" ) ;
     291      sdh.observer = tcolr->asString( obsId ) ;
     292      tpoolr->destroy( tcolr ) ;
     293    }
    221294    Int nbeam = 0 ;
    222295    //
     
    227300    TableIterator iter1( t0, "FEED1" ) ;
    228301    while( !iter1.pastEnd() ) {
    229       MeasurementSet t1( iter1.table() ) ;
    230       ROScalarColumn<Int> mFeedCol( t1, "FEED1" ) ;
    231       Int feedId = mFeedCol( 0 ) ; // assume FEED1 == FEED2
     302      Table t1 = iter1.table() ;
     303      // assume FEED1 == FEED2
     304      tcolr = tpoolr->construct( t1, "FEED1" ) ;
     305      Int feedId = tcolr->asInt( 0 ) ;
     306      tpoolr->destroy( tcolr ) ;
    232307      nbeam++ ;
    233308      //
     
    238313      TableIterator iter2( t1, "FIELD_ID" ) ;
    239314      while( !iter2.pastEnd() ) {
    240         MeasurementSet t2( iter2.table() ) ;
    241         ROScalarColumn<Int> mFieldIdCol( t2, "FIELD_ID" ) ;
    242         Int fieldId = mFieldIdCol( 0 ) ;
    243         ROScalarColumn<String> mFieldNameCol( fieldtab, "NAME" ) ;
    244         ROScalarColumn<Int> mSrcIdCol( fieldtab, "SOURCE_ID" ) ;
    245         String fieldName = mFieldNameCol( fieldId ) + "__" + String::toString(fieldId) ;
    246         Int srcId = mSrcIdCol( fieldId ) ;
     315        Table t2 = iter2.table() ;
     316        tcolr = tpoolr->construct( t2, "FIELD_ID" ) ;
     317        Int fieldId = tcolr->asInt( 0 ) ;
     318        tpoolr->destroy( tcolr ) ;
     319        tcolr = tpoolr->construct( fieldtab, "SOURCE_ID" ) ;
     320        Int srcId = tcolr->asInt( fieldId ) ;
     321        tpoolr->destroy( tcolr ) ;
     322        tcolr = tpoolr->construct( fieldtab, "NAME" ) ;
     323        String fieldName = tcolr->asString( fieldId ) + "__" + String::toString(fieldId) ;
     324        tpoolr->destroy( tcolr ) ;
    247325        //
    248326        // ITERATION: DATA_DESC_ID
     
    252330        TableIterator iter3( t2, "DATA_DESC_ID" ) ;
    253331        while( !iter3.pastEnd() ) {
    254           MeasurementSet t3( iter3.table() ) ;
    255           ROScalarColumn<Int> mDDIdCol( t3, "DATA_DESC_ID" ) ;
    256           Int ddId = mDDIdCol( 0 ) ;
    257           ROMSDataDescColumns ddCols( ddtab ) ;
    258           Int polId = ddCols.polarizationId()(ddId) ;
    259           Int spwId = ddCols.spectralWindowId()(ddId) ;
     332          Table t3 = iter3.table() ;
     333          tcolr = tpoolr->construct( t3, "DATA_DESC_ID" ) ;
     334          Int ddId = tcolr->asInt( 0 ) ;
     335          tpoolr->destroy( tcolr ) ;
     336          tcolr = tpoolr->construct( ddtab, "POLARIZATION_ID" ) ;
     337          Int polId = tcolr->asInt( ddId ) ;
     338          tpoolr->destroy( tcolr ) ;
     339          tcolr = tpoolr->construct( ddtab, "SPECTRAL_WINDOW_ID" ) ;
     340          Int spwId = tcolr->asInt( ddId ) ;
     341          tpoolr->destroy( tcolr ) ;
    260342          // polarization information
    261           ROMSPolarizationColumns polCols( poltab ) ;
    262           Int npol = polCols.numCorr()(polId) ;
    263           Vector<Int> corrtype = polCols.corrType()(polId) ;
     343          tcolr = tpoolr->construct( poltab, "NUM_CORR" ) ;
     344          Int npol = tcolr->asInt( polId ) ;
     345          tpoolr->destroy( tcolr ) ;
     346          ROArrayColumn<Int> *roArrICol = new ROArrayColumn<Int>( poltab, "CORR_TYPE" ) ;
     347          Vector<Int> corrtype = (*roArrICol)( polId ) ;
     348          delete roArrICol ;
    264349          //os_ << "npol = " << npol << LogIO::POST ;
    265350          //os_ << "corrtype = " << corrtype << LogIO::POST ;
     
    269354          MSSource srctabSel( srctab( srctab.col("SOURCE_ID") == srcId && srctab.col("SPECTRAL_WINDOW_ID") == spwId ) ) ;
    270355          //os_ << "srcId = " << srcId << " spwId = " << spwId << " nrow = " << srctabSel.nrow() << LogIO::POST ;
    271           ROMSSourceColumns srcCols( srctabSel ) ;
    272           String srcName = srcCols.name()(0) ;
     356          tcolr = tpoolr->construct( srctabSel, "NAME" ) ;
     357          String srcName = tcolr->asString( 0 ) ;
     358          tpoolr->destroy( tcolr ) ;
    273359          //os_ << "srcName = " << srcName << LogIO::POST ;
    274           Array<Double> srcPM = srcCols.properMotion()(0) ;
     360          ROArrayColumn<Double> *roArrDCol = new ROArrayColumn<Double>( srctabSel, "PROPER_MOTION" ) ;
     361          Array<Double> srcPM = (*roArrDCol)( 0 ) ;
     362          delete roArrDCol ;
    275363          //os_ << "srcPM = " << srcPM << LogIO::POST ;
    276           Array<Double> srcDir = srcCols.direction()(0) ;
     364          roArrDCol = new ROArrayColumn<Double>( srctabSel, "DIRECTION" ) ;
     365          Array<Double> srcDir = (*roArrDCol)( 0 ) ;
     366          delete roArrDCol ;
    277367          //os_ << "srcDir = " << srcDir << LogIO::POST ;
    278           Array<Double> sysVels = srcCols.sysvel()(0) ;
     368          Array<Double> sysVels ;
    279369          Double sysVel = 0.0 ;
     370          if ( srctabSel.tableDesc().isColumn( "SYSVEL" ) ) {
     371            roArrDCol = new ROArrayColumn<Double>( srctabSel, "SYSVEL" ) ;
     372            sysVels = (*roArrDCol)( 0 ) ;
     373            delete roArrDCol ;
     374          }
    280375          if ( !sysVels.empty() ) {
    281376            //os_ << "sysVels.shape() = " << sysVels.shape() << LogIO::POST ;
    282377            // NB: assume all SYSVEL values are the same
    283             Double sysVel = sysVels( IPosition(1,0) ) ;
     378            sysVel = sysVels( IPosition(1,0) ) ;
    284379          }
     380          //delete tmpArrCol ;
    285381          //os_ << "sysVel = " << sysVel << LogIO::POST ;
    286           MDirection md = srcCols.directionMeas()(0) ;
     382          ROScalarMeasColumn<MDirection> *tmpMeasCol = new ROScalarMeasColumn<MDirection>( srctabSel, "DIRECTION" ) ;
     383          MDirection md = (*tmpMeasCol)( 0 ) ;
     384          delete tmpMeasCol ;
    287385          // for MOLECULES subtable
    288           Int numLines = srcCols.numLines()(0) ;
     386          tcolr = tpoolr->construct( srctabSel, "NUM_LINES" ) ;
     387          Int numLines = tcolr->asInt( 0 ) ;
     388          tpoolr->destroy( tcolr ) ;
    289389          //os_ << "numLines = " << numLines << LogIO::POST ;
    290390          Vector<Double> restFreqs( numLines, 0.0 ) ;
    291391          Vector<String> transitionName( numLines, "" ) ;
    292392          if ( numLines != 0 ) {
    293             Array< Quantum<Double> > qRestFreqs = srcCols.restFrequencyQuant()(0) ;
    294             for ( int i = 0 ; i < numLines ; i++ ) {
    295               restFreqs[i] = qRestFreqs( IPosition( 1, i ) ).getValue( "Hz" ) ;
     393            if ( srctabSel.tableDesc().isColumn( "REST_FREQUENCY" ) ) {
     394              sharedQDArrCol = new ROArrayQuantColumn<Double>( srctabSel, "REST_FREQUENCY" ) ;
     395              Array< Quantum<Double> > qRestFreqs = (*sharedQDArrCol)( 0 ) ;
     396              delete sharedQDArrCol ;
     397              for ( int i = 0 ; i < numLines ; i++ ) {
     398                restFreqs[i] = qRestFreqs( IPosition( 1, i ) ).getValue( "Hz" ) ;
     399              }
    296400            }
    297401            //os_ << "restFreqs = " << restFreqs << LogIO::POST ;
    298402            if ( srctabSel.tableDesc().isColumn( "TRANSITION" ) ) {
    299               ROScalarColumn<String> transitionNameCol = srcCols.transition() ;
     403              tcolr = tpoolr->construct( srctabSel, "TRANSITION" ) ;
     404              transitionName = tcolr->asString( 0 ) ;
     405              tpoolr->destroy( tcolr ) ;
    300406              //os_ << "transitionNameCol.nrow() = " << transitionNameCol.nrow() << LogIO::POST ;
    301               transitionName = transitionNameCol(0) ;
    302407            }
    303408          }
     
    305410          // spectral setup
    306411          MeasFrame mf( me, mp, md ) ;
    307           ROMSSpWindowColumns spwCols( spwtab ) ;
    308           MFrequency::Types freqRef = MFrequency::castType((uInt)(spwCols.measFreqRef()(spwId))) ;
    309           Int nchan = spwCols.numChan()(spwId) ;
     412          tcolr = tpoolr->construct( spwtab, "MEAS_FREQ_REF" ) ;
     413          MFrequency::Types freqRef = MFrequency::castType((uInt)(tcolr->asInt(spwId))) ;
     414          tpoolr->destroy( tcolr ) ;
     415          tcolr = tpoolr->construct( spwtab, "NUM_CHAN" ) ;
     416          Int nchan = tcolr->asInt( spwId ) ;
     417          tpoolr->destroy( tcolr ) ;
    310418          Bool even = False ;
    311419          if ( (nchan/2)*2 == nchan ) even = True ;
    312420          if ( sdh.nchan < nchan ) sdh.nchan = nchan ;
    313           Quantum<Double> qtotbw = spwCols.totalBandwidthQuant()(spwId) ;
    314           Double totbw = qtotbw.getValue( "Hz" ) ;
     421          ROScalarQuantColumn<Double> *tmpQuantCol = new ROScalarQuantColumn<Double>( spwtab, "TOTAL_BANDWIDTH" ) ;
     422          Double totbw = (*tmpQuantCol)( spwId ).getValue( "Hz" ) ;
     423          delete tmpQuantCol ;
    315424          if ( sdh.bandwidth < totbw ) sdh.bandwidth = totbw ;
    316425          if ( sdh.freqref == "" )
     
    318427            sdh.freqref = "LSRK" ;
    319428          if ( sdh.reffreq == -1.0 ) {
    320             Quantum<Double> qreffreq = spwCols.refFrequencyQuant()(spwId) ;
     429            tmpQuantCol = new ROScalarQuantColumn<Double>( spwtab, "REF_FREQUENCY" ) ;
     430            Quantum<Double> qreffreq = (*tmpQuantCol)( spwId ) ;
     431            delete tmpQuantCol ;
    321432            if ( freqRef == MFrequency::LSRK ) {
    322433              sdh.reffreq = qreffreq.getValue("Hz") ;
     
    331442          Double refpix = 0.5*(nchan-1) ;
    332443          Double refval = 0.0 ;
    333           Double increment = spwCols.chanWidthQuant()(spwId)(refip).getValue("Hz") ;
     444          sharedQDArrCol = new ROArrayQuantColumn<Double>( spwtab, "CHAN_WIDTH" ) ;
     445          Double increment = (*sharedQDArrCol)( spwId )( refip ).getValue( "Hz" ) ;
     446          delete sharedQDArrCol ;
    334447          //os_ << "nchan = " << nchan << " refchan = " << refchan << "(even=" << even << ") refpix = " << refpix << LogIO::POST ;
    335           Vector< Quantum<Double> > chanFreqs = spwCols.chanFreqQuant()(spwId) ;
     448          sharedQDArrCol = new ROArrayQuantColumn<Double>( spwtab, "CHAN_FREQ" ) ;
     449          Vector< Quantum<Double> > chanFreqs = (*sharedQDArrCol)( spwId ) ;
     450          delete sharedQDArrCol ;
    336451          if ( freqRef == MFrequency::LSRK ) {
    337452            if ( even ) {
     
    365480          // for TSYS and TCAL
    366481          MSSysCal caltabsel( caltab( caltab.col("ANTENNA_ID") == antenna_ && caltab.col("FEED_ID") == feedId && caltab.col("SPECTRAL_WINDOW_ID") == spwId ).sort("TIME") ) ;
    367           //Vector<uInt> tcalidrange = addTcal( caltabsel ) ;
    368482          //
    369483          // ITERATION: SCAN_NUMBER
     
    373487          TableIterator iter4( t3, "SCAN_NUMBER" ) ;
    374488          while( !iter4.pastEnd() ) {
    375             MeasurementSet t4( iter4.table() ) ;
    376             ROScalarColumn<Int> mScanNumCol( t4, "SCAN_NUMBER" ) ;
    377             Int scanNum = mScanNumCol( 0 ) ;
     489            Table t4 = iter4.table() ;
     490            tcolr = tpoolr->construct( t4, "SCAN_NUMBER" ) ;
     491            Int scanNum = tcolr->asInt( 0 ) ;
     492            tpoolr->destroy( tcolr ) ;
    378493            uInt cycle = 0 ;
    379494            //
     
    384499            TableIterator iter5( t4, "STATE_ID" ) ;
    385500            while( !iter5.pastEnd() ) {
    386               MeasurementSet t5( iter5.table().sort( "TIME" ) ) ;
    387               ROScalarColumn<Int> mStateIdCol( t5, "STATE_ID" ) ;
    388               Int stateId = mStateIdCol( 0 ) ;
    389               ROMSStateColumns stateCols( t5.state() ) ;
    390               String obstype = stateCols.obsMode()(stateId) ;
     501              Table t5 = iter5.table() ;
     502              tcolr = tpoolr->construct( t5, "STATE_ID" ) ;
     503              Int stateId = tcolr->asInt( 0 ) ;
     504              tpoolr->destroy( tcolr ) ;
     505              tcolr = tpoolr->construct( stattab, "OBS_MODE" ) ;
     506              String obstype = tcolr->asString( stateId ) ;
     507              tpoolr->destroy( tcolr ) ;
    391508              if ( sdh.obstype == "" ) sdh.obstype = obstype ;
    392509
     
    394511              Int prevnr = oldnr ;
    395512              Int addednr = 0 ;
     513              Int nloop = 0 ;
    396514           
    397515              // SPECTRA, FLAG
    398               ArrayColumn<Float> spCol( table_->table(), "SPECTRA" ) ;
    399               ArrayColumn<uChar> flagCol( table_->table(), "FLAGTRA" ) ;
    400516              ROArrayColumn<Bool> mFlagCol( t5, "FLAG" ) ;
    401517              if ( isFloatData_ ) {
    402518                //os_ << "FLOAT_DATA exists" << LogIO::POST ;
    403519                ROArrayColumn<Float> mFloatDataCol( t5, "FLOAT_DATA" ) ;
    404                 IPosition cShape = mFloatDataCol.shape( 0 ) ;
    405                 IPosition newShape( 2, cShape[1], nrow ) ;
    406                 for ( int ipol = 0 ; ipol < npol ; ipol++ ) {
    407                   table_->table().addRow( nrow ) ;
    408                   addednr += nrow ;
    409                   Int newnr = oldnr + nrow ;
    410                   RefRows rows( oldnr, newnr-1 ) ;
    411                   Slice paxis( ipol, 1, 1 ) ;
    412                   Slice caxis( 0, cShape[1], 1 ) ;
    413                   Slicer slicer( paxis, caxis ) ;
    414                   spCol.putColumnCells( rows, mFloatDataCol.getColumn(slicer).reform(newShape) ) ;
    415                   Array<Bool> flags = mFlagCol.getColumn(slicer).reform(newShape) ;
    416                   Array<uChar> flagtra( flags.shape() ) ;
    417                   convertArray( flagtra, flags ) ;
    418                   flagCol.putColumnCells( rows, flagtra ) ;
    419                   oldnr = newnr ;
     520                addednr = nrow*npol ;
     521                oldnr += addednr ;
     522                table_->table().addRow( addednr ) ;
     523                nloop = npol ;
     524                for ( Int irow = 0 ; irow < nrow ; irow++ ) {
     525                  Matrix<Float> sp = mFloatDataCol( irow ) ;
     526                  for ( Int ipol = 0 ; ipol < npol ; ipol++ ) {
     527                    spCol->put( prevnr+ipol*nrow+irow, sp.row(ipol) ) ;
     528                  }
     529                }
     530                for ( Int irow = 0 ; irow < nrow ; irow++ ) {
     531                  Matrix<Bool> flb = mFlagCol( irow ) ;
     532                  Matrix<uChar> fl( flb.shape() ) ;
     533                  convertArray( fl, flb ) ;
     534                  for ( Int ipol = 0 ; ipol < npol ; ipol++ ) {
     535                    flCol->put( prevnr+ipol*nrow+irow, fl.row(ipol) ) ;
     536                  }
    420537                }
    421538                if ( sdh.fluxunit == "" ) {
     
    428545                //os_ << "DATA exists" << LogIO::POST ;
    429546                ROArrayColumn<Complex> mDataCol( t5, "DATA" ) ;
    430                 IPosition cShape = mDataCol.shape( 0 ) ;
    431                 IPosition newShape( 2, cShape[1], nrow ) ;
    432                 Bool crossOK = False ;
    433                 for ( int ipol = 0 ; ipol < npol ; ipol++ ) {
    434                   //os_ << "corrtype[" << ipol << "] = " << corrtype[ipol] << LogIO::POST ;
    435                   if ( corrtype[ipol] == Stokes::XY || corrtype[ipol] == Stokes::YX
    436                        || corrtype[ipol] == Stokes::RL || corrtype[ipol] == Stokes::LR ) {
    437                     if ( !crossOK ) {
    438                       //os_ << "cross polarization data" << LogIO::POST ;
    439                       table_->table().addRow( nrow, True ) ;
    440                       addednr += nrow ;
    441                       //os_ << "table_->nrow() = " << table_->nrow() << LogIO::POST ;
    442                       Int newnr = oldnr + nrow ;
    443                       RefRows rows( oldnr, newnr-1 ) ;
    444                       Slice paxis( ipol, 1, 1 ) ;
    445                       Slice caxis( 0, cShape[1], 1 ) ;
    446                       Slicer slicer( paxis, caxis ) ;
    447                       Array<Complex> data = mDataCol.getColumn(slicer).reform(newShape) ;
    448                       spCol.putColumnCells( rows, real( data ) ) ;
    449                       Array<Bool> flags = mFlagCol.getColumn(slicer).reform(newShape) ;
    450                       Array<uChar> flagtra( flags.shape() ) ;
    451                       convertArray( flagtra, flags ) ;
    452                       flagCol.putColumnCells( rows, flagtra ) ;
    453                       oldnr = newnr ;
    454                       table_->table().addRow( nrow, True ) ;
    455                       addednr += nrow ;
    456                       newnr = oldnr + nrow ;
    457                       rows = RefRows( oldnr, newnr-1 ) ;
    458                       if ( corrtype[ipol] == Stokes::YX || corrtype[ipol] == Stokes::LR ) {
    459                         data = conj( data ) ;
     547                addednr = nrow*npol ;
     548                oldnr += addednr ;
     549                table_->table().addRow( addednr ) ;
     550                nloop = npol ;
     551                for ( Int irow = 0 ; irow < nrow ; irow++ ) {
     552                  Bool crossOK = False ;
     553                  Matrix<Complex> sp = mDataCol( irow ) ;
     554                  for ( Int ipol = 0 ; ipol < npol ; ipol++ ) {
     555                    if ( corrtype[ipol] == Stokes::XY || corrtype[ipol] == Stokes::YX
     556                         || corrtype[ipol] == Stokes::RL || corrtype[ipol] == Stokes::LR ) {
     557                      if ( !crossOK ) {
     558                        crossOK = True ;
     559                        Int pidx = prevnr + ipol * nrow + irow ;
     560                        spCol->put( pidx, real( sp.row(ipol) ) ) ;
     561                        if ( corrtype[ipol] == Stokes::XY || corrtype[ipol] == Stokes::RL )
     562                          spCol->put( pidx+nrow, imag( sp.row(ipol) ) ) ;
     563                        else
     564                          spCol->put( pidx+nrow, imag( conj(sp.row(ipol)) ) ) ;
    460565                      }
    461                       spCol.putColumnCells( rows, imag( data ) ) ;
    462                       flagCol.putColumnCells( rows, flagtra ) ;
    463                       crossOK = True ;
    464                       oldnr = newnr ;
     566                    }
     567                    else {
     568                      spCol->put( prevnr+ipol*nrow+irow, real( sp.row(ipol) ) ) ;
    465569                    }
    466570                  }
    467                   else {
    468                     table_->table().addRow( nrow, True ) ;
    469                     addednr += nrow ;
    470                     //os_ << "table_->nrow() = " << table_->nrow() << LogIO::POST ;
    471                     Int newnr = oldnr + nrow ;
    472                     RefRows rows( oldnr, newnr-1 ) ;
    473                     Slice paxis( ipol, 1, 1 ) ;
    474                     Slice caxis( 0, cShape[1], 1 ) ;
    475                     Slicer slicer( paxis, caxis ) ;
    476                     Array<Complex> data = mDataCol.getColumn(slicer).reform(newShape) ;
    477                     spCol.putColumnCells( rows, real( data ) ) ;
    478                     Array<Bool> flags = mFlagCol.getColumn(slicer).reform(newShape) ;
    479                     Array<uChar> flagtra( flags.shape() ) ;
    480                     convertArray( flagtra, flags ) ;
    481                     flagCol.putColumnCells( rows, flagtra ) ;
    482                     oldnr = newnr ;
     571                }
     572                for ( Int irow = 0 ; irow < nrow ; irow++ ) {
     573                  Bool crossOK = False ;
     574                  Matrix<Bool> flb = mFlagCol( irow ) ;
     575                  Matrix<uChar> fl( flb.shape() ) ;
     576                  convertArray( fl, flb ) ;
     577                  for ( Int ipol = 0 ; ipol < npol ; ipol++ ) {
     578                    if ( corrtype[ipol] == Stokes::XY || corrtype[ipol] == Stokes::YX
     579                         || corrtype[ipol] == Stokes::RL || corrtype[ipol] == Stokes::LR ) {
     580                      if ( !crossOK ) {
     581                        crossOK = True ;
     582                        Int pidx = prevnr + ipol * nrow + irow ;
     583                        flCol->put( pidx, fl.row(ipol) ) ;
     584                        flCol->put( pidx+nrow, fl.row(ipol+1) ) ;
     585                      }
     586                    }
     587                    else {
     588                      flCol->put( prevnr+ipol*nrow+irow, fl.row(ipol) ) ;
     589                    }
    483590                  }
    484591                }
     
    495602              RefRows rows( prevnr, prevnr+addednr-1 ) ;
    496603
    497               // CYCLENO
    498               ScalarColumn<uInt> cyclenoCol( table_->table(), "CYCLENO" ) ;
    499               Vector<uInt> cycleno( nrow ) ;
    500               indgen( cycleno, cycle ) ;
    501               for ( int i = 0 ; i < addednr ; i += nrow ) {
    502                 Int startrow = prevnr + i ;
    503                 Int endrow = startrow + nrow - 1 ;
    504                 RefRows prows( startrow, endrow ) ;
    505                 cyclenoCol.putColumnCells( prows, cycleno ) ;
    506               }
    507               cycle += nrow ;
    508 
    509               // POLNO
    510               ScalarColumn<uInt> polNoCol( table_->table(), "POLNO" ) ;
    511               Vector<uInt> polno( nrow ) ;
    512               Int pidx = 0 ;
    513               Bool crossOK = False ;
    514               for ( int i = 0 ; i < npol ; i++ ) {
    515                 Vector<uInt> polnos = getPolNo( corrtype[i] ) ;
    516                 if ( polnos.size() > 1 ) {
    517                   if ( crossOK ) continue ;
    518                   else crossOK = True ;
    519                 }
    520                 for ( uInt j = 0 ; j < polnos.size() ; j++ ) {
    521                   Int startrow = prevnr + pidx * nrow ;
    522                   Int endrow = startrow + nrow - 1 ;
    523                   RefRows prows( startrow, endrow ) ;
    524                   polno = polnos[j] ;
    525                   polNoCol.putColumnCells( prows, polno ) ;
    526                   pidx++ ;
    527                 }
    528               }
    529 
    530               // FLAGROW
    531               ScalarColumn<uInt> flagRowCol( table_->table(), "FLAGROW" ) ;
    532               ROScalarColumn<Bool> mFlagRowCol( t5, "FLAG_ROW" ) ;
    533               Vector<uInt> fr( nrow ) ;
    534               convertArray( fr, mFlagRowCol.getColumn() ) ;
    535               for ( int i = 0 ; i < addednr ; i += nrow ) {
    536                 Int startrow = prevnr + i ;
    537                 Int endrow = startrow + nrow - 1 ;
    538                 RefRows prows( startrow, endrow ) ;
    539                 flagRowCol.putColumnCells( prows, fr ) ;
    540               }
    541 
    542604              // TIME
    543               MEpoch::ScalarColumn timeCol( table_->table(), "TIME" ) ;
    544               MEpoch::ROScalarColumn mTimeCol( t5, "TIME" ) ;
     605              ROScalarMeasColumn<MEpoch> *mTimeCol = new ROScalarMeasColumn<MEpoch>( t5, "TIME" ) ;
    545606              Int tidx = prevnr ;
    546               for ( Int i = 0 ; i < addednr ; i += nrow ) {
     607              for ( Int i = 0 ; i < nloop ; i++ ) {
    547608                for ( Int j = 0 ; j < nrow ; j++ ) {
    548                   timeCol.put( tidx++, mTimeCol( j ) ) ;
     609                  timeCol->put( tidx++, (*mTimeCol)( j ) ) ;
    549610                }
    550611              }
    551612           
    552               // INTERVAL
    553               ScalarColumn<Double> intervalCol( table_->table(), "INTERVAL" ) ;
    554               ROScalarColumn<Double> mIntervalCol( t5, "INTERVAL" ) ;
    555               Vector<Double> integ = mIntervalCol.getColumn() ;
    556               for ( int i = 0 ; i < addednr ; i += nrow ) {
    557                 Int startrow = prevnr + i ;
    558                 Int endrow = startrow + nrow - 1 ;
    559                 RefRows prows( startrow, endrow ) ;
    560                 intervalCol.putColumnCells( prows, integ ) ;
    561               }
    562 
    563               // SRCTYPE
    564               ScalarColumn<Int> srcTypeCol( table_->table(), "SRCTYPE" ) ;
    565               Vector<Int> srcType( addednr, getSrcType( stateId ) ) ;
    566               srcTypeCol.putColumnCells( rows, srcType ) ;
    567 
    568613              // TSYS
    569               ArrayColumn<Float> tsysCol( table_->table(), "TSYS" ) ;
    570614              Vector<Double> sysCalTime ;
    571615              if ( isSysCal_ ) {
    572                 sysCalTime = getSysCalTime( caltabsel, mTimeCol ) ;
     616                sysCalTime = getSysCalTime( caltabsel, *mTimeCol ) ;
    573617                tidx = prevnr ;
    574618                uInt calidx = 0 ;
    575619                for ( Int i = 0 ; i < nrow ; i++ ) {
    576                   Array<Float> tsys ;
     620                  Matrix<Float> tsys ;
    577621                  calidx = getTsys( calidx, tsys, caltabsel, sysCalTime(i) ) ;
    578622                  //os_ << "tsys = " << tsys << LogIO::POST ;
    579                   IPosition cShape = tsys.shape() ;
    580                   //os_ << "cShape = " << cShape << LogIO::POST ;
    581                   if ( cShape.size() == 0 ) {
    582                     cShape = IPosition( 1, npol ) ;
     623                  uInt ncol = tsys.ncolumn() ;
     624                  if ( ncol == 0 ) {
     625                    IPosition cShape = IPosition( 2, npol, 1 ) ;
    583626                    tsys.resize( cShape ) ;
    584627                    tsys = 1.0 ;
    585628                  }
    586629                  for ( Int ipol = 0 ; ipol < npol ; ipol++ ) {
    587                     if ( cShape.nelements() == 1 ) {
    588                       Array<Float> subtsys( IPosition(1,1), tsys(IPosition(1,ipol)) ) ;
    589                       tsysCol.put( prevnr+i+nrow*ipol, subtsys ) ;
    590                     }
    591                     else {
    592                       Slice paxis( ipol, 1, 1 ) ;
    593                       Slice caxis( 0, cShape[1], 1 ) ;
    594                       Slicer slicer( paxis, caxis ) ;
    595                       Array<Float> subtsys = tsys( slicer ) ;
    596                       tsysCol.put( prevnr+i+nrow*ipol, subtsys ) ;
    597                     }
     630                    //floatArrCol->put( prevnr+i+nrow*ipol, tsys.row( ipol ) ) ;
     631                    tsysCol->put( prevnr+i+nrow*ipol, tsys.row( ipol ) ) ;
    598632                  }                 
    599633                }
    600634              }
    601635              else {
    602                 Array<Float> tsys( IPosition( 2, 1, addednr ), 1.0 ) ;
    603                 tsysCol.putColumnCells( rows, tsys ) ;
     636                Vector<Float> tsys( 1, 1.0 ) ;
     637                for ( Int i = prevnr ; i < prevnr+addednr ; i++ )
     638                  tsysCol->put( i, tsys ) ;
    604639              }
    605640
     641
     642              // INTERVAL
     643              tcolr = tpoolr->construct( t5, "INTERVAL" ) ;
     644              //Vector<Double> integ = mIntervalCol->getColumn() ;
     645              for ( int i = 0 ; i < nloop ; i++ ) {
     646                //Int startrow = prevnr + i ;
     647                //Int endrow = startrow + nrow - 1 ;
     648                //RefRows prows( startrow, endrow ) ;
     649                //intervalCol->putColumnCells( prows, integ ) ;
     650                for ( int j = 0 ; j < nrow ; j++ ) {
     651                  intervalCol->putScalar( prevnr+i*nrow+j, (Double)(tcolr->asdouble( j )) ) ;
     652                }
     653              }
     654              tpoolr->destroy( tcolr ) ;
     655
     656              // SRCTYPE
     657              Int srcType = getSrcType( stateId, tpoolr ) ;
     658              for ( int i = 0 ; i < addednr ; i++ ) {
     659                srctypeCol->putScalar( prevnr+i, srcType ) ;
     660              }
     661              //Vector<Int> *srcType = new Vector<Int>( addednr, getSrcType( stateId ) ) ;
     662              //srcTypeCol->putColumnCells( rows, *srcType ) ;
     663
    606664              // DIRECTION, AZIMUTH, ELEVATION, SCANRATE
    607               ArrayColumn<Double> dirCol( table_->table(), "DIRECTION" ) ;
    608               ScalarColumn<Float> azCol( table_->table(), "AZIMUTH" ) ;
    609               ScalarColumn<Float> elCol( table_->table(), "ELEVATION" ) ;
    610               ArrayColumn<Double> scanRateCol( table_->table(), "SCANRATE" ) ;
    611665              Vector<Double> defaultScanrate( 2, 0.0 ) ;
    612666              uInt diridx = 0 ;
     
    617671                  Vector<Double> scanrate ;
    618672                  String refString ;
    619                   diridx = getDirection( diridx, dir, scanrate, refString, pointCols, mTimeCol(i).get("s").getValue() ) ;
     673                  diridx = getDirection( diridx, dir, scanrate, refString, pointtab, (*mTimeCol)(i).get("s").getValue() ) ;
    620674                  //os_ << "diridx = " << diridx << " dmTimeCol(" << i << ") = " << mTimeCol(i).get("s").getValue()-mTimeCol(0).get("s").getValue() << LogIO::POST ;
    621675                  //os_ << "dir = " << dir << LogIO::POST ;
     
    624678                  MDirection::getType( dirType, refString ) ;
    625679                  //os_ << "dirType = " << dirType << LogIO::POST ;
    626                   mf.resetEpoch( mTimeCol(i) ) ;
     680                  mf.resetEpoch( (*mTimeCol)(i) ) ;
    627681                  mf.resetDirection( MDirection( MVDirection(dir), dirType ) ) ;
    628682                  if ( refString == "J2000" ) {
    629683                    //os_ << "J2000" << LogIO::POST ;
    630684                    for ( Int ipol = 0 ; ipol < npol ; ipol++ ) {
    631                       dirCol.put( prevnr+i+nrow*ipol, dir ) ;
     685                      dirCol->put( prevnr+i+nrow*ipol, dir ) ;
    632686                    }
    633687                    MDirection::Convert toazel( dirType, MDirection::Ref( MDirection::AZEL, mf ) ) ;
    634688                    Vector<Double> azel = toazel( dir ).getAngle("rad").getValue() ;
    635689                    for ( Int ipol = 0 ; ipol < npol ; ipol++ ) {
    636                       azCol.put( prevnr+i+nrow*ipol, azel(0) ) ;
    637                       elCol.put( prevnr+i+nrow*ipol, azel(1) ) ;
     690                      azCol->putScalar( prevnr+i+nrow*ipol, (Float)azel(0) ) ;
     691                      elCol->putScalar( prevnr+i+nrow*ipol, (Float)azel(1) ) ;
    638692                    }                 
    639693                  }
     
    641695                    //os_ << "AZEL" << LogIO::POST ;
    642696                    for ( Int ipol = 0 ; ipol < npol ; ipol++ ) {
    643                       azCol.put( prevnr+i+nrow*ipol, dir(0) ) ;
    644                       elCol.put( prevnr+i+nrow*ipol, dir(1) ) ;
     697                      azCol->putScalar( prevnr+i+nrow*ipol, (Float)dir(0) ) ;
     698                      elCol->putScalar( prevnr+i+nrow*ipol, (Float)dir(1) ) ;
    645699                    }
    646700                    MDirection::Convert toj2000( dirType, MDirection::Ref( MDirection::J2000, mf ) ) ;
    647701                    Vector<Double> newdir = toj2000( dir ).getAngle("rad").getValue() ;
    648702                    for ( Int ipol = 0 ; ipol < npol ; ipol++ ) {
    649                       dirCol.put( prevnr+i+nrow*ipol, newdir ) ;
     703                      dirCol->put( prevnr+i+nrow*ipol, newdir ) ;
    650704                    }                 
    651705                  }
     
    657711                    Vector<Double> newdir = toj2000( dir ).getAngle("rad").getValue() ;
    658712                    for ( Int ipol = 0 ; ipol < npol ; ipol++ ) {
    659                       dirCol.put( prevnr+i+nrow*ipol, newdir ) ;
    660                       azCol.put( prevnr+i+nrow*ipol, dir(0) ) ;
    661                       elCol.put( prevnr+i+nrow*ipol, dir(1) ) ;
     713                      dirCol->put( prevnr+i+nrow*ipol, newdir ) ;
     714                      azCol->putScalar( prevnr+i+nrow*ipol, (Float)dir(0) ) ;
     715                      elCol->putScalar( prevnr+i+nrow*ipol, (Float)dir(1) ) ;
    662716                    }                 
    663717                  }
     
    665719                    //os_ << "scanrate.size() = " << scanrate.size() << LogIO::POST ;
    666720                    for ( Int ipol = 0 ; ipol < npol ; ipol++ ) {
    667                       scanRateCol.put( prevnr+i+nrow*ipol, scanrate ) ;
     721                      scanrateCol->put( prevnr+i+nrow*ipol, scanrate ) ;
    668722                    }
    669723                  }
     
    671725                    //os_ << "scanrate.size() = " << scanrate.size() << LogIO::POST ;
    672726                    for ( Int ipol = 0 ; ipol < npol ; ipol++ ) {
    673                       scanRateCol.put( prevnr+i+nrow*ipol, defaultScanrate ) ;
     727                      scanrateCol->put( prevnr+i+nrow*ipol, defaultScanrate ) ;
    674728                    }
    675729                  }
     
    678732              else {
    679733                // All directions are set to source direction
    680                 ROArrayMeasColumn<MDirection> dmcol = pointCols.directionMeasCol() ;
    681                 ROArrayColumn<Double> dcol = pointCols.direction() ;
     734                ROArrayMeasColumn<MDirection> dmcol( pointtab, "DIRECTION" ) ;
     735                ROArrayColumn<Double> dcol( pointtab, "DIRECTION" ) ;
    682736                IPosition ip( dmcol(0).shape().nelements(), 0 ) ;
    683737                IPosition outp( 1, 2 ) ;
     
    690744                mf.resetDirection( MDirection( MVDirection(srcDir), dirType ) ) ;
    691745                if ( ref != "J2000" ) {
    692                   mf.resetEpoch( pointCols.timeMeas()(0) ) ;
     746                  ROScalarMeasColumn<MEpoch> tmCol( pointtab, "TIME" ) ;
     747                  mf.resetEpoch( tmCol( 0 ) ) ;
    693748                  MDirection::Convert toj2000( dirType, MDirection::Ref( MDirection::J2000, mf ) ) ;
    694749                  defaultDir = toj2000( defaultDir ).getAngle("rad").getValue() ;
    695750                }
    696751                for ( Int i = 0 ; i < nrow ; i++ ) {
    697                   mf.resetEpoch( mTimeCol(i) ) ;
     752                  mf.resetEpoch( (*mTimeCol)(i) ) ;
    698753                  for ( Int ipol = 0 ; ipol < npol ; ipol++ ) {
    699754                    Int localidx = prevnr+i+nrow*ipol ;
    700755                    MDirection::Convert toazel( dirType, MDirection::Ref( MDirection::AZEL, mf ) ) ;
    701756                    Vector<Double> azel = toazel( defaultDir ).getAngle("rad").getValue() ;
    702                     azCol.put( localidx, azel(0) ) ;
    703                     elCol.put( localidx, azel(1) ) ;
    704                     dirCol.put( localidx, defaultDir ) ;
    705                     scanRateCol.put( localidx, defaultScanrate ) ;
     757                    azCol->putScalar( localidx, (Float)azel(0) ) ;
     758                    elCol->putScalar( localidx, (Float)azel(1) ) ;
     759                    dirCol->put( localidx, defaultDir ) ;
     760                    scanrateCol->put( localidx, defaultScanrate ) ;
    706761                  }
    707762                }
    708763              }
    709764
     765              // CYCLENO
     766              for ( int i = 0 ; i < nloop ; i++ ) {
     767                for ( int j = 0 ; j < nrow ; j++ ) {
     768                  cyclenoCol->putScalar( prevnr+nrow*i+j, cycle+j ) ;
     769                }
     770              }
     771              cycle += nrow ;
     772
     773              // POLNO
     774              Int pidx = 0 ;
     775              Bool crossOK = False ;
     776              for ( int i = 0 ; i < npol ; i++ ) {
     777                Vector<uInt> polnos = getPolNo( corrtype[i] ) ;
     778                if ( polnos.size() > 1 ) {
     779                  if ( crossOK ) continue ;
     780                  else crossOK = True ;
     781                }
     782                for ( uInt j = 0 ; j < polnos.size() ; j++ ) {
     783                  for ( Int irow = 0 ; irow < nrow ; irow++ ) {
     784                    polnoCol->putScalar( prevnr+pidx*nrow+irow, polnos[j] ) ;
     785                  }
     786                  pidx++ ;
     787                }
     788              }
     789
     790              // FLAGROW
     791              tcolr = tpoolr->construct( t5, "FLAG_ROW" ) ;
     792              for ( int i = 0 ; i < nloop ; i++ ) {
     793                for ( int j = 0 ; j < nrow ; j++ ) {
     794                  flagrowCol->putScalar( prevnr+nrow*i+j, (uInt)(tcolr->asBool( j )) ) ;
     795                }
     796              }
     797              tpoolr->destroy( tcolr ) ;
     798
    710799              // TCAL_ID
    711               ScalarColumn<uInt> tcalIdCol( table_->table(), "TCAL_ID" ) ;
    712800              if ( isSysCal_ ) {
    713801                for( Int irow = 0 ; irow < nrow ; irow++ ) {
     
    718806                  }
    719807                  for ( Int ipol = 0 ; ipol < npol ; ipol++ ) {
    720                   tcalIdCol.put( prevnr+irow+nrow*ipol, tcalids[ipol] ) ;
     808                    tcalidCol->putScalar( prevnr+irow+nrow*ipol, tcalids[ipol] ) ;
    721809                  }
    722810                }
    723811              }
    724812              else {
    725                 Vector<uInt> tcalid( addednr, 0 ) ;
    726                 tcalIdCol.putColumnCells( rows, tcalid ) ;
     813                //Vector<uInt> tcalid( addednr, 0 ) ;
     814                //uIntCol->putColumnCells( rows, tcalid ) ;
     815                uInt tcalid = 0 ;
     816                for ( Int irow = 0 ; irow < addednr ; irow++ )
     817                  tcalidCol->putScalar( prevnr+irow, tcalid ) ;
    727818              }
    728819
    729820              // WEATHER_ID
    730               uInt widprev = 0 ;
    731               Vector<uInt> vWid( nrow, 0 ) ;
    732821              if ( isWeather_ ) {
    733                 for ( int j = 0 ; j < nrow ; j++ ) {
    734                   //os_ << "TIME value = " << mTimeCol( j ).get("s").getValue() << LogIO::POST ;
    735                   uInt wid = getWeatherId( widprev, mTimeCol( j ).get("s").getValue() ) ;
    736                   //os_ << "wid = " << wid << LogIO::POST ;
    737                   vWid[j] = wid ;
    738                   widprev = wid ;
     822                uInt wid = 0 ;
     823                for ( Int irow = 0 ; irow < nrow ; irow++ ) {
     824                  wid = getWeatherId( wid, (*mTimeCol)(irow).get("s").getValue() ) ;
     825                  for ( Int ipol = 0 ; ipol < nloop ; ipol++ ) {
     826                    weatheridCol->putScalar( prevnr+ipol*nrow+irow, wid ) ;
     827                  }
    739828                }
    740829              }
    741830
    742               ScalarColumn<uInt> weatherIdCol( table_->table(), "WEATHER_ID" ) ;
    743               for ( int i = 0 ; i < addednr ; i += nrow ) {
    744                 Int startrow = prevnr + i ;
    745                 Int endrow = startrow + nrow - 1 ;
    746                 RefRows prows( startrow, endrow ) ;
    747                 weatherIdCol.putColumnCells( prows, vWid ) ;               
    748               }
     831              delete mTimeCol ;
    749832             
    750833              //os_ << "field: " << fieldId << " scan: " << scanNum << " obs: " << obsId << " state: " << stateId << " ddid: " << ddId << endl ;
    751               //os_ << "t.nrow() = " << t5.nrow() << endl ;
     834              //os_ << "addednr = " << addednr << endl ;
    752835              added5 += addednr ;
    753836              iter5.next() ;
     
    755838
    756839            // SCANNO
    757             RefRows rows5( current5, current5+added5-1 ) ;
    758             Vector<uInt> scanno( added5, scanNum ) ;
    759             ScalarColumn<uInt> scannoCol( table_->table(), "SCANNO" ) ;
    760             scannoCol.putColumnCells( rows5, scanno ) ;
    761 
     840            // MS: 1-base
     841            // Scantable: 0-base
     842            Int dest5 = current5 + added5 ;
     843            scanNum -= 1 ;
     844            for ( Int irow = current5 ; irow < dest5 ; irow++ )
     845              scannoCol->putScalar( irow, (uInt)scanNum ) ;
     846
     847            //os_ << "added5 = " << added5 << endl ;
    762848            added4 += added5 ;
    763849            iter4.next() ;
     
    765851
    766852          // IFNO
    767           RefRows rows4( current4, current4+added4-1 ) ;
    768           Vector<uInt> shareduIArr( added4, spwId ) ;
    769           ScalarColumn<uInt> shareduIArrCol( table_->table(), "IFNO" ) ;
    770           shareduIArrCol.putColumnCells( rows4, shareduIArr ) ;
     853          Int dest4 = current4 + added4 ;
     854          for ( Int irow = current4 ; irow < dest4 ; irow++ )
     855            ifnoCol->putScalar( irow, (uInt)spwId ) ;
    771856
    772857          // FREQ_ID
    773           shareduIArr = ifmap[spwId] ;
    774           shareduIArrCol.attach( table_->table(), "FREQ_ID" ) ;
    775           shareduIArrCol.putColumnCells( rows4, shareduIArr ) ;
     858          uInt fid = ifmap[spwId] ;
     859          for ( Int irow = current4 ; irow < dest4 ; irow++ )
     860            freqidCol->putScalar( irow, fid ) ;
    776861
    777862          // MOLECULE_ID
    778           shareduIArr = molId ;
    779           shareduIArrCol.attach( table_->table(), "MOLECULE_ID" ) ;
    780           shareduIArrCol.putColumnCells( rows4, shareduIArr ) ;
     863          for ( Int irow = current4 ; irow < dest4 ; irow++ )
     864            molidCol->putScalar( irow, molId ) ;
    781865
    782866          // SRCNAME
    783           ScalarColumn<String> srcNameCol( table_->table(), "SRCNAME" ) ;
    784           Vector<String> vSrcName( added4, srcName ) ;
    785           srcNameCol.putColumnCells( rows4, vSrcName ) ;
     867          for ( Int irow = current4 ; irow < dest4 ; irow++ )
     868            srcnameCol->putScalar( irow, srcName ) ;
    786869
    787870          // SRCVELOCITY, SRCPROPERMOTION and SRCDIRECTION
    788871          // no reference conversion for direction at the moment (assume J2000)
    789872          // no reference conversion for velocity at the moment (assume LSRK)
    790           Matrix<Double> sharedDArr( 2, added4 ) ;
    791           for ( uInt icol = 0 ; icol < added4 ; icol++ ) {
    792             sharedDArr.column(icol) = srcPM ;
    793           }
    794           ArrayColumn<Double> sharedDArrCol( table_->table(), "SRCPROPERMOTION" ) ;
    795           sharedDArrCol.putColumnCells( rows4, sharedDArr ) ;
    796           for ( uInt icol = 0 ; icol < added4 ; icol++ ) {
    797             sharedDArr.column(icol) = srcDir ;
    798           }         
    799           sharedDArrCol.attach( table_->table(), "SRCDIRECTION" ) ;
    800           sharedDArrCol.putColumnCells( rows4, sharedDArr ) ;
    801           ScalarColumn<Double> sysVelCol( table_->table(), "SRCVELOCITY" ) ;
    802           Vector<Double> sysVelArr( added4, sysVel ) ;
    803           sysVelCol.putColumnCells( rows4, sysVelArr ) ;
    804 
     873          for ( Int irow = current4 ; irow < dest4 ; irow++ )
     874            srcpmCol->put( irow, srcPM ) ;
     875          for ( Int irow = current4 ; irow < dest4 ; irow++ )
     876            srcdirCol->put( irow, srcDir ) ;
     877          for ( Int irow = current4 ; irow < dest4 ; irow++ )
     878            srcvelCol->putScalar( irow, sysVel ) ;
     879
     880          //os_ << "added4 = " << added4 << endl ;
    805881          added3 += added4 ;
    806882          iter3.next() ;
     
    808884
    809885        // FIELDNAME
    810         RefRows rows3( current3, current3+added3-1 ) ;
    811         Vector<String> vFieldName( added3, fieldName ) ;
    812         ScalarColumn<String> fieldNameCol( table_->table(), "FIELDNAME" ) ;
    813         fieldNameCol.putColumnCells( rows3, vFieldName ) ;
    814 
     886        Int dest3 = current3 + added3 ;
     887        for ( Int irow = current3 ; irow < dest3 ; irow++ )
     888          fieldnameCol->putScalar( irow, fieldName ) ;
     889
     890        //os_ << "added3 = " << added3 << endl ;
    815891        added2 += added3 ;
    816892        iter2.next() ;
     
    818894
    819895      // BEAMNO
    820       RefRows rows2( current2, current2+added2-1 ) ;
    821       Vector<uInt> beamno( added2, feedId ) ;
    822       ScalarColumn<uInt> beamnoCol( table_->table(), "BEAMNO" ) ;
    823       beamnoCol.putColumnCells( rows2, beamno ) ;
     896      Int dest2 = current2 + added2 ;
     897      for ( Int irow = current2 ; irow < dest2 ; irow++ )
     898        beamnoCol->putScalar( irow, (uInt)feedId ) ;
    824899
    825900      // FOCUS_ID
    826901      // tentative
    827       beamnoCol.attach( table_->table(), "FOCUS_ID" ) ;
    828       beamno = 0 ;
    829       beamnoCol.putColumnCells( rows2, beamno ) ;
    830 
     902      uInt focusId = 0 ;
     903      for ( Int irow = current2 ; irow < dest2 ; irow++ )
     904        focusidCol->putScalar( irow, focusId ) ;
     905     
     906      //os_ << "added2 = " << added2 << endl ;
    831907      added1 += added2 ;
    832908      iter1.next() ;
     
    834910    if ( sdh.nbeam < nbeam ) sdh.nbeam = nbeam ;
    835911
     912    //os_ << "added1 = " << added1 << endl ;
    836913    added0 += added1 ;
    837914    iter0.next() ;
    838915  }
    839916
     917  //os_ << "added0 = " << added0 << endl ;
     918
    840919  // REFBEAMNO
    841920  // set 0 at the moment
    842   ScalarColumn<Int> sharedICol( table_->table(), "REFBEAMNO" ) ;
    843   Vector<Int> sharedI( added0, 0 ) ;
    844   sharedICol.putColumn( sharedI ) ;
     921  tcolw = tpoolw->construct( table_->table(), "REFBEAMNO" ) ;
     922  for ( Int irow = current0 ; irow < added0 ; irow++ )
     923    tcolw->putScalar( irow, 0 ) ;
     924  tpoolw->destroy( tcolw ) ;
     925
     926  // FIT_ID
     927  // nothing to do
     928  tcolw = tpoolw->construct( table_->table(), "FIT_ID" ) ;
     929  for ( Int irow = current0 ; irow < added0 ; irow++ )
     930    tcolw->putScalar( irow, -1 ) ;
     931  tpoolw->destroy( tcolw ) ;
    845932
    846933  // OPACITY
    847934  // not used?
    848   ScalarColumn<Float> opacityCol( table_->table(), "OPACITY" ) ;
    849   Vector<Float> opacity( added0, 0.0 ) ;
    850   opacityCol.putColumn( opacity ) ;
    851  
    852   // FIT_ID
    853   // nothing to do
    854   sharedICol.attach( table_->table(), "FIT_ID" ) ;
    855   sharedI = -1 ;
    856   sharedICol.putColumn( sharedI ) ;
     935  tcolw = tpoolw->construct( table_->table(), "OPACITY" ) ;
     936  for ( Int irow = current0 ; irow < added0 ; irow++ )
     937    tcolw->putScalar( irow, 0.0 ) ;
     938  tpoolw->destroy( tcolw ) ;
     939
     940  // delete Scantable columns
     941  tpoolw->destroy( scannoCol ) ;
     942  tpoolw->destroy( cyclenoCol ) ;
     943  tpoolw->destroy( beamnoCol ) ;
     944  tpoolw->destroy( ifnoCol ) ;
     945  tpoolw->destroy( polnoCol ) ;
     946  tpoolw->destroy( freqidCol ) ;
     947  tpoolw->destroy( molidCol ) ;
     948  tpoolw->destroy( flagrowCol ) ;
     949  delete timeCol ;
     950  tpoolw->destroy( intervalCol ) ;
     951  tpoolw->destroy( srcnameCol ) ;
     952  tpoolw->destroy( srctypeCol ) ;
     953  tpoolw->destroy( fieldnameCol ) ;
     954  delete spCol ;
     955  delete flCol ;
     956  delete tsysCol ;
     957  delete dirCol ;
     958  tpoolw->destroy( azCol ) ;
     959  tpoolw->destroy( elCol ) ;
     960  tpoolw->destroy( tcalidCol ) ;
     961  tpoolw->destroy( focusidCol ) ;
     962  tpoolw->destroy( weatheridCol ) ;
     963  delete srcpmCol ;
     964  delete srcdirCol ;
     965  tpoolw->destroy( srcvelCol ) ;
     966  delete scanrateCol ;
     967
     968  delete tpoolr ;
     969  delete tpoolw ;
    857970
    858971
    859972  // Table Keywords
    860973  sdh.nif = ifmap.size() ;
    861   String antennaName = antCols.name()(antenna_) ;
    862   if ( antennaName == telescopeName ) {
     974  if ( ( telescopeName == "" ) || ( antennaName == telescopeName ) ) {
    863975    sdh.antennaname = antennaName ;
    864976  }
     
    869981    sdh.antennaname += "@" + stationName ;
    870982  }
    871   sdh.antennaposition = antCols.position()(antenna_);
    872   ROMSPointingColumns pointingCols( mstable_.pointing() ) ;
    873   String dirref = pointingCols.direction().keywordSet().asRecord("MEASINFO").asString("Ref") ;
     983  ROArrayColumn<Double> pdirCol( pointtab, "DIRECTION" ) ;
     984  String dirref = pdirCol.keywordSet().asRecord("MEASINFO").asString("Ref") ;
    874985  if ( dirref == "AZELGEO" || dirref == "AZEL" ) {
    875986    dirref = "J2000" ;
     
    8931004  }
    8941005  table_->setHeader( sdh ) ;
     1006
     1007  // save path to POINTING table
     1008  //Path datapath(mstable_.tableName()) ;
     1009  Path datapath( tablename_ ) ;
     1010  String pTabName = datapath.absoluteName() + "/POINTING" ;
     1011  table_->table().rwKeywordSet().define( "POINTING", pTabName ) ;
     1012
     1013  // for GBT
     1014  if ( antennaName == "GBT" ) {
     1015    String goTabName = datapath.absoluteName() + "/GBT_GO" ;
     1016    table_->table().rwKeywordSet().define( "GBT_GO", goTabName ) ;
     1017  }
     1018  //os_ << "end MSFiller::fill()" << LogIO::POST ;
    8951019}
    8961020
    8971021void MSFiller::close()
    8981022{
    899   tablesel_.closeSubTables() ;
     1023  //tablesel_.closeSubTables() ;
    9001024  mstable_.closeSubTables() ;
    901   tablesel_.unlock() ;
     1025  //tablesel_.unlock() ;
    9021026  mstable_.unlock() ;
    9031027}
    9041028
    905 void MSFiller::fillId( uInt idx, const char *colname, RefRows &rows )
     1029Int MSFiller::getSrcType( Int stateId, boost::object_pool<ROTableColumn> *tpool )
    9061030{
    907   ScalarColumn<uInt> col( table_->table(), colname ) ;
    908   Vector<uInt> ids( rows.nrow(), idx ) ;
    909   col.putColumnCells( rows, ids ) ;
    910 }
    911 
    912 void MSFiller::fillId( Int idx, const char *colname, RefRows &rows )
    913 {
    914   ScalarColumn<Int> col( table_->table(), colname ) ;
    915   Vector<Int> ids( rows.nrow(), idx ) ;
    916   col.putColumnCells( rows, ids ) ;
    917 }
    918 
    919 Int MSFiller::getSrcType( Int stateId )
    920 {
     1031  //os_ << "start MSFiller::getSrcType()" << LogIO::POST ;
     1032
    9211033  MSState statetab = mstable_.state() ;
    922   ROScalarColumn<String> obsModeCol( statetab, "OBS_MODE" ) ;
    923   String obsMode = obsModeCol( stateId ) ;
    924   ROScalarColumn<Bool> sigCol( statetab, "SIG" ) ;
    925   ROScalarColumn<Bool> refCol( statetab, "REF" ) ;
    926   Bool sig = sigCol( stateId ) ;
    927   Bool ref = refCol( stateId ) ;
     1034  ROTableColumn *sharedCol ;
     1035  sharedCol = tpool->construct( statetab, "OBS_MODE" ) ;
     1036  String obsMode = sharedCol->asString( stateId ) ;
     1037  tpool->destroy( sharedCol ) ;
     1038  sharedCol = tpool->construct( statetab, "SIG" ) ;
     1039  Bool sig = sharedCol->asBool( stateId ) ;
     1040  tpool->destroy( sharedCol ) ;
     1041  sharedCol = tpool->construct( statetab, "REF" ) ;
     1042  Bool ref = sharedCol->asBool( stateId ) ;
     1043  tpool->destroy( sharedCol ) ;
     1044  sharedCol = tpool->construct( statetab, "CAL" ) ;
     1045  Double cal = (Double)(sharedCol->asdouble( stateId )) ;
     1046  tpool->destroy( sharedCol ) ;
    9281047  //os_ << "OBS_MODE = " << obsMode << LogIO::POST ;
    9291048
     
    9531072    //       SIG=1: FSON
    9541073    //       REF=1: FSOFF
     1074    // Calibration scan if CAL != 0
    9551075    Int epos = obsMode.find_first_of( sep ) ;
    9561076    Int nextpos = obsMode.find_first_of( sep, epos+1 ) ;
     
    9691089        if ( ref ) srcType = SrcType::FSOFF ;
    9701090      }
     1091    }
     1092    if ( cal > 0.0 ) {
     1093      if ( srcType == SrcType::NOD )
     1094        srcType = SrcType::NODCAL ;
     1095      else if ( srcType == SrcType::PSON )
     1096        srcType = SrcType::PONCAL ;
     1097      else if ( srcType == SrcType::PSOFF )
     1098        srcType = SrcType::POFFCAL ;
     1099      else if ( srcType == SrcType::FSON )
     1100        srcType = SrcType::FONCAL ;
     1101      else if ( srcType == SrcType::FSOFF )
     1102        srcType = SrcType::FOFFCAL ;
     1103      else
     1104        srcType = SrcType::CAL ;
    9711105    }
    9721106  }
     
    10011135   
    10021136  //os_ << "srcType = " << srcType << LogIO::POST ;
    1003 
     1137  //os_ << "end MSFiller::getSrcType()" << LogIO::POST ;
    10041138  return srcType ;
    10051139}
     
    10071141Vector<uInt> MSFiller::getPolNo( Int corrType )
    10081142{
     1143  //os_ << "start MSFiller::getPolNo()" << LogIO::POST ;
    10091144  Vector<uInt> polno( 1 ) ;
    10101145
     
    10361171  }
    10371172  //os_ << "polno = " << polno << LogIO::POST ;
     1173  //os_ << "end MSFiller::getPolNo()" << LogIO::POST ;
    10381174 
    10391175  return polno ;
     
    10421178String MSFiller::getPolType( Int corrType )
    10431179{
     1180  //os_ << "start MSFiller::getPolType()" << LogIO::POST ;
    10441181  String poltype = "" ;
    10451182
     
    10531190    poltype = "linpol" ;
    10541191
     1192  //os_ << "end MSFiller::getPolType()" << LogIO::POST ;
    10551193  return poltype ;
    10561194}
     
    10581196void MSFiller::fillWeather()
    10591197{
    1060   MSWeather mWeather( mstable_.weather() ) ;
    1061   MSWeather mWeatherSel( mWeather( mWeather.col("ANTENNA_ID") == antenna_ ).sort("TIME") ) ;
     1198  //os_ << "start MSFiller::fillWeather()" << LogIO::POST ;
     1199  Table mWeather = mstable_.weather()  ;
     1200  //Table mWeatherSel = mWeather( mWeather.col("ANTENNA_ID") == antenna_ ).sort("TIME") ;
     1201  Table mWeatherSel( mWeather( mWeather.col("ANTENNA_ID") == antenna_ ).sort("TIME") ) ;
    10621202  //os_ << "mWeatherSel.nrow() = " << mWeatherSel.nrow() << LogIO::POST ;
    10631203  if ( mWeatherSel.nrow() == 0 ) {
    10641204    os_ << "No rows with ANTENNA_ID = " << antenna_ << ", Try -1..." << LogIO::POST ;
    1065     mWeatherSel = MSWeather( mWeather( mWeather.col("ANTENNA_ID") == -1 ) ) ;
     1205    mWeatherSel = Table( MSWeather( mWeather( mWeather.col("ANTENNA_ID") == -1 ) ) ) ;
    10661206    if ( mWeatherSel.nrow() == 0 ) {
    10671207      os_ << "No rows in WEATHER table" << LogIO::POST ;
    10681208    }
    10691209  }
    1070   ROMSWeatherColumns mWeatherCols( mWeatherSel ) ;
    1071   Int wnrow = mWeatherCols.nrow() ;
     1210  uInt wnrow = mWeatherSel.nrow() ;
    10721211  //os_ << "wnrow = " << wnrow << LogIO::POST ;
    10731212
     
    10781217  wtab.addRow( wnrow ) ;
    10791218
    1080   ScalarColumn<Float> tempCol( wtab, "TEMPERATURE" ) ;
    1081   tempCol.putColumn( mWeatherCols.temperature() ) ;
    1082   ScalarColumn<Float> pressCol( wtab, "PRESSURE" ) ;
    1083   pressCol.putColumn( mWeatherCols.pressure() ) ;
    1084   ScalarColumn<Float> humCol( wtab, "HUMIDITY" ) ;
    1085   humCol.putColumn( mWeatherCols.relHumidity() ) ;
    1086   ScalarColumn<Float> windVelCol( wtab, "WINDSPEED" ) ;
    1087   windVelCol.putColumn( mWeatherCols.windSpeed() ) ;
    1088   ScalarColumn<Float> windDirCol( wtab, "WINDAZ" ) ;
    1089   windDirCol.putColumn( mWeatherCols.windDirection() ) ;
    1090   Vector<uInt> ids( wnrow ) ;
    1091   indgen( ids ) ;
     1219  ScalarColumn<Float> *fCol ;
     1220  ROScalarColumn<Float> *sharedFloatCol ;
     1221  if ( mWeatherSel.tableDesc().isColumn( "TEMPERATURE" ) ) {
     1222    fCol = new ScalarColumn<Float>( wtab, "TEMPERATURE" ) ;
     1223    sharedFloatCol = new ROScalarColumn<Float>( mWeatherSel, "TEMPERATURE" ) ;
     1224    fCol->putColumn( *sharedFloatCol ) ;
     1225    delete sharedFloatCol ;
     1226    delete fCol ;
     1227  }
     1228  if ( mWeatherSel.tableDesc().isColumn( "PRESSURE" ) ) {
     1229    fCol = new ScalarColumn<Float>( wtab, "PRESSURE" ) ;
     1230    sharedFloatCol = new ROScalarColumn<Float>( mWeatherSel, "PRESSURE" ) ;
     1231    fCol->putColumn( *sharedFloatCol ) ;
     1232    delete sharedFloatCol ;
     1233    delete fCol ;
     1234  }
     1235  if ( mWeatherSel.tableDesc().isColumn( "REL_HUMIDITY" ) ) {
     1236    fCol = new ScalarColumn<Float>( wtab, "HUMIDITY" ) ;
     1237    sharedFloatCol = new ROScalarColumn<Float>( mWeatherSel, "REL_HUMIDITY" ) ;
     1238    fCol->putColumn( *sharedFloatCol ) ;
     1239    delete sharedFloatCol ;
     1240    delete fCol ;
     1241  }
     1242  if ( mWeatherSel.tableDesc().isColumn( "WIND_SPEED" ) ) { 
     1243    fCol = new ScalarColumn<Float>( wtab, "WINDSPEED" ) ;
     1244    sharedFloatCol = new ROScalarColumn<Float>( mWeatherSel, "WIND_SPEED" ) ;
     1245    fCol->putColumn( *sharedFloatCol ) ;
     1246    delete sharedFloatCol ;
     1247    delete fCol ;
     1248  }
     1249  if ( mWeatherSel.tableDesc().isColumn( "WIND_DIRECTION" ) ) {
     1250    fCol = new ScalarColumn<Float>( wtab, "WINDAZ" ) ;
     1251    sharedFloatCol = new ROScalarColumn<Float>( mWeatherSel, "WIND_DIRECTION" ) ;
     1252    fCol->putColumn( *sharedFloatCol ) ;
     1253    delete sharedFloatCol ;
     1254    delete fCol ;
     1255  }
    10921256  ScalarColumn<uInt> idCol( wtab, "ID" ) ;
    1093   idCol.putColumn( ids ) ;
    1094 
    1095   String tUnit = mWeatherCols.timeQuant().getUnits() ;
    1096   mwTime_ = mWeatherCols.time().getColumn() ;
     1257  for ( uInt irow = 0 ; irow < wnrow ; irow++ )
     1258    idCol.put( irow, irow ) ;
     1259
     1260  ROScalarQuantColumn<Double> tqCol( mWeatherSel, "TIME" ) ;
     1261  ROScalarColumn<Double> tCol( mWeatherSel, "TIME" ) ;
     1262  String tUnit = tqCol.getUnits() ;
     1263  mwTime_ = tCol.getColumn() ;
    10971264  if ( tUnit == "d" )
    10981265    mwTime_ *= 86400.0 ;
    1099   String iUnit = mWeatherCols.intervalQuant().getUnits() ;
    1100   mwInterval_ = mWeatherCols.interval().getColumn() ;
     1266  tqCol.attach( mWeatherSel, "INTERVAL" ) ;
     1267  tCol.attach( mWeatherSel, "INTERVAL" ) ;
     1268  String iUnit = tqCol.getUnits() ;
     1269  mwInterval_ = tCol.getColumn() ;
    11011270  if ( iUnit == "d" )
    11021271    mwInterval_ *= 86400.0 ;
    11031272  //os_ << "mwTime[0] = " << mwTime_[0] << " mwInterval[0] = " << mwInterval_[0] << LogIO::POST ;
     1273  //os_ << "end MSFiller::fillWeather()" << LogIO::POST ;
    11041274}
    11051275
    11061276void MSFiller::fillFocus()
    11071277{
     1278  //os_ << "start MSFiller::fillFocus()" << LogIO::POST ;
    11081279  // tentative
    11091280  Table tab = table_->focus().table() ;
     
    11111282  ScalarColumn<uInt> idCol( tab, "ID" ) ;
    11121283  idCol.put( 0, 0 ) ;
     1284  //os_ << "end MSFiller::fillFocus()" << LogIO::POST ;
    11131285}
    11141286
    1115 void MSFiller::fillTcal()
     1287void MSFiller::fillTcal( boost::object_pool<ROTableColumn> *tpool )
    11161288{
    1117   MSSysCal sctab = mstable_.sysCal() ;
     1289  //os_ << "start MSFiller::fillTcal()" << LogIO::POST ;
     1290
     1291  //MSSysCal sctab = mstable_.sysCal() ;
     1292  Table sctab = mstable_.sysCal() ;
    11181293  if ( sctab.nrow() == 0 ) {
    11191294    os_ << "No SysCal rows" << LogIO::POST ;
     
    11211296  }
    11221297  Bool isSp = sctab.tableDesc().isColumn( "TCAL_SPECTRUM" ) ;
    1123   MSSysCal sctabsel( sctab( sctab.col("ANTENNA_ID") == antenna_ ) ) ;
     1298  //MSSysCal sctabsel =  sctab( sctab.col("ANTENNA_ID") == antenna_ ) ;
     1299  //Table sctabsel =  sctab( sctab.col("ANTENNA_ID") == antenna_ ) ;
     1300  Table sctabsel( sctab( sctab.col("ANTENNA_ID") == antenna_ ) ) ;
    11241301  if ( sctabsel.nrow() == 0 ) {
    11251302    os_ << "No SysCal rows" << LogIO::POST ;
    11261303    return ;
    11271304  }
    1128   ROArrayColumn<Float> tmpTcalCol( sctabsel, "TCAL" ) ;
    1129   uInt npol = tmpTcalCol.shape( 0 )(0) ;
     1305  ROArrayColumn<Float> *tmpTcalCol = new ROArrayColumn<Float>( sctabsel, "TCAL" ) ;
     1306  uInt npol = tmpTcalCol->shape( 0 )(0) ;
     1307  delete tmpTcalCol ;
    11301308  //os_ << "fillTcal(): npol = " << npol << LogIO::POST ;
    11311309  Table tab = table_->tcal().table() ;
     
    11331311  ScalarColumn<String> timeCol( tab, "TIME" ) ;
    11341312  ArrayColumn<Float> tcalCol( tab, "TCAL" ) ;
     1313  ROTableColumn *sharedCol ;
    11351314  uInt oldnr = 0 ;
    11361315  uInt newnr = 0 ;
    11371316  TableIterator iter0( sctabsel, "FEED_ID" ) ;
    1138   // Record for TCAL_ID
    1139   // "FIELD0": "SPW0": Vector<uInt>
    1140   //           "SPW1": Vector<uInt>
    1141   //  ...
    11421317  while( !iter0.pastEnd() ) {
    1143     MSSysCal t0( iter0.table() ) ;
    1144     ROScalarColumn<Int> feedIdCol( t0, "FEED_ID" ) ;
    1145     Int feedId = feedIdCol( 0 ) ;
     1318    Table t0 = iter0.table() ;
     1319    sharedCol = tpool->construct( t0, "FEED_ID" ) ;
     1320    Int feedId = sharedCol->asInt( 0 ) ;
     1321    tpool->destroy( sharedCol ) ;
    11461322    String ffield = "FEED" + String::toString( feedId ) ;
    11471323    Record rec ;
     
    11501326      MSSysCal t1( iter1.table().sort("TIME") ) ;
    11511327      uInt nrow = t1.nrow() ;
    1152       ROMSSysCalColumns scCols( t1 ) ;
    1153       Int spwId = scCols.spectralWindowId()(0) ;
     1328      sharedCol = tpool->construct( t1, "SPECTRAL_WINDOW_ID" ) ;
     1329      Int spwId = sharedCol->asInt( 0 ) ;
     1330      tpool->destroy( sharedCol ) ;
    11541331      String spwfield = "SPW" + String::toString( spwId ) ;
    1155       ROScalarQuantColumn<Double> scTimeCol = scCols.timeQuant() ;
     1332      ROScalarQuantColumn<Double> scTimeCol( t1, "TIME" ) ;
    11561333      ROArrayColumn<Float> scTcalCol ;
    11571334      IPosition newShape( 2, 1, nrow ) ;
    11581335      if ( isSp ) {
    1159         scTcalCol.reference( scCols.tcalSpectrum() ) ;
     1336        scTcalCol.attach( t1, "TCAL_SPECTRUM" ) ;
    11601337        newShape[0] = scTcalCol.shape(0)(1) ;
    11611338      }
    11621339      else {
    1163         scTcalCol.reference( scCols.tcal() ) ;
     1340        scTcalCol.attach( t1, "TCAL" ) ;
    11641341      }
    1165       Vector<uInt> idx( nrow ) ;
    1166       Vector<String> sTime( nrow ) ;
     1342      tab.addRow( nrow*npol ) ;
     1343      newnr += nrow*npol ;
    11671344      for ( uInt irow = 0 ; irow < nrow ; irow++ ) {
    1168         sTime[irow] = MVTime( scTimeCol(irow) ).string(MVTime::YMD) ;
     1345        String sTime = MVTime( scTimeCol(irow) ).string( MVTime::YMD ) ;
     1346        for ( uInt ipol = 0 ; ipol < npol ; ipol++ ) {
     1347          timeCol.put( oldnr+irow+ipol*nrow, sTime ) ;
     1348        }
     1349      }
     1350      uInt idx = oldnr ;
     1351      for ( uInt ipol = 0 ; ipol < npol ; ipol++ ) {
     1352        for ( uInt irow = 0 ; irow < nrow ; irow++ ) {
     1353          idCol.put( oldnr+ipol*nrow+irow, idx++ ) ;
     1354        }
    11691355      }
    11701356      Vector<uInt> idminmax( 2, oldnr ) ;
    1171       for ( uInt ipol = 0 ; ipol < npol ; ipol++ ) {
    1172         tab.addRow( nrow ) ;
    1173         newnr += nrow ;
    1174         RefRows rows( oldnr, newnr-1 ) ;
    1175         indgen( idx, oldnr ) ;
    1176         idCol.putColumnCells( rows, idx ) ;
    1177         timeCol.putColumnCells( rows, sTime ) ;
    1178         Slicer slicer ;
    1179         if ( isSp ) {
    1180           Slice paxis( ipol, 1, 1 ) ;
    1181           Slice caxis( 0, newShape[0], 1 ) ;
    1182           slicer = Slicer( paxis, caxis ) ;
     1357      for ( uInt irow = 0 ; irow < nrow ; irow++ ) {
     1358        Matrix<Float> subtcal = scTcalCol( irow ) ;
     1359        for ( uInt ipol = 0 ; ipol < npol ; ipol++ ) {
     1360          tcalCol.put( oldnr+ipol*nrow+irow, subtcal.row( ipol ) ) ;
    11831361        }
    1184         else {
    1185           Slice paxis( ipol, 1, 1 ) ;
    1186           slicer = Slicer( paxis ) ;
    1187         }
    1188         Array<Float> subtcal = scTcalCol.getColumn( slicer ).reform( newShape ) ;
    1189         tcalCol.putColumnCells( rows, subtcal ) ;
    1190         oldnr += nrow ;
    11911362      }
    11921363      idminmax[1] = newnr - 1 ;
     1364      oldnr = newnr ;
    11931365      rec.define( spwfield, idminmax ) ;
    11941366      iter1++ ;
     
    11981370  }
    11991371
     1372
    12001373  //tcalrec_.print( std::cout ) ;
     1374  //os_ << "end MSFiller::fillFocus()" << LogIO::POST ;
    12011375}
    1202 
    1203 // void MSFiller::fillMolecules()
    1204 // {
    1205 //   os_ << "MSFiller::fillMolecules()" << LogIO::POST ;
    1206 //   // tentative
    1207 //   Table tab = table_->molecules().table() ;
    1208 //   tab.addRow( 1 ) ;
    1209 //   ScalarColumn<uInt> idCol( tab, "ID" ) ;
    1210 //   idCol.put( 0, 0 ) ;
    1211 // }
    1212 
    1213 // void MSFiller::fillFit()
    1214 // {
    1215 //   os_ << "MSFiller::fillFit()" << LogIO::POST ;
    1216 //   // tentative
    1217 //   Table tab = table_->fit().table() ;
    1218 //   tab.addRow( 1 ) ;
    1219 //   ScalarColumn<uInt> idCol( tab, "ID" ) ;
    1220 //   idCol.put( 0, 0 ) ;
    1221 // }
    1222 
    1223 // void MSFiller::fillFrequencies()
    1224 // {
    1225 //   os_ << "MSFiller::fillFrequencies()" << LogIO::POST ;
    1226 //   // tentative
    1227 //   Table tab = table_->frequencies().table() ;
    1228 //   tab.addRow( 1 ) ;
    1229 //   ScalarColumn<uInt> idCol( tab, "ID" ) ;
    1230 //   idCol.put( 0, 0 ) ;
    1231 // }
    1232 
    1233 // void MSFiller::fillHistory()
    1234 // {
    1235 //   os_ << "MSFiller::fillHistory()" << LogIO::POST ;
    1236 //   // tentative
    1237 //   Table tab = table_->history().table() ;
    1238 //   tab.addRow( 1 ) ;
    1239 //   ScalarColumn<uInt> idCol( tab, "ID" ) ;
    1240 //   idCol.put( 0, 0 ) ;
    1241 // }
    12421376
    12431377uInt MSFiller::getWeatherId( uInt idx, Double wtime )
    12441378{
     1379  //os_ << "start MSFiller::getWeatherId()" << LogIO::POST ;
    12451380  uInt nrow = mwTime_.size() ;
    12461381  if ( nrow == 0 )
     
    12711406  //os_ << LogIO::WARN << "Couldn't find correct WEATHER_ID for time " << wtime << LogIO::POST ;
    12721407
     1408  //os_ << "end MSFiller::getWeatherId()" << LogIO::POST ;
    12731409  return wid ;
    12741410}
     
    12761412Vector<Double> MSFiller::getSysCalTime( MSSysCal &tab, MEpoch::ROScalarColumn &tcol )
    12771413{
     1414  //os_ << "start MSFiller::getSysCalTime()" << LogIO::POST ;
    12781415  uInt nrow = tcol.table().nrow() ;
    12791416  Vector<Double> tstr( nrow, -1.0 ) ;
     
    12811418    return tstr ;
    12821419  uInt scnrow = tab.nrow() ;
    1283   ROMSSysCalColumns sysCalCols( tab ) ;
    1284   ROScalarMeasColumn<MEpoch> scTimeCol = sysCalCols.timeMeas() ;
    1285   ROScalarQuantColumn<Double> scIntervalCol = sysCalCols.intervalQuant() ;
     1420  ROScalarMeasColumn<MEpoch> scTimeCol( tab, "TIME" ) ;
     1421  ROScalarQuantColumn<Double> scIntervalCol( tab, "INTERVAL" ) ;
    12861422  uInt idx = 0 ;
    12871423  const Double half = 0.5e0 ;
     
    13061442    }
    13071443  }
     1444  //os_ << "end MSFiller::getSysCalTime()" << LogIO::POST ;
    13081445  return tstr ;
    13091446}
    13101447
    1311 uInt MSFiller::getTsys( uInt idx, Array<Float> &tsys, MSSysCal &tab, Double t )
     1448uInt MSFiller::getTsys( uInt idx, Matrix<Float> &tsys, MSSysCal &tab, Double t )
    13121449{
     1450  //os_ << "start MSFiller::getTsys()" << LogIO::POST ;
    13131451  uInt nrow = tab.nrow() ;
    13141452  if ( nrow == 0 ) {
     
    13181456  }
    13191457  Bool isSp = tab.tableDesc().isColumn( "TSYS_SPECTRUM" ) ;
    1320   ROMSSysCalColumns calCols( tab ) ;
    1321   ROScalarMeasColumn<MEpoch> scTimeCol = calCols.timeMeas() ;
     1458  ROScalarMeasColumn<MEpoch> scTimeCol( tab, "TIME" ) ;
    13221459  ROArrayColumn<Float> mTsysCol ;
    13231460  if ( isSp ) {
    1324     mTsysCol.reference( calCols.tsysSpectrum() ) ;
     1461    mTsysCol.attach( tab, "TSYS_SPECTRUM" ) ;
    13251462  }
    13261463  else {
    1327     mTsysCol.reference( calCols.tsys() ) ;
     1464    mTsysCol.attach( tab, "TSYS" ) ;
    13281465  }
    13291466  for ( uInt i = idx ; i < nrow ; i++ ) {
     
    13351472    }
    13361473  }
     1474  //os_ << "MSFiller::getTsys() idx = " << idx << " tsys = " << tsys << LogIO::POST ;
     1475  //os_ << "end MSFiller::getTsys()" << LogIO::POST ;
    13371476  return idx ;
    13381477}
     
    13401479Vector<uInt> MSFiller::getTcalId( Int fid, Int spwid, Double t )
    13411480{
     1481  //os_ << "start MSFiller::getTcalId()" << LogIO::POST ;
    13421482  String feed = "FEED" + String::toString(fid) ;
    13431483  String spw = "SPW" + String::toString(spwid) ;
     
    13501490  }
    13511491  Vector<uInt> ids = tcalrec_.asRecord(feed).asArrayuInt(spw) ;
    1352   Table ttabsel = ttab( ttab.col("TIME") == sctime && ttab.col("ID") >= ids[0] && ttab.col("ID") <= ids[1] ).sort("ID") ;
     1492  //Table ttabsel = ttab( ttab.col("TIME") == sctime && ttab.col("ID") >= ids[0] && ttab.col("ID") <= ids[1] ).sort("ID") ;
     1493  Table ttabsel( ttab( ttab.col("TIME") == sctime && ttab.col("ID") >= ids[0] && ttab.col("ID") <= ids[1] ).sort("ID")) ;
    13531494  uInt nrow = ttabsel.nrow() ;
    13541495  Vector<uInt> tcalids( nrow ) ;
     
    13721513  }
    13731514 
     1515  //os_ << "end MSFiller::getTcalId()" << LogIO::POST ;
    13741516  return tcalids ;
    13751517}
    13761518
    1377 uInt MSFiller::getDirection( uInt idx, Vector<Double> &dir, Vector<Double> &srate, String &ref, ROMSPointingColumns &cols, Double t )
     1519uInt MSFiller::getDirection( uInt idx, Vector<Double> &dir, Vector<Double> &srate, String &ref, MSPointing &tab, Double t )
    13781520{
     1521  //os_ << "start MSFiller::getDirection()" << LogIO::POST ;
    13791522  // assume that cols is sorted by TIME
    13801523  Bool doInterp = False ;
    1381   uInt nrow = cols.nrow() ;
     1524  //uInt nrow = cols.nrow() ;
     1525  uInt nrow = tab.nrow() ;
    13821526  if ( nrow == 0 )
    13831527    return 0 ;
    1384   ROScalarMeasColumn<MEpoch> tcol = cols.timeMeas() ;
    1385   ROArrayMeasColumn<MDirection> dmcol = cols.directionMeasCol() ;
    1386   ROArrayColumn<Double> dcol = cols.direction() ;
     1528  ROScalarMeasColumn<MEpoch> tcol( tab, "TIME" ) ;
     1529  ROArrayMeasColumn<MDirection> dmcol( tab, "DIRECTION" ) ;
     1530  ROArrayColumn<Double> dcol( tab, "DIRECTION" ) ;
    13871531  // ensure that tcol(idx) < t
    13881532  //os_ << "tcol(idx) = " << tcol(idx).get("s").getValue() << " t = " << t << " diff = " << tcol(idx).get("s").getValue()-t << endl ;
     
    14141558  //os_ << "searched idx = " << idx << LogIO::POST ;
    14151559
    1416   Slice ds( 0, 2, 1 ) ;
    1417   Slice ds0( 0, 1, 1 ) ;
    1418   Slice ds1( 1, 1, 1 ) ;
    1419   Slicer dslice0( ds, ds0 ) ;
    1420   Slicer dslice1( ds, ds1 ) ;
    14211560  //os_ << "dmcol(idx).shape() = " << dmcol(idx).shape() << LogIO::POST ;
    14221561  IPosition ip( dmcol(idx).shape().nelements(), 0 ) ;
     
    14241563  ref = dmcol(idx)(ip).getRefString() ;
    14251564  //os_ << "ref = " << ref << LogIO::POST ;
    1426   IPosition outp(1,2) ;
    14271565  if ( doInterp ) {
    14281566    //os_ << "do interpolation" << LogIO::POST ;
     
    14301568    Double tref0 = tcol(idx).get("s").getValue() ;
    14311569    Double tref1 = tcol(idx+1).get("s").getValue() ;
    1432     Vector<Double> dir0 = dcol(idx)(dslice0).reform(outp) ;
     1570    Matrix<Double> mdir0 = dcol( idx ) ;
     1571    Matrix<Double> mdir1 = dcol( idx+1 ) ;
     1572    Vector<Double> dir0 = mdir0.column( 0 ) ;
    14331573    //os_ << "dir0 = " << dir0 << LogIO::POST ;
    1434     Vector<Double> dir1 = dcol(idx+1)(dslice0).reform(outp) ;
     1574    Vector<Double> dir1 = mdir1.column( 0 ) ;
    14351575    //os_ << "dir1 = " << dir1 << LogIO::POST ;
    14361576    Double dt0 = t - tref0 ;
    14371577    Double dt1 = tref1 - t ;
    14381578    dir.reference( (dt0*dir1+dt1*dir0)/(dt0+dt1) ) ;
    1439     if ( dcol(idx).shape()(1) > 1 ) {
    1440       if ( dt0 >= dt1 ) {
    1441         srate.reference( dcol(idx)(dslice1).reform(outp) ) ;
    1442       }
    1443       else {
    1444         srate.reference( dcol(idx+1)(dslice1) ) ;
    1445       }
     1579    if ( mdir0.ncolumn() > 1 ) {
     1580      if ( dt0 >= dt1 )
     1581        srate.reference( mdir0.column( 1 ) ) ;
     1582      else
     1583        srate.reference( mdir1.column( 1 ) ) ;
    14461584    }
    14471585    //os_ << "dir = " << dir << LogIO::POST ;
     
    14491587  else {
    14501588    //os_ << "no interpolation" << LogIO::POST ;
    1451     dir.reference( dcol(idx)(dslice0).reform(outp) ) ;
    1452     if ( dcol(idx).shape()(1) > 1 ) {
    1453       srate.reference( dcol(idx)(dslice1).reform(outp) ) ;
    1454     }
    1455   }
    1456 
     1589    Matrix<Double> mdir0 = dcol( idx ) ;
     1590    dir.reference( mdir0.column( 0 ) ) ;
     1591    if ( mdir0.ncolumn() > 1 )
     1592      srate.reference( mdir0.column( 1 ) ) ;
     1593  }
     1594
     1595  //os_ << "end MSFiller::getDirection()" << LogIO::POST ;
    14571596  return idx ;
    14581597}
  • trunk/src/MSFiller.h

    r1974 r1987  
    1616// STL
    1717#include <string>
     18
     19// Boost
     20#include <boost/pool/object_pool.hpp>
     21
    1822// AIPS++
    1923#include <casa/aips.h>
    2024#include <casa/Utilities/CountedPtr.h>
    2125#include <casa/Arrays/Vector.h>
     26#include <casa/Arrays/Matrix.h>
    2227#include <casa/Logging/LogIO.h>
    2328
    2429#include <casa/Containers/Record.h>
    25 #include <tables/Tables/RefRows.h>
     30
     31//#include <tables/Tables/TableColumn.h>
    2632
    2733#include <ms/MeasurementSets/MeasurementSet.h>
    28 #include <ms/MeasurementSets/MSColumns.h>
     34#include <ms/MeasurementSets/MSPointing.h>
    2935
    3036#include "Scantable.h"
     
    5965  //void fillHistory() ;
    6066  //void fillFit() ;
    61   void fillTcal() ;
    62 
    63   // fill ID columns
    64   void fillId( casa::uInt idx, const char *colname, casa::RefRows &rows ) ;
    65   void fillId( casa::Int idx, const char *colname, casa::RefRows &rows ) ;
     67  void fillTcal( boost::object_pool<casa::ROTableColumn> *pool ) ;
    6668
    6769  // get SRCTYPE from STATE_ID
    68   casa::Int getSrcType( casa::Int stateId ) ;
     70  casa::Int getSrcType( casa::Int stateId, boost::object_pool<casa::ROTableColumn> *pool ) ;
     71  //casa::Int getSrcType( casa::Int stateId ) ;
    6972
    7073  // get POLNO from CORR_TYPE
     
    8588  // assume that tab is selected by ANTENNA_ID, FEED_ID, SPECTRAL_WINDOW_ID
    8689  // and sorted by TIME
    87   casa::uInt getTsys( casa::uInt idx, casa::Array<casa::Float> &tsys, casa::MSSysCal &tab, casa::Double t ) ;
     90  casa::uInt getTsys( casa::uInt idx, casa::Matrix<casa::Float> &tsys, casa::MSSysCal &tab, casa::Double t ) ;
    8891
    8992  // get TCAL_ID
     
    9194
    9295  // get direction for DIRECTION, AZIMUTH, and ELEVATION columns
    93   casa::uInt getDirection( casa::uInt idx, casa::Vector<casa::Double> &dir, casa::Vector<casa::Double> &srate, casa::String &ref, casa::ROMSPointingColumns &cols, casa::Double t ) ;
     96  casa::uInt getDirection( casa::uInt idx, casa::Vector<casa::Double> &dir, casa::Vector<casa::Double> &srate, casa::String &ref, casa::MSPointing &tab, casa::Double t ) ;
    9497 
    9598  casa::CountedPtr<Scantable> table_ ;
    9699  casa::MeasurementSet mstable_ ;
    97   casa::MeasurementSet tablesel_ ;
     100  casa::String tablename_ ;
    98101  casa::Int antenna_ ;
    99102  casa::Bool getPt_ ;
     
    115118  casa::Vector<casa::Double> mwInterval_ ;
    116119
     120  // Record for TCAL_ID
     121  // "FIELD0": "SPW0": Vector<uInt>
     122  //           "SPW1": Vector<uInt>
     123  //  ...
    117124  casa::Record tcalrec_ ;
     125
     126  //casa::ROTableColumn *scCol_ ;
    118127};
    119128
  • trunk/src/MSWriter.cpp

    r1977 r1987  
    358358       
    359359        // SCAN_NUMBER
     360        // MS: 1-based
     361        // Scantable: 0-based
    360362        RefRows rows3( current3, current3+added3-1 ) ;
    361         Vector<Int> scanNum( added3, scanNo ) ;
     363        Vector<Int> scanNum( added3, scanNo+1 ) ;
    362364        ScalarColumn<Int> scanNumCol( *mstable_, "SCAN_NUMBER" ) ;
    363365        scanNumCol.putColumnCells( rows3, scanNum ) ;
  • trunk/src/Scantable.cpp

    r1947 r1987  
    12671267  String out;
    12681268  table_.keywordSet().get("AntennaName", out);
     1269  String::size_type pos1 = out.find("@") ;
     1270  String::size_type pos2 = out.find("//") ;
     1271  if ( pos2 != String::npos )
     1272    out = out.substr(pos2+2,pos1) ;
     1273  else if ( pos1 != String::npos )
     1274    out = out.substr(0,pos1) ;
    12691275  return out;
    12701276}
Note: See TracChangeset for help on using the changeset viewer.