[DRAFT] 39 Support Defragment of TDMS File#40
Draft
jimkring wants to merge 8 commits intoWiresmithTech:mainfrom
Draft
[DRAFT] 39 Support Defragment of TDMS File#40jimkring wants to merge 8 commits intoWiresmithTech:mainfrom
jimkring wants to merge 8 commits intoWiresmithTech:mainfrom
Conversation
jimkring
commented
Feb 20, 2024
| pub use file::TdmsFile; | ||
| pub use file::TdmsFileWriter; | ||
| pub use io::data_types::TdmsStorageType; | ||
| pub use io::data_types::{TdmsStorageType, DataType}; |
Author
There was a problem hiding this comment.
@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.
jimkring
commented
Feb 20, 2024
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"), | ||
| } | ||
|
|
Author
There was a problem hiding this comment.
@JamesMc86 this whole block could be refactored into a copy_channel_data high-level API method
jimkring
commented
Feb 20, 2024
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 | ||
| } | ||
| } |
Author
There was a problem hiding this comment.
@JamesMc86 New function allows reading a channel type from a TdmsFile
jimkring
commented
Feb 20, 2024
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), | ||
| }) | ||
| }) | ||
| } | ||
|
|
Author
There was a problem hiding this comment.
@JamesMc86 new function allows getting a channel_type from an Index so that it can be accessed from higher level APIs
Contributor
|
This is looking great - all looks on the right track to me |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Doing some work on a defragment function
Implements #39