[−][src]Crate netcdf
Rust bindings for Unidata's libnetcdf
Examples
Read:
// Open file simple_xy.nc: let file = netcdf::open("simle_xy.nc")?; // Access any variable, attribute, or dimension through lookups on hashmaps let var = &file.variable("data").expect("Could not find variable 'data'"); // Read variable as numeric types let data_i32 = var.value::<i32>(None)?; let data_f32 : f32 = var.value(None)?; // You can also use values() to read the variable, data will be read as the type given as type parameter (in this case T=i32) // Pass (None, None) when you don't care about the hyperslab indexes (get all data) let data = var.values::<i32>(None, None)?;
Write:
// Write let mut file = netcdf::create("crabs2.nc")?; let dim_name = "ncrabs"; file.add_dimension(dim_name, 10)?; let var_name = "crab_coolness_level"; let data : Vec<i32> = vec![42; 10]; // Variable type written to file let var = file.add_variable::<i32>( var_name, &[dim_name], )?; var.put_values(&data, None, None);
Append:
// You can also modify a Variable inside an existing netCDF file // open it in read/write mode let mut file = netcdf::append("crabs2.nc")?; // get a mutable binding of the variable "crab_coolness_level" let mut var = file.variable_mut("crab_coolness_level").unwrap(); let data : Vec<i32> = vec![100; 10]; // write 5 first elements of the vector `data` into `var` starting at index 2; var.put_values(&data[..5], Some(&[2]), Some(&[5])); // Change the first value of `var` into '999' var.put_value(999.0f32, Some(&[0]));
Re-exports
pub use attribute::*; |
pub use dimension::*; |
pub use file::*; |
pub use group::*; |
pub use variable::*; |
Modules
attribute | Add and read attributes from netcdf groups and variables |
dimension | Interact with netcdf dimensions |
error | Errors that can appear when interacting with netcdf files. This module contains conversion traits and the result type used in this crate. |
file | Open, create, and append netcdf files |
group | All netcdf items belong in the root group, which can be interacted with to get the underlying data |
variable | Variables in the netcdf file |
Functions
append | Open a netcdf file in append mode |
create | Open a netcdf file in create mode |
open | Open a netcdf file in read mode |