Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] 39 Support Defragment of TDMS File #40

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

jimkring
Copy link

@jimkring jimkring commented Feb 20, 2024

Doing some work on a defragment function

Implements #39

@jimkring jimkring changed the title [DRAFT] Defragment [DRAFT] 39 Support Defragment of TDMS File Feb 20, 2024
@jimkring jimkring marked this pull request as draft February 20, 2024 19:33
@@ -11,7 +11,7 @@ mod raw_data;
pub use error::TdmsError;
pub use file::TdmsFile;
pub use file::TdmsFileWriter;
pub use io::data_types::TdmsStorageType;
pub use io::data_types::{TdmsStorageType, DataType};
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JamesMc86 I made DataType public so that I could use it in my high-level tests. Not sure if this is how you want to expose supported datatypes in the API.

Comment on lines +60 to +130
// #todo: refactor this into a `copy_channel()` function

let channel_length = input_file.channel_length(&channel_path).unwrap();

// print the channel length
println!("channel_length: {:?}", channel_length);


// print the channel type
let channel_type = input_file.get_channel_type(&channel_path);
match channel_type {
Some(t) => println!("channel_type: {:?}", t),
None => println!("channel_type: None"),
}

let channel_type = input_file.get_channel_type(&channel_path);

match channel_type {

Some(DataType::SingleFloat) => {
let mut data: Vec<f32> = vec![0.0; channel_length as usize];
input_file.read_channel(&channel_path, &mut data).unwrap();
writer.write_channels(&[channel_path], &data, tedium::DataLayout::Interleaved).unwrap();
},
Some(DataType::DoubleFloat) => {
let mut data: Vec<f64> = vec![0.0; channel_length as usize];
input_file.read_channel(&channel_path, &mut data).unwrap();
writer.write_channels(&[channel_path], &data, tedium::DataLayout::Interleaved).unwrap();
},
Some(DataType::I8) => {
let mut data: Vec<i8> = vec![0; channel_length as usize];
input_file.read_channel(&channel_path, &mut data).unwrap();
writer.write_channels(&[channel_path], &data, tedium::DataLayout::Interleaved).unwrap();
},
Some(DataType::I16) => {
let mut data: Vec<i16> = vec![0; channel_length as usize];
input_file.read_channel(&channel_path, &mut data).unwrap();
writer.write_channels(&[channel_path], &data, tedium::DataLayout::Interleaved).unwrap();
},
Some(DataType::I32) => {
let mut data: Vec<i32> = vec![0; channel_length as usize];
input_file.read_channel(&channel_path, &mut data).unwrap();
writer.write_channels(&[channel_path], &data, tedium::DataLayout::Interleaved).unwrap();
},
Some(DataType::I64) => {
let mut data: Vec<i64> = vec![0; channel_length as usize];
input_file.read_channel(&channel_path, &mut data).unwrap();
writer.write_channels(&[channel_path], &data, tedium::DataLayout::Interleaved).unwrap();
},
Some(DataType::U8) => {
let mut data: Vec<u8> = vec![0; channel_length as usize];
input_file.read_channel(&channel_path, &mut data).unwrap();
writer.write_channels(&[channel_path], &data, tedium::DataLayout::Interleaved).unwrap();
},
Some(DataType::U16) => {
let mut data: Vec<u16> = vec![0; channel_length as usize];
},
Some(DataType::U32) => {
let mut data: Vec<u32> = vec![0; channel_length as usize];
input_file.read_channel(&channel_path, &mut data).unwrap();
writer.write_channels(&[channel_path], &data, tedium::DataLayout::Interleaved).unwrap();
},
Some(DataType::U64) => {
let mut data: Vec<u64> = vec![0; channel_length as usize];
input_file.read_channel(&channel_path, &mut data).unwrap();
writer.write_channels(&[channel_path], &data, tedium::DataLayout::Interleaved).unwrap();
},
Some(data_type) => println!("Unsupported data type: {}", data_type),
None => println!("None"),
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JamesMc86 this whole block could be refactored into a copy_channel_data high-level API method

Comment on lines +152 to +160

pub fn get_channel_type(&self, channel: &ChannelPath) -> Option<DataType> {
let data_type = self.index.channel_type(channel);
if let Some(data_type) = data_type {
Some(*data_type)
} else {
None
}
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JamesMc86 New function allows reading a channel type from a TdmsFile

Comment on lines +177 to +192
// Get the data type for the given channel.
///
/// Returns None if the channel does not exist.
pub fn channel_type(&self, path: &ChannelPath) -> Option<&DataType> {
self.objects
.get(path.path())
.and_then(|object| {
object
.latest_data_format
.as_ref()
.and_then(|format| match format {
DataFormat::RawData(meta) => Some(&meta.data_type),
})
})
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JamesMc86 new function allows getting a channel_type from an Index so that it can be accessed from higher level APIs

@JamesMc86
Copy link
Contributor

This is looking great - all looks on the right track to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants