Skip to content
Merged
Changes from 5 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
50 changes: 49 additions & 1 deletion ush/bash_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ function declare_from_tmpl() {
# MEMDIR='mem001' YMD=${PDY} HH=${cyc} declare_from_tmpl -rx \
# COMOUT_ATMOS_HISTORY:COM_ATMOS_HISTORY_TMPL
#
if [[ ${DEBUG_WORKFLOW:-"NO"} == "NO" ]]; then set +x; fi
if [[ ${DEBUG_WORKFLOW:-"NO"} == "NO" ]]; then
set +x
fi
local opts="-g"
local OPTIND=1
while getopts "rx" option; do
Expand Down Expand Up @@ -110,7 +112,53 @@ function wait_for_file() {
return 1
}

# This utility is to be used to create a COM structure in the DATAROOT
# It will replace the root path (up to $COMROOT) with $DATAROOT
# Use realpath --relative-to to get the relative path from $COMROOT to the target file
# and then prepend $DATAROOT to that path to get the new target path
function dataroot_com_path() {
#
# Generate a COM path in the DATAROOT based on an existing COM path.
#
# This function takes an existing COM path and generates a corresponding
# path in the DATAROOT by replacing the root directory with DATAROOT.
#
# Syntax:
# dataroot_com_path original_com_path
#
# original_com_path: The original COM path to be transformed.
#
# Example:
# # Declare COMOUT_ATMOS_ANALYSIS using template
# YMD=${PDY} HH=${cyc} declare_from_tmpl -rx \
# COMOUT_ATMOS_ANALYSIS:COM_ATMOS_ANALYSIS_TMPL
# # Get the DATAROOT version of the COM path
# pCOMOUT_ATMOS_ANALYSIS=$(dataroot_com_path "${COMOUT_ATMOS_ANALYSIS}")
# echo "New COM path in DATAROOT: ${pCOMOUT_ATMOS_ANALYSIS}"
#

if [[ $# -ne 1 ]]; then
echo "FATAL ERROR in dataroot_com_path: Incorrect number of arguments!"
echo "Usage: dataroot_com_path original_com_path"
exit 2
fi

local original_com_path=${1}

if [[ -z "${COMROOT:-}" || -z "${DATAROOT:-}" ]]; then
echo "FATAL ERROR in dataroot_com_path: COMROOT and DATAROOT must be defined!"
exit 2
fi

local relative_path
relative_path=$(realpath --relative-to="${COMROOT}" "${original_com_path}")
local new_com_path="${DATAROOT}/${relative_path}"

echo "${new_com_path}"
}

# shellcheck disable=

declare -xf declare_from_tmpl
declare -xf wait_for_file
declare -xf dataroot_com_path
Loading