diff --git a/machines/config_workflow.xml b/machines/config_workflow.xml
index 7f6f2fc311..2902e74185 100644
--- a/machines/config_workflow.xml
+++ b/machines/config_workflow.xml
@@ -43,9 +43,20 @@
case.run or case.test
$DOUT_S
- 1
- 1
- 0:20:00
+ 1
+ 1
+ 0:20:00
+
+
+
+ template.cupid
+ false
+ case.st_archive
+ $RUN_POSTPROCESSING
+
+ 1
+ 1
+ 0:20:00
@@ -56,28 +67,14 @@
case.st_archive
1
- 200
- 10
- 12:00:00
+ 200
+ 10
+ 12:00:00
- 72
- 9
- 0:20:00
-
-
-
-
-
-
- template.cupid
- false
- case.st_archive
- 1
-
- 1
- 1
- 0:20:00
+ 72
+ 9
+ 0:20:00
diff --git a/machines/template.cupid b/machines/template.cupid
index 8b1b94e2fd..d5399dea7f 100755
--- a/machines/template.cupid
+++ b/machines/template.cupid
@@ -1,5 +1,16 @@
#!/bin/bash -e
+# Function to add some number of years to a string that
+# is formatted as YYYY-MM-DD and print out the updated
+# string in the same format
+add_years() {
+ YEAR=`echo $1 | cut -d '-' -f 1`
+ MM=`echo $1 | cut -d '-' -f 2`
+ DD=`echo $1 | cut -d '-' -f 3`
+ NEW_YEAR=`printf '%04d' "$((YEAR + $2))"`-`printf '%02d' "${MM}"`-`printf '%02d' "${DD}"`
+ echo $NEW_YEAR
+}
+
# Batch system directives
{{ batchdirectives }}
@@ -11,37 +22,108 @@ source .env_mach_specific.sh
# by setting $PYTHONPATH; since this is conda-based we
# want an empty PYTHONPATH environment variable
MACH=`./xmlquery --value MACH`
-unset PYTHONPATH
-conda activate cupid-infrastructure
-
-# Set variables that should eventually come from environment file
-CUPID_EXAMPLE=key_metrics
-RUN_CUPID_ANALYSIS=TRUE
-RUN_CUPID_TIMESERIES=TRUE
-
-if [ "${RUN_CUPID_ANALYSIS}" == "TRUE" ]; then
- # 1. Generate CUPiD config file
- {{ srcroot }}/tools/CUPiD/helper_scripts/generate_cupid_config_for_cesm_case.py \
- --cesm-root {{ SRCROOT }}
-
- # 2. Generate ADF config file
- {{ srcroot }}/tools/CUPiD/helper_scripts/generate_adf_config_file.py \
- --cesm-root {{ SRCROOT }} \
- --cupid-config-loc ${PWD} \
- --adf-template {{ SRCROOT }}/tools/CUPiD/externals/ADF/config_amwg_default_plots.yaml \
- --out-file adf_config.yml
-
- # 3. Generate timeseries files and run ADF
- if [ "${RUN_CUPID_TIMESERIES}" == "TRUE" ]; then
- {{ srcroot }}/tools/CUPiD/cupid/run_timeseries.py
+
+# Set variables that come from environment file
+CUPID_EXAMPLE=`./xmlquery --value CUPID_EXAMPLE`
+CUPID_GEN_TIMESERIES=`./xmlquery --value CUPID_GEN_TIMESERIES`
+CUPID_GEN_DIAGNOSTICS=`./xmlquery --value CUPID_GEN_DIAGNOSTICS`
+CUPID_GEN_HTML=`./xmlquery --value CUPID_GEN_HTML`
+CUPID_BASELINE_CASE=`./xmlquery --value CUPID_BASELINE_CASE`
+CUPID_BASELINE_ROOT=`./xmlquery --value CUPID_BASELINE_ROOT`
+CUPID_START_YEAR=`./xmlquery --value CUPID_START_YEAR`
+CUPID_NYEARS=`./xmlquery --value CUPID_NYEARS`
+CUPID_END_YEAR=`add_years $CUPID_START_YEAR $CUPID_NYEARS`
+CUPID_BASE_START_YEAR=`./xmlquery --value CUPID_BASE_START_YEAR`
+CUPID_BASE_NYEARS=`./xmlquery --value CUPID_BASE_NYEARS`
+CUPID_BASE_END_YEAR=`add_years $CUPID_BASE_START_YEAR $CUPID_BASE_NYEARS`
+CUPID_RUN_ALL=`./xmlquery --value CUPID_RUN_ALL`
+CUPID_RUN_ATM=`./xmlquery --value CUPID_RUN_ATM`
+CUPID_RUN_OCN=`./xmlquery --value CUPID_RUN_OCN`
+CUPID_RUN_LND=`./xmlquery --value CUPID_RUN_LND`
+CUPID_RUN_ICE=`./xmlquery --value CUPID_RUN_ICE`
+CUPID_RUN_ROF=`./xmlquery --value CUPID_RUN_ROF`
+CUPID_RUN_GLC=`./xmlquery --value CUPID_RUN_GLC`
+CUPID_RUN_ADF=`./xmlquery --value CUPID_RUN_ADF`
+CUPID_INFRASTRUCTURE_ENV=`./xmlquery --value CUPID_INFRASTRUCTURE_ENV`
+CUPID_ANALYSIS_ENV=`./xmlquery --value CUPID_ANALYSIS_ENV`
+
+# Create directory for running CUPiD
+mkdir -p cupid-postprocessing
+cd cupid-postprocessing
+
+# If CUPID_RUN_ALL is TRUE, we don't add any component flags.
+# The lack of any component flags tells CUPiD to run all components.
+CUPID_FLAG_STRING=""
+if [ "${CUPID_RUN_ALL}" == "FALSE" ]; then
+ if [ "${CUPID_RUN_ATM}" == "TRUE" ]; then
+ CUPID_FLAG_STRING+=" --atm"
+ fi
+ if [ "${CUPID_RUN_OCN}" == "TRUE" ]; then
+ CUPID_FLAG_STRING+=" --ocn"
fi
+ if [ "${CUPID_RUN_LND}" == "TRUE" ]; then
+ CUPID_FLAG_STRING+=" --lnd"
+ fi
+ if [ "${CUPID_RUN_ICE}" == "TRUE" ]; then
+ CUPID_FLAG_STRING+=" --ice"
+ fi
+ if [ "${CUPID_RUN_ROF}" == "TRUE" ]; then
+ CUPID_FLAG_STRING+=" --rof"
+ fi
+ if [ "${CUPID_RUN_GLC}" == "TRUE" ]; then
+ CUPID_FLAG_STRING+=" --glc"
+ fi
+ if [ "${CUPID_FLAG_STRING}" == "" ]; then
+ echo "If CUPID_RUN_ALL is False, user must set at least one component"
+ exit 1
+ fi
+fi
+if [ "${CUPID_RUN_ALL}" == "TRUE" ]; then
+ echo "CUPID_RUN_ALL is True, running diagnostics for all components"
+fi
+
+unset PYTHONPATH
+conda activate $CUPID_INFRASTRUCTURE_ENV
+
+# 1. Generate CUPiD config file
+{{ SRCROOT }}/tools/CUPiD/helper_scripts/generate_cupid_config_for_cesm_case.py \
+ --cesm-root {{ SRCROOT }} \
+ --case-root {{ CASEROOT }} \
+ --cupid-example $CUPID_EXAMPLE \
+ --cupid-baseline-case $CUPID_BASELINE_CASE \
+ --cupid-baseline-root $CUPID_BASELINE_ROOT \
+ --cupid-start-year $CUPID_START_YEAR \
+ --cupid-end-year $CUPID_END_YEAR \
+ --cupid-base-start-year $CUPID_BASE_START_YEAR \
+ --cupid-base-end-year $CUPID_BASE_END_YEAR \
+
+# 2. Generate ADF config file
+if [ "${CUPID_RUN_ADF}" == "TRUE" ]; then
+ {{ SRCROOT }}/tools/CUPiD/helper_scripts/generate_adf_config_file.py \
+ --cesm-root {{ SRCROOT }} \
+ --cupid-config-loc {{ SRCROOT }}/tools/CUPiD/examples/${CUPID_EXAMPLE} \
+ --adf-template {{ SRCROOT }}/tools/CUPiD/externals/ADF/config_amwg_default_plots.yaml \
+ --out-file adf_config.yml
+fi
+
+# 3. Generate timeseries files
+if [ "${CUPID_GEN_TIMESERIES}" == "TRUE" ]; then
+ {{ SRCROOT }}/tools/CUPiD/cupid/run_timeseries.py $CUPID_FLAG_STRING
+fi
+
+#4. Run ADF
+if [ "${CUPID_RUN_ADF}" == "TRUE" ]; then
conda deactivate
- conda activate cupid-analysis
+ conda activate $CUPID_ANALYSIS_ENV
{{ SRCROOT }}/tools/CUPiD/externals/ADF/run_adf_diag adf_config.yml
+fi
- # 4. Run CUPiD and build webpage
- conda deactivate
- conda activate cupid-infrastructure
- {{ srcroot }}/tools/CUPiD/cupid/run_diagnostics.py
- {{ srcroot }}/tools/CUPiD/cupid/cupid_webpage.py
+# 5. Run CUPiD and build webpage
+conda deactivate
+conda activate $CUPID_INFRASTRUCTURE_ENV
+if [ "${CUPID_GEN_DIAGNOSTICS}" == "TRUE" ]; then
+ {{ SRCROOT }}/tools/CUPiD/cupid/run_diagnostics.py $CUPID_FLAG_STRING
+fi
+if [ "${CUPID_GEN_HTML}" == "TRUE" ]; then
+ {{ SRCROOT }}/tools/CUPiD/cupid/cupid_webpage.py
fi