From 5c59f800779469a9d07b12833c2e1f210ec51a1e Mon Sep 17 00:00:00 2001
From: Ger van Diepen <diepen@astron.nl>
Date: Wed, 28 Sep 2011 12:15:43 +0000
Subject: [PATCH] bug 1738: First version

---
 LCS/Common/CMakeLists.txt                |   1 +
 LCS/Common/include/Common/CMakeLists.txt |   2 +
 LCS/Common/include/Common/CasaLogSink.h  |  97 +++++++++
 LCS/Common/include/Common/InputParSet.h  | 116 +++++++++++
 LCS/Common/src/CMakeLists.txt            |   2 +
 LCS/Common/src/CasaLogSink.cc            | 113 +++++++++++
 LCS/Common/src/InputParSet.cc            | 243 +++++++++++++++++++++++
 LCS/Common/test/CMakeLists.txt           |   2 +
 LCS/Common/test/tCasaLogSink.cc          |  47 +++++
 LCS/Common/test/tCasaLogSink.sh          |   2 +
 LCS/Common/test/tInputParSet.cc          |  90 +++++++++
 LCS/Common/test/tInputParSet.in          |   2 +
 LCS/Common/test/tInputParSet.sh          |   2 +
 13 files changed, 719 insertions(+)
 create mode 100644 LCS/Common/include/Common/CasaLogSink.h
 create mode 100644 LCS/Common/include/Common/InputParSet.h
 create mode 100644 LCS/Common/src/CasaLogSink.cc
 create mode 100644 LCS/Common/src/InputParSet.cc
 create mode 100644 LCS/Common/test/tCasaLogSink.cc
 create mode 100755 LCS/Common/test/tCasaLogSink.sh
 create mode 100644 LCS/Common/test/tInputParSet.cc
 create mode 100644 LCS/Common/test/tInputParSet.in
 create mode 100755 LCS/Common/test/tInputParSet.sh

diff --git a/LCS/Common/CMakeLists.txt b/LCS/Common/CMakeLists.txt
index 3724366972c..bfc72f3d989 100644
--- a/LCS/Common/CMakeLists.txt
+++ b/LCS/Common/CMakeLists.txt
@@ -3,6 +3,7 @@
 lofar_package(Common 3.3)
 
 include(LofarFindPackage)
+lofar_find_package(Casacore COMPONENTS casa)
 lofar_find_package(Boost REQUIRED)
 lofar_find_package(Readline)
 
diff --git a/LCS/Common/include/Common/CMakeLists.txt b/LCS/Common/include/Common/CMakeLists.txt
index b3f6d8c4bef..5df6eb7ace0 100644
--- a/LCS/Common/include/Common/CMakeLists.txt
+++ b/LCS/Common/include/Common/CMakeLists.txt
@@ -9,6 +9,7 @@ execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
 install(FILES 
   Allocator.h
   Backtrace.h
+  CasaLogSink.h
   CheckConfig.h
   ComplexBuiltinFP.h
   ComplexBuiltinInt.h
@@ -21,6 +22,7 @@ install(FILES
   Exceptions.h
   FileLocator.h
   hexdump.h
+  InputParSet.h
   i4complex.h
   KVpair.h
   lofar_algorithm.h
diff --git a/LCS/Common/include/Common/CasaLogSink.h b/LCS/Common/include/Common/CasaLogSink.h
new file mode 100644
index 00000000000..d03dcd3359d
--- /dev/null
+++ b/LCS/Common/include/Common/CasaLogSink.h
@@ -0,0 +1,97 @@
+//# CasaLogSink.h: LogSink to convert casacore messages to LOFAR 
+//#
+//# Copyright (C) 2011
+//# ASTRON (Netherlands Institute for Radio Astronomy)
+//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
+//#
+//# This file is part of the LOFAR software suite.
+//# The LOFAR software suite is free software: you can redistribute it and/or
+//# modify it under the terms of the GNU General Public License as published
+//# by the Free Software Foundation, either version 3 of the License, or
+//# (at your option) any later version.
+//#
+//# The LOFAR software suite is distributed in the hope that it will be useful,
+//# but WITHOUT ANY WARRANTY; without even the implied warranty of
+//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//# GNU General Public License for more details.
+//#
+//# You should have received a copy of the GNU General Public License along
+//# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
+//#
+//# $Id$
+
+#ifndef LOFAR_COMMON_CASALOGSINK_H
+#define LOFAR_COMMON_CASALOGSINK_H
+
+// \file LogSink to convert casacore messages to LOFAR 
+
+//# Never #include <config.h> or #include <lofar_config.h> in a header file!
+//# Includes
+
+#ifdef HAVE_AIPSPP
+
+//#Includes
+#include <casa/Logging/LogSink.h>
+#include <casa/Logging/LogFilter.h>
+
+namespace LOFAR {
+
+  // @brief log4cxx LogSink for Casa log messages.
+  // @details
+  // This class can be used to redirect the casacore log messages to
+  // the logging system used by LOFAR.
+  // It can be achieved by defining this sink as the global casa LogSink
+  // as follows:
+  // @code
+  //   CasaLogSink::attach();
+  // @endcode
+
+  class CasaLogSink : public casa::LogSinkInterface
+  {
+  public:
+    // By default no filtering is done.
+    CasaLogSink();
+
+    // Create the sink with the given filter (level).
+    // @{
+    explicit CasaLogSink (casa::LogMessage::Priority filter);
+    explicit CasaLogSink (const casa::LogFilterInterface& filter);
+    // @}
+
+    ~CasaLogSink();
+
+    // Make an object of this class the global casacore LogSink.
+    static void attach();
+
+    // If the message passes the filter, write it to the log4cxx sink.
+    virtual casa::Bool postLocally (const casa::LogMessage& message);
+
+    // Clear the local sink (i.e. remove all messages from it).
+    virtual void clearLocally();
+
+    // Returns the id for this class...
+    static casa::String localId();
+    // Returns the id of the LogSink in use...
+    casa::String id() const;
+
+  private:
+    // Copying is forbidden.
+    // @{
+    CasaLogSink (const CasaLogSink& other);
+    CasaLogSink& operator= (const CasaLogSink& other);
+    // @}
+  };
+
+} // end namespace
+
+#else
+namespace LOFAR {
+  class CasaLogSink {
+  public:
+    //# This won't do anything.
+    static void attach();
+  };
+}
+#endif
+
+#endif
diff --git a/LCS/Common/include/Common/InputParSet.h b/LCS/Common/include/Common/InputParSet.h
new file mode 100644
index 00000000000..a072cff2bae
--- /dev/null
+++ b/LCS/Common/include/Common/InputParSet.h
@@ -0,0 +1,116 @@
+//# InputParSet.h: Parameters using ParameterSet or casacore's Input
+//#
+//# Copyright (C) 2011
+//# ASTRON (Netherlands Institute for Radio Astronomy)
+//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
+//#
+//# This file is part of the LOFAR software suite.
+//# The LOFAR software suite is free software: you can redistribute it and/or
+//# modify it under the terms of the GNU General Public License as published
+//# by the Free Software Foundation, either version 3 of the License, or
+//# (at your option) any later version.
+//#
+//# The LOFAR software suite is distributed in the hope that it will be useful,
+//# but WITHOUT ANY WARRANTY; without even the implied warranty of
+//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//# GNU General Public License for more details.
+//#
+//# You should have received a copy of the GNU General Public License along
+//# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
+//#
+//# $Id$
+
+#ifndef LOFAR_COMMON_INPUTPARSET_H
+#define LOFAR_COMMON_INPUTPARSET_H
+
+// \file
+// Parameters using ParameterSet or casacore's Input
+
+//# Never #include <config.h> or #include <lofar_config.h> in a header file!
+//# Includes
+#include <Common/ParameterSet.h>
+
+//# Forward declare Input.
+namespace casa {
+  class Input;
+}
+
+
+namespace LOFAR {
+
+  // \addtogroup Common
+  // @{
+
+  // This class makes it possible to get parameters from a parset file using
+  // ParameterSet or from the command line arguments using casacore' Input.
+  //
+  // It will be determined from the command line argumenst if Input
+  // or ParameterSet is used. If a single argument without an =-sign is used,
+  // the ParameterSet is used with that argument as parset name.
+
+  class InputParSet
+  {
+  public:
+    // The default constructor enables the creation of parameters. 
+    InputParSet();
+
+    ~InputParSet();
+  
+    // Create a new parameter.
+    void create (const string& key, const string& defaultValue,
+                 const string& help, const string& type); 
+
+    // Fill the parameter list from argc, argv command line args.
+    // If a single argument without =-sign is given, it is the name of a parset.
+    // If '-h' is given, help info will be printed and exit(1) is called.
+    // '?', '--help' and 'help' are also considered as help request.
+    void readArguments (int argc, char const* const* argv);
+
+    // Get the value of the parameter as a double.
+    double getDouble (const string& key) const;
+
+    // Get the value of the parameter as a vector of doubles.
+    vector<double> getDoubleVector (const string& key) const;
+
+    // Get the value of the parameter as an integer.
+    int getInt (const string& key) const;
+
+    // Get the value of the parameter as a vector of integers.
+    vector<int> getIntVector (const string& key) const;
+
+    // Get the value of the parameter as a string.
+    string getString (const string& key) const;
+
+    // Get the value of the parameter as a bool.
+    bool getBool (const string& key) const;
+
+    // Set version string for announcements.
+    void setVersion (const string&);
+
+    // Show the help info.
+    void showHelp (ostream& os, const string& name);
+
+  private:
+    struct IPV {
+      IPV();
+      IPV (const string& shelp, const string& stype,
+           const string& sdefVal);
+      string help;
+      string type;
+      string defVal;
+    };
+
+    // Get the default value for the given parameter iterator.
+    // It throws an exception if it has no default value.
+    string getDefault (map<string,IPV>::const_iterator iter) const;
+
+    ParameterSet itsParSet;
+    casa::Input* itsInput;
+    bool         itsUsePS;     //# true = use ParameterSet
+    string       itsVersion;
+    map<string, IPV> itsParms;
+  };
+
+} // namespace LOFAR
+
+#endif
diff --git a/LCS/Common/src/CMakeLists.txt b/LCS/Common/src/CMakeLists.txt
index 88f071656cf..fe4723c67e1 100644
--- a/LCS/Common/src/CMakeLists.txt
+++ b/LCS/Common/src/CMakeLists.txt
@@ -5,6 +5,7 @@ include(LofarPackageVersion)
 set(common_LIB_SRCS
   Package__Version.cc
   Allocator.cc
+  CasaLogSink.cc
   DataConvert.cc
   Exception.cc
   FileLocator.cc
@@ -16,6 +17,7 @@ set(common_LIB_SRCS
   ParameterSet.cc
   ParameterSetImpl.cc
   ParameterValue.cc
+  InputParSet.cc
   PrettyUnits.cc
   Process.cc
   ReadLine.cc
diff --git a/LCS/Common/src/CasaLogSink.cc b/LCS/Common/src/CasaLogSink.cc
new file mode 100644
index 00000000000..ef83e80cb30
--- /dev/null
+++ b/LCS/Common/src/CasaLogSink.cc
@@ -0,0 +1,113 @@
+//# CasaLogSink.cc: LogSink to convert casacore messages to LOFAR 
+//#
+//# Copyright (C) 2011
+//# ASTRON (Netherlands Institute for Radio Astronomy)
+//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
+//#
+//# This file is part of the LOFAR software suite.
+//# The LOFAR software suite is free software: you can redistribute it and/or
+//# modify it under the terms of the GNU General Public License as published
+//# by the Free Software Foundation, either version 3 of the License, or
+//# (at your option) any later version.
+//#
+//# The LOFAR software suite is distributed in the hope that it will be useful,
+//# but WITHOUT ANY WARRANTY; without even the implied warranty of
+//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//# GNU General Public License for more details.
+//#
+//# You should have received a copy of the GNU General Public License along
+//# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
+//#
+//# $Id$
+
+// @author Ger van Diepen (gvd AT astron DOT nl)
+
+#include <lofar_config.h>
+#include <Common/CasaLogSink.h>
+#include <Common/LofarLogger.h>
+
+
+namespace LOFAR {
+
+#ifdef HAVE_AIPSPP
+
+  CasaLogSink::CasaLogSink()
+    : casa::LogSinkInterface (casa::LogFilter())
+  {}
+
+  CasaLogSink::CasaLogSink (casa::LogMessage::Priority filter)
+    : casa::LogSinkInterface (casa::LogFilter(filter))
+  {}
+
+  CasaLogSink::CasaLogSink (const casa::LogFilterInterface& filter)
+    : casa::LogSinkInterface (filter)
+  {}
+
+  CasaLogSink::~CasaLogSink()
+  {}
+
+  void CasaLogSink::attach()
+  {
+    casa::LogSinkInterface* globalSink = new LOFAR::CasaLogSink;
+    // Note that the pointer is taken over by LogSink.
+    casa::LogSink::globalSink (globalSink);
+  }
+
+  casa::Bool CasaLogSink::postLocally (const casa::LogMessage& message)
+  {
+    casa::Bool posted = casa::False;
+    if (filter().pass(message)) {
+      std::string msg (message.origin().location() + ": " + message.message());
+      posted = casa::True;
+      switch (message.priority()) {
+      case casa::LogMessage::DEBUGGING:
+      case casa::LogMessage::DEBUG2:
+      case casa::LogMessage::DEBUG1:
+	{
+	  LOG_DEBUG (msg);
+	  break;
+	}
+      case casa::LogMessage::NORMAL5:
+      case casa::LogMessage::NORMAL4:
+      case casa::LogMessage::NORMAL3:
+      case casa::LogMessage::NORMAL2:
+      case casa::LogMessage::NORMAL1:
+      case casa::LogMessage::NORMAL:
+	{
+	  LOG_INFO (msg);
+	  break;
+	}
+      case casa::LogMessage::WARN:
+	{
+	  LOG_WARN (msg);
+	  break;
+	}
+      case casa::LogMessage::SEVERE:
+	{
+	  LOG_ERROR (msg);
+	  break;
+	}
+      }
+    }
+    return posted;
+  }
+
+  void CasaLogSink::clearLocally()
+  {}
+
+  casa::String CasaLogSink::localId()
+  {
+    return casa::String("CasaLogSink");
+  }
+
+  casa::String CasaLogSink::id() const
+  {
+    return casa::String("CasaLogSink");
+  }
+
+#else
+  void CasaLogSink::attach()
+  {}
+#endif
+
+} // end namespaces
diff --git a/LCS/Common/src/InputParSet.cc b/LCS/Common/src/InputParSet.cc
new file mode 100644
index 00000000000..aaafe7b7c72
--- /dev/null
+++ b/LCS/Common/src/InputParSet.cc
@@ -0,0 +1,243 @@
+//# InputParSet.cc: Parameters using ParameterSet or casacore's Input
+//#
+//# Copyright (C) 2011
+//# ASTRON (Netherlands Institute for Radio Astronomy)
+//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
+//#
+//# This file is part of the LOFAR software suite.
+//# The LOFAR software suite is free software: you can redistribute it and/or
+//# modify it under the terms of the GNU General Public License as published
+//# by the Free Software Foundation, either version 3 of the License, or
+//# (at your option) any later version.
+//#
+//# The LOFAR software suite is distributed in the hope that it will be useful,
+//# but WITHOUT ANY WARRANTY; without even the implied warranty of
+//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//# GNU General Public License for more details.
+//#
+//# You should have received a copy of the GNU General Public License along
+//# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
+//#
+//# $Id$
+
+#include <lofar_config.h>
+#include <Common/InputParSet.h>
+#include <Common/Exceptions.h>
+#ifdef HAVE_AIPSPP
+# include <casa/Inputs/Input.h>
+#endif
+
+namespace LOFAR {
+
+  InputParSet::InputParSet()
+    : itsInput (0),
+      itsUsePS (false)
+  {
+#ifdef HAVE_AIPSPP
+    itsInput = new casa::Input;
+#endif
+  }
+
+  InputParSet::~InputParSet()
+  {
+#ifdef HAVE_AIPSPP
+    delete itsInput;
+#endif
+  }
+  
+  void InputParSet::create (const std::string& key,
+                            const std::string& defaultValue,
+                            const std::string& help,
+                            const std::string& type)
+  {
+#ifdef HAVE_AIPSPP
+    itsInput->create (key, defaultValue, help, type);
+#endif
+    itsParms[key] = IPV(help, type, defaultValue);
+  }
+
+  void InputParSet::readArguments (int argc, char const* const* argv)
+  {
+    if (argc == 2) {
+      string value(argv[1]);
+      // Use ParameterSet if no =-sign.
+      if (value.find('=') == string::npos) {
+        if (value == "-h"  ||  value == "--help"  ||  value == "help" ||
+            value == "?") {
+          showHelp (cerr, argv[0]);
+          exit(1);
+        }
+        itsParSet = ParameterSet (value);
+        itsUsePS  = true;
+        return;
+      }
+    }
+#ifdef HAVE_AIPSPP
+    itsInput->readArguments (argc, argv);
+#else
+    THROW (APSException, "Program parameters are given on the command line, "
+           "but casacore's Input is available to handle them");
+#endif
+  }
+
+  string InputParSet::getDefault (map<string,IPV>::const_iterator iter) const
+  {
+    return iter->second.defVal;
+  }
+
+  double InputParSet::getDouble (const std::string& key) const
+  {
+    map<string,IPV>::const_iterator iter = itsParms.find(key);
+    if (iter == itsParms.end()) {
+      THROW (APSException, "Parameter " + key +
+             " does not exist in InputParSet");
+    }
+    if (itsUsePS) {
+      if (itsParSet.isDefined (key)) {
+        return itsParSet.getDouble (key);
+      }
+      ParameterValue pv(getDefault(iter));
+      return pv.getDouble();
+    }
+#ifdef HAVE_AIPSPP
+    return itsInput->getDouble (key);
+#endif
+    return 0;
+  }
+
+  vector<double> InputParSet::getDoubleVector (const std::string& key) const
+  {
+    map<string,IPV>::const_iterator iter = itsParms.find(key);
+    if (iter == itsParms.end()) {
+      THROW (APSException, "Parameter " + key +
+             " does not exist in InputParSet");
+    }
+    if (itsUsePS) {
+      if (itsParSet.isDefined (key)) {
+        return itsParSet.getDoubleVector (key);
+      }
+      ParameterValue pv('[' + getDefault(iter) + ']');
+      return pv.getDoubleVector();
+    }
+#ifdef HAVE_AIPSPP
+    casa::Block<double> vals (itsInput->getDoubleArray (key));
+    return vector<double>(vals.begin(), vals.end());
+#endif
+    return vector<double>();
+  }
+
+  int InputParSet::getInt (const std::string& key) const
+  {
+    map<string,IPV>::const_iterator iter = itsParms.find(key);
+    if (iter == itsParms.end()) {
+      THROW (APSException, "Parameter " + key +
+             " does not exist in InputParSet");
+    }
+    if (itsUsePS) {
+      if (itsParSet.isDefined (key)) {
+        return itsParSet.getInt (key);
+      }
+      ParameterValue pv(getDefault(iter));
+      return pv.getInt();
+    }
+#ifdef HAVE_AIPSPP
+    return itsInput->getInt (key);
+#endif
+    return 0;
+  }
+
+  vector<int> InputParSet::getIntVector (const std::string& key) const
+  {
+    map<string,IPV>::const_iterator iter = itsParms.find(key);
+    if (iter == itsParms.end()) {
+      THROW (APSException, "Parameter " + key +
+             " does not exist in InputParSet");
+    }
+    if (itsUsePS) {
+      if (itsParSet.isDefined (key)) {
+        return itsParSet.getIntVector (key);
+      }
+      ParameterValue pv('[' + getDefault(iter) + ']');
+      return pv.getIntVector();
+    }
+#ifdef HAVE_AIPSPP
+    casa::Block<int> vals (itsInput->getIntArray (key));
+    return vector<int>(vals.begin(), vals.end());
+#endif
+    return vector<int>();
+  }
+
+  bool InputParSet::getBool (const std::string& key) const
+  {
+    map<string,IPV>::const_iterator iter = itsParms.find(key);
+    if (iter == itsParms.end()) {
+      THROW (APSException, "Parameter " + key +
+             " does not exist in InputParSet");
+    }
+    if (itsUsePS) {
+      if (itsParSet.isDefined (key)) {
+        return itsParSet.getBool (key);
+      }
+      ParameterValue pv(getDefault(iter));
+      return pv.getBool();
+    }
+#ifdef HAVE_AIPSPP
+    return itsInput->getBool (key);
+#endif
+    return false;
+  }
+
+  string InputParSet::getString (const std::string& key) const
+  {
+    map<string,IPV>::const_iterator iter = itsParms.find(key);
+    if (iter == itsParms.end()) {
+      THROW (APSException, "Parameter " + key +
+             " does not exist in InputParSet");
+    }
+    if (itsUsePS) {
+      if (itsParSet.isDefined (key)) {
+        return itsParSet.getString (key);
+      }
+      return getDefault(iter);
+    }
+#ifdef HAVE_AIPSPP
+    return itsInput->getString (key);
+#endif
+    return 0;
+  }
+
+  void InputParSet::setVersion (const string& version)
+  {
+    itsVersion == version;
+#ifdef HAVE_AIPSPP
+    itsInput->version (version);
+#endif
+  }
+
+  void InputParSet::showHelp (ostream& os, const string& name)
+  {
+    os << name << "  version " << itsVersion << endl;
+    for (map<string,IPV>::const_iterator iter = itsParms.begin();
+         iter!=itsParms.end(); ++iter) {
+      os << iter->first << ", " << iter->second.type << ", ";
+      os << '(' << iter->second.defVal << ')';
+      os << endl;
+      if (! iter->second.help.empty()) {
+        os << "    " << iter->second.help << endl;
+      }
+    }
+  }
+
+
+  InputParSet::IPV::IPV()
+  {}
+
+  InputParSet::IPV::IPV (const string& shelp, const string& stype,
+                         const string& sdefVal)
+    : help   (shelp),
+      type   (stype),
+      defVal (sdefVal)
+  {}
+
+
+} // namespace LOFAR
diff --git a/LCS/Common/test/CMakeLists.txt b/LCS/Common/test/CMakeLists.txt
index 1f59cb2c888..4800d5ae8f6 100644
--- a/LCS/Common/test/CMakeLists.txt
+++ b/LCS/Common/test/CMakeLists.txt
@@ -3,6 +3,7 @@
 include(LofarCTest)
 
 lofar_add_test(testLogger testLogger.cc)
+lofar_add_test(tCasaLogSink tCasaLogSink.cc)
 lofar_add_test(tAllocator tAllocator.cc)
 lofar_add_test(tDataConvert tDataConvert.cc)
 lofar_add_test(tTypeNames tTypeNames.cc)
@@ -24,6 +25,7 @@ lofar_add_test(tPrettyUnits tPrettyUnits.cc)
 lofar_add_test(tParameterValue tParameterValue.cc)
 lofar_add_test(tParameterSet tParameterSet.cc)
 lofar_add_test(tParameterSetPerf tParameterSetPerf.cc)
+lofar_add_test(tInputParSet tInputParSet.cc)
 lofar_add_test(tgetparsetvalue DEPENDS getparsetvalue)
 #lofar_add_test(tBacktrace tBacktrace.cc)
 lofar_add_test(tReadLine tReadLine.cc)
diff --git a/LCS/Common/test/tCasaLogSink.cc b/LCS/Common/test/tCasaLogSink.cc
new file mode 100644
index 00000000000..544fb19b5a1
--- /dev/null
+++ b/LCS/Common/test/tCasaLogSink.cc
@@ -0,0 +1,47 @@
+//# tCasaLogSink.h: Test program for class CasaLogSink
+//#
+//# Copyright (C) 2011
+//# ASTRON (Netherlands Institute for Radio Astronomy)
+//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
+//#
+//# This file is part of the LOFAR software suite.
+//# The LOFAR software suite is free software: you can redistribute it and/or
+//# modify it under the terms of the GNU General Public License as published
+//# by the Free Software Foundation, either version 3 of the License, or
+//# (at your option) any later version.
+//#
+//# The LOFAR software suite is distributed in the hope that it will be useful,
+//# but WITHOUT ANY WARRANTY; without even the implied warranty of
+//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//# GNU General Public License for more details.
+//#
+//# You should have received a copy of the GNU General Public License along
+//# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
+//#
+//# $Id$
+
+// @author Ger van Diepen (gvd AT astron DOT nl)
+
+#include <lofar_config.h>
+#include <Common/CasaLogSink.h>
+#include <Common/lofar_iostream.h>
+
+#include <casa/Logging/LogIO.h>
+
+using namespace LOFAR;
+
+int main()
+{
+  CasaLogSink::attach();
+
+#ifdef HAVE_AIPSPP
+  cout << "writing to casa logger ..." << endl;
+  casa::LogIO logger;
+  logger << casa::LogIO::DEBUG1 << "debug  message" << casa::LogIO::POST;
+  logger << casa::LogIO::NORMAL << "normal message" << casa::LogIO::POST;
+  logger << casa::LogIO::WARN   << "warn   message" << casa::LogIO::POST;
+  logger << casa::LogIO::SEVERE << "error  message" << casa::LogIO::POST;
+#endif
+
+  return 0;
+}
diff --git a/LCS/Common/test/tCasaLogSink.sh b/LCS/Common/test/tCasaLogSink.sh
new file mode 100755
index 00000000000..eb035bd3d08
--- /dev/null
+++ b/LCS/Common/test/tCasaLogSink.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+./runctest.sh tCasaLogSink 2>&1 > tCasaLogSink.log
diff --git a/LCS/Common/test/tInputParSet.cc b/LCS/Common/test/tInputParSet.cc
new file mode 100644
index 00000000000..f59a3d11048
--- /dev/null
+++ b/LCS/Common/test/tInputParSet.cc
@@ -0,0 +1,90 @@
+//# tInputParSet.cc: Test program for class InutParSet
+//#
+//# Copyright (C) 2011
+//# ASTRON (Netherlands Institute for Radio Astronomy)
+//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
+//#
+//# This file is part of the LOFAR software suite.
+//# The LOFAR software suite is free software: you can redistribute it and/or
+//# modify it under the terms of the GNU General Public License as published
+//# by the Free Software Foundation, either version 3 of the License, or
+//# (at your option) any later version.
+//#
+//# The LOFAR software suite is distributed in the hope that it will be useful,
+//# but WITHOUT ANY WARRANTY; without even the implied warranty of
+//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//# GNU General Public License for more details.
+//#
+//# You should have received a copy of the GNU General Public License along
+//# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
+//#
+//# $Id$
+
+#include <Common/InputParSet.h>
+#include <Common/StreamUtil.h>
+
+using namespace LOFAR;
+
+void testInput (int argc, char* argv[])
+{
+  InputParSet inputs;
+  // define the input structure
+  inputs.setVersion("2011Sep19-CT/SvdT/JvZ/GvD");
+  inputs.create ("ms", "",
+                 "Name of input MeasurementSet",
+                 "string");
+  inputs.create ("image", "",
+                 "Name of output image file (default is <msname-stokes-mode-nchan>.img)",
+                 "string");
+  inputs.create ("nscales", "5",
+                 "Scales for MultiScale Clean",
+                 "int");
+  inputs.create ("noise", "1.0",
+                 "Noise (in Jy) for briggsabs weighting",
+                 "float");
+  inputs.create ("nonoise", "",
+                 "Noise (in Jy) for briggsabs weighting",
+                 "float");
+  inputs.create ("spwid", "0",
+                 "spectral window id(s) to be used",
+                 "int vector");
+  inputs.create ("fixed", "False",
+                 "Keep clean model fixed",
+                 "bool");
+  inputs.create ("uservector", "1.1, 3.4",
+                 "user-defined scales for MultiScale clean",
+                 "float vector");
+
+  // Fill the input structure from the command line.
+  inputs.readArguments (argc, argv);
+
+  // Get the input specification.
+  bool fixed   = inputs.getBool("fixed");
+  int nscales  = inputs.getInt("nscales");
+  double noise = inputs.getDouble("noise");
+  double nnoise= inputs.getDouble("nonoise");
+  string ms    = inputs.getString("ms");
+  string image = inputs.getString("image");
+  vector<int> spwid(inputs.getIntVector("spwid"));
+  vector<double> uservector(inputs.getDoubleVector("uservector"));
+
+  cout << "fixed=" << fixed << endl;
+  cout << "nscales=" << nscales << endl;
+  cout << "noise=" << noise << endl;
+  cout << "nonoise=" << nnoise << endl;
+  cout << "ms=" << ms << endl;
+  cout << "image=" << image << endl;
+  cout << "spwid=" << spwid << endl;
+  cout << "uservector=" << uservector << endl;
+}
+
+int main (int argc, char* argv[])
+{
+  try {
+    testInput (argc, argv);
+  } catch (std::exception& x) {
+    cout << "Unexpected exception: " << x.what() << endl;
+    return 1;
+  }
+  return 0;
+}
diff --git a/LCS/Common/test/tInputParSet.in b/LCS/Common/test/tInputParSet.in
new file mode 100644
index 00000000000..a6f528fcacb
--- /dev/null
+++ b/LCS/Common/test/tInputParSet.in
@@ -0,0 +1,2 @@
+# xx
+image=1.5xx
diff --git a/LCS/Common/test/tInputParSet.sh b/LCS/Common/test/tInputParSet.sh
new file mode 100755
index 00000000000..9341e11f081
--- /dev/null
+++ b/LCS/Common/test/tInputParSet.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+./runctest.sh tInputParSet 2>&1 > tInputParSet.log
-- 
GitLab