Crate mseed

Source
Expand description

§libmseed bindings for Rust.

This library contains bindings to the libmseed C library which is used to manage miniSEED data. The library itself is a work in progress and is likely lacking some bindings here and there, so be warned.

The mseed library strives to be as close to libmseed as possible, but also strives to make using libmseed as safe as possible. All resource management is automatic as well as adding strong types to all interfaces (including MSResult).

§High-level miniSEED record I/O

Reading and writing miniSEED records is implemented by means of MSReader and MSWriter, respectively.

use std::fs::OpenOptions;

use mseed::{MSControlFlags, MSReader, MSWriter};

let mut reader =
    MSReader::new_with_flags("path/to/in.mseed", MSControlFlags::MSF_UNPACKDATA).unwrap();

let out_file = OpenOptions::new().write(true).open("out.mseed").unwrap();
let mut writer = MSWriter::new(out_file);

while let Some(msr) = reader.next() {
    let msr = msr.unwrap();

    if msr.network().unwrap() == "NET" && msr.station().unwrap() == "STA" {
        // do something with msr

        writer
            .write_record(&msr, MSControlFlags::MSF_FLUSHDATA)
            .unwrap();
    }
}

§Low-level miniSEED record I/O

Creating miniSEED records from raw data samples is possible using the low-level pack_raw() function:

use std::fs::OpenOptions;
use std::io::{BufWriter, Write};

use time::format_description::well_known::Iso8601;
use time::OffsetDateTime;

use mseed::{self, MSControlFlags, PackInfo};

let pack_info = PackInfo::new("FDSN:XX_TEST__X_Y_Z").unwrap();

let file = OpenOptions::new()
    .create(true)
    .write(true)
    .open("path/to/out.mseed")
    .unwrap();
let mut writer = BufWriter::new(file);

let record_handler = move |rec: &[u8]| {
    let _ = writer.write(rec);
};

let mut data_samples: Vec<i32> = (1..100).collect();
let start_time = OffsetDateTime::parse("2012-01-01T00:00:00Z", &Iso8601::DEFAULT).unwrap();
mseed::pack_raw(
    &mut data_samples,
    &start_time,
    record_handler,
    &pack_info,
    MSControlFlags::MSF_FLUSHDATA,
)
.unwrap();

Structs§

ConnectionInfo
Holds the connection information that MSFileParam should use for reading.
MSBitFieldFlags
Bit field flags.
MSControlFlags
Parsing, packing and trace construction control flags.
MSError
A structure representing libmseed errors.
MSFileParam
A state container for reading miniSEED records.
MSRecord
miniSEED record structure.
MSTraceId
A container for a trace identifier composed by MSTraceSegments.
MSTraceIdIter
An iterator for MSTraceId.
MSTraceList
A container for MSTraceIds.
MSTraceSegment
A container for a continuous trace segment.
MSTraceSegmentIter
An iterator for MSTraceSegment.
MSWriter
Generic miniSEED record writer.
PackInfo
Struct providing miniSEED record packing information.
RecordDetection
Structure returned by detect().
RecordDisplay
Helper struct for printing MSRecord with format! and {}.
TlPackInfo
Struct aggregating MSTraceList packing information.
TraceListDisplay
Helper struct for printing MSTraceList with format! and {}.

Enums§

MSDataEncoding
An enumeration of possible data encodings.
MSErrorCode
An enumeration of possible errors that can happen when working with miniSEED records.
MSSampleType
An enumeration of possible sample types.
MSSubSeconds
Enumeration of subsecond format identifiers.
MSTimeFormat
Enumeration of time format identifiers.

Traits§

DataSampleType
IntoConnectionInfo
Converts an object into a ConnectionInfo struct. This allows the constructor of the client to accept a file path or an URL in a range of different formats.

Functions§

detect
Detect miniSEED record in buffer.
factor_multiplier_to_sample_rate
Calculates the sample rate as samples per second (Hz) from SEED 2.x sample rate factor and multiplier.
pack_header2
Pack a miniSEED version 2 header into the specified buffer.
pack_header3
Pack a miniSEED version 3 header into the specified buffer.
pack_raw
Low level function that packs raw data samples into miniSEED records.
pack_record
Pack record data into miniSEED records.
pack_trace_list
Packs the trace lists’ data into miniSEED records.
repack_mseed3
Repack a parsed miniSEED record into a version 3 record.
seedchan2xchan
Converts a SEED 2.x channel identifier to an extended channel identifier.
xchan2seedchan
Converts an extended channel identifier to a SEED 2.x channel identifier.

Type Aliases§

MSReader
Counterpart of MSWriter.
MSResult
A specialized library Result type.