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 CMakeLists.txt with a proposed use of the dic-like structure #82

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 27 additions & 35 deletions rrfs-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@
#! NOAA/NCEP, National Centers for Environmental Prediction RDASapp !
#!-------------------------------------------------------------------------

include(funcs.cmake)

### Define CTests here ###

# FV3-JEDI tests

set(rrfs_test_execs "")

# MPAS-JEDI tests
add_to_dictionary(rrfs_test_execs "rrfs_mpasjedi_2022052619_Ens3Dvar" "mpasjedi_variational.x")
add_to_dictionary(rrfs_test_execs "rrfs_mpasjedi_2022052619_atms_npp_qc" "mpasjedi_variational.x")
add_to_dictionary(rrfs_test_execs "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 @@ -14,6 +28,12 @@ if (CLONE_RRFSDATA)
# # A bit of guesswork here, I don't know if folks using this option stored it in the same directory structure
# set (fv3-jedi_data_testinput_tier_1_local "$ENV{FV3_JEDI_TESTFILES}/fv3-jedi-data/testinput_tier_1")
if(FV3_DYCORE)
list( APPEND rrfs_fv3jedi_tests
rrfs_fv3jedi_hyb_2022052619
rrfs_fv3jedi_letkf_2022052619
)
add_to_dictionary(rrfs_test_execs "rrfs_fv3jedi_hyb_2022052619" "fv3jedi_var.x")
add_to_dictionary(rrfs_test_execs "rrfs_fv3jedi_letkf_2022052619" "fv3jedi_letkf.x")

message(STATUS "MACHINE_ID is " ${MACHINE_ID})
if("${MACHINE_ID}" STREQUAL "orion")
Expand All @@ -22,22 +42,7 @@ 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
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(case IN LISTS rrfs_fv3jedi_tests)
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 +54,7 @@ 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)
get_from_dictionary(rrfs_test_execs ${case} exe)
ecbuild_add_test( TARGET ${target_test}
MPI 80
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/rundir-${target_test}
Expand All @@ -72,26 +76,16 @@ if (CLONE_RRFSDATA)
set(RESTORE_MPI_ARGS ${MPI_ARGS})
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
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
)

add_to_dictionary(rrfs_test_execs "rrfs_mpasjedi_2022052619_Ens3Dvar" "mpasjedi_variational.x")
add_to_dictionary(rrfs_test_execs "rrfs_mpasjedi_2022052619_letkf" "mpasjedi_enkf.x")
add_to_dictionary(rrfs_test_execs "rrfs_mpasjedi_2022052619_atms_npp_qc" "mpasjedi_variational.x")
foreach(case IN LISTS rrfs_mpasjedi_tests)

get_from_dictionary(rrfs_test_execs ${case} exe)
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 +105,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
43 changes: 43 additions & 0 deletions rrfs-test/funcs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# 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()
Loading