LCOV - code coverage report
Current view: top level - flagging/Flagging - AgentFlagger.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 780 0.0 %
Date: 2024-10-04 16:51:10 Functions: 0 32 0.0 %

          Line data    Source code
       1             : ///# AgentFlagger.cc: this defines AgentFlagger
       2             : //# Copyright (C) 2000,2001,2002
       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             : //# $Id$
      27             : #include <casacore/casa/Arrays/Vector.h>
      28             : #include <casacore/casa/Arrays/ArrayMath.h>
      29             : #include <casacore/casa/Arrays/ArrayLogical.h>
      30             : #include <casacore/casa/BasicSL/Complex.h>
      31             : #include <casacore/casa/Utilities/Regex.h>
      32             : #include <casacore/casa/OS/HostInfo.h>
      33             : #include <casacore/casa/Exceptions/Error.h>
      34             : #include <flagging/Flagging/AgentFlagger.h>
      35             : #include <flagging/Flagging/FlagVersion.h>
      36             : #include <stdarg.h>
      37             : #include <sstream>
      38             : #include <iostream>
      39             : #include <vector>
      40             : 
      41             : #include <flagging/Flagging/FlagCalTableHandler.h>
      42             : #include <flagging/Flagging/FlagMSHandler.h>
      43             : #ifdef USE_GRPC
      44             : #include <flagging/Flagging/grpcFlagAgentDisplay.h>
      45             : #endif
      46             : 
      47             : using namespace casacore;
      48             : namespace casa {
      49             : 
      50             : const bool AgentFlagger::dbg = false;
      51             : 
      52             : 
      53             : // -----------------------------------------------------------------------
      54             : // Default Constructor
      55             : // -----------------------------------------------------------------------
      56           0 : AgentFlagger::AgentFlagger ()
      57             : {
      58           0 :         fdh_p = NULL;
      59           0 :         summaryAgent_p = NULL;
      60           0 :         displayAgent_p = NULL;
      61             : 
      62           0 :         done();
      63           0 : }
      64             : 
      65             : 
      66             : // -----------------------------------------------------------------------
      67             : // Default Destructor
      68             : // -----------------------------------------------------------------------
      69           0 : AgentFlagger::~AgentFlagger ()
      70             : {
      71           0 :         done();
      72           0 : }
      73             : 
      74             : void
      75           0 : AgentFlagger::done()
      76             : {
      77           0 :         if(fdh_p){
      78           0 :                 delete fdh_p;
      79           0 :                 fdh_p = NULL;
      80             :         }
      81             : 
      82             :         // Default values of parameters
      83           0 :         msname_p = "";
      84           0 :         iterationApproach_p = FlagDataHandler::SUB_INTEGRATION;
      85           0 :         timeInterval_p = 0.0;
      86           0 :         isMS_p = true;
      87           0 :         combinescans_p = false;
      88           0 :         extendflags_p = true;
      89           0 :         spw_p = "";
      90           0 :         scan_p = "";
      91           0 :         field_p = "";
      92           0 :         antenna_p = "";
      93           0 :         timerange_p = "";
      94           0 :         correlation_p = "";
      95           0 :         intent_p = "";
      96           0 :         feed_p = "";
      97           0 :         array_p = "";
      98           0 :         uvrange_p = "";
      99           0 :         observation_p = "";
     100             : 
     101           0 :         max_p = 0.0;
     102             : 
     103           0 :         dataselection_p = Record();
     104             : 
     105             :         /*
     106             :         if (! dataselection_p.empty()) {
     107             :                 Record temp;
     108             :                 dataselection_p = temp;
     109             :         }
     110             :          */
     111             : 
     112           0 :         if (! agentParams_p.empty()) {
     113           0 :                 Record temp;
     114           0 :                 agentParams_p = temp;
     115           0 :         }
     116             : 
     117           0 :         if(summaryAgent_p){
     118           0 :                 summaryAgent_p = NULL;
     119             :         }
     120             : 
     121           0 :         if(displayAgent_p){
     122           0 :                 displayAgent_p = NULL;
     123             :         }
     124             : 
     125           0 :         mode_p = "";
     126           0 :         agents_config_list_p.clear();
     127           0 :         agents_config_list_copy_p.clear();
     128           0 :         agents_list_p.clear();
     129             : 
     130           0 :         return;
     131             : }
     132             : 
     133             : // ---------------------------------------------------------------------
     134             : // AgentFlagger::open
     135             : // Create a FlagDataHandler object based on the input type:
     136             : // MS or a calibration file. Open the MS or cal table and
     137             : // attach it to the tool.
     138             : // ---------------------------------------------------------------------
     139             : bool
     140           0 : AgentFlagger::open(String msname, Double ntime)
     141             : {
     142             : 
     143           0 :         LogIO os(LogOrigin("AgentFlagger", __FUNCTION__));
     144             : 
     145           0 :         if (msname.empty()) {
     146             :                 os << LogIO::SEVERE << "No Measurement Set has been parsed"
     147           0 :                                 << LogIO::POST;
     148           0 :                 return false;
     149             :         }
     150             : 
     151           0 :         msname_p = msname;
     152             : 
     153           0 :         if (ntime)
     154           0 :                 timeInterval_p = ntime;
     155             : 
     156           0 :         max_p = timeInterval_p;
     157             : 
     158             :         if(dbg){
     159             :                 os << LogIO::NORMAL << "msname = " << msname_p << " ntime = " << timeInterval_p << LogIO::POST;
     160             :         }
     161             : 
     162           0 :         if(fdh_p) delete fdh_p;
     163             : 
     164             :         // create a FlagDataHandler object
     165           0 :         Table table(msname_p,TableLock(TableLock::AutoNoReadLocking));
     166           0 :         TableInfo& info = table.tableInfo();
     167           0 :         String type = info.type();
     168           0 :         table.flush();
     169           0 :         table.relinquishAutoLocks(true);
     170           0 :         table.unlock();
     171           0 :         os << LogIO::NORMAL << "Table type is " << type << LogIO::POST;
     172             : 
     173             :         // For a measurement set
     174           0 :         if (type == "Measurement Set")
     175             :         {
     176           0 :                 isMS_p = true;
     177           0 :                 fdh_p = new FlagMSHandler(msname_p, iterationApproach_p, timeInterval_p);
     178             :         }
     179             :         // For a calibration file
     180             :         else
     181             :         {
     182           0 :                 isMS_p = false;
     183           0 :                 fdh_p = new FlagCalTableHandler(msname_p, iterationApproach_p, timeInterval_p);
     184             :         }
     185             : 
     186             :         // Open the MS
     187           0 :         fdh_p->open();
     188             : 
     189           0 :         return true;
     190           0 : }
     191             : 
     192             : // ---------------------------------------------------------------------
     193             : // AgentFlagger::selectData
     194             : // Get a record with data selection parameters and
     195             : // Parse it to the FlagDataHandler to select the data
     196             : // ---------------------------------------------------------------------
     197             : bool
     198           0 : AgentFlagger::selectData(Record selrec)
     199             : {
     200             : 
     201           0 :         LogIO os(LogOrigin("AgentFlagger", __FUNCTION__));
     202             :         if (dbg)
     203             :                 os << LogIO::NORMAL << "Called from selectData(Record)" << LogIO::POST;
     204             : 
     205           0 :         if (! fdh_p){
     206           0 :                 os << LogIO::SEVERE << "There is no MS attached. Please run af.open first." << LogIO::POST;
     207           0 :                 return false;
     208             :         }
     209             : 
     210             : 
     211           0 :         if (! selrec.empty()) {
     212             : 
     213           0 :                 dataselection_p = selrec;
     214             : 
     215             :                 // Check if all the parameters are in the record. If not,
     216             :                 // use the default values
     217           0 :                 if (dataselection_p.isDefined("spw"))
     218           0 :                         dataselection_p.get("spw", spw_p);
     219           0 :                 if (dataselection_p.isDefined("scan"))
     220           0 :                         dataselection_p.get("scan", scan_p);
     221           0 :                 if (dataselection_p.isDefined("field"))
     222           0 :                         dataselection_p.get("field", field_p);
     223           0 :                 if (dataselection_p.isDefined("antenna"))
     224           0 :                         dataselection_p.get("antenna", antenna_p);
     225           0 :                 if (dataselection_p.isDefined("timerange"))
     226           0 :                         dataselection_p.get("timerange", timerange_p);
     227           0 :                 if (dataselection_p.isDefined("correlation"))
     228           0 :                         dataselection_p.get("correlation", correlation_p);
     229           0 :                 if (dataselection_p.isDefined("intent"))
     230           0 :                         dataselection_p.get("intent", intent_p);
     231           0 :                 if (dataselection_p.isDefined("feed"))
     232           0 :                         dataselection_p.get("feed", feed_p);
     233           0 :                 if (dataselection_p.isDefined("array"))
     234           0 :                         dataselection_p.get("array", array_p);
     235           0 :                 if (dataselection_p.isDefined("uvrange"))
     236           0 :                         dataselection_p.get("uvrange", uvrange_p);
     237           0 :                 if (dataselection_p.isDefined("observation"))
     238           0 :                         dataselection_p.get("observation", observation_p);
     239             : 
     240             :         }
     241             : 
     242           0 :         bool ret_status = true;
     243             : 
     244             :         // Set the data selection
     245           0 :         ret_status = fdh_p->setDataSelection(dataselection_p);
     246           0 :         if (!ret_status) {
     247             :                 os << LogIO::SEVERE << "Failed to set the data selection."
     248           0 :                                 << LogIO::POST;
     249           0 :                 return false;
     250             :         }
     251             : 
     252             :         // Select the data
     253           0 :         ret_status = fdh_p->selectData();
     254           0 :         if (!ret_status) {
     255             :                 os << LogIO::SEVERE << "Failed to select the data."
     256           0 :                                 << LogIO::POST;
     257           0 :                 return false;
     258             :         }
     259             : 
     260             : 
     261           0 :         return true;
     262           0 : }
     263             : 
     264             : 
     265             : // ---------------------------------------------------------------------
     266             : // AgentFlagger::selectData
     267             : // Create a record with data selection parameters.
     268             : // ---------------------------------------------------------------------
     269             : bool
     270           0 : AgentFlagger::selectData(String field, String spw, String array,
     271             :                 String feed, String scan, String antenna,
     272             :                 String uvrange,  String timerange, String correlation,
     273             :                 String intent, String observation)
     274             : {
     275             : 
     276           0 :         LogIO os(LogOrigin("AgentFlagger", __FUNCTION__));
     277             : 
     278             :         if (dbg)
     279             :                 os << LogIO::NORMAL << "Called from selectData(String....)" << LogIO::POST;
     280             : 
     281             :         // Create a record with the parameters
     282           0 :         Record selection = Record();
     283             : 
     284           0 :         selection.define("spw", spw);
     285           0 :         selection.define("scan", scan);
     286           0 :         selection.define("field", field);
     287           0 :         selection.define("antenna", antenna);
     288           0 :         selection.define("timerange", timerange);
     289           0 :         selection.define("correlation", correlation);
     290           0 :         selection.define("intent", intent);
     291           0 :         selection.define("feed", feed);
     292           0 :         selection.define("array", array);
     293           0 :         selection.define("uvrange", uvrange);
     294           0 :         selection.define("observation", observation);
     295             : 
     296             :         // Call the main selectData() method
     297           0 :         selectData(selection);
     298             : 
     299           0 :         return true;
     300             : 
     301           0 : }
     302             : 
     303             : 
     304             : // ---------------------------------------------------------------------
     305             : // AgentFlagger::parseAgentParameters
     306             : // Create a vector of agents and parameters
     307             : // Each input record contains data selection parameters
     308             : // and agent's specific parameters
     309             : // ---------------------------------------------------------------------
     310             : bool
     311           0 : AgentFlagger::parseAgentParameters(Record agent_params)
     312             : {
     313           0 :         LogIO os(LogOrigin("AgentFlagger", __FUNCTION__));
     314             : 
     315           0 :         if (! fdh_p){
     316           0 :                 os << LogIO::SEVERE << "There is no MS attached. Please run af.open first." << LogIO::POST;
     317           0 :                 return false;
     318             :         }
     319             : 
     320             :         // Default values for some parameters
     321           0 :         String mode = "";
     322           0 :         String agent_name = "";
     323           0 :         Bool apply = true;
     324           0 :         String datacolumn = "DATA";
     325             : 
     326             :         // create a temporary vector of agents
     327           0 :         std::vector<Record> listOfAgents;
     328             : 
     329             : 
     330           0 :         if(agent_params.empty()){
     331             :                 os << LogIO::SEVERE << "No agent's record has been provided."
     332           0 :                                 << LogIO::POST;
     333           0 :                 return false;
     334             :         }
     335             : 
     336             :         // Use the given Record of parameters
     337           0 :         agentParams_p = agent_params;
     338             : 
     339           0 :         if (! agentParams_p.isDefined("mode")) {
     340             :                 os << LogIO::WARN << "No mode has been provided"
     341           0 :                                 << LogIO::POST;
     342           0 :                 return false;
     343             :         }
     344             : 
     345             :         // Get mode
     346           0 :         agentParams_p.get("mode", mode);
     347             : 
     348             :         // Validate mode against known modes
     349           0 :         if (! isModeValid(mode)){
     350             :                 os << LogIO::WARN << "Mode "<< mode << " is not valid or doesn't exist"
     351           0 :                                 << LogIO::POST;
     352           0 :                 return false;
     353             :         }
     354             : 
     355             :     // Name for the logging output
     356           0 :     if (! agentParams_p.isDefined("agentname")){
     357           0 :         agent_name = mode;
     358           0 :         agent_name.capitalize();
     359           0 :         agentParams_p.define("agentname", agent_name);
     360             :     }
     361             : 
     362           0 :     agentParams_p.get("agentname", agent_name);
     363             : 
     364           0 :     os << LogIO::DEBUG1 << "Parsing parameters for agent: "<<mode<< LogIO::POST;
     365             : 
     366             :         // Validate datacolumn
     367           0 :         if (mode.compare("tfcrop") == 0 or mode.compare("clip") == 0 or mode.compare("rflag") == 0
     368           0 :                         or mode.compare("antint") == 0 or mode.compare("display") == 0){
     369             : 
     370           0 :                 if (agentParams_p.isDefined("datacolumn"))
     371           0 :                         agentParams_p.get("datacolumn", datacolumn);
     372             : 
     373           0 :                 os << LogIO::NORMAL3 << "Validating data column "<<datacolumn<<" based on input type"<< LogIO::POST;
     374             : 
     375           0 :                 if(!validateDataColumn(datacolumn)){
     376           0 :                         os << LogIO::WARN<< "Cannot parse agent parameters "<< LogIO::POST;
     377           0 :                         return false;
     378             :                 }
     379             : 
     380           0 :                 os << LogIO::DEBUG1 << "Will use data column "<< datacolumn <<  LogIO::POST;
     381           0 :                 agentParams_p.define("datacolumn", datacolumn);
     382             :         }
     383             : 
     384             :         // Enforce a default value for the apply parameter
     385           0 :         if (! agentParams_p.isDefined("apply")){
     386           0 :                 agentParams_p.define("apply", apply);
     387             :         }
     388             : 
     389             :         // If there is a tfcrop, extend or rflag agent in the list,
     390             :         // get the maximum value of ntime and the combinescans parameter
     391           0 :         if (mode.compare("tfcrop") == 0 or mode.compare("extend") == 0 or mode.compare("rflag") == 0) {
     392             :                 Double ntime;
     393           0 :                 if (agentParams_p.isDefined("ntime")){
     394           0 :                         agentParams_p.get("ntime", ntime);
     395           0 :                         getMax(ntime);
     396             :                 }
     397             : 
     398             :                 // Get the combinescans parameter. If any of them is true,
     399             :                 // it will be true for the whole list
     400           0 :                 Bool combine = false;
     401           0 :                 if (agentParams_p.isDefined("combinescans"))
     402           0 :                         agentParams_p.get("combinescans", combine);
     403             : 
     404           0 :                 combinescans_p = combinescans_p || combine;
     405             : 
     406             :                 os << LogIO::DEBUG2 << "max ntime="<<max_p<<" and combinescans="<<
     407           0 :                                 combinescans_p << LogIO::POST;
     408             : 
     409             :         }
     410             : 
     411             :         // Activate async i/o if tfcrop/clip/rflag is present
     412           0 :         if (mode.compare("tfcrop") == 0 or mode.compare("clip") == 0 or mode.compare("rflag") == 0)
     413             :         {
     414           0 :                 fdh_p->enableAsyncIO(true);
     415             :         }
     416             : 
     417             :         // Default for all modes
     418           0 :         String correlation = "";
     419             : 
     420             :         // Make correlation always uppercase
     421           0 :         if (agentParams_p.isDefined("correlation")) {
     422           0 :                 agentParams_p.get("correlation", correlation);
     423           0 :                 correlation.upcase();
     424           0 :                 agentParams_p.define("correlation", correlation);
     425             :         }
     426             : 
     427             : 
     428             :         // Create one agent for each polarization
     429           0 :         if (mode.compare("tfcrop") == 0) {
     430             : 
     431           0 :                 if (not agentParams_p.isDefined("correlation")) {
     432             :                         // Default for tfcrop
     433           0 :                         correlation = "ABS_ALL";
     434           0 :                         if (datacolumn.compare("FLOAT_DATA") == 0)
     435           0 :                             correlation = "REAL_ALL";
     436           0 :                         agentParams_p.define("correlation", correlation);
     437             :                 }
     438             :                 if (dbg){
     439             :                         cout << "mode="<<mode<<" correlation="<<correlation<<endl;
     440             :                 }
     441             : 
     442             :                 // Is the expression polarization an ALL?
     443           0 :                 if (isExpressionPolarizationAll(correlation)) {
     444             : 
     445             :                         // Get the complex unitary function (ABS, NORM, REAL, IMAG, ARG)
     446           0 :                         String function = getExpressionFunction(correlation);
     447             : 
     448             :                         // Get all the polarizations in the MS
     449           0 :                         std::vector<String> *allpol = fdh_p->corrProducts_p;
     450             : 
     451           0 :                         for (size_t i=0; i < allpol->size(); i++){
     452             :                                 // compose the full expression
     453           0 :                                 String func = function;
     454           0 :                                 String pol = allpol->at(i);
     455           0 :                                 String exp = func.append("_");
     456           0 :                                 exp = func.append(pol);
     457             : 
     458             :                                 // Save the record to a list of agents
     459           0 :                                 agentParams_p.define("correlation", exp);
     460           0 :                                 String name = agent_name;
     461           0 :                                 name = name.append("_");
     462           0 :                                 name = name.append(pol);
     463           0 :                                 agentParams_p.define("agentname", name);
     464           0 :                                 listOfAgents.push_back(agentParams_p);
     465           0 :                         }
     466           0 :                 }
     467             :         }
     468             : 
     469             :         // Check if extend agent should be added to the list later
     470           0 :         if (mode.compare("tfcrop") == 0 or mode.compare("rflag") == 0){
     471           0 :                 if (agentParams_p.isDefined("extendflags"))
     472           0 :                                 agentParams_p.get("extendflags", extendflags_p);
     473             :         }
     474             : 
     475           0 :         if (listOfAgents.size() > 0) {
     476             :                 // add the agent(s) to the list
     477           0 :                 for (size_t i=0; i < listOfAgents.size(); i++) {
     478           0 :                         agents_config_list_p.push_back(listOfAgents.at(i));
     479             :                 }
     480             :         }
     481             :         else {
     482           0 :                 agents_config_list_p.push_back(agentParams_p);
     483             :         }
     484             : 
     485             :         if (dbg){
     486             :                 for (size_t i=0; i < agents_config_list_p.size(); i++) {
     487             :                         ostringstream os;
     488             :                         agents_config_list_p.at(i).print(os);
     489             :                         String str(os.str());
     490             :                         cout << str << endl;
     491             :                 }
     492             :         }
     493             : 
     494             :         // Keep a copy of the vector of Agents parameters
     495           0 :         agents_config_list_copy_p = agents_config_list_p;
     496             : 
     497             :         // Parse the parameters of the extend agent
     498           0 :         if ((mode.compare("tfcrop") == 0 or mode.compare("rflag") == 0) and
     499           0 :                         extendflags_p==true){
     500             : 
     501             :                 os << LogIO::NORMAL << "Will extend the flags after " << mode <<
     502           0 :                                 "; extendflags=true" << LogIO::POST;
     503             : 
     504           0 :                 extendflags_p = false;
     505           0 :                 parseExtendParameters(
     506             :                                 "", // field
     507             :                                 "",   // spw
     508             :                                 "",   // array
     509             :                                 "",   // feed
     510             :                                 "",   // scan
     511             :                                 "",   // antenna
     512             :                                 "",   // uvrange
     513             :                                 "",   // timerange
     514             :                                 "",   // correlation
     515             :                                 "",   // intent
     516             :                                 "",   // observation
     517             :                                 max_p,  // ntime
     518           0 :                                 combinescans_p, // combinescans
     519             :                                 true,   // extendpols
     520             :                                 50.0,   // growtime
     521             :                                 80.0    // growfreq
     522             : //                              false,  // growaround
     523             : //                              false,  // flagneartime
     524             : //                              false,  // flagnearfreq
     525             : //                              true    // apply
     526             :                                 );
     527             :         }
     528             : 
     529           0 :         return true;
     530           0 : }
     531             : 
     532             : /*
     533             :  * Build a string with a list of agents, for logging purposes. Uses the names they have in
     534             :  * the mode parameter, for example display, rflag, summary, etc. rather than the more
     535             :  * internal names of the agent classes. When the list of agents is very long, a short
     536             :  * cut of the list is produced.
     537             :  *
     538             :  * @param agents list of agents (items as casacore records, with a "mode" field)
     539             :  * @return a comma separated list of agents
     540             :  */
     541           0 : std::string buildListAgentNames(const std::vector<Record> &agents) {
     542           0 :     const size_t MAX_LIST_PRINT = 10;
     543             : 
     544           0 :     std::string all;
     545           0 :     if (!agents.empty()) {
     546           0 :         auto elem = agents.cbegin();
     547           0 :         String mode;
     548           0 :         elem->get("mode", mode);
     549           0 :         all += mode;
     550           0 :         size_t count = 1;
     551             : 
     552           0 :         while (++elem != agents.cend() && ++count <= MAX_LIST_PRINT) {
     553           0 :             elem->get("mode", mode);
     554           0 :             all += ", " + mode;
     555             :         }
     556           0 :         if (agents.size() > MAX_LIST_PRINT) {
     557           0 :             all += ", ... (" + std::to_string(agents.size()-MAX_LIST_PRINT) +
     558           0 :                 " more, not shown)";
     559             :         }
     560           0 :     }
     561           0 :     return all;
     562           0 : }
     563             : 
     564             : /*
     565             :  * For a mode (agent) configuration check:
     566             :  * if using time or channel averaging in auto-flagging modes (clip, tfcrop, rflag),
     567             :  * the agents can only be used in combination with a subset of other agents. These
     568             :  * 'whitelisted' agents are: + display + extend + antint.
     569             :  * See CAS-12294 for discussions.
     570             :  *
     571             :  * Additionally, check that timeavg and channelavg are never set for
     572             :  * any of the non-autof-lagging methods. This is in principle never
     573             :  * possible via the task interface but the list mode parser is weaks
     574             :  * and accepts such misconfigurations.
     575             : 
     576             :  *
     577             :  * @param mode flagging mode, using flagdata naming convention
     578             :  * @param agent_rec record with the agent configuration
     579             :  * @param anyNotAvg non-empty name if any avg-disallowed agent is in the list
     580             :  *
     581             :  * @throws AipsError if there is any configuration error
     582             :  */
     583           0 : void AgentFlagger::checkAveragingConfig(const std::string &mode, const Record &agent_rec,
     584             :                                         const std::string &anyNotAvg) {
     585           0 :     Bool tavg = false;
     586           0 :     int exists = agent_rec.fieldNumber ("timeavg");
     587           0 :     if (exists >= 0) {
     588           0 :         agent_rec.get("timeavg", tavg);
     589             :     }
     590             : 
     591           0 :     Bool cavg = false;
     592           0 :     exists = agent_rec.fieldNumber ("channelavg");
     593           0 :     if (exists >= 0) {
     594           0 :         agent_rec.get("channelavg", cavg);
     595             :     }
     596             : 
     597           0 :     if ("clip" == mode or "rflag" == mode or "tfcrop" == mode) {
     598           0 :         if ((tavg or cavg) and not anyNotAvg.empty()) {
     599           0 :             ostringstream msg;
     600             :             msg << "Cannot use " << mode << " mode with timeavg=True or channelavg=True "
     601           0 :                 "and additional modes other than extend, display, and antint. timeavg="
     602           0 :                 << tavg << ", channelavg=" << cavg <<  ", and the following mode has been "
     603           0 :                 "set up: " << anyNotAvg + ". Refusing to accept this configuration.";
     604           0 :             throw AipsError(msg);
     605           0 :         }
     606             :     } else {
     607           0 :         if ((tavg or cavg)) {
     608           0 :             ostringstream msg;
     609           0 :             msg << "Cannot use timeavg or channelavg in mode " << mode << ". timeavg="
     610           0 :                 << tavg << ", channelavg=" << cavg <<  ". These averaging "
     611             :                 "options are only allowed for auto-flagging methods. Refusing this "
     612           0 :                 "configuration.";
     613           0 :             throw AipsError(msg);
     614           0 :         }
     615             :     }
     616           0 : }
     617             : 
     618             : /*
     619             :  * Check: the auto-flagging agents (clip, tfcrop, rflag) can only be combined with some
     620             :  * other selected agents: display + extend + antint.
     621             :  * See CAS-12294 for discussions.
     622             :  *
     623             :  * @param configs list of agent configurations
     624             :  *
     625             :  * @throws AipsError if there is any configuration error
     626             :  */
     627           0 : std::string AgentFlagger::searchAnyAgentsNotAvg(const std::vector<Record> &configs)
     628             : {
     629           0 :     const std::vector<std::string> whitelist = { "clip", "rflag", "tfcrop", "extend", "display", "antint" };
     630             : 
     631           0 :     for (const auto &agent : configs) {
     632           0 :         String recname;
     633           0 :         agent.get("mode", recname);
     634           0 :         std::string name = recname;
     635           0 :         const auto &found = std::find(whitelist.cbegin(), whitelist.cend(), name);
     636           0 :         if (found == whitelist.cend()) {
     637           0 :             return name;
     638             :         }
     639           0 :     }
     640             : 
     641           0 :     return "";
     642           0 : }
     643             : 
     644             : // ---------------------------------------------------------------------
     645             : // AgentFlagger::initAgents
     646             : // Initialize the Agents
     647             : // Call parseAgentParameters and selectData first
     648             : // ---------------------------------------------------------------------
     649             : bool
     650           0 : AgentFlagger::initAgents()
     651             : {
     652             : 
     653           0 :         LogIO os(LogOrigin("AgentFlagger",__FUNCTION__));
     654             : 
     655           0 :         if (! fdh_p){
     656           0 :                 os << LogIO::SEVERE << "There is no MS attached. Please run af.open first." << LogIO::POST;
     657           0 :                 return false;
     658             :         }
     659             : 
     660           0 :         if (dataselection_p.empty()){
     661           0 :                 os << LogIO::SEVERE << "There is no MS Selection available." << LogIO::POST;
     662           0 :                 return false;
     663             :         }
     664             : 
     665           0 :         if (agents_config_list_p.empty()){
     666           0 :                 return false;
     667             :         }
     668             : 
     669             : 
     670             :         os << LogIO::NORMAL << "There are initially "<< agents_config_list_p.size()<<
     671             :             " agents in the list. Agents: "
     672           0 :            << buildListAgentNames(agents_config_list_p) << LogIO::POST;
     673             : 
     674             : 
     675             :         // Check once here, to re-use then with every agent in the list
     676           0 :         const auto &anyAgentNotAvg = searchAnyAgentsNotAvg(agents_config_list_p);
     677             : 
     678           0 :         size_t list_size = agents_config_list_p.size();
     679             : 
     680             :         // Send the logging of the re-applying agents to the debug
     681             :         // as we are only interested in seeing the unapply action (flagcmd)
     682           0 :         Bool retstate = true;
     683             :         // Just to log this info
     684           0 :         std::vector<Record> agents_config_list_filtered;
     685             :         // To set some parameters only once
     686           0 :         bool itersetDone = false;
     687           0 :         bool timesetDone = false;
     688             :         // Loop through the vector of agents
     689           0 :         for (size_t i=0; i < list_size; i++) {
     690             : 
     691             :                 // Get agent record
     692           0 :                 Record agent_rec = agents_config_list_p[i];
     693             :                 if (dbg){
     694             :                         os<< LogIO::NORMAL<< "Record["<<i<<"].nfields()="<<agent_rec.nfields()<<LogIO::POST;
     695             :                         ostringstream os;
     696             :                         agent_rec.print(os);
     697             :                         String str(os.str());
     698             :                         cout << str << endl;
     699             : 
     700             :                 }
     701             : 
     702             :                 // Get the mode
     703           0 :                 String mode;
     704           0 :                 agent_rec.get("mode", mode);
     705             : 
     706             :         /*
     707             :          * Special constraints for some agents
     708             :          */
     709             : 
     710             :         // constraints that will produce exceptions if not met
     711           0 :         checkAveragingConfig(mode, agent_rec, anyAgentNotAvg);
     712             : 
     713             :         // If quack mode with quackincrement = true, skip it
     714           0 :         if (mode.compare("quack") == 0 and i > 0 and list_size > 1){
     715           0 :                 Bool quackincrement = false;
     716           0 :                 int exists = agent_rec.fieldNumber ("quackincrement");
     717           0 :                 if (exists >= 0) agent_rec.get("quackincrement", quackincrement);
     718             : 
     719           0 :                 if (quackincrement){
     720           0 :                     os << LogIO::WARN << "Cannot have quackincrement=True in list mode. Agent quack will be ignored!" << LogIO::POST;
     721           0 :                     continue;
     722             :                 }
     723             :         }
     724             : 
     725             :                 // Set the new time interval only once
     726           0 :                 if (!timesetDone and (mode.compare("tfcrop") == 0 or mode.compare("extend") == 0 or
     727           0 :                                 mode.compare("rflag") == 0)) {
     728           0 :                         fdh_p->setTimeInterval(max_p);
     729           0 :                         timesetDone = true;
     730             :                 }
     731             : 
     732             :                 // Change the new iteration approach only once
     733           0 :                 if (!itersetDone and (mode.compare("tfcrop") == 0 or mode.compare("extend") == 0
     734           0 :                                 or mode.compare("rflag") == 0 or mode.compare("display") == 0)) {
     735           0 :                         if (combinescans_p)
     736           0 :                                 fdh_p->setIterationApproach(FlagDataHandler::COMBINE_SCANS_MAP_ANTENNA_PAIRS_ONLY);
     737             :                         else
     738           0 :                                 fdh_p->setIterationApproach(FlagDataHandler::COMPLETE_SCAN_MAP_ANTENNA_PAIRS_ONLY);
     739             : 
     740           0 :                         itersetDone = true;
     741             :                 }
     742             : 
     743             :                 // Agent's name
     744           0 :                 String agent_name;
     745           0 :                 agent_rec.get("agentname",agent_name);
     746             : 
     747           0 :                 FlagAgentBase *fa = 0;
     748             : 
     749             :                 try
     750             :                 {
     751             :                         // CAS-3943 (flagdata seg-faults when non-existent data column is to be read)
     752           0 :                         Bool createAgent = true;
     753           0 :                         if (((mode.compare("tfcrop") == 0 or mode.compare("rflag") == 0
     754           0 :                                         or mode.compare("clip") == 0 or mode.compare("display") == 0 or
     755           0 :                               mode.compare("antint") == 0))
     756           0 :                                         and (agent_rec.fieldNumber ("datacolumn") >= 0))
     757             :                         {
     758           0 :                                 String datacolumn;
     759           0 :                                 agent_rec.get("datacolumn", datacolumn);
     760           0 :                                 datacolumn.upcase();
     761             : 
     762           0 :                                 if ((datacolumn.compare("CORRECTED") == 0) or (datacolumn.compare("RESIDUAL") == 0))
     763             :                                 {
     764           0 :                                         createAgent = fdh_p->checkIfColumnExists(MS::columnName(MS::CORRECTED_DATA));
     765           0 :                                         if (!createAgent)
     766             :                                         {
     767           0 :                                                 os << LogIO::WARN << "Agent " << agent_name << " cannot be created, necessary CORRECTED_DATA column is not available" << LogIO::POST;
     768           0 :                                                 os << LogIO::WARN << "If wishing to flag residuals, use datacolumn=\'RESIDUAL_DATA\', which will calculate DATA-MODEL" << LogIO::POST;
     769             :                                         }
     770             :                                 }
     771           0 :                         }
     772             : 
     773             :                         // Create this agent if the necessary columns are available
     774           0 :                         if (createAgent)
     775             :                         {
     776           0 :                                 FlagAgentBase *tfa = FlagAgentBase::create(fdh_p, agent_rec);
     777           0 :                                 fa = tfa;
     778             :                         }
     779             :                 }
     780           0 :                 catch(AipsError x)
     781             :                 {
     782           0 :                         fa = 0;
     783             :                         // Send out a useful message, and stop adding agents to the list.
     784             :                         // All valid agents before the problematic one, will remain in agents_list_p
     785             :                         // A subsequent call to initAgents() will add to the list.
     786           0 :                         ostringstream oss;
     787           0 :                         agent_rec.print(oss);
     788           0 :                         String recstr(oss.str());
     789           0 :                         while(recstr.contains('\n'))
     790             :                         {
     791           0 :                                 recstr = recstr.replace(recstr.index('\n'),1,", ");
     792             :                         }
     793             : 
     794             :                         os << LogIO::WARN << "Cannot create agent "<< agent_name << ": "
     795           0 :                                         << x.getMesg() << LogIO::POST;
     796           0 :                         os << LogIO::DEBUG1<< "Input parameters : " << recstr << LogIO::POST;
     797           0 :                         continue;
     798             : 
     799           0 :                 }
     800             : 
     801           0 :                 if (fa == 0){
     802           0 :                         os << LogIO::WARN << "Agent "<< agent_name<< " is NULL. Skipping it."<<LogIO::POST;
     803           0 :                         continue;
     804             :                 }
     805             : 
     806             : /*
     807             :                 // Get the last summary agent to list the results back to the task
     808             :                 if (mode.compare("summary") == 0) {
     809             :                         summaryAgent_p = (FlagAgentSummary *) fa;
     810             :                 }
     811             : */
     812             : 
     813             :                 // Get the display agent.
     814           0 :                 if (mode.compare("display") == 0){
     815           0 :                         displayAgent_p = (FlagAgentDisplay *) fa;
     816             :                 }
     817             : 
     818             :                 // Add the agent to the FlagAgentList
     819           0 :                 agents_list_p.push_back(fa);
     820           0 :                 agents_config_list_filtered.push_back(agent_rec);
     821           0 :         }
     822             : 
     823             :         os << LogIO::NORMAL << "There are " << agents_list_p.size()
     824             :            << " valid agents in the list. Agents: "
     825           0 :            << buildListAgentNames(agents_config_list_filtered) << LogIO::POST;
     826             : 
     827             :         // Clear the list so that this method cannot be called twice
     828           0 :         agents_config_list_p.clear();
     829             : 
     830           0 :         if (agents_list_p.size() < 1)
     831           0 :                 retstate = false;
     832             : 
     833           0 :         return retstate;
     834           0 : }
     835             : 
     836             : 
     837             : // ---------------------------------------------------------------------
     838             : // AgentFlagger::run
     839             : // Run the agents
     840             : // It assumes that initAgents has been called first
     841             : // ---------------------------------------------------------------------
     842             : Record
     843           0 : AgentFlagger::run(Bool writeflags, Bool sequential)
     844             : {
     845             : 
     846           0 :         LogIO os(LogOrigin("AgentFlagger", __FUNCTION__));
     847             : 
     848           0 :         if (! fdh_p){
     849           0 :                 os << LogIO::SEVERE << "There is no MS attached. Please run af.open first." << LogIO::POST;
     850           0 :                 return Record();
     851             :         }
     852             : 
     853           0 :         if (agents_list_p.empty()) {
     854           0 :                 os << LogIO::SEVERE << "There is no agent to run in list"<< LogIO::POST;
     855           0 :                 return Record();
     856             :         }
     857             : 
     858             : 
     859             :         // Use the maximum ntime of the list
     860           0 :         os << LogIO::DEBUG2 << "ntime for all agents will be "<< max_p << LogIO::POST;
     861           0 :         os << LogIO::DEBUG2 << "combinescans for all agents will be "<< combinescans_p << LogIO::POST;
     862             : 
     863             :         // Report to return
     864           0 :         FlagReport combinedReport;
     865             : 
     866             : 
     867             :         // Generate the iterators
     868             :         // It will iterate through the data to evaluate the necessary memory
     869             :         // and get the START and STOP values of the scans for the quack agent
     870           0 :         fdh_p->generateIterator();
     871             : 
     872           0 :         agents_list_p.start();
     873             :         os << LogIO::DEBUGGING << "Generated iterators. Start loop over chunks / agents. "
     874           0 :             "Size of agents list is " << agents_list_p.size() << LogIO::POST;
     875             : 
     876             :         // iterate over chunks
     877           0 :         while (fdh_p->nextChunk())
     878             :         {
     879             :                 // iterate over visBuffers
     880           0 :                 while (fdh_p->nextBuffer())
     881             :                 {
     882             : 
     883             :                         // Apply or unapply the flags, in sequential or in parallel.
     884             :                         // By default it is set to true, which will preserve the order
     885             :                         // in which the agents are added to the list.
     886           0 :                         agents_list_p.apply(sequential);
     887             : 
     888             :                         // Flush flags to MS
     889           0 :                         if (writeflags) {
     890           0 :                                 fdh_p->flushFlags();
     891             :                         }
     892             :                 }
     893             : 
     894             :                 // Print the chunk summary stats
     895           0 :                 if (fdh_p->summarySignal())
     896             :                 {
     897           0 :                         agents_list_p.chunkSummary();
     898           0 :                         fdh_p->progressCounts_p = 0;
     899             :                 }
     900             :         }
     901             : 
     902             :         // Print the MS summary stats
     903           0 :         agents_list_p.tableSummary();
     904           0 :         if (writeflags)
     905           0 :                 os << LogIO::NORMAL << "=> " << "Writing flags to the MS" << LogIO::POST;
     906             : 
     907           0 :         agents_list_p.terminate();
     908           0 :         agents_list_p.join();
     909             : 
     910             :         // Gather the display reports from all agents
     911           0 :         combinedReport = agents_list_p.gatherReports();
     912             : 
     913             :         // Send reports to display agent
     914           0 :         if (displayAgent_p)
     915           0 :                 displayAgent_p->displayReports(combinedReport);
     916             : 
     917           0 :         agents_list_p.clear();
     918             : 
     919           0 :         return combinedReport;
     920           0 : }
     921             : 
     922             : // ---------------------------------------------------------------------
     923             : // AgentFlagger::isExpressionPolarizationAll
     924             : // Returns true if expression contains a polarization ALL
     925             : //
     926             : // ---------------------------------------------------------------------
     927             : bool
     928           0 : AgentFlagger::isExpressionPolarizationAll(String correlation)
     929             : {
     930             : 
     931           0 :         if (correlation.find("ALL") == string::npos){
     932           0 :                 return false;
     933             :         }
     934             : 
     935           0 :         return true;
     936             : }
     937             : 
     938             : // ---------------------------------------------------------------------
     939             : // AgentFlagger::getExpressionFunction
     940             : // Get the unitary function of a polarization expression
     941             : // returns a String with the function name
     942             : //
     943             : // ---------------------------------------------------------------------
     944             : String
     945           0 : AgentFlagger::getExpressionFunction(String expression)
     946             : {
     947             : 
     948           0 :         String func;
     949             : 
     950             :         // Parse complex unitary function
     951           0 :         if (expression.find("REAL") != string::npos)
     952             :         {
     953           0 :                 func = "REAL";
     954             :         }
     955           0 :         else if (expression.find("IMAG") != string::npos)
     956             :         {
     957           0 :                 func = "IMAG";
     958             :         }
     959           0 :         else if (expression.find("ARG") != string::npos)
     960             :         {
     961           0 :                 func = "ARG";
     962             :         }
     963           0 :         else if (expression.find("ABS") != string::npos)
     964             :         {
     965           0 :                 func = "ABS";
     966             :         }
     967           0 :         else if (expression.find("NORM") != string::npos)
     968             :         {
     969           0 :                 func = "NORM";
     970             :         }
     971             :         else
     972             :         {
     973           0 :                 return "";
     974             :         }
     975             : 
     976           0 :         return func;
     977           0 : }
     978             : 
     979             : // ---------------------------------------------------------------------
     980             : // AgentFlagger::getMax
     981             : // Get the maximum between two values and
     982             : // assign it to the max_p class member.
     983             : // ---------------------------------------------------------------------
     984             : void
     985           0 : AgentFlagger::getMax(Double value)
     986             : {
     987           0 :         if (value > max_p)
     988           0 :                 max_p = value;
     989             : 
     990           0 :         return;
     991             : 
     992             : }
     993             : 
     994             : 
     995             : // ---------------------------------------------------------------------
     996             : // AgentFlagger::getFlagVersionList
     997             : // Get the flag versions list from the file FLAG_VERSION_LIST in the
     998             : // MS directory
     999             : //
    1000             : // ---------------------------------------------------------------------
    1001             : bool
    1002           0 : AgentFlagger::getFlagVersionList(Vector<String> &verlist)
    1003             : {
    1004             : 
    1005           0 :         LogIO os(LogOrigin("AgentFlagger", __FUNCTION__, WHERE));
    1006             : 
    1007             :         try
    1008             :         {
    1009             : 
    1010           0 :                 if (! fdh_p){
    1011           0 :                         os << LogIO::SEVERE << "There is no MS attached. Please run af.open first." << LogIO::POST;
    1012           0 :                         return false;
    1013             :                 }
    1014             : 
    1015           0 :                 verlist.resize(0);
    1016             :                 Int num;
    1017             : 
    1018           0 :                 FlagVersion fv(fdh_p->getTableName(),"FLAG","FLAG_ROW");
    1019           0 :                 Vector<String> vlist = fv.getVersionList();
    1020             : 
    1021           0 :                 num = verlist.nelements();
    1022           0 :                 verlist.resize( num + vlist.nelements() + 1, true );
    1023           0 :                 verlist[num] = String("\nMS : ") + fdh_p->getTableName() + String("\n");
    1024             : 
    1025           0 :                 for(Int j=0; j<(Int)vlist.nelements(); j++)
    1026           0 :                         verlist[num+j+1] = vlist[j];
    1027           0 :         }
    1028           0 :         catch (AipsError x)
    1029             :         {
    1030           0 :                 os << LogIO::SEVERE << "Could not get Flag Version List : " << x.getMesg() << LogIO::POST;
    1031           0 :                 return false;
    1032           0 :         }
    1033             : 
    1034           0 :         return true;
    1035           0 : }
    1036             : 
    1037             : 
    1038             : // ---------------------------------------------------------------------
    1039             : // AgentFlagger::printFlagSelection
    1040             : // Print the flag versions list
    1041             : //
    1042             : // ---------------------------------------------------------------------
    1043             : bool
    1044           0 : AgentFlagger::printFlagSelections()
    1045             : {
    1046             : 
    1047           0 :         LogIO os(LogOrigin("AgentFlagger", __FUNCTION__, WHERE));
    1048             : 
    1049             :         // Use the copy of the agent records list because the original
    1050             :         // was deallocated in the init() method.
    1051           0 :         if (! agents_config_list_copy_p.empty())
    1052             :         {
    1053           0 :                 os << "Current list of agents : "  << LogIO::POST;
    1054             : 
    1055             :                 // TODO: loop through list
    1056             :                 // Duplicate the vector... ???
    1057           0 :                 for (size_t i=0; i < agents_config_list_copy_p.size(); i++) {
    1058           0 :                         ostringstream out;
    1059           0 :                         Record agent_rec;
    1060           0 :                         agent_rec = agents_config_list_copy_p.at(i);
    1061           0 :                         agent_rec.print(out);
    1062           0 :                         os << out.str() << LogIO::POST;
    1063           0 :                 }
    1064             :                 if (dbg)
    1065             :                         cout << "Size of original list " << agents_config_list_copy_p.size() << endl;
    1066             : 
    1067             :         }
    1068           0 :         else os << " No current agents " << LogIO::POST;
    1069             : 
    1070           0 :         return true;
    1071           0 : }
    1072             : 
    1073             : 
    1074             : // ---------------------------------------------------------------------
    1075             : // AgentFlagger::saveFlagVersion
    1076             : // Save the flag version
    1077             : //
    1078             : // ---------------------------------------------------------------------
    1079             : bool
    1080           0 : AgentFlagger::saveFlagVersion(String versionname, String comment, String merge)
    1081             : {
    1082           0 :         LogIO os(LogOrigin("AgentFlagger", __FUNCTION__, WHERE));
    1083             : 
    1084           0 :         if (! fdh_p){
    1085           0 :                 os << LogIO::SEVERE << "There is no MS attached. Please run af.open first." << LogIO::POST;
    1086           0 :                 return false;
    1087             :         }
    1088             : 
    1089           0 :         FlagVersion fv(fdh_p->getTableName(),"FLAG","FLAG_ROW");
    1090           0 :         fv.saveFlagVersion(versionname, comment, merge);
    1091             : 
    1092           0 :         return true;
    1093           0 : }
    1094             : 
    1095             : 
    1096             : // ---------------------------------------------------------------------
    1097             : // AgentFlagger::restoreFlagVersion
    1098             : // Restore the flag version
    1099             : //
    1100             : // ---------------------------------------------------------------------
    1101             : bool
    1102           0 : AgentFlagger::restoreFlagVersion(Vector<String> versionname, String merge)
    1103             : {
    1104           0 :         LogIO os(LogOrigin("AgentFlagger", __FUNCTION__, WHERE));
    1105             : 
    1106           0 :         if (! fdh_p){
    1107           0 :                 os << LogIO::SEVERE << "There is no MS attached. Please run af.open first." << LogIO::POST;
    1108           0 :                 return false;
    1109             :         }
    1110             : 
    1111             :         try
    1112             :         {
    1113           0 :                 FlagVersion fv(fdh_p->getTableName(),"FLAG","FLAG_ROW");
    1114           0 :                 for(Int j=0;j<(Int)versionname.nelements();j++)
    1115           0 :                         fv.restoreFlagVersion(versionname[j], merge);
    1116           0 :         }
    1117           0 :         catch (AipsError x)
    1118             :         {
    1119           0 :                 os << LogIO::SEVERE << "Could not restore Flag Version : " << x.getMesg() << LogIO::POST;
    1120           0 :                 throw AipsError(x);
    1121             : //              return false;
    1122           0 :         }
    1123           0 :         return true;
    1124           0 : }
    1125             : 
    1126             : // ---------------------------------------------------------------------
    1127             : // AgentFlagger::deleteFlagVersion
    1128             : // Delete the flag version
    1129             : //
    1130             : // ---------------------------------------------------------------------
    1131             : bool
    1132           0 : AgentFlagger::deleteFlagVersion(Vector<String> versionname)
    1133             : {
    1134             : 
    1135           0 :         LogIO os(LogOrigin("AgentFlagger", __FUNCTION__, WHERE));
    1136             : 
    1137           0 :         if (! fdh_p){
    1138           0 :                 os << LogIO::SEVERE << "There is no MS attached. Please run af.open first." << LogIO::POST;
    1139           0 :                 return false;
    1140             :         }
    1141             : 
    1142             :         try
    1143             :         {
    1144           0 :                 FlagVersion fv(fdh_p->getTableName(),"FLAG","FLAG_ROW");
    1145           0 :                 for(Int j=0;j<(Int)versionname.nelements();j++)
    1146           0 :                         fv.deleteFlagVersion(versionname[j]);
    1147           0 :         }
    1148           0 :         catch (AipsError x)
    1149             :         {
    1150           0 :                 os << LogIO::SEVERE << "Could not delete Flag Version : " << x.getMesg() << LogIO::POST;
    1151           0 :                 return false;
    1152           0 :         }
    1153           0 :         return true;
    1154           0 : }
    1155             : 
    1156             : // ---------------------------------------------------------------------
    1157             : // AgentFlagger::isModeValid
    1158             : // Check if mode is valid.
    1159             : // Return false if not in the list
    1160             : // ---------------------------------------------------------------------
    1161             : bool
    1162           0 : AgentFlagger::isModeValid(String mode)
    1163             : {
    1164             :         bool ret;
    1165             : 
    1166             :         // The validation depends on the type of input
    1167           0 :         if (isMS_p) {
    1168           0 :                 if (mode.compare("manual") == 0 or mode.compare("clip") == 0 or
    1169           0 :                                 mode.compare("quack") == 0 or mode.compare("shadow") == 0 or
    1170           0 :                                 mode.compare("elevation") == 0 or 
    1171           0 :                                 mode.compare("tfcrop") == 0 or 
    1172           0 :                                 mode.compare("extend") == 0 or mode.compare("rflag") == 0 or
    1173           0 :                                 mode.compare("antint") == 0 or 
    1174           0 :                                 mode.compare("unflag") == 0 or mode.compare("summary") == 0
    1175           0 :                                 or mode.compare("display") == 0) {
    1176             : 
    1177           0 :                         ret = true;
    1178             :                 }
    1179             :                 else
    1180           0 :                         ret = false;
    1181             :         }
    1182             :         else {
    1183           0 :                 if (mode.compare("manual") == 0 or mode.compare("clip") == 0 or
    1184           0 :                                 mode.compare("quack") == 0 or mode.compare("tfcrop") == 0 or
    1185           0 :                                 mode.compare("extend") == 0 or mode.compare("rflag") == 0 or
    1186           0 :                                 mode.compare("antint") == 0 or 
    1187           0 :                                 mode.compare("unflag") == 0 or mode.compare("summary") == 0
    1188           0 :                                 or mode.compare("display") == 0) {
    1189             : 
    1190           0 :                         ret = true;
    1191             :                 }
    1192             :                 else
    1193           0 :                         ret = false;
    1194             : 
    1195             :         }
    1196             : 
    1197           0 :         return ret;
    1198             : }
    1199             : 
    1200             : 
    1201             : Bool
    1202           0 : AgentFlagger::validateDataColumn(String datacol)
    1203             : {
    1204             : 
    1205           0 :     String datacolumn = "";
    1206           0 :     Bool ret = false;
    1207           0 :     datacol.upcase();
    1208             : 
    1209           0 :     LogIO os(LogOrigin("AgentFlagger", __FUNCTION__));
    1210             : 
    1211             :     // The validation depends on the type of input
    1212           0 :     if (isMS_p) {
    1213           0 :         if (datacol.compare("DATA") == 0)
    1214           0 :             datacolumn = "DATA";
    1215           0 :         else if(datacol.compare("CORRECTED") == 0)
    1216           0 :             datacolumn = "CORRECTED_DATA";
    1217           0 :         else if(datacol.compare("MODEL") == 0)
    1218           0 :             datacolumn = "MODEL_DATA";
    1219           0 :          else if(datacol.compare("FLOAT_DATA") == 0)
    1220           0 :             datacolumn = "FLOAT_DATA";
    1221           0 :         else if(datacol.compare("WEIGHT_SPECTRUM") == 0)
    1222           0 :             datacolumn = "WEIGHT_SPECTRUM";
    1223           0 :         else if(datacol.compare("WEIGHT") == 0)
    1224           0 :             datacolumn = "WEIGHT";
    1225           0 :         else if(datacol.compare("RESIDUAL") == 0)
    1226           0 :              datacolumn = "CORRECTED_DATA";
    1227           0 :          else if(datacol.compare("RESIDUAL_DATA") == 0)
    1228           0 :              datacolumn = "DATA";
    1229             :        else
    1230           0 :             datacolumn = "";
    1231             :     }
    1232             :     else {
    1233             :         // cal tables
    1234           0 :         if (datacol.compare("FPARAM") == 0 or (datacol.compare("CPARAM") == 0) or
    1235           0 :                 (datacol.compare("SNR") == 0))
    1236           0 :             datacolumn = datacol;
    1237             :     }
    1238             : 
    1239             :     // Check if main tables exist
    1240           0 :     if (fdh_p->checkIfColumnExists(datacolumn)) {
    1241           0 :             ret = true;
    1242             :     }
    1243             :     else {
    1244           0 :         os << LogIO::WARN << "Data column "<< datacolumn << " does not exist in input data"  << LogIO::POST;
    1245             :     }
    1246             : 
    1247             :     // Check if other columns were requested also
    1248             :     // RESIDUAL is calculated later from CORRECTED-MODEL
    1249             :     // RESIDUAL_DATA is calculated later from DATA-MODEL
    1250             : 
    1251           0 :     if (datacol.compare("RESIDUAL") == 0 or datacol.compare("RESIDUAL_DATA")==0){
    1252           0 :         ret = false;
    1253             :         // check if  MODEL _DATA or virtual MODEL_DATA exist
    1254           0 :         if (fdh_p->checkIfColumnExists("MODEL_DATA") or fdh_p->checkIfSourceModelColumnExists()){
    1255           0 :                 ret = true;
    1256             :         }
    1257             :         else {
    1258           0 :                 os << LogIO::WARN << "Data column MODEL_DATA or virtual MODEL_DATA  does not exist in input data" << LogIO::POST;
    1259             :         }
    1260             : 
    1261             :     }
    1262             : 
    1263           0 :     return ret;
    1264           0 : }
    1265             : 
    1266             : 
    1267             : // ---------------------------------------------------------------------
    1268             : // AgentFlagger::parseManualParameters
    1269             : // Parse data selection parameters and specific manual parameters
    1270             : //
    1271             : // ---------------------------------------------------------------------
    1272             : bool
    1273           0 : AgentFlagger::parseManualParameters(String field, String spw, String array,
    1274             :                 String feed, String scan, String antenna,
    1275             :                 String uvrange,  String timerange, String correlation,
    1276             :                 String intent, String observation, Bool autocorr,
    1277             :                 Bool apply)
    1278             : {
    1279             : 
    1280           0 :         LogIO os(LogOrigin("AgentFlagger", __FUNCTION__));
    1281             : 
    1282             :         // Default values for some parameters
    1283           0 :         String mode = "manual";
    1284           0 :         String agent_name = "Manual";
    1285             : 
    1286             :         // Create a record with the parameters
    1287           0 :         Record agent_record = Record();
    1288             : 
    1289           0 :         agent_record.define("mode", mode);
    1290           0 :         agent_record.define("spw", spw);
    1291           0 :         agent_record.define("scan", scan);
    1292           0 :         agent_record.define("field", field);
    1293           0 :         agent_record.define("antenna", antenna);
    1294           0 :         agent_record.define("timerange", timerange);
    1295           0 :         agent_record.define("correlation", correlation);
    1296           0 :         agent_record.define("intent", intent);
    1297           0 :         agent_record.define("feed", feed);
    1298           0 :         agent_record.define("array", array);
    1299           0 :         agent_record.define("uvrange", uvrange);
    1300           0 :         agent_record.define("observation", observation);
    1301           0 :         agent_record.define("apply", apply);
    1302           0 :         agent_record.define("agentname", agent_name);
    1303             : 
    1304           0 :         agent_record.define("autocorr", autocorr);
    1305             : 
    1306             :         // Call the main method
    1307           0 :         parseAgentParameters(agent_record);
    1308             : 
    1309           0 :         return true;
    1310           0 : }
    1311             : 
    1312             : 
    1313             : // ---------------------------------------------------------------------
    1314             : // AgentFlagger::parseClipParameters
    1315             : // Parse data selection parameters and specific clip parameters
    1316             : //
    1317             : // ---------------------------------------------------------------------
    1318             : bool
    1319           0 : AgentFlagger::parseClipParameters(String field, String spw, String array, String feed, String scan,
    1320             :                 String antenna, String uvrange, String timerange, String correlation,
    1321             :                 String intent, String observation, String datacolumn,
    1322             :                 Vector<Double> clipminmax, Bool clipoutside, Bool channelavg, casac::variant chanbin, Bool timeavg,
    1323             :                 String timebin, Bool clipzeros, Bool apply)
    1324             : {
    1325             : 
    1326           0 :         LogIO os(LogOrigin("AgentFlagger", __FUNCTION__));
    1327             : 
    1328             :         // Default values for some parameters
    1329           0 :         String mode = "clip";
    1330           0 :         String agent_name = "Clip";
    1331             : 
    1332             :         // Create a record with the parameters
    1333           0 :         Record agent_record = Record();
    1334             : 
    1335           0 :         agent_record.define("mode", mode);
    1336           0 :         agent_record.define("spw", spw);
    1337           0 :         agent_record.define("scan", scan);
    1338           0 :         agent_record.define("field", field);
    1339           0 :         agent_record.define("antenna", antenna);
    1340           0 :         agent_record.define("timerange", timerange);
    1341           0 :         agent_record.define("correlation", correlation);
    1342           0 :         agent_record.define("intent", intent);
    1343           0 :         agent_record.define("feed", feed);
    1344           0 :         agent_record.define("array", array);
    1345           0 :         agent_record.define("uvrange", uvrange);
    1346           0 :         agent_record.define("observation", observation);
    1347           0 :         agent_record.define("apply", apply);
    1348           0 :         agent_record.define("agentname", agent_name);
    1349             : 
    1350           0 :         agent_record.define("datacolumn", datacolumn);
    1351           0 :         agent_record.define("clipminmax", clipminmax);
    1352           0 :         agent_record.define("clipoutside", clipoutside);
    1353           0 :         agent_record.define("channelavg", channelavg);
    1354             : 
    1355           0 :         if (chanbin.type() == casac::variant::INT)
    1356             :         {
    1357             :                 /*** need range check ***/
    1358           0 :                 agent_record.define("chanbin", (int) chanbin.toInt());
    1359             :         }
    1360           0 :         else if (chanbin.type() == casac::variant::INTVEC)
    1361             :         {
    1362             :                 /*** need range check ***/
    1363           0 :                 auto cb = chanbin.toIntVec( );
    1364           0 :         std::vector<int> vec;
    1365           0 :         std::for_each( cb.begin( ), cb.end( ), [&](long x){vec.push_back((int)x);} );
    1366           0 :                 agent_record.define("chanbin", Array<Int>(vec));
    1367           0 :         }
    1368             : 
    1369           0 :     agent_record.define("timeavg", timeavg);
    1370           0 :     agent_record.define("timebin", timebin);
    1371           0 :         agent_record.define("clipzeros", clipzeros);
    1372             : 
    1373             : 
    1374             :         // Call the main method
    1375           0 :         parseAgentParameters(agent_record);
    1376             : 
    1377           0 :         return true;
    1378             : 
    1379           0 : }
    1380             : 
    1381             : // ---------------------------------------------------------------------
    1382             : // AgentFlagger::parseQuackParameters
    1383             : // Parse data selection parameters and specific quack parameters
    1384             : //
    1385             : // ---------------------------------------------------------------------
    1386             : bool
    1387           0 : AgentFlagger::parseQuackParameters(String field, String spw, String array, String feed, String scan,
    1388             :                 String antenna, String uvrange, String timerange, String correlation,
    1389             :                 String intent, String observation, String quackmode, Double quackinterval,
    1390             :                 Bool quackincrement, Bool apply)
    1391             : {
    1392             : 
    1393           0 :         LogIO os(LogOrigin("AgentFlagger", __FUNCTION__));
    1394             : 
    1395             :         // Default values for some parameters
    1396           0 :         String mode = "quack";
    1397           0 :         String agent_name = "Quack";
    1398             : 
    1399             :         // Create a record with the parameters
    1400           0 :         Record agent_record = Record();
    1401             : 
    1402           0 :         agent_record.define("mode", mode);
    1403           0 :         agent_record.define("spw", spw);
    1404           0 :         agent_record.define("scan", scan);
    1405           0 :         agent_record.define("field", field);
    1406           0 :         agent_record.define("antenna", antenna);
    1407           0 :         agent_record.define("timerange", timerange);
    1408           0 :         agent_record.define("correlation", correlation);
    1409           0 :         agent_record.define("intent", intent);
    1410           0 :         agent_record.define("feed", feed);
    1411           0 :         agent_record.define("array", array);
    1412           0 :         agent_record.define("uvrange", uvrange);
    1413           0 :         agent_record.define("observation", observation);
    1414           0 :         agent_record.define("apply", apply);
    1415           0 :         agent_record.define("agentname", agent_name);
    1416             : 
    1417           0 :         agent_record.define("quackmode", quackmode);
    1418           0 :         agent_record.define("quackinterval", quackinterval);
    1419           0 :         agent_record.define("quackincrement", quackincrement);
    1420             : 
    1421             :         // Call the main method
    1422           0 :         parseAgentParameters(agent_record);
    1423             : 
    1424           0 :         return true;
    1425             : 
    1426           0 : }
    1427             : 
    1428             : // ---------------------------------------------------------------------
    1429             : // AgentFlagger::parseElevationParameters
    1430             : // Parse data selection parameters and specific elevation parameters
    1431             : //
    1432             : // ---------------------------------------------------------------------
    1433             : bool
    1434           0 : AgentFlagger::parseElevationParameters(String field, String spw, String array, String feed, String scan,
    1435             :                 String antenna, String uvrange, String timerange,String correlation,
    1436             :                 String intent, String observation, Double lowerlimit, Double upperlimit, Bool apply)
    1437             : {
    1438             : 
    1439           0 :         LogIO os(LogOrigin("AgentFlagger", __FUNCTION__));
    1440             : 
    1441             :         // Default values for some parameters
    1442           0 :         String mode = "elevation";
    1443           0 :         String agent_name = "Elevation";
    1444             : 
    1445             :         // Create a record with the parameters
    1446           0 :         Record agent_record = Record();
    1447             : 
    1448           0 :         agent_record.define("mode", mode);
    1449           0 :         agent_record.define("spw", spw);
    1450           0 :         agent_record.define("scan", scan);
    1451           0 :         agent_record.define("field", field);
    1452           0 :         agent_record.define("antenna", antenna);
    1453           0 :         agent_record.define("timerange", timerange);
    1454           0 :         agent_record.define("correlation", correlation);
    1455           0 :         agent_record.define("intent", intent);
    1456           0 :         agent_record.define("feed", feed);
    1457           0 :         agent_record.define("array", array);
    1458           0 :         agent_record.define("uvrange", uvrange);
    1459           0 :         agent_record.define("observation", observation);
    1460           0 :         agent_record.define("apply", apply);
    1461           0 :         agent_record.define("agentname", agent_name);
    1462             : 
    1463           0 :         agent_record.define("lowerlimit", lowerlimit);
    1464           0 :         agent_record.define("upperlimit", upperlimit);
    1465             : 
    1466             :         // Call the main method
    1467           0 :         parseAgentParameters(agent_record);
    1468             : 
    1469           0 :         return true;
    1470             : 
    1471           0 : }
    1472             : 
    1473             : // ---------------------------------------------------------------------
    1474             : // AgentFlagger::parseTfcropParameters
    1475             : // Parse data selection parameters and specific tfcrop parameters
    1476             : //
    1477             : // ---------------------------------------------------------------------
    1478             : bool
    1479           0 : AgentFlagger::parseTfcropParameters(String field, String spw, String array, String feed, String scan,
    1480             :                 String antenna, String uvrange, String timerange, String correlation,
    1481             :                 String intent, String observation, Double ntime, Bool combinescans,
    1482             :                 String datacolumn, Double timecutoff, Double freqcutoff, String timefit,
    1483             :                 String freqfit, Int maxnpieces, String flagdimension, String usewindowstats, Int halfwin,
    1484             :                 Bool extendflags, Bool apply, Bool channelavg, casac::variant chanbin, Bool timeavg,
    1485             :             String timebin)
    1486             : {
    1487             : 
    1488           0 :         LogIO os(LogOrigin("AgentFlagger", __FUNCTION__));
    1489             : 
    1490             :         // Default values for some parameters
    1491           0 :         String mode = "tfcrop";
    1492           0 :         String agent_name = "Tfcrop";
    1493             : 
    1494             :         // Create a record with the parameters
    1495           0 :         Record agent_record = Record();
    1496             : 
    1497           0 :         agent_record.define("mode", mode);
    1498           0 :         agent_record.define("spw", spw);
    1499           0 :         agent_record.define("scan", scan);
    1500           0 :         agent_record.define("field", field);
    1501           0 :         agent_record.define("antenna", antenna);
    1502           0 :         agent_record.define("timerange", timerange);
    1503           0 :         agent_record.define("correlation", correlation);
    1504           0 :         agent_record.define("intent", intent);
    1505           0 :         agent_record.define("feed", feed);
    1506           0 :         agent_record.define("array", array);
    1507           0 :         agent_record.define("uvrange", uvrange);
    1508           0 :         agent_record.define("observation", observation);
    1509           0 :         agent_record.define("apply", apply);
    1510           0 :         agent_record.define("agentname", agent_name);
    1511             : 
    1512           0 :         agent_record.define("ntime", ntime);
    1513           0 :         agent_record.define("combinescans", combinescans);
    1514           0 :         agent_record.define("datacolumn", datacolumn);
    1515           0 :         agent_record.define("timecutoff", timecutoff);
    1516           0 :         agent_record.define("freqcutoff", freqcutoff);
    1517           0 :         agent_record.define("timefit", timefit);
    1518           0 :         agent_record.define("freqfit", freqfit);
    1519           0 :         agent_record.define("maxnpieces", maxnpieces);
    1520           0 :         agent_record.define("flagdimension", flagdimension);
    1521           0 :         agent_record.define("usewindowstats", usewindowstats);
    1522           0 :         agent_record.define("halfwin", halfwin);
    1523           0 :         agent_record.define("extendflags", extendflags);
    1524           0 :         agent_record.define("apply", apply);
    1525             : 
    1526           0 :         if (chanbin.type() == casac::variant::INT)
    1527             :         {
    1528             :                 /*** need range check ***/
    1529           0 :                 agent_record.define("chanbin", (int) chanbin.toInt());
    1530             :         }
    1531           0 :         else if (chanbin.type() == casac::variant::INTVEC)
    1532             :         {
    1533             :                 /*** need range check ***/
    1534           0 :                 auto cb = chanbin.toIntVec( );
    1535           0 :         std::vector<int> vec;
    1536           0 :         std::for_each( cb.begin( ), cb.end( ), [&](long x){vec.push_back((int)x);} );
    1537           0 :                 agent_record.define("chanbin", Array<Int>(vec));
    1538           0 :         }
    1539             : 
    1540           0 :         agent_record.define("channelavg", channelavg);
    1541           0 :     agent_record.define("timeavg", timeavg);
    1542           0 :     agent_record.define("timebin", timebin);
    1543             : 
    1544             :         // Call the main method
    1545           0 :         parseAgentParameters(agent_record);
    1546             : 
    1547           0 :         return true;
    1548             : 
    1549           0 : }
    1550             : 
    1551             : // ---------------------------------------------------------------------
    1552             : // AgentFlagger::parseAntIntParameters
    1553             : // Parse data selection parameters and specific antint parameters
    1554             : //
    1555             : // ---------------------------------------------------------------------
    1556             : bool
    1557           0 : AgentFlagger::parseAntIntParameters(String field, String spw, String /* array */, 
    1558             :                                     String /* feed */, String scan, String antenna,
    1559             :                                     String uvrange, String timerange, 
    1560             :                                     String correlation, String intent,
    1561             :                                     String observation, String antint_ref_antenna,
    1562             :                                     Double minchanfrac,
    1563             :                                     Bool verbose, Bool apply)
    1564             : {
    1565             : 
    1566           0 :         LogIO os(LogOrigin("AgentFlagger", __FUNCTION__));
    1567             : 
    1568             :         // Mode specific values for some general parameters
    1569           0 :         String mode = "antint";
    1570           0 :         String agent_name = "AntennaIntegrations";
    1571             : 
    1572             :         // Create a record with the parameters for this mode
    1573           0 :         Record agent_record = Record();
    1574             : 
    1575           0 :         agent_record.define("mode", mode);
    1576           0 :         agent_record.define("agentname", agent_name);
    1577           0 :         agent_record.define("field", field);
    1578           0 :         agent_record.define("spw", spw);
    1579             : 
    1580           0 :         agent_record.define("scan", scan);
    1581           0 :         agent_record.define("antenna", antenna);
    1582           0 :         agent_record.define("uvrange", uvrange);
    1583           0 :         agent_record.define("timerange", timerange);
    1584           0 :         agent_record.define("correlation", correlation);
    1585           0 :         agent_record.define("intent", intent);
    1586           0 :         agent_record.define("observation", observation);
    1587           0 :         agent_record.define("antint_ref_antenna", antint_ref_antenna);
    1588           0 :         agent_record.define("minchanfrac", minchanfrac);
    1589           0 :         agent_record.define("verbose", verbose);
    1590           0 :         agent_record.define("apply", apply);
    1591             : 
    1592             :         // Call the main method
    1593           0 :         parseAgentParameters(agent_record);
    1594             : 
    1595           0 :         return true;
    1596           0 : }
    1597             : 
    1598             : // ---------------------------------------------------------------------
    1599             : // AgentFlagger::parseExtendParameters
    1600             : // Parse data selection parameters and specific extend parameters
    1601             : //
    1602             : // This method is called from parseAgentParameters, and it calls parseAgentParameters
    1603             : // again, passing a record set up for a "extend" agent. That way, an extend agent
    1604             : // is added after the main (RFlag or TFcrop) agent.
    1605             : // ---------------------------------------------------------------------
    1606             : bool
    1607           0 : AgentFlagger::parseExtendParameters(String field, String spw, String array, String feed, String scan,
    1608             :                 String antenna, String uvrange, String timerange, String correlation, String intent,
    1609             :                 String observation, Double ntime, Bool combinescans, Bool extendpols, Double growtime,
    1610             :                 Double growfreq, Bool growaround, Bool flagneartime, Bool flagnearfreq, Bool apply)
    1611             : {
    1612             : 
    1613           0 :         LogIO os(LogOrigin("AgentFlagger", __FUNCTION__));
    1614             : 
    1615             :         // Default values for some parameters
    1616           0 :         String mode = "extend";
    1617           0 :         String agent_name = "Extend";
    1618             : 
    1619             :         // Create a record with the parameters
    1620           0 :         Record agent_record = Record();
    1621             : 
    1622           0 :         agent_record.define("mode", mode);
    1623           0 :         agent_record.define("spw", spw);
    1624           0 :         agent_record.define("scan", scan);
    1625           0 :         agent_record.define("field", field);
    1626           0 :         agent_record.define("antenna", antenna);
    1627           0 :         agent_record.define("timerange", timerange);
    1628           0 :         agent_record.define("correlation", correlation);
    1629           0 :         agent_record.define("intent", intent);
    1630           0 :         agent_record.define("feed", feed);
    1631           0 :         agent_record.define("array", array);
    1632           0 :         agent_record.define("uvrange", uvrange);
    1633           0 :         agent_record.define("observation", observation);
    1634           0 :         agent_record.define("apply", apply);
    1635           0 :         agent_record.define("agentname", agent_name);
    1636             : 
    1637           0 :         agent_record.define("ntime", ntime);
    1638           0 :         agent_record.define("combinescans", combinescans);
    1639           0 :         agent_record.define("extendpols", extendpols);
    1640           0 :         agent_record.define("growtime", growtime);
    1641           0 :         agent_record.define("growfreq", growfreq);
    1642           0 :         agent_record.define("growaround", growaround);
    1643           0 :         agent_record.define("flagneartime", flagneartime);
    1644           0 :         agent_record.define("flagnearfreq", flagnearfreq);
    1645           0 :         agent_record.define("apply", apply);
    1646             : 
    1647             :         // Call the main method
    1648           0 :         parseAgentParameters(agent_record);
    1649             : 
    1650           0 :         return true;
    1651             : 
    1652           0 : }
    1653             : 
    1654             : 
    1655             : 
    1656             : // ---------------------------------------------------------------------
    1657             : // AgentFlagger::parseSummaryParameters
    1658             : // Parse data selection parameters and specific summary parameters
    1659             : //
    1660             : // ---------------------------------------------------------------------
    1661             : bool
    1662           0 : AgentFlagger::parseSummaryParameters(String field, String spw, String array,
    1663             :                 String feed, String scan, String antenna,
    1664             :                 String uvrange,  String timerange, String correlation,
    1665             :                 String intent, String observation,
    1666             :                 Bool spwchan, Bool spwcorr, Bool basecnt, Bool fieldcnt, String name)
    1667             : {
    1668             : 
    1669           0 :         LogIO os(LogOrigin("AgentFlagger", __FUNCTION__));
    1670             : 
    1671             :         // Default values for some parameters
    1672           0 :         String mode = "summary";
    1673           0 :         String agent_name = "Summary";
    1674             : 
    1675             :         // Create a record with the parameters
    1676           0 :         Record agent_record = Record();
    1677             : 
    1678           0 :         agent_record.define("mode", mode);
    1679           0 :         agent_record.define("spw", spw);
    1680           0 :         agent_record.define("scan", scan);
    1681           0 :         agent_record.define("field", field);
    1682           0 :         agent_record.define("antenna", antenna);
    1683           0 :         agent_record.define("timerange", timerange);
    1684           0 :         agent_record.define("correlation", correlation);
    1685           0 :         agent_record.define("intent", intent);
    1686           0 :         agent_record.define("feed", feed);
    1687           0 :         agent_record.define("array", array);
    1688           0 :         agent_record.define("uvrange", uvrange);
    1689           0 :         agent_record.define("observation", observation);
    1690           0 :         agent_record.define("agentname", agent_name);
    1691             : 
    1692           0 :         agent_record.define("spwchan", spwchan);
    1693           0 :         agent_record.define("spwcorr", spwcorr);
    1694           0 :         agent_record.define("basecnt", basecnt);
    1695           0 :     agent_record.define("fieldcnt", fieldcnt);
    1696           0 :         agent_record.define("name", name);
    1697             : 
    1698             :         // Call the main method
    1699           0 :         parseAgentParameters(agent_record);
    1700             : 
    1701           0 :         return true;
    1702           0 : }
    1703             : 
    1704             : 
    1705             : } //#end casa namespace

Generated by: LCOV version 1.16