From 9faa41da2c8d4d82651a22b4437e57c5d6880382 Mon Sep 17 00:00:00 2001 From: webisu Date: Mon, 12 Aug 2024 13:24:37 -0400 Subject: [PATCH 1/7] USE_NETCDF3/4 -> USE_NETCDF --- CMakeLists.txt | 11 ++-------- tests/CMakeLists.txt | 6 ++---- wgrib2/CMakeLists.txt | 2 +- wgrib2/Config.c | 8 ++----- wgrib2/Import_netcdf.c | 2 +- wgrib2/Netcdf.c | 46 ++++++----------------------------------- wgrib2/Netcdf_sup.c | 2 +- wgrib2/config.h.in | 4 +--- wgrib2/init.c | 4 ++-- wgrib2/wgrib2.h | 7 ------- wgrib2/wgrib2_meta.h.in | 4 +--- 11 files changed, 19 insertions(+), 77 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d096f0e..2bf7087d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,9 +11,7 @@ project(wgrib2 VERSION ${pVersion} LANGUAGES Fortran C) # Handle user build options. option(ENABLE_DOCS "Enable generation of doxygen-based documentation." OFF) -option(USE_NETCDF3 "Use NetCDF-3?" off) -option(USE_NETCDF4 "Use NetCDF-4?" off) -option(USE_HDF5 "Use HDF5?" off) +option(USE_NETCDF "Use NetCDF" on) option(USE_REGEX "Use Regex?" on) option(USE_TIGGE "Use tigge?" on) option(USE_MYSQL "Use MySQL?" off) @@ -86,10 +84,6 @@ if(USE_G2CLIB) endif() endif() -if(USE_NETCDF3 AND USE_NETCDF4) - message(FATAL_ERROR "USE_NETCDF3 OR USE_NetCDF4, not both") -endif() - # If user wants to use NCEPLIBS-ip, find it and the sp library. message(STATUS "Checking if the user want to use NCEPLIBS-ip...") if(USE_IPOLATES) @@ -99,9 +93,8 @@ if(USE_IPOLATES) endif() message(STATUS "Checking if the user want to use NetCDF...") -if(USE_NETCDF4) +if(USE_NETCDF) find_package(NetCDF MODULE REQUIRED COMPONENTS C) - list(APPEND definitions_list -DUSE_NETCDF4 -DUSE_HDF5 -DHDF5="hdf5") endif() if(USE_OPENJPEG AND USE_JASPER) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4889a49c..21dedf7d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -111,15 +111,13 @@ copy_test_data(ref_simple_packing.grib2.spread.txt) shell_test(run_wgrib2_tests) shell_test(run_wgrib2_rpn_tests) -if (USE_NETCDF4) +if (USE_NETCDF) shell_test(run_wgrib2_netcdf4_tests) + shell_test(run_wgrib2_netcdf3_tests) copy_test_data(ref_ncdump4.gdas.t12z.pgrb2.1p00.anl.75r.grib2.txt) copy_test_data(ref_tablenc.gdas.t12z.pgrb2.1p00.anl.75r.grib2.txt) copy_test_data(nctab.table) endif() -if (USE_NETCDF3) - shell_test(run_wgrib2_netcdf3_tests) -endif() if (USE_IPOLATES) shell_test(run_ipolates_tests) copy_test_data(ref_new_grid_gdas.t12z.pgrb2.1p00.anl.75r.grib2.txt) diff --git a/wgrib2/CMakeLists.txt b/wgrib2/CMakeLists.txt index a669db23..4a8033d3 100644 --- a/wgrib2/CMakeLists.txt +++ b/wgrib2/CMakeLists.txt @@ -84,7 +84,7 @@ endif() add_executable(wgrib2_exe ${callable_src}) set_target_properties(wgrib2_exe PROPERTIES OUTPUT_NAME wgrib2) -if(USE_NETCDF4) +if(USE_NETCDF) target_link_libraries(obj_lib PUBLIC NetCDF::NetCDF_C) endif() diff --git a/wgrib2/Config.c b/wgrib2/Config.c index 823b050b..76f84fd1 100644 --- a/wgrib2/Config.c +++ b/wgrib2/Config.c @@ -10,7 +10,7 @@ #include "grb2.h" #include "fnlist.h" -#if defined USE_NETCDF3 || defined USE_NETCDF4 +#if defined USE_NETCDF #include #endif @@ -39,17 +39,13 @@ int f_config(ARG0) { inv_out += strlen(inv_out); sprintf(inv_out,"Compiled on %s %s\n\n",__TIME__,__DATE__); -#if defined USE_NETCDF3 || defined USE_NETCDF4 +#if defined USE_NETCDF strcat(inv_out, "Netcdf package: "); strcat(inv_out, nc_inq_libvers()); strcat(inv_out, " is installed\n"); #else strcat(inv_out, "Netcdf package is not installed\n"); #endif -//#if defined USE_NETCDF4 -// strcat(inv_out, "netcdf4: " USE_NETCDF4 "\n"); -// strcat(inv_out, "hdf5: " USE_HDF5 "\n"); -//#endif #ifdef USE_AEC strcat(inv_out, USE_AEC " is installed\n" ); #endif diff --git a/wgrib2/Import_netcdf.c b/wgrib2/Import_netcdf.c index 8961ce02..2648f350 100644 --- a/wgrib2/Import_netcdf.c +++ b/wgrib2/Import_netcdf.c @@ -22,7 +22,7 @@ #include "wgrib2.h" #include "fnlist.h" -#if defined USE_NETCDF3 || defined USE_NETCDF4 +#if defined USE_NETCDF #include diff --git a/wgrib2/Netcdf.c b/wgrib2/Netcdf.c index c590d005..3e710405 100644 --- a/wgrib2/Netcdf.c +++ b/wgrib2/Netcdf.c @@ -1,4 +1,4 @@ -/****************************************************************************************** +/******************************************************************************************FF This file is part of wgrib2 and is distributed under terms of the GNU General Public License For details see, Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, @@ -23,13 +23,10 @@ //#define DEBUG_NC -#if defined USE_NETCDF3 || defined USE_NETCDF4 +#if defined USE_NETCDF #include // change by Sander Hulst 5/2011, for netcdf-4 library compiled without netcdf-4/hdf format -#if defined USE_NETCDF3 -#undef NC_NETCDF4 -#endif /* defined in Netcdf_sup.c */ extern g2nc_4Dlt nc_4Dlt[G2NC_NUM_4DLT]; @@ -255,34 +252,8 @@ int f_netcdf(ARG1) save->dim_latlon=0; save->lev_ind=-1; save->time_ind=-1; - { - const char * vlib; - float nclib_ver; - vlib = nc_inq_libvers(); - sscanf(vlib,"%f",&nclib_ver); + save->nc4 = nc4 ? 1 : 0; -#ifdef DEBUG_NC -fprintf(stderr,"netcdf: library version defined as = %f\n",nclib_ver); -fprintf(stderr,"netcdf: long version = %s\n",vlib); -#endif - save->nc4 = 0; - if(nc4) - { -#ifdef NC_NETCDF4 - if(nclib_ver >= 4.0) save->nc4 = 1; - else - { - fatal_error( -"netcdf: -nc4 option require wgrib2 to be compiled with NetCDF-4/HDF5/zlib libraries,\n was compiled with libnetcdf version %s", - vlib); - } -#else - fatal_error( -"netcdf: -nc4 option require wgrib2 to be compiled with NetCDF-4/HDF5/zlib libraries,\n was compiled with libnetcdf version %s", - vlib); -#endif - } - } if ( nc_table ) { if ( nc_table->grads >= 0) save->grads_compatible = nc_table->grads; @@ -758,14 +729,11 @@ fprintf(stderr,"netcdf: skip this field as not at one of user-defined levels: le save->verf_utime = verf_utime; // define NEW nc file, assume nx and ny of the 1st message hold for all messages... // get some info for grid_mapping -#ifdef NC_NETCDF4 if (save->nc4) - netcdf_command( nc_create(save->ncfile, NC_NETCDF4, &(save->ncid)) ); + netcdf_command_plus( nc_create(save->ncfile, NC_NETCDF4, &(save->ncid)),"error creating compressed netcdf4 file" ); else - netcdf_command( nc_create(save->ncfile, NC_CLASSIC_MODEL, &(save->ncid)) ); -#else - netcdf_command( nc_create(save->ncfile, 0, &(save->ncid)) ); -#endif + netcdf_command_plus( nc_create(save->ncfile, NC_CLASSIC_MODEL, &(save->ncid)),"error creating classic netcdf file" ); + create_nc_dims(save->ncid, lt_4D, &(save->time_dim), &(save->time_var), save->time_ind, save->time_step, save->time_step_type, @@ -1047,7 +1015,6 @@ min, max, add_offset, scale_factor, varname_buf); netcdf_command( nc_put_att_float(save->ncid, varid, "valid_min", NC_FLOAT, 1, &valid_min) ); netcdf_command( nc_put_att_float(save->ncid, varid, "valid_max", NC_FLOAT, 1, &valid_max) ); } -#ifdef NC_NETCDF4 if (save->nc4) { netcdf_command( nc_def_var_chunking(save->ncid, varid, NC_CHUNKED, chunks) ); @@ -1056,7 +1023,6 @@ min, max, add_offset, scale_factor, varname_buf); // netcdf_command( nc_def_var_endian(save->ncid, varid, endian) ); // NC_ENDIAN_NATIVE,NC_ENDIAN_LITTLE,NC_ENDIAN_BIG } -#endif netcdf_command( nc_enddef(save->ncid) ); } diff --git a/wgrib2/Netcdf_sup.c b/wgrib2/Netcdf_sup.c index b3d31c02..3b70c82d 100644 --- a/wgrib2/Netcdf_sup.c +++ b/wgrib2/Netcdf_sup.c @@ -26,7 +26,7 @@ vsm: test compilation with undefined USE_NETCDF... //#define DEBUG_NC -#if defined USE_NETCDF3 || defined USE_NETCDF4 +#if defined USE_NETCDF /* * Create time string (UTC) from time diff --git a/wgrib2/config.h.in b/wgrib2/config.h.in index d7a711a2..ba868be6 100644 --- a/wgrib2/config.h.in +++ b/wgrib2/config.h.in @@ -2,9 +2,7 @@ #ifndef _CONFIG_H #define _CONFIG_H -#cmakedefine USE_NETCDF3 -#cmakedefine USE_NETCDF4 -#cmakedefine USE_HDF5 +#cmakedefine USE_NETCDF #cmakedefine USE_REGEX #cmakedefine USE_TIGGE #cmakedefine USE_MYSQL diff --git a/wgrib2/init.c b/wgrib2/init.c index 667bd5e6..dbaa94f2 100644 --- a/wgrib2/init.c +++ b/wgrib2/init.c @@ -148,7 +148,7 @@ extern int warn_check_pdt; extern char ext_name_field, ext_name_space; -#if defined USE_NETCDF3 || defined USE_NETCDF4 +#if defined USE_NETCDF extern int nc4; #endif @@ -269,7 +269,7 @@ void init_globals(void) { ext_name_field = '.'; ext_name_space = '_'; -#if defined USE_NETCDF3 || defined USE_NETCDF4 +#if defined USE_NETCDF nc4 = 0; #endif diff --git a/wgrib2/wgrib2.h b/wgrib2/wgrib2.h index dd96bd7a..98a61d50 100644 --- a/wgrib2/wgrib2.h +++ b/wgrib2/wgrib2.h @@ -16,13 +16,6 @@ #include "wgrib2_api.h" -#ifdef USE_NETCDF4 -#define USE_NETCDF -#endif -#ifdef USE_NETCDF3 -#define USE_NETCDF -#endif - #ifndef BUILD_COMMENTS #define BUILD_COMMENTS "unknown build" #endif diff --git a/wgrib2/wgrib2_meta.h.in b/wgrib2/wgrib2_meta.h.in index fda745e6..9627b707 100644 --- a/wgrib2/wgrib2_meta.h.in +++ b/wgrib2/wgrib2_meta.h.in @@ -5,9 +5,7 @@ #ifndef _WGRIB2_META_H #define _WGRIB2_META_H -#cmakedefine USE_NETCDF3 -#cmakedefine USE_NETCDF4 -#cmakedefine USE_HDF5 +#cmakedefine USE_NETCDF #cmakedefine USE_REGEX #cmakedefine USE_TIGGE #cmakedefine USE_MYSQL From 6480d3b738aad4dd93cd269bf7c40015e67e733f Mon Sep 17 00:00:00 2001 From: webisu Date: Mon, 12 Aug 2024 13:34:43 -0400 Subject: [PATCH 2/7] spack changes --- spack/package.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/spack/package.py b/spack/package.py index b1662479..32e46cbb 100644 --- a/spack/package.py +++ b/spack/package.py @@ -9,8 +9,7 @@ from spack.package import * variant_map = { - "netcdf3": "USE_NETCDF3", - "netcdf4": "USE_NETCDF4", + "netcdf": "USE_NETCDF", "spectral": "USE_SPECTRAL", "mysql": "USE_MYSQL", "udf": "USE_UDF", @@ -76,13 +75,7 @@ def url_for_version(self, version): return url_fmt.format(version) variant( - "netcdf3", - default=True, - description="Link in netcdf3 library to write netcdf3 files", - when="@:3.1", - ) - variant( - "netcdf4", default=False, description="Link in netcdf4 library to write netcdf3/4 files" + "netcdf", default=False, description="Link in netcdf library to read, write netcdf files" ) variant( "ipolates", From c391ca5919f6d1884a6bb743cc5a93eeec350388 Mon Sep 17 00:00:00 2001 From: webisu Date: Mon, 12 Aug 2024 13:42:36 -0400 Subject: [PATCH 3/7] spack fix 2 --- spack/package.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/spack/package.py b/spack/package.py index 32e46cbb..e3c06624 100644 --- a/spack/package.py +++ b/spack/package.py @@ -140,13 +140,12 @@ def url_for_version(self, version): variant("openjpeg", default=False, description="Enable OpenJPEG", when="@:3.1") variant("enable_docs", default=False, description="Build doxygen documentation", when="@3.4.0:") - conflicts("+netcdf3", when="+netcdf4") conflicts("+openmp", when="%apple-clang") - depends_on("wget", type=("build"), when="@:3.1 +netcdf4") + depends_on("wget", type=("build"), when="@:3.1 +netcdf") depends_on("ip@5.1:", when="@develop +ipolates") depends_on("libaec@1.0.6:", when="@3.2: +aec") - depends_on("netcdf-c", when="@3.2: +netcdf4") + depends_on("netcdf-c", when="@3.2: +netcdf") depends_on("jasper@:2", when="@3.2: +jasper") depends_on("zlib-api", when="+png") depends_on("libpng", when="+png") @@ -217,7 +216,7 @@ def setup_build_environment(self, env): def build(self, pkg, spec, prefix): # Get source files for netCDF4 builds - if self.spec.satisfies("+netcdf4"): + if self.spec.satisfies("+netcdf"): with working_dir(self.build_directory): os.system( "wget https://downloads.unidata.ucar.edu/netcdf-c/4.8.1/netcdf-c-4.8.1.tar.gz" From 9d978027e2e19e2ee7cf278665ec709b80ce762b Mon Sep 17 00:00:00 2001 From: webisu Date: Mon, 12 Aug 2024 14:05:02 -0400 Subject: [PATCH 4/7] spack test fix --- spack/package.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/spack/package.py b/spack/package.py index e3c06624..d4c910df 100644 --- a/spack/package.py +++ b/spack/package.py @@ -9,6 +9,8 @@ from spack.package import * variant_map = { + "netcdf3": "USE_NETCDF3", + "netcdf4": "USE_NETCDF4", "netcdf": "USE_NETCDF", "spectral": "USE_SPECTRAL", "mysql": "USE_MYSQL", @@ -75,8 +77,18 @@ def url_for_version(self, version): return url_fmt.format(version) variant( - "netcdf", default=False, description="Link in netcdf library to read, write netcdf files" + "netcdf3", + default=True, + description="Link in netcdf3 library to write netcdf3 files", + when="@:3.1", + ) + variant( + "netcdf4", default=False, description="Link in netcdf4 library to write netcdf3/4 files" ) + variant( + "netcdf", default=False, description="Link in netcdf library to write netcdf3/4 files new" + ) + variant( "ipolates", default=False, @@ -140,11 +152,16 @@ def url_for_version(self, version): variant("openjpeg", default=False, description="Enable OpenJPEG", when="@:3.1") variant("enable_docs", default=False, description="Build doxygen documentation", when="@3.4.0:") + conflicts("+netcdf3", when="+netcdf4") + conflicts("+netcdf3", when="+netcdf") + conflicts("+netcdf4", when="+netcdf") conflicts("+openmp", when="%apple-clang") + depends_on("wget", type=("build"), when="@:3.1 +netcdf4") depends_on("wget", type=("build"), when="@:3.1 +netcdf") depends_on("ip@5.1:", when="@develop +ipolates") depends_on("libaec@1.0.6:", when="@3.2: +aec") + depends_on("netcdf-c", when="@3.2: +netcdf4") depends_on("netcdf-c", when="@3.2: +netcdf") depends_on("jasper@:2", when="@3.2: +jasper") depends_on("zlib-api", when="+png") @@ -216,6 +233,14 @@ def setup_build_environment(self, env): def build(self, pkg, spec, prefix): # Get source files for netCDF4 builds + if self.spec.satisfies("+netcdf4"): + with working_dir(self.build_directory): + os.system( + "wget https://downloads.unidata.ucar.edu/netcdf-c/4.8.1/netcdf-c-4.8.1.tar.gz" + ) + os.system( + "wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.12/hdf5-1.12.1/src/hdf5-1.12.1.tar.gz" + ) if self.spec.satisfies("+netcdf"): with working_dir(self.build_directory): os.system( From af81b5a651e5768cc4e6e420f4aeaedba21a567e Mon Sep 17 00:00:00 2001 From: webisu Date: Mon, 12 Aug 2024 14:18:10 -0400 Subject: [PATCH 5/7] test spack fix --- spack/package.py | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/spack/package.py b/spack/package.py index d4c910df..b1662479 100644 --- a/spack/package.py +++ b/spack/package.py @@ -11,7 +11,6 @@ variant_map = { "netcdf3": "USE_NETCDF3", "netcdf4": "USE_NETCDF4", - "netcdf": "USE_NETCDF", "spectral": "USE_SPECTRAL", "mysql": "USE_MYSQL", "udf": "USE_UDF", @@ -85,10 +84,6 @@ def url_for_version(self, version): variant( "netcdf4", default=False, description="Link in netcdf4 library to write netcdf3/4 files" ) - variant( - "netcdf", default=False, description="Link in netcdf library to write netcdf3/4 files new" - ) - variant( "ipolates", default=False, @@ -153,16 +148,12 @@ def url_for_version(self, version): variant("enable_docs", default=False, description="Build doxygen documentation", when="@3.4.0:") conflicts("+netcdf3", when="+netcdf4") - conflicts("+netcdf3", when="+netcdf") - conflicts("+netcdf4", when="+netcdf") conflicts("+openmp", when="%apple-clang") depends_on("wget", type=("build"), when="@:3.1 +netcdf4") - depends_on("wget", type=("build"), when="@:3.1 +netcdf") depends_on("ip@5.1:", when="@develop +ipolates") depends_on("libaec@1.0.6:", when="@3.2: +aec") depends_on("netcdf-c", when="@3.2: +netcdf4") - depends_on("netcdf-c", when="@3.2: +netcdf") depends_on("jasper@:2", when="@3.2: +jasper") depends_on("zlib-api", when="+png") depends_on("libpng", when="+png") @@ -241,14 +232,6 @@ def build(self, pkg, spec, prefix): os.system( "wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.12/hdf5-1.12.1/src/hdf5-1.12.1.tar.gz" ) - if self.spec.satisfies("+netcdf"): - with working_dir(self.build_directory): - os.system( - "wget https://downloads.unidata.ucar.edu/netcdf-c/4.8.1/netcdf-c-4.8.1.tar.gz" - ) - os.system( - "wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.12/hdf5-1.12.1/src/hdf5-1.12.1.tar.gz" - ) make() From 75b0fe1b01456bfe95e706f4e4c46c9a23483b4d Mon Sep 17 00:00:00 2001 From: webisu Date: Mon, 12 Aug 2024 14:25:24 -0400 Subject: [PATCH 6/7] test spack fix --- spack/package.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/spack/package.py b/spack/package.py index b1662479..149d727b 100644 --- a/spack/package.py +++ b/spack/package.py @@ -11,6 +11,7 @@ variant_map = { "netcdf3": "USE_NETCDF3", "netcdf4": "USE_NETCDF4", + "netcdf": "USE_NETCDF", "spectral": "USE_SPECTRAL", "mysql": "USE_MYSQL", "udf": "USE_UDF", @@ -84,6 +85,9 @@ def url_for_version(self, version): variant( "netcdf4", default=False, description="Link in netcdf4 library to write netcdf3/4 files" ) + variant( + "netcdf", default=False, description="Link in netcdf4 library to write netcdf3/4 files" + ) variant( "ipolates", default=False, @@ -148,12 +152,15 @@ def url_for_version(self, version): variant("enable_docs", default=False, description="Build doxygen documentation", when="@3.4.0:") conflicts("+netcdf3", when="+netcdf4") + conflicts("+netcdf3", when="+netcdf") conflicts("+openmp", when="%apple-clang") depends_on("wget", type=("build"), when="@:3.1 +netcdf4") + depends_on("wget", type=("build"), when="@:3.1 +netcdf") depends_on("ip@5.1:", when="@develop +ipolates") depends_on("libaec@1.0.6:", when="@3.2: +aec") depends_on("netcdf-c", when="@3.2: +netcdf4") + depends_on("netcdf-c", when="@3.2: +netcdf") depends_on("jasper@:2", when="@3.2: +jasper") depends_on("zlib-api", when="+png") depends_on("libpng", when="+png") @@ -232,6 +239,14 @@ def build(self, pkg, spec, prefix): os.system( "wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.12/hdf5-1.12.1/src/hdf5-1.12.1.tar.gz" ) + if self.spec.satisfies("+netcdf"): + with working_dir(self.build_directory): + os.system( + "wget https://downloads.unidata.ucar.edu/netcdf-c/4.8.1/netcdf-c-4.8.1.tar.gz" + ) + os.system( + "wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.12/hdf5-1.12.1/src/hdf5-1.12.1.tar.gz" + ) make() From d948feb51bed460e73f9db095f1e19ca6443dc96 Mon Sep 17 00:00:00 2001 From: AlysonStahl-NOAA <166434581+AlysonStahl-NOAA@users.noreply.github.com> Date: Mon, 12 Aug 2024 14:28:44 -0700 Subject: [PATCH 7/7] renamed workflow option --- .github/workflows/Linux_options.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Linux_options.yml b/.github/workflows/Linux_options.yml index 62ccf346..8f132418 100644 --- a/.github/workflows/Linux_options.yml +++ b/.github/workflows/Linux_options.yml @@ -34,7 +34,7 @@ jobs: options: "-DUSE_AEC=ON" } - { - options: "-DUSE_NETCDF4=ON" + options: "-DUSE_NETCDF=ON" } - { options: "-DBUILD_WGRIB=ON"