source: branches/hpc34/external-alma/oldasdm2ASAP/oldasdm2ASAP.cc@ 2740

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

New Development: No

JIRA Issue: Yes CAS-1913

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...

Support latest ASDM definition in asdm2ASAP.
Now asdm2ASAP is linked to libalma_v3.so to be able to read latest ASDM.

The importasdm task invokes asdm2ASAP when singledish is True.

Older version of asdm2ASAP is renamec as oldasdm2ASAP.
The oldasdm2ASAP and related classes are built by linking to libalma.so.
It is installed but not used by any tasks.


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 "OldASDMFiller.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] [-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 OldASDMFiller 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 OldASDMFiller *filler = new OldASDMFiller( 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<OldASDMReader> reader = filler->getReader() ;
128 string aname = reader->getAntennaName() ;
129 string outname = asapname ;
130 if ( asapname.size() == 0 ) {
131 outname = asdmname + "." + aname + ".asap" ;
132 }
133 if ( apcCorrected[iapc] == True ) {
134 outname += ".wvr-corrected" ;
135 }
136
137 //logsink_p->postLocally( LogMessage("specified option summary:",LogOrigin(funcname,WHERE)) ) ;
138 //logsink_p->postLocally( LogMessage(" antenna = "+String(aname)+" (ID: "+String::toString(reader->getAntennaId())+")",LogOrigin(funcname,WHERE)) ) ;
139 //logsink_p->postLocally( LogMessage(" asdmname = "+asdmname,LogOrigin(funcname,WHERE)) ) ;
140 //logsink_p->postLocally( LogMessage(" asapname = "+outname,LogOrigin(funcname,WHERE)) ) ;
141 //logsink_p->postLocally( LogMessage(" apcCorrected = "+String::toString(apcCorrected[iapc]),LogOrigin(funcname,WHERE) ) ) ;
142 //logsink_p->postLocally( LogMessage(" timeSampling = "+timeSampling,LogOrigin(funcname,WHERE) ) ) ;
143 //logsink_p->postLocally( LogMessage(" corrMode = "+corrMode,LogOrigin(funcname,WHERE) ) ) ;
144
145 // save scantable on disk
146 Directory dir( outname ) ;
147 if ( dir.exists() ) {
148 if ( overwrite ) {
149 logsink_p->postLocally( LogMessage("Delete existing file "+outname+" ...",LogOrigin(funcname,WHERE)) ) ;
150 dir.removeRecursive() ;
151 }
152 else {
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 logsink_p->postLocally( LogMessage("Creating "+outname+"...",LogOrigin(funcname,WHERE)) ) ;
167 stable->makePersistent( outname ) ;
168 }
169 else {
170 logsink_p->postLocally( LogMessage(outname+" will not be created since there are no data associate with the selection",LogOrigin(funcname,WHERE)) ) ;
171 }
172
173 // finalize
174 reader = 0 ;
175 delete filler ;
176
177 }
178
179 if ( logfile.size() != 0 )
180 ofs.close() ;
181
182 return 0 ;
183}
Note: See TracBrowser for help on using the repository browser.