Skip to content

Add optional netcdf/hdf5-free, library-only build - #2

Open
rljacob wants to merge 1 commit into
masterfrom
rljacob/make-netcdf-optional
Open

Add optional netcdf/hdf5-free, library-only build#2
rljacob wants to merge 1 commit into
masterfrom
rljacob/make-netcdf-optional

Conversation

@rljacob

@rljacob rljacob commented Aug 17, 2026

Copy link
Copy Markdown
Member

Adds a --disable-netcdf configure option that builds libTempestRemap with no NetCDF or HDF5 dependency. The default build is unchanged — this is purely additive.

Why disabling NetCDF also drops HDF5

configure.ac never mentions HDF5, but config/netcdf.m4 does AC_REQUIRE([ACX_HDF5]) and folds $HDF5_LIBS into NETCDF_LIBS — netCDF-4 files are HDF5 containers, so the probe for nc_inq_libvers links HDF5 too. Skipping ACX_NETCDF therefore drops both dependencies at once.

Approach

The numerical core is already netcdf-independent in its logic: mesh generation into in-memory Mesh objects, overlap-mesh construction, FV/SE weight generation, and the sparse-matrix apply/analysis in OfflineMap. NetCDF is confined to the vendored netcdf-cxx-4.2 files, the file-I/O methods of GridElements/OfflineMap/NetCDFUtilities, the write tails of the generators, and NcFile::FileFormat leaking into public signatures. Those are now guarded by TEMPEST_NETCDF.

Scope: library-only, in-memory remapping

Because every file format here is NetCDF-based (Exodus/SCRIP/UGRID meshes, SCRIP map files), --disable-netcdf implies a library-only build: no command-line tools are produced, and the library does in-memory remapping only. Downstream users (e.g. MOAB) feed and extract data through the Mesh/OfflineMap API — the ...WithMeshes variants are the netcdf-free entry points, while the file-path variants are guarded out.

Where a caller passes an output filename to such a build, the guarded path raises an exception naming the option rather than silently ignoring the request.

Supporting changes

  • Defines.h now includes the generated TempestConfig.h. It was previously never included anywhere, so an AC_DEFINE'd macro would have been invisible. Routing it through Defines.h also makes TEMPEST_NETCDF self-carrying for consumers of the installed headers, so they cannot see a different API surface than the library was built with.
  • OVERLAPMESH_USE_UNSORTED_MAP is now an #ifndef fallback, since configure also defines it and TempestConfig.h is now included.
  • Two pre-existing latent bugs fixed: LinearRemapFV.cpp used std::cout and OfflineMap.cpp used INT_MAX/INT_MIN, both relying on netcdfcpp.h to supply <iostream>/<climits> transitively. Added direct includes.
  • GenerateRectilinearMeshFromFile.cpp moves to the netcdf-only source list — it derives the mesh from a NetCDF input file, so unlike the other generators it has no in-memory-only behavior.

Verification

Both configurations were built and run:

  • Default build (--with-netcdf=/usr --with-hdf5=/usr): compiles clean, all 26 tools built, full CS→RLL overlap→map pipeline produces a working 218 KB map.nc.
  • Library-only build (--disable-netcdf): compiles clean, no executables, and nm reports zero netcdf/hdf5 undefined symbols in the archive.
  • Functional test linking only the netcdf-free library (ldd confirms neither is pulled in): generates CS + RLL meshes, builds the overlap mesh, and produces FV→FV weights (8584 nnz, 200×384) identical to the default build's, with 0 consistency and 0 conservation violations; applying the operator to a constant field returns exactly 1.0.
  • make dist from a --disable-netcdf tree still ships all conditional sources and all 23 test scripts, so the tarball stays configure-independent.

Note for reviewers

The Makefile.gmake/mk/ legacy HPC build is intentionally untouched; this option is autotools-only. One judgment call worth a look: the file-path API variants (GenerateOfflineMap, GenerateOverlapMesh, GenerateGLLMetaData, GenerateOverlapMesh_v1) are guarded out since they read from disk at entry. If a downstream consumer depends on one of those signatures, that's the piece to revisit.

🤖 Generated with Claude Code

Add a --disable-netcdf configure option that builds libTempestRemap with
no NetCDF or HDF5 dependency. The default build is unchanged.

NetCDF is required by default, and HDF5 comes along with it transitively:
config/netcdf.m4 does AC_REQUIRE([ACX_HDF5]) and folds $HDF5_LIBS into
NETCDF_LIBS, since netCDF-4 files are HDF5 containers. Skipping ACX_NETCDF
therefore drops both dependencies at once.

The numerical core is already netcdf-independent in its logic: mesh
generation into in-memory Mesh objects, overlap-mesh construction, FV/SE
weight generation, and the sparse-matrix apply/analysis in OfflineMap.
NetCDF is confined to the vendored netcdf-cxx-4.2 files, the file-I/O
methods of GridElements/OfflineMap/NetCDFUtilities, the write tails of the
generators, and NcFile::FileFormat leaking into public signatures. Those
are now guarded by TEMPEST_NETCDF.

Because every file format here is NetCDF-based (Exodus/SCRIP/UGRID meshes,
SCRIP map files), --disable-netcdf implies a library-only build: no
command-line tools are produced and the library does in-memory remapping
only. Downstream users feed and extract data through the Mesh/OfflineMap
API; the ...WithMeshes API variants are the netcdf-free entry points, while
the file-path variants are guarded out. Where a caller passes an output
filename to such a build, the guarded path raises an exception naming the
option instead of silently ignoring the request.

Supporting changes:

- Defines.h now includes the generated TempestConfig.h. It was previously
  never included anywhere, so an AC_DEFINE'd macro would have been
  invisible; routing it through Defines.h also makes TEMPEST_NETCDF
  self-carrying for consumers of the installed headers, so they cannot see
  a different API surface than the library was built with.
- OVERLAPMESH_USE_UNSORTED_MAP is now an #ifndef fallback in Defines.h,
  since configure also defines it and TempestConfig.h is now included.
- Add missing <iostream> to LinearRemapFV.cpp and <climits>/<iostream> to
  OfflineMap.cpp. Both relied on netcdfcpp.h to supply these transitively.
- GenerateRectilinearMeshFromFile.cpp moves to the netcdf-only source list;
  it derives the mesh from a NetCDF input file, so unlike the other
  generators it has no in-memory-only behavior.

Verified both configurations: the default build compiles clean with all 26
tools and a working remap pipeline; --disable-netcdf compiles clean, builds
no executables, and yields an archive with zero netcdf/hdf5 undefined
symbols. A test program linking only the netcdf-free library (confirmed by
ldd to pull in neither) generates meshes, builds the overlap mesh, and
produces FV-to-FV weights identical to the default build, with no
consistency or conservation violations.

Co-Authored-By: Claude <noreply@anthropic.com>
@rljacob
rljacob requested review from vijaysm and a balanced review from Copilot August 17, 2026 18:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an optional Autotools library-only build without NetCDF/HDF5.

Changes:

  • Adds --disable-netcdf configuration and conditional build targets.
  • Guards NetCDF-dependent APIs and file I/O.
  • Adds direct standard-library includes previously supplied transitively.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
configure.ac Adds the NetCDF build option.
Makefile.am Conditionally builds NetCDF sources and tools.
src/Defines.h Includes generated feature configuration.
src/TempestRemapAPI.h Conditionally exposes NetCDF APIs.
src/GridElements.h Guards mesh file-I/O declarations.
src/GridElements.cpp Guards mesh file-I/O implementations.
src/OfflineMap.h Guards map file-I/O declarations.
src/OfflineMap.cpp Guards map file-I/O implementations.
src/LinearRemapFV.cpp Adds the direct iostream dependency.
src/GenerateCSMesh.cpp Handles unavailable NetCDF output.
src/GenerateGLLMetaData.cpp Guards file-based metadata generation.
src/GenerateICOMesh.cpp Handles unavailable NetCDF output.
src/GenerateLambertConfConicMesh.cpp Handles unavailable NetCDF output.
src/GenerateOfflineMap.cpp Separates in-memory mapping from file I/O.
src/GenerateOverlapMesh.cpp Retains in-memory overlap generation.
src/GenerateOverlapMesh_v1.cpp Guards the file-based legacy API.
src/GenerateRLLMesh.cpp Guards NetCDF input and output.
src/GenerateStereographicMesh.cpp Handles unavailable NetCDF output.
src/GenerateTransectMesh.cpp Handles unavailable NetCDF output.
src/GenerateUTMMesh.cpp Handles unavailable NetCDF output.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/Defines.h
// TEMPEST_NETCDF visible both when building TempestRemap and to downstream
// consumers of the installed headers, so that both see the same API surface.
//
#include "TempestConfig.h"
Comment thread src/TempestRemapAPI.h
bool fgll;
};

#if defined(TEMPEST_NETCDF)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can verify that this is a valid comment and fails during MOAB configure/linkage. I'm fixing MOAB but this should not even be exposed when netcdf is disabled. @rljacob

Comment on lines +900 to +902
_EXCEPTIONT("Cannot write map file: TempestRemap was built without "
"NetCDF support (--disable-netcdf). The offline map is available "
"in the \"mapRemap\" argument.");
@vijaysm

vijaysm commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

This is pretty good. Will test this today and cross-check with the MOAB link.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants