Skip to content

Commit

Permalink
Update shell scripts to meet linter standards and address bugs associ…
Browse files Browse the repository at this point in the history
…ated with the changes
  • Loading branch information
BrianCurtis-NOAA committed Mar 21, 2024
1 parent 0f17662 commit 978a86b
Show file tree
Hide file tree
Showing 7 changed files with 2,253 additions and 2,295 deletions.
79 changes: 42 additions & 37 deletions tests/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,53 @@ function trim {
var="${var#"${var%%[![:space:]]*}"}"
# remove trailing whitespace characters
var="${var%"${var##*[![:space:]]}"}"
echo -n "$var"
echo -n "${var}"
}

SECONDS=0

if [[ $(uname -s) == Darwin ]]; then
readonly MYDIR=$(cd "$(dirname "$(greadlink -f -n "${BASH_SOURCE[0]}" )" )" && pwd -P)
uname_s=$(uname -s)
if [[ ${uname_s} == Darwin ]]; then
greadlnk=$(greadlink -f -n "${BASH_SOURCE[0]}" )
MYDIR=$(cd "$(dirname "${greadlnk}" )" && pwd -P)
else
readonly MYDIR=$(cd "$(dirname "$(readlink -f -n "${BASH_SOURCE[0]}" )" )" && pwd -P)
readlnk=$(readlink -f -n "${BASH_SOURCE[0]}" )
MYDIR=$(cd "$(dirname "${readlnk}" )" && pwd -P)
fi
readonly MYDIR

# ----------------------------------------------------------------------
# Parse arguments.

readonly ARGC=$#

if [[ $ARGC -lt 2 ]]; then
echo "Usage: $0 MACHINE_ID [ MAKE_OPT [ COMPILE_ID ] [ RT_COMPILER ] [ clean_before ] [ clean_after ] ]"
if [[ ${ARGC} -lt 2 ]]; then
echo "Usage: $0 MACHINE_ID [ MAKE_OPT ] [ COMPILE_ID ] [ RT_COMPILER ] [ clean_before ] [ clean_after ]"
echo Valid MACHINE_IDs:
echo $( ls -1 ../cmake/configure_* | sed s:.*configure_::g | sed s:\.cmake:: ) | fold -sw72
echostuff=$( ls -1 ../cmake/configure_* )
echostuff=${echostuff/:.*configure_::g}
echostuff=${echostuff/:\.cmake::}
echostuff=$( fold -sw72 <<< "${echostuff}" )

#echo $( ls -1 ../cmake/configure_* | sed s:.*configure_::g | sed s:\.cmake:: ) | fold -sw72
exit 1
else
MACHINE_ID=$1
MAKE_OPT=${2:-}
COMPILE_ID=${3:+_$3}
COMPILE_ID=${3:+$3}
RT_COMPILER=${4:-intel}
clean_before=${5:-YES}
clean_after=${6:-YES}
fi

BUILD_NAME=fv3${COMPILE_ID}
BUILD_NAME=fv3_${COMPILE_ID}

PATHTR=${PATHTR:-$( cd ${MYDIR}/.. && pwd )}
PATHTR=${PATHTR:-$( cd "${MYDIR}/.." && pwd )}
BUILD_DIR=${BUILD_DIR:-$(pwd)/build_${BUILD_NAME}}

# ----------------------------------------------------------------------
# Make sure we have reasonable number of threads.

if [[ $MACHINE_ID == derecho ]]; then
if [[ ${MACHINE_ID} == derecho ]]; then
BUILD_JOBS=${BUILD_JOBS:-3}
fi

Expand All @@ -54,26 +62,26 @@ BUILD_JOBS=${BUILD_JOBS:-8}
hostname

set +x
if [[ $MACHINE_ID == macosx ]] || [[ $MACHINE_ID == linux ]]; then
source $PATHTR/modulefiles/ufs_${MACHINE_ID}.${RT_COMPILER}
if [[ ${MACHINE_ID} == macosx ]] || [[ ${MACHINE_ID} == linux ]]; then
source "${PATHTR}/modulefiles/ufs_${MACHINE_ID}.${RT_COMPILER}"
else
# Activate lua environment for gaea c5
if [[ $MACHINE_ID == gaea ]]; then
if [[ ${MACHINE_ID} == gaea ]]; then
module reset
fi
# Load fv3 module
module use $PATHTR/modulefiles
module use "${PATHTR}/modulefiles"
modulefile="ufs_${MACHINE_ID}.${RT_COMPILER}"
module load $modulefile
module load "${modulefile}"
module list
fi
set -x

echo "Compiling ${MAKE_OPT} into $BUILD_NAME.exe on $MACHINE_ID"
echo "Compiling ${MAKE_OPT} into ${BUILD_NAME}.exe on ${MACHINE_ID}"

# set CMAKE_FLAGS based on $MAKE_OPT

CMAKE_FLAGS=$MAKE_OPT
CMAKE_FLAGS=${MAKE_OPT}
CMAKE_FLAGS+=" -DMPI=ON"

if [[ ${MAKE_OPT} == *-DDEBUG=ON* ]]; then
Expand All @@ -87,11 +95,8 @@ fi

# Check if suites argument is provided or not
set +ex
TEST=$( echo $MAKE_OPT | grep -e "-DCCPP_SUITES=" )
if [[ $? -eq 0 ]]; then
SUITES=$( echo $MAKE_OPT | sed 's/.*-DCCPP_SUITES=//' | sed 's/ .*//' )
echo "Compiling suites ${SUITES}"
fi
SUITES=$(grep -Po "\-DCCPP_SUITES=\K[^ ]*" <<< "${MAKE_OPT}")
export SUITES
set -ex

# Valid applications
Expand All @@ -104,31 +109,31 @@ if [[ "${MAKE_OPT}" == *"-DAPP=NG-GODAS"* ]]; then
CMAKE_FLAGS+=" -DMOM6SOLO=ON"
fi

CMAKE_FLAGS=$(trim "${CMAKE_FLAGS}")
CMAKE_FLAGS=$(set -e; trim "${CMAKE_FLAGS}")
echo "CMAKE_FLAGS = ${CMAKE_FLAGS}"

if [ $clean_before = YES ] ; then
rm -rf ${BUILD_DIR}
if [[ ${clean_before} = YES ]] ; then
rm -rf "${BUILD_DIR}"
fi

export BUILD_VERBOSE=1
export BUILD_DIR
export BUILD_JOBS
export CMAKE_FLAGS

bash -x ${PATHTR}/build.sh
bash -x "${PATHTR}/build.sh"

mv ${BUILD_DIR}/ufs_model ${PATHTR}/tests/${BUILD_NAME}.exe
if [[ $MACHINE_ID == linux ]]; then
cp ${PATHTR}/modulefiles/ufs_${MACHINE_ID}.${RT_COMPILER} ${PATHTR}/tests/modules.${BUILD_NAME}
mv "${BUILD_DIR}/ufs_model" "${PATHTR}/tests/${BUILD_NAME}.exe"
if [[ ${MACHINE_ID} == linux ]]; then
cp "${PATHTR}/modulefiles/ufs_${MACHINE_ID}.${RT_COMPILER}" "${PATHTR}/tests/modules.${BUILD_NAME}"
else
cp ${PATHTR}/modulefiles/ufs_${MACHINE_ID}.${RT_COMPILER}.lua ${PATHTR}/tests/modules.${BUILD_NAME}.lua
cp "${PATHTR}/modulefiles/ufs_${MACHINE_ID}.${RT_COMPILER}.lua" "${PATHTR}/tests/modules.${BUILD_NAME}.lua"
fi

if [ $clean_after = YES ] ; then
rm -rf ${BUILD_DIR}
if [[ ${clean_after} = YES ]] ; then
rm -rf "${BUILD_DIR}"
fi

elapsed=$SECONDS
echo "Elapsed time $elapsed seconds. Compiling ${CMAKE_FLAGS} finished"
echo "Compile ${COMPILE_ID/#_} elapsed time $elapsed seconds. ${CMAKE_FLAGS}" > compile${COMPILE_ID}_time.log
elapsed=${SECONDS}
echo "Elapsed time ${elapsed} seconds. Compiling ${CMAKE_FLAGS} finished"
echo "Compile ${COMPILE_ID} elapsed time ${elapsed} seconds. ${CMAKE_FLAGS}" > "compile_${COMPILE_ID}_time.log"
Loading

0 comments on commit 978a86b

Please sign in to comment.