[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 2248 2011-07-27 03:00:12Z 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 | 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 |
|
---|
[2197] | 178 | }
|
---|
[2208] | 179 |
|
---|
| 180 | if ( logfile.size() != 0 )
|
---|
| 181 | ofs.close() ;
|
---|
[2197] | 182 |
|
---|
| 183 | return 0 ;
|
---|
| 184 | }
|
---|