conspire/io/netcdf/
mod.rs1#[cfg(test)]
2mod test;
3
4pub mod base;
5pub mod ffi;
6pub mod from;
7pub mod variable;
8
9use std::{
10 ffi::{NulError, c_int},
11 sync::{Mutex, MutexGuard},
12};
13
14static NC_LOCK: Mutex<()> = Mutex::new(());
15
16pub(crate) fn nc_lock() -> MutexGuard<'static, ()> {
17 NC_LOCK.lock().unwrap_or_else(|e| e.into_inner())
18}
19
20pub struct NetCDF {
21 ncid: c_int,
22 dimid: c_int,
23 varid: c_int,
24}
25
26impl Drop for NetCDF {
27 fn drop(&mut self) {
28 self.close();
29 }
30}
31
32pub trait DefineVariable {
33 fn define_variable<T: NcType>(
34 &mut self,
35 name: &str,
36 ndims: usize,
37 dim_names: &[&str],
38 ) -> Result<(), NulError>;
39}
40
41pub trait PutVariable {
42 fn put_variable<T: NcType>(&mut self, name: &str, data: &[T]) -> Result<(), NulError>;
43}
44
45pub trait GetVariable {
46 fn get_variable<T: NcType>(&self, name: &str, len: usize) -> Result<Vec<T>, NulError>;
47 fn try_get_variable<T: NcType>(
48 &self,
49 name: &str,
50 len: usize,
51 ) -> Result<Option<Vec<T>>, NulError>;
52}
53
54pub trait NcType: Default + Clone {
55 const XTYPE: c_int;
56 fn put_var(ncid: c_int, varid: c_int, data: *const Self) -> c_int;
57 fn get_var(ncid: c_int, varid: c_int, data: *mut Self) -> c_int;
58}