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 28 : CalLibraryParse::CalLibraryParse(): 39 28 : callibRec_(NULL) { 40 28 : reset(); 41 28 : } 42 : 43 28 : CalLibraryParse::~CalLibraryParse() { 44 28 : delete callibRec_; 45 28 : } 46 : 47 28 : void CalLibraryParse::reset() { 48 : //if (CalLibraryParse::callibRec_ != 0x0) delete CalLibraryParse::callibRec_; 49 : //CalLibraryParse::callibRec_ = 0x0; 50 28 : if (callibRec_ != NULL) delete callibRec_; 51 28 : callibRec_ = new Record(); 52 28 : resetCaltable(); 53 28 : } 54 : 55 49 : void CalLibraryParse::resetCaltable() { 56 49 : caltableName_ = ""; 57 49 : mapName_ = ""; 58 49 : mapList_.resize(0); 59 49 : calwt_ = true; 60 49 : resetParamRecord(); 61 49 : } 62 : 63 49 : void CalLibraryParse::resetParamRecord() { 64 49 : paramRec_.define("field", ""); 65 49 : paramRec_.define("intent", ""); 66 49 : paramRec_.define("spw", ""); 67 49 : paramRec_.define("obs", ""); 68 49 : paramRec_.define("scan", ""); 69 49 : paramRec_.define("tinterp", ""); 70 49 : paramRec_.define("finterp", ""); 71 49 : paramRec_.define("reach", ""); 72 49 : addDefaultMap("antmap"); 73 49 : addDefaultMap("fldmap"); 74 49 : addDefaultMap("obsmap"); 75 49 : addDefaultMap("scanmap"); 76 49 : addDefaultMap("spwmap"); 77 49 : } 78 : 79 245 : void CalLibraryParse::addDefaultMap(String key) { 80 245 : if (paramRec_.isDefined(key) && (paramRec_.dataType(key) == TpString)) 81 7 : paramRec_.removeField(key); 82 245 : paramRec_.define(key, mapList_); 83 245 : } 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 51 : void CalLibraryParse::addStringParam(String key, String val) { 93 51 : if (paramRec_.isDefined(key)) { 94 30 : if (paramRec_.dataType(key) == TpArrayInt) paramRec_.removeField(key); 95 30 : val.gsub("'", "\""); // repl ' with " around field 96 30 : paramRec_.define(key, val); 97 21 : } else if (key == "caltable") { 98 21 : caltableName_ = val; 99 : } else { 100 0 : issueKeywordWarning(key); 101 : } 102 51 : } 103 : 104 17 : void CalLibraryParse::addBoolParam(String key, Bool val) { 105 17 : if (key == "calwt") 106 17 : calwt_ = val; 107 : else 108 0 : issueKeywordWarning(key); 109 17 : } 110 : 111 5 : void CalLibraryParse::addMapParam(String mapname, Int val) { 112 5 : if (paramRec_.isDefined(mapname)) { 113 5 : mapName_ = mapname; 114 5 : mapList_.resize(1); 115 5 : mapList_[0] = val; 116 : } else { 117 0 : issueKeywordWarning(mapname); 118 : } 119 5 : } 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 5 : void CalLibraryParse::addMap() { 128 5 : paramRec_.define(mapName_, mapList_); 129 5 : mapList_.resize(0); 130 5 : } 131 : 132 21 : void CalLibraryParse::addCaltable() { 133 : // triggered by endl 134 21 : if (!caltableName_.empty()) { 135 21 : uInt calIndex = 0; 136 21 : Record caltableRec; 137 : 138 21 : if (callibRec_->isDefined(caltableName_)) { 139 2 : caltableRec = callibRec_->asRecord(caltableName_); 140 : // Remove calwt and then add it as the last field 141 2 : Bool calwt = caltableRec.asBool("calwt"); 142 2 : caltableRec.removeField("calwt"); // this has to be last! 143 2 : calIndex = caltableRec.nfields(); 144 2 : caltableRec.defineRecord(String::toString(calIndex), paramRec_); 145 2 : caltableRec.define("calwt", calwt); // put it back in! 146 2 : callibRec_->defineRecord(caltableName_, caltableRec); 147 : } else { 148 19 : caltableRec.defineRecord(String::toString(0), paramRec_); 149 19 : caltableRec.define("calwt", calwt_); 150 19 : callibRec_->defineRecord(caltableName_, caltableRec); 151 : } 152 21 : resetCaltable(); // get ready for the next one! 153 21 : } 154 21 : } 155 : 156 28 : const Record* CalLibraryParse::record() { 157 28 : return callibRec_; 158 : } 159 : 160 : }