Skip to content

Commit

Permalink
Merge branch 'develop' into as_ci
Browse files Browse the repository at this point in the history
  • Loading branch information
AlysonStahl-NOAA authored Oct 18, 2024
2 parents 8ddd650 + 25fd33c commit 8647fd4
Show file tree
Hide file tree
Showing 16 changed files with 194 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/developer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
export CFLAGS='-Wall -g -fprofile-abs-path -fprofile-arcs -ftest-coverage -O0 -I/home/runner/work/wgrib2/wgrib2/nceplibs/NCEPLIBS-g2c/include'
export FCFLAGS='-Wall -g -fprofile-abs-path -fprofile-arcs -ftest-coverage -O0'
export FFLAGS='-Wall -g -fprofile-abs-path -fprofile-arcs -ftest-coverage -O0'
cmake .. -DENABLE_DOCS=ON -DFTP_TEST_FILES=ON -DCMAKE_PREFIX_PATH="$GITHUB_WORKSPACE/nceplibs/NCEPLIBS-ip;$GITHUB_WORKSPACE/nceplibs/jasper;$GITHUB_WORKSPACE/nceplibs/NCEPLIBS-g2c" -DTEST_FILE_DIR=/home/runner/data -DUSE_NETCDF4=ON -DUSE_AEC=ON -DUSE_IPOLATES=ON -DUSE_JASPER=ON
cmake .. -DENABLE_DOCS=ON -DFTP_TEST_FILES=ON -DCMAKE_PREFIX_PATH="$GITHUB_WORKSPACE/nceplibs/NCEPLIBS-ip;$GITHUB_WORKSPACE/nceplibs/jasper;$GITHUB_WORKSPACE/nceplibs/NCEPLIBS-g2c" -DTEST_FILE_DIR=/home/runner/data -DMAKE_FTN_API=ON -DUSE_NETCDF4=ON -DUSE_AEC=ON -DUSE_IPOLATES=ON -DUSE_JASPER=ON
make VERBOSE=1
ctest --verbose --output-on-failure --rerun-failed
gcovr --root .. -v --html-details --exclude ../tests --exclude CMakeFiles --print-summary -o test-coverage.html &> /dev/null
Expand Down
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ option(FTP_EXTRA_TEST_FILES "Fetch even more large files from FTP and test them.
option(MAKE_FTN_API "add ftn api?" off)
option(DISABLE_STAT "disable posix feature" off)
set(BUILD_COMMENTS "stock build")

option(BUILD_LIB "Build wgrib2 library?" on)
option(BUILD_SHARED_LIB "Build shared library?" off)
# if BUILD_LIB, then code is compiled as relocatable
option(BUILD_SHARED_LIB "Build shared library?" on)
# To create libwgrib2.so for python, you have to build with BUILD_SHARED_LIB off
# and manually create libwgrib2.so from the needed *.a files

option(BUILD_WGRIB "Build wgrib code?" off)

if (MAKE_FTN_API OR USE_IPOLATES)
Expand Down Expand Up @@ -84,6 +89,10 @@ if(USE_G2CLIB)
endif()
endif()

if (BUILD_SHARED_LIB AND NOT BUILD_LIB)
message(FATAL_ERROR "BUILD_SHARED_LIB is on but BUILD_LIB is off")
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 Down
11 changes: 11 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ if (USE_JASPER OR USE_OPENJPEG)
copy_test_data(ref_jpeg2simple.txt)
endif()

if (MAKE_FTN_API)
shell_test(test_ftn_api)
endif()
if (BUILD_LIB)
shell_test(test_lib)
endif()
if (BUILD_SHARED_LIB)
shell_test(test_shared_lib)
endif()


if (FTP_TEST_FILES)
copy_test_data(ref_WW3_Regional_US_West_Coast_20220718_0000.grib2.inv)
copy_test_data(ref_merge_fcst.aqm.t12z.max_8hr_o3.227.grib2.txt)
Expand Down
13 changes: 13 additions & 0 deletions tests/run_wgrib2_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,18 @@ echo "*** Testing write/read section"
touch secs.txt
diff -w secs.txt simple.txt


echo "*** test pdt 48 ***"
n=`../wgrib2/wgrib2 ./data/gdas.t12z.pgrb2.1p00.anl.75r.grib2 -d 1 -set_pdt +48 -set_byte 4 12 00:12:0 | grep -c "aerosol_size"`
if [ "$n" -ne 1 ] ; then
exit 1
fi
set -x
echo "*** test pdt 49 ***"
n=`../wgrib2/wgrib2 ./data/gdas.t12z.pgrb2.1p00.anl.75r.grib2 -d 1 -set_pdt +49 -set_byte 4 12 00:12:0 | grep -c "aerosol_size"`
if [ "$n" -ne 1 ] ; then
exit 1
fi

echo "*** SUCCESS!"
exit 0
15 changes: 15 additions & 0 deletions tests/test_ftn_api.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
#
# script to see if ftn_api compiled
#

echo "see if ftn_api compiled"
set -xe

if [ ! -f ../wgrib2/ftn_api/include/wgrib2api.mod ] ; then
echo "failed: did not find wgrib2api.mod"
exit 1
fi

echo "*** SUCCESS!"
exit 0
15 changes: 15 additions & 0 deletions tests/test_lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
#
# script to see if shared lib was made
#

echo "see if shared library made"
set -xe

if [ ! -f ../wgrib2/libwgrib2.so -a ! -f ../wgrib2/libwgrib2.a ] ; then
echo "failed: did not find libwgrib2"
exit 1
fi

echo "*** SUCCESS!"
exit 0
15 changes: 15 additions & 0 deletions tests/test_shared_lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
#
# script to see if shared lib was made
#

echo "see if shared library made"
set -xe

if [ ! -f ../wgrib2/libwgrib2.so ] ; then
echo "failed: did not find libwgrib2.so"
exit 1
fi

echo "*** SUCCESS!"
exit 0
40 changes: 16 additions & 24 deletions wgrib2/Aerosol.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,27 @@

/*
* 2/2012 Public Domain: Wesley Ebisuzaki
* 10/2024 fix to handle all pdts Wesley Ebisuzaki
*/

/*
* HEADER:200:aerosol_size:inv:0:optical properties of an aerosol
*/

int f_aerosol_size(ARG0) {
int pdt, type;
unsigned char *sec4;
unsigned char *ptr;
double size1, size2;

if (mode >= 0) {
pdt = code_table_4_0(sec);
if (pdt < 44 || pdt > 48) return 0;
type = code_table_4_91(sec);
if (type == 255) return 0;
sec4 = sec[4];

size1 = scaled2dbl(INT1(sec4[14]), int4(sec4+15));
size2 = scaled2dbl(INT1(sec4[19]), int4(sec4+20));
ptr = code_table_4_91_location(sec);
if (ptr == NULL) return 0;
if (*ptr == 255) return 0;
size1 = scaled2dbl(INT1(ptr[1]), int4(ptr+2));
size2 = scaled2dbl(INT1(ptr[6]), int4(ptr+7));

sprintf(inv_out,"aerosol_size ");
inv_out += strlen(inv_out);
type = code_table_4_91(sec);
prt_code_table_4_91(type, size1, size2, inv_out);
prt_code_table_4_91(ptr[0], size1, size2, inv_out);

}
return 0;
Expand All @@ -40,23 +36,19 @@ int f_aerosol_size(ARG0) {
*/

int f_aerosol_wavelength(ARG0) {
int pdt, type;
unsigned char *sec4;
unsigned char *ptr;
double wave1, wave2;

if (mode >= 0) {
pdt = code_table_4_0(sec);
if (pdt != 48) return 0;
type = code_table_4_91b(sec);
if (type == 255) return 0;
sec4 = sec[4];

wave1 = scaled2dbl(INT1(sec4[25]), int4(sec4+26));
wave2 = scaled2dbl(INT1(sec4[30]), int4(sec4+31));
ptr = code_table_4_91b_location(sec);
if (ptr == NULL) return 0;
if (*ptr == 255) return 0;
wave1 = scaled2dbl(INT1(ptr[1]), int4(ptr+2));
wave2 = scaled2dbl(INT1(ptr[6]), int4(ptr+7));

sprintf(inv_out,"aerosol_wavelength ");
inv_out += strlen(inv_out);
prt_code_table_4_91(type, wave1, wave2, inv_out);
prt_code_table_4_91(ptr[0], wave1, wave2, inv_out);

}
return 0;
Expand Down
50 changes: 33 additions & 17 deletions wgrib2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
# subdirectory.
#
# Kyle Gerheiser, Edward Hartnett, Wesley Ebisuzaki
#
# if BUILD_SHARED_LIB
# ftn_api -> shared library, interface to fortran
# wgrib2_lib -> shared (includes gctpc)
#
# if !BUILD_SHARED_LIB
# ftn_api -> static library, interface to fortran
# wgrib2_lib -> static library includeing gctpc
#
# note: in wgrib2 v3.1.3 or earlier, all the libraries
# incuding aec, jasper, etc were included with the wgrib2 library
# in github version, it is different.


# sets lib_src
set(lib_src AAIG.c AAIGlong.c addtime.c aec_pk.c Aerosol.c Alarm.c
Expand Down Expand Up @@ -44,14 +57,16 @@ Type_reftime.c UDF.c Undefine.c units.c Unix_time.c Unmerge_fcst.c
unpk_0.c unpk.c unpk_complex.c unpk_run_length.c update_sec3.c
update_sec4.c v1_v2_if.c VerfTime.c Warn_old_g2lib.c Waves.c
wgrib2_api.c wgrib2.c Wind_dir.c Wind_speed.c Wind_uv.c Write_sec.c
Wrt_grib.c wrtieee.c wxtext.c)
Wrt_grib.c wrtieee.c wxtext.c
)

include_directories(gctpc/source/include)
add_subdirectory(gctpc)

if(MAKE_FTN_API)
add_subdirectory(ftn_api)
endif()

add_subdirectory(gctpc)

# make this an object lib so we can re-use most of object files
# The only files that differ are ${callable_src} which are compiled
# with -DCALLABLE_WGRIB2
Expand All @@ -67,25 +82,27 @@ configure_file (

if(BUILD_LIB)

# with -DCALLABLE_WGRIB2 for the lib
if(BUILD_SHARED_LIB)
add_library(wgrib2_lib SHARED ${lib_src} $<TARGET_OBJECTS:gctpc> ${callable_src})
add_library(wgrib2_lib SHARED ${lib_src} )
set_property(TARGET wgrib2_lib PROPERTY POSITION_INDEPENDENT_CODE ON)
else()
add_library(wgrib2_lib STATIC ${lib_src} $<TARGET_OBJECTS:gctpc> ${callable_src})
add_library(wgrib2_lib STATIC ${lib_src} $<TARGET_OBJECTS:gctpc> )
# add_library(wgrib2_lib STATIC ${lib_src} )
set_property(TARGET wgrib2_lib PROPERTY POSITION_INDEPENDENT_CODE ON)
endif()

# library and executable have same name (wgrib2) but different target names
set_target_properties(wgrib2_lib PROPERTIES OUTPUT_NAME wgrib2)
target_compile_definitions(wgrib2_lib PRIVATE CALLABLE_WGRIB2)
# target_compile_definitions(wgrib2_lib PRIVATE CALLABLE_WGRIB2)
endif()


# without -DCALLABLE_WGRIB2 for the executable
add_executable(wgrib2_exe ${callable_src})
add_executable(wgrib2_exe wgrib2_main.c)
set_target_properties(wgrib2_exe PROPERTIES OUTPUT_NAME wgrib2)

if(USE_NETCDF)
target_link_libraries(obj_lib PUBLIC NetCDF::NetCDF_C)
target_link_libraries(wgrib2_exe PUBLIC NetCDF::NetCDF_C)
endif()

if(USE_PNG)
Expand All @@ -98,6 +115,7 @@ endif()

if(USE_IPOLATES)
target_link_libraries(obj_lib PUBLIC ip::ip_d)
target_link_libraries(wgrib2_exe PUBLIC ip::ip_d)

# Link to the Fortran runtime library for each compiler if using ip2.
# The wgrib2 exectuable is created using the C compiler and
Expand All @@ -110,13 +128,13 @@ if(USE_IPOLATES)

endif()

target_link_libraries(obj_lib PUBLIC gctpc -lm)
## target_link_libraries(obj_lib PUBLIC gctpc -lm)

# Link to gctpc directly because oobject libraries do not link transitively
target_link_libraries(wgrib2_exe PRIVATE gctpc)
# Link to gctpc directly because object libraries do not link transitively
target_link_libraries(wgrib2_exe PRIVATE gctpc -lm)

if(USE_AEC)
target_link_libraries(wgrib2_exe PRIVATE aec)
target_link_libraries(wgrib2_exe PRIVATE ${LIBAEC_LIBRARIES})
endif()

if(USE_JASPER)
Expand All @@ -130,10 +148,11 @@ if(USE_OPENJPEG)
endif()

target_link_libraries(wgrib2_exe PRIVATE obj_lib)
# target_link_libraries(wgrib2_exe PRIVATE wgrib2_lib)

if(BUILD_LIB)
set(headers wgrib2_api.h wgrib2.h ${CMAKE_BINARY_DIR}/wgrib2/wgrib2_meta.h)
target_link_libraries(wgrib2_lib PUBLIC gctpc)
## target_link_libraries(wgrib2_lib PUBLIC gctpc)
set_target_properties(wgrib2_lib PROPERTIES PUBLIC_HEADER "${headers}")
target_compile_definitions(wgrib2_lib PUBLIC ${definitions_list})

Expand All @@ -156,6 +175,3 @@ install(
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})





3 changes: 1 addition & 2 deletions wgrib2/ExtName.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,8 @@ int f_misc(ARG0) {
strcat(inv_out,":");
inv_out += strlen(inv_out);
}
if (pdt == 48) {
if (pdt == 48 || pdt == 49) { /* aerosol with optical properties */
f_aerosol_size(call_ARG0(inv_out,NULL));
strcat(inv_out,":");
inv_out += strlen(inv_out);
f_aerosol_wavelength(call_ARG0(inv_out,NULL));
strcat(inv_out,":");
Expand Down
12 changes: 6 additions & 6 deletions wgrib2/fatal_error.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#ifdef CALLABLE_WGRIB2

#include <setjmp.h>
#endif

#include "wgrib2.h"

/*
Expand All @@ -17,9 +17,9 @@
* fprintf(ARGS)
* do_fatal_error_processing
*/
#ifdef CALLABLE_WGRIB2

extern jmp_buf fatal_err;
#endif



void fatal_error(const char *fmt, ...)
Expand All @@ -32,9 +32,9 @@ void fatal_error(const char *fmt, ...)
va_end(arg);

err_bin(1); err_string(1);
#ifdef CALLABLE_WGRIB2

longjmp(fatal_err,1);
#endif

exit(8);
return;
}
15 changes: 10 additions & 5 deletions wgrib2/ftn_api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,26 @@ set(c_src
fort_wgrib2.c
)

add_library(wgrib2_api ${fortran_src} ${c_src})
if (BUILD_SHARED_LIB)
add_library(wgrib2_ftn_api SHARED ${fortran_src} ${c_src})
else()
add_library(wgrib2_ftn_api STATIC ${fortran_src} ${c_src})
set_property(TARGET wgrib2_ftn_api PROPERTY POSITION_INDEPENDENT_CODE ON)
endif()

set(module_dir "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR}")
set_target_properties(wgrib2_api PROPERTIES Fortran_MODULE_DIRECTORY ${module_dir})
set_target_properties(wgrib2_ftn_api PROPERTIES Fortran_MODULE_DIRECTORY ${module_dir})

target_include_directories(wgrib2_api
target_include_directories(wgrib2_ftn_api
PUBLIC $<BUILD_INTERFACE:${module_dir}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}>)

target_link_libraries(wgrib2_api PUBLIC wgrib2_lib)
target_link_libraries(wgrib2_ftn_api PUBLIC wgrib2_lib)

install(DIRECTORY ${module_dir} DESTINATION ${CMAKE_INSTALL_PREFIX})

install(
TARGETS wgrib2_api
TARGETS wgrib2_ftn_api
EXPORT wgrib2_exports
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down
Loading

0 comments on commit 8647fd4

Please sign in to comment.