Show the file size of the files in the tmp_dir on the LCD.
[ruwai.git] / software / c++ / ruwaicom / src / libmseed / libmseed.h
blobe6033c49f813d0ada644da900d51f0873aa6e7e2
2 /***************************************************************************
3 * libmseed.h:
4 *
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:
17 * http://www.gnu.org/
19 * Written by Chad Trabant
20 * IRIS Data Management Center
21 ***************************************************************************/
24 #ifndef LIBMSEED_H
25 #define LIBMSEED_H 1
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
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 */
41 #define DE_ASCII 0
42 #define DE_INT16 1
43 #define DE_INT32 3
44 #define DE_FLOAT32 4
45 #define DE_FLOAT64 5
46 #define DE_STEIM1 10
47 #define DE_STEIM2 11
48 #define DE_GEOSCOPE24 12
49 #define DE_GEOSCOPE163 13
50 #define DE_GEOSCOPE164 14
51 #define DE_CDSN 16
52 #define DE_SRO 30
53 #define DE_DWWSSN 32
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.
99 * Offset = Value
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)
107 * Usage:
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.
127 * Offset = Value
128 * [0-5] = Digits or NULL, SEED sequence number
129 * [6-47] = Space character (ASCII 32), remainder of fixed header
131 * Usage:
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 */
163 typedef int8_t flag;
165 /* SEED binary time */
166 typedef struct btime_s
168 uint16_t year;
169 uint16_t day;
170 uint8_t hour;
171 uint8_t min;
172 uint8_t sec;
173 uint8_t unused;
174 uint16_t fract;
175 } LMP_PACKED
176 BTime;
178 /* Fixed section data of header */
179 struct fsdh_s
181 char sequence_number[6];
182 char dataquality;
183 char reserved;
184 char station[5];
185 char location[2];
186 char channel[3];
187 char network[2];
188 BTime start_time;
189 uint16_t numsamples;
190 int16_t samprate_fact;
191 int16_t samprate_mult;
192 uint8_t act_flags;
193 uint8_t io_flags;
194 uint8_t dq_flags;
195 uint8_t numblockettes;
196 int32_t time_correct;
197 uint16_t data_offset;
198 uint16_t blockette_offset;
199 } LMP_PACKED;
201 /* Blockette 100, Sample Rate (without header) */
202 struct blkt_100_s
204 float samprate;
205 int8_t flags;
206 uint8_t reserved[3];
207 } LMP_PACKED;
209 /* Blockette 200, Generic Event Detection (without header) */
210 struct blkt_200_s
212 float amplitude;
213 float period;
214 float background_estimate;
215 uint8_t flags;
216 uint8_t reserved;
217 BTime time;
218 char detector[24];
219 } LMP_PACKED;
221 /* Blockette 201, Murdock Event Detection (without header) */
222 struct blkt_201_s
224 float amplitude;
225 float period;
226 float background_estimate;
227 uint8_t flags;
228 uint8_t reserved;
229 BTime time;
230 uint8_t snr_values[6];
231 uint8_t loopback;
232 uint8_t pick_algorithm;
233 char detector[24];
234 } LMP_PACKED;
236 /* Blockette 300, Step Calibration (without header) */
237 struct blkt_300_s
239 BTime time;
240 uint8_t numcalibrations;
241 uint8_t flags;
242 uint32_t step_duration;
243 uint32_t interval_duration;
244 float amplitude;
245 char input_channel[3];
246 uint8_t reserved;
247 uint32_t reference_amplitude;
248 char coupling[12];
249 char rolloff[12];
250 } LMP_PACKED;
252 /* Blockette 310, Sine Calibration (without header) */
253 struct blkt_310_s
255 BTime time;
256 uint8_t reserved1;
257 uint8_t flags;
258 uint32_t duration;
259 float period;
260 float amplitude;
261 char input_channel[3];
262 uint8_t reserved2;
263 uint32_t reference_amplitude;
264 char coupling[12];
265 char rolloff[12];
266 } LMP_PACKED;
268 /* Blockette 320, Pseudo-random Calibration (without header) */
269 struct blkt_320_s
271 BTime time;
272 uint8_t reserved1;
273 uint8_t flags;
274 uint32_t duration;
275 float ptp_amplitude;
276 char input_channel[3];
277 uint8_t reserved2;
278 uint32_t reference_amplitude;
279 char coupling[12];
280 char rolloff[12];
281 char noise_type[8];
282 } LMP_PACKED;
284 /* Blockette 390, Generic Calibration (without header) */
285 struct blkt_390_s
287 BTime time;
288 uint8_t reserved1;
289 uint8_t flags;
290 uint32_t duration;
291 float amplitude;
292 char input_channel[3];
293 uint8_t reserved2;
294 } LMP_PACKED;
296 /* Blockette 395, Calibration Abort (without header) */
297 struct blkt_395_s
299 BTime time;
300 uint8_t reserved[2];
301 } LMP_PACKED;
303 /* Blockette 400, Beam (without header) */
304 struct blkt_400_s
306 float azimuth;
307 float slowness;
308 uint16_t configuration;
309 uint8_t reserved[2];
310 } LMP_PACKED;
312 /* Blockette 405, Beam Delay (without header) */
313 struct blkt_405_s
315 uint16_t delay_values[1];
318 /* Blockette 500, Timing (without header) */
319 struct blkt_500_s
321 float vco_correction;
322 BTime time;
323 int8_t usec;
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];
329 } LMP_PACKED;
331 /* Blockette 1000, Data Only SEED (without header) */
332 struct blkt_1000_s
334 uint8_t encoding;
335 uint8_t byteorder;
336 uint8_t reclen;
337 uint8_t reserved;
338 } LMP_PACKED;
340 /* Blockette 1001, Data Extension (without header) */
341 struct blkt_1001_s
343 uint8_t timing_qual;
344 int8_t usec;
345 uint8_t reserved;
346 uint8_t framecnt;
347 } LMP_PACKED;
349 /* Blockette 2000, Opaque Data (without header) */
350 struct blkt_2000_s
352 uint16_t length;
353 uint16_t data_offset;
354 uint32_t recnum;
355 uint8_t byteorder;
356 uint8_t flags;
357 uint8_t numheaders;
358 char payload[1];
359 } LMP_PACKED;
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;
371 BlktLink;
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 */
380 StreamState;
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 */
414 MSRecord;
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 */
435 MSTrace;
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 */
442 MSTraceGroup;
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 */
457 MSTraceSeg;
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 */
476 MSTraceID;
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 */
484 MSTraceList;
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;
491 } SelectTime;
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;
498 } Selections;
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
611 FILE *fp;
612 char filename[512];
613 char *rawrec;
614 int readlen;
615 int readoffset;
616 int packtype;
617 off_t packhdroffset;
618 off_t filepos;
619 off_t filesize;
620 int recordcount;
621 } MSFileParam;
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;
693 } MSLogParam;
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
718 hptime_t leapsecond;
719 int32_t TAIdelta;
720 struct LeapSecond_s *next;
721 } LeapSecond;
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); \
741 ms_gswap2 (x.day); \
742 ms_gswap2 (x.fract);
745 #ifdef __cplusplus
747 #endif
749 #endif /* LIBMSEED_H */