source: SH_SHM/trunk/source/seed_io/seedcfg.h @ 326

Revision 326, 16.4 KB checked in by marcus, 13 years ago (diff)

r165 | klaus | 2011-02-17 12:03:57 +0100 (Do, 17 Feb 2011) | 1 line

handle data record identifier M; also in split_seed

Line 
1
2/* file seedcfg.h
3 *      =========
4 *
5 * $Revision: 165 $, $Date: 2011-02-17 12:03:57 +0100 (Do, 17 Feb 2011) $
6 *
7 * SEED basic constants and types
8 * K. Stammler, 25-Dec-93
9 */
10
11
12#ifndef __TCUSRDEF
13#include BC_TCUSRDEF
14#endif
15
16
17/* temporary */
18/* #define err_writemsg(a,b,c) printf("status %d\n",a) */
19
20
21
22
23/*
24 * error codes
25 * -----------
26 */
27
28#define SeedERR_OFFSET       7000
29#define SeedERR_OPENINPUT    (SeedERR_OFFSET+1)   /* error opening input file */
30#define SeedERR_NOSETUP      (SeedERR_OFFSET+2)   /* no setup file read */
31#define SeedERR_EOF_FOUND    (SeedERR_OFFSET+3)   /* EOF found */
32#define SeedERR_ILLSTREAM    (SeedERR_OFFSET+4)   /* illegal stream name */
33#define SeedERR_NOTIMELIST   (SeedERR_OFFSET+5)   /* no time list specified */
34#define SeedERR_TWLOVFL      (SeedERR_OFFSET+6)   /* too many time lists */
35#define SeedERR_TWLLTH       (SeedERR_OFFSET+7)   /* time list too long */
36#define SeedERR_ILLTWL       (SeedERR_OFFSET+8)   /* illegal time window */
37#define SeedERR_STREAMOVFL   (SeedERR_OFFSET+9)   /* too many streams */
38#define SeedERR_ILLRECSIZE   (SeedERR_OFFSET+10)  /* illegal record size */
39#define SeedERR_SFD_READ     (SeedERR_OFFSET+11)  /* error reading sfd-file */
40#define SeedERR_SFD_NOTFOUND (SeedERR_OFFSET+12)  /* stream not found in sfd */
41#define SeedERR_SFD_NEXT     (SeedERR_OFFSET+13)  /* next file returned */
42#define SeedERR_CHAN_OOR     (SeedERR_OFFSET+14)  /* SEED channel out of range*/
43#define SeedERR_STROVFL      (SeedERR_OFFSET+15)  /* string overflow */
44#define SeedERR_SEEDREAD     (SeedERR_OFFSET+16)  /* read error on SEED file */
45#define SeedERR_SEEDSEEK     (SeedERR_OFFSET+17)  /* seek error on SEED file */
46#define SeedERR_BUG          (SeedERR_OFFSET+18)  /* program bug */
47#define SeedERR_NOT_OPEN     (SeedERR_OFFSET+19)  /* channel not opened */
48#define SeedERR_TIMEGAP      (SeedERR_OFFSET+20)  /* time gap */
49#define SeedERR_OPENOUTPUT   (SeedERR_OFFSET+21)  /* error opening outp. file */
50#define SeedERR_SEEDWRITE    (SeedERR_OFFSET+22)  /* error writing SEED file */
51#define SeedERR_ZEROLTH      (SeedERR_OFFSET+23)  /* zero length trace quested*/
52#define SeedERR_NEXTTIMEPOS  (SeedERR_OFFSET+24)  /* next possible time positioned */
53#define SeedERR_DOUBLEDATA   (SeedERR_OFFSET+25)  /* double data in SEED file */
54#define SeedERR_DATA_UNAVAIL (SeedERR_OFFSET+26)  /* data not available */
55#define SeedERR_ILLCUT       (SeedERR_OFFSET+27)  /* illegal cut command */
56#define SeedERR_DECODE_ERR   (SeedERR_OFFSET+28)  /* error decoding record */
57#define SeedERR_READ_LOOKUP  (SeedERR_OFFSET+29)  /* error reading CD lookup */
58#define SeedERR_ILL_COMPRS   (SeedERR_OFFSET+30)  /* illegal compression */
59#define SeedERR_NOCALIB      (SeedERR_OFFSET+31)  /* no calibration gain found */
60
61
62
63/*
64 * constants
65 * ---------
66 */
67
68#define Seed_C_SHORTSTRLTH 7
69#define Seed_C_SFDLINELTH 512
70#define Seed_C_MAX_RECLTH 8192
71
72/* set flags for setup parameters */
73#define Seed_F_SET_MAX_NO_OF_STREAMS      0x00000001L
74#define Seed_F_SET_MAX_NO_OF_TWL          0x00000002L
75#define Seed_F_SET_MAX_LTH_OF_TWL         0x00000004L
76#define Seed_F_SET_PHYS_REC_SIZE          0x00000008L
77#define Seed_F_SET_SEED_REC_SIZE          0x00000010L
78#define Seed_F_SET_NEW_SEED_NAMES         0x00000020L
79#define Seed_F_SET_DUMP_ILL_RECS          0x00000040L
80#define Seed_F_SET_EOM_EOF_CNT            0x00000080L
81#define Seed_F_SET_MAX_ERRCNT_ILLEGAL     0x00000100L
82#define Seed_F_SET_MAX_ERRCNT_INCOMPLETE  0x00000200L
83#define Seed_F_SET_MAX_ERRCNT_READERR     0x00000400L
84#define Seed_F_SET_COPY_BUF_LTH           0x00000800L
85
86#define Seed_C_ILLEGAL -1
87
88/* SEED data record activity flags */
89#define Seed_F_ACT_CALIBRATION            0x01
90#define Seed_F_ACT_TIMECORRAPP            0x02
91#define Seed_F_ACT_TRIGSTART              0x04
92#define Seed_F_ACT_TRIGEND                0x08
93#define Seed_F_ACT_PLEAP                  0x10
94#define Seed_F_ACT_NLEAP                  0x20
95#define Seed_F_ACT_EVENT                  0x40
96
97/* SEED data record I/O flags */
98#define Seed_F_IO_PARITY                  0x01
99#define Seed_F_IO_LONGREC                 0x02
100#define Seed_F_IO_SHORTREC                0x04
101#define Seed_F_IO_SERIESSTART             0x08
102#define Seed_F_IO_SERIESEND               0x10
103#define Seed_F_IO_CLOCKLOCKED             0x20
104
105/* SEED data record quality flags */
106#define Seed_F_QUAL_SATURATED             0x01
107#define Seed_F_QUAL_CLIPPED               0x02
108#define Seed_F_QUAL_SPIKES                0x04
109#define Seed_F_QUAL_GLITCHES              0x08
110#define Seed_F_QUAL_MISSING_PADDED        0x10
111#define Seed_F_QUAL_SYNCERR               0x20
112#define Seed_F_QUAL_FILTERCHARGING        0x40
113#define Seed_F_QUAL_TIMETAG               0x80
114/* private flag */
115#define Seed_F_QUAL_NOCALIB               0x1000
116#define Seed_F_QUAL_DATA_LOCKED           0x2000
117#define Seed_F_QUAL_NETLOC_CORRECTION     0x4000
118
119/* SeedNextStream modes */
120#define Seed_C_NSM_RESET 0
121#define Seed_C_NSM_NEXT_STREAM 1
122#define Seed_C_NSM_NEXT_SELECTED 2
123#define Seed_C_NSM_TOTAL_NUMBER 3
124
125#define Seed_C_MAXCHAN 10
126
127/* Steim1 compression format */
128#define Seed_C_FRAMELTH 64     /* frame length in bytes */
129#define Seed_C_MAXFRAMESMP 120 /* maximum number of samples/frame */
130#define Seed_C_FRAMEDIFFS 16   /* number of difference longwords in one frame */
131
132/* SFD file item identification characters */
133#define Seed_C_SfdTStart 'b'
134#define Seed_C_SfdTEnd   'e'
135#define Seed_C_SfdName   'n'
136#define Seed_C_SfdRecno  'r'
137#define Seed_C_SfdStream 's'
138#define Seed_C_SfdCalib  'c'
139#define Seed_C_SfdSwapH  'h'
140#define Seed_C_SfdOffset 'o'
141#define Seed_C_SfdReclth 'l'
142#define Seed_C_SfdAddinf 'a'
143
144/* return values to stream selection requests */
145#define Seed_C_IsSelected 0
146#define Seed_C_TimeNotSelected 1
147#define Seed_C_StreamNotSelected 2
148
149/* data compression types for blockette 1000 */
150#define Seed_C_DcmpSteim1 10
151#define Seed_C_DcmpSteim2 11
152
153/* length of netcode and locid together */
154#define Seed_C_AddinfLth 4
155#define Seed_C_EmptyAddinfStr "...."
156
157/* this characters can appear in a data record header */
158#define Seed_C_DATCHARS "DQRM"
159
160/* data formats (should not be here ...) */
161#define Seed_C_FORMAT_MSEED 1
162
163
164
165/*
166 * types
167 * -----
168 */
169
170#define SeedSbyteT signed char
171
172typedef struct {
173        char      setupfile[BC_FILELTH+1]; /* name of setup file */
174        int       max_no_of_streams;    /* maximum number of streams */
175        int       max_no_of_twl;        /* maximum number of time window lists */
176        int       max_lth_of_twl;       /* maximum length of a time window list */
177        int       phys_rec_size;        /* physical record size in bytes */
178        int       seed_rec_size;        /* SEED record size */
179        int       seed_phys_recs;       /* physical records per SEED records */
180        BOOLEAN   new_seed_names;       /* use new names for SEED files (with "_") */
181        BOOLEAN   dump_ill_recs;        /* dump unknown records to file */
182        int       eom_eof_cnt;          /* number of consecutive EOF's for EOM */
183        int       max_errcnt_illegal;   /* maximum number of illegal records */
184        int       max_errcnt_incomplete;/* maximum number of incomplete records */
185        int       max_errcnt_readerr;   /* maximum number of read errors */
186        long      copy_buf_lth;         /* length of copy SEED buffer (in long's) */
187} SeedSetupParT;
188
189/* stream identifier */
190typedef struct {
191        char     array[Seed_C_SHORTSTRLTH+1];      /* array name or "none" */
192        char     station[Seed_C_SHORTSTRLTH+1];    /* station name */
193        char     channel[Seed_C_SHORTSTRLTH+1];    /* channel name, e.g. VBB */
194        char     comp;                             /* component */
195} SeedStreamT;
196
197/* time type */
198typedef TIME SeedTimeT;
199
200/* time window lists */
201typedef struct {
202        SeedTimeT    *tw_begin;      /* start of time window */
203        SeedTimeT    *tw_end;        /* end of time window */
204        int          twl_length;     /* length of list */
205} SeedTwlT;
206
207/* SEED file descriptor */
208typedef struct {
209        char     stream[BC_SHORTSTRLTH+1];  /* stream string */
210        char     t_start[BC_TIMELTH+1];     /* start time of file */
211        char     t_end[BC_TIMELTH+1];       /* end time of file */
212        char     name[BC_FILELTH+1];        /* file name */
213        char     sfdfile[BC_FILELTH+1];     /* corresponding sfd-file */
214        int      recno;                     /* number of SEED records in file */
215        int      ufd;                       /* UNIX file descr. or Seed_C_ILLEGAL */
216        int      pos;                       /* current read position in records */
217        int      sample;                    /* sample position in record */
218        float    calib;                     /* calibration of channel */
219        int      dataflags;                 /* flags set on data Seed_F_QUAL_... */
220        BOOLEAN  swap_hdr;                  /* swap header after read */
221        int      reclth;                    /* SEED file record length */
222        int      byteoff;                   /* byte offset in SEED file */
223        int      pri;                       /* priority of entry */
224        int      dataformat;                /* data format ID */
225        char     addinf[Seed_C_AddinfLth+1];/* netcode+locid */
226} SeedFileDescrT;
227
228#define UBYTE unsigned char
229#define WORD  short
230#define UWORD unsigned short
231#define INT32 int
232#define UINT32 unsigned int
233
234typedef struct {
235    UWORD year ;             /* e.g. 1991 */
236    UWORD day ;              /* 1..366 */
237    UBYTE hours ;            /* 0..23 */
238    UBYTE minutes ;          /* 0..59 */
239    UBYTE seconds ;          /* 0..59, 60 for leap */
240    UBYTE alignment_1 ;
241    UWORD frac_secs ;           /* 0.0001 seconds, 0..9999 */
242} SeedBtimeT ;
243
244typedef struct {
245        char   seqno[6];                      /* sequence number */
246        char   indicator;                     /* type of record */
247        char   Reserved_bytes_A;              /* not used */
248        char   statcode[5];                   /* station name */
249        char   locid[2];                      /* location identifier */
250        char   channel[3];                    /* channel */
251        char   network[2];                    /* network code */
252        SeedBtimeT  starttime;                /* start time of record */
253        UWORD  no_of_samples;                 /* number of samples in record */
254        WORD   smprate_fact;                  /* sample rate factor */
255        WORD   smprate_mult;                  /* sample rate multiplier */
256        UBYTE  activity;                      /* activity flags */
257        UBYTE  ioflags;                       /* IO flags */
258        UBYTE  quality;                       /* data quality flags */
259        UBYTE  no_of_blockettes;              /* number of blockettes to follow */
260        INT32  timecorr;                      /* time correction in ms */
261        UWORD  databegin;                     /* beginning of data */
262        UWORD  first;                         /* first blockette */
263} SeedDataHeaderT;
264
265
266typedef struct {
267        UWORD  type;                          /* blockette type (1000) */
268        WORD   nextblock;                     /* byte number of next blockette */
269        UBYTE  format;                        /* encoding format */
270        UBYTE  wordorder;                     /* word order */
271        UBYTE  reclthexp;                     /* record length (power of 2) */
272        UBYTE  reserved;                      /* not used */
273} SeedBlockette1000T;
274
275typedef struct {
276        UWORD  type;                          /* blockette type (1001) */
277        WORD   nextblock;                     /* byte number of next blockette */
278        UBYTE  timequal;                      /* time quality */
279        UBYTE  reserved;                      /* ... */
280} SeedBlockette1001T;
281
282
283/* SeedDecodeSteim1 can also read Steim2 */
284#define SeedDecodeSteim SeedDecodeSteim1
285
286
287/*
288 * prototypes
289 * ----------
290 */
291
292/*--------------------------------------------------------------------*/
293
294
295void SeedReadSetupFile( char fname[], STATUS *status );
296
297/* Reads setup file (file containing basic constants) of SEED
298 * processing.  Parameters are read to seedv_setup structure.
299 *
300 * parameters of routine
301 * char       fname[];        input; name of setup file
302 * STATUS     *status;        output; return status
303 */
304
305
306/*--------------------------------------------------------------------*/
307
308
309void SeedChangeSetup( SeedSetupParT *par, long setflags, STATUS *status );
310
311/* Changes setup values.  Only these values are copied whose setup-bit
312 * is set in 'setflags'.
313 *
314 * parameters of routine
315 * SeedSetupParT *par;          input; new values of setup parameters
316 * long          setflags;      input; setup flags (Seed_F_SET_... - Bits)
317 * STATUS        *status;       output; return status
318 */
319
320
321/*--------------------------------------------------------------------*/
322
323
324void SeedSetup( SeedSetupParT *setup, STATUS *status );
325
326/* Gets setup file.
327 *
328 * parameters of routine
329 * SeedSetupParT *setup;     output; SEED setup
330 * STATUS     *status;       output; return status
331 */
332
333
334/*--------------------------------------------------------------------*/
335
336
337void SeedSetupF( STATUS *status );
338
339/* Fortran interface to SeedSetup.
340 *
341 * parameters of routine
342 * STATUS     *status;       output; return status
343 */
344
345
346/*--------------------------------------------------------------------*/
347
348
349void SeedInitialize( STATUS *status );
350
351/* Allocates memory for stream lists and time window lists.
352 * Routine SeedReadSetupFile must be called before.
353 *
354 * parameters of routine
355 * STATUS     *status;      output; return status
356 */
357
358
359/*--------------------------------------------------------------------*/
360
361
362void SeedFinish( void );
363
364/* Frees memory of time lists and stream lists
365 *
366 * no parameters
367 */
368
369
370/*--------------------------------------------------------------------*/
371
372
373void SeedReadSelections( char fname[], STATUS *status );
374
375/* Reads selections of streams and time windows from
376 * given file.
377 *
378 * parameters of routine
379 * char       fname[];        input; name of setup file
380 */
381
382
383/*--------------------------------------------------------------------*/
384
385
386void SeedPrintSelections( void );
387
388/* Prints selections read by SeedReadSelections to standard output
389 *
390 * no parameters
391 */
392
393
394/*--------------------------------------------------------------------*/
395
396
397void SeedGetSetup( SeedSetupParT *setup );
398
399/* Returns SEED setup parameters.  The values are copied to a passed
400 * structure.  Changes to the parameters are not possible.
401 *
402 * parameters of routine
403 * SeedSetupParT *setup;     output; setup parameters
404 */
405
406
407/*--------------------------------------------------------------------*/
408
409
410BOOLEAN SeedIsSelected( SeedStreamT *str, char timestr[], STATUS *status );
411
412/* Checks whether specified stream and time is in selection list
413 *
414 * parameters of routine
415 * SeedStreamT   *str;        input; stream to check
416 * SeedTimeT     *time;       input; time to check
417 * STATUS        *status;     output; return status
418 */
419
420
421/*--------------------------------------------------------------------*/
422
423
424BOOLEAN SeedWindowIsSelected( SeedStreamT *str, char t_start[],
425        char t_end[], STATUS *status );
426
427/* Checks whether specified time window is selected on any stream.
428 *
429 * parameters of routine
430 * SeedStreamT   *str;        input; stream to check
431 * char          t_start[];   input; start of time window
432 * char          t_end[];       input; time to check
433 * STATUS        *status;     output; return status
434 */
435
436
437/*--------------------------------------------------------------------*/
438
439
440int SeedNextStream( int mode );
441
442/* Returns index next stream or next selected stream depending on 'mode'
443 * Possible values of 'mode' are:
444 *    Seed_C_NSM_RESET:           start new list, returns illegal value
445 *    Seed_C_NSM_NEXT_STREAM:     next stream, whether or not selected
446 *    Seed_C_NSM_NEXT_SELECTED:   next selected stream
447 *    Seed_C_NSM_TOTAL_NUMBER:    total number of streams
448 * If no more stream is available, Seed_C_ILLEGAL is returned
449 *
450 * parameters of routine
451 * int        mode;            input; controls returned value
452 *                             returns requested stream index
453 */
454
455
456/*--------------------------------------------------------------------*/
457
458
459int SeedIdentifyStreamString( char str[] );
460
461/* Returns stream index.  'str' is stream string like "bfo-vbb-z".
462 *
463 * parameters of routine
464 * char       str[];           input; stream string
465 *                             returns stream index or Seed_C_ILLEGAL
466 */
467
468
469/*--------------------------------------------------------------------*/
470
471
472void SeedGetStreamString( int stream_idx, char str[] );
473
474/* Returns tream string from stream index.  'str' must be long
475 * enough, i.e. 2*Seed_C_SHORTSTRLTH+3+1.
476 *
477 * parameters of routine
478 * int        stream_idx;      input; stream index number
479 * char       str[];           output; stream string
480 */
481
482
483/*--------------------------------------------------------------------*/
484
485
486void SeedPrepareStreamString( char str[] );
487
488/* replaces the characters "-","/","_" by blanks in given string
489 *
490 * parameters of routine
491 * char       str[];        modify; string to be modified
492 */
493
494
495/*--------------------------------------------------------------------*/
Note: See TracBrowser for help on using the repository browser.