Replace netcdf-fortran with a FORCES-owned netcdf-c wrapper
This merge request removes the netcdf-fortran dependency from FORCES and replaces it with a FORCES-owned wrapper built directly on top of netcdf-c.
The new wrapper is implemented in mo_netcdf_wrapper and provides the NetCDF-4 subset currently needed by FORCES. Existing higher-level FORCES interfaces such as mo_netcdf, mo_ncread, and mo_ncwrite now use that wrapper instead of importing netcdf-fortran.
Motivation
The main motivation for this change is to avoid recurring problems caused by netcdf-fortran, in particular:
- fragile compiler-dependent behavior in the Fortran bindings
- packaging and compatibility issues around
netcdf-fortran - the problematic
FourByteInthandling innetcdf-fortran, which can create unnecessary flat copies for largeinteger(i4)arrays - dimension sizes limited by default integers
By switching to a thin FORCES-owned wrapper around netcdf-c, we keep control over the supported API surface, numeric kinds, and data-path behavior.
Main Changes
- Added
mo_netcdf_wrapperas a strict-kind NetCDF wrapper on top ofnetcdf-c - Added a small C companion layer for stable access to selected
netcdf-cfunctionality - Refactored
mo_netcdf,mo_ncread, andmo_ncwriteto use the new wrapper instead ofnetcdf-fortran - Kept the existing FORCES OOP NetCDF API in
mo_netcdfintact for current callers - Preserved FORCES NetCDF semantics at the wrapper boundary:
- Fortran-style 1-based slicing indices
- current FORCES dimension ordering
- strict use of
mo_kind/iso_c_bindingkinds inside the wrapper
- Kept the direct-buffer
integer(i4)I/O path so contiguousi4reads and writes do not go through the problematic flat-copy behavior - Added wrapper support for small but useful
nf90-style file and metadata routines such as:-
redef,abort -
inq_path,inq_format - attribute copy/delete
- group rename
- variable-property inquiry and fill handling
-
- Added a dedicated
mo_netcdf_wrapperpfUnit test module - Added documentation of the remaining interface gaps compared to
netcdf-fortran
Compatibility
- No intended breaking changes for existing FORCES users of
mo_netcdf - Production code under
src/no longer importsnetcdf - The wrapper is intentionally a FORCES-owned NetCDF-4 subset, not a full replacement for the entire
netcdf-fortransurface - Parallel NetCDF I/O via MPI is still out of scope
- Concurrent OpenMP threads calling NetCDF routines directly are still not supported by this change
Validation
The following areas were validated:
- build with NetCDF C only
- no
use netcdfremaining in production sources - existing NetCDF-related pfUnit suites
- dedicated wrapper regressions for:
-
inq_path/inq_format -
redef/enddef/abort - attribute copy/delete
- group rename
- variable-property inquiry
- fill-value define/inquire
-
Notes
- This merge request does not try to expose the full
netcdf-fortranAPI. - The wrapper preserves familiar
nf90-style behavior where useful, but it is an independent FORCES implementation built onnetcdf-c.
Edited by Sebastian Müller