📄 ms_intro.3
字号:
.IP numsamples:The number of samples pointed to by the 'datasamples' pointer..IP sampletype:The type of samples pointed to by the 'datasamples' pointer.Supported types are 'a' (ASCII), 'i' (integer), 'f' (float) and 'd'(double). The size of each sample type in bytes is returnedby the get_samplesize(3) lookup routine..IP prvtptr:A private pointer for general use. This pointer is not used bylibmseed and can safely be used by the calling program..IP ststate:Pointer to a StreamState struct used internally to track streamoriented state variables. Memory for this only allocated when needed..IP next:A pointer to the next MSTrace structure. The value will be 0 for thelast link in a chain of MSTrace structures..SH LOG MESSAGESAll of the log and diagnostic messages emitted by the libraryfunctions use the same interface. The output from this interface canbe controlled. This is useful when the library will be embedded in alarger system with a custom logging facility. See the man page formore details..nf ms_log() : the central logging facility. Behavior is controlled by the settings specified with ms_loginit(). ms_loginit() : set the functions and prefixes used for log, diagnostic and error messages..fiThe default destination for log messages is standard output (stdout),while all diagnostic (including error) messages go to standard error(stderr). Most of the internal messages emmited by the library areconsidered diagnostic and will, by default, go to standard error.The default prefix for log and diagnostic messages is nothing. Thedefault prefix for diagnostic error messages is "Error: ".There are reentrant versions of these functions that operate directlyon a logging parameter MSLogParam struct. These are intended for usein threaded programs or where a complex logging scheme is desired.See the man pages for more details..SH WAVEFORM DATAWaveform data samples are managed by libmseed in a couple of differentformats depending on how they are unpacked or will be packed. Anarray of samples is completely represented by an array of samplevalues, the number of samples and a sample type. The number ofsamples is always the actual number of sample values, not the numberof bytes needed for storing the values. Samples can be either ASCII,32-bit integer, 32-bit floats or 64-bit double precision floats.Sample types are identified by a single ASCII type character:.nf"a" - ASCII (8 bits)"i" - integer (32 bits)"f" - float (32 bits)"d" - double (64 bits).fiThe size of each sample type in bytes is returned by theget_samplesize(3) lookup routine..SH BYTE ORDERThe SEED 2.4 standard allows data only SEED (Mini-SEED) to be eitherin big (most significant byte first) or little (least significant bytefirst) endian byte order. Unfortunately it is not well defined whatlittle endian Mini-SEED really means. While libmseed supports allfour combinations of big and little endian header and data the surestway to avoid compatibility problems is to always create big endianMini-SEED records (header and data)..B Reading MiniSEED - how libmseed determines the byte order of a record:The byte order of a record header is determined by checking if therecord start year is a sane value (e.g. between 1920 and 2020). Thebyte order of (compressed) data samples is determined by the byteorder flag in the Blockette 1000, if a Blockette 1000 is not presentthe byte order is assumed to be the same as the header. To force thebyte order determination of either the header or data section of arecord the following environment variables can be set:.nfUNPACK_HEADER_BYTEORDERUNPACK_DATA_BYTEORDER.fiThese variables should be set to either 0 (little endian) or 1 (bigendian). A programmatic equivalent of setting these environmentvariables is provided via the following macros:.nfMS_UNPACKHEADERBYTEORDER(X)MS_UNPACKDATABYTEORDER(X).fi.B Writing MiniSEED - in what byte order libmseed creates records:Normally the byte order of MiniSEED created by libmseed is controlledvia a flag in the API. This byte order flag determines the orderingfor both the header and data sections of a record. To force the byteorder of either the header or data section of a record the followingenvironment variables can be set:.nfPACK_HEADER_BYTEORDERPACK_DATA_BYTEORDER.fiThese variables should be set to either 0 (little endian) or 1 (bigendian). A programmatic equivalent of setting these environmentvariables is provided via the following macros:.nfMS_PACKHEADERBYTEORDER(X)MS_PACKDATABYTEORDER(X).fiNote that some interpretations of the SEED 2.4 format imply thatso-called little endian MiniSEED means that the record header islittle endian but that the data section is big endian (as the onlydefined data encodings must be based on the SEED DDL which, in turn,must be defined in terms of big endian). Libmseed will not createMiniSEED of this flavor by default but can be configured to do so bysetting the environment variables described above approriately..SH COMMON USAGEExample programs using libmseed are provided in the 'examples'directory of the source code distribution.One of the most common tasks is to read a file of Mini-SEED recordsand either perform some action based on the header values or applysome process to the data samples. This task is greatly simplified byusing the library functions ms_readmsr(3) and ms_readtraces(3). Thems_readmsr(3) routine will open a specified file and return MSRecordstructures for each Mini-SEED record it reads from the file. Thems_readtraces(3) routine will do the same except add all the data readto a MSTraceGroup, this is ideal for quickly reading data forprocessing. Both of these routines are able to automatically detectrecord length.Skeleton code for reading a file with ms_readmsr(3):.nfmain() { MSRecord *msr = NULL; int retcode; while ( (retcode = ms_readmsr (&msr, filename, 0, NULL, NULL, 1, 0, verbose)) == MS_NOERROR ) { /* Do something with the record here, e.g. print */ msr_print (msr, verbose); } if ( retcode != MS_ENDOFFILE ) ms_log (2, "Cannot read %s: %s\n", filename, ms_errorstr(retcode)); /* Cleanup memory and close file */ ms_readmsr (&msr, NULL, 0, NULL, NULL, 0, 0);}.fiFor reading two files with ms_readtraces(3):.nfmain() { MSTraceGroup *mstg = NULL; int retcode; retcode = ms_readtraces (&mstg, filename, 0, -1.0, -1.0, 0, 1, 0, verbose); if ( retcode != MS_ENDOFFILE ) ms_log (2, "Cannot read %s: %s\n", filename, ms_errorstr(retcode)); retcode = ms_readtraces (&mstg, filename2, 0, -1.0, -1.0, 0, 1, 0, verbose); if ( retcode != MS_ENDOFFILE ) ms_log (2, "Cannot read %s: %s\n", filename2, ms_errorstr(retcode)); if ( ! mstg ) { fprintf (stderr, "Error reading file\\n"); return -1; } /* Do something with the traces here, e.g. print */ mst_printtracelist (mstg, 0, verbose, 0); mst_freegroup (&mstg);}.fiAnother common task is to create (pack) Mini-SEED records. The librarysupports packing of Mini-SEED either from MSRecord structures, MSTracestructures or MSTraceGroup collections using, respectively, msr_pack(3),mst_pack(3) or mst_packgroup(3). In each case the appropriate datastructure and parameters are provided to the routine along with afunction pointer to a routine that will be called each time a recordis complete and should be disposed of.When packing Mini-SEED records the concept of a record header templateis used, the template is always in the form of a MSRecord structure.This allows the calling program to dictate the contents, with a fewexceptions, of the header in the final data records.Skeleton code for creating (packing) Mini-SEED records withmst_pack(3):.nfstatic void record_handler (char *record, int reclen, void *srcname) { if ( fwrite(record, reclen, 1, outfile) != 1 ) { ms_log (2, "Error writing %s to output file\n", (char *)srcname); }}main() { int psamples; int precords; MSTrace *mst; char srcname[50]; mst = mst_init (NULL); /* Populate MSTrace values */ strcpy (mst->network, "XX"); strcpy (mst->station, "TEST"); strcpy (mst->channel, "BHE"); mst->starttime = ms_seedtimestr2hptime ("2004,350,00:00:00.000000"); mst->samprate = 40.0; /* The datasamples pointer and numsamples counter will be adjusted by the packing routine, the datasamples array must be dynamic memory allocated by the malloc() family of routines. */ mst->datasamples = dataptr; /* pointer to 32-bit integer data samples */ mst->numsamples = 1234; mst->sampletype = 'i'; /* declare type to be 32-bit integers */ mst_srcname (mst, srcname, 0); /* Pack 4096 byte, big-endian records, using Steim-2 compression */ precords = mst_pack (mst, &record_handler, srcname, 4096, DE_STEIM2, 1, &psamples, 1, verbose, NULL); ms_log (0, "Packed %d samples into %d records\n", psamples, precords); mst_free (&mst);}.fi.SH SEE ALSO\fBmsr_unpack(3)\fP, \fBms_time(3)\fP and \fBmsr_pack(3)\fP.SH AUTHOR.nfChad TrabantIRIS Data Management Center.fi
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -