Struct sdf::file::File
[−]
[src]
pub struct File { /* fields omitted */ }
An .sdf file.
The file is mostly a simple wrapper around an fwifc_file
handle, but we do a bit of extra
smarts (or dumbs) to help other users.
- We ensure that we reindex the file only once, regardless of the number of times that
reindex
has been called.
Methods
impl File
[src]
fn open<T: Into<Vec<u8>>>(path: T) -> Result<File>
Opens an .sdf data file.
Examples
use sdf::file::File; let file = File::open("data/110630_174316.sdf").unwrap();
fn reindex(&mut self) -> Result<()>
(Re-)Creates the index file.
The index file is required for navigating the file. This is a blocking operation and may take some time. The index file is placed in the same directory as the data file.
Examples
use sdf::file::File; let mut file = File::open("data/110630_174316.sdf").unwrap(); file.reindex().unwrap();
fn remove_index(&self) -> Result<()>
Remove this file's index from the filesystem.
Examples
use sdf::file::File; let mut file = File::open("data/110630_174316.sdf").unwrap(); file.reindex().unwrap(); file.remove_index().unwrap();
fn set_sosbl_mode(&mut self, mode: SosblMode) -> Result<()>
Sets the mode timestamp of the start of the sample block.
Examples
use sdf::file::{File, SosblMode}; let mut file = File::open("data/110630_174316.sdf").unwrap(); file.set_sosbl_mode(SosblMode::Relative).unwrap(); file.set_sosbl_mode(SosblMode::Absolute).unwrap();
fn info(&mut self) -> Result<FileInfo>
Gets information about the file.
Examples
use sdf::file::File; let mut file = File::open("data/110630_174316.sdf").unwrap(); let file_info = file.info();
fn calibration(&mut self, kind: CalibrationTableKind) -> Result<Calibration>
Gets the calibration info for the file.
We manually copy all of the calibration info into new vectors because we can't really trust the memory behind the fwifc call.
Examples
use sdf::file::{File, CalibrationTableKind, Channel}; let mut file = File::open("data/110630_174316.sdf").unwrap(); let calibration = file.calibration(CalibrationTableKind::Amplitude(Channel::High)).unwrap();
fn read(&mut self) -> Result<Record>
Reads a sample data record from the file.
Panics
Panics if the underlying sdfifc library returns a record with two blocks with the same channel. We assume that this can't happen, and so we panic (rather than returning an error) to indicate that this is a very exceptional case.
Examples
use sdf::file::File; let mut file = File::open("data/110630_174316.sdf").unwrap(); file.reindex().unwrap(); let record = file.read().unwrap();
fn seek(&mut self, index: u32) -> Result<()>
Seeks to a record index in the file.
Examples
Seeks to the first record.
use sdf::file::File; let mut file = File::open("data/110630_174316.sdf").unwrap(); file.reindex().unwrap(); file.seek(1).unwrap();
Seeks to the end of the file.
use std::u32; use sdf::file::File; let mut file = File::open("data/110630_174316.sdf").unwrap(); file.reindex().unwrap(); file.seek(u32::MAX).unwrap();
fn seek_time(&mut self, time: f64) -> Result<()>
Seeks to an internal timestamp, in seconds.
Examples
use sdf::file::File; let mut file = File::open("data/110630_174316.sdf").unwrap(); file.reindex().unwrap(); file.seek_time(1.0).unwrap();
fn seek_time_external(&mut self, time: f64) -> Result<()>
Seeks to an external time in seconds.
Either day or week seconds. This requires GPS-synchronized data.
Examples
use sdf::file::File; let mut file = File::open("data/110630_174316.sdf").unwrap(); file.reindex().unwrap(); file.seek_time_external(1.0).unwrap();
fn tell(&mut self) -> Result<u32>
Returns the index of the next record to be read.
Examples
use sdf::file::File; let mut file = File::open("data/110630_174316.sdf").unwrap(); file.reindex().unwrap(); assert_eq!(1, file.tell().unwrap()); file.read().unwrap(); assert_eq!(2, file.tell().unwrap());
fn indexed(&self) -> bool
Returns true if this file is indexed.
Examples
use sdf::file::File; let file = File::open("data/110630_174316.sdf").unwrap(); file.indexed();