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