2 /***************************************************************************
5 * Interface declarations for the Mini-SEED library (libmseed).
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public License
9 * as published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License (GNU-LGPL) for more details. The
16 * GNU-LGPL and further information can be found here:
19 * Written by Chad Trabant
20 * IRIS Data Management Center
21 ***************************************************************************/
31 #include "lmplatform.h"
33 #define LIBMSEED_VERSION "2.17"
34 #define LIBMSEED_RELEASE "2015.213"
36 #define MINRECLEN 128 /* Minimum Mini-SEED record length, 2^7 bytes */
37 /* Note: the SEED specification minimum is 256 */
38 #define MAXRECLEN 1048576 /* Maximum Mini-SEED record length, 2^20 bytes */
40 /* SEED data encoding types */
48 #define DE_GEOSCOPE24 12
49 #define DE_GEOSCOPE163 13
50 #define DE_GEOSCOPE164 14
55 /* Library return and error code values, error values should always be negative */
56 #define MS_ENDOFFILE 1 /* End of file reached return value */
57 #define MS_NOERROR 0 /* No error */
58 #define MS_GENERROR -1 /* Generic unspecified error */
59 #define MS_NOTSEED -2 /* Data not SEED */
60 #define MS_WRONGLENGTH -3 /* Length of data read was not correct */
61 #define MS_OUTOFRANGE -4 /* SEED record length out of range */
62 #define MS_UNKNOWNFORMAT -5 /* Unknown data encoding format */
63 #define MS_STBADCOMPFLAG -6 /* Steim, invalid compression flag(s) */
65 /* Define the high precision time tick interval as 1/modulus seconds */
66 /* Default modulus of 1000000 defines tick interval as a microsecond */
67 #define HPTMODULUS 1000000
69 /* Error code for routines that normally return a high precision time.
70 * The time value corresponds to '1902/1/1 00:00:00.000000' with the
71 * default HPTMODULUS */
72 #define HPTERROR -2145916800000000LL
74 /* Macros to scale between Unix/POSIX epoch time & high precision time */
75 #define MS_EPOCH2HPTIME(X) X * (hptime_t) HPTMODULUS
76 #define MS_HPTIME2EPOCH(X) X / HPTMODULUS
78 /* Macro to test a character for data record indicators */
79 #define MS_ISDATAINDICATOR(X) (X=='D' || X=='R' || X=='Q' || X=='M')
81 /* Macro to test default sample rate tolerance: abs(1-sr1/sr2) < 0.0001 */
82 #define MS_ISRATETOLERABLE(A,B) (ms_dabs (1.0 - (A / B)) < 0.0001)
84 /* Macro to test for sane year and day values, used primarily to
85 * determine if byte order swapping is needed.
87 * Year : between 1900 and 2100
88 * Day : between 1 and 366
90 * This test is non-unique (non-deterministic) for days 1, 256 and 257
91 * in the year 2056 because the swapped values are also within range.
93 #define MS_ISVALIDYEARDAY(Y,D) (Y >= 1900 && Y <= 2100 && D >= 1 && D <= 366)
95 /* Macro to test memory for a SEED data record signature by checking
96 * SEED data record header values at known byte offsets to determine
97 * if the memory contains a valid record.
100 * [0-5] = Digits, spaces or NULL, SEED sequence number
101 * 6 = Data record quality indicator
102 * 7 = Space or NULL [not valid SEED]
103 * 24 = Start hour (0-23)
104 * 25 = Start minute (0-59)
105 * 26 = Start second (0-60)
108 * MS_ISVALIDHEADER ((char *)X) X buffer must contain at least 27 bytes
110 #define MS_ISVALIDHEADER(X) ( \
111 (isdigit ((int) *(X)) || *(X) == ' ' || !*(X) ) && \
112 (isdigit ((int) *(X+1)) || *(X+1) == ' ' || !*(X+1) ) && \
113 (isdigit ((int) *(X+2)) || *(X+2) == ' ' || !*(X+2) ) && \
114 (isdigit ((int) *(X+3)) || *(X+3) == ' ' || !*(X+3) ) && \
115 (isdigit ((int) *(X+4)) || *(X+4) == ' ' || !*(X+4) ) && \
116 (isdigit ((int) *(X+5)) || *(X+5) == ' ' || !*(X+5) ) && \
117 MS_ISDATAINDICATOR(*(X+6)) && \
118 (*(X+7) == ' ' || *(X+7) == '\0') && \
119 (int)(*(X+24)) >= 0 && (int)(*(X+24)) <= 23 && \
120 (int)(*(X+25)) >= 0 && (int)(*(X+25)) <= 59 && \
121 (int)(*(X+26)) >= 0 && (int)(*(X+26)) <= 60 )
123 /* Macro to test memory for a blank/noise SEED data record signature
124 * by checking for a valid SEED sequence number and padding characters
125 * to determine if the memory contains a valid blank/noise record.
128 * [0-5] = Digits or NULL, SEED sequence number
129 * [6-47] = Space character (ASCII 32), remainder of fixed header
132 * MS_ISVALIDBLANK ((char *)X) X buffer must contain at least 27 bytes
134 #define MS_ISVALIDBLANK(X) ( \
135 (isdigit ((int) *(X)) || !*(X) ) && \
136 (isdigit ((int) *(X+1)) || !*(X+1) ) && \
137 (isdigit ((int) *(X+2)) || !*(X+2) ) && \
138 (isdigit ((int) *(X+3)) || !*(X+3) ) && \
139 (isdigit ((int) *(X+4)) || !*(X+4) ) && \
140 (isdigit ((int) *(X+5)) || !*(X+5) ) && \
141 (*(X+6) ==' ') && (*(X+7) ==' ') && (*(X+8) ==' ') && \
142 (*(X+9) ==' ') && (*(X+10)==' ') && (*(X+11)==' ') && \
143 (*(X+12)==' ') && (*(X+13)==' ') && (*(X+14)==' ') && \
144 (*(X+15)==' ') && (*(X+16)==' ') && (*(X+17)==' ') && \
145 (*(X+18)==' ') && (*(X+19)==' ') && (*(X+20)==' ') && \
146 (*(X+21)==' ') && (*(X+22)==' ') && (*(X+23)==' ') && \
147 (*(X+24)==' ') && (*(X+25)==' ') && (*(X+26)==' ') && \
148 (*(X+27)==' ') && (*(X+28)==' ') && (*(X+29)==' ') && \
149 (*(X+30)==' ') && (*(X+31)==' ') && (*(X+32)==' ') && \
150 (*(X+33)==' ') && (*(X+34)==' ') && (*(X+35)==' ') && \
151 (*(X+36)==' ') && (*(X+37)==' ') && (*(X+38)==' ') && \
152 (*(X+39)==' ') && (*(X+40)==' ') && (*(X+41)==' ') && \
153 (*(X+42)==' ') && (*(X+43)==' ') && (*(X+44)==' ') && \
154 (*(X+45)==' ') && (*(X+46)==' ') && (*(X+47)==' ') )
156 /* A simple bitwise AND test to return 0 or 1 */
157 #define bit(x,y) (x&y)?1:0
159 /* Require a large (>= 64-bit) integer type for hptime_t */
160 typedef int64_t hptime_t
;
162 /* A single byte flag type */
165 /* SEED binary time */
166 typedef struct btime_s
178 /* Fixed section data of header */
181 char sequence_number
[6];
190 int16_t samprate_fact
;
191 int16_t samprate_mult
;
195 uint8_t numblockettes
;
196 int32_t time_correct
;
197 uint16_t data_offset
;
198 uint16_t blockette_offset
;
201 /* Blockette 100, Sample Rate (without header) */
209 /* Blockette 200, Generic Event Detection (without header) */
214 float background_estimate
;
221 /* Blockette 201, Murdock Event Detection (without header) */
226 float background_estimate
;
230 uint8_t snr_values
[6];
232 uint8_t pick_algorithm
;
236 /* Blockette 300, Step Calibration (without header) */
240 uint8_t numcalibrations
;
242 uint32_t step_duration
;
243 uint32_t interval_duration
;
245 char input_channel
[3];
247 uint32_t reference_amplitude
;
252 /* Blockette 310, Sine Calibration (without header) */
261 char input_channel
[3];
263 uint32_t reference_amplitude
;
268 /* Blockette 320, Pseudo-random Calibration (without header) */
276 char input_channel
[3];
278 uint32_t reference_amplitude
;
284 /* Blockette 390, Generic Calibration (without header) */
292 char input_channel
[3];
296 /* Blockette 395, Calibration Abort (without header) */
303 /* Blockette 400, Beam (without header) */
308 uint16_t configuration
;
312 /* Blockette 405, Beam Delay (without header) */
315 uint16_t delay_values
[1];
318 /* Blockette 500, Timing (without header) */
321 float vco_correction
;
324 uint8_t reception_qual
;
325 uint32_t exception_count
;
326 char exception_type
[16];
327 char clock_model
[32];
328 char clock_status
[128];
331 /* Blockette 1000, Data Only SEED (without header) */
340 /* Blockette 1001, Data Extension (without header) */
349 /* Blockette 2000, Opaque Data (without header) */
353 uint16_t data_offset
;
361 /* Blockette chain link, generic linkable blockette index */
362 typedef struct blkt_link_s
364 uint16_t blktoffset
; /* Offset to this blockette */
365 uint16_t blkt_type
; /* Blockette type */
366 uint16_t next_blkt
; /* Offset to next blockette */
367 void *blktdata
; /* Blockette data */
368 uint16_t blktdatalen
; /* Length of blockette data in bytes */
369 struct blkt_link_s
*next
;
373 typedef struct StreamState_s
375 int64_t packedrecords
; /* Count of packed records */
376 int64_t packedsamples
; /* Count of packed samples */
377 int32_t lastintsample
; /* Value of last integer sample packed */
378 flag comphistory
; /* Control use of lastintsample for compression history */
382 typedef struct MSRecord_s
{
383 char *record
; /* Mini-SEED record */
384 int32_t reclen
; /* Length of Mini-SEED record in bytes */
386 /* Pointers to SEED data record structures */
387 struct fsdh_s
*fsdh
; /* Fixed Section of Data Header */
388 BlktLink
*blkts
; /* Root of blockette chain */
389 struct blkt_100_s
*Blkt100
; /* Blockette 100, if present */
390 struct blkt_1000_s
*Blkt1000
; /* Blockette 1000, if present */
391 struct blkt_1001_s
*Blkt1001
; /* Blockette 1001, if present */
393 /* Common header fields in accessible form */
394 int32_t sequence_number
; /* SEED record sequence number */
395 char network
[11]; /* Network designation, NULL terminated */
396 char station
[11]; /* Station designation, NULL terminated */
397 char location
[11]; /* Location designation, NULL terminated */
398 char channel
[11]; /* Channel designation, NULL terminated */
399 char dataquality
; /* Data quality indicator */
400 hptime_t starttime
; /* Record start time, corrected (first sample) */
401 double samprate
; /* Nominal sample rate (Hz) */
402 int64_t samplecnt
; /* Number of samples in record */
403 int8_t encoding
; /* Data encoding format */
404 int8_t byteorder
; /* Original/Final byte order of record */
406 /* Data sample fields */
407 void *datasamples
; /* Data samples, 'numsamples' of type 'sampletype'*/
408 int64_t numsamples
; /* Number of data samples in datasamples */
409 char sampletype
; /* Sample type code: a, i, f, d */
411 /* Stream oriented state information */
412 StreamState
*ststate
; /* Stream processing state information */
416 /* Container for a continuous trace, linkable */
417 typedef struct MSTrace_s
{
418 char network
[11]; /* Network designation, NULL terminated */
419 char station
[11]; /* Station designation, NULL terminated */
420 char location
[11]; /* Location designation, NULL terminated */
421 char channel
[11]; /* Channel designation, NULL terminated */
422 char dataquality
; /* Data quality indicator */
423 char type
; /* MSTrace type code */
424 hptime_t starttime
; /* Time of first sample */
425 hptime_t endtime
; /* Time of last sample */
426 double samprate
; /* Nominal sample rate (Hz) */
427 int64_t samplecnt
; /* Number of samples in trace coverage */
428 void *datasamples
; /* Data samples, 'numsamples' of type 'sampletype' */
429 int64_t numsamples
; /* Number of data samples in datasamples */
430 char sampletype
; /* Sample type code: a, i, f, d */
431 void *prvtptr
; /* Private pointer for general use, unused by libmseed */
432 StreamState
*ststate
; /* Stream processing state information */
433 struct MSTrace_s
*next
; /* Pointer to next trace */
437 /* Container for a group (chain) of traces */
438 typedef struct MSTraceGroup_s
{
439 int32_t numtraces
; /* Number of MSTraces in the trace chain */
440 struct MSTrace_s
*traces
; /* Root of the trace chain */
444 /* Container for a continuous trace segment, linkable */
445 typedef struct MSTraceSeg_s
{
446 hptime_t starttime
; /* Time of first sample */
447 hptime_t endtime
; /* Time of last sample */
448 double samprate
; /* Nominal sample rate (Hz) */
449 int64_t samplecnt
; /* Number of samples in trace coverage */
450 void *datasamples
; /* Data samples, 'numsamples' of type 'sampletype'*/
451 int64_t numsamples
; /* Number of data samples in datasamples */
452 char sampletype
; /* Sample type code: a, i, f, d */
453 void *prvtptr
; /* Private pointer for general use, unused by libmseed */
454 struct MSTraceSeg_s
*prev
; /* Pointer to previous segment */
455 struct MSTraceSeg_s
*next
; /* Pointer to next segment */
459 /* Container for a trace ID, linkable */
460 typedef struct MSTraceID_s
{
461 char network
[11]; /* Network designation, NULL terminated */
462 char station
[11]; /* Station designation, NULL terminated */
463 char location
[11]; /* Location designation, NULL terminated */
464 char channel
[11]; /* Channel designation, NULL terminated */
465 char dataquality
; /* Data quality indicator */
466 char srcname
[45]; /* Source name (Net_Sta_Loc_Chan_Qual), NULL terminated */
467 char type
; /* Trace type code */
468 hptime_t earliest
; /* Time of earliest sample */
469 hptime_t latest
; /* Time of latest sample */
470 void *prvtptr
; /* Private pointer for general use, unused by libmseed */
471 int32_t numsegments
; /* Number of segments for this ID */
472 struct MSTraceSeg_s
*first
; /* Pointer to first of list of segments */
473 struct MSTraceSeg_s
*last
; /* Pointer to last of list of segments */
474 struct MSTraceID_s
*next
; /* Pointer to next trace */
478 /* Container for a continuous trace segment, linkable */
479 typedef struct MSTraceList_s
{
480 int32_t numtraces
; /* Number of traces in list */
481 struct MSTraceID_s
*traces
; /* Pointer to list of traces */
482 struct MSTraceID_s
*last
; /* Pointer to last used trace in list */
486 /* Data selection structure time window definition containers */
487 typedef struct SelectTime_s
{
488 hptime_t starttime
; /* Earliest data for matching channels */
489 hptime_t endtime
; /* Latest data for matching channels */
490 struct SelectTime_s
*next
;
493 /* Data selection structure definition containers */
494 typedef struct Selections_s
{
495 char srcname
[100]; /* Matching (globbing) source name: Net_Sta_Loc_Chan_Qual */
496 struct SelectTime_s
*timewindows
;
497 struct Selections_s
*next
;
501 /* Global variables (defined in pack.c) and macros to set/force
502 * pack byte orders */
503 extern flag packheaderbyteorder
;
504 extern flag packdatabyteorder
;
505 #define MS_PACKHEADERBYTEORDER(X) (packheaderbyteorder = X);
506 #define MS_PACKDATABYTEORDER(X) (packdatabyteorder = X);
508 /* Global variables (defined in unpack.c) and macros to set/force
509 * unpack byte orders */
510 extern flag unpackheaderbyteorder
;
511 extern flag unpackdatabyteorder
;
512 #define MS_UNPACKHEADERBYTEORDER(X) (unpackheaderbyteorder = X);
513 #define MS_UNPACKDATABYTEORDER(X) (unpackdatabyteorder = X);
515 /* Global variables (defined in unpack.c) and macros to set/force
516 * encoding and fallback encoding */
517 extern int unpackencodingformat
;
518 extern int unpackencodingfallback
;
519 #define MS_UNPACKENCODINGFORMAT(X) (unpackencodingformat = X);
520 #define MS_UNPACKENCODINGFALLBACK(X) (unpackencodingfallback = X);
522 /* Mini-SEED record related functions */
523 extern int msr_parse (char *record
, int recbuflen
, MSRecord
**ppmsr
, int reclen
,
524 flag dataflag
, flag verbose
);
526 extern int msr_parse_selection ( char *recbuf
, int recbuflen
, int64_t *offset
,
527 MSRecord
**ppmsr
, int reclen
,
528 Selections
*selections
, flag dataflag
, flag verbose
);
530 extern int msr_unpack (char *record
, int reclen
, MSRecord
**ppmsr
,
531 flag dataflag
, flag verbose
);
533 extern int msr_pack (MSRecord
*msr
, void (*record_handler
) (char *, int, void *),
534 void *handlerdata
, int64_t *packedsamples
, flag flush
, flag verbose
);
536 extern int msr_pack_header (MSRecord
*msr
, flag normalize
, flag verbose
);
538 extern int msr_unpack_data (MSRecord
*msr
, int swapflag
, flag verbose
);
540 extern MSRecord
* msr_init (MSRecord
*msr
);
541 extern void msr_free (MSRecord
**ppmsr
);
542 extern void msr_free_blktchain (MSRecord
*msr
);
543 extern BlktLink
* msr_addblockette (MSRecord
*msr
, char *blktdata
, int length
,
544 int blkttype
, int chainpos
);
545 extern int msr_normalize_header (MSRecord
*msr
, flag verbose
);
546 extern MSRecord
* msr_duplicate (MSRecord
*msr
, flag datadup
);
547 extern double msr_samprate (MSRecord
*msr
);
548 extern double msr_nomsamprate (MSRecord
*msr
);
549 extern hptime_t
msr_starttime (MSRecord
*msr
);
550 extern hptime_t
msr_starttime_uc (MSRecord
*msr
);
551 extern hptime_t
msr_endtime (MSRecord
*msr
);
552 extern char* msr_srcname (MSRecord
*msr
, char *srcname
, flag quality
);
553 extern void msr_print (MSRecord
*msr
, flag details
);
554 extern double msr_host_latency (MSRecord
*msr
);
556 extern int ms_detect (const char *record
, int recbuflen
);
557 extern int ms_parse_raw (char *record
, int maxreclen
, flag details
, flag swapflag
);
560 /* MSTrace related functions */
561 extern MSTrace
* mst_init (MSTrace
*mst
);
562 extern void mst_free (MSTrace
**ppmst
);
563 extern MSTraceGroup
* mst_initgroup (MSTraceGroup
*mstg
);
564 extern void mst_freegroup (MSTraceGroup
**ppmstg
);
565 extern MSTrace
* mst_findmatch (MSTrace
*startmst
, char dataquality
,
566 char *network
, char *station
, char *location
, char *channel
);
567 extern MSTrace
* mst_findadjacent (MSTraceGroup
*mstg
, flag
*whence
, char dataquality
,
568 char *network
, char *station
, char *location
, char *channel
,
569 double samprate
, double sampratetol
,
570 hptime_t starttime
, hptime_t endtime
, double timetol
);
571 extern int mst_addmsr (MSTrace
*mst
, MSRecord
*msr
, flag whence
);
572 extern int mst_addspan (MSTrace
*mst
, hptime_t starttime
, hptime_t endtime
,
573 void *datasamples
, int64_t numsamples
,
574 char sampletype
, flag whence
);
575 extern MSTrace
* mst_addmsrtogroup (MSTraceGroup
*mstg
, MSRecord
*msr
, flag dataquality
,
576 double timetol
, double sampratetol
);
577 extern MSTrace
* mst_addtracetogroup (MSTraceGroup
*mstg
, MSTrace
*mst
);
578 extern int mst_groupheal (MSTraceGroup
*mstg
, double timetol
, double sampratetol
);
579 extern int mst_groupsort (MSTraceGroup
*mstg
, flag quality
);
580 extern int mst_convertsamples (MSTrace
*mst
, char type
, flag truncate
);
581 extern char * mst_srcname (MSTrace
*mst
, char *srcname
, flag quality
);
582 extern void mst_printtracelist (MSTraceGroup
*mstg
, flag timeformat
,
583 flag details
, flag gaps
);
584 extern void mst_printsynclist ( MSTraceGroup
*mstg
, char *dccid
, flag subsecond
);
585 extern void mst_printgaplist (MSTraceGroup
*mstg
, flag timeformat
,
586 double *mingap
, double *maxgap
);
587 extern int mst_pack (MSTrace
*mst
, void (*record_handler
) (char *, int, void *),
588 void *handlerdata
, int reclen
, flag encoding
, flag byteorder
,
589 int64_t *packedsamples
, flag flush
, flag verbose
,
590 MSRecord
*mstemplate
);
591 extern int mst_packgroup (MSTraceGroup
*mstg
, void (*record_handler
) (char *, int, void *),
592 void *handlerdata
, int reclen
, flag encoding
, flag byteorder
,
593 int64_t *packedsamples
, flag flush
, flag verbose
,
594 MSRecord
*mstemplate
);
596 /* MSTraceList related functions */
597 extern MSTraceList
* mstl_init ( MSTraceList
*mstl
);
598 extern void mstl_free ( MSTraceList
**ppmstl
, flag freeprvtptr
);
599 extern MSTraceSeg
* mstl_addmsr ( MSTraceList
*mstl
, MSRecord
*msr
, flag dataquality
,
600 flag autoheal
, double timetol
, double sampratetol
);
601 extern int mstl_convertsamples ( MSTraceSeg
*seg
, char type
, flag truncate
);
602 extern void mstl_printtracelist ( MSTraceList
*mstl
, flag timeformat
,
603 flag details
, flag gaps
);
604 extern void mstl_printsynclist ( MSTraceList
*mstl
, char *dccid
, flag subsecond
);
605 extern void mstl_printgaplist (MSTraceList
*mstl
, flag timeformat
,
606 double *mingap
, double *maxgap
);
608 /* Reading Mini-SEED records from files */
609 typedef struct MSFileParam_s
623 extern int ms_readmsr (MSRecord
**ppmsr
, const char *msfile
, int reclen
, off_t
*fpos
, int *last
,
624 flag skipnotdata
, flag dataflag
, flag verbose
);
625 extern int ms_readmsr_r (MSFileParam
**ppmsfp
, MSRecord
**ppmsr
, const char *msfile
, int reclen
,
626 off_t
*fpos
, int *last
, flag skipnotdata
, flag dataflag
, flag verbose
);
627 extern int ms_readmsr_main (MSFileParam
**ppmsfp
, MSRecord
**ppmsr
, const char *msfile
, int reclen
,
628 off_t
*fpos
, int *last
, flag skipnotdata
, flag dataflag
, Selections
*selections
, flag verbose
);
629 extern int ms_readtraces (MSTraceGroup
**ppmstg
, const char *msfile
, int reclen
, double timetol
, double sampratetol
,
630 flag dataquality
, flag skipnotdata
, flag dataflag
, flag verbose
);
631 extern int ms_readtraces_timewin (MSTraceGroup
**ppmstg
, const char *msfile
, int reclen
, double timetol
, double sampratetol
,
632 hptime_t starttime
, hptime_t endtime
, flag dataquality
, flag skipnotdata
, flag dataflag
, flag verbose
);
633 extern int ms_readtraces_selection (MSTraceGroup
**ppmstg
, const char *msfile
, int reclen
, double timetol
, double sampratetol
,
634 Selections
*selections
, flag dataquality
, flag skipnotdata
, flag dataflag
, flag verbose
);
635 extern int ms_readtracelist (MSTraceList
**ppmstl
, const char *msfile
, int reclen
, double timetol
, double sampratetol
,
636 flag dataquality
, flag skipnotdata
, flag dataflag
, flag verbose
);
637 extern int ms_readtracelist_timewin (MSTraceList
**ppmstl
, const char *msfile
, int reclen
, double timetol
, double sampratetol
,
638 hptime_t starttime
, hptime_t endtime
, flag dataquality
, flag skipnotdata
, flag dataflag
, flag verbose
);
639 extern int ms_readtracelist_selection (MSTraceList
**ppmstl
, const char *msfile
, int reclen
, double timetol
, double sampratetol
,
640 Selections
*selections
, flag dataquality
, flag skipnotdata
, flag dataflag
, flag verbose
);
642 extern int msr_writemseed ( MSRecord
*msr
, const char *msfile
, flag overwrite
, int reclen
,
643 flag encoding
, flag byteorder
, flag verbose
);
644 extern int mst_writemseed ( MSTrace
*mst
, const char *msfile
, flag overwrite
, int reclen
,
645 flag encoding
, flag byteorder
, flag verbose
);
646 extern int mst_writemseedgroup ( MSTraceGroup
*mstg
, const char *msfile
, flag overwrite
,
647 int reclen
, flag encoding
, flag byteorder
, flag verbose
);
649 /* General use functions */
650 extern char* ms_recsrcname (char *record
, char *srcname
, flag quality
);
651 extern int ms_splitsrcname (char *srcname
, char *net
, char *sta
, char *loc
, char *chan
, char *qual
);
652 extern int ms_strncpclean (char *dest
, const char *source
, int length
);
653 extern int ms_strncpcleantail (char *dest
, const char *source
, int length
);
654 extern int ms_strncpopen (char *dest
, const char *source
, int length
);
655 extern int ms_doy2md (int year
, int jday
, int *month
, int *mday
);
656 extern int ms_md2doy (int year
, int month
, int mday
, int *jday
);
657 extern hptime_t
ms_btime2hptime (BTime
*btime
);
658 extern char* ms_btime2isotimestr (BTime
*btime
, char *isotimestr
);
659 extern char* ms_btime2mdtimestr (BTime
*btime
, char *mdtimestr
);
660 extern char* ms_btime2seedtimestr (BTime
*btime
, char *seedtimestr
);
661 extern int ms_hptime2tomsusecoffset (hptime_t hptime
, hptime_t
*toms
, int8_t *usecoffset
);
662 extern int ms_hptime2btime (hptime_t hptime
, BTime
*btime
);
663 extern char* ms_hptime2isotimestr (hptime_t hptime
, char *isotimestr
, flag subsecond
);
664 extern char* ms_hptime2mdtimestr (hptime_t hptime
, char *mdtimestr
, flag subsecond
);
665 extern char* ms_hptime2seedtimestr (hptime_t hptime
, char *seedtimestr
, flag subsecond
);
666 extern hptime_t
ms_time2hptime (int year
, int day
, int hour
, int min
, int sec
, int usec
);
667 extern hptime_t
ms_seedtimestr2hptime (char *seedtimestr
);
668 extern hptime_t
ms_timestr2hptime (char *timestr
);
669 extern double ms_nomsamprate (int factor
, int multiplier
);
670 extern int ms_genfactmult (double samprate
, int16_t *factor
, int16_t *multiplier
);
671 extern int ms_ratapprox (double real
, int *num
, int *den
, int maxval
, double precision
);
672 extern int ms_bigendianhost (void);
673 extern double ms_dabs (double val
);
676 /* Lookup functions */
677 extern uint8_t ms_samplesize (const char sampletype
);
678 extern char* ms_encodingstr (const char encoding
);
679 extern char* ms_blktdesc (uint16_t blkttype
);
680 extern uint16_t ms_blktlen (uint16_t blkttype
, const char *blktdata
, flag swapflag
);
681 extern char * ms_errorstr (int errorcode
);
683 /* Logging facility */
684 #define MAX_LOG_MSG_LENGTH 200 /* Maximum length of log messages */
686 /* Logging parameters */
687 typedef struct MSLogParam_s
689 void (*log_print
)(char*);
690 const char *logprefix
;
691 void (*diag_print
)(char*);
692 const char *errprefix
;
695 extern int ms_log (int level
, ...);
696 extern int ms_log_l (MSLogParam
*logp
, int level
, ...);
697 extern void ms_loginit (void (*log_print
)(char*), const char *logprefix
,
698 void (*diag_print
)(char*), const char *errprefix
);
699 extern MSLogParam
*ms_loginit_l (MSLogParam
*logp
,
700 void (*log_print
)(char*), const char *logprefix
,
701 void (*diag_print
)(char*), const char *errprefix
);
703 /* Selection functions */
704 extern Selections
*ms_matchselect (Selections
*selections
, char *srcname
,
705 hptime_t starttime
, hptime_t endtime
, SelectTime
**ppselecttime
);
706 extern Selections
*msr_matchselect (Selections
*selections
, MSRecord
*msr
, SelectTime
**ppselecttime
);
707 extern int ms_addselect (Selections
**ppselections
, char *srcname
,
708 hptime_t starttime
, hptime_t endtime
);
709 extern int ms_addselect_comp (Selections
**ppselections
, char *net
, char* sta
, char *loc
,
710 char *chan
, char *qual
, hptime_t starttime
, hptime_t endtime
);
711 extern int ms_readselectionsfile (Selections
**ppselections
, char *filename
);
712 extern void ms_freeselections (Selections
*selections
);
713 extern void ms_printselections (Selections
*selections
);
715 /* Leap second declarations, implementation in gentutils.c */
716 typedef struct LeapSecond_s
720 struct LeapSecond_s
*next
;
723 extern LeapSecond
*leapsecondlist
;
724 extern int ms_readleapseconds (char *envvarname
);
725 extern int ms_readleapsecondfile (char *filename
);
727 /* Generic byte swapping routines */
728 extern void ms_gswap2 ( void *data2
);
729 extern void ms_gswap3 ( void *data3
);
730 extern void ms_gswap4 ( void *data4
);
731 extern void ms_gswap8 ( void *data8
);
733 /* Generic byte swapping routines for memory aligned quantities */
734 extern void ms_gswap2a ( void *data2
);
735 extern void ms_gswap4a ( void *data4
);
736 extern void ms_gswap8a ( void *data8
);
738 /* Byte swap macro for the BTime struct */
739 #define MS_SWAPBTIME(x) \
740 ms_gswap2 (x.year); \
749 #endif /* LIBMSEED_H */