Ignore:
Timestamp:
07/06/11 16:52:38 (13 years ago)
Author:
Takeshi Nakazato
Message:

New Development: No

JIRA Issue: Yes CAS-1913

Ready for Test: No

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No?

Module(s): Module Names change impacts.

Description: Describe your changes here...

Update of asdm2ASAP and related classes.

  • replaced LogIO with StreamLogSink?
  • all log messages are written to logger via StreamLogSink?
  • no output to stdout/stderr
  • commented out junk log
  • added time_sampling selection
  • supported wvr_corrected_data='both'
  • added logfile specification
  • added corr_mode selection


File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/external-alma/asdm2ASAP/asdm2ASAP.cc

    r2197 r2208  
    11#include <iostream>
     2#include <fstream>
    23#include <casa/Utilities/Regex.h>
    34#include <casa/Inputs/Input.h>
     
    56#include <casa/Containers/Record.h>
    67#include <casa/OS/Directory.h>
     8#include <casa/Logging/LogIO.h>
     9#include <casa/Logging/LogSink.h>
     10#include <casa/Logging/StreamLogSink.h>
     11#include <casa/Logging/LogFilter.h>
    712#include <Scantable.h>
    813#include "ASDMFiller.h"
     
    1823  Input inp ;
    1924  String indent = "   " ;
    20   String versionInfo = "$Id$\nConverts an ASDM dataset into Scantable.\nUsage:\n"+indent+argv[0]+" -antenna <antenna name or id> -asdm <ASDM directory> -asap <Scantable name>" ;
    21   inp.version( versionInfo ) ;
     25  String versionInfo = "$Id$\nConverts an ASDM dataset into Scantable.\nUsage:\n"+indent+argv[0]+" -antenna <antenna name or id> -asdm <ASDM directory> -asap <Scantable name> [-apc both|yes|no] [-corr-mode ca|ao|ca+ao] [-ocorr-mode ao] [-time-sampling all|integration|subintegration]" ;
     26  Bool helpMode = False ;
     27  for ( int i = 1 ; i < argc ; i++ ) {
     28    if ( strncmp( argv[i], "-h", 2 ) == 0
     29         || strncmp( argv[i], "--help", 6 ) == 0
     30         || strncmp( argv[i], "-v", 2 ) == 0
     31         || strncmp( argv[i], "--version", 9 ) == 0 ) {
     32      helpMode = True ;
     33      break ;
     34    }
     35  }
     36  if ( helpMode )
     37    inp.version( versionInfo ) ;
     38  else
     39    inp.version( "" ) ;
    2240
    2341  inp.create( "antenna", "0", "antenna name or id", "String" ) ;
    2442  inp.create( "asdm", "", "ASDM directory name", "String" ) ;
    2543  inp.create( "asap", "", "Scantable name", "String" ) ;
    26   inp.create( "apc", "False", "Retrieve Atm Phase Corrected data or not", "Bool" ) ;
    27   inp.create( "overwrite", "True", "Overwrite existing Scantable or not", "Bool" ) ;
     44  inp.create( "apc", "both", "Retrieve Atm Phase Corrected data or not: both|yes|no", "String" ) ;
     45  inp.create( "overwrite", "True", "Overwrite existing Scantable or not: True|False", "Bool" ) ;
     46  inp.create( "corr-mode", "ca+ao", "Input correlator mode: ca+ao|ca|ao", "String" ) ;
     47  inp.create( "ocorr-mode", "ao", "Output correlator mode: ao", "String" ) ;
     48  inp.create( "time-sampling", "all", "time sampling mode: all|integration|subintegration", "String" ) ;
     49  inp.create( "logfile", "", "logger output", "String" ) ;
    2850  inp.readArguments( argc, argv ) ;
    2951
     
    3153  string antenna = inp.getString( "antenna" ) ;
    3254  string asapname = inp.getString( "asap" ) ;
    33   Bool apcCorrected = inp.getBool( "apc" ) ;
     55  string apc = inp.getString( "apc" ) ;
    3456  Bool overwrite = inp.getBool( "overwrite" ) ;
     57  string corrMode = inp.getString( "corr-mode" ) ;
     58  string timeSampling = inp.getString( "time-sampling" ) ;
     59  string logfile = inp.getString( "logfile" ) ;
    3560   
    36    
    37   // create ASDMFiller object
    38   CountedPtr<Scantable> stable( new Scantable() ) ;
    39   ASDMFiller *filler = new ASDMFiller( stable ) ;
    40 
    41   // open data
    42   Record rec ;
    43   Record asdmRec ;
    44   Regex reg( "[0-9]+$" ) ;
    45   asdmRec.define( "apc", apcCorrected ) ;
    46   if ( reg.match( antenna.c_str(), antenna.size() ) != String::npos ) {
    47     // antenna is specifiec as id
    48     int aid = atoi( antenna.c_str() ) ;
    49     asdmRec.define( "antenna", aid ) ;
     61  int numApc = 1 ;
     62  Vector<Bool> apcCorrected ;
     63  apcCorrected.resize( numApc ) ;
     64  if ( apc == "both" ) {
     65    numApc = 2 ;
     66    apcCorrected.resize( numApc ) ;
     67    apcCorrected[0] = True ;
     68    apcCorrected[1] = False ;
     69  }
     70  else if ( apc == "yes" ) {
     71    apcCorrected.resize( numApc ) ;
     72    apcCorrected[0] = True ;
     73  }
     74  else if ( apc == "no" ) {
     75    apcCorrected.resize( numApc ) ;
     76    apcCorrected[0] = False ;
    5077  }
    5178  else {
    52     // antenna is specified as name
    53     asdmRec.define( "antenna", antenna ) ;
     79    throw AipsError( "Unrecognized value for -apc option" ) ;
    5480  }
    55   rec.defineRecord( "asdm", asdmRec ) ;
    56   filler->open( asdmname, rec ) ;
     81   
    5782
    58   // output filename
    59   CountedPtr<ASDMReader> reader = filler->getReader() ;
    60   string aname = reader->getAntennaName() ;
    61   int aid = reader->getAntennaId() ;
    62   if ( asapname.size() == 0 ) {
    63     asapname = asdmname + "." + aname + ".asap" ;
     83  ofstream ofs ;
     84  CountedPtr<LogSinkInterface> logsink_p ;
     85  String funcname( argv[0] ) ;
     86  if ( logfile.size() != 0 ) {
     87    ofs.open( logfile.c_str(), ios_base::app ) ;
     88    logsink_p = new StreamLogSink( &ofs ) ;
     89    logsink_p->cerrToo( false ) ;
     90  }
     91  else {
     92    logsink_p = new StreamLogSink() ;
    6493  }
     94  // create ASDMFiller object
     95  //logsink_p->postLocally( LogMessage( "numApc = "+String::toString(numApc), LogOrigin(funcname,WHERE) ) ) ;
     96  for ( int iapc = 0 ; iapc < numApc ; iapc++ ) {
     97    CountedPtr<Scantable> stable( new Scantable() ) ;
     98    ASDMFiller *filler = new ASDMFiller( stable ) ;
    6599
    66   cout << "specified option summary:" << endl ;
    67   cout << "   antenna = " << antenna << " (ID: " << aid << ")" << endl ;
    68   cout << "   asdmname = " << asdmname << endl ;
    69   cout << "   asapname = " << asapname << endl ;
    70   cout << "   apcCorrected = " << apcCorrected << endl ;
     100    // set logger
     101    filler->setLogger( logsink_p ) ;
    71102
    72   // save scantable on disk
    73   Directory dir( asapname ) ;
    74   if ( dir.exists() ) {
    75     if ( overwrite ) {
    76       cout << "Delete existing file..." << endl ;
    77       dir.removeRecursive() ;
     103    // open data
     104    Record rec ;
     105    Record asdmRec ;
     106    Regex reg( "[0-9]+$" ) ;
     107    //asdmRec.define( "apc", apcCorrected ) ;
     108    asdmRec.define( "apc", apcCorrected[iapc] ) ;
     109    asdmRec.define( "corr", corrMode ) ;
     110    asdmRec.define( "sampling", timeSampling ) ;
     111    if ( reg.match( antenna.c_str(), antenna.size() ) != String::npos ) {
     112      // antenna is specifiec as id
     113      int aid = atoi( antenna.c_str() ) ;
     114      asdmRec.define( "antenna", aid ) ;
    78115    }
    79116    else {
    80       cerr << "Output file " << asapname << " exists." << endl ;
    81       return 1 ;
     117      // antenna is specified as name
     118      asdmRec.define( "antenna", antenna ) ;
    82119    }
     120    rec.defineRecord( "asdm", asdmRec ) ;
     121    filler->open( asdmname, rec ) ;
     122   
     123    // output filename
     124    CountedPtr<ASDMReader> reader = filler->getReader() ;
     125    string aname = reader->getAntennaName() ;
     126    int aid = reader->getAntennaId() ;
     127    string outname = asapname ;
     128    if ( asapname.size() == 0 ) {
     129      outname = asdmname + "." + aname + ".asap" ;
     130    }
     131    if ( apcCorrected[iapc] == True ) {
     132      outname += ".wvr-corrected" ;
     133    }
     134   
     135    //logsink_p->postLocally( LogMessage("specified option summary:",LogOrigin(funcname,WHERE)) ) ;
     136    //logsink_p->postLocally( LogMessage("   antenna = "+String(aname)+" (ID: "+String::toString(aid)+")",LogOrigin(funcname,WHERE)) ) ;
     137    //logsink_p->postLocally( LogMessage("   asdmname = "+asdmname,LogOrigin(funcname,WHERE)) ) ;
     138    //logsink_p->postLocally( LogMessage("   asapname = "+outname,LogOrigin(funcname,WHERE)) ) ;
     139    //logsink_p->postLocally( LogMessage("   apcCorrected = "+String::toString(apcCorrected[iapc]),LogOrigin(funcname,WHERE) ) ) ;
     140    //logsink_p->postLocally( LogMessage("   timeSampling = "+timeSampling,LogOrigin(funcname,WHERE) ) ) ;
     141    //logsink_p->postLocally( LogMessage("   corrMode = "+corrMode,LogOrigin(funcname,WHERE) ) ) ;
     142   
     143    // save scantable on disk
     144    Directory dir( outname ) ;
     145    if ( dir.exists() ) {
     146      if ( overwrite ) {
     147        //*os << "Delete existing file " << outname << " ..." << LogIO::POST ;
     148        logsink_p->postLocally( LogMessage("Delete existing file "+outname+" ...",LogOrigin(funcname,WHERE)) ) ;
     149        dir.removeRecursive() ;
     150      }
     151      else {
     152        //*os << LogIO::WARN << "Output file " << outname << " exists." << LogIO::POST ;
     153        logsink_p->postLocally( LogMessage("Output file "+outname+" exists.",LogOrigin(funcname,WHERE),LogMessage::WARN) ) ;
     154        return 1 ;
     155      }
     156    }
     157   
     158    // fill data
     159    filler->fill() ;
     160   
     161    // close data
     162    filler->close() ;
     163   
     164    // save data only if nrow is not zero
     165    if ( stable->nrow() > 0 ) {
     166      //*os << "Creating " << outname << "..." << LogIO::POST ;
     167      logsink_p->postLocally( LogMessage("Creating "+outname+"...",LogOrigin(funcname,WHERE)) ) ;
     168      stable->makePersistent( outname ) ;
     169    }
     170    else {
     171      //*os << outname << " will not be created since there are no data associate with the selection" << LogIO::POST ;
     172      logsink_p->postLocally( LogMessage(outname+" will not be created since there are no data associate with the selection",LogOrigin(funcname,WHERE)) ) ;
     173    }
     174   
     175    // finalize
     176    reader = 0 ;
     177    delete filler ;
     178   
    83179  }
    84 
    85   // fill data
    86   filler->fill() ;
    87 
    88   // close data
    89   filler->close() ;
    90 
    91   // save data
    92   stable->makePersistent( asapname ) ;
    93 
    94   // finalize
    95   reader = 0 ;
    96   delete filler ;
     180 
     181  if ( logfile.size() != 0 )
     182    ofs.close() ;
     183  //delete os ;
    97184
    98185  return 0 ;
Note: See TracChangeset for help on using the changeset viewer.