source: trunk/external-alma/asdm2ASAP/asdm2ASAP.cc @ 2208

Last change on this file since 2208 was 2208, checked in by Takeshi Nakazato, 13 years ago

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 size: 6.6 KB
Line 
1#include <iostream>
2#include <fstream>
3#include <casa/Utilities/Regex.h>
4#include <casa/Inputs/Input.h>
5#include <casa/BasicSL/String.h>
6#include <casa/Containers/Record.h>
7#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>
12#include <Scantable.h>
13#include "ASDMFiller.h"
14
15using namespace std ;
16using namespace asdm ;
17using namespace casa ;
18using namespace asap ;
19
20int main( int argc, char *argv[] )
21{
22  // options
23  Input inp ;
24  String indent = "   " ;
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( "" ) ;
40
41  inp.create( "antenna", "0", "antenna name or id", "String" ) ;
42  inp.create( "asdm", "", "ASDM directory name", "String" ) ;
43  inp.create( "asap", "", "Scantable name", "String" ) ;
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" ) ;
50  inp.readArguments( argc, argv ) ;
51
52  string asdmname = inp.getString( "asdm" ) ;
53  string antenna = inp.getString( "antenna" ) ;
54  string asapname = inp.getString( "asap" ) ;
55  string apc = inp.getString( "apc" ) ;
56  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" ) ;
60   
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 ;
77  }
78  else {
79    throw AipsError( "Unrecognized value for -apc option" ) ;
80  }
81   
82
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() ;
93  }
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 ) ;
99
100    // set logger
101    filler->setLogger( logsink_p ) ;
102
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 ) ;
115    }
116    else {
117      // antenna is specified as name
118      asdmRec.define( "antenna", antenna ) ;
119    }
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   
179  }
180 
181  if ( logfile.size() != 0 )
182    ofs.close() ;
183  //delete os ;
184
185  return 0 ;
186}
Note: See TracBrowser for help on using the repository browser.