Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
362 changes: 316 additions & 46 deletions scripts/0.run_all.bash
Original file line number Diff line number Diff line change
@@ -1,68 +1,338 @@
#!/bin/bash


#if [ $# -ne 5 ]
#then
# echo ""
# echo "Instructions: execute the command below"
# echo ""
# echo "${0} GitHubUserRepo EXP_NAME RESOLUTION LABELI FCST"
# echo ""
# echo "GitHubUserRepo :: GitHub link for your personal fork, eg: https://github.com/MYUSER/MONAN-Model.git"
# echo "EXP_NAME :: Forcing: GFS"
# echo "RESOLUTION :: number of points in resolution model grid, e.g: 1024002 (24 km)"
# echo "LABELI :: Initial date YYYYMMDDHH, e.g.: 2024010100"
# echo "FCST :: Forecast hours, e.g.: 24 or 36, etc."
# echo ""
# echo "24 hour forcast example:"
# echo "${0} https://github.com/MYUSER/MONAN-Model.git GFS 1024002 2024010100 24"
# echo ""
# exit
#fi

# Set environment variables exports:
echo ""
echo -e "\033[1;32m==>\033[0m Moduling environment for MONAN model...\n"


#--- Function that shows usage.
function show_usage() {
echo " Usage: "
echo ""
echo " ${0} [-o] [-z] [-bc TAG_CONVERT_MPAS] [ -bm TAG_MONAN ] [-d OUTPUT_DIAG_INT] \\"
echo " [-e EXP ] [-f FCST] [-gc GIT_CONVERT_MPAS] [-gm GIT_MONAN ] [-i INPUT_PATH] \\"
echo " [-l NLEV] [-r RES] [-s STEP] [-t YYYYMMDDHH] [-v VARTABLE]"
echo ""
echo " List of optional flags: "
echo ""
echo " -bc TAG_CONVERT -- branch or tag name of the MONAN repository. For example:"
echo " \"develop\". This is used only by step 1."
echo " -bm TAG_MONAN -- branch or tag name of the MONAN repository. For example:"
echo " \"develop\". This is used only by step 1."
echo " -d OUTPUT_DIAG_INT -- Output interval for diagnostic. The format must be"
echo " \"HH:MM:SS\". This is used by steps 3 and 4."
echo " -e EXP -- Meteorological drivers. For example, GFS"
echo " -f FCST -- Simulation length in hours, e.g., 24 or 48."
echo " -gc GIT_CONVERT -- GitHub handle for MONAN. For example:"
echo " https://github.com/monanadmin/MONAN-Model.git"
echo " This is used only by step 1."
echo " -gm GIT_MONAN -- GitHub handle for MONAN. For example:"
echo " https://github.com/monanadmin/MONAN-Model.git"
echo " This is used only by step 1."
echo " -i INPUT_PATH -- Path containing input data for MONAN. If left empty, the"
echo " default path defined in setenv.bash will be used"
echo " -l NLEV -- Number of vertical levels for the output. This is used"
echo " by steps 3 and 4."
echo " -o -- Overwrite static files. This is used only by step 2."
echo " -r RES -- grid resolution. Supported options are:"
echo " 5898242 (~ 10 km)"
echo " 2621442 (~ 15 km)"
echo " 1024002 (~ 24 km)"
echo " 40962 (~ 120 km)"
echo " -s STEP -- Step to run. Options are:"
echo " 1 - Compile MONAN executables."
echo " 2 - Run pre-processing."
echo " 3 - Run atmospheric model."
echo " 4 - Run post-processing."
echo " 0 - Run all steps 1-4."
echo " -t YYYYMMDDHH -- Initial time. For example if 22 Sept 2025 00 UTC, the"
echo " argument should be 2025092200. This is used by steps"
echo " 2, 3 and 4."
echo " -v VARTABLE -- Suffix for defining which version of the"
echo " stream_list_atmosphere.diagnostics template to use."
echo " The default is to not use any suffix. This is used only"
echo " by steps 3 and 4."
echo " -z -- This will remove all files generated by all scripts and"
echo " reset the directory to the original state, except for"
echo " directory \"scripts\"."
echo ""
echo " All settings can be defined directly in the script."
echo ""
}
#---~---


#--- Set environment variables exports:
. setenv.bash
#---~---




#--- Default input variables:
STEP=1
OVERWRITE=""
github_link_MONAN="https://github.com/monanadmin/MONAN-Model.git"
tag_or_branch_name_MONAN="release/1.4.1-rc"
github_link_CONVERT_MPAS="https://github.com/monanadmin/convert_mpas.git"
tag_or_branch_name_CONVERT_MPAS="release/1.2.0"
EXP="GFS"
INPUT_PATH=""
RES=1024002
YYYYMMDDHHi=2024010100
FCST=24
NLEV=55
OUTPUT_DIAG_INTERVAL="03:00:00"
VARTABLE=""
ZERO_STATE=false
#---~---


# Standart directories variables:---------------------------------------
#--- Parse arguments.
while [[ ${#} > 0 ]]
do
key="${1}"
case ${key} in
-bc)
tag_or_branch_name_CONVERT_MPAS="${2}"
shift 2 # past flag and argument
;;
-bm)
tag_or_branch_name_MONAN="${2}"
shift 2 # past flag and argument
;;
-d)
OUTPUT_DIAG_INTERVAL="${2}"
shift 2 # Past flag and argument
;;
-e)
EXP="${2}"
shift 2 # past flag and argument
;;
-f)
FCST="${2}"
shift 2 # past flag and argument
;;
-gc)
github_link_CONVERT_MPAS="${2}"
shift 2 # past flag and argument
;;
-gm)
github_link_MONAN="${2}"
shift 2 # past flag and argument
;;
-i)
INPUT_PATH="${2}"
shift 2 # Past flag and argument
;;
-l)
NLEV="${2}"
shift 2 # Past flag and argument
;;
-o)
OVERWRITE="-o"
shift 1 # past flag
;;
-r)
RES="${2}"
shift 2 # past flag and argument
;;
-s)
STEP="${2}"
shift 2 # past flag and argument
;;
-t)
YYYYMMDDHHi="${2}"
shift 2 # past flag and argument
;;
-v)
VFIRST=$(echo ${2} | cut -c 1-1)
case "${VFIRST}" in
.) VARTABLE="${2}" ;;
*) VARTABLE=".${2}" ;;
esac
shift 2 # past flag and argument
;;
-z)
ZERO_STATE=true
shift 1 # past flag
;;
*)
echo "Unknown key-value argument pair."
show_usage
exit 2
;;
esac
done
#---~---


#--- Set and create standard directories
DIRHOMES=${DIR_SCRIPTS}/scripts_CD-CT; mkdir -p ${DIRHOMES}
DIRHOMED=${DIR_DADOS}/scripts_CD-CT; mkdir -p ${DIRHOMED}
SCRIPTS=${DIRHOMES}/scripts; mkdir -p ${SCRIPTS}
DATAIN=${DIRHOMED}/datain; mkdir -p ${DATAIN}
DATAOUT=${DIRHOMED}/dataout; mkdir -p ${DATAOUT}
SOURCES=${DIRHOMES}/sources; mkdir -p ${SOURCES}
EXECS=${DIRHOMED}/execs; mkdir -p ${EXECS}
#----------------------------------------------------------------------
#---~---



# Input variables:-----------------------------------------------------
github_link="https://github.com/monanadmin/MONAN-Model.git"
monan_branch=release/1.4.1-rc
convertmpas_branch=release/1.2.0
EXP=GFS
RES=1024002
YYYYMMDDHHi=2024010100
FCST=24
#----------------------------------------------------------------------

#---~---
# If the user has set -z, we ask for confirmation before all work is deleted...
#---~---
if ${ZERO_STATE}
then
echo -e ""
echo -e "${ORANGE}!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!${NC}"
echo -e "${ORANGE}!!! WARNING !!! WARNING !!! WARNING !!! WARNING !!!${NC}"
echo -e "${ORANGE}!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!${NC}"
echo -e "${ORANGE}==>${NC} This script is about to reset this working case."
read -p " Are you sure about this? [y|N] " proceed
proceed=$(echo ${proceed:-N} | tr [:upper:] [:lower:])
case "${proceed}" in
y|yes)
#---~---
# Give one last chance to avoid accidental file deletion.
#---~---
echo -e ""
echo -e ""
echo -e "${ORANGE}==>${NC} Alright, but mind that this cannot be undone."
echo -e "${ORANGE}==>${NC} I am giving you a few seconds to cancel this script"
echo -e " in case you change your mind. Hit Ctrl+C before the countdown ends."
echo -e ""
echo -e ""
count=11
while [[ ${count} -gt 1 ]]
do
let count=${count}-1
echo -e "${ORANGE}==>${NC} File deletion will begin in ${count} seconds."
sleep 1
done
/bin/rm -frv ${DATAIN}
/bin/rm -frv ${DATAOUT}
/bin/rm -frv ${SOURCES}
/bin/rm -frv ${EXECS}
/bin/rm -frv ${DIR_SCRIPTS}/run.??????????
;;
*)
#--- Keep files.
echo -e ""
echo -e "${GREEN}==>${NC} Keeping all files. To run MONAN, call this script again"
echo -e " without the \"-z\" option."
#---~---
;;
esac

#---~---
# We do not run the scripts when -z is set.
#---~---
exit 0
#---~---
fi
#---~---


#--- If INPUT_PATH is provided, replace the path in setenv.bash
if [[ "${INPUT_PATH}" != "" ]] && [[ -d "${INPUT_PATH}" ]]
then
sed -i.bck "s,^export DIRDADOS=.*,export DIRDADOS=${INPUT_PATH},g" ${SCRIPTS}/setenv.bash
/bin/rm -f ${SCRIPTS}/setenv.bash.bck
fi
#---~---


#---~---
# Make sure the grid resolution settings are valid.
#---~---
case "${RES}" in
5898242)
echo -e "${GREEN}==>${NC} Grid resolution ${RES} (~ 10 km).\n"
;;
2621442)
echo -e "${GREEN}==>${NC} Grid resolution ${RES} (~ 15 km).\n"
;;
1024002)
echo -e "${GREEN}==>${NC} Grid resolution ${RES} (~ 24 km).\n"
;;
40962)
echo -e "${GREEN}==>${NC} Grid resolution ${RES} (~ 120 km).\n"
;;
*)
echo -e "${ORANGE}****** WARNING ******${NC} \n"
echo -e "${ORANGE}==>${NC} Provided grid resolution (${RES}) is not recognised.\n"
echo -e "${ORANGE}==>${NC} We cannot guarantee that MONAN will run fine.\n"
;;
esac
#---~---


# STEP 1: Installing and compiling the A-MONAN model and utility programs:
#time ${SCRIPTS}/1.install_monan.bash ${github_link} ${monan_branch} ${convertmpas_branch}
#exit
#--- Make sure VARTABLE has the leading "-v" if not empty.
if [[ "${VARTABLE}" == "" ]]
then
dv_VARTABLE=""
else
dv_VARTABLE="-v ${VARTABLE}"
fi
#---~---

# STEP 2: Executing the pre-processing fase. Preparing all CI/CC files needed:
#time ${SCRIPTS}/2.pre_processing.bash ${EXP} ${RES} ${YYYYMMDDHHi} ${FCST}
#exit

# STEP 3: Executing the Model run:
time ${SCRIPTS}/3.run_model.bash ${EXP} ${RES} ${YYYYMMDDHHi} ${FCST}
exit
#---~---
# Select step.
#---~---
case ${STEP} in
0)
#---~---
# Call the script itself four times, passing all the configuration.
#---~---
step_now=0
while [[ ${step_now} -lt 4 ]]
do
#--- Update step
let step_now=${step_now}+1
#---~---

# STEP 4: Executing the Post of Model run:
time ${SCRIPTS}/4.run_post.bash ${EXP} ${RES} ${YYYYMMDDHHi} ${FCST}
exit

time ${SCRIPTS}/make_template.bash ${EXP} ${RES} ${YYYYMMDDHHi} ${FCST}
#--- Run step
time ${0} ${OVERWRITE} ${dv_VARTABLE} -bc ${tag_or_branch_name_CONVERT_MPAS} \
-bm ${tag_or_branch_name_MONAN} -d ${OUTPUT_DIAG_INTERVAL} -e ${EXP} -f ${FCST} \
-gc ${github_link_CONVERT_MPAS} -gm ${github_link_MONAN} -l ${NLEV} -r ${RES} \
-s ${step_now} -t ${YYYYMMDDHHi}
#---~---
done
#---~---
;;
1)
#---~---
# STEP 1: Install and compile MONAN and its utility programs.
#---~---
time 1.install_monan.bash -bc ${tag_or_branch_name_CONVERT_MPAS} \
-bm ${tag_or_branch_name_MONAN} -gc ${github_link_CONVERT_MPAS} \
-gm ${github_link_MONAN}
#---~---
;;
2)
#---~---
# STEP 2: Run the pre-processing step, and make initial/boundary conditions if needed.
#---~---
time 2.pre_processing.bash ${OVERWRITE} -e ${EXP} -f ${FCST} -r ${RES} -t ${YYYYMMDDHHi}
#---~---
;;
3)
#---~---
# STEP 3: Run the model.
#---~---
time 3.run_model.bash ${dv_VARTABLE} -d ${OUTPUT_DIAG_INTERVAL} -e ${EXP} -f ${FCST} \
-l ${NLEV} -r ${RES} -t ${YYYYMMDDHHi}
#---~---
;;
4)
#---~---
# STEP 4: Run the post-processing step.
#---~---
time 4.run_post.bash ${dv_VARTABLE} -d ${OUTPUT_DIAG_INTERVAL} -e ${EXP} -f ${FCST} \
-l ${NLEV} -r ${RES} -t ${YYYYMMDDHHi}
#---~---
;;
esac
#---~---
Loading