[2197] | 1 | #include <iostream>
|
---|
[2208] | 2 | #include <fstream>
|
---|
[2197] | 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>
|
---|
[2208] | 8 | #include <casa/Logging/LogIO.h>
|
---|
| 9 | #include <casa/Logging/LogSink.h>
|
---|
| 10 | #include <casa/Logging/StreamLogSink.h>
|
---|
| 11 | #include <casa/Logging/LogFilter.h>
|
---|
[2241] | 12 | #include "../../src/Scantable.h"
|
---|
[2197] | 13 | #include "ASDMFiller.h"
|
---|
| 14 |
|
---|
| 15 | using namespace std ;
|
---|
| 16 | using namespace asdm ;
|
---|
| 17 | using namespace casa ;
|
---|
| 18 | using namespace asap ;
|
---|
| 19 |
|
---|
| 20 | int main( int argc, char *argv[] )
|
---|
| 21 | {
|
---|
| 22 | // options
|
---|
| 23 | Input inp ;
|
---|
| 24 | String indent = " " ;
|
---|
[2216] | 25 | String versionInfo = "$Id: asdm2ASAP.cc 2273 2011-08-12 06:20:30Z 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]" ;
|
---|
[2208] | 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( "" ) ;
|
---|
[2197] | 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" ) ;
|
---|
[2208] | 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" ) ;
|
---|
[2248] | 46 | inp.create( "corr-mode", "ca,ao", "Input correlator mode: ca+ao|ca|ao", "String" ) ;
|
---|
[2208] | 47 | inp.create( "ocorr-mode", "ao", "Output correlator mode: ao", "String" ) ;
|
---|
| 48 | inp.create( "time-sampling", "all", "time sampling mode: all|integration|subintegration", "String" ) ;
|
---|
[2216] | 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" ) ;
|
---|
[2208] | 50 | inp.create( "logfile", "", "logger output", "String" ) ;
|
---|
[2197] | 51 | inp.readArguments( argc, argv ) ;
|
---|
| 52 |
|
---|
| 53 | string asdmname = inp.getString( "asdm" ) ;
|
---|
| 54 | string antenna = inp.getString( "antenna" ) ;
|
---|
| 55 | string asapname = inp.getString( "asap" ) ;
|
---|
[2208] | 56 | string apc = inp.getString( "apc" ) ;
|
---|
[2197] | 57 | Bool overwrite = inp.getBool( "overwrite" ) ;
|
---|
[2208] | 58 | string corrMode = inp.getString( "corr-mode" ) ;
|
---|
| 59 | string timeSampling = inp.getString( "time-sampling" ) ;
|
---|
[2215] | 60 | string resolutionType = inp.getString( "srt" ) ;
|
---|
[2208] | 61 | string logfile = inp.getString( "logfile" ) ;
|
---|
[2197] | 62 |
|
---|
[2208] | 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 ;
|
---|
[2197] | 71 | }
|
---|
[2208] | 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 | }
|
---|
[2197] | 80 | else {
|
---|
[2208] | 81 | throw AipsError( "Unrecognized value for -apc option" ) ;
|
---|
[2197] | 82 | }
|
---|
[2208] | 83 |
|
---|
[2197] | 84 |
|
---|
[2208] | 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() ;
|
---|
[2197] | 95 | }
|
---|
[2208] | 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 ) ;
|
---|
[2197] | 101 |
|
---|
[2208] | 102 | // set logger
|
---|
| 103 | filler->setLogger( logsink_p ) ;
|
---|
[2197] | 104 |
|
---|
[2208] | 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 ) ;
|
---|
[2215] | 113 | asdmRec.define( "srt", resolutionType ) ;
|
---|
[2208] | 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 ) ;
|
---|
[2197] | 118 | }
|
---|
| 119 | else {
|
---|
[2208] | 120 | // antenna is specified as name
|
---|
| 121 | asdmRec.define( "antenna", antenna ) ;
|
---|
[2197] | 122 | }
|
---|
[2208] | 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 | 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)) ) ;
|
---|
[2273] | 138 | //logsink_p->postLocally( LogMessage(" antenna = "+String(aname)+" (ID: "+String::toString(reader->getAntennaId())+")",LogOrigin(funcname,WHERE)) ) ;
|
---|
[2208] | 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 |
|
---|
[2197] | 177 | }
|
---|
[2208] | 178 |
|
---|
| 179 | if ( logfile.size() != 0 )
|
---|
| 180 | ofs.close() ;
|
---|
[2197] | 181 |
|
---|
| 182 | return 0 ;
|
---|
| 183 | }
|
---|