Skip to content

Commit

Permalink
Merge pull request #228 from NOAA-EMC/netcdf_wne
Browse files Browse the repository at this point in the history
USE_NETCDF3/4 -> USE_NETCDF
  • Loading branch information
AlysonStahl-NOAA authored Aug 13, 2024
2 parents de500ac + d11fdad commit 746374b
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Linux_options.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
options: "-DUSE_AEC=ON"
}
- {
options: "-DUSE_NETCDF4=ON"
options: "-DUSE_NETCDF=ON"
}
- {
options: "-DBUILD_WGRIB=ON"
Expand Down
11 changes: 2 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions spack/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
variant_map = {
"netcdf3": "USE_NETCDF3",
"netcdf4": "USE_NETCDF4",
"netcdf": "USE_NETCDF",
"spectral": "USE_SPECTRAL",
"mysql": "USE_MYSQL",
"udf": "USE_UDF",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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()

Expand Down
6 changes: 2 additions & 4 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion wgrib2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
8 changes: 2 additions & 6 deletions wgrib2/Config.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "grb2.h"
#include "fnlist.h"

#if defined USE_NETCDF3 || defined USE_NETCDF4
#if defined USE_NETCDF
#include <netcdf.h>
#endif

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion wgrib2/Import_netcdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "wgrib2.h"
#include "fnlist.h"

#if defined USE_NETCDF3 || defined USE_NETCDF4
#if defined USE_NETCDF

#include <netcdf.h>

Expand Down
46 changes: 6 additions & 40 deletions wgrib2/Netcdf.c
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -23,13 +23,10 @@

//#define DEBUG_NC

#if defined USE_NETCDF3 || defined USE_NETCDF4
#if defined USE_NETCDF
#include <netcdf.h>

// 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];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) );
Expand All @@ -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) );
}

Expand Down
2 changes: 1 addition & 1 deletion wgrib2/Netcdf_sup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions wgrib2/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions wgrib2/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
7 changes: 0 additions & 7 deletions wgrib2/wgrib2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions wgrib2/wgrib2_meta.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 746374b

Please sign in to comment.