Line data Source code
1 : //# CalLibraryParse.cc: Class to hold results from cal library parser 2 : //# Copyright (C) 1994,1995,1997,1998,1999,2000,2001,2003 3 : //# Associated Universities, Inc. Washington DC, USA. 4 : //# 5 : //# This library is free software; you can redistribute it and/or modify it 6 : //# under the terms of the GNU Library General Public License as published by 7 : //# the Free Software Foundation; either version 2 of the License, or (at your 8 : //# option) any later version. 9 : //# 10 : //# This library is distributed in the hope that it will be useful, but WITHOUT 11 : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 : //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 13 : //# License for more details. 14 : //# 15 : //# You should have received a copy of the GNU Library General Public License 16 : //# along with this library; if not, write to the Free Software Foundation, 17 : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 : //# 19 : //# Correspondence concerning AIPS++ should be addressed as follows: 20 : //# Internet email: casa-feedback@nrao.edu. 21 : //# Postal address: AIPS++ Project Office 22 : //# National Radio Astronomy Observatory 23 : //# 520 Edgemont Road 24 : //# Charlottesville, VA 22903-2475 USA 25 : //# 26 : 27 : #include <synthesis/CalLibrary/CalLibraryParse.h> 28 : #include <casacore/casa/Logging/LogIO.h> 29 : #include <casacore/casa/Logging/LogSink.h> 30 : 31 : using namespace casacore; 32 : namespace casa { 33 : 34 : CalLibraryParse* CalLibraryParse::thisCalLibParser = 0x0; 35 : //Record* CalLibraryParse::callibRec_; 36 : 37 : 38 34 : CalLibraryParse::CalLibraryParse(): 39 34 : callibRec_(NULL) { 40 34 : reset(); 41 34 : } 42 : 43 34 : CalLibraryParse::~CalLibraryParse() { 44 34 : delete callibRec_; 45 34 : } 46 : 47 34 : void CalLibraryParse::reset() { 48 : //if (CalLibraryParse::callibRec_ != 0x0) delete CalLibraryParse::callibRec_; 49 : //CalLibraryParse::callibRec_ = 0x0; 50 34 : if (callibRec_ != NULL) delete callibRec_; 51 34 : callibRec_ = new Record(); 52 34 : resetCaltable(); 53 34 : } 54 : 55 58 : void CalLibraryParse::resetCaltable() { 56 58 : caltableName_ = ""; 57 58 : mapName_ = ""; 58 58 : mapList_.resize(0); 59 58 : calwt_ = true; 60 58 : resetParamRecord(); 61 58 : } 62 : 63 58 : void CalLibraryParse::resetParamRecord() { 64 58 : paramRec_.define("field", ""); 65 58 : paramRec_.define("intent", ""); 66 58 : paramRec_.define("spw", ""); 67 58 : paramRec_.define("obs", ""); 68 58 : paramRec_.define("scan", ""); 69 58 : paramRec_.define("tinterp", ""); 70 58 : paramRec_.define("finterp", ""); 71 58 : paramRec_.define("reach", ""); 72 58 : addDefaultMap("antmap"); 73 58 : addDefaultMap("fldmap"); 74 58 : addDefaultMap("obsmap"); 75 58 : addDefaultMap("scanmap"); 76 58 : addDefaultMap("spwmap"); 77 58 : } 78 : 79 290 : void CalLibraryParse::addDefaultMap(String key) { 80 290 : if (paramRec_.isDefined(key) && (paramRec_.dataType(key) == TpString)) 81 5 : paramRec_.removeField(key); 82 290 : paramRec_.define(key, mapList_); 83 290 : } 84 : 85 0 : void CalLibraryParse::issueKeywordWarning(String key) { 86 0 : LogIO logIO; 87 0 : stringstream ss; 88 0 : ss << "Cal Library: undefined keyword " << key << " will be ignored."; 89 0 : logIO << ss.str() << LogIO::WARN << LogIO::POST; 90 0 : } 91 : 92 71 : void CalLibraryParse::addStringParam(String key, String val) { 93 71 : if (paramRec_.isDefined(key)) { 94 47 : if (paramRec_.dataType(key) == TpArrayInt) paramRec_.removeField(key); 95 47 : val.gsub("'", "\""); // repl ' with " around field 96 47 : paramRec_.define(key, val); 97 24 : } else if (key == "caltable") { 98 24 : caltableName_ = val; 99 : } else { 100 0 : issueKeywordWarning(key); 101 : } 102 71 : } 103 : 104 20 : void CalLibraryParse::addBoolParam(String key, Bool val) { 105 20 : if (key == "calwt") 106 20 : calwt_ = val; 107 : else 108 0 : issueKeywordWarning(key); 109 20 : } 110 : 111 4 : void CalLibraryParse::addMapParam(String mapname, Int val) { 112 4 : if (paramRec_.isDefined(mapname)) { 113 4 : mapName_ = mapname; 114 4 : mapList_.resize(1); 115 4 : mapList_[0] = val; 116 : } else { 117 0 : issueKeywordWarning(mapname); 118 : } 119 4 : } 120 : 121 5 : void CalLibraryParse::addMapParam(Int val) { 122 5 : size_t mapsize = mapList_.size(); 123 5 : mapList_.resize(mapsize + 1, true); 124 5 : mapList_[mapsize] = val; 125 5 : } 126 : 127 4 : void CalLibraryParse::addMap() { 128 4 : paramRec_.define(mapName_, mapList_); 129 4 : mapList_.resize(0); 130 4 : } 131 : 132 24 : void CalLibraryParse::addCaltable() { 133 : // triggered by endl 134 24 : if (!caltableName_.empty()) { 135 24 : uInt calIndex = 0; 136 24 : Record caltableRec; 137 : 138 24 : if (callibRec_->isDefined(caltableName_)) { 139 4 : caltableRec = callibRec_->asRecord(caltableName_); 140 : // Remove calwt and then add it as the last field 141 4 : Bool calwt = caltableRec.asBool("calwt"); 142 4 : caltableRec.removeField("calwt"); // this has to be last! 143 4 : calIndex = caltableRec.nfields(); 144 4 : caltableRec.defineRecord(String::toString(calIndex), paramRec_); 145 4 : caltableRec.define("calwt", calwt); // put it back in! 146 4 : callibRec_->defineRecord(caltableName_, caltableRec); 147 : } else { 148 20 : caltableRec.defineRecord(String::toString(0), paramRec_); 149 20 : caltableRec.define("calwt", calwt_); 150 20 : callibRec_->defineRecord(caltableName_, caltableRec); 151 : } 152 24 : resetCaltable(); // get ready for the next one! 153 24 : } 154 24 : } 155 : 156 34 : const Record* CalLibraryParse::record() { 157 34 : return callibRec_; 158 : } 159 : 160 : }