Skip to content

Commit

Permalink
Merge branch 'develop' into feature/stack
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeGayno-NOAA committed Apr 28, 2021
2 parents d1dcec5 + 03e862f commit 0f6a865
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 22 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ endif()

# Find packages.
find_package(NetCDF 4.3.3 REQUIRED C Fortran)
find_package(MPI 3.0 REQUIRED C Fortran)
find_package(ESMF MODULE REQUIRED)
find_package(MPI REQUIRED C Fortran)
find_package(ESMF 8.0.0 REQUIRED)

if(OPENMP)
find_package(OpenMP 4.5 REQUIRED COMPONENTS Fortran)
Expand All @@ -56,7 +56,7 @@ endif()
find_package(sfcio 1.4.0 REQUIRED)
find_package(w3nco 2.4.0 REQUIRED)
find_package(bacio 2.4.0 REQUIRED)
find_package(nemsio 2.5.1 REQUIRED)
find_package(nemsio 2.5.0 REQUIRED)
find_package(sigio 2.3.0 REQUIRED)
find_package(sp 2.3.3 REQUIRED)
find_package(ip 3.3.3 REQUIRED)
Expand Down
31 changes: 28 additions & 3 deletions cmake/FindESMF.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ if (ESMF_FOUND)
endif()
endforeach()

# Construct ESMF_VERSION from ESMF_VERSION_STRING_GIT
if(ESMF_FOUND)
# ESMF_VERSION_MAJOR and ESMF_VERSION_MINOR are defined in ESMFMKFILE
set(ESMF_VERSION 0)
set(ESMF_VERSION_PATCH ${ESMF_VERSION_REVISION})
set(ESMF_BETA_RELEASE FALSE)
if(ESMF_VERSION_BETASNAPSHOT MATCHES "^('T')$")
set(ESMF_BETA_RELEASE TRUE)
string(REGEX REPLACE ".*beta_snapshot_*\([0-9]*\).*" "\\1" ESMF_BETA_SNAPSHOT "${ESMF_VERSION_STRING_GIT}")
endif()
set(ESMF_VERSION "${ESMF_VERSION_MAJOR}.${ESMF_VERSION_MINOR}.${ESMF_VERSION_PATCH}")
endif()

separate_arguments(ESMF_F90COMPILEPATHS NATIVE_COMMAND ${ESMF_F90COMPILEPATHS})
foreach (ITEM ${ESMF_F90COMPILEPATHS})
string(REGEX REPLACE "^-I" "" ITEM "${ITEM}")
Expand All @@ -87,14 +100,16 @@ if (ESMF_FOUND)
find_library(esmf_lib NAMES esmf_fullylinked PATHS ${ESMF_LIBSDIR})
if(esmf_lib MATCHES "esmf_lib-NOTFOUND")
message(FATAL_ERROR "Neither the dynamic nor the static ESMF library was found")
else()
message(STATUS "Found ESMF library: ${esmf_lib}")
endif()
set(ESMF_INTERFACE_LINK_LIBRARIES "")
else()
# When linking the static library, also need the ESMF linker flags; strip any leading/trailing whitespaces
string(STRIP "${ESMF_F90ESMFLINKRPATHS} ${ESMF_F90ESMFLINKPATHS} ${ESMF_F90LINKPATHS} ${ESMF_F90LINKLIBS} ${ESMF_F90LINKOPTS}" ESMF_INTERFACE_LINK_LIBRARIES)
message(STATUS "Found ESMF library: ${esmf_lib}")
endif()

message(STATUS "Found ESMF library: ${esmf_lib}")
if(ESMF_BETA_RELEASE)
message(STATUS "Detected ESMF Beta snapshot ${ESMF_BETA_SNAPSHOT}")
endif()

set_target_properties(esmf PROPERTIES
Expand All @@ -103,3 +118,13 @@ if (ESMF_FOUND)
INTERFACE_LINK_LIBRARIES "${ESMF_INTERFACE_LINK_LIBRARIES}")

endif()

## Finalize find_package
include(FindPackageHandleStandardArgs)

find_package_handle_standard_args( ${CMAKE_FIND_PACKAGE_NAME}
REQUIRED_VARS ESMF_LIBSDIR
ESMF_INTERFACE_LINK_LIBRARIES
ESMF_F90COMPILEPATHS
VERSION_VAR ESMF_VERSION
HANDLE_COMPONENTS )
3 changes: 1 addition & 2 deletions modulefiles/build.wcoss_cray.intel
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module load cray-mpich/7.2.0
module load craype-haswell
module load alps/5.2.4-2.0502.9822.32.1.ari
module load cray-netcdf/4.3.3.1
module load cray-hdf5/1.8.14
module load cray-hdf5/1.8.14

module use /usrx/local/nceplibs/NCEPLIBS/cmake/install/NCEPLIBS-v1.2.0/modules
module load bacio/2.4.1
Expand All @@ -34,6 +34,5 @@ setenv Jasper_ROOT /usrx/local/prod/jasper/1.900.1/intel/haswell
module use /gpfs/hps3/emc/nems/noscrub/emc.nemspara/soft/modulefiles
#module load esmf/8.0.0
setenv ESMFMKFILE /gpfs/hps3/emc/nems/noscrub/emc.nemspara/soft/esmf/8.0.0/lib/esmf.mk
setenv NETCDF /opt/cray/netcdf/4.3.3.1/INTEL/14.0
module rm gcc
module load gcc/6.3.0
5 changes: 5 additions & 0 deletions sorc/chgres_cube.fd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ if(CMAKE_Fortran_COMPILER_ID MATCHES "^(Intel)$")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -r8 -convert big_endian -assume byterecl")
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^(GNU)$")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -ffree-line-length-0 -fdefault-real-8 -fconvert=big-endian")

# Turn on this argument mismatch flag for gfortran10.
if(CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER_EQUAL 10)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fallow-argument-mismatch")
endif()
endif()

set(exe_name chgres_cube)
Expand Down
58 changes: 45 additions & 13 deletions sorc/chgres_cube.fd/input_data.F90
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ module input_data

private

public :: check_soilt

! Fields associated with the atmospheric model.

type(esmf_field), public :: dzdt_input_grid !< vert velocity
Expand All @@ -69,7 +71,8 @@ module input_data
integer, public :: veg_type_landice_input = 15 !< NOAH land ice option
!< defined at this veg type.
!< Default is igbp.

integer, parameter :: ICET_DEFAULT = 265.0 !< Default value of soil and skin
!< temperature (K) over ice.
type(esmf_field), public :: canopy_mc_input_grid !< canopy moist content
type(esmf_field), public :: f10m_input_grid !< log((z0+10)*1/z0)
type(esmf_field), public :: ffmm_input_grid !< log((z0+z1)*1/z0)
Expand Down Expand Up @@ -4597,15 +4600,15 @@ subroutine read_input_sfc_grib2_file(localpet)

integer :: rc, varnum, iret, i, j,k
integer :: ncid2d, varid, varsize
integer, parameter :: icet_default = 265.0
!integer, parameter :: icet_default = 265.0

logical :: exist, rap_latlon

real(esmf_kind_r4) :: value

real(esmf_kind_r4), allocatable :: dummy2d(:,:),tsk_save(:,:),icec_save(:,:)
real(esmf_kind_r4), allocatable :: dummy2d(:,:),icec_save(:,:)
real(esmf_kind_r4), allocatable :: dummy1d(:)
real(esmf_kind_r8), allocatable :: dummy2d_8(:,:),dummy2d_82(:,:)
real(esmf_kind_r8), allocatable :: dummy2d_8(:,:),dummy2d_82(:,:),tsk_save(:,:)
real(esmf_kind_r8), allocatable :: dummy3d(:,:,:), dummy3d_stype(:,:,:)
integer(esmf_kind_i4), allocatable :: slmsk_save(:,:)
integer(esmf_kind_i8), allocatable :: dummy2d_i(:,:)
Expand Down Expand Up @@ -4834,7 +4837,7 @@ subroutine read_input_sfc_grib2_file(localpet)
print*,"- READ SKIN TEMPERATURE."
rc = grb2_inq(the_file, inv_file, ':TMP:',':surface:', data2=dummy2d)
if (rc <= 0 ) call error_handler("READING SKIN TEMPERATURE.", rc)
tsk_save(:,:) = dummy2d
tsk_save(:,:) = real(dummy2d,esmf_kind_r8)
dummy2d_8 = real(dummy2d,esmf_kind_r8)
do j = 1, j_input
do i = 1, i_input
Expand Down Expand Up @@ -5390,14 +5393,7 @@ subroutine read_input_sfc_grib2_file(localpet)
vname = "soilt"
vname_file = ":TSOIL:"
call read_grib_soil(the_file,inv_file,vname,vname_file,dummy3d,rc)
do k=1,lsoil_input
do j = 1, j_input
do i = 1, i_input
if (slmsk_save(i,j) == 0_esmf_kind_i4 ) dummy3d(i,j,k) = tsk_save(i,j)
if (slmsk_save(i,j) == 2_esmf_kind_i4 ) dummy3d(i,j,k) = icet_default
enddo
enddo
enddo
call check_soilt(dummy3d,slmsk_save,tsk_save)
print*,'soilt ',maxval(dummy3d),minval(dummy3d)

deallocate(tsk_save, slmsk_save)
Expand Down Expand Up @@ -6607,4 +6603,40 @@ recursive subroutine quicksort(a, first, last)
if (j+1 < last) call quicksort(a, j+1, last)
end subroutine quicksort

!> Check for and replace certain values in soil temperature.
!> At open water points (landmask=0) use skin temperature as
!> a filler value. At land points (landmask=1) with excessive
!> soil temperature, replace soil temperature with skin temperature.
!> In GEFSv12.0 data there are some erroneous missing values at
!> land points which this corrects. At sea ice points (landmask=2),
!> store a default ice column temperature because grib2 files do not
!> have ice column temperature which FV3 expects at these points.
!!
!! @param soilt [inout] 3-dimensional soil temperature arrray
!! @param landmask [in] landmask of the input grid
!! @param skint [in] 2-dimensional skin temperature array
!! @author Larissa Reames CIMMS/NSSL

subroutine check_soilt(soilt, landmask, skint)
implicit none
real(esmf_kind_r8), intent(inout) :: soilt(i_input,j_input,lsoil_input)
real(esmf_kind_r8), intent(in) :: skint(i_input,j_input)
integer(esmf_kind_i4), intent(in) :: landmask(i_input,j_input)

integer :: i, j, k

do k=1,lsoil_input
do j = 1, j_input
do i = 1, i_input
if (landmask(i,j) == 0_esmf_kind_i4 ) then
soilt(i,j,k) = skint(i,j)
else if (landmask(i,j) == 1_esmf_kind_i4 .and. soilt(i,j,k) > 350.0_esmf_kind_r8) then
soilt(i,j,k) = skint(i,j)
else if (landmask(i,j) == 2_esmf_kind_i4 ) then
soilt(i,j,k) = ICET_DEFAULT
endif
enddo
enddo
enddo
end subroutine check_soilt
end module input_data
12 changes: 11 additions & 1 deletion tests/chgres_cube/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This is the cmake build file for the tests directory of the
# UFS_UTILS project.
#
# George Gayno, Lin Gan, Ed Hartnett
# George Gayno, Lin Gan, Ed Hartnett, Larissa Reames

# Include cmake to allow parallel I/O tests.
include (LibMPI)
Expand Down Expand Up @@ -58,3 +58,13 @@ add_mpi_test(ftst_search_util
EXECUTABLE ${CMAKE_CURRENT_BINARY_DIR}/ftst_search_util
NUMPROCS 1
TIMEOUT 60)

add_executable(ftst_sfc_input_data ftst_sfc_input_data.F90)
target_link_libraries(ftst_sfc_input_data
chgres_cube_lib)

# Cause test to be run with MPI.
add_mpi_test(ftst_sfc_input_data
EXECUTABLE ${CMAKE_CURRENT_BINARY_DIR}/ftst_sfc_input_data
NUMPROCS 4
TIMEOUT 60)
93 changes: 93 additions & 0 deletions tests/chgres_cube/ftst_sfc_input_data.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
program test_sfc_input_data

! Test sfc_input_data. For now only one test is performed
! on the subroutine soilt_check using a sample 3x3 matrix.
!
! author: Larissa Reames (larissa.reames@noaa.gov)

use mpi
use esmf
use input_data
use model_grid

implicit none

integer :: ierr

integer(esmf_kind_i4), allocatable :: mask(:,:)
real(esmf_kind_r8), allocatable :: soilt_bad(:,:,:), &
soilt_updated(:,:,:), &
soilt_correct(:,:,:)
real(esmf_kind_r8), allocatable :: skint(:,:)

call mpi_init(ierr)

lsoil_input = 2
i_input = 3
j_input = 3

allocate(mask(i_input,j_input))
allocate(skint(i_input,j_input))
allocate(soilt_bad(i_input,j_input,lsoil_input))
allocate(soilt_updated(i_input,j_input,lsoil_input))
allocate(soilt_correct(i_input,j_input,lsoil_input))

!--------------------------------------------------------
! These variables are used to test all three functions of
! the check_soilt routine (i.e., replace water point
! temperature and excessive land point soil temperature
! with skin temperature and store a default ice column
! temperature in the soil temperature array at sea ice
! points since this array isn't available in grib2 files)
!--------------------------------------------------------

! Definition of the mask. The '0' indicates open water, '1'
! any land point, and '2' sea ice.

mask = reshape((/0, 1, 0, 0, 0, 1, 0, 0, 2/),(/3,3/))

! Soil temperature array with some values that are all incorrect
! based on landmask type. This will be the input soil array

soilt_bad(1:i_input,1:j_input,1) = reshape((/0., 9999999.9, 0., &
0., 0., 295.0, &
0., 25.0, 25.0 /),(/3,3/))
soilt_bad(1:i_input,1:j_input,2) = reshape((/0., 9999999.9, 0., &
0., 0., 295.0, &
0., 25.0, 25.0 /),(/3,3/))

! Subjective, reasonable skin temperature array.

skint = reshape((/285.0, 295.0, 280.0, 281.0, 282.0, 283.0, 284.0, 285.0, 260.0/), &
(/3,3/))

!--------------------------------------------------------
! This is the corrected soil temperature array that
! should be passed back from the check_soilt routine
!--------------------------------------------------------

soilt_correct(1:i_input,1:j_input,1) = reshape( (/285.0, 295.0, 280.0, &
281.0, 282.0, 295.0, &
284.0, 285.0, 265.0/), (/3,3/))
soilt_correct(1:i_input,1:j_input,2) = reshape( (/285.0, 295.0, 280.0, &
281.0, 282.0, 295.0, &
284.0, 285.0, 265.0/), (/3,3/))


print*,"Starting test of check_soilt subroutine."

soilt_updated = soilt_bad
call check_soilt(soilt_updated,mask,skint)

if (any(soilt_updated /= soilt_correct)) then
print*,'TEST FAILED '
print*,'ARRAY SHOULD BE:', soilt_correct
print*,'ARRAY FROM TEST:', soilt_updated
stop 2
endif

call mpi_finalize(ierr)

print*,"SUCCESS!"

end program test_sfc_input_data

0 comments on commit 0f6a865

Please sign in to comment.