Skip to content
Snippets Groups Projects
Commit ec0d3bcd authored by Ger van Diepen's avatar Ger van Diepen
Browse files

bug 1172:

Needed access to a parset file from a script
parent c49b2a4a
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
//# 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;
}
......@@ -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
......
key1 = [1,2,3]
key1.sub1 = [aa, bb]
#!/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
#!/bin/sh
$lofar_sharedir/runtest.sh tgetparsetvalue > tgetparsetvalue.log 2>&1
[1,2,3]
1
2
3
3
2
1
[aa, bb]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment