Skip to content

Commit

Permalink
save work
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgraham4401 committed Nov 14, 2023
1 parent 05e4369 commit 57dc81f
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 60 deletions.
43 changes: 27 additions & 16 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions src/gather.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use std::io::Read;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Precision {
Single,
Double,
}

#[derive(Debug)]
pub struct Gather<T> {
pub id: u16,
pub nt: u16,
pub nx: u16,
pub dt: f32,
pub data: Option<Vec<T>>,
precision: Option<Precision>,
}

fn read_binary_file(file_name: &str) -> Vec<u8> {
let mut file = std::fs::File::open(file_name).unwrap();
let mut buffer = Vec::new();
file.read_to_end(&mut buffer).unwrap();
buffer
}

fn load_data_into_gather<T>(path: &str, time_sampling: f32, samples_per_trace: u16, number_of_traces: u16 ) -> Gather<T> {
let data_from_file = read_binary_file(path);
Gather {
id: 1,
dt: time_sampling,
nt: samples_per_trace,
nx: number_of_traces,
precision: None,
data: None,
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn it_works() {
assert_eq!(2, 2);
}

#[test]
fn reads_binary_file() {
let file_path: &str = "./resources/shot6220.bin";
let gather = load_data_into_gather(file_path, 0.004, 3101, 1000);
println!("Gather: {:?}", gather)
}
}
45 changes: 1 addition & 44 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,44 +1 @@
use std::io::Read;

#[derive(Debug)]
pub struct Gather {
id: u16,
nt: u16,
nx: u16,
dt: f32,
data: Vec<u8>,
}

fn read_binary_file(file_name: &str) -> Vec<u8> {
let mut file = std::fs::File::open(file_name).unwrap();
let mut buffer = Vec::new();
file.read_to_end(&mut buffer).unwrap();
buffer
}

fn load_data_into_gather(path: &str, time_sampling: f32, samples_per_trace: u16, number_of_traces: u16 ) -> Gather {
Gather {
id: 1,
data: read_binary_file(path),
dt: time_sampling,
nt: samples_per_trace,
nx: number_of_traces,
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn it_works() {
assert_eq!(2, 2);
}

#[test]
fn reads_binary_file() {
let file_path: &str = "./resources/shot6220.bin";
let gather = load_data_into_gather(file_path, 0.004, 3101, 1000);
println!("Gather: {:?}", gather)
}
}
mod gather;

0 comments on commit 57dc81f

Please sign in to comment.