forked from ufs-community/ufs-srweather-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance ability to use template variables (ufs-community#650)
## DESCRIPTION OF CHANGES: 1. Enhance ability to use template variables in the experiment configuration file (either in the default configuration file `config_defaults.sh` or the user configuration file `config.sh`). 2. Modify WE2E test system to include test of template variable use. 3. Fix bugs. ### Notes on template variables: A template variable (or simply a template) is an experiment variable that contains in its definition a reference to another variable(s). The referenced variable can be another experiment variable (i.e. one that is defined in `var_defns.sh`), or it can be a local variable (i.e. one that is not defined in `var_defns.sh` but in the script or function that sources `var_defns.sh` and uses the template). For example, a template named `TEMPL_VAR` my be defined in `config_defaults.sh` or `config.sh` as `TEMPL_VAR='cd ${some_dir}'` where `some_dir` may be an experiment variable or a local variable. `TEMPL_VAR` can then be evaluated using bash's `eval` built-in command in a script or function that first sources `var_defns.sh` and, if necessary, defines `some_dir`. Note that single quotes must be used on the right-hand side to avoid expansion of `${some_dir}` before run time (i.e. when `eval` is called on `TEMPL_VAR`). For details, see the documentation added in PR #[198](ufs-community#198). ### Changes to WE2E tests: * Modify the WE2E test configuration file `config.deactivate_tasks.sh` to include template variables. `deactivate_tasks` now serves as a test of both deactivating tasks and of using template variables. * Add `template_vars` as an alternate test name for `deactivate_tasks` (by creating a symlink named `config.template_vars.sh` that points to `config.deactivate_tasks.sh`). ### Bug fixes: * In `get_WE2Etest_names_subdirs_descs.sh`, change the variable `alt_test_subdirs` to `alt_test_names` at a single location. * In `setup.sh`, set `BUILD_ENV_FN` and `WFLOW_ENV_FN` (instead of in `load_modules_run_task.sh` and `launch_FV3LAM_wflow.sh`, respectively). This way, these variables will have the correct values in `var_defns.sh`. * In `get_expts_status.sh`, fix the way `homerrfs` is calculated. ## TESTS CONDUCTED: The WE2E tests `grid_RRFS_CONUS_25km_ics_FV3GFS_lbcs_FV3GFS_suite_GFS_v15p2` and `template_vars` were run on Hera. Both completed successfully. ## DOCUMENTATION: Documentation is added to the User's Guide via PR #[198](ufs-community#198) into the ufs-srweather-app repo. ## Dependencies: PR #[198](ufs-community#198) for the documentation. ## CONTRIBUTORS: @christinaholtNOAA and @mkavulich brought up the issue of templates as part of PR #[617](https://github.com/NOAA-EMC/regional_workflow/pull/617).
- Loading branch information
1 parent
ac662c7
commit b38acc4
Showing
16 changed files
with
685 additions
and
648 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
config.deactivate_tasks.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# | ||
#----------------------------------------------------------------------- | ||
# | ||
# This file defines a function that returns the contents of a bash script/ | ||
# function with all empty lines, comment lines, and leading and trailing | ||
# whitespace removed. Arguments are as follows: | ||
# | ||
# fp: | ||
# The relative or full path to the file containing the bash script or | ||
# function. | ||
# | ||
# output_varname_contents: | ||
# Name of the output variable that will contain the (processed) contents | ||
# of the file. This is the output of the function. | ||
# | ||
#----------------------------------------------------------------------- | ||
# | ||
function get_bash_file_contents() { | ||
|
||
{ save_shell_opts; set -u +x; } > /dev/null 2>&1 | ||
|
||
local valid_args=( \ | ||
"fp" \ | ||
"output_varname_contents" \ | ||
) | ||
process_args valid_args "$@" | ||
print_input_args "valid_args" | ||
# | ||
# Verify that the required arguments to this function have been specified. | ||
# If not, print out an error message and exit. | ||
# | ||
if [ -z "$fp" ]; then | ||
print_err_msg_exit "\ | ||
The argument \"fp\" specifying the relative or full path to the file to | ||
read was not specified in the call to this function: | ||
fp = \"$fp\"" | ||
fi | ||
|
||
local contents \ | ||
crnt_line | ||
# | ||
# Read in all lines in the file. In doing so: | ||
# | ||
# 1) Concatenate any line ending with the bash line continuation character | ||
# (a backslash) with the following line. | ||
# 2) Remove any leading and trailing whitespace. | ||
# | ||
# Note that these two actions are automatically performed by the "read" | ||
# utility in the while-loop below. | ||
# | ||
contents="" | ||
while read crnt_line; do | ||
contents="${contents}${crnt_line} | ||
" | ||
done < "$fp" | ||
# | ||
# Strip out any comment and empty lines from contents. | ||
# | ||
contents=$( printf "${contents}" | \ | ||
$SED -r -e "/^#.*/d" `# Remove comment lines.` \ | ||
-e "/^$/d" `# Remove empty lines.` \ | ||
) | ||
# | ||
# Set output variables. | ||
# | ||
printf -v ${output_varname_contents} "${contents}" | ||
|
||
{ restore_shell_opts; } > /dev/null 2>&1 | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# | ||
#----------------------------------------------------------------------- | ||
# | ||
# This file defines a function that checks that all experiment variables | ||
# set in the user-specified experiment configuration file are defined (by | ||
# being assigned default values) in the default experiment configuration | ||
# file. If a variable is found in the former that is not defined in the | ||
# latter, this function exits with an error message. | ||
# | ||
# This check is performed in order to prevent the user from defining | ||
# arbitrary variables in the user-specified configuration file; the | ||
# latter should be used to specify only varaibles that have already been | ||
# defined in the default configuration file. | ||
# | ||
# Arguments are as follows: | ||
# | ||
# default_config_fp: | ||
# The relative or full path to the default experiment configuration file. | ||
# | ||
# config_fp: | ||
# The relative or full path to the user-specified experiment configuration | ||
# file. | ||
# | ||
#----------------------------------------------------------------------- | ||
# | ||
function check_expt_config_vars() { | ||
|
||
. ${scrfunc_dir}/source_util_funcs.sh | ||
|
||
{ save_shell_opts; set -u +x; } > /dev/null 2>&1 | ||
|
||
local valid_args=( \ | ||
"default_config_fp" \ | ||
"config_fp" \ | ||
) | ||
process_args valid_args "$@" | ||
print_input_args "valid_args" | ||
|
||
local var_list_default \ | ||
var_list_user \ | ||
crnt_line \ | ||
var_name \ | ||
regex_search | ||
# | ||
# Get the list of variable definitions, first from the default experiment | ||
# configuration file and then from the user-specified experiment | ||
# configuration file. | ||
# | ||
get_bash_file_contents fp="${default_config_fp}" \ | ||
output_varname_contents="var_list_default" | ||
|
||
get_bash_file_contents fp="${config_fp}" \ | ||
output_varname_contents="var_list_user" | ||
# | ||
# Loop through each line/variable in var_list_user. For each line, | ||
# extract the the name of the variable that is being set (say VAR) and | ||
# check that this variable is set somewhere in the default configuration | ||
# file by verifying that a line that starts with "VAR=" exists in | ||
# var_list_default. | ||
# | ||
while read crnt_line; do | ||
# | ||
# Note that a variable name will be found only if the equal sign immediately | ||
# follows the variable name. | ||
# | ||
var_name=$( printf "%s" "${crnt_line}" | $SED -n -r -e "s/^([^ =\"]*)=.*/\1/p") | ||
|
||
if [ -z "${var_name}" ]; then | ||
|
||
print_info_msg " | ||
The current line (crnt_line) of the user-specified experiment configuration | ||
file (config_fp) does not contain a variable name (i.e. var_name is empty): | ||
config_fp = \"${config_fp}\" | ||
crnt_line = \"${crnt_line}\" | ||
var_name = \"${var_name}\" | ||
Skipping to next line." | ||
|
||
else | ||
# | ||
# Use grep to search for the variable name (followed by an equal sign, | ||
# all at the beginning of a line) in the list of variables in the default | ||
# configuration file. | ||
# | ||
# Note that we use a herestring to input into grep the list of variables | ||
# in the default configuration file. grep will return with a zero status | ||
# if the specified string (regex_search) is not found in the default | ||
# variables list and a nonzero status otherwise. Note also that we | ||
# redirect the output of grep to null because we are only interested in | ||
# its exit status. | ||
# | ||
regex_search="^${var_name}=" | ||
grep "${regex_search}" <<< "${var_list_default}" > /dev/null 2>&1 || \ | ||
print_err_msg_exit "\ | ||
The variable (var_name) defined on the current line (crnt_line) of the | ||
user-specified experiment configuration file (config_fp) does not appear | ||
in the default experiment configuration file (default_config_fp): | ||
config_fp = \"${config_fp}\" | ||
default_config_fp = \"${default_config_fp}\" | ||
crnt_line = \"${crnt_line}\" | ||
var_name = \"${var_name}\" | ||
Please assign a default value to this variable in the default configuration | ||
file and rerun." | ||
|
||
fi | ||
|
||
done <<< "${var_list_user}" | ||
|
||
{ restore_shell_opts; } > /dev/null 2>&1 | ||
|
||
} |
Oops, something went wrong.