Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update rrfs-test/CMakeLists.txt to be more compact for adding a CTest #81

Merged
merged 7 commits into from
Jun 18, 2024
117 changes: 78 additions & 39 deletions rrfs-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,72 @@
#! NOAA/NCEP, National Centers for Environmental Prediction RDASapp !
#!-------------------------------------------------------------------------

###########################
### Begin function list ###
TingLei-NOAA marked this conversation as resolved.
Show resolved Hide resolved
###########################

# Function to add key-value pairs to the dictionary
function(add_to_dictionary dict key value)
# Check if the key already exists
foreach(entry IN LISTS ${dict})
string(FIND "${entry}" "=" EQUAL_POS)
if(EQUAL_POS GREATER -1)
string(SUBSTRING "${entry}" 0 ${EQUAL_POS} ENTRY_KEY)
if(ENTRY_KEY STREQUAL ${key})
# Key exists, check the value
math(EXPR VALUE_START "${EQUAL_POS} + 1")
string(SUBSTRING "${entry}" ${VALUE_START} -1 ENTRY_VALUE)
if(NOT ENTRY_VALUE STREQUAL ${value})
message(FATAL_ERROR "Error: Key '${key}' already exists with a different value '${ENTRY_VALUE}'")
else()
return()
endif()
endif()
endif()
endforeach()

# Key does not exist, add the new entry
set(entry "${key}=${value}")
list(APPEND ${dict} "${entry}")
set(${dict} "${${dict}}" PARENT_SCOPE)
endfunction()

# Function to get the value by key from the dictionary
function(get_from_dictionary dict key result)
foreach(entry IN LISTS ${dict})
string(FIND "${entry}" "=" EQUAL_POS)
if(EQUAL_POS GREATER -1)
string(SUBSTRING "${entry}" 0 ${EQUAL_POS} ENTRY_KEY)
if(ENTRY_KEY STREQUAL ${key})
math(EXPR VALUE_START "${EQUAL_POS} + 1")
string(SUBSTRING "${entry}" ${VALUE_START} -1 ENTRY_VALUE)
set(${result} "${ENTRY_VALUE}" PARENT_SCOPE)
return()
endif()
endif()
endforeach()
# If the key is not found, set the result to an empty string or some default value
set(${result} "" PARENT_SCOPE)
endfunction()

################################################
### End function list, begin executable code ###
################################################

### Define CTests here ###

# FV3-JEDI tests
set(rrfs_fv3jedi_tests "")
guoqing-noaa marked this conversation as resolved.
Show resolved Hide resolved
add_to_dictionary(rrfs_fv3jedi_tests "rrfs_fv3jedi_hyb_2022052619" "fv3jedi_var.x")
add_to_dictionary(rrfs_fv3jedi_tests "rrfs_fv3jedi_letkf_2022052619" "fv3jedi_letkf.x")

# MPAS-JEDI tests
set(rrfs_mpasjedi_tests "")
add_to_dictionary(rrfs_mpasjedi_tests "rrfs_mpasjedi_2022052619_Ens3Dvar" "mpasjedi_variational.x")
add_to_dictionary(rrfs_mpasjedi_tests "rrfs_mpasjedi_2022052619_atms_npp_qc" "mpasjedi_variational.x")
add_to_dictionary(rrfs_mpasjedi_tests "rrfs_mpasjedi_2022052619_letkf" "mpasjedi_enkf.x")


# rrfs data - from rrfs-test-data repo if found, from local directory, or from tarball
if (CLONE_RRFSDATA)
message(STATUS "Use test data from rrfs-test-data repository")
Expand All @@ -22,22 +88,12 @@ if (CLONE_RRFSDATA)
set(MPI_ARGS "${MPI_ARGS} --exclusive")
endif()

# JEDI test cases
# ----------------
# NOTE: To add a new ctest for FV3, simple add the new yaml file here (without the extension)
# Also need to add the associated executable to the rrfs_fv3jedi_exes list below
list( APPEND rrfs_fv3jedi_tests
guoqing-noaa marked this conversation as resolved.
Show resolved Hide resolved
rrfs_fv3jedi_hyb_2022052619
rrfs_fv3jedi_letkf_2022052619
)

# JEDI executables for each test case above
list ( APPEND rrfs_fv3jedi_exes
fv3jedi_var.x
fv3jedi_letkf.x
)

foreach(case IN LISTS rrfs_fv3jedi_tests)
foreach(keypair ${rrfs_fv3jedi_tests})
guoqing-noaa marked this conversation as resolved.
Show resolved Hide resolved
string(REGEX MATCH "([^=]+)=([^=]*)" match ${keypair})
guoqing-noaa marked this conversation as resolved.
Show resolved Hide resolved
if(match)
set(case ${CMAKE_MATCH_1})
set(exe ${CMAKE_MATCH_2})
endif()
set(casedir "${CMAKE_CURRENT_BINARY_DIR}/rundir-${case}")
set(src_casedir "${rrfs-test_data_local}/rrfs-data_fv3jedi_2022052619")
if (NOT EXISTS "${casedir}")
Expand All @@ -49,8 +105,6 @@ if (CLONE_RRFSDATA)
file(CREATE_LINK ${src_casedir}/Data ${casedir}/Data SYMBOLIC)
file(COPY ${src_yaml}/${case}.yaml DESTINATION ${casedir} )
set(target_test ${case})
list(FIND rrfs_fv3jedi_tests "${case}" index)
list(GET rrfs_fv3jedi_exes ${index} exe)
ecbuild_add_test( TARGET ${target_test}
MPI 80
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/rundir-${target_test}
Expand All @@ -73,25 +127,12 @@ if (CLONE_RRFSDATA)
set(MPI_ARGS "${MPI_ARGS} --exclusive")
endif()

# JEDI test cases
# ----------------
# NOTE: To add a new ctest for MPAS, simple add the new yaml file here (without the extension)
# Also need to add the associated executable to the rrfs_fv3jedi_exes list below
list( APPEND rrfs_mpasjedi_tests
rrfs_mpasjedi_2022052619_Ens3Dvar
rrfs_mpasjedi_2022052619_letkf
rrfs_mpasjedi_2022052619_atms_npp_qc
)

# JEDI executables for each test case above
list ( APPEND rrfs_mpasjedi_exes
mpasjedi_variational.x
mpasjedi_enkf.x
mpasjedi_variational.x
)

foreach(case IN LISTS rrfs_mpasjedi_tests)

foreach(keypair ${rrfs_mpasjedi_tests})
guoqing-noaa marked this conversation as resolved.
Show resolved Hide resolved
string(REGEX MATCH "([^=]+)=([^=]*)" match ${keypair})
if(match)
set(case ${CMAKE_MATCH_1})
set(exe ${CMAKE_MATCH_2})
endif()
set(casedir "${CMAKE_CURRENT_BINARY_DIR}/rundir-${case}")
set(src_casedir "${rrfs-test_data_local}/rrfs-data_mpasjedi_2022052619")
if (NOT EXISTS "${casedir}")
Expand All @@ -111,8 +152,6 @@ if (CLONE_RRFSDATA)
file(COPY ${DATA_FILES} DESTINATION ${casedir})
file(COPY ${src_yaml}/${case}.yaml DESTINATION ${casedir} )
set(target_test ${case})
list(FIND rrfs_mpasjedi_tests "${case}" index)
list(GET rrfs_mpasjedi_exes ${index} exe)
ecbuild_add_test( TARGET ${target_test}
MPI 36
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/rundir-${target_test}
Expand Down
Loading