Changes in / [2473:2373]


Ignore:
Files:
9 deleted
59 edited

Legend:

Unmodified
Added
Removed
  • /branches/hpc33/CMakeLists.txt

    r2473 r2373  
    8686if( APPLE )
    8787   set( SO dylib )
    88    if( CMAKE_SYSTEM MATCHES ^Darwin-10 OR
    89                 CMAKE_SYSTEM MATCHES ^Darwin-11 )
     88   if( CMAKE_SYSTEM MATCHES ^Darwin-10 )
    9089      if( NOT archflag )
    91          if( EXISTS /opt/casa/darwin11 )
    92             set( archflag x86_64 )
    93          elseif( EXISTS /opt/casa/darwin10-64b )
     90         if( EXISTS /opt/casa/darwin10-64b )
    9491            set( archflag x86_64 )
    9592         elseif( EXISTS /opt/casa/core2-apple-darwin10 )
     
    267264      -DPYVERSION=${PV} )
    268265else()
    269    # with CASA
    270266   if( NOT PYTHON_FOUND )
    271267      if ( NOT PYTHON_LIBNAME )
    272          #set( _names 2.9 2.8 2.7 2.6 2.5.2 2.5 )
    273          set( _names 2.6 2.5.2 2.5 )
    274          # OSX 10.7 has Python2.7 by default. CASA has't yet supported python > 2.6 anyway.
     268         set( _names 2.9 2.8 2.7 2.6 2.5.2 2.5 )
    275269         # (The library named libpython.2.5.2.dylib seems to exist only in the CASA world.)
    276270      else()
     
    282276
    283277         casa_find(
    284             PYTHON${_v}
    285             #PREFIX_HINTS ${PYTHON_ROOT_DIR}
     278            PYTHON${_v}
    286279            LIBS python${_v}
    287280            NO_REQUIRE
     
    319312      # Python library was not in a lib(64) directory!
    320313      message( WARNING "Python library path \"${PYTHON${PYTHON_LIBNAME}_LIBRARIES}\" does not contain \"/lib(64)/lib${python_library}\"" )
    321       set( python_prefix ${casa_packages} )
    322    endif()
    323 
    324    #
    325    # For some unknown reason cmake sets the /usr for Lion
    326    #
    327    if( APPLE )
    328314      set( python_prefix ${casa_packages} )
    329315   endif()
  • /branches/hpc33/cmake/withcasa.cmake

    r2473 r2373  
    66# environment dependent settings
    77if( APPLE )
    8    if( CMAKE_SYSTEM MATCHES ^Darwin-10 OR
    9                 CMAKE_SYSTEM MATCHES ^Darwin-11 )
    10       if ( NOT arch )
    11          set( arch darwin64 )
    12       endif()
     8   if( NOT arch )
     9      set( arch darwin )
     10   endif()
     11   if( CMAKE_SYSTEM MATCHES ^Darwin-10 )
    1312      if( NOT archflag )
    14          if( EXISTS /opt/casa/darwin11 )
    15             set( archflag x86_64 )
    16          elseif( EXISTS /opt/casa/darwin10-64b )
     13         if( EXISTS /opt/casa/darwin10-64b )
    1714            set( archflag x86_64 )
    1815         elseif( EXISTS /opt/casa/core2-apple-darwin10 )
     
    2320      endif()
    2421      if( archflag STREQUAL x86_64 )
    25          if( CMAKE_SYSTEM MATCHES ^Darwin-11 )
    26              set( casa_packages /opt/casa/darwin11 )
    27          else()
    28              set( casa_packages /opt/casa/darwin10-64b )
    29          endif()
     22         set( casa_packages /opt/casa/darwin10-64b )
    3023      else()
    3124         set( casa_packages /opt/casa/core2-apple-darwin10 )
    3225      endif()
    3326   elseif( CMAKE_SYSTEM MATCHES ^Darwin-9 )
    34       if ( NOT arch )
    35          set( arch darwin )
    36       endif()
    3727      set( casa_packages /opt/casa/core2-apple-darwin8/3rd-party )
    3828   endif()         
  • /branches/hpc33/external-alma/asdm2ASAP/ASDMFiller.cc

    r2473 r2373  
    134134        //unsigned int scanno = reader_->getScanNo() ;
    135135        unsigned int scanno = reader_->getScanNoOfCurrentRow() ;
    136         //logsink_->postLocally( LogMessage("scanno = "+String::toString(scanno),LogOrigin(className_,funcName,WHERE)) ) ;
    137136        //uInt subscanno = reader_->getSubscanNo() ;
    138137        citer = cycleno.find( scanno ) ;
     
    153152        string freqref = "" ;
    154153
    155         //logsink_->postLocally( LogMessage("numData = "+String::toString(numData),LogOrigin(className_,funcName,WHERE)) ) ;
    156154        for ( unsigned int idata = 0 ; idata < numData ; idata++ ) {
    157155          // prepare to extract binary data
    158           //logsink_->postLocally( LogMessage("prepare data...",LogOrigin(className_,funcName,WHERE)) ) ;
    159156          reader_->prepareData( idata ) ;
    160157
     
    162159          //unsigned int subscanno = reader_->getSubscanNo( idata ) ;
    163160          unsigned int subscanno = reader_->getSubscanNo() ;
    164           //logsink_->postLocally( LogMessage("subscanno = "+String::toString(subscanno),LogOrigin(className_,funcName,WHERE)) ) ;
    165161
    166162          // IFNO
    167163          //uInt ifno = reader_->getIFNo( idata ) ;
    168164          uInt ifno = reader_->getIFNo() ;
    169           //logsink_->postLocally( LogMessage("ifno = "+String::toString(ifno),LogOrigin(className_,funcName,WHERE)) ) ;
     165
    170166          // source spec
    171167          int srctype = reader_->getSrcType( scanno, subscanno ) ;
    172           //logsink_->postLocally( LogMessage("srctype = "+String::toString(srctype),LogOrigin(className_,funcName,WHERE)) ) ;
    173168          string srcname ;
    174169          string fieldname ;
     
    190185                                      sysVel,
    191186                                      rf ) ;
    192           //logsink_->postLocally( LogMessage("srcname = "+String::toString(srcname),LogOrigin(className_,funcName,WHERE)) ) ;         
    193 
     187         
    194188          // fill MOLECULE_ID and add MOLECULES row if necessary
    195189          Vector<casa::Double> restFreqs( rf.size() ) ;
     
    203197          casa::Double mjd = (casa::Double)(reader_->getTime()) ;
    204198          casa::Double interval = (casa::Double)(reader_->getInterval()) ;
    205           //logsink_->postLocally( LogMessage("mjd = "+String::toString(mjd),LogOrigin(className_,funcName,WHERE)) ) ;
    206199
    207200          // fill TIME and INTERVAL
     
    221214          unsigned int flagrow = reader_->getFlagRow() ;
    222215          setFlagrow( (uInt)flagrow ) ;
    223           //logsink_->postLocally( LogMessage("flagrow = "+String::toString(flagrow),LogOrigin(className_,funcName,WHERE)) ) ;
     216
    224217          // fill WEATHER_ID and add WEATHER row if necessary
    225218          float temperature ;
     
    244237                       (casa::Float)windspeed,
    245238                       (casa::Float)windaz ) ;
    246           //logsink_->postLocally( LogMessage("temperature = "+String::toString(temperature),LogOrigin(className_,funcName,WHERE)) ) ;
     239
    247240          // fill AZIMUTH, ELEVATION, DIRECTION and SCANRATE
    248241          vector<double> dir ;
     
    309302//               oss << dataShape[i] << ", " ;
    310303//           }
    311 //           logsink_->postLocally( LogMessage(oss.str(),LogOrigin(className_,funcName,WHERE)) ) ;
     304          //logsink_->postLocally( LogMessage(oss.str(),LogOrigin(className_,funcName,WHERE)) ) ;
    312305                                     
    313306          //int numPol = reader_->getNumPol( idata ) ;
     
    324317          // SPECTRA, FLAGTRA, TSYS, TCAL
    325318          //float *sp = reader_->getSpectrum( idata ) ;
    326           //logsink_->postLocally( LogMessage("getting spectra...",LogOrigin(className_,funcName,WHERE)) ) ;
    327319          float *sp = reader_->getSpectrum() ;
    328           //logsink_->postLocally( LogMessage("sp[0] = "+String::toString(sp[0]),LogOrigin(className_,funcName,WHERE)) ) ;
    329320          vector< vector<float> > ts ;
    330321          vector< vector<float> > tc ;
     
    332323          reader_->getTcalAndTsys( tc, ts ) ;
    333324          Matrix<casa::Float> spectra = toMatrix( sp, numPol, numChan ) ;
    334           //logsink_->postLocally( LogMessage("spectra(0,0) = "+String::toString(spectra(0,0)),LogOrigin(className_,funcName,WHERE)) ) ;
    335325          Vector<uChar> flagtra( numChan, 0 ) ;
    336326          Matrix<casa::Float> tsys = toMatrix( ts, numPol, numChan ) ;
    337327          Matrix<casa::Float> tcal = toMatrix( tc, numPol, numChan ) ;
    338           //logsink_->postLocally( LogMessage("tsys(0,0) = "+String::toString(tsys(0,0)),LogOrigin(className_,funcName,WHERE)) ) ;
    339328//           String caltime = "" ;
    340329//           if ( anyNE( tcal, (casa::Float)1.0 ) )
  • /branches/hpc33/external-alma/asdm2ASAP/ASDMReader.cc

    r2473 r2373  
    850850                                    vector<double> &restfreq )
    851851{
    852   String funcName = "getSourceProperty" ;
    853852  ostringstream oss ;
    854853  oss << fieldRow_p->getFieldName() << "__" << vmsData_->v_fieldId[dataIndex_] ;
    855854  fieldname = oss.str() ;
    856   SourceRow *srow = 0 ;
    857855  if ( fieldRow_p->isSourceIdExists() ) {
    858856    int sourceId = fieldRow_p->getSourceId() ;
    859     srow = asdm_->getSource().getRowByKey( sourceId, timeInterval_, specWinTag_ ) ;
    860   }
    861   if ( srow != 0 ) {
    862     //logsink_->postLocally( LogMessage("timeInterval_="+String::toString(timeInterval_.getStart().getMJD()),LogOrigin(className_,funcName,WHERE)) ) ;
    863     //logsink_->postLocally( LogMessage("specWinTag_="+String::toString(specWinTag_.toString()),LogOrigin(className_,funcName,WHERE)) ) ;
    864     //SourceRow *srow = asdm_->getSource().getRowByKey( sourceId, timeInterval_, specWinTag_ ) ;
    865     //logsink_->postLocally( LogMessage("sourceId="+String::toString(sourceId),LogOrigin(className_,funcName,WHERE)) ) ;
    866     //if ( srow == 0 )
    867     //logsink_->postLocally( LogMessage("nullpo",LogOrigin(className_,funcName,WHERE)) ) ;
     857    SourceRow *srow = asdm_->getSource().getRowByKey( sourceId, timeInterval_, specWinTag_ ) ;
    868858
    869859    // source name
    870860    srcname = srow->getSourceName() ;
    871     //logsink_->postLocally( LogMessage("srcname="+String::toString(srcname),LogOrigin(className_,funcName,WHERE)) ) ;
    872861
    873862    // source direction
     
    876865    srcdir[0] = limitedAngle( srcdirA[0].get() ) ;
    877866    srcdir[1] = limitedAngle( srcdirA[1].get() ) ;
    878     //logsink_->postLocally( LogMessage("srcdir=["+String::toString(srcdir[0])+","+String::toString(srcdir[1])+"]",LogOrigin(className_,funcName,WHERE)) ) ;
    879867    if ( srow->isDirectionCodeExists() ) {
    880868      DirectionReferenceCodeMod::DirectionReferenceCode dircode = srow->getDirectionCode() ;
     
    893881    srcpm[0] = srcpmA[0].get() ;
    894882    srcpm[1] = srcpmA[1].get() ;
    895     //logsink_->postLocally( LogMessage("srcpm=["+String::toString(srcpm[0])+","+String::toString(srcpm[1])+"]",LogOrigin(className_,funcName,WHERE)) ) ;
     883
    896884    // systemic velocity
    897885    if ( srow->isSysVelExists() ) {
     
    903891      sysvel = 0.0 ;
    904892    }
    905     //logsink_->postLocally( LogMessage("sysvel="+String::toString(sysvel),LogOrigin(className_,funcName,WHERE)) ) ;
     893
    906894    // rest frequency
    907895    if ( srow->isRestFrequencyExists() ) {
     
    915903      restfreq.resize( 0 ) ;
    916904    }
    917     //logsink_->postLocally( LogMessage("restfreq.size()="+String::toString(restfreq.size()),LogOrigin(className_,funcName,WHERE)) ) ;
    918905  }
    919906  else {
     
    11881175  vector< vector<float> > defaultT( 1, vector<float>( 1, 1.0 ) ) ;
    11891176  SysCalRow *scrow = getSysCalRow() ;
    1190   //logsink_->postLocally( LogMessage("scrow = "+String::toString((long)scrow),LogOrigin(className_,funcName,WHERE)) ) ;
    11911177  if ( scrow == 0 ) {
    11921178    tcal = defaultT ;
     
    11981184      unsigned int numReceptor = tsysSpec.size() ;
    11991185      unsigned int numChan = tsysSpec[0].size() ;
    1200       //logsink_->postLocally( LogMessage("TSYS: numReceptor = "+String::toString(numReceptor),LogOrigin(className_,funcName,WHERE)) ) ;
    1201       //logsink_->postLocally( LogMessage("TSYS:numChan = "+String::toString(numChan),LogOrigin(className_,funcName,WHERE)) ) ;
    12021186      tsys.resize( numReceptor ) ;
    12031187      for ( unsigned int ir = 0 ; ir < numReceptor ; ir++ ) {
     
    12151199      unsigned int numReceptor = tcalSpec.size() ;
    12161200      unsigned int numChan = tcalSpec[0].size() ;
    1217       //logsink_->postLocally( LogMessage("TCAL: numReceptor = "+String::toString(numReceptor),LogOrigin(className_,funcName,WHERE)) ) ;
    1218       //logsink_->postLocally( LogMessage("TCAL: numChan = "+String::toString(numChan),LogOrigin(className_,funcName,WHERE)) ) ;
    12191201      tcal.resize( numReceptor ) ;
    12201202      for ( unsigned int ir = 0 ; ir < numReceptor ; ir++ ) {
    1221         tcal[ir].resize( numChan ) ;
     1203        tcal[ir].resize( numReceptor ) ;
    12221204        for ( unsigned int ic = 0 ; ic < numChan ; ic++ ) {
    12231205          tcal[ir][ic] = tcalSpec[ir][ic].get() ;
  • /branches/hpc33/external-alma/oldasdm2ASAP/OldASDMReader.cc

    r2473 r2373  
    12011201      tcal.resize( numReceptor ) ;
    12021202      for ( unsigned int ir = 0 ; ir < numReceptor ; ir++ ) {
    1203         tcal[ir].resize( numChan ) ;
     1203        tcal[ir].resize( numReceptor ) ;
    12041204        for ( unsigned int ic = 0 ; ic < numChan ; ic++ ) {
    12051205          tcal[ir][ic] = tcalSpec[ir][ic].get() ;
  • /branches/hpc33/python/CMakeLists.txt

    r2473 r2373  
    3838     ${PYTHONDIR}/simplelinefinder.py
    3939     ${PYTHONDIR}/utils.py
    40      ${PYTHONDIR}/asapgrid.py
    4140     ${PYTHONDIR}/svninfo.txt )
    4241
  • /branches/hpc33/python/__init__.py

    r2473 r2373  
    5252from opacity import skydip
    5353from opacity import model as opacity_model
    54 from asapgrid import asapgrid
    5554from _asap import srctype
    5655
  • /branches/hpc33/python/asapmath.py

    r2473 r2373  
    988988    tb.open(tablename=filename,nomodify=True)
    989989    ant1=tb.getcol('ANTENNA1',0,-1,1)
    990     #anttab=tb.getkeyword('ANTENNA').split()[-1]
    991     anttab=tb.getkeyword('ANTENNA').lstrip('Table: ')
     990    anttab=tb.getkeyword('ANTENNA').split()[-1]
    992991    tb.close()
    993992    #tb.open(tablename=filename+'/ANTENNA',nomodify=True)
  • /branches/hpc33/src/CMakeLists.txt

    r2473 r2373  
    2121# source files for libpyrap
    2222set( ASAP_SRCS
    23      ${SRCDIR}/concurrent.cpp
    2423     ${SRCDIR}/MathUtils.cpp
    2524     ${SRCDIR}/TableTraverse.cpp
     
    5958     ${SRCDIR}/AsapLogSink.cpp
    6059     ${SRCDIR}/STUpgrade.cpp
    61      ${SRCDIR}/STGrid.cpp
    6260     ${SRCDIR}/Templates.cpp )
    6361
     
    8078     ${SRCDIR}/python_MSWriter.cpp
    8179     ${SRCDIR}/python_LogSink.cpp
    82      ${SRCDIR}/python_STGrid.cpp
    8380     ${SRCDIR}/python_asap.cpp )
    8481
     
    103100install( TARGETS ${ASAPLIB}
    104101         LIBRARY DESTINATION ${PYTHON_INSTALL_DIR} )
    105 if( NOT STANDALONE )
    106   execute_process(
    107     COMMAND ln -Fs ../${PYTHON_INSTALL_DIR}/_${ASAPLIB}.so ${CMAKE_INSTALL_PREFIX}/lib/_${ASAPLIB}.so
    108     OUTPUT_VARIABLE stuff)
    109 endif()
  • /branches/hpc33/src/STFitter.cpp

    r2473 r2373  
    118118    g = dynamic_cast<Gaussian1D<Float>* >(funcs_[i]);
    119119    if (g) {
    120       const GaussianSpectralElement *gauss = dynamic_cast<const GaussianSpectralElement *>(listGauss[i]) ;
    121       (*g)[0] = gauss->getAmpl();
    122       (*g)[1] = gauss->getCenter();
    123       (*g)[2] = gauss->getFWHM();
    124 //       (*g)[0] = listGauss[i].getAmpl();
    125 //       (*g)[1] = listGauss[i].getCenter();
    126 //       (*g)[2] = listGauss[i].getFWHM();
     120      (*g)[0] = listGauss[i].getAmpl();
     121      (*g)[1] = listGauss[i].getCenter();
     122      (*g)[2] = listGauss[i].getFWHM();
    127123    }
    128124  }
  • /branches/hpc33/src/STMath.cpp

    r2473 r2373  
    5353#include "STMath.h"
    5454#include "STSelector.h"
    55 #include "Accelerator.h"
    5655
    5756using namespace casa;
    5857using namespace asap;
    5958
    60 
    61 // 2012/02/17 TN
    62 // Since STGrid is implemented, average doesn't consider direction
    63 // when accumulating
    6459// tolerance for direction comparison (rad)
    65 // #define TOL_OTF    1.0e-15
    66 // #define TOL_POINT  2.9088821e-4  // 1 arcmin
     60#define TOL_OTF    1.0e-15
     61#define TOL_POINT  2.9088821e-4  // 1 arcmin
    6762
    6863STMath::STMath(bool insitu) :
     
    8883  WeightType wtype = stringToWeight(weight);
    8984
    90   // 2012/02/17 TN
    91   // Since STGrid is implemented, average doesn't consider direction
    92   // when accumulating
    9385  // check if OTF observation
    94 //   String obstype = in[0]->getHeader().obstype ;
    95 //   Double tol = 0.0 ;
    96 //   if ( (obstype.find( "OTF" ) != String::npos) || (obstype.find( "OBSERVE_TARGET" ) != String::npos) ) {
    97 //     tol = TOL_OTF ;
    98 //   }
    99 //   else {
    100 //     tol = TOL_POINT ;
    101 //   }
     86  String obstype = in[0]->getHeader().obstype ;
     87  Double tol = 0.0 ;
     88  if ( (obstype.find( "OTF" ) != String::npos) || (obstype.find( "OBSERVE_TARGET" ) != String::npos) ) {
     89    tol = TOL_OTF ;
     90  }
     91  else {
     92    tol = TOL_POINT ;
     93  }
    10294
    10395  // output
     
    150142  while (!iter.pastEnd()) {
    151143    Table subt = iter.table();
    152     // copy the first row of this selection into the new table
    153     tout.addRow();
    154     TableCopy::copyRows(tout, subt, outrowCount, 0, 1);
    155     // re-index to 0
    156     if ( avmode != "SCAN" && avmode != "SOURCE" ) {
    157       scanColOut.put(outrowCount, uInt(0));
    158     }
    159     ++outrowCount;
    160     // 2012/02/17 TN
    161     // Since STGrid is implemented, average doesn't consider direction
    162     // when accumulating
    163 //     MDirection::ScalarColumn dircol ;
    164 //     dircol.attach( subt, "DIRECTION" ) ;
    165 //     Int length = subt.nrow() ;
    166 //     vector< Vector<Double> > dirs ;
    167 //     vector<int> indexes ;
    168 //     for ( Int i = 0 ; i < length ; i++ ) {
    169 //       Vector<Double> t = dircol(i).getAngle(Unit(String("rad"))).getValue() ;
    170 //       //os << << count++ << ": " ;
    171 //       //os << "[" << t[0] << "," << t[1] << "]" << LogIO::POST ;
    172 //       bool adddir = true ;
    173 //       for ( uInt j = 0 ; j < dirs.size() ; j++ ) {
    174 //         //if ( allTrue( t == dirs[j] ) ) {
    175 //         Double dx = t[0] - dirs[j][0] ;
    176 //         Double dy = t[1] - dirs[j][1] ;
    177 //         Double dd = sqrt( dx * dx + dy * dy ) ;
    178 //         //if ( allNearAbs( t, dirs[j], tol ) ) {
    179 //         if ( dd <= tol ) {
    180 //           adddir = false ;
    181 //           break ;
    182 //         }
    183 //       }
    184 //       if ( adddir ) {
    185 //         dirs.push_back( t ) ;
    186 //         indexes.push_back( i ) ;
    187 //       }
     144//     // copy the first row of this selection into the new table
     145//     tout.addRow();
     146//     TableCopy::copyRows(tout, subt, outrowCount, 0, 1);
     147//     // re-index to 0
     148//     if ( avmode != "SCAN" && avmode != "SOURCE" ) {
     149//       scanColOut.put(outrowCount, uInt(0));
    188150//     }
    189 //     uInt rowNum = dirs.size() ;
    190 //     tout.addRow( rowNum ) ;
    191 //     for ( uInt i = 0 ; i < rowNum ; i++ ) {
    192 //       TableCopy::copyRows( tout, subt, outrowCount+i, indexes[i], 1 ) ;
    193 //       // re-index to 0
    194 //       if ( avmode != "SCAN" && avmode != "SOURCE" ) {
    195 //         scanColOut.put(outrowCount+i, uInt(0));
    196 //       }       
    197 //     }
    198 //     outrowCount += rowNum ;
     151//     ++outrowCount;
     152    MDirection::ScalarColumn dircol ;
     153    dircol.attach( subt, "DIRECTION" ) ;
     154    Int length = subt.nrow() ;
     155    vector< Vector<Double> > dirs ;
     156    vector<int> indexes ;
     157    for ( Int i = 0 ; i < length ; i++ ) {
     158      Vector<Double> t = dircol(i).getAngle(Unit(String("rad"))).getValue() ;
     159      //os << << count++ << ": " ;
     160      //os << "[" << t[0] << "," << t[1] << "]" << LogIO::POST ;
     161      bool adddir = true ;
     162      for ( uInt j = 0 ; j < dirs.size() ; j++ ) {
     163        //if ( allTrue( t == dirs[j] ) ) {
     164        Double dx = t[0] - dirs[j][0] ;
     165        Double dy = t[1] - dirs[j][1] ;
     166        Double dd = sqrt( dx * dx + dy * dy ) ;
     167        //if ( allNearAbs( t, dirs[j], tol ) ) {
     168        if ( dd <= tol ) {
     169          adddir = false ;
     170          break ;
     171        }
     172      }
     173      if ( adddir ) {
     174        dirs.push_back( t ) ;
     175        indexes.push_back( i ) ;
     176      }
     177    }
     178    uInt rowNum = dirs.size() ;
     179    tout.addRow( rowNum ) ;
     180    for ( uInt i = 0 ; i < rowNum ; i++ ) {
     181      TableCopy::copyRows( tout, subt, outrowCount+i, indexes[i], 1 ) ;
     182      // re-index to 0
     183      if ( avmode != "SCAN" && avmode != "SOURCE" ) {
     184        scanColOut.put(outrowCount+i, uInt(0));
     185      }       
     186    }
     187    outrowCount += rowNum ;
    199188    ++iter;
    200189  }
     
    216205      ROScalarColumn<Double> tmp(tin, "TIME");
    217206      Double td;tmp.get(0,td);
    218 
    219 #if 1
    220       static char const*const colNames1[] = { "IFNO", "BEAMNO", "POLNO" };
    221       uInt const values1[] = { rec.asuInt("IFNO"), rec.asuInt("BEAMNO"), rec.asuInt("POLNO") };
    222       SingleTypeEqPredicate<uInt, 3> myPred(tin, colNames1, values1);
    223       CustomTableExprNodeRep myNodeRep(tin, myPred);
    224       myNodeRep.link(); // to avoid automatic delete when myExpr is destructed.
    225       CustomTableExprNode myExpr(myNodeRep);
    226       Table basesubt = tin(myExpr);
    227 #else
    228207      Table basesubt = tin( tin.col("BEAMNO") == Int(rec.asuInt("BEAMNO"))
    229208                         && tin.col("IFNO") == Int(rec.asuInt("IFNO"))
    230209                         && tin.col("POLNO") == Int(rec.asuInt("POLNO")) );
    231 #endif
    232210      Table subt;
    233211      if ( avmode == "SOURCE") {
     
    240218      }
    241219
    242       // 2012/02/17 TN
    243       // Since STGrid is implemented, average doesn't consider direction
    244       // when accumulating
    245 //       vector<uInt> removeRows ;
    246 //       uInt nrsubt = subt.nrow() ;
    247 //       for ( uInt irow = 0 ; irow < nrsubt ; irow++ ) {
    248 //         //if ( !allTrue((subt.col("DIRECTION").getArrayDouble(TableExprId(irow)))==rec.asArrayDouble("DIRECTION")) ) {
    249 //         Vector<Double> x0 = (subt.col("DIRECTION").getArrayDouble(TableExprId(irow))) ;
    250 //         Vector<Double> x1 = rec.asArrayDouble("DIRECTION") ;
    251 //         double dx = x0[0] - x1[0];
    252 //         double dy = x0[1] - x1[1];
    253 //         Double dd = sqrt( dx * dx + dy * dy ) ;
    254 //         //if ( !allNearAbs((subt.col("DIRECTION").getArrayDouble(TableExprId(irow))), rec.asArrayDouble("DIRECTION"), tol ) ) {
    255 //         if ( dd > tol ) {
    256 //           removeRows.push_back( irow ) ;
    257 //         }
    258 //       }
    259 //       if ( removeRows.size() != 0 ) {
    260 //         subt.removeRow( removeRows ) ;
    261 //       }
     220      vector<uInt> removeRows ;
     221      uInt nrsubt = subt.nrow() ;
     222      for ( uInt irow = 0 ; irow < nrsubt ; irow++ ) {
     223        //if ( !allTrue((subt.col("DIRECTION").getArrayDouble(TableExprId(irow)))==rec.asArrayDouble("DIRECTION")) ) {
     224        Vector<Double> x0 = (subt.col("DIRECTION").getArrayDouble(TableExprId(irow))) ;
     225        Vector<Double> x1 = rec.asArrayDouble("DIRECTION") ;
     226        double dx = x0[0] - x1[0];
     227        double dy = x0[1] - x1[1];
     228        Double dd = sqrt( dx * dx + dy * dy ) ;
     229        //if ( !allNearAbs((subt.col("DIRECTION").getArrayDouble(TableExprId(irow))), rec.asArrayDouble("DIRECTION"), tol ) ) {
     230        if ( dd > tol ) {
     231          removeRows.push_back( irow ) ;
     232        }
     233      }
     234      if ( removeRows.size() != 0 ) {
     235        subt.removeRow( removeRows ) ;
     236      }
    262237     
    263 //       if ( nrsubt == removeRows.size() )
    264 //         throw(AipsError("Averaging data is empty.")) ;
     238      if ( nrsubt == removeRows.size() )
     239        throw(AipsError("Averaging data is empty.")) ;
    265240
    266241      specCol.attach(subt,"SPECTRA");
     
    346321{
    347322  (void) mode; // currently unused
    348   // 2012/02/17 TN
    349   // Since STGrid is implemented, average doesn't consider direction
    350   // when accumulating
    351323  // check if OTF observation
    352 //   String obstype = in->getHeader().obstype ;
    353 //   Double tol = 0.0 ;
    354 //   if ( obstype.find( "OTF" ) != String::npos ) {
    355 //     tol = TOL_OTF ;
    356 //   }
    357 //   else {
    358 //     tol = TOL_POINT ;
    359 //   }
     324  String obstype = in->getHeader().obstype ;
     325  Double tol = 0.0 ;
     326  if ( obstype.find( "OTF" ) != String::npos ) {
     327    tol = TOL_OTF ;
     328  }
     329  else {
     330    tol = TOL_POINT ;
     331  }
    360332
    361333  // clone as this is non insitu
     
    390362    flagCol.attach(subt,"FLAGTRA");
    391363    tsysCol.attach(subt,"TSYS");
    392 
    393     tout.addRow();
    394     TableCopy::copyRows(tout, subt, outrowCount, 0, 1);
    395     if ( avmode != "SCAN") {
    396       scanColOut.put(outrowCount, uInt(0));
    397     }
    398     Vector<Float> tmp;
    399     specCol.get(0, tmp);
    400     uInt nchan = tmp.nelements();
    401     // have to do channel by channel here as MaskedArrMath
    402     // doesn't have partialMedians
    403     Vector<uChar> flags = flagCol.getColumn(Slicer(Slice(0)));
    404     Vector<Float> outspec(nchan);
    405     Vector<uChar> outflag(nchan,0);
    406     Vector<Float> outtsys(1);/// @fixme when tsys is channel based
    407     for (uInt i=0; i<nchan; ++i) {
    408       Vector<Float> specs = specCol.getColumn(Slicer(Slice(i)));
    409       MaskedArray<Float> ma = maskedArray(specs,flags);
    410       outspec[i] = median(ma);
    411       if ( allEQ(ma.getMask(), False) )
    412         outflag[i] = userflag;// flag data
    413     }
    414     outtsys[0] = median(tsysCol.getColumn());
    415     specColOut.put(outrowCount, outspec);
    416     flagColOut.put(outrowCount, outflag);
    417     tsysColOut.put(outrowCount, outtsys);
    418     Double intsum = sum(intCol.getColumn());
    419     intColOut.put(outrowCount, intsum);
    420     ++outrowCount;
     364//     tout.addRow();
     365//     TableCopy::copyRows(tout, subt, outrowCount, 0, 1);
     366//     if ( avmode != "SCAN") {
     367//       scanColOut.put(outrowCount, uInt(0));
     368//     }
     369//     Vector<Float> tmp;
     370//     specCol.get(0, tmp);
     371//     uInt nchan = tmp.nelements();
     372//     // have to do channel by channel here as MaskedArrMath
     373//     // doesn't have partialMedians
     374//     Vector<uChar> flags = flagCol.getColumn(Slicer(Slice(0)));
     375//     Vector<Float> outspec(nchan);
     376//     Vector<uChar> outflag(nchan,0);
     377//     Vector<Float> outtsys(1);/// @fixme when tsys is channel based
     378//     for (uInt i=0; i<nchan; ++i) {
     379//       Vector<Float> specs = specCol.getColumn(Slicer(Slice(i)));
     380//       MaskedArray<Float> ma = maskedArray(specs,flags);
     381//       outspec[i] = median(ma);
     382//       if ( allEQ(ma.getMask(), False) )
     383//         outflag[i] = userflag;// flag data
     384//     }
     385//     outtsys[0] = median(tsysCol.getColumn());
     386//     specColOut.put(outrowCount, outspec);
     387//     flagColOut.put(outrowCount, outflag);
     388//     tsysColOut.put(outrowCount, outtsys);
     389//     Double intsum = sum(intCol.getColumn());
     390//     intColOut.put(outrowCount, intsum);
     391//     ++outrowCount;
     392//     ++iter;
     393    MDirection::ScalarColumn dircol ;
     394    dircol.attach( subt, "DIRECTION" ) ;
     395    Int length = subt.nrow() ;
     396    vector< Vector<Double> > dirs ;
     397    vector<int> indexes ;
     398    // Handle MX mode averaging
     399    if (in->nbeam() > 1 ) {     
     400      length = 1;
     401    }
     402    for ( Int i = 0 ; i < length ; i++ ) {
     403      Vector<Double> t = dircol(i).getAngle(Unit(String("rad"))).getValue() ;
     404      bool adddir = true ;
     405      for ( uInt j = 0 ; j < dirs.size() ; j++ ) {
     406        //if ( allTrue( t == dirs[j] ) ) {
     407        Double dx = t[0] - dirs[j][0] ;
     408        Double dy = t[1] - dirs[j][1] ;
     409        Double dd = sqrt( dx * dx + dy * dy ) ;
     410        //if ( allNearAbs( t, dirs[j], tol ) ) {
     411        if ( dd <= tol ) {
     412          adddir = false ;
     413          break ;
     414        }
     415      }
     416      if ( adddir ) {
     417        dirs.push_back( t ) ;
     418        indexes.push_back( i ) ;
     419      }
     420    }
     421    uInt rowNum = dirs.size() ;
     422    tout.addRow( rowNum );
     423    for ( uInt i = 0 ; i < rowNum ; i++ ) {
     424      TableCopy::copyRows(tout, subt, outrowCount+i, indexes[i], 1) ;
     425      // Handle MX mode averaging
     426      if ( avmode != "SCAN") {
     427        scanColOut.put(outrowCount+i, uInt(0));
     428      }
     429    }
     430    MDirection::ScalarColumn dircolOut ;
     431    dircolOut.attach( tout, "DIRECTION" ) ;
     432    for ( uInt irow = 0 ; irow < rowNum ; irow++ ) {
     433      Vector<Double> t = \
     434        dircolOut(outrowCount+irow).getAngle(Unit(String("rad"))).getValue() ;
     435      Vector<Float> tmp;
     436      specCol.get(0, tmp);
     437      uInt nchan = tmp.nelements();
     438      // have to do channel by channel here as MaskedArrMath
     439      // doesn't have partialMedians
     440      Vector<uChar> flags = flagCol.getColumn(Slicer(Slice(0)));
     441      // mask spectra for different DIRECTION
     442      for ( uInt jrow = 0 ; jrow < subt.nrow() ; jrow++ ) {
     443        Vector<Double> direction = \
     444          dircol(jrow).getAngle(Unit(String("rad"))).getValue() ;
     445        //if ( t[0] != direction[0] || t[1] != direction[1] ) {
     446        Double dx = t[0] - direction[0];
     447        Double dy = t[1] - direction[1];
     448        Double dd = sqrt(dx*dx + dy*dy);
     449        //if ( !allNearAbs( t, direction, tol ) ) {
     450        if ( dd > tol &&  in->nbeam() < 2 ) {
     451          flags[jrow] = userflag ;
     452        }
     453      }
     454      Vector<Float> outspec(nchan);
     455      Vector<uChar> outflag(nchan,0);
     456      Vector<Float> outtsys(1);/// @fixme when tsys is channel based
     457      for (uInt i=0; i<nchan; ++i) {
     458        Vector<Float> specs = specCol.getColumn(Slicer(Slice(i)));
     459        MaskedArray<Float> ma = maskedArray(specs,flags);
     460        outspec[i] = median(ma);
     461        if ( allEQ(ma.getMask(), False) )
     462          outflag[i] = userflag;// flag data
     463      }
     464      outtsys[0] = median(tsysCol.getColumn());
     465      specColOut.put(outrowCount+irow, outspec);
     466      flagColOut.put(outrowCount+irow, outflag);
     467      tsysColOut.put(outrowCount+irow, outtsys);
     468      Vector<Double> integ = intCol.getColumn() ;
     469      MaskedArray<Double> mi = maskedArray( integ, flags ) ;
     470      Double intsum = sum(mi);
     471      intColOut.put(outrowCount+irow, intsum);
     472    }
     473    outrowCount += rowNum ;
    421474    ++iter;
    422 
    423     // 2012/02/17 TN
    424     // Since STGrid is implemented, average doesn't consider direction
    425     // when accumulating
    426 //     MDirection::ScalarColumn dircol ;
    427 //     dircol.attach( subt, "DIRECTION" ) ;
    428 //     Int length = subt.nrow() ;
    429 //     vector< Vector<Double> > dirs ;
    430 //     vector<int> indexes ;
    431 //     // Handle MX mode averaging
    432 //     if (in->nbeam() > 1 ) {     
    433 //       length = 1;
    434 //     }
    435 //     for ( Int i = 0 ; i < length ; i++ ) {
    436 //       Vector<Double> t = dircol(i).getAngle(Unit(String("rad"))).getValue() ;
    437 //       bool adddir = true ;
    438 //       for ( uInt j = 0 ; j < dirs.size() ; j++ ) {
    439 //         //if ( allTrue( t == dirs[j] ) ) {
    440 //         Double dx = t[0] - dirs[j][0] ;
    441 //         Double dy = t[1] - dirs[j][1] ;
    442 //         Double dd = sqrt( dx * dx + dy * dy ) ;
    443 //         //if ( allNearAbs( t, dirs[j], tol ) ) {
    444 //         if ( dd <= tol ) {
    445 //           adddir = false ;
    446 //           break ;
    447 //         }
    448 //       }
    449 //       if ( adddir ) {
    450 //         dirs.push_back( t ) ;
    451 //         indexes.push_back( i ) ;
    452 //       }
    453 //     }
    454 //     uInt rowNum = dirs.size() ;
    455 //     tout.addRow( rowNum );
    456 //     for ( uInt i = 0 ; i < rowNum ; i++ ) {
    457 //       TableCopy::copyRows(tout, subt, outrowCount+i, indexes[i], 1) ;
    458 //       // Handle MX mode averaging
    459 //       if ( avmode != "SCAN") {
    460 //         scanColOut.put(outrowCount+i, uInt(0));
    461 //       }
    462 //     }
    463 //     MDirection::ScalarColumn dircolOut ;
    464 //     dircolOut.attach( tout, "DIRECTION" ) ;
    465 //     for ( uInt irow = 0 ; irow < rowNum ; irow++ ) {
    466 //       Vector<Double> t = \
    467 //      dircolOut(outrowCount+irow).getAngle(Unit(String("rad"))).getValue() ;
    468 //       Vector<Float> tmp;
    469 //       specCol.get(0, tmp);
    470 //       uInt nchan = tmp.nelements();
    471 //       // have to do channel by channel here as MaskedArrMath
    472 //       // doesn't have partialMedians
    473 //       Vector<uChar> flags = flagCol.getColumn(Slicer(Slice(0)));
    474 //       // mask spectra for different DIRECTION
    475 //       for ( uInt jrow = 0 ; jrow < subt.nrow() ; jrow++ ) {
    476 //         Vector<Double> direction = \
    477 //        dircol(jrow).getAngle(Unit(String("rad"))).getValue() ;
    478 //         //if ( t[0] != direction[0] || t[1] != direction[1] ) {
    479 //         Double dx = t[0] - direction[0];
    480 //         Double dy = t[1] - direction[1];
    481 //         Double dd = sqrt(dx*dx + dy*dy);
    482 //         //if ( !allNearAbs( t, direction, tol ) ) {
    483 //         if ( dd > tol &&  in->nbeam() < 2 ) {
    484 //           flags[jrow] = userflag ;
    485 //         }
    486 //       }
    487 //       Vector<Float> outspec(nchan);
    488 //       Vector<uChar> outflag(nchan,0);
    489 //       Vector<Float> outtsys(1);/// @fixme when tsys is channel based
    490 //       for (uInt i=0; i<nchan; ++i) {
    491 //         Vector<Float> specs = specCol.getColumn(Slicer(Slice(i)));
    492 //         MaskedArray<Float> ma = maskedArray(specs,flags);
    493 //         outspec[i] = median(ma);
    494 //         if ( allEQ(ma.getMask(), False) )
    495 //           outflag[i] = userflag;// flag data
    496 //       }
    497 //       outtsys[0] = median(tsysCol.getColumn());
    498 //       specColOut.put(outrowCount+irow, outspec);
    499 //       flagColOut.put(outrowCount+irow, outflag);
    500 //       tsysColOut.put(outrowCount+irow, outtsys);
    501 //       Vector<Double> integ = intCol.getColumn() ;
    502 //       MaskedArray<Double> mi = maskedArray( integ, flags ) ;
    503 //       Double intsum = sum(mi);
    504 //       intColOut.put(outrowCount+irow, intsum);
    505 //     }
    506 //     outrowCount += rowNum ;
    507 //     ++iter;
    508475  }
    509476  return out;
     
    29872954                    "Use merge first."));
    29882955 
    2989   // 2012/02/17 TN
    2990   // Since STGrid is implemented, average doesn't consider direction
    2991   // when accumulating
    29922956  // check if OTF observation
    2993 //   String obstype = in[0]->getHeader().obstype ;
    2994 //   Double tol = 0.0 ;
    2995 //   if ( obstype.find( "OTF" ) != String::npos ) {
    2996 //     tol = TOL_OTF ;
    2997 //   }
    2998 //   else {
    2999 //     tol = TOL_POINT ;
    3000 //   }
     2957  String obstype = in[0]->getHeader().obstype ;
     2958  Double tol = 0.0 ;
     2959  if ( obstype.find( "OTF" ) != String::npos ) {
     2960    tol = TOL_OTF ;
     2961  }
     2962  else {
     2963    tol = TOL_POINT ;
     2964  }
    30012965
    30022966  CountedPtr<Scantable> out ;     // processed result
     
    35933557    ScalarColumn<uInt> freqidColOut ;
    35943558    freqidColOut.attach( out->table(), "FREQ_ID" ) ;
    3595 //     MDirection::ScalarColumn dirColOut ;
    3596 //     dirColOut.attach( out->table(), "DIRECTION" ) ;
     3559    MDirection::ScalarColumn dirColOut ;
     3560    dirColOut.attach( out->table(), "DIRECTION" ) ;
    35973561    Table &tab = tmpout->table() ;
    35983562    Block<String> cols(1);
     
    36113575      ScalarColumn<uInt> polnos ;
    36123576      polnos.attach( iter.table(), "POLNO" ) ;
    3613 //       MDirection::ScalarColumn dircol ;
    3614 //       dircol.attach( iter.table(), "DIRECTION" ) ;
     3577      MDirection::ScalarColumn dircol ;
     3578      dircol.attach( iter.table(), "DIRECTION" ) ;
    36153579      uInt polno = polnos( 0 ) ;
    36163580      //os << "POLNO iteration: " << polno << LogIO::POST ;
     
    36713635        if ( polout == polno ) {
    36723636          uInt ifout = ifnoColOut( irow ) ;
    3673 //           Vector<Double> direction = dirColOut(irow).getAngle(Unit(String("rad"))).getValue() ;
     3637          Vector<Double> direction = dirColOut(irow).getAngle(Unit(String("rad"))).getValue() ;
    36743638          uInt igrp ;
    36753639          for ( uInt jgrp = 0 ; jgrp < freqgrp.size() ; jgrp++ ) {
     
    36823646            for ( uInt jrow = 0 ; jrow < iter.table().nrow() ; jrow++ ) {
    36833647              uInt ifno = ifnoCol( jrow ) ;
    3684               // 2012/02/17 TN
    3685               // Since STGrid is implemented, average doesn't consider direction
    3686               // when accumulating
    3687 //               Vector<Double> tdir = dircol(jrow).getAngle(Unit(String("rad"))).getValue() ;
    3688 //               //if ( ifno == freqgrp[igrp][imem] && allTrue( tdir == direction  ) ) {
    3689 //               Double dx = tdir[0] - direction[0] ;
    3690 //               Double dy = tdir[1] - direction[1] ;
    3691 //               Double dd = sqrt( dx * dx + dy * dy ) ;
     3648              Vector<Double> tdir = dircol(jrow).getAngle(Unit(String("rad"))).getValue() ;
     3649              //if ( ifno == freqgrp[igrp][imem] && allTrue( tdir == direction  ) ) {
     3650              Double dx = tdir[0] - direction[0] ;
     3651              Double dy = tdir[1] - direction[1] ;
     3652              Double dd = sqrt( dx * dx + dy * dy ) ;
    36923653              //if ( ifno == freqgrp[igrp][imem] && allNearAbs( tdir, direction, tol ) ) {
    3693 //               if ( ifno == freqgrp[igrp][imem] && dd <= tol ) {
    3694               if ( ifno == freqgrp[igrp][imem] ) {
     3654              if ( ifno == freqgrp[igrp][imem] && dd <= tol ) {
    36953655                Vector<Float> spec = specCols( jrow ) ;
    36963656                Vector<uChar> flag = flagCols( jrow ) ;
     
    44634423}
    44644424
    4465 vector<float> STMath::getSpectrumFromTime( double reftime,
    4466                                            CountedPtr<Scantable>& s,
    4467                                            string mode )
    4468 {
    4469   LogIO os( LogOrigin( "STMath", "getSpectrumFromTime", WHERE ) ) ;
    4470   vector<float> sp ;
    4471 
    4472   if ( s->nrow() == 0 ) {
    4473     os << LogIO::SEVERE << "No spectra in the input scantable. Return empty spectrum." << LogIO::POST ;
    4474     return sp ;
    4475   }
    4476   else if ( s->nrow() == 1 ) {
    4477     //os << "use row " << 0 << " (scanno = " << s->getScan( 0 ) << ")" << LogIO::POST ;
    4478     return s->getSpectrum( 0 ) ;
    4479   }
    4480   else {
    4481     ROScalarColumn<Double> timeCol( s->table(), "TIME" ) ;
    4482     Vector<Double> timeVec = timeCol.getColumn() ;
    4483     vector<int> idx = getRowIdFromTime( reftime, timeVec ) ;
    4484     if ( mode == "before" ) {
    4485       int id = -1 ;
    4486       if ( idx[0] != -1 ) {
    4487         id = idx[0] ;
    4488       }
    4489       else if ( idx[1] != -1 ) {
    4490         os << LogIO::WARN << "Failed to find a scan before reftime. return a spectrum just after the reftime." << LogIO::POST ;
    4491         id = idx[1] ;
    4492       }
    4493       //os << "use row " << id << " (scanno = " << s->getScan( id ) << ")" << LogIO::POST ;
    4494       sp = s->getSpectrum( id ) ;
    4495     }
    4496     else if ( mode == "after" ) {
    4497       int id = -1 ;
    4498       if ( idx[1] != -1 ) {
    4499         id = idx[1] ;
    4500       }
    4501       else if ( idx[0] != -1 ) {
    4502         os << LogIO::WARN << "Failed to find a scan after reftime. return a spectrum just before the reftime." << LogIO::POST ;
    4503         id = idx[1] ;
    4504       }
    4505       //os << "use row " << id << " (scanno = " << s->getScan( id ) << ")" << LogIO::POST ;
    4506       sp = s->getSpectrum( id ) ;
    4507     }
    4508     else if ( mode == "nearest" ) {
    4509       int id = -1 ;
    4510       if ( idx[0] == -1 ) {
    4511         id = idx[1] ;
    4512       }
    4513       else if ( idx[1] == -1 ) {
    4514         id = idx[0] ;
    4515       }
    4516       else if ( idx[0] == idx[1] ) {
    4517         id = idx[0] ;
    4518       }
    4519       else {
    4520         //double t0 = getMJD( s->getTime( idx[0] ) ) ;
    4521         //double t1 = getMJD( s->getTime( idx[1] ) ) ;
    4522 //         double t0 = s->getEpoch( idx[0] ).get( Unit( "d" ) ).getValue() ;
    4523 //         double t1 = s->getEpoch( idx[1] ).get( Unit( "d" ) ).getValue() ;
    4524         double t0 = timeVec[idx[0]] ;
    4525         double t1 = timeVec[idx[1]] ;
    4526 //         cout << "t0-t0c=" << t0-t0c << endl ;
    4527 //         cout << "t1-t1c=" << t1-t1c << endl ;
    4528 //         double tref = getMJD( reftime ) ;
    4529         double tref = reftime ;
    4530         if ( abs( t0 - tref ) > abs( t1 - tref ) ) {
    4531           id = idx[1] ;
    4532         }
    4533         else {
    4534           id = idx[0] ;
    4535         }
    4536       }
    4537       //os << "use row " << id << " (scanno = " << s->getScan( id ) << ")" << LogIO::POST ;
    4538       sp = s->getSpectrum( id ) ;     
    4539     }
    4540     else if ( mode == "linear" ) {
    4541       if ( idx[0] == -1 ) {
    4542         // use after
    4543         os << LogIO::WARN << "Failed to interpolate. return a spectrum just after the reftime." << LogIO::POST ;
    4544         int id = idx[1] ;
    4545         //os << "use row " << id << " (scanno = " << s->getScan( id ) << ")" << LogIO::POST ;
    4546         sp = s->getSpectrum( id ) ;
    4547       }
    4548       else if ( idx[1] == -1 ) {
    4549         // use before
    4550         os << LogIO::WARN << "Failed to interpolate. return a spectrum just before the reftime." << LogIO::POST ;
    4551         int id = idx[0] ;
    4552         //os << "use row " << id << " (scanno = " << s->getScan( id ) << ")" << LogIO::POST ;
    4553         sp = s->getSpectrum( id ) ;
    4554       }
    4555       else if ( idx[0] == idx[1] ) {
    4556         // use before
    4557         //os << "No need to interporate." << LogIO::POST ;
    4558         int id = idx[0] ;
    4559         //os << "use row " << id << " (scanno = " << s->getScan( id ) << ")" << LogIO::POST ;
    4560         sp = s->getSpectrum( id ) ;
    4561       }
    4562       else {
    4563         // do interpolation
    4564         //os << "interpolate between " << idx[0] << " and " << idx[1] << " (scanno: " << s->getScan( idx[0] ) << ", " << s->getScan( idx[1] ) << ")" << LogIO::POST ;
    4565         //double t0 = getMJD( s->getTime( idx[0] ) ) ;
    4566         //double t1 = getMJD( s->getTime( idx[1] ) ) ;
    4567 //         double t0 = s->getEpoch( idx[0] ).get( Unit( "d" ) ).getValue() ;
    4568 //         double t1 = s->getEpoch( idx[1] ).get( Unit( "d" ) ).getValue() ;
    4569         double t0 = timeVec[idx[0]] ;
    4570         double t1 = timeVec[idx[1]] ;
    4571 //         cout << "t0-t0c=" << t0-t0c << endl ;
    4572 //         cout << "t1-t1c=" << t1-t1c << endl ;
    4573 //         double tref = getMJD( reftime ) ;
    4574         double tref = reftime ;
    4575         vector<float> sp0 = s->getSpectrum( idx[0] ) ;
    4576         vector<float> sp1 = s->getSpectrum( idx[1] ) ;
    4577         for ( unsigned int i = 0 ; i < sp0.size() ; i++ ) {
    4578           float v = ( sp1[i] - sp0[i] ) / ( t1 - t0 ) * ( tref - t0 ) + sp0[i] ;
    4579           sp.push_back( v ) ;
    4580         }
    4581       }
    4582     }
    4583     else {
    4584       os << LogIO::SEVERE << "Unknown mode" << LogIO::POST ;
    4585     }
    4586     return sp ;
    4587   }
    4588 }
    4589 
    45904425double STMath::getMJD( string strtime )
    45914426{
     
    46464481  v.push_back( just_before ) ;
    46474482  v.push_back( just_after ) ;
    4648 
    4649   return v ;
    4650 }
    4651 
    4652 vector<int> STMath::getRowIdFromTime( double reftime, Vector<Double> &t )
    4653 {
    4654 //   double reft = reftime ;
    4655   double dtmin = 1.0e100 ;
    4656   double dtmax = -1.0e100 ;
    4657 //   vector<double> dt ;
    4658   int just_before = -1 ;
    4659   int just_after = -1 ;
    4660   //cout << setprecision(24) << reft << endl ;
    4661 //   ROScalarColumn<Double> timeCol( s->table(), "TIME" ) ;
    4662 //   for ( int i = 0 ; i < s->nrow() ; i++ ) {
    4663 //     cout << setprecision(24) << timeCol(i) << endl ;
    4664 //     //dt.push_back( getMJD( s->getTime( i ) ) - reft ) ;
    4665 //     dt.push_back( timeCol(i) - reft ) ;
    4666 //   }
    4667   Vector<Double> dt = t - reftime ;
    4668   for ( unsigned int i = 0 ; i < dt.size() ; i++ ) {
    4669     if ( dt[i] > 0.0 ) {
    4670       // after reftime
    4671       if ( dt[i] < dtmin ) {
    4672         just_after = i ;
    4673         dtmin = dt[i] ;
    4674       }
    4675     }
    4676     else if ( dt[i] < 0.0 ) {
    4677       // before reftime
    4678       if ( dt[i] > dtmax ) {
    4679         just_before = i ;
    4680         dtmax = dt[i] ;
    4681       }
    4682     }
    4683     else {
    4684       // just a reftime
    4685       just_before = i ;
    4686       just_after = i ;
    4687       dtmax = 0 ;
    4688       dtmin = 0 ;
    4689       break ;
    4690     }
    4691   }
    4692 
    4693   vector<int> v(2) ;
    4694   v[0] = just_before ;
    4695   v[1] = just_after ;
    46964483
    46974484  return v ;
     
    50194806                                            int index )
    50204807{
    5021 //   string reftime = on->getTime( index ) ;
    5022   ROTableColumn timeCol( on->table(), "TIME" ) ;
    5023   double reftime = timeCol.asdouble(index) ;
     4808  string reftime = on->getTime( index ) ;
    50244809  vector<int> ii( 1, on->getIF( index ) ) ;
    50254810  vector<int> ib( 1, on->getBeam( index ) ) ;
  • /branches/hpc33/src/STMath.h

    r2473 r2373  
    403403
    404404  vector<float> getSpectrumFromTime( string reftime, casa::CountedPtr<Scantable>& s, string mode = "before" ) ;
    405   vector<float> getSpectrumFromTime( double reftime, casa::CountedPtr<Scantable>& s, string mode = "before" ) ;
    406405  vector<float> getTcalFromTime( string reftime, casa::CountedPtr<Scantable>& s, string mode="before" ) ;
    407406  vector<float> getTsysFromTime( string reftime, casa::CountedPtr<Scantable>& s, string mode="before" ) ;
    408407  vector<int> getRowIdFromTime( string reftime, casa::CountedPtr<Scantable>& s ) ;
    409   vector<int> getRowIdFromTime( double reftime, casa::Vector<casa::Double>& t ) ;
    410408
    411409  // Chopper-Wheel type calibration
  • /branches/hpc33/src/Scantable.h

    r2473 r2373  
    480480   */
    481481  void parallactify(bool flag)
    482     { focusTable_.setParallactify(flag); }
     482    { focus().setParallactify(flag); }
    483483
    484484  /**
  • /branches/hpc33/src/python_asap.cpp

    r2473 r2373  
    8484  asap::python::python_STAtmosphere();
    8585  asap::python::python_SrcType();
    86   asap::python::python_STGrid();
    8786
    8887#ifndef HAVE_LIBPYRAP
  • /branches/hpc33/src/python_asap.h

    r2473 r2373  
    5252    void python_STAtmosphere();
    5353    void python_SrcType();
    54     void python_STGrid();
    5554
    5655  } // python
  • /trunk/CMakeLists.txt

    r2473 r2373  
    1515message( STATUS "USE_LIBCASACORE = " ${USE_LIBCASACORE} )
    1616message( STATUS "STANDALONE = " ${STANDALONE} )
    17 
    18 # Use casapy's fork of casacore 
    19 if ( NOT STANDALONE )
    20   add_definitions( -DUSE_CASAPY )
    21 endif ()
    2217
    2318# Define compiler paths on OSX 10.5. This must be done before invoking project()
     
    4742# default is RelWithDebInfo
    4843#
    49 
    50 
    5144if ( NOT CMAKE_BUILD_TYPE )
    5245   set( CMAKE_BUILD_TYPE RelWithDebInfo )
     
    9386if( APPLE )
    9487   set( SO dylib )
    95    if( CMAKE_SYSTEM MATCHES ^Darwin-10 OR
    96                 CMAKE_SYSTEM MATCHES ^Darwin-11 )
     88   if( CMAKE_SYSTEM MATCHES ^Darwin-10 )
    9789      if( NOT archflag )
    98          if( EXISTS /opt/casa/darwin11 )
    99             set( archflag x86_64 )
    100          elseif( EXISTS /opt/casa/darwin10-64b )
     90         if( EXISTS /opt/casa/darwin10-64b )
    10191            set( archflag x86_64 )
    10292         elseif( EXISTS /opt/casa/core2-apple-darwin10 )
     
    274264      -DPYVERSION=${PV} )
    275265else()
    276    # with CASA
    277266   if( NOT PYTHON_FOUND )
    278267      if ( NOT PYTHON_LIBNAME )
    279          #set( _names 2.9 2.8 2.7 2.6 2.5.2 2.5 )
    280          set( _names 2.6 2.5.2 2.5 )
    281          # OSX 10.7 has Python2.7 by default. CASA has't yet supported python > 2.6 anyway.
     268         set( _names 2.9 2.8 2.7 2.6 2.5.2 2.5 )
    282269         # (The library named libpython.2.5.2.dylib seems to exist only in the CASA world.)
    283270      else()
     
    289276
    290277         casa_find(
    291             PYTHON${_v}
    292             #PREFIX_HINTS ${PYTHON_ROOT_DIR}
     278            PYTHON${_v}
    293279            LIBS python${_v}
    294280            NO_REQUIRE
     
    326312      # Python library was not in a lib(64) directory!
    327313      message( WARNING "Python library path \"${PYTHON${PYTHON_LIBNAME}_LIBRARIES}\" does not contain \"/lib(64)/lib${python_library}\"" )
    328       set( python_prefix ${casa_packages} )
    329    endif()
    330 
    331    #
    332    # For some unknown reason cmake sets the /usr for Lion
    333    #
    334    if( APPLE )
    335314      set( python_prefix ${casa_packages} )
    336315   endif()
     
    606585# libraries and executables
    607586#
    608 set( ASAPPYLIB _asap )
    609587set( ASAPLIB asap )
    610588set( PYRAPLIB pyrap )
     
    612590set( ASAP2TO3 asap2to3 )
    613591if ( NOT STANDALONE )
    614 #   set( ASDM2ASAP_OLD oldasdm2ASAP )
     592   set( ASDM2ASAP_OLD oldasdm2ASAP )
    615593   set( ASDM2ASAP asdm2ASAP )
    616594endif()
  • /trunk/cmake/withcasa.cmake

    r2473 r2373  
    66# environment dependent settings
    77if( APPLE )
    8    if( CMAKE_SYSTEM MATCHES ^Darwin-10 OR
    9                 CMAKE_SYSTEM MATCHES ^Darwin-11 )
    10       if ( NOT arch )
    11          set( arch darwin64 )
    12       endif()
     8   if( NOT arch )
     9      set( arch darwin )
     10   endif()
     11   if( CMAKE_SYSTEM MATCHES ^Darwin-10 )
    1312      if( NOT archflag )
    14          if( EXISTS /opt/casa/darwin11 )
    15             set( archflag x86_64 )
    16          elseif( EXISTS /opt/casa/darwin10-64b )
     13         if( EXISTS /opt/casa/darwin10-64b )
    1714            set( archflag x86_64 )
    1815         elseif( EXISTS /opt/casa/core2-apple-darwin10 )
     
    2320      endif()
    2421      if( archflag STREQUAL x86_64 )
    25          if( CMAKE_SYSTEM MATCHES ^Darwin-11 )
    26              set( casa_packages /opt/casa/darwin11 )
    27          else()
    28              set( casa_packages /opt/casa/darwin10-64b )
    29          endif()
     22         set( casa_packages /opt/casa/darwin10-64b )
    3023      else()
    3124         set( casa_packages /opt/casa/core2-apple-darwin10 )
    3225      endif()
    3326   elseif( CMAKE_SYSTEM MATCHES ^Darwin-9 )
    34       if ( NOT arch )
    35          set( arch darwin )
    36       endif()
    3727      set( casa_packages /opt/casa/core2-apple-darwin8/3rd-party )
    3828   endif()         
     
    124114endif()
    125115message( STATUS "LIBXML2_LIBRARY = " ${LIBXML2_LIBRARY} )
    126 #set( ASDM_INCLUDE_DIR_OLD ${CASA_CODE_PATH}/alma/implement/ASDM
    127 #                          ${CASA_CODE_PATH}/alma/implement/Enumerations
    128 #                          ${CASA_CODE_PATH}/alma/implement/ASDMBinaries
    129 #                          ${CASA_CODE_PATH}/alma/implement/Enumtcl
    130 #                          ${LIBXML2_INCLUDE_DIR} )
    131 #set( ASDM_LIBRARY_OLD ${casaroot}/${arch}/lib/libalma${CMAKE_SHARED_LIBRARY_SUFFIX}
    132 #                      ${LIBXML2_LIBRARY}/libxml2${CMAKE_SHARED_LIBRARY_SUFFIX} )
    133 #set( ASDM_INCLUDE_DIR ${CASA_CODE_PATH}/alma_v3/implement/ASDM
    134 #                      ${CASA_CODE_PATH}/alma_v3/implement/Enumerations
    135 #                      ${CASA_CODE_PATH}/alma_v3/implement/ASDMBinaries
    136 #                      ${CASA_CODE_PATH}/alma_v3/implement/Enumtcl
    137 #                      ${LIBXML2_INCLUDE_DIR} )
    138 #set( ASDM_LIBRARY ${casaroot}/${arch}/lib/libalma_v3${CMAKE_SHARED_LIBRARY_SUFFIX}
    139 #                  ${LIBXML2_LIBRARY}/libxml2${CMAKE_SHARED_LIBRARY_SUFFIX} )
    140 set( ASDM_INCLUDE_DIR ${CASA_CODE_PATH}/alma/implement/ASDM
    141                       ${CASA_CODE_PATH}/alma/implement/Enumerations
    142                       ${CASA_CODE_PATH}/alma/implement/ASDMBinaries
    143                       ${CASA_CODE_PATH}/alma/implement/Enumtcl
     116set( ASDM_INCLUDE_DIR_OLD ${CASA_CODE_PATH}/alma/implement/ASDM
     117                          ${CASA_CODE_PATH}/alma/implement/Enumerations
     118                          ${CASA_CODE_PATH}/alma/implement/ASDMBinaries
     119                          ${CASA_CODE_PATH}/alma/implement/Enumtcl
     120                          ${LIBXML2_INCLUDE_DIR} )
     121set( ASDM_LIBRARY_OLD ${casaroot}/${arch}/lib/libalma${CMAKE_SHARED_LIBRARY_SUFFIX}
     122                      ${LIBXML2_LIBRARY}/libxml2${CMAKE_SHARED_LIBRARY_SUFFIX} )
     123set( ASDM_INCLUDE_DIR ${CASA_CODE_PATH}/alma_v3/implement/ASDM
     124                      ${CASA_CODE_PATH}/alma_v3/implement/Enumerations
     125                      ${CASA_CODE_PATH}/alma_v3/implement/ASDMBinaries
     126                      ${CASA_CODE_PATH}/alma_v3/implement/Enumtcl
    144127                      ${LIBXML2_INCLUDE_DIR} )
    145 set( ASDM_LIBRARY ${casaroot}/${arch}/lib/libalma${CMAKE_SHARED_LIBRARY_SUFFIX}
     128set( ASDM_LIBRARY ${casaroot}/${arch}/lib/libalma_v3${CMAKE_SHARED_LIBRARY_SUFFIX}
    146129                  ${LIBXML2_LIBRARY}/libxml2${CMAKE_SHARED_LIBRARY_SUFFIX} )
    147130add_definitions( -DWITHOUT_ACS )
     
    164147   add_subdirectory( share )
    165148   add_subdirectory( external-alma/asdm2ASAP )
    166 #   add_subdirectory( external-alma/oldasdm2ASAP )
     149   add_subdirectory( external-alma/oldasdm2ASAP )
    167150endmacro( asap_add_subdirectory )
    168151
  • /trunk/external-alma/asdm2ASAP/ASDMFiller.cc

    r2473 r2373  
    7676  Vector<casa::Double> antpos = table_->getHeader().antennaposition ;
    7777
     78  //STHeader hdr = table_->getHeader() ;
     79 
    7880  // data selection
    7981  reader_->select() ;
     
    101103
    102104  // CYCLENO
     105  //unsigned int cycleno = 0 ;
    103106  map< unsigned int, unsigned int > cycleno ;
    104107  map< unsigned int, unsigned int >::iterator citer ;
     
    108111      //logsink_->postLocally( LogMessage("start configDescId "+String::toString(configDescIdList[icon])+" fieldId "+String::toString(fieldIdList[ifield]),LogOrigin(className_,funcName,WHERE)) ) ;
    109112
     113      //Bool status = reader_->setMainRow( configDescIdList[icon], fieldIdList[ifield] ) ;
    110114      if ( !(reader_->setMainRow( configDescIdList[icon], fieldIdList[ifield] )) ) {
    111115        //logsink_->postLocally( LogMessage("skip configDescId "+String::toString(configDescIdList[icon])+" fieldId "+String::toString(fieldIdList[ifield]),LogOrigin(className_,funcName,WHERE)) ) ;
     
    128132
    129133        // scan and subscan
     134        //unsigned int scanno = reader_->getScanNo() ;
    130135        unsigned int scanno = reader_->getScanNoOfCurrentRow() ;
    131136        //logsink_->postLocally( LogMessage("scanno = "+String::toString(scanno),LogOrigin(className_,funcName,WHERE)) ) ;
     137        //uInt subscanno = reader_->getSubscanNo() ;
    132138        citer = cycleno.find( scanno ) ;
    133139        if ( citer == cycleno.end() )
     
    154160
    155161          // subscan number
     162          //unsigned int subscanno = reader_->getSubscanNo( idata ) ;
    156163          unsigned int subscanno = reader_->getSubscanNo() ;
    157164          //logsink_->postLocally( LogMessage("subscanno = "+String::toString(subscanno),LogOrigin(className_,funcName,WHERE)) ) ;
    158165
    159166          // IFNO
     167          //uInt ifno = reader_->getIFNo( idata ) ;
    160168          uInt ifno = reader_->getIFNo() ;
    161169          //logsink_->postLocally( LogMessage("ifno = "+String::toString(ifno),LogOrigin(className_,funcName,WHERE)) ) ;
     
    169177          double sysVel ;
    170178          vector<double> rf ;
     179          //reader_->getSourceProperty( idata,
     180          //                            srcname,
     181          //                            fieldname,
     182          //                            srcDirection,
     183          //                            srcProperMotion,
     184          //                            sysVel,
     185          //                            rf ) ;
    171186          reader_->getSourceProperty( srcname,
    172187                                      fieldname,
     
    184199         
    185200          // time and interval
     201          //casa::Double mjd = (casa::Double)(reader_->getTime( idata )) ;
     202          //casa::Double interval = (casa::Double)(reader_->getInterval( idata )) ;
    186203          casa::Double mjd = (casa::Double)(reader_->getTime()) ;
    187204          casa::Double interval = (casa::Double)(reader_->getInterval()) ;
     
    201218
    202219          // fill FLAGROW
     220          //unsigned int flagrow = reader_->getFlagRow( idata ) ;
    203221          unsigned int flagrow = reader_->getFlagRow() ;
    204222          setFlagrow( (uInt)flagrow ) ;
     
    210228          float windspeed ;
    211229          float windaz ;
     230          //reader_->getWeatherInfo( idata,
     231          //                         temperature,
     232          //                         pressure,
     233          //                         humidity,
     234          //                         windspeed,
     235          //                         windaz ) ;
    212236          reader_->getWeatherInfo( temperature,
    213237                                   pressure,
     
    226250          double el ;
    227251          vector<double> srate ;
     252          //reader_->getPointingInfo( idata,
     253          //                          dir,
     254          //                          az,
     255          //                          el,
     256          //                          srate ) ;
    228257          reader_->getPointingInfo( dir,
    229258                                    az,
     
    253282          }
    254283          else {
     284            //reader_->getFrequency( idata, refpix, refval, incr, freqref ) ;
    255285            reader_->getFrequency( refpix, refval, incr, freqref ) ;
    256286            refval = (double)toLSRK( casa::Double(refval),
     
    268298
    269299          // loop on polarization
     300          //vector<unsigned int> dataShape = reader_->getDataShape( idata ) ;
    270301          vector<unsigned int> dataShape = reader_->getDataShape() ;
    271302//           ostringstream oss ;
     
    280311//           logsink_->postLocally( LogMessage(oss.str(),LogOrigin(className_,funcName,WHERE)) ) ;
    281312                                     
     313          //int numPol = reader_->getNumPol( idata ) ;
    282314          unsigned int numPol = dataShape[0] ;
    283315          unsigned int numChan = dataShape[1] ;
     
    286318
    287319          // OPACITY
     320          //vector<float> tau = reader_->getOpacity( idata ) ;
    288321          vector<float> tau = reader_->getOpacity() ;
    289322          Vector<casa::Float> opacity = toVector( tau, numPol ) ;
    290323
    291324          // SPECTRA, FLAGTRA, TSYS, TCAL
     325          //float *sp = reader_->getSpectrum( idata ) ;
     326          //logsink_->postLocally( LogMessage("getting spectra...",LogOrigin(className_,funcName,WHERE)) ) ;
    292327          float *sp = reader_->getSpectrum() ;
    293328          //logsink_->postLocally( LogMessage("sp[0] = "+String::toString(sp[0]),LogOrigin(className_,funcName,WHERE)) ) ;
    294329          vector< vector<float> > ts ;
    295330          vector< vector<float> > tc ;
     331          //reader_->getTcalAndTsys( idata, tc, ts ) ;
    296332          reader_->getTcalAndTsys( tc, ts ) ;
    297333          Matrix<casa::Float> spectra = toMatrix( sp, numPol, numChan ) ;
  • /trunk/external-alma/asdm2ASAP/ASDMReader.cc

    r2473 r2373  
    12711271      CalAtmosphereRow *atmrow = atmrows[row0] ;
    12721272      tau = atmrow->getTau() ;
    1273     }
    1274     else {
    1275       tau.resize( 1 ) ;
    1276       tau[0] = 0.0 ;
    12771273    }
    12781274  }
  • /trunk/external-alma/atnf/PKSIO/ASTEDataset.cc

    r2473 r2373  
    529529    c18[16] = '\0' ;
    530530    RX[i] = string( c18 ) ;
    531   }
    532   // DEBUG
    533 //   nro_debug_output( "RX", ASTE_ARYMAX, RX ) ;
    534   //
     531    // DEBUG
     532//     if ( i == 0 ) {
     533//       cout << "RX      " ;
     534//     }
     535//     else if ( ( i % 5 ) == 0 ) {
     536//       cout << endl << "        " ;
     537//     }
     538//     cout << RX[i] << " " ;
     539    //
     540  }
     541  //cout << endl ;
    535542  for ( int i = 0 ; i < ASTE_ARYMAX ; i++ ) {
    536543    if ( readHeader( HPBW[i], sameEndian ) == -1 ) {
     
    538545      return -1 ;
    539546    }
    540   }
    541   // DEBUG
    542 //   nro_debug_output( "HPBW", ASTE_ARYMAX, HPBW ) ;
    543   //
     547    // DEBUG
     548//     if ( i == 0 ) {
     549//       cout << "HPBW    " ;
     550//     }
     551//     else if ( ( i % 5 ) == 0 ) {
     552//       cout << endl << "        " ;
     553//     }
     554//     cout << HPBW[i] << " " ;
     555    //
     556  }
     557  //cout << endl ;
    544558  for ( int i = 0 ; i < ASTE_ARYMAX ; i++ ) {
    545559    if ( readHeader( EFFA[i], sameEndian ) == -1 ) {
     
    547561      return -1 ;
    548562    }
    549   }
    550   // DEBUG
    551 //   nro_debug_output( "EFFA", ASTE_ARYMAX, EFFA ) ;
    552   //
     563    // DEBUG
     564//     if ( i == 0 ) {
     565//       cout << "EFFA    " ;
     566//     }
     567//     else if ( ( i % 5 ) == 0 ) {
     568//       cout << endl << "        " ;
     569//     }
     570//     cout << EFFA[i] << " " ;
     571    //
     572  }
     573  //cout << endl ;
    553574  for ( int i = 0 ; i < ASTE_ARYMAX ; i++ ) {
    554575    if ( readHeader( EFFB[i], sameEndian ) == -1 ) {
     
    556577      return -1 ;
    557578    }
    558   }
    559   // DEBUG
    560 //   nro_debug_output( "EFFB", ASTE_ARYMAX, EFFB ) ;
    561   //
     579    // DEBUG
     580//     if ( i == 0 ) {
     581//       cout << "EFFB    " ;
     582//     }
     583//     else if ( ( i % 5 ) == 0 ) {
     584//       cout << endl << "        " ;
     585//     }
     586//     cout << EFFB[i] << " " ;
     587    //
     588  }
     589  //cout << endl ;
    562590  for ( int i = 0 ; i < ASTE_ARYMAX ; i++ ) {
    563591    if ( readHeader( EFFL[i], sameEndian ) == -1 ) {
     
    565593      return -1 ;
    566594    }
    567   }
    568   // DEBUG
    569 //   nro_debug_output( "EFFL", ASTE_ARYMAX, EFFL ) ;
    570   //
     595    // DEBUG
     596//     if ( i == 0 ) {
     597//       cout << "EFFL    " ;
     598//     }
     599//     else if ( ( i % 5 ) == 0 ) {
     600//       cout << endl << "        " ;
     601//     }
     602//     cout << EFFL[i] << " " ;
     603    //
     604  }
     605  //cout << endl ;
    571606  for ( int i = 0 ; i < ASTE_ARYMAX ; i++ ) {
    572607    if ( readHeader( EFSS[i], sameEndian ) == -1 ) {
     
    574609      return -1 ;
    575610    }
    576   }
    577   // DEBUG
    578 //   nro_debug_output( "EFSS", ASTE_ARYMAX, EFSS ) ;
    579   //
     611    // DEBUG
     612//     if ( i == 0 ) {
     613//       cout << "EFSS    " ;
     614//     }
     615//     else if ( ( i % 5 ) == 0 ) {
     616//       cout << endl << "        " ;
     617//     }
     618//     cout << EFSS[i] << " " ;
     619    //
     620  }
     621  //cout << endl ;
    580622  for ( int i= 0 ; i < ASTE_ARYMAX ; i++) {
    581623    if ( readHeader( GAIN[i], sameEndian ) == -1 ) {
     
    583625      return -1 ;
    584626    }
    585   }
    586   // DEBUG
    587 //   nro_debug_output( "GAIN", ASTE_ARYMAX, GAIN ) ;
    588   //
     627    // DEBUG
     628//     if ( i == 0 ) {
     629//       cout << "GAIN    " ;
     630//     }
     631//     else if ( ( i % 5 ) == 0 ) {
     632//       cout << endl << "        " ;
     633//     }
     634//     cout << GAIN[i] << " " ;
     635    //
     636  }
     637  //cout << endl ;
    589638  for ( int i= 0 ; i < ASTE_ARYMAX ; i++) {
    590639    strcpy( c4, str4.c_str() ) ;
     
    594643    }
    595644    HORN[i] = string( c4 ) ;
    596   }
    597   // DEBUG
    598 //   nro_debug_output( "HORN", ASTE_ARYMAX, HORN ) ;
    599   //
     645    // DEBUG
     646//     if ( i == 0 ) {
     647//       cout << "HORN    " ;
     648//     }
     649//     else if ( ( i % 5 ) == 0 ) {
     650//       cout << endl << "        " ;
     651//     }
     652//     cout << HORN[i] << " " ;
     653    //
     654  }
     655  //cout << endl ;
    600656  for ( int i= 0 ; i < ASTE_ARYMAX ; i++) {
    601657    strcpy( c4, str4.c_str() ) ;
     
    605661    }
    606662    POLTP[i] = string( c4 ) ;
    607   }
    608   // DEBUG
    609 //   nro_debug_output( "POLTP", ASTE_ARYMAX, POLTP ) ;
    610   //
     663    // DEBUG
     664//     if ( i == 0 ) {
     665//       cout << "POLTP   " ;
     666//     }
     667//     else if ( ( i % 5 ) == 0 ) {
     668//       cout << endl << "        " ;
     669//     }
     670//     cout << POLTP[i] << " " ;
     671    //
     672  }
     673  //cout << endl ;
    611674  for ( int i= 0 ; i < ASTE_ARYMAX ; i++) {
    612675    if ( readHeader( POLDR[i], sameEndian ) == -1 ) {
     
    614677      return -1 ;
    615678    }
    616   }
    617   // DEBUG
    618 //   nro_debug_output( "POLDR", ASTE_ARYMAX, POLDR ) ;
    619   //
     679     // DEBUG
     680//     if ( i == 0 ) {
     681//       cout << "POLDR   " ;
     682//     }
     683//     else if ( ( i % 5 ) == 0 ) {
     684//       cout << endl << "        " ;
     685//     }
     686//     cout << POLDR[i] << " " ;
     687    //
     688  }
     689  //cout << endl ;
    620690  for ( int i= 0 ; i < ASTE_ARYMAX ; i++) {
    621691    if ( readHeader( POLAN[i], sameEndian ) == -1 ) {
     
    623693      return -1 ;
    624694    }
    625   }
    626   // DEBUG
    627 //   nro_debug_output( "POLAN", ASTE_ARYMAX, POLAN ) ;
    628   //
     695    // DEBUG
     696//     if ( i == 0 ) {
     697//       cout << "POLAN   " ;
     698//     }
     699//     else if ( ( i % 5 ) == 0 ) {
     700//       cout << endl << "        " ;
     701//     }
     702//     cout << POLAN[i] << " " ;
     703    //
     704  }
     705  //cout << endl ;
    629706  for ( int i= 0 ; i < ASTE_ARYMAX ; i++) {
    630707    if ( readHeader( DFRQ[i], sameEndian ) == -1 ) {
     
    632709      return -1 ;
    633710    }
    634   }
    635   // DEBUG
    636 //   nro_debug_output( "DFRQ", ASTE_ARYMAX, DFRQ ) ;
    637   //
     711    // DEBUG
     712//     if ( i == 0 ) {
     713//       cout << "DFRQ    " ;
     714//     }
     715//     else if ( ( i % 5 ) == 0 ) {
     716//       cout << endl << "        " ;
     717//     }
     718//     cout << DFRQ[i] << " " ;
     719    //
     720  }
     721  //cout << endl ;
    638722  for ( int i= 0 ; i < ASTE_ARYMAX ; i++) {
    639723    strcpy( c4, str4.c_str() ) ;
     
    643727    }
    644728    SIDBD[i] = string( c4 ) ;
    645   }
    646   // DEBUG
    647 //   nro_debug_output( "SIDBD", ASTE_ARYMAX, SIDBD ) ;
    648   //
     729    // DEBUG
     730//     if ( i == 0 ) {
     731//       cout << "SIDBD   " ;
     732//     }
     733//     else if ( ( i % 5 ) == 0 ) {
     734//       cout << endl << "        " ;
     735//     }
     736//     cout << SIDBD[i] << " " ;
     737    //
     738  }
     739  //cout << endl ;
    649740  for ( int i= 0 ; i < ASTE_ARYMAX ; i++) {
    650741    if ( readHeader( REFN[i], sameEndian ) == -1 ) {
     
    652743      return -1 ;
    653744    }
    654   }
    655   // DEBUG
    656 //   nro_debug_output( "REFN", ASTE_ARYMAX, REFN ) ;
    657   //
     745    // DEBUG
     746//     if ( i == 0 ) {
     747//       cout << "REFN    " ;
     748//     }
     749//     else if ( ( i % 5 ) == 0 ) {
     750//       cout << endl << "        " ;
     751//     }
     752//     cout << REFN[i] << " " ;
     753    //
     754  }
     755  //cout << endl ;
    658756  for ( int i= 0 ; i < ASTE_ARYMAX ; i++) {
    659757    if ( readHeader( IPINT[i], sameEndian ) == -1 ) {
     
    661759      return -1 ;
    662760    }
    663   }
    664   // DEBUG
    665 //   nro_debug_output( "IPINT", ASTE_ARYMAX, IPINT ) ;
    666   //
     761    // DEBUG
     762//     if ( i == 0 ) {
     763//       cout << "IPINT   " ;
     764//     }
     765//     else if ( ( i % 5 ) == 0 ) {
     766//       cout << endl << "        " ;
     767//     }
     768//     cout << IPINT[i] << " " ;
     769    //
     770  }
     771  //cout << endl ;
    667772  for ( int i= 0 ; i < ASTE_ARYMAX ; i++) {
    668773    if ( readHeader( MULTN[i], sameEndian ) == -1 ) {
     
    670775      return -1 ;
    671776    }
    672   }
    673   // DEBUG
    674 //   nro_debug_output( "MULTN", ASTE_ARYMAX, MULTN ) ;
    675   //
     777    // DEBUG
     778//     if ( i == 0 ) {
     779//       cout << "MULTN   " ;
     780//     }
     781//     else if ( ( i % 5 ) == 0 ) {
     782//       cout << endl << "        " ;
     783//     }
     784//     cout << MULTN[i] << " " ;
     785    //
     786  }
     787  //cout << endl ;
    676788  for ( int i= 0 ; i < ASTE_ARYMAX ; i++) {
    677789    if ( readHeader( MLTSCF[i], sameEndian ) == -1 ) {
     
    679791      return -1 ;
    680792    }
    681   }
    682   // DEBUG
    683 //   nro_debug_output( "MLTSCF", ASTE_ARYMAX, MLTSCF ) ;
    684   //
     793    // DEBUG
     794//     if ( i == 0 ) {
     795//       cout << "MLTSCF  " ;
     796//     }
     797//     else if ( ( i % 5 ) == 0 ) {
     798//       cout << endl << "        " ;
     799//     }
     800//     cout << MLTSCF[i] << " " ;
     801    //
     802  }
     803  //cout << endl ;
    685804  for ( int i= 0 ; i < ASTE_ARYMAX ; i++) {
    686805    strcpy( c8, str8.c_str() ) ;
     
    690809    }
    691810    LAGWIND[i] = string( c8 ) ;
    692   }
    693   // DEBUG
    694 //   nro_debug_output( "LAGWIND", ASTE_ARYMAX, LAGWIND ) ;
    695   //
     811    // DEBUG
     812//     if ( i == 0 ) {
     813//       cout << "LAGWIND " ;
     814//     }
     815//     else if ( ( i % 5 ) == 0 ) {
     816//       cout << endl << "        " ;
     817//     }
     818//     cout << LAGWIND[i] << " " ;
     819    //
     820  }
     821  //cout << endl ;
    696822  for ( int i= 0 ; i < ASTE_ARYMAX ; i++) {
    697823    if ( readHeader( BEBW[i], sameEndian ) == -1 ) {
     
    699825      return -1 ;
    700826    }
    701   }
    702   // DEBUG
    703 //   nro_debug_output( "BEBW", ASTE_ARYMAX, BEBW ) ;
    704   //
     827    // DEBUG
     828//     if ( i == 0 ) {
     829//       cout << "BEBW    " ;
     830//     }
     831//     else if ( ( i % 5 ) == 0 ) {
     832//       cout << endl << "        " ;
     833//     }
     834//     cout << BEBW[i] << " " ;
     835    //
     836  }
     837  //cout << endl ;
    705838  for ( int i= 0 ; i < ASTE_ARYMAX ; i++) {
    706839    if ( readHeader( BERES[i], sameEndian ) == -1 ) {
     
    708841      return -1 ;
    709842    }
    710   }
    711   // DEBUG
    712 //   nro_debug_output( "BERES", ASTE_ARYMAX, BERES ) ;
    713   //
     843    // DEBUG
     844//     if ( i == 0 ) {
     845//       cout << "BERES   " ;
     846//     }
     847//     else if ( ( i % 5 ) == 0 ) {
     848//       cout << endl << "        " ;
     849//     }
     850//     cout << BERES[i] << " " ;
     851    //
     852  }
     853  //cout << endl ;
    714854  for ( int i= 0 ; i < ASTE_ARYMAX ; i++) {
    715855    if ( readHeader( CHWID[i], sameEndian ) == -1 ) {
     
    717857      return -1 ;
    718858    }
    719   }
    720   // DEBUG
    721 //   nro_debug_output( "CHWID", ASTE_ARYMAX, CHWID ) ;
    722   //
     859    // DEBUG
     860//     if ( i == 0 ) {
     861//       cout << "CHWID   " ;
     862//     }
     863//     else if ( ( i % 5 ) == 0 ) {
     864//       cout << endl << "        " ;
     865//     }
     866//     cout << CHWID[i] << " " ;
     867    //
     868  }
     869  //cout << endl ;
    723870  for ( int i= 0 ; i < ASTE_ARYMAX ; i++) {
    724871    if ( readHeader( ARRY[i], sameEndian ) == -1 ) {
     
    726873      return -1 ;
    727874    }
    728   }
    729   // DEBUG
    730 //   nro_debug_output( "ARRY", ASTE_ARYMAX, ARRY ) ;
    731   //
     875    // DEBUG
     876//     if ( i == 0 ) {
     877//       cout << "ARRY    " ;
     878//     }
     879//     else if ( ( i % 5 ) == 0 ) {
     880//       cout << endl << "        " ;
     881//     }
     882//     cout << ARRY[i] << " " ;
     883    //
     884  }
     885  //cout << endl ;
    732886  for ( int i= 0 ; i < ASTE_ARYMAX ; i++) {
    733887    if ( readHeader( NFCAL[i], sameEndian ) == -1 ) {
     
    735889      return -1 ;
    736890    }
    737   }
    738   // DEBUG
    739 //   nro_debug_output( "NFCAL", ASTE_ARYMAX, NFCAL ) ;
    740   //
     891    // DEBUG
     892//     if ( i == 0 ) {
     893//       cout << "NFCAL   " ;
     894//     }
     895//     else if ( ( i % 5 ) == 0 ) {
     896//       cout << endl << "        " ;
     897//     }
     898//     cout << NFCAL[i] << " " ;
     899    //
     900  }
     901  //cout << endl ;
    741902  for ( int i= 0 ; i < ASTE_ARYMAX ; i++) {
    742903    if ( readHeader( F0CAL[i], sameEndian ) == -1 ) {
     
    744905      return -1 ;
    745906    }
    746   }
    747   // DEBUG
    748 //   nro_debug_output( "F0CAL", ASTE_ARYMAX, F0CAL ) ;
    749   //
     907    // DEBUG
     908//     if ( i == 0 ) {
     909//       cout << "F0CAL   " ;
     910//     }
     911//     else if ( ( i % 5 ) == 0 ) {
     912//       cout << endl << "        " ;
     913//     }
     914//     cout << F0CAL[i] << " " ;
     915    //
     916  }
     917  //cout << endl ;
    750918  for ( int i= 0 ; i < ASTE_ARYMAX ; i++) {
    751919    for ( int j = 0 ; j < 10 ; j++ ) {
     
    754922        return -1 ;
    755923      }
    756     }
    757   }
    758   // DEBUG
    759 //   nro_debug_output( "FQCAL", ASTE_ARYMAX, 10,  FQCAL ) ;
    760   //
     924      // DEBUG
     925//       if ( j == 0 ) {
     926//         if ( i < 10 )
     927//           cout << "FQCAL0" << i << " " ;
     928//         else
     929//           cout << "FQCAL" << i << " " ;
     930//       }
     931//       else if ( ( j % 5 ) == 0 ) {
     932//         cout << endl << "        " ;
     933//       }
     934//       cout << FQCAL[i][j] << " " ;
     935      //
     936    }
     937    //cout << endl ;
     938  }
    761939  for ( int i= 0 ; i < ASTE_ARYMAX ; i++) {
    762940    for ( int j = 0 ; j < 10 ; j++ ) {
     
    765943        return -1 ;
    766944      }
    767     }
    768   }
    769   // DEBUG
    770 //   nro_debug_output( "CHCAL", ASTE_ARYMAX, 10, CHCAL ) ;
    771   //
     945     // DEBUG
     946//       if ( j == 0 ) {
     947//         if ( i < 10 )
     948//           cout << "CHCAL0" << i << " " ;
     949//         else
     950//           cout << "CHCAL" << i << " " ;
     951//       }
     952//       else if ( ( j % 5 ) == 0 ) {
     953//         cout << endl << "        " ;
     954//       }
     955//       cout << CHCAL[i][j] << " " ;
     956     //
     957    }
     958    //cout << endl ;
     959  }
    772960  for ( int i= 0 ; i < ASTE_ARYMAX ; i++) {
    773961    for ( int j = 0 ; j < 10 ; j++ ) {
     
    776964        return -1 ;
    777965      }
    778     }
    779   }
    780   // DEBUG
    781 //   nro_debug_output( "CWCAL", ASTE_ARYMAX, 10, CWCAL ) ;
    782   //
     966      // DEBUG
     967//       if ( j == 0 ) {
     968//         if ( i < 10 )
     969//           cout << "CWCAL0" << i << " " ;
     970//         else
     971//           cout << "CWCAL" << i << " " ;
     972//       }
     973//       else if ( ( j % 5 ) == 0 ) {
     974//         cout << endl << "        " ;
     975//       }
     976//       cout << CWCAL[i][j] << " " ;
     977      //
     978    }
     979    //cout << endl ;
     980  }
    783981  if ( readHeader( SCNLEN, sameEndian ) == -1 ) {
    784982    os << LogIO::WARN << "Error while reading data SCNLEN." << LogIO::POST ;
     
    8261024      return -1 ;
    8271025    }
    828   }
    829   // DEBUG
    830 //   nro_debug_output( "DSBFC", ASTE_ARYMAX, DSBFC ) ;
    831   //
    832 
     1026    // DEBUG
     1027//     if ( i == 0 ) {
     1028//       cout << "DSBFC   " ;
     1029//     }
     1030//     else if ( ( i % 5 ) == 0 ) {
     1031//       cout << endl << "        " ;
     1032//     }
     1033//     cout << DSBFC[i] << " " ;
     1034    //
     1035  }
     1036  //cout << endl ;
    8331037
    8341038  scanNum_ = NSCAN + 1 ; // includes ZERO scan
  • /trunk/external-alma/atnf/PKSIO/ASTEFXDataset.cc

    r2473 r2373  
    529529    c18[16] = '\0' ;
    530530    RX[i] = string( c18 ) ;
    531   }
    532   // DEBUG
    533 //   nro_debug_output( "RX", ASTE_ARYMAX_FX, RX ) ;
    534   //
     531    // DEBUG
     532//     if ( i == 0 ) {
     533//       cout << "RX      " ;
     534//     }
     535//     else if ( ( i % 5 ) == 0 ) {
     536//       cout << endl << "        " ;
     537//     }
     538//     cout << RX[i] << " " ;
     539    //
     540  }
     541  //cout << endl ;
    535542  for ( int i = 0 ; i < ASTE_ARYMAX_FX ; i++ ) {
    536543    if ( readHeader( HPBW[i], sameEndian ) == -1 ) {
     
    538545      return -1 ;
    539546    }
    540   }
    541   // DEBUG
    542 //   nro_debug_output( "HPBW", ASTE_ARYMAX_FX, HPBW ) ;
    543   //
     547//     // DEBUG
     548//     if ( i == 0 ) {
     549//       cout << "HPBW    " ;
     550//     }
     551//     else if ( ( i % 5 ) == 0 ) {
     552//       cout << endl <    //cerr << "Error opening file " << filename_ << "." << endl ;< "        " ;
     553//     }
     554//     cout << HPBW[i] << " " ;
     555    //
     556  }
     557  //cout << endl ;
    544558  for ( int i = 0 ; i < ASTE_ARYMAX_FX ; i++ ) {
    545559    if ( readHeader( EFFA[i], sameEndian ) == -1 ) {
     
    547561      return -1 ;
    548562    }
    549   }
    550   // DEBUG
    551 //   nro_debug_output( "EFFA", ASTE_ARYMAX_FX, EFFA ) ;
    552   //
     563    // DEBUG
     564//     if ( i == 0 ) {
     565//       cout << "EFFA    " ;
     566//     }
     567//     else if ( ( i % 5 ) == 0 ) {
     568//       cout << endl << "        " ;
     569//     }
     570//     cout << EFFA[i] << " " ;
     571    //
     572  }
     573  //cout << endl ;
    553574  for ( int i = 0 ; i < ASTE_ARYMAX_FX ; i++ ) {
    554575    if ( readHeader( EFFB[i], sameEndian ) == -1 ) {
     
    556577      return -1 ;
    557578    }
    558   }
    559   // DEBUG
    560 //   nro_debug_output( "EFFB", ASTE_ARYMAX_FX, EFFB ) ;
    561   //
     579    // DEBUG
     580//     if ( i == 0 ) {
     581//       cout << "EFFB    " ;
     582//     }
     583//     else if ( ( i % 5 ) == 0 ) {
     584//       cout << endl << "        " ;
     585//     }
     586//     cout << EFFB[i] << " " ;
     587    //
     588  }
     589  //cout << endl ;
    562590  for ( int i = 0 ; i < ASTE_ARYMAX_FX ; i++ ) {
    563591    if ( readHeader( EFFL[i], sameEndian ) == -1 ) {
     
    565593      return -1 ;
    566594    }
    567   }
    568   // DEBUG
    569 //   nro_debug_output( "EFFL", ASTE_ARYMAX_FX, EFFL ) ;
    570   //
     595    // DEBUG
     596//     if ( i == 0 ) {
     597//       cout << "EFFL    " ;
     598//     }
     599//     else if ( ( i % 5 ) == 0 ) {
     600//       cout << endl << "        " ;
     601//     }
     602//     cout << EFFL[i] << " " ;
     603    //
     604  }
     605  //cout << endl ;
    571606  for ( int i = 0 ; i < ASTE_ARYMAX_FX ; i++ ) {
    572607    if ( readHeader( EFSS[i], sameEndian ) == -1 ) {
     
    574609      return -1 ;
    575610    }
    576   }
    577   // DEBUG
    578 //   nro_debug_output( "EFSS", ASTE_ARYMAX_FX, EFSS ) ;
    579   //
     611    // DEBUG
     612//     if ( i == 0 ) {
     613//       cout << "EFSS    " ;
     614//     }
     615//     else if ( ( i % 5 ) == 0 ) {
     616//       cout << endl << "        " ;
     617//     }
     618//     cout << EFSS[i] << " " ;
     619    //
     620  }
     621  //cout << endl ;
    580622  for ( int i= 0 ; i < ASTE_ARYMAX_FX ; i++) {
    581623    if ( readHeader( GAIN[i], sameEndian ) == -1 ) {
     
    583625      return -1 ;
    584626    }
    585   }
    586   // DEBUG
    587 //   nro_debug_output( "GAIN", ASTE_ARYMAX_FX, GAIN ) ;
    588   //
     627    // DEBUG
     628//     if ( i == 0 ) {
     629//       cout << "GAIN    " ;
     630//     }
     631//     else if ( ( i % 5 ) == 0 ) {
     632//       cout << endl << "        " ;
     633//     }
     634//     cout << GAIN[i] << " " ;
     635    //
     636  }
     637  //cout << endl ;
    589638  for ( int i= 0 ; i < ASTE_ARYMAX_FX ; i++) {
    590639    strcpy( c4, str4.c_str() ) ;
     
    594643    }
    595644    HORN[i] = string( c4 ) ;
    596   }
    597   // DEBUG
    598 //   nro_debug_output( "HORN", ASTE_ARYMAX_FX, HORN ) ;
    599   //
     645    // DEBUG
     646//     if ( i == 0 ) {
     647//       cout << "HORN    " ;
     648//     }
     649//     else if ( ( i % 5 ) == 0 ) {
     650//       cout << endl << "        " ;
     651//     }
     652//     cout << HORN[i] << " " ;
     653    //
     654  }
     655  //cout << endl ;
    600656  for ( int i= 0 ; i < ASTE_ARYMAX_FX ; i++) {
    601657    strcpy( c4, str4.c_str() ) ;
     
    605661    }
    606662    POLTP[i] = string( c4 ) ;
    607   }
    608   // DEBUG
    609 //   nro_debug_output( "POLTP", ASTE_ARYMAX_FX, POLTP ) ;
    610   //
     663    // DEBUG
     664//     if ( i == 0 ) {
     665//       cout << "POLTP   " ;
     666//     }
     667//     else if ( ( i % 5 ) == 0 ) {
     668//       cout << endl << "        " ;
     669//     }
     670//     cout << POLTP[i] << " " ;
     671    //
     672  }
     673  //cout << endl ;
    611674  for ( int i= 0 ; i < ASTE_ARYMAX_FX ; i++) {
    612675    if ( readHeader( POLDR[i], sameEndian ) == -1 ) {
     
    614677      return -1 ;
    615678    }
    616   }
    617   // DEBUG
    618 //   nro_debug_output( "POLDR", ASTE_ARYMAX_FX, POLDR ) ;
    619   //
     679     // DEBUG
     680//     if ( i == 0 ) {
     681//       cout << "POLDR   " ;
     682//     }
     683//     else if ( ( i % 5 ) == 0 ) {
     684//       cout << endl << "        " ;
     685//     }
     686//     cout << POLDR[i] << " " ;
     687    //
     688  }
     689  //cout << endl ;
    620690  for ( int i= 0 ; i < ASTE_ARYMAX_FX ; i++) {
    621691    if ( readHeader( POLAN[i], sameEndian ) == -1 ) {
     
    623693      return -1 ;
    624694    }
    625   }
    626   // DEBUG
    627 //   nro_debug_output( "POLAN", ASTE_ARYMAX_FX, POLAN ) ;
    628   //
     695    // DEBUG
     696//     if ( i == 0 ) {
     697//       cout << "POLAN   " ;
     698//     }
     699//     else if ( ( i % 5 ) == 0 ) {
     700//       cout << endl << "        " ;
     701//     }
     702//     cout << POLAN[i] << " " ;
     703    //
     704  }
     705  //cout << endl ;
    629706  for ( int i= 0 ; i < ASTE_ARYMAX_FX ; i++) {
    630707    if ( readHeader( DFRQ[i], sameEndian ) == -1 ) {
     
    632709      return -1 ;
    633710    }
    634   }
    635   // DEBUG
    636 //   nro_debug_output( "DFRQ", ASTE_ARYMAX_FX, DFRQ ) ;
    637   //
     711    // DEBUG
     712//     if ( i == 0 ) {
     713//       cout << "DFRQ    " ;
     714//     }
     715//     else if ( ( i % 5 ) == 0 ) {
     716//       cout << endl << "        " ;
     717//     }
     718//     cout << DFRQ[i] << " " ;
     719    //
     720  }
     721  //cout << endl ;
    638722  for ( int i= 0 ; i < ASTE_ARYMAX_FX ; i++) {
    639723    strcpy( c4, str4.c_str() ) ;
     
    643727    }
    644728    SIDBD[i] = string( c4 ) ;
    645   }
    646   // DEBUG
    647 //   nro_debug_output( "SIDBD", ASTE_ARYMAX_FX, SIDBD ) ;
    648   //
     729    // DEBUG
     730//     if ( i == 0 ) {
     731//       cout << "SIDBD   " ;
     732//     }
     733//     else if ( ( i % 5 ) == 0 ) {
     734//       cout << endl << "        " ;
     735//     }
     736//     cout << SIDBD[i] << " " ;
     737    //
     738  }
     739  //cout << endl ;
    649740  for ( int i= 0 ; i < ASTE_ARYMAX_FX ; i++) {
    650741    if ( readHeader( REFN[i], sameEndian ) == -1 ) {
     
    652743      return -1 ;
    653744    }
    654   }
    655   // DEBUG
    656 //   nro_debug_output( "REFN", ASTE_ARYMAX_FX, REFN ) ;
    657   //
     745    // DEBUG
     746//     if ( i == 0 ) {
     747//       cout << "REFN    " ;
     748//     }
     749//     else if ( ( i % 5 ) == 0 ) {
     750//       cout << endl << "        " ;
     751//     }
     752//     cout << REFN[i] << " " ;
     753    //
     754  }
     755  //cout << endl ;
    658756  for ( int i= 0 ; i < ASTE_ARYMAX_FX ; i++) {
    659757    if ( readHeader( IPINT[i], sameEndian ) == -1 ) {
     
    661759      return -1 ;
    662760    }
    663   }
    664   // DEBUG
    665 //   nro_debug_output( "IPINT", ASTE_ARYMAX_FX, IPINT ) ;
    666   //
     761    // DEBUG
     762//     if ( i == 0 ) {
     763//       cout << "IPINT   " ;
     764//     }
     765//     else if ( ( i % 5 ) == 0 ) {
     766//       cout << endl << "        " ;
     767//     }
     768//     cout << IPINT[i] << " " ;
     769    //
     770  }
     771  //cout << endl ;
    667772  for ( int i= 0 ; i < ASTE_ARYMAX_FX ; i++) {
    668773    if ( readHeader( MULTN[i], sameEndian ) == -1 ) {
     
    670775      return -1 ;
    671776    }
    672   }
    673   // DEBUG
    674 //   nro_debug_output( "MULTN", ASTE_ARYMAX_FX, MULTN ) ;
    675   //
     777    // DEBUG
     778//     if ( i == 0 ) {
     779//       cout << "MULTN   " ;
     780//     }
     781//     else if ( ( i % 5 ) == 0 ) {
     782//       cout << endl << "        " ;
     783//     }
     784//     cout << MULTN[i] << " " ;
     785    //
     786  }
     787  //cout << endl ;
    676788  for ( int i= 0 ; i < ASTE_ARYMAX_FX ; i++) {
    677789    if ( readHeader( MLTSCF[i], sameEndian ) == -1 ) {
     
    679791      return -1 ;
    680792    }
    681   }
    682   // DEBUG
    683 //   nro_debug_output( "MLTSCF", ASTE_ARYMAX_FX, MLTSCF ) ;
    684   //
     793    // DEBUG
     794//     if ( i == 0 ) {
     795//       cout << "MLTSCF  " ;
     796//     }
     797//     else if ( ( i % 5 ) == 0 ) {
     798//       cout << endl << "        " ;
     799//     }
     800//     cout << MLTSCF[i] << " " ;
     801    //
     802  }
     803  //cout << endl ;
    685804  for ( int i= 0 ; i < ASTE_ARYMAX_FX ; i++) {
    686805    strcpy( c8, str8.c_str() ) ;
     
    690809    }
    691810    LAGWIND[i] = string( c8 ) ;
    692   }
    693   // DEBUG
    694 //   nro_debug_output( "LAGWIND", ASTE_ARYMAX_FX, LAGWIND ) ;
    695   //
     811    // DEBUG
     812//     if ( i == 0 ) {
     813//       cout << "LAGWIND " ;
     814//     }
     815//     else if ( ( i % 5 ) == 0 ) {
     816//       cout << endl << "        " ;
     817//     }
     818//     cout << LAGWIND[i] << " " ;
     819    //
     820  }
     821  //cout << endl ;
    696822  for ( int i= 0 ; i < ASTE_ARYMAX_FX ; i++) {
    697823    if ( readHeader( BEBW[i], sameEndian ) == -1 ) {
     
    699825      return -1 ;
    700826    }
    701   }
    702   // DEBUG
    703 //   nro_debug_output( "BEBW", ASTE_ARYMAX_FX, BEBW ) ;
    704   //
     827    // DEBUG
     828//     if ( i == 0 ) {
     829//       cout << "BEBW    " ;
     830//     }
     831//     else if ( ( i % 5 ) == 0 ) {
     832//       cout << endl << "        " ;
     833//     }
     834//     cout << BEBW[i] << " " ;
     835    //
     836  }
     837  //cout << endl ;
    705838  for ( int i= 0 ; i < ASTE_ARYMAX_FX ; i++) {
    706839    if ( readHeader( BERES[i], sameEndian ) == -1 ) {
     
    708841      return -1 ;
    709842    }
    710   }
    711   // DEBUG
    712 //   nro_debug_output( "BERES", ASTE_ARYMAX_FX, BERES ) ;
    713   //
     843    // DEBUG
     844//     if ( i == 0 ) {
     845//       cout << "BERES   " ;
     846//     }
     847//     else if ( ( i % 5 ) == 0 ) {
     848//       cout << endl << "        " ;
     849//     }
     850//     cout << BERES[i] << " " ;
     851    //
     852  }
     853  //cout << endl ;
    714854  for ( int i= 0 ; i < ASTE_ARYMAX_FX ; i++) {
    715855    if ( readHeader( CHWID[i], sameEndian ) == -1 ) {
     
    717857      return -1 ;
    718858    }
    719   }
    720   // DEBUG
    721 //   nro_debug_output( "CHWID", ASTE_ARYMAX_FX, CHWID ) ;
    722   //
     859    // DEBUG
     860//     if ( i == 0 ) {
     861//       cout << "CHWID   " ;
     862//     }
     863//     else if ( ( i % 5 ) == 0 ) {
     864//       cout << endl << "        " ;
     865//     }
     866//     cout << CHWID[i] << " " ;
     867    //
     868  }
     869  //cout << endl ;
    723870  for ( int i= 0 ; i < ASTE_ARYMAX_FX ; i++) {
    724871    if ( readHeader( ARRY[i], sameEndian ) == -1 ) {
     
    726873      return -1 ;
    727874    }
    728   }
    729   // DEBUG
    730 //   nro_debug_output( "ARRY", ASTE_ARYMAX_FX, ARRY ) ;
    731   //
     875    // DEBUG
     876//     if ( i == 0 ) {
     877//       cout << "ARRY    " ;
     878//     }
     879//     else if ( ( i % 5 ) == 0 ) {
     880//       cout << endl << "        " ;
     881//     }
     882//     cout << ARRY[i] << " " ;
     883    //
     884  }
     885  //cout << endl ;
    732886  for ( int i= 0 ; i < ASTE_ARYMAX_FX ; i++) {
    733887    if ( readHeader( NFCAL[i], sameEndian ) == -1 ) {
     
    735889      return -1 ;
    736890    }
    737   }
    738   // DEBUG
    739 //   nro_debug_output( "NFCAL", ASTE_ARYMAX_FX, NFCAL ) ;
    740   //
     891    // DEBUG
     892//     if ( i == 0 ) {
     893//       cout << "NFCAL   " ;
     894//     }
     895//     else if ( ( i % 5 ) == 0 ) {
     896//       cout << endl << "        " ;
     897//     }
     898//     cout << NFCAL[i] << " " ;
     899    //
     900  }
     901  //cout << endl ;
    741902  for ( int i= 0 ; i < ASTE_ARYMAX_FX ; i++) {
    742903    if ( readHeader( F0CAL[i], sameEndian ) == -1 ) {
     
    744905      return -1 ;
    745906    }
    746   }
    747   // DEBUG
    748 //   nro_debug_output( "F0CAL", ASTE_ARYMAX_FX, F0CAL ) ;
    749   //
     907    // DEBUG
     908//     if ( i == 0 ) {
     909//       cout << "F0CAL   " ;
     910//     }
     911//     else if ( ( i % 5 ) == 0 ) {
     912//       cout << endl << "        " ;
     913//     }
     914//     cout << F0CAL[i] << " " ;
     915    //
     916  }
     917  //cout << endl ;
    750918  for ( int i= 0 ; i < ASTE_ARYMAX_FX ; i++) {
    751919    for ( int j = 0 ; j < 10 ; j++ ) {
     
    754922        return -1 ;
    755923      }
    756     }
    757   }
    758   // DEBUG
    759 //   nro_debug_output( "FQCAL", ASTE_ARYMAX_FX, 10, FQCAL ) ;
    760   //
     924      // DEBUG
     925//       if ( j == 0 ) {
     926//         if ( i < 10 )
     927//           cout << "FQCAL0" << i << " " ;
     928//         else
     929//           cout << "FQCAL" << i << " " ;
     930//       }
     931//       else if ( ( j % 5 ) == 0 ) {
     932//         cout << endl << "        " ;
     933//       }
     934//       cout << FQCAL[i][j] << " " ;
     935      //
     936    }
     937    //cout << endl ;
     938  }
    761939  for ( int i= 0 ; i < ASTE_ARYMAX_FX ; i++) {
    762940    for ( int j = 0 ; j < 10 ; j++ ) {
     
    765943        return -1 ;
    766944      }
    767     }
    768   }
    769   // DEBUG
    770 //   nro_debug_output( "CHCAL", ASTE_ARYMAX_FX, 10, CHCAL ) ;
    771   //
     945     // DEBUG
     946//       if ( j == 0 ) {
     947//         if ( i < 10 )
     948//           cout << "CHCAL0" << i << " " ;
     949//         else
     950//           cout << "CHCAL" << i << " " ;
     951//       }
     952//       else if ( ( j % 5 ) == 0 ) {
     953//         cout << endl << "        " ;
     954//       }
     955//      cout << CHCAL[i][j] << " " ;
     956     //
     957    }
     958    //cout << endl ;
     959  }
    772960  for ( int i= 0 ; i < ASTE_ARYMAX_FX ; i++) {
    773961    for ( int j = 0 ; j < 10 ; j++ ) {
     
    776964        return -1 ;
    777965      }
    778     }
    779   }
    780   // DEBUG
    781 //   nro_debug_output( "CWCAL", ASTE_ARYMAX_FX, 10, CWCAL ) ;
    782   //
     966      // DEBUG
     967//       if ( j == 0 ) {
     968//         if ( i < 10 )
     969//           cout << "CWCAL0" << i << " " ;
     970//         else
     971//           cout << "CWCAL" << i << " " ;
     972//       }
     973//       else if ( ( j % 5 ) == 0 ) {
     974//         cout << endl << "        " ;
     975//       }
     976//       cout << CWCAL[i][j] << " " ;
     977      //
     978    }
     979    //cout << endl ;
     980  }
    783981  if ( readHeader( SCNLEN, sameEndian ) == -1 ) {
    784982    os << LogIO::WARN << "Error while reading data SCNLEN." << endl ;
     
    8261024      return -1 ;
    8271025    }
    828   }
    829   // DEBUG
    830 //   nro_debug_output( "DSBFC", ASTE_ARYMAX_FX, DSBFC ) ;
    831   //
     1026     // DEBUG
     1027//     if ( i == 0 ) {
     1028//       cout << "DSBFC   " ;
     1029//     }
     1030//     else if ( ( i % 5 ) == 0 ) {
     1031//       cout << endl << "        " ;
     1032//     }
     1033//     cout << DSBFC[i] << " " ;
     1034    //
     1035  }
     1036  //cout << endl ;
    8321037
    8331038  scanNum_ = NSCAN + 1 ; // includes ZERO scan
  • /trunk/external-alma/atnf/PKSIO/NRODataset.cc

    r2473 r2373  
    827827  return vlsr ;
    828828}
    829 
    830 uInt NRODataset::getPolNo( int i )
    831 {
    832   int idx = getIndex( i ) ;
    833 //   cout << "HORN[" << idx << "]=" << HORN[idx]
    834 //        << ", RX[" << idx << "]=" << RX[idx] << endl ;
    835   return polNoFromRX( RX[idx].c_str() ) ;
    836 }
    837 
    838 uInt NRODataset::polNoFromRX( const char *rx )
    839 {
    840   uInt polno = 0 ;
    841   // 2012/03/15 TN
    842   // T100H/V is multi-polarization receiver which is installed
    843   // on NRO 45m telescope. Here, POLNO is assigned as follows:
    844   //
    845   //    POLNO=0: T100H
    846   //          1: T100V
    847   //
    848   // For other receivers, POLNO is always 0.
    849   if ( strncmp( rx, "T100V", 5 ) == 0 )
    850     polno = 1 ;
    851   return polno ;
    852 }
  • /trunk/external-alma/atnf/PKSIO/NRODataset.h

    r2473 r2373  
    4444#include <atnf/PKSIO/NRODataRecord.h>
    4545#include <casa/namespace.h>
    46 #include <casa/iomanip.h>
    4746
    4847#define SCAN_HEADER_SIZE 424
     
    201200  virtual vector<double> getFrequencies( int i ) ;
    202201  virtual uInt getArrayId( string type ) ;
    203   virtual uInt getPolNo( int irow ) ;
    204202
    205203 protected:
     
    240238  virtual double toLSR( double v, double t, double x, double y ) ;
    241239
    242   // POLNO from RX
    243   uInt polNoFromRX( const char *rx ) ;
    244 
    245240  // Type of file record
    246241  string LOFIL ;
     
    523518} ;
    524519
    525 // debug message output
    526 template<class T> inline void nro_debug_output( char *name, int len, vector<T> &val )
    527 {
    528   for ( int i = 0 ; i < len ; i++ ) {
    529     if ( i == 0 ) {
    530       cout << setw(8) << left << name ;
    531     }
    532     else if ( ( i % 5 ) == 0 ) {
    533       cout << endl << "        " ;
    534     }
    535     cout << "\'" << val[i] << "\' " ;
    536   }
    537   cout << endl ;
    538 }
    539 
    540 template<class T> inline void nro_debug_output( char *name, int len1, int len2, vector< vector<T> > &val )
    541 {
    542   for ( int i = 0 ; i < len1 ; i++ ) {
    543     for ( int j = 0 ; j < len2 ; j++ ) {
    544       if ( j == 0 ) {
    545         if ( i < 10 )
    546           cout << name << "0" << i << " " ;
    547         else
    548           cout << name << i << " " ;
    549       }
    550       else if ( ( j % 5 ) == 0 ) {
    551         cout << endl << "        " ;
    552       }
    553       cout << "\'" << val[i][j] << "\' " ;
    554     }
    555     cout << endl ;
    556   }
    557 }
    558 
    559520
    560521#endif /* NRO_HEADER_H */
  • /trunk/external-alma/atnf/PKSIO/NROFITSDataset.cc

    r2473 r2373  
    620620  }
    621621  // DEBUG
    622 //   nro_debug_output( "RX", ARYNM, RX ) ;
     622//   for ( int i = 0 ; i < ARYNM ; i++ ) {
     623//     if ( i == 0 ) {
     624//       cout << "RX      " ;
     625//     }
     626//     else if ( ( i % 5 ) == 0 ) {
     627//       cout << endl << "        " ;
     628//     }
     629//     cout << "\'" << RX[i] << "\' " ;
     630//   }
     631//   cout << endl ;
    623632  //
    624633  if ( readColumn( HPBW, "HPBW", sameEndian ) != 0 ) {
     
    627636  }
    628637  // DEBUG
    629 //   nro_debug_output( "HPBW", ARYNM, HPBW ) ;
     638//   for ( int i = 0 ; i < ARYNM ; i++ ) {
     639//     if ( i == 0 ) {
     640//       //cout << "HPBW    " ;
     641//     }
     642//     else if ( ( i % 5 ) == 0 ) {
     643//       //cout << endl << "        " ;
     644//     }
     645//     //cout << HPBW[i] << " " ;
     646//   }
     647//   //cout << endl ;
    630648  //
    631649  if ( readColumn( EFFA, "EFFA", sameEndian ) != 0 ) {
     
    634652  }
    635653  // DEBUG
    636 //   nro_debug_output( "EFFA", ARYNM, EFFA ) ;
     654//   for ( int i = 0 ; i < ARYNM ; i++ ) {
     655//     if ( i == 0 ) {
     656//       //cout << "EFFA    " ;
     657//     }
     658//     else if ( ( i % 5 ) == 0 ) {
     659//       //cout << endl << "        " ;
     660//     }
     661//     //cout << EFFA[i] << " " ;
     662//   }
     663//   //cout << endl ;
    637664  //
    638665  if ( readColumn( EFFB, "EFFB", sameEndian ) != 0 ) {
     
    641668  }
    642669  // DEBUG
    643 //   nro_debug_output( "EFFB", ARYNM, EFFB ) ;
     670//   for ( int i = 0 ; i < ARYNM ; i++ ) {
     671//     if ( i == 0 ) {
     672//       //cout << "EFFB    " ;
     673//     }
     674//     else if ( ( i % 5 ) == 0 ) {
     675//       //cout << endl << "        " ;
     676//     }
     677//     //cout << EFFB[i] << " " ;
     678//   }
     679//   //cout << endl ;
    644680  //
    645681  if ( readColumn( EFFL, "EFFL", sameEndian ) != 0 ) {
     
    648684  }
    649685  // DEBUG
    650 //   nro_debug_output( "EFFL", ARYNM, EFFL ) ;
     686//   for ( int i = 0 ; i < ARYNM ; i++ ) {
     687//     if ( i == 0 ) {
     688//       //cout << "EFFL    " ;
     689//     }
     690//     else if ( ( i % 5 ) == 0 ) {
     691//       //cout << endl << "        " ;
     692//     }
     693//     //cout << EFFL[i] << " " ;
     694//   }
     695//   //cout << endl ;
    651696  //
    652697  if ( readColumn( EFSS, "EFSS", sameEndian ) != 0 ) {
     
    655700  }
    656701  // DEBUG
    657 //   nro_debug_output( "EFSS", ARYNM, EFSS ) ;
     702//   for ( int i = 0 ; i < ARYNM ; i++ ) {
     703//     if ( i == 0 ) {
     704//       //cout << "EFSS    " ;
     705//     }
     706//     else if ( ( i % 5 ) == 0 ) {
     707//       //cout << endl << "        " ;
     708//     }
     709//     //cout << EFSS[i] << " " ;
     710//   }
     711//   //cout << endl ;
    658712  //
    659713  if ( readColumn( GAIN, "GAIN", sameEndian ) != 0 ) {
     
    662716  }
    663717  // DEBUG
    664 //   nro_debug_output( "GAIN", ARYNM, GAIN ) ;
     718//   for ( int i = 0 ; i < ARYNM ; i++ ) {
     719//     if ( i == 0 ) {
     720//       //cout << "GAIN    " ;
     721//     }
     722//     else if ( ( i % 5 ) == 0 ) {
     723//       //cout << endl << "        " ;
     724//     }
     725//     //cout << GAIN[i] << " " ;
     726//   }
     727//   //cout << endl ;
    665728  //
    666729  if ( readColumn( HORN, "HORN" ) != 0 ) {
     
    669732  }
    670733  // DEBUG
    671 //   nro_debug_output( "HORN", ARYNM, HORN ) ;
     734//   for ( int i = 0 ; i < ARYNM ; i++ ) {
     735//     if ( i == 0 ) {
     736//       //cout << "HORN    " ;
     737//     }
     738//     else if ( ( i % 5 ) == 0 ) {
     739//       //cout << endl << "        " ;
     740//     }
     741//     //cout << "\'" << HORN[i] << "\' " ;
     742//   }
     743//   //cout << endl ;
    672744  //
    673745  if ( readColumn( POLTP, "POLTP" ) != 0 ) {
     
    676748  }
    677749  // DEBUG
    678 //   nro_debug_output( "POLTP", ARYNM, POLTP ) ;
     750//   for ( int i = 0 ; i < ARYNM ; i++ ) {
     751//     if ( i == 0 ) {
     752//       //cout << "POLTP   " ;
     753//     }
     754//     else if ( ( i % 5 ) == 0 ) {
     755//       //cout << endl << "        " ;
     756//     }
     757//     //cout << "\'" << POLTP[i] << "\' " ;
     758//   }
     759//   //cout << endl ;
    679760  //
    680761  vector<int> ipoldr( ARYNM, 0 ) ;
     
    686767    POLDR[i] = (double)ipoldr[i] ;
    687768  // DEBUG
    688 //   nro_debug_output( "POLDR", ARYNM, POLDR ) ;
     769//   for ( int i = 0 ; i < ARYNM ; i++ ) {
     770//     if ( i == 0 ) {
     771//       //cout << "POLDR   " ;
     772//     }
     773//     else if ( ( i % 5 ) == 0 ) {
     774//       //cout << endl << "        " ;
     775//     }
     776//     //cout << POLDR[i] << " " ;
     777//   }
     778//   //cout << endl ;
    689779  //
    690780  if ( readColumn( POLAN, "POLAN", sameEndian ) != 0 ) {
     
    693783  }
    694784  // DEBUG
    695 //   nro_debug_output( "POLAN", ARYNM, POLAN ) ;
     785//   for ( int i = 0 ; i < ARYNM ; i++ ) {
     786//     if ( i == 0 ) {
     787//       //cout << "POLAN   " ;
     788//     }
     789//     else if ( ( i % 5 ) == 0 ) {
     790//       //cout << endl << "        " ;
     791//     }
     792//     //cout << POLAN[i] << " " ;
     793//   }
     794//   //cout << endl ;
    696795  //
    697796  if ( readColumn( DFRQ, "DFRQ", sameEndian ) != 0 ) {
     
    700799  }
    701800  // DEBUG
    702 //   nro_debug_output( "DFRQ", ARYNM, DFRQ ) ;
     801//   for ( int i = 0 ; i < ARYNM ; i++ ) {
     802//     if ( i == 0 ) {
     803//       //cout << "DFRQ    " ;
     804//     }
     805//     else if ( ( i % 5 ) == 0 ) {
     806//       //cout << endl << "        " ;
     807//     }
     808//     //cout << DFRQ[i] << " " ;
     809//   }
     810//   //cout << endl ;
    703811  //
    704812  if ( readColumn( SIDBD, "SIDBD" ) != 0 ) {
     
    707815  }
    708816  // DEBUG
    709 //   nro_debug_output( "SIDBD", ARYNM, SIDBD ) ;
     817//   for ( int i = 0 ; i < ARYNM ; i++ ) {
     818//     if ( i == 0 ) {
     819//       //cout << "SIDBD   " ;
     820//     }
     821//     else if ( ( i % 5 ) == 0 ) {
     822//       //cout << endl << "        " ;
     823//     }
     824//     //cout << "\'" << SIDBD[i] << "\' " ;
     825//   }
     826//   //cout << endl ;
    710827  //
    711828  if ( readColumn( REFN, "REFN", sameEndian ) != 0 ) {
     
    714831  }
    715832  // DEBUG
    716 //   nro_debug_output( "REFN", ARYNM, REFN ) ;
     833//   for ( int i = 0 ; i < ARYNM ; i++ ) {
     834//     if ( i == 0 ) {
     835//       //cout << "REFN    " ;
     836//     }
     837//     else if ( ( i % 5 ) == 0 ) {
     838//       //cout << endl << "        " ;
     839//     }
     840//     //cout << REFN[i] << " " ;
     841//   }
     842//   //cout << endl ;
    717843  //
    718844  if ( readColumn( IPINT, "IPINT", sameEndian ) != 0 ) {
     
    721847  }
    722848  // DEBUG
    723 //   nro_debug_output( "IPINT", ARYNM, IPINT ) ;
     849//   for ( int i = 0 ; i < ARYNM ; i++ ) {
     850//     if ( i == 0 ) {
     851//       //cout << "IPINT   " ;
     852//     }
     853//     else if ( ( i % 5 ) == 0 ) {
     854//       //cout << endl << "        " ;
     855//     }
     856//     //cout << IPINT[i] << " " ;
     857//   }
     858//   //cout << endl ;
    724859  //
    725860  if ( readColumn( MULTN, "MULTN", sameEndian ) != 0 ) {
     
    728863  }
    729864  // DEBUG
    730 //   nro_debug_output( "MULTN", ARYNM, MULTN ) ;
     865//   for ( int i = 0 ; i < ARYNM ; i++ ) {
     866//     if ( i == 0 ) {
     867//       //cout << "MULTN   " ;
     868//     }
     869//     else if ( ( i % 5 ) == 0 ) {
     870//       //cout << endl << "        " ;
     871//     }
     872//     //cout << MULTN[i] << " " ;
     873//   }
     874//   //cout << endl ;
    731875  //
    732876  if ( readColumn( MLTSCF, "MLTSCF", sameEndian ) != 0 ) {
     
    735879  }
    736880  // DEBUG
    737 //   nro_debug_output( "MLTSCF", ARYNM, MLTSCF ) ;
     881//   for ( int i = 0 ; i < ARYNM ; i++ ) {
     882//     if ( i == 0 ) {
     883//       //cout << "MLTSCF  " ;
     884//     }
     885//     else if ( ( i % 5 ) == 0 ) {
     886//       //cout << endl << "        " ;
     887//     }
     888//     //cout << MLTSCF[i] << " " ;
     889//   }
     890//   //cout << endl ;
    738891  //
    739892  if ( readColumn( LAGWIND, "LAGWIN" ) != 0 ) {
     
    742895  }
    743896  // DEBUG
    744 //   nro_debug_output( "LAGWIND", ARYNM, LAGWIND ) ;
     897//   for ( int i = 0 ; i < ARYNM ; i++ ) {
     898//     if ( i == 0 ) {
     899//       //cout << "LAGWIND " ;
     900//     }
     901//     else if ( ( i % 5 ) == 0 ) {
     902//       //cout << endl << "        " ;
     903//     }
     904//     //cout << "\'" << LAGWIND[i] << "\' " ;
     905//   }
     906//   //cout << endl ;
    745907  //
    746908  if ( readColumn( BEBW, "BEBW", sameEndian ) != 0 ) {
     
    749911  }
    750912  // DEBUG
    751 //   nro_debug_output( "BEBW", ARYNM, BEBW ) ;
     913//   for ( int i = 0 ; i < ARYNM ; i++ ) {
     914//     if ( i == 0 ) {
     915//       //cout << "BEBW    " ;
     916//     }
     917//     else if ( ( i % 5 ) == 0 ) {
     918//       //cout << endl << "        " ;
     919//     }
     920//     //cout << BEBW[i] << " " ;
     921//   } 
     922//   //cout << endl ;
    752923  //
    753924  if ( readColumn( BERES, "BERES", sameEndian ) != 0 ) {
     
    756927  }
    757928  // DEBUG
    758 //   nro_debug_output( "BERES", ARYNM, BERES ) ;
     929//   for ( int i = 0 ; i < ARYNM ; i++ ) {
     930//     if ( i == 0 ) {
     931//       //cout << "BERES   " ;
     932//     }
     933//     else if ( ( i % 5 ) == 0 ) {
     934//       //cout << endl << "        " ;
     935//     }
     936//     //cout << BERES[i] << " " ;
     937//   }
     938//   //cout << endl ;
    759939  //
    760940  if ( readColumn( CHWID, "CHWID", sameEndian ) != 0 ) {
     
    762942    return -1 ;
    763943  }
    764   // DEBUG
    765 //   nro_debug_output( "CHWID", ARYNM, CHWID ) ;
     944    // DEBUG
     945//   for ( int i = 0 ; i < ARYNM ; i++ ) {
     946//     if ( i == 0 ) {
     947//       //cout << "CHWID   " ;
     948//     }
     949//     else if ( ( i % 5 ) == 0 ) {
     950//       //cout << endl << "        " ;
     951//     }
     952//     //cout << CHWID[i] << " " ;
     953//   }
     954//   //cout << endl ;
    766955  //
    767956  if ( readARRY() != 0 ) {
     
    770959  }
    771960  // DEBUG
    772 //   nro_debug_output( "ARRY", NRO_FITS_ARYMAX, ARRY ) ;
     961//   for ( int i = 0 ; i < NRO_FITS_ARYMAX ; i++ ) {
     962//     if ( i == 0 ) {
     963//       //cout << "ARRY    " ;
     964//     }
     965//     else if ( ( i % 20 ) == 0 ) {
     966//       //cout << endl << "        " ;
     967//     }
     968//     //cout << ARRY[i] << " " ;
     969//   }
     970//   //cout << endl ;
    773971  //
    774972  if ( readColumn( NFCAL, "NFCAL", sameEndian ) != 0 ) {
     
    776974    return -1 ;
    777975  }
    778   // DEBUG
    779 //   nro_debug_output( "NFCAL", ARYNM, NFCAL ) ;
     976    // DEBUG
     977//   for ( int i = 0 ; i < ARYNM ; i++ ) {
     978//     if ( i == 0 ) {
     979//       //cout << "NFCAL   " ;
     980//     }
     981//     else if ( ( i % 5 ) == 0 ) {
     982//       //cout << endl << "        " ;
     983//     }
     984//     //cout << NFCAL[i] << " " ;
     985//   }
     986//   //cout << endl ;
    780987  //
    781988  if ( readColumn( F0CAL, "F0CAL", sameEndian ) != 0 ) {
     
    783990    return -1 ;
    784991  }
    785   // DEBUG
    786 //   nro_debug_output( "F0CAL", ARYNM, F0CAL ) ;
     992    // DEBUG
     993//   for ( int i = 0 ; i < ARYNM ; i++ ) {
     994//     if ( i == 0 ) {
     995//       //cout << "F0CAL   " ;
     996//     }
     997//     else if ( ( i % 5 ) == 0 ) {
     998//       //cout << endl << "        " ;
     999//     }
     1000//     //cout << F0CAL[i] << " " ;
     1001//   }
     1002//   //cout << endl ;
    7871003  //
    7881004  for ( int i= 0 ; i < 10 ; i++) {
     
    7971013  }
    7981014  // DEBUG
    799 //   nro_debug_output( "FQCAL", ARYNM, 10, FQCAL ) ;
     1015//   for ( int i = 0 ; i < ARYNM ; i++ ) {
     1016//     for ( int j = 0 ; j < 10 ; j++ ) {
     1017//       if ( j == 0 ) {
     1018//         if ( i < 10 )
     1019//           //cout << "FQCAL0" << i << " " ;
     1020//         else
     1021//           //cout << "FQCAL" << i << " " ;
     1022//       }
     1023//       else if ( ( j % 5 ) == 0 ) {
     1024//         //cout << endl << "        " ;
     1025//       }
     1026//       //cout << FQCAL[i][j] << " " ;
     1027//     }
     1028//     //cout << endl ;
     1029//   }
    8001030  //
    8011031  for ( int i= 0 ; i < 10 ; i++) {
     
    8101040  }
    8111041  // DEBUG
    812 //   nro_debug_output( "CHCAL", ARYNM, 10, CHCAL ) ;
     1042//   for ( int i = 0 ; i < ARYNM ; i++ ) {
     1043//     for ( int j = 0 ; j < 10 ; j++ ) {
     1044//       if ( j == 0 ) {
     1045//         if ( i < 10 )
     1046//           //cout << "CHCAL0" << i << " " ;
     1047//         else
     1048//           //cout << "CHCAL" << i << " " ;
     1049//       }
     1050//       else if ( ( j % 5 ) == 0 ) {
     1051//         //cout << endl << "        " ;
     1052//       }
     1053//      //cout << CHCAL[i][j] << " " ;
     1054//    }
     1055//    //cout << endl ;
     1056//   }
    8131057  //
    8141058  for ( int i= 0 ; i < 10 ; i++) {
     
    8231067  }
    8241068  // DEBUG
    825 //   nro_debug_output( "CWCAL", ARYNM, 10, CWCAL ) ;
     1069//   for ( int i = 0 ; i < ARYNM ; i++ ) {
     1070//     for ( int j = 0 ; j < 10 ; j++ ) {
     1071//       if ( j == 0 ) {
     1072//         if ( i < 10 )
     1073//           //cout << "CWCAL0" << i << " " ;
     1074//         else
     1075//           //cout << "CWCAL" << i << " " ;
     1076//       }
     1077//       else if ( ( j % 5 ) == 0 ) {
     1078//         //cout << endl << "        " ;
     1079//       }
     1080//       //cout << CWCAL[i][j] << " " ;
     1081//     }
     1082//     //cout << endl ;
     1083//   }
    8261084  //
    8271085  if ( readHeader( SCNLEN, "NAXIS1", sameEndian ) != 0 ) {
     
    8591117  }
    8601118  // DEBUG
    861 //   nro_debug_output( "DSBFC", ARYNM, DSBFC ) ;
     1119//   for ( int i = 0 ; i < ARYNM ; i++ ) {
     1120//     if ( i == 0 ) {
     1121//       //cout << "DSBFC   " ;
     1122//     }
     1123//     else if ( ( i % 5 ) == 0 ) {
     1124//       //cout << endl << "        " ;
     1125//     }
     1126//     //cout << DSBFC[i] << " " ;
     1127//   }
     1128//   //cout << endl ;
    8621129  //
    8631130
     
    19302197}
    19312198
     2199int NROFITSDataset::readTable( char *v, char *name )
     2200{
     2201  //
     2202  // Read 'name' attribute defined as char from the 0-th row
     2203  // of the FITS Scan Record
     2204  //
     2205  int status = readTable( v, name, (int)strlen( v ), 0 ) ;
     2206
     2207  return status ;
     2208}
     2209
    19322210int NROFITSDataset::readTable( char *v, char *name, int clen, int idx )
    19332211{
     
    19362214  // of the FITS Scan Record
    19372215  //
    1938   int status = movePointer( name, idx ) ;
    1939   if ( status < 0 )
    1940     return status ;
     2216  int status = 0 ;
     2217
     2218  // skip header
     2219  fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
     2220
     2221  // find offset
     2222  int offset = getOffset( name ) ;
     2223  if ( offset == -1 ) {
     2224    //cerr << "Error, " << name << " is not found in the name list." << endl ;
     2225    return -1 ;
     2226  }
     2227  offset += idx * scanLen_ ;
     2228  //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
     2229  fseek( fp_, offset, SEEK_CUR ) ;
    19412230
    19422231  // get length of char
     
    19652254}
    19662255
     2256int NROFITSDataset::readTable( int &v, char *name, int b )
     2257{
     2258  //
     2259  // Read 'name' attribute defined as int from the 0-th row
     2260  // of the FITS Scan Record
     2261  //
     2262  int status = readTable( v, name, b, 0 ) ;
     2263
     2264  return status ;
     2265}
     2266
    19672267int NROFITSDataset::readTable( int &v, char *name, int b, int idx )
    19682268{
     
    19712271  // of the FITS Scan Record
    19722272  //
    1973   int status = movePointer( name, idx ) ;
    1974   if ( status < 0 )
    1975     return status ;
     2273  int status = 0 ;
     2274  // skip header
     2275  fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
     2276
     2277  // find offset
     2278  int offset = getOffset( name ) ;
     2279  if ( offset == -1 ) {
     2280    //cerr << "Error, " << name << " is not found in the name list." << endl ;
     2281    return -1 ;
     2282  }
     2283  offset += idx * scanLen_ ;
     2284  //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
     2285  fseek( fp_, offset, SEEK_CUR ) ;
    19762286
    19772287  // read data
     
    19832293}
    19842294
     2295int NROFITSDataset::readTable( float &v, char *name, int b )
     2296{
     2297  //
     2298  // Read 'name' attribute defined as float from the 0-th row
     2299  // of the FITS Scan Record
     2300  //
     2301  int status = readTable( v, name, b, 0 ) ;
     2302
     2303  return status ;
     2304}
     2305
    19852306int NROFITSDataset::readTable( float &v, char *name, int b, int idx )
    19862307{
     
    19892310  // of the FITS Scan Record
    19902311  //
    1991   int status = movePointer( name, idx ) ;
    1992   if ( status < 0 )
    1993     return status ;
     2312  int status = 0 ;
     2313
     2314  // skip header
     2315  fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
     2316
     2317  // find offset
     2318  int offset = getOffset( name ) ;
     2319  if ( offset == -1 ) {
     2320    //cerr << "Error, " << name << " is not found in the name list." << endl ;
     2321    return -1 ;
     2322  }
     2323  offset += idx * scanLen_ ;
     2324  //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
     2325  fseek( fp_, offset, SEEK_CUR ) ;
    19942326
    19952327  // read data
     
    20012333}
    20022334
     2335int NROFITSDataset::readTable( double &v, char *name, int b )
     2336{
     2337  //
     2338  // Read 'name' attribute defined as double from the 0-th row
     2339  // of the FITS Scan Record
     2340  //
     2341  int status = readTable( v, name, b, 0 ) ;
     2342
     2343  return status ;
     2344}
     2345
    20032346int NROFITSDataset::readTable( double &v, char *name, int b, int idx )
    20042347{
     
    20072350  // of the FITS Scan Record
    20082351  //
    2009   int status = movePointer( name, idx ) ;
    2010   if ( status < 0 )
    2011     return status ;
     2352  int status = 0 ;
     2353
     2354  // skip header
     2355  fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
     2356
     2357  // find offset
     2358  int offset = getOffset( name ) ;
     2359  if ( offset == -1 ) {
     2360    //cerr << "Error, " << name << " is not found in the name list." << endl ;
     2361    return -1 ;
     2362  }
     2363  offset += idx * scanLen_ ;
     2364  //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
     2365  fseek( fp_, offset, SEEK_CUR ) ;
    20122366
    20132367  // read data
     
    20242378  // Read 'name' attribute defined as char array from the FITS Scan Record
    20252379  //
    2026   int status = movePointer( name, idx ) ;
    2027   if ( status < 0 )
    2028     return status ;
     2380  int status = 0 ;
     2381 
     2382  // skip header
     2383  fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
     2384
     2385  // find offset
     2386  int offset = getOffset( name ) ;
     2387  if ( offset == -1 ) {
     2388    //cerr << "Error, " << name << " is not found in the name list." << endl ;
     2389    return -1 ;
     2390  }
     2391  offset += idx * scanLen_ ;
     2392  //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
     2393  fseek( fp_, offset, SEEK_CUR ) ;
    20292394
    20302395  // get length of char
     
    20612426  // Read 'name' attribute defined as int array from the FITS Scan Record
    20622427  //
    2063   int status = movePointer( name, idx ) ;
    2064   if ( status < 0 )
    2065     return status ;
     2428  int status = 0 ;
     2429 
     2430  // skip header
     2431  fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
     2432
     2433  // find offset
     2434  int offset = getOffset( name ) ;
     2435  if ( offset == -1 ) {
     2436    //cerr << "Error, " << name << " is not found in the name list." << endl ;
     2437    return -1 ;
     2438  }
     2439  offset += idx * scanLen_ ;
     2440  //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
     2441  fseek( fp_, offset, SEEK_CUR ) ;
    20662442
    20672443  for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
     
    20802456  // Read 'name' attribute defined as float array from the FITS Scan Record
    20812457  //
    2082   int status = movePointer( name, idx ) ;
    2083   if ( status < 0 )
    2084     return status ;
     2458  int status = 0 ;
     2459 
     2460  // skip header
     2461  fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
     2462
     2463  // find offset
     2464  int offset = getOffset( name ) ;
     2465  if ( offset == -1 ) {
     2466    //cerr << "Error, " << name << " is not found in the name list." << endl ;
     2467    return -1 ;
     2468  }
     2469  offset += idx * scanLen_ ;
     2470  //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
     2471  fseek( fp_, offset, SEEK_CUR ) ;
    20852472
    20862473  for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
     
    20992486  // Read 'name' attribute defined as double array from the FITS Scan Record
    21002487  //
    2101   int status = movePointer( name, idx ) ;
    2102   if ( status < 0 )
    2103     return status ;
     2488  int status = 0 ;
     2489 
     2490  // skip header
     2491  fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
     2492
     2493  // find offset
     2494  int offset = getOffset( name ) ;
     2495  if ( offset == -1 ) {
     2496    //cerr << "Error, " << name << " is not found in the name list." << endl ;
     2497    return -1 ;
     2498  }
     2499  offset += idx * scanLen_ ;
     2500  //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
     2501  fseek( fp_, offset, SEEK_CUR ) ;
    21042502
    21052503  for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
     
    21132511}
    21142512
     2513int NROFITSDataset::readColumn( vector<string> &v, char *name )
     2514{
     2515  //
     2516  // Read 0-th column of ARRYTP-dependent 'name' attributes
     2517  // defined as char array from the FITS Scan Record
     2518  //
     2519  int status = readColumn( v, name, 0 ) ;
     2520
     2521  return status ;
     2522}
     2523
    21152524int NROFITSDataset::readColumn( vector<string> &v, char *name, int idx )
    21162525{
     
    21192528  // defined as char array from the FITS Scan Record
    21202529  //
    2121   int status = movePointer( name ) ;
    2122   if ( status < 0 )
    2123     return status ;
     2530  int status = 0 ;
     2531
     2532  // skip header
     2533  fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
     2534
     2535  // find offset
     2536  int offset = getOffset( name ) ;
     2537  if ( offset == -1 ) {
     2538    //cerr << "Error, " << name << " is not found in the name list." << endl ;
     2539    return -1 ;
     2540  }
     2541  //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
     2542  fseek( fp_, offset, SEEK_CUR ) ;
    21242543
    21252544  // get length of char
     
    21362555
    21372556  for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
    2138     int offset = scanLen_ * arrayid_[i] + xsize * idx ;
     2557    offset = scanLen_ * arrayid_[i] + xsize * idx ;
    21392558    fseek( fp_, offset, SEEK_CUR ) ;
    21402559//     int clen = (int)strlen( v[i] ) ;
     
    21582577}
    21592578
     2579int NROFITSDataset::readColumn( vector<int> &v, char *name, int b )
     2580{
     2581  //
     2582  // Read 0-th column of ARRYTP-dependent 'name' attributes
     2583  // defined as int array from the FITS Scan Record
     2584  //
     2585  int status = readColumn( v, name, b, 0 ) ;
     2586
     2587  return status ;
     2588}
     2589
    21602590int NROFITSDataset::readColumn( vector<int> &v, char *name, int b, int idx )
    21612591{
     
    21642594  // defined as int array from the FITS Scan Record
    21652595  //
    2166   int status = movePointer( name ) ;
    2167   if ( status < 0 )
    2168     return status ;
     2596  int status = 0 ;
     2597
     2598  // skip header
     2599  fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
     2600
     2601  // find offset
     2602  int offset = getOffset( name ) ;
     2603  if ( offset == -1 ) {
     2604    //cerr << "Error, " << name << " is not found in the name list." << endl ;
     2605    return -1 ;
     2606  }
     2607  //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
     2608  fseek( fp_, offset, SEEK_CUR ) ;
    21692609
    21702610  for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
    2171     int offset = scanLen_ * arrayid_[i] + sizeof(int) * idx ;
     2611    offset = scanLen_ * arrayid_[i] + sizeof(int) * idx ;
    21722612    fseek( fp_, offset, SEEK_CUR ) ;
    21732613    fread( &v[i], 1, sizeof(int), fp_ ) ;
     
    21812621}
    21822622
     2623int NROFITSDataset::readColumn( vector<float> &v, char *name, int b )
     2624{
     2625  //
     2626  // Read 0-th column of ARRYTP-dependent 'name' attributes
     2627  // defined as float array from the FITS Scan Record
     2628  //
     2629  int status = readColumn( v, name, b, 0 ) ;
     2630
     2631  return status ;
     2632}
     2633
    21832634int NROFITSDataset::readColumn( vector<float> &v, char *name, int b, int idx )
    21842635{
     
    21872638  // defined as float array from the FITS Scan Record
    21882639  //
    2189   int status = movePointer( name ) ;
    2190   if ( status < 0 )
    2191     return status ;
     2640  int status = 0 ;
     2641
     2642  // skip header
     2643  fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
     2644
     2645  // find offset
     2646  int offset = getOffset( name ) ;
     2647  if ( offset == -1 ) {
     2648    //cerr << "Error, " << name << " is not found in the name list." << endl ;
     2649    return -1 ;
     2650  }
     2651  //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
     2652  fseek( fp_, offset, SEEK_CUR ) ;
    21922653
    21932654  for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
    2194     int offset = scanLen_ * arrayid_[i] + sizeof(float) * idx ;
     2655    offset = scanLen_ * arrayid_[i] + sizeof(float) * idx ;
    21952656    fseek( fp_, offset, SEEK_CUR ) ;
    21962657    fread( &v[i], 1, sizeof(float), fp_ ) ;
     
    22042665}
    22052666
     2667int NROFITSDataset::readColumn( vector<double> &v, char *name, int b )
     2668{
     2669  //
     2670  // Read 0-th column of ARRYTP-dependent 'name' attributes
     2671  // defined as double array from the FITS Scan Record
     2672  //
     2673  int status = readColumn( v, name, b, 0 ) ;
     2674
     2675  return status ;
     2676}
     2677
    22062678int NROFITSDataset::readColumn( vector<double> &v, char *name, int b, int idx )
    22072679{
     
    22102682  // defined as double array from the FITS Scan Record
    22112683  //
    2212   int status = movePointer( name ) ;
    2213   if ( status < 0 )
    2214     return status ;
     2684  int status = 0 ;
     2685
     2686  // skip header
     2687  fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
     2688
     2689  // find offset
     2690  int offset = getOffset( name ) ;
     2691  if ( offset == -1 ) {
     2692    //cerr << "Error, " << name << " is not found in the name list." << endl ;
     2693    return -1 ;
     2694  }
     2695  //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
     2696  fseek( fp_, offset, SEEK_CUR ) ;
    22152697
    22162698  for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
    2217     int offset = scanLen_ * arrayid_[i] + sizeof(double) * idx ;
     2699    offset = scanLen_ * arrayid_[i] + sizeof(double) * idx ;
    22182700    fseek( fp_, offset, SEEK_CUR ) ;
    22192701    fread( &v[i], 1, sizeof(double), fp_ ) ;
     
    22602742}
    22612743
    2262 uInt NROFITSDataset::getPolNo( int irow )
    2263 {
    2264   char rx[9] ;
    2265   readTable( rx, "RX", 8, irow ) ;
    2266   rx[8] = '\0' ;
    2267   //cout << rx << endl ;
    2268   return polNoFromRX( rx ) ;
    2269 }
    2270 
    2271 int NROFITSDataset::movePointer( char *name, int idx )
    2272 {
    2273   // find offset
    2274   int offset = getOffset( name ) ;
    2275   if ( offset == -1 ) {
    2276     //cerr << "Error, " << name << " is not found in the name list." << endl ;
    2277     return -1 ;
    2278   }
    2279 
    2280   offset += idx * scanLen_ ;
    2281 
    2282   //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
    2283   fseek( fp_, FITS_HEADER_SIZE+offset, SEEK_SET ) ;
    2284 
    2285   return 0 ;
    2286 }
    2287 
    22882744// double NROFITSDataset::toLSR( double v, double t, double x, double y )
    22892745// {
  • /trunk/external-alma/atnf/PKSIO/NROFITSDataset.h

    r2473 r2373  
    9797  virtual double getStartIntTime( int i ) ;
    9898  virtual double getScanTime( int i ) ;
    99   virtual uInt getPolNo( int irow ) ;
    10099
    101100 protected:
     
    105104  // Read char data
    106105  int readHeader( string &v, char *name ) ;
    107   int readTable( char *v, char *name, int clen, int idx=0 ) ;
    108   int readTable( vector<char *> &v, char *name, int idx=0 ) ;
    109   int readColumn( vector<string> &v, char *name, int idx=0 ) ;
     106  int readTable( char *v, char *name ) ;
     107  int readTable( char *v, char *name, int clen, int idx ) ;
     108  int readTable( vector<char *> &v, char *name, int idx ) ;
     109  int readColumn( vector<string> &v, char *name ) ;
     110  int readColumn( vector<string> &v, char *name, int idx ) ;
    110111
    111112  // Read int data
    112113  int readHeader( int &v, char *name, int b ) ;
    113   int readTable( int &v, char *name, int b, int idx=0 ) ;
    114   int readTable( vector<int> &v, char *name, int b, int idx=0 ) ;
    115   int readColumn( vector<int> &v, char *name, int b, int idx=0 ) ;
     114  int readTable( int &v, char *name, int b ) ;
     115  int readTable( int &v, char *name, int b, int idx ) ;
     116  int readTable( vector<int> &v, char *name, int b, int idx ) ;
     117  int readColumn( vector<int> &v, char *name, int b ) ;
     118  int readColumn( vector<int> &v, char *name, int b, int idx ) ;
    116119
    117120  // Read float data
    118121  int readHeader( float &v, char *name, int b ) ;
    119   int readTable( float &v, char *name, int b, int idx=0 ) ;
    120   int readTable( vector<float> &v, char *name, int b, int idx=0 ) ;
    121   int readColumn( vector<float> &v, char *name, int b, int idx=0 ) ;
     122  int readTable( float &v, char *name, int b ) ;
     123  int readTable( float &v, char *name, int b, int idx ) ;
     124  int readTable( vector<float> &v, char *name, int b, int idx ) ;
     125  int readColumn( vector<float> &v, char *name, int b ) ;
     126  int readColumn( vector<float> &v, char *name, int b, int idx ) ;
    122127
    123128  // Read double data
    124129  int readHeader( double &v, char *name, int b ) ;
    125   int readTable( double &v, char *name, int b, int idx=0 ) ;
    126   int readTable( vector<double> &v, char *name, int b, int idx=0 ) ;
    127   int readColumn( vector<double> &v, char *name, int b, int idx=0 ) ;
     130  int readTable( double &v, char *name, int b ) ;
     131  int readTable( double &v, char *name, int b, int idx ) ;
     132  int readTable( vector<double> &v, char *name, int b, int idx ) ;
     133  int readColumn( vector<double> &v, char *name, int b ) ;
     134  int readColumn( vector<double> &v, char *name, int b, int idx ) ;
    128135
    129136  // read ARRY
     
    147154  // get offset bytes for attributes
    148155  int getOffset( char *name ) ;
    149 
    150   // move pointer to target position
    151   int movePointer( char *name, int idx=0 ) ;
    152156
    153157  // convert frequency frame
  • /trunk/external-alma/atnf/PKSIO/NROOTFDataset.cc

    r2473 r2373  
    535535    c18[16] = '\0' ;
    536536    RX[i] = string( c18 ) ;
    537   }
    538   // DEBUG
    539 //   nro_debug_output( "RX", NRO_ARYMAX, RX ) ;
    540   //
     537    // DEBUG
     538//     if ( i == 0 ) {
     539//       cout << "RX      " ;
     540//     }
     541//     else if ( ( i % 5 ) == 0 ) {
     542//       cout << endl << "        " ;
     543//     }
     544//     cout << RX[i] << " " ;
     545    //
     546  }
     547  //cout << endl ;
    541548  for ( int i = 0 ; i < NRO_ARYMAX ; i++ ) {
    542549    if ( readHeader( HPBW[i], sameEndian ) == -1 ) {
     
    544551      return -1 ;
    545552    }
    546   }
    547   // DEBUG
    548 //   nro_debug_output( "HPBW", NRO_ARYMAX, HPBW ) ;
    549   //
     553    // DEBUG
     554//     if ( i == 0 ) {
     555//       cout << "HPBW    " ;
     556//     }
     557//     else if ( ( i % 5 ) == 0 ) {
     558//       cout << endl << "        " ;
     559//     }
     560//     cout << HPBW[i] << " " ;
     561    //
     562  }
     563  //cout << endl ;
    550564  for ( int i = 0 ; i < NRO_ARYMAX ; i++ ) {
    551565    if ( readHeader( EFFA[i], sameEndian ) == -1 ) {
     
    553567      return -1 ;
    554568    }
    555   }
    556   // DEBUG
    557 //   nro_debug_output( "EFFA", NRO_ARYMAX, EFFA ) ;
    558   //
     569    // DEBUG
     570//     if ( i == 0 ) {
     571//       cout << "EFFA    " ;
     572//     }
     573//     else if ( ( i % 5 ) == 0 ) {
     574//       cout << endl << "        " ;
     575//     }
     576//     cout << EFFA[i] << " " ;
     577    //
     578  }
     579  //cout << endl ;
    559580  for ( int i = 0 ; i < NRO_ARYMAX ; i++ ) {
    560581    if ( readHeader( EFFB[i], sameEndian ) == -1 ) {
     
    562583      return -1 ;
    563584    }
    564   }
    565   // DEBUG
    566 //   nro_debug_output( "EFFB", NRO_ARYMAX, EFFB ) ;
    567   //
     585    // DEBUG
     586//     if ( i == 0 ) {
     587//       cout << "EFFB    " ;
     588//     }
     589//     else if ( ( i % 5 ) == 0 ) {
     590//       cout << endl << "        " ;
     591//     }
     592//     cout << EFFB[i] << " " ;
     593    //
     594  }
     595  //cout << endl ;
    568596  for ( int i = 0 ; i < NRO_ARYMAX ; i++ ) {
    569597    if ( readHeader( EFFL[i], sameEndian ) == -1 ) {
     
    571599      return -1 ;
    572600    }
    573   }
    574   // DEBUG
    575 //   nro_debug_output( "EFFL", NRO_ARYMAX, EFFL ) ;
    576   //
     601    // DEBUG
     602//     if ( i == 0 ) {
     603//       cout << "EFFL    " ;
     604//     }
     605//     else if ( ( i % 5 ) == 0 ) {
     606//       cout << endl << "        " ;
     607//     }
     608//     cout << EFFL[i] << " " ;
     609    //
     610  }
     611  //cout << endl ;
    577612  for ( int i = 0 ; i < NRO_ARYMAX ; i++ ) {
    578613    if ( readHeader( EFSS[i], sameEndian ) == -1 ) {
     
    580615      return -1 ;
    581616    }
    582   }
    583   // DEBUG
    584 //   nro_debug_output( "EFSS", NRO_ARYMAX, EFSS ) ;
    585   //
     617    // DEBUG
     618//     if ( i == 0 ) {
     619//       cout << "EFSS    " ;
     620//     }
     621//     else if ( ( i % 5 ) == 0 ) {
     622//       cout << endl << "        " ;
     623//     }
     624//     cout << EFSS[i] << " " ;
     625    //
     626  }
     627  //cout << endl ;
    586628  for ( int i = 0 ; i < NRO_ARYMAX ; i++) {
    587629    if ( readHeader( GAIN[i], sameEndian ) == -1 ) {
     
    589631      return -1 ;
    590632    }
    591   }
    592   // DEBUG
    593 //   nro_debug_output( "GAIN", NRO_ARYMAX, GAIN ) ;
    594   //
     633    // DEBUG
     634//     if ( i == 0 ) {
     635//       cout << "GAIN    " ;
     636//     }
     637//     else if ( ( i % 5 ) == 0 ) {
     638//       cout << endl << "        " ;
     639//     }
     640//     cout << GAIN[i] << " " ;
     641    //
     642  }
     643  //cout << endl ;
    595644  for ( int i = 0 ; i < NRO_ARYMAX ; i++) {
    596645    strcpy( c4, str4.c_str() ) ;
     
    600649    }
    601650    HORN[i] = string( c4 ) ;
    602   }
    603   // DEBUG
    604 //   nro_debug_output( "HORN", NRO_ARYMAX, HORN ) ;
    605   //
     651    // DEBUG
     652//     if ( i == 0 ) {
     653//       cout << "HORN    " ;
     654//     }
     655//     else if ( ( i % 5 ) == 0 ) {
     656//       cout << endl << "        " ;
     657//     }
     658//     cout << HORN[i] << " " ;
     659    //
     660  }
     661  //cout << endl ;
    606662  for ( int i = 0 ; i < NRO_ARYMAX ; i++) {
    607663    strcpy( c4, str4.c_str() ) ;
     
    611667    }
    612668    POLTP[i] = string( c4 ) ;
    613   }
    614   // DEBUG
    615 //   nro_debug_output( "POLTP", NRO_ARYMAX, POLTP ) ;
    616   //
     669    // DEBUG
     670//     if ( i == 0 ) {
     671//       cout << "POLTP   " ;
     672//     }
     673//     else if ( ( i % 5 ) == 0 ) {
     674//       cout << endl << "        " ;
     675//     }
     676//     cout << POLTP[i] << " " ;
     677    //
     678  }
     679  //cout << endl ;
    617680  for ( int i = 0 ; i < NRO_ARYMAX ; i++) {
    618681    if ( readHeader( POLDR[i], sameEndian ) == -1 ) {
     
    620683      return -1 ;
    621684    }
    622   }
    623   // DEBUG
    624 //   nro_debug_output( "POLDR", NRO_ARYMAX, POLDR ) ;
    625   //
     685    // DEBUG
     686//     if ( i == 0 ) {
     687//       cout << "POLDR   " ;
     688//     }
     689//     else if ( ( i % 5 ) == 0 ) {
     690//       cout << endl << "        " ;
     691//     }
     692//     cout << POLDR[i] << " " ;
     693    //
     694  }
     695  //cout << endl ;
    626696  for ( int i = 0 ; i < NRO_ARYMAX ; i++) {
    627697    if ( readHeader( POLAN[i], sameEndian ) == -1 ) {
     
    629699      return -1 ;
    630700    }
    631   }
    632   // DEBUG
    633 //   nro_debug_output( "POLAN", NRO_ARYMAX, POLAN ) ;
    634   //
     701    // DEBUG
     702//     if ( i == 0 ) {
     703//       cout << "POLAN   " ;
     704//     }
     705//     else if ( ( i % 5 ) == 0 ) {
     706//       cout << endl << "        " ;
     707//     }
     708//     cout << POLAN[i] << " " ;
     709    //
     710  }
     711  //cout << endl ;
    635712  for ( int i = 0 ; i < NRO_ARYMAX ; i++) {
    636713    if ( readHeader( DFRQ[i], sameEndian ) == -1 ) {
     
    638715      return -1 ;
    639716    }
    640   }
    641   // DEBUG
    642 //   nro_debug_output( "DFRQ", NRO_ARYMAX, DFRQ ) ;
    643   //
     717    // DEBUG
     718//     if ( i == 0 ) {
     719//       cout << "DFRQ    " ;
     720//     }
     721//     else if ( ( i % 5 ) == 0 ) {
     722//       cout << endl << "        " ;
     723//     }
     724//     cout << DFRQ[i] << " " ;
     725    //
     726  }
     727  //cout << endl ;
    644728  for ( int i = 0 ; i < NRO_ARYMAX ; i++) {
    645729    strcpy( c4, str4.c_str() ) ;
     
    649733    }
    650734    SIDBD[i] = string( c4 ) ;
    651   }
    652   // DEBUG
    653 //   nro_debug_output( "SIDBD", NRO_ARYMAX, SIDBD ) ;
    654   //
     735    // DEBUG
     736//     if ( i == 0 ) {
     737//       cout << "SIDBD   " ;
     738//     }
     739//     else if ( ( i % 5 ) == 0 ) {
     740//       cout << endl << "        " ;
     741//     }
     742//     cout << SIDBD[i] << " " ;
     743    //
     744  }
     745  //cout << endl ;
    655746  for ( int i = 0 ; i < NRO_ARYMAX ; i++) {
    656747    if ( readHeader( REFN[i], sameEndian ) == -1 ) {
     
    658749      return -1 ;
    659750    }
    660   }
    661   // DEBUG
    662 //   nro_debug_output( "REFN", NRO_ARYMAX, REFN ) ;
    663   //
     751    // DEBUG
     752//     if ( i == 0 ) {
     753//       cout << "REFN    " ;
     754//     }
     755//     else if ( ( i % 5 ) == 0 ) {
     756//       cout << endl << "        " ;
     757//     }
     758//     cout << REFN[i] << " " ;
     759    //
     760  }
     761  //cout << endl ;
    664762  for ( int i = 0 ; i < NRO_ARYMAX ; i++) {
    665763    if ( readHeader( IPINT[i], sameEndian ) == -1 ) {
     
    667765      return -1 ;
    668766    }
    669   }
    670   // DEBUG
    671 //   nro_debug_output( "IPINT", NRO_ARYMAX, IPINT ) ;
    672   //
     767    // DEBUG
     768//     if ( i == 0 ) {
     769//       cout << "IPINT   " ;
     770//     }
     771//     else if ( ( i % 5 ) == 0 ) {
     772//       cout << endl << "        " ;
     773//     }
     774//     cout << IPINT[i] << " " ;
     775    //
     776  }
     777  //cout << endl ;
    673778  for ( int i = 0 ; i < NRO_ARYMAX ; i++) {
    674779    if ( readHeader( MULTN[i], sameEndian ) == -1 ) {
     
    676781      return -1 ;
    677782    }
    678   }
    679   // DEBUG
    680 //   nro_debug_output( "MULTN", NRO_ARYMAX, MULTN ) ;
    681   //
     783    // DEBUG
     784//     if ( i == 0 ) {
     785//       cout << "MULTN   " ;
     786//     }
     787//     else if ( ( i % 5 ) == 0 ) {
     788//       cout << endl << "        " ;
     789//     }
     790//     cout << MULTN[i] << " " ;
     791    //
     792  }
     793  //cout << endl ;
    682794  for ( int i = 0 ; i < NRO_ARYMAX ; i++) {
    683795    if ( readHeader( MLTSCF[i], sameEndian ) == -1 ) {
     
    685797      return -1 ;
    686798    }
    687   }
    688   // DEBUG
    689 //   nro_debug_output( "MLTSCF", NRO_ARYMAX, MLTSCF ) ;
    690   //
     799    // DEBUG
     800//     if ( i == 0 ) {
     801//       cout << "MLTSCF  " ;
     802//     }
     803//     else if ( ( i % 5 ) == 0 ) {
     804//       cout << endl << "        " ;
     805//     }
     806//     cout << MLTSCF[i] << " " ;
     807    //
     808  }
     809  //cout << endl ;
    691810  for ( int i = 0 ; i < NRO_ARYMAX ; i++) {
    692811    strcpy( c8, str8.c_str() ) ;
     
    696815    }
    697816    LAGWIND[i] = string( c8 ) ;
    698   }
    699   // DEBUG
    700 //   nro_debug_output( "LAGWIND", NRO_ARYMAX, LAGWIND ) ;
    701   //
     817    // DEBUG
     818//     if ( i == 0 ) {
     819//       cout << "LAGWIND " ;
     820//     }
     821//     else if ( ( i % 5 ) == 0 ) {
     822//       cout << endl << "        " ;
     823//     }
     824//     cout << LAGWIND[i] << " " ;
     825    //
     826  }
     827  //cout << endl ;
    702828  for ( int i = 0 ; i < NRO_ARYMAX ; i++) {
    703829    if ( readHeader( BEBW[i], sameEndian ) == -1 ) {
     
    705831      return -1 ;
    706832    }
    707   }
    708   // DEBUG
    709 //   nro_debug_output( "BEBW", NRO_ARYMAX, BEBW ) ;
    710   //
     833    // DEBUG
     834//     if ( i == 0 ) {
     835//       cout << "BEBW    " ;
     836//     }
     837//     else if ( ( i % 5 ) == 0 ) {
     838//       cout << endl << "        " ;
     839//     }
     840//     cout << BEBW[i] << " " ;
     841    //
     842  }
     843  //cout << endl ;
    711844  for ( int i = 0 ; i < NRO_ARYMAX ; i++) {
    712845    if ( readHeader( BERES[i], sameEndian ) == -1 ) {
     
    714847      return -1 ;
    715848    }
    716   }
    717   // DEBUG
    718 //   nro_debug_output( "BERES", NRO_ARYMAX, BERES ) ;
    719   //
     849    // DEBUG
     850//     if ( i == 0 ) {
     851//       cout << "BERES   " ;
     852//     }
     853//     else if ( ( i % 5 ) == 0 ) {
     854//       cout << endl << "        " ;
     855//     }
     856//     cout << BERES[i] << " " ;
     857    //
     858  }
     859  //cout << endl ;
    720860  for ( int i = 0 ; i < NRO_ARYMAX ; i++) {
    721861    if ( readHeader( CHWID[i], sameEndian ) == -1 ) {
     
    723863      return -1 ;
    724864    }
    725   }
    726   // DEBUG
    727 //   nro_debug_output( "CHWID", NRO_ARYMAX, CHWID ) ;
    728   //
     865    // DEBUG
     866//     if ( i == 0 ) {
     867//       cout << "CHWID   " ;
     868//     }
     869//     else if ( ( i % 5 ) == 0 ) {
     870//       cout << endl << "        " ;
     871//     }
     872//     cout << CHWID[i] << " " ;
     873    //
     874  }
     875  //cout << endl ;
    729876  for ( int i = 0 ; i < NRO_ARYMAX ; i++) {
    730877    if ( readHeader( ARRY[i], sameEndian ) == -1 ) {
     
    732879      return -1 ;
    733880    }
    734   }
    735   // DEBUG
    736 //   nro_debug_output( "ARRY", NRO_ARYMAX, ARRY ) ;
    737   //
     881    // DEBUG
     882//     if ( i == 0 ) {
     883//       cout << "ARRY    " ;
     884//     }
     885//     else if ( ( i % 5 ) == 0 ) {
     886//       cout << endl << "        " ;
     887//     }
     888//     cout << ARRY[i] << " " ;
     889    //
     890  }
     891  //cout << endl ;
    738892  for ( int i = 0 ; i < NRO_ARYMAX ; i++) {
    739893    if ( readHeader( NFCAL[i], sameEndian ) == -1 ) {
     
    741895      return -1 ;
    742896    }
    743   }
    744   // DEBUG
    745 //   nro_debug_output( "NFCAL", NRO_ARYMAX, NFCAL ) ;
    746   //
     897    // DEBUG
     898//     if ( i == 0 ) {
     899//       cout << "NFCAL   " ;
     900//     }
     901//     else if ( ( i % 5 ) == 0 ) {
     902//       cout << endl << "        " ;
     903//     }
     904//     cout << NFCAL[i] << " " ;
     905    //
     906  }
     907  //cout << endl ;
    747908  for ( int i = 0 ; i < NRO_ARYMAX ; i++) {
    748909    if ( readHeader( F0CAL[i], sameEndian ) == -1 ) {
     
    750911      return -1 ;
    751912    }
    752   }
    753   // DEBUG
    754 //   nro_debug_output( "F0CAL", NRO_ARYMAX, F0CAL ) ;
    755   //
     913    // DEBUG
     914//     if ( i == 0 ) {
     915//       cout << "F0CAL   " ;
     916//     }
     917//     else if ( ( i % 5 ) == 0 ) {
     918//       cout << endl << "        " ;
     919//     }
     920//     cout << F0CAL[i] << " " ;
     921    //
     922  }
     923  //cout << endl ;
    756924  for ( int i = 0 ; i < NRO_ARYMAX ; i++) {
    757925    for ( int j = 0 ; j < 10 ; j++ ) {
     
    760928        return -1 ;
    761929      }
    762     }
    763   }
    764   // DEBUG
    765 //   nro_debug_output( "FQCAL", NRO_ARYMAX, 10, FQCAL ) ;
    766   // 
     930      // DEBUG
     931//       if ( j == 0 ) {
     932//         if ( i < 10 )
     933//           cout << "FQCAL0" << i << " " ;
     934//         else
     935//           cout << "FQCAL" << i << " " ;
     936//       }
     937//       else if ( ( j % 5 ) == 0 ) {
     938//         cout << endl << "        " ;
     939//       }
     940//       cout << FQCAL[i][j] << " " ;
     941      //
     942    }
     943    //cout << endl ;
     944  }
    767945  for ( int i = 0 ; i < NRO_ARYMAX ; i++) {
    768946    for ( int j = 0 ; j < 10 ; j++ ) {
     
    771949        return -1 ;
    772950      }
    773     }
    774   }
    775   // DEBUG
    776 //   nro_debug_output( "CHCAL", NRO_ARYMAX, 10, CHCAL ) ;
    777   // 
     951     // DEBUG
     952//       if ( j == 0 ) {
     953//         if ( i < 10 )
     954//           cout << "CHCAL0" << i << " " ;
     955//         else
     956//           cout << "CHCAL" << i << " " ;
     957//       }
     958//       else if ( ( j % 5 ) == 0 ) {
     959//         cout << endl << "        " ;
     960//       }
     961//       cout << CHCAL[i][j] << " " ;
     962     //
     963    }
     964    //cout << endl ;
     965  }
    778966  for ( int i = 0 ; i < NRO_ARYMAX ; i++) {
    779967    for ( int j = 0 ; j < 10 ; j++ ) {
     
    782970        return -1 ;
    783971      }
    784     }
    785   }
    786   // DEBUG
    787 //   nro_debug_output( "CWCAL", NRO_ARYMAX, 10, CWCAL ) ;
    788   // 
     972      // DEBUG
     973//       if ( j == 0 ) {
     974//         if ( i < 10 )
     975//           cout << "CWCAL0" << i << " " ;
     976//         else
     977//           cout << "CWCAL" << i << " " ;
     978//       }
     979//       else if ( ( j % 5 ) == 0 ) {
     980//         cout << endl << "        " ;
     981//       }
     982//       cout << CWCAL[i][j] << " " ;
     983      //
     984    }
     985    //cout << endl ;
     986  }
    789987  if ( readHeader( SCNLEN, sameEndian ) == -1 ) {
    790988    os << LogIO::WARN << "Error while reading data SCNLEN." << LogIO::POST ;
  • /trunk/external-alma/atnf/PKSIO/NROReader.cc

    r2473 r2373  
    582582
    583583  // polno
    584   polno = dataset_->getPolNo( irow ) ;
     584  polno = 0 ;
    585585  //cout << "polno = " << polno << endl ;
    586586
  • /trunk/external-alma/oldasdm2ASAP/OldASDMFiller.cc

    r2473 r2373  
    7676  Vector<casa::Double> antpos = table_->getHeader().antennaposition ;
    7777
     78  //STHeader hdr = table_->getHeader() ;
     79 
    7880  // data selection
    7981  reader_->select() ;
     
    101103
    102104  // CYCLENO
     105  //unsigned int cycleno = 0 ;
    103106  map< unsigned int, unsigned int > cycleno ;
    104107  map< unsigned int, unsigned int >::iterator citer ;
     
    108111      //logsink_->postLocally( LogMessage("start configDescId "+String::toString(configDescIdList[icon])+" fieldId "+String::toString(fieldIdList[ifield]),LogOrigin(className_,funcName,WHERE)) ) ;
    109112
     113      //Bool status = reader_->setMainRow( configDescIdList[icon], fieldIdList[ifield] ) ;
    110114      if ( !(reader_->setMainRow( configDescIdList[icon], fieldIdList[ifield] )) ) {
    111115        //logsink_->postLocally( LogMessage("skip configDescId "+String::toString(configDescIdList[icon])+" fieldId "+String::toString(fieldIdList[ifield]),LogOrigin(className_,funcName,WHERE)) ) ;
     
    128132
    129133        // scan and subscan
     134        //unsigned int scanno = reader_->getScanNo() ;
    130135        unsigned int scanno = reader_->getScanNoOfCurrentRow() ;
     136        //uInt subscanno = reader_->getSubscanNo() ;
    131137        citer = cycleno.find( scanno ) ;
    132138        if ( citer == cycleno.end() )
     
    151157
    152158          // subscan number
     159          //unsigned int subscanno = reader_->getSubscanNo( idata ) ;
    153160          unsigned int subscanno = reader_->getSubscanNo() ;
    154161
    155162          // IFNO
     163          //uInt ifno = reader_->getIFNo( idata ) ;
    156164          uInt ifno = reader_->getIFNo() ;
    157165
     
    164172          double sysVel ;
    165173          vector<double> rf ;
     174          //reader_->getSourceProperty( idata,
     175          //                            srcname,
     176          //                            fieldname,
     177          //                            srcDirection,
     178          //                            srcProperMotion,
     179          //                            sysVel,
     180          //                            rf ) ;
    166181          reader_->getSourceProperty( srcname,
    167182                                      fieldname,
     
    178193         
    179194          // time and interval
     195          //casa::Double mjd = (casa::Double)(reader_->getTime( idata )) ;
     196          //casa::Double interval = (casa::Double)(reader_->getInterval( idata )) ;
    180197          casa::Double mjd = (casa::Double)(reader_->getTime()) ;
    181198          casa::Double interval = (casa::Double)(reader_->getInterval()) ;
     
    194211
    195212          // fill FLAGROW
     213          //unsigned int flagrow = reader_->getFlagRow( idata ) ;
    196214          unsigned int flagrow = reader_->getFlagRow() ;
    197215          setFlagrow( (uInt)flagrow ) ;
     
    203221          float windspeed ;
    204222          float windaz ;
     223          //reader_->getWeatherInfo( idata,
     224          //                         temperature,
     225          //                         pressure,
     226          //                         humidity,
     227          //                         windspeed,
     228          //                         windaz ) ;
    205229          reader_->getWeatherInfo( temperature,
    206230                                   pressure,
     
    219243          double el ;
    220244          vector<double> srate ;
     245          //reader_->getPointingInfo( idata,
     246          //                          dir,
     247          //                          az,
     248          //                          el,
     249          //                          srate ) ;
    221250          reader_->getPointingInfo( dir,
    222251                                    az,
     
    246275          }
    247276          else {
     277            //reader_->getFrequency( idata, refpix, refval, incr, freqref ) ;
    248278            reader_->getFrequency( refpix, refval, incr, freqref ) ;
    249279            refval = (double)toLSRK( casa::Double(refval),
     
    261291
    262292          // loop on polarization
     293          //vector<unsigned int> dataShape = reader_->getDataShape( idata ) ;
    263294          vector<unsigned int> dataShape = reader_->getDataShape() ;
    264295//           ostringstream oss ;
     
    273304          //logsink_->postLocally( LogMessage(oss.str(),LogOrigin(className_,funcName,WHERE)) ) ;
    274305                                     
     306          //int numPol = reader_->getNumPol( idata ) ;
    275307          unsigned int numPol = dataShape[0] ;
    276308          unsigned int numChan = dataShape[1] ;
     
    279311
    280312          // OPACITY
     313          //vector<float> tau = reader_->getOpacity( idata ) ;
    281314          vector<float> tau = reader_->getOpacity() ;
    282315          Vector<casa::Float> opacity = toVector( tau, numPol ) ;
    283316
    284317          // SPECTRA, FLAGTRA, TSYS, TCAL
     318          //float *sp = reader_->getSpectrum( idata ) ;
    285319          float *sp = reader_->getSpectrum() ;
    286320          vector< vector<float> > ts ;
    287321          vector< vector<float> > tc ;
     322          //reader_->getTcalAndTsys( idata, tc, ts ) ;
    288323          reader_->getTcalAndTsys( tc, ts ) ;
    289324          Matrix<casa::Float> spectra = toMatrix( sp, numPol, numChan ) ;
  • /trunk/python/asapfitter.py

    r2473 r2373  
    151151                self.x = self.data._getabcissa(row)
    152152                self.y = self.data._getspectrum(row)
    153                 #self.mask = mask_and(self.mask, self.data._getmask(row))
    154                 if len(self.x) == len(self.mask):
    155                     self.mask = mask_and(self.mask, self.data._getmask(row))
    156                 else:
    157                     asaplog.push('lengths of data and mask are not the same. preset mask will be ignored')
    158                     asaplog.post('WARN','asapfit.fit')
    159                     self.mask=self.data._getmask(row)
     153                self.mask = mask_and(self.mask, self.data._getmask(row))
    160154                asaplog.push("Fitting:")
    161155                i = row
     
    544538            return
    545539        if not self._p or self._p.is_dead:
     540            #if rcParams['plotter.gui']:
     541            #    from asap.asaplotgui import asaplotgui as asaplot
     542            #else:
     543            #    from asap.asaplot import asaplot
     544            #self._p = asaplot()
    546545            from asap.asapplotter import new_asaplot
    547             del self._p
    548546            self._p = new_asaplot(rcParams['plotter.gui'])
    549547        self._p.hold()
     
    661659            self.x = scan._getabcissa(r)
    662660            self.y = scan._getspectrum(r)
    663             #self.mask = mask_and(self.mask, scan._getmask(r))
    664             if len(self.x) == len(self.mask):
    665                 self.mask = mask_and(self.mask, self.data._getmask(row))
    666             else:
    667                 asaplog.push('lengths of data and mask are not the same. preset mask will be ignored')
    668                 asaplog.post('WARN','asapfit.fit')
    669                 self.mask=self.data._getmask(row)
     661            self.mask = mask_and(self.mask, scan._getmask(r))
    670662            self.data = None
    671663            self.fit()
  • /trunk/python/asapgrid.py

    r2473 r2373  
    88
    99class asapgrid:
    10     """
    11     The asapgrid class is defined to convolve data onto regular
    12     spatial grid. Typical usage is as follows:
    13 
    14        # create asapgrid instance with two input data
    15        g = asapgrid( ['testimage1.asap','testimage2.asap'] )
    16        # set IFNO if necessary
    17        g.setIF( 0 )
    18        # set POLNOs if necessary
    19        g.setPolList( [0,1] )
    20        # set SCANNOs if necessary
    21        g.setScanList( [22,23,24] )
    22        # define image with full specification
    23        # you can skip some parameters (see help for defineImage)
    24        g.defineImage( nx=12, ny=12, cellx='10arcsec', celly='10arcsec',
    25                       center='J2000 10h10m10s -5d05m05s' )
    26        # set convolution function
    27        g.setFunc( func='sf', width=3 )
    28        # enable min/max clipping
    29        g.enableClip()
    30        # or, disable min/max clipping
    31        #g.disableClip()
    32        # actual gridding
    33        g.grid()
    34        # save result
    35        g.save( outfile='grid.asap' )
    36        # plot result
    37        g.plot( plotchan=1246, plotpol=-1, plotgrid=True, plotobs=True )
    38     """
    3910    def __init__( self, infile ):
    40         """
    41         Create asapgrid instance.
    42 
    43         infile -- input data as a string or string list if you want
    44                   to grid more than one data at once. 
    45         """
     11        self.infile = infile
    4612        self.outfile = None
     13        self.gridder = stgrid( self.infile )
    4714        self.ifno = None
    48         self.gridder = stgrid()
    49         self.setData( infile )
    5015
    5116    def setData( self, infile ):
    52         """
    53         Set data to be processed.
    54 
    55         infile -- input data as a string or string list if you want
    56                   to grid more than one data at once. 
    57         """
    58         if isinstance( infile, str ):
    59             self.gridder._setin( infile )
    60         else:
    61             self.gridder._setfiles( infile )
    62         self.infile = infile
     17        self.gridder._setin( infile )
    6318
    6419    def setIF( self, ifno ):
    65         """
    66         Set IFNO to be processed. Currently, asapgrid allows to process
    67         only one IFNO for one gridding run even if the data contains
    68         multiple IFs. If you didn't specify IFNO, default value, which
    69         is IFNO in the first spectrum, will be processed.
    70 
    71         ifno -- IFNO to be processed.
    72         """
    7320        self.ifno = ifno
    7421        self.gridder._setif( self.ifno )
    7522
    7623    def setPolList( self, pollist ):
    77         """
    78         Set list of polarization components you want to process.
    79         If not specified, all POLNOs will be processed.
    80 
    81         pollist -- list of POLNOs.
    82         """
    8324        self.gridder._setpollist( pollist )
    8425
    8526    def setScanList( self, scanlist ):
    86         """
    87         Set list of scans you want to process. If not specified, all
    88         scans will be processed.
    89 
    90         scanlist -- list of SCANNOs.
    91         """
    9227        self.gridder._setscanlist( scanlist )
    9328
    9429    def defineImage( self, nx=-1, ny=-1, cellx='', celly='', center='' ):
    95         """
    96         Define spatial grid.
    97 
    98         First two parameters, nx and ny, define number of pixels of
    99         the grid. If which of those is not specified, it will be set
    100         to the same value as the other. If none of them are specified,
    101         it will be determined from map extent and cell size.
    102 
    103         Next two parameters, cellx and celly, define size of pixel.
    104         You should set those parameters as string, which is constructed
    105         numerical value and unit, e.g. '0.5arcmin', or numerical value.
    106         If those values are specified as numerical value, their units
    107         will be assumed to 'arcsec'. If which of those is not specified,
    108         it will be set to the same value as the other. If none of them
    109         are specified, it will be determined from map extent and number
    110         of pixels, or set to '1arcmin' if neither nx nor ny is set.
    111 
    112         The last parameter, center, define the central coordinate of
    113         the grid. You should specify its value as a string, like,
    114 
    115            'J2000 05h08m50s -16d23m30s'
    116 
    117         or
    118 
    119            'J2000 05:08:50 -16.23.30'
    120 
    121         You can omit equinox when you specify center coordinate. In that
    122         case, J2000 is assumed. If center is not specified, it will be
    123         determined from the observed positions of input data.
    124 
    125         nx -- number of pixels along x (R.A.) direction.
    126         ny -- number of pixels along y (Dec.) direction.
    127         cellx -- size of pixel in x (R.A.) direction.
    128         celly -- size of pixel in y (Dec.) direction.
    129         center -- central position of the grid.
    130         """
    131         if not isinstance( cellx, str ):
    132             cellx = '%sarcsec'%(cellx)
    133         if not isinstance( celly, str ):
    134             celly = '%sarcsec'%(celly)
    13530        self.gridder._defineimage( nx, ny, cellx, celly, center )
    13631
    13732    def setFunc( self, func='box', width=-1 ):
    138         """
    139         Set convolution function. Possible options are 'box' (Box-car,
    140         default), 'sf' (prolate spheroidal), and 'gauss' (Gaussian).
    141         Width of convolution function can be set using width parameter.
    142         By default (-1), width is automatically set depending on each
    143         convolution function. Default values for width are:
    144 
    145            'box': 1 pixel
    146            'sf': 3 pixels
    147            'gauss': 1 pixel (width is used as HWHM)
    148 
    149         func -- Function type ('box', 'sf', 'gauss').
    150         width -- Width of convolution function. Default (-1) is to
    151                  choose pre-defined value for each convolution function.
    152         """
    15333        self.gridder._setfunc( func, width )
    15434
    15535    def setWeight( self, weightType='uniform' ):
    156         """
    157         Set weight type. Possible options are 'uniform' (default),
    158         'tint' (weight by integration time), 'tsys' (weight by
    159         Tsys: 1/Tsys**2), and 'tintsys' (weight by integration time
    160         as well as Tsys: tint/Tsys**2).
    161 
    162         weightType -- weight type ('uniform', 'tint', 'tsys', 'tintsys')
    163         """
    164         self.gridder._setweight( weightType )
    165 
    166     def enableClip( self ):
    167         """
    168         Enable min/max clipping.
    169 
    170         By default, min/max clipping is disabled so that you should
    171         call this method before actual gridding if you want to do
    172         clipping.
    173         """
    174         self.gridder._enableclip()
    175 
    176     def disableClip( self ):
    177         """
    178         Disable min/max clipping.
    179         """
    180         self.gridder._disableclip()
     36        self.gridder._setweight( weightType )
    18137
    18238    def grid( self ):
    183         """
    184         Actual gridding which will be done based on several user inputs.
    185         """
    18639        self.gridder._grid()
    18740
    18841    def save( self, outfile='' ):
    189         """
    190         Save result. By default, output data name will be constructed
    191         from first element of input data name list (e.g. 'input.asap.grid').
    192 
    193         outfile -- output data name.
    194         """
    19542        self.outfile = self.gridder._save( outfile )
    19643
    197     def plot( self, plotchan=-1, plotpol=-1, plotobs=False, plotgrid=False ):
    198         """
    199         Plot gridded data.
    200 
    201         plotchan -- Which channel you want to plot. Default (-1) is
    202                     to average all the channels.
    203         plotpol -- Which polarization component you want to plot.
    204                    Default (-1) is to average all the polarization
    205                    components.
    206         plotobs -- Also plot observed position if True. Default
    207                    is False. Setting True for large amount of spectra
    208                    might be time consuming.
    209         plotgrid -- Also plot grid center if True. Default is False.
    210                     Setting True for large number of grids might be
    211                     time consuming.
    212         """
     44    def plot( self, plotchan=-1, plotpol=-1 ):
    21345        import time
    21446        t0=time.time()
     
    21749        rcParams['scantable.storage'] = 'disk'
    21850        plotter = _SDGridPlotter( self.infile, self.outfile, self.ifno )
    219         plotter.plot( chan=plotchan, pol=plotpol, plotobs=plotobs, plotgrid=plotgrid )
     51        plotter.plot( chan=plotchan, pol=plotpol )
    22052        # back to original setup
    22153        rcParams['scantable.storage'] = storg
     
    22658class _SDGridPlotter:
    22759    def __init__( self, infile, outfile=None, ifno=-1 ):
    228         if isinstance( infile, str ):
    229             self.infile = [infile]
    230         else:
    231             self.infile = infile
     60        self.infile = infile
    23261        self.outfile = outfile
    23362        if self.outfile is None:
    234             self.outfile = self.infile[0].rstrip('/')+'.grid'
     63            self.outfile = self.infile.rstrip('/')+'.grid'
    23564        self.nx = -1
    23665        self.ny = -1
     
    25079
    25180    def get( self ):
     81        self.tablein = scantable( self.infile, average=False )
     82        if self.ifno < 0:
     83            ifno = self.tablein.getif(0)
     84            print 'ifno=',ifno
     85        else:
     86            ifno = self.ifno
     87        sel = selector()
     88        sel.set_ifs( ifno )
     89        self.tablein.set_selection( sel )
     90        self.nchan = len(self.tablein._getspectrum(0))
     91        self.nrow = self.tablein.nrow()
     92        del sel
     93
    25294        s = scantable( self.outfile, average=False )
    253         self.nchan = len(s._getspectrum(0))
    25495        nrow = s.nrow()
    25596        pols = numpy.ones( nrow, dtype=int )
     
    265106        idx = 0
    266107        d0 = s.get_direction( 0 ).split()[-1]
    267         while ( s.get_direction(self.npol*idx) is not None \
    268                 and s.get_direction(self.npol*idx).split()[-1] == d0 ):
     108        while ( s.get_direction(self.npol*idx).split()[-1] == d0 ): 
    269109            idx += 1
    270110       
     
    277117        #print self.blc
    278118        #print self.trc
    279         if nrow > 1:
    280             incrx = s.get_directionval( self.npol )
    281             incry = s.get_directionval( self.nx*self.npol )
    282         else:
    283             incrx = [0.0,0.0]
    284             incry = [0.0,0.0]
     119        incrx = s.get_directionval( self.npol )
     120        incry = s.get_directionval( self.nx*self.npol )
    285121        self.cellx = abs( self.blc[0] - incrx[0] )
    286122        self.celly = abs( self.blc[1] - incry[1] )
    287123        #print 'cellx,celly=',self.cellx,self.celly
    288124
    289     def plot( self, chan=-1, pol=-1, plotobs=False, plotgrid=False ):
     125    def plot( self, chan=-1, pol=-1 ):
    290126        if pol < 0:
    291127            opt = 'averaged over pol'
    292128        else:
    293129            opt = 'pol %s'%(pol)
    294         if type(chan) is list:
    295             opt += ', averaged over channel %s-%s'%(chan[0],chan[1])
    296         elif chan < 0:
     130        if chan < 0:
    297131            opt += ', averaged over channel'
    298132        else:
    299133            opt += ', channel %s'%(chan)
    300         data = self.getData( chan, pol )
    301         data = numpy.fliplr( data )
     134        data = self.getData( chan, pol )
    302135        title = 'Gridded Image (%s)'%(opt)
    303136        pl.figure(10)
    304137        pl.clf()
    305138        # plot grid position
    306         if plotgrid:
    307             x = numpy.arange(self.blc[0],self.trc[0]+0.5*self.cellx,self.cellx,dtype=float)
    308             #print 'len(x)=',len(x)
    309             #print 'x=',x
    310             ybase = numpy.ones(self.nx,dtype=float)*self.blc[1]
    311             #print 'len(ybase)=',len(ybase)
    312             incr = self.celly
    313             for iy in xrange(self.ny):
    314                 y = ybase + iy * incr
    315                 #print y
    316                 pl.plot(x,y,',',color='blue')
     139        x = numpy.arange(self.blc[0],self.trc[0]+0.5*self.cellx,self.cellx,dtype=float)
     140        #print 'len(x)=',len(x)
     141        #print 'x=',x
     142        ybase = numpy.ones(self.nx,dtype=float)*self.blc[1]
     143        #print 'len(ybase)=',len(ybase)
     144        incr = self.celly
     145        for iy in xrange(self.ny):
     146            y = ybase + iy * incr
     147            #print y
     148            pl.plot(x,y,',',color='blue')
    317149        # plot observed position
    318         if plotobs:
    319             for i in xrange(len(self.infile)):
    320                 self.createTableIn( self.infile[i] )
    321                 irow = 0
    322                 while ( irow < self.nrow ):
    323                     chunk = self.getPointingChunk( irow )
    324                     #print chunk
    325                     pl.plot(chunk[0],chunk[1],',',color='green')
    326                     irow += chunk.shape[1]
    327                     #print irow
     150        irow = 0
     151        while ( irow < self.nrow ):
     152            chunk = self.getPointingChunk( irow )
     153            #print chunk
     154            pl.plot(chunk[0],chunk[1],',',color='green')
     155            irow += chunk.shape[1]
     156            #print irow
    328157        # show image
    329         extent=[self.trc[0]+0.5*self.cellx,
    330                 self.blc[0]-0.5*self.cellx,
     158        extent=[self.blc[0]-0.5*self.cellx,
     159                self.trc[0]+0.5*self.cellx,
    331160                self.blc[1]-0.5*self.celly,
    332161                self.trc[1]+0.5*self.celly]
    333         deccorr = 1.0/numpy.cos(0.5*(self.blc[1]+self.trc[1]))
    334162        pl.imshow(data,extent=extent,origin='lower',interpolation='nearest')
    335163        pl.colorbar()
    336164        pl.xlabel('R.A. [rad]')
    337165        pl.ylabel('Dec. [rad]')
    338         ax = pl.axes()
    339         ax.set_aspect(deccorr)
    340166        pl.title( title )
    341 
    342     def createTableIn( self, tab ):
    343         del self.tablein
    344         self.tablein = scantable( tab, average=False )
    345         if self.ifno < 0:
    346             ifno = self.tablein.getif(0)
    347             print 'ifno=',ifno
    348         else:
    349             ifno = self.ifno
    350         sel = selector()
    351         sel.set_ifs( ifno )
    352         self.tablein.set_selection( sel )
    353         self.nchan = len(self.tablein._getspectrum(0))
    354         self.nrow = self.tablein.nrow()
    355         del sel
    356        
    357167
    358168    def getPointingChunk( self, irow ):
     
    370180
    371181    def getData( self, chan=-1, pol=-1 ):
    372         if type(chan) == list:
    373             spectra = self.__chanAverage(start=chan[0],end=chan[1])
    374         elif chan == -1:
     182        if chan == -1:
    375183            spectra = self.__chanAverage()
    376184        else:
     
    381189        else:
    382190            retval = data[pol]
     191        #retval[0][self.nx-1] = -1.0
    383192        return retval
    384193
    385     def __chanAverage( self, start=-1, end=-1 ):
     194    def __chanAverage( self ):
    386195        s = scantable( self.outfile, average=False )
    387196        nrow = s.nrow()
     
    389198        irow = 0
    390199        sp = [0 for i in xrange(self.nchan)]
    391         if start < 0:
    392             start = 0
    393         if end < 0:
    394             end = self.nchan
    395200        for i in xrange(nrow/self.npol):
    396201            for ip in xrange(self.npol):
    397                 sp = s._getspectrum( irow )[start:end]
     202                sp = s._getspectrum( irow )
    398203                spectra[ip,i] = numpy.mean( sp )
    399204                irow += 1
    400            
    401205        return spectra
    402206
  • /trunk/python/asaplot.py

    r2473 r2373  
    77from matplotlib.backends.backend_agg import FigureCanvasAgg
    88from matplotlib.backend_bases import FigureManagerBase
    9 from matplotlib import _pylab_helpers
    109
    1110class asaplot(asaplotbase):
     
    2322        del v['self']
    2423        asaplotbase.__init__(self,**v)
    25         _pylab_helpers.Gcf.destroy(0)
    26         self.window = None
    2724        self.canvas = FigureCanvasAgg(self.figure)
    2825        self.figmgr = FigureManagerBase(self.canvas,1)
    29         _pylab_helpers.Gcf.figs[self.figmgr.num] = self.figmgr
    3026
    3127    def map(self):
  • /trunk/python/asaplotbase.py

    r2473 r2373  
    8282
    8383        self.buffering = buffering
    84 
    85         self.events = {'button_press':None,
    86                        'button_release':None,
    87                        'motion_notify':None}
    8884
    8985    def clear(self):
     
    558554
    559555        The set_* methods of class Line2D define the attribute names and
    560         values.  For non-US usage, 'colour' is recognized as synonymous with
    561         'color'.
     556        values.  For non-US usage, "colour" is recognized as synonymous with
     557        "color".
    562558
    563559        Set the value to None to delete an attribute.
  • /trunk/python/asaplotgui.py

    r2473 r2373  
    1010# Force use of the newfangled toolbar.
    1111matplotlib.rcParams['toolbar'] = 'toolbar2'
    12 from matplotlib import _pylab_helpers
    13 from asap.logging import asaplog, asaplog_post_dec
    1412
    1513class asaplotgui(asaplotbase):
     
    2927
    3028        asaplotbase.__init__(self, **v)
    31         #matplotlib.rcParams["interactive"] = True
     29        self.window = Tk.Tk()
     30        def dest_callback():
     31            self.is_dead = True
     32            self.window.destroy()
    3233
    33         _pylab_helpers.Gcf.destroy(0)
    34         self.window = Tk.Tk()
    35         self.window.protocol("WM_DELETE_WINDOW", self.quit)
     34        self.window.protocol("WM_DELETE_WINDOW", dest_callback)
    3635        self.canvas = FigureCanvasTkAgg(self.figure, master=self.window)
    3736        self.canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
    3837        # Simply instantiating this is enough to get a working toolbar.
    39         self.figmgr = FigureManagerTkAgg(self.canvas, 0, self.window)
    40         # Register this plot to matplotlib without activating it
    41         #_pylab_helpers.Gcf.set_active(self.figmgr)
    42         _pylab_helpers.Gcf.figs[self.figmgr.num] = self.figmgr
     38        self.figmgr = FigureManagerTkAgg(self.canvas, 1, self.window)
    4339        self._set_window_title('ASAP Plotter - Tk')
    44         self.canvas.show()
    4540
     41        self.events = {'button_press':None,
     42                       'button_release':None,
     43                       'motion_notify':None}
     44
     45        matplotlib.rcParams["interactive"] = True
     46        #self.buffering = buffering
     47
     48        self.canvas.show()
    4649
    4750    def map(self):
     
    5053        window stack.
    5154        """
    52         if self.is_dead:
    53             raise RuntimeError( "No plotter to show. Not yet plotted or plotter is closed." )
    5455        self.window.wm_deiconify()
    5556        self.window.lift()
     
    6061        """
    6162        self.is_dead = True
    62         if not self.figmgr:
    63             return
    64         #self.window.destroy()
    65         _pylab_helpers.Gcf.destroy(self.figmgr.num)
    66         del self.window, self.canvas, self.figmgr
    67         self.window = None
    68         self.canvas = None
    69         self.figmgr = None
     63        self.window.destroy()
    7064
    7165    def show(self, hardrefresh=True):
     
    7367        Show graphics dependent on the current buffering state.
    7468        """
    75         if self.is_dead:
    76             raise RuntimeError( "No plotter to show (not yet plotted or closed)." )
    7769        if not self.buffering:
    7870            if hardrefresh:
     
    8577        Clear the figure.
    8678        """
    87         if not self.window:
    88             asaplog.push( "No plotter window to terminate." )
    89             asaplog.post( "WARN" )
    90             return
    9179        self.window.destroy()
    9280
     
    9583        Hide the ASAPlot graphics window.
    9684        """
    97         if not self.window:
    98             asaplog.push( "No plotter window to unmap." )
    99             asaplog.post( "WARN" )
    100             return
    10185        self.window.wm_withdraw()
    10286
  • /trunk/python/asaplotgui_gtk.py

    r2473 r2373  
    1212matplotlib.rcParams['toolbar'] = 'toolbar2'
    1313from matplotlib.backends.backend_gtk import NavigationToolbar2GTK as NavigationToolbar
    14 from matplotlib import _pylab_helpers
    1514
    1615class asaplotgui(asaplotbase):
     
    3029
    3130        asaplotbase.__init__(self, **v)
    32         matplotlib.rcParams['interactive'] = True
    3331        matplotlib.interactive = True
    34 
    35         _pylab_helpers.Gcf.destroy(0)
    3632        self.canvas = FigureCanvas(self.figure)
    3733        # Simply instantiating this is enough to get a working toolbar.
     
    4339        self.window.connect("destroy", dest_callback )
    4440        self.window.set_title('ASAP Plotter - GTK')
     41        self.events = {'button_press':None,
     42                       'button_release':None,
     43                       'motion_notify':None}
     44
     45        self.buffering = buffering
     46        matplotlib.rcParams['interactive'] = True
    4547        #self.canvas.set_size_request(800,600)
    46         _pylab_helpers.Gcf.figs[self.figmgr.num] = self.figmgr
    4748
    4849        #self.canvas.show()
     
    5354        window stack.
    5455        """
    55         if self.is_dead:
    56             raise RuntimeError( "No plotter to show. Not yet plotted or plotter is closed." )
    5756        self.window.deiconify()
    5857        #self.window.lift()
    5958
     59#     def position(self):
     60#         """
     61#         Use the mouse to get a position from a graph.
     62#         """
     63
     64#         def position_disable(event):
     65#             self.register('button_press', None)
     66#             print '%.4f, %.4f' % (event.xdata, event.ydata)
     67
     68#         print 'Press any mouse button...'
     69#         self.register('button_press', position_disable)
     70
     71
    6072    def quit(self):
    6173        """
    6274        Destroy the ASAPlot graphics window.
    6375        """
    64         self.is_dead = True
    65         if not self.figmgr:
    66             return
    67         #self.window.destroy()
    68         _pylab_helpers.Gcf.destroy(self.figmgr.num)
    69         del self.window, self.canvas, self.figmgr
    70         self.window = None
    71         self.canvas = None
    72         self.figmgr = None
     76        self.window.destroy()
     77
     78
     79#     def region(self):
     80#         """
     81#         Use the mouse to get a rectangular region from a plot.
     82
     83#         The return value is [x0, y0, x1, y1] in world coordinates.
     84#         """
     85
     86#         def region_start(event):
     87#             height = self.canvas.figure.bbox.height()
     88#             self.rect = {'fig': None, 'height': height,
     89#                          'x': event.x, 'y': height - event.y,
     90#                          'world': [event.xdata, event.ydata,
     91#                                    event.xdata, event.ydata]}
     92#             self.register('button_press', None)
     93#             self.register('motion_notify', region_draw)
     94#             self.register('button_release', region_disable)
     95
     96#         def region_draw(event):
     97#             self.canvas._tkcanvas.delete(self.rect['fig'])
     98#             self.rect['fig'] = self.canvas._tkcanvas.create_rectangle(
     99#                                 self.rect['x'], self.rect['y'],
     100#                                 event.x, self.rect['height'] - event.y)
     101
     102#         def region_disable(event):
     103#             self.register('motion_notify', None)
     104#             self.register('button_release', None)
     105
     106#             self.canvas._tkcanvas.delete(self.rect['fig'])
     107
     108#             self.rect['world'][2:4] = [event.xdata, event.ydata]
     109#             print '(%.2f, %.2f)  (%.2f, %.2f)' % (self.rect['world'][0],
     110#                 self.rect['world'][1], self.rect['world'][2],
     111#                 self.rect['world'][3])
     112
     113#         self.register('button_press', region_start)
     114
     115#         # This has to be modified to block and return the result (currently
     116#         # printed by region_disable) when that becomes possible in matplotlib.
     117
     118#         return [0.0, 0.0, 0.0, 0.0]
     119
     120
     121#     def register(self, type=None, func=None):
     122#         """
     123#         Register, reregister, or deregister events of type 'button_press',
     124#         'button_release', or 'motion_notify'.
     125
     126#         The specified callback function should have the following signature:
     127
     128#             def func(event)
     129
     130#         where event is an MplEvent instance containing the following data:
     131
     132#             name                # Event name.
     133#             canvas              # FigureCanvas instance generating the event.
     134#             x      = None       # x position - pixels from left of canvas.
     135#             y      = None       # y position - pixels from bottom of canvas.
     136#             button = None       # Button pressed: None, 1, 2, 3.
     137#             key    = None       # Key pressed: None, chr(range(255)), shift,
     138#                                   win, or control
     139#             inaxes = None       # Axes instance if cursor within axes.
     140#             xdata  = None       # x world coordinate.
     141#             ydata  = None       # y world coordinate.
     142
     143#         For example:
     144
     145#             def mouse_move(event):
     146#                 print event.xdata, event.ydata
     147
     148#             a = asaplot()
     149#             a.register('motion_notify', mouse_move)
     150
     151#         If func is None, the event is deregistered.
     152
     153#         Note that in TkAgg keyboard button presses don't generate an event.
     154#         """
     155
     156#         if not self.events.has_key(type): return
     157
     158#         if func is None:
     159#             if self.events[type] is not None:
     160#                 # It's not clear that this does anything.
     161#                 self.canvas.mpl_disconnect(self.events[type])
     162#                 self.events[type] = None
     163
     164#                 # It seems to be necessary to return events to the toolbar.
     165#                 if type == 'motion_notify':
     166#                     self.canvas.mpl_connect(type + '_event',
     167#                         self.figmgr.toolbar.mouse_move)
     168#                 elif type == 'button_press':
     169#                     self.canvas.mpl_connect(type + '_event',
     170#                         self.figmgr.toolbar.press)
     171#                 elif type == 'button_release':
     172#                     self.canvas.mpl_connect(type + '_event',
     173#                         self.figmgr.toolbar.release)
     174
     175#         else:
     176#             self.events[type] = self.canvas.mpl_connect(type + '_event', func)
     177
    73178
    74179    def show(self, hardrefresh=True):
     
    76181        Show graphics dependent on the current buffering state.
    77182        """
    78         if self.is_dead:
    79             raise RuntimeError( "No plotter to show (not yet plotted or closed)." )
    80183        if not self.buffering:
    81184            if hardrefresh:
     
    89192        Clear the figure.
    90193        """
    91         if not self.window:
    92             asaplog.push( "No plotter window to terminate." )
    93             asaplog.post( "WARN" )
    94             return
    95194        self.window.destroy()
    96195
     
    99198        Hide the ASAPlot graphics window.
    100199        """
    101         if not self.window:
    102             asaplog.push( "No plotter window to unmap." )
    103             asaplog.post( "WARN" )
    104             return
    105200        self.window.wm_withdraw()
  • /trunk/python/asaplotgui_qt4.py

    r2473 r2373  
    2929
    3030        asaplotbase.__init__(self, **v)
    31         matplotlib.rcParams["interactive"] = True
    3231
    33         _pylab_helpers.Gcf.destroy(0)
    3432        self.canvas = FigureCanvasQTAgg(self.figure)
    3533        # Simply instantiating this is enough to get a working toolbar.
    36         self.figmgr = FigureManagerQTAgg(self.canvas, 0)
     34        self.figmgr = FigureManagerQTAgg(self.canvas, 1)
    3735        self.window = self.figmgr.window
    3836        self._set_window_title('ASAP Plotter - Qt4')
    39         # Register this plot to matplotlib without activating it
    40         #_pylab_helpers.Gcf.set_active(self.figmgr)
    41         _pylab_helpers.Gcf.figs[self.figmgr.num] = self.figmgr
     37        # register this plot to matplotlib
     38        _pylab_helpers.Gcf.set_active(self.figmgr)
    4239
    4340        #############
     
    5249        qt.QtCore.QObject.connect(self.window, qt.QtCore.SIGNAL('destroyed()'),dest_callback)
    5350
     51        self.events = {'button_press':None,
     52                       'button_release':None,
     53                       'motion_notify':None}
     54
     55        matplotlib.rcParams["interactive"] = True
     56        self.buffering = buffering
     57
    5458        self.unmap()
    5559        #self.canvas.show()
     
    6064        window stack.
    6165        """
    62         if self.is_dead:
    63             raise RuntimeError( "No plotter to show. Not yet plotted or plotter is closed." )
    6466        self.window.activateWindow()
    6567        #To raise this window to the top of the stacking order
     
    7274        """
    7375        self.is_dead = True
    74         if not self.figmgr:
    75             return
    76         try:
    77             #self.window.close()
    78             # TODO destroy casabar
    79             _pylab_helpers.Gcf.destroy(self.figmgr.num)
    80             del self.window, self.canvas, self.figmgr
    81             self.window = None
    82             self.canvas = None
    83             self.figmgr = None
     76        try: self.window.close()
    8477        except RuntimeError: pass # the window may already be closed by user
    8578
     
    8881        Show graphics dependent on the current buffering state.
    8982        """
    90         if self.is_dead:
    91             raise RuntimeError( "No plotter to show (not yet plotted or closed)." )
    9283        if not self.buffering:
    9384            if hardrefresh:
     
    10293        Clear the figure.
    10394        """
    104         if not self.window:
    105             asaplog.push( "No plotter window to terminate." )
    106             asaplog.post( "WARN" )
    107             return
    10895        self.window.close()
    10996
     
    11299        Hide the ASAPlot graphics window.
    113100        """
    114         if not self.window:
    115             asaplog.push( "No plotter window to unmap." )
    116             asaplog.post( "WARN" )
    117             return
    118101        self.window.hide()
    119102
  • /trunk/python/asapmath.py

    r2473 r2373  
    2626                  the time of the first spectrum in the first scantable
    2727                  as reference time.
    28         compel:   True forces to average overwrapped IFs.
    2928    Example:
    3029        # return a time averaged scan from scana and scanb
     
    164163    type enum is pson or psoff. The data must contains 'CAL' signal
    165164    on/off in each integration. To identify 'CAL' on state, the source type
    166     enum of poncal and poffcal need to be present.
     165    enum of poncal and poffcal need to be present in the source name field.
     166    (GBT MS data reading process to scantable automatically append these
     167    id names to the source names)
    167168
    168169    Parameters:
     
    311312        asaplog.push('Plot only first spectrum for each [if,pol] pairs to verify calibration.')
    312313        asaplog.post('WARN')
     314        #p=asaplotgui.asaplotgui()
    313315        p=new_asaplot()
    314316        #nr=min(6,len(ifnos)*len(polnos))
     
    530532        asaplog.push('Plot only first spectrum for each [if,pol] pairs to verify calibration.')
    531533        asaplog.post('WARN')
     534        #p=asaplotgui.asaplotgui()
    532535        p=new_asaplot()
    533536        #nr=min(6,len(ifnos)*len(polnos))
     
    624627    type enum is fson and fsoff. The data must contains 'CAL' signal
    625628    on/off in each integration. To identify 'CAL' on state, the source type
    626     enum of foncal and foffcal need to be present.
     629    enum of foncal and foffcal need to be present in the source name field.
     630    (GBT MS data reading via scantable automatically append these
     631    id names to the source names)
    627632
    628633    Parameters:
     
    740745        asaplog.push('Plot only first spectrum for each [if,pol] pairs to verify calibration.')
    741746        asaplog.post('WARN')
     747        #p=asaplotgui.asaplotgui()
    742748        p=new_asaplot()
    743749        #nr=min(6,len(ifnos)*len(polnos))
  • /trunk/python/asapplotter.py

    r2473 r2373  
    4545        if visible is not None:
    4646            self._visible = visible
    47         self._plotter = None
    48         self._inikwg = kwargs
     47        self._plotter = self._newplotter(**kwargs)
     48        # additional tool bar
     49        self._plotter.figmgr.casabar=self._new_custombar()
    4950
    5051        self._panelling = None
     
    5455        self._rows = None
    5556        self._cols = None
     57        self._autoplot = False
    5658        self._minmaxx = None
    5759        self._minmaxy = None
     
    7476        self._panelrows = []
    7577        self._headtext={'string': None, 'textobj': None}
    76         self._colormap = None
    77         self._linestyles = None
    78         self._legendloc = None
    7978
    8079    def _translate(self, instr):
     
    8685        return None
    8786
    88     def _reload_plotter(self):
    89         if self._plotter is not None:
    90             if  not self._plotter.is_dead:
    91                 # clear lines and axes
    92                 self._plotter.clear()
    93             if self.casabar_exists():
    94                 del self._plotter.figmgr.casabar
    95             self._plotter.quit()
    96             del self._plotter
    97         self._plotter = new_asaplot(self._visible,**self._inikwg)
    98         self._plotter.figmgr.casabar=self._new_custombar()
    99         # just to make sure they're set
    100         self._plotter.palette(color=0,colormap=self._colormap,
    101                               linestyle=0,linestyles=self._linestyles)
    102         self._plotter.legend(self._legendloc)
     87    def _newplotter(self, **kwargs):
     88        return new_asaplot(self._visible,**kwargs)
    10389
    10490    def _new_custombar(self):
     
    121107        return False
    122108
    123     def _assert_plotter(self,action="status",errmsg=None):
    124         """
    125         Check plot window status. Returns True if plot window is alive.
    126         Parameters
    127             action:    An action to take if the plotter window is not alive.
    128                        ['status'|'reload'|'halt']
    129                        The action 'status' simply returns False if asaplot
    130                        is not alive. When action='reload', plot window is
    131                        reloaded and the method returns True. Finally, an
    132                        error is raised when action='halt'.
    133             errmsg:    An error (warning) message to send to the logger,
    134                        when plot window is not alive.
    135         """
    136         if self._plotter and not self._plotter.is_dead:
    137             return True
    138         # Plotter is not alive.
    139         haltmsg = "Plotter window has not yet been loaded or is closed."
    140         if type(errmsg)==str and len(errmsg) > 0:
    141             haltmsg = errmsg
    142        
    143         if action.upper().startswith("R"):
    144             # reload plotter
    145             self._reload_plotter()
    146             return True
    147         elif action.upper().startswith("H"):
    148             # halt
    149             asaplog.push(haltmsg)
    150             asaplog.post("ERROR")
    151             raise RuntimeError(haltmsg)
    152         else:
    153             if errmsg:
    154                 asaplog.push(errmsg)
    155                 asaplog.post("WARN")
    156             return False
    157 
    158 
    159109    @asaplog_post_dec
    160110    def plot(self, scan=None):
     
    169119            are consistent e.g. all 'channel' or all 'velocity' etc.
    170120        """
     121        self._startrow = 0
     122        self._ipanel = -1
     123        self._reset_header()
     124        if self._plotter.is_dead:
     125            if self.casabar_exists():
     126                del self._plotter.figmgr.casabar
     127            self._plotter = self._newplotter()
     128            self._plotter.figmgr.casabar=self._new_custombar()
     129        if self.casabar_exists():
     130            self._plotter.figmgr.casabar.set_pagecounter(1)
     131        self._panelrows = []
     132        self._plotter.hold()
     133        #self._plotter.clear()
    171134        if not self._data and not scan:
    172135            msg = "Input is not a scantable"
    173136            raise TypeError(msg)
    174         self._startrow = 0
    175         self._ipanel = -1
    176         self._reset_header()
    177         self._panelrows = []
    178 
    179         self._assert_plotter(action="reload")
    180         if self.casabar_exists():
    181             self._plotter.figmgr.casabar.set_pagecounter(1)
    182 
    183         self._plotter.hold()
    184         #self._plotter.clear()
    185137        if scan:
    186138            self.set_data(scan, refresh=False)
    187         self._plotter.palette(color=0,colormap=self._colormap,
    188                               linestyle=0,linestyles=self._linestyles)
    189         self._plotter.legend(self._legendloc)
    190 
    191139        self._plot(self._data)
    192140        if self._minmaxy is not None:
     
    199147
    200148    def gca(self):
    201         errmsg = "No axis to retun. Need to plot first."
    202         if not self._assert_plotter(action="status",errmsg=errmsg):
    203             return None
    204149        return self._plotter.figure.gca()
    205150
    206151    def refresh(self):
    207152        """Do a soft refresh"""
    208         errmsg = "No figure to re-plot. Need to plot first."
    209         self._assert_plotter(action="halt",errmsg=errmsg)
    210 
    211153        self._plotter.figure.show()
    212154
     
    221163                        if different IFs are spread over panels (default 0)
    222164        """
    223         ## this method relies on already plotted figure
    224         if not self._assert_plotter(action="status") or (self._data is None):
    225             msg = "Cannot create mask interactively on plot. Can only create mask after plotting."
    226             asaplog.push( msg )
    227             asaplog.post( "ERROR" )
     165        if self._data is None:
    228166            return []
    229167        outmask = []
     
    272210    # forwards to matplotlib axes
    273211    def text(self, *args, **kwargs):
    274         self._assert_plotter(action="reload")
    275212        if kwargs.has_key("interactive"):
    276213            if kwargs.pop("interactive"):
     
    282219
    283220    def arrow(self, *args, **kwargs):
    284         self._assert_plotter(action="reload")
    285221        if kwargs.has_key("interactive"):
    286222            if kwargs.pop("interactive"):
     
    295231
    296232    def annotate(self, text, xy=None, xytext=None, **kwargs):
    297         self._assert_plotter(action="reload")
    298233        if kwargs.has_key("interactive"):
    299234            if kwargs.pop("interactive"):
     
    307242
    308243    def axvline(self, *args, **kwargs):
    309         self._assert_plotter(action="reload")
    310244        if kwargs.has_key("interactive"):
    311245            if kwargs.pop("interactive"):
     
    317251
    318252    def axhline(self, *args, **kwargs):
    319         self._assert_plotter(action="reload")
    320253        if kwargs.has_key("interactive"):
    321254            if kwargs.pop("interactive"):
     
    327260
    328261    def axvspan(self, *args, **kwargs):
    329         self._assert_plotter(action="reload")
    330262        if kwargs.has_key("interactive"):
    331263            if kwargs.pop("interactive"):
     
    342274
    343275    def axhspan(self, *args, **kwargs):
    344         self._assert_plotter(action="reload")
    345276        if kwargs.has_key("interactive"):
    346277            if kwargs.pop("interactive"):
     
    357288
    358289    def _axes_callback(self, axesfunc, *args, **kwargs):
    359         self._assert_plotter(action="reload")
    360290        panel = 0
    361291        if kwargs.has_key("panel"):
     
    574504        """
    575505        self._lmap = mp
    576         #self._plotter.legend(mode)
    577         self._legendloc = mode
     506        self._plotter.legend(mode)
    578507        if isinstance(fontsize, int):
    579508            from matplotlib import rc as rcp
     
    584513    def set_title(self, title=None, fontsize=None, refresh=True):
    585514        """
    586         Set the title of sub-plots. If multiple sub-plots are plotted,
     515        Set the title of the plot. If multiple panels are plotted,
    587516        multiple titles have to be specified.
    588517        Parameters:
    589             title:      a list of titles of sub-plots.
    590             fontsize:   a font size of titles (integer)
    591518            refresh:    True (default) or False. If True, the plot is
    592519                        replotted based on the new parameter setting(s).
     
    594521        Example:
    595522             # two panels are visible on the plotter
    596              plotter.set_title(['First Panel','Second Panel'])
     523             plotter.set_title(["First Panel","Second Panel"])
    597524        """
    598525        self._title = title
     
    610537            ordinate:    a list of ordinate labels. None (default) let
    611538                         data determine the labels
    612             fontsize:    a font size of vertical axis labels (integer)
    613539            refresh:     True (default) or False. If True, the plot is
    614540                         replotted based on the new parameter setting(s).
     
    616542        Example:
    617543             # two panels are visible on the plotter
    618              plotter.set_ordinate(['First Y-Axis','Second Y-Axis'])
     544             plotter.set_ordinate(["First Y-Axis","Second Y-Axis"])
    619545        """
    620546        self._ordinate = ordinate
     
    633559            abcissa:     a list of abcissa labels. None (default) let
    634560                         data determine the labels
    635             fontsize:    a font size of horizontal axis labels (integer)
    636561            refresh:     True (default) or False. If True, the plot is
    637562                         replotted based on the new parameter setting(s).
     
    639564        Example:
    640565             # two panels are visible on the plotter
    641              plotter.set_ordinate(['First X-Axis','Second X-Axis'])
     566             plotter.set_ordinate(["First X-Axis","Second X-Axis"])
    642567        """
    643568        self._abcissa = abcissa
     
    659584                        Otherwise,the parameter(s) are set without replotting.
    660585        Example:
    661              plotter.set_colors('red green blue')
     586             plotter.set_colors("red green blue")
    662587             # If for example four lines are overlaid e.g I Q U V
    663588             # 'I' will be 'red', 'Q' will be 'green', U will be 'blue'
    664589             # and 'V' will be 'red' again.
    665590        """
    666         #if isinstance(colmap,str):
    667         #    colmap = colmap.split()
    668         #self._plotter.palette(0, colormap=colmap)
    669         self._colormap = colmap
     591        if isinstance(colmap,str):
     592            colmap = colmap.split()
     593        self._plotter.palette(0, colormap=colmap)
    670594        if refresh and self._data: self.plot(self._data)
    671595
     
    680604                         is taken from the .asaprc setting
    681605                         plotter.histogram
    682             linewidth:   a line width
    683606            refresh:     True (default) or False. If True, the plot is
    684607                         replotted based on the new parameter setting(s).
     
    697620        only one color has been set.
    698621        Parameters:
    699             linestyles:      a list of linestyles to use.
     622             linestyles:     a list of linestyles to use.
    700623                             'line', 'dashed', 'dotted', 'dashdot',
    701624                             'dashdotdot' and 'dashdashdot' are
    702625                             possible
    703             linewidth:       a line width
    704626            refresh:         True (default) or False. If True, the plot is
    705627                             replotted based on the new parameter setting(s).
    706628                             Otherwise,the parameter(s) are set without replotting.
    707629        Example:
    708              plotter.set_colors('black')
    709              plotter.set_linestyles('line dashed dotted dashdot')
     630             plotter.set_colors("black")
     631             plotter.set_linestyles("line dashed dotted dashdot")
    710632             # If for example four lines are overlaid e.g I Q U V
    711633             # 'I' will be 'solid', 'Q' will be 'dashed',
    712634             # U will be 'dotted' and 'V' will be 'dashdot'.
    713635        """
    714         #if isinstance(linestyles,str):
    715         #    linestyles = linestyles.split()
    716         #self._plotter.palette(color=0,linestyle=0,linestyles=linestyles)
    717         self._linestyles = linestyles
     636        if isinstance(linestyles,str):
     637            linestyles = linestyles.split()
     638        self._plotter.palette(color=0,linestyle=0,linestyles=linestyles)
    718639        if isinstance(linewidth, float) or isinstance(linewidth, int):
    719640            from matplotlib import rc as rcp
     
    786707        If the spectrum is flagged no line will be drawn in that location.
    787708        """
    788         errmsg = "Cannot plot spectral lines. Need to plot scantable first."
    789         self._assert_plotter(action="halt",errmsg=errmsg)
    790709        if not self._data:
    791710            raise RuntimeError("No scantable has been plotted yet.")
     
    865784             dpi:         The dpi of the output non-ps plot
    866785        """
    867         errmsg = "Cannot save figure. Need to plot first."
    868         self._assert_plotter(action="halt",errmsg=errmsg)
    869        
    870786        self._plotter.save(filename,orientation,dpi)
    871787        return
     
    875791        """
    876792        Set a plotting mask for a specific polarization.
    877         This is useful for masking out 'noise' Pangle outside a source.
     793        This is useful for masking out "noise" Pangle outside a source.
    878794        Parameters:
    879795             mask:           a mask from scantable.create_mask
     
    884800        Example:
    885801             select = selector()
    886              select.setpolstrings('Pangle')
     802             select.setpolstrings("Pangle")
    887803             plotter.set_mask(mymask, select)
    888804        """
     
    13401256        PL.ion()
    13411257        PL.draw()
    1342         if matplotlib.get_backend() == 'Qt4Agg': PL.gcf().show()
     1258        PL.gcf().show()
    13431259        if (self._outfile is not None):
    13441260           PL.savefig(self._outfile)
     
    13791295        [xmin,xmax,ymin,ymax] = PL.axis()
    13801296        PL.axis([xmax,xmin,ymin,ymax])
    1381         PL.ion()
     1297        #PL.ion()
    13821298        PL.draw()
    1383         if matplotlib.get_backend() == 'Qt4Agg': PL.gcf().show()
     1299        PL.gcf().show()
    13841300        if (self._outfile is not None):
    13851301           PL.savefig(self._outfile)
     
    13891305    @asaplog_post_dec
    13901306    def plottp(self, scan=None, outfile=None):
    1391         self._assert_plotter(action="reload")
     1307        if self._plotter.is_dead:
     1308            if self.casabar_exists():
     1309                del self._plotter.figmgr.casabar
     1310            self._plotter = self._newplotter()
     1311            self._plotter.figmgr.casabar=self._new_custombar()
    13921312        self._plotter.hold()
    13931313        self._plotter.clear()
     
    14791399        See the method help for detailed information.
    14801400        """
    1481         self._assert_plotter(action="reload")
    14821401        self._plotter.text(*args, **kwargs)
    14831402    # end matplotlib.Figure.text forwarding function
     
    15181437
    15191438        if plot:
    1520             errmsg = "Can plot header only after the first call to plot()."
    1521             self._assert_plotter(action="halt",errmsg=errmsg)
    15221439            self._plotter.hold()
    15231440            self._header_plot(headstr,fontsize=fontsize)
     
    15521469            asaplog.push("No header has been plotted. Exit without any operation")
    15531470            asaplog.post("WARN")
    1554         elif self._assert_plotter(action="status"):
     1471        else:
    15551472            self._plotter.hold()
    15561473            for textobj in self._headtext['textobj']:
  • /trunk/python/customgui_tkagg.py

    r2473 r2373  
    135135        self.disable_button()
    136136        self.figmgr.window.wm_withdraw()
    137         self._p.quit()
    138137
    139138    def enable_button(self):
     
    148147        #self.bSpec.config(relief='raised', state=Tk.DISABLED)
    149148        self.bStat.config(relief='raised', state=Tk.DISABLED)
    150         self.bNext.config(state=Tk.DISABLED)
    151         self.bPrev.config(state=Tk.DISABLED)
     149        #self.bNext.config(state=Tk.DISABLED)
     150        #self.bPrev.config(state=Tk.DISABLED)
    152151        self.button = False
    153152        self.mode = ''
     
    648647        self.disable_button()
    649648        self.figmgr.window.wm_withdraw()
    650         self._p.quit()
    651649
    652650    def enable_button(self):
  • /trunk/python/flagplotter.py

    r2473 r2373  
    2727        self._scan = None
    2828        asapplotter.__init__(self,visible=visible, **kwargs)
    29         self._assert_plotter(action='reload')
    3029        self._plotter._set_window_title('Flag Plotter')
    3130        self._panelling = 'r'
     
    101100                         without writing the output. USE WITH CARE.
    102101        """
    103         if not self._data:
    104             raise RuntimeError("No scantable has been set yet.")
    105102        # simply calls scantable.save
    106103        self._data.save(name,format,overwrite)
  • /trunk/python/interactivemask.py

    r2473 r2373  
    5555            raise TypeError(msg)
    5656
    57         self.mask = _n_bools(self.scan.nchan(self.scan.getif(0)),True)
     57        self.mask = _n_bools(self.scan.nchan(),True)
    5858        self.callback = None
    5959        self.event = None
     
    9292            self.mask = self.scan.create_mask(masklist,invert=invert)
    9393        elif invert == True:
    94             self.mask = _n_bools(self.scan.nchan(self.scan.getif(0)),False)
    95         else:
    96             self.mask = _n_bools(self.scan.nchan(self.scan.getif(0)),True)
     94            self.mask = _n_bools(self.scan.nchan(),False)
     95        else:
     96            self.mask = _n_bools(self.scan.nchan(),True)
    9797
    9898
     
    157157
    158158        #if not self.p._plotter or self.p._plotter.is_dead:
    159         if not self.p:
     159        if not self.p or self.p._plotter.is_dead:
    160160            asaplog.push('A new ASAP plotter will be loaded')
    161161            asaplog.post()
     
    163163            self.p = asapplotter()
    164164            self.newplot = True
    165         self.p._assert_plotter(action='reload')
    166        
     165
    167166        # Plot selected spectra if needed
    168167        if self.scan != self.p._data:
     
    172171                asaplog.post("WARN")
    173172            # Need replot
    174             self.p._legendloc = 1
     173            self.p._plotter.legend(1)
    175174            self.p.plot(self.scan)
    176175            # disable casa toolbar
  • /trunk/python/logging.py

    r2473 r2373  
    5656            logs = self.logger.pop().strip()
    5757            if len(logs) > 0:
    58                 if rcParams['verbose']:
    59                     print >>sys.stdout, logs
    60                     if hasattr(sys.stdout, "flush"):
    61                         sys.stdout.flush()
     58                print >>sys.stdout, logs
     59                sys.stdout.flush()
    6260        self._log = ""
    6361
     
    112110        level = "INFO"
    113111        try:
    114             try:
    115                 val = f(*args, **kw)
    116                 return val
    117             except Exception, ex:
    118                 level = "ERROR"
    119                 asaplog.push(str(ex))
    120                 if rcParams['verbose']:
    121                     pass
    122                 else:
    123                     raise
     112            val = f(*args, **kw)
     113            return val
     114        except Exception, ex:
     115            level = "ERROR"
     116            asaplog.push(str(ex))
     117            if rcParams['verbose']:
     118                pass
     119            else:
     120                raise
    124121        finally:
    125122            asaplog.post(level, f.func_name)
     123            #asaplog.post(level, ".".join([f.__module__,f.func_name]))
    126124    return wrap_it
    127125
  • /trunk/python/opacity.py

    r2473 r2373  
    77from asap.selector import selector
    88from asap._asap import atmosphere
    9 from asap import rcParams
     9
    1010
    1111class model(object):
     
    151151        plot:       Plot each fit (airmass vs. Tsys). Default is 'False'
    152152    """
    153     # quiten output
    154     verbose = rcParams["verbose"]
    155     rcParams["verbose"] = False
    156     try:
     153    if plot:
     154        from matplotlib import pylab
     155    scan = _import_data(data)
     156    f = fitter()
     157    f.set_function(poly=1)
     158    sel = selector()
     159    basesel = scan.get_selection()
     160    inos = scan.getifnos()
     161    pnos = scan.getpolnos()
     162    opacities = []
     163    om = model(temperature, pressure, humidity)
     164    for ino in inos:
     165        sel.set_ifs(ino)
     166        opacity = []
     167        fits = []
     168        airms = []
     169        tsyss = []
    157170        if plot:
    158             from matplotlib import pylab
    159         scan = _import_data(data)
    160         f = fitter()
    161         f.set_function(poly=1)
    162         sel = selector()
    163         basesel = scan.get_selection()
    164         inos = scan.getifnos()
    165         pnos = scan.getpolnos()
    166         opacities = []
    167         om = model(temperature, pressure, humidity)
    168         for ino in inos:
    169             sel.set_ifs(ino)
    170             opacity = []
    171             fits = []
    172             airms = []
    173             tsyss = []
    174             if plot:
    175                 pylab.cla()
    176                 pylab.ioff()
    177                 pylab.clf()
    178                 pylab.xlabel("Airmass")
    179                 pylab.ylabel(r"$T_{sys}$")
    180             for pno in pnos:
    181                 sel.set_polarisations(pno)
    182                 scan.set_selection(basesel+sel)
    183                 freq = scan.get_coordinate(0).get_reference_value()/1e9
    184                 freqstr = "%0.4f GHz" % freq
    185                 tsys = scan.get_tsys()
    186                 elev = scan.get_elevation()
    187                 airmass = [ 1./math.sin(i) for i in elev ]
    188                 airms.append(airmass)
    189                 tsyss.append(tsys)
    190                 f.set_data(airmass, tsys)
    191                 f.fit()
    192                 fits.append(f.get_fit())
    193                 params = f.get_parameters()["params"]
    194                 opacity.append(params[1]/tsky)
     171            pylab.cla()
     172            pylab.ioff()
     173            pylab.clf()
     174            pylab.xlabel("Airmass")
     175            pylab.ylabel(r"$T_{sys}$")
     176        for pno in pnos:
     177            sel.set_polarisations(pno)
     178            scan.set_selection(basesel+sel)
     179            freq = scan.get_coordinate(0).get_reference_value()/1e9
     180            freqstr = "%0.4f GHz" % freq
     181            tsys = scan.get_tsys()
     182            elev = scan.get_elevation()
     183            airmass = [ 1./math.sin(i) for i in elev ]
     184            airms.append(airmass)
     185            tsyss.append(tsys)
     186            f.set_data(airmass, tsys)
     187            f.fit()
     188            fits.append(f.get_fit())
     189            params = f.get_parameters()["params"]
     190            opacity.append(params[1]/tsky)
     191        if averagepol:
     192            opacities.append(sum(opacity)/len(opacity))
     193        else:
     194            opacities += opacity
     195        if plot:
     196            colors = ['b','g','k']
     197            n = len(airms)
     198            for i in range(n):
     199                pylab.plot(airms[i], tsyss[i], 'o', color=colors[i])
     200                pylab.plot(airms[i], fits[i], '-', color=colors[i])
     201                pylab.figtext(0.7,0.3-(i/30.0),
     202                                  r"$\tau_{fit}=%0.2f$" % opacity[i],
     203                                  color=colors[i])
    195204            if averagepol:
    196                 opacities.append(sum(opacity)/len(opacity))
    197             else:
    198                 opacities += opacity
    199             if plot:
    200                 colors = ['b','g','k']
    201                 n = len(airms)
    202                 for i in range(n):
    203                     pylab.plot(airms[i], tsyss[i], 'o', color=colors[i])
    204                     pylab.plot(airms[i], fits[i], '-', color=colors[i])
    205                     pylab.figtext(0.7,0.3-(i/30.0),
    206                                       r"$\tau_{fit}=%0.2f$" % opacity[i],
    207                                       color=colors[i])
    208                 if averagepol:
    209                     pylab.figtext(0.7,0.3-(n/30.0),
    210                                       r"$\tau_{avg}=%0.2f$" % opacities[-1],
    211                                       color='r')
    212                     n +=1
    213205                pylab.figtext(0.7,0.3-(n/30.0),
    214                               r"$\tau_{model}=%0.2f$" % om.get_opacities(freq*1e9),
    215                               color='grey')
    216 
    217                 pylab.title("IF%d : %s" % (ino, freqstr))
    218 
    219                 pylab.ion()
    220                 pylab.draw()
    221                 raw_input("Hit <return> for next fit...")
    222             sel.reset()
    223 
    224         scan.set_selection(basesel)
    225         if plot:
    226             pylab.close()
    227         return opacities
    228     finally:
    229         rcParams["verbose"] = verbose
     206                                  r"$\tau_{avg}=%0.2f$" % opacities[-1],
     207                                  color='r')
     208                n +=1
     209            pylab.figtext(0.7,0.3-(n/30.0),
     210                          r"$\tau_{model}=%0.2f$" % om.get_opacities(freq*1e9),
     211                          color='grey')
     212
     213            pylab.title("IF%d : %s" % (ino, freqstr))
     214
     215            pylab.ion()
     216            pylab.draw()
     217            raw_input("Hit <return> for next fit...")
     218        sel.reset()
     219
     220    scan.set_selection(basesel)
     221    if plot:
     222        pylab.close()
     223    return opacities
  • /trunk/python/scantable.py

    r2473 r2373  
    1919from asap.utils import _n_bools, mask_not, mask_and, mask_or, page
    2020from asap.asapfitter import fitter
    21 
    22 ###############################################################
    23 ### WK temporarily added these lines for testing 2011/11/28 ###
    24 ###############################################################
    25 #from asap._asap import TestClass
    26 
    27 #class testclass(TestClass):
    28 #    def __init__(self, nelem):
    29 #        TestClass.__init__(self, nelem)
    30 
    31 ###############################################################
    3221
    3322
     
    275264        Parameters:
    276265
    277             name:        the name of the outputfile. For format 'ASCII'
     266            name:        the name of the outputfile. For format "ASCII"
    278267                         this is the root file name (data in 'name'.txt
    279268                         and header in 'name'_header.txt)
     
    533522
    534523            selection:    a selector object (default unset the selection), or
    535                           any combination of 'pols', 'ifs', 'beams', 'scans',
    536                           'cycles', 'name', 'query'
     524                          any combination of "pols", "ifs", "beams", "scans",
     525                          "cycles", "name", "query"
    537526
    538527        Examples::
     
    768757        return self._row_callback(self._gettsys, "Tsys")
    769758
    770     def get_tsysspectrum(self, row=-1):
    771         """\
    772         Return the channel dependent system temperatures.
    773 
    774         Parameters:
    775 
    776             row:    the rowno to get the information for. (default all rows)
    777 
    778         Returns:
    779 
    780             a list of Tsys values for the current selection
    781 
    782         """
    783         return self._get_column( self._gettsysspectrum, row )
    784759
    785760    def get_weather(self, row=-1):
     
    12021177            end:      the end frequency or period to remove
    12031178
    1204             unit:     the frequency unit (default 'MHz') or '' for
     1179            unit:     the frequency unit (default "MHz") or "" for
    12051180                      explicit lag channels
    12061181
     
    12641239        if rowno is None:
    12651240            rowno = []
     1241        if mask is None:
     1242            mask = []
    12661243        if isinstance(rowno, int):
    12671244            rowno = [rowno]
    12681245        elif not (isinstance(rowno, list) or isinstance(rowno, tuple)):
    12691246            raise TypeError("The row number(s) must be int, list or tuple.")
     1247
    12701248        if len(rowno) == 0: rowno = [i for i in xrange(self.nrow())]
    12711249
    1272         usecommonmask = True
    1273        
    1274         if mask is None:
    1275             mask = []
    1276         if isinstance(mask, list) or isinstance(mask, tuple):
    1277             if len(mask) == 0:
    1278                 mask = [[]]
    1279             else:
    1280                 if isinstance(mask[0], bool):
    1281                     if len(mask) != self.nchan(self.getif(rowno[0])):
    1282                         raise ValueError("The spectra and the mask have "
    1283                                          "different length.")
    1284                     mask = [mask]
    1285                 elif isinstance(mask[0], list) or isinstance(mask[0], tuple):
    1286                     usecommonmask = False
    1287                     if len(mask) != len(rowno):
    1288                         raise ValueError("When specifying masks for each "
    1289                                          "spectrum, the numbers of them "
    1290                                          "must be identical.")
    1291                     for i in xrange(mask):
    1292                         if len(mask[i]) != self.nchan(self.getif(rowno[i])):
    1293                             raise ValueError("The spectra and the mask have "
    1294                                              "different length.")
    1295                 else:
    1296                     raise TypeError("The mask must be a boolean list or "
    1297                                     "a list of boolean list.")
    1298         else:
     1250        if not (isinstance(mask, list) or isinstance(mask, tuple)):
    12991251            raise TypeError("The mask must be a boolean list or a list of "
    13001252                            "boolean list.")
    1301 
     1253        if len(mask) == 0: mask = [True for i in xrange(self.nchan())]
     1254        if isinstance(mask[0], bool): mask = [mask]
     1255        elif not (isinstance(mask[0], list) or isinstance(mask[0], tuple)):
     1256            raise TypeError("The mask must be a boolean list or a list of "
     1257                            "boolean list.")
     1258
     1259        usecommonmask = (len(mask) == 1)
     1260        if not usecommonmask:
     1261            if len(mask) != len(rowno):
     1262                raise ValueError("When specifying masks for each spectrum, "
     1263                                 "the numbers of them must be identical.")
     1264        for amask in mask:
     1265            if len(amask) != self.nchan():
     1266                raise ValueError("The spectra and the mask have different "
     1267                                 "length.")
     1268       
    13021269        res = []
    13031270
     
    14261393        if not (isinstance(mask,list) or isinstance(mask, tuple)):
    14271394            raise TypeError("The mask should be list or tuple.")
    1428         if len(mask) <= 0:
    1429             raise TypeError("The mask elements should be > 0")
     1395        if len(mask) < 2:
     1396            raise TypeError("The mask elements should be > 1")
    14301397        data = self._getabcissa(row)
    14311398        if len(data) != len(mask):
     
    14671434        if not (isinstance(mask,list) or isinstance(mask, tuple)):
    14681435            raise TypeError("The mask should be list or tuple.")
    1469         if len(mask) <= 0:
    1470             raise TypeError("The mask elements should be > 0")
     1436        if len(mask) < 2:
     1437            raise TypeError("The mask elements should be > 1")
    14711438        istart = []
    14721439        iend = []
     
    17541721                # provided your scantable is called scan
    17551722                selection = selector()
    1756                 selection.set_name('ORION*')
     1723                selection.set_name("ORION*")
    17571724                selection.set_ifs([1])
    17581725                scan.set_selection(selection)
     
    19951962                         The first row of the ascii file must give the column
    19961963                         names and these MUST include columns
    1997                          'ELEVATION' (degrees) and 'FACTOR' (multiply data
     1964                         "ELEVATION" (degrees) and "FACTOR" (multiply data
    19981965                         by this) somewhere.
    19991966                         The second row must give the data type of the
     
    20121979
    20131980            method:      Interpolation method when correcting from a table.
    2014                          Values are  'nearest', 'linear' (default), 'cubic'
    2015                          and 'spline'
     1981                         Values are  "nearest", "linear" (default), "cubic"
     1982                         and "spline"
    20161983
    20171984            insitu:      if False a new scantable is returned.
     
    20472014
    20482015            method:      Interpolation method for regridding the spectra.
    2049                          Choose from 'nearest', 'linear', 'cubic' (default)
    2050                          and 'spline'
     2016                         Choose from "nearest", "linear", "cubic" (default)
     2017                         and "spline"
    20512018
    20522019            insitu:      if False a new scantable is returned.
     
    20562023        """
    20572024        if insitu is None: insitu = rcParams["insitu"]
    2058         oldInsitu = self._math._insitu()
    20592025        self._math._setinsitu(insitu)
    20602026        varlist = vars()
     
    20622028        s = scantable(self._math._freq_align(self, reftime, method))
    20632029        s._add_history("freq_align", varlist)
    2064         self._math._setinsitu(oldInsitu)
    20652030        if insitu:
    20662031            self._assign(s)
     
    21382103
    21392104            method:      Interpolation method when correcting from a table.
    2140                          Values are  'nearest', 'linear', 'cubic' (default)
    2141                          and 'spline'
     2105                         Values are  "nearest", "linear", "cubic" (default)
     2106                         and "spline"
    21422107
    21432108            insitu:      if False a new scantable is returned.
     
    22222187
    22232188            poltype:    The new polarisation type. Valid types are:
    2224                         'linear', 'circular', 'stokes' and 'linpol'
     2189                        "linear", "circular", "stokes" and "linpol"
    22252190
    22262191        """
     
    23092274
    23102275    @asaplog_post_dec
    2311     def regrid_channel(self, width=5, plot=False, insitu=None):
    2312         """\
    2313         Regrid the spectra by the specified channel width
    2314 
    2315         Parameters:
    2316 
    2317             width:      The channel width (float) of regridded spectra
    2318                         in the current spectral unit.
    2319 
    2320             plot:       [NOT IMPLEMENTED YET]
    2321                         plot the original and the regridded spectra.
    2322                         In this each indivual fit has to be approved, by
    2323                         typing 'y' or 'n'
    2324 
    2325             insitu:     if False a new scantable is returned.
    2326                         Otherwise, the scaling is done in-situ
    2327                         The default is taken from .asaprc (False)
    2328 
    2329         """
    2330         if insitu is None: insitu = rcParams['insitu']
    2331         varlist = vars()
    2332 
    2333         if plot:
    2334            asaplog.post()
    2335            asaplog.push("Verification plot is not implemtnetd yet.")
    2336            asaplog.post("WARN")
    2337 
    2338         s = self.copy()
    2339         s._regrid_specchan(width)
    2340 
    2341         s._add_history("regrid_channel", varlist)
    2342 
    2343 #         if plot:
    2344 #             from asap.asapplotter import new_asaplot
    2345 #             theplot = new_asaplot(rcParams['plotter.gui'])
    2346 #             theplot.set_panels()
    2347 #             ylab=s._get_ordinate_label()
    2348 #             #theplot.palette(0,["#777777","red"])
    2349 #             for r in xrange(s.nrow()):
    2350 #                 xsm=s._getabcissa(r)
    2351 #                 ysm=s._getspectrum(r)
    2352 #                 xorg=orgscan._getabcissa(r)
    2353 #                 yorg=orgscan._getspectrum(r)
    2354 #                 theplot.clear()
    2355 #                 theplot.hold()
    2356 #                 theplot.set_axes('ylabel',ylab)
    2357 #                 theplot.set_axes('xlabel',s._getabcissalabel(r))
    2358 #                 theplot.set_axes('title',s._getsourcename(r))
    2359 #                 theplot.set_line(label='Original',color="#777777")
    2360 #                 theplot.plot(xorg,yorg)
    2361 #                 theplot.set_line(label='Smoothed',color="red")
    2362 #                 theplot.plot(xsm,ysm)
    2363 #                 ### Ugly part for legend
    2364 #                 for i in [0,1]:
    2365 #                     theplot.subplots[0]['lines'].append(
    2366 #                         [theplot.subplots[0]['axes'].lines[i]]
    2367 #                         )
    2368 #                 theplot.release()
    2369 #                 ### Ugly part for legend
    2370 #                 theplot.subplots[0]['lines']=[]
    2371 #                 res = raw_input("Accept smoothing ([y]/n): ")
    2372 #                 if res.upper() == 'N':
    2373 #                     s._setspectrum(yorg, r)
    2374 #             theplot.quit()
    2375 #             del theplot
    2376 #             del orgscan
    2377 
    2378         if insitu: self._assign(s)
    2379         else: return s
    2380 
    2381     @asaplog_post_dec
    23822276    def _parse_wn(self, wn):
    23832277        if isinstance(wn, list) or isinstance(wn, tuple):
     
    24032297                val = int(wn[:-1])
    24042298                res = [i for i in xrange(val)]
    2405             elif wn[:2] == '>=' or wn[:2] == '=>':   # cases '>=a','=>a' : return [a,-999], which is
    2406                                                      #                     then interpreted in C++
    2407                                                      #                     side as [a,a+1,...,a_nyq]
    2408                                                      #                     (CAS-3759)
     2299            elif wn[:2] == '>=' or wn[:2] == '=>':   # cases '>=a','=>a' : return [a,a+1,...,a_nyq]
    24092300                val = int(wn[2:])
    2410                 res = [val, -999]
    2411                 #res = [i for i in xrange(val, self.nchan()/2+1)]
    2412             elif wn[-2:] == '<=' or wn[-2:] == '=<': # cases 'a<=','a=<' : return [a,-999], which is
    2413                                                      #                     then interpreted in C++
    2414                                                      #                     side as [a,a+1,...,a_nyq]
    2415                                                      #                     (CAS-3759)
     2301                res = [i for i in xrange(val, self.nchan()/2+1)]
     2302            elif wn[-2:] == '<=' or wn[-2:] == '=<': # cases 'a<=','a=<' : return [a,a+1,...,a_nyq]
    24162303                val = int(wn[:-2])
    2417                 res = [val, -999]
    2418                 #res = [i for i in xrange(val, self.nchan()/2+1)]
    2419             elif wn[0] == '>':                       # case '>a' :         return [a+1,-999], which is
    2420                                                      #                     then interpreted in C++
    2421                                                      #                     side as [a+1,a+2,...,a_nyq]
    2422                                                      #                     (CAS-3759)
     2304                res = [i for i in xrange(val, self.nchan()/2+1)]
     2305            elif wn[0] == '>':                       # case '>a' :         return [a+1,a+2,...,a_nyq]
    24232306                val = int(wn[1:])+1
    2424                 res = [val, -999]
    2425                 #res = [i for i in xrange(val, self.nchan()/2+1)]
    2426             elif wn[-1] == '<':                      # case 'a<' :         return [a+1,-999], which is
    2427                                                      #                     then interpreted in C++
    2428                                                      #                     side as [a+1,a+2,...,a_nyq]
    2429                                                      #                     (CAS-3759)
     2307                res = [i for i in xrange(val, self.nchan()/2+1)]
     2308            elif wn[-1] == '<':                      # case 'a<' :         return [a+1,a+2,...,a_nyq]
    24302309                val = int(wn[:-1])+1
    2431                 res = [val, -999]
    2432                 #res = [i for i in xrange(val, self.nchan()/2+1)]
     2310                res = [i for i in xrange(val, self.nchan()/2+1)]
    24332311
    24342312            return res
     
    24792357                                        number corresponding to the Nyquist
    24802358                                        frequency for the case of FFT).
    2481                            default is [0].
     2359                           default is [].
    24822360            rejwn:         the wave numbers NOT to be used for fitting.
    24832361                           can be set just as addwn but has higher priority:
     
    25232401                workscan = self.copy()
    25242402           
    2525             #if mask          is None: mask          = [True for i in xrange(workscan.nchan())]
    2526             if mask          is None: mask          = []
     2403            if mask          is None: mask          = [True for i in xrange(workscan.nchan())]
    25272404            if applyfft      is None: applyfft      = True
    25282405            if fftmethod     is None: fftmethod     = 'fft'
    25292406            if fftthresh     is None: fftthresh     = 3.0
    2530             if addwn         is None: addwn         = [0]
     2407            if addwn         is None: addwn         = []
    25312408            if rejwn         is None: rejwn         = []
    25322409            if clipthresh    is None: clipthresh    = 3.0
     
    26032480                                         number corresponding to the Nyquist
    26042481                                         frequency for the case of FFT).
    2605                             default is [0].
     2482                            default is [].
    26062483            rejwn:          the wave numbers NOT to be used for fitting.
    26072484                            can be set just as addwn but has higher priority:
     
    26642541                workscan = self.copy()
    26652542           
    2666             #if mask           is None: mask           = [True for i in xrange(workscan.nchan())]
    2667             if mask           is None: mask           = []
     2543            if mask           is None: mask           = [True for i in xrange(workscan.nchan())]
    26682544            if applyfft       is None: applyfft       = True
    26692545            if fftmethod      is None: fftmethod      = 'fft'
    26702546            if fftthresh      is None: fftthresh      = 3.0
    2671             if addwn          is None: addwn          = [0]
     2547            if addwn          is None: addwn          = []
    26722548            if rejwn          is None: rejwn          = []
    26732549            if clipthresh     is None: clipthresh     = 3.0
     
    27602636                workscan = self.copy()
    27612637
    2762             #if mask         is None: mask         = [True for i in xrange(workscan.nchan())]
    2763             if mask         is None: mask         = []
     2638            if mask         is None: mask         = [True for i in xrange(workscan.nchan())]
    27642639            if npiece       is None: npiece       = 2
    27652640            if clipthresh   is None: clipthresh   = 3.0
     
    28632738                workscan = self.copy()
    28642739           
    2865             #if mask           is None: mask           = [True for i in xrange(workscan.nchan())]
    2866             if mask           is None: mask           = []
     2740            if mask           is None: mask           = [True for i in xrange(workscan.nchan())]
    28672741            if npiece         is None: npiece         = 2
    28682742            if clipthresh     is None: clipthresh     = 3.0
     
    29402814                workscan = self.copy()
    29412815
    2942             #if mask         is None: mask         = [True for i in \
    2943             #                                           xrange(workscan.nchan())]
    2944             if mask         is None: mask         = []
     2816            if mask         is None: mask         = [True for i in \
     2817                                                       xrange(workscan.nchan())]
    29452818            if order        is None: order        = 0
    29462819            if plot         is None: plot         = False
     
    30802953                workscan = self.copy()
    30812954
    3082             #if mask           is None: mask           = [True for i in xrange(workscan.nchan())]
    3083             if mask           is None: mask           = []
     2955            if mask           is None: mask           = [True for i in xrange(workscan.nchan())]
    30842956            if order          is None: order          = 0
    30852957            if edge           is None: edge           = (0, 0)
  • /trunk/python/utils.py

    r2473 r2373  
    8686    else:
    8787        return message
    88 
    89 def toggle_verbose():
    90     from asap import rcParams
    91     rcParams['verbose'] = not bool(rcParams['verbose'])
  • /trunk/src/CMakeLists.txt

    r2473 r2373  
    2121# source files for libpyrap
    2222set( ASAP_SRCS
    23      ${SRCDIR}/concurrent.cpp
    2423     ${SRCDIR}/MathUtils.cpp
    2524     ${SRCDIR}/TableTraverse.cpp
     
    8382     ${SRCDIR}/python_asap.cpp )
    8483
    85 add_library( ${ASAPLIB} SHARED ${ASAP_SRCS} )
    86 add_library( ${ASAPPYLIB} SHARED ${ASAP_PYSRCS} )
     84add_library( ${ASAPLIB} SHARED ${ASAP_SRCS} ${ASAP_PYSRCS} )
    8785
    8886# library name must be _asap.so
    89 set_target_properties( ${ASAPPYLIB}
     87set_target_properties( ${ASAPLIB}
    9088                       PROPERTIES
    91                        PREFIX ""
     89                       PREFIX _
    9290                       SUFFIX .so )
    9391
     
    9896                       #${CASACORE_LIBRARIES}
    9997                       ${WCSLIB} )
    100 target_link_libraries( ${ASAPPYLIB}
    101                        ${ASAPLIB} )
    10298
    103 add_dependencies( inst ${ASAPLIB}
    104                        ${ASAPPYLIB} )
     99add_dependencies( inst ${ASAPLIB} )
    105100
    106101# install directory
    107102install( TARGETS ${ASAPLIB}
    108          LIBRARY DESTINATION ${LIB_INSTALL_DIR} )
    109 install( TARGETS ${ASAPPYLIB}
    110103         LIBRARY DESTINATION ${PYTHON_INSTALL_DIR} )
    111 #if( NOT STANDALONE )
    112 #  execute_process(
    113 #    COMMAND ln -Fs ../${PYTHON_INSTALL_DIR}/_${ASAPLIB}.so ${CMAKE_INSTALL_PREFIX}/lib/_${ASAPLIB}.so
    114 #    OUTPUT_VARIABLE stuff)
    115 #endif()
     104if( NOT STANDALONE )
     105  execute_process(
     106    COMMAND ln -Fs ../${PYTHON_INSTALL_DIR}/_asap.so ${CMAKE_INSTALL_PREFIX}/lib/_asap.so
     107    OUTPUT_VARIABLE stuff)
     108endif()
  • /trunk/src/FillerBase.cpp

    r2473 r2373  
    121121  Int idx = -1 ;
    122122  for ( uInt i = 0 ; i < nEntry ; i++ ) {
    123     if ( restfreq.conform( mEntry_[i] ) &&
    124          allEQ( restfreq, mEntry_[i] ) ) {
    125       idx = i ;
    126       break ;
     123    if ( restfreq.conform( mEntry_[i] ) ) {
     124      if ( allEQ( restfreq, mEntry_[i] ) ) {
     125        idx = i ;
     126        break ;
     127      }
    127128    }
    128129  }
     
    133134    Vector<String> tmp ;
    134135    id = table_->molecules().addEntry(restfreq,tmp,tmp) ;
    135     mEntry_.push_back( restfreq.copy() ) ;
     136    mEntry_.push_back( restfreq ) ;
    136137    mIdx_.push_back( id ) ;
    137138  }
  • /trunk/src/Makefile

    r2473 r2373  
    142142HEADERS   := MathUtils.h \
    143143             LineCatalog.h \
     144             Lorentzian1D.h \
     145             Lorentzian1DParam.h \
    144146             Logger.h \
    145147             STAttr.h \
  • /trunk/src/STFitter.cpp

    r2473 r2373  
    22//# Fitter.cc: A Fitter class for spectra
    33//#--------------------------------------------------------------------------
    4 //# Copyright (C) 2004-2012
     4//# Copyright (C) 2004
    55//# ATNF
    66//#
     
    3838#include <scimath/Functionals/CompoundFunction.h>
    3939#include <scimath/Functionals/Gaussian1D.h>
    40 #include <scimath/Functionals/Lorentzian1D.h>
     40#include "Lorentzian1D.h"
    4141#include <scimath/Functionals/Sinusoid1D.h>
    4242#include <scimath/Functionals/Polynomial.h>
     
    118118    g = dynamic_cast<Gaussian1D<Float>* >(funcs_[i]);
    119119    if (g) {
    120       const GaussianSpectralElement *gauss =
    121         dynamic_cast<const GaussianSpectralElement *>(listGauss[i]) ;
    122       (*g)[0] = gauss->getAmpl();
    123       (*g)[1] = gauss->getCenter();
    124       (*g)[2] = gauss->getFWHM();     
    125       /*
    126120      (*g)[0] = listGauss[i].getAmpl();
    127121      (*g)[1] = listGauss[i].getCenter();
    128122      (*g)[2] = listGauss[i].getFWHM();
    129       */
    130123    }
    131124  }
  • /trunk/src/STGrid.cpp

    r2473 r2373  
    1 //
    2 // C++ Implementation: STGrid
    3 //
    4 // Description:
    5 //
    6 //
    7 // Author: Takeshi Nakazato <takeshi.nakazato@nao.ac.jp>, (C) 2011
    8 //
    9 // Copyright: See COPYING file that comes with this distribution
    10 //
    11 //
     1#include <iostream>
     2#include <fstream>
     3
    124#include <casa/BasicSL/String.h>
    135#include <casa/Arrays/Vector.h>
     6#include <casa/Arrays/Matrix.h>
     7#include <casa/Arrays/Cube.h>
    148#include <casa/Arrays/ArrayMath.h>
     9#include <casa/Arrays/ArrayPartMath.h>
    1510#include <casa/Quanta/Quantum.h>
    1611#include <casa/Quanta/QuantumHolder.h>
     
    2015#include <tables/Tables/Table.h>
    2116#include <tables/Tables/TableRecord.h>
    22 #include <tables/Tables/TableRow.h>
    2317#include <tables/Tables/ExprNode.h>
    2418#include <tables/Tables/ScalarColumn.h>
    2519#include <tables/Tables/ArrayColumn.h>
    26 #include <tables/Tables/TableCopy.h>
    2720
    2821#include <measures/Measures/MDirection.h>
    2922
    30 #include "MathUtils.h"
    31 #include <atnf/PKSIO/SrcType.h>
     23#include <MathUtils.h>
    3224
    3325#include "STGrid.h"
    3426
    3527using namespace std ;
    36 using namespace concurrent ;
    3728using namespace casa ;
    3829using namespace asap ;
     
    4031namespace asap {
    4132
    42 // for performance check
    43 double eToInt = 0.0 ;
    44 double eGetWeight = 0.0 ;
    45 
    4633// constructor
    4734STGrid::STGrid()
    48   : vshape_( 1 ), wshape_( 2 ), dshape_( 2 )
    4935{
    5036  init() ;
     
    5238
    5339STGrid::STGrid( const string infile )
    54   : vshape_( 1 ), wshape_( 2 ), dshape_( 2 )
    5540{
    5641  init() ;
    5742
    5843  setFileIn( infile ) ;
    59 }
    60 
    61 STGrid::STGrid( const vector<string> infile )
    62 {
    63   init() ;
    64 
    65   setFileList( infile ) ;
    6644}
    6745
     
    8260  userSupport_ = -1 ;
    8361  convSampling_ = 100 ;
    84   nprocessed_ = 0 ;
    85   nchunk_ = 0 ;
    86 
    87   // initialize user input
    88   nxUI_ = -1 ;
    89   nyUI_ = -1 ;
    90   cellxUI_ = "" ;
    91   cellyUI_ = "" ;
    92   centerUI_ = "" ;
    93   doclip_ = False ;
    9462}
    9563
    9664void STGrid::setFileIn( const string infile )
    9765{
    98   nfile_ = 1 ;
    9966  String name( infile ) ;
    100   infileList_.resize( nfile_ ) ;
    101   infileList_[0] = String(infile) ;
    102 }
    103 
    104 void STGrid::setFileList( const vector<string> infile )
    105 {
    106   nfile_ = infile.size() ;
    107   infileList_.resize( nfile_ ) ;
    108   for ( uInt i = 0 ; i < nfile_ ; i++ ) {
    109     infileList_[i] = infile[i] ;
     67  if ( infile_.compare( name ) != 0 ) {
     68    infile_ = String( infile ) ;
     69    tab_ = Table( infile_ ) ;
    11070  }
    11171}
     
    11474{
    11575  pollist_.assign( Vector<uInt>( pols ) ) ;
     76  cout << "pollist_ = " << pollist_ << endl ;
    11677}
    11778
     
    11980{
    12081  scanlist_.assign( Vector<uInt>( scans ) ) ;
     82  cout << "scanlist_ = " << scanlist_ << endl ;
    12183}
    12284
     
    12587  wtype_ = String( wType ) ;
    12688  wtype_.upcase() ;
     89  cout << "wtype_ = " << wtype_ << endl ;
    12790}
    12891
     
    13396                          string scenter )
    13497{
    135   nxUI_ = (Int)nx ;
    136   nyUI_ = (Int)ny ;
    137   cellxUI_ = String( scellx ) ;
    138   cellyUI_ = String( scelly ) ;
    139   centerUI_ = String( scenter ) ;
     98  ROArrayColumn<Double> dirCol( tab_, "DIRECTION" ) ;
     99  Matrix<Double> direction = dirCol.getColumn() ;
     100  Double rmax, rmin, dmax, dmin ;
     101  minMax( rmin, rmax, direction.row( 0 ) ) ;
     102  minMax( dmin, dmax, direction.row( 1 ) ) ;
     103
     104  Int npx = (Int)nx ;
     105  Int npy = (Int)ny ;
     106  String cellx( scellx ) ;
     107  String celly( scelly ) ;
     108  String center( scenter ) ;
     109  setupGrid( npx, npy,
     110             cellx, celly,
     111             rmin, rmax,
     112             dmin, dmax,
     113             center ) ;
    140114}
    141115 
     
    176150                Double*);
    177151}
    178 void STGrid::call_ggridsd( Array<Double> &xypos,
    179                            Array<Complex> &spectra,
    180                            Int &nvispol,
    181                            Int &nvischan,
    182                            Array<Int> &flagtra,
    183                            Array<Int> &flagrow,
    184                            Array<Float> &weight,
    185                            Int &nrow,
    186                            Int &irow,
    187                            Array<Complex> &gdata,
    188                            Array<Float> &gwgt,
    189                            Int &nx,
    190                            Int &ny,
    191                            Int &npol,
    192                            Int &nchan,
    193                            Int &support,
    194                            Int &sampling,
    195                            Vector<Float> &convFunc,
    196                            Int *chanMap,
    197                            Int *polMap )
    198 {
    199   // parameters for gridding
    200   Int idopsf = 0 ;
    201   Int len = npol*nchan ;
    202   Double *sumw_p = new Double[len] ;
    203   {
    204     Double *work_p = sumw_p ;
    205     for ( Int i = 0 ; i < len ; i++ ) {
    206       *work_p = 0.0 ;
    207       work_p++ ;
    208     }
    209   }
    210 
    211   // prepare pointer
    212   Bool deletePos, deleteData, deleteWgt, deleteFlag, deleteFlagR, deleteConv, deleteDataG, deleteWgtG ;
    213   Double *xy_p = xypos.getStorage( deletePos ) ;
    214   const Complex *values_p = spectra.getStorage( deleteData ) ;
    215   const Int *flag_p = flagtra.getStorage( deleteFlag ) ;
    216   const Int *rflag_p = flagrow.getStorage( deleteFlagR ) ;
    217   const Float *wgt_p = weight.getStorage( deleteWgt ) ;
    218   Complex *grid_p = gdata.getStorage( deleteDataG ) ;
    219   Float *wgrid_p = gwgt.getStorage( deleteWgtG ) ;
    220   Float *conv_p = convFunc.getStorage( deleteConv ) ;
    221 
    222   // pass copy of irow to ggridsd since it will be modified in theroutine
    223   Int irowCopy = irow ;
    224      
    225   // call ggridsd
    226   ggridsd( xy_p,
    227            values_p,
    228            &nvispol,
    229            &nvischan,
    230            &idopsf,
    231            flag_p,
    232            rflag_p,
    233            wgt_p,
    234            &nrow,
    235            &irowCopy,
    236            grid_p,
    237            wgrid_p,
    238            &nx,
    239            &ny,
    240            &npol,
    241            &nchan,
    242            &support,
    243            &sampling,
    244            conv_p,
    245            chanMap,
    246            polMap,
    247            sumw_p ) ;
    248 
    249   // finalization
    250   xypos.putStorage( xy_p, deletePos ) ;
    251   spectra.freeStorage( values_p, deleteData ) ;
    252   flagtra.freeStorage( flag_p, deleteFlag ) ;
    253   flagrow.freeStorage( rflag_p, deleteFlagR ) ;
    254   weight.freeStorage( wgt_p, deleteWgt ) ;
    255   gdata.putStorage( grid_p, deleteDataG ) ;
    256   gwgt.putStorage( wgrid_p, deleteWgtG ) ;
    257   convFunc.putStorage( conv_p, deleteConv ) ;
    258   delete sumw_p ;
    259 }
    260 
    261 #define NEED_UNDERSCORES
    262 #if defined(NEED_UNDERSCORES)
    263 #define ggridsd2 ggridsd2_
    264 #endif
    265 extern "C" {
    266    void ggridsd2(Double*,
    267                  const Complex*,
    268                  Int*,
    269                  Int*,
    270                  Int*,
    271                  const Int*,
    272                  const Int*,
    273                  const Float*,
    274                  Int*,
    275                  Int*,
    276                  Complex*,
    277                  Float*,
    278                  Int*,
    279                  Complex*,
    280                  Float*,
    281                  Float*,
    282                  Complex*,
    283                  Float*,
    284                  Float*,
    285                  Int*,
    286                  Int*,
    287                  Int *,
    288                  Int *,
    289                  Int*,
    290                  Int*,
    291                  Float*,
    292                  Int*,
    293                  Int*,
    294                  Double*);
    295 }
    296 void STGrid::call_ggridsd2( Array<Double> &xypos,
    297                             Array<Complex> &spectra,
    298                             Int &nvispol,
    299                             Int &nvischan,
    300                             Array<Int> &flagtra,
    301                             Array<Int> &flagrow,
    302                             Array<Float> &weight,
    303                             Int &nrow,
    304                             Int &irow,
    305                             Array<Complex> &gdata,
    306                             Array<Float> &gwgt,
    307                             Array<Int> &npoints,
    308                             Array<Complex> &clipmin,
    309                             Array<Float> &clipwmin,
    310                             Array<Float> &clipcmin,
    311                             Array<Complex> &clipmax,
    312                             Array<Float> &clipwmax,
    313                             Array<Float> &clipcmax,
    314                             Int &nx,
    315                             Int &ny,
    316                             Int &npol,
    317                             Int &nchan,
    318                             Int &support,
    319                             Int &sampling,
    320                             Vector<Float> &convFunc,
    321                             Int *chanMap,
    322                             Int *polMap )
    323 {
    324   // parameters for gridding
    325   Int idopsf = 0 ;
    326   Int len = npol*nchan ;
    327   Double *sumw_p = new Double[len] ;
    328   {
    329     Double *work_p = sumw_p ;
    330     for ( Int i = 0 ; i < len ; i++ ) {
    331       *work_p = 0.0 ;
    332       work_p++ ;
    333     }
    334   }
    335 
    336   // prepare pointer
    337   Bool deletePos, deleteData, deleteWgt, deleteFlag, deleteFlagR, deleteConv, deleteDataG, deleteWgtG, deleteNpts, deleteCMin, deleteCWMin, deleteCCMin, deleteCMax, deleteCWMax, deleteCCMax ;
    338   Double *xy_p = xypos.getStorage( deletePos ) ;
    339   const Complex *values_p = spectra.getStorage( deleteData ) ;
    340   const Int *flag_p = flagtra.getStorage( deleteFlag ) ;
    341   const Int *rflag_p = flagrow.getStorage( deleteFlagR ) ;
    342   const Float *wgt_p = weight.getStorage( deleteWgt ) ;
    343   Complex *grid_p = gdata.getStorage( deleteDataG ) ;
    344   Float *wgrid_p = gwgt.getStorage( deleteWgtG ) ;
    345   Float *conv_p = convFunc.getStorage( deleteConv ) ;
    346   Int *npts_p = npoints.getStorage( deleteNpts ) ;
    347   Complex *cmin_p = clipmin.getStorage( deleteCMin ) ;
    348   Float *cwmin_p = clipwmin.getStorage( deleteCWMin ) ;
    349   Float *ccmin_p = clipcmin.getStorage( deleteCCMin ) ;
    350   Complex *cmax_p = clipmax.getStorage( deleteCMax ) ;
    351   Float *cwmax_p = clipwmax.getStorage( deleteCWMax ) ;
    352   Float *ccmax_p = clipcmax.getStorage( deleteCCMax ) ;
    353 
    354   // pass copy of irow to ggridsd since it will be modified in theroutine
    355   Int irowCopy = irow ;
    356      
    357   // call ggridsd
    358   ggridsd2( xy_p,
    359             values_p,
    360             &nvispol,
    361             &nvischan,
    362             &idopsf,
    363             flag_p,
    364             rflag_p,
    365             wgt_p,
    366             &nrow,
    367             &irowCopy,
    368             grid_p,
    369             wgrid_p,
    370             npts_p,
    371             cmin_p,
    372             cwmin_p,
    373             ccmin_p,
    374             cmax_p,
    375             cwmax_p,
    376             ccmax_p,
    377             &nx,
    378             &ny,
    379             &npol,
    380             &nchan,
    381             &support,
    382             &sampling,
    383             conv_p,
    384             chanMap,
    385             polMap,
    386             sumw_p ) ;
    387 
    388   // finalization
    389   xypos.putStorage( xy_p, deletePos ) ;
    390   spectra.freeStorage( values_p, deleteData ) ;
    391   flagtra.freeStorage( flag_p, deleteFlag ) ;
    392   flagrow.freeStorage( rflag_p, deleteFlagR ) ;
    393   weight.freeStorage( wgt_p, deleteWgt ) ;
    394   gdata.putStorage( grid_p, deleteDataG ) ;
    395   gwgt.putStorage( wgrid_p, deleteWgtG ) ;
    396   convFunc.putStorage( conv_p, deleteConv ) ;
    397   clipmin.putStorage( cmin_p, deleteCMin ) ;
    398   clipwmin.putStorage( cwmin_p, deleteCWMin ) ;
    399   clipcmin.putStorage( ccmin_p, deleteCCMin ) ;
    400   clipmax.putStorage( cmax_p, deleteCMax ) ;
    401   clipwmax.putStorage( cwmax_p, deleteCWMax ) ;
    402   clipcmax.putStorage( ccmax_p, deleteCCMax ) ;
    403   delete sumw_p ;
    404 }
    405 
    406 void STGrid::grid()
     152void STGrid::grid()
    407153{
    408154  LogIO os( LogOrigin("STGrid", "grid", WHERE) ) ;
    409   double t0,t1 ;
    410 
    411   // data selection
     155
     156  // retrieve data
     157  Cube<Float> spectra ;
     158  Matrix<Double> direction ;
     159  Cube<uChar> flagtra ;
     160  Matrix<uInt> rflag ;
     161  Matrix<Float> weight ;
     162  double t0, t1 ;
    412163  t0 = mathutil::gettimeofday_sec() ;
    413   selectData() ;
     164  getData( spectra, direction, flagtra, rflag, weight ) ;
    414165  t1 = mathutil::gettimeofday_sec() ;
    415   os << LogIO::DEBUGGING << "selectData: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
    416 
    417   setupGrid() ;
    418   setupArray() ;
    419 
    420   if ( wtype_.compare("UNIFORM") != 0 &&
    421        wtype_.compare("TINT") != 0 &&
    422        wtype_.compare("TSYS") != 0 &&
    423        wtype_.compare("TINTSYS") != 0 ) {
    424     LogIO os( LogOrigin("STGrid", "grid", WHERE) ) ;
    425     os << LogIO::WARN << "Unsupported weight type '" << wtype_ << "', apply UNIFORM weight" << LogIO::POST ;
    426     wtype_ = "UNIFORM" ;
    427   }
    428 
     166  os << "getData: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
     167  IPosition sshape = spectra.shape() ;
     168  //os << "spectra.shape()=" << spectra.shape() << LogIO::POST ;
     169  //os << "max(spectra) = " << max(spectra) << LogIO::POST ;
     170  //os << "weight = " << weight << LogIO::POST ;
     171
     172  // flagtra: uChar -> Int
     173  // rflag: uInt -> Int
     174  Cube<Int> flagI ;
     175  Matrix<Int> rflagI ;
     176  t0 = mathutil::gettimeofday_sec() ;
     177  toInt( &flagtra, &flagI ) ;
     178  toInt( &rflag, &rflagI ) ;
     179  t1 = mathutil::gettimeofday_sec() ;
     180  os << "toInt: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
     181 
    429182  // grid parameter
    430183  os << LogIO::DEBUGGING ;
    431   os << "----------" << endl ;
    432   os << "Data selection summary" << endl ;
    433   os << "   ifno = " << ifno_ << endl ;
    434   os << "   pollist = " << pollist_ << endl ;
    435   os << "   scanlist = " << scanlist_ << endl ;
    436184  os << "----------" << endl ;
    437185  os << "Grid parameter summary" << endl ;
     
    439187  os << "   (cellx,celly) = (" << cellx_ << "," << celly_ << ")" << endl ;
    440188  os << "   center = " << center_ << endl ;
    441   os << "   weighting = " << wtype_ << endl ;
    442   os << "   convfunc = " << convType_ << " with support " << convSupport_ << endl ;
    443   os << "   doclip = " << (doclip_?"True":"False") << endl ;
    444189  os << "----------" << LogIO::POST ;
    445190  os << LogIO::NORMAL ;
    446191
    447   if ( doclip_ )
    448     gridPerRowWithClipping() ;
    449   else
    450     gridPerRow() ;
    451 }
    452 
    453 void STGrid::updateChunkShape()
    454 {
    455   // TODO: nchunk_ must be determined from nchan_, npol_, and (nx_,ny_)
    456   //       by considering data size to be allocated for ggridsd input/output
    457   nchunk_ = 400 ;
    458   nchunk_ = min( nchunk_, nrow_ ) ;
    459   vshape_ = IPosition( 1, nchunk_ ) ;
    460   wshape_ = IPosition( 2, nchan_, nchunk_ ) ;
    461   dshape_ = IPosition( 2, 2, nchunk_ ) ;
    462 }
    463 
    464 struct STGChunk {
    465   Int nrow ;
    466   Array<Complex> spectra;
    467   Array<Int> flagtra;
    468   Array<Int> rflag;
    469   Array<Float> weight;
    470   Array<Double> direction;
    471   STGChunk(IPosition const &wshape, IPosition const &vshape,
    472            IPosition const &dshape)
    473     : spectra(wshape), flagtra(wshape), rflag(vshape), weight(wshape),
    474       direction(dshape)
    475   { }
    476 };
    477 
    478 struct STCommonData {
    479   Int gnx;
    480   Int gny;
    481   Int *chanMap;
     192  // convolution kernel
    482193  Vector<Float> convFunc ;
    483   Array<Complex> gdataArrC;
    484   Array<Float> gwgtArr;
    485   STCommonData(IPosition const &gshape, Array<Float> const &data)
    486     : gdataArrC(gshape, 0.0), gwgtArr(data) {}
    487 };
    488 
    489 struct STCommonDataWithClipping {
    490   Int gnx;
    491   Int gny;
    492   Int *chanMap;
    493   Vector<Float> convFunc ;
    494   Array<Complex> gdataArrC;
    495   Array<Float> gwgtArr;
    496   Array<Int> npoints ;
    497   Array<Complex> clipMin ;
    498   Array<Float> clipWMin ;
    499   Array<Float> clipCMin ;
    500   Array<Complex> clipMax ;
    501   Array<Float> clipWMax ;
    502   Array<Float> clipCMax ; 
    503   STCommonDataWithClipping(IPosition const &gshape,
    504                            IPosition const &pshape,
    505                            Array<Float> const &data)
    506     : gdataArrC(gshape, 0.0),
    507       gwgtArr(data),
    508       npoints(pshape, 0),
    509       clipMin(gshape, Complex(FLT_MAX,0.0)),
    510       clipWMin(gshape, 0.0),
    511       clipCMin(gshape, 0.0),
    512       clipMax(gshape, Complex(-FLT_MAX,0.0)),
    513       clipWMax(gshape, 0.0),
    514       clipCMax(gshape, 0.0)
    515   {}
    516 };
    517 
    518 #define DO_AHEAD 3
    519 
    520 struct STContext {
    521   STCommonData &common;
    522   FIFO<STGChunk *, DO_AHEAD> queue;
    523   STGrid *const self;
    524   const Int pol;
    525   STContext(STGrid *obj, STCommonData &common, Int pol)
    526     : self(obj), common(common), pol(pol) {}
    527 };
    528 
    529 struct STContextWithClipping {
    530   STCommonDataWithClipping &common;
    531   FIFO<STGChunk *, DO_AHEAD> queue;
    532   STGrid *const self;
    533   const Int pol;
    534   STContextWithClipping(STGrid *obj, STCommonDataWithClipping &common, Int pol)
    535     : self(obj), common(common), pol(pol) {}
    536 };
    537 
    538 
    539 bool STGrid::produceChunk(void *ctx) throw(PCException)
    540 {
    541   STContext &context = *(STContext *)ctx;
    542   if ( context.self->nprocessed_ >= context.self->nrow_ ) {
    543     return false;
    544   }
    545   STGChunk *chunk = new STGChunk(context.self->wshape_,
    546                                  context.self->vshape_,
    547                                  context.self->dshape_);
    548 
    549   double t0 = mathutil::gettimeofday_sec() ;
    550   chunk->nrow = context.self->getDataChunk(
    551         context.self->wshape_, context.self->vshape_, context.self->dshape_,
    552         chunk->spectra, chunk->direction,
    553         chunk->flagtra, chunk->rflag, chunk->weight);
    554   double t1 = mathutil::gettimeofday_sec() ;
    555   context.self->eGetData_ += t1-t0 ;
    556 
    557   context.queue.lock();
    558   context.queue.put(chunk);
    559   context.queue.unlock();
    560   return true;
    561 }
    562 
    563 void STGrid::consumeChunk(void *ctx) throw(PCException)
    564 {
    565   STContext &context = *(STContext *)ctx;
    566   STGChunk *chunk = NULL;
    567   try {
    568     context.queue.lock();
    569     chunk = context.queue.get();
    570     context.queue.unlock();
    571   } catch (FullException &e) {
    572     context.queue.unlock();
    573     // TODO: log error
    574     throw PCException();
    575   }
    576 
    577   double t0, t1 ;
     194  t0 = mathutil::gettimeofday_sec() ;
     195  setConvFunc( convFunc ) ;
     196  t1 = mathutil::gettimeofday_sec() ;
     197  os << "setConvFunc: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
     198  //cout << "convSupport=" << convSupport_ << endl ;
     199  //cout << "convFunc=" << convFunc << endl ;
     200
    578201  // world -> pixel
    579   Array<Double> xypos( context.self->dshape_ ) ;
     202  Matrix<Double> xypos( direction.shape(), 0.0 ) ;
    580203  t0 = mathutil::gettimeofday_sec() ;
    581   context.self->toPixel( chunk->direction, xypos ) ;
     204  toPixel( direction, xypos ) ; 
    582205  t1 = mathutil::gettimeofday_sec() ;
    583   context.self->eToPixel_ += t1-t0 ;
    584    
     206  os << "toPixel: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
     207 
    585208  // call ggridsd
    586   Int nvispol = 1 ;
     209  Bool deletePos, deleteData, deleteWgt, deleteFlag, deleteFlagR, deleteConv, deleteDataG, deleteWgtG ;
     210  Double *xypos_p = xypos.getStorage( deletePos ) ;
     211  Cube<Complex> dataC( spectra.shape(), 0.0 ) ;
     212  setReal( dataC, spectra ) ;
     213  const Complex *data_p = dataC.getStorage( deleteData ) ;
     214  const Float *wgt_p = weight.getStorage( deleteWgt ) ;
     215  const Int *flag_p = flagI.getStorage( deleteFlag ) ;
     216  const Int *rflag_p = rflagI.getStorage( deleteFlagR ) ;
     217  Float *conv_p = convFunc.getStorage( deleteConv ) ;
     218  // Extend grid plane with convSupport_
     219  Int gnx = nx_ ;
     220  Int gny = ny_ ;
     221//   Int gnx = nx_+convSupport_*2 ;
     222//   Int gny = ny_+convSupport_*2 ;
     223  IPosition gshape( 4, gnx, gny, npol_, nchan_ ) ;
     224  Array<Complex> gdataArrC( gshape, 0.0 ) ;
     225  Array<Float> gwgtArr( gshape, 0.0 ) ;
     226  Complex *gdata_p = gdataArrC.getStorage( deleteDataG ) ;
     227  Float *wdata_p = gwgtArr.getStorage( deleteWgtG ) ;
     228  Int idopsf = 0 ;
     229  Int *chanMap = new Int[nchan_] ;
     230  {
     231    Int *work_p = chanMap ;
     232    for ( Int i = 0 ; i < nchan_ ; i++ ) {
     233      *work_p = i ;
     234      work_p++ ;
     235    }
     236  }
     237  Int *polMap = new Int[npol_] ;
     238  {
     239    Int *work_p = polMap ;
     240    for ( Int i = 0 ; i < npol_ ; i++ ) {
     241      *work_p = i ;
     242      work_p++ ;
     243    }
     244  }
     245  Double *sumw_p = new Double[npol_*nchan_] ;
     246  {
     247    Double *work_p = sumw_p ;
     248    for ( Int i = 0 ; i < npol_*nchan_ ; i++ ) {
     249      *work_p = 0.0 ;
     250      work_p++ ;
     251    }
     252  }
     253  t0 = mathutil::gettimeofday_sec() ;
    587254  Int irow = -1 ;
    588   t0 = mathutil::gettimeofday_sec() ;
    589   context.self->call_ggridsd( xypos,
    590                 chunk->spectra,
    591                 nvispol,
    592                 context.self->nchan_,
    593                 chunk->flagtra,
    594                 chunk->rflag,
    595                 chunk->weight,
    596                 chunk->nrow,
    597                 irow,
    598                 context.common.gdataArrC,
    599                 context.common.gwgtArr,
    600                 context.common.gnx,
    601                 context.common.gny,
    602                 context.self->npol_,
    603                 context.self->nchan_,
    604                 context.self->convSupport_,
    605                 context.self->convSampling_,
    606                 context.common.convFunc,
    607                 context.common.chanMap,
    608                 (Int*)&context.pol ) ;
     255  ggridsd( xypos_p,
     256           data_p,
     257           &npol_,
     258           &nchan_,
     259           &idopsf,
     260           flag_p,
     261           rflag_p,
     262           wgt_p,
     263           &nrow_,
     264           &irow,
     265           gdata_p,
     266           wdata_p,
     267           &gnx,
     268           &gny,
     269           &npol_,
     270           &nchan_,
     271           &convSupport_,
     272           &convSampling_,
     273           conv_p,
     274           chanMap,
     275           polMap,
     276           sumw_p ) ;
    609277  t1 = mathutil::gettimeofday_sec() ;
    610   context.self->eGGridSD_ += t1-t0 ;
    611  
    612   delete chunk;
    613 }
    614 
    615 void STGrid::gridPerRow()
    616 {
    617   LogIO os( LogOrigin("STGrid", "gridPerRow", WHERE) ) ;
    618   double t0, t1 ;
    619 
    620 
    621   // grid data
    622   // Extend grid plane with convSupport_
    623   //   Int gnx = nx_+convSupport_*2 ;
    624   //   Int gny = ny_+convSupport_*2 ;
    625   Int gnx = nx_;
    626   Int gny = ny_;
    627 
    628   IPosition gshape( 4, gnx, gny, npol_, nchan_ ) ;
    629   // 2011/12/20 TN
    630   // data_ and gwgtArr share storage
    631   data_.resize( gshape ) ;
    632   data_ = 0.0 ;
    633   STCommonData common = STCommonData(gshape, data_);
    634   common.gnx = gnx ;
    635   common.gny = gny ;
    636 
    637   // parameters for gridding
    638   Int *chanMap = new Int[nchan_] ;
    639   for ( Int i = 0 ; i < nchan_ ; i++ ) {
    640     chanMap[i] = i ;
    641   }
    642   common.chanMap = chanMap;
    643 
    644   // convolution kernel
    645   t0 = mathutil::gettimeofday_sec() ;
    646   setConvFunc( common.convFunc ) ;
    647   t1 = mathutil::gettimeofday_sec() ;
    648   os << LogIO::DEBUGGING << "setConvFunc: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
    649 
    650   // for performance check
    651   eGetData_ = 0.0 ;
    652   eToPixel_ = 0.0 ;
    653   eGGridSD_ = 0.0 ;
    654   double eInitPol = 0.0 ;
    655 
    656   for ( uInt ifile = 0 ; ifile < nfile_ ; ifile++ ) {
    657     initTable( ifile ) ;
    658 
    659     os << "start table " << ifile << ": " << infileList_[ifile] << LogIO::POST ;   
    660     Broker broker = Broker(produceChunk, consumeChunk);
    661     for ( Int ipol = 0 ; ipol < npol_ ; ipol++ ) {
    662       t0 = mathutil::gettimeofday_sec() ;
    663       initPol( ipol ) ; // set ptab_ and attach()
    664       t1 = mathutil::gettimeofday_sec() ;
    665       eInitPol += t1-t0 ;
    666      
    667       STContext context(this, common, ipol);
    668      
    669       os << "start pol " << ipol << LogIO::POST ;
    670      
    671       nprocessed_ = 0 ;
    672 #if 1
    673       broker.runProducerAsMasterThread(&context, DO_AHEAD);
    674 #else
    675       for (;;) {
    676         bool produced = produceChunk(&context);
    677         if (! produced) {
    678           break;
    679         }
    680         consumeChunk(&context);
    681       }
    682 #endif
    683 
    684       os << "end pol " << ipol << LogIO::POST ;
    685 
    686     }
    687     os << "end table " << ifile << LogIO::POST ;   
    688   }
    689   os << LogIO::DEBUGGING << "initPol: elapsed time is " << eInitPol << " sec." << LogIO::POST ;
    690   os << LogIO::DEBUGGING << "getData: elapsed time is " << eGetData_-eToInt-eGetWeight << " sec." << LogIO::POST ;
    691   os << LogIO::DEBUGGING << "toPixel: elapsed time is " << eToPixel_ << " sec." << LogIO::POST ;
    692   os << LogIO::DEBUGGING << "ggridsd: elapsed time is " << eGGridSD_ << " sec." << LogIO::POST ;
    693   os << LogIO::DEBUGGING << "toInt: elapsed time is " << eToInt << " sec." << LogIO::POST ;
    694   os << LogIO::DEBUGGING << "getWeight: elapsed time is " << eGetWeight << " sec." << LogIO::POST ;
    695  
     278  os << "ggridsd: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
     279  xypos.putStorage( xypos_p, deletePos ) ;
     280  dataC.freeStorage( data_p, deleteData ) ;
     281  weight.freeStorage( wgt_p, deleteWgt ) ;
     282  flagI.freeStorage( flag_p, deleteFlag ) ;
     283  rflagI.freeStorage( rflag_p, deleteFlagR ) ;
     284  convFunc.putStorage( conv_p, deleteConv ) ;
     285  delete polMap ;
    696286  delete chanMap ;
    697 
    698   // set data
    699   setData( common.gdataArrC, common.gwgtArr ) ;
    700 
    701 }
    702 
    703 void STGrid::consumeChunkWithClipping(void *ctx) throw(PCException)
    704 {
    705   STContextWithClipping &context = *(STContextWithClipping *)ctx;
    706   STGChunk *chunk = NULL;
    707   try {
    708     context.queue.lock();
    709     chunk = context.queue.get();
    710     context.queue.unlock();
    711   } catch (FullException &e) {
    712     context.queue.unlock();
    713     // TODO: log error
    714     throw PCException();
    715   }
    716 
    717   double t0, t1 ;
    718   // world -> pixel
    719   Array<Double> xypos( context.self->dshape_ ) ;
    720   t0 = mathutil::gettimeofday_sec() ;
    721   context.self->toPixel( chunk->direction, xypos ) ;
    722   t1 = mathutil::gettimeofday_sec() ;
    723   context.self->eToPixel_ += t1-t0 ;
    724    
    725   // call ggridsd
    726   Int nvispol = 1 ;
    727   Int irow = -1 ;
    728   t0 = mathutil::gettimeofday_sec() ;
    729   context.self->call_ggridsd2( xypos,
    730                 chunk->spectra,
    731                 nvispol,
    732                 context.self->nchan_,
    733                 chunk->flagtra,
    734                 chunk->rflag,
    735                 chunk->weight,
    736                 chunk->nrow,
    737                 irow,
    738                 context.common.gdataArrC,
    739                 context.common.gwgtArr,
    740                 context.common.npoints,
    741                 context.common.clipMin,
    742                 context.common.clipWMin,
    743                 context.common.clipCMin,
    744                 context.common.clipMax,
    745                 context.common.clipWMax,
    746                 context.common.clipCMax,
    747                 context.common.gnx,
    748                 context.common.gny,
    749                 context.self->npol_,
    750                 context.self->nchan_,
    751                 context.self->convSupport_,
    752                 context.self->convSampling_,
    753                 context.common.convFunc,
    754                 context.common.chanMap,
    755                 (Int*)&context.pol ) ;
    756   t1 = mathutil::gettimeofday_sec() ;
    757   context.self->eGGridSD_ += t1-t0 ;
    758  
    759   delete chunk;
    760 }
    761 
    762 void STGrid::gridPerRowWithClipping()
    763 {
    764   LogIO os( LogOrigin("STGrid", "gridPerRowWithClipping", WHERE) ) ;
    765   double t0, t1 ;
    766 
    767 
    768   // grid data
    769   // Extend grid plane with convSupport_
    770   //   Int gnx = nx_+convSupport_*2 ;
    771   //   Int gny = ny_+convSupport_*2 ;
    772   Int gnx = nx_;
    773   Int gny = ny_;
    774 
    775   IPosition gshape( 4, gnx, gny, npol_, nchan_ ) ;
    776   IPosition pshape( 3, gnx, gny, npol_ ) ;
    777   // 2011/12/20 TN
    778   // data_ and gwgtArr share storage
    779   data_.resize( gshape ) ;
    780   data_ = 0.0 ;
    781   STCommonDataWithClipping common = STCommonDataWithClipping( gshape,
    782                                                               pshape,
    783                                                               data_ ) ;
    784   common.gnx = gnx ;
    785   common.gny = gny ;
    786 
    787   // parameters for gridding
    788   Int *chanMap = new Int[nchan_] ;
    789   for ( Int i = 0 ; i < nchan_ ; i++ ) {
    790     chanMap[i] = i ;
    791   }
    792   common.chanMap = chanMap;
    793 
    794   // convolution kernel
    795   t0 = mathutil::gettimeofday_sec() ;
    796   setConvFunc( common.convFunc ) ;
    797   t1 = mathutil::gettimeofday_sec() ;
    798   os << LogIO::DEBUGGING << "setConvFunc: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
    799 
    800   // for performance check
    801   eGetData_ = 0.0 ;
    802   eToPixel_ = 0.0 ;
    803   eGGridSD_ = 0.0 ;
    804   double eInitPol = 0.0 ;
    805 
    806   for ( uInt ifile = 0 ; ifile < nfile_ ; ifile++ ) {
    807     initTable( ifile ) ;
    808 
    809     os << "start table " << ifile << ": " << infileList_[ifile] << LogIO::POST ;   
    810     Broker broker = Broker(produceChunk, consumeChunkWithClipping);
    811     for ( Int ipol = 0 ; ipol < npol_ ; ipol++ ) {
    812       t0 = mathutil::gettimeofday_sec() ;
    813       initPol( ipol ) ; // set ptab_ and attach()
    814       t1 = mathutil::gettimeofday_sec() ;
    815       eInitPol += t1-t0 ;
    816      
    817       STContextWithClipping context(this, common, ipol);
    818      
    819       os << "start pol " << ipol << LogIO::POST ;
    820      
    821       nprocessed_ = 0 ;
    822 #if 1
    823       broker.runProducerAsMasterThread(&context, DO_AHEAD);
    824 #else
    825       for (;;) {
    826         bool produced = produceChunk(&context);
    827         if (! produced) {
    828           break;
    829         }
    830         consumeChunkWithClipping(&context);
    831       }
    832 #endif
    833 
    834       os << "end pol " << ipol << LogIO::POST ;
    835 
    836     }
    837     os << "end table " << ifile << LogIO::POST ;   
    838   }
    839   os << LogIO::DEBUGGING << "initPol: elapsed time is " << eInitPol << " sec." << LogIO::POST ;
    840   os << LogIO::DEBUGGING << "getData: elapsed time is " << eGetData_-eToInt-eGetWeight << " sec." << LogIO::POST ;
    841   os << LogIO::DEBUGGING << "toPixel: elapsed time is " << eToPixel_ << " sec." << LogIO::POST ;
    842   os << LogIO::DEBUGGING << "ggridsd2: elapsed time is " << eGGridSD_ << " sec." << LogIO::POST ;
    843   os << LogIO::DEBUGGING << "toInt: elapsed time is " << eToInt << " sec." << LogIO::POST ;
    844   os << LogIO::DEBUGGING << "getWeight: elapsed time is " << eGetWeight << " sec." << LogIO::POST ;
    845  
    846   delete chanMap ;
    847 
    848   // clip min and max in each grid
    849 //   os << "BEFORE CLIPPING" << LogIO::POST ;
    850 //   os << "gdataArrC=" << common.gdataArrC << LogIO::POST ;
    851 //   os << "gwgtArr=" << common.gwgtArr << LogIO::POST ;
    852   t0 = mathutil::gettimeofday_sec() ;
    853   clipMinMax( common.gdataArrC,
    854               common.gwgtArr,
    855               common.npoints,
    856               common.clipMin,
    857               common.clipWMin,
    858               common.clipCMin,
    859               common.clipMax,
    860               common.clipWMax,
    861               common.clipCMax ) ;
    862   t1 = mathutil::gettimeofday_sec() ;
    863   os << LogIO::DEBUGGING << "clipMinMax: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
    864 //   os << "AFTER CLIPPING" << LogIO::POST ;
    865 //   os << "gdataArrC=" << common.gdataArrC << LogIO::POST ;
    866 //   os << "gwgtArr=" << common.gwgtArr << LogIO::POST ;
    867 
    868   // set data
    869   setData( common.gdataArrC, common.gwgtArr ) ;
    870 
    871 }
    872 
    873 void STGrid::clipMinMax( Array<Complex> &grid,
    874                          Array<Float> &weight,
    875                          Array<Int> &npoints,
    876                          Array<Complex> &clipmin,
    877                          Array<Float> &clipwmin,
    878                          Array<Float> &clipcmin,
    879                          Array<Complex> &clipmax,
    880                          Array<Float> &clipwmax,
    881                          Array<Float> &clipcmax )
    882 {
    883   //LogIO os( LogOrigin("STGrid","clipMinMax",WHERE) ) ;
    884 
    885   // prepare pointers
    886   Bool delG, delW, delNP, delCMin, delCWMin, delCCMin, delCMax, delCWMax, delCCMax ;
    887   Complex *grid_p = grid.getStorage( delG ) ;
    888   Float *wgt_p = weight.getStorage( delW ) ;
    889   const Int *npts_p = npoints.getStorage( delNP ) ;
    890   const Complex *cmin_p = clipmin.getStorage( delCMin ) ;
    891   const Float *cwmin_p = clipwmin.getStorage( delCWMin ) ;
    892   const Float *ccmin_p = clipcmin.getStorage( delCCMin ) ;
    893   const Complex *cmax_p = clipmax.getStorage( delCMax ) ;
    894   const Float *cwmax_p = clipwmax.getStorage( delCWMax ) ;
    895   const Float *ccmax_p = clipcmax.getStorage( delCCMax ) ;
    896 
    897   const IPosition &gshape = grid.shape() ;
    898   long offset = gshape[0] * gshape[1] * gshape[2] ; // nx * ny * npol
    899   Int nchan = gshape[3] ;
    900   long origin = nchan * offset ;
    901   for ( long i = 0 ; i < offset ; i++ ) {
    902     if ( *npts_p > 2 ) {
    903       for ( Int ichan = 0 ; ichan < nchan ; ichan++ ) {
    904         // clip minimum and maximum
    905         *grid_p -= (*cmin_p)*(*cwmin_p)*(*ccmin_p)
    906           + (*cmax_p)*(*cwmax_p)*(*ccmax_p) ;
    907         *wgt_p -= (*cwmin_p)*(*ccmin_p)
    908           + (*cwmax_p)*(*ccmax_p) ;
    909        
    910         grid_p += offset ;
    911         wgt_p += offset ;
    912         cmin_p += offset ;
    913         cwmin_p += offset ;
    914         ccmin_p += offset ;
    915         cmax_p += offset ;
    916         cwmax_p += offset ;
    917         ccmax_p += offset ;
    918       }
    919       grid_p -= origin ;
    920       wgt_p -= origin ;
    921       cmin_p -= origin ;
    922       cwmin_p -= origin ;
    923       ccmin_p -= origin ;
    924       cmax_p -= origin ;
    925       cwmax_p -= origin ;
    926       ccmax_p -= origin ;
    927     }
    928     grid_p++ ;
    929     wgt_p++ ;
    930     npts_p++ ;
    931     cmin_p++ ;
    932     cwmin_p++ ;
    933     ccmin_p++ ;
    934     cmax_p++ ;
    935     cwmax_p++ ;
    936     ccmax_p++ ;
    937   }
    938   grid_p -= offset ;
    939   wgt_p -= offset ;
    940   npts_p -= offset ;
    941   cmin_p -= offset ;
    942   cwmin_p -= offset ;
    943   ccmin_p -= offset ;
    944   cmax_p -= offset ;
    945   cwmax_p -= offset ;
    946   ccmax_p -= offset ; 
    947 
    948   // finalization
    949   grid.putStorage( grid_p, delG ) ;
    950   weight.putStorage( wgt_p, delW ) ;
    951   npoints.freeStorage( npts_p, delNP ) ;
    952   clipmin.freeStorage( cmin_p, delCMin ) ;
    953   clipwmin.freeStorage( cwmin_p, delCWMin ) ;
    954   clipcmin.freeStorage( ccmin_p, delCCMin ) ;
    955   clipmax.freeStorage( cmax_p, delCMax ) ;
    956   clipwmax.freeStorage( cwmax_p, delCWMax ) ;
    957   clipcmax.freeStorage( ccmax_p, delCCMax ) ;
    958 }
    959 
    960 void STGrid::initPol( Int ipol )
    961 {
    962   LogIO os( LogOrigin("STGrid","initPol",WHERE) ) ;
    963   if ( npolOrg_ == 1 ) {
    964     os << "single polarization data." << LogIO::POST ;
    965     ptab_ = tab_ ;
    966   }
    967   else
    968     ptab_ = tab_( tab_.col("POLNO") == pollist_[ipol] ) ;
    969 
    970   attach( ptab_ ) ;
    971 }
    972 
    973 void STGrid::initTable( uInt idx )
    974 {
    975   tab_ = tableList_[idx] ;
    976   nrow_ = rows_[idx] ;
    977   updateChunkShape() ;
    978 }
    979 
    980 void STGrid::setData( Array<Complex> &gdata,
     287  gdataArrC.putStorage( gdata_p, deleteDataG ) ;
     288  gwgtArr.putStorage( wdata_p, deleteWgtG ) ;
     289  Array<Float> gdataArr = real( gdataArrC ) ;
     290  setData( data_, gdataArr, gwgtArr ) ;
     291  //Matrix<Double> sumWeight( IPosition( 2, npol_, nchan_ ), sumw_p, TAKE_OVER ) ;
     292  delete sumw_p ;
     293  //cout << "sumWeight = " << sumWeight << endl ;
     294//   os << "gdataArr = " << gdataArr << LogIO::POST ;
     295//   os << "gwgtArr = " << gwgtArr << LogIO::POST ;
     296//   os << "data_ " << data_ << LogIO::POST ;
     297}
     298
     299void STGrid::setData( Array<Float> &data,
     300                      Array<Float> &gdata,
    981301                      Array<Float> &gwgt )
    982302{
    983   // 2011/12/20 TN
    984   // gwgt and data_ share storage
    985303  LogIO os( LogOrigin("STGrid","setData",WHERE) ) ;
    986304  double t0, t1 ;
    987305  t0 = mathutil::gettimeofday_sec() ;
    988   uInt len = data_.nelements() ;
    989   const Complex *w1_p ;
    990   Float *w2_p ;
    991   Bool b1, b2 ;
    992   const Complex *gdata_p = gdata.getStorage( b1 ) ;
    993   Float *gwgt_p = data_.getStorage( b2 ) ;
     306  data.resize( gdata.shape() ) ;
     307  uInt len = data.nelements() ;
     308  Float *w0_p ;
     309  const Float *w1_p, *w2_p ;
     310  Bool b0, b1, b2 ;
     311  Float *data_p = data.getStorage( b0 ) ;
     312  const Float *gdata_p = gdata.getStorage( b1 ) ;
     313  const Float *gwgt_p = gwgt.getStorage( b2 ) ;
     314  w0_p = data_p ;
    994315  w1_p = gdata_p ;
    995316  w2_p = gwgt_p ;
    996317  for ( uInt i = 0 ; i < len ; i++ ) {
    997     if ( *w2_p > 0.0 ) *w2_p = (*w1_p).real() / *w2_p ;
     318    *w0_p = (*w2_p > 0.0) ? (*w1_p / *w2_p) : 0.0 ;
     319    w0_p++ ;
    998320    w1_p++ ;
    999321    w2_p++ ;
    1000322  }
     323  data.putStorage( data_p, b0 ) ;
    1001324  gdata.freeStorage( gdata_p, b1 ) ;
    1002   data_.putStorage( gwgt_p, b2 ) ;
     325  gwgt.freeStorage( gwgt_p, b2 ) ;
    1003326  t1 = mathutil::gettimeofday_sec() ;
    1004   os << LogIO::DEBUGGING << "setData: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
    1005 }
    1006 
    1007 void STGrid::setupGrid()
    1008 {
    1009   Double xmin,xmax,ymin,ymax ;
    1010   mapExtent( xmin, xmax, ymin, ymax ) ;
    1011  
    1012   setupGrid( nxUI_, nyUI_, cellxUI_, cellyUI_,
    1013              xmin, xmax, ymin, ymax, centerUI_ ) ;
     327  os << "setData: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
    1014328}
    1015329
     
    1024338                        String &center )
    1025339{
    1026   LogIO os( LogOrigin("STGrid","setupGrid",WHERE) ) ;
    1027340  //cout << "nx=" << nx << ", ny=" << ny << endl ;
    1028341
     
    1058371    center_(0) = xcen.getValue( "rad" ) ;
    1059372    center_(1) = ycen.getValue( "rad" ) ;
    1060     double base = 0.5 * (xmin + xmax) ;
    1061     int maxrotate = 1 ;
    1062     int nelem = 2 * maxrotate + 1 ;
    1063     double *sep = new double[nelem] ;
    1064     for ( int i = 0 ; i < nelem ; i++ )
    1065       sep[i] = abs(base - center_[0] - (i-maxrotate) * C::_2pi) ;
    1066 //     os << "sep[0]=" << sep[0] << endl 
    1067 //        << "sep[1]=" << sep[1] << endl
    1068 //        << "sep[2]=" << sep[2] << LogIO::POST ;
    1069     int idx = 0 ;
    1070     base = sep[0] ;
    1071     int nrotate = 0 ;
    1072     while ( idx < nelem ) {
    1073       if ( base > sep[idx] ) {
    1074         base = sep[idx] ;
    1075         nrotate = idx ;
    1076       }
    1077       idx++ ;
    1078     }
    1079     delete sep ;
    1080     nrotate -= maxrotate ;
    1081 //     os << "nrotate = " << nrotate << LogIO::POST ;
    1082     center_[0] += nrotate * C::_2pi ;
    1083   }
    1084 //   os << "xmin=" << xmin << LogIO::POST ;
    1085 //   os << "center_=" << center_ << LogIO::POST ;
    1086 
    1087 
    1088   nx_ = nx ;
    1089   ny_ = ny ;
    1090   if ( nx < 0 && ny > 0 ) {
    1091     nx_ = ny ;
    1092     ny_ = ny ;
    1093   }
    1094   if ( ny < 0 && nx > 0 ) {
    1095     nx_ = nx ;
    1096     ny_ = nx ;
    1097   }
     373  }
     374
    1098375
    1099376  //Double wx = xmax - xmin ;
     
    1104381  wx *= 1.10 ;
    1105382  wy *= 1.10 ;
    1106 
    1107383  Quantum<Double> qcellx ;
    1108384  Quantum<Double> qcelly ;
     385  nx_ = nx ;
     386  ny_ = ny ;
     387  if ( nx < 0 && ny > 0 ) {
     388    nx_ = ny ;
     389    ny_ = ny ;
     390  }
     391  if ( ny < 0 && nx > 0 ) {
     392    nx_ = nx ;
     393    ny_ = nx ;
     394  }
    1109395  //cout << "nx_ = " << nx_ << ",  ny_ = " << ny_ << endl ;
    1110396  if ( cellx.size() != 0 && celly.size() != 0 ) {
     
    1113399  }
    1114400  else if ( celly.size() != 0 ) {
    1115     os << "Using celly to x-axis..." << LogIO::POST ;
     401    cout << "Using celly to x-axis..." << endl ;
    1116402    readQuantity( qcelly, celly ) ;
    1117403    qcellx = qcelly ;
    1118404  }
    1119405  else if ( cellx.size() != 0 ) {
    1120     os << "Using cellx to y-axis..." << LogIO::POST ;
     406    cout << "Using cellx to y-axis..." << endl ;
    1121407    readQuantity( qcellx, cellx ) ;
    1122408    qcelly = qcellx ;
     
    1124410  else {
    1125411    if ( nx_ < 0 ) {
    1126       os << "No user preference in grid setting. Using default..." << LogIO::POST ;
     412      cout << "No user preference in grid setting. Using default..." << endl ;
    1127413      readQuantity( qcellx, "1.0arcmin" ) ;
    1128414      qcelly = qcellx ;
    1129415    }
    1130416    else {
    1131       if ( wx == 0.0 ) {
    1132         os << "Using default spatial extent (10arcmin) in x" << LogIO::POST ;
    1133         wx = 0.00290888 ;
    1134       }
    1135       if ( wy == 0.0 ) {
    1136         os << "Using default spatial extent (10arcmin) in y" << LogIO::POST ;
    1137         wy = 0.00290888 ;
    1138       }
    1139417      qcellx = Quantum<Double>( wx/nx_, "rad" ) ;
    1140418      qcelly = Quantum<Double>( wy/ny_, "rad" ) ;
     
    1142420  }
    1143421  cellx_ = qcellx.getValue( "rad" ) ;
    1144   // DEC correction
    1145   cellx_ /= cos( center_[1] ) ;
    1146422  celly_ = qcelly.getValue( "rad" ) ;
    1147   //os << "cellx_=" << cellx_ << ", celly_=" << celly_ << ", cos("<<center_(1)<<")=" << cos(center_(1)) << LogIO::POST ;
    1148423  if ( nx_ < 0 ) {
    1149     if ( wx == 0.0 ) {
    1150       os << "Using default spatial extent (10arcmin) in x" << LogIO::POST ;
    1151       wx = 0.00290888 ;
    1152     }
    1153     if ( wy == 0.0 ) {
    1154       os << "Using default spatial extent (10arcmin) in y" << LogIO::POST ;
    1155       wy = 0.00290888 ;
    1156     }
    1157424    nx_ = Int( ceil( wx/cellx_ ) ) ;
    1158425    ny_ = Int( ceil( wy/celly_ ) ) ;
     
    1160427}
    1161428
    1162 void STGrid::mapExtent( Double &xmin, Double &xmax,
    1163                         Double &ymin, Double &ymax )
    1164 {
    1165   //LogIO os( LogOrigin("STGrid","mapExtent",WHERE) ) ;
    1166   directionCol_.attach( tableList_[0], "DIRECTION" ) ;
    1167   Matrix<Double> direction = directionCol_.getColumn() ;
    1168   //os << "dirCol.nrow() = " << dirCol.nrow() << LogIO::POST ;
    1169   minMax( xmin, xmax, direction.row( 0 ) ) ;
    1170   minMax( ymin, ymax, direction.row( 1 ) ) ;
    1171   Double amin, amax, bmin, bmax ;
    1172   for ( uInt i = 1 ; i < nfile_ ; i++ ) {
    1173     directionCol_.attach( tableList_[i], "DIRECTION" ) ;
    1174     direction.assign( directionCol_.getColumn() ) ;
    1175     //os << "dirCol.nrow() = " << dirCol.nrow() << LogIO::POST ;
    1176     minMax( amin, amax, direction.row( 0 ) ) ;
    1177     minMax( bmin, bmax, direction.row( 1 ) ) ;
    1178     xmin = min( xmin, amin ) ;
    1179     xmax = max( xmax, amax ) ;
    1180     ymin = min( ymin, bmin ) ;
    1181     ymax = max( ymax, bmax ) ;
    1182   }
    1183   //os << "(xmin,xmax)=(" << xmin << "," << xmax << ")" << LogIO::POST ;
    1184   //os << "(ymin,ymax)=(" << ymin << "," << ymax << ")" << LogIO::POST ;
    1185 }
    1186 
    1187 void STGrid::selectData()
    1188 {
    1189   LogIO os( LogOrigin("STGrid","selectData",WHERE) ) ;   
     429void STGrid::selectData( Table &tab )
     430{
    1190431  Int ifno = ifno_ ;
    1191   tableList_.resize( nfile_ ) ;
    1192   if ( ifno_ == -1 ) {
    1193     Table taborg( infileList_[0] ) ;
     432  Table taborg( infile_ ) ;
     433  if ( ifno == -1 ) {
     434    LogIO os( LogOrigin("STGrid","selectData",WHERE) ) ;
     435//     os << LogIO::SEVERE
     436//        << "Please set IFNO before actual gridding"
     437//        << LogIO::EXCEPTION ;
    1194438    ROScalarColumn<uInt> ifnoCol( taborg, "IFNO" ) ;
    1195     ifno_ = ifnoCol( 0 ) ;
     439    ifno = ifnoCol( 0 ) ;
    1196440    os << LogIO::WARN
    1197        << "IFNO is not given. Using default IFNO: " << ifno_ << LogIO::POST ;
    1198   }
    1199   for ( uInt i = 0 ; i < nfile_ ; i++ ) {
    1200     Table taborg( infileList_[i] ) ;
    1201     TableExprNode node ;
    1202     if ( ifno != -1 || isMultiIF( taborg ) ) {
    1203       os << "apply selection on IFNO" << LogIO::POST ;
    1204       node = taborg.col("IFNO") == ifno_ ;
    1205     }
    1206     if ( scanlist_.size() > 0 ) {
    1207       os << "apply selection on SCANNO" << LogIO::POST ;
    1208       node = node && taborg.col("SCANNO").in( scanlist_ ) ;
    1209     }
    1210     if ( node.isNull() ) {
    1211       tableList_[i] = taborg ;
     441       << "IFNO is not given. Using default IFNO: " << ifno << LogIO::POST ;
     442  }
     443//   tab = taborg( taborg.col("IFNO") == ifno ) ;
     444  TableExprNode node ;
     445  node = taborg.col("IFNO") == ifno ;
     446  if ( scanlist_.size() > 0 ) {
     447    node = node && taborg.col("SCANNO").in( scanlist_ ) ;
     448  }
     449  tab = taborg( node ) ;
     450  if ( tab.nrow() == 0 ) {
     451    LogIO os( LogOrigin("STGrid","selectData",WHERE) ) ;
     452    os << LogIO::SEVERE
     453       << "No corresponding rows for given selection: IFNO " << ifno
     454       << " SCANNO " << scanlist_
     455       << LogIO::EXCEPTION ;
     456  }
     457}
     458
     459void STGrid::getData( Cube<Float> &spectra,
     460                      Matrix<Double> &direction,
     461                      Cube<uChar> &flagtra,
     462                      Matrix<uInt> &rflag,
     463                      Matrix<Float> &weight )
     464{
     465  Table tab ;
     466  selectData( tab ) ;
     467  updatePolList( tab ) ;
     468//   cout << "npol_ = " << npol_ << endl ;
     469//   cout << "nchan_ = " << nchan_ << endl ;
     470//   cout << "nrow_ = " << nrow_ << endl ;
     471  spectra.resize( npol_, nchan_, nrow_ ) ;
     472  flagtra.resize( npol_, nchan_, nrow_ ) ;
     473  rflag.resize( npol_, nrow_ ) ;
     474  Cube<Float> tsys( npol_, nchan_, nrow_ ) ;
     475  Matrix<Double> tint( npol_, nrow_ ) ;
     476  // boolean for pointer access
     477  Bool bsp, bfl, bfr, bts, bti ;
     478  // pointer to the data
     479  Float *sp_p = spectra.getStorage( bsp ) ;
     480  uChar *fl_p = flagtra.getStorage( bfl ) ;
     481  uInt *fr_p = rflag.getStorage( bfr ) ;
     482  Float *ts_p = tsys.getStorage( bts ) ;
     483  Double *ti_p = tint.getStorage( bti ) ;
     484  // working pointer
     485  Float *wsp_p = sp_p ;
     486  uChar *wfl_p = fl_p ;
     487  uInt *wfr_p = fr_p ;
     488  Float *wts_p = ts_p ;
     489  Double *wti_p = ti_p ;
     490  uInt len = nchan_ * nrow_ ;
     491  IPosition mshape( 2, nchan_, nrow_ ) ;
     492  IPosition vshape( 1, nrow_ ) ;
     493  for ( Int ipol = 0 ; ipol < npol_ ; ipol++ ) {
     494    Table subt = tab( tab.col("POLNO") == pollist_[ipol] ) ;
     495    ROArrayColumn<Float> spectraCol( subt, "SPECTRA" ) ;
     496    ROArrayColumn<Double> directionCol( subt, "DIRECTION" ) ;
     497    ROArrayColumn<uChar> flagtraCol( subt, "FLAGTRA" ) ;
     498    ROScalarColumn<uInt> rflagCol( subt, "FLAGROW" ) ;
     499    ROArrayColumn<Float> tsysCol( subt, "TSYS" ) ;
     500    ROScalarColumn<Double> tintCol( subt, "INTERVAL" ) ;
     501    Matrix<Float> spSlice( mshape, wsp_p, SHARE ) ;
     502    Matrix<uChar> flSlice( mshape, wfl_p, SHARE ) ;
     503    Vector<uInt> frSlice( vshape, wfr_p, SHARE ) ;
     504    spectraCol.getColumn( spSlice ) ;
     505    flagtraCol.getColumn( flSlice ) ;
     506    rflagCol.getColumn( frSlice ) ;
     507    if ( ipol == 0 )
     508      directionCol.getColumn( direction ) ;
     509    Vector<Float> tmpF = tsysCol( 0 ) ;
     510    Vector<Double> tmpD( vshape, wti_p, SHARE ) ;
     511    Matrix<Float> tsSlice( mshape, wts_p, SHARE ) ;
     512    if ( tmpF.nelements() == (uInt)nchan_ ) {
     513      tsysCol.getColumn( tsSlice ) ;
    1212514    }
    1213515    else {
    1214       tableList_[i] = taborg( node ) ;
    1215     }
    1216     os << LogIO::DEBUGGING << "tableList_[" << i << "].nrow()=" << tableList_[i].nrow() << LogIO::POST ;
    1217     if ( tableList_[i].nrow() == 0 ) {
    1218       os << LogIO::SEVERE
    1219          << "No corresponding rows for given selection: IFNO " << ifno_ ;
    1220       if ( scanlist_.size() > 0 )
    1221         os << " SCANNO " << scanlist_ ;
    1222       os << LogIO::EXCEPTION ;
    1223     }
    1224   }
    1225 }
    1226 
    1227 Bool STGrid::isMultiIF( Table &tab )
    1228 {
    1229   ROScalarColumn<uInt> ifnoCol( tab, "IFNO" ) ;
    1230   Vector<uInt> ifnos = ifnoCol.getColumn() ;
    1231   return anyNE( ifnos, ifnos[0] ) ;
    1232 }
    1233 
    1234 void STGrid::attach( Table &tab )
    1235 {
    1236   // attach to table
    1237   spectraCol_.attach( tab, "SPECTRA" ) ;
    1238   flagtraCol_.attach( tab, "FLAGTRA" ) ;
    1239   directionCol_.attach( tab, "DIRECTION" ) ;
    1240   flagRowCol_.attach( tab, "FLAGROW" ) ;
    1241   tsysCol_.attach( tab, "TSYS" ) ;
    1242   intervalCol_.attach( tab, "INTERVAL" ) ;
    1243 }
    1244 
    1245 Int STGrid::getDataChunk(
    1246                          IPosition const &wshape,
    1247                          IPosition const &vshape,
    1248                          IPosition const &dshape,
    1249                          Array<Complex> &spectra,
    1250                          Array<Double> &direction,
    1251                          Array<Int> &flagtra,
    1252                          Array<Int> &rflag,
    1253                          Array<Float> &weight )
    1254 {
    1255   LogIO os( LogOrigin("STGrid","getDataChunk",WHERE) ) ;
    1256 
    1257   Array<Float> spectraF_(wshape);
    1258   Array<uChar> flagtraUC_(wshape);
    1259   Array<uInt> rflagUI_(vshape);
    1260   Int nrow = getDataChunk( spectraF_, direction, flagtraUC_, rflagUI_, weight ) ;
    1261   if ( nrow < nchunk_ ) {
    1262     spectra.resize( spectraF_.shape() ) ;
    1263     flagtra.resize( flagtraUC_.shape() ) ;
    1264     rflag.resize( rflagUI_.shape() ) ;
    1265   }
    1266   double t0, t1 ;
    1267   t0 = mathutil::gettimeofday_sec() ;
    1268   convertArray( spectra, spectraF_ ) ;
    1269   toInt( flagtraUC_, flagtra ) ;
    1270   toInt( rflagUI_, rflag ) ;
    1271   t1 = mathutil::gettimeofday_sec() ;
    1272   eToInt = t1 - t0 ;
    1273  
    1274   return nrow ;
    1275 }
    1276 
    1277 #if 0
    1278 Int STGrid::getDataChunk( Array<Complex> &spectra,
    1279                           Array<Double> &direction,
    1280                           Array<Int> &flagtra,
    1281                           Array<Int> &rflag,
    1282                           Array<Float> &weight )
    1283 {
    1284   LogIO os( LogOrigin("STGrid","getDataChunk",WHERE) ) ;
    1285   Int nrow = getDataChunk( spectraF_, direction, flagtraUC_, rflagUI_, weight ) ;
    1286   if ( nrow < nchunk_ ) {
    1287     spectra.resize( spectraF_.shape() ) ;
    1288     flagtra.resize( flagtraUC_.shape() ) ;
    1289     rflag.resize( rflagUI_.shape() ) ;
    1290   }
    1291   double t0, t1 ;
    1292   t0 = mathutil::gettimeofday_sec() ;
    1293   convertArray( spectra, spectraF_ ) ;
    1294   toInt( flagtraUC_, flagtra ) ;
    1295   toInt( rflagUI_, rflag ) ;
    1296   t1 = mathutil::gettimeofday_sec() ;
    1297   eToInt = t1 - t0 ;
    1298  
    1299   return nrow ;
    1300 }
    1301 #endif
    1302 
    1303 Int STGrid::getDataChunk( Array<Float> &spectra,
    1304                           Array<Double> &direction,
    1305                           Array<uChar> &flagtra,
    1306                           Array<uInt> &rflag,
    1307                           Array<Float> &weight )
    1308 {
    1309   LogIO os( LogOrigin("STGrid","getDataChunk",WHERE) ) ;
    1310   Int nrow = spectra.shape()[1] ;
    1311   Int remainingRow = nrow_ - nprocessed_ ;
    1312   if ( remainingRow < nrow ) {
    1313     nrow = remainingRow ;
    1314     IPosition mshape( 2, nchan_, nrow ) ;
    1315     IPosition vshape( 1, nrow ) ;
    1316     spectra.resize( mshape ) ;
    1317     flagtra.resize( mshape ) ;
    1318     direction.resize( IPosition(2,2,nrow) ) ;
    1319     rflag.resize( vshape ) ;
    1320     weight.resize( mshape ) ;
    1321   }
    1322   // 2011/12/22 TN
    1323   // tsys shares its storage with weight
    1324   Array<Float> tsys( weight ) ;
    1325   Array<Double> tint( rflag.shape() ) ;
    1326 
    1327   Vector<uInt> rflagVec( rflag ) ;
    1328   Vector<Double> tintVec( tint ) ;
    1329 
    1330   RefRows rows( nprocessed_, nprocessed_+nrow-1, 1 ) ;
    1331   //os<<LogIO::DEBUGGING<<"nprocessed_="<<nprocessed_<<": rows.nrows()="<<rows.nrows()<<LogIO::POST ;
    1332   spectraCol_.getColumnCells( rows, spectra ) ;
    1333   flagtraCol_.getColumnCells( rows, flagtra ) ;
    1334   directionCol_.getColumnCells( rows, direction ) ;
    1335   flagRowCol_.getColumnCells( rows, rflagVec ) ;
    1336   intervalCol_.getColumnCells( rows, tintVec ) ;
    1337   Vector<Float> tsysTemp = tsysCol_( nprocessed_ ) ;
    1338   if ( tsysTemp.nelements() == (uInt)nchan_ )
    1339     tsysCol_.getColumnCells( rows, tsys ) ;
    1340   else
    1341     tsys = tsysTemp[0] ;
    1342 
    1343   double t0,t1 ;
    1344   t0 = mathutil::gettimeofday_sec() ;
     516      tsSlice = tmpF( 0 ) ;
     517    }
     518    tintCol.getColumn( tmpD ) ;
     519
     520    wsp_p += len ;
     521    wfl_p += len ;
     522    wfr_p += nrow_ ;
     523    wts_p += len ;
     524    wti_p += nrow_ ;
     525  }
     526  spectra.putStorage( sp_p, bsp ) ;
     527  flagtra.putStorage( fl_p, bfl ) ;
     528  rflag.putStorage( fr_p, bfr ) ;
     529  tsys.putStorage( ts_p, bts ) ;
     530  tint.putStorage( ti_p, bti ) ;
     531
    1345532  getWeight( weight, tsys, tint ) ;
    1346   t1 = mathutil::gettimeofday_sec() ;
    1347   eGetWeight += t1-t0 ;
    1348 
    1349   nprocessed_ += nrow ;
    1350  
    1351   return nrow ;
    1352 }
    1353 
    1354 void STGrid::setupArray()
    1355 {
    1356   LogIO os( LogOrigin("STGrid","setupArray",WHERE) ) ;
    1357   ROScalarColumn<uInt> polnoCol( tableList_[0], "POLNO" ) ;
     533}
     534
     535void STGrid::updatePolList( Table &tab )
     536{
     537  ROScalarColumn<uInt> polnoCol( tab, "POLNO" ) ;
    1358538  Vector<uInt> pols = polnoCol.getColumn() ;
    1359   //os << pols << LogIO::POST ;
    1360539  Vector<uInt> pollistOrg ;
    1361   npolOrg_ = 0 ;
     540  uInt npolOrg = 0 ;
    1362541  uInt polno ;
    1363542  for ( uInt i = 0 ; i < polnoCol.nrow() ; i++ ) {
     
    1365544    polno = pols( i ) ;
    1366545    if ( allNE( pollistOrg, polno ) ) {
    1367       pollistOrg.resize( npolOrg_+1, True ) ;
    1368       pollistOrg[npolOrg_] = polno ;
    1369       npolOrg_++ ;
     546      pollistOrg.resize( npolOrg+1, True ) ;
     547      pollistOrg[npolOrg] = polno ;
     548      npolOrg++ ;
    1370549    }
    1371550  }
     
    1386565  npol_ = pollist_.size() ;
    1387566  if ( npol_ == 0 ) {
     567    LogIO os( LogOrigin("STGrid","updatePolList",WHERE) ) ;
    1388568    os << LogIO::SEVERE << "Empty pollist" << LogIO::EXCEPTION ;
    1389569  }
    1390   rows_.resize( nfile_ ) ;
    1391   for ( uInt i = 0 ; i < nfile_ ; i++ ) {
    1392     rows_[i] = tableList_[i].nrow() / npolOrg_ ;
    1393     //if ( nrow_ < rows_[i] )
    1394     //  nrow_ = rows_[i] ;
    1395   }
    1396   flagtraCol_.attach( tableList_[0], "FLAGTRA" ) ;
    1397   nchan_ = flagtraCol_( 0 ).nelements() ;
     570  nrow_ = tab.nrow() / npolOrg ;
     571  ROArrayColumn<uChar> tmpCol( tab, "FLAGTRA" ) ;
     572  nchan_ = tmpCol( 0 ).nelements() ;
     573//   LogIO os( LogOrigin("STGrid","updatePolList",WHERE) ) ;
    1398574//   os << "npol_ = " << npol_ << "(" << pollist_ << ")" << endl
    1399575//      << "nchan_ = " << nchan_ << endl
     
    1401577}
    1402578
    1403 void STGrid::getWeight( Array<Float> &w,
    1404                               Array<Float> &tsys,
    1405                               Array<Double> &tint )
     579void STGrid::getWeight( Matrix<Float> &w,
     580                        Cube<Float> &tsys,
     581                        Matrix<Double> &tint )
    1406582{
    1407583  LogIO os( LogOrigin("STGrid","getWeight",WHERE) ) ;
    1408 
    1409   // 2011/12/22 TN
    1410   // w (weight) and tsys share storage
    1411   IPosition refShape = tsys.shape() ;
    1412   Int nchan = refShape[0] ;
    1413   Int nrow = refShape[1] ;
    1414 //   os << "nchan=" << nchan << ", nrow=" << nrow << LogIO::POST ;
    1415 //   os << "w.shape()=" << w.shape() << endl
    1416 //      << "tsys.shape()=" << tsys.shape() << endl
    1417 //      << "tint.shape()=" << tint.shape() << LogIO::POST ;
     584  double t0, t1 ;
     585  t0 = mathutil::gettimeofday_sec() ;
     586  // resize
     587  w.resize( nchan_, nrow_ ) ;
    1418588
    1419589  // set weight
     590  Bool warn = False ;
    1420591  if ( wtype_.compare( "UNIFORM" ) == 0 ) {
    1421592    w = 1.0 ;
    1422593  }
    1423594  else if ( wtype_.compare( "TINT" ) == 0 ) {
     595    if ( npol_ > 1 ) warn = True ;
    1424596    Bool b0, b1 ;
    1425597    Float *w_p = w.getStorage( b0 ) ;
     
    1427599    const Double *ti_p = tint.getStorage( b1 ) ;
    1428600    const Double *w1_p = ti_p ;
    1429     for ( Int irow = 0 ; irow < nrow ; irow++ ) {
    1430       for ( Int ichan = 0 ; ichan < nchan ; ichan++ ) {
    1431         *w0_p = *w1_p ;
     601    for ( Int irow = 0 ; irow < nrow_ ; irow++ ) {
     602      Float val = (Float)(polMean( w1_p )) ;
     603      for ( Int ichan = 0 ; ichan < nchan_ ; ichan++ ) {
     604        *w0_p = val ;
    1432605        w0_p++ ;
    1433606      }
    1434       w1_p++ ;
    1435607    }
    1436608    w.putStorage( w_p, b0 ) ;
     
    1438610  }
    1439611  else if ( wtype_.compare( "TSYS" ) == 0 ) {
    1440     Bool b0 ;
     612    if ( npol_ > 1 ) warn = True ;
     613    Bool b0, b1 ;
    1441614    Float *w_p = w.getStorage( b0 ) ;
    1442615    Float *w0_p = w_p ;
    1443     for ( Int irow = 0 ; irow < nrow ; irow++ ) {
    1444       for ( Int ichan = 0 ; ichan < nchan ; ichan++ ) {
    1445         Float temp = *w0_p ;
    1446         *w0_p = 1.0 / ( temp * temp ) ;
     616    const Float *ts_p = tsys.getStorage( b1 ) ;
     617    const Float *w1_p = ts_p ;
     618    for ( Int irow = 0 ; irow < nrow_ ; irow++ ) {
     619      for ( Int ichan = 0 ; ichan < nchan_ ; ichan++ ) {
     620        Float val = polMean( w1_p ) ;
     621        *w0_p = 1.0 / ( val * val ) ;
    1447622        w0_p++ ;
    1448623      }
    1449624    }
    1450625    w.putStorage( w_p, b0 ) ;
     626    tsys.freeStorage( ts_p, b1 ) ;
    1451627  }
    1452628  else if ( wtype_.compare( "TINTSYS" ) == 0 ) {
    1453     Bool b0, b1 ;
     629    if ( npol_ > 1 ) warn = True ;
     630    Bool b0, b1, b2 ;
    1454631    Float *w_p = w.getStorage( b0 ) ;
    1455632    Float *w0_p = w_p ;
    1456633    const Double *ti_p = tint.getStorage( b1 ) ;
    1457634    const Double *w1_p = ti_p ;
    1458     for ( Int irow = 0 ; irow < nrow ; irow++ ) {
    1459       Float interval = *w1_p ;
    1460       for ( Int ichan = 0 ; ichan < nchan ; ichan++ ) {
    1461         Float temp = *w0_p ;
     635    const Float *ts_p = tsys.getStorage( b2 ) ;
     636    const Float *w2_p = ts_p ;
     637    for ( Int irow = 0 ; irow < nrow_ ; irow++ ) {
     638      Float interval = (Float)(polMean( w1_p )) ;
     639      for ( Int ichan = 0 ; ichan < nchan_ ; ichan++ ) {
     640        Float temp = polMean( w2_p ) ;
    1462641        *w0_p = interval / ( temp * temp ) ;
    1463642        w0_p++ ;
    1464643      }
    1465       w1_p++ ;
    1466644    }
    1467645    w.putStorage( w_p, b0 ) ;
    1468646    tint.freeStorage( ti_p, b1 ) ;
     647    tsys.freeStorage( ts_p, b2 ) ;
    1469648  }
    1470649  else {
    1471650    //LogIO os( LogOrigin("STGrid", "getWeight", WHERE) ) ;
    1472     //os << LogIO::WARN << "Unsupported weight type '" << wtype_ << "', apply UNIFORM weight" << LogIO::POST ;
     651    os << LogIO::WARN << "Unsupported weight type '" << wtype_ << "', apply UNIFORM weight" << LogIO::POST ;
    1473652    w = 1.0 ;
    1474653  }
    1475 }
    1476 
    1477 void STGrid::toInt( Array<uChar> &u, Array<Int> &v )
    1478 {
    1479   uInt len = u.nelements() ;
     654
     655  if ( npol_ > 1 ) {
     656    //LogIO os( LogOrigin("STGrid", "getWeight", WHERE) ) ;
     657    os << LogIO::WARN << "STGrid doesn't support assigning polarization-dependent weight. Use averaged weight over polarization." << LogIO::POST ;
     658  }
     659  t1 = mathutil::gettimeofday_sec() ;
     660  os << "getWeight: elapsed time is " << t1-t0 << " sec" << LogIO::POST ;
     661}
     662
     663Float STGrid::polMean( const Float *p )
     664{
     665  Float v = 0.0 ;
     666  for ( Int i = 0 ; i < npol_ ; i++ ) {
     667    v += *p ;
     668    p++ ;
     669  }
     670  v /= npol_ ;
     671  return v ;
     672}
     673
     674Double STGrid::polMean( const Double *p )
     675{
     676  Double v = 0.0 ;
     677  for ( Int i = 0 ; i < npol_ ; i++ ) {
     678    v += *p ;
     679    p++ ;
     680  }
     681  v /= npol_ ;
     682  return v ;
     683}
     684
     685void STGrid::toInt( Array<uChar> *u, Array<Int> *v )
     686{
     687  uInt len = u->nelements() ;
    1480688  Int *int_p = new Int[len] ;
    1481689  Bool deleteIt ;
    1482   const uChar *data_p = u.getStorage( deleteIt ) ;
     690  const uChar *data_p = u->getStorage( deleteIt ) ;
    1483691  Int *i_p = int_p ;
    1484692  const uChar *u_p = data_p ;
     
    1488696    u_p++ ;
    1489697  }
    1490   u.freeStorage( data_p, deleteIt ) ;
    1491   v.takeStorage( u.shape(), int_p, TAKE_OVER ) ;
    1492 }
    1493 
    1494 void STGrid::toInt( Array<uInt> &u, Array<Int> &v )
    1495 {
    1496   uInt len = u.nelements() ;
     698  u->freeStorage( data_p, deleteIt ) ;
     699  v->takeStorage( u->shape(), int_p, TAKE_OVER ) ;
     700}
     701
     702void STGrid::toInt( Array<uInt> *u, Array<Int> *v )
     703{
     704  uInt len = u->nelements() ;
    1497705  Int *int_p = new Int[len] ;
    1498706  Bool deleteIt ;
    1499   const uInt *data_p = u.getStorage( deleteIt ) ;
     707  const uInt *data_p = u->getStorage( deleteIt ) ;
    1500708  Int *i_p = int_p ;
    1501709  const uInt *u_p = data_p ;
     
    1505713    u_p++ ;
    1506714  }
    1507   u.freeStorage( data_p, deleteIt ) ;
    1508   v.takeStorage( u.shape(), int_p, TAKE_OVER ) ;
    1509 }
    1510 
    1511 void STGrid::toPixel( Array<Double> &world, Array<Double> &pixel )
     715  u->freeStorage( data_p, deleteIt ) ;
     716  v->takeStorage( u->shape(), int_p, TAKE_OVER ) ;
     717}
     718
     719void STGrid::toPixel( Matrix<Double> &world, Matrix<Double> &pixel )
    1512720{
    1513721  // gridding will be done on (nx_+2*convSupport_) x (ny_+2*convSupport_)
    1514722  // grid plane to avoid unexpected behavior on grid edge
    1515   Block<Double> pixc( 2 ) ;
    1516   pixc[0] = Double( nx_-1 ) * 0.5 ;
    1517   pixc[1] = Double( ny_-1 ) * 0.5 ;
    1518 //   pixc[0] = Double( nx_+2*convSupport_-1 ) * 0.5 ;
    1519 //   pixc[1] = Double( ny_+2*convSupport_-1 ) * 0.5 ;
     723  Vector<Double> pixc( 2 ) ;
     724  pixc(0) = Double( nx_-1 ) * 0.5 ;
     725  pixc(1) = Double( ny_-1 ) * 0.5 ;
     726//   pixc(0) = Double( nx_+2*convSupport_-1 ) * 0.5 ;
     727//   pixc(1) = Double( ny_+2*convSupport_-1 ) * 0.5 ;
    1520728  uInt nrow = world.shape()[1] ;
    1521   Bool bw, bp ;
    1522   const Double *w_p = world.getStorage( bw ) ;
    1523   Double *p_p = pixel.getStorage( bp ) ;
    1524   const Double *ww_p = w_p ;
    1525   Double *wp_p = p_p ;
    1526   for ( uInt i = 0 ; i < nrow ; i++ ) {
    1527     *wp_p = pixc[0] + ( *ww_p - center_[0] ) / cellx_ ;
    1528     wp_p++ ;
    1529     ww_p++ ;
    1530     *wp_p = pixc[1] + ( *ww_p - center_[1] ) / celly_ ;
    1531     wp_p++ ;
    1532     ww_p++ ;
    1533   }
    1534   world.freeStorage( w_p, bw ) ;
    1535   pixel.putStorage( p_p, bp ) ; 
     729  Vector<Double> cell( 2 ) ;
     730  cell(0) = cellx_ ;
     731  cell(1) = celly_ ;
     732  for ( uInt irow = 0 ; irow < nrow ; irow++ ) {
     733    for ( uInt i = 0 ; i < 2 ; i++ ) {
     734      pixel( i, irow ) = pixc(i) + ( world(i, irow) - center_(i) ) / cell(i) ;
     735    }
     736  }
     737//   String gridfile = "grid."+convType_+"."+String::toString(convSupport_)+".dat" ;
     738//   ofstream ofs( gridfile.c_str(), ios::out ) ;
     739//   ofs << "center " << center_(0) << " " << pixc(0)
     740//       << " " << center_(1) << " " << pixc(1) << endl ;
     741//   for ( uInt irow = 0 ; irow < nrow ; irow++ ) {
     742//     ofs << irow ;
     743//     for ( uInt i = 0 ; i < 2 ; i++ ) {
     744//       ofs << " " << world(i, irow) << " " << pixel(i, irow) ;
     745//     }
     746//     ofs << endl ;
     747//   }
     748//   ofs.close() ;
    1536749}
    1537750
     
    1599812    // to take into account Gaussian tail
    1600813    if ( convSupport_ < 0 )
    1601       convSupport_ = 4 ; // 1 * 4
     814      convSupport_ = 12 ; // 3 * 4
    1602815    else {
    1603816      convSupport_ = userSupport_ * 4 ;
     
    1626839  String outfile_ ;
    1627840  if ( outfile.size() == 0 ) {
    1628     if ( infileList_[0].lastchar() == '/' ) {
    1629       outfile_ = infileList_[0].substr( 0, infileList_[0].size()-1 ) ;
     841    if ( infile_.lastchar() == '/' ) {
     842      outfile_ = infile_.substr( 0, infile_.size()-1 ) ;
    1630843    }
    1631844    else {
    1632       outfile_ = infileList_[0] ;
     845      outfile_ = infile_ ;
    1633846    }
    1634847    outfile_ += ".grid" ;
     
    1684897
    1685898  t1 = mathutil::gettimeofday_sec() ;
    1686   os << LogIO::DEBUGGING << "saveData: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
    1687 
    1688   fillMainColumns( tab ) ;
    1689 
     899  os << "saveData: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
     900 
    1690901  return outfile_ ;
    1691902}
     
    1693904void STGrid::prepareTable( Table &tab, String &name )
    1694905{
    1695   Table t( infileList_[0], Table::Old ) ;
     906  Table t( infile_, Table::Old ) ;
    1696907  t.deepCopy( name, Table::New, False, t.endianFormat(), True ) ;
    1697908  tab = Table( name, Table::Update ) ;
    1698   // 2012/02/13 TN
    1699   // explicitly copy subtables since no rows including subtables are
    1700   // copied by Table::deepCopy with noRows=True
    1701   TableCopy::copySubTables( tab, t ) ;
    1702 }
    1703 
    1704 void STGrid::fillMainColumns( Table &tab )
    1705 {
    1706   // values for fill
    1707   Table t( infileList_[0], Table::Old ) ;
    1708   Table tsel = t( t.col( "IFNO" ) == (uInt)ifno_, 1 ) ;
    1709   ROTableRow row( tsel ) ;
    1710   row.get( 0 ) ;
    1711   const TableRecord &rec = row.record() ;
    1712   uInt freqId = rec.asuInt( "FREQ_ID" ) ;
    1713   uInt molId = rec.asuInt( "MOLECULE_ID" ) ;
    1714   uInt tcalId = rec.asuInt( "TCAL_ID" ) ;
    1715   uInt focusId = rec.asuInt( "FOCUS_ID" ) ;
    1716   uInt weatherId = rec.asuInt( "WEATHER_ID" ) ;
    1717   String srcname = rec.asString( "SRCNAME" ) ;
    1718   String fieldname = rec.asString( "FIELDNAME" ) ;
    1719   Vector<Float> defaultTsys( 1, 1.0 ) ;
    1720   // @todo how to set flagtra for gridded spectra?
    1721   Vector<uChar> flagtra = rec.asArrayuChar( "FLAGTRA" ) ;
    1722   flagtra = (uChar)0 ;
    1723   Float opacity = rec.asFloat( "OPACITY" ) ;
    1724   Double srcvel = rec.asDouble( "SRCVELOCITY" ) ;
    1725   Vector<Double> srcpm = rec.asArrayDouble( "SRCPROPERMOTION" ) ;
    1726   Vector<Double> srcdir = rec.asArrayDouble( "SRCDIRECTION" ) ;
    1727   Vector<Double> scanrate = rec.asArrayDouble( "SCANRATE" ) ;
    1728   Double time = rec.asDouble( "TIME" ) ;
    1729   Double interval = rec.asDouble( "INTERVAL" ) ;
    1730 
    1731   // fill columns
    1732   Int nrow = tab.nrow() ;
    1733   ScalarColumn<uInt> scannoCol( tab, "SCANNO" ) ;
    1734   ScalarColumn<uInt> ifnoCol( tab, "IFNO" ) ;
    1735   ScalarColumn<uInt> freqIdCol( tab, "FREQ_ID" ) ;
    1736   ScalarColumn<uInt> molIdCol( tab, "MOLECULE_ID" ) ;
    1737   ScalarColumn<uInt> tcalidCol( tab, "TCAL_ID" ) ;
    1738   ScalarColumn<Int> fitidCol( tab, "FIT_ID" ) ;
    1739   ScalarColumn<uInt> focusidCol( tab, "FOCUS_ID" ) ;
    1740   ScalarColumn<uInt> weatheridCol( tab, "WEATHER_ID" ) ;
    1741   ArrayColumn<uChar> flagtraCol( tab, "FLAGTRA" ) ;
    1742   ScalarColumn<uInt> rflagCol( tab, "FLAGROW" ) ;
    1743   ArrayColumn<Float> tsysCol( tab, "TSYS" ) ;
    1744   ScalarColumn<String> srcnameCol( tab, "SRCNAME" ) ;
    1745   ScalarColumn<String> fieldnameCol( tab, "FIELDNAME" ) ;
    1746   ScalarColumn<Int> srctypeCol( tab, "SRCTYPE" ) ;
    1747   ScalarColumn<Float> opacityCol( tab, "OPACITY" ) ;
    1748   ScalarColumn<Double> srcvelCol( tab, "SRCVELOCITY" ) ;
    1749   ArrayColumn<Double> srcpmCol( tab, "SRCPROPERMOTION" ) ;
    1750   ArrayColumn<Double> srcdirCol( tab, "SRCDIRECTION" ) ;
    1751   ArrayColumn<Double> scanrateCol( tab, "SCANRATE" ) ;
    1752   ScalarColumn<Double> timeCol( tab, "TIME" ) ;
    1753   ScalarColumn<Double> intervalCol( tab, "INTERVAL" ) ;
    1754   for ( Int i = 0 ; i < nrow ; i++ ) {
    1755     scannoCol.put( i, (uInt)i ) ;
    1756     ifnoCol.put( i, (uInt)ifno_ ) ;
    1757     freqIdCol.put( i, freqId ) ;
    1758     molIdCol.put( i, molId ) ;
    1759     tcalidCol.put( i, tcalId ) ;
    1760     fitidCol.put( i, -1 ) ;
    1761     focusidCol.put( i, focusId ) ;
    1762     weatheridCol.put( i, weatherId ) ;
    1763     flagtraCol.put( i, flagtra ) ;
    1764     rflagCol.put( i, 0 ) ;
    1765     tsysCol.put( i, defaultTsys ) ;
    1766     srcnameCol.put( i, srcname ) ;
    1767     fieldnameCol.put( i, fieldname ) ;
    1768     srctypeCol.put( i, (Int)SrcType::PSON ) ;
    1769     opacityCol.put( i, opacity ) ;
    1770     srcvelCol.put( i, srcvel ) ;
    1771     srcpmCol.put( i, srcpm ) ;
    1772     srcdirCol.put( i, srcdir ) ;
    1773     scanrateCol.put( i, scanrate ) ;
    1774     timeCol.put( i, time ) ;
    1775     intervalCol.put( i, interval ) ;
    1776   }
    1777 }
    1778 
    1779 }
     909}
     910}
  • /trunk/src/STGrid.h

    r2473 r2373  
    1919
    2020#include <casa/BasicSL/String.h>
    21 #include <casa/Arrays/Array.h>
    2221#include <casa/Arrays/Vector.h>
    23 #include <casa/Containers/RecordField.h>
     22#include <casa/Arrays/Matrix.h>
     23#include <casa/Arrays/Cube.h>
     24// #include <casa/Arrays/ArrayMath.h>
     25// #include <casa/Inputs/Input.h>
     26// #include <casa/Quanta/Quantum.h>
     27// #include <casa/Quanta/QuantumHolder.h>
     28// #include <casa/Utilities/CountedPtr.h>
    2429
    2530#include <tables/Tables/Table.h>
    26 #include <tables/Tables/ScalarColumn.h>
    27 #include <tables/Tables/ArrayColumn.h>
     31// #include <tables/Tables/ScalarColumn.h>
     32// #include <tables/Tables/ArrayColumn.h>
    2833
    29 #include "concurrent.h"
     34// #include <measures/Measures/MDirection.h>
     35
     36// #include "Scantable.h"
    3037
    3138using namespace std ;
     
    3845  STGrid() ;
    3946  STGrid( const string infile ) ;
    40   STGrid( const vector<string> infile ) ;
    4147  virtual ~STGrid() {} ;
    4248
    4349  void setFileIn( const string infile ) ;
    44   void setFileList( const vector<string> infile ) ;
    4550
    4651  void setIF( unsigned int ifno ) { ifno_ = ifno ; } ;
     
    6065  void setWeight( const string wType="uniform" ) ;
    6166
    62   void enableClip() { doclip_ = True ; } ;
    63   void disableClip() { doclip_ = False ; } ;
    64 
    6567  void grid() ;
    6668 
     
    7072  void init() ;
    7173
    72   // actual gridding
    73   void gridPerRow() ;
    74   void gridPerRowWithClipping() ;
    75 
    76   // clipping
    77   void clipMinMax( Array<Complex> &data,
    78                    Array<Float> &weight,
    79                    Array<Int> &npoints,
    80                    Array<Complex> &clipmin,
    81                    Array<Float> &clipwmin,
    82                    Array<Float> &clipcmin,
    83                    Array<Complex> &clipmax,
    84                    Array<Float> &clipwmax,
    85                    Array<Float> &clipcmax ) ;
    86                    
    87 
    88   void setupGrid() ;
    8974  void setupGrid( Int &nx,
    9075                  Int &ny,
     
    9681                  Double &ymax,
    9782                  String &center ) ;
    98   void mapExtent( Double &xmin, Double &xmax,
    99                   Double &ymin, Double &ymax ) ;
    10083
    101   void setData( Array<Complex> &gdata,
     84  void setData( Array<Float> &data,
     85                Array<Float> &gdata,
    10286                Array<Float> &gwgt ) ;
    10387 
    104   Int getDataChunk( IPosition const &wshape,
    105                     IPosition const &vshape,
    106                     IPosition const &dshape,
    107                     Array<Complex> &spectra,
    108                     Array<Double> &direction,
    109                     Array<Int> &flagtra,
    110                     Array<Int> &rflag,
    111                     Array<Float> &weight ) ;
    112   Int getDataChunk( Array<Complex> &spectra,
    113                     Array<Double> &direction,
    114                     Array<Int> &flagtra,
    115                     Array<Int> &rflag,
    116                     Array<Float> &weight ) ;
    117   Int getDataChunk( Array<Float> &spectra,
    118                     Array<Double> &direction,
    119                     Array<uChar> &flagtra,
    120                     Array<uInt> &rflag,
    121                     Array<Float> &weight ) ;
     88  void getData( Cube<Float> &spectra,
     89                Matrix<Double> &direction,
     90                Cube<uChar> &flagtra,
     91                Matrix<uInt> &rflag,
     92                Matrix<Float> &weight ) ;
    12293
    123   void getWeight( Array<Float> &w,
    124                   Array<Float> &tsys,
    125                   Array<Double> &tint ) ;
    126  
    127   void toInt( Array<uChar> &u, Array<Int> &v ) ;
    128   void toInt( Array<uInt> &u, Array<Int> &v ) ;
     94  void getWeight( Matrix<Float> &w,
     95                  Cube<Float> &tsys,
     96                  Matrix<Double> &tint ) ;
    12997
    130   void toPixel( Array<Double> &world, Array<Double> &pixel ) ;
     98  void toInt( Array<uChar> *u, Array<Int> *v ) ;
     99  void toInt( Array<uInt> *u, Array<Int> *v ) ;
     100
     101  void toPixel( Matrix<Double> &world, Matrix<Double> &pixel ) ;
    131102 
    132103  void boxFunc( Vector<Float> &convFunc, Int &convSize ) ;
     
    135106  void pbFunc( Vector<Float> &convFunc ) ;
    136107  void setConvFunc( Vector<Float> &convFunc ) ;
     108  void selectData( Table &tab ) ;
     109
     110  Float polMean( const Float *p ) ;
     111  Double polMean( const Double *p ) ;
     112
     113  void updatePolList( Table &tab ) ;
    137114
    138115  void prepareTable( Table &tab, String &name ) ;
    139116
    140   void selectData() ;
    141   void setupArray() ;
    142 
    143   void updateChunkShape() ;
    144   void attach( Table &tab ) ;
    145 
    146   void call_ggridsd( Array<Double> &xy,
    147                      Array<Complex> &values,
    148                      Int &nvispol,
    149                      Int &nvischan,
    150                      Array<Int> &flag,
    151                      Array<Int> &rflag,
    152                      Array<Float> &weight,
    153                      Int &nrow,
    154                      Int &irow,
    155                      Array<Complex> &grid,
    156                      Array<Float> &wgrid,
    157                      Int &nx,
    158                      Int &ny,
    159                      Int &npol,
    160                      Int &nchan,
    161                      Int &support,
    162                      Int &sampling,
    163                      Vector<Float> &convFunc,
    164                      Int *chanMap,
    165                      Int *polMap ) ;
    166   void call_ggridsd2( Array<Double> &xy,
    167                       Array<Complex> &values,
    168                       Int &nvispol,
    169                       Int &nvischan,
    170                       Array<Int> &flag,
    171                       Array<Int> &rflag,
    172                       Array<Float> &weight,
    173                       Int &nrow,
    174                       Int &irow,
    175                       Array<Complex> &grid,
    176                       Array<Float> &wgrid,
    177                       Array<Int> &npoints,
    178                       Array<Complex> &clipmin,
    179                       Array<Float> &clipwmin,
    180                       Array<Float> &clipcmin,
    181                       Array<Complex> &clipmax,
    182                       Array<Float> &clipwmax,
    183                       Array<Float> &clipcmax,
    184                       Int &nx,
    185                       Int &ny,
    186                       Int &npol,
    187                       Int &nchan,
    188                       Int &support,
    189                       Int &sampling,
    190                       Vector<Float> &convFunc,
    191                       Int *chanMap,
    192                       Int *polMap ) ;
    193 
    194   void initPol( Int ipol ) ;
    195   void initTable( uInt idx ) ;
    196   Bool isMultiIF( Table &tab ) ;
    197   void fillMainColumns( Table &tab ) ;
    198   static bool produceChunk(void *ctx) throw(concurrent::PCException);
    199   static void consumeChunk(void *ctx) throw(concurrent::PCException);
    200   static void consumeChunkWithClipping(void *ctx) throw(concurrent::PCException);
    201 
    202 
    203   // user input
    204   Int nxUI_ ;
    205   Int nyUI_ ;
    206   String cellxUI_ ;
    207   String cellyUI_ ;
    208   String centerUI_ ;
    209 
    210   Block<String> infileList_ ;
    211   uInt nfile_ ;
     117  String infile_ ;
    212118  Int ifno_ ;
    213   Bool doclip_ ;
    214 
    215119  Int nx_ ;
    216120  Int ny_ ;
    217121  Int npol_ ;
    218   Int npolOrg_ ;
    219122  Int nchan_ ;
     123  Int nrow_ ;
    220124  Double cellx_ ;
    221125  Double celly_ ;
     
    225129  Int userSupport_ ;
    226130  Int convSampling_ ;
     131  Array<Float> data_ ;
    227132  Vector<uInt> pollist_ ;
    228133  Vector<uInt> scanlist_ ;
    229134  String wtype_ ;
    230   Block<Table> tableList_ ;
    231   Vector<uInt> rows_ ;
    232   Int nchunk_ ;
    233 
    234   /////////////// gridPerRow variable
    235   IPosition vshape_;
    236   IPosition wshape_;
    237   IPosition dshape_;
    238   // loop variable
    239   Int nrow_ ;
    240   Array<Float> data_ ;
    241135
    242136  Table tab_ ;
    243   // per pol
    244   Table ptab_ ;
    245   ROArrayColumn<Float> spectraCol_ ;
    246   ROArrayColumn<uChar> flagtraCol_ ;
    247   ROArrayColumn<Double> directionCol_ ;
    248   ROScalarColumn<uInt> flagRowCol_ ;
    249   ROArrayColumn<Float> tsysCol_ ;
    250   ROScalarColumn<Double> intervalCol_ ;
    251 
    252   Int nprocessed_ ;
    253 
    254 
    255   double eGetData_;
    256   double eToPixel_;
    257   double eGGridSD_;
    258137};
    259138}
  • /trunk/src/STLineFinder.cpp

    r2473 r2373  
    886886STLineFinder::STLineFinder() throw() : edge(0,0)
    887887{
    888   useScantable = true;
    889888  setOptions();
    890889}
     
    926925  itsNoiseBox = in_noise_box;
    927926  itsUseMedian = in_median;
     927
     928  useScantable = true;
    928929}
    929930
     
    935936  scan=in_scan.getCP();
    936937  AlwaysAssert(!scan.null(),AipsError);
    937   useScantable = true;
    938938}
    939939
     
    943943void STLineFinder::setData(const std::vector<float> &in_spectrum)
    944944{
    945   //spectrum = Vector<Float>(in_spectrum);
    946   spectrum.assign( Vector<Float>(in_spectrum) );
     945  spectrum = Vector<Float>(in_spectrum);
    947946  useScantable = false;
    948947}
     
    967966  // no mask given...
    968967  if (in_mask.size() == 0) {
    969     //mask = Vector<Bool>(nchan,True);
    970     mask.assign( Vector<Bool>(nchan,True) );
     968    mask = Vector<Bool>(nchan,True);
    971969  } else {
    972970    // use provided mask
    973     //mask=Vector<Bool>(in_mask);
    974     mask.assign( Vector<Bool>(in_mask) );
     971    mask=Vector<Bool>(in_mask);
    975972  }
    976973  if (mask.nelements()!=nchan)
  • /trunk/src/STMath.cpp

    r2473 r2373  
    5757using namespace asap;
    5858
    59 // 2012/02/17 TN
    60 // Since STGrid is implemented, average doesn't consider direction
    61 // when accumulating
    6259// tolerance for direction comparison (rad)
    63 // #define TOL_OTF    1.0e-15
    64 // #define TOL_POINT  2.9088821e-4  // 1 arcmin
     60#define TOL_OTF    1.0e-15
     61#define TOL_POINT  2.9088821e-4  // 1 arcmin
    6562
    6663STMath::STMath(bool insitu) :
     
    8683  WeightType wtype = stringToWeight(weight);
    8784
    88   // 2012/02/17 TN
    89   // Since STGrid is implemented, average doesn't consider direction
    90   // when accumulating
    9185  // check if OTF observation
    92 //   String obstype = in[0]->getHeader().obstype ;
    93 //   Double tol = 0.0 ;
    94 //   if ( (obstype.find( "OTF" ) != String::npos) || (obstype.find( "OBSERVE_TARGET" ) != String::npos) ) {
    95 //     tol = TOL_OTF ;
    96 //   }
    97 //   else {
    98 //     tol = TOL_POINT ;
    99 //   }
     86  String obstype = in[0]->getHeader().obstype ;
     87  Double tol = 0.0 ;
     88  if ( (obstype.find( "OTF" ) != String::npos) || (obstype.find( "OBSERVE_TARGET" ) != String::npos) ) {
     89    tol = TOL_OTF ;
     90  }
     91  else {
     92    tol = TOL_POINT ;
     93  }
    10094
    10195  // output
     
    148142  while (!iter.pastEnd()) {
    149143    Table subt = iter.table();
    150     // copy the first row of this selection into the new table
    151     tout.addRow();
    152     TableCopy::copyRows(tout, subt, outrowCount, 0, 1);
    153     // re-index to 0
    154     if ( avmode != "SCAN" && avmode != "SOURCE" ) {
    155       scanColOut.put(outrowCount, uInt(0));
    156     }
    157     ++outrowCount;
    158     // 2012/02/17 TN
    159     // Since STGrid is implemented, average doesn't consider direction
    160     // when accumulating
    161 //     MDirection::ScalarColumn dircol ;
    162 //     dircol.attach( subt, "DIRECTION" ) ;
    163 //     Int length = subt.nrow() ;
    164 //     vector< Vector<Double> > dirs ;
    165 //     vector<int> indexes ;
    166 //     for ( Int i = 0 ; i < length ; i++ ) {
    167 //       Vector<Double> t = dircol(i).getAngle(Unit(String("rad"))).getValue() ;
    168 //       //os << << count++ << ": " ;
    169 //       //os << "[" << t[0] << "," << t[1] << "]" << LogIO::POST ;
    170 //       bool adddir = true ;
    171 //       for ( uInt j = 0 ; j < dirs.size() ; j++ ) {
    172 //         //if ( allTrue( t == dirs[j] ) ) {
    173 //         Double dx = t[0] - dirs[j][0] ;
    174 //         Double dy = t[1] - dirs[j][1] ;
    175 //         Double dd = sqrt( dx * dx + dy * dy ) ;
    176 //         //if ( allNearAbs( t, dirs[j], tol ) ) {
    177 //         if ( dd <= tol ) {
    178 //           adddir = false ;
    179 //           break ;
    180 //         }
    181 //       }
    182 //       if ( adddir ) {
    183 //         dirs.push_back( t ) ;
    184 //         indexes.push_back( i ) ;
    185 //       }
     144//     // copy the first row of this selection into the new table
     145//     tout.addRow();
     146//     TableCopy::copyRows(tout, subt, outrowCount, 0, 1);
     147//     // re-index to 0
     148//     if ( avmode != "SCAN" && avmode != "SOURCE" ) {
     149//       scanColOut.put(outrowCount, uInt(0));
    186150//     }
    187 //     uInt rowNum = dirs.size() ;
    188 //     tout.addRow( rowNum ) ;
    189 //     for ( uInt i = 0 ; i < rowNum ; i++ ) {
    190 //       TableCopy::copyRows( tout, subt, outrowCount+i, indexes[i], 1 ) ;
    191 //       // re-index to 0
    192 //       if ( avmode != "SCAN" && avmode != "SOURCE" ) {
    193 //         scanColOut.put(outrowCount+i, uInt(0));
    194 //       }       
    195 //     }
    196 //     outrowCount += rowNum ;
     151//     ++outrowCount;
     152    MDirection::ScalarColumn dircol ;
     153    dircol.attach( subt, "DIRECTION" ) ;
     154    Int length = subt.nrow() ;
     155    vector< Vector<Double> > dirs ;
     156    vector<int> indexes ;
     157    for ( Int i = 0 ; i < length ; i++ ) {
     158      Vector<Double> t = dircol(i).getAngle(Unit(String("rad"))).getValue() ;
     159      //os << << count++ << ": " ;
     160      //os << "[" << t[0] << "," << t[1] << "]" << LogIO::POST ;
     161      bool adddir = true ;
     162      for ( uInt j = 0 ; j < dirs.size() ; j++ ) {
     163        //if ( allTrue( t == dirs[j] ) ) {
     164        Double dx = t[0] - dirs[j][0] ;
     165        Double dy = t[1] - dirs[j][1] ;
     166        Double dd = sqrt( dx * dx + dy * dy ) ;
     167        //if ( allNearAbs( t, dirs[j], tol ) ) {
     168        if ( dd <= tol ) {
     169          adddir = false ;
     170          break ;
     171        }
     172      }
     173      if ( adddir ) {
     174        dirs.push_back( t ) ;
     175        indexes.push_back( i ) ;
     176      }
     177    }
     178    uInt rowNum = dirs.size() ;
     179    tout.addRow( rowNum ) ;
     180    for ( uInt i = 0 ; i < rowNum ; i++ ) {
     181      TableCopy::copyRows( tout, subt, outrowCount+i, indexes[i], 1 ) ;
     182      // re-index to 0
     183      if ( avmode != "SCAN" && avmode != "SOURCE" ) {
     184        scanColOut.put(outrowCount+i, uInt(0));
     185      }       
     186    }
     187    outrowCount += rowNum ;
    197188    ++iter;
    198189  }
     
    227218      }
    228219
    229       // 2012/02/17 TN
    230       // Since STGrid is implemented, average doesn't consider direction
    231       // when accumulating
    232 //       vector<uInt> removeRows ;
    233 //       uInt nrsubt = subt.nrow() ;
    234 //       for ( uInt irow = 0 ; irow < nrsubt ; irow++ ) {
    235 //         //if ( !allTrue((subt.col("DIRECTION").getArrayDouble(TableExprId(irow)))==rec.asArrayDouble("DIRECTION")) ) {
    236 //         Vector<Double> x0 = (subt.col("DIRECTION").getArrayDouble(TableExprId(irow))) ;
    237 //         Vector<Double> x1 = rec.asArrayDouble("DIRECTION") ;
    238 //         double dx = x0[0] - x1[0];
    239 //         double dy = x0[1] - x1[1];
    240 //         Double dd = sqrt( dx * dx + dy * dy ) ;
    241 //         //if ( !allNearAbs((subt.col("DIRECTION").getArrayDouble(TableExprId(irow))), rec.asArrayDouble("DIRECTION"), tol ) ) {
    242 //         if ( dd > tol ) {
    243 //           removeRows.push_back( irow ) ;
    244 //         }
    245 //       }
    246 //       if ( removeRows.size() != 0 ) {
    247 //         subt.removeRow( removeRows ) ;
    248 //       }
     220      vector<uInt> removeRows ;
     221      uInt nrsubt = subt.nrow() ;
     222      for ( uInt irow = 0 ; irow < nrsubt ; irow++ ) {
     223        //if ( !allTrue((subt.col("DIRECTION").getArrayDouble(TableExprId(irow)))==rec.asArrayDouble("DIRECTION")) ) {
     224        Vector<Double> x0 = (subt.col("DIRECTION").getArrayDouble(TableExprId(irow))) ;
     225        Vector<Double> x1 = rec.asArrayDouble("DIRECTION") ;
     226        double dx = x0[0] - x1[0];
     227        double dy = x0[1] - x1[1];
     228        Double dd = sqrt( dx * dx + dy * dy ) ;
     229        //if ( !allNearAbs((subt.col("DIRECTION").getArrayDouble(TableExprId(irow))), rec.asArrayDouble("DIRECTION"), tol ) ) {
     230        if ( dd > tol ) {
     231          removeRows.push_back( irow ) ;
     232        }
     233      }
     234      if ( removeRows.size() != 0 ) {
     235        subt.removeRow( removeRows ) ;
     236      }
    249237     
    250 //       if ( nrsubt == removeRows.size() )
    251 //         throw(AipsError("Averaging data is empty.")) ;
     238      if ( nrsubt == removeRows.size() )
     239        throw(AipsError("Averaging data is empty.")) ;
    252240
    253241      specCol.attach(subt,"SPECTRA");
     
    333321{
    334322  (void) mode; // currently unused
    335   // 2012/02/17 TN
    336   // Since STGrid is implemented, average doesn't consider direction
    337   // when accumulating
    338323  // check if OTF observation
    339 //   String obstype = in->getHeader().obstype ;
    340 //   Double tol = 0.0 ;
    341 //   if ( obstype.find( "OTF" ) != String::npos ) {
    342 //     tol = TOL_OTF ;
    343 //   }
    344 //   else {
    345 //     tol = TOL_POINT ;
    346 //   }
     324  String obstype = in->getHeader().obstype ;
     325  Double tol = 0.0 ;
     326  if ( obstype.find( "OTF" ) != String::npos ) {
     327    tol = TOL_OTF ;
     328  }
     329  else {
     330    tol = TOL_POINT ;
     331  }
    347332
    348333  // clone as this is non insitu
     
    377362    flagCol.attach(subt,"FLAGTRA");
    378363    tsysCol.attach(subt,"TSYS");
    379 
    380     tout.addRow();
    381     TableCopy::copyRows(tout, subt, outrowCount, 0, 1);
    382     if ( avmode != "SCAN") {
    383       scanColOut.put(outrowCount, uInt(0));
    384     }
    385     Vector<Float> tmp;
    386     specCol.get(0, tmp);
    387     uInt nchan = tmp.nelements();
    388     // have to do channel by channel here as MaskedArrMath
    389     // doesn't have partialMedians
    390     Vector<uChar> flags = flagCol.getColumn(Slicer(Slice(0)));
    391     Vector<Float> outspec(nchan);
    392     Vector<uChar> outflag(nchan,0);
    393     Vector<Float> outtsys(1);/// @fixme when tsys is channel based
    394     for (uInt i=0; i<nchan; ++i) {
    395       Vector<Float> specs = specCol.getColumn(Slicer(Slice(i)));
    396       MaskedArray<Float> ma = maskedArray(specs,flags);
    397       outspec[i] = median(ma);
    398       if ( allEQ(ma.getMask(), False) )
    399         outflag[i] = userflag;// flag data
    400     }
    401     outtsys[0] = median(tsysCol.getColumn());
    402     specColOut.put(outrowCount, outspec);
    403     flagColOut.put(outrowCount, outflag);
    404     tsysColOut.put(outrowCount, outtsys);
    405     Double intsum = sum(intCol.getColumn());
    406     intColOut.put(outrowCount, intsum);
    407     ++outrowCount;
     364//     tout.addRow();
     365//     TableCopy::copyRows(tout, subt, outrowCount, 0, 1);
     366//     if ( avmode != "SCAN") {
     367//       scanColOut.put(outrowCount, uInt(0));
     368//     }
     369//     Vector<Float> tmp;
     370//     specCol.get(0, tmp);
     371//     uInt nchan = tmp.nelements();
     372//     // have to do channel by channel here as MaskedArrMath
     373//     // doesn't have partialMedians
     374//     Vector<uChar> flags = flagCol.getColumn(Slicer(Slice(0)));
     375//     Vector<Float> outspec(nchan);
     376//     Vector<uChar> outflag(nchan,0);
     377//     Vector<Float> outtsys(1);/// @fixme when tsys is channel based
     378//     for (uInt i=0; i<nchan; ++i) {
     379//       Vector<Float> specs = specCol.getColumn(Slicer(Slice(i)));
     380//       MaskedArray<Float> ma = maskedArray(specs,flags);
     381//       outspec[i] = median(ma);
     382//       if ( allEQ(ma.getMask(), False) )
     383//         outflag[i] = userflag;// flag data
     384//     }
     385//     outtsys[0] = median(tsysCol.getColumn());
     386//     specColOut.put(outrowCount, outspec);
     387//     flagColOut.put(outrowCount, outflag);
     388//     tsysColOut.put(outrowCount, outtsys);
     389//     Double intsum = sum(intCol.getColumn());
     390//     intColOut.put(outrowCount, intsum);
     391//     ++outrowCount;
     392//     ++iter;
     393    MDirection::ScalarColumn dircol ;
     394    dircol.attach( subt, "DIRECTION" ) ;
     395    Int length = subt.nrow() ;
     396    vector< Vector<Double> > dirs ;
     397    vector<int> indexes ;
     398    // Handle MX mode averaging
     399    if (in->nbeam() > 1 ) {     
     400      length = 1;
     401    }
     402    for ( Int i = 0 ; i < length ; i++ ) {
     403      Vector<Double> t = dircol(i).getAngle(Unit(String("rad"))).getValue() ;
     404      bool adddir = true ;
     405      for ( uInt j = 0 ; j < dirs.size() ; j++ ) {
     406        //if ( allTrue( t == dirs[j] ) ) {
     407        Double dx = t[0] - dirs[j][0] ;
     408        Double dy = t[1] - dirs[j][1] ;
     409        Double dd = sqrt( dx * dx + dy * dy ) ;
     410        //if ( allNearAbs( t, dirs[j], tol ) ) {
     411        if ( dd <= tol ) {
     412          adddir = false ;
     413          break ;
     414        }
     415      }
     416      if ( adddir ) {
     417        dirs.push_back( t ) ;
     418        indexes.push_back( i ) ;
     419      }
     420    }
     421    uInt rowNum = dirs.size() ;
     422    tout.addRow( rowNum );
     423    for ( uInt i = 0 ; i < rowNum ; i++ ) {
     424      TableCopy::copyRows(tout, subt, outrowCount+i, indexes[i], 1) ;
     425      // Handle MX mode averaging
     426      if ( avmode != "SCAN") {
     427        scanColOut.put(outrowCount+i, uInt(0));
     428      }
     429    }
     430    MDirection::ScalarColumn dircolOut ;
     431    dircolOut.attach( tout, "DIRECTION" ) ;
     432    for ( uInt irow = 0 ; irow < rowNum ; irow++ ) {
     433      Vector<Double> t = \
     434        dircolOut(outrowCount+irow).getAngle(Unit(String("rad"))).getValue() ;
     435      Vector<Float> tmp;
     436      specCol.get(0, tmp);
     437      uInt nchan = tmp.nelements();
     438      // have to do channel by channel here as MaskedArrMath
     439      // doesn't have partialMedians
     440      Vector<uChar> flags = flagCol.getColumn(Slicer(Slice(0)));
     441      // mask spectra for different DIRECTION
     442      for ( uInt jrow = 0 ; jrow < subt.nrow() ; jrow++ ) {
     443        Vector<Double> direction = \
     444          dircol(jrow).getAngle(Unit(String("rad"))).getValue() ;
     445        //if ( t[0] != direction[0] || t[1] != direction[1] ) {
     446        Double dx = t[0] - direction[0];
     447        Double dy = t[1] - direction[1];
     448        Double dd = sqrt(dx*dx + dy*dy);
     449        //if ( !allNearAbs( t, direction, tol ) ) {
     450        if ( dd > tol &&  in->nbeam() < 2 ) {
     451          flags[jrow] = userflag ;
     452        }
     453      }
     454      Vector<Float> outspec(nchan);
     455      Vector<uChar> outflag(nchan,0);
     456      Vector<Float> outtsys(1);/// @fixme when tsys is channel based
     457      for (uInt i=0; i<nchan; ++i) {
     458        Vector<Float> specs = specCol.getColumn(Slicer(Slice(i)));
     459        MaskedArray<Float> ma = maskedArray(specs,flags);
     460        outspec[i] = median(ma);
     461        if ( allEQ(ma.getMask(), False) )
     462          outflag[i] = userflag;// flag data
     463      }
     464      outtsys[0] = median(tsysCol.getColumn());
     465      specColOut.put(outrowCount+irow, outspec);
     466      flagColOut.put(outrowCount+irow, outflag);
     467      tsysColOut.put(outrowCount+irow, outtsys);
     468      Vector<Double> integ = intCol.getColumn() ;
     469      MaskedArray<Double> mi = maskedArray( integ, flags ) ;
     470      Double intsum = sum(mi);
     471      intColOut.put(outrowCount+irow, intsum);
     472    }
     473    outrowCount += rowNum ;
    408474    ++iter;
    409 
    410     // 2012/02/17 TN
    411     // Since STGrid is implemented, average doesn't consider direction
    412     // when accumulating
    413 //     MDirection::ScalarColumn dircol ;
    414 //     dircol.attach( subt, "DIRECTION" ) ;
    415 //     Int length = subt.nrow() ;
    416 //     vector< Vector<Double> > dirs ;
    417 //     vector<int> indexes ;
    418 //     // Handle MX mode averaging
    419 //     if (in->nbeam() > 1 ) {     
    420 //       length = 1;
    421 //     }
    422 //     for ( Int i = 0 ; i < length ; i++ ) {
    423 //       Vector<Double> t = dircol(i).getAngle(Unit(String("rad"))).getValue() ;
    424 //       bool adddir = true ;
    425 //       for ( uInt j = 0 ; j < dirs.size() ; j++ ) {
    426 //         //if ( allTrue( t == dirs[j] ) ) {
    427 //         Double dx = t[0] - dirs[j][0] ;
    428 //         Double dy = t[1] - dirs[j][1] ;
    429 //         Double dd = sqrt( dx * dx + dy * dy ) ;
    430 //         //if ( allNearAbs( t, dirs[j], tol ) ) {
    431 //         if ( dd <= tol ) {
    432 //           adddir = false ;
    433 //           break ;
    434 //         }
    435 //       }
    436 //       if ( adddir ) {
    437 //         dirs.push_back( t ) ;
    438 //         indexes.push_back( i ) ;
    439 //       }
    440 //     }
    441 //     uInt rowNum = dirs.size() ;
    442 //     tout.addRow( rowNum );
    443 //     for ( uInt i = 0 ; i < rowNum ; i++ ) {
    444 //       TableCopy::copyRows(tout, subt, outrowCount+i, indexes[i], 1) ;
    445 //       // Handle MX mode averaging
    446 //       if ( avmode != "SCAN") {
    447 //         scanColOut.put(outrowCount+i, uInt(0));
    448 //       }
    449 //     }
    450 //     MDirection::ScalarColumn dircolOut ;
    451 //     dircolOut.attach( tout, "DIRECTION" ) ;
    452 //     for ( uInt irow = 0 ; irow < rowNum ; irow++ ) {
    453 //       Vector<Double> t = \
    454 //      dircolOut(outrowCount+irow).getAngle(Unit(String("rad"))).getValue() ;
    455 //       Vector<Float> tmp;
    456 //       specCol.get(0, tmp);
    457 //       uInt nchan = tmp.nelements();
    458 //       // have to do channel by channel here as MaskedArrMath
    459 //       // doesn't have partialMedians
    460 //       Vector<uChar> flags = flagCol.getColumn(Slicer(Slice(0)));
    461 //       // mask spectra for different DIRECTION
    462 //       for ( uInt jrow = 0 ; jrow < subt.nrow() ; jrow++ ) {
    463 //         Vector<Double> direction = \
    464 //        dircol(jrow).getAngle(Unit(String("rad"))).getValue() ;
    465 //         //if ( t[0] != direction[0] || t[1] != direction[1] ) {
    466 //         Double dx = t[0] - direction[0];
    467 //         Double dy = t[1] - direction[1];
    468 //         Double dd = sqrt(dx*dx + dy*dy);
    469 //         //if ( !allNearAbs( t, direction, tol ) ) {
    470 //         if ( dd > tol &&  in->nbeam() < 2 ) {
    471 //           flags[jrow] = userflag ;
    472 //         }
    473 //       }
    474 //       Vector<Float> outspec(nchan);
    475 //       Vector<uChar> outflag(nchan,0);
    476 //       Vector<Float> outtsys(1);/// @fixme when tsys is channel based
    477 //       for (uInt i=0; i<nchan; ++i) {
    478 //         Vector<Float> specs = specCol.getColumn(Slicer(Slice(i)));
    479 //         MaskedArray<Float> ma = maskedArray(specs,flags);
    480 //         outspec[i] = median(ma);
    481 //         if ( allEQ(ma.getMask(), False) )
    482 //           outflag[i] = userflag;// flag data
    483 //       }
    484 //       outtsys[0] = median(tsysCol.getColumn());
    485 //       specColOut.put(outrowCount+irow, outspec);
    486 //       flagColOut.put(outrowCount+irow, outflag);
    487 //       tsysColOut.put(outrowCount+irow, outtsys);
    488 //       Vector<Double> integ = intCol.getColumn() ;
    489 //       MaskedArray<Double> mi = maskedArray( integ, flags ) ;
    490 //       Double intsum = sum(mi);
    491 //       intColOut.put(outrowCount+irow, intsum);
    492 //     }
    493 //     outrowCount += rowNum ;
    494 //     ++iter;
    495475  }
    496476  return out;
     
    19301910  ArrayColumn<Float> specCol(tout, "SPECTRA");
    19311911  ArrayColumn<uChar> flagCol(tout, "FLAGTRA");
    1932   ArrayColumn<Float> tsysCol(tout, "TSYS");
    1933 
    19341912  for (uInt i=0; i < tout.nrow(); ++i ) {
    19351913    MaskedArray<Float> main  = maskedArray(specCol(i), flagCol(i));
    19361914    MaskedArray<Float> maout;
    19371915    LatticeUtilities::bin(maout, main, 0, Int(width));
     1916    /// @todo implement channel based tsys binning
    19381917    specCol.put(i, maout.getArray());
    19391918    flagCol.put(i, flagsFromMA(maout));
    1940     if (tsysCol(i).nelements() == specCol(i).nelements()) {
    1941       MaskedArray<Float> matsysin = maskedArray(tsysCol(i), flagCol(i));
    1942       MaskedArray<Float> matsysout;
    1943       LatticeUtilities::bin(matsysout, matsysin, 0, Int(width));
    1944       tsysCol.put(i, matsysout.getArray());
    1945     }
    19461919    // take only the first binned spectrum's length for the deprecated
    19471920    // global header item nChan
     
    27772750                             mask, timeCol(i), !first,
    27782751                             interp, False);
    2779           (void) ok; // unused stop compiler nagging
     2752          (void) ok; // unused stop compiler nagging     
    27802753          // back into scantable
    27812754          flagOut.resize(maskOut.nelements());
     
    29812954                    "Use merge first."));
    29822955 
    2983   // 2012/02/17 TN
    2984   // Since STGrid is implemented, average doesn't consider direction
    2985   // when accumulating
    29862956  // check if OTF observation
    2987 //   String obstype = in[0]->getHeader().obstype ;
    2988 //   Double tol = 0.0 ;
    2989 //   if ( obstype.find( "OTF" ) != String::npos ) {
    2990 //     tol = TOL_OTF ;
    2991 //   }
    2992 //   else {
    2993 //     tol = TOL_POINT ;
    2994 //   }
     2957  String obstype = in[0]->getHeader().obstype ;
     2958  Double tol = 0.0 ;
     2959  if ( obstype.find( "OTF" ) != String::npos ) {
     2960    tol = TOL_OTF ;
     2961  }
     2962  else {
     2963    tol = TOL_POINT ;
     2964  }
    29952965
    29962966  CountedPtr<Scantable> out ;     // processed result
     
    30453015      uInt rows = tmpin[itable]->nrow() ;
    30463016      uInt freqnrows = tmpin[itable]->frequencies().table().nrow() ;
    3047       freqIDCol.attach( tmpin[itable]->table(), "FREQ_ID" ) ;
    3048       //ifnoCol.attach( tmpin[itable]->table(), "IFNO" ) ;
    30493017      for ( uInt irow = 0 ; irow < rows ; irow++ ) {
    30503018        if ( freqid[itable].size() == freqnrows ) {
     
    30523020        }
    30533021        else {
     3022          freqIDCol.attach( tmpin[itable]->table(), "FREQ_ID" ) ;
     3023          ifnoCol.attach( tmpin[itable]->table(), "IFNO" ) ;
    30543024          uInt id = freqIDCol( irow ) ;
    30553025          if ( freqid[itable].size() == 0 || count( freqid[itable].begin(), freqid[itable].end(), id ) == 0 ) {
    30563026            //os << "itable = " << itable << ": IF " << id << " is included in the list" << LogIO::POST ;
    30573027            vector<double> abcissa = tmpin[itable]->getAbcissa( irow ) ;
    3058             double lbedge, rbedge;
    30593028            freqid[itable].push_back( id ) ;
    3060             lbedge = abcissa[0] - 0.5 * ( abcissa[1] - abcissa[0] );
    3061             rbedge = abcissa[abcissa.size()-1] + 0.5 * ( abcissa[1] - abcissa[0] );
    3062             iffreq[itable].push_back( min(lbedge, rbedge) ) ;
    3063             iffreq[itable].push_back( max(lbedge, rbedge) ) ;
     3029            iffreq[itable].push_back( abcissa[0] - 0.5 * ( abcissa[1] - abcissa[0] ) ) ;
     3030            iffreq[itable].push_back( abcissa[abcissa.size()-1] + 0.5 * ( abcissa[1] - abcissa[0] ) ) ;
    30643031          }
    30653032        }
     
    31463113    // Grouping continuous IF groups (without frequency gap)
    31473114    // freqgrp: list of IF group indexes in each frequency group
     3115    // freqrange: list of minimum and maximum frequency in each frequency group
    31483116    // freqgrp[numgrp][nummember]
    31493117    // freqgrp: [[ifgrp00, ifgrp01, ifgrp02, ...],
     
    31513119    //           ...
    31523120    //           [ifgrpn0, ifgrpn1, ifgrpn2, ...]]
     3121    // freqrange[numgrp*2]
     3122    // freqrange: [min_grp0, max_grp0, min_grp1, max_grp1, ...]
    31533123    vector< vector<uInt> > freqgrp ;
    31543124    double freqrange = 0.0 ;
     
    31663136      freqrange = ifgfreq[2*i+1] ;
    31673137    }
    3168 
     3138       
    31693139
    31703140    // print IF groups
     
    33553325
    33563326    // save column values in the vector
     3327    vector< vector<uInt> > freqTableIdVec( insize ) ;
    33573328    vector< vector<uInt> > freqIdVec( insize ) ;
    33583329    vector< vector<uInt> > ifNoVec( insize ) ;
    33593330    for ( uInt itable = 0 ; itable < insize ; itable++ ) {
     3331      ScalarColumn<uInt> freqIDs ;
     3332      freqIDs.attach( newin[itable]->frequencies().table(), "ID" ) ;
    33603333      ifnoCol.attach( newin[itable]->table(), "IFNO" ) ;
    33613334      freqIDCol.attach( newin[itable]->table(), "FREQ_ID" ) ;
     3335      for ( uInt irow = 0 ; irow < newin[itable]->frequencies().table().nrow() ; irow++ ) {
     3336        freqTableIdVec[itable].push_back( freqIDs( irow ) ) ;
     3337      }
    33623338      for ( uInt irow = 0 ; irow < newin[itable]->table().nrow() ; irow++ ) {
    33633339        freqIdVec[itable].push_back( freqIDCol( irow ) ) ;
     
    33743350      vector<uInt> freqIdUpdate ;
    33753351      for ( uInt irow = 0 ; irow < rows ; irow++ ) {
    3376         uInt ifno = ifNoVec[itable][irow] ;  // IFNO is reset by group index (IF group index)
     3352        uInt ifno = ifNoVec[itable][irow] ;  // IFNO is reset by group index
    33773353        double minfreq = ifgfreq[2*ifno] ;
    33783354        double maxfreq = ifgfreq[2*ifno+1] ;
     
    33823358        double resol = abcissa[1] - abcissa[0] ;
    33833359        //os << "abcissa range  : [" << abcissa[0] << "," << abcissa[nchan-1] << "]" << LogIO::POST ;
    3384         uInt imin, imax;
    3385         int sigres;
    3386         if ( resol >= 0. ) {
    3387           imin = 0;
    3388           imax = nchan - 1 ;
    3389           sigres = 1 ;
    3390         } else {
    3391           imin = nchan - 1 ;
    3392           imax = 0 ;
    3393           sigres = -1 ;
    3394           resol = abs(resol) ;
    3395         }
    3396         if ( minfreq <= abcissa[imin] )
    3397           nminchan = imin ;
     3360        if ( minfreq <= abcissa[0] )
     3361          nminchan = 0 ;
    33983362        else {
    33993363          //double cfreq = ( minfreq - abcissa[0] ) / resol ;
    3400           double cfreq = ( minfreq - abcissa[imin] + 0.5 * resol ) / resol ;
    3401           nminchan = imin + sigres * (int(cfreq) + ( ( cfreq - int(cfreq) <= 0.5 ) ? 0 : 1 )) ;
     3364          double cfreq = ( minfreq - abcissa[0] + 0.5 * resol ) / resol ;
     3365          nminchan = int(cfreq) + ( ( cfreq - int(cfreq) <= 0.5 ) ? 0 : 1 ) ;
    34023366        }
    3403         if ( maxfreq >= abcissa[imax] )
    3404           nmaxchan = imax;
     3367        if ( maxfreq >= abcissa[abcissa.size()-1] )
     3368          nmaxchan = abcissa.size() - 1 ;
    34053369        else {
    34063370          //double cfreq = ( abcissa[abcissa.size()-1] - maxfreq ) / resol ;
    3407           double cfreq = ( abcissa[imax] - maxfreq + 0.5 * resol ) / resol ;
    3408           nmaxchan = imax - sigres * (int(cfreq) +( ( cfreq - int(cfreq) >= 0.5 ) ? 1 : 0 )) ;
     3371          double cfreq = ( abcissa[abcissa.size()-1] - maxfreq + 0.5 * resol ) / resol ;
     3372          nmaxchan = abcissa.size() - 1 - int(cfreq) - ( ( cfreq - int(cfreq) >= 0.5 ) ? 1 : 0 ) ;
    34093373        }
    34103374        //os << "channel range (" << irow << "): [" << nminchan << "," << nmaxchan << "]" << LogIO::POST ;
    3411         if ( nmaxchan < nminchan ) {
    3412           int tmp = nmaxchan ;
    3413           nmaxchan = nminchan ;
    3414           nminchan = tmp ;
    3415         }
    34163375        if ( nmaxchan > nminchan ) {
    34173376          newin[itable]->reshapeSpectrum( nminchan, nmaxchan, irow ) ;
    34183377          int newchan = nmaxchan - nminchan + 1 ;
    3419           if ( count( freqIdUpdate.begin(), freqIdUpdate.end(), freqIdVec[itable][irow] ) == 0 && newchan < nchan ) {
     3378          if ( count( freqIdUpdate.begin(), freqIdUpdate.end(), freqIdVec[itable][irow] ) == 0 && newchan < nchan )
    34203379            freqIdUpdate.push_back( freqIdVec[itable][irow] ) ;
    3421 
    3422             // Update before nminchan is lost
    3423             uInt freqId = freqIdVec[itable][irow] ;
    3424             Double refpix ;
    3425             Double refval ;
    3426             Double increment ;
    3427             newin[itable]->frequencies().getEntry( refpix, refval, increment, freqId ) ;
    3428             //refval = refval - ( refpix - nminchan ) * increment ;
    3429             refval = abcissa[nminchan] ;
    3430             refpix = 0 ;
    3431             newin[itable]->frequencies().setEntry( refpix, refval, increment, freqId ) ;
    3432           }
    34333380        }
    34343381        else {
     
    34363383        }
    34373384      }
    3438 //       for ( uInt i = 0 ; i < freqIdUpdate.size() ; i++ ) {
    3439 //      uInt freqId = freqIdUpdate[i] ;
    3440 //      Double refpix ;
    3441 //      Double refval ;
    3442 //      Double increment ;
     3385      for ( uInt i = 0 ; i < freqIdUpdate.size() ; i++ ) {
     3386        uInt freqId = freqIdUpdate[i] ;
     3387        Double refpix ;
     3388        Double refval ;
     3389        Double increment ;
    34433390       
    3444 //      // update row
    3445 //      newin[itable]->frequencies().getEntry( refpix, refval, increment, freqId ) ;
    3446 //      refval = refval - ( refpix - nminchan ) * increment ;
    3447 //      refpix = 0 ;
    3448 //      newin[itable]->frequencies().setEntry( refpix, refval, increment, freqId ) ;
    3449 //       }   
     3391        // update row
     3392        newin[itable]->frequencies().getEntry( refpix, refval, increment, freqId ) ;
     3393        refval = refval - ( refpix - nminchan ) * increment ;
     3394        refpix = 0 ;
     3395        newin[itable]->frequencies().setEntry( refpix, refval, increment, freqId ) ;
     3396      }   
    34503397    }
    34513398
     
    34843431            if ( nchan < minchan ) {
    34853432              minchan = nchan ;
    3486               maxdnu = abs(dnu) ;
     3433              maxdnu = dnu ;
    34873434              newin[tableid]->frequencies().getEntry( refpixref, refvalref, refinc, rowid ) ;
    34883435              refreqid = rowid ;
    34893436              reftable = tableid ;
    3490               // Spectra are reversed when dnu < 0
    3491               if (dnu < 0)
    3492                 refpixref = minchan - 1 -refpixref ;
    34933437            }
    34943438          }
     
    35053449          //os << "   regridChannel applied to " ;
    35063450          //if ( tableid != reftable )
    3507           refreqid = newin[tableid]->frequencies().addEntry( refpixref, refvalref, maxdnu ) ;
     3451          refreqid = newin[tableid]->frequencies().addEntry( refpixref, refvalref, refinc ) ;
    35083452          for ( uInt irow = 0 ; irow < newin[tableid]->table().nrow() ; irow++ ) {
    35093453            uInt tfreqid = freqIdVec[tableid][irow] ;
     
    35263470          vector<double> abcissa = newin[tableid]->getAbcissa( index ) ;
    35273471          minchan = abcissa.size() ;
    3528           maxdnu = abs( abcissa[1] - abcissa[0]) ;
     3472          maxdnu = abcissa[1] - abcissa[0] ;
    35293473        }
    35303474      }
     
    35963540          vector<double> abcissa = tmpout->getAbcissa( irow ) ;
    35973541          double bw = ( abcissa[1] - abcissa[0] ) * abcissa.size() ;
    3598           int nchan = (int) abs( bw / gmaxdnu[igrp] ) ;
    3599           // All spectra will have positive frequency increments
     3542          int nchan = (int)( bw / gmaxdnu[igrp] ) ;
    36003543          tmpout->regridChannel( nchan, gmaxdnu[igrp], irow ) ;
    36013544          break ;
     
    36143557    ScalarColumn<uInt> freqidColOut ;
    36153558    freqidColOut.attach( out->table(), "FREQ_ID" ) ;
    3616 //     MDirection::ScalarColumn dirColOut ;
    3617 //     dirColOut.attach( out->table(), "DIRECTION" ) ;
     3559    MDirection::ScalarColumn dirColOut ;
     3560    dirColOut.attach( out->table(), "DIRECTION" ) ;
    36183561    Table &tab = tmpout->table() ;
    36193562    Block<String> cols(1);
    36203563    cols[0] = String("POLNO") ;
    36213564    TableIterator iter( tab, cols ) ;
     3565    bool done = false ;
    36223566    vector< vector<uInt> > sizes( freqgrp.size() ) ;
    36233567    while( !iter.pastEnd() ) {
     
    36313575      ScalarColumn<uInt> polnos ;
    36323576      polnos.attach( iter.table(), "POLNO" ) ;
    3633 //       MDirection::ScalarColumn dircol ;
    3634 //       dircol.attach( iter.table(), "DIRECTION" ) ;
     3577      MDirection::ScalarColumn dircol ;
     3578      dircol.attach( iter.table(), "DIRECTION" ) ;
    36353579      uInt polno = polnos( 0 ) ;
    36363580      //os << "POLNO iteration: " << polno << LogIO::POST ;
     
    36703614//       }
    36713615      // get a list of number of channels for each frequency group member
    3672       for ( uInt igrp = 0 ; igrp < freqgrp.size() ; igrp++ ) {
    3673         sizes[igrp].resize( freqgrp[igrp].size() ) ;
    3674         for ( uInt imem = 0 ; imem < freqgrp[igrp].size() ; imem++ ) {
    3675           for ( uInt irow = 0 ; irow < iter.table().nrow() ; irow++ ) {
    3676             uInt ifno = ifnoCol( irow ) ;
    3677             if ( ifno == freqgrp[igrp][imem] ) {
    3678               Vector<Float> spec = specCols( irow ) ;
    3679               sizes[igrp][imem] = spec.nelements() ;
    3680               break ;
    3681             }
    3682           }
    3683         }
     3616      if ( !done ) {
     3617        for ( uInt igrp = 0 ; igrp < freqgrp.size() ; igrp++ ) {
     3618          sizes[igrp].resize( freqgrp[igrp].size() ) ;
     3619          for ( uInt imem = 0 ; imem < freqgrp[igrp].size() ; imem++ ) {
     3620            for ( uInt irow = 0 ; irow < iter.table().nrow() ; irow++ ) {
     3621              uInt ifno = ifnoCol( irow ) ;
     3622              if ( ifno == freqgrp[igrp][imem] ) {
     3623                Vector<Float> spec = specCols( irow ) ;
     3624                sizes[igrp][imem] = spec.nelements() ;
     3625                break ;
     3626              }               
     3627            }
     3628          }
     3629        }
     3630        done = true ;
    36843631      }
    36853632      // combine spectra
     
    36883635        if ( polout == polno ) {
    36893636          uInt ifout = ifnoColOut( irow ) ;
    3690 //           Vector<Double> direction = dirColOut(irow).getAngle(Unit(String("rad"))).getValue() ;
     3637          Vector<Double> direction = dirColOut(irow).getAngle(Unit(String("rad"))).getValue() ;
    36913638          uInt igrp ;
    36923639          for ( uInt jgrp = 0 ; jgrp < freqgrp.size() ; jgrp++ ) {
     
    36993646            for ( uInt jrow = 0 ; jrow < iter.table().nrow() ; jrow++ ) {
    37003647              uInt ifno = ifnoCol( jrow ) ;
    3701               // 2012/02/17 TN
    3702               // Since STGrid is implemented, average doesn't consider direction
    3703               // when accumulating
    3704 //               Vector<Double> tdir = dircol(jrow).getAngle(Unit(String("rad"))).getValue() ;
    3705 //               //if ( ifno == freqgrp[igrp][imem] && allTrue( tdir == direction  ) ) {
    3706 //               Double dx = tdir[0] - direction[0] ;
    3707 //               Double dy = tdir[1] - direction[1] ;
    3708 //               Double dd = sqrt( dx * dx + dy * dy ) ;
     3648              Vector<Double> tdir = dircol(jrow).getAngle(Unit(String("rad"))).getValue() ;
     3649              //if ( ifno == freqgrp[igrp][imem] && allTrue( tdir == direction  ) ) {
     3650              Double dx = tdir[0] - direction[0] ;
     3651              Double dy = tdir[1] - direction[1] ;
     3652              Double dd = sqrt( dx * dx + dy * dy ) ;
    37093653              //if ( ifno == freqgrp[igrp][imem] && allNearAbs( tdir, direction, tol ) ) {
    3710 //               if ( ifno == freqgrp[igrp][imem] && dd <= tol ) {
    3711               if ( ifno == freqgrp[igrp][imem] ) {
     3654              if ( ifno == freqgrp[igrp][imem] && dd <= tol ) {
    37123655                Vector<Float> spec = specCols( jrow ) ;
    37133656                Vector<uChar> flag = flagCols( jrow ) ;
     
    37283671          specColOut.put( irow, newspec ) ;
    37293672          flagColOut.put( irow, newflag ) ;
    3730           // IFNO renumbering (renumbered as frequency group ID)
     3673          // IFNO renumbering
    37313674          ifnoColOut.put( irow, igrp ) ;
    37323675        }
     
    37393682      uInt index = 0 ;
    37403683      uInt pixShift = 0 ;
    3741 
    37423684      while ( freqgrp[igrp][index] != gmemid[igrp] ) {
    37433685        pixShift += sizes[igrp][index++] ;
    37443686      }
    37453687      for ( uInt irow = 0 ; irow < out->table().nrow() ; irow++ ) {
    3746         //if ( ifnoColOut( irow ) == gmemid[igrp] && !updated[igrp] ) {
    3747         if ( ifnoColOut( irow ) == igrp && !updated[igrp] ) {
     3688        if ( ifnoColOut( irow ) == gmemid[igrp] && !updated[igrp] ) {
    37483689          uInt freqidOut = freqidColOut( irow ) ;
    37493690          //os << "freqgrp " << igrp << " freqidOut = " << freqidOut << LogIO::POST ;
     
    37523693          double increm ;
    37533694          out->frequencies().getEntry( refpix, refval, increm, freqidOut ) ;
    3754           if (increm < 0)
    3755             refpix = sizes[igrp][index] - 1 - refpix ; // reversed
    37563695          refpix += pixShift ;
    3757           out->frequencies().setEntry( refpix, refval, gmaxdnu[igrp], freqidOut ) ;
     3696          out->frequencies().setEntry( refpix, refval, increm, freqidOut ) ;
    37583697          updated[igrp] = true ;
    37593698        }
  • /trunk/src/STMathWrapper.h

    r2473 r2373  
    197197                                   const std::string& refTime,
    198198                                   const std::string& method  )
    199   { return ScantableWrapper(STMath::frequencyAlign(in.getCP(),
    200                                                    refTime, method)); }
     199  { return ScantableWrapper(STMath::frequencyAlign(in.getCP())); }
    201200
    202201  ScantableWrapper convertPolarisation( const ScantableWrapper& in,
  • /trunk/src/Scantable.cpp

    r2473 r2373  
    7070#include "STUpgrade.h"
    7171#include "Scantable.h"
    72 
    73 #define debug 1
    7472
    7573using namespace casa;
     
    18871885}
    18881886
    1889 void asap::Scantable::regridSpecChannel( double dnu, int nChan )
    1890 {
    1891   LogIO os( LogOrigin( "Scantable", "regridChannel()", WHERE ) ) ;
    1892   os << "Regrid abcissa with spectral resoultion " << dnu << " " << freqTable_.getUnitString() << " with channel number " << ((nChan>0)? String(nChan) : "covering band width")<< LogIO::POST ;
    1893   int freqnrow = freqTable_.table().nrow() ;
    1894   Vector<bool> firstTime( freqnrow, true ) ;
    1895   double oldincr, factor;
    1896   uInt currId;
    1897   Double refpix ;
    1898   Double refval ;
    1899   Double increment ;
    1900   for ( int irow = 0 ; irow < nrow() ; irow++ ) {
    1901     currId = mfreqidCol_(irow);
    1902     vector<double> abcissa = getAbcissa( irow ) ;
    1903     if (nChan < 0) {
    1904       int oldsize = abcissa.size() ;
    1905       double bw = (abcissa[oldsize-1]-abcissa[0]) +                     \
    1906         0.5 * (abcissa[1]-abcissa[0] + abcissa[oldsize-1]-abcissa[oldsize-2]) ;
    1907       nChan = int( ceil( abs(bw/dnu) ) ) ;
    1908     }
    1909     // actual regridding
    1910     regridChannel( nChan, dnu, irow ) ;
    1911 
    1912     // update FREQUENCIES subtable
    1913     if (firstTime[currId]) {
    1914       oldincr = abcissa[1]-abcissa[0] ;
    1915       factor = dnu/oldincr ;
    1916       firstTime[currId] = false ;
    1917       freqTable_.getEntry( refpix, refval, increment, currId ) ;
    1918 
    1919       //refval = refval - ( refpix + 0.5 * (1 - factor) ) * increment ;
    1920       if (factor > 0 ) {
    1921         refpix = (refpix + 0.5)/factor - 0.5;
    1922       } else {
    1923         refpix = (abcissa.size() - 0.5 - refpix)/abs(factor) - 0.5;
    1924       }
    1925       freqTable_.setEntry( refpix, refval, increment*factor, currId ) ;
    1926       //os << "ID" << currId << ": channel width (Orig) = " << oldincr << " [" << freqTable_.getUnitString() << "], scale factor = " << factor << LogIO::POST ;
    1927       //os << "     frequency increment (Orig) = " << increment << "-> (New) " << increment*factor << LogIO::POST ;
    1928     }
    1929   }
    1930 }
    1931 
    19321887void asap::Scantable::regridChannel( int nChan, double dnu )
    19331888{
     
    19501905  }
    19511906
    1952   // change channel number for specCol_, flagCol_, and tsysCol_ (if necessary)
     1907  // change channel number for specCol_ and flagCol_
     1908  Vector<Float> newspec( nChan, 0 ) ;
     1909  Vector<uChar> newflag( nChan, false ) ;
    19531910  vector<string> coordinfo = getCoordInfo() ;
    19541911  string oldinfo = coordinfo[0] ;
     
    19761933  Vector<Float> oldspec = specCol_( irow ) ;
    19771934  Vector<uChar> oldflag = flagsCol_( irow ) ;
    1978   Vector<Float> oldtsys = tsysCol_( irow ) ;
    19791935  Vector<Float> newspec( nChan, 0 ) ;
    1980   Vector<uChar> newflag( nChan, true ) ;
    1981   Vector<Float> newtsys ;
    1982   bool regridTsys = false ;
    1983   if (oldtsys.size() == oldspec.size()) {
    1984     regridTsys = true ;
    1985     newtsys.resize(nChan,false) ;
    1986     newtsys = 0 ;
    1987   }
     1936  Vector<uChar> newflag( nChan, false ) ;
    19881937
    19891938  // regrid
     
    19911940  int oldsize = abcissa.size() ;
    19921941  double olddnu = abcissa[1] - abcissa[0] ;
    1993   //int ichan = 0 ;
     1942  //int refChan = 0 ;
     1943  //double frac = 0.0 ;
     1944  //double wedge = 0.0 ;
     1945  //double pile = 0.0 ;
     1946  int ichan = 0 ;
    19941947  double wsum = 0.0 ;
    1995   Vector<double> zi( nChan+1 ) ;
    1996   Vector<double> yi( oldsize + 1 ) ;
    1997   yi[0] = abcissa[0] - 0.5 * olddnu ;
    1998   for ( int ii = 1 ; ii < oldsize ; ii++ )
    1999     yi[ii] = 0.5* (abcissa[ii-1] + abcissa[ii]) ;
    2000   yi[oldsize] = abcissa[oldsize-1] \
    2001     + 0.5 * (abcissa[oldsize-1] - abcissa[oldsize-2]) ;
    2002   //zi[0] = abcissa[0] - 0.5 * olddnu ;
    2003   zi[0] = ((olddnu*dnu > 0) ? yi[0] : yi[oldsize]) ;
    2004   for ( int ii = 1 ; ii < nChan ; ii++ )
     1948  Vector<Float> zi( nChan+1 ) ;
     1949  Vector<Float> yi( oldsize + 1 ) ;
     1950  zi[0] = abcissa[0] - 0.5 * olddnu ;
     1951  zi[1] = zi[1] + dnu ;
     1952  for ( int ii = 2 ; ii < nChan ; ii++ )
    20051953    zi[ii] = zi[0] + dnu * ii ;
    20061954  zi[nChan] = zi[nChan-1] + dnu ;
    2007   // Access zi and yi in ascending order
    2008   int izs = ((dnu > 0) ? 0 : nChan ) ;
    2009   int ize = ((dnu > 0) ? nChan : 0 ) ;
    2010   int izincr = ((dnu > 0) ? 1 : -1 ) ;
    2011   int ichan =  ((olddnu > 0) ? 0 : oldsize ) ;
    2012   int iye = ((olddnu > 0) ? oldsize : 0 ) ;
    2013   int iyincr = ((olddnu > 0) ? 1 : -1 ) ;
    2014   //for ( int ii = izs ; ii != ize ; ii+=izincr ){
    2015   int ii = izs ;
    2016   while (ii != ize) {
    2017     // always zl < zr
    2018     double zl = zi[ii] ;
    2019     double zr = zi[ii+izincr] ;
    2020     // Need to access smaller index for the new spec, flag, and tsys.
    2021     // Values between zi[k] and zi[k+1] should be stored in newspec[k], etc.
    2022     int i = min(ii, ii+izincr) ;
    2023     //for ( int jj = ichan ; jj != iye ; jj+=iyincr ) {
    2024     int jj = ichan ;
    2025     while (jj != iye) {
    2026       // always yl < yr
    2027       double yl = yi[jj] ;
    2028       double yr = yi[jj+iyincr] ;
    2029       // Need to access smaller index for the original spec, flag, and tsys.
    2030       // Values between yi[k] and yi[k+1] are stored in oldspec[k], etc.
    2031       int j = min(jj, jj+iyincr) ;
    2032       if ( yr <= zl ) {
    2033         jj += iyincr ;
    2034         continue ;
    2035       }
    2036       else if ( yl <= zl ) {
    2037         if ( yr < zr ) {
    2038           if (!oldflag[j]) {
    2039             newspec[i] += oldspec[j] * ( yr - zl ) ;
    2040             if (regridTsys) newtsys[i] += oldtsys[j] * ( yr - zl ) ;
    2041             wsum += ( yr - zl ) ;
    2042           }
    2043           newflag[i] = newflag[i] && oldflag[j] ;
    2044         }
    2045         else {
    2046           if (!oldflag[j]) {
    2047             newspec[i] += oldspec[j] * abs(dnu) ;
    2048             if (regridTsys) newtsys[i] += oldtsys[j] * abs(dnu) ;
    2049             wsum += abs(dnu) ;
    2050           }
    2051           newflag[i] = newflag[i] && oldflag[j] ;
    2052           ichan = jj ;
    2053           break ;
    2054         }
    2055       }
    2056       else if ( yl < zr ) {
    2057         if ( yr <= zr ) {
    2058           if (!oldflag[j]) {
    2059             newspec[i] += oldspec[j] * ( yr - yl ) ;
    2060             if (regridTsys) newtsys[i] += oldtsys[j] * ( yr - yl ) ;
    2061             wsum += ( yr - yl ) ;
    2062           }
    2063           newflag[i] = newflag[i] && oldflag[j] ;
    2064         }
    2065         else {
    2066           if (!oldflag[j]) {
    2067             newspec[i] += oldspec[j] * ( zr - yl ) ;
    2068             if (regridTsys) newtsys[i] += oldtsys[j] * ( zr - yl ) ;
    2069             wsum += ( zr - yl ) ;
    2070           }
    2071           newflag[i] = newflag[i] && oldflag[j] ;
    2072           ichan = jj ;
    2073           break ;
    2074         }
    2075       }
    2076       else {
    2077         ichan = jj - iyincr ;
    2078         break ;
    2079       }
    2080       jj += iyincr ;
    2081     }
    2082     if ( wsum != 0.0 ) {
    2083       newspec[i] /= wsum ;
    2084       if (regridTsys) newtsys[i] /= wsum ;
    2085     }
    2086     wsum = 0.0 ;
    2087     ii += izincr ;
    2088   }
    2089 //   if ( dnu > 0.0 ) {
    2090 //     for ( int ii = 0 ; ii < nChan ; ii++ ) {
    2091 //       double zl = zi[ii] ;
    2092 //       double zr = zi[ii+1] ;
    2093 //       for ( int j = ichan ; j < oldsize ; j++ ) {
    2094 //         double yl = yi[j] ;
    2095 //         double yr = yi[j+1] ;
    2096 //         if ( yl <= zl ) {
    2097 //           if ( yr <= zl ) {
    2098 //             continue ;
    2099 //           }
    2100 //           else if ( yr <= zr ) {
    2101 //          if (!oldflag[j]) {
    2102 //            newspec[ii] += oldspec[j] * ( yr - zl ) ;
    2103 //            if (regridTsys) newtsys[ii] += oldtsys[j] * ( yr - zl ) ;
    2104 //            wsum += ( yr - zl ) ;
    2105 //          }
    2106 //          newflag[ii] = newflag[ii] && oldflag[j] ;
    2107 //           }
    2108 //           else {
    2109 //          if (!oldflag[j]) {
    2110 //            newspec[ii] += oldspec[j] * dnu ;
    2111 //            if (regridTsys) newtsys[ii] += oldtsys[j] * dnu ;
    2112 //            wsum += dnu ;
    2113 //          }
    2114 //          newflag[ii] = newflag[ii] && oldflag[j] ;
    2115 //             ichan = j ;
    2116 //             break ;
    2117 //           }
    2118 //         }
    2119 //         else if ( yl < zr ) {
    2120 //           if ( yr <= zr ) {
    2121 //          if (!oldflag[j]) {
    2122 //            newspec[ii] += oldspec[j] * ( yr - yl ) ;
    2123 //            if (regridTsys) newtsys[ii] += oldtsys[j] * ( yr - yl ) ;
    2124 //               wsum += ( yr - yl ) ;
    2125 //          }
    2126 //          newflag[ii] = newflag[ii] && oldflag[j] ;
    2127 //           }
    2128 //           else {
    2129 //          if (!oldflag[j]) {
    2130 //            newspec[ii] += oldspec[j] * ( zr - yl ) ;
    2131 //            if (regridTsys) newtsys[ii] += oldtsys[j] * ( zr - yl ) ;
    2132 //            wsum += ( zr - yl ) ;
    2133 //          }
    2134 //          newflag[ii] = newflag[ii] && oldflag[j] ;
    2135 //             ichan = j ;
    2136 //             break ;
    2137 //           }
    2138 //         }
    2139 //         else {
    2140 //           ichan = j - 1 ;
    2141 //           break ;
    2142 //         }
    2143 //       }
    2144 //       if ( wsum != 0.0 ) {
    2145 //         newspec[ii] /= wsum ;
    2146 //      if (regridTsys) newtsys[ii] /= wsum ;
    2147 //       }
    2148 //       wsum = 0.0 ;
     1955  yi[0] = abcissa[0] - 0.5 * olddnu ;
     1956  yi[1] = abcissa[1] + 0.5 * olddnu ;
     1957  for ( int ii = 2 ; ii < oldsize ; ii++ )
     1958    yi[ii] = abcissa[ii-1] + olddnu ;
     1959  yi[oldsize] = abcissa[oldsize-1] + 0.5 * olddnu ;
     1960  if ( dnu > 0.0 ) {
     1961    for ( int ii = 0 ; ii < nChan ; ii++ ) {
     1962      double zl = zi[ii] ;
     1963      double zr = zi[ii+1] ;
     1964      for ( int j = ichan ; j < oldsize ; j++ ) {
     1965        double yl = yi[j] ;
     1966        double yr = yi[j+1] ;
     1967        if ( yl <= zl ) {
     1968          if ( yr <= zl ) {
     1969            continue ;
     1970          }
     1971          else if ( yr <= zr ) {
     1972            newspec[ii] += oldspec[j] * ( yr - zl ) ;
     1973            newflag[ii] = newflag[ii] || oldflag[j] ;
     1974            wsum += ( yr - zl ) ;
     1975          }
     1976          else {
     1977            newspec[ii] += oldspec[j] * dnu ;
     1978            newflag[ii] = newflag[ii] || oldflag[j] ;
     1979            wsum += dnu ;
     1980            ichan = j ;
     1981            break ;
     1982          }
     1983        }
     1984        else if ( yl < zr ) {
     1985          if ( yr <= zr ) {
     1986              newspec[ii] += oldspec[j] * ( yr - yl ) ;
     1987              newflag[ii] = newflag[ii] || oldflag[j] ;
     1988              wsum += ( yr - yl ) ;
     1989          }
     1990          else {
     1991            newspec[ii] += oldspec[j] * ( zr - yl ) ;
     1992            newflag[ii] = newflag[ii] || oldflag[j] ;
     1993            wsum += ( zr - yl ) ;
     1994            ichan = j ;
     1995            break ;
     1996          }
     1997        }
     1998        else {
     1999          ichan = j - 1 ;
     2000          break ;
     2001        }
     2002      }
     2003      if ( wsum != 0.0 )
     2004        newspec[ii] /= wsum ;
     2005      wsum = 0.0 ;
     2006    }
     2007  }
     2008  else if ( dnu < 0.0 ) {
     2009    for ( int ii = 0 ; ii < nChan ; ii++ ) {
     2010      double zl = zi[ii] ;
     2011      double zr = zi[ii+1] ;
     2012      for ( int j = ichan ; j < oldsize ; j++ ) {
     2013        double yl = yi[j] ;
     2014        double yr = yi[j+1] ;
     2015        if ( yl >= zl ) {
     2016          if ( yr >= zl ) {
     2017            continue ;
     2018          }
     2019          else if ( yr >= zr ) {
     2020            newspec[ii] += oldspec[j] * abs( yr - zl ) ;
     2021            newflag[ii] = newflag[ii] || oldflag[j] ;
     2022            wsum += abs( yr - zl ) ;
     2023          }
     2024          else {
     2025            newspec[ii] += oldspec[j] * abs( dnu ) ;
     2026            newflag[ii] = newflag[ii] || oldflag[j] ;
     2027            wsum += abs( dnu ) ;
     2028            ichan = j ;
     2029            break ;
     2030          }
     2031        }
     2032        else if ( yl > zr ) {
     2033          if ( yr >= zr ) {
     2034            newspec[ii] += oldspec[j] * abs( yr - yl ) ;
     2035            newflag[ii] = newflag[ii] || oldflag[j] ;
     2036            wsum += abs( yr - yl ) ;
     2037          }
     2038          else {
     2039            newspec[ii] += oldspec[j] * abs( zr - yl ) ;
     2040            newflag[ii] = newflag[ii] || oldflag[j] ;
     2041            wsum += abs( zr - yl ) ;
     2042            ichan = j ;
     2043            break ;
     2044          }
     2045        }
     2046        else {
     2047          ichan = j - 1 ;
     2048          break ;
     2049        }
     2050      }
     2051      if ( wsum != 0.0 )
     2052        newspec[ii] /= wsum ;
     2053      wsum = 0.0 ;
     2054    }
     2055  }
     2056//    * ichan = 0
     2057//    ***/
     2058//   //ofs << "olddnu = " << olddnu << ", dnu = " << dnu << endl ;
     2059//   pile += dnu ;
     2060//   wedge = olddnu * ( refChan + 1 ) ;
     2061//   while ( wedge < pile ) {
     2062//     newspec[0] += olddnu * oldspec[refChan] ;
     2063//     newflag[0] = newflag[0] || oldflag[refChan] ;
     2064//     //ofs << "channel " << refChan << " is included in new channel 0" << endl ;
     2065//     refChan++ ;
     2066//     wedge += olddnu ;
     2067//     wsum += olddnu ;
     2068//     //ofs << "newspec[0] = " << newspec[0] << " wsum = " << wsum << endl ;
     2069//   }
     2070//   frac = ( wedge - pile ) / olddnu ;
     2071//   wsum += ( 1.0 - frac ) * olddnu ;
     2072//   newspec[0] += ( 1.0 - frac ) * olddnu * oldspec[refChan] ;
     2073//   newflag[0] = newflag[0] || oldflag[refChan] ;
     2074//   //ofs << "channel " << refChan << " is partly included in new channel 0" << " with fraction of " << ( 1.0 - frac ) << endl ;
     2075//   //ofs << "newspec[0] = " << newspec[0] << " wsum = " << wsum << endl ;
     2076//   newspec[0] /= wsum ;
     2077//   //ofs << "newspec[0] = " << newspec[0] << endl ;
     2078//   //ofs << "wedge = " << wedge << ", pile = " << pile << endl ;
     2079
     2080//   /***
     2081//    * ichan = 1 - nChan-2
     2082//    ***/
     2083//   for ( int ichan = 1 ; ichan < nChan - 1 ; ichan++ ) {
     2084//     pile += dnu ;
     2085//     newspec[ichan] += frac * olddnu * oldspec[refChan] ;
     2086//     newflag[ichan] = newflag[ichan] || oldflag[refChan] ;
     2087//     //ofs << "channel " << refChan << " is partly included in new channel " << ichan << " with fraction of " << frac << endl ;
     2088//     refChan++ ;
     2089//     wedge += olddnu ;
     2090//     wsum = frac * olddnu ;
     2091//     //ofs << "newspec[" << ichan << "] = " << newspec[ichan] << " wsum = " << wsum << endl ;
     2092//     while ( wedge < pile ) {
     2093//       newspec[ichan] += olddnu * oldspec[refChan] ;
     2094//       newflag[ichan] = newflag[ichan] || oldflag[refChan] ;
     2095//       //ofs << "channel " << refChan << " is included in new channel " << ichan << endl ;
     2096//       refChan++ ;
     2097//       wedge += olddnu ;
     2098//       wsum += olddnu ;
     2099//       //ofs << "newspec[" << ichan << "] = " << newspec[ichan] << " wsum = " << wsum << endl ;
    21492100//     }
     2101//     frac = ( wedge - pile ) / olddnu ;
     2102//     wsum += ( 1.0 - frac ) * olddnu ;
     2103//     newspec[ichan] += ( 1.0 - frac ) * olddnu * oldspec[refChan] ;
     2104//     newflag[ichan] = newflag[ichan] || oldflag[refChan] ;
     2105//     //ofs << "channel " << refChan << " is partly included in new channel " << ichan << " with fraction of " << ( 1.0 - frac ) << endl ;
     2106//     //ofs << "wedge = " << wedge << ", pile = " << pile << endl ;
     2107//     //ofs << "newspec[" << ichan << "] = " << newspec[ichan] << " wsum = " << wsum << endl ;
     2108//     newspec[ichan] /= wsum ;
     2109//     //ofs << "newspec[" << ichan << "] = " << newspec[ichan] << endl ;
    21502110//   }
    2151 //   else if ( dnu < 0.0 ) {
    2152 //     for ( int ii = 0 ; ii < nChan ; ii++ ) {
    2153 //       double zl = zi[ii] ;
    2154 //       double zr = zi[ii+1] ;
    2155 //       for ( int j = ichan ; j < oldsize ; j++ ) {
    2156 //         double yl = yi[j] ;
    2157 //         double yr = yi[j+1] ;
    2158 //         if ( yl >= zl ) {
    2159 //           if ( yr >= zl ) {
    2160 //             continue ;
    2161 //           }
    2162 //           else if ( yr >= zr ) {
    2163 //          if (!oldflag[j]) {
    2164 //            newspec[ii] += oldspec[j] * abs( yr - zl ) ;
    2165 //            if (regridTsys) newtsys[ii] += oldtsys[j] * abs( yr - zl ) ;
    2166 //            wsum += abs( yr - zl ) ;
    2167 //          }
    2168 //          newflag[ii] = newflag[ii] && oldflag[j] ;
    2169 //           }
    2170 //           else {
    2171 //          if (!oldflag[j]) {
    2172 //            newspec[ii] += oldspec[j] * abs( dnu ) ;
    2173 //            if (regridTsys) newtsys[ii] += oldtsys[j] * abs( dnu ) ;
    2174 //            wsum += abs( dnu ) ;
    2175 //          }
    2176 //          newflag[ii] = newflag[ii] && oldflag[j] ;
    2177 //             ichan = j ;
    2178 //             break ;
    2179 //           }
    2180 //         }
    2181 //         else if ( yl > zr ) {
    2182 //           if ( yr >= zr ) {
    2183 //          if (!oldflag[j]) {
    2184 //            newspec[ii] += oldspec[j] * abs( yr - yl ) ;
    2185 //            if (regridTsys) newtsys[ii] += oldtsys[j] * abs( yr - yl ) ;
    2186 //            wsum += abs( yr - yl ) ;
    2187 //          }
    2188 //          newflag[ii] = newflag[ii] && oldflag[j] ;
    2189 //           }
    2190 //           else {
    2191 //          if (!oldflag[j]) {
    2192 //            newspec[ii] += oldspec[j] * abs( zr - yl ) ;
    2193 //            if (regridTsys) newtsys[ii] += oldtsys[j] * abs( zr - yl ) ;
    2194 //            wsum += abs( zr - yl ) ;
    2195 //          }
    2196 //          newflag[ii] = newflag[ii] && oldflag[j] ;
    2197 //             ichan = j ;
    2198 //             break ;
    2199 //           }
    2200 //         }
    2201 //         else {
    2202 //           ichan = j - 1 ;
    2203 //           break ;
    2204 //         }
    2205 //       }
    2206 //       if ( wsum != 0.0 ) {
    2207 //         newspec[ii] /= wsum ;
    2208 //      if (regridTsys) newtsys[ii] /= wsum ;
    2209 //       }
    2210 //       wsum = 0.0 ;
    2211 //     }
     2111
     2112//   /***
     2113//    * ichan = nChan-1
     2114//    ***/
     2115//   // NOTE: Assumed that all spectra have the same bandwidth
     2116//   pile += dnu ;
     2117//   newspec[nChan-1] += frac * olddnu * oldspec[refChan] ;
     2118//   newflag[nChan-1] = newflag[nChan-1] || oldflag[refChan] ;
     2119//   //ofs << "channel " << refChan << " is partly included in new channel " << nChan-1 << " with fraction of " << frac << endl ;
     2120//   refChan++ ;
     2121//   wedge += olddnu ;
     2122//   wsum = frac * olddnu ;
     2123//   //ofs << "newspec[" << nChan - 1 << "] = " << newspec[nChan-1] << " wsum = " << wsum << endl ;
     2124//   for ( int jchan = refChan ; jchan < oldsize ; jchan++ ) {
     2125//     newspec[nChan-1] += olddnu * oldspec[jchan] ;
     2126//     newflag[nChan-1] = newflag[nChan-1] || oldflag[jchan] ;
     2127//     wsum += olddnu ;
     2128//     //ofs << "channel " << jchan << " is included in new channel " << nChan-1 << " with fraction of " << frac << endl ;
     2129//     //ofs << "newspec[" << nChan - 1 << "] = " << newspec[nChan-1] << " wsum = " << wsum << endl ;
    22122130//   }
    2213 // //   //ofs << "olddnu = " << olddnu << ", dnu = " << dnu << endl ;
    2214 // //   pile += dnu ;
    2215 // //   wedge = olddnu * ( refChan + 1 ) ;
    2216 // //   while ( wedge < pile ) {
    2217 // //     newspec[0] += olddnu * oldspec[refChan] ;
    2218 // //     newflag[0] = newflag[0] || oldflag[refChan] ;
    2219 // //     //ofs << "channel " << refChan << " is included in new channel 0" << endl ;
    2220 // //     refChan++ ;
    2221 // //     wedge += olddnu ;
    2222 // //     wsum += olddnu ;
    2223 // //     //ofs << "newspec[0] = " << newspec[0] << " wsum = " << wsum << endl ;
    2224 // //   }
    2225 // //   frac = ( wedge - pile ) / olddnu ;
    2226 // //   wsum += ( 1.0 - frac ) * olddnu ;
    2227 // //   newspec[0] += ( 1.0 - frac ) * olddnu * oldspec[refChan] ;
    2228 // //   newflag[0] = newflag[0] || oldflag[refChan] ;
    2229 // //   //ofs << "channel " << refChan << " is partly included in new channel 0" << " with fraction of " << ( 1.0 - frac ) << endl ;
    2230 // //   //ofs << "newspec[0] = " << newspec[0] << " wsum = " << wsum << endl ;
    2231 // //   newspec[0] /= wsum ;
    2232 // //   //ofs << "newspec[0] = " << newspec[0] << endl ;
    2233 // //   //ofs << "wedge = " << wedge << ", pile = " << pile << endl ;
    2234 
    2235 // //   /***
    2236 // //    * ichan = 1 - nChan-2
    2237 // //    ***/
    2238 // //   for ( int ichan = 1 ; ichan < nChan - 1 ; ichan++ ) {
    2239 // //     pile += dnu ;
    2240 // //     newspec[ichan] += frac * olddnu * oldspec[refChan] ;
    2241 // //     newflag[ichan] = newflag[ichan] || oldflag[refChan] ;
    2242 // //     //ofs << "channel " << refChan << " is partly included in new channel " << ichan << " with fraction of " << frac << endl ;
    2243 // //     refChan++ ;
    2244 // //     wedge += olddnu ;
    2245 // //     wsum = frac * olddnu ;
    2246 // //     //ofs << "newspec[" << ichan << "] = " << newspec[ichan] << " wsum = " << wsum << endl ;
    2247 // //     while ( wedge < pile ) {
    2248 // //       newspec[ichan] += olddnu * oldspec[refChan] ;
    2249 // //       newflag[ichan] = newflag[ichan] || oldflag[refChan] ;
    2250 // //       //ofs << "channel " << refChan << " is included in new channel " << ichan << endl ;
    2251 // //       refChan++ ;
    2252 // //       wedge += olddnu ;
    2253 // //       wsum += olddnu ;
    2254 // //       //ofs << "newspec[" << ichan << "] = " << newspec[ichan] << " wsum = " << wsum << endl ;
    2255 // //     }
    2256 // //     frac = ( wedge - pile ) / olddnu ;
    2257 // //     wsum += ( 1.0 - frac ) * olddnu ;
    2258 // //     newspec[ichan] += ( 1.0 - frac ) * olddnu * oldspec[refChan] ;
    2259 // //     newflag[ichan] = newflag[ichan] || oldflag[refChan] ;
    2260 // //     //ofs << "channel " << refChan << " is partly included in new channel " << ichan << " with fraction of " << ( 1.0 - frac ) << endl ;
    2261 // //     //ofs << "wedge = " << wedge << ", pile = " << pile << endl ;
    2262 // //     //ofs << "newspec[" << ichan << "] = " << newspec[ichan] << " wsum = " << wsum << endl ;
    2263 // //     newspec[ichan] /= wsum ;
    2264 // //     //ofs << "newspec[" << ichan << "] = " << newspec[ichan] << endl ;
    2265 // //   }
    2266 
    2267 // //   /***
    2268 // //    * ichan = nChan-1
    2269 // //    ***/
    2270 // //   // NOTE: Assumed that all spectra have the same bandwidth
    2271 // //   pile += dnu ;
    2272 // //   newspec[nChan-1] += frac * olddnu * oldspec[refChan] ;
    2273 // //   newflag[nChan-1] = newflag[nChan-1] || oldflag[refChan] ;
    2274 // //   //ofs << "channel " << refChan << " is partly included in new channel " << nChan-1 << " with fraction of " << frac << endl ;
    2275 // //   refChan++ ;
    2276 // //   wedge += olddnu ;
    2277 // //   wsum = frac * olddnu ;
    2278 // //   //ofs << "newspec[" << nChan - 1 << "] = " << newspec[nChan-1] << " wsum = " << wsum << endl ;
    2279 // //   for ( int jchan = refChan ; jchan < oldsize ; jchan++ ) {
    2280 // //     newspec[nChan-1] += olddnu * oldspec[jchan] ;
    2281 // //     newflag[nChan-1] = newflag[nChan-1] || oldflag[jchan] ;
    2282 // //     wsum += olddnu ;
    2283 // //     //ofs << "channel " << jchan << " is included in new channel " << nChan-1 << " with fraction of " << frac << endl ;
    2284 // //     //ofs << "newspec[" << nChan - 1 << "] = " << newspec[nChan-1] << " wsum = " << wsum << endl ;
    2285 // //   }
    2286 // //   //ofs << "wedge = " << wedge << ", pile = " << pile << endl ;
    2287 // //   //ofs << "newspec[" << nChan - 1 << "] = " << newspec[nChan-1] << " wsum = " << wsum << endl ;
    2288 // //   newspec[nChan-1] /= wsum ;
    2289 // //   //ofs << "newspec[" << nChan - 1 << "] = " << newspec[nChan-1] << endl ;
    2290 
    2291 // //   // ofs.close() ;
     2131//   //ofs << "wedge = " << wedge << ", pile = " << pile << endl ;
     2132//   //ofs << "newspec[" << nChan - 1 << "] = " << newspec[nChan-1] << " wsum = " << wsum << endl ;
     2133//   newspec[nChan-1] /= wsum ;
     2134//   //ofs << "newspec[" << nChan - 1 << "] = " << newspec[nChan-1] << endl ;
     2135
     2136//   // ofs.close() ;
    22922137
    22932138  specCol_.put( irow, newspec ) ;
    22942139  flagsCol_.put( irow, newflag ) ;
    2295   if (regridTsys) tsysCol_.put( irow, newtsys );
    22962140
    22972141  return ;
     
    28532697  }
    28542698
    2855   addAuxWaveNumbers(whichrow, addNWaves, rejectNWaves, nWaves);
     2699  addAuxWaveNumbers(addNWaves, rejectNWaves, nWaves);
    28562700}
    28572701
     
    29352779}
    29362780
    2937 void Scantable::addAuxWaveNumbers(const int whichrow, const std::vector<int>& addNWaves, const std::vector<int>& rejectNWaves, std::vector<int>& nWaves)
    2938 {
    2939   std::vector<int> tempAddNWaves, tempRejectNWaves;
     2781void Scantable::addAuxWaveNumbers(const std::vector<int>& addNWaves, const std::vector<int>& rejectNWaves, std::vector<int>& nWaves)
     2782{
    29402783  for (uInt i = 0; i < addNWaves.size(); ++i) {
    2941     tempAddNWaves.push_back(addNWaves[i]);
    2942   }
    2943   if ((tempAddNWaves.size() == 2) && (tempAddNWaves[1] == -999)) {
    2944     setWaveNumberListUptoNyquistFreq(whichrow, tempAddNWaves);
    2945   }
    2946 
    2947   for (uInt i = 0; i < rejectNWaves.size(); ++i) {
    2948     tempRejectNWaves.push_back(rejectNWaves[i]);
    2949   }
    2950   if ((tempRejectNWaves.size() == 2) && (tempRejectNWaves[1] == -999)) {
    2951     setWaveNumberListUptoNyquistFreq(whichrow, tempRejectNWaves);
    2952   }
    2953 
    2954   for (uInt i = 0; i < tempAddNWaves.size(); ++i) {
    29552784    bool found = false;
    29562785    for (uInt j = 0; j < nWaves.size(); ++j) {
    2957       if (nWaves[j] == tempAddNWaves[i]) {
     2786      if (nWaves[j] == addNWaves[i]) {
    29582787        found = true;
    29592788        break;
    29602789      }
    29612790    }
    2962     if (!found) nWaves.push_back(tempAddNWaves[i]);
    2963   }
    2964 
    2965   for (uInt i = 0; i < tempRejectNWaves.size(); ++i) {
     2791    if (!found) nWaves.push_back(addNWaves[i]);
     2792  }
     2793
     2794  for (uInt i = 0; i < rejectNWaves.size(); ++i) {
    29662795    for (std::vector<int>::iterator j = nWaves.begin(); j != nWaves.end(); ) {
    2967       if (*j == tempRejectNWaves[i]) {
     2796      if (*j == rejectNWaves[i]) {
    29682797        j = nWaves.erase(j);
    29692798      } else {
     
    29762805    sort(nWaves.begin(), nWaves.end());
    29772806    unique(nWaves.begin(), nWaves.end());
    2978   }
    2979 }
    2980 
    2981 void Scantable::setWaveNumberListUptoNyquistFreq(const int whichrow, std::vector<int>& nWaves)
    2982 {
    2983   if ((nWaves.size() == 2)&&(nWaves[1] == -999)) {
    2984     int val = nWaves[0];
    2985     int nyquistFreq = nchan(getIF(whichrow))/2+1;
    2986     nWaves.clear();
    2987     if (val > nyquistFreq) {  // for safety, at least nWaves contains a constant; CAS-3759
    2988       nWaves.push_back(0);
    2989     }
    2990     while (val <= nyquistFreq) {
    2991       nWaves.push_back(val);
    2992       val++;
    2993     }
    29942807  }
    29952808}
     
    30312844
    30322845      //FOR DEBUGGING------------
    3033       /*
    30342846      if (whichrow < 0) {// == nRow -1) {
    30352847        cout << "+++ i=" << setw(3) << whichrow << ", IF=" << setw(2) << getIF(whichrow);
     
    30432855        cout << flush;
    30442856      }
    3045       */
    30462857      //-------------------------
    30472858
     
    33783189  std::vector<bool> mask = getMask(whichrow);
    33793190  uInt maskSize = mask.size();
    3380   if (inMask.size() != 0) {
    3381     if (maskSize != inMask.size()) {
    3382       throw(AipsError("mask sizes are not the same."));
    3383     }
    3384     for (uInt i = 0; i < maskSize; ++i) {
    3385       mask[i] = mask[i] && inMask[i];
    3386     }
     3191  if (maskSize != inMask.size()) {
     3192    throw(AipsError("mask sizes are not the same."));
     3193  }
     3194  for (uInt i = 0; i < maskSize; ++i) {
     3195    mask[i] = mask[i] && inMask[i];
    33873196  }
    33883197
     
    37063515std::string Scantable::getMaskRangeList(const std::vector<bool>& mask, int whichrow, const casa::String& coordInfo, bool hasSameNchan, bool verbose)
    37073516{
    3708   if (mask.size() <= 0) {
    3709     throw(AipsError("The mask elements should be > 0"));
     3517  if (mask.size() < 2) {
     3518    throw(AipsError("The mask elements should be > 1"));
    37103519  }
    37113520  int IF = getIF(whichrow);
     
    37403549std::vector<int> Scantable::getMaskEdgeIndices(const std::vector<bool>& mask)
    37413550{
    3742   if (mask.size() <= 0) {
    3743     throw(AipsError("The mask elements should be > 0"));
     3551  if (mask.size() < 2) {
     3552    throw(AipsError("The mask elements should be > 1"));
    37443553  }
    37453554
  • /trunk/src/Scantable.h

    r2473 r2373  
    501501  void regridChannel( int nchan, double dnu ) ;
    502502  void regridChannel( int nchan, double dnu, int irow ) ;
    503 
    504   void regridSpecChannel( double dnu, int nchan=-1 ) ;
    505503
    506504  bool getFlagtraFast(casa::uInt whichrow);
     
    741739                           const std::string& fftThAttr,
    742740                           std::vector<int>& nWaves);
    743   void addAuxWaveNumbers(const int whichrow,
    744                          const std::vector<int>& addNWaves,
     741  void addAuxWaveNumbers(const std::vector<int>& addNWaves,
    745742                         const std::vector<int>& rejectNWaves,
    746743                         std::vector<int>& nWaves);
    747   void setWaveNumberListUptoNyquistFreq(const int whichrow,
    748                                         std::vector<int>& nWaves);
    749744  bool hasSameNchanOverIFs();
    750745  std::string getMaskRangeList(const std::vector<bool>& mask,
  • /trunk/src/ScantableWrapper.h

    r2473 r2373  
    268268  { table_->reshapeSpectrum( nmin, nmax ); }
    269269
    270   void regridSpecChannel( double dnu, int nchan )
    271   { table_->regridSpecChannel( dnu, nchan ); }
    272 
    273270  void polyBaseline(const std::vector<bool>& mask, int order, bool getresidual=true, const std::string& showprogress="true,1000", const bool outlog=false, const std::string& blfile="")
    274271  { table_->polyBaseline(mask, order, getresidual, showprogress, outlog, blfile); }
  • /trunk/src/Templates.cpp

    r2473 r2373  
    3636#include <casa/Utilities/CountedPtr.h>
    3737
    38 //template class casa::CountedConstPtr<asap::Scantable>;
     38template class casa::CountedConstPtr<asap::Scantable>;
    3939template class casa::CountedPtr<asap::Scantable>;
    4040template class casa::CountedPtr<asap::STPol>;
     41template class casa::PtrRep<asap::Scantable>;
     42template class casa::SimpleCountedConstPtr<asap::Scantable>;
     43template class casa::SimpleCountedConstPtr<asap::STPol>;
     44template class casa::SimpleCountedPtr<asap::Scantable>;
     45template class casa::SimpleCountedPtr<asap::STPol>;
    4146
    4247#include <casa/Arrays/ArrayLogical.h>
  • /trunk/src/python_STGrid.cpp

    r2473 r2373  
    2121    .def( init <> () )
    2222    .def( init < const std::string > () )
    23     .def( init < const std::vector<std::string> > () )
    2423    .def("_setif", &STGrid::setIF)
    2524    .def("_setpollist", &STGrid::setPolList)
     
    2928    .def("_grid", &STGrid::grid)
    3029    .def("_setin", &STGrid::setFileIn)
    31     .def("_setfiles", &STGrid::setFileList)
    3230    .def("_setweight", &STGrid::setWeight)
    33     .def("_enableclip", &STGrid::enableClip)
    34     .def("_disableclip", &STGrid::disableClip)
    3531    .def("_save", &STGrid::saveData)
    3632    ;
  • /trunk/src/python_Scantable.cpp

    r2473 r2373  
    145145         (boost::python::arg("nmin")=-1,
    146146          boost::python::arg("nmax")=-1) )
    147     .def("_regrid_specchan", &ScantableWrapper::regridSpecChannel,
    148          (boost::python::arg("nchan")=-1) )
    149147    .def("_poly_baseline", &ScantableWrapper::polyBaseline)
    150148    .def("_auto_poly_baseline", &ScantableWrapper::autoPolyBaseline)
Note: See TracChangeset for help on using the changeset viewer.