netcdf3 0.1.0

A Rust implementation of NetCDF-3 file format
Documentation
netcdf3-0.1.0 has been yanked.

netcdf3

LICENSE Build Status Crates.io Version

Documentation

Description

netcdf3 is a library for read/write NetCDF-3 file written in Rust.

Technical features

  • Read classic and 64-bit offset NetCDF-3 file :
    • Open file and parse the header.
    • Read all variables of a file.
    • Read a part of variables.
    • Keeping the shape of the N-dimensional arrays (using the crate ndarray)
  • Write classic and 64-bit offset NetCDF-3 file.

Examples

Read a file

use netcdf3::{
    FileReader, Version, DataSet,
};

fn main()
{

    // Read the data set
    let data_set: DataSet = {
        let mut file_reader = FileReader::open("netcdf3_file.nc").unwrap();
        let _ = file_reader.read_all_vars().unwrap();
        file_reader.close()
    };

    println!("FILE DESCRIPTION");
    println!("----------------");
    println!("Version                          : {}", match data_set.version() {
        Version::Classic => "Classic",
        Version::Offset64Bit => "64-Bit Offset",
    });
    println!("Number of dimensions             : {}", data_set.num_dims());
    for dim in data_set.get_dims() {
        println!("    {name} = {size}{is_unlimited}", name=dim.name(), size=dim.size(), is_unlimited=
            if dim.is_unlimited() {
                " (unlimited)"
            } else {
                ""
            }
        );
    }
    println!("Number of global attributes      : {}", data_set.num_global_attrs());
    for attr in data_set.get_global_attrs() {
        println!("    {name}({data_type})", name=attr.name(), data_type=attr.data_type().c_api_name());
    }

    println!("Number of variables              : {}", data_set.num_vars());
    for var in data_set.get_vars() {
        println!("   {} :", var.name());
        println!("        dimensions           : {:?}", var.get_dim_names());
        println!("        number of elements   : {}", var.len());
        println!("        data type            : {}", var.data_type().c_api_name());
        println!("        is a record variable : {}", var.is_record_var());
        println!("        number of attributes : {}", var.num_attrs());
        for attr in var.get_attrs() {
            println!("            {name}({data_type})", name=attr.name(), data_type=attr.data_type().c_api_name());
        }
    }
}

Run a similar example with the command :

cargo run --example read_file