libmseed 3.1.3
The miniSEED data format library
|
Definitions and functions related to individual miniSEED records. More...
Data Structures | |
struct | MS3Record |
miniSEED record container More... | |
Functions | |
int | msr3_parse (const char *record, uint64_t recbuflen, MS3Record **ppmsr, uint32_t flags, int8_t verbose) |
Parse miniSEED from a buffer. | |
int | msr3_pack (const MS3Record *msr, void(*record_handler)(char *, int, void *), void *handlerdata, int64_t *packedsamples, uint32_t flags, int8_t verbose) |
Pack data into miniSEED records. | |
int | msr3_repack_mseed3 (const MS3Record *msr, char *record, uint32_t recbuflen, int8_t verbose) |
Repack a parsed miniSEED record into a version 3 record. | |
int | msr3_pack_header3 (const MS3Record *msr, char *record, uint32_t recbuflen, int8_t verbose) |
Pack a miniSEED version 3 header into the specified buffer. | |
int | msr3_pack_header2 (const MS3Record *msr, char *record, uint32_t recbuflen, int8_t verbose) |
Pack a miniSEED version 2 header into the specified buffer. | |
int64_t | msr3_unpack_data (MS3Record *msr, int8_t verbose) |
Unpack data samples for a MS3Record. | |
int | msr3_data_bounds (const MS3Record *msr, uint32_t *dataoffset, uint32_t *datasize) |
Determine the data payload bounds for a MS3Record. | |
int64_t | ms_decode_data (const void *input, uint64_t inputsize, uint8_t encoding, uint64_t samplecount, void *output, uint64_t outputsize, char *sampletype, int8_t swapflag, const char *sid, int8_t verbose) |
Decode data samples to a supplied buffer. | |
MS3Record * | msr3_init (MS3Record *msr) |
Initialize and return an MS3Record. | |
void | msr3_free (MS3Record **ppmsr) |
Free all memory associated with a MS3Record. | |
MS3Record * | msr3_duplicate (const MS3Record *msr, int8_t datadup) |
Duplicate a MS3Record. | |
nstime_t | msr3_endtime (const MS3Record *msr) |
Calculate time of the last sample in a record. | |
void | msr3_print (const MS3Record *msr, int8_t details) |
Print header values of an MS3Record. | |
int | msr3_resize_buffer (MS3Record *msr) |
Resize data sample buffer of MS3Record to what is needed. | |
double | msr3_sampratehz (const MS3Record *msr) |
Calculate sample rate in samples/second (Hertz) for a given MS3Record. | |
nstime_t | msr3_nsperiod (const MS3Record *msr) |
Calculate sample period in nanoseconds/sample for a given MS3Record. | |
double | msr3_host_latency (const MS3Record *msr) |
Calculate data latency based on the host time. | |
int64_t | ms3_detect (const char *record, uint64_t recbuflen, uint8_t *formatversion) |
Detect miniSEED record in buffer. | |
int | ms_parse_raw3 (const char *record, int maxreclen, int8_t details) |
Parse and verify a miniSEED 3.x record header. | |
int | ms_parse_raw2 (const char *record, int maxreclen, int8_t details, int8_t swapflag) |
Parse and verify a miniSEED 2.x record header. | |
Definitions and functions related to individual miniSEED records.
struct MS3Record |
miniSEED record container
Data Fields | ||
---|---|---|
const char * | record | Raw miniSEED record, if available. |
int32_t | reclen | Length of miniSEED record in bytes. |
uint8_t | swapflag | Byte swap indicator (bitmask), see Byte swap flags. |
char | sid[LM_SIDLEN] | Source identifier as URN, max length LM_SIDLEN. |
uint8_t | formatversion | Format major version. |
uint8_t | flags | Record-level bit flags. |
nstime_t | starttime | Record start time (first sample) |
double | samprate | Nominal sample rate as samples/second (Hz) or period (s) |
int16_t | encoding | Data encoding format, see Data Encodings. |
uint8_t | pubversion | Publication version. |
int64_t | samplecnt | Number of samples in record. |
uint32_t | crc | CRC of entire record. |
uint16_t | extralength | Length of extra headers in bytes. |
uint32_t | datalength | Length of data payload in bytes. |
char * | extra | Pointer to extra headers. |
void * | datasamples | Data samples, numsamples of type sampletype. |
uint64_t | datasize | Size of datasamples buffer in bytes. |
int64_t | numsamples | Number of data samples in datasamples. |
char | sampletype | Sample type code: t, i, f, d Sample Types. |
|
extern |
Parse miniSEED from a buffer.
This routine will attempt to parse (detect and unpack) a miniSEED record from a specified memory buffer and populate a supplied MS3Record structure. Both miniSEED 2.x and 3.x records are supported.
The record length is automatically detected. For miniSEED 2.x this means the record must contain a 1000 blockette.
record | Buffer containing record to parse |
recbuflen | Buffer length in bytes |
ppmsr | Pointer-to-point to a MS3Record that will be populated |
flags | Flags controlling features:
|
verbose | control verbosity of diagnostic output |
0 | Success, populates the supplied MS3Record. |
>0 | Data record detected but not enough data is present, the return value is a hint of how many more bytes are needed. |
<0 | library error code is returned. |
MessageOnError - this function logs a message on error except MS_NOTSEED
|
extern |
Pack data into miniSEED records.
Packing is performed according to the version at MS3Record::formatversion.
The MS3Record::datasamples array and MS3Record::numsamples value will not be changed by this routine. It is the responsibility of the calling routine to adjust the data buffer if desired.
As each record is filled and finished they are passed to record_handler() which should expect 1) a char*
to the record, 2) the length of the record and 3) a pointer supplied by the original caller containing optional private data (handlerdata). It is the responsibility of record_handler() to process the record, the memory will be re-used or freed when record_handler() returns.
The following data encodings and expected MS3Record::sampletype are supported:
't'
'i'
'i'
'f'
'd'
'i'
'i'
If flags has MSF_FLUSHDATA set, all of the data will be packed into data records even though the last one will probably be smaller than requested or, in the case of miniSEED 2, unfilled.
Default values are: record length = 4096, encoding = 11 (Steim2). The defaults are triggered when msr.reclen and msr.encoding are set to -1.
[in] | msr | MS3Record containing data to pack |
[in] | record_handler() | Callback function called for each record |
[in] | handlerdata | A pointer that will be provided to the record_handler() |
[out] | packedsamples | The number of samples packed, returned to caller |
[in] | flags | Bit flags used to control the packing process:
|
[in] | verbose | Controls logging verbosity, 0 is no diagnostic output |
MessageOnError - this function logs a message on error
|
extern |
Repack a parsed miniSEED record into a version 3 record.
Pack the parsed header into a version 3 header and copy the raw encoded data from the original record. The original record must be available at the MS3Record.record pointer.
This can be used to efficiently convert format versions or modify header values without unpacking the data samples.
[in] | msr | MS3Record containing record to repack |
[out] | record | Destination buffer for repacked record |
[in] | recbuflen | Length of destination buffer |
[in] | verbose | Controls logging verbosity, 0 is no diagnostic output |
MessageOnError - this function logs a message on error
|
extern |
Pack a miniSEED version 3 header into the specified buffer.
Default values are: record length = 4096, encoding = 11 (Steim2). The defaults are triggered when msr.reclen and msr.encoding are set to -1.
[in] | msr | MS3Record to pack |
[out] | record | Destination for packed header |
[in] | recbuflen | Length of destination buffer |
[in] | verbose | Controls logging verbosity, 0 is no diagnostic output |
MessageOnError - this function logs a message on error
|
extern |
Pack a miniSEED version 2 header into the specified buffer.
Default values are: record length = 4096, encoding = 11 (Steim2). The defaults are triggered when msr.reclen and msr.encoding are set to -1.
[in] | msr | MS3Record to pack |
[out] | record | Destination for packed header |
[in] | recbuflen | Length of destination buffer |
[in] | verbose | Controls logging verbosity, 0 is no diagnostic output |
MessageOnError - this function logs a message on error
|
extern |
Unpack data samples for a MS3Record.
This routine can be used to unpack the data samples for a MS3Record that was earlier parsed without the data samples being decoded.
The packed/encoded data is accessed in the record indicated by MS3Record.record and the unpacked samples are placed in MS3Record.datasamples. The resulting data samples are either text characters, 32-bit integers, 32-bit floats or 64-bit floats in host byte order.
An internal buffer is allocated if the encoded data is not aligned for the sample size, which is a decent indicator of the alignment needed for decoding efficiently.
[in] | msr | Target MS3Record to unpack data samples |
[in] | verbose | Flag to control verbosity, 0 means no diagnostic output |
MessageOnError - this function logs a message on error
|
extern |
Determine the data payload bounds for a MS3Record.
Bounds are the starting offset in record and size. For miniSEED 2.x the raw record is expected to be located at the MS3Record.record pointer.
When the encoding is a fixed length per sample (text, integers, or floats), calculate the data size based on the sample count and use if less than size determined otherwise.
When the encoding is Steim1 or Steim2, search for 64-byte padding frames (all zeros) at the end of the payload and remove from the reported size.
[in] | msr | The MS3Record to determine payload bounds for |
[out] | dataoffset | Offset from start of record to start of payload |
[out] | datasize | Payload size in bytes |
MessageOnError - this function logs a message on error
|
extern |
Decode data samples to a supplied buffer.
[in] | input | Encoded data |
[in] | inputsize | Size of input buffer in bytes |
[in] | encoding | Data encoding |
[in] | samplecount | Number of samples to decode |
[out] | output | Decoded data |
[in] | outputsize | Size of output buffer in bytes |
[out] | sampletype | Pointer to (single character) sample type of decoded data |
[in] | swapflag | Flag indicating if encoded data needs swapping |
[in] | sid | Source identifier to include in diagnostic/error messages |
[in] | verbose | Flag to control verbosity, 0 means no diagnostic output |
MessageOnError - this function logs a message on error
Initialize and return an MS3Record.
Memory is allocated if for a new MS3Record if msr is NULL.
If memory for the datasamples
field has been allocated the pointer will be retained for reuse. If memory for extra headers has been allocated it will be released.
[in] | msr | A MS3Record to re-initialize |
MessageOnError - this function logs a message on error
|
extern |
Duplicate a MS3Record.
Extra headers are duplicated as well.
If the datadup flag is true (non-zero) and the source MS3Record has associated data samples copy them as well.
[in] | msr | MS3Record to duplicate |
[in] | datadup | Flag to control duplication of data samples |
MessageOnError - this function logs a message on error
Calculate time of the last sample in a record.
If leap seconds have been loaded into the internal library list: when a record completely contains a leap second, starts before and ends after, the calculated end time will be adjusted (reduced) by one second.
[in] | msr | MS3Record to calculate end time of |
|
extern |
|
extern |
Resize data sample buffer of MS3Record to what is needed.
This routine should only be used if pre-allocation of memory, via libmseed_prealloc_block_size, was enabled to allocate the buffer.
[in] | msr | MS3Record to resize buffer |
MessageOnError - this function logs a message on error
|
externinline |
|
extern |
Calculate data latency based on the host time.
Calculation is based on the time of the last sample in the record; in other words, the difference between the host time and the time of the last sample in the record.
Double precision is returned, but the true precision is dependent on the accuracy of the host system clock among other things.
[in] | msr | MS3Record to calculate latency for |
|
extern |
Detect miniSEED record in buffer.
Determine if the buffer contains a miniSEED data record by verifying known signatures (fields with known limited values).
If miniSEED 2.x is detected, search the record up to recbuflen bytes for a 1000 blockette. If no blockette 1000 is found, search at 64-byte offsets for the fixed section of the next header, thereby implying the record length.
[in] | record | Buffer to test for record |
[in] | recbuflen | Length of buffer |
[out] | formatversion | Major version of format detected, 0 if unknown |
-1 | Data record not detected or error |
0 | Data record detected but could not determine length |
>0 | Size of the record in bytes |
MessageOnError - this function logs a message on error
|
extern |
Parse and verify a miniSEED 3.x record header.
Parsing is done at the lowest level, printing error messages for invalid header values and optionally print raw header values.
The buffer at record is assumed to be a miniSEED record. Not every possible test is performed, common errors and those causing library parsing to fail should be detected.
This routine is primarily intended to diagnose invalid miniSEED headers.
[in] | record | Buffer to parse as miniSEED |
[in] | maxreclen | Maximum length to search in buffer |
[in] | details | Controls diagnostic output as follows:
|
MessageOnError - this function logs a message on error
|
extern |
Parse and verify a miniSEED 2.x record header.
Parsing is done at the lowest level, printing error messages for invalid header values and optionally print raw header values.
The buffer record is assumed to be a miniSEED record. Not every possible test is performed, common errors and those causing libmseed parsing to fail should be detected.
This routine is primarily intended to diagnose invalid miniSEED headers.
[in] | record | Buffer to parse as miniSEED |
[in] | maxreclen | Maximum length to search in buffer |
[in] | details | Controls diagnostic output as follows:
|
[in] | swapflag | Flag controlling byte-swapping as follows:
|
MessageOnError - this function logs a message on error