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 FourByteInt handling in netcdf-fortran, which can create unnecessary flat copies for large integer(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_wrapper as a strict-kind NetCDF wrapper on top of netcdf-c
  • Added a small C companion layer for stable access to selected netcdf-c functionality
  • Refactored mo_netcdf, mo_ncread, and mo_ncwrite to use the new wrapper instead of netcdf-fortran
  • Kept the existing FORCES OOP NetCDF API in mo_netcdf intact 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_binding kinds inside the wrapper
  • Kept the direct-buffer integer(i4) I/O path so contiguous i4 reads 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_wrapper pfUnit 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 imports netcdf
  • The wrapper is intentionally a FORCES-owned NetCDF-4 subset, not a full replacement for the entire netcdf-fortran surface
  • 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 netcdf remaining 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-fortran API.
  • The wrapper preserves familiar nf90-style behavior where useful, but it is an independent FORCES implementation built on netcdf-c.
Edited by Sebastian Müller

Merge request reports

Loading