Content-type: text/html
#define DH_STATION_LEN 5
#define DH_CHANNEL_LEN 3
#define DH_LOCATION_LEN 2
#define DH_NETWORK_LEN 2
/* Linked list structure for storing blockettes. */
typedef struct _bs { /* blockette structure. */
char *pb; /* ptr to actual blockette. */
unsigned short int type; /* blockette number. */
unsigned short int len; /* length of blockette in bytes.*/
unsigned short int wordorder; /* wordorder of blockette. */
struct _bs *next; /* ptr to next blockette struct.*/
} BS;
/* Data header structure, containing SEED Fixed Data Header info */
/* as well as other useful info. */
typedef struct data_hdr {
int seq_no; /* sequence number */
char station_id[DH_STATION_LEN+1]; /* station name */
char location_id[DH_LOCATION_LEN+1]; /* location id */
char channel_id[DH_CHANNEL_LEN+1]; /* channel name */
char network_id[DH_NETWORK_LEN+1]; /* network id */
INT_TIME begtime; /* begin time with corrections */
INT_TIME endtime; /* end time of packet */
INT_TIME hdrtime; /* begin time in hdr */
int num_samples; /* number of samples */
int num_data_frames; /* number of data frames */
int sample_rate; /* sample rate */
int sample_rate_mult; /* sample rate multiplier. */
int num_blockettes; /* # of blockettes (0) */
int num_ticks_correction; /* time correction in ticks */
int first_data; /* offset to first data */
int first_blockette; /* offset of first blockette */
BS *pblockettes; /* ptr to blockette structures */
int data_type; /* data_type (for logs or data) */
int blksize; /* blocksize of record (bytes). */
unsigned char activity_flags; /* activity flags */
unsigned char io_flags; /* i/o flags */
unsigned char data_quality_flags; /* data quality flags */
unsigned char hdr_wordorder; /* wordorder of header. */
unsigned char data_wordorder; /* wordorder of data. */
char record_type; /* record type ('D' or 'V') */
char cextra[2]; /* future expansion. */
int x0; /* first value (STEIM compress) */
int xn; /* last value (STEIM compress) */
int xm1; /* future expansion. */
int xm2; /* future expansion. */
int extra[1]; /* future expansion. */
} DATA_HDR;
/* Attribute structure for a specific data_hdr and blksize. */
typedef struct _ms_attr{
int sample_size; /* # bytes for sampe (0=NA) */
int alignment; /* alignment requirement (1 min)*/
int nframes; /* # of frame in use (0=NA) */
int framelimit; /* max # of frames (0=NA) */
int nbytes; /* # of bytes in use */
int bytelimit; /* max # of bytes */
} MS_ATTR;
/* Time structures. */
typedef struct _ext_time {
int year; /* Year. */
int doy; /* Day of year (1-366) */
int month; /* Month (1-12) */
int day; /* Day of month (1-31) */
int hour; /* Hour (0-23) */
int minute; /* Minute (0-59) */
int second; /* Second (0-60 (leap)) */
int usec; /* Microseconds (0-999999) */
} EXT_TIME;
typedef struct _int_time {
int year; /* Year. */
int second; /* Seconds in year (0-...) */
int usec; /* Microseconds (0-999999) */
} INT_TIME;
extern int get_my_wordorder()
extern int set_hdr_wordorder (int wordorder) /* desired wordorder of MiniSEED hdr. */
extern int set_data_wordorder (int wordorder) /* desired wordorder of MiniSEED data. */
extern int read_ms (DATA_HDR **phdr, /* pointer to pointer to DATA_HDR. */ void *data_buffer, /* pointer to output data buffer. */ int max_num_points, /* max # data points to return. */ FILE *fp); /* FILE pointer for input file. */
extern int read_ms_record (DATA_HDR **phdr, /* pointer to pointer to DATA_HDR. */ char **pbuf, /* ptr to buf ptr for MiniSEED record. */ FILE *fp); /* FILE pointer for input file. */
void free_data_hdr (DATA_HDR *hdr)
The following functions are useful for creating MiniSEED records.
DATA_HDR new_data_hdr ()
extern int ms_pack_data (DATA_HDR *hdr, /* ptr to initial data hdr. */ BS *init_bs, /* ptr to onetime blockettes. */ int num_samples, /* number of data samples. */ int *data, /* ptr to data buffer. */ int *n_blocks, /* # MiniSEED blocks (returned). */ char **pp_ms, /* ptr **MiniSEED (returned). */ int ms_len, /* MiniSEED buffer len (if supplied). */ char *p_errmsg) /* ptr to error msg buffer. */
If the ptr *pp_ms is NULL, the ms_pack_data function will allocate a buffer of sufficient size to hold the created MiniSEED records, return the ptr to the buffer in *pp_ms, and ignore the value of ms_len. If the ptr *pp_ms is not NULL, it is assumed to be a buffer of size ms_len bytes into which the function will write the MiniSEED records.
The function sets the variable *n_blocks to contain the number of MiniSEED records that were created The function returns the total number of initial data samples that were packed into the MiniSEED records, which should equal the total num_samples if there was sufficient room in the MiniSEED buffer for the required number of MiniSEED blocks. If the function value is less than num_samples, you can output the created MiniSEED records, adjust the DATA_HDR time value, and call the function again with an adjusted ptr to the input data buffer and adjusted num_samples.
INT_TIME ext_to_int (EXT_TIME et)
EXT_TIME int_to_ext (INT_TIME it)
void dy_to_mdy (int doy, int year, int *month, int *mday)
int mdy_to_doy (int month, int day, int year)
INT_TIME normalize_time (INT_TIME it)
The structure is normalized in the following order: minute, hour, day_of_year, year, and second. Once the second field has been normalized, the minute, hour, day, month, and year are normalized again. Once the date has been normalized, the month and day_of_month are calculated for the normalized field.
This function can be used to compute a new normalize time after values have been added to field(s) of an INT_TIME structure.
EXT_TIME normalize_ext (EXT_TIME et)
The structure is normalized in the following order: minute, hour, day_of_year, year, and second. Once the second field has been normalized, the minute, hour, day, month, and year are normalized again. Once the date has been normalized, the month and day_of_month are calculated for the normalized field.
This function can be used to compute a new normalize time after values have been added to field(s) of an EXT_TIME structure. Note that the month and day_of_month field are never normalized, but merely recomputed after the date has been normalized. Therefore, NEVER change the month or day_of_month field.
INT_TIME add_time (INT_TIME it, int seconds, int usecs)
INT_TIME add_dtime (INT_TIME it, double usecs)
time_interval2 (int n, int rate, int rate_mult, int *second, int *usecs)
double dsamples_in_time2 (int rate, int rate_mult, int usecs)
The function dsamples_in_time2 computes the the number of samples that span the specified time in usecs at the specified sample rate. Rate and rate_mult are taken from the DATA_HDR sample_rate and sample_rate_mult fields respectively and are defined by SEED. For example, at sample rate 100 (rate=100, rate_mult=1, for 100 samples per second) the span of 1,500,000 usecs (1.5 seconds) would span 100.0 samples of data.
double tdiff (INT_TIME it1, INT_TIME it2)
char *time_to_str (INT_TIME it, int fmt)
0 JULIAN_FMT: yyyy.doy hh:mm:ss.ffff
1 JULIAN_FMT_1: yyyy.doy,hh:mm:ss.ffff
2 MONTH_FMT: yyyy.mm.dd hh:mm:ss.ffff
3 MONTH_FMT_1: yyyy.mm.dd,hh:mm:ss.ffff
4 JULIANC_FMT: yyyy,doy hh:mm:ss.ffff
5 JULIANC_FMT_1: yyyy,doy,hh:mm:ss.ffff
6 MONTHS_FMT: yyyy/mm/dd hh:mm:ss.ffff
7 MONTHS_FMT_1: yyyy/mm/dd,hh:mm:ss.ffff
INT_TIME *parse_date(char *str)
time_t unix_time_from_ext_time (EXT_TIME et)
time_t unix_time_from_int_time (INT_TIME it)
INT_TIME int_time_from_timeval (struct timeval *tv)
c c Parameters for SEED data header data structures c integer DH_STATION_LEN, DH_CHANNEL_LEN, DH_LOCATION_LEN, 1 DH_NETWORK_LEN parameter ( 1 DH_STATION_LEN = 6, 2 DH_CHANNEL_LEN = 4, 3 DH_LOCATION_LEN = 3, 4 DH_NETWORK_LEN = 3 ) c c Date/Time data structure used for time calculations. c structure /INT_TIME/ integer year integer second integer usec end structure c c Date/Time data structure used for external interface. c structure /EXT_TIME/ integer year integer doy integer month integer day integer hour integer minute integer second integer usec end structure c c Data Header structure containing data from SEED Fixed Data Header c WARNING - this assumes pointers take the same space as an integer. c structure /DATA_HDR/ integer seq_no character*(DH_STATION_LEN) station_id character*(DH_LOCATION_LEN) location_id character*(DH_CHANNEL_LEN) channel_id character*(DH_NETWORK_LEN) network_id record /INT_TIME/ begtime record /INT_TIME/ endtime record /INT_TIME/ hdrtime integer num_samples integer num_data_frames integer sample_rate integer sample_rate_mult integer num_blockettes integer num_ticks_correction integer first_data integer first_blockette integer pblockettes integer data_type integer blksize character activity_flags character io_flags character data_quality_flags character hdr_wordorder character data_wordorder character record_type character cextra(2) integer x0 integer xn integer xm1 integer xm2 integer extra(1) end structure
integer function f_get_my_wordorder()
integer function f_set_hdr_wordorder integer wordorder
extern int f_set_data_wordorder integer wordorder
The function f_read_ms requires an argument fp which is a file handle that is returned by ifopen function. See the fio routines for fortran-callable routines for C buffered and unbufferd I/O.
integer function f_read_ms (hdr, data_buffer, maxpts, fp) record /DATA_HDR/ hdr integer maxpts integer data(maxpts) integer fp
integer function f_init_data_hdr (hdr) record /DATA_HDR/ hdr
integer function f_delete_blockette (hdr, n) record /DATA_HDR/ hdr integer n
The following functions are useful for creating MiniSEED records.
integer function f_ms_pack_data (hdr, num_samples, data, n_blocks, mseed, ms_len) record /DATA_HDR/ hdr integer num_samples integer data(num_samples) integer n_blocks character mseed[ms_len] integer ms_len
The resulting MiniSEED records may be written to a file using the fio routines for fortran-callable routines for C buffered and unbufferd I/O.
subroutine f_add_time (it, seconds, usecs, ot) record /INT_TIME/ it integer seconds integer usec record /INT_TIME/ ot
subroutine f_add_dtime (it, usecs, ot) record /INT_TIME/ it integer seconds double precision usec record /INT_TIME/ ot
subroutine f_time_interval2 (n, rate, rate_mult, seconds, usecs) integer n integer rate integer rate_mult integer seconds integer usecs
double precision function f_dsamples_in_time2 (rate, rate_mult, usecs) integer rate integer rate_mult integer usecs
The function f_dsamples_in_time2 computes the the number of samples that span the specified time in usecs at the specified sample rate. Rate and rate_mult are taken from the DATA_HDR sample_rate and sample_rate_mult fields respectively and are defined by SEED. For example, at sample rate 100 (rate=100, rate_mult=1, for 100 samples per second) the span of 1,500,000 usecs (1.5 seconds) would span 100.0 samples of data.
double precision function f_tdiff (it1, it2) record /INT_TIME/ it1 record /INT_TIME/ it2
subroutine f_dy_to_mdy (doy, year, month, mday) integer doy integer year integer month integer mday
integer function f_mdy_to_doy (month, day, year) integer month integer day integer year
subroutine f_ext_to_int (et, it) record /EXT_TIME/ et record /EXT_TIME/ it
subroutine f_int_to_ext (it, et) record /EXT_TIME/ it record /EXT_TIME/ et
subroutine f_time_to_str (it, fmt, str) record /INT_TIME/ it integer fmt character*(*) str
0 JULIAN_FMT: yyyy.doy hh:mm:ss.ffff
1 JULIAN_FMT_1: yyyy.doy,hh:mm:ss.ffff
2 MONTH_FMT: yyyy.mm.dd hh:mm:ss.ffff
3 MONTH_FMT_1: yyyy.mm.dd,hh:mm:ss.ffff
4 JULIANC_FMT: yyyy,doy hh:mm:ss.ffff
5 JULIANC_FMT_1: yyyy,doy,hh:mm:ss.ffff
6 MONTHS_FMT: yyyy/mm/dd hh:mm:ss.ffff
7 MONTHS_FMT_1: yyyy/mm/dd,hh:mm:ss.ffff
The timestamp string is returned in the last argument str.
integer function f_parse_date(it, str)
The time functions make use of the leapseconds file to tell them when leapseconds have (and will) occur. The format of the leapseconds file is compatible with that of Unix systems that have leapseconds file. The file must either be installed as /usr/local/lib/leapseconds or you should set the environment variable LEAPSECONDS to the pathname of the leapseconds file to use. If (for some reason) you do not wish to use a leapseconds file, you may set LEAPSECONDS to /dev/null, which will suppress any error messages about a missing leapseconds file.