From 2476ead686b4e5b2d1d746ca58c4419be68af9e0 Mon Sep 17 00:00:00 2001 From: HugoFara Date: Thu, 15 Oct 2026 23:55:59 -0300 Subject: [PATCH 1/2] feat(build): FOREFIRE_ENABLE_NETCDF to build without NetCDF `#include ` in DataBroker.h pulled NetCDF into 48 of the 58 files in src/. A new FF_NO_NETCDF guard compiles out every NetCDF-backed path (loadFromNCFile, load/saveArrivalTimeNC, saveData, writeNetCDF, the PGD form of createDomain, the NetCDF form of loadData). Each keeps a stub that prints that the build has no NetCDF, so the command table is unchanged. Default is ON: a normal build compiles exactly the same code as before (tests/runff KML and NetCDF outputs match their references). Only adds lines, no existing line changes. Needed for a WebAssembly build (#171), and allows a slim pip wheel without NetCDF/HDF5. --- CMakeLists.txt | 8 +++++++- src/Command.cpp | 29 +++++++++++++++++++++++++++++ src/DataBroker.cpp | 15 +++++++++++++++ src/DataBroker.h | 8 ++++++++ src/FireDomain.cpp | 16 ++++++++++++++++ 5 files changed, 75 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 798f6e38..1b4f3d2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,7 @@ else() endif() option(FOREFIRE_ENABLE_MPI "Enable MPI coupling when MPI is available" ${_ff_default_mpi}) +option(FOREFIRE_ENABLE_NETCDF "Build the NetCDF-backed I/O paths" ON) option(FOREFIRE_NATIVE_ARCH "Optimise for the build machine's CPU (-march=native)" ${_ff_default_native}) option(FOREFIRE_BUILD_PYTHON "Build the pyforefire Python extension module" ${_ff_default_python}) option(FOREFIRE_STATIC_CORE "Build the ForeFire core as a static library" ${_ff_default_static}) @@ -137,7 +138,12 @@ endif() # detection logic below lives in exactly one place. add_library(forefire_netcdf INTERFACE) -if(DEFINED ENV{SRC_MESONH} AND DEFINED ENV{XYZ} AND DEFINED ENV{FF_STATIC}) +if(NOT FOREFIRE_ENABLE_NETCDF) + # FF_NO_NETCDF compiles out every NetCDF-backed path; each entry point keeps + # a stub that reports the missing support (see DataBroker.h). + message(STATUS "NetCDF support disabled (FOREFIRE_ENABLE_NETCDF=OFF)") + target_compile_definitions(forefire_netcdf INTERFACE FF_NO_NETCDF) +elseif(DEFINED ENV{SRC_MESONH} AND DEFINED ENV{XYZ} AND DEFINED ENV{FF_STATIC}) message(STATUS "MESONH and XYZ environment variables are set. FF_STATIC too, static NetCDF.") set(MESONH $ENV{SRC_MESONH}) set(XYZ $ENV{XYZ}) diff --git a/src/Command.cpp b/src/Command.cpp index f6913284..56352509 100644 --- a/src/Command.cpp +++ b/src/Command.cpp @@ -89,6 +89,9 @@ namespace libforefire { size_t n = argCount(arg); +#ifndef FF_NO_NETCDF + // The two-argument form reads the domain extent out of a MesoNH PGD + // file, so it exists only where NetCDF does. if (n == 2) { @@ -176,6 +179,7 @@ namespace libforefire } } +#endif /* FF_NO_NETCDF */ if (n >= 3) { FFPoint SW = getPoint("sw", arg); @@ -2502,6 +2506,18 @@ namespace libforefire return normal; } +#ifdef FF_NO_NETCDF + + // saveData writes a landscape file, which is NetCDF end to end; there is no + // partial behaviour to keep when NetCDF is compiled out. + int Command::saveData(const std::string &arg, size_t &numTabs) + { + std::cout << "saveData: this build has no NetCDF support" << std::endl; + return error; + } + +#else + int Command::saveData(const std::string &arg, size_t &numTabs) { // Check for an argument @@ -2836,6 +2852,8 @@ namespace libforefire } } +#endif /* FF_NO_NETCDF */ + int Command::loadData(const string &arg, size_t &numTabs) { @@ -2865,6 +2883,11 @@ namespace libforefire if (args.size() == 2) { +#ifdef FF_NO_NETCDF + cout << "loadData: reading a domain from " << path + << " needs NetCDF, which this build has no support for" << endl; + return error; +#else simParam->setParameter("NetCDFfile", args[0]); try { @@ -2950,6 +2973,7 @@ namespace libforefire } ExecuteCommand(com); +#endif /* FF_NO_NETCDF */ } if (args.size() == 1) { @@ -3710,6 +3734,10 @@ namespace libforefire void Command::writeNetCDF(const char *filename, const string &varName, const std::vector> &matrix, const vector &latitudes, const vector &longitudes) { +#ifdef FF_NO_NETCDF + std::cerr << "writeNetCDF: this build has no NetCDF support, " + << filename << " not written" << std::endl; +#else try { // Create (or replace) the NetCDF file using NetCDF-4 mode. @@ -3753,6 +3781,7 @@ namespace libforefire { std::cerr << "Error writing NetCDF file: " << e.what() << std::endl; } +#endif /* FF_NO_NETCDF */ } void Command::writeASCII(const char *filename, const std::vector> &matrix, double SWX, double SWY, double NEX, double NEY) { diff --git a/src/DataBroker.cpp b/src/DataBroker.cpp index bf89c961..0413490d 100644 --- a/src/DataBroker.cpp +++ b/src/DataBroker.cpp @@ -1105,6 +1105,19 @@ namespace libforefire } } +#ifdef FF_NO_NETCDF + + void DataBroker::loadFromNCFile(std::string filename) + { + // The empty-filename early return matches the NetCDF path: the command + // layer calls this with no file on every session setup. + if (filename.empty()) return; + cout << "loadFromNCFile: this build has no NetCDF support, ignoring " + << filename << endl; + } + +#else + void DataBroker::loadFromNCFile(std::string filename) { if(filename.empty()) @@ -1682,4 +1695,6 @@ namespace libforefire return data; } +#endif /* FF_NO_NETCDF */ + } diff --git a/src/DataBroker.h b/src/DataBroker.h index b54c0281..2c3ab066 100644 --- a/src/DataBroker.h +++ b/src/DataBroker.h @@ -22,9 +22,15 @@ #include "FFArrays.h" #include "ParallelData.h" #include "SimulationParameters.h" +// FF_NO_NETCDF drops every NetCDF-backed code path. The umbrella header is +// included in exactly this one place, and the `using namespace` below drags it +// into every translation unit that reaches DataBroker.h, so the guard here is +// what makes a NetCDF-free build (Emscripten, slim wheels) possible at all. +#ifndef FF_NO_NETCDF #include using namespace netCDF; using namespace netCDF::exceptions; +#endif using namespace std; @@ -205,6 +211,7 @@ class DataBroker { bool isRelevantData(FFPoint&, FFPoint&); +#ifndef FF_NO_NETCDF /*! \brief loading a NCXYZTDataLayer from an NcFile */ XYZTDataLayer* constructXYZTLayer(NcVar&, FFPoint&, FFPoint&,double , double , int ); /*! \brief loading a FuelDataLayer from an NcFile */ @@ -216,6 +223,7 @@ class DataBroker { /*! \transpose data from fortran netcdf*/ double* readAndTransposeFortranProjectedField(NcVar* , const size_t& ,const size_t& , const size_t& ,const size_t& ,bool , int ); int* readAndTransposeIntFortranProjectedField(NcVar* , const size_t& ,const size_t& , const size_t& ,const size_t&, bool , int ); +#endif public: diff --git a/src/FireDomain.cpp b/src/FireDomain.cpp index a10fde54..c0ae4f2c 100644 --- a/src/FireDomain.cpp +++ b/src/FireDomain.cpp @@ -3460,6 +3460,20 @@ +#ifdef FF_NO_NETCDF + + void FireDomain::loadArrivalTimeNC(string fname){ + cout << "loadArrivalTimeNC: this build has no NetCDF support, ignoring " + << fname << endl; + } + + void FireDomain::saveArrivalTimeNC(){ + cout << "saveArrivalTimeNC: this build has no NetCDF support, " + "nothing written" << endl; + } + +#else + void FireDomain::loadArrivalTimeNC(string fname){ if (getDomainID()!=0) return; @@ -3598,6 +3612,8 @@ } +#endif /* FF_NO_NETCDF */ + void FireDomain::visualizeBurningMatrixAroundNode(FireNode* fn){ if( !striclyWithinDomain(fn) ) return; /* Position of the firenode in the burning matrix */ From 68097af2ac1909e575e564fc9a0428818e75d74b Mon Sep 17 00:00:00 2001 From: Antonio Leblanc Date: Thu, 22 Oct 2026 09:25:38 -0300 Subject: [PATCH 2/2] docs(changelog): FOREFIRE_ENABLE_NETCDF --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e48e8525..36a0d091 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,10 @@ Merged since v2.5.0, not yet released. required `parametersProperties` keys before writing. ([#179]) - A User Guide page on driving a simulation from NumPy arrays, with no landscape file and no GIS. ([#189]) +- `-DFOREFIRE_ENABLE_NETCDF=OFF` builds the engine without NetCDF or HDF5, + the first step towards a WebAssembly build and a slim wheel. Commands that + read or write NetCDF files report that the build has no NetCDF support. + The default stays on. ([#171]) ### Fixed @@ -248,3 +252,4 @@ repository stays easy to return to. [#192]: https://github.com/forefireAPI/forefire/pull/192 [#203]: https://github.com/forefireAPI/forefire/pull/203 [#205]: https://github.com/forefireAPI/forefire/issues/205 +[#171]: https://github.com/forefireAPI/forefire/issues/171