32#define LIBMSEED_VERSION "3.4.1"
33#define LIBMSEED_RELEASE "2026.167"
73#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
86#if defined(WIN64) || defined(_WIN64)
87#define PRIsize_t "I64u"
89#define PRIsize_t "I32u"
93#if defined(_MSC_VER) && _MSC_VER <= 1700
94typedef signed char int8_t;
95typedef unsigned char uint8_t;
96typedef signed short int int16_t;
97typedef unsigned short int uint16_t;
98typedef signed int int32_t;
99typedef unsigned int uint32_t;
100typedef signed __int64 int64_t;
101typedef unsigned __int64 uint64_t;
115#define snprintf _snprintf
116#define vsnprintf _vsnprintf
117#define strtoull _strtoui64
118#define fileno _fileno
122#define fdopen _fdopen
126#if defined(__MINGW32__) || defined(__MINGW64__)
129#define _fseeki64 fseeko64
130#define _ftelli64 ftello64
143#define MAXRECLEN 10485760
144#define MAXRECLENv2 131172
150#define MS_ISRATETOLERABLE(A, B) (fabs (1.0 - ((A) / (B))) < 0.0001)
154#define MS2_ISDATAINDICATOR(X) ((X) == 'D' || (X) == 'R' || (X) == 'Q' || (X) == 'M')
172#define MS3_ISVALIDHEADER(X) \
173 (*(X) == 'M' && *((X) + 1) == 'S' && *((X) + 2) == 3 && (uint8_t)(*((X) + 12)) >= 0 && \
174 (uint8_t)(*((X) + 12)) <= 23 && (uint8_t)(*((X) + 13)) >= 0 && (uint8_t)(*((X) + 13)) <= 59 && \
175 (uint8_t)(*((X) + 14)) >= 0 && (uint8_t)(*((X) + 14)) <= 60)
193#define MS2_ISVALIDHEADER(X) \
194 ((isdigit ((uint8_t)*(X)) || *(X) == ' ' || !*(X)) && \
195 (isdigit ((uint8_t)*((X) + 1)) || *((X) + 1) == ' ' || !*((X) + 1)) && \
196 (isdigit ((uint8_t)*((X) + 2)) || *((X) + 2) == ' ' || !*((X) + 2)) && \
197 (isdigit ((uint8_t)*((X) + 3)) || *((X) + 3) == ' ' || !*((X) + 3)) && \
198 (isdigit ((uint8_t)*((X) + 4)) || *((X) + 4) == ' ' || !*((X) + 4)) && \
199 (isdigit ((uint8_t)*((X) + 5)) || *((X) + 5) == ' ' || !*((X) + 5)) && \
200 MS2_ISDATAINDICATOR (*((X) + 6)) && (*((X) + 7) == ' ' || *((X) + 7) == '\0') && \
201 (uint8_t)(*((X) + 24)) >= 0 && (uint8_t)(*((X) + 24)) <= 23 && (uint8_t)(*((X) + 25)) >= 0 && \
202 (uint8_t)(*((X) + 25)) <= 59 && (uint8_t)(*((X) + 26)) >= 0 && (uint8_t)(*((X) + 26)) <= 60)
205#define bit(x, y) ((x) & (y)) ? 1 : 0
209#define DEPRECATED __declspec (deprecated)
210#elif defined(__GNUC__) | defined(__clang__)
211#define DEPRECATED __attribute__ ((__deprecated__))
234#define NSTMODULUS 1000000000
239#define NSTERROR -2145916800000000000LL
244#define NSTUNSET -2145916799999999999LL
248#define MS_EPOCH2NSTIME(X) (X) * (nstime_t)NSTMODULUS
252#define MS_NSTIME2EPOCH(X) (X) / NSTMODULUS
261#define MS_HPTIME2NSTIME(X) (X) * (nstime_t)1000
270#define MS_NSTIME2HPTIME(X) (X) / 1000
295 ISOMONTHDAY_DOY_Z = 3,
296 ISOMONTHDAY_SPACE = 4,
297 ISOMONTHDAY_SPACE_Z = 5,
329 uint8_t *min, uint8_t *sec, uint32_t *nsec);
340extern int ms_doy2md (
int year,
int yday,
int *month,
int *mday);
341extern int ms_md2doy (
int year,
int month,
int mday,
int *yday);
358#define MS_PACK_DEFAULT_RECLEN 4096
363#define MS_PACK_DEFAULT_ENCODING DE_STEIM2
400#define MS3Record_INITIALIZER \
405 .formatversion = 0, \
407 .starttime = NSTUNSET, \
416 .datasamples = NULL, \
421extern int msr3_parse (
const char *record, uint64_t recbuflen,
MS3Record **ppmsr, uint32_t flags,
424extern int msr3_pack (
const MS3Record *msr,
void (*record_handler) (
char *,
int,
void *),
425 void *handlerdata, int64_t *packedsamples, uint32_t flags, int8_t verbose);
450extern int64_t
ms_decode_data (
const void *input, uint64_t inputsize, uint8_t encoding,
451 uint64_t samplecount,
void *output, uint64_t outputsize,
452 char *sampletype, int8_t swapflag,
const char *sid, int8_t verbose);
464extern int64_t
ms3_detect (
const char *record, uint64_t recbuflen, uint8_t *formatversion);
465extern int ms_parse_raw3 (
const char *record,
int maxreclen, int8_t details);
466extern int ms_parse_raw2 (
const char *record,
int maxreclen, int8_t details, int8_t swapflag);
605#define MSTRACEID_SKIPLIST_HEIGHT 8
683#define MS3Tolerance_INITIALIZER {.time = NULL, .samprate = NULL}
691 int8_t autoheal, uint32_t flags,
const MS3Tolerance *tolerance);
694 int8_t autoheal, uint32_t flags,
697 int8_t splitversion, uint32_t flags,
const MS3Tolerance *tolerance,
700 uint64_t bufferlength, int8_t splitversion,
704 uint64_t outputsize, int8_t verbose);
708 void *handlerdata,
int reclen, int8_t encoding, int64_t *packedsamples,
709 uint32_t flags, int8_t verbose,
char *extra);
715 uint32_t flags, int8_t verbose,
char *extra,
716 uint32_t flush_idle_seconds);
721 void (*record_handler) (
char *,
int,
void *),
722 void *handlerdata,
int reclen, int8_t encoding,
723 int64_t *packedsamples, uint32_t flags,
724 int8_t verbose,
char *extra,
725 uint32_t flush_idle_seconds);
728 void (*record_handler) (
char *,
int,
void *),
void *handlerdata,
729 int reclen, int8_t encoding, int64_t *packedsamples,
730 uint32_t flags, int8_t verbose,
char *extra);
732 void (*) (
char *,
int,
void *),
void *,
int, int8_t,
733 int64_t *, uint32_t, int8_t,
char *);
735 int8_t details, int8_t gaps, int8_t versions);
739 double *mingap,
double *maxgap);
792#define LMIO_INITIALIZER {.type = LMIO_NULL, .handle = NULL, .handle2 = NULL, .still_running = 0}
818#define MS3FileParam_INITIALIZER \
824 .readbuffer = NULL, \
828 .input = LMIO_INITIALIZER}
832 uint32_t flags, int8_t verbose);
834 uint32_t flags,
const MS3Selections *selections, int8_t verbose);
836 const MS3Tolerance *tolerance, int8_t splitversion, uint32_t flags,
840 nstime_t endtime, int8_t splitversion, uint32_t flags,
845 uint32_t flags, int8_t verbose);
851 uint32_t flags, int8_t verbose);
853 int maxreclen, int8_t encoding, uint32_t flags, int8_t verbose);
858#define ms3_mstl_init_fd(fd) ms3_msfp_init_fd(fd)
870extern int ms_sid2nslc_n (
const char *sid,
char *net,
size_t netsize,
char *sta,
size_t stasize,
871 char *loc,
size_t locsize,
char *chan,
size_t chansize);
873extern int ms_nslc2sid (
char *sid,
int sidlen, uint16_t flags,
const char *net,
const char *sta,
874 const char *loc,
const char *chan);
877extern int ms_strncpclean (
char *dest,
const char *source,
int length);
879extern int ms_strncpopen (
char *dest,
const char *source,
int length);
1018#define mseh_get(msr, ptr, valueptr, type, maxlength) \
1019 mseh_get_ptr_r (msr, ptr, valueptr, type, maxlength, NULL)
1023#define mseh_get_uint64(msr, ptr, valueptr) mseh_get_ptr_r (msr, ptr, valueptr, 'u', 0, NULL)
1027#define mseh_get_int64(msr, ptr, valueptr) mseh_get_ptr_r (msr, ptr, valueptr, 'i', 0, NULL)
1031#define mseh_get_number(msr, ptr, valueptr) mseh_get_ptr_r (msr, ptr, valueptr, 'n', 0, NULL)
1035#define mseh_get_string(msr, ptr, buffer, maxlength) \
1036 mseh_get_ptr_r (msr, ptr, buffer, 's', maxlength, NULL)
1040#define mseh_get_boolean(msr, ptr, valueptr) mseh_get_ptr_r (msr, ptr, valueptr, 'b', 0, NULL)
1044#define mseh_exists(msr, ptr) (!mseh_get_ptr_r (msr, ptr, NULL, 0, 0, NULL))
1051#define mseh_set(msr, ptr, valueptr, type) mseh_set_ptr_r (msr, ptr, valueptr, type, NULL)
1055#define mseh_set_uint64(msr, ptr, valueptr) mseh_set_ptr_r (msr, ptr, valueptr, 'u', NULL)
1059#define mseh_set_int64(msr, ptr, valueptr) mseh_set_ptr_r (msr, ptr, valueptr, 'i', NULL)
1063#define mseh_set_number(msr, ptr, valueptr) mseh_set_ptr_r (msr, ptr, valueptr, 'n', NULL)
1067#define mseh_set_string(msr, ptr, valueptr) mseh_set_ptr_r (msr, ptr, valueptr, 's', NULL)
1071#define mseh_set_boolean(msr, ptr, valueptr) mseh_set_ptr_r (msr, ptr, valueptr, 'b', NULL)
1203#define MAX_LOG_MSG_LENGTH 200
1228#define MSLogRegistry_INITIALIZER {.maxmessages = 0, .messagecnt = 0, .messages = NULL}
1246#define MSLogParam_INITIALIZER \
1247 {.log_print = NULL, \
1248 .logprefix = NULL, \
1249 .diag_print = NULL, \
1250 .errprefix = NULL, \
1251 .registry = MSLogRegistry_INITIALIZER}
1256#define ms_log(level, ...) ms_rlog (__func__, level, __VA_ARGS__)
1261#define ms_log_l(logp, level, ...) ms_rlog_l (logp, __func__, level, __VA_ARGS__)
1263#if defined(__GNUC__) || defined(__clang__)
1264__attribute__ ((__format__ (__printf__, 3, 4)))
1267ms_rlog (
const char *function,
int level,
const char *format, ...);
1268#if defined(__GNUC__) || defined(__clang__)
1269__attribute__ ((__format__ (__printf__, 4, 5)))
1276#define ms_loginit(log_print, logprefix, diag_print, errprefix) \
1277 ms_rloginit (log_print, logprefix, diag_print, errprefix, 0)
1281#define ms_loginit_l(logp, log_print, logprefix, diag_print, errprefix) \
1282 ms_rloginit_l (logp, log_print, logprefix, diag_print, errprefix, 0)
1284extern void ms_rloginit (
void (*log_print) (
const char *),
const char *logprefix,
1285 void (*diag_print) (
const char *),
const char *errprefix,
int maxmessages);
1287 const char *logprefix,
void (*diag_print) (
const char *),
1288 const char *errprefix,
int maxmessages);
1353#define ms_dabs(val) fabs (val)
1358extern int lmp_fseek64 (FILE *stream, int64_t offset,
int whence);
1367extern uint32_t
ms_crc32c (
const uint8_t *input,
int length, uint32_t previousCRC32C);
1371ms_gswap2 (
void *data2)
1375 memcpy (&dat, data2, 2);
1377 dat = (uint16_t)(((dat & 0xff00) >> 8) | ((dat & 0x00ff) << 8));
1379 memcpy (data2, &dat, 2);
1384ms_gswap4 (
void *data4)
1388 memcpy (&dat, data4, 4);
1390 dat = ((dat & 0xff000000) >> 24) | ((dat & 0x000000ff) << 24) | ((dat & 0x00ff0000) >> 8) |
1391 ((dat & 0x0000ff00) << 8);
1393 memcpy (data4, &dat, 4);
1398ms_gswap8 (
void *data8)
1402 memcpy (&dat, data8,
sizeof (uint64_t));
1404 dat = ((dat & 0xff00000000000000) >> 56) | ((dat & 0x00000000000000ff) << 56) |
1405 ((dat & 0x00ff000000000000) >> 40) | ((dat & 0x000000000000ff00) << 40) |
1406 ((dat & 0x0000ff0000000000) >> 24) | ((dat & 0x0000000000ff0000) << 24) |
1407 ((dat & 0x000000ff00000000) >> 8) | ((dat & 0x00000000ff000000) << 8);
1409 memcpy (data8, &dat,
sizeof (uint64_t));
1412#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) || defined(__clang__)
1414__attribute__ ((deprecated (
"Use ms_gswap2 instead."))) static inline
void
1415ms_gswap2a (
void *data2)
1420__attribute__ ((deprecated (
"Use ms_gswap4 instead."))) static inline
void
1421ms_gswap4a (
void *data4)
1426__attribute__ ((deprecated (
"Use ms_gswap8 instead."))) static inline
void
1427ms_gswap8a (
void *data8)
1431#elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320)
1433__declspec (deprecated (
"Use ms_gswap2 instead.")) static inline
void
1434ms_gswap2a (
void *data2)
1439__declspec (deprecated (
"Use ms_gswap4 instead.")) static inline
void
1440ms_gswap4a (
void *data4)
1445__declspec (deprecated (
"Use ms_gswap8 instead.")) static inline
void
1446ms_gswap8a (
void *data8)
1453ms_gswap2a (
void *data2)
1459ms_gswap4a (
void *data4)
1465ms_gswap8a (
void *data8)
1502 void *(*malloc) (size_t);
1503 void *(*realloc) (
void *, size_t);
1533#define DE_ASCII DE_TEXT
1550#define DE_GEOSCOPE24 12
1551#define DE_GEOSCOPE163 13
1552#define DE_GEOSCOPE164 14
1564#define MSSWAP_HEADER 0x01
1565#define MSSWAP_PAYLOAD 0x02
1573#define MS_ENDOFFILE 1
1575#define MS_GENERROR -1
1576#define MS_NOTSEED -2
1577#define MS_WRONGLENGTH -3
1578#define MS_OUTOFRANGE -4
1579#define MS_UNKNOWNFORMAT -5
1580#define MS_STBADCOMPFLAG -6
1581#define MS_INVALIDCRC -7
1591#define MSF_UNPACKDATA 0x0001
1592#define MSF_SKIPNOTDATA 0x0002
1593#define MSF_VALIDATECRC 0x0004
1594#define MSF_PNAMERANGE 0x0008
1595#define MSF_ATENDOFFILE 0x0010
1596#define MSF_SEQUENCE 0x0020
1597#define MSF_FLUSHDATA \
1599#define MSF_PACKVER2 0x0080
1600#define MSF_RECORDLIST 0x0100
1601#define MSF_MAINTAINMSTL 0x0200
1602#define MSF_PPUPDATETIME \
1604#define MSF_SPLITISVERSION \
1606#define MSF_SKIPADJACENTDUPLICATES 0x1000
struct MS3SelectTime * next
Pointer to next selection time, NULL if the last.
Definition libmseed.h:490
nstime_t endtime
Latest data for matching channels, use NSTUNSET for open.
Definition libmseed.h:489
uint8_t pubversion
Selected publication version, use 0 for any.
Definition libmseed.h:499
char sidpattern[100]
Matching (globbing) pattern for source ID.
Definition libmseed.h:496
struct MS3Selections * next
Pointer to next selection, NULL if the last.
Definition libmseed.h:498
nstime_t starttime
Earliest data for matching channels, use NSTUNSET for open.
Definition libmseed.h:488
struct MS3SelectTime * timewindows
Pointer to time window list for this source ID.
Definition libmseed.h:497
int ms3_addselect(MS3Selections **ppselections, const char *sidpattern, nstime_t starttime, nstime_t endtime, uint8_t pubversion)
Add selection parameters to selection list.
Definition selection.c:185
int ms3_readselectionsfile(MS3Selections **ppselections, const char *filename)
Read data selections from a file.
Definition selection.c:431
void ms3_printselections(const MS3Selections *selections)
Print the selections list using the ms_log() facility.
Definition selection.c:706
void ms3_freeselections(MS3Selections *selections)
Free all memory associated with a MS3Selections.
Definition selection.c:664
const MS3Selections * ms3_matchselect(const MS3Selections *selections, const char *sid, nstime_t starttime, nstime_t endtime, int pubversion, const MS3SelectTime **ppselecttime)
Test the specified parameters for a matching selection entry.
Definition selection.c:58
int ms3_addselect_comp(MS3Selections **ppselections, char *network, char *station, char *location, char *channel, nstime_t starttime, nstime_t endtime, uint8_t pubversion)
Add selection parameters to a selection list based on separate source name codes.
Definition selection.c:310
const MS3Selections * msr3_matchselect(const MS3Selections *selections, const MS3Record *msr, const MS3SelectTime **ppselecttime)
Test the MS3Record for a matching selection entry.
Definition selection.c:149
Data selection structure time window definition containers.
Definition libmseed.h:487
Data selection structure definition containers.
Definition libmseed.h:495
int readlength
INTERNAL: Length of data in read buffer.
Definition libmseed.h:810
int64_t streampos
OUTPUT: Read position of input stream.
Definition libmseed.h:806
int64_t endoffset
INPUT: End position in input stream, 0 == unknown (e.g. pipe).
Definition libmseed.h:805
int64_t recordcount
OUTPUT: Count of records read from this stream/file so far.
Definition libmseed.h:807
LMIO input
INTERNAL: IO handle, file or URL.
Definition libmseed.h:813
uint32_t flags
INTERNAL: Stream reading state flags.
Definition libmseed.h:812
char path[512]
INPUT: File name or URL.
Definition libmseed.h:803
int readoffset
INTERNAL: Read offset in read buffer.
Definition libmseed.h:811
char * readbuffer
INTERNAL: Read buffer, allocated internally.
Definition libmseed.h:809
int64_t startoffset
INPUT: Start position in input stream.
Definition libmseed.h:804
int ms3_readtracelist(MS3TraceList **ppmstl, const char *mspath, const MS3Tolerance *tolerance, int8_t splitversion, uint32_t flags, int8_t verbose)
Read miniSEED from a file into a trace list.
Definition fileutils.c:692
int ms3_readtracelist_selection(MS3TraceList **ppmstl, const char *mspath, const MS3Tolerance *tolerance, const MS3Selections *selections, int8_t splitversion, uint32_t flags, int8_t verbose)
Read miniSEED from a file into a trace list, with selection filtering.
Definition fileutils.c:784
void ms3_url_freeheaders(void)
Free all set headers for URL-based requests.
Definition fileutils.c:968
int ms3_readmsr_r(MS3FileParam **ppmsfp, MS3Record **ppmsr, const char *mspath, uint32_t flags, int8_t verbose)
Definition fileutils.c:650
int ms3_url_addheader(const char *header)
Add header to any URL-based requests.
Definition fileutils.c:948
int libmseed_url_support(void)
Run-time test for URL support in libmseed.
Definition fileutils.c:49
MS3FileParam * ms3_msfp_init_fd(int fd)
Initialize MS3FileParam parameters for a file descriptor.
Definition fileutils.c:78
int ms3_readmsr(MS3Record **ppmsr, const char *mspath, uint32_t flags, int8_t verbose)
Read miniSEED records from a file or URL.
Definition fileutils.c:628
int ms3_readtracelist_timewin(MS3TraceList **ppmstl, const char *mspath, const MS3Tolerance *tolerance, nstime_t starttime, nstime_t endtime, int8_t splitversion, uint32_t flags, int8_t verbose)
Read miniSEED from a file into a trace list, with time range selection.
Definition fileutils.c:716
MS3FileParam * ms3_msfp_init(int64_t startoffset, int64_t endoffset, int fd)
Initialize MS3FileParam parameters.
Definition fileutils.c:109
int ms3_readmsr_selection(MS3FileParam **ppmsfp, MS3Record **ppmsr, const char *mspath, uint32_t flags, const MS3Selections *selections, int8_t verbose)
Definition fileutils.c:670
int ms3_url_userpassword(const char *userpassword)
Set authentication credentials for URL-based requests.
Definition fileutils.c:919
int64_t msr3_writemseed(MS3Record *msr, const char *mspath, int8_t overwrite, uint32_t flags, int8_t verbose)
Write miniSEED from an MS3Record container to a file.
Definition fileutils.c:1007
int64_t mstl3_writemseed(MS3TraceList *mstl, const char *mspath, int8_t overwrite, int maxreclen, int8_t encoding, uint32_t flags, int8_t verbose)
Write miniSEED from an MS3TraceList container to a file.
Definition fileutils.c:1115
int ms3_url_useragent(const char *program, const char *version)
Set User-Agent header for URL-based requests.
Definition fileutils.c:889
State container for reading miniSEED records from files or URLs.
Definition libmseed.h:802
int32_t TAIdelta
TAI-UTC difference in seconds.
Definition libmseed.h:1330
nstime_t leapsecond
Time of leap second as epoch since 1 January 1900.
Definition libmseed.h:1329
struct LeapSecond * next
Pointer to next entry, NULL if the last.
Definition libmseed.h:1331
LeapSecond * leapsecondlist
int ms_readleapsecondfile(const char *filename)
Read leap second from the specified file.
Definition genutils.c:1876
int ms_readleapseconds(const char *envvarname)
Read leap second file specified by an environment variable.
Definition genutils.c:1847
Leap second list container.
Definition libmseed.h:1328
void(* diag_print)(const char *)
Function to call for diagnostic and error messages.
Definition libmseed.h:1239
char message[MAX_LOG_MSG_LENGTH]
Log, warning or error message.
Definition libmseed.h:1212
char function[30]
Function generating the message.
Definition libmseed.h:1211
void(* log_print)(const char *)
Function to call for regular messages.
Definition libmseed.h:1237
int level
Message level.
Definition libmseed.h:1210
const char * logprefix
Message prefix for regular and diagnostic messages.
Definition libmseed.h:1238
const char * errprefix
Message prefix for error messages.
Definition libmseed.h:1240
MSLogRegistry registry
Message registry.
Definition libmseed.h:1241
int ms_rlog_l(MSLogParam *logp, const char *function, int level, const char *format,...)
Register log message using specified logging parameters.
Definition logging.c:299
MSLogParam * ms_rloginit_l(MSLogParam *logp, void(*log_print)(const char *), const char *logprefix, void(*diag_print)(const char *), const char *errprefix, int maxmessages)
Initialize specified MSLogParam logging parameters.
Definition logging.c:128
#define MAX_LOG_MSG_LENGTH
Definition libmseed.h:1203
int ms_rlog_pop(MSLogParam *logp, char *message, size_t size, int context)
Pop error and warning messages from log registry.
Definition logging.c:641
int ms_rlog_free(MSLogParam *logp)
Free, without emitting, all messages from log registry.
Definition logging.c:693
void ms_rloginit(void(*log_print)(const char *), const char *logprefix, void(*diag_print)(const char *), const char *errprefix, int maxmessages)
Initialize the global logging parameters.
Definition logging.c:88
int ms_rlog(const char *function, int level, const char *format,...)
Register log message using global logging parameters.
Definition logging.c:247
int ms_rlog_emit(MSLogParam *logp, int count, int context)
Emit, aka send to print functions, messages from log registry.
Definition logging.c:564
Log registry entry.
Definition libmseed.h:1209
Logging parameters. Callers should not modify these values directly and generally should not need to ...
Definition libmseed.h:1236
Log message registry.
Definition libmseed.h:1220
void(* free)(void *)
Pointer to desired free().
Definition libmseed.h:1504
LIBMSEED_MEMORY libmseed_memory
void * libmseed_memory_prealloc(void *ptr, size_t size, size_t *currentsize)
size_t libmseed_prealloc_block_size
Definition libmseed.h:1501
uint8_t swapflag
Byte swap indicator (bitmask), see Byte swap flags.
Definition libmseed.h:374
void * datasamples
Data samples, numsamples of type sampletype.
Definition libmseed.h:391
uint32_t datalength
Length of data payload in bytes.
Definition libmseed.h:387
uint32_t crc
CRC of entire record.
Definition libmseed.h:385
uint8_t formatversion
Format major version.
Definition libmseed.h:378
int32_t reclen
Length of miniSEED record in bytes.
Definition libmseed.h:373
uint8_t flags
Record-level bit flags.
Definition libmseed.h:379
uint16_t extralength
Length of extra headers in bytes.
Definition libmseed.h:386
uint64_t datasize
Size of datasamples buffer in bytes.
Definition libmseed.h:392
const char * record
Raw miniSEED record, if available.
Definition libmseed.h:372
double samprate
Nominal sample rate as samples/second (Hz) or period (s).
Definition libmseed.h:381
int64_t numsamples
Number of data samples in datasamples.
Definition libmseed.h:393
int64_t samplecnt
Number of samples in record.
Definition libmseed.h:384
char sampletype
Sample type code: t, i, f, d Sample Types.
Definition libmseed.h:394
int16_t encoding
Data encoding format, see Data Encodings.
Definition libmseed.h:382
nstime_t starttime
Record start time (first sample).
Definition libmseed.h:380
char sid[LM_SIDLEN]
Source identifier as URN, max length LM_SIDLEN.
Definition libmseed.h:377
uint8_t pubversion
Publication version.
Definition libmseed.h:383
char * extra
Pointer to extra headers.
Definition libmseed.h:388
int64_t ms3_detect(const char *record, uint64_t recbuflen, uint8_t *formatversion)
Detect miniSEED record in buffer.
Definition parseutils.c:175
MS3RecordPacker * msr3_pack_init(const MS3Record *msr, uint32_t flags, int8_t verbose)
Initialize a packer for generator-style record creation.
Definition pack.c:180
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.
Definition pack.c:638
struct MS3RecordPacker MS3RecordPacker
Opaque packing context for MS3Record generator-style interface.
Definition libmseed.h:428
void msr3_print(const MS3Record *msr, int8_t details)
Print header values of an MS3Record.
Definition msrutils.c:225
MS3Record * msr3_init(MS3Record *msr)
Initialize and return an MS3Record.
Definition msrutils.c:44
double msr3_sampratehz(const MS3Record *msr)
Calculate sample rate in samples/second (Hertz) for a given MS3Record.
Definition msrutils.c:343
int64_t msr3_unpack_data(MS3Record *msr, int8_t verbose)
Unpack data samples for a MS3Record.
Definition unpack.c:1215
double msr3_host_latency(const MS3Record *msr)
Calculate data latency based on the host time.
Definition msrutils.c:393
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.
Definition pack.c:966
void msr3_free(MS3Record **ppmsr)
Free all memory associated with a MS3Record.
Definition msrutils.c:86
int ms_parse_raw3(const char *record, int maxreclen, int8_t details)
Parse and verify a miniSEED 3.x record header.
Definition parseutils.c:330
int msr3_resize_buffer(MS3Record *msr)
Resize data sample buffer of MS3Record to what is needed.
Definition msrutils.c:301
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.
Definition unpack.c:1370
int msr3_parse(const char *record, uint64_t recbuflen, MS3Record **ppmsr, uint32_t flags, int8_t verbose)
Parse miniSEED from a buffer.
Definition parseutils.c:61
int msr3_repack_mseed2(const MS3Record *msr, char *record, uint32_t recbuflen, int8_t verbose)
Repack a parsed miniSEED record into a version 2 record.
Definition pack.c:855
int msr3_pack_next(MS3RecordPacker *packer, char **record, int32_t *reclen)
Generate next miniSEED record.
Definition pack.c:381
MS3Record * msr3_duplicate(const MS3Record *msr, int8_t datadup)
Duplicate a MS3Record.
Definition msrutils.c:118
nstime_t msr3_endtime(const MS3Record *msr)
Calculate time of the last sample in a record.
Definition msrutils.c:200
void msr3_pack_free(MS3RecordPacker **packer, int64_t *packedsamples)
Free packer and resources.
Definition pack.c:600
int ms_parse_raw2(const char *record, int maxreclen, int8_t details, int8_t swapflag)
Parse and verify a miniSEED 2.x record header.
Definition parseutils.c:534
nstime_t msr3_nsperiod(const MS3Record *msr)
Calculate sample period in nanoseconds/sample for a given MS3Record.
Definition msrutils.c:362
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.
Definition pack.c:733
int msr3_data_bounds(const MS3Record *msr, uint32_t *dataoffset, uint32_t *datasize)
Determine the data payload bounds for a MS3Record.
Definition unpack.c:1102
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 using a callback function to handle the records.
Definition pack.c:113
miniSEED record container
Definition libmseed.h:371
struct MS3RecordPtr * next
Pointer to next entry, NULL if the last.
Definition libmseed.h:556
void * prvtptr
Private pointer, will not be populated by library but will be free'd.
Definition libmseed.h:555
MS3RecordPtr * last
Pointer to last entry, NULL if the none.
Definition libmseed.h:564
int64_t fileoffset
Offset into file to record for fileptr or filename.
Definition libmseed.h:551
const char * filename
Pointer (borrowed) to file name containing record, NULL if not used.
Definition libmseed.h:550
MS3RecordPtr * first
Pointer to first entry, NULL if the none.
Definition libmseed.h:563
MS3Record * msr
Pointer to MS3Record for this record.
Definition libmseed.h:552
const char * bufferptr
Pointer in buffer to record, NULL if not used.
Definition libmseed.h:548
FILE * fileptr
Pointer to open FILE containing record, NULL if not used.
Definition libmseed.h:549
uint64_t recordcnt
Count of records in the list (for convenience).
Definition libmseed.h:562
nstime_t endtime
End time of record, time of last sample.
Definition libmseed.h:553
uint32_t dataoffset
Offset from start of record to encoded data.
Definition libmseed.h:554
Record list, holds MS3RecordPtr entries that contribute to a given MS3TraceSeg.
Definition libmseed.h:561
A miniSEED record pointer and metadata.
Definition libmseed.h:547
int ms_sid2nslc_n(const char *sid, char *net, size_t netsize, char *sta, size_t stasize, char *loc, size_t locsize, char *chan, size_t chansize)
Parse network, station, location and channel codes from an FDSN Source ID.
Definition genutils.c:243
int ms_strncpopen(char *dest, const char *source, int length)
Copy fixed number of characters into unterminated string.
Definition genutils.c:808
DEPRECATED int ms_sid2nslc(const char *sid, char *net, char *sta, char *loc, char *chan)
Definition genutils.c:360
int ms_strncpclean(char *dest, const char *source, int length)
Copy string, removing spaces, always terminated.
Definition genutils.c:702
int ms_xchan2seedchan(char *seedchan, const char *xchan)
Convert extended channel to SEED 2.x channel.
Definition genutils.c:592
int ms_seedchan2xchan(char *xchan, const char *seedchan)
Convert SEED 2.x channel to extended channel.
Definition genutils.c:537
int ms_strncpcleantail(char *dest, const char *source, int length)
Copy string, removing trailing spaces, always terminated.
Definition genutils.c:756
int ms_nslc2sid(char *sid, int sidlen, uint16_t flags, const char *net, const char *sta, const char *loc, const char *chan)
Convert network, station, location and channel to an FDSN Source ID.
Definition genutils.c:398
struct MS3TraceID * next[MSTRACEID_SKIPLIST_HEIGHT]
Next trace ID at first pointer, NULL if the last.
Definition libmseed.h:636
int64_t numsamples
Number of data samples in datasamples.
Definition libmseed.h:616
struct MS3RecordList * recordlist
List of pointers to records that contributed.
Definition libmseed.h:620
uint64_t prngstate
INTERNAL: State for Pseudo RNG.
Definition libmseed.h:646
nstime_t endtime
Time of last sample.
Definition libmseed.h:611
struct MS3TraceSeg * first
Pointer to first of list of segments.
Definition libmseed.h:634
nstime_t latest
Time of latest sample.
Definition libmseed.h:631
struct MS3TraceID traces
Head node of trace skip list, first entry at traces.next[0].
Definition libmseed.h:645
uint8_t pubversion
Largest contributing publication version.
Definition libmseed.h:629
void * prvtptr
Definition libmseed.h:618
uint8_t height
Height of skip list at next.
Definition libmseed.h:638
uint64_t datasize
Size of datasamples buffer in bytes.
Definition libmseed.h:615
nstime_t earliest
Time of earliest sample.
Definition libmseed.h:630
double(* samprate)(const MS3Record *msr)
Pointer to function that returns sample rate tolerance.
Definition libmseed.h:677
void * prvtptr
Private pointer for general use, unused by library.
Definition libmseed.h:632
void * datasamples
Data samples, numsamples of type sampletype.
Definition libmseed.h:614
char sampletype
Sample type code, see Sample Types.
Definition libmseed.h:617
struct MS3TraceSeg * prev
Pointer to previous segment.
Definition libmseed.h:621
int64_t samplecnt
Number of samples in trace coverage.
Definition libmseed.h:613
char sid[LM_SIDLEN]
Source identifier as URN, max length LM_SIDLEN.
Definition libmseed.h:628
struct MS3TraceSeg * last
Pointer to last of list of segments.
Definition libmseed.h:635
uint32_t numtraceids
Number of traces IDs in list.
Definition libmseed.h:644
double(* time)(const MS3Record *msr)
Pointer to function that returns time tolerance.
Definition libmseed.h:676
double samprate
Nominal sample rate (Hz).
Definition libmseed.h:612
struct MS3TraceSeg * next
Pointer to next segment, NULL if the last.
Definition libmseed.h:622
nstime_t starttime
Time of first sample.
Definition libmseed.h:610
uint32_t numsegments
Number of segments for this ID.
Definition libmseed.h:633
int64_t mstl3_unpack_recordlist(MS3TraceID *id, MS3TraceSeg *seg, void *output, uint64_t outputsize, int8_t verbose)
Unpack data samples in a Record List associated with a MS3TraceList.
Definition tracelist.c:1692
void mstl3_printsynclist(const MS3TraceList *mstl, const char *dccid, ms_subseconds_t subseconds)
Print SYNC trace list summary information for a MS3TraceList.
Definition tracelist.c:2936
void mstl3_printtracelist(const MS3TraceList *mstl, ms_timeformat_t timeformat, int8_t details, int8_t gaps, int8_t versions)
Print trace list summary information for a MS3TraceList.
Definition tracelist.c:2801
int64_t mstl3_pack(MS3TraceList *mstl, void(*record_handler)(char *, int, void *), void *handlerdata, int reclen, int8_t encoding, int64_t *packedsamples, uint32_t flags, int8_t verbose, char *extra)
Pack MS3TraceList data into miniSEED records.
Definition tracelist.c:2116
void mstl3_free(MS3TraceList **ppmstl, int8_t freeprvtptr)
Free all memory associated with a MS3TraceList.
Definition tracelist.c:102
MS3TraceSeg * mstl3_addmsr(MS3TraceList *mstl, const MS3Record *msr, int8_t splitversion, int8_t autoheal, uint32_t flags, const MS3Tolerance *tolerance)
Add data coverage from an MS3Record to a MS3TraceList.
Definition tracelist.c:787
int64_t mstl3_readbuffer(MS3TraceList **ppmstl, const char *buffer, uint64_t bufferlength, int8_t splitversion, uint32_t flags, const MS3Tolerance *tolerance, int8_t verbose)
Parse miniSEED from a buffer and populate a MS3TraceList.
Definition tracelist.c:851
int mstl3_pack_next(MS3TraceListPacker *packer, uint32_t flags, char **record, int32_t *reclen)
Generate next miniSEED record from trace list packing state.
Definition tracelist.c:2246
void mstl3_printgaplist(const MS3TraceList *mstl, ms_timeformat_t timeformat, double *mingap, double *maxgap)
Print gap/overlap list summary information for a MS3TraceList.
Definition tracelist.c:3016
int64_t mstl3_pack_segment(MS3TraceList *mstl, MS3TraceID *id, MS3TraceSeg *seg, void(*record_handler)(char *, int, void *), void *handlerdata, int reclen, int8_t encoding, int64_t *packedsamples, uint32_t flags, int8_t verbose, char *extra)
Pack a MS3TraceSeg data into miniSEED records.
Definition tracelist.c:2623
int mstl3_resize_buffers(MS3TraceList *mstl)
Resize data sample buffers of MS3TraceList to what is needed.
Definition tracelist.c:1600
int64_t mstl3_readbuffer_selection(MS3TraceList **ppmstl, const char *buffer, uint64_t bufferlength, int8_t splitversion, uint32_t flags, const MS3Tolerance *tolerance, const MS3Selections *selections, int8_t verbose)
Parse miniSEED from a buffer and populate a MS3TraceList.
Definition tracelist.c:899
struct MS3TraceListPacker MS3TraceListPacker
Opaque packing context for MS3TraceList generator-style interface.
Definition libmseed.h:712
int64_t mstl3_pack_ppupdate_flushidle(MS3TraceList *mstl, void(*record_handler)(char *, int, void *), void *handlerdata, int reclen, int8_t encoding, int64_t *packedsamples, uint32_t flags, int8_t verbose, char *extra, uint32_t flush_idle_seconds)
Definition tracelist.c:2135
DEPRECATED int64_t mstraceseg3_pack(MS3TraceID *, MS3TraceSeg *, void(*)(char *, int, void *), void *, int, int8_t, int64_t *, uint32_t, int8_t, char *)
Definition tracelist.c:2769
int mstl3_convertsamples(MS3TraceSeg *seg, char type, int8_t truncate)
Convert the data samples associated with an MS3TraceSeg to another data type.
Definition tracelist.c:1444
MS3TraceList * mstl3_init(MS3TraceList *mstl)
Initialize a MS3TraceList container.
Definition tracelist.c:67
#define MSTRACEID_SKIPLIST_HEIGHT
Maximum skip list height for MSTraceIDs.
Definition libmseed.h:605
MS3TraceID * mstl3_findID(MS3TraceList *mstl, const char *sid, uint8_t pubversion, MS3TraceID **prev)
Find matching MS3TraceID in a MS3TraceList.
Definition tracelist.c:163
void mstl3_pack_free(MS3TraceListPacker **packer, int64_t *packedsamples)
Free trace list packing state and resources.
Definition tracelist.c:2548
MS3TraceListPacker * mstl3_pack_init(MS3TraceList *mstl, int reclen, int8_t encoding, uint32_t flags, int8_t verbose, char *extra, uint32_t flush_idle_seconds)
Initialize a packing state for generator-style trace list packing.
Definition tracelist.c:2179
MS3TraceSeg * mstl3_addmsr_recordptr(MS3TraceList *mstl, const MS3Record *msr, MS3RecordPtr **pprecptr, int8_t splitversion, int8_t autoheal, uint32_t flags, const MS3Tolerance *tolerance)
Definition tracelist.c:809
Callback functions that return time and sample rate tolerances.
Definition libmseed.h:675
Container for a trace ID, linkable.
Definition libmseed.h:627
Container for a collection of continuous trace segment, linkable.
Definition libmseed.h:643
Container for a continuous trace segment, linkable.
Definition libmseed.h:609
uint32_t ms_crc32c(const uint8_t *input, int length, uint32_t previousCRC32C)
int ms_encoding_sizetype(uint8_t encoding, uint8_t *samplesize, char *sampletype)
Return sample size and/or type for given encoding value.
Definition lookup.c:74
uint8_t ms_samplesize(char sampletype)
Determine data sample size for each type.
Definition lookup.c:39
int ms_bigendianhost(void)
Runtime test for host endianess.
Definition genutils.c:1823
uint64_t lmp_nanosleep(uint64_t nanoseconds)
Sleep for a specified number of nanoseconds.
Definition genutils.c:2045
nstime_t ms_sampletime(nstime_t time, int64_t offset, double samprate)
Calculate the time of a sample in an array.
Definition genutils.c:1784
int lmp_fseek64(FILE *stream, int64_t offset, int whence)
Definition genutils.c:2023
int64_t lmp_ftell64(FILE *stream)
Definition genutils.c:2007
const char * ms_encodingstr(uint8_t encoding)
Descriptive string for data encodings.
Definition lookup.c:126
const char * ms_errorstr(int errorcode)
Descriptive string for library Return codes.
Definition lookup.c:205
nstime_t lmp_systemtime(void)
Return the current system time.
Definition genutils.c:2078
int lmp_strncasecmp(const char *s1, const char *s2, size_t n)
Case-insensitive, ASCII-only string comparison.
Definition genutils.c:2125
int8_t flag
Definition libmseed.h:1474
#define LM_SIDLEN
Length of source ID string.
Definition libmseed.h:146
#define DEPRECATED
Definition libmseed.h:213
Type definition for data source I/O: file-system versus URL.
Definition libmseed.h:777
void * handle
Primary IO handle, either file or URL.
Definition libmseed.h:785
void * handle2
Secondary IO handle for URL.
Definition libmseed.h:786
int still_running
Fetch status flag for URL transmissions.
Definition libmseed.h:787
enum LMIO::@254045037044215310213377126306215005316170340112 type
IO handle type.
@ LMIO_FD
IO handle is a provided file descriptor.
Definition libmseed.h:783
@ LMIO_URL
IO handle is URL-type.
Definition libmseed.h:782
@ LMIO_NULL
IO handle type is undefined.
Definition libmseed.h:780
@ LMIO_FILE
IO handle is FILE-type.
Definition libmseed.h:781