#include "brttpkt.h" PktChannel2Db *pktchannel2db_create (Dbptr dbwfdisc, Pf *params) void pktchannel2db_free (PktChannel2Db *pdb) int pktchannel2db_put (PktChannel2Db *pdb, PktChannel *chan, size_t maxheap, double maxduration) void pktchannel2db_convert_wf (int convert_type, int *buf, long nsamp, float fgap_value, int igap_value)
The accumulation of waveform segments from potentially time fragmented data sources, such as certain real-time packet data, is done in a manner similar to cdorb2db(1). Upon reception of the first input data source for a particular channel, the start time of the first sample and the sample rate are used to define a constant time sampling grid over the requested time slices. The sample values in the entire grid are then pre-filled with official "gap" floating point sample values, using trfill_gap(3), for floating data, or the TRGAP_VALUE_S4 value in tr.h, for integer data. As data is accumulated, each new sample value is projected into its proper slot within the fixed sample grid to replace the gap value, or any other existing value such as would happen with time overlapping data. After all data has been accumulated, the final data arrays in the output database will show gap sample values at sample times where there were no input sample values.
pktchannel2db_create creates a new PktChannel2Db object and returns a pointer to the object instance. This pointer is used as a handle for subsequent operations. dbwfdisc is a database pointer to the output database wfdisc table. Since there are potentially many parameters for a conversion of this type, all of the parameters must be defined in the params Antelope parameter file object. The defined parameters are as follows.
- max_open_files
This is the maximum number of waveform files that will be open at any one time. If more files need to be opened, then the oldest files will be closed to preserve this number. If this number is not specified, then the default value of 200 is used.- verbose
This controls logging verbosity. This defaults to 0.- addcheck
If this is yes, then new wfdisc rows are always checked for consistency against the existing wfdisc rows. If there is a conflict with one or more existing wfdisc rows, then an error message is printed and the particular input data packet is ignored. If this is no, then no wfdisc consistency checking is done. New rows may or may not overlap with existing rows even when other attributes, like calib or datatype, are different. When not add checking, a new waveform file will always be created and given a unique name from any of the existing waveform file names. This defaults to no.- wfduration
this is the duration of output wfdisc waveform segments in seconds. The output segments are always aligned exactly on day-hour boundaries. This defaults to one day, 86400.0 seconds.- datatype
this specifies the output waveform datatype. If it is integer, then the output waveform files will be in integer format, either s4, for motorola byte order machines, or i4, for x86 byte order machines. If it is float, then the output waveform files will be in floating format, either t4, for motorola byte order machines, or f4, for x86 byte order machines. If it is input, then the output waveform files will be in the same format as the input waveform packets. If it is i4, f4, s4, t4, then the output format is in the specified format regardless of the machine or the input data. Note that other datatypes, such as sd, are not supported. This defaults to input.- gain
This is a floating gain applied to the input sample values before they are converted. The input calib is also divided by this value to form the output calib. This can be useful, for example, for gaining up filtered floating data before it is converted to integer. This defaults to 1.0.- maxheap
This controls the flushing behavior of the waveform buffers. See pktchannel2buffer(3) for an explanation. This defaults to 100000000.- maxduration
This controls the flushing behavior of the waveform buffers. See pktchannel2buffer(3) for an explanation. This defaults to 3600.0.- realtime_thresh
This is a data latency threshold value in seconds that controls adaptive flushing of waveform buffers. This causes the maxheap and maxduration values to be decreased in a linear fashion according to the data latency. When the data latency is greater than realtime_thresh, maxheap and maxduration are used directly. As the data latency goes down from realtime_thresh to 0, the values of maxheap and maxduration are ramped down to 0, which causes the data to be immediately flushed out to the waveform files. In this manner data latency is minimized when the data is caught up with real time but is buffered efficiently when data is lagging behind real time. This defaults to 3600.0.- samprate_thresh
This is a floating precentage threshold that is used to determine if a sample rate change is large enough to trigger generation of new wfdisc rows and waveform files. If this is less than 0.0, then sample rate changes will never trigger generation of new wfdisc rows and waveform files. This defaults to 10.0.- calib_thresh
This is a floating precentage threshold that is used to determine if a calib value change is large enough to trigger generation of new wfdisc rows and waveform files. If this is less than 0.0, then neither calib, calper nor segtype value changes will trigger generation of new wfdisc rows and waveform files. If the calib, calper and segtype values are being managed through post-processing, such as with rtdbclean(1), then calib_thresh should be set to a negative number. This defaults to 1.0.- calper_thresh
This is a floating precentage threshold that is used to determine if a calper value change is large enough to trigger generation of new wfdisc rows and waveform files. If this is less than 0.0, then calper value changes will never trigger generation of new wfdisc rows and waveform files. This defaults to 1.0.
A PktChannel2Db object is freed with pktchannel2db_free.
pktchannel2db_put will put a single PktChannel packet of data into a PktChannel2Db object, which will cause the packet to be written out as a portion of an existing waveform segment. If there is not an existing waveform segment that would contain the new packet, then one or more new waveform segments are created with new wfdisc rows added to the output database. The new wavefrom segments are created, filled with gap values and then the new packet sample values overwrite the waveform sample values.
pktchannel2db_convert_wf is a utility routine that can be used for converting waveform data in buffer buf with nsamp samples between various formats according to convert_type. All conversions are done in place and the converted gap values for floats are specified by fgap_value and for integers are specified by igap_value. The conversion convert_type values are as follows:
- CONVERT_WF_NONE
No conversion.- CONVERT_WF_FH2IH
Convert floats to integers in local machine byte order.- CONVERT_WF_IH2FH
Convert integers to floats in local machine byte order.- CONVERT_WF_F42S4
Convert floats in x86 byte order to integers in motorola byte order.- CONVERT_WF_T42I4
Convert floats in motorola byte order to integers in x86 byte order.- CONVERT_WF_I42T4
Convert integers in x86 byte order to floats in motorola byte order.- CONVERT_WF_S42F4
Convert integers in motorola byte order to floats in x86 byte order.- CONVERT_WF_I42S4
Convert integers in x86 byte order to integers in motorola byte order.- CONVERT_WF_S42I4
Convert integers in motorola byte order to integers in x86 byte order.- CONVERT_WF_F42T4
Convert floats in x86 byte order to floats in motorola byte order.- CONVERT_WF_T42F4
Convert floats in motorola byte order to floats in x86 byte order.
Everything else returns 0 if OK or -1 if there is an error. If there is an error, then messages are left on the error register.