📄 mst_pack.3
字号:
.TH MST_PACK 3 2007/08/16 "Libmseed API".SH DESCRIPTIONPacking of Mini-SEED records from MSTrace segments..SH SYNOPSIS.nf.B #include <libmseed.h>.BI "int \fBmst_pack\fP ( MSTrace *" mst ",".BI " void (*" record_handler ") (char *, int, void *),".BI " void *" handlerdata ", int " reclen ", flag " encoding ",".BI " flag " byteorder ", int *" packedsamples ", flag " flush ",".BI " flag " verbose ", MSRecord *" mstemplate " );".BI "int \fBmsr_packgroup\fP ( MSTraceGroup *" mstg ",".BI " void (*" record_handler ") (char *, int, void *),".BI " void *" handlerdata ", int " reclen ", flag " encoding ",".BI " flag " byteorder ", int *" packedsamples ", flag " flush ",".BI " flag " verbose ", MSRecord *" mstemplate " );".fi.SH DESCRIPTION\fBmst_pack\fP creates (packs) Mini-SEED data records from a MSTracesegment using the specified record length (\fIreclen\fP), Mini-SEED\fIencoding\fP and \fIbyteorder\fP. Using \fImstemplate\fP as atemplate, the common header fields and blockettes are packed into arecord header. If no template will be used \fImstemplate\fP should beset to NULL. A Blockette 1000 will be added if one is not present inthe template. The MSTrace.datasamples array and MSTrace.numsamples valuewill be adjusted (reduced) as samples are packed into data records.This routine will modify the record length, encoding format, byteorder and sequence number of the MSRecord template. The start time,sample rate, data array, number of samples and sample type of theMSRecord template are preserved.Default values will be used for any of the key characteristics ofrecord length, encoding format and byte order that are -1. Thedefault values are: reclen = 4096 bytes, encoding = 11 (Steim2) andbyteorder = 1 (MSBF or big-endian).\fIreclen\fP should be set to the desired data record length in byteswhich must be expressible as 2 raised to the power of X where X isbetween (and including) 8 to 20.\fIencoding\fP should be set to one of the following supportedMini-SEED data encoding formats: DE_ASCII (0), DE_INT16 (1), DE_INT32(3), DE_FLOAT32 (4), DE_FLOAT64 (5), DE_STEIM1 (10) and DE_STEIM2(11). The encoding aliases are defined in libmseed.h.MSTrace.sampletype should indicated the sample type as either 'a'(ASCII), 'i' (32-bit integers), 'f' (32-bit floats) or 'd' (64-bitdoubles).The encoding format must be appropriate for the sample type of theMSTrace samples. For example, Steim compression and integer encodingformats require integer samples and float encoding formats require theappropriate size floats as input. As a counter example, float samplescannot be packed using Steim compression or integer encoding formats.\fIbyteorder\fP must be either 0 (LSBF or little-endian) or 1 (MBF orbig-endian).Each time a complete record is packed it will be passed to the\fIrecord_handler()\fP function which expects three arguments: 1) achar * to the record buffer, 2) the length of the record in bytes and3) a void pointer supplied by the caller. It is the responsibility of\fIrecord_handler()\fP to process the record, the memory will bere-used or freed when \fIrecord_handler()\fP returns. This functionpointer is required, there is no other way to access the packedrecords.The \fIhandlerdata\fP pointer will be passed as the 3rd argument to\fIrecord_handler()\fP. This allows the caller to optionally passdata directly to the \fIrecord_handler()\fP.The integer pointed to by \fIpackedsamples\fP will be set to the totalnumber of samples packed.If the \fIflush\fP flag is not zero all of the data will be packedinto records, otherwise records will only be packed while there areenough data samples to completely fill a record.The \fIverbose\fP flag controls verbosity, a value of zero will resultin no diagnostic output.\fBmst_packgroup\fP simply calls \fBmst_pack\fP for each MSTrace in thespecified MSTraceGroup. The integer pointed to by \fIpackedsamples\fPwill be set to the total number of samples packed..SH COMPRESSION HISTORYWhen the encoding format is Steim 1 or 2 compression contiguousrecords will be created including compression history. Put simply,this means that the first difference in the compression series will bethe difference between the first sample of the current record and thelast sample of the previous record. For the first record in a series(no previous record), a so-called cold start, the first differencewill be zero.The compression history can be seeded by allocating the StreamStatestruct for the MSTrace and setting the \fBlastintsample\fP member tothe integer sample value that preceded the first sample in the currentseries and setting the \fBcomphistory\fP flag to true (1)..SH RETURN VALUES\fBmst_pack\fP returns the number records created on success and -1 onerror.\fBmst_packgroup\fP returns the total (for all MSTraces) number ofrecord created on success and -1 on error..SH CAVEATSWhen using a MSRecord template (\fImstemplate\fP) the dataqualitymember must be set to a valid value. It is also advisable to set thenetwork, station, location and channel indicators to appropriatevalues. Unless these source indicators need to change they can simplybe copied from the matching MSTrace members..SH EXAMPLESkeleton 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\fBms_intro(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 + -