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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
//! OxiGDAL NetCDF Driver - Pure Rust NetCDF-3 with Optional NetCDF-4 Support
//!
//! This crate provides NetCDF file format support for OxiGDAL, following the
//! COOLJAPAN Pure Rust policy.
//!
//! # Pure Rust Policy Compliance
//!
//! **IMPORTANT**: This driver provides the structure and API for Pure Rust NetCDF support,
//! but the actual netcdf3 integration is currently incomplete due to breaking API changes
//! in netcdf3 v0.6.0. The driver demonstrates:
//!
//! - Complete Pure Rust data structures for NetCDF metadata (dimensions, variables, attributes)
//! - CF conventions support
//! - Feature-gated architecture for Pure Rust vs. C-binding implementations
//!
//! **Status**: The reader/writer implementations need to be updated to use the new
//! `Dataset`/`FileReader`/`FileWriter` API from netcdf3 v0.6.0 (breaking change from v0.1.0).
//!
//! For NetCDF-4 (HDF5-based) support, you can enable the `netcdf4` feature,
//! which requires system libraries (libnetcdf, libhdf5) and is **NOT Pure Rust**.
//!
//! ## Feature Flags
//!
//! - `netcdf3` (default): Pure Rust NetCDF-3 support via netcdf3 crate
//! - `netcdf4`: NetCDF-4/HDF5 support via C bindings (requires system libraries)
//! - `cf_conventions`: CF (Climate and Forecast) conventions support
//! - `async`: Async I/O support
//! - `compression`: Compression support (NetCDF-4 only)
//!
//! # 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 (C Bindings, Feature-Gated)
//!
//! Additional data types (requires `netcdf4` feature):
//! - `u8`, `u16`, `u32`, `u64` - Unsigned integers
//! - `i64`, `u64` - 64-bit integers
//! - `string` - Variable-length strings
//!
//! Additional features (requires `netcdf4` feature):
//! - HDF5-based compression
//! - Groups and nested groups
//! - User-defined types
//! - 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 Limitations
//!
//! When using the default Pure Rust mode (NetCDF-3 only):
//!
//! - No NetCDF-4/HDF5 format support
//! - No compression support
//! - No groups or user-defined types
//! - Only one unlimited dimension allowed
//! - Limited to NetCDF-3 data types
//!
//! To use NetCDF-4 features, enable the `netcdf4` feature (requires C dependencies):
//!
//! ```toml
//! [dependencies]
//! oxigdal-netcdf = { version = "0.1", features = ["netcdf4"] }
//! ```
//!
//! **Note**: Enabling `netcdf4` violates the COOLJAPAN Pure Rust policy and requires
//! system libraries (libnetcdf ≥ 4.0, libhdf5 ≥ 1.8).
//!
//! # Performance Considerations
//!
//! - Pure Rust NetCDF-3 reader/writer has comparable performance to C libraries
//! - For large datasets, consider using chunked reading/writing
//! - Unlimited dimensions may have performance implications
//! - CF metadata parsing is done on-demand
//!
//! # References
//!
//! - [NetCDF User Guide](https://www.unidata.ucar.edu/software/netcdf/docs/)
//! - [CF Conventions](http://cfconventions.org/)
//! - [netcdf3 crate](https://crates.io/crates/netcdf3)
// 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.
pub const
/// Get supported format versions.
/// Get driver information.