Skip to content

Commit

Permalink
Add warning for impossible selections and avoid pruning operation
Browse files Browse the repository at this point in the history
  • Loading branch information
Chad Trabant committed Sep 28, 2017
1 parent 4547808 commit 940062c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2017.270: 3.20
- Add test and warning for impossible combination of selections
applied to a single record and avoid any pruning operation.
Specifically, two or more selections may specify two or more different
time ranges within the same record. The program does not support this
as it is limited to trimming a single record to a single time range.

2017.251: 3.20rc
- Update libmseed to 2.19.4.
- Reorgznize miniSEED output writer such that re-packed records that
Expand Down
18 changes: 17 additions & 1 deletion doc/dataselect.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH DATASELECT 1 2016/10/28
.TH DATASELECT 1 2017/9/27
.SH NAME
Mini-SEED data selection, sorting and pruning

Expand Down Expand Up @@ -265,6 +265,10 @@ IU COLA 00 LH[ENZ] R
IU COLA 00 LHZ * 2008,100,10,00,00 2008,100,10,30,00
.fi

\fBWarning:\fP with a selection file it is possible to specify
multiple, arbitrary selections. Some combinations of these selects
are not possible. See \fBCAVEATS AND LIMITATIONS\fP for more details.

.SH "INPUT LIST FILE"
A list file can be used to specify input files, one file per line.
The initial '@' character indicating a list file is not considered
Expand Down Expand Up @@ -406,6 +410,18 @@ can be parsed to determine run-time errors. Additionally the program
will return an exit code of 0 on successful operation and 1 when any
errors were encountered.

.SH CAVEATS AND LIMITATIONS

With the ability to specify multiple, arbitrary data selections it is
possbile to specify very complex and pathological compound selections.
When pruning samples from records into order to fit the requested
selections, this program is limited to trimming samples from the
beginning and/or end of the record. This means it is not possible to
select two or more non-intersecting time ranges from a single record.
Put another way, one cannot select select data from the beginning and
end, but not the middle of a record. The work-around for this
limitation is to run the program once for each selection.

.SH AUTHOR
.nf
Chad Trabant
Expand Down
9 changes: 8 additions & 1 deletion doc/dataselect.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
1. [Archive Format Examples](#archive-format-examples)
1. [Leap Second List File](#leap-second-list-file)
1. [Error Handling And Return Codes](#error-handling-and-return-codes)
1. [Caveats And Limitations](#caveats-and-limitations)
1. [Author](#author)

## <a id='synopsis'>Synopsis</a>
Expand Down Expand Up @@ -198,6 +199,8 @@ IU COLA 00 LH[ENZ] R
IU COLA 00 LHZ * 2008,100,10,00,00 2008,100,10,30,00
</pre>

<p ><b>Warning:</b> with a selection file it is possible to specify multiple, arbitrary selections. Some combinations of these selects are not possible. See <b>CAVEATS AND LIMITATIONS</b> for more details.</p>

## <a id='input-list-file'>Input List File</a>

<p >A list file can be used to specify input files, one file per line. The initial '@' character indicating a list file is not considered part of the file name. As an example, if the following command line option was used:</p>
Expand Down Expand Up @@ -314,6 +317,10 @@ II_BFO_00_BHZ_Q

<p >Any significant error message will be pre-pended with "ERROR" which can be parsed to determine run-time errors. Additionally the program will return an exit code of 0 on successful operation and 1 when any errors were encountered.</p>

## <a id='caveats-and-limitations'>Caveats And Limitations</a>

<p >With the ability to specify multiple, arbitrary data selections it is possbile to specify very complex and pathological compound selections. When pruning samples from records into order to fit the requested selections, this program is limited to trimming samples from the beginning and/or end of the record. This means it is not possible to select two or more non-intersecting time ranges from a single record. Put another way, one cannot select select data from the beginning and end, but not the middle of a record. The work-around for this limitation is to run the program once for each selection.</p>

## <a id='author'>Author</a>

<pre >
Expand All @@ -322,4 +329,4 @@ IRIS Data Management Center
</pre>


(man page 2016/10/28)
(man page 2017/9/27)
23 changes: 21 additions & 2 deletions src/dataselect.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* Written by Chad Trabant, IRIS Data Management Center.
*
* modified 2017.251
* modified 2017.270
***************************************************************************/

/***************************************************************************
Expand Down Expand Up @@ -117,7 +117,7 @@

#include "dsarchive.h"

#define VERSION "3.20rc"
#define VERSION "3.20"
#define PACKAGE "dataselect"

/* Input/output file selection information containers */
Expand Down Expand Up @@ -2537,6 +2537,7 @@ findselectlimits (Selections *select, char *srcname, hptime_t starttime,
hptime_t endtime, Record *rec)
{
SelectTime *selecttime;
char timestring[100];

if (!rec || !srcname || !select)
return -1;
Expand All @@ -2545,6 +2546,7 @@ findselectlimits (Selections *select, char *srcname, hptime_t starttime,
{
while (selecttime)
{
/* Continue if selection edge time does not intersect with record coverage */
if ((starttime < selecttime->starttime && !(starttime <= selecttime->starttime && endtime >= selecttime->starttime)))
{
selecttime = selecttime->next;
Expand All @@ -2556,11 +2558,28 @@ findselectlimits (Selections *select, char *srcname, hptime_t starttime,
continue;
}

/* Check that the selection intersects previous selection range if set,
* otherwise the combined selection is not possible. */
if (rec->selectstart != HPTERROR && rec->selectend != HPTERROR &&
!(rec->selectstart <= selecttime->endtime && rec->selectend >= selecttime->starttime))
{
ms_hptime2mdtimestr(starttime, timestring, 1);
ms_log (1, "Warning: impossible combination of selections for record (%s, %s), not pruning.\n",
srcname, timestring);
rec->selectstart = HPTERROR;
rec->selectend = HPTERROR;
return 0;
}

if (rec->selectstart == HPTERROR || rec->selectstart > selecttime->starttime)
{
rec->selectstart = selecttime->starttime;
}

if (rec->selectend == HPTERROR || rec->selectend < selecttime->endtime)
{
rec->selectend = selecttime->endtime;
}

/* Shortcut if the entire record is already selected */
if (rec->starttime >= rec->selectstart && rec->endtime <= rec->selectend)
Expand Down

0 comments on commit 940062c

Please sign in to comment.