diff --git a/LCS/ACC/APS/src/Makefile.am b/LCS/ACC/APS/src/Makefile.am index 1f78ee2d82c3566c7dd90ca11fd0203fe7facc19..023065e6d2f18d6826b45d13cc63c0652e9d9338 100644 --- a/LCS/ACC/APS/src/Makefile.am +++ b/LCS/ACC/APS/src/Makefile.am @@ -6,7 +6,11 @@ libaps_la_SOURCES = Package__Version.cc \ ParameterSet.cc \ ParameterSetImpl.cc -bin_PROGRAMS = versionaps +bin_PROGRAMS = getparsetvalue versionaps + +getparsetvalue_SOURCES = getparsetvalue.cc +getparsetvalue_LDADD = libaps.la +getparsetvalue_DEPENDENCIES = libaps.la $(LOFAR_DEPEND) versionaps_SOURCES = versionaps.cc versionaps_LDADD = libaps.la diff --git a/LCS/ACC/APS/src/getparsetvalue.cc b/LCS/ACC/APS/src/getparsetvalue.cc new file mode 100644 index 0000000000000000000000000000000000000000..ce8603f00c71be13102e611d49b89f8a7dd7bae9 --- /dev/null +++ b/LCS/ACC/APS/src/getparsetvalue.cc @@ -0,0 +1,69 @@ +//# getparsetvalue.cc: Get a value as a string from a parameter set +//# +//# Copyright (C) 2008 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program 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 2 of the License, or +//# (at your option) any later version. +//# +//# This program 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 this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +//# Always #include <lofar_config.h> first! +#include <lofar_config.h> + +#include <APS/ParameterSet.h> +#include <Common/LofarLogger.h> +#include <stdexcept> +#include <iostream> + +int main (int argc, const char* argv[]) +{ + try { + if (argc < 3) { + std::cerr << "Run as: getparsetvalue parsetfile parmname [index]" + << " negative index counts from the end (a la python)" + << std::endl; + return 1; + } + int inx = 0; + bool useAll = true; + if (argc > 3) { + std::istringstream iss(argv[3]); + iss >> inx; + useAll = false; + } + LOFAR::ACC::APS::ParameterSet parset(argv[1]); + if (useAll) { + std::string value = parset.getString (argv[2]); + std::cout << value << std::endl; + } else { + std::vector<std::string> values = parset.getStringVector (argv[2]); + // Negative index is + int i = inx; + if (i < 0) { + i += values.size(); + } + ASSERTSTR (i >= 0 && i < int(values.size()), + "Index " << inx + << " exceeds value size " << values.size() + << " of parameter " << argv[2]); + std::cout << values[i] << std::endl; + } + } catch (std::exception &x) { + std::cerr << x.what() << std::endl; + return 1; + } + return 0; +} diff --git a/LCS/ACC/APS/test/Makefile.am b/LCS/ACC/APS/test/Makefile.am index 1618b3a12364c037704ac81e3a6925d4a9983d3f..58cbe1067a5cfee97813b42b2f465ae5b2a54379 100644 --- a/LCS/ACC/APS/test/Makefile.am +++ b/LCS/ACC/APS/test/Makefile.am @@ -8,7 +8,8 @@ LDADD = ../src/libaps.la DEPENDENCIES = ../src/libaps.la $(LOFAR_DEPEND) TESTSCRIPTS = tKeyPrefix.sh \ - tParameterSet_test.sh + tParameterSet_test.sh \ + tgetparsetvalue.sh TESTS = $(TESTSCRIPTS) @@ -19,6 +20,9 @@ EXTRA_DIST = tParameterSet.in_merge_nocase \ tParameterSet.in_param_normal \ tParameterSet.log_prop \ tParameterSet.stdout \ + tgetparsetvalue.run \ + tgetparsetvalue.parset \ + tgetparsetvalue.stdout \ $(TESTSCRIPTS) include $(top_srcdir)/Makefile.common diff --git a/LCS/ACC/APS/test/tgetparsetvalue.parset b/LCS/ACC/APS/test/tgetparsetvalue.parset new file mode 100644 index 0000000000000000000000000000000000000000..60353d89d2825162cf2140ab07046e1bce2dade6 --- /dev/null +++ b/LCS/ACC/APS/test/tgetparsetvalue.parset @@ -0,0 +1,2 @@ +key1 = [1,2,3] +key1.sub1 = [aa, bb] diff --git a/LCS/ACC/APS/test/tgetparsetvalue.run b/LCS/ACC/APS/test/tgetparsetvalue.run new file mode 100755 index 0000000000000000000000000000000000000000..8c805325c1c69f953f331e25d6bba6dbefff454f --- /dev/null +++ b/LCS/ACC/APS/test/tgetparsetvalue.run @@ -0,0 +1,12 @@ +#!/bin/sh + +../src/getparsetvalue tgetparsetvalue.parset key1 +../src/getparsetvalue tgetparsetvalue.parset key1 0 +../src/getparsetvalue tgetparsetvalue.parset key1 1 +../src/getparsetvalue tgetparsetvalue.parset key1 2 +../src/getparsetvalue tgetparsetvalue.parset key1 3 +../src/getparsetvalue tgetparsetvalue.parset key1 -1 +../src/getparsetvalue tgetparsetvalue.parset key1 -2 +../src/getparsetvalue tgetparsetvalue.parset key1 -3 +../src/getparsetvalue tgetparsetvalue.parset key1 -4 +../src/getparsetvalue tgetparsetvalue.parset key1.sub1 diff --git a/LCS/ACC/APS/test/tgetparsetvalue.sh b/LCS/ACC/APS/test/tgetparsetvalue.sh new file mode 100755 index 0000000000000000000000000000000000000000..3d37aa06c56956febd944596fd0f711ef6ca19eb --- /dev/null +++ b/LCS/ACC/APS/test/tgetparsetvalue.sh @@ -0,0 +1,2 @@ +#!/bin/sh +$lofar_sharedir/runtest.sh tgetparsetvalue > tgetparsetvalue.log 2>&1 diff --git a/LCS/ACC/APS/test/tgetparsetvalue.stdout b/LCS/ACC/APS/test/tgetparsetvalue.stdout new file mode 100644 index 0000000000000000000000000000000000000000..76bda7d2e75be8c327df3109c18a11617aec5dc8 --- /dev/null +++ b/LCS/ACC/APS/test/tgetparsetvalue.stdout @@ -0,0 +1,8 @@ +[1,2,3] +1 +2 +3 +3 +2 +1 +[aa, bb]