Skip to content

Commit

Permalink
Refactor some build scripts (NOAA-EMC#794)
Browse files Browse the repository at this point in the history
Refactors the build_ufs script to allow the build of any UFS app to support future expansion of global-workflow capability. The default should be sufficient for most users, as S2SWA can be used for ATM, ATMA, S2S, and S2SW as well. The new format of the command is now:
```
build_ufs.sh [-a UFS_app][-v]
  -a UFS_app:
    Specify the UFS application to build. The default if none is provided is S2SWA
  -v:
    Turn on verbose mode (BUILD_VERBOSE)
```

build_all.sh is similarly refactored to include the same options. Also, a new `-c build_config` option is added to specify an alternative list of programs to build.
```
build_all.sh [-a UFS_app][-c build_config][-h][-v]
  -a UFS_app:
    Build a specific UFS app instead of the default
  -c build_config:
    Selectively build based on the provided config instead of the default config
  -h:
    Print usage message and exit
  -v:
    Run all scripts in verbose mode
```

partial_build.sh is also updated to take the new `-c` option to specify a build config.
```
partial_build.sh [-c config_file][-h][-v]
  -c config_file:
    Selectively build based on the provided config. The default if none is specified is gfs_build.cfg
  -h:
    Print usage message and exit
  -v:
    Run in verbose mode
```

In addition to the above, build_all and partial_build had their indentation redone and their usage/help statement updated/added. Also, the build configuration file was renamed to from fv3gfs_build.cfg to gfs_build.cfg.

Fixes NOAA-EMC#745
Fixes NOAA-EMC#751
  • Loading branch information
WalterKolczynski-NOAA authored May 18, 2022
1 parent 2abee02 commit fa12db2
Show file tree
Hide file tree
Showing 4 changed files with 300 additions and 275 deletions.
225 changes: 123 additions & 102 deletions sorc/build_all.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
#! /usr/bin/env bash

set +x
#------------------------------------
# Exception handling is now included.
Expand All @@ -7,40 +8,61 @@ set +x
#
#------------------------------------

_build_ufs_options=""

while getopts "ac" option;do
case $option in
a)
echo "Received -a flag, building ufs-weather-model for ATMAERO app"
echo "skipping builds not needed for prototype runs"
_build_ufs_options=-a
break
;;
c)
echo "Received -c flag, building ufs-weather-model for S2SW app"
echo "skipping builds not needed for prototype runs"
_build_ufs_options=-c
break
;;
esac
done

#------------------------------------
# END USER DEFINED STUFF
#------------------------------------
function _usage() {
cat <<-EOF
Builds all of the global-workflow components by calling the individual build
scripts in sequence.
Usage: $BASH_SOURCE [-a UFS_app][-c build_config][-h][-v]
-a UFS_app:
Build a specific UFS app instead of the default
-c build_config:
Selectively build based on the provided config instead of the default config
-h:
print this help message and exit
-v:
Execute all build scripts with -v option to turn on verbose where supported
EOF
exit 1
}

_build_ufs_opt=""
_verbose_opt=""
# Reset option counter in case this script is sourced
OPTIND=1
while getopts ":a:c:hv" option; do
case "${option}" in
a) _build_ufs_opt+="-a ${OPTARG} ";;
c) _partial_opt+="-c ${OPTARG} ";;
h) _usage;;
# s) _build_ufs_opt+="-s ${OPTARG} ";;
v) _verbose_opt="-v";;
\?)
echo "Unrecognized option: ${option}"
usage
;;
:)
echo "${option} requires an argument"
usage
;;
esac
done

build_dir=$(pwd)
logs_dir=$build_dir/logs
if [ ! -d $logs_dir ]; then
echo "Creating logs folder"
mkdir $logs_dir
echo "Creating logs folder"
mkdir $logs_dir
fi

# Check final exec folder exists
if [ ! -d "../exec" ]; then
echo "Creating ../exec folder"
mkdir ../exec
echo "Creating ../exec folder"
mkdir ../exec
fi

#------------------------------------
Expand All @@ -52,12 +74,12 @@ source ./machine-setup.sh > /dev/null 2>&1
#------------------------------------
# INCLUDE PARTIAL BUILD
#------------------------------------
. ./partial_build.sh $@
source ./partial_build.sh $_verbose_opt $_partial_opt

if [ $target = jet ]; then
Build_gldas=false
Build_gfs_util=false
Build_ww3_prepost=false
Build_gldas=false
Build_gfs_util=false
Build_ww3_prepost=false
fi

#------------------------------------
Expand All @@ -66,133 +88,132 @@ fi
ERRSCRIPT=${ERRSCRIPT:-'eval [[ $err = 0 ]]'}
err=0


#------------------------------------
# build WW3 pre & post execs
#------------------------------------
$Build_ww3_prepost && {
echo " .... Building WW3 pre and post execs .... "
./build_ww3prepost.sh > $logs_dir/build_ww3_prepost.log 2>&1
rc=$?
if [[ $rc -ne 0 ]] ; then
echo "Fatal error in building WW3 pre/post processing."
echo "The log file is in $logs_dir/build_ww3_prepost.log"
fi
((err+=$rc))
echo " .... Building WW3 pre and post execs .... "
./build_ww3prepost.sh ${_verbose_opt} > $logs_dir/build_ww3_prepost.log 2>&1
rc=$?
if [[ $rc -ne 0 ]] ; then
echo "Fatal error in building WW3 pre/post processing."
echo "The log file is in $logs_dir/build_ww3_prepost.log"
fi
((err+=$rc))
}

#------------------------------------
# build forecast model
#------------------------------------
$Build_ufs_model && {
echo " .... Building forecast model .... "
./build_ufs.sh ${_build_ufs_options} > $logs_dir/build_ufs.log 2>&1
rc=$?
if [[ $rc -ne 0 ]] ; then
echo "Fatal error in building UFS model."
echo "The log file is in $logs_dir/build_ufs.log"
fi
((err+=$rc))
echo " .... Building forecast model .... "
./build_ufs.sh $_verbose_opt ${_build_ufs_opt} > $logs_dir/build_ufs.log 2>&1
rc=$?
if [[ $rc -ne 0 ]] ; then
echo "Fatal error in building UFS model."
echo "The log file is in $logs_dir/build_ufs.log"
fi
((err+=$rc))
}

#------------------------------------
# build gsi
#------------------------------------
$Build_gsi && {
echo " .... Building gsi .... "
./build_gsi.sh > $logs_dir/build_gsi.log 2>&1
rc=$?
if [[ $rc -ne 0 ]] ; then
echo "Fatal error in building gsi."
echo "The log file is in $logs_dir/build_gsi.log"
fi
((err+=$rc))
echo " .... Building gsi .... "
./build_gsi.sh $_verbose_opt > $logs_dir/build_gsi.log 2>&1
rc=$?
if [[ $rc -ne 0 ]] ; then
echo "Fatal error in building gsi."
echo "The log file is in $logs_dir/build_gsi.log"
fi
((err+=$rc))
}

#------------------------------------
# build ncep_post
#------------------------------------
$Build_ncep_post && {
echo " .... Building ncep_post .... "
./build_ncep_post.sh > $logs_dir/build_ncep_post.log 2>&1
rc=$?
if [[ $rc -ne 0 ]] ; then
echo "Fatal error in building ncep_post."
echo "The log file is in $logs_dir/build_ncep_post.log"
fi
((err+=$rc))
echo " .... Building ncep_post .... "
./build_ncep_post.sh $_verbose_opt > $logs_dir/build_ncep_post.log 2>&1
rc=$?
if [[ $rc -ne 0 ]] ; then
echo "Fatal error in building ncep_post."
echo "The log file is in $logs_dir/build_ncep_post.log"
fi
((err+=$rc))
}

#------------------------------------
# build ufs_utils
#------------------------------------
$Build_ufs_utils && {
echo " .... Building ufs_utils .... "
./build_ufs_utils.sh > $logs_dir/build_ufs_utils.log 2>&1
rc=$?
if [[ $rc -ne 0 ]] ; then
echo "Fatal error in building ufs_utils."
echo "The log file is in $logs_dir/build_ufs_utils.log"
fi
((err+=$rc))
echo " .... Building ufs_utils .... "
./build_ufs_utils.sh $_verbose_opt > $logs_dir/build_ufs_utils.log 2>&1
rc=$?
if [[ $rc -ne 0 ]] ; then
echo "Fatal error in building ufs_utils."
echo "The log file is in $logs_dir/build_ufs_utils.log"
fi
((err+=$rc))
}

#------------------------------------
# build gldas
#------------------------------------
$Build_gldas && {
echo " .... Building gldas .... "
./build_gldas.sh > $logs_dir/build_gldas.log 2>&1
rc=$?
if [[ $rc -ne 0 ]] ; then
echo "Fatal error in building gldas."
echo "The log file is in $logs_dir/build_gldas.log"
fi
((err+=$rc))
echo " .... Building gldas .... "
./build_gldas.sh $_verbose_opt > $logs_dir/build_gldas.log 2>&1
rc=$?
if [[ $rc -ne 0 ]] ; then
echo "Fatal error in building gldas."
echo "The log file is in $logs_dir/build_gldas.log"
fi
((err+=$rc))
}

#------------------------------------
# build gfs_wafs - optional checkout
#------------------------------------
if [ -d gfs_wafs.fd ]; then
$Build_gfs_wafs && {
echo " .... Building gfs_wafs .... "
./build_gfs_wafs.sh > $logs_dir/build_gfs_wafs.log 2>&1
rc=$?
if [[ $rc -ne 0 ]] ; then
echo "Fatal error in building gfs_wafs."
echo "The log file is in $logs_dir/build_gfs_wafs.log"
fi
((err+=$rc))
$Build_gfs_wafs && {
echo " .... Building gfs_wafs .... "
./build_gfs_wafs.sh $_verbose_opt > $logs_dir/build_gfs_wafs.log 2>&1
rc=$?
if [[ $rc -ne 0 ]] ; then
echo "Fatal error in building gfs_wafs."
echo "The log file is in $logs_dir/build_gfs_wafs.log"
fi
((err+=$rc))
}
fi

#------------------------------------
# build workflow_utils
#------------------------------------
$Build_workflow_utils && {
echo " .... Building workflow_utils .... "
target=$target ./build_workflow_utils.sh > $logs_dir/build_workflow_utils.log 2>&1
rc=$?
if [[ $rc -ne 0 ]] ; then
echo "Fatal error in building workflow_utils."
echo "The log file is in $logs_dir/build_workflow_utils.log"
fi
((err+=$rc))
echo " .... Building workflow_utils .... "
target=$target ./build_workflow_utils.sh $_verbose_opt > $logs_dir/build_workflow_utils.log 2>&1
rc=$?
if [[ $rc -ne 0 ]] ; then
echo "Fatal error in building workflow_utils."
echo "The log file is in $logs_dir/build_workflow_utils.log"
fi
((err+=$rc))
}

#------------------------------------
# build gfs_util
#------------------------------------
$Build_gfs_util && {
echo " .... Building gfs_util .... "
./build_gfs_util.sh > $logs_dir/build_gfs_util.log 2>&1
rc=$?
if [[ $rc -ne 0 ]] ; then
echo "Fatal error in building gfs_util."
echo "The log file is in $logs_dir/build_gfs_util.log"
fi
((err+=$rc))
echo " .... Building gfs_util .... "
./build_gfs_util.sh $_verbose_opt > $logs_dir/build_gfs_util.log 2>&1
rc=$?
if [[ $rc -ne 0 ]] ; then
echo "Fatal error in building gfs_util."
echo "The log file is in $logs_dir/build_gfs_util.log"
fi
((err+=$rc))
}

#------------------------------------
Expand Down
18 changes: 8 additions & 10 deletions sorc/build_ufs.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#! /usr/bin/env bash
set -eux

# Build ATMW by default
APP="ATMW"
CCPP_SUITES="FV3_GFS_v16,FV3_GFS_v16_RRTMGP,FV3_GFS_v16_ugwpv1,FV3_GFS_v17_p8"
# Default settings
APP="S2SWA"
CCPP_SUITES="FV3_GFS_v16,FV3_GFS_v16_RRTMGP,FV3_GFS_v16_ugwpv1,FV3_GFS_v17_p8,FV3_GFS_v16_coupled_nsstNoahmpUGWPv1,FV3_GFS_v16_coupled_p7_rrtmgp,FV3_GFS_v17_coupled_p8"

while getopts "c" option; do
while getopts "a:s:v" option; do
case "${option}" in
c)
APP="S2SW"
CCPP_SUITES="FV3_GFS_v16_coupled_nsstNoahmpUGWPv1,FV3_GFS_v16_coupled_p7_rrtmgp,FV3_GFS_v17_coupled_p8"
;;
a) APP="${OPTARG}" ;;
# s) CCPP_SUITES="${OPTARG}";;
v) BUILD_VERBOSE="YES";;
*)
echo "Unrecognized option: ${1}"
exit 1
Expand All @@ -30,7 +29,6 @@ esac

MOD_PATH=$cwd/ufs_model.fd/modulefiles


cd ufs_model.fd/
set +x
module purge
Expand All @@ -43,5 +41,5 @@ if [ -d build ]; then
rm -R build
fi
mkdir -p build && cd build
cmake -DAPP=${APP} -DCCPP_SUITES=${CCPP_SUITES} -DUFS_GOCART="ON" ..
cmake -DAPP=${APP} -DCCPP_SUITES=${CCPP_SUITES} ..
OMP_NUM_THREADS=1 make -j ${BUILD_JOBS:-8} VERBOSE=${BUILD_VERBOSE:-}
File renamed without changes.
Loading

0 comments on commit fa12db2

Please sign in to comment.