Commit fb245ac0 authored by Karl Wette's avatar Karl Wette
Browse files

Merge branch 'lalapps_dumpSFT-updates' into 'master'

lalapps_dumpSFT updates

See merge request lscsoft/lalsuite!1373
parents 2e90e095 cd33a62c
......@@ -36,6 +36,7 @@
#include <lal/LALString.h>
/*---------- DEFINES ----------*/
#define MIN(x,y) ((x) < (y) ? (x) : (y))
/*----- Macros ----- */
......@@ -50,15 +51,14 @@ typedef struct
BOOLEAN headerOnly;
BOOLEAN dataOnly;
BOOLEAN timestampsOnly;
BOOLEAN noHeader; // deprecated, use --dataOnly instead
UINT4 Nmax;
} UserVariables_t;
/*---------- internal prototypes ----------*/
int XLALprintDescriptor ( const SFTDescriptor *ptr );
int XLALprintHeader ( const SFTtype *header );
int XLALprintData ( const SFTtype *sft );
int XLALprintTimestamps ( const SFTCatalog *catalog );
int XLALprintTimestamps ( const SFTCatalog *catalog, const UINT4 Nmax );
int XLALReadUserInput ( int argc, char *argv[], UserVariables_t *uvar );
......@@ -79,10 +79,13 @@ main(int argc, char *argv[])
constraints.detector = detector;
SFTCatalog *catalog;
XLAL_CHECK ( (catalog = XLALSFTdataFind ( uvar.SFTfiles, &constraints )) != NULL, XLAL_EFUNC, "No SFTs matched your --SFTfiles query\n" );
if ( XLALUserVarWasSet(&uvar.Nmax) && ( uvar.Nmax > catalog->length ) ) {
XLALPrintWarning("Nmax=%u requested but SFT catalog has only %u entries. Returning them all.", uvar.Nmax, catalog->length);
}
if ( uvar.headerOnly )
{
for ( UINT4 i=0; i < catalog->length; i ++ )
for ( UINT4 i=0; i < MIN(uvar.Nmax,catalog->length); i ++ )
{
SFTDescriptor *ptr = &(catalog->data[i]);
......@@ -93,7 +96,7 @@ main(int argc, char *argv[])
} // if --headerOnly
else if ( uvar.timestampsOnly )
{
XLAL_CHECK ( XLALprintTimestamps ( catalog ) == XLAL_SUCCESS, XLAL_EFUNC );
XLAL_CHECK ( XLALprintTimestamps ( catalog, uvar.Nmax ) == XLAL_SUCCESS, XLAL_EFUNC );
} // if --timestampsOnly
else // if --dataOnly or data+headers [default]
{
......@@ -110,7 +113,7 @@ main(int argc, char *argv[])
}
} // if we're dealing with 'segmented SFTs': currently can't map them to catalog-descriptors
for ( UINT4 i=0; i < sfts->length; i ++ )
for ( UINT4 i=0; i < MIN(uvar.Nmax,sfts->length); i ++ )
{
SFTtype *sft_i = &(sfts->data[i]);;
......@@ -190,7 +193,7 @@ XLALprintData ( const SFTtype *sft )
// "The timestamps file is of the format: <repeated lines of the form "seconds nano-seconds">
// allowing for '%#' as comments, which are ignored."
int
XLALprintTimestamps ( const SFTCatalog *catalog )
XLALprintTimestamps ( const SFTCatalog *catalog, const UINT4 Nmax )
{
XLAL_CHECK ( (catalog != NULL) && (catalog->data != NULL), XLAL_EINVAL );
......@@ -212,7 +215,7 @@ XLALprintTimestamps ( const SFTCatalog *catalog )
// print timestamps
printf ( "%%%% Timestamps: seconds nano-seconds\n" );
for ( UINT4 i=0; i < catalog->length; i ++ )
for ( UINT4 i=0; i < MIN(Nmax,catalog->length); i ++ )
{
const SFTtype *header = &(catalog->data[i].header);
printf ( "%10d %09d\n", header->epoch.gpsSeconds, header->epoch.gpsNanoSeconds );
......@@ -225,12 +228,14 @@ XLALprintTimestamps ( const SFTCatalog *catalog )
int
XLALReadUserInput ( int argc, char *argv[], UserVariables_t *uvar )
{
/* set a few defaults */
uvar->Nmax = LAL_UINT4_MAX;
XLALRegisterUvarMember( SFTfiles, STRING, 'i', REQUIRED, "File-pattern for input SFTs");
XLALRegisterUvarMember( headerOnly, BOOLEAN, 'H', OPTIONAL, "Output only SFT headers");
XLALRegisterUvarMember( dataOnly, BOOLEAN, 'd', OPTIONAL, "Output only SFT data, no header info");
XLALRegisterUvarMember( timestampsOnly, BOOLEAN, 't', OPTIONAL, "Output only timestamps, in timestamps-file format");
XLALRegisterUvarMember( noHeader, BOOLEAN, 'n', DEPRECATED, "DEPRECATED: user --dataOnly instead");
XLALRegisterUvarMember( Nmax, UINT4, 'N', OPTIONAL, "When run on multiple SFTs, exit after this many");
/* read cmdline & cfgfile */
BOOLEAN should_exit = 0;
......@@ -240,14 +245,8 @@ XLALReadUserInput ( int argc, char *argv[], UserVariables_t *uvar )
}
// ---------- sanity input checks ----------
// deal with deprecated --noHeader option by mapping it 1:1 onto --dataOnly
XLAL_CHECK ( UVAR_SET2( noHeader, dataOnly ) <= 1, XLAL_EINVAL, "Use at most one of --dataOnly or --noHeader [deprecated]\n");
if ( XLALUserVarWasSet( &uvar->noHeader ) ) {
uvar->dataOnly = uvar->noHeader;
uvar->noHeader = 0;
}
XLAL_CHECK ( UVAR_SET3( headerOnly, dataOnly, timestampsOnly ) <= 1, XLAL_EINVAL, "Contradictory input: at most *one* of --headerOnly, --dataOnly or --timestampsOnly allowed\n" );
XLAL_CHECK ( uvar->Nmax > 0, XLAL_EINVAL );
return XLAL_SUCCESS;
......
......@@ -32,3 +32,30 @@ for file in stdout-*.txt; do
exit 1
fi
done
## run again with each flag to test --Nmax option
for flag in H d t; do
basecl1="lalapps_dumpSFT -$flag --Nmax 1 -i ./SFT-good"
out1="stdout-$flag-SFT-good-first.txt"
cl1="$basecl1 | grep -v '^%' > $out1"
echo $cl1
eval $cl1
if [ -s stderr.txt ]; then
echo "ERROR: '$basecl1' should not write to standard error"
exit 1
fi
Nlines=$(wc -l < $out1)
basecl2="lalapps_dumpSFT -$flag -i ./SFT-good"
out2="stdout-$flag-SFT-good-all.txt"
cl2="$basecl2 | grep -v '^%' | head -n $Nlines > $out2"
echo $cl2
eval $cl2
if [ -s stderr.txt ]; then
echo "ERROR: '$basecl2' should not write to standard error"
exit 1
fi
if ! diff -s $out1 $out2; then
echo "ERROR: $out1 and $out2 should be equal"
exit 1
fi
done
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment