From 1f03d8ad90584c21768c25f4014f6a712d224992 Mon Sep 17 00:00:00 2001 From: Oliver Heidmann <oliver.heidmann@mpimet.mpg.de> Date: Thu, 6 Mar 2025 11:31:09 +0100 Subject: [PATCH] fixed use of wrong HAVE_ for memory streams, improved error handling --- CMakeLists.txt | 13 ++++++++++--- src/process.cc | 12 ++++++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bfad1b261..eb15a8df0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,10 @@ include(CheckIncludeFileCXX) include(CheckIncludeFiles) include(CMakePrintHelpers) +add_library(cdolib) +add_library(operators) +add_executable(cdo) + # --- Language Standards set(CMAKE_C_STANDARD 11) set(CMAKE_CXX_STANDARD 20) @@ -21,9 +25,9 @@ configure_file ( "${PROJECT_SOURCE_DIR}/cmake/cdo_config_features.h.in" "${PROJECT_BINARY_DIR}/src/cdo_config_features.h" ) -# --- Other compile definitions currently required TEMP -list(APPEND cdo_compile_definitions - restrict= +# --- Other compile definitions currently required TEMP +list(APPEND cdo_compile_definitions + restrict= CDI_SIZE_TYPE=size_t #size type for cdi, in cdo its size_t YAC_FOR_CDO HAVE_CONFIG_H=1 @@ -83,6 +87,8 @@ find_package(netCDF 4.0 REQUIRED) if (TARGET netCDF::netcdf) message(DEBUG "Checking for netCDF_HAS_NC4 flag equal 'yes' : flag is: ${netCDF_HAS_NC4}") list(APPEND cdo_compile_definitions HAVE_NETCDF=${netCDF_FOUND}) + list(APPEND cdo_compile_definitions HAVE_LIBNETCDF=${netCDF_FOUND}) + list(APPEND cdo_compile_definitions HAVE_NETCDF4=${netCDF_FOUND}) else() message(WARNING "Netcdf not found, compiling without netcdf") endif () @@ -98,6 +104,7 @@ if(CMOR_ROOT) find_package(CMOR) if(TARGET CMOR::CMOR) list(APPEND cdo_compile_definitions "HAVE_LIBCMOR=1") + target_link_libraries(operators PUBLIC CMOR::CMOR Uuid::uuid json-c Udunits) endif() endif() # ---------------------------------------------------------------------- diff --git a/src/process.cc b/src/process.cc index 03d8742b9..463702301 100644 --- a/src/process.cc +++ b/src/process.cc @@ -14,7 +14,7 @@ #include <pthread.h> #endif -#ifdef HAVE_LIBNETCDF +#ifdef HAVE_NETCDF #include <netcdf.h> #include <netcdf_mem.h> #endif @@ -306,7 +306,7 @@ Process::create_output() { int ncid = -1; -#ifdef HAVE_LIBNETCDF +#ifdef HAVE_NETCDF if (auto retVal = nc_create_mem("test_name", 0, 4096, &ncid)) { printf("Error: %s\n", nc_strerror(retVal)); @@ -316,10 +316,14 @@ Process::create_output() int streamID = streamOpenWriteNCMem(ncid); #else - int streamID = -1; + int streamID = -100103; #endif - if (streamID < 0) { throw std::runtime_error("ERROR: could not open stream from memory"); } + + std::stringstream ss = std::stringstream(); + ss << "ERROR: could not open output stream to memory: errcode: "; + ss << std::to_string(streamID); + if (streamID < 0) { throw std::runtime_error(ss.str());} return { ncid, streamID }; } -- GitLab