Dimension

Struct Dimension 

Source
pub struct Dimension { /* private fields */ }
Expand description

NetCDF-3 dimension

Dimension instances are managed by the struct DataSet.

DataSets allow to create, get, remove and rename Dimensions.

§Examples

§Create and get fixed-size and unlimited-size dimensions

use std::rc::Rc;
use netcdf3::{DataSet, Dimension, DimensionType};

const DIM_NAME_1: &str = "dim_1";
const DIM_SIZE_1: usize = 10;
const DIM_NAME_2: &str = "dim_2";
const DIM_SIZE_2: usize = 20;

// First create a data set
let mut data_set = DataSet::new();

// Add one *fixed-size* dimensions and set the *unlimited-size* dimension
data_set.set_unlimited_dim(DIM_NAME_1, DIM_SIZE_1).unwrap();
data_set.add_fixed_dim(DIM_NAME_2, DIM_SIZE_2).unwrap();

// Read values throught the data set
assert_eq!(2,                                   data_set.num_dims());
assert_eq!(true,                                data_set.has_unlimited_dim());
assert_eq!(true,                                data_set.has_dim(DIM_NAME_1));
assert_eq!(Some(DIM_SIZE_1),                    data_set.dim_size(DIM_NAME_1));
assert_eq!(Some(DimensionType::UnlimitedSize),  data_set.dim_type(DIM_NAME_1));
assert_eq!(true,                                data_set.has_dim(DIM_NAME_2));
assert_eq!(Some(DIM_SIZE_2),                    data_set.dim_size(DIM_NAME_2));
assert_eq!(Some(DimensionType::FixedSize),      data_set.dim_type(DIM_NAME_2));

// Or through references of the dimensions
let dim_1: Rc<Dimension> = data_set.get_dim(DIM_NAME_1).unwrap();
assert_eq!(DIM_NAME_1,                          dim_1.name());
assert_eq!(DIM_SIZE_1,                          dim_1.size());
assert_eq!(true,                                dim_1.is_unlimited());
assert_eq!(false,                               dim_1.is_fixed());
assert_eq!(DimensionType::UnlimitedSize,        dim_1.dim_type());

let dim_2: Rc<Dimension> = data_set.get_dim(DIM_NAME_2).unwrap();
assert_eq!(DIM_NAME_2,                          dim_2.name());
assert_eq!(DIM_SIZE_2,                          dim_2.size());
assert_eq!(false,                               dim_2.is_unlimited());
assert_eq!(true,                                dim_2.is_fixed());
assert_eq!(DimensionType::FixedSize,            dim_2.dim_type());

§Rename a dimension

use netcdf3::{DataSet, DimensionType};

const DIM_NAME_1: &str = "dim_1";
const DIM_NAME_2: &str = "dim_2";
const DIM_SIZE: usize = 10;

// First create a data set
let mut data_set = DataSet::new();

// Add a *fixed-size* dimension
data_set.add_fixed_dim(DIM_NAME_1, DIM_SIZE).unwrap();

assert_eq!(1,                                   data_set.num_dims());
assert_eq!(false,                               data_set.has_unlimited_dim());
assert_eq!(true,                                data_set.has_dim(DIM_NAME_1));
assert_eq!(Some(DIM_SIZE),                      data_set.dim_size(DIM_NAME_1));
assert_eq!(Some(DimensionType::FixedSize),      data_set.dim_type(DIM_NAME_1));
assert_eq!(false,                               data_set.has_dim(DIM_NAME_2));
assert_eq!(None,                                data_set.dim_size(DIM_NAME_2));
assert_eq!(None,                                data_set.dim_type(DIM_NAME_2));

// Rename the *fixed-size* dimension
data_set.rename_dim(DIM_NAME_1, DIM_NAME_2).unwrap();

assert_eq!(1,                                   data_set.num_dims());
assert_eq!(false,                               data_set.has_unlimited_dim());
assert_eq!(false,                               data_set.has_dim(DIM_NAME_1));
assert_eq!(None,                                data_set.dim_size(DIM_NAME_1));
assert_eq!(None,                                data_set.dim_type(DIM_NAME_1));
assert_eq!(true,                                data_set.has_dim(DIM_NAME_2));
assert_eq!(Some(DIM_SIZE),                      data_set.dim_size(DIM_NAME_2));
assert_eq!(Some(DimensionType::FixedSize),      data_set.dim_type(DIM_NAME_2));

§Remove a dimension

use std::rc::Rc;
use netcdf3::{DataSet, Dimension, DimensionType};

const DIM_NAME: &str = "dim_1";
const DIM_SIZE: usize = 10;

// First create a data set
let mut data_set = DataSet::new();

// Set the *unlimited-size* dimension
data_set.set_unlimited_dim(DIM_NAME, DIM_SIZE).unwrap();

assert_eq!(1,                                   data_set.num_dims());
assert_eq!(true,                                data_set.has_unlimited_dim());
assert_eq!(true,                                data_set.has_dim(DIM_NAME));
assert_eq!(Some(DIM_SIZE),                      data_set.dim_size(DIM_NAME));
assert_eq!(Some(DimensionType::UnlimitedSize),  data_set.dim_type(DIM_NAME));

// Remove the *unlimited-size* dimension
let _removed_dim: Rc<Dimension> = data_set.remove_dim(DIM_NAME).unwrap();

assert_eq!(0,                                   data_set.num_dims());
assert_eq!(false,                               data_set.has_unlimited_dim());
assert_eq!(false,                               data_set.has_dim(DIM_NAME));
assert_eq!(None,                                data_set.dim_size(DIM_NAME));
assert_eq!(None,                                data_set.dim_type(DIM_NAME));

Implementations§

Source§

impl Dimension

Source

pub fn name(&self) -> String

Returns the name of the NetCDF-3 dimension.

Source

pub fn size(&self) -> usize

Returns the size of the NetCDF-3 dimension.

Source

pub fn dim_type(&self) -> DimensionType

Returns the dimension type (fixed size ou unlimited size) of the NetCDF-3 dimension.

Source

pub fn is_unlimited(&self) -> bool

Returns true if the dimension is a unlimited size dimension, otherwise return false.

Source

pub fn is_fixed(&self) -> bool

Returns true if the dimension is a fixed size dimension, otherwise return false.

Trait Implementations§

Source§

impl Clone for Dimension

Source§

fn clone(&self) -> Dimension

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Dimension

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Dimension

Source§

fn eq(&self, other: &Dimension) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Dimension

Source§

impl StructuralPartialEq for Dimension

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.