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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
//! OxiGDAL NetCDF Driver - Pure Rust NetCDF-4 (HDF5) with Optional NetCDF-3
//!
//! This crate provides NetCDF file format support for OxiGDAL, following the
//! COOLJAPAN Pure Rust policy.
//!
//! # Pure Rust Policy Compliance
//!
//! Real NetCDF-4 files (which are HDF5 files carrying the NetCDF-4 conventions)
//! are read and written with the Pure-Rust [`oxinetcdf`] crate atop
//! [`oxih5`](https://crates.io/crates/oxih5). There is **no** `libnetcdf`, no
//! `libhdf5`, and no FFI — the default build is 100% Pure Rust.
//!
//! - Reading honours the NetCDF-4 conventions: dimension scales, coordinate
//! variables, `DIMENSION_LIST` axis linkage, and user attributes (`units`,
//! `_FillValue`, `scale_factor`, `add_offset`, …).
//! - Writing produces real HDF5/NetCDF-4 files via the Pure-Rust backend.
//! - Optional NetCDF-3 classic support is available behind the `netcdf3`
//! feature (the `netcdf3` crate, also Pure Rust).
//!
//! ## Feature Flags
//!
//! - `std` (default): standard-library support.
//! - `netcdf3`: Pure Rust NetCDF-3 (classic / 64-bit offset) support via the
//! `netcdf3` crate. NetCDF-4 support is always available and needs no feature.
//! - `cf_conventions`: CF (Climate and Forecast) conventions support
//! - `async`: Async I/O support
//!
//! # NetCDF Format Support
//!
//! ## NetCDF-3 (Pure Rust, Default)
//!
//! Fully supported data types:
//! - `i8`, `i16`, `i32` - Signed integers
//! - `f32`, `f64` - Floating point numbers
//! - `char` - Character data
//!
//! Features:
//! - Fixed and unlimited dimensions
//! - Multi-dimensional arrays
//! - Variable and global attributes
//! - Coordinate variables
//!
//! ## NetCDF-4 (Pure Rust, always available)
//!
//! Real NetCDF-4 / HDF5 files are read and written via the Pure-Rust
//! [`oxinetcdf`] backend. Additional data types over NetCDF-3:
//! - `u8`, `u16`, `u32`, `u64` - Unsigned integers
//! - `i64`, `u64` - 64-bit integers
//! - `string` - Variable-length strings
//!
//! Additional features:
//! - HDF5-based (DEFLATE) compression
//! - Groups and coordinate variables
//! - Multiple unlimited dimensions
//!
//! # Example - Reading NetCDF-3 File (Pure Rust)
//!
//! ```ignore
//! use oxigdal_netcdf::NetCdfReader;
//!
//! // Open a NetCDF-3 file
//! let reader = NetCdfReader::open("data.nc")?;
//!
//! // Get metadata
//! println!("{}", reader.metadata().summary());
//!
//! // List dimensions
//! for dim in reader.dimensions().iter() {
//! println!("Dimension: {} (size: {})", dim.name(), dim.len());
//! }
//!
//! // List variables
//! for var in reader.variables().iter() {
//! println!("Variable: {} (type: {})", var.name(), var.data_type().name());
//! }
//!
//! // Read variable data
//! let temperature = reader.read_f32("temperature")?;
//! println!("Temperature data: {:?}", temperature);
//! ```
//!
//! # Example - Writing NetCDF-3 File (Pure Rust)
//!
//! ```ignore
//! use oxigdal_netcdf::{NetCdfWriter, NetCdfVersion};
//! use oxigdal_netcdf::dimension::Dimension;
//! use oxigdal_netcdf::variable::{Variable, DataType};
//! use oxigdal_netcdf::attribute::{Attribute, AttributeValue};
//!
//! // Create a new NetCDF-3 file
//! let mut writer = NetCdfWriter::create("output.nc", NetCdfVersion::Classic)?;
//!
//! // Add dimensions
//! writer.add_dimension(Dimension::new_unlimited("time", 0)?)?;
//! writer.add_dimension(Dimension::new("lat", 180)?)?;
//! writer.add_dimension(Dimension::new("lon", 360)?)?;
//!
//! // Add coordinate variables
//! writer.add_variable(Variable::new_coordinate("time", DataType::F64)?)?;
//! writer.add_variable(Variable::new_coordinate("lat", DataType::F32)?)?;
//! writer.add_variable(Variable::new_coordinate("lon", DataType::F32)?)?;
//!
//! // Add data variable
//! let temp_var = Variable::new(
//! "temperature",
//! DataType::F32,
//! vec!["time".to_string(), "lat".to_string(), "lon".to_string()],
//! )?;
//! writer.add_variable(temp_var)?;
//!
//! // Add variable attributes
//! writer.add_variable_attribute(
//! "temperature",
//! Attribute::new("units", AttributeValue::text("celsius"))?,
//! )?;
//! writer.add_variable_attribute(
//! "temperature",
//! Attribute::new("long_name", AttributeValue::text("Air Temperature"))?,
//! )?;
//!
//! // Add global attributes
//! writer.add_global_attribute(
//! Attribute::new("Conventions", AttributeValue::text("CF-1.8"))?,
//! )?;
//! writer.add_global_attribute(
//! Attribute::new("title", AttributeValue::text("Temperature Data"))?,
//! )?;
//!
//! // End define mode
//! writer.end_define_mode()?;
//!
//! // Write data
//! let time_data = vec![0.0, 1.0, 2.0];
//! writer.write_f64("time", &time_data)?;
//!
//! let lat_data: Vec<f32> = (0..180).map(|i| -90.0 + i as f32).collect();
//! writer.write_f32("lat", &lat_data)?;
//!
//! let lon_data: Vec<f32> = (0..360).map(|i| -180.0 + i as f32).collect();
//! writer.write_f32("lon", &lon_data)?;
//!
//! // Write temperature data
//! let temp_data = vec![20.0f32; 3 * 180 * 360];
//! writer.write_f32("temperature", &temp_data)?;
//!
//! // Close file
//! writer.close()?;
//! ```
//!
//! # CF Conventions Support
//!
//! The driver recognizes and parses CF (Climate and Forecast) conventions metadata:
//!
//! ```ignore
//! use oxigdal_netcdf::NetCdfReader;
//!
//! let reader = NetCdfReader::open("cf_data.nc")?;
//!
//! if let Some(cf) = reader.cf_metadata() {
//! if cf.is_cf_compliant() {
//! println!("CF Conventions: {}", cf.conventions.as_deref().unwrap_or(""));
//! println!("Title: {}", cf.title.as_deref().unwrap_or(""));
//! println!("Institution: {}", cf.institution.as_deref().unwrap_or(""));
//! }
//! }
//! ```
//!
//! # Pure Rust Notes
//!
//! - NetCDF-4 reading/writing is Pure Rust via [`oxinetcdf`] atop `oxih5`
//! (DEFLATE compression through `oxiarc-deflate`); no C libraries are used.
//! - The Pure-Rust NetCDF-4 writer supports data variables, dimensions, and
//! string attributes. Constructs it cannot yet represent (e.g. explicit
//! coordinate-variable values or numeric attributes) return a typed error
//! rather than producing an incomplete file.
//! - NetCDF-3 classic support is optional (`netcdf3` feature) and allows only
//! one unlimited dimension per the classic model.
//!
//! # Performance Considerations
//!
//! - For large datasets, consider using chunked reading/writing
//! - CF metadata parsing is done on-demand
//!
//! # References
//!
//! - [NetCDF User Guide](https://www.unidata.ucar.edu/software/netcdf/docs/)
//! - [CF Conventions](http://cfconventions.org/)
//! - [oxinetcdf crate](https://crates.io/crates/oxinetcdf)
// Pedantic disabled to reduce noise - default clippy::all is sufficient
// #![warn(clippy::pedantic)]
// Allow unexpected cfg for optional netcdf4 feature
// Allow unused imports during development
// Allow missing docs during API development
// Allow dead code for future netcdf3/netcdf4 integration
// Allow manual div_ceil for dimension calculations
// Allow expect() for internal netcdf state invariants
// Allow collapsible match for netcdf error handling
// Allow struct field pub visibility in internal modules
extern crate std;
pub
// Re-export commonly used types
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use NetCdfReader;
pub use ;
pub use NetCdfWriter;
/// Crate version
pub const VERSION: &str = env!;
/// Crate name
pub const NAME: &str = env!;
/// Pure Rust compliance status
///
/// Returns true if running in Pure Rust mode (no C dependencies).
/// Returns false if netcdf4 feature is enabled (requires C libraries).
pub const
/// Check if NetCDF-3 support is available.
pub const
/// Check if NetCDF-4 support is available.
///
/// Always `true`: NetCDF-4 (HDF5) reading/writing is provided by the Pure-Rust
/// [`oxinetcdf`] backend and needs no feature flag.
pub const
/// Get supported format versions.
///
/// NetCDF-4 variants are always supported (Pure-Rust `oxinetcdf` backend);
/// NetCDF-3 variants require the optional `netcdf3` feature.
/// Get driver information.