|
NEP 4.3.0
NetCDF Expansion Pack
|
Author: Edward Hartnett, Intelligent Data Design, Inc.
Starting with v4.3.0, use nep_nxcdf supplies explicit backend initialization, mode/type constants and binary16/bfloat16 bit-buffer I/O. This module is separate from NetCDF-Fortran's netcdf module and from the retired NEP compression module nep; compression users still use nep_compress from nep-compress.
Enable both NEP_ENABLE_NXCDF=ON and NEP_ENABLE_FORTRAN=ON. This combination requires NetCDF-Fortran >=4.6.2, a compatible netcdf.mod and Fortran compiler, in addition to nxCDF's HDF5 >=2.1.1 and unmodified NetCDF-C >=4.10.1. Released 4.10.1 (10 slots) and the pinned development revision (64 slots) are supported. nf90_nxcdf remains a compile-time parameter; CMake selects its encoding from the detected C header scheme and the C bridge checks equality with NC_NXCDF. Build NetCDF-Fortran against the same C/HDF5 stack. Rebuild NEP, nep_nxcdf.mod and applications when switching schemes; compiled modules and binaries must not be mixed across UDF encodings. The selected compiler's default integer kind must match c_int. Missing or incompatible NetCDF-Fortran is a configure error for this combination, not a silently skipped binding. Reader-only builds retain their existing optional NetCDF-Fortran discovery behavior.
For custom installations, include both C and Fortran pkg-config directories in PKG_CONFIG_PATH, and select their common HDF5/netcdf-c stack:
The installed artifacts are ${libdir}/libnepnxcdff.so and ${includedir}/nep/nep_nxcdf.mod. Fortran .mod files are compiler-specific; use a compiler compatible with the one that built both modules. Neither new artifact is installed when either option is OFF.
A downstream CMake program needs only the installed NEP prefix, its dependency pkg-config paths, and the exported target:
For manual linking, using NEP_PREFIX for the installation prefix and lib for its configured library directory:
Keep libncnxcdf/libnep and their dependencies on the runtime loader path. No external HDF5 filter plugin is needed for this example or the binding tests.
All procedures are integer functions returning NetCDF status codes. nf90_nxcdf_initialize() registers nxCDF and returns nf90_noerr on success or nf90_einternal on registration failure. Call it before standard nf90_create/nf90_open with the nf90_nxcdf flag. There is no finalize wrapper: the process-wide dispatch registration must remain valid for open files.
The four I/O generics are:
Array rank must match the file variable rank; scalar specifics require scalar variables. With no selection arguments, the array shape must equal the entire variable's current dimension lengths. Use explicit selection to append unlimited dimensions. A partial selection uses the leading count rectangle of memory; noncontiguous actual arguments are supported through owned packed temporaries. Strides apply to the file, not to the memory rectangle. Unselected get elements are preserved. Zero counts succeed after ID/type/selection validation without accessing a buffer. Vectors on scalar calls must be empty; omitted vectors read or write the whole scalar, and explicit empty vectors allow the scalar var1 path. Start-only array calls with unit memory extents use var1; other contiguous selections use vara, strided selections use vars, and whole-variable calls use var. These implementation choices do not change Fortran indexing.
The matching half variable type uses raw-bit I/O. NC_FLOAT/NC_DOUBLE variables use the corresponding C small-float wrapper's numeric conversion; other variable types return nf90_ebadtype (nf90_echar for character data). Rounding is NEP round-to-nearest-even, with no new Fortran conversion engine. To numerically convert a Fortran real32/real64 array to a half variable, use standard nf90_put_var; standard nf90_get_var reads a half variable into real32/real64.
Malformed wrapper shapes/vectors and size-product overflow return nf90_einval; allocation failure returns nf90_enomem. ID/type/bounds failures retain NetCDF errors. A range-warning read (nf90_erange) still copies completed results back; a structural/I/O failure does not scatter a temporary get buffer. Writes retain C's completed-write range semantics and are not rolled back on a range warning.
| Fortran constant | Value | Meaning |
|---|---|---|
| nf90_nxcdf | Build-selected NC_UDF9 encoding | UDF slot 9 in either supported scheme; checked against the selected C headers |
| nf90_netcdf4_model | 67108864 | NetCDF-4 enhanced-model compatibility flag |
| nf90_float16 / nf90_bfloat16 | 17 / 18 | IEEE binary16 / bfloat16 |
| nf90_float8_e4m3 / nf90_float8_e5m2 | 19 / 20 | FP8 |
| nf90_float6_e2m3 / nf90_float6_e3m2 | 21 / 22 | FP6 |
| nf90_float4_e2m1 | 23 | FP4 |
| nf90_complex / nf90_doublecomplex | 24 / 25 | Complex atomic types |
| nf90_bitfield8 / nf90_bitfield16 / nf90_bitfield32 / nf90_bitfield64 | 26 / 27 / 28 / 29 | Bitfield atomic types |
| nf90_std_ref | 30 | Unified HDF5 reference type; constant only |
Use ior(nf90_nxcdf,nf90_netcdf4_model) or ior(nf90_nxcdf,nf90_classic_model) for compatibility mode. These modes reject nxCDF-specific types, as in C. The two model flags are mutually exclusive. Build-time C assertions and a mixed-language test check constant parity.
Constants do not imply a supported Fortran value interface for FP8/FP6/FP4, complex, bitfield or reference types. No reference token representation, reference I/O, nc_ref_*/nc_deref_* wrappers or reference cleanup is supplied in v4.3.0. Full compound/vlen/NC_STRING value interfaces and recursive ownership are also beyond this binding's scope; the C implementations are not thereby broken or disabled. Existing NetCDF-Fortran enum/compound metadata and ordinary numeric and NC_CHAR character I/O are covered. NC_CHAR is not NC_STRING. There are no F77, map/varm, or half attribute wrappers.
This example writes raw binary16 encodings of +1 and -1, closes the file, and checks them after reopening. The bfloat16 encodings would instead be 3F80 and BF80, with the bfloat16 type and generic names.
The nxcdf_fortran CTest label runs focused type/mode/I/O tests and a separate installed consumer that uses only the exported target. Normal nxCDF CI builds NetCDF-Fortran against the same pinned C/HDF5 stack and runs these tests; the existing C-only sanitizer full suite is unchanged. Spack uses its existing +fortran+nxcdf variants; conda currently disables nxCDF.