1 | #include <iostream> |
---|
2 | #include <casa/Utilities/Regex.h> |
---|
3 | #include <casa/Inputs/Input.h> |
---|
4 | #include <casa/BasicSL/String.h> |
---|
5 | #include <casa/Containers/Record.h> |
---|
6 | #include <casa/OS/Directory.h> |
---|
7 | #include <Scantable.h> |
---|
8 | #include "ASDMFiller.h" |
---|
9 | |
---|
10 | using namespace std ; |
---|
11 | using namespace asdm ; |
---|
12 | using namespace casa ; |
---|
13 | using namespace asap ; |
---|
14 | |
---|
15 | int main( int argc, char *argv[] ) |
---|
16 | { |
---|
17 | // options |
---|
18 | Input inp ; |
---|
19 | 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 ) ; |
---|
22 | |
---|
23 | inp.create( "antenna", "0", "antenna name or id", "String" ) ; |
---|
24 | inp.create( "asdm", "", "ASDM directory name", "String" ) ; |
---|
25 | 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" ) ; |
---|
28 | inp.readArguments( argc, argv ) ; |
---|
29 | |
---|
30 | string asdmname = inp.getString( "asdm" ) ; |
---|
31 | string antenna = inp.getString( "antenna" ) ; |
---|
32 | string asapname = inp.getString( "asap" ) ; |
---|
33 | Bool apcCorrected = inp.getBool( "apc" ) ; |
---|
34 | Bool overwrite = inp.getBool( "overwrite" ) ; |
---|
35 | |
---|
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 ) ; |
---|
50 | } |
---|
51 | else { |
---|
52 | // antenna is specified as name |
---|
53 | asdmRec.define( "antenna", antenna ) ; |
---|
54 | } |
---|
55 | rec.defineRecord( "asdm", asdmRec ) ; |
---|
56 | filler->open( asdmname, rec ) ; |
---|
57 | |
---|
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" ; |
---|
64 | } |
---|
65 | |
---|
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 ; |
---|
71 | |
---|
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() ; |
---|
78 | } |
---|
79 | else { |
---|
80 | cerr << "Output file " << asapname << " exists." << endl ; |
---|
81 | return 1 ; |
---|
82 | } |
---|
83 | } |
---|
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 ; |
---|
97 | |
---|
98 | return 0 ; |
---|
99 | } |
---|