libmseed 3.1.3
The miniSEED data format library
Loading...
Searching...
No Matches
libmseed.h
Go to the documentation of this file.
1/**********************************************************************/
24#ifndef LIBMSEED_H
25#define LIBMSEED_H 1
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31#define LIBMSEED_VERSION "3.1.3"
32#define LIBMSEED_RELEASE "2024.165"
33
59/* C99 standard headers */
60#include <stdlib.h>
61#include <stdio.h>
62#include <stdarg.h>
63#include <time.h>
64#include <string.h>
65#include <ctype.h>
66#include <math.h>
67
70#define PRIsize_t "zu"
71
72#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
73 #define LMP_WIN 1
74#endif
75
76/* Set platform specific features, Windows versus everything else */
77#if defined(LMP_WIN)
78 #include <windows.h>
79 #include <sys/types.h>
80
81 /* Re-define print conversion for size_t values */
82 #undef PRIsize_t
83 #if defined(WIN64) || defined(_WIN64)
84 #define PRIsize_t "I64u"
85 #else
86 #define PRIsize_t "I32u"
87 #endif
88
89 /* For MSVC 2012 and earlier define standard int types, otherwise use inttypes.h */
90 #if defined(_MSC_VER) && _MSC_VER <= 1700
91 typedef signed char int8_t;
92 typedef unsigned char uint8_t;
93 typedef signed short int int16_t;
94 typedef unsigned short int uint16_t;
95 typedef signed int int32_t;
96 typedef unsigned int uint32_t;
97 typedef signed __int64 int64_t;
98 typedef unsigned __int64 uint64_t;
99 #else
100 #include <inttypes.h>
101 #endif
102
103 /* For MSVC define PRId64 and SCNd64 and alternate functions */
104 #if defined(_MSC_VER)
105 #if !defined(PRId64)
106 #define PRId64 "I64d"
107 #endif
108 #if !defined(SCNd64)
109 #define SCNd64 "I64d"
110 #endif
111
112 #define snprintf _snprintf
113 #define vsnprintf _vsnprintf
114 #define strcasecmp _stricmp
115 #define strncasecmp _strnicmp
116 #define strtoull _strtoui64
117 #define fileno _fileno
118 #define fdopen _fdopen
119 #endif
120
121 /* Extras needed for MinGW */
122 #if defined(__MINGW32__) || defined(__MINGW64__)
123 #include <fcntl.h>
124
125 #define _fseeki64 fseeko64
126 #define _ftelli64 ftello64
127
128 #define fstat _fstat
129 #define stat _stat
130 #endif
131#else
132 /* All other platforms */
133 #include <inttypes.h>
134#endif
135
136#define MINRECLEN 40
137#define MAXRECLEN 10485760
138#define MAXRECLENv2 131172
139
140#define LM_SIDLEN 64
141
144#define MS_ISRATETOLERABLE(A,B) (fabs (1.0 - ((A) / (B))) < 0.0001)
145
148#define MS2_ISDATAINDICATOR(X) ((X)=='D' || (X)=='R' || (X)=='Q' || (X)=='M')
149
166#define MS3_ISVALIDHEADER(X) ( \
167 *(X) == 'M' && *((X) + 1) == 'S' && *((X) + 2) == 3 && \
168 (uint8_t) (*((X) + 12)) >= 0 && (uint8_t) (*((X) + 12)) <= 23 && \
169 (uint8_t) (*((X) + 13)) >= 0 && (uint8_t) (*((X) + 13)) <= 59 && \
170 (uint8_t) (*((X) + 14)) >= 0 && (uint8_t) (*((X) + 14)) <= 60)
171
188#define MS2_ISVALIDHEADER(X) ( \
189 (isdigit ((uint8_t) * (X)) || *(X) == ' ' || !*(X)) && \
190 (isdigit ((uint8_t) * ((X) + 1)) || *((X) + 1) == ' ' || !*((X) + 1)) && \
191 (isdigit ((uint8_t) * ((X) + 2)) || *((X) + 2) == ' ' || !*((X) + 2)) && \
192 (isdigit ((uint8_t) * ((X) + 3)) || *((X) + 3) == ' ' || !*((X) + 3)) && \
193 (isdigit ((uint8_t) * ((X) + 4)) || *((X) + 4) == ' ' || !*((X) + 4)) && \
194 (isdigit ((uint8_t) * ((X) + 5)) || *((X) + 5) == ' ' || !*((X) + 5)) && \
195 MS2_ISDATAINDICATOR (*((X) + 6)) && \
196 (*((X) + 7) == ' ' || *((X) + 7) == '\0') && \
197 (uint8_t) (*((X) + 24)) >= 0 && (uint8_t) (*((X) + 24)) <= 23 && \
198 (uint8_t) (*((X) + 25)) >= 0 && (uint8_t) (*((X) + 25)) <= 59 && \
199 (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
225typedef int64_t nstime_t;
226
230#define NSTMODULUS 1000000000
231
235#define NSTERROR -2145916800000000000LL
236
240#define NSTUNSET -2145916799999999999LL
241
244#define MS_EPOCH2NSTIME(X) (X) * (nstime_t) NSTMODULUS
245
248#define MS_NSTIME2EPOCH(X) (X) / NSTMODULUS
249
257#define MS_HPTIME2NSTIME(X) (X) * (nstime_t) 1000
258
266#define MS_NSTIME2HPTIME(X) (X) / 1000
267
282typedef enum
283{
284 ISOMONTHDAY = 0,
285 ISOMONTHDAY_Z = 1,
286 ISOMONTHDAY_DOY = 2,
287 ISOMONTHDAY_DOY_Z = 3,
288 ISOMONTHDAY_SPACE = 4,
289 ISOMONTHDAY_SPACE_Z = 5,
290 SEEDORDINAL = 6,
291 UNIXEPOCH = 7,
292 NANOSECONDEPOCH = 8
294
307typedef enum
308{
309 NONE = 0,
310 MICRO = 1,
311 NANO = 2,
312 MICRO_NONE = 3,
313 NANO_NONE = 4,
314 NANO_MICRO = 5,
315 NANO_MICRO_NONE = 6
317
318extern int ms_nstime2time (nstime_t nstime, uint16_t *year, uint16_t *yday,
319 uint8_t *hour, uint8_t *min, uint8_t *sec, uint32_t *nsec);
320extern char* ms_nstime2timestr (nstime_t nstime, char *timestr,
321 ms_timeformat_t timeformat, ms_subseconds_t subsecond);
322DEPRECATED extern char* ms_nstime2timestrz (nstime_t nstime, char *timestr,
323 ms_timeformat_t timeformat, ms_subseconds_t subsecond);
324extern nstime_t ms_time2nstime (int year, int yday, int hour, int min, int sec, uint32_t nsec);
325extern nstime_t ms_timestr2nstime (const char *timestr);
326extern nstime_t ms_mdtimestr2nstime (const char *timestr);
327extern nstime_t ms_seedtimestr2nstime (const char *seedtimestr);
328extern int ms_doy2md (int year, int yday, int *month, int *mday);
329extern int ms_md2doy (int year, int month, int mday, int *yday);
330
346#define MS_PACK_DEFAULT_RECLEN 4096
347
351#define MS_PACK_DEFAULT_ENCODING DE_STEIM2
352
358typedef struct MS3Record {
359 const char *record;
360 int32_t reclen;
361 uint8_t swapflag;
362
363 /* Common header fields in accessible form */
366 uint8_t flags;
368 double samprate;
369 int16_t encoding;
370 uint8_t pubversion;
371 int64_t samplecnt;
372 uint32_t crc;
373 uint16_t extralength;
374 uint32_t datalength;
375 char *extra;
376
377 /* Data sample fields */
379 uint64_t datasize;
380 int64_t numsamples;
382} MS3Record;
383
384extern int msr3_parse (const char *record, uint64_t recbuflen, MS3Record **ppmsr,
385 uint32_t flags, int8_t verbose);
386
387extern int msr3_pack (const MS3Record *msr,
388 void (*record_handler) (char *, int, void *),
389 void *handlerdata, int64_t *packedsamples,
390 uint32_t flags, int8_t verbose);
391
392extern int msr3_repack_mseed3 (const MS3Record *msr, char *record, uint32_t recbuflen, int8_t verbose);
393
394extern int msr3_pack_header3 (const MS3Record *msr, char *record, uint32_t recbuflen, int8_t verbose);
395
396extern int msr3_pack_header2 (const MS3Record *msr, char *record, uint32_t recbuflen, int8_t verbose);
397
398extern int64_t msr3_unpack_data (MS3Record *msr, int8_t verbose);
399
400extern int msr3_data_bounds (const MS3Record *msr, uint32_t *dataoffset, uint32_t *datasize);
401
402extern int64_t ms_decode_data (const void *input, uint64_t inputsize, uint8_t encoding,
403 uint64_t samplecount, void *output, uint64_t outputsize,
404 char *sampletype, int8_t swapflag, const char *sid, int8_t verbose);
405
406extern MS3Record* msr3_init (MS3Record *msr);
407extern void msr3_free (MS3Record **ppmsr);
408extern MS3Record* msr3_duplicate (const MS3Record *msr, int8_t datadup);
409extern nstime_t msr3_endtime (const MS3Record *msr);
410extern void msr3_print (const MS3Record *msr, int8_t details);
411extern int msr3_resize_buffer (MS3Record *msr);
412extern double msr3_sampratehz (const MS3Record *msr);
413extern nstime_t msr3_nsperiod (const MS3Record *msr);
414extern double msr3_host_latency (const MS3Record *msr);
415
416extern int64_t ms3_detect (const char *record, uint64_t recbuflen, uint8_t *formatversion);
417extern int ms_parse_raw3 (const char *record, int maxreclen, int8_t details);
418extern int ms_parse_raw2 (const char *record, int maxreclen, int8_t details, int8_t swapflag);
443
451
452extern const MS3Selections* ms3_matchselect (const MS3Selections *selections, const char *sid,
453 nstime_t starttime, nstime_t endtime,
454 int pubversion, const MS3SelectTime **ppselecttime);
455extern const MS3Selections* msr3_matchselect (const MS3Selections *selections, const MS3Record *msr,
456 const MS3SelectTime **ppselecttime);
457extern int ms3_addselect (MS3Selections **ppselections, const char *sidpattern,
458 nstime_t starttime, nstime_t endtime, uint8_t pubversion);
459extern int ms3_addselect_comp (MS3Selections **ppselections,
460 char *network, char* station, char *location, char *channel,
461 nstime_t starttime, nstime_t endtime, uint8_t pubversion);
462extern int ms3_readselectionsfile (MS3Selections **ppselections, const char *filename);
463extern void ms3_freeselections (MS3Selections *selections);
464extern void ms3_printselections (const MS3Selections *selections);
492typedef struct MS3RecordPtr
493{
494 const char *bufferptr;
495 FILE *fileptr;
496 const char *filename;
497 int64_t fileoffset;
500 uint32_t dataoffset;
501 void *prvtptr;
504
512
547#define MSTRACEID_SKIPLIST_HEIGHT 8
548
564
578
580typedef struct MS3TraceList {
581 uint32_t numtraceids;
583 uint64_t prngstate;
585
611typedef struct MS3Tolerance
612{
613 double (*time) (const MS3Record *msr);
614 double (*samprate) (const MS3Record *msr);
616
619#define MS3Tolerance_INITIALIZER \
620 { \
621 .time = NULL, .samprate = NULL \
622 }
623
624extern MS3TraceList* mstl3_init (MS3TraceList *mstl);
625extern void mstl3_free (MS3TraceList **ppmstl, int8_t freeprvtptr);
626extern MS3TraceID* mstl3_findID (MS3TraceList *mstl, const char *sid, uint8_t pubversion, MS3TraceID **prev);
627
630#define mstl3_addmsr(mstl, msr, splitversion, autoheal, flags, tolerance) \
631 mstl3_addmsr_recordptr (mstl, msr, NULL, splitversion, autoheal, flags, tolerance)
632
633extern MS3TraceSeg* mstl3_addmsr_recordptr (MS3TraceList *mstl, const MS3Record *msr, MS3RecordPtr **pprecptr,
634 int8_t splitversion, int8_t autoheal, uint32_t flags,
635 const MS3Tolerance *tolerance);
636extern int64_t mstl3_readbuffer (MS3TraceList **ppmstl, const char *buffer, uint64_t bufferlength,
637 int8_t splitversion, uint32_t flags,
638 const MS3Tolerance *tolerance, int8_t verbose);
639extern int64_t mstl3_readbuffer_selection (MS3TraceList **ppmstl, const char *buffer, uint64_t bufferlength,
640 int8_t splitversion, uint32_t flags,
641 const MS3Tolerance *tolerance, const MS3Selections *selections,
642 int8_t verbose);
643extern int64_t mstl3_unpack_recordlist (MS3TraceID *id, MS3TraceSeg *seg, void *output,
644 uint64_t outputsize, int8_t verbose);
645extern int mstl3_convertsamples (MS3TraceSeg *seg, char type, int8_t truncate);
646extern int mstl3_resize_buffers (MS3TraceList *mstl);
647extern int64_t mstl3_pack (MS3TraceList *mstl, void (*record_handler) (char *, int, void *),
648 void *handlerdata, int reclen, int8_t encoding,
649 int64_t *packedsamples, uint32_t flags, int8_t verbose, char *extra);
650extern void mstl3_printtracelist (const MS3TraceList *mstl, ms_timeformat_t timeformat,
651 int8_t details, int8_t gaps, int8_t versions);
652extern void mstl3_printsynclist (const MS3TraceList *mstl, const char *dccid, ms_subseconds_t subseconds);
653extern void mstl3_printgaplist (const MS3TraceList *mstl, ms_timeformat_t timeformat,
654 double *mingap, double *maxgap);
691typedef struct LMIO
692{
693 enum
694 {
698 LMIO_FD = 3
700 void *handle;
701 void *handle2;
703} LMIO;
704
707#define LMIO_INITIALIZER \
708 { \
709 .type = LMIO_NULL, .handle = NULL, .handle2 = NULL, .still_running = 0 \
710 }
711
719typedef struct MS3FileParam
720{
721 char path[512];
722 int64_t startoffset;
723 int64_t endoffset;
724 int64_t streampos;
725 int64_t recordcount;
726
730 uint32_t flags;
733
736#define MS3FileParam_INITIALIZER \
737 { \
738 .path = "", .startoffset = 0, .endoffset = 0, .streampos = 0, \
739 .recordcount = 0, .readbuffer = NULL, .readlength = 0, \
740 .readoffset = 0, .flags = 0, .input = LMIO_INITIALIZER \
741 }
742
743extern int ms3_readmsr (MS3Record **ppmsr, const char *mspath, uint32_t flags, int8_t verbose);
744extern int ms3_readmsr_r (MS3FileParam **ppmsfp, MS3Record **ppmsr, const char *mspath,
745 uint32_t flags, int8_t verbose);
746extern int ms3_readmsr_selection (MS3FileParam **ppmsfp, MS3Record **ppmsr, const char *mspath,
747 uint32_t flags, const MS3Selections *selections, int8_t verbose);
748extern int ms3_readtracelist (MS3TraceList **ppmstl, const char *mspath, const MS3Tolerance *tolerance,
749 int8_t splitversion, uint32_t flags, int8_t verbose);
750extern int ms3_readtracelist_timewin (MS3TraceList **ppmstl, const char *mspath, const MS3Tolerance *tolerance,
751 nstime_t starttime, nstime_t endtime, int8_t splitversion, uint32_t flags,
752 int8_t verbose);
753extern int ms3_readtracelist_selection (MS3TraceList **ppmstl, const char *mspath, const MS3Tolerance *tolerance,
754 const MS3Selections *selections, int8_t splitversion, uint32_t flags, int8_t verbose);
755extern int ms3_url_useragent (const char *program, const char *version);
756extern int ms3_url_userpassword (const char *userpassword);
757extern int ms3_url_addheader (const char *header);
758extern void ms3_url_freeheaders (void);
759extern int64_t msr3_writemseed (MS3Record *msr, const char *mspath, int8_t overwrite,
760 uint32_t flags, int8_t verbose);
761extern int64_t mstl3_writemseed (MS3TraceList *mst, const char *mspath, int8_t overwrite,
762 int maxreclen, int8_t encoding, uint32_t flags, int8_t verbose);
763extern int libmseed_url_support (void);
764extern MS3FileParam *ms3_mstl_init_fd (int fd);
776extern int ms_sid2nslc (const char *sid, char *net, char *sta, char *loc, char *chan);
777extern int ms_nslc2sid (char *sid, int sidlen, uint16_t flags,
778 const char *net, const char *sta, const char *loc, const char *chan);
779extern int ms_seedchan2xchan (char *xchan, const char *seedchan);
780extern int ms_xchan2seedchan (char *seedchan, const char *xchan);
781extern int ms_strncpclean (char *dest, const char *source, int length);
782extern int ms_strncpcleantail (char *dest, const char *source, int length);
783extern int ms_strncpopen (char *dest, const char *source, int length);
838
870
889
905
906
912typedef struct LM_PARSED_JSON_s LM_PARSED_JSON;
913
916#define mseh_get(msr, ptr, valueptr, type, maxlength) \
917 mseh_get_ptr_r (msr, ptr, valueptr, type, maxlength, NULL)
918
921#define mseh_get_number(msr, ptr, valueptr) \
922 mseh_get_ptr_r (msr, ptr, valueptr, 'n', 0, NULL)
923
926#define mseh_get_int64(msr, ptr, valueptr) \
927 mseh_get_ptr_r (msr, ptr, valueptr, 'i', 0, NULL)
928
931#define mseh_get_string(msr, ptr, buffer, maxlength) \
932 mseh_get_ptr_r (msr, ptr, buffer, 's', maxlength, NULL)
933
936#define mseh_get_boolean(msr, ptr, valueptr) \
937 mseh_get_ptr_r (msr, ptr, valueptr, 'b', 0, NULL)
938
941#define mseh_exists(msr, ptr) \
942 (!mseh_get_ptr_r (msr, ptr, NULL, 0, 0, NULL))
943
944extern int mseh_get_ptr_r (const MS3Record *msr, const char *ptr,
945 void *value, char type, uint32_t maxlength,
946 LM_PARSED_JSON **parsestate);
947
950#define mseh_set(msr, ptr, valueptr, type) \
951 mseh_set_ptr_r (msr, ptr, valueptr, type, NULL)
952
955#define mseh_set_number(msr, ptr, valueptr) \
956 mseh_set_ptr_r (msr, ptr, valueptr, 'n', NULL)
957
960#define mseh_set_int64(msr, ptr, valueptr) \
961 mseh_set_ptr_r (msr, ptr, valueptr, 'i', NULL)
962
965#define mseh_set_string(msr, ptr, valueptr) \
966 mseh_set_ptr_r (msr, ptr, valueptr, 's', NULL)
967
970#define mseh_set_boolean(msr, ptr, valueptr) \
971 mseh_set_ptr_r (msr, ptr, valueptr, 'b', NULL)
972
973extern int mseh_set_ptr_r (MS3Record *msr, const char *ptr,
974 void *value, char type,
975 LM_PARSED_JSON **parsestate);
976
977extern int mseh_add_event_detection_r (MS3Record *msr, const char *ptr,
978 MSEHEventDetection *eventdetection,
979 LM_PARSED_JSON **parsestate);
980
981extern int mseh_add_calibration_r (MS3Record *msr, const char *ptr,
982 MSEHCalibration *calibration,
983 LM_PARSED_JSON **parsestate);
984
985extern int mseh_add_timing_exception_r (MS3Record *msr, const char *ptr,
986 MSEHTimingException *exception,
987 LM_PARSED_JSON **parsestate);
988
989extern int mseh_add_recenter_r (MS3Record *msr, const char *ptr,
990 MSEHRecenter *recenter,
991 LM_PARSED_JSON **parsestate);
992
993extern int mseh_serialize (MS3Record *msr, LM_PARSED_JSON **parsestate);
994extern void mseh_free_parsestate (LM_PARSED_JSON **parsestate);
995extern int mseh_replace (MS3Record *msr, char *jsonstring);
996
997extern int mseh_print (const MS3Record *msr, int indent);
1106#define MAX_LOG_MSG_LENGTH 200
1107
1111typedef struct MSLogEntry
1112{
1113 int level;
1114 char function[30];
1116 struct MSLogEntry *next;
1117} MSLogEntry;
1118
1122typedef struct MSLogRegistry
1123{
1124 int maxmessages;
1125 int messagecnt;
1126 MSLogEntry *messages;
1128
1131#define MSLogRegistry_INITIALIZER \
1132 { \
1133 .maxmessages = 0, .messagecnt = 0, .messages = NULL \
1134 }
1135
1141typedef struct MSLogParam
1142{
1143 void (*log_print)(const char*);
1144 const char *logprefix;
1145 void (*diag_print)(const char*);
1146 const char *errprefix;
1148} MSLogParam;
1149
1152#define MSLogParam_INITIALIZER \
1153 { \
1154 .log_print = NULL, .logprefix = NULL, \
1155 .diag_print = NULL, .errprefix = NULL, \
1156 .registry = MSLogRegistry_INITIALIZER \
1157 }
1158
1162#define ms_log(level, ...) \
1163 ms_rlog(__func__, level, __VA_ARGS__)
1164
1168#define ms_log_l(logp, level, ...) \
1169 ms_rlog_l(logp, __func__, level, __VA_ARGS__)
1170
1171#if defined(__GNUC__) || defined(__clang__)
1172__attribute__((__format__ (__printf__, 3, 4)))
1173#endif
1174extern int ms_rlog (const char *function, int level, const char *format, ...);
1175#if defined(__GNUC__) || defined(__clang__)
1176__attribute__ ((__format__ (__printf__, 4, 5)))
1177#endif
1178extern int ms_rlog_l (MSLogParam *logp, const char *function, int level, const char *format, ...);
1179
1182#define ms_loginit(log_print, logprefix, diag_print, errprefix) \
1183 ms_rloginit(log_print, logprefix, diag_print, errprefix, 0)
1184
1187#define ms_loginit_l(logp, log_print, logprefix, diag_print, errprefix) \
1188 ms_rloginit_l(logp, log_print, logprefix, diag_print, errprefix, 0)
1189
1190extern void ms_rloginit (void (*log_print)(const char*), const char *logprefix,
1191 void (*diag_print)(const char*), const char *errprefix,
1192 int maxmessages);
1193extern MSLogParam *ms_rloginit_l (MSLogParam *logp,
1194 void (*log_print)(const char*), const char *logprefix,
1195 void (*diag_print)(const char*), const char *errprefix,
1196 int maxmessages);
1197extern int ms_rlog_emit (MSLogParam *logp, int count, int context);
1198extern int ms_rlog_free (MSLogParam *logp);
1199
1234typedef struct LeapSecond
1235{
1237 int32_t TAIdelta;
1239} LeapSecond;
1240
1243extern int ms_readleapseconds (const char *envvarname);
1244extern int ms_readleapsecondfile (const char *filename);
1251extern uint8_t ms_samplesize (char sampletype);
1252extern int ms_encoding_sizetype (uint8_t encoding, uint8_t *samplesize, char *sampletype);
1253extern const char *ms_encodingstr (uint8_t encoding);
1254extern const char *ms_errorstr (int errorcode);
1255
1256extern nstime_t ms_sampletime (nstime_t time, int64_t offset, double samprate);
1257extern int ms_bigendianhost (void);
1258
1260#define ms_dabs(val) fabs(val)
1261
1263extern int64_t lmp_ftell64 (FILE *stream);
1265extern int lmp_fseek64 (FILE *stream, int64_t offset, int whence);
1267extern uint64_t lmp_nanosleep (uint64_t nanoseconds);
1268
1270extern uint32_t ms_crc32c (const uint8_t *input, int length, uint32_t previousCRC32C);
1271
1273static inline void
1274ms_gswap2 (void *data2)
1275{
1276 uint16_t dat;
1277
1278 memcpy (&dat, data2, 2);
1279
1280 dat = ((dat & 0xff00) >> 8) | ((dat & 0x00ff) << 8);
1281
1282 memcpy (data2, &dat, 2);
1283}
1284
1286static inline void
1287ms_gswap4 (void *data4)
1288{
1289 uint32_t dat;
1290
1291 memcpy (&dat, data4, 4);
1292
1293 dat = ((dat & 0xff000000) >> 24) | ((dat & 0x000000ff) << 24) |
1294 ((dat & 0x00ff0000) >> 8) | ((dat & 0x0000ff00) << 8);
1295
1296 memcpy (data4, &dat, 4);
1297}
1298
1300static inline void
1301ms_gswap8 (void *data8)
1302{
1303 uint64_t dat;
1304
1305 memcpy (&dat, data8, sizeof(uint64_t));
1306
1307 dat = ((dat & 0xff00000000000000) >> 56) | ((dat & 0x00000000000000ff) << 56) |
1308 ((dat & 0x00ff000000000000) >> 40) | ((dat & 0x000000000000ff00) << 40) |
1309 ((dat & 0x0000ff0000000000) >> 24) | ((dat & 0x0000000000ff0000) << 24) |
1310 ((dat & 0x000000ff00000000) >> 8) | ((dat & 0x00000000ff000000) << 8);
1311
1312 memcpy (data8, &dat, sizeof(uint64_t));
1313}
1314
1315#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) || defined (__clang__)
1317__attribute__ ((deprecated("Use ms_gswap2 instead.")))
1318static inline void ms_gswap2a (void *data2) { ms_gswap2 (data2); }
1320__attribute__ ((deprecated("Use ms_gswap4 instead.")))
1321static inline void ms_gswap4a (void *data4) { ms_gswap4 (data4); }
1323__attribute__ ((deprecated("Use ms_gswap8 instead.")))
1324static inline void ms_gswap8a (void *data8) { ms_gswap8 (data8); }
1325#elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320)
1327__declspec(deprecated("Use ms_gswap2 instead."))
1328static inline void ms_gswap2a (void *data2) { ms_gswap2 (data2); }
1330__declspec(deprecated("Use ms_gswap4 instead."))
1331static inline void ms_gswap4a (void *data4) { ms_gswap4 (data4); }
1333__declspec(deprecated("Use ms_gswap8 instead."))
1334static inline void ms_gswap8a (void *data8) { ms_gswap8 (data8); }
1335#else
1337static inline void ms_gswap2a (void *data2) { ms_gswap2 (data2); }
1339static inline void ms_gswap4a (void *data4) { ms_gswap4 (data4); }
1341static inline void ms_gswap8a (void *data8) { ms_gswap8 (data8); }
1342#endif
1343
1347typedef int8_t flag;
1348
1373typedef struct LIBMSEED_MEMORY
1374{
1375 void *(*malloc) (size_t);
1376 void *(*realloc) (void *, size_t);
1377 void (*free) (void *);
1379
1382
1396extern size_t libmseed_prealloc_block_size;
1397
1402extern void *libmseed_memory_prealloc (void *ptr, size_t size, size_t *currentsize);
1403
1406#define DE_ASCII DE_TEXT
1407
1416#define DE_TEXT 0
1417#define DE_INT16 1
1418#define DE_INT32 3
1419#define DE_FLOAT32 4
1420#define DE_FLOAT64 5
1421#define DE_STEIM1 10
1422#define DE_STEIM2 11
1423#define DE_GEOSCOPE24 12
1424#define DE_GEOSCOPE163 13
1425#define DE_GEOSCOPE164 14
1426#define DE_CDSN 16
1427#define DE_SRO 30
1428#define DE_DWWSSN 32
1437#define MSSWAP_HEADER 0x01
1438#define MSSWAP_PAYLOAD 0x02
1446#define MS_ENDOFFILE 1
1447#define MS_NOERROR 0
1448#define MS_GENERROR -1
1449#define MS_NOTSEED -2
1450#define MS_WRONGLENGTH -3
1451#define MS_OUTOFRANGE -4
1452#define MS_UNKNOWNFORMAT -5
1453#define MS_STBADCOMPFLAG -6
1454#define MS_INVALIDCRC -7
1464#define MSF_UNPACKDATA 0x0001
1465#define MSF_SKIPNOTDATA 0x0002
1466#define MSF_VALIDATECRC 0x0004
1467#define MSF_PNAMERANGE 0x0008
1468#define MSF_ATENDOFFILE 0x0010
1469#define MSF_SEQUENCE 0x0020
1470#define MSF_FLUSHDATA 0x0040
1471#define MSF_PACKVER2 0x0080
1472#define MSF_RECORDLIST 0x0100
1473#define MSF_MAINTAINMSTL 0x0200
1476#ifdef __cplusplus
1477}
1478#endif
1479
1480#endif /* LIBMSEED_H */
struct MS3SelectTime * next
Pointer to next selection time, NULL if the last.
Definition libmseed.h:441
nstime_t endtime
Latest data for matching channels, use NSTUNSET for open.
Definition libmseed.h:440
uint8_t pubversion
Selected publication version, use 0 for any.
Definition libmseed.h:449
char sidpattern[100]
Matching (globbing) pattern for source ID.
Definition libmseed.h:446
struct MS3Selections * next
Pointer to next selection, NULL if the last.
Definition libmseed.h:448
nstime_t starttime
Earliest data for matching channels, use NSTUNSET for open.
Definition libmseed.h:439
struct MS3SelectTime * timewindows
Pointer to time window list for this source ID.
Definition libmseed.h:447
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:181
int ms3_readselectionsfile(MS3Selections **ppselections, const char *filename)
Read data selections from a file.
Definition selection.c:428
void ms3_printselections(const MS3Selections *selections)
Print the selections list using the ms_log() facility.
Definition selection.c:707
void ms3_freeselections(MS3Selections *selections)
Free all memory associated with a MS3Selections.
Definition selection.c:665
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:305
const MS3Selections * msr3_matchselect(const MS3Selections *selections, const MS3Record *msr, const MS3SelectTime **ppselecttime)
Test the MS3Record for a matching selection entry.
Definition selection.c:145
Data selection structure time window definition containers.
Definition libmseed.h:438
Data selection structure definition containers.
Definition libmseed.h:445
char type[30]
Definition libmseed.h:825
double duration
Definition libmseed.h:860
char wave[30]
Definition libmseed.h:830
char inputchannel[30]
Definition libmseed.h:863
struct MSEHEventDetection * next
Definition libmseed.h:836
double signalperiod
Definition libmseed.h:828
char amplituderange[30]
Definition libmseed.h:859
int firstpulsepositive
Definition libmseed.h:853
nstime_t onsettime
Definition libmseed.h:832
int medlookback
Definition libmseed.h:834
float vcocorrection
Definition libmseed.h:882
nstime_t endtime
Definition libmseed.h:851
char type[30]
Definition libmseed.h:849
struct MSEHCalibration * next
Definition libmseed.h:868
int continued
Definition libmseed.h:856
char clockstatus[128]
Definition libmseed.h:887
double signalamplitude
Definition libmseed.h:827
double stepbetween
Definition libmseed.h:862
uint32_t count
Definition libmseed.h:885
char units[30]
Definition libmseed.h:831
int alternatesign
Definition libmseed.h:854
char type[30]
Definition libmseed.h:900
double backgroundestimate
Definition libmseed.h:829
nstime_t time
Definition libmseed.h:881
double amplitude
Definition libmseed.h:857
char rolloff[30]
Definition libmseed.h:866
char trigger[30]
Definition libmseed.h:855
char coupling[30]
Definition libmseed.h:865
int steps
Definition libmseed.h:852
char noise[30]
Definition libmseed.h:867
char trigger[30]
Definition libmseed.h:903
char inputunits[30]
Definition libmseed.h:858
double sineperiod
Definition libmseed.h:861
int usec
Definition libmseed.h:883
uint8_t medsnr[6]
Definition libmseed.h:833
int medpickalgorithm
Definition libmseed.h:835
char type[16]
Definition libmseed.h:886
nstime_t begintime
Definition libmseed.h:901
double refamplitude
Definition libmseed.h:864
char detector[30]
Definition libmseed.h:826
nstime_t endtime
Definition libmseed.h:902
nstime_t begintime
Definition libmseed.h:850
int receptionquality
Definition libmseed.h:884
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:821
int mseh_print(const MS3Record *msr, int indent)
Print the extra header structure for the specified MS3Record.
Definition extraheaders.c:1156
int mseh_serialize(MS3Record *msr, LM_PARSED_JSON **parsestate)
Generate extra headers string (serialize) from internal state.
Definition extraheaders.c:997
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:493
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:150
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:629
void mseh_free_parsestate(LM_PARSED_JSON **parsestate)
Free internally parsed (deserialized) JSON data.
Definition extraheaders.c:1054
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:312
struct LM_PARSED_JSON_s LM_PARSED_JSON
Internal structure for holding parsed JSON extra headers.
Definition libmseed.h:912
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:913
int mseh_replace(MS3Record *msr, char *jsonstring)
Replace extra headers with supplied JSON.
Definition extraheaders.c:1091
Container for calibration parameters for use in extra headers.
Definition libmseed.h:848
Container for event detection parameters for use in extra headers.
Definition libmseed.h:824
Container for recenter parameters for use in extra headers.
Definition libmseed.h:899
Container for timing exception parameters for use in extra headers.
Definition libmseed.h:880
int readlength
INTERNAL: Length of data in read buffer.
Definition libmseed.h:728
int64_t streampos
OUTPUT: Read position of input stream.
Definition libmseed.h:724
int64_t endoffset
INPUT: End position in input stream, 0 == unknown (e.g. pipe)
Definition libmseed.h:723
int64_t recordcount
OUTPUT: Count of records read from this stream/file so far.
Definition libmseed.h:725
LMIO input
INTERNAL: IO handle, file or URL.
Definition libmseed.h:731
uint32_t flags
INTERNAL: Stream reading state flags.
Definition libmseed.h:730
char path[512]
INPUT: File name or URL.
Definition libmseed.h:721
int readoffset
INTERNAL: Read offset in read buffer.
Definition libmseed.h:729
char * readbuffer
INTERNAL: Read buffer, allocated internally.
Definition libmseed.h:727
int64_t startoffset
INPUT: Start position in input stream.
Definition libmseed.h:722
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:587
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:676
void ms3_url_freeheaders(void)
Free all set headers for URL-based requests.
Definition fileutils.c:847
int ms3_readmsr_r(MS3FileParam **ppmsfp, MS3Record **ppmsr, const char *mspath, uint32_t flags, int8_t verbose)
Read miniSEED records from a file or URL in a thread-safe way.
Definition fileutils.c:144
int ms3_url_addheader(const char *header)
Add header to any URL-based requests.
Definition fileutils.c:827
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:117
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:612
int64_t mstl3_writemseed(MS3TraceList *mst, 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_readmsr_selection(MS3FileParam **ppmsfp, MS3Record **ppmsr, const char *mspath, uint32_t flags, const MS3Selections *selections, int8_t verbose)
Read miniSEED records from a file or URL with optional selection.
Definition fileutils.c:257
int ms3_url_userpassword(const char *userpassword)
Set authentication credentials for URL-based requests.
Definition fileutils.c:798
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
int ms3_url_useragent(const char *program, const char *version)
Set User-Agent header for URL-based requests.
Definition fileutils.c:768
State container for reading miniSEED records from files or URLs.
Definition libmseed.h:720
int32_t TAIdelta
TAI-UTC difference in seconds.
Definition libmseed.h:1237
nstime_t leapsecond
Time of leap second as epoch since 1 January 1900.
Definition libmseed.h:1236
struct LeapSecond * next
Pointer to next entry, NULL if the last.
Definition libmseed.h:1238
LeapSecond * leapsecondlist
int ms_readleapsecondfile(const char *filename)
Read leap second from the specified file.
Definition genutils.c:1730
int ms_readleapseconds(const char *envvarname)
Read leap second file specified by an environment variable.
Definition genutils.c:1700
Leap second list container.
Definition libmseed.h:1235
void(* diag_print)(const char *)
Function to call for diagnostic and error messages.
Definition libmseed.h:1145
char message[MAX_LOG_MSG_LENGTH]
Log, warning or error message.
Definition libmseed.h:1115
char function[30]
Function generating the message.
Definition libmseed.h:1114
void(* log_print)(const char *)
Function to call for regular messages.
Definition libmseed.h:1143
int level
Message level.
Definition libmseed.h:1113
const char * logprefix
Message prefix for regular and diagnostic messages.
Definition libmseed.h:1144
const char * errprefix
Message prefix for error messages.
Definition libmseed.h:1146
MSLogRegistry registry
Message registry.
Definition libmseed.h:1147
int ms_rlog_l(MSLogParam *logp, const char *function, int level, const char *format,...)
Register log message using specified logging parameters.
Definition logging.c:310
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:134
#define MAX_LOG_MSG_LENGTH
Definition libmseed.h:1106
int ms_rlog_free(MSLogParam *logp)
Free, without emitting, all messages from log registry.
Definition logging.c:637
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:92
int ms_rlog(const char *function, int level, const char *format,...)
Register log message using global logging parameters.
Definition logging.c:258
int ms_rlog_emit(MSLogParam *logp, int count, int context)
Emit, aka send to print functions, messages from log registry.
Definition logging.c:573
Log registry entry.
Definition libmseed.h:1112
Logging parameters. Callers should not modify these values directly and generally should not need to ...
Definition libmseed.h:1142
Log message registry.
Definition libmseed.h:1123
void(* free)(void *)
Pointer to desired free()
Definition libmseed.h:1377
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:1374
uint8_t swapflag
Byte swap indicator (bitmask), see Byte swap flags.
Definition libmseed.h:361
void * datasamples
Data samples, numsamples of type sampletype.
Definition libmseed.h:378
uint32_t datalength
Length of data payload in bytes.
Definition libmseed.h:374
uint32_t crc
CRC of entire record.
Definition libmseed.h:372
uint8_t formatversion
Format major version.
Definition libmseed.h:365
int32_t reclen
Length of miniSEED record in bytes.
Definition libmseed.h:360
uint8_t flags
Record-level bit flags.
Definition libmseed.h:366
uint16_t extralength
Length of extra headers in bytes.
Definition libmseed.h:373
uint64_t datasize
Size of datasamples buffer in bytes.
Definition libmseed.h:379
const char * record
Raw miniSEED record, if available.
Definition libmseed.h:359
double samprate
Nominal sample rate as samples/second (Hz) or period (s)
Definition libmseed.h:368
int64_t numsamples
Number of data samples in datasamples.
Definition libmseed.h:380
int64_t samplecnt
Number of samples in record.
Definition libmseed.h:371
char sampletype
Sample type code: t, i, f, d Sample Types.
Definition libmseed.h:381
int16_t encoding
Data encoding format, see Data Encodings.
Definition libmseed.h:369
nstime_t starttime
Record start time (first sample)
Definition libmseed.h:367
char sid[LM_SIDLEN]
Source identifier as URN, max length LM_SIDLEN.
Definition libmseed.h:364
uint8_t pubversion
Publication version.
Definition libmseed.h:370
char * extra
Pointer to extra headers.
Definition libmseed.h:375
int64_t ms3_detect(const char *record, uint64_t recbuflen, uint8_t *formatversion)
Detect miniSEED record in buffer.
Definition parseutils.c:179
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:394
void msr3_print(const MS3Record *msr, int8_t details)
Print header values of an MS3Record.
Definition msrutils.c:228
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:347
int64_t msr3_unpack_data(MS3Record *msr, int8_t verbose)
Unpack data samples for a MS3Record.
Definition unpack.c:1120
double msr3_host_latency(const MS3Record *msr)
Calculate data latency based on the host time.
Definition msrutils.c:397
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:858
void msr3_free(MS3Record **ppmsr)
Free all memory associated with a MS3Record.
Definition msrutils.c:89
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:305
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:1275
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
MS3Record * msr3_duplicate(const MS3Record *msr, int8_t datadup)
Duplicate a MS3Record.
Definition msrutils.c:121
nstime_t msr3_endtime(const MS3Record *msr)
Calculate time of the last sample in a record.
Definition msrutils.c:202
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:527
nstime_t msr3_nsperiod(const MS3Record *msr)
Calculate sample period in nanoseconds/sample for a given MS3Record.
Definition msrutils.c:366
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:489
int msr3_data_bounds(const MS3Record *msr, uint32_t *dataoffset, uint32_t *datasize)
Determine the data payload bounds for a MS3Record.
Definition unpack.c:1021
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:106
miniSEED record container
Definition libmseed.h:358
struct MS3RecordPtr * next
Pointer to next entry, NULL if the last.
Definition libmseed.h:502
void * prvtptr
Private pointer, will not be populated by library but will be free'd.
Definition libmseed.h:501
MS3RecordPtr * last
Pointer to last entry, NULL if the none.
Definition libmseed.h:510
int64_t fileoffset
Offset into file to record for fileptr or filename.
Definition libmseed.h:497
const char * filename
Pointer to file name containing record, NULL if not used.
Definition libmseed.h:496
MS3RecordPtr * first
Pointer to first entry, NULL if the none.
Definition libmseed.h:509
MS3Record * msr
Pointer to MS3Record for this record.
Definition libmseed.h:498
const char * bufferptr
Pointer in buffer to record, NULL if not used.
Definition libmseed.h:494
FILE * fileptr
Pointer to open FILE containing record, NULL if not used.
Definition libmseed.h:495
uint64_t recordcnt
Count of records in the list (for convenience)
Definition libmseed.h:508
nstime_t endtime
End time of record, time of last sample.
Definition libmseed.h:499
uint32_t dataoffset
Offset from start of record to encoded data.
Definition libmseed.h:500
Record list, holds MS3RecordPtr entries that contribute to a given MS3TraceSeg.
Definition libmseed.h:507
A miniSEED record pointer and metadata.
Definition libmseed.h:493
int ms_strncpopen(char *dest, const char *source, int length)
Copy fixed number of characters into unterminated string.
Definition genutils.c:690
int ms_sid2nslc(const char *sid, char *net, char *sta, char *loc, char *chan)
Parse network, station, location and channel from an FDSN Source ID.
Definition genutils.c:183
int ms_strncpclean(char *dest, const char *source, int length)
Copy string, removing spaces, always terminated.
Definition genutils.c:584
int ms_xchan2seedchan(char *seedchan, const char *xchan)
Convert extended channel to SEED 2.x channel.
Definition genutils.c:480
int ms_seedchan2xchan(char *xchan, const char *seedchan)
Convert SEED 2.x channel to extended channel.
Definition genutils.c:435
int ms_strncpcleantail(char *dest, const char *source, int length)
Copy string, removing trailing spaces, always terminated.
Definition genutils.c:638
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:314
struct MS3TraceID * next[MSTRACEID_SKIPLIST_HEIGHT]
Next trace ID at first pointer, NULL if the last.
Definition libmseed.h:575
int64_t numsamples
Number of data samples in datasamples.
Definition libmseed.h:557
struct MS3RecordList * recordlist
List of pointers to records that contributed.
Definition libmseed.h:560
uint64_t prngstate
INTERNAL: State for Pseudo RNG.
Definition libmseed.h:583
nstime_t endtime
Time of last sample.
Definition libmseed.h:552
struct MS3TraceSeg * first
Pointer to first of list of segments.
Definition libmseed.h:573
nstime_t latest
Time of latest sample.
Definition libmseed.h:570
struct MS3TraceID traces
Head node of trace skip list, first entry at traces.next[0].
Definition libmseed.h:582
uint8_t pubversion
Largest contributing publication version.
Definition libmseed.h:568
void * prvtptr
Private pointer for general use, unused by library.
Definition libmseed.h:559
uint8_t height
Height of skip list at next.
Definition libmseed.h:576
uint64_t datasize
Size of datasamples buffer in bytes.
Definition libmseed.h:556
nstime_t earliest
Time of earliest sample.
Definition libmseed.h:569
double(* samprate)(const MS3Record *msr)
Pointer to function that returns sample rate tolerance.
Definition libmseed.h:614
void * prvtptr
Private pointer for general use, unused by library.
Definition libmseed.h:571
void * datasamples
Data samples, numsamples of type sampletype.
Definition libmseed.h:555
char sampletype
Sample type code, see Sample Types.
Definition libmseed.h:558
struct MS3TraceSeg * prev
Pointer to previous segment.
Definition libmseed.h:561
int64_t samplecnt
Number of samples in trace coverage.
Definition libmseed.h:554
char sid[LM_SIDLEN]
Source identifier as URN, max length LM_SIDLEN.
Definition libmseed.h:567
struct MS3TraceSeg * last
Pointer to last of list of segments.
Definition libmseed.h:574
uint32_t numtraceids
Number of traces IDs in list.
Definition libmseed.h:581
double(* time)(const MS3Record *msr)
Pointer to function that returns time tolerance.
Definition libmseed.h:613
double samprate
Nominal sample rate (Hz)
Definition libmseed.h:553
struct MS3TraceSeg * next
Pointer to next segment, NULL if the last.
Definition libmseed.h:562
nstime_t starttime
Time of first sample.
Definition libmseed.h:551
uint32_t numsegments
Number of segments for this ID.
Definition libmseed.h:572
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:1614
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:2252
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:2120
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:1936
void mstl3_free(MS3TraceList **ppmstl, int8_t freeprvtptr)
Free all memory associated with a MS3TraceList.
Definition tracelist.c:89
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:816
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:2325
int mstl3_resize_buffers(MS3TraceList *mstl)
Resize data sample buffers of MS3TraceList to what is needed.
Definition tracelist.c:1523
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:865
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:1373
MS3TraceList * mstl3_init(MS3TraceList *mstl)
Initialize a MS3TraceList container.
Definition tracelist.c:54
#define MSTRACEID_SKIPLIST_HEIGHT
Maximum skip list height for MSTraceIDs.
Definition libmseed.h:547
MS3TraceID * mstl3_findID(MS3TraceList *mstl, const char *sid, uint8_t pubversion, MS3TraceID **prev)
Find matching MS3TraceID in a MS3TraceList.
Definition tracelist.c:180
MS3TraceSeg * mstl3_addmsr_recordptr(MS3TraceList *mstl, const MS3Record *msr, MS3RecordPtr **pprecptr, int8_t splitversion, int8_t autoheal, uint32_t flags, const MS3Tolerance *tolerance)
Add data coverage from an MS3Record to a MS3TraceList.
Definition tracelist.c:364
Callback functions that return time and sample rate tolerances.
Definition libmseed.h:612
Container for a trace ID, linkable.
Definition libmseed.h:566
Container for a collection of continuous trace segment, linkable.
Definition libmseed.h:580
Container for a continuous trace segment, linkable.
Definition libmseed.h:550
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:1679
uint64_t lmp_nanosleep(uint64_t nanoseconds)
nstime_t ms_sampletime(nstime_t time, int64_t offset, double samprate)
Calculate the time of a sample in an array.
Definition genutils.c:1638
int lmp_fseek64(FILE *stream, int64_t offset, int whence)
int64_t lmp_ftell64(FILE *stream)
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
int8_t flag
Definition libmseed.h:1347
#define LM_SIDLEN
Length of source ID string.
Definition libmseed.h:140
#define DEPRECATED
Definition libmseed.h:210
Type definition for data source I/O: file-system versus URL.
Definition libmseed.h:692
void * handle
Primary IO handle, either file or URL.
Definition libmseed.h:700
void * handle2
Secondary IO handle for URL.
Definition libmseed.h:701
int still_running
Fetch status flag for URL transmissions.
Definition libmseed.h:702
@ LMIO_FD
IO handle is a provided file descriptor.
Definition libmseed.h:698
@ LMIO_URL
IO handle is URL-type.
Definition libmseed.h:697
@ LMIO_NULL
IO handle type is undefined.
Definition libmseed.h:695
@ LMIO_FILE
IO handle is FILE-type.
Definition libmseed.h:696
enum LMIO::@0 type
IO handle type.