Skip to content

Commit

Permalink
Merge branch 'develop' into feature/gdas_init.v16
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeGayno-NOAA committed Jun 1, 2021
2 parents 977b49f + ebc60b8 commit 57fc550
Show file tree
Hide file tree
Showing 3 changed files with 334 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/chgres_cube/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ add_mpi_test(chgres_cube-ftst_convert_winds
NUMPROCS 3
TIMEOUT 60)

add_executable(ftst_read_sfc_nemsio ftst_read_sfc_nemsio.F90)
target_link_libraries(ftst_read_sfc_nemsio chgres_cube_lib)

# Cause test to be run with MPI.
add_mpi_test(chgres_cube-ftst_read_sfc_nemsio
EXECUTABLE ${CMAKE_CURRENT_BINARY_DIR}/ftst_read_sfc_nemsio
NUMPROCS 1
TIMEOUT 60)

add_executable(ftst_read_sfc_netcdf ftst_read_sfc_netcdf.F90)
target_link_libraries(ftst_read_sfc_netcdf chgres_cube_lib)

Expand Down
1 change: 1 addition & 0 deletions tests/chgres_cube/data/files.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
https://ftp.emc.ncep.noaa.gov/static_files/public/UFS/ufs_utils/unit_tests/chgres_cube/gfs.v16.sfc.history.nc
https://ftp.emc.ncep.noaa.gov/static_files/public/UFS/ufs_utils/unit_tests/chgres_cube/gfs.v16.sfc2.history.nc
https://ftp.emc.ncep.noaa.gov/static_files/public/UFS/ufs_utils/unit_tests/chgres_cube/gfs.v16.atm.history.nc
https://ftp.emc.ncep.noaa.gov/static_files/public/UFS/ufs_utils/unit_tests/chgres_cube/gfs.v15.sfc.history.nemsio
324 changes: 324 additions & 0 deletions tests/chgres_cube/ftst_read_sfc_nemsio.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,324 @@
program readsfc_nemsio

! Unit test for the read_input_sfc_gaussian_nemsio_file routine.
!
! Reads a 9x9 version of the FV3GFS nemsio history
! file. This smaller version of the full file was created
! because the full file is too big for Github. The
! data read from the file is compared to expected
! values as determined by nemsio data dump utilities.
!
! Author George Gayno

use esmf

use model_grid, only : i_input, j_input, &
input_grid, &
num_tiles_input_grid

use input_data, only : read_input_sfc_data, &
lsoil_input, &
landsea_mask_input_grid, &
terrain_input_grid, &
soilm_liq_input_grid, &
soilm_tot_input_grid, &
soil_temp_input_grid, &
seaice_fract_input_grid, &
seaice_depth_input_grid, &
seaice_skin_temp_input_grid, &
snow_liq_equiv_input_grid, &
snow_depth_input_grid, &
veg_type_input_grid, &
soil_type_input_grid, &
t2m_input_grid, &
q2m_input_grid, &
tprcp_input_grid, &
f10m_input_grid, &
ffmm_input_grid, &
ustar_input_grid, &
srflag_input_grid, &
skin_temp_input_grid, &
canopy_mc_input_grid, &
z0_input_grid

use program_setup, only : input_type, &
data_dir_input_grid, &
sfc_files_input_grid

implicit none

integer, parameter :: NUM_VALUES=2

real, parameter :: EPSILON=0.001

type(esmf_polekind_flag) :: polekindflag(2)
type(esmf_vm) :: vm

integer :: rc, localpet, npets

real(esmf_kind_r8), allocatable :: data_one_tile(:,:)
real(esmf_kind_r8), allocatable :: data_one_tile_3d(:,:,:)

! The expected values were determined by checking
! the input nemsio file using nemsio data dump utilities.

real :: landsea_mask_expected_values(NUM_VALUES) ! land-sea mask
real :: terrain_expected_values(NUM_VALUES) ! terrain height
real :: soilm_liq1_expected_values(NUM_VALUES) ! layer 1 liquid soil moisture
real :: soilm_liq2_expected_values(NUM_VALUES) ! layer 2 liquid soil moisture
real :: soilm_liq3_expected_values(NUM_VALUES) ! layer 3 liquid soil moisture
real :: soilm_liq4_expected_values(NUM_VALUES) ! layer 4 liquid soil moisture
real :: soilm_tot1_expected_values(NUM_VALUES) ! layer 1 total soil moisture
real :: soilm_tot2_expected_values(NUM_VALUES) ! layer 2 total soil moisture
real :: soilm_tot3_expected_values(NUM_VALUES) ! layer 3 total soil moisture
real :: soilm_tot4_expected_values(NUM_VALUES) ! layer 4 total soil moisture
real :: soil_temp1_expected_values(NUM_VALUES) ! layer 1 soil temperature
real :: soil_temp2_expected_values(NUM_VALUES) ! layer 2 soil temperature
real :: soil_temp3_expected_values(NUM_VALUES) ! layer 3 soil temperature
real :: soil_temp4_expected_values(NUM_VALUES) ! layer 4 soil temperature
real :: seaice_fract_expected_values(NUM_VALUES) ! sea ice fraction
real :: seaice_depth_expected_values(NUM_VALUES) ! sea ice depth
real :: seaice_skin_temp_expected_values(NUM_VALUES) ! sea ice skin temperature
real :: snow_liq_equiv_expected_values(NUM_VALUES) ! liquid equivalent snow depth
real :: snow_depth_expected_values(NUM_VALUES) ! physical snow depth
real :: veg_type_expected_values(NUM_VALUES) ! vegetation type
real :: soil_type_expected_values(NUM_VALUES) ! soil type
real :: t2m_expected_values(NUM_VALUES) ! two-meter temperature
real :: q2m_expected_values(NUM_VALUES) ! two-meter specific humidity
real :: tprcp_expected_values(NUM_VALUES) ! precipitation
real :: f10m_expected_values(NUM_VALUES) ! log((z0+10)*l/z0)
real :: ffmm_expected_values(NUM_VALUES) ! log((z0+z1)*l/z0)
real :: ustar_expected_values(NUM_VALUES) ! friction velocity
real :: srflag_expected_values(NUM_VALUES) ! snow/rain flag
real :: skin_temp_expected_values(NUM_VALUES) ! skin temperature
real :: canopy_mc_expected_values(NUM_VALUES) ! canopy moisture content
real :: z0_expected_values(NUM_VALUES) ! roughness length

data landsea_mask_expected_values /0.0, 0.0/
data terrain_expected_values / 100.0, 100.0 /
data soilm_liq1_expected_values / 0.05, 0.05 /
data soilm_liq2_expected_values / 0.15, 0.15 /
data soilm_liq3_expected_values / 0.25, 0.25 /
data soilm_liq4_expected_values / 0.35, 0.35 /
data soilm_tot1_expected_values / 0.1, 0.1 /
data soilm_tot2_expected_values / 0.2, 0.2 /
data soilm_tot3_expected_values / 0.3, 0.3 /
data soilm_tot4_expected_values / 0.4, 0.4 /
data soil_temp1_expected_values / 265.0, 265.0 /
data soil_temp2_expected_values / 275.0, 275.0 /
data soil_temp3_expected_values / 285.0, 285.0 /
data soil_temp4_expected_values / 295.0, 295.0 /
data seaice_fract_expected_values / 0.75, 0.75 /
data seaice_depth_expected_values / 2.3, 2.3/
data seaice_skin_temp_expected_values / 265.0, 265.0 /
data snow_liq_equiv_expected_values / 2.5, 2.5 /
data snow_depth_expected_values / 2600.0, 2600.0 /
data veg_type_expected_values / 14.0, 14.0 /
data soil_type_expected_values / 4.0, 4.0 /
data t2m_expected_values / 300.0, 300.0 /
data q2m_expected_values / 3.0, 3.0 /
data tprcp_expected_values / 3.1, 3.1 /
data f10m_expected_values / 3.5, 3.5 /
data ffmm_expected_values / 3.2, 3.2 /
data ustar_expected_values / 3.3, 3.3 /
data srflag_expected_values / 0.0, 0.0/
data skin_temp_expected_values / 305.0, 305.0 /
data canopy_mc_expected_values / 0.5, 0.5 /
data z0_expected_values / 370.0, 370.0 /

print*,"Starting test of read_input_sfc_gaussian_nemsio_file."

call mpi_init(rc)

call ESMF_Initialize(rc=rc)

call ESMF_VMGetGlobal(vm, rc=rc)

call ESMF_VMGet(vm, localPet=localpet, petCount=npets, rc=rc)

i_input = 9
j_input = 9

input_type = "gaussian_nemsio"
num_tiles_input_grid = 1
data_dir_input_grid = "data"
sfc_files_input_grid(1) = "gfs.v15.sfc.history.nemsio"

polekindflag(1:2) = ESMF_POLEKIND_MONOPOLE
input_grid = ESMF_GridCreate1PeriDim(minIndex=(/1,1/), &
maxIndex=(/i_input,j_input/), &
polekindflag=polekindflag, &
periodicDim=1, &
poleDim=2, &
coordSys=ESMF_COORDSYS_SPH_DEG, &
regDecomp=(/1,npets/), &
indexflag=ESMF_INDEX_GLOBAL, rc=rc)

! Call the chgres_cube read routine.

call read_input_sfc_data(localpet)

allocate(data_one_tile(i_input,j_input))
allocate(data_one_tile_3d(i_input,j_input,lsoil_input))

call ESMF_FieldGather(terrain_input_grid, data_one_tile, rootPet=0, rc=rc)
if (localpet == 0) then
if (abs(data_one_tile(1,1) - terrain_expected_values(1)) > EPSILON) stop 6
if (abs(data_one_tile(i_input,j_input) - terrain_expected_values(2)) > EPSILON) stop 8
endif

call ESMF_FieldGather(soilm_liq_input_grid, data_one_tile_3d, rootPet=0, rc=rc)
if (localpet == 0) then
if (abs(data_one_tile_3d(1,1,1) - soilm_liq1_expected_values(1)) > EPSILON) stop 10
if (abs(data_one_tile_3d(i_input,j_input,1) - soilm_liq1_expected_values(2)) > EPSILON) stop 11
if (abs(data_one_tile_3d(1,1,2) - soilm_liq2_expected_values(1)) > EPSILON) stop 12
if (abs(data_one_tile_3d(i_input,j_input,2) - soilm_liq2_expected_values(2)) > EPSILON) stop 13
if (abs(data_one_tile_3d(1,1,3) - soilm_liq3_expected_values(1)) > EPSILON) stop 14
if (abs(data_one_tile_3d(i_input,j_input,3) - soilm_liq3_expected_values(2)) > EPSILON) stop 15
if (abs(data_one_tile_3d(1,1,4) - soilm_liq4_expected_values(1)) > EPSILON) stop 16
if (abs(data_one_tile_3d(i_input,j_input,4) - soilm_liq4_expected_values(2)) > EPSILON) stop 17
endif

call ESMF_FieldGather(soilm_tot_input_grid, data_one_tile_3d, rootPet=0, rc=rc)
if (localpet == 0) then
if (abs(data_one_tile_3d(1,1,1) - soilm_tot1_expected_values(1)) > EPSILON) stop 20
if (abs(data_one_tile_3d(i_input,j_input,1) - soilm_tot1_expected_values(2)) > EPSILON) stop 21
if (abs(data_one_tile_3d(1,1,2) - soilm_tot2_expected_values(1)) > EPSILON) stop 22
if (abs(data_one_tile_3d(i_input,j_input,2) - soilm_tot2_expected_values(2)) > EPSILON) stop 23
if (abs(data_one_tile_3d(1,1,3) - soilm_tot3_expected_values(1)) > EPSILON) stop 24
if (abs(data_one_tile_3d(i_input,j_input,3) - soilm_tot3_expected_values(2)) > EPSILON) stop 25
if (abs(data_one_tile_3d(1,1,4) - soilm_tot4_expected_values(1)) > EPSILON) stop 26
if (abs(data_one_tile_3d(i_input,j_input,4) - soilm_tot4_expected_values(2)) > EPSILON) stop 27
endif

call ESMF_FieldGather(soil_temp_input_grid, data_one_tile_3d, rootPet=0, rc=rc)
if (localpet == 0) then
if (abs(data_one_tile_3d(1,1,1) - soil_temp1_expected_values(1)) > EPSILON) stop 30
if (abs(data_one_tile_3d(i_input,j_input,1) - soil_temp1_expected_values(2)) > EPSILON) stop 31
if (abs(data_one_tile_3d(1,1,2) - soil_temp2_expected_values(1)) > EPSILON) stop 32
if (abs(data_one_tile_3d(i_input,j_input,2) - soil_temp2_expected_values(2)) > EPSILON) stop 33
if (abs(data_one_tile_3d(1,1,3) - soil_temp3_expected_values(1)) > EPSILON) stop 34
if (abs(data_one_tile_3d(i_input,j_input,3) - soil_temp3_expected_values(2)) > EPSILON) stop 35
if (abs(data_one_tile_3d(1,1,4) - soil_temp4_expected_values(1)) > EPSILON) stop 36
if (abs(data_one_tile_3d(i_input,j_input,4) - soil_temp4_expected_values(2)) > EPSILON) stop 37
endif

call ESMF_FieldGather(landsea_mask_input_grid, data_one_tile, rootPet=0, rc=rc)
if (localpet == 0) then
if (abs(data_one_tile(1,1) - landsea_mask_expected_values(1)) > EPSILON) stop 39
if (abs(data_one_tile(i_input,j_input) - landsea_mask_expected_values(2)) > EPSILON) stop 40
endif

call ESMF_FieldGather(seaice_fract_input_grid, data_one_tile, rootPet=0, rc=rc)
if (localpet == 0) then
if (abs(data_one_tile(1,1) - seaice_fract_expected_values(1)) > EPSILON) stop 41
if (abs(data_one_tile(i_input,j_input) - seaice_fract_expected_values(2)) > EPSILON) stop 42
endif

call ESMF_FieldGather(seaice_depth_input_grid, data_one_tile, rootPet=0, rc=rc)
if (localpet == 0) then
if (abs(data_one_tile(1,1) - seaice_depth_expected_values(1)) > EPSILON) stop 43
if (abs(data_one_tile(i_input,j_input) - seaice_depth_expected_values(2)) > EPSILON) stop 44
endif

call ESMF_FieldGather(seaice_skin_temp_input_grid, data_one_tile, rootPet=0, rc=rc)
if (localpet == 0) then
if (abs(data_one_tile(1,1) - seaice_skin_temp_expected_values(1)) > EPSILON) stop 45
if (abs(data_one_tile(i_input,j_input) - seaice_skin_temp_expected_values(2)) > EPSILON) stop 46
endif

call ESMF_FieldGather(snow_liq_equiv_input_grid, data_one_tile, rootPet=0, rc=rc)
if (localpet == 0) then
if (abs(data_one_tile(1,1) - snow_liq_equiv_expected_values(1)) > EPSILON) stop 47
if (abs(data_one_tile(i_input,j_input) - snow_liq_equiv_expected_values(2)) > EPSILON) stop 48
endif

call ESMF_FieldGather(snow_depth_input_grid, data_one_tile, rootPet=0, rc=rc)
if (localpet == 0) then
if (abs(data_one_tile(1,1) - snow_depth_expected_values(1)) > EPSILON) stop 49
if (abs(data_one_tile(i_input,j_input) - snow_depth_expected_values(2)) > EPSILON) stop 50
endif

call ESMF_FieldGather(veg_type_input_grid, data_one_tile, rootPet=0, rc=rc)
if (localpet == 0) then
if (abs(data_one_tile(1,1) - veg_type_expected_values(1)) > EPSILON) stop 51
if (abs(data_one_tile(i_input,j_input) - veg_type_expected_values(2)) > EPSILON) stop 52
endif

call ESMF_FieldGather(soil_type_input_grid, data_one_tile, rootPet=0, rc=rc)
if (localpet == 0) then
if (abs(data_one_tile(1,1) - soil_type_expected_values(1)) > EPSILON) stop 53
if (abs(data_one_tile(i_input,j_input) - soil_type_expected_values(2)) > EPSILON) stop 54
endif

call ESMF_FieldGather(t2m_input_grid, data_one_tile, rootPet=0, rc=rc)
if (localpet == 0) then
if (abs(data_one_tile(1,1) - t2m_expected_values(1)) > EPSILON) stop 55
if (abs(data_one_tile(i_input,j_input) - t2m_expected_values(2)) > EPSILON) stop 56
endif

call ESMF_FieldGather(q2m_input_grid, data_one_tile, rootPet=0, rc=rc)
if (localpet == 0) then
if (abs(data_one_tile(1,1) - q2m_expected_values(1)) > EPSILON) stop 57
if (abs(data_one_tile(i_input,j_input) - q2m_expected_values(2)) > EPSILON) stop 58
endif

call ESMF_FieldGather(tprcp_input_grid, data_one_tile, rootPet=0, rc=rc)
if (localpet == 0) then
if (abs(data_one_tile(1,1) - tprcp_expected_values(1)) > EPSILON) stop 59
if (abs(data_one_tile(i_input,j_input) - tprcp_expected_values(2)) > EPSILON) stop 60
endif

call ESMF_FieldGather(f10m_input_grid, data_one_tile, rootPet=0, rc=rc)
if (localpet == 0) then
if (abs(data_one_tile(1,1) - f10m_expected_values(1)) > EPSILON) stop 61
if (abs(data_one_tile(i_input,j_input) - f10m_expected_values(2)) > EPSILON) stop 62
endif

call ESMF_FieldGather(ffmm_input_grid, data_one_tile, rootPet=0, rc=rc)
if (localpet == 0) then
if (abs(data_one_tile(1,1) - ffmm_expected_values(1)) > EPSILON) stop 63
if (abs(data_one_tile(i_input,j_input) - ffmm_expected_values(2)) > EPSILON) stop 64
endif

call ESMF_FieldGather(ustar_input_grid, data_one_tile, rootPet=0, rc=rc)
if (localpet == 0) then
if (abs(data_one_tile(1,1) - ustar_expected_values(1)) > EPSILON) stop 65
if (abs(data_one_tile(i_input,j_input) - ustar_expected_values(2)) > EPSILON) stop 66
endif

call ESMF_FieldGather(srflag_input_grid, data_one_tile, rootPet=0, rc=rc)
if (localpet == 0) then
if (abs(data_one_tile(1,1) - srflag_expected_values(1)) > EPSILON) stop 67
if (abs(data_one_tile(i_input,j_input) - srflag_expected_values(2)) > EPSILON) stop 68
endif

call ESMF_FieldGather(skin_temp_input_grid, data_one_tile, rootPet=0, rc=rc)
if (localpet == 0) then
if (abs(data_one_tile(1,1) - skin_temp_expected_values(1)) > EPSILON) stop 69
if (abs(data_one_tile(i_input,j_input) - skin_temp_expected_values(2)) > EPSILON) stop 70
endif

call ESMF_FieldGather(canopy_mc_input_grid, data_one_tile, rootPet=0, rc=rc)
if (localpet == 0) then
if (abs(data_one_tile(1,1) - canopy_mc_expected_values(1)) > EPSILON) stop 71
if (abs(data_one_tile(i_input,j_input) - canopy_mc_expected_values(2)) > EPSILON) stop 72
endif

call ESMF_FieldGather(z0_input_grid, data_one_tile, rootPet=0, rc=rc)
if (localpet == 0) then
if (abs(data_one_tile(1,1) - z0_expected_values(1)) > EPSILON) stop 73
if (abs(data_one_tile(i_input,j_input) - z0_expected_values(2)) > EPSILON) stop 74
endif

print*,"OK"

deallocate(data_one_tile, data_one_tile_3d)

call ESMF_finalize(endflag=ESMF_END_KEEPMPI)

call mpi_finalize(rc)

print*,"SUCCESS!"

end program readsfc_nemsio

0 comments on commit 57fc550

Please sign in to comment.