Skip to content

Commit

Permalink
Build rdbfmsua on Hera, Orion, and WCOSS2 (#50)
Browse files Browse the repository at this point in the history
`rdbfmsua` was disabled because it needs gempak and gfortran, and
writing a `find_package` is very difficult for these.
After some investigation, some progress was made and this utility is now
able to be built on Hera, Orion, and WCOSS2 with cmake.
  • Loading branch information
aerorahul authored Mar 12, 2024
1 parent 82980f9 commit ecabf5a
Show file tree
Hide file tree
Showing 19 changed files with 145 additions and 77 deletions.
10 changes: 4 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ find_package(g2 REQUIRED)
find_package(bufr REQUIRED)
find_package(landsfcutil REQUIRED)
find_package(wgrib2 REQUIRED)
#rdbfmsua.fd needs gempak and gfortran
#but gempak is so old, any hopes of a find_package(gempak) is null
#some things ought to wither and die
#find_package(gempak REQUIRED)
#find_package(gfortran REQUIRED)
# rdbfmsua.fd needs gempak and gfortran, but
# make them optional and skip rdbfmsua building if they are not found.
find_package(gempak)
find_package(gfortran)

# See https://github.com/NOAA-EMC/NCEPLIBS-nemsio/pull/22
target_link_libraries(nemsio::nemsio INTERFACE w3emc::w3emc_d bacio::bacio_4)
Expand All @@ -70,4 +69,3 @@ add_subdirectory(src)

# Install utility scripts.
add_subdirectory(ush)

62 changes: 21 additions & 41 deletions cmake/Findgempak.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
# - OS_ROOT - root of gempak os installation
#

list( APPEND _libraries appl bridge cgemlib gemlib syslib )

# First find the INCLUDE_DIRS
find_path(
GEMPAK_INCLUDE_DIR
NAMES GEMPRM.PRM BRIDGE.PRM
Expand All @@ -27,6 +26,7 @@ find_path(
DOC "Path to GEMPRM.PRM, BRIDGE.PRM"
)

# FIXME: On Hera, MCHPRM.PRM is linked to GEMINC directory so may cause issues
find_path(
OS_GEMPAK_INCLUDE_DIR
NAMES MCHPRM.PRM
Expand All @@ -38,70 +38,50 @@ find_path(
DOC "Path to MCHPRM.PRM"
)

mark_as_advanced(GEMPAK_INCLUDE_DIR OS_GEMPAK_INCLUDE_DIR)

# if(NOT TARGET gempak::gempak)
# message(DEBUG "[FindGempak.cmake]: creating target gempak::gempak")
# add_library(gempak::gempak UNKNOWN IMPORTED)
# set_target_properties(gempak::gempak PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${GEMPAK_INCLUDE_DIR};${OS_GEMPAK_INCLUDE_DIR}")
# endif()

# Next find the LIBRARY_DIRS and LIBRARIES
list( APPEND _libraries gemlib appl syslib cgemlib bridge )

foreach( _lib IN LISTS _libraries )
find_library(
GEMPAK_${_lib}_LIBRARY
NAMES ${_lib}.a
NAMES ${_lib}.a lib${_lib}.a
HINTS ${GEMPAK_LIBRARY_DIRS}
${GEMPAK} $ENV{GEMPAK}
${OS_ROOT} $ENV{OS_ROOT}
${GEMLIB} $ENV{GEMLIB}
${GEMOLB} $ENV{GEMOLB}
PATH_SUFFIXES lib lib64
DOC "Path to GEMPAK_${_lib}_LIBRARY"
)
endforeach()

# target_link_libraries(gempak::gempak INTERFACE ${GEMPAK_${_lib}_LIBRARY})

if(NOT TARGET gempak::gempak_${_lib})
add_library(gempak::gempak_${_lib} UNKNOWN IMPORTED)
set_target_properties(gempak::gempak_${_lib} PROPERTIES
IMPORTED_LOCATION "${GEMPAK_${_lib}_LIBRARY}"
)
if(EXISTS "${GEMPAK_${_lib}_LIBRARY}")
set_target_properties(gempak::gempak_${_lib} PROPERTIES
IMPORTED_LOCATION "${GEMPAK_${_lib}_LIBRARY}")
endif()
endif()
mark_as_advanced(GEMPAK_INCLUDE_DIR OS_GEMPAK_INCLUDE_DIR GEMPAK_gemlib_LIBRARY GEMPAK_appl_LIBRARY GEMPAK_syslib_LIBRARY GEMPAK_cgemlib_LIBRARY GEMPAK_bridge_LIBRARY)

if(NOT TARGET gempak::gempak)
add_library(gempak::gempak UNKNOWN IMPORTED)
set_target_properties(gempak::gempak PROPERTIES
IMPORTED_LOCATION "${GEMPAK_${_lib}_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${GEMPAK_INCLUDE_DIR};${OS_GEMPAK_INCLUDE_DIR}"
)
if(EXISTS "${GEMPAK_${_lib}_LIBRARY}")
set_target_properties(gempak::gempak PROPERTIES
IMPORTED_LOCATION "${GEMPAK_${_lib}_LIBRARY}")
endif()
endif()
list(APPEND GEMPAK_LIBRARIES "${GEMPAK_${_lib}_LIBRARY}")
message(DEBUG "[Findgempak.cmake]: creating target gempak::gempak")

foreach( _lib IN LISTS _libraries )
list( APPEND GEMPAK_LIBRARIES "${GEMPAK_${_lib}_LIBRARY}" )
add_library(gempak::${_lib} UNKNOWN IMPORTED)
set_target_properties(gempak::${_lib} PROPERTIES IMPORTED_LOCATION "${GEMPAK_${_lib}_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${GEMPAK_INCLUDE_DIR};${OS_GEMPAK_INCLUDE_DIR}")
endforeach()

message(STATUS "GEMPAK_LIBRARIES = ${GEMPAK_LIBRARIES}")
set(GEMPAK_LIBRARIES "${GEMPAK_LIBRARIES}" CACHE STRING "gempak library targets" FORCE)
mark_as_advanced(GEMPAK_LIBRARIES)

message(DEBUG "[FindGempak.cmake]: linking with appl.a bridge.a cgemlib.a gemlib.a syslib.a")
set_target_properties(gempak::gempak PROPERTIES
INTERFACE_LINK_LIBRARIES "${GEMPAK_LIBRARIES}")
add_library(gempak::gempak INTERFACE IMPORTED)
target_link_libraries(gempak::gempak INTERFACE gempak::gemlib gempak::appl gempak::syslib gempak::cgemlib gempak::bridge)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(gempak
REQUIRED_VARS GEMPAK_INCLUDE_DIR OS_GEMPAK_INCLUDE_DIR
REQUIRED_VARS GEMPAK_LIBRARIES GEMPAK_INCLUDE_DIR OS_GEMPAK_INCLUDE_DIR
)

if(gempak_FOUND AND NOT gempak_FIND_QUIETLY)
message(STATUS "FindGempak:")
message(STATUS "Findgempak:")
message(STATUS " - GEMPAK_INCLUDE_DIR: ${GEMPAK_INCLUDE_DIR}")
message(STATUS " - OS_GEMPAK_INCLUDE_DIR: ${OS_GEMPAK_INCLUDE_DIR}")
# message(STATUS " - GEMPAK_LIBRARIES: ${GEMPAK_LIBRARIES}")
message(STATUS " - GEMPAK_LIBRARIES: ${GEMPAK_LIBRARIES}")
endif()

13 changes: 7 additions & 6 deletions cmake/Findgfortran.cmake
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
find_library(
GFORTRAN_LIBRARY
NAMES libgfortran.a
HINTS /apps/gnu/gcc-6.5.0
NAMES libgfortran.so
HINTS ${GFORTRAN_LIBRARY_DIRS}
${gfortran_ROOT} $ENV{gfortran_ROOT}
PATH_SUFFIXES lib lib64
DOC "Path to GFORTRAN_LIBRARY"
)

mark_as_advanced(GFORTRAN_LIBRARY)

message(DEBUG "GFORTRAN_LIBRARY = ${GFORTRAN_LIBRARY}")

message(DEBUG "[Findgfortran.cmake]: creating target gfortran::gfortran")
add_library(gfortran::gfortran UNKNOWN IMPORTED)

message(STATUS "GFORTRAN_LIBRARY = ${GFORTRAN_LIBRARY}")

message(DEBUG "[Findgfortran.cmake]: linking with gfortran.a")
message(DEBUG "[Findgfortran.cmake]: linking with gfortran.so")
set_target_properties(gfortran::gfortran PROPERTIES IMPORTED_LOCATION ${GFORTRAN_LIBRARY})

include(FindPackageHandleStandardArgs)
Expand All @@ -24,4 +25,4 @@ find_package_handle_standard_args(gfortran
if(gfortran_FOUND AND NOT gfortran_FIND_QUIETLY)
message(STATUS "Findgfortran:")
message(STATUS " - GFORTRAN_LIBRARY: ${GFORTRAN_LIBRARY}")
endif()
endif()
2 changes: 0 additions & 2 deletions modulefiles/gfsutils_common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ local wrf_io_ver=os.getenv("wrf_io_ver") or "1.2.0"
local ncio_ver=os.getenv("ncio_ver") or "1.1.2"
local g2_ver=os.getenv("g2_ver") or "3.4.5"
local landsfcutil_ver=os.getenv("landsfcutil_ver") or "2.4.1"
local gempak_ver=os.getenv("gempak_ver") or "7.14.1"
local wgrib2_ver=os.getenv("wgrib2_ver") or "2.0.8"
local libpng_ver=os.getenv("libpng_ver") or "1.6.37"

Expand All @@ -38,5 +37,4 @@ load(pathJoin("wrf-io", wrf_io_ver))
load(pathJoin("ncio", ncio_ver))
load(pathJoin("g2", g2_ver))
load(pathJoin("landsfcutil", landsfcutil_ver))
--load(pathJoin("gempak", gempak_ver))
load(pathJoin("wgrib2", wgrib2_ver))
6 changes: 6 additions & 0 deletions modulefiles/gfsutils_hera.intel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ load(pathJoin("cmake", cmake_ver))

load("gfsutils_common")

local gempak_ver=os.getenv("gempak_ver") or "7.4.2"
load(pathJoin("gempak", gempak_ver))

-- Used in rdbfmsua.f
setenv("gfortran_ROOT", "/apps/gnu/gcc-9.2.0")

whatis("Description: GFS utilities environment on Hera with Intel Compilers")
6 changes: 6 additions & 0 deletions modulefiles/gfsutils_orion.intel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ load(pathJoin("cmake", cmake_ver))

load("gfsutils_common")

local gempak_ver=os.getenv("gempak_ver") or "7.5.1"
load(pathJoin("gempak", gempak_ver))

-- Used in rdbfmsua.f
setenv("gfortran_ROOT", "/apps/gcc-8/gcc-8.3.0")

whatis("Description: GFS utilities environment on Orion with Intel Compilers")
5 changes: 4 additions & 1 deletion modulefiles/gfsutils_wcoss2.intel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ load(pathJoin("nemsio", nemsio_ver))
load(pathJoin("wrf_io", wrf_io_ver))
load(pathJoin("g2", g2_ver))
load(pathJoin("landsfcutil", landsfcutil_ver))
--load(pathJoin("gempak", gempak_ver))
load(pathJoin("gempak", gempak_ver))
load(pathJoin("wgrib2", wgrib2_ver))

-- Used in rdbfmsua.f
setenv("gfortran_ROOT", "//opt/cray/pe/gcc/10.3.0/snos")

pushenv("HPC_OPT", "/apps/ops/para/libs")
prepend_path("MODULEPATH", "/apps/ops/para/libs/modulefiles/compiler/intel/19.1.3.304")
prepend_path("MODULEPATH", "/apps/ops/para/libs/modulefiles/mpi/intel/19.1.3.304/cray-mpich/8.1.7")
Expand Down
11 changes: 10 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ add_subdirectory(supvit.fd)

add_subdirectory(mkgfsawps.fd)
add_subdirectory(overgridid.fd)
# add_subdirectory(rdbfmsua.fd)
if (gempak_FOUND AND gfortran_FOUND)
add_subdirectory(rdbfmsua.fd)
else()
if(NOT gempak_FOUND)
message(WARNING "GEMPAK not found, skipping rdbfmsua.fd")
endif()
if(NOT gfortran_FOUND)
message(WARNING "gfortran not found, skipping rdbfmsua.fd")
endif()
endif()
add_subdirectory(webtitle.fd)

add_subdirectory(ocnicepost.fd)
Expand Down
6 changes: 5 additions & 1 deletion src/ocnicepost.fd/utils_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,11 @@ subroutine nf90_err(ierr, string)
character(len=*), intent(in) :: string
if (ierr /= nf90_noerr) then
write(0, '(a)') 'FATAL ERROR: ' // trim(string)// ' : ' // trim(nf90_strerror(ierr))
stop ierr
! This fails on WCOSS2 with Intel 19 compiler. See
! https://community.intel.com/t5/Intel-Fortran-Compiler/STOP-and-ERROR-STOP-with-variable-stop-codes/m-p/1182521#M149254
! When WCOSS2 moves to Intel 2020+, uncomment the next line and remove stop 99
!stop ierr
stop 99
end if
end subroutine nf90_err
end module utils_mod
3 changes: 1 addition & 2 deletions src/rdbfmsua.fd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ list(APPEND fortran_src
)

if(CMAKE_Fortran_COMPILER_ID MATCHES "^(Intel)$")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -convert big_endian -fp-model source")
set_source_files_properties(${fortran_src_free} PROPERTIES COMPILE_FLAGS "-free")
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^(GNU)$")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fconvert=big-endian")
set_source_files_properties(${fortran_src_free} PROPERTIES COMPILE_FLAGS "-ffree-form")
endif()

Expand All @@ -16,5 +14,6 @@ target_link_libraries(${exe_name} PRIVATE bufr::bufr_4
w3emc::w3emc_4
gempak::gempak
gfortran::gfortran)
#target_link_libraries(${exe_name} PRIVATE "-lgfortran")

install(TARGETS ${exe_name} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ SHELL=/bin/sh
# LEX, or CAL. An explicit rule will need to be added for PASCAL modules.
#
OBJS= rdbfmsua.o


# Tunable parameters
#
Expand All @@ -38,33 +38,21 @@ OBJS= rdbfmsua.o
# LIBS List of libraries
# CMD Name of the executable
#
FC = ifort
# FFLAGS = -O3 -q32 -I${GEMINC} -I${NAWIPS}/os/${NA_OS}/include
# FFLAGS = -I${GEMINC} -I${NAWIPS}/os/${NA_OS}/include
FFLAGS = -I${GEMINC} -I${OS_INC}
# LDFLAGS = -O3 -q32 -s
# LDFLAGS = -Wl,-Map,MAPFILE
FC = ifort
FFLAGS = -g -traceback -I${GEMINC} -I${OS_INC}

# BRIDGE=/gpfs/dell1/nco/ops/nwpara/gempak.v7.3.1/nawips/os/linux3.10.0_x86_64/lib/libbridge.a
BRIDGE=${GEMOLB}/bridge.a
GFORTRAN=/apps/gcc/6.2.0/lib64

LIBS = ${DECOD_UT_LIB} ${BUFR_LIB4} \
${GEMLIB}/gemlib.a ${GEMLIB}/appl.a ${GEMLIB}/syslib.a ${GEMLIB}/cgemlib.a -L${GFORTRAN} -lgfortran ${BRIDGE}

# LIBS = ${DECOD_UT_LIB} ${BUFR_LIB4} \
# -L${GEMOLB} -lgemlib -lappl -lsyslib -lcgemlib -lgfortran ${BRIDGE}

# -L${GEMOLB} -lgemlib -lappl -lsyslib -lcgemlib -lgfortran ${BRIDGE}
# -L/nwprod/gempak/nawips1/os/linux2.6.32_x86_64/lib -lgemlib -lappl -lsyslib -lcgemlib -lbridge -lncepBUFR \
# -lgfortran

CMD = rdbfmsua

# To perform the default compilation, use the first line
# To compile with flowtracing turned on, use the second line
# To compile giving profile additonal information, use the third line
# CFLAGS= -O3 -q32
# CFLAGS= -O3 -q32

# Lines from here on down should not need to be changed. They are the
# actual rules which make uses to build a.out.
Expand All @@ -77,7 +65,7 @@ $(CMD): $(OBJS)
# The following rule reads the required NAWIPS definitions and then recursively
# runs this same makefile with a new target in the spawned shell.
#

clean:
-rm -f ${OBJS}

Expand Down
76 changes: 76 additions & 0 deletions src/rdbfmsua.fd/to_be_deleted/makefile.wcoss2
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
SHELL=/bin/sh
#
# This makefile was produced by /usr/bin/fmgen at 11:21:07 AM on 10/28/94
# If it is invoked by the command line
# make -f makefile
# it will compile the fortran modules indicated by SRCS into the object
# modules indicated by OBJS and produce an executable named a.out.
#
# If it is invoked by the command line
# make -f makefile a.out.prof
# it will compile the fortran modules indicated by SRCS into the object
# modules indicated by OBJS and produce an executable which profiles
# named a.out.prof.
#
# To remove all the objects but leave the executables use the command line
# make -f makefile clean
#
# To remove everything but the source files use the command line
# make -f makefile clobber
#
# To remove the source files created by /usr/bin/fmgen and this makefile
# use the command line
# make -f makefile void
#
# The parameters SRCS and OBJS should not need to be changed. If, however,
# you need to add a new module add the name of the source module to the
# SRCS parameter and add the name of the resulting object file to the OBJS
# parameter. The new modules are not limited to fortran, but may be C, YACC,
# LEX, or CAL. An explicit rule will need to be added for PASCAL modules.
#
OBJS= rdbfmsua.o


# Tunable parameters
#
# FC Name of the fortran compiling system to use
# LDFLAGS Flags to the loader
# LIBS List of libraries
# CMD Name of the executable
#
FC = ftn
FFLAGS = -g -traceback -I${GEMINC} -I${OS_INC}

BRIDGE=${GEMOLB}/libbridge.a
GFORTRAN=/opt/cray/pe/gcc/10.3.0/snos/lib64/libgfortran.a

LIBS = ${DECOD_UT_LIB} ${BUFR_LIB4} \
-L${GEMOLB} -lgemlib -lappl -lsyslib -lcgemlib ${GFORTRAN} ${BRIDGE}

CMD = rdbfmsua

# To perform the default compilation, use the first line
# To compile with flowtracing turned on, use the second line
# To compile giving profile additonal information, use the third line
# CFLAGS= -O3 -q32

# Lines from here on down should not need to be changed. They are the
# actual rules which make uses to build a.out.
#

$(CMD): $(OBJS)
$(FC) $(LDFLAGS) -o $(@) $(OBJS) $(LIBS)


# The following rule reads the required NAWIPS definitions and then recursively
# runs this same makefile with a new target in the spawned shell.
#

clean:
-rm -f ${OBJS}

clobber: clean
-rm -f ${CMD}

void: clobber
-rm -f ${SRCS} makefile
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit ecabf5a

Please sign in to comment.