libmseed 3.1.9
The miniSEED data format library
Loading...
Searching...
No Matches
libmseed.h
Go to the documentation of this file.
1
23
24#ifndef LIBMSEED_H
25#define LIBMSEED_H 1
26
27#ifdef __cplusplus
28extern "C"
29{
30#endif
31
32#define LIBMSEED_VERSION "3.1.9"
33#define LIBMSEED_RELEASE "2025.267"
34
46
59
60/* C99 standard headers */
61#include <ctype.h>
62#include <math.h>
63#include <stdarg.h>
64#include <stdio.h>
65#include <stdlib.h>
66#include <string.h>
67#include <time.h>
68
71#define PRIsize_t "zu"
72
73#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
74#define LMP_WIN 1
75#endif
76
77/* Set platform specific features, Windows versus everything else */
78#if defined(LMP_WIN)
79#include <sys/timeb.h>
80#include <sys/types.h>
81#include <windows.h>
82
83/* Re-define print conversion for size_t values */
84#undef PRIsize_t
85#if defined(WIN64) || defined(_WIN64)
86#define PRIsize_t "I64u"
87#else
88#define PRIsize_t "I32u"
89#endif
90
91/* For MSVC 2012 and earlier define standard int types, otherwise use inttypes.h */
92#if defined(_MSC_VER) && _MSC_VER <= 1700
93typedef signed char int8_t;
94typedef unsigned char uint8_t;
95typedef signed short int int16_t;
96typedef unsigned short int uint16_t;
97typedef signed int int32_t;
98typedef unsigned int uint32_t;
99typedef signed __int64 int64_t;
100typedef unsigned __int64 uint64_t;
101#else
102#include <inttypes.h>
103#endif
104
105/* For MSVC define PRId64 and SCNd64 and alternate functions */
106#if defined(_MSC_VER)
107#if !defined(PRId64)
108#define PRId64 "I64d"
109#endif
110#if !defined(SCNd64)
111#define SCNd64 "I64d"
112#endif
113
114#define snprintf _snprintf
115#define vsnprintf _vsnprintf
116#define strcasecmp _stricmp
117#define strncasecmp _strnicmp
118#define strtoull _strtoui64
119#define fileno _fileno
120#define fdopen _fdopen
121#endif
122
123/* Extras needed for MinGW */
124#if defined(__MINGW32__) || defined(__MINGW64__)
125#include <fcntl.h>
126
127#define _fseeki64 fseeko64
128#define _ftelli64 ftello64
129
130#define fstat _fstat
131#define stat _stat
132#endif
133#else
134/* All other platforms */
135#include <inttypes.h>
136#include <sys/time.h>
137#endif
138
139#define MINRECLEN 40
140#define MAXRECLEN 10485760
141#define MAXRECLENv2 131172
142
143#define LM_SIDLEN 64
144
147#define MS_ISRATETOLERABLE(A, B) (fabs (1.0 - ((A) / (B))) < 0.0001)
148
151#define MS2_ISDATAINDICATOR(X) ((X) == 'D' || (X) == 'R' || (X) == 'Q' || (X) == 'M')
152
169#define MS3_ISVALIDHEADER(X) \
170 (*(X) == 'M' && *((X) + 1) == 'S' && *((X) + 2) == 3 && (uint8_t)(*((X) + 12)) >= 0 && \
171 (uint8_t)(*((X) + 12)) <= 23 && (uint8_t)(*((X) + 13)) >= 0 && (uint8_t)(*((X) + 13)) <= 59 && \
172 (uint8_t)(*((X) + 14)) >= 0 && (uint8_t)(*((X) + 14)) <= 60)
173
190#define MS2_ISVALIDHEADER(X) \
191 ((isdigit ((uint8_t)*(X)) || *(X) == ' ' || !*(X)) && \
192 (isdigit ((uint8_t)*((X) + 1)) || *((X) + 1) == ' ' || !*((X) + 1)) && \
193 (isdigit ((uint8_t)*((X) + 2)) || *((X) + 2) == ' ' || !*((X) + 2)) && \
194 (isdigit ((uint8_t)*((X) + 3)) || *((X) + 3) == ' ' || !*((X) + 3)) && \
195 (isdigit ((uint8_t)*((X) + 4)) || *((X) + 4) == ' ' || !*((X) + 4)) && \
196 (isdigit ((uint8_t)*((X) + 5)) || *((X) + 5) == ' ' || !*((X) + 5)) && \
197 MS2_ISDATAINDICATOR (*((X) + 6)) && (*((X) + 7) == ' ' || *((X) + 7) == '\0') && \
198 (uint8_t)(*((X) + 24)) >= 0 && (uint8_t)(*((X) + 24)) <= 23 && (uint8_t)(*((X) + 25)) >= 0 && \
199 (uint8_t)(*((X) + 25)) <= 59 && (uint8_t)(*((X) + 26)) >= 0 && (uint8_t)(*((X) + 26)) <= 60)
200
202#define bit(x, y) ((x) & (y)) ? 1 : 0
203
205#ifdef _MSC_VER
206#define DEPRECATED __declspec (deprecated)
207#elif defined(__GNUC__) | defined(__clang__)
208#define DEPRECATED __attribute__ ((__deprecated__))
209#else
210#define DEPRECATED
211#endif
212
220
226typedef int64_t nstime_t;
227
231#define NSTMODULUS 1000000000
232
236#define NSTERROR -2145916800000000000LL
237
241#define NSTUNSET -2145916799999999999LL
242
245#define MS_EPOCH2NSTIME(X) (X) * (nstime_t)NSTMODULUS
246
249#define MS_NSTIME2EPOCH(X) (X) / NSTMODULUS
250
258#define MS_HPTIME2NSTIME(X) (X) * (nstime_t)1000
259
267#define MS_NSTIME2HPTIME(X) (X) / 1000
268
287typedef enum
288{
289 ISOMONTHDAY = 0,
290 ISOMONTHDAY_Z = 1,
291 ISOMONTHDAY_DOY = 2,
292 ISOMONTHDAY_DOY_Z = 3,
293 ISOMONTHDAY_SPACE = 4,
294 ISOMONTHDAY_SPACE_Z = 5,
295 SEEDORDINAL = 6,
296 UNIXEPOCH = 7,
297 NANOSECONDEPOCH = 8
299
314typedef enum
315{
316 NONE = 0,
317 MICRO = 1,
318 NANO = 2,
319 MICRO_NONE = 3,
320 NANO_NONE = 4,
321 NANO_MICRO = 5,
322 NANO_MICRO_NONE = 6
324
325extern int ms_nstime2time (nstime_t nstime, uint16_t *year, uint16_t *yday, uint8_t *hour,
326 uint8_t *min, uint8_t *sec, uint32_t *nsec);
327extern char *ms_nstime2timestr_n (nstime_t nstime, char *timestr, size_t timestrsize,
328 ms_timeformat_t timeformat, ms_subseconds_t subsecond);
329DEPRECATED extern char *ms_nstime2timestr (nstime_t nstime, char *timestr,
330 ms_timeformat_t timeformat, ms_subseconds_t subsecond);
331DEPRECATED extern char *ms_nstime2timestrz (nstime_t nstime, char *timestr,
332 ms_timeformat_t timeformat, ms_subseconds_t subsecond);
333extern nstime_t ms_time2nstime (int year, int yday, int hour, int min, int sec, uint32_t nsec);
334extern nstime_t ms_timestr2nstime (const char *timestr);
335extern nstime_t ms_mdtimestr2nstime (const char *timestr);
336extern nstime_t ms_seedtimestr2nstime (const char *seedtimestr);
337extern int ms_doy2md (int year, int yday, int *month, int *mday);
338extern int ms_md2doy (int year, int month, int mday, int *yday);
339
341
351
355#define MS_PACK_DEFAULT_RECLEN 4096
356
360#define MS_PACK_DEFAULT_ENCODING DE_STEIM2
361
365
367typedef struct MS3Record
368{
369 const char *record;
370 int32_t reclen;
371 uint8_t swapflag;
372
373 /* Common header fields in accessible form */
376 uint8_t flags;
378 double samprate;
379 int16_t encoding;
380 uint8_t pubversion;
381 int64_t samplecnt;
382 uint32_t crc;
383 uint16_t extralength;
384 uint32_t datalength;
385 char *extra;
386
387 /* Data sample fields */
389 uint64_t datasize;
390 int64_t numsamples;
392} MS3Record;
393
396#define MS3Record_INITIALIZER \
397 {.record = NULL, \
398 .reclen = -1, \
399 .swapflag = 0, \
400 .sid = {0}, \
401 .formatversion = 0, \
402 .flags = 0, \
403 .starttime = NSTUNSET, \
404 .samprate = 0.0, \
405 .encoding = -1, \
406 .pubversion = 0, \
407 .samplecnt = -1, \
408 .crc = 0, \
409 .extralength = 0, \
410 .datalength = 0, \
411 .extra = NULL, \
412 .datasamples = NULL, \
413 .datasize = 0, \
414 .numsamples = 0, \
415 .sampletype = 0}
416
417extern int msr3_parse (const char *record, uint64_t recbuflen, MS3Record **ppmsr, uint32_t flags,
418 int8_t verbose);
419
420extern int msr3_pack (const MS3Record *msr, void (*record_handler) (char *, int, void *),
421 void *handlerdata, int64_t *packedsamples, uint32_t flags, int8_t verbose);
422
423extern int msr3_repack_mseed3 (const MS3Record *msr, char *record, uint32_t recbuflen,
424 int8_t verbose);
425
426extern int msr3_repack_mseed2 (const MS3Record *msr, char *record, uint32_t recbuflen,
427 int8_t verbose);
428
429extern int msr3_pack_header3 (const MS3Record *msr, char *record, uint32_t recbuflen,
430 int8_t verbose);
431
432extern int msr3_pack_header2 (const MS3Record *msr, char *record, uint32_t recbuflen,
433 int8_t verbose);
434
435extern int64_t msr3_unpack_data (MS3Record *msr, int8_t verbose);
436
437extern int msr3_data_bounds (const MS3Record *msr, uint32_t *dataoffset, uint32_t *datasize);
438
439extern int64_t ms_decode_data (const void *input, uint64_t inputsize, uint8_t encoding,
440 uint64_t samplecount, void *output, uint64_t outputsize,
441 char *sampletype, int8_t swapflag, const char *sid, int8_t verbose);
442
443extern MS3Record *msr3_init (MS3Record *msr);
444extern void msr3_free (MS3Record **ppmsr);
445extern MS3Record *msr3_duplicate (const MS3Record *msr, int8_t datadup);
446extern nstime_t msr3_endtime (const MS3Record *msr);
447extern void msr3_print (const MS3Record *msr, int8_t details);
448extern int msr3_resize_buffer (MS3Record *msr);
449extern double msr3_sampratehz (const MS3Record *msr);
450extern nstime_t msr3_nsperiod (const MS3Record *msr);
451extern double msr3_host_latency (const MS3Record *msr);
452
453extern int64_t ms3_detect (const char *record, uint64_t recbuflen, uint8_t *formatversion);
454extern int ms_parse_raw3 (const char *record, int maxreclen, int8_t details);
455extern int ms_parse_raw2 (const char *record, int maxreclen, int8_t details, int8_t swapflag);
457
473
481
483typedef struct MS3Selections
484{
485 char sidpattern[100];
488 uint8_t pubversion;
490
491extern const MS3Selections *ms3_matchselect (const MS3Selections *selections, const char *sid,
492 nstime_t starttime, nstime_t endtime, int pubversion,
493 const MS3SelectTime **ppselecttime);
494extern const MS3Selections *msr3_matchselect (const MS3Selections *selections, const MS3Record *msr,
495 const MS3SelectTime **ppselecttime);
496extern int ms3_addselect (MS3Selections **ppselections, const char *sidpattern, nstime_t starttime,
497 nstime_t endtime, uint8_t pubversion);
498extern int ms3_addselect_comp (MS3Selections **ppselections, char *network, char *station,
499 char *location, char *channel, nstime_t starttime, nstime_t endtime,
500 uint8_t pubversion);
501extern int ms3_readselectionsfile (MS3Selections **ppselections, const char *filename);
502extern void ms3_freeselections (MS3Selections *selections);
503extern void ms3_printselections (const MS3Selections *selections);
505
508
531typedef struct MS3RecordPtr
532{
533 const char *bufferptr;
534 FILE *fileptr;
535 const char *filename;
536 int64_t fileoffset;
539 uint32_t dataoffset;
540 void *prvtptr;
543
551
553
588
590#define MSTRACEID_SKIPLIST_HEIGHT 8
591
609
625
627typedef struct MS3TraceList
628{
629 uint32_t numtraceids;
631 uint64_t prngstate;
633
659typedef struct MS3Tolerance
660{
661 double (*time) (const MS3Record *msr);
662 double (*samprate) (
663 const MS3Record *msr);
665
668#define MS3Tolerance_INITIALIZER {.time = NULL, .samprate = NULL}
669
670extern MS3TraceList *mstl3_init (MS3TraceList *mstl);
671extern void mstl3_free (MS3TraceList **ppmstl, int8_t freeprvtptr);
672extern MS3TraceID *mstl3_findID (MS3TraceList *mstl, const char *sid, uint8_t pubversion,
673 MS3TraceID **prev);
674
675extern MS3TraceSeg *mstl3_addmsr (MS3TraceList *mstl, const MS3Record *msr, int8_t splitversion,
676 int8_t autoheal, uint32_t flags, const MS3Tolerance *tolerance);
678 MS3RecordPtr **pprecptr, int8_t splitversion,
679 int8_t autoheal, uint32_t flags,
680 const MS3Tolerance *tolerance);
681extern int64_t mstl3_readbuffer (MS3TraceList **ppmstl, const char *buffer, uint64_t bufferlength,
682 int8_t splitversion, uint32_t flags, const MS3Tolerance *tolerance,
683 int8_t verbose);
684extern int64_t mstl3_readbuffer_selection (MS3TraceList **ppmstl, const char *buffer,
685 uint64_t bufferlength, int8_t splitversion,
686 uint32_t flags, const MS3Tolerance *tolerance,
687 const MS3Selections *selections, int8_t verbose);
688extern int64_t mstl3_unpack_recordlist (MS3TraceID *id, MS3TraceSeg *seg, void *output,
689 uint64_t outputsize, int8_t verbose);
690extern int mstl3_convertsamples (MS3TraceSeg *seg, char type, int8_t truncate);
691extern int mstl3_resize_buffers (MS3TraceList *mstl);
692extern int64_t mstl3_pack (MS3TraceList *mstl, void (*record_handler) (char *, int, void *),
693 void *handlerdata, int reclen, int8_t encoding, int64_t *packedsamples,
694 uint32_t flags, int8_t verbose, char *extra);
695extern int64_t mstl3_pack_ppupdate_flushidle (MS3TraceList *mstl,
696 void (*record_handler) (char *, int, void *),
697 void *handlerdata, int reclen, int8_t encoding,
698 int64_t *packedsamples, uint32_t flags,
699 int8_t verbose, char *extra,
700 uint32_t flush_idle_seconds);
701extern int64_t mstl3_pack_segment (MS3TraceList *mstl, MS3TraceID *id, MS3TraceSeg *seg,
702 void (*record_handler) (char *, int, void *), void *handlerdata,
703 int reclen, int8_t encoding, int64_t *packedsamples,
704 uint32_t flags, int8_t verbose, char *extra);
706 void (*) (char *, int, void *), void *, int, int8_t,
707 int64_t *, uint32_t, int8_t, char *);
708extern void mstl3_printtracelist (const MS3TraceList *mstl, ms_timeformat_t timeformat,
709 int8_t details, int8_t gaps, int8_t versions);
710extern void mstl3_printsynclist (const MS3TraceList *mstl, const char *dccid,
711 ms_subseconds_t subseconds);
712extern void mstl3_printgaplist (const MS3TraceList *mstl, ms_timeformat_t timeformat,
713 double *mingap, double *maxgap);
715
748
750typedef struct LMIO
751{
752 enum
753 {
759 void *handle;
760 void *handle2;
762} LMIO;
763
766#define LMIO_INITIALIZER {.type = LMIO_NULL, .handle = NULL, .handle2 = NULL, .still_running = 0}
767
775typedef struct MS3FileParam
776{
777 char path[512];
778 int64_t startoffset;
779 int64_t endoffset;
780 int64_t streampos;
781 int64_t recordcount;
782
786 uint32_t flags;
789
792#define MS3FileParam_INITIALIZER \
793 {.path = "", \
794 .startoffset = 0, \
795 .endoffset = 0, \
796 .streampos = 0, \
797 .recordcount = 0, \
798 .readbuffer = NULL, \
799 .readlength = 0, \
800 .readoffset = 0, \
801 .flags = 0, \
802 .input = LMIO_INITIALIZER}
803
804extern int ms3_readmsr (MS3Record **ppmsr, const char *mspath, uint32_t flags, int8_t verbose);
805extern int ms3_readmsr_r (MS3FileParam **ppmsfp, MS3Record **ppmsr, const char *mspath,
806 uint32_t flags, int8_t verbose);
807extern int ms3_readmsr_selection (MS3FileParam **ppmsfp, MS3Record **ppmsr, const char *mspath,
808 uint32_t flags, const MS3Selections *selections, int8_t verbose);
809extern int ms3_readtracelist (MS3TraceList **ppmstl, const char *mspath,
810 const MS3Tolerance *tolerance, int8_t splitversion, uint32_t flags,
811 int8_t verbose);
812extern int ms3_readtracelist_timewin (MS3TraceList **ppmstl, const char *mspath,
813 const MS3Tolerance *tolerance, nstime_t starttime,
814 nstime_t endtime, int8_t splitversion, uint32_t flags,
815 int8_t verbose);
816extern int ms3_readtracelist_selection (MS3TraceList **ppmstl, const char *mspath,
817 const MS3Tolerance *tolerance,
818 const MS3Selections *selections, int8_t splitversion,
819 uint32_t flags, int8_t verbose);
820extern int ms3_url_useragent (const char *program, const char *version);
821extern int ms3_url_userpassword (const char *userpassword);
822extern int ms3_url_addheader (const char *header);
823extern void ms3_url_freeheaders (void);
824extern int64_t msr3_writemseed (MS3Record *msr, const char *mspath, int8_t overwrite,
825 uint32_t flags, int8_t verbose);
826extern int64_t mstl3_writemseed (MS3TraceList *mstl, const char *mspath, int8_t overwrite,
827 int maxreclen, int8_t encoding, uint32_t flags, int8_t verbose);
828extern int libmseed_url_support (void);
829extern MS3FileParam *ms3_mstl_init_fd (int fd);
831
841extern int ms_sid2nslc_n (const char *sid, char *net, size_t netsize, char *sta, size_t stasize,
842 char *loc, size_t locsize, char *chan, size_t chansize);
843DEPRECATED extern int ms_sid2nslc (const char *sid, char *net, char *sta, char *loc, char *chan);
844extern int ms_nslc2sid (char *sid, int sidlen, uint16_t flags, const char *net, const char *sta,
845 const char *loc, const char *chan);
846extern int ms_seedchan2xchan (char *xchan, const char *seedchan);
847extern int ms_xchan2seedchan (char *seedchan, const char *xchan);
848extern int ms_strncpclean (char *dest, const char *source, int length);
849extern int ms_strncpcleantail (char *dest, const char *source, int length);
850extern int ms_strncpopen (char *dest, const char *source, int length);
852
881
907
941
961
977
983typedef struct LM_PARSED_JSON_s LM_PARSED_JSON;
984
987#define mseh_get(msr, ptr, valueptr, type, maxlength) \
988 mseh_get_ptr_r (msr, ptr, valueptr, type, maxlength, NULL)
989
992#define mseh_get_number(msr, ptr, valueptr) mseh_get_ptr_r (msr, ptr, valueptr, 'n', 0, NULL)
993
996#define mseh_get_int64(msr, ptr, valueptr) mseh_get_ptr_r (msr, ptr, valueptr, 'i', 0, NULL)
997
1000#define mseh_get_string(msr, ptr, buffer, maxlength) \
1001 mseh_get_ptr_r (msr, ptr, buffer, 's', maxlength, NULL)
1002
1005#define mseh_get_boolean(msr, ptr, valueptr) mseh_get_ptr_r (msr, ptr, valueptr, 'b', 0, NULL)
1006
1009#define mseh_exists(msr, ptr) (!mseh_get_ptr_r (msr, ptr, NULL, 0, 0, NULL))
1010
1011extern int mseh_get_ptr_r (const MS3Record *msr, const char *ptr, void *value, char type,
1012 uint32_t maxlength, LM_PARSED_JSON **parsestate);
1013
1016#define mseh_set(msr, ptr, valueptr, type) mseh_set_ptr_r (msr, ptr, valueptr, type, NULL)
1017
1020#define mseh_set_number(msr, ptr, valueptr) mseh_set_ptr_r (msr, ptr, valueptr, 'n', NULL)
1021
1024#define mseh_set_int64(msr, ptr, valueptr) mseh_set_ptr_r (msr, ptr, valueptr, 'i', NULL)
1025
1028#define mseh_set_string(msr, ptr, valueptr) mseh_set_ptr_r (msr, ptr, valueptr, 's', NULL)
1029
1032#define mseh_set_boolean(msr, ptr, valueptr) mseh_set_ptr_r (msr, ptr, valueptr, 'b', NULL)
1033
1034extern int mseh_set_ptr_r (MS3Record *msr, const char *ptr, void *value, char type,
1035 LM_PARSED_JSON **parsestate);
1036
1037extern int mseh_add_event_detection_r (MS3Record *msr, const char *ptr,
1038 MSEHEventDetection *eventdetection,
1039 LM_PARSED_JSON **parsestate);
1040
1041extern int mseh_add_calibration_r (MS3Record *msr, const char *ptr, MSEHCalibration *calibration,
1042 LM_PARSED_JSON **parsestate);
1043
1044extern int mseh_add_timing_exception_r (MS3Record *msr, const char *ptr,
1045 MSEHTimingException *exception,
1046 LM_PARSED_JSON **parsestate);
1047
1048extern int mseh_add_recenter_r (MS3Record *msr, const char *ptr, MSEHRecenter *recenter,
1049 LM_PARSED_JSON **parsestate);
1050
1051extern int mseh_serialize (MS3Record *msr, LM_PARSED_JSON **parsestate);
1052extern void mseh_free_parsestate (LM_PARSED_JSON **parsestate);
1053extern int mseh_replace (MS3Record *msr, char *jsonstring);
1054
1055extern int mseh_print (const MS3Record *msr, int indent);
1057
1084
1162
1164#define MAX_LOG_MSG_LENGTH 200
1165
1169typedef struct MSLogEntry
1170{
1171 int level;
1172 char function[30];
1174 struct MSLogEntry *next;
1175} MSLogEntry;
1176
1180typedef struct MSLogRegistry
1181{
1182 int maxmessages;
1183 int messagecnt;
1184 MSLogEntry *messages;
1186
1189#define MSLogRegistry_INITIALIZER {.maxmessages = 0, .messagecnt = 0, .messages = NULL}
1190
1196typedef struct MSLogParam
1197{
1198 void (*log_print) (const char *);
1199 const char *logprefix;
1200 void (*diag_print) (const char *);
1201 const char *errprefix;
1203} MSLogParam;
1204
1207#define MSLogParam_INITIALIZER \
1208 {.log_print = NULL, \
1209 .logprefix = NULL, \
1210 .diag_print = NULL, \
1211 .errprefix = NULL, \
1212 .registry = MSLogRegistry_INITIALIZER}
1213
1217#define ms_log(level, ...) ms_rlog (__func__, level, __VA_ARGS__)
1218
1222#define ms_log_l(logp, level, ...) ms_rlog_l (logp, __func__, level, __VA_ARGS__)
1223
1224#if defined(__GNUC__) || defined(__clang__)
1225__attribute__ ((__format__ (__printf__, 3, 4)))
1226#endif
1227extern int
1228ms_rlog (const char *function, int level, const char *format, ...);
1229#if defined(__GNUC__) || defined(__clang__)
1230__attribute__ ((__format__ (__printf__, 4, 5)))
1231#endif
1232extern int
1233ms_rlog_l (MSLogParam *logp, const char *function, int level, const char *format, ...);
1234
1237#define ms_loginit(log_print, logprefix, diag_print, errprefix) \
1238 ms_rloginit (log_print, logprefix, diag_print, errprefix, 0)
1239
1242#define ms_loginit_l(logp, log_print, logprefix, diag_print, errprefix) \
1243 ms_rloginit_l (logp, log_print, logprefix, diag_print, errprefix, 0)
1244
1245extern void ms_rloginit (void (*log_print) (const char *), const char *logprefix,
1246 void (*diag_print) (const char *), const char *errprefix, int maxmessages);
1247extern MSLogParam *ms_rloginit_l (MSLogParam *logp, void (*log_print) (const char *),
1248 const char *logprefix, void (*diag_print) (const char *),
1249 const char *errprefix, int maxmessages);
1250extern int ms_rlog_emit (MSLogParam *logp, int count, int context);
1251extern int ms_rlog_free (MSLogParam *logp);
1252
1254
1287typedef struct LeapSecond
1288{
1290 int32_t TAIdelta;
1292} LeapSecond;
1293
1296extern int ms_readleapseconds (const char *envvarname);
1297extern int ms_readleapsecondfile (const char *filename);
1299
1303
1304extern uint8_t ms_samplesize (char sampletype);
1305extern int ms_encoding_sizetype (uint8_t encoding, uint8_t *samplesize, char *sampletype);
1306extern const char *ms_encodingstr (uint8_t encoding);
1307extern const char *ms_errorstr (int errorcode);
1308
1309extern nstime_t ms_sampletime (nstime_t time, int64_t offset, double samprate);
1310extern int ms_bigendianhost (void);
1311
1313#define ms_dabs(val) fabs (val)
1314
1316extern int64_t lmp_ftell64 (FILE *stream);
1318extern int lmp_fseek64 (FILE *stream, int64_t offset, int whence);
1320extern uint64_t lmp_nanosleep (uint64_t nanoseconds);
1322extern nstime_t lmp_systemtime (void);
1323
1325extern uint32_t ms_crc32c (const uint8_t *input, int length, uint32_t previousCRC32C);
1326
1328static inline void
1329ms_gswap2 (void *data2)
1330{
1331 uint16_t dat;
1332
1333 memcpy (&dat, data2, 2);
1334
1335 dat = ((dat & 0xff00) >> 8) | ((dat & 0x00ff) << 8);
1336
1337 memcpy (data2, &dat, 2);
1338}
1339
1341static inline void
1342ms_gswap4 (void *data4)
1343{
1344 uint32_t dat;
1345
1346 memcpy (&dat, data4, 4);
1347
1348 dat = ((dat & 0xff000000) >> 24) | ((dat & 0x000000ff) << 24) | ((dat & 0x00ff0000) >> 8) |
1349 ((dat & 0x0000ff00) << 8);
1350
1351 memcpy (data4, &dat, 4);
1352}
1353
1355static inline void
1356ms_gswap8 (void *data8)
1357{
1358 uint64_t dat;
1359
1360 memcpy (&dat, data8, sizeof (uint64_t));
1361
1362 dat = ((dat & 0xff00000000000000) >> 56) | ((dat & 0x00000000000000ff) << 56) |
1363 ((dat & 0x00ff000000000000) >> 40) | ((dat & 0x000000000000ff00) << 40) |
1364 ((dat & 0x0000ff0000000000) >> 24) | ((dat & 0x0000000000ff0000) << 24) |
1365 ((dat & 0x000000ff00000000) >> 8) | ((dat & 0x00000000ff000000) << 8);
1366
1367 memcpy (data8, &dat, sizeof (uint64_t));
1368}
1369
1370#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) || defined(__clang__)
1372__attribute__ ((deprecated ("Use ms_gswap2 instead."))) static inline void
1373ms_gswap2a (void *data2)
1374{
1375 ms_gswap2 (data2);
1376}
1378__attribute__ ((deprecated ("Use ms_gswap4 instead."))) static inline void
1379ms_gswap4a (void *data4)
1380{
1381 ms_gswap4 (data4);
1382}
1384__attribute__ ((deprecated ("Use ms_gswap8 instead."))) static inline void
1385ms_gswap8a (void *data8)
1386{
1387 ms_gswap8 (data8);
1388}
1389#elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320)
1391__declspec (deprecated ("Use ms_gswap2 instead.")) static inline void
1392ms_gswap2a (void *data2)
1393{
1394 ms_gswap2 (data2);
1395}
1397__declspec (deprecated ("Use ms_gswap4 instead.")) static inline void
1398ms_gswap4a (void *data4)
1399{
1400 ms_gswap4 (data4);
1401}
1403__declspec (deprecated ("Use ms_gswap8 instead.")) static inline void
1404ms_gswap8a (void *data8)
1405{
1406 ms_gswap8 (data8);
1407}
1408#else
1410static inline void
1411ms_gswap2a (void *data2)
1412{
1413 ms_gswap2 (data2);
1414}
1416static inline void
1417ms_gswap4a (void *data4)
1418{
1419 ms_gswap4 (data4);
1420}
1422static inline void
1423ms_gswap8a (void *data8)
1424{
1425 ms_gswap8 (data8);
1426}
1427#endif
1428
1430
1432typedef int8_t flag;
1433
1456
1458typedef struct LIBMSEED_MEMORY
1459{
1460 void *(*malloc) (size_t);
1461 void *(*realloc) (void *, size_t);
1462 void (*free) (void *);
1464
1467
1481extern size_t libmseed_prealloc_block_size;
1482
1487extern void *libmseed_memory_prealloc (void *ptr, size_t size, size_t *currentsize);
1488
1490
1491#define DE_ASCII DE_TEXT
1492
1501#define DE_TEXT 0
1502#define DE_INT16 1
1503#define DE_INT32 3
1504#define DE_FLOAT32 4
1505#define DE_FLOAT64 5
1506#define DE_STEIM1 10
1507#define DE_STEIM2 11
1508#define DE_GEOSCOPE24 12
1509#define DE_GEOSCOPE163 13
1510#define DE_GEOSCOPE164 14
1511#define DE_CDSN 16
1512#define DE_SRO 30
1513#define DE_DWWSSN 32
1515
1522#define MSSWAP_HEADER 0x01
1523#define MSSWAP_PAYLOAD 0x02
1525
1531#define MS_ENDOFFILE 1
1532#define MS_NOERROR 0
1533#define MS_GENERROR -1
1534#define MS_NOTSEED -2
1535#define MS_WRONGLENGTH -3
1536#define MS_OUTOFRANGE -4
1537#define MS_UNKNOWNFORMAT -5
1538#define MS_STBADCOMPFLAG -6
1539#define MS_INVALIDCRC -7
1541
1549#define MSF_UNPACKDATA 0x0001
1550#define MSF_SKIPNOTDATA 0x0002
1551#define MSF_VALIDATECRC 0x0004
1552#define MSF_PNAMERANGE 0x0008
1553#define MSF_ATENDOFFILE 0x0010
1554#define MSF_SEQUENCE 0x0020
1555#define MSF_FLUSHDATA \
1556 0x0040
1557#define MSF_PACKVER2 0x0080
1558#define MSF_RECORDLIST 0x0100
1559#define MSF_MAINTAINMSTL 0x0200
1560#define MSF_PPUPDATETIME \
1561 0x0400
1562
1563
1564#ifdef __cplusplus
1565}
1566#endif
1567
1568#endif /* LIBMSEED_H */
struct MS3SelectTime * next
Pointer to next selection time, NULL if the last.
Definition libmseed.h:479
nstime_t endtime
Latest data for matching channels, use NSTUNSET for open.
Definition libmseed.h:478
uint8_t pubversion
Selected publication version, use 0 for any.
Definition libmseed.h:488
char sidpattern[100]
Matching (globbing) pattern for source ID.
Definition libmseed.h:485
struct MS3Selections * next
Pointer to next selection, NULL if the last.
Definition libmseed.h:487
nstime_t starttime
Earliest data for matching channels, use NSTUNSET for open.
Definition libmseed.h:477
struct MS3SelectTime * timewindows
Pointer to time window list for this source ID.
Definition libmseed.h:486
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:183
int ms3_readselectionsfile(MS3Selections **ppselections, const char *filename)
Read data selections from a file.
Definition selection.c:427
void ms3_printselections(const MS3Selections *selections)
Print the selections list using the ms_log() facility.
Definition selection.c:702
void ms3_freeselections(MS3Selections *selections)
Free all memory associated with a MS3Selections.
Definition selection.c:660
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:306
const MS3Selections * msr3_matchselect(const MS3Selections *selections, const MS3Record *msr, const MS3SelectTime **ppselecttime)
Test the MS3Record for a matching selection entry.
Definition selection.c:147
Data selection structure time window definition containers.
Definition libmseed.h:476
Data selection structure definition containers.
Definition libmseed.h:484
char type[30]
Definition libmseed.h:892
double duration
Definition libmseed.h:931
char wave[30]
Definition libmseed.h:897
char inputchannel[30]
Definition libmseed.h:934
struct MSEHEventDetection * next
Definition libmseed.h:905
double signalperiod
Definition libmseed.h:895
char amplituderange[30]
Definition libmseed.h:929
int firstpulsepositive
Definition libmseed.h:923
nstime_t onsettime
Definition libmseed.h:900
int medlookback
Definition libmseed.h:903
float vcocorrection
Definition libmseed.h:953
nstime_t endtime
Definition libmseed.h:921
char type[30]
Definition libmseed.h:918
struct MSEHCalibration * next
Definition libmseed.h:939
int continued
Definition libmseed.h:926
char clockstatus[128]
Definition libmseed.h:959
double signalamplitude
Definition libmseed.h:894
double stepbetween
Definition libmseed.h:933
uint32_t count
Definition libmseed.h:956
char units[30]
Definition libmseed.h:898
int alternatesign
Definition libmseed.h:924
char type[30]
Definition libmseed.h:972
double backgroundestimate
Definition libmseed.h:896
nstime_t time
Definition libmseed.h:952
double amplitude
Definition libmseed.h:927
char rolloff[30]
Definition libmseed.h:937
char trigger[30]
Definition libmseed.h:925
char coupling[30]
Definition libmseed.h:936
int steps
Definition libmseed.h:922
char noise[30]
Definition libmseed.h:938
char trigger[30]
Definition libmseed.h:975
char inputunits[30]
Definition libmseed.h:928
double sineperiod
Definition libmseed.h:932
int usec
Definition libmseed.h:954
uint8_t medsnr[6]
Definition libmseed.h:902
int medpickalgorithm
Definition libmseed.h:904
char type[16]
Definition libmseed.h:957
nstime_t begintime
Definition libmseed.h:973
double refamplitude
Definition libmseed.h:935
char detector[30]
Definition libmseed.h:893
nstime_t endtime
Definition libmseed.h:974
nstime_t begintime
Definition libmseed.h:920
int receptionquality
Definition libmseed.h:955
int mseh_add_timing_exception_r(MS3Record *msr, const char *ptr, MSEHTimingException *exception, LM_PARSED_JSON **parsestate)
Add timing exception to the extra headers of the given record.
Definition extraheaders.c:829
int mseh_print(const MS3Record *msr, int indent)
Print the extra header structure for the specified MS3Record.
Definition extraheaders.c:1171
int mseh_serialize(MS3Record *msr, LM_PARSED_JSON **parsestate)
Generate extra headers string (serialize) from internal state.
Definition extraheaders.c:1007
int mseh_add_event_detection_r(MS3Record *msr, const char *ptr, MSEHEventDetection *eventdetection, LM_PARSED_JSON **parsestate)
Add event detection to the extra headers of the given record.
Definition extraheaders.c:496
int mseh_get_ptr_r(const MS3Record *msr, const char *ptr, void *value, char type, uint32_t maxlength, LM_PARSED_JSON **parsestate)
Search for and return an extra header value.
Definition extraheaders.c:156
int mseh_add_calibration_r(MS3Record *msr, const char *ptr, MSEHCalibration *calibration, LM_PARSED_JSON **parsestate)
Add calibration to the extra headers of the given record.
Definition extraheaders.c:633
void mseh_free_parsestate(LM_PARSED_JSON **parsestate)
Free internally parsed (deserialized) JSON data.
Definition extraheaders.c:1068
int mseh_set_ptr_r(MS3Record *msr, const char *ptr, void *value, char type, LM_PARSED_JSON **parsestate)
Set the value of extra header values.
Definition extraheaders.c:317
struct LM_PARSED_JSON_s LM_PARSED_JSON
Internal structure for holding parsed JSON extra headers.
Definition libmseed.h:983
int mseh_add_recenter_r(MS3Record *msr, const char *ptr, MSEHRecenter *recenter, LM_PARSED_JSON **parsestate)
Add recenter event to the extra headers of the given record.
Definition extraheaders.c:921
int mseh_replace(MS3Record *msr, char *jsonstring)
Replace extra headers with supplied JSON.
Definition extraheaders.c:1105
Container for calibration parameters for use in extra headers.
Definition libmseed.h:917
Container for event detection parameters for use in extra headers.
Definition libmseed.h:891
Container for recenter parameters for use in extra headers.
Definition libmseed.h:971
Container for timing exception parameters for use in extra headers.
Definition libmseed.h:951
int readlength
INTERNAL: Length of data in read buffer.
Definition libmseed.h:784
int64_t streampos
OUTPUT: Read position of input stream.
Definition libmseed.h:780
int64_t endoffset
INPUT: End position in input stream, 0 == unknown (e.g. pipe)
Definition libmseed.h:779
int64_t recordcount
OUTPUT: Count of records read from this stream/file so far.
Definition libmseed.h:781
LMIO input
INTERNAL: IO handle, file or URL.
Definition libmseed.h:787
uint32_t flags
INTERNAL: Stream reading state flags.
Definition libmseed.h:786
char path[512]
INPUT: File name or URL.
Definition libmseed.h:777
int readoffset
INTERNAL: Read offset in read buffer.
Definition libmseed.h:785
char * readbuffer
INTERNAL: Read buffer, allocated internally.
Definition libmseed.h:783
int64_t startoffset
INPUT: Start position in input stream.
Definition libmseed.h:778
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:591
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:677
void ms3_url_freeheaders(void)
Free all set headers for URL-based requests.
Definition fileutils.c:848
int ms3_readmsr_r(MS3FileParam **ppmsfp, MS3Record **ppmsr, const char *mspath, uint32_t flags, int8_t verbose)
Definition fileutils.c:549
int ms3_url_addheader(const char *header)
Add header to any URL-based requests.
Definition fileutils.c:828
int libmseed_url_support(void)
Run-time test for URL support in libmseed.
Definition fileutils.c:49
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:527
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:615
int ms3_readmsr_selection(MS3FileParam **ppmsfp, MS3Record **ppmsr, const char *mspath, uint32_t flags, const MS3Selections *selections, int8_t verbose)
Definition fileutils.c:569
int ms3_url_userpassword(const char *userpassword)
Set authentication credentials for URL-based requests.
Definition fileutils.c:799
MS3FileParam * ms3_mstl_init_fd(int fd)
Initialize MS3FileParam parameters for a file descriptor.
Definition fileutils.c:75
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:899
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:960
int ms3_url_useragent(const char *program, const char *version)
Set User-Agent header for URL-based requests.
Definition fileutils.c:769
State container for reading miniSEED records from files or URLs.
Definition libmseed.h:776
int32_t TAIdelta
TAI-UTC difference in seconds.
Definition libmseed.h:1290
nstime_t leapsecond
Time of leap second as epoch since 1 January 1900.
Definition libmseed.h:1289
struct LeapSecond * next
Pointer to next entry, NULL if the last.
Definition libmseed.h:1291
LeapSecond * leapsecondlist
int ms_readleapsecondfile(const char *filename)
Read leap second from the specified file.
Definition genutils.c:1853
int ms_readleapseconds(const char *envvarname)
Read leap second file specified by an environment variable.
Definition genutils.c:1824
Leap second list container.
Definition libmseed.h:1288
void(* diag_print)(const char *)
Function to call for diagnostic and error messages.
Definition libmseed.h:1200
char message[MAX_LOG_MSG_LENGTH]
Log, warning or error message.
Definition libmseed.h:1173
char function[30]
Function generating the message.
Definition libmseed.h:1172
void(* log_print)(const char *)
Function to call for regular messages.
Definition libmseed.h:1198
int level
Message level.
Definition libmseed.h:1171
const char * logprefix
Message prefix for regular and diagnostic messages.
Definition libmseed.h:1199
const char * errprefix
Message prefix for error messages.
Definition libmseed.h:1201
MSLogRegistry registry
Message registry.
Definition libmseed.h:1202
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:1164
int ms_rlog_free(MSLogParam *logp)
Free, without emitting, all messages from log registry.
Definition logging.c:612
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:551
Log registry entry.
Definition libmseed.h:1170
Logging parameters. Callers should not modify these values directly and generally should not need to ...
Definition libmseed.h:1197
Log message registry.
Definition libmseed.h:1181
void(* free)(void *)
Pointer to desired free()
Definition libmseed.h:1462
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:1459
uint8_t swapflag
Byte swap indicator (bitmask), see Byte swap flags.
Definition libmseed.h:371
void * datasamples
Data samples, numsamples of type sampletype.
Definition libmseed.h:388
uint32_t datalength
Length of data payload in bytes.
Definition libmseed.h:384
uint32_t crc
CRC of entire record.
Definition libmseed.h:382
uint8_t formatversion
Format major version.
Definition libmseed.h:375
int32_t reclen
Length of miniSEED record in bytes.
Definition libmseed.h:370
uint8_t flags
Record-level bit flags.
Definition libmseed.h:376
uint16_t extralength
Length of extra headers in bytes.
Definition libmseed.h:383
uint64_t datasize
Size of datasamples buffer in bytes.
Definition libmseed.h:389
const char * record
Raw miniSEED record, if available.
Definition libmseed.h:369
double samprate
Nominal sample rate as samples/second (Hz) or period (s)
Definition libmseed.h:378
int64_t numsamples
Number of data samples in datasamples.
Definition libmseed.h:390
int64_t samplecnt
Number of samples in record.
Definition libmseed.h:381
char sampletype
Sample type code: t, i, f, d Sample Types.
Definition libmseed.h:391
int16_t encoding
Data encoding format, see Data Encodings.
Definition libmseed.h:379
nstime_t starttime
Record start time (first sample)
Definition libmseed.h:377
char sid[LM_SIDLEN]
Source identifier as URN, max length LM_SIDLEN.
Definition libmseed.h:374
uint8_t pubversion
Publication version.
Definition libmseed.h:380
char * extra
Pointer to extra headers.
Definition libmseed.h:385
int64_t ms3_detect(const char *record, uint64_t recbuflen, uint8_t *formatversion)
Detect miniSEED record in buffer.
Definition parseutils.c:175
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:399
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:1147
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:997
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:316
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:1302
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:886
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
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:520
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:494
int msr3_data_bounds(const MS3Record *msr, uint32_t *dataoffset, uint32_t *datasize)
Determine the data payload bounds for a MS3Record.
Definition unpack.c:1050
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.
Definition pack.c:112
miniSEED record container
Definition libmseed.h:368
struct MS3RecordPtr * next
Pointer to next entry, NULL if the last.
Definition libmseed.h:541
void * prvtptr
Private pointer, will not be populated by library but will be free'd.
Definition libmseed.h:540
MS3RecordPtr * last
Pointer to last entry, NULL if the none.
Definition libmseed.h:549
int64_t fileoffset
Offset into file to record for fileptr or filename.
Definition libmseed.h:536
const char * filename
Pointer to file name containing record, NULL if not used.
Definition libmseed.h:535
MS3RecordPtr * first
Pointer to first entry, NULL if the none.
Definition libmseed.h:548
MS3Record * msr
Pointer to MS3Record for this record.
Definition libmseed.h:537
const char * bufferptr
Pointer in buffer to record, NULL if not used.
Definition libmseed.h:533
FILE * fileptr
Pointer to open FILE containing record, NULL if not used.
Definition libmseed.h:534
uint64_t recordcnt
Count of records in the list (for convenience)
Definition libmseed.h:547
nstime_t endtime
End time of record, time of last sample.
Definition libmseed.h:538
uint32_t dataoffset
Offset from start of record to encoded data.
Definition libmseed.h:539
Record list, holds MS3RecordPtr entries that contribute to a given MS3TraceSeg.
Definition libmseed.h:546
A miniSEED record pointer and metadata.
Definition libmseed.h:532
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:621
int64_t numsamples
Number of data samples in datasamples.
Definition libmseed.h:601
struct MS3RecordList * recordlist
List of pointers to records that contributed.
Definition libmseed.h:605
uint64_t prngstate
INTERNAL: State for Pseudo RNG.
Definition libmseed.h:631
nstime_t endtime
Time of last sample.
Definition libmseed.h:596
struct MS3TraceSeg * first
Pointer to first of list of segments.
Definition libmseed.h:619
nstime_t latest
Time of latest sample.
Definition libmseed.h:616
struct MS3TraceID traces
Head node of trace skip list, first entry at traces.next[0].
Definition libmseed.h:630
uint8_t pubversion
Largest contributing publication version.
Definition libmseed.h:614
void * prvtptr
Definition libmseed.h:603
uint8_t height
Height of skip list at next.
Definition libmseed.h:623
uint64_t datasize
Size of datasamples buffer in bytes.
Definition libmseed.h:600
nstime_t earliest
Time of earliest sample.
Definition libmseed.h:615
double(* samprate)(const MS3Record *msr)
Pointer to function that returns sample rate tolerance.
Definition libmseed.h:662
void * prvtptr
Private pointer for general use, unused by library.
Definition libmseed.h:617
void * datasamples
Data samples, numsamples of type sampletype.
Definition libmseed.h:599
char sampletype
Sample type code, see Sample Types.
Definition libmseed.h:602
struct MS3TraceSeg * prev
Pointer to previous segment.
Definition libmseed.h:606
int64_t samplecnt
Number of samples in trace coverage.
Definition libmseed.h:598
char sid[LM_SIDLEN]
Source identifier as URN, max length LM_SIDLEN.
Definition libmseed.h:613
struct MS3TraceSeg * last
Pointer to last of list of segments.
Definition libmseed.h:620
uint32_t numtraceids
Number of traces IDs in list.
Definition libmseed.h:629
double(* time)(const MS3Record *msr)
Pointer to function that returns time tolerance.
Definition libmseed.h:661
double samprate
Nominal sample rate (Hz)
Definition libmseed.h:597
struct MS3TraceSeg * next
Pointer to next segment, NULL if the last.
Definition libmseed.h:607
nstime_t starttime
Time of first sample.
Definition libmseed.h:595
uint32_t numsegments
Number of segments for this ID.
Definition libmseed.h:618
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:1620
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:2434
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:2299
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:2038
void mstl3_free(MS3TraceList **ppmstl, int8_t freeprvtptr)
Free all memory associated with a MS3TraceList.
Definition tracelist.c:99
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:758
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:822
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:2505
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:2122
int mstl3_resize_buffers(MS3TraceList *mstl)
Resize data sample buffers of MS3TraceList to what is needed.
Definition tracelist.c:1529
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:870
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:2057
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:2267
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:1377
MS3TraceList * mstl3_init(MS3TraceList *mstl)
Initialize a MS3TraceList container.
Definition tracelist.c:64
#define MSTRACEID_SKIPLIST_HEIGHT
Maximum skip list height for MSTraceIDs.
Definition libmseed.h:590
MS3TraceID * mstl3_findID(MS3TraceList *mstl, const char *sid, uint8_t pubversion, MS3TraceID **prev)
Find matching MS3TraceID in a MS3TraceList.
Definition tracelist.c:160
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:780
Callback functions that return time and sample rate tolerances.
Definition libmseed.h:660
Container for a trace ID, linkable.
Definition libmseed.h:612
Container for a collection of continuous trace segment, linkable.
Definition libmseed.h:628
Container for a continuous trace segment, linkable.
Definition libmseed.h:594
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:1800
uint64_t lmp_nanosleep(uint64_t nanoseconds)
Sleep for a specified number of nanoseconds.
Definition genutils.c:2022
nstime_t ms_sampletime(nstime_t time, int64_t offset, double samprate)
Calculate the time of a sample in an array.
Definition genutils.c:1761
int lmp_fseek64(FILE *stream, int64_t offset, int whence)
Definition genutils.c:2000
int64_t lmp_ftell64(FILE *stream)
Definition genutils.c:1984
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:2054
int8_t flag
Definition libmseed.h:1432
#define LM_SIDLEN
Length of source ID string.
Definition libmseed.h:143
#define DEPRECATED
Definition libmseed.h:210
Type definition for data source I/O: file-system versus URL.
Definition libmseed.h:751
void * handle
Primary IO handle, either file or URL.
Definition libmseed.h:759
void * handle2
Secondary IO handle for URL.
Definition libmseed.h:760
int still_running
Fetch status flag for URL transmissions.
Definition libmseed.h:761
enum LMIO::@254045037044215310213377126306215005316170340112 type
IO handle type.
@ LMIO_FD
IO handle is a provided file descriptor.
Definition libmseed.h:757
@ LMIO_URL
IO handle is URL-type.
Definition libmseed.h:756
@ LMIO_NULL
IO handle type is undefined.
Definition libmseed.h:754
@ LMIO_FILE
IO handle is FILE-type.
Definition libmseed.h:755