Skip to content

Commit 81c6433

Browse files
author
Chad Trabant
committed
Add capability to store record metadata in TraceLists. Fix memory leak.
1 parent a139225 commit 81c6433

File tree

5 files changed

+185
-43
lines changed

5 files changed

+185
-43
lines changed

example/lm_parse.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ main (int argc, char **argv)
8686

8787
if (tracegap)
8888
{
89-
mstl3_addmsr (mstl, msr, 0, 1, NULL);
89+
mstl3_addmsr (mstl, msr, 0, 1, flags, NULL);
9090
}
9191
else
9292
{

example/lm_read_buffer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ main (int argc, char **argv)
8585
}
8686

8787
/* Read all miniSEED in buffer, accumulate in MS3TraceList */
88-
records = mstl3_readbuffer (&mstl, buffer, bufferlength, NULL,
89-
splitversion, flags, verbose);
88+
records = mstl3_readbuffer (&mstl, buffer, bufferlength,
89+
splitversion, flags, NULL, verbose);
9090

9191
if (records < 0)
9292
{

fileutils.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,11 @@ ms3_readtracelist_timewin (MS3TraceList **ppmstl, const char *msfile,
637637
* according to data publication version (or quality for miniSEED
638638
* 2.x). See mstl3_addmsr() for full details.
639639
*
640+
* If the ::MSF_STOREMETADATA flag is set in \a flags, the raw bit
641+
* flags and extra headers for record will be stored in a list of
642+
* ::MS3Metadata structures associated with the appropriate
643+
* ::MS3TraceSeg.
644+
*
640645
* @param[out] ppmstl Pointer-to-pointer to a ::MS3TraceList to populate
641646
* @param[in] msfile File to read
642647
* @param[in] tolerance Tolerance function pointers as ::MS3Tolerance
@@ -676,7 +681,7 @@ ms3_readtracelist_selection (MS3TraceList **ppmstl, const char *msfile,
676681
while ((retcode = ms3_readmsr_selection (&msfp, &msr, msfile, NULL, NULL,
677682
flags, selections, verbose)) == MS_NOERROR)
678683
{
679-
mstl3_addmsr (*ppmstl, msr, splitversion, 1, tolerance);
684+
mstl3_addmsr (*ppmstl, msr, splitversion, 1, flags, tolerance);
680685
}
681686

682687
/* Reset return code to MS_NOERROR on successful read by ms_readmsr_selection() */

libmseed.h

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,28 @@ extern void ms3_printselections (MS3Selections *selections);
390390
\sa mstl3_writemseed()
391391
@{ */
392392

393+
/**
394+
* @brief Container for a list of raw flags and extra headers
395+
*
396+
* A list of bit flags and extra headers with a time range of the
397+
* record they came from. In @ref trace-list functionality, this
398+
* container is used to retain flags and extra headers that
399+
* contributed to each entry.
400+
*
401+
* Note: the list is stored in the reverse order that they entries
402+
* were added.
403+
*
404+
* @see mstl3_add_metadata()
405+
*/
406+
typedef struct MS3Metadata
407+
{
408+
nstime_t starttime; //!< Start time for record containing metadata
409+
nstime_t endtime; //!< End time for record containing metadata
410+
uint8_t flags; //!< Record-level bit flags
411+
char *extra; //!< Record-level extra headers, NULL-terminated if existing
412+
struct MS3Metadata *next; //!< Pointer to next entry, NULL if the last
413+
} MS3Metadata;
414+
393415
/** @brief Container for a continuous trace segment, linkable */
394416
typedef struct MS3TraceSeg {
395417
nstime_t starttime; //!< Time of first sample
@@ -400,6 +422,7 @@ typedef struct MS3TraceSeg {
400422
int64_t numsamples; //!< Number of data samples in datasamples
401423
char sampletype; //!< Sample type code, see @ref sample-types
402424
void *prvtptr; //!< Private pointer for general use, unused by library
425+
struct MS3Metadata *metadata; //!< List of flags and extra headers from records that contributed
403426
struct MS3TraceSeg *prev; //!< Pointer to previous segment
404427
struct MS3TraceSeg *next; //!< Pointer to next segment, NULL if the last
405428
} MS3TraceSeg;
@@ -449,21 +472,23 @@ typedef struct MS3TraceList {
449472
*
450473
* \sa mstl3_addmsr()
451474
*/
452-
typedef struct MS3Tolerance {
453-
double (*time)(MS3Record *msr);
454-
double (*samprate)(MS3Record *msr);
475+
typedef struct MS3Tolerance
476+
{
477+
double (*time) (MS3Record *msr); //!< Pointer to function that returns time tolerance
478+
double (*samprate) (MS3Record *msr); //!< Pointer to function that returns sample rate tolerance
455479
} MS3Tolerance;
456480

457481
extern MS3TraceList* mstl3_init (MS3TraceList *mstl);
458482
extern void mstl3_free (MS3TraceList **ppmstl, int8_t freeprvtptr);
459483
extern MS3TraceSeg* mstl3_addmsr (MS3TraceList *mstl, MS3Record *msr, int8_t splitversion,
460-
int8_t autoheal, MS3Tolerance *tolerance);
484+
int8_t autoheal, uint32_t flags, MS3Tolerance *tolerance);
461485
extern int64_t mstl3_readbuffer (MS3TraceList **ppmstl, char *buffer, uint64_t bufferlength,
462-
MS3Tolerance *tolerance, int8_t splitversion,
463-
uint32_t flags, int8_t verbose);
486+
int8_t splitversion, uint32_t flags,
487+
MS3Tolerance *tolerance, int8_t verbose);
464488
extern int64_t mstl3_readbuffer_selection (MS3TraceList **ppmstl, char *buffer, uint64_t bufferlength,
489+
int8_t splitversion, uint32_t flags,
465490
MS3Tolerance *tolerance, MS3Selections *selections,
466-
int8_t splitversion, uint32_t flags, int8_t verbose);
491+
int8_t verbose);
467492
extern int mstl3_convertsamples (MS3TraceSeg *seg, char type, int8_t truncate);
468493
extern int mstl3_pack (MS3TraceList *mstl, void (*record_handler) (char *, int, void *),
469494
void *handlerdata, int reclen, int8_t encoding,
@@ -946,18 +971,19 @@ extern LIBMSEED_MEMORY libmseed_memory;
946971

947972
/** @defgroup control-flags Control flags
948973
@ingroup low-level
949-
@brief Parsing and packing control flags
974+
@brief Parsing, packing and trace construction control flags
950975
951976
These are bit flags that can be combined into a bitmask to control
952-
aspects of the libraries parsing and packing routines.
977+
aspects of the library's parsing, packing and trace managment routines.
953978
954979
@{ */
955-
#define MSF_UNPACKDATA 0x0001 //!< [Parsing] unpack data samples
956-
#define MSF_SKIPNOTDATA 0x0002 //!< [Parsing] skip input that cannot be identified as miniSEED
957-
#define MSF_VALIDATECRC 0x0004 //!< [Parsing] validate CRC (if version 3)
958-
#define MSF_SEQUENCE 0x0008 //!< [Packing] UNSUPPORTED: Maintain a record-level sequence number
959-
#define MSF_FLUSHDATA 0x0010 //!< [Packing] pack all available data even if final record would not be filled
960-
#define MSF_ATENDOFFILE 0x0020 //!< [Parsing] reading routine is at the end of the file
980+
#define MSF_UNPACKDATA 0x0001 //!< [Parsing] unpack data samples
981+
#define MSF_SKIPNOTDATA 0x0002 //!< [Parsing] skip input that cannot be identified as miniSEED
982+
#define MSF_VALIDATECRC 0x0004 //!< [Parsing] validate CRC (if version 3)
983+
#define MSF_SEQUENCE 0x0008 //!< [Packing] UNSUPPORTED: Maintain a record-level sequence number
984+
#define MSF_FLUSHDATA 0x0010 //!< [Packing] pack all available data even if final record would not be filled
985+
#define MSF_ATENDOFFILE 0x0020 //!< [Parsing] reading routine is at the end of the file
986+
#define MSF_STOREMETADATA 0x0040 //!< [Tracelist] store record-level metadata in trace lists
961987
/** @} */
962988

963989
#ifdef __cplusplus

0 commit comments

Comments
 (0)