libmseed 3.5.4
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.5.4"
33#define LIBMSEED_RELEASE "2026.217"
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#include <io.h>
83
84/* Re-define print conversion for size_t values */
85#undef PRIsize_t
86#if defined(WIN64) || defined(_WIN64)
87#define PRIsize_t "I64u"
88#else
89#define PRIsize_t "I32u"
90#endif
91
92/* For MSVC 2012 and earlier define standard int types, otherwise use inttypes.h */
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;
102#else
103#include <inttypes.h>
104#endif
105
106/* For MSVC define PRId64 and SCNd64 and alternate functions */
107#if defined(_MSC_VER)
108#if !defined(PRId64)
109#define PRId64 "I64d"
110#endif
111#if !defined(SCNd64)
112#define SCNd64 "I64d"
113#endif
114
115#define snprintf _snprintf
116#define vsnprintf _vsnprintf
117#define strtoull _strtoui64
118#define fileno _fileno
119#define dup _dup
120#define dup2 _dup2
121#define close _close
122#define fdopen _fdopen
123#endif
124
125/* Extras needed for MinGW */
126#if defined(__MINGW32__) || defined(__MINGW64__)
127#include <fcntl.h>
128
129#define _fseeki64 fseeko64
130#define _ftelli64 ftello64
131
132#define fstat _fstat
133#define stat _stat
134#endif
135#else
136/* All other platforms */
137#include <inttypes.h>
138#include <sys/time.h>
139#include <unistd.h>
140#endif
141
142#define MINRECLEN 40
143#define MAXRECLEN 10485760
144#define MAXRECLENv2 131172
145
146#define LM_SIDLEN 64
147
150#define MS_ISRATETOLERABLE(A, B) (fabs ((B) - (A)) < 0.0001 * fabs (B))
151
154#define MS2_ISDATAINDICATOR(X) ((X) == 'D' || (X) == 'R' || (X) == 'Q' || (X) == 'M')
155
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)
176
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)
203
205#define bit(x, y) ((x) & (y)) ? 1 : 0
206
208#ifdef _MSC_VER
209#define DEPRECATED __declspec (deprecated)
210#elif defined(__GNUC__) | defined(__clang__)
211#define DEPRECATED __attribute__ ((__deprecated__))
212#else
213#define DEPRECATED
214#endif
215
223
229typedef int64_t nstime_t;
230
234#define NSTMODULUS 1000000000
235
239#define NSTERROR -2145916800000000000LL
240
244#define NSTUNSET -2145916799999999999LL
245
248#define MS_EPOCH2NSTIME(X) (X) * (nstime_t)NSTMODULUS
249
252#define MS_NSTIME2EPOCH(X) (X) / NSTMODULUS
253
261#define MS_HPTIME2NSTIME(X) (X) * (nstime_t)1000
262
270#define MS_NSTIME2HPTIME(X) (X) / 1000
271
290typedef enum
291{
292 ISOMONTHDAY = 0,
293 ISOMONTHDAY_Z = 1,
294 ISOMONTHDAY_DOY = 2,
295 ISOMONTHDAY_DOY_Z = 3,
296 ISOMONTHDAY_SPACE = 4,
297 ISOMONTHDAY_SPACE_Z = 5,
298 SEEDORDINAL = 6,
299 UNIXEPOCH = 7,
300 NANOSECONDEPOCH = 8
302
317typedef enum
318{
319 NONE = 0,
320 MICRO = 1,
321 NANO = 2,
322 MICRO_NONE = 3,
323 NANO_NONE = 4,
324 NANO_MICRO = 5,
325 NANO_MICRO_NONE = 6
327
328extern int ms_nstime2time (nstime_t nstime, uint16_t *year, uint16_t *yday, uint8_t *hour,
329 uint8_t *min, uint8_t *sec, uint32_t *nsec);
330extern char *ms_nstime2timestr_n (nstime_t nstime, char *timestr, size_t timestrsize,
331 ms_timeformat_t timeformat, ms_subseconds_t subsecond);
332DEPRECATED extern char *ms_nstime2timestr (nstime_t nstime, char *timestr,
333 ms_timeformat_t timeformat, ms_subseconds_t subsecond);
334DEPRECATED extern char *ms_nstime2timestrz (nstime_t nstime, char *timestr,
335 ms_timeformat_t timeformat, ms_subseconds_t subsecond);
336extern nstime_t ms_time2nstime (int year, int yday, int hour, int min, int sec, uint32_t nsec);
337extern nstime_t ms_timestr2nstime (const char *timestr);
338extern nstime_t ms_mdtimestr2nstime (const char *timestr);
339extern nstime_t ms_seedtimestr2nstime (const char *seedtimestr);
340extern int ms_doy2md (int year, int yday, int *month, int *mday);
341extern int ms_md2doy (int year, int month, int mday, int *yday);
342
344
354
358#define MS_PACK_DEFAULT_RECLEN 4096
359
363#define MS_PACK_DEFAULT_ENCODING DE_STEIM2
364
368
370typedef struct MS3Record
371{
372 const char *record;
373 int32_t reclen;
374 uint8_t swapflag;
375
376 /* Common header fields in accessible form */
379 uint8_t flags;
381 double samprate;
382 int16_t encoding;
383 uint8_t pubversion;
384 int64_t samplecnt;
385 uint32_t crc;
386 uint16_t extralength;
387 uint32_t datalength;
388 char *extra;
389
390 /* Data sample fields */
392 uint64_t datasize;
393 int64_t numsamples;
395} MS3Record;
396
400#define MS3Record_INITIALIZER \
401 {.record = NULL, \
402 .reclen = -1, \
403 .swapflag = 0, \
404 .sid = {0}, \
405 .formatversion = 0, \
406 .flags = 0, \
407 .starttime = NSTUNSET, \
408 .samprate = 0.0, \
409 .encoding = -1, \
410 .pubversion = 0, \
411 .samplecnt = -1, \
412 .crc = 0, \
413 .extralength = 0, \
414 .datalength = 0, \
415 .extra = NULL, \
416 .datasamples = NULL, \
417 .datasize = 0, \
418 .numsamples = 0, \
419 .sampletype = 0}
420
421extern int msr3_parse (const char *record, uint64_t recbuflen, MS3Record **ppmsr, uint32_t flags,
422 int8_t verbose);
423
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);
426
429
430extern MS3RecordPacker *msr3_pack_init (const MS3Record *msr, uint32_t flags, int8_t verbose);
431extern int msr3_pack_next (MS3RecordPacker *packer, char **record, int32_t *reclen);
432extern void msr3_pack_free (MS3RecordPacker **packer, int64_t *packedsamples);
433
434extern int msr3_repack_mseed3 (const MS3Record *msr, char *record, uint32_t recbuflen,
435 int8_t verbose);
436
437extern int msr3_repack_mseed2 (const MS3Record *msr, char *record, uint32_t recbuflen,
438 int8_t verbose);
439
440extern int msr3_pack_header3 (const MS3Record *msr, char *record, uint32_t recbuflen,
441 int8_t verbose);
442
443extern int msr3_pack_header2 (const MS3Record *msr, char *record, uint32_t recbuflen,
444 int8_t verbose);
445
446extern int64_t msr3_unpack_data (MS3Record *msr, int8_t verbose);
447
448extern int msr3_data_bounds (const MS3Record *msr, uint32_t *dataoffset, uint32_t *datasize);
449
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);
453
454extern MS3Record *msr3_init (MS3Record *msr);
455extern void msr3_free (MS3Record **ppmsr);
456extern MS3Record *msr3_duplicate (const MS3Record *msr, int8_t datadup);
457extern MS3Record *msr3_duplicate_extra (const MS3Record *msr, int8_t datadup, int8_t extradup);
458extern nstime_t msr3_endtime (const MS3Record *msr);
459extern void msr3_print (const MS3Record *msr, int8_t details);
460extern int msr3_resize_buffer (MS3Record *msr);
461extern double msr3_sampratehz (const MS3Record *msr);
462extern nstime_t msr3_nsperiod (const MS3Record *msr);
463extern double msr3_host_latency (const MS3Record *msr);
464
465extern int64_t ms3_detect (const char *record, uint64_t recbuflen, uint8_t *formatversion);
466extern int ms_parse_raw3 (const char *record, int maxreclen, int8_t details);
467extern int ms_parse_raw2 (const char *record, int maxreclen, int8_t details, int8_t swapflag);
469
485
493
495typedef struct MS3Selections
496{
497 char sidpattern[100];
500 uint8_t pubversion;
502
503extern const MS3Selections *ms3_matchselect (const MS3Selections *selections, const char *sid,
504 nstime_t starttime, nstime_t endtime, int pubversion,
505 const MS3SelectTime **ppselecttime);
506extern const MS3Selections *msr3_matchselect (const MS3Selections *selections, const MS3Record *msr,
507 const MS3SelectTime **ppselecttime);
508extern int ms3_addselect (MS3Selections **ppselections, const char *sidpattern, nstime_t starttime,
509 nstime_t endtime, uint8_t pubversion);
510extern int ms3_addselect_comp (MS3Selections **ppselections, char *network, char *station,
511 char *location, char *channel, nstime_t starttime, nstime_t endtime,
512 uint8_t pubversion);
513extern int ms3_readselectionsfile (MS3Selections **ppselections, const char *filename);
514extern void ms3_freeselections (MS3Selections *selections);
515extern void ms3_printselections (const MS3Selections *selections);
517
520
550typedef struct MS3RecordPtr
551{
552 const char *bufferptr;
553 FILE *fileptr;
554 const char *filename;
555 int64_t fileoffset;
558 uint32_t dataoffset;
559 void *prvtptr;
562
570
572
607
609#define MSTRACEID_SKIPLIST_HEIGHT 8
610
628
644
646typedef struct MS3TraceList
647{
648 uint32_t numtraceids;
650 uint64_t prngstate;
652
680typedef struct MS3Tolerance
681{
682 double (*time) (const MS3Record *msr);
683 double (*samprate) (
684 const MS3Record *msr);
686
689#define MS3Tolerance_INITIALIZER {.time = NULL, .samprate = NULL}
690
691extern MS3TraceList *mstl3_init (MS3TraceList *mstl);
692extern void mstl3_free (MS3TraceList **ppmstl, int8_t freeprvtptr);
693extern MS3TraceID *mstl3_findID (MS3TraceList *mstl, const char *sid, uint8_t pubversion,
694 MS3TraceID **prev);
695
696extern MS3TraceSeg *mstl3_addmsr (MS3TraceList *mstl, const MS3Record *msr, int8_t splitversion,
697 int8_t autoheal, uint32_t flags, const MS3Tolerance *tolerance);
699 MS3RecordPtr **pprecptr, int8_t splitversion,
700 int8_t autoheal, uint32_t flags,
701 const MS3Tolerance *tolerance);
702extern int64_t mstl3_readbuffer (MS3TraceList **ppmstl, const char *buffer, uint64_t bufferlength,
703 int8_t splitversion, uint32_t flags, const MS3Tolerance *tolerance,
704 int8_t verbose);
705extern int64_t mstl3_readbuffer_selection (MS3TraceList **ppmstl, const char *buffer,
706 uint64_t bufferlength, int8_t splitversion,
707 uint32_t flags, const MS3Tolerance *tolerance,
708 const MS3Selections *selections, int8_t verbose);
709extern int64_t mstl3_unpack_recordlist (MS3TraceID *id, MS3TraceSeg *seg, void *output,
710 uint64_t outputsize, int8_t verbose);
711extern int mstl3_convertsamples (MS3TraceSeg *seg, char type, int8_t truncate);
712extern int mstl3_resize_buffers (MS3TraceList *mstl);
713extern int64_t mstl3_pack (MS3TraceList *mstl, void (*record_handler) (char *, int, void *),
714 void *handlerdata, int reclen, int8_t encoding, int64_t *packedsamples,
715 uint32_t flags, int8_t verbose, char *extra);
716
719
720extern MS3TraceListPacker *mstl3_pack_init (MS3TraceList *mstl, int reclen, int8_t encoding,
721 uint32_t flags, int8_t verbose, char *extra,
722 uint32_t flush_idle_seconds);
723extern int mstl3_pack_next (MS3TraceListPacker *packer, uint32_t flags, char **record, int32_t *reclen);
724extern void mstl3_pack_free (MS3TraceListPacker **packer, int64_t *packedsamples);
725
726extern int64_t mstl3_pack_ppupdate_flushidle (MS3TraceList *mstl,
727 void (*record_handler) (char *, int, void *),
728 void *handlerdata, int reclen, int8_t encoding,
729 int64_t *packedsamples, uint32_t flags,
730 int8_t verbose, char *extra,
731 uint32_t flush_idle_seconds);
732
733extern int64_t mstl3_pack_segment (MS3TraceList *mstl, MS3TraceID *id, MS3TraceSeg *seg,
734 void (*record_handler) (char *, int, void *), void *handlerdata,
735 int reclen, int8_t encoding, int64_t *packedsamples,
736 uint32_t flags, int8_t verbose, char *extra);
738 void (*) (char *, int, void *), void *, int, int8_t,
739 int64_t *, uint32_t, int8_t, char *);
740extern void mstl3_printtracelist (const MS3TraceList *mstl, ms_timeformat_t timeformat,
741 int8_t details, int8_t gaps, int8_t versions);
742extern void mstl3_printsynclist (const MS3TraceList *mstl, const char *dccid,
743 ms_subseconds_t subseconds);
744extern void mstl3_printgaplist (const MS3TraceList *mstl, ms_timeformat_t timeformat,
745 double *mingap, double *maxgap);
747
782
789typedef struct LMIO
790{
791 enum
792 {
798 void *handle;
799 void *handle2;
802} LMIO;
803
806#define LMIO_INITIALIZER {.type = LMIO_NULL, .handle = NULL, .handle2 = NULL, .still_running = 0, .urlfail = 0}
807
817typedef struct MS3FileParam
818{
819 char path[512];
820 int64_t startoffset;
821 int64_t endoffset;
822 int64_t streampos;
823 int64_t recordcount;
824
828 uint32_t flags;
831
834#define MS3FileParam_INITIALIZER \
835 {.path = "", \
836 .startoffset = 0, \
837 .endoffset = 0, \
838 .streampos = 0, \
839 .recordcount = 0, \
840 .readbuffer = NULL, \
841 .readlength = 0, \
842 .readoffset = 0, \
843 .flags = 0, \
844 .input = LMIO_INITIALIZER}
845
846extern int ms3_readmsr (MS3Record **ppmsr, const char *mspath, uint32_t flags, int8_t verbose);
847extern int ms3_readmsr_r (MS3FileParam **ppmsfp, MS3Record **ppmsr, const char *mspath,
848 uint32_t flags, int8_t verbose);
849extern int ms3_readmsr_selection (MS3FileParam **ppmsfp, MS3Record **ppmsr, const char *mspath,
850 uint32_t flags, const MS3Selections *selections, int8_t verbose);
851extern int ms3_readtracelist (MS3TraceList **ppmstl, const char *mspath,
852 const MS3Tolerance *tolerance, int8_t splitversion, uint32_t flags,
853 int8_t verbose);
854extern int ms3_readtracelist_timewin (MS3TraceList **ppmstl, const char *mspath,
855 const MS3Tolerance *tolerance, nstime_t starttime,
856 nstime_t endtime, int8_t splitversion, uint32_t flags,
857 int8_t verbose);
858extern int ms3_readtracelist_selection (MS3TraceList **ppmstl, const char *mspath,
859 const MS3Tolerance *tolerance,
860 const MS3Selections *selections, int8_t splitversion,
861 uint32_t flags, int8_t verbose);
862extern int ms3_url_useragent (const char *program, const char *version);
863extern int ms3_url_timeout (long connecttimeout, long stalltimeout);
864extern int ms3_url_userpassword (const char *userpassword);
865extern int ms3_url_addheader (const char *header);
866extern void ms3_url_freeheaders (void);
867extern int64_t msr3_writemseed (MS3Record *msr, const char *mspath, int8_t overwrite,
868 uint32_t flags, int8_t verbose);
869extern int64_t mstl3_writemseed (MS3TraceList *mstl, const char *mspath, int8_t overwrite,
870 int maxreclen, int8_t encoding, uint32_t flags, int8_t verbose);
871extern int libmseed_url_support (void);
872extern MS3FileParam *ms3_msfp_init (int64_t startoffset, int64_t endoffset, int fd);
873extern MS3FileParam *ms3_msfp_init_fd (int fd);
875#define ms3_mstl_init_fd(fd) ms3_msfp_init_fd(fd)
877
887extern int ms_sid2nslc_n (const char *sid, char *net, size_t netsize, char *sta, size_t stasize,
888 char *loc, size_t locsize, char *chan, size_t chansize);
889DEPRECATED extern int ms_sid2nslc (const char *sid, char *net, char *sta, char *loc, char *chan);
890extern int ms_nslc2sid (char *sid, int sidlen, uint16_t flags, const char *net, const char *sta,
891 const char *loc, const char *chan);
892extern int ms_seedchan2xchan (char *xchan, const char *seedchan);
893extern int ms_xchan2seedchan (char *seedchan, const char *xchan);
894extern int ms_strncpclean (char *dest, const char *source, int length);
895extern int ms_strncpcleantail (char *dest, const char *source, int length);
896extern int ms_strncpopen (char *dest, const char *source, int length);
898
927
957
995
1021
1041
1047typedef struct LM_PARSED_JSON_s LM_PARSED_JSON;
1048
1049extern int mseh_get_ptr_type (const MS3Record *msr, const char *ptr, LM_PARSED_JSON **parsestate);
1050
1053#define mseh_get(msr, ptr, valueptr, type, maxlength) \
1054 mseh_get_ptr_r (msr, ptr, valueptr, type, maxlength, NULL)
1055
1058#define mseh_get_uint64(msr, ptr, valueptr) mseh_get_ptr_r (msr, ptr, valueptr, 'u', 0, NULL)
1059
1062#define mseh_get_int64(msr, ptr, valueptr) mseh_get_ptr_r (msr, ptr, valueptr, 'i', 0, NULL)
1063
1066#define mseh_get_number(msr, ptr, valueptr) mseh_get_ptr_r (msr, ptr, valueptr, 'n', 0, NULL)
1067
1070#define mseh_get_string(msr, ptr, buffer, maxlength) \
1071 mseh_get_ptr_r (msr, ptr, buffer, 's', maxlength, NULL)
1072
1075#define mseh_get_boolean(msr, ptr, valueptr) mseh_get_ptr_r (msr, ptr, valueptr, 'b', 0, NULL)
1076
1079#define mseh_exists(msr, ptr) (!mseh_get_ptr_r (msr, ptr, NULL, 0, 0, NULL))
1080
1081extern int mseh_get_ptr_r (const MS3Record *msr, const char *ptr, void *value, char type,
1082 uint32_t maxlength, LM_PARSED_JSON **parsestate);
1083
1086#define mseh_set(msr, ptr, valueptr, type) mseh_set_ptr_r (msr, ptr, valueptr, type, NULL)
1087
1090#define mseh_set_uint64(msr, ptr, valueptr) mseh_set_ptr_r (msr, ptr, valueptr, 'u', NULL)
1091
1094#define mseh_set_int64(msr, ptr, valueptr) mseh_set_ptr_r (msr, ptr, valueptr, 'i', NULL)
1095
1098#define mseh_set_number(msr, ptr, valueptr) mseh_set_ptr_r (msr, ptr, valueptr, 'n', NULL)
1099
1102#define mseh_set_string(msr, ptr, valueptr) mseh_set_ptr_r (msr, ptr, valueptr, 's', NULL)
1103
1106#define mseh_set_boolean(msr, ptr, valueptr) mseh_set_ptr_r (msr, ptr, valueptr, 'b', NULL)
1107
1108extern int mseh_set_ptr_r (MS3Record *msr, const char *ptr, void *value, char type,
1109 LM_PARSED_JSON **parsestate);
1110
1111extern int mseh_add_event_detection_r (MS3Record *msr, const char *ptr,
1112 MSEHEventDetection *eventdetection,
1113 LM_PARSED_JSON **parsestate);
1114
1115extern int mseh_add_calibration_r (MS3Record *msr, const char *ptr, MSEHCalibration *calibration,
1116 LM_PARSED_JSON **parsestate);
1117
1118extern int mseh_add_timing_exception_r (MS3Record *msr, const char *ptr,
1119 MSEHTimingException *exception,
1120 LM_PARSED_JSON **parsestate);
1121
1122extern int mseh_add_recenter_r (MS3Record *msr, const char *ptr, MSEHRecenter *recenter,
1123 LM_PARSED_JSON **parsestate);
1124
1125extern int mseh_serialize (MS3Record *msr, LM_PARSED_JSON **parsestate);
1126extern void mseh_free_parsestate (LM_PARSED_JSON **parsestate);
1127extern int mseh_replace (MS3Record *msr, char *jsonstring);
1128
1129extern int mseh_print (const MS3Record *msr, int indent);
1131
1160
1238
1240#define MAX_LOG_MSG_LENGTH 200
1241
1245typedef struct MSLogEntry
1246{
1247 int level;
1248 char function[30];
1250 struct MSLogEntry *next;
1251} MSLogEntry;
1252
1256typedef struct MSLogRegistry
1257{
1258 int maxmessages;
1259 int messagecnt;
1260 MSLogEntry *messages;
1262
1265#define MSLogRegistry_INITIALIZER {.maxmessages = 0, .messagecnt = 0, .messages = NULL}
1266
1272typedef struct MSLogParam
1273{
1274 void (*log_print) (const char *);
1275 const char *logprefix;
1276 void (*diag_print) (const char *);
1277 const char *errprefix;
1279} MSLogParam;
1280
1283#define MSLogParam_INITIALIZER \
1284 {.log_print = NULL, \
1285 .logprefix = NULL, \
1286 .diag_print = NULL, \
1287 .errprefix = NULL, \
1288 .registry = MSLogRegistry_INITIALIZER}
1289
1293#define ms_log(level, ...) ms_rlog (__func__, level, __VA_ARGS__)
1294
1298#define ms_log_l(logp, level, ...) ms_rlog_l (logp, __func__, level, __VA_ARGS__)
1299
1300#if defined(__GNUC__) || defined(__clang__)
1301__attribute__ ((__format__ (__printf__, 3, 4)))
1302#endif
1303extern int
1304ms_rlog (const char *function, int level, const char *format, ...);
1305#if defined(__GNUC__) || defined(__clang__)
1306__attribute__ ((__format__ (__printf__, 4, 5)))
1307#endif
1308extern int
1309ms_rlog_l (MSLogParam *logp, const char *function, int level, const char *format, ...);
1310
1313#define ms_loginit(log_print, logprefix, diag_print, errprefix) \
1314 ms_rloginit (log_print, logprefix, diag_print, errprefix, 0)
1315
1318#define ms_loginit_l(logp, log_print, logprefix, diag_print, errprefix) \
1319 ms_rloginit_l (logp, log_print, logprefix, diag_print, errprefix, 0)
1320
1321extern void ms_rloginit (void (*log_print) (const char *), const char *logprefix,
1322 void (*diag_print) (const char *), const char *errprefix, int maxmessages);
1323extern MSLogParam *ms_rloginit_l (MSLogParam *logp, void (*log_print) (const char *),
1324 const char *logprefix, void (*diag_print) (const char *),
1325 const char *errprefix, int maxmessages);
1326extern int ms_rlog_emit (MSLogParam *logp, int count, int context);
1327extern int ms_rlog_pop (MSLogParam *logp, char *message, size_t size, int context);
1328extern int ms_rlog_free (MSLogParam *logp);
1329
1331
1364typedef struct LeapSecond
1365{
1367 int32_t TAIdelta;
1369} LeapSecond;
1370
1373extern int ms_readleapseconds (const char *envvarname);
1374extern int ms_readleapsecondfile (const char *filename);
1376
1380
1381extern uint8_t ms_samplesize (char sampletype);
1382extern int ms_encoding_sizetype (uint8_t encoding, uint8_t *samplesize, char *sampletype);
1383extern const char *ms_encodingstr (uint8_t encoding);
1384extern const char *ms_errorstr (int errorcode);
1385
1386extern nstime_t ms_sampletime (nstime_t time, int64_t offset, double samprate);
1387extern int ms_bigendianhost (void);
1388
1390#define ms_dabs(val) fabs (val)
1391
1393extern int64_t lmp_ftell64 (FILE *stream);
1395extern int lmp_fseek64 (FILE *stream, int64_t offset, int whence);
1397extern uint64_t lmp_nanosleep (uint64_t nanoseconds);
1399extern nstime_t lmp_systemtime (void);
1401extern int lmp_strncasecmp (const char *s1, const char *s2, size_t n);
1402
1404extern uint32_t ms_crc32c (const uint8_t *input, int length, uint32_t previousCRC32C);
1405
1407static inline void
1408ms_gswap2 (void *data2)
1409{
1410 uint16_t dat;
1411
1412 memcpy (&dat, data2, 2);
1413
1414 dat = (uint16_t)(((dat & 0xff00) >> 8) | ((dat & 0x00ff) << 8));
1415
1416 memcpy (data2, &dat, 2);
1417}
1418
1420static inline void
1421ms_gswap4 (void *data4)
1422{
1423 uint32_t dat;
1424
1425 memcpy (&dat, data4, 4);
1426
1427 dat = ((dat & 0xff000000) >> 24) | ((dat & 0x000000ff) << 24) | ((dat & 0x00ff0000) >> 8) |
1428 ((dat & 0x0000ff00) << 8);
1429
1430 memcpy (data4, &dat, 4);
1431}
1432
1434static inline void
1435ms_gswap8 (void *data8)
1436{
1437 uint64_t dat;
1438
1439 memcpy (&dat, data8, sizeof (uint64_t));
1440
1441 dat = ((dat & 0xff00000000000000) >> 56) | ((dat & 0x00000000000000ff) << 56) |
1442 ((dat & 0x00ff000000000000) >> 40) | ((dat & 0x000000000000ff00) << 40) |
1443 ((dat & 0x0000ff0000000000) >> 24) | ((dat & 0x0000000000ff0000) << 24) |
1444 ((dat & 0x000000ff00000000) >> 8) | ((dat & 0x00000000ff000000) << 8);
1445
1446 memcpy (data8, &dat, sizeof (uint64_t));
1447}
1448
1449#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) || defined(__clang__)
1451__attribute__ ((deprecated ("Use ms_gswap2 instead."))) static inline void
1452ms_gswap2a (void *data2)
1453{
1454 ms_gswap2 (data2);
1455}
1457__attribute__ ((deprecated ("Use ms_gswap4 instead."))) static inline void
1458ms_gswap4a (void *data4)
1459{
1460 ms_gswap4 (data4);
1461}
1463__attribute__ ((deprecated ("Use ms_gswap8 instead."))) static inline void
1464ms_gswap8a (void *data8)
1465{
1466 ms_gswap8 (data8);
1467}
1468#elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320)
1470__declspec (deprecated ("Use ms_gswap2 instead.")) static inline void
1471ms_gswap2a (void *data2)
1472{
1473 ms_gswap2 (data2);
1474}
1476__declspec (deprecated ("Use ms_gswap4 instead.")) static inline void
1477ms_gswap4a (void *data4)
1478{
1479 ms_gswap4 (data4);
1480}
1482__declspec (deprecated ("Use ms_gswap8 instead.")) static inline void
1483ms_gswap8a (void *data8)
1484{
1485 ms_gswap8 (data8);
1486}
1487#else
1489static inline void
1490ms_gswap2a (void *data2)
1491{
1492 ms_gswap2 (data2);
1493}
1495static inline void
1496ms_gswap4a (void *data4)
1497{
1498 ms_gswap4 (data4);
1499}
1501static inline void
1502ms_gswap8a (void *data8)
1503{
1504 ms_gswap8 (data8);
1505}
1506#endif
1507
1509
1511typedef int8_t flag;
1512
1535
1537typedef struct LIBMSEED_MEMORY
1538{
1539 void *(*malloc) (size_t);
1540 void *(*realloc) (void *, size_t);
1541 void (*free) (void *);
1543
1546
1560extern size_t libmseed_prealloc_block_size;
1561
1566extern void *libmseed_memory_prealloc (void *ptr, size_t size, size_t *currentsize);
1567
1569
1570#define DE_ASCII DE_TEXT
1571
1580#define DE_TEXT 0
1581#define DE_INT16 1
1582#define DE_INT32 3
1583#define DE_FLOAT32 4
1584#define DE_FLOAT64 5
1585#define DE_STEIM1 10
1586#define DE_STEIM2 11
1587#define DE_GEOSCOPE24 12
1588#define DE_GEOSCOPE163 13
1589#define DE_GEOSCOPE164 14
1590#define DE_CDSN 16
1591#define DE_SRO 30
1592#define DE_DWWSSN 32
1594
1601#define MSSWAP_HEADER 0x01
1602#define MSSWAP_PAYLOAD 0x02
1604
1610#define MS_ENDOFFILE 1
1611#define MS_NOERROR 0
1612#define MS_GENERROR -1
1613#define MS_NOTSEED -2
1614#define MS_WRONGLENGTH -3
1615#define MS_OUTOFRANGE -4
1616#define MS_UNKNOWNFORMAT -5
1617#define MS_STBADCOMPFLAG -6
1618#define MS_INVALIDCRC -7
1620
1628#define MSF_UNPACKDATA 0x0001
1629#define MSF_SKIPNOTDATA 0x0002
1630#define MSF_VALIDATECRC 0x0004
1631#define MSF_PNAMERANGE 0x0008
1632#define MSF_ATENDOFFILE 0x0010
1633#define MSF_SEQUENCE 0x0020
1634#define MSF_FLUSHDATA 0x0040
1635#define MSF_PACKVER2 0x0080
1636#define MSF_RECORDLIST 0x0100
1637#define MSF_MAINTAINMSTL 0x0200
1638#define MSF_PPUPDATETIME 0x0400
1639#define MSF_SPLITISVERSION 0x0800
1640#define MSF_SKIPADJACENTDUPLICATES 0x1000
1641#define MSF_RECORDLIST_NOEXTRAS 0x2000
1643
1644#ifdef __cplusplus
1645}
1646#endif
1647
1648#endif /* LIBMSEED_H */
struct MS3SelectTime * next
Pointer to next selection time, NULL if the last.
Definition libmseed.h:491
nstime_t endtime
Latest data for matching channels, use NSTUNSET for open.
Definition libmseed.h:490
uint8_t pubversion
Selected publication version, use 0 for any.
Definition libmseed.h:500
char sidpattern[100]
Matching (globbing) pattern for source ID.
Definition libmseed.h:497
struct MS3Selections * next
Pointer to next selection, NULL if the last.
Definition libmseed.h:499
nstime_t starttime
Earliest data for matching channels, use NSTUNSET for open.
Definition libmseed.h:489
struct MS3SelectTime * timewindows
Pointer to time window list for this source ID.
Definition libmseed.h:498
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:186
int ms3_readselectionsfile(MS3Selections **ppselections, const char *filename)
Read data selections from a file.
Definition selection.c:442
void ms3_printselections(const MS3Selections *selections)
Print the selections list using the ms_log() facility.
Definition selection.c:763
void ms3_freeselections(MS3Selections *selections)
Free all memory associated with a MS3Selections.
Definition selection.c:721
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:319
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:488
Data selection structure definition containers.
Definition libmseed.h:496
char type[30]
Definition libmseed.h:942
double duration
Definition libmseed.h:985
char wave[30]
Definition libmseed.h:947
char inputchannel[30]
Definition libmseed.h:988
struct MSEHEventDetection * next
Definition libmseed.h:955
double signalperiod
Definition libmseed.h:945
char amplituderange[30]
Definition libmseed.h:983
int firstpulsepositive
Definition libmseed.h:977
nstime_t onsettime
Definition libmseed.h:950
int medlookback
Definition libmseed.h:953
float vcocorrection
Definition libmseed.h:1013
nstime_t endtime
Definition libmseed.h:975
char type[30]
Definition libmseed.h:972
struct MSEHCalibration * next
Definition libmseed.h:993
int continued
Definition libmseed.h:980
char clockstatus[128]
Definition libmseed.h:1019
double signalamplitude
Definition libmseed.h:944
double stepbetween
Definition libmseed.h:987
uint32_t count
Definition libmseed.h:1016
char units[30]
Definition libmseed.h:948
int alternatesign
Definition libmseed.h:978
char type[30]
Definition libmseed.h:1036
double backgroundestimate
Definition libmseed.h:946
nstime_t time
Definition libmseed.h:1012
double amplitude
Definition libmseed.h:981
char rolloff[30]
Definition libmseed.h:991
char trigger[30]
Definition libmseed.h:979
char coupling[30]
Definition libmseed.h:990
int steps
Definition libmseed.h:976
char noise[30]
Definition libmseed.h:992
char trigger[30]
Definition libmseed.h:1039
char inputunits[30]
Definition libmseed.h:982
double sineperiod
Definition libmseed.h:986
int usec
Definition libmseed.h:1014
uint8_t medsnr[6]
Definition libmseed.h:952
int medpickalgorithm
Definition libmseed.h:954
char type[16]
Definition libmseed.h:1017
nstime_t begintime
Definition libmseed.h:1037
double refamplitude
Definition libmseed.h:989
char detector[30]
Definition libmseed.h:943
nstime_t endtime
Definition libmseed.h:1038
nstime_t begintime
Definition libmseed.h:974
int receptionquality
Definition libmseed.h:1015
int mseh_get_ptr_type(const MS3Record *msr, const char *ptr, LM_PARSED_JSON **parsestate)
Search for and return the type of an extra header value.
Definition extraheaders.c:164
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:1036
int mseh_print(const MS3Record *msr, int indent)
Print the extra header structure for the specified MS3Record.
Definition extraheaders.c:1385
int mseh_serialize(MS3Record *msr, LM_PARSED_JSON **parsestate)
Generate extra headers string (serialize) from internal state.
Definition extraheaders.c:1220
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:668
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:319
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:808
void mseh_free_parsestate(LM_PARSED_JSON **parsestate)
Free internally parsed (deserialized) JSON data.
Definition extraheaders.c:1277
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:467
struct LM_PARSED_JSON_s LM_PARSED_JSON
Internal structure for holding parsed JSON extra headers.
Definition libmseed.h:1047
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:1134
int mseh_replace(MS3Record *msr, char *jsonstring)
Replace extra headers with supplied JSON.
Definition extraheaders.c:1317
Container for calibration parameters for use in extra headers.
Definition libmseed.h:971
Container for event detection parameters for use in extra headers.
Definition libmseed.h:941
Container for recenter parameters for use in extra headers.
Definition libmseed.h:1035
Container for timing exception parameters for use in extra headers.
Definition libmseed.h:1011
int readlength
INTERNAL: Length of data in read buffer.
Definition libmseed.h:826
int64_t streampos
OUTPUT: Read position of input stream.
Definition libmseed.h:822
int64_t endoffset
INPUT: End position in input stream, 0 == unknown (e.g. pipe).
Definition libmseed.h:821
int64_t recordcount
OUTPUT: Count of records read from this stream/file so far.
Definition libmseed.h:823
LMIO input
INTERNAL: IO handle, file or URL.
Definition libmseed.h:829
uint32_t flags
INTERNAL: Stream reading state flags.
Definition libmseed.h:828
char path[512]
INPUT: File name or URL.
Definition libmseed.h:819
int readoffset
INTERNAL: Read offset in read buffer.
Definition libmseed.h:827
char * readbuffer
INTERNAL: Read buffer, allocated internally.
Definition libmseed.h:825
int64_t startoffset
INPUT: Start position in input stream.
Definition libmseed.h:820
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:729
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:823
void ms3_url_freeheaders(void)
Free all set headers for URL-based requests.
Definition fileutils.c:1045
int ms3_readmsr_r(MS3FileParam **ppmsfp, MS3Record **ppmsr, const char *mspath, uint32_t flags, int8_t verbose)
Definition fileutils.c:687
int ms3_url_addheader(const char *header)
Add header to any URL-based requests.
Definition fileutils.c:1025
int libmseed_url_support(void)
Run-time test for URL support in libmseed.
Definition fileutils.c:50
MS3FileParam * ms3_msfp_init_fd(int fd)
Initialize MS3FileParam parameters for a file descriptor.
Definition fileutils.c:79
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:665
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:753
MS3FileParam * ms3_msfp_init(int64_t startoffset, int64_t endoffset, int fd)
Initialize MS3FileParam parameters.
Definition fileutils.c:110
int ms3_url_timeout(long connecttimeout, long stalltimeout)
Set connection and stall timeouts for URL-based requests.
Definition fileutils.c:966
int ms3_readmsr_selection(MS3FileParam **ppmsfp, MS3Record **ppmsr, const char *mspath, uint32_t flags, const MS3Selections *selections, int8_t verbose)
Definition fileutils.c:707
int ms3_url_userpassword(const char *userpassword)
Set authentication credentials for URL-based requests.
Definition fileutils.c:996
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:1084
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:1192
int ms3_url_useragent(const char *program, const char *version)
Set User-Agent header for URL-based requests.
Definition fileutils.c:928
State container for reading miniSEED records from files or URLs.
Definition libmseed.h:818
int32_t TAIdelta
TAI-UTC difference in seconds.
Definition libmseed.h:1367
nstime_t leapsecond
Time of leap second as epoch since 1 January 1900.
Definition libmseed.h:1366
struct LeapSecond * next
Pointer to next entry, NULL if the last.
Definition libmseed.h:1368
LeapSecond * leapsecondlist
int ms_readleapsecondfile(const char *filename)
Read leap second from the specified file.
Definition genutils.c:1979
int ms_readleapseconds(const char *envvarname)
Read leap second file specified by an environment variable.
Definition genutils.c:1950
Leap second list container.
Definition libmseed.h:1365
void(* diag_print)(const char *)
Function to call for diagnostic and error messages.
Definition libmseed.h:1276
char message[MAX_LOG_MSG_LENGTH]
Log, warning or error message.
Definition libmseed.h:1249
char function[30]
Function generating the message.
Definition libmseed.h:1248
void(* log_print)(const char *)
Function to call for regular messages.
Definition libmseed.h:1274
int level
Message level.
Definition libmseed.h:1247
const char * logprefix
Message prefix for regular and diagnostic messages.
Definition libmseed.h:1275
const char * errprefix
Message prefix for error messages.
Definition libmseed.h:1277
MSLogRegistry registry
Message registry.
Definition libmseed.h:1278
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:1240
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:1246
Logging parameters. Callers should not modify these values directly and generally should not need to ...
Definition libmseed.h:1273
Log message registry.
Definition libmseed.h:1257
void(* free)(void *)
Pointer to desired free().
Definition libmseed.h:1541
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:1538
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:232
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:775
struct MS3RecordPacker MS3RecordPacker
Opaque packing context for MS3Record generator-style interface.
Definition libmseed.h:428
MS3Record * msr3_duplicate_extra(const MS3Record *msr, int8_t datadup, int8_t extradup)
Duplicate a MS3Record.
Definition msrutils.c:120
void msr3_print(const MS3Record *msr, int8_t details)
Print header values of an MS3Record.
Definition msrutils.c:248
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:367
int64_t msr3_unpack_data(MS3Record *msr, int8_t verbose)
Unpack data samples for a MS3Record.
Definition unpack.c:1257
double msr3_host_latency(const MS3Record *msr)
Calculate data latency based on the host time.
Definition msrutils.c:417
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:1110
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:331
int msr3_resize_buffer(MS3Record *msr)
Resize data sample buffer of MS3Record to what is needed.
Definition msrutils.c:324
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:1419
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:992
int msr3_pack_next(MS3RecordPacker *packer, char **record, int32_t *reclen)
Generate next miniSEED record.
Definition pack.c:477
MS3Record * msr3_duplicate(const MS3Record *msr, int8_t datadup)
Duplicate a MS3Record.
Definition msrutils.c:201
nstime_t msr3_endtime(const MS3Record *msr)
Calculate time of the last sample in a record.
Definition msrutils.c:223
void msr3_pack_free(MS3RecordPacker **packer, int64_t *packedsamples)
Free packer and resources.
Definition pack.c:704
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:535
nstime_t msr3_nsperiod(const MS3Record *msr)
Calculate sample period in nanoseconds/sample for a given MS3Record.
Definition msrutils.c:386
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:870
int msr3_data_bounds(const MS3Record *msr, uint32_t *dataoffset, uint32_t *datasize)
Determine the data payload bounds for a MS3Record.
Definition unpack.c:1143
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:560
void * prvtptr
Private pointer, will not be populated by library but will be free'd.
Definition libmseed.h:559
MS3RecordPtr * last
Pointer to last entry, NULL if the none.
Definition libmseed.h:568
int64_t fileoffset
Offset into file to record for fileptr or filename.
Definition libmseed.h:555
const char * filename
Pointer (borrowed) to file name containing record, NULL if not used.
Definition libmseed.h:554
MS3RecordPtr * first
Pointer to first entry, NULL if the none.
Definition libmseed.h:567
MS3Record * msr
Pointer to MS3Record for this record, msr->record is only valid if from a caller-supplied buffer.
Definition libmseed.h:556
const char * bufferptr
Pointer in buffer to record, NULL if not used.
Definition libmseed.h:552
FILE * fileptr
Pointer to open FILE containing record, NULL if not used.
Definition libmseed.h:553
uint64_t recordcnt
Count of records in the list (for convenience).
Definition libmseed.h:566
nstime_t endtime
End time of record, time of last sample.
Definition libmseed.h:557
uint32_t dataoffset
Offset from start of record to encoded data.
Definition libmseed.h:558
Record list, holds MS3RecordPtr entries that contribute to a given MS3TraceSeg.
Definition libmseed.h:565
A miniSEED record pointer and metadata.
Definition libmseed.h:551
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:250
int ms_strncpopen(char *dest, const char *source, int length)
Copy fixed number of characters into unterminated string.
Definition genutils.c:815
DEPRECATED int ms_sid2nslc(const char *sid, char *net, char *sta, char *loc, char *chan)
Definition genutils.c:367
int ms_strncpclean(char *dest, const char *source, int length)
Copy string, removing spaces, always terminated.
Definition genutils.c:709
int ms_xchan2seedchan(char *seedchan, const char *xchan)
Convert extended channel to SEED 2.x channel.
Definition genutils.c:599
int ms_seedchan2xchan(char *xchan, const char *seedchan)
Convert SEED 2.x channel to extended channel.
Definition genutils.c:544
int ms_strncpcleantail(char *dest, const char *source, int length)
Copy string, removing trailing spaces, always terminated.
Definition genutils.c:763
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:405
struct MS3TraceID * next[MSTRACEID_SKIPLIST_HEIGHT]
Next trace ID at first pointer, NULL if the last.
Definition libmseed.h:640
int64_t numsamples
Number of data samples in datasamples.
Definition libmseed.h:620
struct MS3RecordList * recordlist
List of pointers to records that contributed.
Definition libmseed.h:624
uint64_t prngstate
INTERNAL: State for Pseudo RNG.
Definition libmseed.h:650
nstime_t endtime
Time of last sample.
Definition libmseed.h:615
struct MS3TraceSeg * first
Pointer to first of list of segments.
Definition libmseed.h:638
nstime_t latest
Time of latest sample.
Definition libmseed.h:635
struct MS3TraceID traces
Head node of trace skip list, first entry at traces.next[0].
Definition libmseed.h:649
uint8_t pubversion
Largest contributing publication version.
Definition libmseed.h:633
void * prvtptr
Definition libmseed.h:622
uint8_t height
Height of skip list at next.
Definition libmseed.h:642
uint64_t datasize
Size of datasamples buffer in bytes.
Definition libmseed.h:619
nstime_t earliest
Time of earliest sample.
Definition libmseed.h:634
double(* samprate)(const MS3Record *msr)
Pointer to function that returns sample rate tolerance.
Definition libmseed.h:683
void * prvtptr
Private pointer for general use, unused by library.
Definition libmseed.h:636
void * datasamples
Data samples, numsamples of type sampletype.
Definition libmseed.h:618
char sampletype
Sample type code, see Sample Types.
Definition libmseed.h:621
struct MS3TraceSeg * prev
Pointer to previous segment.
Definition libmseed.h:625
int64_t samplecnt
Number of samples in trace coverage.
Definition libmseed.h:617
char sid[LM_SIDLEN]
Source identifier as URN, max length LM_SIDLEN.
Definition libmseed.h:632
struct MS3TraceSeg * last
Pointer to last of list of segments.
Definition libmseed.h:639
uint32_t numtraceids
Number of traces IDs in list.
Definition libmseed.h:648
double(* time)(const MS3Record *msr)
Pointer to function that returns time tolerance.
Definition libmseed.h:682
double samprate
Nominal sample rate (Hz).
Definition libmseed.h:616
struct MS3TraceSeg * next
Pointer to next segment, NULL if the last.
Definition libmseed.h:626
nstime_t starttime
Time of first sample.
Definition libmseed.h:614
uint32_t numsegments
Number of segments for this ID.
Definition libmseed.h:637
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:2209
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:3761
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:3626
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:2717
void mstl3_free(MS3TraceList **ppmstl, int8_t freeprvtptr)
Free all memory associated with a MS3TraceList.
Definition tracelist.c:123
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:1249
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:1315
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:3077
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:3841
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:3458
int mstl3_resize_buffers(MS3TraceList *mstl)
Resize data sample buffers of MS3TraceList to what is needed.
Definition tracelist.c:2117
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:1365
struct MS3TraceListPacker MS3TraceListPacker
Opaque packing context for MS3TraceList generator-style interface.
Definition libmseed.h:718
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:2763
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:3594
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:1953
MS3TraceList * mstl3_init(MS3TraceList *mstl)
Initialize a MS3TraceList container.
Definition tracelist.c:88
#define MSTRACEID_SKIPLIST_HEIGHT
Maximum skip list height for MSTraceIDs.
Definition libmseed.h:609
MS3TraceID * mstl3_findID(MS3TraceList *mstl, const char *sid, uint8_t pubversion, MS3TraceID **prev)
Find matching MS3TraceID in a MS3TraceList.
Definition tracelist.c:184
void mstl3_pack_free(MS3TraceListPacker **packer, int64_t *packedsamples)
Free trace list packing state and resources.
Definition tracelist.c:3372
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:2822
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:1271
Callback functions that return time and sample rate tolerances.
Definition libmseed.h:681
Container for a trace ID, linkable.
Definition libmseed.h:631
Container for a collection of continuous trace segment, linkable.
Definition libmseed.h:647
Container for a continuous trace segment, linkable.
Definition libmseed.h:613
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:1926
uint64_t lmp_nanosleep(uint64_t nanoseconds)
Sleep for a specified number of nanoseconds.
Definition genutils.c:2159
nstime_t ms_sampletime(nstime_t time, int64_t offset, double samprate)
Calculate the time of a sample in an array.
Definition genutils.c:1866
int lmp_fseek64(FILE *stream, int64_t offset, int whence)
Definition genutils.c:2137
int64_t lmp_ftell64(FILE *stream)
Definition genutils.c:2121
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:2192
int lmp_strncasecmp(const char *s1, const char *s2, size_t n)
Case-insensitive, ASCII-only string comparison.
Definition genutils.c:2239
int8_t flag
Definition libmseed.h:1511
#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:790
void * handle
Primary IO handle, either file or URL.
Definition libmseed.h:798
void * handle2
Secondary IO handle for URL.
Definition libmseed.h:799
int still_running
Fetch status flag for URL transmissions.
Definition libmseed.h:800
int urlfail
Transfer failure flag for URL transmissions.
Definition libmseed.h:801
enum LMIO::@254045037044215310213377126306215005316170340112 type
IO handle type.
@ LMIO_FD
IO handle is a provided file descriptor.
Definition libmseed.h:796
@ LMIO_URL
IO handle is URL-type.
Definition libmseed.h:795
@ LMIO_NULL
IO handle type is undefined.
Definition libmseed.h:793
@ LMIO_FILE
IO handle is FILE-type.
Definition libmseed.h:794