1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
//! Rust bindings for Unidata's [libnetcdf](http://www.unidata.ucar.edu/software/netcdf/)
//!
//! This crate allows one to store and retrieve multi-dimensional arrays from a
//! `netCDF` supported format, which can be a `netCDF` file, a subset of `hdf5` files,
//! or from a DAP url.
//!
//!
//! `netCDF` files are self-contained, they contain metadata about the data contained in them.
//! See the [`CF Conventions`](http://cfconventions.org/) for conventions used for climate and
//! forecast models.
//!
//! To explore the documentation, see the [`Functions`](#functions) section, in particular
//! [`open()`](open), [`create()`](create), and [`append()`](append).
//!
//! For more information see:
//! * [The official introduction to `netCDF`](https://docs.unidata.ucar.edu/nug/current/netcdf_introduction.html)
//! * [The `NetCDF-c` repository](https://github.com/Unidata/netcdf-c)
//!
//! # Installing netcdf-c
//!
//! This crate depends on [Unidata NetCDF-c](https://github.com/Unidata/netcdf-c) and dependencies
//! of this library (such as hdf5).
//! An alternative to the system libraries is to use the bundled sources of netcdf by using the `static` feature of this crate. This will require build utilities such as `cmake`, `c++` compiler and more.
//!
//!
//! # Examples
//!
//! How to read a variable from a file:
//!
//! ```no_run
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Open the file `simple_xy.nc`:
//! let file = netcdf::open("simple_xy.nc")?;
//!
//! // Get the variable in this file with the name "data"
//! let var = &file.variable("data").expect("Could not find variable 'data'");
//!
//! // Read a single datapoint from a 1D variable as a numeric type
//! let data_i32 = var.get_value::<i32, _>(4)?;
//! let data_f32 : f32 = var.get_value(5)?;
//!
//! // If your variable is multi-dimensional you need to use a
//! // type that supports `Selection`, such as a tuple or array
//! let data_i32 = var.get_value::<i32, _>([40, 0, 0])?;
//! let data_i32 = var.get_value::<i32, _>((40, 0, 0))?;
//!
//! // You can use `values_arr()` to get all the data from the variable.
//! // This requires the `ndarray` feature
//! // Passing `..` will give you the entire slice
//! # #[cfg(feature = "ndarray")]
//! let data = var.get::<i32, _>(..)?;
//!
//! // A subset can also be selected, the following will extract the slice at
//! // `(40, 0, 0)` and get a dataset of size `100, 100` from this
//! # #[cfg(feature = "ndarray")]
//! let data = var.get::<i32, _>(([40, 0 ,0], [1, 100, 100]))?;
//! # #[cfg(feature = "ndarray")]
//! let data = var.get::<i32, _>((40, ..100, ..100))?;
//!
//! // You can read into an ndarray to reuse an allocation
//! # #[cfg(feature = "ndarray")]
//! let mut data = ndarray::Array::<f32, _>::zeros((100, 100));
//! # #[cfg(feature = "ndarray")]
//! var.get_into(data.view_mut(), (0, .., ..))?;
//! # Ok(()) }
//! ```
//!
//! How to create a new file and write to it:
//!
//! ```no_run
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Create a new file with default settings
//! let mut file = netcdf::create("crabs.nc")?;
//!
//! // We must create a dimension which corresponds to our data
//! file.add_dimension("ncrabs", 10)?;
//! // These dimensions can also be unlimited and will be resized when writing
//! file.add_unlimited_dimension("time")?;
//!
//! // A variable can now be declared, and must be created from the dimension names.
//! let mut var = file.add_variable::<i32>(
//! "crab_coolness_level",
//! &["time", "ncrabs"],
//! )?;
//! // Metadata can be added to the variable, but will not be used when
//! // writing or reading data
//! var.put_attribute("units", "Kelvin")?;
//! var.put_attribute("add_offset", 273.15_f32)?;
//!
//! // Data can then be created and added to the variable
//! let data : Vec<i32> = vec![42; 10];
//! var.put_values(&data, (0, ..))?;
//!
//! // Values can be added along the unlimited dimension, which
//! // resizes along the `time` axis
//! var.put_values(&data, (11, ..))?;
//!
//! // Using the ndarray feature you can also use
//! # #[cfg(feature = "ndarray")]
//! let values = ndarray::Array::from_shape_fn((5, 10), |(j, i)| (j * 10 + i) as f32);
//! # #[cfg(feature = "ndarray")]
//! var.put(values.view(), (11.., ..))?;
//! # Ok(()) }
//! ```
//!
//! How to derive `NcTypeDescriptor` for a custom type (requires `derive` feature flag).
//! See [NcTypeDescriptor] for additional examples.
//!
//! ```no_run
//! # #[cfg(not(feature = "derive"))]
//! # fn main() { /* This test does nothing without derive feature flag */ }
//! # #[cfg(feature = "derive")]
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! #[repr(C)]
//! #[derive(netcdf::NcType)]
//! struct Foo {
//! bar: f64,
//! baz: i64,
//! }
//! let mut file = netcdf::create("custom.nc")?;
//! file.add_type::<Foo>()?;
//! let mut var = file.add_variable::<Foo>("variable", &[])?;
//! var.put_value(Foo { bar: 1.0, baz: 2 }, ())?;
//! # Ok(()) }
//!
use nc_type;
pub
pub
pub
pub
pub
pub
pub
pub
pub
pub use ;
pub use ;
pub use ;
pub use ;
pub use FileMem;
pub use RawFile;
pub use ;
pub use ;
pub use NcType;
pub use NcTypeDescriptor;
pub use ;
/// Open a netcdf file in create mode
///
/// Will create a `netCDF4` file and overwrite existing file
/// Open a `netCDF` file in create mode with the given options
/// Open a `netCDF` file in create and parallel mode with the given options
/// Open a `netCDF` file in append mode
/// Open a `netCDF` file in append mode with the given options
/// Open a `netCDF` file in read mode
/// Open in parallel mode
/// Open a `netCDF` file in read mode with the given options
/// Open a `netCDF` file from a buffer
pub