Skip to content

Commit

Permalink
Adding hafs_datool and hafs_vi to CMake based build
Browse files Browse the repository at this point in the history
  • Loading branch information
BijuThomas-NOAA committed Feb 15, 2022
1 parent ce20bb8 commit f5821a8
Show file tree
Hide file tree
Showing 12 changed files with 474 additions and 6 deletions.
12 changes: 6 additions & 6 deletions sorc/build_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export HDF5_INCLUDE=${HDF5_INCLUDE:-"-I${HDF5_INCLUDES:-"-I${HDF5}/include"}}"}
#export HDF5_LDFLAGS=${HDF5_LDFLAGS:-"-L${HDF5}/lib -lhdf5_hl -lhdf5hl_fortran -lhdf5 -lhdf5_fortran"}
export HDF5_LDFLAGS=${HDF5_LDFLAGS:-"-L${HDF5_LIBRARIES:-"${HDF5}/lib"} -lhdf5_hl -lhdf5"}
export BUFR_LDFLAGS="${BUFR_LIBd}"
export ZLIB_INCLUDE=${ZLIB_INCLUDE:-"-I${ZLIB_INCLUDES:--I${ZLIB_ROOT}/include}"}
export ZLIB_LDFLAGS=${ZLIB_LDFLAGS:-"-L${ZLIB_LIBRARIES:--L${ZLIB_ROOT}/lib} -lz -ldl -lm"}
#export ZLIB_INCLUDE=${ZLIB_INCLUDE:-"-I${ZLIB_INCLUDES:--I${ZLIB_ROOT}/include}"}
#export ZLIB_LDFLAGS=${ZLIB_LDFLAGS:-"-L${ZLIB_LIBRARIES:--L${ZLIB_ROOT}/lib} -lz -ldl -lm"}

TOOLS_PATH=${cwd}/hafs_tools.fd
export TOOLS_INC=${TOOLS_PATH}/include
Expand All @@ -62,10 +62,10 @@ cd ${TOOLS_PATH}/sorc

./build_hafs_utils.sh

cd ${TOOLS_PATH}/sorc/hafs_datool
./build_hafs_datool.sh
#cd ${TOOLS_PATH}/sorc/hafs_datool
#./build_hafs_datool.sh

cd ${TOOLS_PATH}/sorc/hafs_vi
make
#cd ${TOOLS_PATH}/sorc/hafs_vi
#make

exit
98 changes: 98 additions & 0 deletions sorc/hafs_tools.fd/sorc/build_hafs_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
## * Removing sources that are not needed or no longer used
## * Merging internal libraries into a single folder with a single driver script
## * Ported hafs_change_prepbufr under hafs_tools.fd from HWRF (2021-06-07)
## Added hafs_datool to CMake based build: Biju Thomas 2022-01-25
#################################################################################

set -x -e
Expand Down Expand Up @@ -177,6 +178,95 @@ _hafsutils_change_prepbufr (){
make install
}


#----

# FUNCTION:

# _hafsutils_datool.sh

# DESCRIPTION:

# This function compiles and install the HAFS utility datool
# application.

# NOTE:

# This function should never be called directly by the user and is for
# internal use only within this script.

_hafsutils_datool (){

# Remove the build dir if it exists from previous build
if [ -d "${HAFS_UTILS_SORC}/build" ]; then
rm -rf ${HAFS_UTILS_SORC}/build
fi

# Create a build directory for a fresh build
mkdir ${HAFS_UTILS_SORC}/build

cd ${HAFS_UTILS_SORC}/build

# Generate makefile using CMake for the application
# BUILD_TYPE supports RELEASE OR DEBUG MODE
if [[ $target = "wcoss_cray" ]]; then
cmake ../hafs_datool -DCMAKE_Fortran_COMPILER=ftn -DCMAKE_C_COMPILER=cc -DBUILD_TYPE=RELEASE
else
cmake ../hafs_datool -DCMAKE_Fortran_COMPILER=ifort -DCMAKE_C_COMPILER=icc -DBUILD_TYPE=RELEASE
fi

# Build the hafs_datool application.
make all VERBOSE=3

# Move the hafs_datool application executable to the HAFS
# utility application executables path.
make install
}

#----

# FUNCTION:

# _hafsutils_vi.sh

# DESCRIPTION:

# This function compiles and install the HAFS utility datool
# application.

# NOTE:

# This function should never be called directly by the user and is for
# internal use only within this script.

_hafsutils_vi (){

# Remove the build dir if it exists from previous build
if [ -d "${HAFS_UTILS_SORC}/build" ]; then
rm -rf ${HAFS_UTILS_SORC}/build
fi

# Create a build directory for a fresh build
mkdir ${HAFS_UTILS_SORC}/build

cd ${HAFS_UTILS_SORC}/build

# Generate makefile using CMake for the application
# BUILD_TYPE supports RELEASE OR DEBUG MODE
if [[ $target = "wcoss_cray" ]]; then
cmake ../hafs_vi -DCMAKE_Fortran_COMPILER=ftn -DCMAKE_C_COMPILER=cc -DBUILD_TYPE=RELEASE
else
cmake ../hafs_vi -DCMAKE_Fortran_COMPILER=ifort -DCMAKE_C_COMPILER=icc -DBUILD_TYPE=RELEASE
fi

# Build the hafs_datool application.
make all VERBOSE=3

# Move the hafs_datool application executable to the HAFS
# utility application executables path.
make install
}

#----


Expand Down Expand Up @@ -212,6 +302,14 @@ build_hafsutils (){
# Build the change_prepbufr application.

_hafsutils_change_prepbufr

# Build the datool application.

_hafsutils_datool

# Build the vi application.

_hafsutils_vi

}

Expand Down
76 changes: 76 additions & 0 deletions sorc/hafs_tools.fd/sorc/cmake/Modules/FindMKL.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# (C) Copyright 2011- ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.

# - Try to find MKL
# Once done this will define
#
# MKL_FOUND - system has Intel MKL
# MKL_INCLUDE_DIRS - the MKL include directories
# MKL_LIBRARIES - link these to use MKL
#
# The following paths will be searched with priority if set in CMake or env
#
# MKLROOT - root directory of the MKL installation
# MKL_PATH - root directory of the MKL installation
# MKL_ROOT - root directory of the MKL installation

option( MKL_PARALLEL "if mkl shoudl be parallel" OFF )

if( MKL_PARALLEL )

set( __mkl_lib_par MKL_LIB_INTEL_THREAD )
set( __mkl_lib_name mkl_intel_thread )

find_package(Threads)

else()

set( __mkl_lib_par MKL_LIB_SEQUENTIAL )
set( __mkl_lib_name mkl_sequential )

endif()

# Search with priority for MKLROOT, MKL_PATH and MKL_ROOT if set in CMake or env
find_path(MKL_INCLUDE_DIR mkl.h
PATHS ${MKLROOT} ${MKL_PATH} ${MKL_ROOT} ENV MKLROOT ENV MKL_PATH ENV MKL_ROOT
PATH_SUFFIXES include NO_DEFAULT_PATH)
find_path(MKL_INCLUDE_DIR mkl.h
PATH_SUFFIXES include)

if( MKL_INCLUDE_DIR ) # use include dir to find libs

set( MKL_INCLUDE_DIRS ${MKL_INCLUDE_DIR} )

if( CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" )
get_filename_component( MKL_LIB_PATH ${MKL_INCLUDE_DIR}/../lib/intel64 ABSOLUTE )
set( __libsfx _lp64 )
else()
get_filename_component( MKL_LIB_PATH ${MKL_INCLUDE_DIR}/../lib/ia32 ABSOLUTE )
set( __libsfx "" )
endif()

find_library( MKL_LIB_INTEL NAMES mkl_intel${__libsfx} PATHS ${MKL_LIB_PATH} )
find_library( ${__mkl_lib_par} NAMES ${__mkl_lib_name} PATHS ${MKL_LIB_PATH} )
find_library( MKL_LIB_CORE NAMES mkl_core PATHS ${MKL_LIB_PATH} )

if( MKL_PARALLEL )
find_library( MKL_LIB_IOMP5 NAMES iomp5 PATHS ${MKL_LIB_PATH} )
endif()

if( MKL_LIB_INTEL AND ${__mkl_lib_par} AND MKL_LIB_CORE )
set( MKL_LIBRARIES ${MKL_LIB_INTEL} ${${__mkl_lib_par}} ${MKL_LIB_CORE} ${MKL_LIB_IOMP5} ${CMAKE_THREAD_LIBS_INIT} )
endif()

endif()

include(FindPackageHandleStandardArgs)

find_package_handle_standard_args( MKL DEFAULT_MSG
MKL_LIBRARIES MKL_INCLUDE_DIRS )

mark_as_advanced( MKL_INCLUDE_DIR MKL_LIB_LAPACK MKL_LIB_INTEL MKL_LIB_SEQUENTIAL MKL_LIB_CORE )
56 changes: 56 additions & 0 deletions sorc/hafs_tools.fd/sorc/hafs_datool/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#=======================================================================
#$$$ CMAKEFILE DOCUMENTATION BLOCK
# Biju Thomas
# Email: [email protected]
#=======================================================================

cmake_minimum_required(VERSION 3.15)
project(
DATOOL
LANGUAGES C Fortran)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Modules/")

if(NOT CMAKE_Fortran_COMPILER_ID MATCHES "^(Intel|GNU)$")
message(WARNING "Compiler not officially supported: ${CMAKE_Fortran_COMPILER_ID}")
endif()

if(NOT CMAKE_C_COMPILER_ID MATCHES "^(Intel|GNU)$")
message(WARNING "Compiler not officially supported: ${CMAKE_C_COMPILER_ID}")
endif()

find_package(NetCDF REQUIRED C Fortran)
find_package(MPI REQUIRED)

set(fortran_srcs
module_mpi.f90
module_structure.f90
sub_tcinfo.f90
sub_netcdf.f90
sub_tools.f90
sub_grids.f90
sub_wind_process.f90
sub_hafs_remap.f90
sub_hafsvi_proc.f90
hafs_datool.f90)

set(exe_name hafs_datool.x)
set(exec_dir ${CMAKE_CURRENT_SOURCE_DIR}/../../exec)

add_executable(${exe_name} ${fortran_srcs})

target_compile_options(${exe_name} PRIVATE
$<$<STREQUAL:${BUILD_TYPE},DEBUG>:-g> $<$<STREQUAL:${BUILD_TYPE},RELEASE>:-O3>
-traceback -fp-model precise -assume byterecl -convert big_endian)

target_link_options(${exe_name} PRIVATE
$<$<STREQUAL:${BUILD_TYPE},DEBUG>:-g> $<$<STREQUAL:${BUILD_TYPE},RELEASE>:-O3>
-traceback -fp-model precise -assume byterecl -convert big_endian)

target_link_libraries(
${exe_name} PRIVATE
NetCDF::NetCDF_Fortran
NetCDF::NetCDF_C
MPI::MPI_Fortran)

install(TARGETS ${exe_name} DESTINATION ${exec_dir})
35 changes: 35 additions & 0 deletions sorc/hafs_tools.fd/sorc/hafs_vi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#=======================================================================
#$$$ CMAKEFILE DOCUMENTATION BLOCK
# Biju Thomas
# Email: [email protected]
#=======================================================================

cmake_minimum_required(VERSION 3.15)
project(
HAFS_VI
LANGUAGES C Fortran)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Modules/")

message(CMAKE_MODULE_PATH " ${CMAKE_MODULE_PATH}")
if(NOT CMAKE_Fortran_COMPILER_ID MATCHES "^(Intel|GNU)$")
message(WARNING "Compiler not officially supported: ${CMAKE_Fortran_COMPILER_ID}")
endif()

if(NOT CMAKE_C_COMPILER_ID MATCHES "^(Intel|GNU)$")
message(WARNING "Compiler not officially supported: ${CMAKE_C_COMPILER_ID}")
endif()


#find_package(NetCDF REQUIRED C Fortran)
#find_package(MPI REQUIRED)
find_package(OpenMP REQUIRED)
find_package(MKL REQUIRED)

add_subdirectory(create_trak_guess)
add_subdirectory(create_trak_init)
add_subdirectory(split)
add_subdirectory(anl_pert)
add_subdirectory(anl_combine)
add_subdirectory(anl_enhance)
add_subdirectory(anl_bogus)
27 changes: 27 additions & 0 deletions sorc/hafs_tools.fd/sorc/hafs_vi/anl_bogus/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#=======================================================================
#$$$ CMAKEFILE DOCUMENTATION BLOCK
# Biju Thomas
# Email: [email protected]
#=======================================================================


set(fortran_srcs
anl_bogus.f90
convert_axi_xy.f90
correct_mat_2.f90
interp_coef_agrid.f90)

set(exe_name hafs_vi_anl_bogus.x)
set(exec_dir ${CMAKE_CURRENT_SOURCE_DIR}/../../../exec)

add_executable(${exe_name} ${fortran_srcs})

target_compile_options(${exe_name} PRIVATE
$<$<STREQUAL:${BUILD_TYPE},DEBUG>:-g -check all> $<$<STREQUAL:${BUILD_TYPE},RELEASE>:-O3>
-traceback -fp-model precise -assume byterecl -convert big_endian)

target_link_options(${exe_name} PRIVATE
$<$<STREQUAL:${BUILD_TYPE},DEBUG>:-g -check all> $<$<STREQUAL:${BUILD_TYPE},RELEASE>:-O3>
-traceback -fp-model precise -assume byterecl -convert big_endian)

install(TARGETS ${exe_name} DESTINATION ${exec_dir})
32 changes: 32 additions & 0 deletions sorc/hafs_tools.fd/sorc/hafs_vi/anl_combine/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#=======================================================================
#$$$ CMAKEFILE DOCUMENTATION BLOCK
# Biju Thomas
# Email: [email protected]
#=======================================================================


set(fortran_srcs
anl_combine.f90
split_sym_asy.f90
correct_mat.f90
interp_coef_agrid.f90
fill_nmm_gridg.f90)

set(exe_name hafs_vi_anl_combine.x)
set(exec_dir ${CMAKE_CURRENT_SOURCE_DIR}/../../../exec)

add_executable(${exe_name} ${fortran_srcs})

target_compile_options(${exe_name} PRIVATE
$<$<STREQUAL:${BUILD_TYPE},DEBUG>:-g -check all> $<$<STREQUAL:${BUILD_TYPE},RELEASE>:-O3>
-traceback -fp-model precise -assume byterecl -convert big_endian)

target_link_options(${exe_name} PRIVATE
$<$<STREQUAL:${BUILD_TYPE},DEBUG>:-g -check all> $<$<STREQUAL:${BUILD_TYPE},RELEASE>:-O3>
-traceback -fp-model precise -assume byterecl -convert big_endian)

target_link_libraries(
${exe_name} PRIVATE
OpenMP::OpenMP_Fortran)

install(TARGETS ${exe_name} DESTINATION ${exec_dir})
Loading

0 comments on commit f5821a8

Please sign in to comment.