Skip to content

Commit

Permalink
Add unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeGayno-NOAA committed May 5, 2022
1 parent fad9932 commit de25b36
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ add_subdirectory(chgres_cube)
add_subdirectory(fre-nctools)
add_subdirectory(global_cycle)
add_subdirectory(sfc_climo_gen)
add_subdirectory(emcsfc_snow2mdl)
19 changes: 19 additions & 0 deletions tests/emcsfc_snow2mdl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This is the cmake build file for the tests directory of the
# UFS_UTILS project.
#
# George Gayno

if(CMAKE_Fortran_COMPILER_ID MATCHES "^(Intel)$")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -r8 -assume byterecl")
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^(GNU)$")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -ffree-line-length-0 -fdefault-real-8")
endif()

# Copy necessary test files from the source data directory to the
# build data directory.
execute_process( COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/data/config.nml ${CMAKE_CURRENT_BINARY_DIR}/fort.41)

add_executable(ftst_program_setup_snow ftst_program_setup.F90)
target_link_libraries(ftst_program_setup_snow snow2mdl_lib)
add_test(NAME emcsfc_snow2mdl-ftst_program_setup COMMAND ftst_program_setup_snow)
34 changes: 34 additions & 0 deletions tests/emcsfc_snow2mdl/data/config.nml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
&source_data
autosnow_file="autosnow.grb"
nesdis_snow_file="imssnow96.grb"
nesdis_lsmask_file="mask.grb"
afwa_snow_global_file="global_snow.grb"
afwa_snow_nh_file="NPR.SNWN.SP.S1200.MESH16"
afwa_snow_sh_file="NPR.SNWS.SP.S1200.MESH16"
afwa_lsmask_nh_file="afwa_mask.nh.bin"
afwa_lsmask_sh_file="afwa_mask.sh.bin"
/
&qc
climo_qc_file="emcsfc_snow_cover_climo.grib2"
/
&model_specs
model_lat_file="global_latitudes.t1534.3072.1536.grb"
model_lon_file="global_longitudes.t1534.3072.1536.grb"
model_lsmask_file="global_slmask.t1534.3072.1536.grb"
gfs_lpl_file="global_lonsperlat.t1534.3072.1536.txt"
/
&output_data
model_snow_file="snogrb_model"
output_grib2=.false.
/
&output_grib_time
grib_year=2012
grib_month=10
grib_day=29
grib_hour=0
/
&parameters
lat_threshold=55.0
min_snow_depth=0.05
snow_cvr_threshold=50.0
/
50 changes: 50 additions & 0 deletions tests/emcsfc_snow2mdl/ftst_program_setup.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
program ftst_program_setup

! Unit test for emc_snow2mdl utility, program_setup.
!
! Reads the program namelist and compares each
! variable to expected values.
!
! Author: George Gayno

use program_setup

implicit none

print*, "Starting test of program_setup."
print*, "testing read_setup_namelist with file fort.41..."

call read_config_nml

if (trim(autosnow_file) /= "autosnow.grb") stop 2
if (trim(nesdis_snow_file) /= "imssnow96.grb") stop 3
if (trim(nesdis_lsmask_file) /= "mask.grb") stop 4
if (trim(afwa_snow_global_file) /= "global_snow.grb") stop 5
if (trim(afwa_snow_nh_file) /= "NPR.SNWN.SP.S1200.MESH16") stop 6
if (trim(afwa_snow_sh_file) /= "NPR.SNWS.SP.S1200.MESH16") stop 7
if (trim(afwa_lsmask_nh_file) /= "afwa_mask.nh.bin") stop 8
if (trim(afwa_lsmask_sh_file) /= "afwa_mask.sh.bin") stop 9

if (trim(climo_qc_file) /= "emcsfc_snow_cover_climo.grib2") stop 10

if (trim(model_lat_file) /= "global_latitudes.t1534.3072.1536.grb") stop 11
if (trim(model_lon_file) /= "global_longitudes.t1534.3072.1536.grb") stop 12
if (trim(model_lsmask_file) /= "global_slmask.t1534.3072.1536.grb") stop 13
if (trim(gfs_lpl_file) /= "global_lonsperlat.t1534.3072.1536.txt") stop 14

if (trim(model_snow_file) /= "snogrb_model") stop 15
if (output_grib2) stop 16

if (grib_year /= 12) stop 17
if (grib_month /= 10) stop 18
if (grib_day /= 29) stop 19
if (grib_hour /= 0) stop 20

if (lat_threshold /= 55.0) stop 22
if (min_snow_depth /= 0.05) stop 23
if (snow_cvr_threshold /= 50.0) stop 24

print*, "OK"
print*, "SUCCESS!"

end program ftst_program_setup

0 comments on commit de25b36

Please sign in to comment.