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