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

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

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Workaround for build failure on Mac.
Changed a way to include Scantable.h.


  • Property svn:keywords set to Id
File size: 6.5 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 "../../src/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: asdm2ASAP.cc 2241 2011-07-22 02:53:39Z TakeshiNakazato $\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] [-srt fr|bw|ca|fr,bw|fr,ca|ca,bw|all]" ;
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( "srt", "all", "spectral resolution mode: all|fr(full resolution)|ca(channel average)|bw(baseband wide)|fr+ca|fr+bw|ca+bw", "String" ) ;
50 inp.create( "logfile", "", "logger output", "String" ) ;
51 inp.readArguments( argc, argv ) ;
52
53 string asdmname = inp.getString( "asdm" ) ;
54 string antenna = inp.getString( "antenna" ) ;
55 string asapname = inp.getString( "asap" ) ;
56 string apc = inp.getString( "apc" ) ;
57 Bool overwrite = inp.getBool( "overwrite" ) ;
58 string corrMode = inp.getString( "corr-mode" ) ;
59 string timeSampling = inp.getString( "time-sampling" ) ;
60 string resolutionType = inp.getString( "srt" ) ;
61 string logfile = inp.getString( "logfile" ) ;
62
63 int numApc = 1 ;
64 Vector<Bool> apcCorrected ;
65 apcCorrected.resize( numApc ) ;
66 if ( apc == "both" ) {
67 numApc = 2 ;
68 apcCorrected.resize( numApc ) ;
69 apcCorrected[0] = True ;
70 apcCorrected[1] = False ;
71 }
72 else if ( apc == "yes" ) {
73 apcCorrected.resize( numApc ) ;
74 apcCorrected[0] = True ;
75 }
76 else if ( apc == "no" ) {
77 apcCorrected.resize( numApc ) ;
78 apcCorrected[0] = False ;
79 }
80 else {
81 throw AipsError( "Unrecognized value for -apc option" ) ;
82 }
83
84
85 ofstream ofs ;
86 CountedPtr<LogSinkInterface> logsink_p ;
87 String funcname( argv[0] ) ;
88 if ( logfile.size() != 0 ) {
89 ofs.open( logfile.c_str(), ios_base::app ) ;
90 logsink_p = new StreamLogSink( &ofs ) ;
91 logsink_p->cerrToo( false ) ;
92 }
93 else {
94 logsink_p = new StreamLogSink() ;
95 }
96 // create ASDMFiller object
97 //logsink_p->postLocally( LogMessage( "numApc = "+String::toString(numApc), LogOrigin(funcname,WHERE) ) ) ;
98 for ( int iapc = 0 ; iapc < numApc ; iapc++ ) {
99 CountedPtr<Scantable> stable( new Scantable() ) ;
100 ASDMFiller *filler = new ASDMFiller( stable ) ;
101
102 // set logger
103 filler->setLogger( logsink_p ) ;
104
105 // open data
106 Record rec ;
107 Record asdmRec ;
108 Regex reg( "[0-9]+$" ) ;
109 //asdmRec.define( "apc", apcCorrected ) ;
110 asdmRec.define( "apc", apcCorrected[iapc] ) ;
111 asdmRec.define( "corr", corrMode ) ;
112 asdmRec.define( "sampling", timeSampling ) ;
113 asdmRec.define( "srt", resolutionType ) ;
114 if ( reg.match( antenna.c_str(), antenna.size() ) != String::npos ) {
115 // antenna is specifiec as id
116 int aid = atoi( antenna.c_str() ) ;
117 asdmRec.define( "antenna", aid ) ;
118 }
119 else {
120 // antenna is specified as name
121 asdmRec.define( "antenna", antenna ) ;
122 }
123 rec.defineRecord( "asdm", asdmRec ) ;
124 filler->open( asdmname, rec ) ;
125
126 // output filename
127 CountedPtr<ASDMReader> reader = filler->getReader() ;
128 string aname = reader->getAntennaName() ;
129 int aid = reader->getAntennaId() ;
130 string outname = asapname ;
131 if ( asapname.size() == 0 ) {
132 outname = asdmname + "." + aname + ".asap" ;
133 }
134 if ( apcCorrected[iapc] == True ) {
135 outname += ".wvr-corrected" ;
136 }
137
138 //logsink_p->postLocally( LogMessage("specified option summary:",LogOrigin(funcname,WHERE)) ) ;
139 //logsink_p->postLocally( LogMessage(" antenna = "+String(aname)+" (ID: "+String::toString(aid)+")",LogOrigin(funcname,WHERE)) ) ;
140 //logsink_p->postLocally( LogMessage(" asdmname = "+asdmname,LogOrigin(funcname,WHERE)) ) ;
141 //logsink_p->postLocally( LogMessage(" asapname = "+outname,LogOrigin(funcname,WHERE)) ) ;
142 //logsink_p->postLocally( LogMessage(" apcCorrected = "+String::toString(apcCorrected[iapc]),LogOrigin(funcname,WHERE) ) ) ;
143 //logsink_p->postLocally( LogMessage(" timeSampling = "+timeSampling,LogOrigin(funcname,WHERE) ) ) ;
144 //logsink_p->postLocally( LogMessage(" corrMode = "+corrMode,LogOrigin(funcname,WHERE) ) ) ;
145
146 // save scantable on disk
147 Directory dir( outname ) ;
148 if ( dir.exists() ) {
149 if ( overwrite ) {
150 logsink_p->postLocally( LogMessage("Delete existing file "+outname+" ...",LogOrigin(funcname,WHERE)) ) ;
151 dir.removeRecursive() ;
152 }
153 else {
154 logsink_p->postLocally( LogMessage("Output file "+outname+" exists.",LogOrigin(funcname,WHERE),LogMessage::WARN) ) ;
155 return 1 ;
156 }
157 }
158
159 // fill data
160 filler->fill() ;
161
162 // close data
163 filler->close() ;
164
165 // save data only if nrow is not zero
166 if ( stable->nrow() > 0 ) {
167 logsink_p->postLocally( LogMessage("Creating "+outname+"...",LogOrigin(funcname,WHERE)) ) ;
168 stable->makePersistent( outname ) ;
169 }
170 else {
171 logsink_p->postLocally( LogMessage(outname+" will not be created since there are no data associate with the selection",LogOrigin(funcname,WHERE)) ) ;
172 }
173
174 // finalize
175 reader = 0 ;
176 delete filler ;
177
178 }
179
180 if ( logfile.size() != 0 )
181 ofs.close() ;
182
183 return 0 ;
184}
Note: See TracBrowser for help on using the repository browser.