[][src]Crate netcdf

Rust bindings for Unidata's [libnetcdf] (http://www.unidata.ucar.edu/software/netcdf/)

Examples

Read:

// Open file simple_xy.nc:
let file = netcdf::open(&path_to_simple_xy).unwrap();

// Access any variable, attribute, or dimension through simple HashMap's:
let var = file.root.variables.get("data").unwrap();

// Read variable as any NC_TYPE, optionally failing if doing so would
// force a cast:
let data : Vec<i32> = var.get_int(false).unwrap();

// You can also use values() to read the variable, data will be implicitly casted
// if needed
let data : Vec<i32> = var.values().unwrap();

// All variable data is read into 1-dimensional Vec.
for x in 0..(6*12) {
    assert_eq!(data[x], x as i32);
}

Write:

// Write
let f = netcdf::test_file_new("crabs2.nc"); // just gets a path inside repo
{
    let mut file = netcdf::create(&f).unwrap();
     
    let dim_name = "ncrabs";
    file.root.add_dimension(dim_name, 10).unwrap();
     
    let var_name = "crab_coolness_level";
    let data : Vec<i32> = vec![42; 10];
    // Variable type written to file is inferred from Vec type:
    file.root.add_variable(
                var_name, 
                &vec![dim_name.to_string()],
                &data
            ).unwrap();
}

// Append:
{
    // You can also modify a Variable inside an existing netCDF file
    // open it in read/write mode
    let mut file = netcdf::append(&f).unwrap();
    // get a mutable binding of the variable "crab_coolness_level"
    let mut var = file.root.variables.get_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_at(&data, &[2], &[5]);
    // Change the first value of `var` into '999'
    var.put_value_at(999 as f32, &[0]);
}

Re-exports

pub use file::open;
pub use file::create;
pub use file::append;

Modules

attribute
dimension
file
group
variable

Structs

NC_ERRORS

Functions

test_file
test_file_new