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

Revision 305, 16.3 KB checked in by marcus, 12 years ago (diff)

r147 | klaus | 2011-01-13 09:13:13 +0100 (Do, 13 Jan 2011) | 1 line

added internal flag for correction of network and location code

Line 
1
2/* file seedcfg.h
3 *      =========
4 *
5 * $Revision: 147 $, $Date: 2011-01-13 09:13:13 +0100 (Do, 13 Jan 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/* data formats (should not be here ...) */
158#define Seed_C_FORMAT_MSEED 1
159
160
161
162/*
163 * types
164 * -----
165 */
166
167#define SeedSbyteT signed char
168
169typedef struct {
170        char      setupfile[BC_FILELTH+1]; /* name of setup file */
171        int       max_no_of_streams;    /* maximum number of streams */
172        int       max_no_of_twl;        /* maximum number of time window lists */
173        int       max_lth_of_twl;       /* maximum length of a time window list */
174        int       phys_rec_size;        /* physical record size in bytes */
175        int       seed_rec_size;        /* SEED record size */
176        int       seed_phys_recs;       /* physical records per SEED records */
177        BOOLEAN   new_seed_names;       /* use new names for SEED files (with "_") */
178        BOOLEAN   dump_ill_recs;        /* dump unknown records to file */
179        int       eom_eof_cnt;          /* number of consecutive EOF's for EOM */
180        int       max_errcnt_illegal;   /* maximum number of illegal records */
181        int       max_errcnt_incomplete;/* maximum number of incomplete records */
182        int       max_errcnt_readerr;   /* maximum number of read errors */
183        long      copy_buf_lth;         /* length of copy SEED buffer (in long's) */
184} SeedSetupParT;
185
186/* stream identifier */
187typedef struct {
188        char     array[Seed_C_SHORTSTRLTH+1];      /* array name or "none" */
189        char     station[Seed_C_SHORTSTRLTH+1];    /* station name */
190        char     channel[Seed_C_SHORTSTRLTH+1];    /* channel name, e.g. VBB */
191        char     comp;                             /* component */
192} SeedStreamT;
193
194/* time type */
195typedef TIME SeedTimeT;
196
197/* time window lists */
198typedef struct {
199        SeedTimeT    *tw_begin;      /* start of time window */
200        SeedTimeT    *tw_end;        /* end of time window */
201        int          twl_length;     /* length of list */
202} SeedTwlT;
203
204/* SEED file descriptor */
205typedef struct {
206        char     stream[BC_SHORTSTRLTH+1];  /* stream string */
207        char     t_start[BC_TIMELTH+1];     /* start time of file */
208        char     t_end[BC_TIMELTH+1];       /* end time of file */
209        char     name[BC_FILELTH+1];        /* file name */
210        char     sfdfile[BC_FILELTH+1];     /* corresponding sfd-file */
211        int      recno;                     /* number of SEED records in file */
212        int      ufd;                       /* UNIX file descr. or Seed_C_ILLEGAL */
213        int      pos;                       /* current read position in records */
214        int      sample;                    /* sample position in record */
215        float    calib;                     /* calibration of channel */
216        int      dataflags;                 /* flags set on data Seed_F_QUAL_... */
217        BOOLEAN  swap_hdr;                  /* swap header after read */
218        int      reclth;                    /* SEED file record length */
219        int      byteoff;                   /* byte offset in SEED file */
220        int      pri;                       /* priority of entry */
221        int      dataformat;                /* data format ID */
222        char     addinf[Seed_C_AddinfLth+1];/* netcode+locid */
223} SeedFileDescrT;
224
225#define UBYTE unsigned char
226#define WORD  short
227#define UWORD unsigned short
228#define INT32 int
229#define UINT32 unsigned int
230
231typedef struct {
232    UWORD year ;             /* e.g. 1991 */
233    UWORD day ;              /* 1..366 */
234    UBYTE hours ;            /* 0..23 */
235    UBYTE minutes ;          /* 0..59 */
236    UBYTE seconds ;          /* 0..59, 60 for leap */
237    UBYTE alignment_1 ;
238    UWORD frac_secs ;           /* 0.0001 seconds, 0..9999 */
239} SeedBtimeT ;
240
241typedef struct {
242        char   seqno[6];                      /* sequence number */
243        char   indicator;                     /* type of record */
244        char   Reserved_bytes_A;              /* not used */
245        char   statcode[5];                   /* station name */
246        char   locid[2];                      /* location identifier */
247        char   channel[3];                    /* channel */
248        char   network[2];                    /* network code */
249        SeedBtimeT  starttime;                /* start time of record */
250        UWORD  no_of_samples;                 /* number of samples in record */
251        WORD   smprate_fact;                  /* sample rate factor */
252        WORD   smprate_mult;                  /* sample rate multiplier */
253        UBYTE  activity;                      /* activity flags */
254        UBYTE  ioflags;                       /* IO flags */
255        UBYTE  quality;                       /* data quality flags */
256        UBYTE  no_of_blockettes;              /* number of blockettes to follow */
257        INT32  timecorr;                      /* time correction in ms */
258        UWORD  databegin;                     /* beginning of data */
259        UWORD  first;                         /* first blockette */
260} SeedDataHeaderT;
261
262
263typedef struct {
264        UWORD  type;                          /* blockette type (1000) */
265        WORD   nextblock;                     /* byte number of next blockette */
266        UBYTE  format;                        /* encoding format */
267        UBYTE  wordorder;                     /* word order */
268        UBYTE  reclthexp;                     /* record length (power of 2) */
269        UBYTE  reserved;                      /* not used */
270} SeedBlockette1000T;
271
272typedef struct {
273        UWORD  type;                          /* blockette type (1001) */
274        WORD   nextblock;                     /* byte number of next blockette */
275        UBYTE  timequal;                      /* time quality */
276        UBYTE  reserved;                      /* ... */
277} SeedBlockette1001T;
278
279
280/* SeedDecodeSteim1 can also read Steim2 */
281#define SeedDecodeSteim SeedDecodeSteim1
282
283
284/*
285 * prototypes
286 * ----------
287 */
288
289/*--------------------------------------------------------------------*/
290
291
292void SeedReadSetupFile( char fname[], STATUS *status );
293
294/* Reads setup file (file containing basic constants) of SEED
295 * processing.  Parameters are read to seedv_setup structure.
296 *
297 * parameters of routine
298 * char       fname[];        input; name of setup file
299 * STATUS     *status;        output; return status
300 */
301
302
303/*--------------------------------------------------------------------*/
304
305
306void SeedChangeSetup( SeedSetupParT *par, long setflags, STATUS *status );
307
308/* Changes setup values.  Only these values are copied whose setup-bit
309 * is set in 'setflags'.
310 *
311 * parameters of routine
312 * SeedSetupParT *par;          input; new values of setup parameters
313 * long          setflags;      input; setup flags (Seed_F_SET_... - Bits)
314 * STATUS        *status;       output; return status
315 */
316
317
318/*--------------------------------------------------------------------*/
319
320
321void SeedSetup( SeedSetupParT *setup, STATUS *status );
322
323/* Gets setup file.
324 *
325 * parameters of routine
326 * SeedSetupParT *setup;     output; SEED setup
327 * STATUS     *status;       output; return status
328 */
329
330
331/*--------------------------------------------------------------------*/
332
333
334void SeedSetupF( STATUS *status );
335
336/* Fortran interface to SeedSetup.
337 *
338 * parameters of routine
339 * STATUS     *status;       output; return status
340 */
341
342
343/*--------------------------------------------------------------------*/
344
345
346void SeedInitialize( STATUS *status );
347
348/* Allocates memory for stream lists and time window lists.
349 * Routine SeedReadSetupFile must be called before.
350 *
351 * parameters of routine
352 * STATUS     *status;      output; return status
353 */
354
355
356/*--------------------------------------------------------------------*/
357
358
359void SeedFinish( void );
360
361/* Frees memory of time lists and stream lists
362 *
363 * no parameters
364 */
365
366
367/*--------------------------------------------------------------------*/
368
369
370void SeedReadSelections( char fname[], STATUS *status );
371
372/* Reads selections of streams and time windows from
373 * given file.
374 *
375 * parameters of routine
376 * char       fname[];        input; name of setup file
377 */
378
379
380/*--------------------------------------------------------------------*/
381
382
383void SeedPrintSelections( void );
384
385/* Prints selections read by SeedReadSelections to standard output
386 *
387 * no parameters
388 */
389
390
391/*--------------------------------------------------------------------*/
392
393
394void SeedGetSetup( SeedSetupParT *setup );
395
396/* Returns SEED setup parameters.  The values are copied to a passed
397 * structure.  Changes to the parameters are not possible.
398 *
399 * parameters of routine
400 * SeedSetupParT *setup;     output; setup parameters
401 */
402
403
404/*--------------------------------------------------------------------*/
405
406
407BOOLEAN SeedIsSelected( SeedStreamT *str, char timestr[], STATUS *status );
408
409/* Checks whether specified stream and time is in selection list
410 *
411 * parameters of routine
412 * SeedStreamT   *str;        input; stream to check
413 * SeedTimeT     *time;       input; time to check
414 * STATUS        *status;     output; return status
415 */
416
417
418/*--------------------------------------------------------------------*/
419
420
421BOOLEAN SeedWindowIsSelected( SeedStreamT *str, char t_start[],
422        char t_end[], STATUS *status );
423
424/* Checks whether specified time window is selected on any stream.
425 *
426 * parameters of routine
427 * SeedStreamT   *str;        input; stream to check
428 * char          t_start[];   input; start of time window
429 * char          t_end[];       input; time to check
430 * STATUS        *status;     output; return status
431 */
432
433
434/*--------------------------------------------------------------------*/
435
436
437int SeedNextStream( int mode );
438
439/* Returns index next stream or next selected stream depending on 'mode'
440 * Possible values of 'mode' are:
441 *    Seed_C_NSM_RESET:           start new list, returns illegal value
442 *    Seed_C_NSM_NEXT_STREAM:     next stream, whether or not selected
443 *    Seed_C_NSM_NEXT_SELECTED:   next selected stream
444 *    Seed_C_NSM_TOTAL_NUMBER:    total number of streams
445 * If no more stream is available, Seed_C_ILLEGAL is returned
446 *
447 * parameters of routine
448 * int        mode;            input; controls returned value
449 *                             returns requested stream index
450 */
451
452
453/*--------------------------------------------------------------------*/
454
455
456int SeedIdentifyStreamString( char str[] );
457
458/* Returns stream index.  'str' is stream string like "bfo-vbb-z".
459 *
460 * parameters of routine
461 * char       str[];           input; stream string
462 *                             returns stream index or Seed_C_ILLEGAL
463 */
464
465
466/*--------------------------------------------------------------------*/
467
468
469void SeedGetStreamString( int stream_idx, char str[] );
470
471/* Returns tream string from stream index.  'str' must be long
472 * enough, i.e. 2*Seed_C_SHORTSTRLTH+3+1.
473 *
474 * parameters of routine
475 * int        stream_idx;      input; stream index number
476 * char       str[];           output; stream string
477 */
478
479
480/*--------------------------------------------------------------------*/
481
482
483void SeedPrepareStreamString( char str[] );
484
485/* replaces the characters "-","/","_" by blanks in given string
486 *
487 * parameters of routine
488 * char       str[];        modify; string to be modified
489 */
490
491
492/*--------------------------------------------------------------------*/
Note: See TracBrowser for help on using the repository browser.