@@ -36,7 +36,9 @@ function declare_from_tmpl() {
3636 # MEMDIR='mem001' YMD=${PDY} HH=${cyc} declare_from_tmpl -rx \
3737 # COMOUT_ATMOS_HISTORY:COM_ATMOS_HISTORY_TMPL
3838 #
39- if [[ ${DEBUG_WORKFLOW:- " NO" } == " NO" ]]; then set +x; fi
39+ if [[ ${DEBUG_WORKFLOW:- " NO" } == " NO" ]]; then
40+ set +x
41+ fi
4042 local opts=" -g"
4143 local OPTIND=1
4244 while getopts " rx" option; do
@@ -110,6 +112,53 @@ function wait_for_file() {
110112 return 1
111113}
112114
115+ # This utility is to be used to create a COM structure in the DATAROOT
116+ # It will replace the root path (up to $COMROOT) with $DATAROOT
117+ # Use realpath --relative-to to get the relative path from $COMROOT to the target file
118+ # and then prepend $DATAROOT to that path to get the new target path
119+ function dataroot_com_path() {
120+ #
121+ # Generate a COM path in the DATAROOT based on an existing COM path.
122+ #
123+ # This function takes an existing COM path and generates a corresponding
124+ # path in the DATAROOT by replacing the root directory with DATAROOT.
125+ #
126+ # Syntax:
127+ # dataroot_com_path original_com_path
128+ #
129+ # original_com_path: The original COM path to be transformed.
130+ #
131+ # Example:
132+ # # Declare COMOUT_ATMOS_ANALYSIS using template
133+ # YMD=${PDY} HH=${cyc} declare_from_tmpl -rx \
134+ # COMOUT_ATMOS_ANALYSIS:COM_ATMOS_ANALYSIS_TMPL
135+ # # Get the DATAROOT version of the COM path
136+ # pCOMOUT_ATMOS_ANALYSIS=$(dataroot_com_path "${COMOUT_ATMOS_ANALYSIS}")
137+ # echo "New COM path in DATAROOT: ${pCOMOUT_ATMOS_ANALYSIS}"
138+ #
139+
140+ set +x
141+ if [[ $# -ne 1 ]]; then
142+ echo " FATAL ERROR in dataroot_com_path: Incorrect number of arguments!"
143+ echo " Usage: dataroot_com_path original_com_path"
144+ exit 2
145+ fi
146+
147+ local original_com_path=${1}
148+
149+ if [[ -z " ${COMROOT:- } " || -z " ${DATAROOT:- } " ]]; then
150+ echo " FATAL ERROR in dataroot_com_path: COMROOT and DATAROOT must be defined!"
151+ exit 2
152+ fi
153+
154+ local relative_path
155+ relative_path=$( realpath --relative-to=" ${COMROOT} " " ${original_com_path} " )
156+ local new_com_path=" ${DATAROOT} /${relative_path} "
157+
158+ echo " ${new_com_path} "
159+ set_trace
160+ }
161+
113162# Initialize stacks for tick-tock profiling (initialize only once)
114163if [[ -z ${_GW_TIMER_STACK+x} ]]; then
115164 declare -xa _GW_TIMER_STACK=()
@@ -198,5 +247,6 @@ tock() {
198247
199248declare -xf declare_from_tmpl
200249declare -xf wait_for_file
250+ declare -xf dataroot_com_path
201251declare -xf tick
202252declare -xf tock
0 commit comments