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" diff --git a/CMakeLists.txt b/CMakeLists.txt index 92c3cac1..4ed952d0 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/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() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f1371f80..f2d730ec 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -112,15 +112,13 @@ copy_test_data(ref_new_grid_gdt_32769.grib2) 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