From bbaf4b6537ea96e6e08a84468c2cb7471809a07b Mon Sep 17 00:00:00 2001 From: mpaiao Date: Mon, 5 Jan 2026 13:46:33 -0300 Subject: [PATCH 01/11] Minor edits to the CD-CT scripts. The numbered scripts now use flags to specify which settings to use (resolution, input). This provides a more intuitive (albeit more verbose) method to configure the runs. Script 0.run_all.bash was rewritten such that all settings can go through it, and a new "step" argument can be passed to specify which step to run (as opposed to commenting or uncommenting each step). --- scripts/0.run_all.bash | 253 +++++++++++++++++++++++++++------- scripts/1.install_monan.bash | 104 ++++++++++---- scripts/2.pre_processing.bash | 128 ++++++++++++----- scripts/3.run_model.bash | 158 +++++++++++++++------ scripts/4.run_post.bash | 158 +++++++++++++++------ scripts/make_degrib.bash | 2 - scripts/make_initatmos.bash | 2 - scripts/make_static.bash | 2 - scripts/make_template.bash | 2 - scripts/setenv.bash | 29 ++-- 10 files changed, 630 insertions(+), 208 deletions(-) diff --git a/scripts/0.run_all.bash b/scripts/0.run_all.bash index c020acc..0155c7b 100755 --- a/scripts/0.run_all.bash +++ b/scripts/0.run_all.bash @@ -1,32 +1,157 @@ #!/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} [-s STEP] [-c] [-o] [-gm GIT_MONAN ] [ -bm TAG_MONAN ] \\" + echo " [-gc GIT_CONVERT_MPAS] [-bc TAG_CONVERT_MPAS] [-e EXP ] [-r RES] \\" + echo " [-i YYYYMMDDHH] [-f FCST]" + echo "" + echo " List of optional flags: " + echo "" + 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 " -c -- Clean files from previous runs (used only if step is 2,3 or 4)." + echo " -o -- Overwrite static files (used only if step is 2)." + echo " -gm GIT_MONAN -- GitHub handle for MONAN. For example:" + echo " https://github.com/monanadmin/MONAN-Model.git" + echo " -bm TAG_MONAN -- branch or tag name of the MONAN repository. For example:" + echo " \"develop\"." + echo " -gm GIT_CONVERT -- GitHub handle for MONAN. For example:" + echo " https://github.com/monanadmin/MONAN-Model.git" + echo " -bm TAG_CONVERT -- branch or tag name of the MONAN repository. For example:" + echo " \"develop\"." + echo " -e EXP -- meteorological drivers. For example, GFS" + echo " -r RES -- grid resolution. Options are:" + echo " 5898242 (~ 10 km)" + echo " 2621442 (~ 15 km)" + echo " 1024002 (~ 24 km)" + echo " 40962 (~ 120 km)" + echo " -i YYYYMMDDHH -- Initial time. For example if 22 Sept 2025 00 UTC, set it to:" + echo " 2025092200" + echo " -f FCST -- Simulation length in hours, e.g., 24 or 48." + echo "" + echo " All settings can be defined directly in the script." + echo "" +} +#---~--- + + +#--- Set environment variables exports: . setenv.bash +#---~--- + + + + +#--- Default input variables: +STEP=1 +CLEAN="" +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" +RES=1024002 +YYYYMMDDHHi=2024010100 +FCST=24 +#---~--- -# 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 + ;; + -c) + CLEAN="-c" + shift 1 # Past flag + ;; + -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) + YYYYMMDDHHi="${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 + ;; + *) + echo "Unknown key-value argument pair." + show_usage + exit 2 + ;; + esac +done +#---~--- + + +#---~--- +# 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 +#---~--- + + +#--- 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} @@ -34,35 +159,65 @@ 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 -#---------------------------------------------------------------------- +#---~--- -# 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 -# 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} -s ${step_now} ${CLEAN} ${OVERWRITE} -gm ${github_link_MONAN} \ + -bm ${tag_or_branch_name_MONAN} -gc ${github_link_CONVERT_MPAS} \ + -bc ${tag_or_branch_name_CONVERT_MPAS} -e ${EXP} -r ${RES} -i ${YYYYMMDDHHi} \ + -f ${FCST} + #---~--- + done + #---~--- + ;; +1) + #---~--- + # STEP 1: Install and compile MONAN and its utility programs. + #---~--- + time 1.install_monan.bash -gm ${github_link_MONAN} -bm ${tag_or_branch_name_MONAN} \ + -gc ${github_link_CONVERT_MPAS} -bc ${tag_or_branch_name_CONVERT_MPAS} + #---~--- + ;; +2) + #---~--- + # STEP 2: Run the pre-processing step, and make initial/boundary conditions if needed. + #---~--- + time 2.pre_processing.bash ${CLEAN} ${OVERWRITE} -e ${EXP} -r ${RES} -i ${YYYYMMDDHHi} \ + -f ${FCST} + #---~--- + ;; +3) + #---~--- + # STEP 3: Run the model. + #---~--- + time 3.run_model.bash ${CLEAN} -e ${EXP} -r ${RES} -i ${YYYYMMDDHHi} -f ${FCST} + #---~--- + ;; +4) + #---~--- + # STEP 4: Run the post-processing step. + #---~--- + time 4.run_post.bash -e ${EXP} -r ${RES} -i ${YYYYMMDDHHi} -f ${FCST} + #---~--- + ;; +esac +#---~--- diff --git a/scripts/1.install_monan.bash b/scripts/1.install_monan.bash index 5cb3f22..7551ca1 100755 --- a/scripts/1.install_monan.bash +++ b/scripts/1.install_monan.bash @@ -16,9 +16,29 @@ # #-----------------------------------------------------------------------------# -#Fixed parameters ------------------------------------------------------------# -github_link_CONVERT_MPAS="https://github.com/monanadmin/convert_mpas.git" -#-----------------------------------------------------------------------------# + +#--- Function that shows usage. +function show_usage() { + echo " Usage: " + echo "" + echo " ${0} -gm GIT_MONAN -bm TAG_MONAN \\" + echo " -gc GIT_CONVERT_MPAS -bc TAG_CONVERT_MPAS" + echo "" + echo " List of **required** flags: " + echo "" + echo " -gm GIT_MONAN -- GitHub handle for MONAN. For example:" + echo " https://github.com/monanadmin/MONAN-Model.git" + echo " -bm TAG_MONAN -- branch or tag name of the MONAN repository. For example:" + echo " \"develop\"." + echo " -gm GIT_CONVERT -- GitHub handle for MONAN. For example:" + echo " https://github.com/monanadmin/MONAN-Model.git" + echo " -bm TAG_CONVERT -- branch or tag name of the MONAN repository. For example:" + echo " \"develop\"." + echo "" +} +#---~--- + + #Functions -------------------------------------------------------------------# function checkout_system() { @@ -50,27 +70,69 @@ function checkout_system() { #-----------------------------------------------------------------------------# -if [ $# -lt 1 ] +#---~--- +# Retrieve configuration. +#---~--- +#--- Default settings (all empty) +github_link_MONAN="" +tag_or_branch_name_MONAN="" +github_link_CONVERT_MPAS="" +tag_or_branch_name_CONVERT_MPAS="" +#---~--- + + +#---~--- +# 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 + ;; + -gc) + github_link_CONVERT_MPAS="${2}" + shift 2 # past flag and argument + ;; + -gm) + github_link_MONAN="${2}" + shift 2 # past flag and argument + ;; + *) + echo "Unknown key-value argument pair." + show_usage + exit 2 + ;; + esac +done +#---~--- + +#---~--- +# Stop if any variable remains unset +#---~--- +if [[ "${tag_or_branch_name_CONVERT_MPAS}" == "" ]] || + [[ "${tag_or_branch_name_MONAN}" == "" ]] || + [[ "${github_link_CONVERT_MPAS}" == "" ]] || + [[ "${github_link_MONAN}" == "" ]] then - echo "" - echo "Instructions: execute the command below" - echo "" - echo "${0} [G] [M] [C]" - echo "" - echo "G :: MONAN GitHub link of your personal fork, eg: https://github.com/MYUSER/MONAN-Model.git" - echo "M :: MONAN tag or branch name of your personal fork. (will be used 'develop' if not informed)" - echo "C :: Convert_MPAS tag from ${github_link_CONVERT_MPAS} (will be used 'develop' if not informed)" - echo "" - exit + echo " This script requires arguments to be set through flags." + show_usage + exit 2 fi +#---~--- -# Set environment variables exports: -echo "" -echo -e "\033[1;32m==>\033[0m Moduling environment for MONAN model...\n" +#--- Set environment variables exports: . setenv.bash +#---~--- -# Standart directories variables:--------------------------------------- +#--- 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} @@ -82,13 +144,9 @@ EXECS=${DIRHOMED}/execs; mkdir -p ${EXECS} # Input variables:----------------------------------------------------- -github_link_MONAN=${1}; #github_link=https://github.com/monanadmin/MONAN-Model.git -tag_or_branch_name_MONAN=${2} tag_or_branch_name_MONAN=${tag_or_branch_name_MONAN:="release/1.3.1-rc"} -echo "MONAN branch name in use: ${tag_or_branch_name_MONAN}" - -tag_or_branch_name_CONVERT_MPAS=${3} tag_or_branch_name_CONVERT_MPAS=${tag_or_branch_name_CONVERT_MPAS:="1.1.0"} +echo "MONAN branch name in use: ${tag_or_branch_name_MONAN}" echo "convert_mpas branch name in use: ${tag_or_branch_name_CONVERT_MPAS}" #---------------------------------------------------------------------- diff --git a/scripts/2.pre_processing.bash b/scripts/2.pre_processing.bash index 34458f3..05eddc4 100755 --- a/scripts/2.pre_processing.bash +++ b/scripts/2.pre_processing.bash @@ -17,37 +17,111 @@ # #-----------------------------------------------------------------------------# -if [ $# -ne 4 -a $# -ne 1 ] -then + + +#--- Function that shows usage. +function show_usage() { + echo " Usage: " + echo "" + echo " ${0} [-c] [-o] [-e EXP ] [-r RES] [-i YYYYMMDDHH] [-f FCST]" echo "" - echo "Instructions: execute the command below" + echo " List of optional flags: " echo "" - echo "${0} EXP_NAME/OP RESOLUTION LABELI FCST" + echo " -c -- Clean files from previous runs." + echo " -o -- Overwrite static files." echo "" - echo "EXP_NAME :: Forcing: GFS" - echo " :: Others options to be added later..." - echo "RESOLUTION :: number of points in resolution model grid, e.g: 1024002 (24 km)" - echo " 40962 (120 km)" - echo "LABELI :: Initial date YYYYMMDDHH, e.g.: 2024010100" - echo "FCST :: Forecast hours, e.g.: 24 or 36, etc." + echo " List of required flags when -c is not set: " echo "" - echo "24 hour forecast example for 24km:" - echo "${0} GFS 1024002 2024010100 24" - echo "48 hour forecast example for 120km:" - echo "${0} GFS 40962 2024010100 48" + echo " -e EXP -- meteorological drivers. For example, GFS" + echo " -r RES -- grid resolution. Options are:" + echo " 5898242 (~ 10 km)" + echo " 2621442 (~ 15 km)" + echo " 1024002 (~ 24 km)" + echo " 40962 (~ 120 km)" + echo " -i YYYYMMDDHH -- Initial time. For example if 22 Sept 2025 00 UTC, set it to:" + echo " 2025092200" + echo " -f FCST -- Simulation length in hours, e.g., 24 or 48." echo "" +} +#---~--- - exit -fi -# Set environment variables exports: -echo "" -echo -e "\033[1;32m==>\033[0m Moduling environment for MONAN model...\n" +#--- Set environment variables exports: . setenv.bash +#---~--- + + + + +#--- Default input variables: +CLEAN=false +OVERWRITE=true +EXP="" +RES="" +YYYYMMDDHHi="" +FCST="" +#---~--- + + +#--- Parse arguments. +while [[ ${#} > 0 ]] +do + key="${1}" + case ${key} in + -c) + CLEAN=true + shift 1 # Past flag + ;; + -e) + EXP="${2}" + shift 2 # past flag and argument + ;; + -f) + FCST="${2}" + shift 2 # past flag and argument + ;; + -i) + YYYYMMDDHHi="${2}" + shift 2 # past flag and argument + ;; + -o) + OVERWRITE=true + shift 1 # past flag + ;; + -r) + RES="${2}" + shift 2 # past flag and argument + ;; + *) + echo "Unknown key-value argument pair." + show_usage + exit 2 + ;; + esac +done +#---~--- + + + +#---~--- +# Make sure all settings were provided (unless this will be to clean up runs). +#---~--- +if ${CLEAN} +then + clean_pre_tmp_files + exit +elif [[ "${EXP}" == "" ]] || [[ "${RES}" == "" ]] || + [[ "${YYYYMMDDHHi}" == "" ]] || [[ "${FCST}" == "" ]] +then + echo " This script requires some arguments to be set through flags." + show_usage + exit 2 +fi +#---~--- -# Standart directories variables:--------------------------------------- +#--- 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} @@ -55,15 +129,7 @@ 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:-------------------------------------- -EXP=${1}; #EXP=GFS -RES=${2}; #RES=1024002 -YYYYMMDDHHi=${3}; #YYYYMMDDHHi=2024012000 -FCST=${4}; #FCST=24 -#------------------------------------------------------- +#---~--- # Local variables-------------------------------------- @@ -94,12 +160,12 @@ ln -sf ${DIRDADOS}/MONAN_datain/datain/WPS_GEOG ${DATAIN} # Creating the x1.${RES}.static.nc file once, if does not exist yet:--------------- -if [ ! -s ${DATAIN}/fixed/x1.${RES}.static.nc ] +if ${OVERWRITE} || [[ ! -s ${DATAIN}/fixed/x1.${RES}.static.nc ]] then echo -e "${GREEN}==>${NC} Creating static.bash for submiting init_atmosphere to create x1.${RES}.static.nc...\n" time ./make_static.bash ${EXP} ${RES} ${YYYYMMDDHHi} ${FCST} else - echo -e "${GREEN}==>${NC} File x1.${RES}.static.nc already exist in ${DATAIN}/fixed.\n" + echo -e "${GREEN}==>${NC} File x1.${RES}.static.nc already exists in ${DATAIN}/fixed.\n" fi #---------------------------------------------------------------------------------- diff --git a/scripts/3.run_model.bash b/scripts/3.run_model.bash index 8aa323f..3155440 100755 --- a/scripts/3.run_model.bash +++ b/scripts/3.run_model.bash @@ -15,35 +15,103 @@ # #-----------------------------------------------------------------------------# -if [ $# -ne 4 -a $# -ne 1 ] -then +#--- Function that shows usage. +function show_usage() { + echo " Usage: " + echo "" + echo " ${0} [-c] [-o] [-e EXP ] [-r RES] [-i YYYYMMDDHH] [-f FCST]" echo "" - echo "Instructions: execute the command below" + echo " List of optional flags: " echo "" - echo "${0} [EXP_NAME/OP] RESOLUTION LABELI FCST" + echo " -c -- Clean files from previous runs." echo "" - 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 " List of required flags when -c is not set: " echo "" - echo "24 hour forecast example for 24km:" - echo "${0} GFS 1024002 2024010100 24" - echo "48 hour forecast example for 120km:" - echo "${0} GFS 40962 2024010100 48" + echo " -e EXP -- meteorological drivers. For example, GFS" + echo " -r RES -- grid resolution. Options are:" + echo " 5898242 (~ 10 km)" + echo " 2621442 (~ 15 km)" + echo " 1024002 (~ 24 km)" + echo " 40962 (~ 120 km)" + echo " -i YYYYMMDDHH -- Initial time. For example if 22 Sept 2025 00 UTC, set it to:" + echo " 2025092200" + echo " -f FCST -- Simulation length in hours, e.g., 24 or 48." echo "" +} +#---~--- - exit -fi -# Set environment variables exports: -echo "" -echo -e "\033[1;32m==>\033[0m Moduling environment for MONAN model...\n" +#--- Set environment variables exports: . setenv.bash +#---~--- + + + + +#--- Default input variables: +CLEAN=false +EXP="" +RES="" +YYYYMMDDHHi="" +FCST="" +#---~--- + + +#--- Parse arguments. +while [[ ${#} > 0 ]] +do + key="${1}" + case ${key} in + -c) + CLEAN=true + shift 1 # Past flag + ;; + -e) + EXP="${2}" + shift 2 # past flag and argument + ;; + -f) + FCST="${2}" + shift 2 # past flag and argument + ;; + -i) + YYYYMMDDHHi="${2}" + shift 2 # past flag and argument + ;; + -r) + RES="${2}" + shift 2 # past flag and argument + ;; + *) + echo "Unknown key-value argument pair." + show_usage + exit 2 + ;; + esac +done +#---~--- + + + +#---~--- +# Make sure all settings were provided (unless this will be to clean up runs). +#---~--- +if ${CLEAN} +then + clean_pre_tmp_files + exit +elif [[ "${EXP}" == "" ]] || [[ "${RES}" == "" ]] || + [[ "${YYYYMMDDHHi}" == "" ]] || [[ "${FCST}" == "" ]] +then + echo " This script requires some arguments to be set through flags." + show_usage + exit 2 +fi +#---~--- -# Standart directories variables:--------------------------------------- +#--- 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} @@ -51,16 +119,10 @@ 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:-------------------------------------- -EXP=${1}; #EXP=GFS -RES=${2}; #RES=1024002 -YYYYMMDDHHi=${3}; #YYYYMMDDHHi=2024012000 -FCST=${4}; #FCST=6 -#------------------------------------------------------- mkdir -p ${DATAOUT}/${YYYYMMDDHHi}/Model/logs +export DIRRUN=${DIRHOMED}/run.${YYYYMMDDHHi}; rm -fr ${DIRRUN}; mkdir -p ${DIRRUN} +#---~--- + # Local variables-------------------------------------- @@ -70,13 +132,12 @@ hhi=${YYYYMMDDHHi:8:2} NLEV=55 CONFIG_CONV_INTERVAL="00:30:00" VARTABLE=".OPER" -export DIRRUN=${DIRHOMED}/run.${YYYYMMDDHHi}; rm -fr ${DIRRUN}; mkdir -p ${DIRRUN} #------------------------------------------------------------------------------------ # Variables for flex outpout interval from streams.atmosphere------------------------ t_strout=$(cat ${SCRIPTS}/namelists/streams.atmosphere.TEMPLATE | sed -n '//s/.*output_interval="\([^"]*\)".*/\1/p') t_stroutsec=$(echo ${t_strout} | awk -F: '{print ($1 * 3600) + ($2 * 60) + $3}') -t_strouthor=$(echo "scale=4; (${t_stroutsec}/60)/60" | bc) +t_strouthor=`echo "scale=4; (${t_stroutsec}/60)/60" | bc` #------------------------------------------------------------------------------------ # Format to HH:MM:SS t_strout (output_interval) @@ -85,26 +146,39 @@ printf -v t_strout "%02d:%02d:%02d" "$h" "$m" "$s" # From now on, CONFI_LEN_DISP becames cte = 0.0, pickin up this value from static file. # Calculating default parameters for different resolutions -if [ $RES -eq 1024002 ]; then #24Km - CONFIG_DT=150.0 +case ${RES} in +5898242) #10km + CONFIG_DT=60.0 + CONFIG_LEN_DISP=10000.0 CONFIG_CONV_INTERVAL="00:15:00" -elif [ $RES -eq 2621442 ]; then #15Km + ;; +2621442) #15Km CONFIG_DT=90.0 + CONFIG_LEN_DISP=15000.0 CONFIG_CONV_INTERVAL="00:15:00" -elif [ $RES -eq 40962 ]; then #120Km - CONFIG_DT=600.0 -elif [ $RES -eq 5898242 ]; then #10Km - CONFIG_DT=60.0 - CONFIG_LEN_DISP=10000.0 + ;; +1024002) #24Km + CONFIG_DT=150.0 + CONFIG_LEN_DISP=24000.0 CONFIG_CONV_INTERVAL="00:15:00" -fi + ;; +40962) #120Km + CONFIG_DT=600.0 + CONFIG_LEN_DISP=120000.0 + ;; +*) + 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 #------------------------------------------------------- # Calculating final forecast dates in model namelist format: DD_HH:MM:SS # using: start_date(yyyymmdd) + FCST(hh) : -ind=$(printf "%02d\n" $(echo "${FCST}/24" | bc)) -inh=$(printf "%02.0f\n" $(echo "((${FCST}/24)-${ind})*24" | bc -l)) +ind=`printf "%02d\n" $(echo "${FCST}/24" | bc)` +inh=`printf "%02.0f\n" $(echo "((${FCST}/24)-${ind})*24" | bc -l)` DD_HHMMSS_forecast=$(echo "${ind}_${inh}:00:00") @@ -131,7 +205,7 @@ for file in "${files_needed[@]}" do if [ ! -s "${file}" ] then - echo -e "\n${RED}==>${NC} ***** ATTENTION *****\n" + echo -e "\n${RED}==>${NC} ***** FATAL ERROR *****\n" echo -e "${RED}==>${NC} [${0}] At least the file ${file} was not generated. \n" exit -1 fi @@ -233,7 +307,7 @@ do if [ ! -s ${DATAOUT}/${YYYYMMDDHHi}/Model/${file} ] then - echo -e "\n${RED}==>${NC} ***** ATTENTION *****\n" + echo -e "\n${RED}==>${NC} ***** FATAL ERROR *****\n" echo -e "${RED}==>${NC} [${0}] At least the file ${DATAOUT}/${YYYYMMDDHHi}/Model/${file} was not generated. \n" exit -1 fi diff --git a/scripts/4.run_post.bash b/scripts/4.run_post.bash index bd4f5a8..f9dadc4 100755 --- a/scripts/4.run_post.bash +++ b/scripts/4.run_post.bash @@ -15,34 +15,102 @@ # #-----------------------------------------------------------------------------# -if [ $# -ne 4 -a $# -ne 1 ] -then +#--- Function that shows usage. +function show_usage() { + echo " Usage: " + echo "" + echo " ${0} [-c] [-o] [-e EXP ] [-r RES] [-i YYYYMMDDHH] [-f FCST]" echo "" - echo "Instructions: execute the command below" + echo " List of optional flags: " echo "" - echo "${0} ]EXP_NAME/OP] RESOLUTION LABELI FCST" + echo " -c -- Clean files from previous runs." echo "" - 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 " List of required flags when -c is not set: " echo "" - echo "24 hour forcast example:" - echo "${0} GFS 1024002 2024010100 24" - echo "${0} GFS 40962 2024010100 48" + echo " -e EXP -- meteorological drivers. For example, GFS" + echo " -r RES -- grid resolution. Options are:" + echo " 5898242 (~ 10 km)" + echo " 2621442 (~ 15 km)" + echo " 1024002 (~ 24 km)" + echo " 40962 (~ 120 km)" + echo " -i YYYYMMDDHH -- Initial time. For example if 22 Sept 2025 00 UTC, set it to:" + echo " 2025092200" + echo " -f FCST -- Simulation length in hours, e.g., 24 or 48." echo "" +} +#---~--- - exit -fi -# Set environment variables exports: -echo "" -echo -e "\033[1;32m==>\033[0m Moduling environment for MONAN model...\n" +#--- Set environment variables exports: . setenv.bash +#---~--- + + + + +#--- Default input variables: +CLEAN=false +EXP="" +RES="" +YYYYMMDDHHi="" +FCST="" +#---~--- +#--- Parse arguments. +while [[ ${#} > 0 ]] +do + key="${1}" + case ${key} in + -c) + CLEAN=true + shift 1 # Past flag + ;; + -e) + EXP="${2}" + shift 2 # past flag and argument + ;; + -f) + FCST="${2}" + shift 2 # past flag and argument + ;; + -i) + YYYYMMDDHHi="${2}" + shift 2 # past flag and argument + ;; + -r) + RES="${2}" + shift 2 # past flag and argument + ;; + *) + echo "Unknown key-value argument pair." + show_usage + exit 2 + ;; + esac +done +#---~--- + + + +#---~--- +# Make sure all settings were provided (unless this will be to clean up runs). +#---~--- +if ${CLEAN} +then + clean_pre_tmp_files + exit +elif [[ "${EXP}" == "" ]] || [[ "${RES}" == "" ]] || + [[ "${YYYYMMDDHHi}" == "" ]] || [[ "${FCST}" == "" ]] +then + echo " This script requires some arguments to be set through flags." + show_usage + exit 2 +fi +#---~--- + -# Standart directories variables:--------------------------------------- +#--- Set and create standard directories DIRHOMES=${DIR_SCRIPTS}/scripts_CD-CT; mkdir -p ${DIRHOMES} DIRHOMED=${DIR_DADOS}/scripts_CD-CT; mkdir -p ${DIRHOMED} export SCRIPTS=${DIRHOMES}/scripts; mkdir -p ${SCRIPTS} @@ -50,16 +118,11 @@ DATAIN=${DIRHOMED}/datain; mkdir -p ${DATAIN} DATAOUT=${DIRHOMED}/dataout; mkdir -p ${DATAOUT} SOURCES=${DIRHOMES}/sources; mkdir -p ${SOURCES} EXECS=${DIRHOMED}/execs; mkdir -p ${EXECS} -#---------------------------------------------------------------------- +mkdir -p ${DATAOUT}/${YYYYMMDDHHi}/Post/logs +export DIRRUN=${DIRHOMED}/run.${YYYYMMDDHHi}; rm -fr ${DIRRUN}; mkdir -p ${DIRRUN} +#---~--- -# Input variables:-------------------------------------- -EXP=${1}; #EXP=GFS -RES=${2}; #RES=1024002 -YYYYMMDDHHi=${3}; #YYYYMMDDHHi=2024042000 -FCST=${4}; #FCST=40 -#------------------------------------------------------- -mkdir -p ${DATAOUT}/${YYYYMMDDHHi}/Post/logs # Local variables-------------------------------------- @@ -67,14 +130,13 @@ START_DATE_YYYYMMDD="${YYYYMMDDHHi:0:4}-${YYYYMMDDHHi:4:2}-${YYYYMMDDHHi:6:2}" START_HH="${YYYYMMDDHHi:8:2}" maxpostpernode=30 # <------ qtde max de convert_mpas por no! VARTABLE=".OPER" -export DIRRUN=${DIRHOMED}/run.${YYYYMMDDHHi}; rm -fr ${DIRRUN}; mkdir -p ${DIRRUN} N_MODEL_LEV=55 #------------------------------------------------------- # Variables for flex outpout interval from streams.atmosphere------------------------ t_strout=$(cat ${SCRIPTS}/namelists/streams.atmosphere.TEMPLATE | sed -n '//s/.*output_interval="\([^"]*\)".*/\1/p') -t_stroutsec=$(echo ${t_strout} | awk -F: '{print ($1 * 3600) + ($2 * 60) + $3}') -t_strouthor=$(echo "scale=4; (${t_stroutsec}/60)/60" | bc) +t_stroutsec=`echo ${t_strout} | awk -F: '{print ($1 * 3600) + ($2 * 60) + $3}'` +t_strouthor=`echo "scale=4; (${t_stroutsec}/60)/60" | bc` #------------------------------------------------------------------------------------ # Format to HH:MM:SS t_strout (output_interval) @@ -82,35 +144,45 @@ IFS=":" read -r h m s <<< "${t_strout}" printf -v t_strout "%02d:%02d:%02d" "$h" "$m" "$s" # Calculating default parameters for different resolutions -if [ $RES -eq 1024002 ]; then #24Km - NLAT=721 #180/0.25 - NLON=1441 #360/0.25 +case ${RES} in +5898242) #10km + NLAT=1801 #180/0.10 (+1) + NLON=3601 #360/0.10 (+1) STARTLAT=-90.0 STARTLON=0.0 ENDLAT=90.0 ENDLON=360.0 -elif [ $RES -eq 2621442 ]; then #15Km - NLAT=1201 #180/0.15 - NLON=2401 #360/0.15 + ;; +2621442) #15Km + NLAT=1200 #180/0.15 + NLON=2400 #360/0.15 STARTLAT=-90.0 STARTLON=0.0 ENDLAT=90.0 ENDLON=360.0 -elif [ $RES -eq 40962 ]; then #120Km - NLAT=150 #180/1.2 - NLON=300 #360/1.2 + ;; +1024002) #24Km + NLAT=720 #180/0.25 + NLON=1440 #360/0.25 STARTLAT=-90.0 STARTLON=0.0 ENDLAT=90.0 ENDLON=360.0 -elif [ $RES -eq 5898242 ]; then #10Km - NLAT=1801 #180/0.10 (+1) - NLON=3601 #360/0.10 (+1) + ;; +40962) #120Km + NLAT=150 #180/1.2 + NLON=300 #360/1.2 STARTLAT=-90.0 STARTLON=0.0 ENDLAT=90.0 ENDLON=360.0 -fi + ;; +*) + 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 #------------------------------------------------------- # NLEVS get from t_iso_levels in Registry_isobaric.xml: @@ -127,7 +199,7 @@ for file in "${files_needed[@]}" do if [ ! -s "${file}" ] then - echo -e "\n${RED}==>${NC} ***** ATTENTION *****\n" + echo -e "\n${RED}==>${NC} ***** FATAL ERROR *****\n" echo -e "${RED}==>${NC} [${0}] At least the file ${file} was not generated. \n" exit -1 fi @@ -182,7 +254,7 @@ cat > ${DIRRUN}/PostAtmos_node.${node}.sh <\033[0m Moduling environment for MONAN model...\n" . setenv.bash diff --git a/scripts/make_initatmos.bash b/scripts/make_initatmos.bash index 0c28dde..8b67d46 100755 --- a/scripts/make_initatmos.bash +++ b/scripts/make_initatmos.bash @@ -22,8 +22,6 @@ then fi # Set environment variables exports: -echo "" -echo -e "\033[1;32m==>\033[0m Moduling environment for MONAN model...\n" . setenv.bash diff --git a/scripts/make_static.bash b/scripts/make_static.bash index f5e0ee0..260d3ca 100755 --- a/scripts/make_static.bash +++ b/scripts/make_static.bash @@ -22,8 +22,6 @@ then fi # Set environment variables exports: -echo "" -echo -e "\033[1;32m==>\033[0m Moduling environment for MONAN model...\n" . setenv.bash diff --git a/scripts/make_template.bash b/scripts/make_template.bash index c71eb6a..26a7021 100755 --- a/scripts/make_template.bash +++ b/scripts/make_template.bash @@ -36,8 +36,6 @@ then fi # Set environment variables exports: -echo "" -echo -e "\033[1;32m==>\033[0m Moduling environment for MONAN model...\n" . setenv.bash diff --git a/scripts/setenv.bash b/scripts/setenv.bash index 793df23..0874ed9 100755 --- a/scripts/setenv.bash +++ b/scripts/setenv.bash @@ -1,5 +1,16 @@ #!/bin/bash +# Colors: +export GREEN='\033[1;32m' # Green +export RED='\033[1;31m' # Red +export NC='\033[0m' # No Color +export BLUE='\033[01;34m' # Blue +export ORANGE='\033[01;91m' # Orange + +# Notify users that this script is being called. +echo "" +echo -e "${GREEN}==>${NC} Load MONAN settings (setenv.bash).\n" + # Load modules: module purge @@ -26,7 +37,7 @@ module list # Put your directories: export DIR_SCRIPTS=$(dirname $(dirname $(pwd))) export DIR_DADOS=$(dirname $(dirname $(pwd))) -export MONANDIR=/mnt/beegfs/carlos.souza/issues/735-tag-convert-teste/scripts_CD-CT/sources/MONAN-Model_release/1.4.1-rc +export MONANDIR=/mnt/beegfs/marcos.longo/MONAN_Simulations/20260105_SoilColour_Control/scripts_CD-CT/sources/MONAN-Model_release/1.4.1-rc # Submiting variables: @@ -100,25 +111,19 @@ export PNETCDFDIR=${PNETCDF} export DIRDADOS=/mnt/beegfs/monan/dados/MONAN_v1.4.x export OPERDIR=/oper/dados/ioper/tempo -# Colors: -export GREEN='\033[1;32m' # Green -export RED='\033[1;31m' # Red -export NC='\033[0m' # No Color -export BLUE='\033[01;34m' # Blue - # Functions: ====================================================================================================== how_many_nodes () { nume=${1} deno=${2} - num=$(echo "${nume}/${deno}" | bc -l) - how_many_nodes_int=$(echo "${num}/1" | bc) - dif=$(echo "scale=0; (${num}-${how_many_nodes_int})*100/1" | bc) - rest=$(echo "scale=0; (((${num}-${how_many_nodes_int})*${deno})+0.5)/1" | bc -l) + num=`echo "${nume}/${deno}" | bc -l` + how_many_nodes_int=`echo "${num}/1" | bc` + dif=`echo "scale=0; (${num}-${how_many_nodes_int})*100/1" | bc` + rest=`echo "scale=0; (((${num}-${how_many_nodes_int})*${deno})+0.5)/1" | bc -l` if [ ${dif} -eq 0 ]; then how_many_nodes_left=0; else how_many_nodes_left=1; fi if [ ${how_many_nodes_int} -eq 0 ]; then how_many_nodes_int=1; how_many_nodes_left=0; rest=0; fi - how_many_nodes=$(echo "${how_many_nodes_int}+${how_many_nodes_left}" | bc ) + how_many_nodes=`echo "${how_many_nodes_int}+${how_many_nodes_left}" | bc ` #echo "INT number of nodes needed: \${how_many_nodes_int} = ${how_many_nodes_int}" #echo "number of nodes left: \${how_many_nodes_left} = ${how_many_nodes_left}" echo "The number of nodes needed: \${how_many_nodes} = ${how_many_nodes}" From 1b87d2a3eb6e6e7083a0f36e8a2023bd64b0a081 Mon Sep 17 00:00:00 2001 From: mpaiao Date: Tue, 6 Jan 2026 16:15:02 -0300 Subject: [PATCH 02/11] Added new options to the scripts for additional flexibility, and also to increase the visibility of variable VARTABLE. --- scripts/0.run_all.bash | 124 ++++++++++++------ scripts/1.install_monan.bash | 12 +- scripts/2.pre_processing.bash | 22 ++-- scripts/3.run_model.bash | 65 ++++++--- scripts/4.run_post.bash | 42 ++++-- scripts/namelists/streams.atmosphere.TEMPLATE | 2 +- scripts/setenv.bash | 2 +- 7 files changed, 179 insertions(+), 90 deletions(-) diff --git a/scripts/0.run_all.bash b/scripts/0.run_all.bash index 0155c7b..65eb72d 100755 --- a/scripts/0.run_all.bash +++ b/scripts/0.run_all.bash @@ -7,37 +7,49 @@ function show_usage() { echo " Usage: " echo "" - echo " ${0} [-s STEP] [-c] [-o] [-gm GIT_MONAN ] [ -bm TAG_MONAN ] \\" - echo " [-gc GIT_CONVERT_MPAS] [-bc TAG_CONVERT_MPAS] [-e EXP ] [-r RES] \\" - echo " [-i YYYYMMDDHH] [-f FCST]" + echo " ${0} [-c] [-o] [-bc TAG_CONVERT_MPAS] [ -bm TAG_MONAN ] [-d OUTPUT_DIAG_INT] \\" + echo " [-e EXP ] [-f FCST] [-gc GIT_CONVERT_MPAS] [-gm GIT_MONAN ] [-l NLEV] \\" + echo " [-r RES] [-s STEP] [-t YYYYMMDDHH] [-v VARTABLE]" echo "" echo " List of optional flags: " echo "" - 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 " -c -- Clean files from previous runs (used only if step is 2,3 or 4)." - echo " -o -- Overwrite static files (used only if step is 2)." - echo " -gm GIT_MONAN -- GitHub handle for MONAN. For example:" - echo " https://github.com/monanadmin/MONAN-Model.git" - echo " -bm TAG_MONAN -- branch or tag name of the MONAN repository. For example:" - echo " \"develop\"." - echo " -gm GIT_CONVERT -- GitHub handle for MONAN. For example:" - echo " https://github.com/monanadmin/MONAN-Model.git" - echo " -bm TAG_CONVERT -- branch or tag name of the MONAN repository. For example:" - echo " \"develop\"." - echo " -e EXP -- meteorological drivers. For example, GFS" - echo " -r RES -- grid resolution. Options are:" - echo " 5898242 (~ 10 km)" - echo " 2621442 (~ 15 km)" - echo " 1024002 (~ 24 km)" - echo " 40962 (~ 120 km)" - echo " -i YYYYMMDDHH -- Initial time. For example if 22 Sept 2025 00 UTC, set it to:" - echo " 2025092200" - echo " -f FCST -- Simulation length in hours, e.g., 24 or 48." + 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 " -c -- Clean files from previous runs. This is used by steps" + echo " 2 and 3." + 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 " -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 "" echo " All settings can be defined directly in the script." echo "" @@ -64,6 +76,9 @@ EXP="GFS" RES=1024002 YYYYMMDDHHi=2024010100 FCST=24 +NLEV=55 +OUTPUT_DIAG_INTERVAL="03:00:00" +VARTABLE="" #---~--- @@ -84,6 +99,10 @@ do CLEAN="-c" shift 1 # Past flag ;; + -d) + OUTPUT_DIAG_INTERVAL="${2}" + shift 2 # Past flag and argument + ;; -e) EXP="${2}" shift 2 # past flag and argument @@ -100,9 +119,9 @@ do github_link_MONAN="${2}" shift 2 # past flag and argument ;; - -i) - YYYYMMDDHHi="${2}" - shift 2 # past flag and argument + -l) + NLEV="${2}" + shift 2 # Past flag and argument ;; -o) OVERWRITE="-o" @@ -116,6 +135,18 @@ do 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 + ;; *) echo "Unknown key-value argument pair." show_usage @@ -162,6 +193,14 @@ EXECS=${DIRHOMED}/execs; mkdir -p ${EXECS} #---~--- +#--- Make sure VARTABLE has the leading "-v" if not empty. +if [[ "${VARTABLE}" == "" ]] +then + dv_VARTABLE="" +else + dv_VARTABLE="-v ${VARTABLE}" +fi +#---~--- #---~--- @@ -181,10 +220,10 @@ case ${STEP} in #--- Run step - time ${0} -s ${step_now} ${CLEAN} ${OVERWRITE} -gm ${github_link_MONAN} \ - -bm ${tag_or_branch_name_MONAN} -gc ${github_link_CONVERT_MPAS} \ - -bc ${tag_or_branch_name_CONVERT_MPAS} -e ${EXP} -r ${RES} -i ${YYYYMMDDHHi} \ - -f ${FCST} + time ${0} ${CLEAN} ${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 #---~--- @@ -193,30 +232,33 @@ case ${STEP} in #---~--- # STEP 1: Install and compile MONAN and its utility programs. #---~--- - time 1.install_monan.bash -gm ${github_link_MONAN} -bm ${tag_or_branch_name_MONAN} \ - -gc ${github_link_CONVERT_MPAS} -bc ${tag_or_branch_name_CONVERT_MPAS} + 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 ${CLEAN} ${OVERWRITE} -e ${EXP} -r ${RES} -i ${YYYYMMDDHHi} \ - -f ${FCST} + time 2.pre_processing.bash ${CLEAN} ${OVERWRITE} -e ${EXP} -f ${FCST} -r ${RES} \ + -t ${YYYYMMDDHHi} #---~--- ;; 3) #---~--- # STEP 3: Run the model. #---~--- - time 3.run_model.bash ${CLEAN} -e ${EXP} -r ${RES} -i ${YYYYMMDDHHi} -f ${FCST} + time 3.run_model.bash ${CLEAN} ${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 -e ${EXP} -r ${RES} -i ${YYYYMMDDHHi} -f ${FCST} + time 4.run_post.bash ${dv_VARTABLE} -d ${OUTPUT_DIAG_INTERVAL} -e ${EXP} -f ${FCST} \ + -l ${NLEV} -r ${RES} -t ${YYYYMMDDHHi} #---~--- ;; esac diff --git a/scripts/1.install_monan.bash b/scripts/1.install_monan.bash index 7551ca1..2136db3 100755 --- a/scripts/1.install_monan.bash +++ b/scripts/1.install_monan.bash @@ -26,14 +26,14 @@ function show_usage() { echo "" echo " List of **required** flags: " echo "" - echo " -gm GIT_MONAN -- GitHub handle for MONAN. For example:" - echo " https://github.com/monanadmin/MONAN-Model.git" + echo " -bc TAG_CONVERT -- branch or tag name of the MONAN repository. For example:" + echo " \"develop\"." echo " -bm TAG_MONAN -- branch or tag name of the MONAN repository. For example:" echo " \"develop\"." - echo " -gm GIT_CONVERT -- GitHub handle for MONAN. For example:" + echo " -gc GIT_CONVERT -- GitHub handle for MONAN. For example:" + echo " https://github.com/monanadmin/MONAN-Model.git" + echo " -gm GIT_MONAN -- GitHub handle for MONAN. For example:" echo " https://github.com/monanadmin/MONAN-Model.git" - echo " -bm TAG_CONVERT -- branch or tag name of the MONAN repository. For example:" - echo " \"develop\"." echo "" } #---~--- @@ -300,7 +300,7 @@ echo "" # install convert_mpas echo "" -echo -e "${GREEN}==>${NC} Moduling environment for convert_mpas...\n" +echo -e "${GREEN}==>${NC} Loading modules needed by convert_mpas...\n" module purge module load gnu9/9.4.0 module load ohpc diff --git a/scripts/2.pre_processing.bash b/scripts/2.pre_processing.bash index 05eddc4..efa9856 100755 --- a/scripts/2.pre_processing.bash +++ b/scripts/2.pre_processing.bash @@ -23,24 +23,24 @@ function show_usage() { echo " Usage: " echo "" - echo " ${0} [-c] [-o] [-e EXP ] [-r RES] [-i YYYYMMDDHH] [-f FCST]" + echo " ${0} [-c] [-o] [-e EXP ] [-r RES] [-t YYYYMMDDHH] [-f FCST]" echo "" echo " List of optional flags: " echo "" echo " -c -- Clean files from previous runs." echo " -o -- Overwrite static files." echo "" - echo " List of required flags when -c is not set: " + echo " List of **required** flags when -c is not set: " echo "" echo " -e EXP -- meteorological drivers. For example, GFS" + echo " -f FCST -- Simulation length in hours, e.g., 24 or 48." echo " -r RES -- grid resolution. Options are:" echo " 5898242 (~ 10 km)" echo " 2621442 (~ 15 km)" echo " 1024002 (~ 24 km)" echo " 40962 (~ 120 km)" - echo " -i YYYYMMDDHH -- Initial time. For example if 22 Sept 2025 00 UTC, set it to:" + echo " -t YYYYMMDDHH -- Initial time. For example if 22 Sept 2025 00 UTC, set it to:" echo " 2025092200" - echo " -f FCST -- Simulation length in hours, e.g., 24 or 48." echo "" } #---~--- @@ -80,10 +80,6 @@ do FCST="${2}" shift 2 # past flag and argument ;; - -i) - YYYYMMDDHHi="${2}" - shift 2 # past flag and argument - ;; -o) OVERWRITE=true shift 1 # past flag @@ -92,6 +88,10 @@ do RES="${2}" shift 2 # past flag and argument ;; + -t) + YYYYMMDDHHi="${2}" + shift 2 # past flag and argument + ;; *) echo "Unknown key-value argument pair." show_usage @@ -162,7 +162,7 @@ ln -sf ${DIRDADOS}/MONAN_datain/datain/WPS_GEOG ${DATAIN} # Creating the x1.${RES}.static.nc file once, if does not exist yet:--------------- if ${OVERWRITE} || [[ ! -s ${DATAIN}/fixed/x1.${RES}.static.nc ]] then - echo -e "${GREEN}==>${NC} Creating static.bash for submiting init_atmosphere to create x1.${RES}.static.nc...\n" + echo -e "${GREEN}==>${NC} Creating static.bash for submitting init_atmosphere to create x1.${RES}.static.nc...\n" time ./make_static.bash ${EXP} ${RES} ${YYYYMMDDHHi} ${FCST} else echo -e "${GREEN}==>${NC} File x1.${RES}.static.nc already exists in ${DATAIN}/fixed.\n" @@ -171,13 +171,13 @@ fi # Degrib phase:--------------------------------------------------------------------- -echo -e "${GREEN}==>${NC} Submiting Degrib...\n" +echo -e "${GREEN}==>${NC} Submitting Degrib...\n" time ./make_degrib.bash ${EXP} ${RES} ${YYYYMMDDHHi} ${FCST} #---------------------------------------------------------------------------------- # Init Atmosphere phase:------------------------------------------------------------ -echo -e "${GREEN}==>${NC} Submiting Init Atmosphere...\n" +echo -e "${GREEN}==>${NC} Submitting Init Atmosphere...\n" time ./make_initatmos.bash ${EXP} ${RES} ${YYYYMMDDHHi} ${FCST} #---------------------------------------------------------------------------------- diff --git a/scripts/3.run_model.bash b/scripts/3.run_model.bash index 3155440..e10a71c 100755 --- a/scripts/3.run_model.bash +++ b/scripts/3.run_model.bash @@ -19,23 +19,30 @@ function show_usage() { echo " Usage: " echo "" - echo " ${0} [-c] [-o] [-e EXP ] [-r RES] [-i YYYYMMDDHH] [-f FCST]" + echo " ${0} [-c] [-v VARTABLE] [-e EXP ] [-r RES] [-t YYYYMMDDHH] [-f FCST] \\" + echo " [-l NLEV] [-ic CONFIG_CONV_INT] [-id OUTPUT_DIAG_INT]" echo "" echo " List of optional flags: " echo "" - echo " -c -- Clean files from previous runs." + echo " -c -- Clean files from previous runs." + 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." echo "" echo " List of required flags when -c is not set: " echo "" - echo " -e EXP -- meteorological drivers. For example, GFS" - echo " -r RES -- grid resolution. Options are:" - echo " 5898242 (~ 10 km)" - echo " 2621442 (~ 15 km)" - echo " 1024002 (~ 24 km)" - echo " 40962 (~ 120 km)" - echo " -i YYYYMMDDHH -- Initial time. For example if 22 Sept 2025 00 UTC, set it to:" - echo " 2025092200" - echo " -f FCST -- Simulation length in hours, e.g., 24 or 48." + echo " -d OUTPUT_DIAG_INT -- Output interval for diagnostic. The format must be" + echo " \"HH:MM:SS\"" + echo " -e EXP -- meteorological drivers. For example, GFS" + echo " -f FCST -- Simulation length in hours, e.g., 24 or 48." + echo " -l NLEV -- Number of vertical levels for the output." + echo " -r RES -- grid resolution. Options are:" + echo " 5898242 (~ 10 km)" + echo " 2621442 (~ 15 km)" + echo " 1024002 (~ 24 km)" + echo " 40962 (~ 120 km)" + echo " -t YYYYMMDDHH -- Initial time. For example if 22 Sept 2025 00 UTC, set it to:" + echo " 2025092200" echo "" } #---~--- @@ -54,6 +61,10 @@ EXP="" RES="" YYYYMMDDHHi="" FCST="" +OUTPUT_DIAG_INT="" +NLEV="" +OUTPUT_DIAG_INTERVAL="" +VARTABLE="" #---~--- @@ -66,6 +77,10 @@ do CLEAN=true shift 1 # Past flag ;; + -d) + OUTPUT_DIAG_INTERVAL="${2}" + shift 2 # Past flag and argument + ;; -e) EXP="${2}" shift 2 # past flag and argument @@ -74,14 +89,26 @@ do FCST="${2}" shift 2 # past flag and argument ;; - -i) - YYYYMMDDHHi="${2}" - shift 2 # past flag and argument + -l) + NLEV="${2}" + shift 2 # Past flag and argument ;; -r) RES="${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 + ;; *) echo "Unknown key-value argument pair." show_usage @@ -100,8 +127,9 @@ if ${CLEAN} then clean_pre_tmp_files exit -elif [[ "${EXP}" == "" ]] || [[ "${RES}" == "" ]] || - [[ "${YYYYMMDDHHi}" == "" ]] || [[ "${FCST}" == "" ]] +elif [[ "${EXP}" == "" ]] || [[ "${RES}" == "" ]] || + [[ "${YYYYMMDDHHi}" == "" ]] || [[ "${FCST}" == "" ]] || + [[ "${NLEV}" == "" ]] || [[ "${OUTPUT_DIAG_INTERVAL}" == "" ]] then echo " This script requires some arguments to be set through flags." show_usage @@ -129,9 +157,7 @@ export DIRRUN=${DIRHOMED}/run.${YYYYMMDDHHi}; rm -fr ${DIRRUN}; mkdir -p ${DIRRU start_date=${YYYYMMDDHHi:0:4}-${YYYYMMDDHHi:4:2}-${YYYYMMDDHHi:6:2}_${YYYYMMDDHHi:8:2}:00:00 cores=${MODEL_ncores} hhi=${YYYYMMDDHHi:8:2} -NLEV=55 CONFIG_CONV_INTERVAL="00:30:00" -VARTABLE=".OPER" #------------------------------------------------------------------------------------ # Variables for flex outpout interval from streams.atmosphere------------------------ @@ -227,7 +253,8 @@ then s,#CONFIG_DT#,${CONFIG_DT},g;s,#CONFIG_LEN_DISP#,${CONFIG_LEN_DISP},g;s,#CONFIG_CONV_INTERVAL#,${CONFIG_CONV_INTERVAL},g" \ ${SCRIPTS}/namelists/namelist.atmosphere.TEMPLATE > ${DIRRUN}/namelist.atmosphere - sed -e "s,#RES#,${RES},g;s,#CIORIG#,${EXP},g;s,#LABELI#,${YYYYMMDDHHi},g;s,#NLEV#,${NLEV},g" \ + sed -e "s,#RES#,${RES},g;s,#CIORIG#,${EXP},g;s,#LABELI#,${YYYYMMDDHHi},g;s,#NLEV#,${NLEV},g; +s,#OUTPUT_DIAG_INTERVAL#,${OUTPUT_DIAG_INTERVAL},g" \ ${SCRIPTS}/namelists/streams.atmosphere.TEMPLATE > ${DIRRUN}/streams.atmosphere fi cp -f ${SCRIPTS}/namelists/stream_list.atmosphere.output ${DIRRUN} diff --git a/scripts/4.run_post.bash b/scripts/4.run_post.bash index f9dadc4..1ec0c8f 100755 --- a/scripts/4.run_post.bash +++ b/scripts/4.run_post.bash @@ -19,23 +19,30 @@ function show_usage() { echo " Usage: " echo "" - echo " ${0} [-c] [-o] [-e EXP ] [-r RES] [-i YYYYMMDDHH] [-f FCST]" + echo " ${0} [-c] [-v VARTABLE] [-o] [-e EXP ] [-r RES] [-t YYYYMMDDHH] [-f FCST] \\" + echo " [-l NLEV]" echo "" echo " List of optional flags: " echo "" echo " -c -- Clean files from previous runs." + 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." echo "" echo " List of required flags when -c is not set: " echo "" + echo " -d OUTPUT_DIAG_INT -- Output interval for diagnostic. The format must be" + echo " \"HH:MM:SS\"" echo " -e EXP -- meteorological drivers. For example, GFS" echo " -r RES -- grid resolution. Options are:" echo " 5898242 (~ 10 km)" echo " 2621442 (~ 15 km)" echo " 1024002 (~ 24 km)" echo " 40962 (~ 120 km)" - echo " -i YYYYMMDDHH -- Initial time. For example if 22 Sept 2025 00 UTC, set it to:" - echo " 2025092200" echo " -f FCST -- Simulation length in hours, e.g., 24 or 48." + echo " -l NLEV -- Number of vertical levels for the output." + echo " -t YYYYMMDDHH -- Initial time. For example if 22 Sept 2025 00 UTC, set it to:" + echo " 2025092200" echo "" } #---~--- @@ -54,6 +61,8 @@ EXP="" RES="" YYYYMMDDHHi="" FCST="" +VARTABLE="" +N_MODEL_LEV="" #---~--- @@ -74,14 +83,26 @@ do FCST="${2}" shift 2 # past flag and argument ;; - -i) - YYYYMMDDHHi="${2}" - shift 2 # past flag and argument + -l) + N_MODEL_LEV="${2}" + shift 2 # Past flag and argument ;; -r) RES="${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 + ;; *) echo "Unknown key-value argument pair." show_usage @@ -101,7 +122,8 @@ then clean_pre_tmp_files exit elif [[ "${EXP}" == "" ]] || [[ "${RES}" == "" ]] || - [[ "${YYYYMMDDHHi}" == "" ]] || [[ "${FCST}" == "" ]] + [[ "${YYYYMMDDHHi}" == "" ]] || [[ "${FCST}" == "" ]] || + [[ "${N_MODEL_LEV}" == "" ]] then echo " This script requires some arguments to be set through flags." show_usage @@ -129,12 +151,10 @@ export DIRRUN=${DIRHOMED}/run.${YYYYMMDDHHi}; rm -fr ${DIRRUN}; mkdir -p ${DIRRU START_DATE_YYYYMMDD="${YYYYMMDDHHi:0:4}-${YYYYMMDDHHi:4:2}-${YYYYMMDDHHi:6:2}" START_HH="${YYYYMMDDHHi:8:2}" maxpostpernode=30 # <------ qtde max de convert_mpas por no! -VARTABLE=".OPER" -N_MODEL_LEV=55 #------------------------------------------------------- -# Variables for flex outpout interval from streams.atmosphere------------------------ -t_strout=$(cat ${SCRIPTS}/namelists/streams.atmosphere.TEMPLATE | sed -n '//s/.*output_interval="\([^"]*\)".*/\1/p') +# Variables for flex output interval from streams.atmosphere------------------------ +t_strout=${OUTPUT_DIAG_INTERVAL} t_stroutsec=`echo ${t_strout} | awk -F: '{print ($1 * 3600) + ($2 * 60) + $3}'` t_strouthor=`echo "scale=4; (${t_stroutsec}/60)/60" | bc` #------------------------------------------------------------------------------------ diff --git a/scripts/namelists/streams.atmosphere.TEMPLATE b/scripts/namelists/streams.atmosphere.TEMPLATE index c732433..01db6b8 100755 --- a/scripts/namelists/streams.atmosphere.TEMPLATE +++ b/scripts/namelists/streams.atmosphere.TEMPLATE @@ -21,7 +21,7 @@ + output_interval="#OUTPUT_DIAG_INTERVAL#" > diff --git a/scripts/setenv.bash b/scripts/setenv.bash index 0874ed9..1e9cbf8 100755 --- a/scripts/setenv.bash +++ b/scripts/setenv.bash @@ -39,7 +39,7 @@ export DIR_SCRIPTS=$(dirname $(dirname $(pwd))) export DIR_DADOS=$(dirname $(dirname $(pwd))) export MONANDIR=/mnt/beegfs/marcos.longo/MONAN_Simulations/20260105_SoilColour_Control/scripts_CD-CT/sources/MONAN-Model_release/1.4.1-rc -# Submiting variables: +# Submission variables: # PRE-Static phase: export STATIC_QUEUE="batch" From c1fcb380324c4cb4c6160e7f090ec20910810337 Mon Sep 17 00:00:00 2001 From: Marcos Longo Date: Wed, 7 Jan 2026 07:37:59 -0300 Subject: [PATCH 03/11] Added config_lsm_scheme to the default namelist.atmosphere.TEMPLATE --- scripts/namelists/namelist.atmosphere.TEMPLATE | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/namelists/namelist.atmosphere.TEMPLATE b/scripts/namelists/namelist.atmosphere.TEMPLATE index bab5a89..65a9a07 100755 --- a/scripts/namelists/namelist.atmosphere.TEMPLATE +++ b/scripts/namelists/namelist.atmosphere.TEMPLATE @@ -62,7 +62,8 @@ config_radtsw_interval = '00:30:00' config_conv_interval = '#CONFIG_CONV_INTERVAL#' config_bucket_update = 'none' - config_physics_suite = 'convection_permitting_monan' + config_physics_suite = 'convection_permitting_monan' + config_lsm_scheme = 'noah' config_mynn_edmf = 0 / &gf_monan From 6b68cf12b603024bb8db7d0e3ea2f09a8128bf3e Mon Sep 17 00:00:00 2001 From: Marcos Longo Date: Wed, 7 Jan 2026 10:33:14 -0300 Subject: [PATCH 04/11] 1. Hot fix in 3.run_model.bash: I replaced the output time interval calculation to refer to OUTPUT_DIAG_INTERVAL 2. A few minor typo fixes that I had inadvertently introduced in the helper function as I was deciding which flags to use. I also removed some forgotten references to OUTPUT_DIAG_INT, which I had originally used by replaced with OUTPUT_DIAG_INTERVAL for clarity. --- scripts/1.install_monan.bash | 3 +-- scripts/2.pre_processing.bash | 2 +- scripts/3.run_model.bash | 15 +++++++-------- scripts/4.run_post.bash | 36 +++++++++++++++++------------------ 4 files changed, 27 insertions(+), 29 deletions(-) diff --git a/scripts/1.install_monan.bash b/scripts/1.install_monan.bash index 2136db3..7aa8518 100755 --- a/scripts/1.install_monan.bash +++ b/scripts/1.install_monan.bash @@ -21,8 +21,7 @@ function show_usage() { echo " Usage: " echo "" - echo " ${0} -gm GIT_MONAN -bm TAG_MONAN \\" - echo " -gc GIT_CONVERT_MPAS -bc TAG_CONVERT_MPAS" + echo " ${0} -bc TAG_CONVERT_MPAS -bm TAG_MONAN -gm GIT_MONAN -gc GIT_CONVERT_MPAS" echo "" echo " List of **required** flags: " echo "" diff --git a/scripts/2.pre_processing.bash b/scripts/2.pre_processing.bash index efa9856..e353fce 100755 --- a/scripts/2.pre_processing.bash +++ b/scripts/2.pre_processing.bash @@ -23,7 +23,7 @@ function show_usage() { echo " Usage: " echo "" - echo " ${0} [-c] [-o] [-e EXP ] [-r RES] [-t YYYYMMDDHH] [-f FCST]" + echo " ${0} [-c] [-o] [-e EXP ] [-f FCST] [-r RES] [-t YYYYMMDDHH]" echo "" echo " List of optional flags: " echo "" diff --git a/scripts/3.run_model.bash b/scripts/3.run_model.bash index e10a71c..5f80e8a 100755 --- a/scripts/3.run_model.bash +++ b/scripts/3.run_model.bash @@ -19,8 +19,8 @@ function show_usage() { echo " Usage: " echo "" - echo " ${0} [-c] [-v VARTABLE] [-e EXP ] [-r RES] [-t YYYYMMDDHH] [-f FCST] \\" - echo " [-l NLEV] [-ic CONFIG_CONV_INT] [-id OUTPUT_DIAG_INT]" + echo " ${0} [-c] [-v VARTABLE] [-d OUTPUT_DIAG_INT] [-e EXP ] [-f FCST] [-l NLEV] \\" + echo " [-r RES] [-t YYYYMMDDHH]" echo "" echo " List of optional flags: " echo "" @@ -29,7 +29,7 @@ function show_usage() { echo " stream_list_atmosphere.diagnostics template to use." echo " The default is to not use any suffix." echo "" - echo " List of required flags when -c is not set: " + echo " List of **required** flags when -c is not set: " echo "" echo " -d OUTPUT_DIAG_INT -- Output interval for diagnostic. The format must be" echo " \"HH:MM:SS\"" @@ -41,8 +41,8 @@ function show_usage() { echo " 2621442 (~ 15 km)" echo " 1024002 (~ 24 km)" echo " 40962 (~ 120 km)" - echo " -t YYYYMMDDHH -- Initial time. For example if 22 Sept 2025 00 UTC, set it to:" - echo " 2025092200" + echo " -t YYYYMMDDHH -- Initial time. For example if 22 Sept 2025 00 UTC," + echo " set it to: 2025092200" echo "" } #---~--- @@ -61,7 +61,6 @@ EXP="" RES="" YYYYMMDDHHi="" FCST="" -OUTPUT_DIAG_INT="" NLEV="" OUTPUT_DIAG_INTERVAL="" VARTABLE="" @@ -160,8 +159,8 @@ hhi=${YYYYMMDDHHi:8:2} CONFIG_CONV_INTERVAL="00:30:00" #------------------------------------------------------------------------------------ -# Variables for flex outpout interval from streams.atmosphere------------------------ -t_strout=$(cat ${SCRIPTS}/namelists/streams.atmosphere.TEMPLATE | sed -n '//s/.*output_interval="\([^"]*\)".*/\1/p') +# Variables for flex outpout interval ------------------------ +t_strout=${OUTPUT_DIAG_INTERVAL} t_stroutsec=$(echo ${t_strout} | awk -F: '{print ($1 * 3600) + ($2 * 60) + $3}') t_strouthor=`echo "scale=4; (${t_stroutsec}/60)/60" | bc` #------------------------------------------------------------------------------------ diff --git a/scripts/4.run_post.bash b/scripts/4.run_post.bash index 1ec0c8f..5048da8 100755 --- a/scripts/4.run_post.bash +++ b/scripts/4.run_post.bash @@ -19,30 +19,30 @@ function show_usage() { echo " Usage: " echo "" - echo " ${0} [-c] [-v VARTABLE] [-o] [-e EXP ] [-r RES] [-t YYYYMMDDHH] [-f FCST] \\" - echo " [-l NLEV]" + echo " ${0} [-c] [-v VARTABLE] [-d OUTPUT_DIAG_INT] [-e EXP ] [-f FCST] [-l NLEV] \\" + echo " [-r RES] [-t YYYYMMDDHH]" echo "" echo " List of optional flags: " echo "" - echo " -c -- Clean files from previous runs." - 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." + echo " -c -- Clean files from previous runs." + 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." echo "" - echo " List of required flags when -c is not set: " + echo " List of **required** flags when -c is not set: " echo "" echo " -d OUTPUT_DIAG_INT -- Output interval for diagnostic. The format must be" echo " \"HH:MM:SS\"" - echo " -e EXP -- meteorological drivers. For example, GFS" - echo " -r RES -- grid resolution. Options are:" - echo " 5898242 (~ 10 km)" - echo " 2621442 (~ 15 km)" - echo " 1024002 (~ 24 km)" - echo " 40962 (~ 120 km)" - echo " -f FCST -- Simulation length in hours, e.g., 24 or 48." - echo " -l NLEV -- Number of vertical levels for the output." - echo " -t YYYYMMDDHH -- Initial time. For example if 22 Sept 2025 00 UTC, set it to:" - echo " 2025092200" + echo " -e EXP -- meteorological drivers. For example, GFS" + echo " -f FCST -- Simulation length in hours, e.g., 24 or 48." + echo " -l NLEV -- Number of vertical levels for the output." + echo " -r RES -- grid resolution. Options are:" + echo " 5898242 (~ 10 km)" + echo " 2621442 (~ 15 km)" + echo " 1024002 (~ 24 km)" + echo " 40962 (~ 120 km)" + echo " -t YYYYMMDDHH -- Initial time. For example if 22 Sept 2025 00 UTC," + echo " set it to: 2025092200" echo "" } #---~--- @@ -153,7 +153,7 @@ START_HH="${YYYYMMDDHHi:8:2}" maxpostpernode=30 # <------ qtde max de convert_mpas por no! #------------------------------------------------------- -# Variables for flex output interval from streams.atmosphere------------------------ +# Variables for flex output interval ------------------------ t_strout=${OUTPUT_DIAG_INTERVAL} t_stroutsec=`echo ${t_strout} | awk -F: '{print ($1 * 3600) + ($2 * 60) + $3}'` t_strouthor=`echo "scale=4; (${t_stroutsec}/60)/60" | bc` From 66e7b4df9393dc8d1a8fdd970b0966bc192326fd Mon Sep 17 00:00:00 2001 From: Marcos Longo Date: Wed, 7 Jan 2026 10:58:19 -0300 Subject: [PATCH 05/11] Added a new optional flag "-i" in 0.run_all.bash. This flag allows resetting the input path for data in setenv.bash. If "-i" is not provided, the default path is used. --- scripts/0.run_all.bash | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/scripts/0.run_all.bash b/scripts/0.run_all.bash index 65eb72d..c8cc13a 100755 --- a/scripts/0.run_all.bash +++ b/scripts/0.run_all.bash @@ -8,8 +8,8 @@ function show_usage() { echo " Usage: " echo "" echo " ${0} [-c] [-o] [-bc TAG_CONVERT_MPAS] [ -bm TAG_MONAN ] [-d OUTPUT_DIAG_INT] \\" - echo " [-e EXP ] [-f FCST] [-gc GIT_CONVERT_MPAS] [-gm GIT_MONAN ] [-l NLEV] \\" - echo " [-r RES] [-s STEP] [-t YYYYMMDDHH] [-v VARTABLE]" + 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 "" @@ -29,6 +29,8 @@ function show_usage() { 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." @@ -73,6 +75,7 @@ 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 @@ -119,6 +122,10 @@ do 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 @@ -203,6 +210,15 @@ 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 +#---~--- + + #---~--- # Select step. #---~--- From 4a1da7bcbed3505b8ad281812a3f05a3e4402d10 Mon Sep 17 00:00:00 2001 From: Marcos Longo Date: Wed, 7 Jan 2026 14:41:00 -0300 Subject: [PATCH 06/11] Hot fix to 4.run_post.bash. Variable OUTPUT_DIAG_INTERVAL was not being properly retrieved. --- scripts/4.run_post.bash | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/4.run_post.bash b/scripts/4.run_post.bash index 5048da8..9bf8ddf 100755 --- a/scripts/4.run_post.bash +++ b/scripts/4.run_post.bash @@ -61,8 +61,9 @@ EXP="" RES="" YYYYMMDDHHi="" FCST="" -VARTABLE="" N_MODEL_LEV="" +OUTPUT_DIAG_INTERVAL="" +VARTABLE="" #---~--- @@ -75,6 +76,10 @@ do CLEAN=true shift 1 # Past flag ;; + -d) + OUTPUT_DIAG_INTERVAL="${2}" + shift 2 # Past flag and argument + ;; -e) EXP="${2}" shift 2 # past flag and argument From 34db38365feab60ebed7e299cc22d1564866f7e7 Mon Sep 17 00:00:00 2001 From: Marcos Longo Date: Thu, 8 Jan 2026 11:10:56 -0300 Subject: [PATCH 07/11] 1. Standardised the usage across all bash scripts to take in options (with dash) to avoid hardcoded variables (especially VARTABLE and OUTPUT_DIAG_INTERVAL). 2. Fixed some of the code in 4.run_post.bash, which was still assuming results every 3 hours. 3. Renamed NLEV in the post-processing to avoid ambiguities 4. Fixed inconsistent configurations for grid resolutions. --- scripts/0.run_all.bash | 18 +-- scripts/2.pre_processing.bash | 6 +- scripts/4.run_post.bash | 68 ++++++---- scripts/make_degrib.bash | 97 ++++++++++---- scripts/make_initatmos.bash | 96 ++++++++++---- scripts/make_static.bash | 96 ++++++++++---- scripts/make_template.bash | 179 +++++++++++++++++++------ scripts/run_past2now.bash | 238 ++++++++++++++++++++++++++++------ 8 files changed, 609 insertions(+), 189 deletions(-) diff --git a/scripts/0.run_all.bash b/scripts/0.run_all.bash index c8cc13a..7bea026 100755 --- a/scripts/0.run_all.bash +++ b/scripts/0.run_all.bash @@ -200,21 +200,21 @@ EXECS=${DIRHOMED}/execs; mkdir -p ${EXECS} #---~--- -#--- Make sure VARTABLE has the leading "-v" if not empty. -if [[ "${VARTABLE}" == "" ]] +#--- If INPUT_PATH is provided, replace the path in setenv.bash +if [[ "${INPUT_PATH}" != "" ]] && [[ -d "${INPUT_PATH}" ]] then - dv_VARTABLE="" -else - dv_VARTABLE="-v ${VARTABLE}" + sed -i.bck "s,^export DIRDADOS=.*,export DIRDADOS=${INPUT_PATH},g" ${SCRIPTS}/setenv.bash + /bin/rm -f ${SCRIPTS}/setenv.bash.bck fi #---~--- -#--- If INPUT_PATH is provided, replace the path in setenv.bash -if [[ "${INPUT_PATH}" != "" ]] && [[ -d "${INPUT_PATH}" ]] +#--- Make sure VARTABLE has the leading "-v" if not empty. +if [[ "${VARTABLE}" == "" ]] then - sed -i.bck "s,^export DIRDADOS=.*,export DIRDADOS=${INPUT_PATH},g" ${SCRIPTS}/setenv.bash - /bin/rm -f ${SCRIPTS}/setenv.bash.bck + dv_VARTABLE="" +else + dv_VARTABLE="-v ${VARTABLE}" fi #---~--- diff --git a/scripts/2.pre_processing.bash b/scripts/2.pre_processing.bash index e353fce..a34e910 100755 --- a/scripts/2.pre_processing.bash +++ b/scripts/2.pre_processing.bash @@ -163,7 +163,7 @@ ln -sf ${DIRDADOS}/MONAN_datain/datain/WPS_GEOG ${DATAIN} if ${OVERWRITE} || [[ ! -s ${DATAIN}/fixed/x1.${RES}.static.nc ]] then echo -e "${GREEN}==>${NC} Creating static.bash for submitting init_atmosphere to create x1.${RES}.static.nc...\n" - time ./make_static.bash ${EXP} ${RES} ${YYYYMMDDHHi} ${FCST} + time ./make_static.bash -e ${EXP} -f ${FCST} -r ${RES} -t ${YYYYMMDDHHi} else echo -e "${GREEN}==>${NC} File x1.${RES}.static.nc already exists in ${DATAIN}/fixed.\n" fi @@ -172,13 +172,13 @@ fi # Degrib phase:--------------------------------------------------------------------- echo -e "${GREEN}==>${NC} Submitting Degrib...\n" -time ./make_degrib.bash ${EXP} ${RES} ${YYYYMMDDHHi} ${FCST} +time ./make_degrib.bash -e ${EXP} -f ${FCST} -r ${RES} -t ${YYYYMMDDHHi} #---------------------------------------------------------------------------------- # Init Atmosphere phase:------------------------------------------------------------ echo -e "${GREEN}==>${NC} Submitting Init Atmosphere...\n" -time ./make_initatmos.bash ${EXP} ${RES} ${YYYYMMDDHHi} ${FCST} +time ./make_initatmos.bash -e ${EXP} -f ${FCST} -r ${RES} -t ${YYYYMMDDHHi} #---------------------------------------------------------------------------------- diff --git a/scripts/4.run_post.bash b/scripts/4.run_post.bash index 9bf8ddf..f4455ec 100755 --- a/scripts/4.run_post.bash +++ b/scripts/4.run_post.bash @@ -19,8 +19,8 @@ function show_usage() { echo " Usage: " echo "" - echo " ${0} [-c] [-v VARTABLE] [-d OUTPUT_DIAG_INT] [-e EXP ] [-f FCST] [-l NLEV] \\" - echo " [-r RES] [-t YYYYMMDDHH]" + echo " ${0} [-c] [-v VARTABLE] [-d OUTPUT_DIAG_INT] [-e EXP ] [-f FCST] \\" + echo " [-l N_MODEL_LEV] [-r RES] [-t YYYYMMDDHH]" echo "" echo " List of optional flags: " echo "" @@ -35,7 +35,7 @@ function show_usage() { echo " \"HH:MM:SS\"" echo " -e EXP -- meteorological drivers. For example, GFS" echo " -f FCST -- Simulation length in hours, e.g., 24 or 48." - echo " -l NLEV -- Number of vertical levels for the output." + echo " -l N_MODEL_LEV -- Number of vertical levels for the output." echo " -r RES -- grid resolution. Options are:" echo " 5898242 (~ 10 km)" echo " 2621442 (~ 15 km)" @@ -126,9 +126,9 @@ if ${CLEAN} then clean_pre_tmp_files exit -elif [[ "${EXP}" == "" ]] || [[ "${RES}" == "" ]] || - [[ "${YYYYMMDDHHi}" == "" ]] || [[ "${FCST}" == "" ]] || - [[ "${N_MODEL_LEV}" == "" ]] +elif [[ "${EXP}" == "" ]] || [[ "${RES}" == "" ]] || + [[ "${YYYYMMDDHHi}" == "" ]] || [[ "${FCST}" == "" ]] || + [[ "${N_MODEL_LEV}" == "" ]] || [[ "${OUTPUT_DIAG_INTERVAL}" == "" ]] then echo " This script requires some arguments to be set through flags." show_usage @@ -168,7 +168,9 @@ t_strouthor=`echo "scale=4; (${t_stroutsec}/60)/60" | bc` IFS=":" read -r h m s <<< "${t_strout}" printf -v t_strout "%02d:%02d:%02d" "$h" "$m" "$s" -# Calculating default parameters for different resolutions +# Calculate default parameters for different resolutions +# ML: This assumes 1deg ~ 100 km, which is making the post-processed output coarser +# than it needs to be... case ${RES} in 5898242) #10km NLAT=1801 #180/0.10 (+1) @@ -203,19 +205,20 @@ case ${RES} in ENDLON=360.0 ;; *) - 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" + echo -e "${RED}****** FATAL ERROR ******${NC} \n" + echo -e "${RED}==>${NC} Provided grid resolution (${RES}) is not recognised.\n" + echo -e "${RED}==>${NC} ${0} cannot post-process this MONAN simulation.\n" + exit -1 ;; esac #------------------------------------------------------- -# NLEVS get from t_iso_levels in Registry_isobaric.xml: +# Retrieve N_ISOBARIC_LEV from t_iso_levels in Registry_isobaric.xml: if [ -s ${MONANDIR}/src/core_atmosphere/diagnostics/Registry_isobaric.xml ] then - NLEV=$(grep "t_iso_levels" ${MONANDIR}/src/core_atmosphere/diagnostics/Registry_isobaric.xml | grep definition | cut -d\" -f4) + N_ISOBARIC_LEV=$(grep "t_iso_levels" ${MONANDIR}/src/core_atmosphere/diagnostics/Registry_isobaric.xml | grep definition | cut -d\" -f4) else - NLEV=18 + N_ISOBARIC_LEV=18 fi @@ -230,8 +233,8 @@ do fi done -# Captura quantos arquivos do modelo tiverem para serem pos-processados e -# quando nos serao necessarios para executar ${maxpostpernode} convert_mpas por no: +# Tally the number of model output files to be postprocessed, and find out how +# many nodes are needed to process ${maxpostpernode} convert_mpas runs per node: #nfiles=$(ls -l ${DATAOUT}/${YYYYMMDDHHi}/Model/MONAN*nc | wc -l) # from streams.atmosphere.TEMPLATE in diagnostics the output_interval is flexible output_interval=${t_strouthor} @@ -241,7 +244,7 @@ echo "${nfiles} post to submit." echo "Max ${maxpostpernode} submits per nodes." how_many_nodes ${nfiles} ${maxpostpernode} -# Cria os diretorios e arquivos/links para cada saida do convert_mpas: +# Make paths and create files/links for each convert_mpas output: cd ${DIRRUN} cp -f ${SCRIPTS}/setenv.bash ${DIRRUN} for ii in $(seq 1 ${nfiles}) @@ -251,7 +254,7 @@ do cp -f ${SCRIPTS}/setenv.bash ${DIRRUN}/dir.${i} cp -f ${SCRIPTS}/namelists/include_fields.diag${VARTABLE} ${DIRRUN}/dir.${i}/include_fields.diag${VARTABLE} cp -f ${DIRRUN}/dir.${i}/include_fields.diag${VARTABLE} ${DIRRUN}/dir.${i}/include_fields - sed -e "s,#NISOLEV#,${NLEV},g;s,#NMODELLEV#,${N_MODEL_LEV},g" \ + sed -e "s,#NISOLEV#,${N_ISOBARIC_LEV},g;s,#NMODELLEV#,${N_MODEL_LEV},g" \ ${SCRIPTS}/namelists/convert_mpas.nml > ${DIRRUN}/dir.${i}/convert_mpas.nml sed -e "s,#NLAT#,${NLAT},g;s,#NLON#,${NLON},g;s,#STARTLAT#,${STARTLAT},g;s,#ENDLAT#,${ENDLAT},g;s,#STARTLON#,${STARTLON},g;s,#ENDLON#,${ENDLON},g;" \ ${SCRIPTS}/namelists/target_domain.TEMPLATE > ${DIRRUN}/dir.${i}/target_domain @@ -260,7 +263,7 @@ done cd ${DIRRUN} -# Laco para criar os arquivos de submissao com os blocos de convertmpas para cada node: +# Loop that generates submission files that distributes chunks of convertmpas runs to each node: node=1 inicio=1 fim=$((maxpostpernode <= nfiles ? maxpostpernode : nfiles)) @@ -305,15 +308,15 @@ do echo "./convert_mpas x1.${RES}.init.nc ${DATAOUT}/${YYYYMMDDHHi}/Model/\${diag_name} > convert_mpas.output" done -# necessario aguardar as rodadas em background +# This is needed to ensure that the job remains active whilst convert_mpas runs in the background wait for ii in \$(seq ${inicio} ${fim}) do i=\$(printf "%04d" \${ii}) hh=${YYYYMMDDHHi:8:2} - currentdate=\$(date -d "${YYYYMMDDHHi:0:8} \${hh}:00 \$(echo "(\${i}-1)*3" | bc) hours" +"%Y%m%d%H") - diag_name_post=MONAN_DIAG_G_POS_${EXP}_${YYYYMMDDHHi}_\${currentdate}.00.00.x${RES}L${NLEV}.nc + currentdate=\$(date -d "${YYYYMMDDHHi:0:8} \${hh}:00:00 \$(echo "(\${i}-1)*${t_strout:0:2}" | bc) hours \$(echo "(\${i}-1)*${t_strout:3:2}" | bc) minutes \$(echo "(\${i}-1)*${t_strout:6:2}" | bc) seconds" +"%Y%m%d%H.%M.%S") + diag_name_post=MONAN_DIAG_G_POS_${EXP}_${YYYYMMDDHHi}_\${currentdate}.x${RES}L${N_ISOBARIC_LEV}.nc cd ${DIRRUN}/dir.\${i} cp latlon.nc ${DATAOUT}/${YYYYMMDDHHi}/Post/\${diag_name_post} >> convert_mpas.output & @@ -340,7 +343,7 @@ done -# Dependencias JobId: +# JobId dependencies: dependency="afterok" for job_id in "${jobid[@]}" do @@ -348,7 +351,7 @@ do done -# Script final , para conferir todos os arquivos, criar o template final e apagar o diretorio DIRRUN +# Final script, which will check every file, make the final template and remove directory ${DIRRUN} node=0 rm -f ${DIRRUN}/PostAtmos_node.${node}.sh cat > ${DIRRUN}/PostAtmos_node.${node}.sh < ${DIRRUN}/PostAtmos_node.${node}.sh < 0 ]] +do + key="${1}" + case ${key} in + -e) + EXP="${2}" + shift 2 # past flag and argument + ;; + -f) + FCST="${2}" + shift 2 # past flag and argument + ;; + -r) + RES="${2}" + shift 2 # past flag and argument + ;; + -t) + YYYYMMDDHHi="${2}" + shift 2 # past flag and argument + ;; + *) + echo "Unknown key-value argument pair." + show_usage + exit 2 + ;; + esac +done +#---~--- + + + +#---~--- +# Make sure all settings were provided (unless this will be to clean up runs). +#---~--- +if [[ "${EXP}" == "" ]] || [[ "${RES}" == "" ]] || + [[ "${YYYYMMDDHHi}" == "" ]] || [[ "${FCST}" == "" ]] +then + echo " This script requires some arguments to be set through flags." + show_usage + exit 2 +fi +#---~--- + + # Standart directories variables:--------------------------------------- DIRHOMES=${DIR_SCRIPTS}/scripts_CD-CT; mkdir -p ${DIRHOMES} DIRHOMED=${DIR_DADOS}/scripts_CD-CT; mkdir -p ${DIRHOMED} @@ -37,14 +94,6 @@ EXECS=${DIRHOMED}/execs; mkdir -p ${EXECS} #---------------------------------------------------------------------- -# Input variables:-------------------------------------- -EXP=${1}; #EXP=GFS -RES=${2}; #RES=1024002 -YYYYMMDDHHi=${3}; #YYYYMMDDHHi=2024012000 -FCST=${4}; #FCST=24 -#------------------------------------------------------- - - # Local variables-------------------------------------- start_date=${YYYYMMDDHHi:0:4}-${YYYYMMDDHHi:4:2}-${YYYYMMDDHHi:6:2}_${YYYYMMDDHHi:8:2}:00:00 OPERDIREXP=${OPERDIR}/${EXP} diff --git a/scripts/make_initatmos.bash b/scripts/make_initatmos.bash index 8b67d46..588fe5e 100755 --- a/scripts/make_initatmos.bash +++ b/scripts/make_initatmos.bash @@ -1,30 +1,88 @@ #!/bin/bash -if [ $# -ne 4 ] -then - echo "" - echo "Instructions: execute the command below" + + +#--- Function that shows usage. +function show_usage() { + echo " Usage: " echo "" - echo "${0} EXP_NAME RESOLUTION LABELI FCST" + echo " ${0} [-e EXP ] [-f FCST] [-r RES] [-t YYYYMMDDHH]" echo "" - echo "EXP_NAME :: Forcing: GFS" - echo " :: Others options to be added later..." - 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 " List of **required** flags: " echo "" - echo "24 hour forcast example:" - echo "${0} GFS 1024002 2024010100 24" + echo " -e EXP -- meteorological drivers. For example, GFS" + echo " -f FCST -- Simulation length in hours, e.g., 24 or 48." + echo " -r RES -- grid resolution. Options are:" + echo " 5898242 (~ 10 km)" + echo " 2621442 (~ 15 km)" + echo " 1024002 (~ 24 km)" + echo " 40962 (~ 120 km)" + echo " -t YYYYMMDDHH -- Initial time. For example if 22 Sept 2025 00 UTC, set it to:" + echo " 2025092200" echo "" - - exit -fi +} +#---~--- # Set environment variables exports: . setenv.bash + + +#--- Default input variables: +EXP="" +RES="" +YYYYMMDDHHi="" +FCST="" +#---~--- + + +#--- Parse arguments. +while [[ ${#} > 0 ]] +do + key="${1}" + case ${key} in + -e) + EXP="${2}" + shift 2 # past flag and argument + ;; + -f) + FCST="${2}" + shift 2 # past flag and argument + ;; + -r) + RES="${2}" + shift 2 # past flag and argument + ;; + -t) + YYYYMMDDHHi="${2}" + shift 2 # past flag and argument + ;; + *) + echo "Unknown key-value argument pair." + show_usage + exit 2 + ;; + esac +done +#---~--- + + + +#---~--- +# Make sure all settings were provided (unless this will be to clean up runs). +#---~--- +if [[ "${EXP}" == "" ]] || [[ "${RES}" == "" ]] || + [[ "${YYYYMMDDHHi}" == "" ]] || [[ "${FCST}" == "" ]] +then + echo " This script requires some arguments to be set through flags." + show_usage + exit 2 +fi +#---~--- + + # Standart directories variables:--------------------------------------- DIRHOMES=${DIR_SCRIPTS}/scripts_CD-CT; mkdir -p ${DIRHOMES} DIRHOMED=${DIR_DADOS}/scripts_CD-CT; mkdir -p ${DIRHOMED} @@ -36,14 +94,6 @@ EXECS=${DIRHOMED}/execs; mkdir -p ${EXECS} #---------------------------------------------------------------------- -# Input variables:-------------------------------------- -EXP=${1}; #EXP=GFS -RES=${2}; #RES=1024002 -YYYYMMDDHHi=${3}; #YYYYMMDDHHi=2024012000 -FCST=${4}; #FCST=24 -#------------------------------------------------------- - - # Local variables-------------------------------------- start_date=${YYYYMMDDHHi:0:4}-${YYYYMMDDHHi:4:2}-${YYYYMMDDHHi:6:2}_${YYYYMMDDHHi:8:2}:00:00 GEODATA=${DATAIN}/WPS_GEOG diff --git a/scripts/make_static.bash b/scripts/make_static.bash index 260d3ca..2571d85 100755 --- a/scripts/make_static.bash +++ b/scripts/make_static.bash @@ -1,30 +1,88 @@ #!/bin/bash -if [ $# -ne 4 ] -then - echo "" - echo "Instructions: execute the command below" + + +#--- Function that shows usage. +function show_usage() { + echo " Usage: " echo "" - echo "${0} EXP_NAME RESOLUTION LABELI FCST" + echo " ${0} [-e EXP ] [-f FCST] [-r RES] [-t YYYYMMDDHH]" echo "" - echo "EXP_NAME :: Forcing: GFS" - echo " :: Others options to be added later..." - 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 " List of **required** flags: " echo "" - echo "24 hour forcast example:" - echo "${0} GFS 1024002 2024010100 24" + echo " -e EXP -- meteorological drivers. For example, GFS" + echo " -f FCST -- Simulation length in hours, e.g., 24 or 48." + echo " -r RES -- grid resolution. Options are:" + echo " 5898242 (~ 10 km)" + echo " 2621442 (~ 15 km)" + echo " 1024002 (~ 24 km)" + echo " 40962 (~ 120 km)" + echo " -t YYYYMMDDHH -- Initial time. For example if 22 Sept 2025 00 UTC, set it to:" + echo " 2025092200" echo "" - - exit -fi +} +#---~--- # Set environment variables exports: . setenv.bash + + +#--- Default input variables: +EXP="" +RES="" +YYYYMMDDHHi="" +FCST="" +#---~--- + + +#--- Parse arguments. +while [[ ${#} > 0 ]] +do + key="${1}" + case ${key} in + -e) + EXP="${2}" + shift 2 # past flag and argument + ;; + -f) + FCST="${2}" + shift 2 # past flag and argument + ;; + -r) + RES="${2}" + shift 2 # past flag and argument + ;; + -t) + YYYYMMDDHHi="${2}" + shift 2 # past flag and argument + ;; + *) + echo "Unknown key-value argument pair." + show_usage + exit 2 + ;; + esac +done +#---~--- + + + +#---~--- +# Make sure all settings were provided (unless this will be to clean up runs). +#---~--- +if [[ "${EXP}" == "" ]] || [[ "${RES}" == "" ]] || + [[ "${YYYYMMDDHHi}" == "" ]] || [[ "${FCST}" == "" ]] +then + echo " This script requires some arguments to be set through flags." + show_usage + exit 2 +fi +#---~--- + + # Standart directories variables:--------------------------------------- DIRHOMES=${DIR_SCRIPTS}/scripts_CD-CT; mkdir -p ${DIRHOMES} DIRHOMED=${DIR_DADOS}/scripts_CD-CT; mkdir -p ${DIRHOMED} @@ -36,14 +94,6 @@ EXECS=${DIRHOMED}/execs; mkdir -p ${EXECS} #---------------------------------------------------------------------- -# Input variables:-------------------------------------- -EXP=${1}; #EXP=GFS -RES=${2}; #RES=1024002 -YYYYMMDDHHi=${3}; #YYYYMMDDHHi=2024012000 -FCST=${4}; #FCST=24 -#------------------------------------------------------- - - # Local variables-------------------------------------- GEODATA=${DATAIN}/WPS_GEOG cores=${STATIC_ncores} diff --git a/scripts/make_template.bash b/scripts/make_template.bash index 26a7021..41c04cb 100755 --- a/scripts/make_template.bash +++ b/scripts/make_template.bash @@ -15,31 +15,116 @@ # #-----------------------------------------------------------------------------# -if [ $# -ne 4 -a $# -ne 1 ] -then +#--- Function that shows usage. +function show_usage() { + echo " Usage: " echo "" - echo "Instructions: execute the command below" + echo " ${0} [-v VARTABLE] [-d OUTPUT_DIAG_INT] [-e EXP ] [-f FCST] \\" + echo " [-r RES] [-t YYYYMMDDHH]" echo "" - echo "${0} ]EXP_NAME/OP] RESOLUTION LABELI FCST" + echo " List of optional flags: " echo "" - 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 " -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." echo "" - echo "24 hour forcast example:" - echo "${0} GFS 1024002 2024010100 24" - echo "${0} GFS 40962 2024010100 48" + echo " List of **required** flags: " echo "" - - exit -fi + echo " -d OUTPUT_DIAG_INT -- Output interval for diagnostic. The format must be" + echo " \"HH:MM:SS\"" + echo " -e EXP -- meteorological drivers. For example, GFS" + echo " -f FCST -- Simulation length in hours, e.g., 24 or 48." + echo " -r RES -- grid resolution. Options are:" + echo " 5898242 (~ 10 km)" + echo " 2621442 (~ 15 km)" + echo " 1024002 (~ 24 km)" + echo " 40962 (~ 120 km)" + echo " -t YYYYMMDDHH -- Initial time. For example if 22 Sept 2025 00 UTC," + echo " set it to: 2025092200" + echo "" +} +#---~--- # Set environment variables exports: . setenv.bash + +#--- Default input variables: +CLEAN=false +EXP="" +RES="" +YYYYMMDDHHi="" +FCST="" +OUTPUT_DIAG_INTERVAL="" +VARTABLE="" +#---~--- + + +#--- Parse arguments. +while [[ ${#} > 0 ]] +do + key="${1}" + case ${key} in + -c) + CLEAN=true + shift 1 # Past flag + ;; + -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 + ;; + -r) + RES="${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 + ;; + *) + echo "Unknown key-value argument pair." + show_usage + exit 2 + ;; + esac +done +#---~--- + + + +#---~--- +# Make sure all settings were provided (unless this will be to clean up runs). +#---~--- +if [[ "${EXP}" == "" ]] || [[ "${RES}" == "" ]] || + [[ "${YYYYMMDDHHi}" == "" ]] || [[ "${FCST}" == "" ]] || + [[ "${OUTPUT_DIAG_INTERVAL}" == "" ]] +then + echo " This script requires some arguments to be set through flags." + show_usage + exit 2 +fi +#---~--- + + + # Standart directories variables:--------------------------------------- DIRHOMES=${DIR_SCRIPTS}/scripts_CD-CT; mkdir -p ${DIRHOMES} DIRHOMED=${DIR_DADOS}/scripts_CD-CT; mkdir -p ${DIRHOMED} @@ -49,14 +134,6 @@ DATAOUT=${DIRHOMED}/dataout; mkdir -p ${DATAOUT} SOURCES=${DIRHOMES}/sources; mkdir -p ${SOURCES} EXECS=${DIRHOMED}/execs; mkdir -p ${EXECS} #---------------------------------------------------------------------- - - -# Input variables:-------------------------------------- -EXP=${1}; #EXP=GFS -RES=${2}; #RES=1024002 -YYYYMMDDHHi=${3}; #YYYYMMDDHHi=2024042000 -FCST=${4}; #FCST=40 -#------------------------------------------------------- mkdir -p ${DATAOUT}/${YYYYMMDDHHi}/Post/logs @@ -64,16 +141,14 @@ mkdir -p ${DATAOUT}/${YYYYMMDDHHi}/Post/logs START_DATE_YYYYMMDD="${YYYYMMDDHHi:0:4}-${YYYYMMDDHHi:4:2}-${YYYYMMDDHHi:6:2}" START_HH="${YYYYMMDDHHi:8:2}" maxpostpernode=20 # <------ qtde max de convert_mpas por no! -VARTABLE=".OPER" export DIRRUN=${DIRHOMED}/run.${YYYYMMDDHHi}; rm -fr ${DIRRUN}; mkdir -p ${DIRRUN} -N_MODEL_LEV=55 #------------------------------------------------------- # Variables for flex outpout interval from streams.atmosphere------------------------ -t_strout=$(cat ${SCRIPTS}/namelists/streams.atmosphere.TEMPLATE | sed -n '//s/.*output_interval="\([^"]*\)".*/\1/p') -t_stroutsec=$(echo ${t_strout} | awk -F: '{print ($1 * 3600) + ($2 * 60) + $3}') -t_strouthor=$(echo "scale=4; (${t_stroutsec}/60)/60" | bc) -t_stroutmin=$(echo "${t_stroutsec}/60" | bc) +t_strout=${OUTPUT_DIAG_INTERVAL} +t_stroutsec=`echo ${t_strout} | awk -F: '{print ($1 * 3600) + ($2 * 60) + $3}'` +t_strouthor=`echo "scale=4; (${t_stroutsec}/60)/60" | bc` +t_stroutmin=`echo "${t_stroutsec}/60" | bc` #------------------------------------------------------------------------------------ cd ${DIRRUN} @@ -83,44 +158,64 @@ cd ${DIRRUN} IFS=":" read -r h m s <<< "${t_strout}" printf -v t_strout "%02d:%02d:%02d" "$h" "$m" "$s" -# Calculating default parameters for different resolutions -if [ $RES -eq 1024002 ]; then #24Km - NLAT=721 #180/0.25 - NLON=1441 #360/0.25 +# Calculate default parameters for different resolutions +# ML: This assumes 1deg ~ 100 km, which is making the post-processed output coarser +# than it needs to be... +case ${RES} in +5898242) #10km + NLAT=1801 #180/0.10 (+1) + NLON=3601 #360/0.10 (+1) STARTLAT=-90.0 STARTLON=0.0 ENDLAT=90.0 ENDLON=360.0 -elif [ $RES -eq 2621442 ]; then #15Km - NLAT=1201 #180/0.15 - NLON=2401 #360/0.15 + ;; +2621442) #15Km + NLAT=1200 #180/0.15 + NLON=2400 #360/0.15 STARTLAT=-90.0 STARTLON=0.0 ENDLAT=90.0 ENDLON=360.0 -elif [ $RES -eq 40962 ]; then #120Km + ;; +1024002) #24Km + NLAT=720 #180/0.25 + NLON=1440 #360/0.25 + STARTLAT=-90.0 + STARTLON=0.0 + ENDLAT=90.0 + ENDLON=360.0 + ;; +40962) #120Km NLAT=150 #180/1.2 NLON=300 #360/1.2 STARTLAT=-90.0 STARTLON=0.0 ENDLAT=90.0 ENDLON=360.0 -fi + ;; +*) + echo -e "${RED}****** FATAL ERROR ******${NC} \n" + echo -e "${RED}==>${NC} Provided grid resolution (${RES}) is not recognised.\n" + echo -e "${RED}==>${NC} ${0} cannot post-process this MONAN simulation.\n" + exit -1 + ;; +esac #------------------------------------------------------- -# NLEVS get from t_iso_levels in Registry_isobaric.xml: +# Retrieve N_ISOBARIC_LEV from t_iso_levels in Registry_isobaric.xml: if [ -s ${MONANDIR}/src/core_atmosphere/diagnostics/Registry_isobaric.xml ] then - NLEV=$(grep "t_iso_levels" ${MONANDIR}/src/core_atmosphere/diagnostics/Registry_isobaric.xml | grep definition | cut -d\" -f4) + N_ISOBARIC_LEV=$(grep "t_iso_levels" ${MONANDIR}/src/core_atmosphere/diagnostics/Registry_isobaric.xml | grep definition | cut -d\" -f4) else - NLEV=18 + N_ISOBARIC_LEV=18 fi output_interval=${t_strouthor} nfiles=$(echo "$FCST/$output_interval + 1" | bc) -diag_name_post=MONAN_DIAG_G_POS_${EXP}_${YYYYMMDDHHi}_${YYYYMMDDHHi}.00.00.x${RES}L${NLEV}.nc -diag_name_templ=MONAN_DIAG_G_POS_${EXP}_${YYYYMMDDHHi}_%y4%m2%d2%h2.%n2.00.x${RES}L${NLEV}.nc +diag_name_post=MONAN_DIAG_G_POS_${EXP}_${YYYYMMDDHHi}_${YYYYMMDDHHi}.00.00.x${RES}L${N_ISOBARIC_LEV}.nc +diag_name_templ=MONAN_DIAG_G_POS_${EXP}_${YYYYMMDDHHi}_%y4%m2%d2%h2.%n2.00.x${RES}L${N_ISOBARIC_LEV}.nc rm -fr ${DIRRUN}/qctlinfo.gs cat > ${DIRRUN}/qctlinfo.gs < 0 ]] +do + key="${1}" + case ${key} in + -c) + CLEAN="-c" + shift 1 # Past flag + ;; + -d) + OUTPUT_DIAG_INTERVAL="${2}" + shift 2 # Past flag and argument + ;; + -e) + EXP="${2}" + shift 2 # past flag and argument + ;; + -f00) + FCST_ZERO="${2}" + shift 2 # past flag and argument + ;; + -f12) + FCST_TWELVE="${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 + ;; + -ti) + YYYYMMDDHHi="${2}" + shift 2 # past flag and argument + ;; + -tf) + YYYYMMDDHHf="${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 + ;; + *) + echo "Unknown key-value argument pair." + show_usage + exit 2 + ;; + esac +done +#---~--- + + + +#--- 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 +#---~--- # Input variables:----------------------------------------------------- DIR_DADOS=/mnt/beegfs/monan/users/renato/issues/ecflow-PREOPER/SCRATCHOUT; mkdir -p ${DIR_DADOS} DIRFLUSHOUT=/mnt/beegfs/monan/users/renato/issues/trashout; mkdir -p ${DIRFLUSHOUT} -EXP=GFS -RES=1024002 -FCST=240 #---------------------------------------------------------------------- -while [ ${yyyymmdd} -le ${yyyymmddf} ] +#--- Make sure VARTABLE has the leading "-v" if not empty. +if [[ "${VARTABLE}" == "" ]] +then + dv_VARTABLE="" +else + dv_VARTABLE="-v ${VARTABLE}" +fi +#---~--- + + +YYYYMMDD=${YYYYMMDDi} +while [ ${YYYYMMDD} -le ${YYYYMMDDf} ] do + HH_LIST="00 12" + for HH in ${HH_LIST} + do + YYYYMMDDHHi="${YYYYMMDD}${HH}" + case ${HH} in + 00) FCST=${FCST_ZERO} ;; + 12) FCST=${FCST_TWELVE} ;; + esac - echo "${SCRIPTS}/2.pre_processing.bash ${EXP} ${RES} ${yyyymmdd}00 240" - ${SCRIPTS}/2.pre_processing.bash ${EXP} ${RES} ${yyyymmdd}00 240 - echo "${SCRIPTS}/3.run_model.bash ${EXP} ${RES} ${yyyymmdd}00 240" - ${SCRIPTS}/3.run_model.bash ${EXP} ${RES} ${yyyymmdd}00 240 - echo "${SCRIPTS}/4.run_post.bash ${EXP} ${RES} ${yyyymmdd}00 240" - ${SCRIPTS}/4.run_post.bash ${EXP} ${RES} ${yyyymmdd}00 240 - - # Final data output directory: - mkdir -p ${DIRFLUSHOUT}/${yyyymmdd}00/ - # Copy post: - cp -fr ${DIRSCRIPTDADOS}/dataout/${yyyymmdd}00/Post/* ${DIRFLUSHOUT}/${yyyymmdd}00/ - # Remove all output files from the original output diretory dataout: - rm -fr ${DIRSCRIPTDADOS}/dataout/${yyyymmdd}00 - rm -fr ${DIRSCRIPTDADOS}/datain/${yyyymmdd}00 + # Set arguments. + ARGS_TWO="${OVERWRITE} -e ${EXP} -f ${FCST} -r ${RES} -t ${YYYYMMDDHHi}" + ARGS_THREE="${dv_VARTABLE} -d ${OUTPUT_DIAG_INTERVAL} -e ${EXP}" + ARGS_THREE="${ARGS_THREE} -f ${FCST} -l ${NLEV} -r ${RES} -t ${YYYYMMDDHHi}" + ARGS_FOUR="${dv_VARTABLE} -d ${OUTPUT_DIAG_INTERVAL} -e ${EXP} -f ${FCST}" + ARGS_FOUR="${ARGS_FOUR} -l ${NLEV} -r ${RES} -t ${YYYYMMDDHHi}" - - - echo "${SCRIPTS}/2.pre_processing.bash ${EXP} ${RES} ${yyyymmdd}12 120" - ${SCRIPTS}/2.pre_processing.bash ${EXP} ${RES} ${yyyymmdd}12 120 - echo "${SCRIPTS}/3.run_model.bash ${EXP} ${RES} ${yyyymmdd}12 120" - ${SCRIPTS}/3.run_model.bash ${EXP} ${RES} ${yyyymmdd}12 120 - echo "${SCRIPTS}/4.run_post.bash ${EXP} ${RES} ${yyyymmdd}12 120" - ${SCRIPTS}/4.run_post.bash ${EXP} ${RES} ${yyyymmdd}12 120 - - # Final data output directory: - mkdir -p ${DIRFLUSHOUT}/${yyyymmdd}12/ - # Copy post: - cp -fr ${DIRSCRIPTDADOS}/dataout/${yyyymmdd}12/Post/* ${DIRFLUSHOUT}/${yyyymmdd}12/ - # Remove all output files from the original output diretory dataout: - rm -fr ${DIRSCRIPTDADOS}/dataout/${yyyymmdd}12 - rm -fr ${DIRSCRIPTDADOS}/datain/${yyyymmdd}12 - - yyyymmdd=$(date -u +%Y%m%d -d "${yyyymmdd} 1 day") + # Run scripts + echo "${SCRIPTS}/2.pre_processing.bash ${ARGS_TWO}" + ${SCRIPTS}/2.pre_processing.bash ${ARGS_TWO} + echo "${SCRIPTS}/3.run_model.bash ${ARGS_THREE}" + ${SCRIPTS}/3.run_model.bash ${ARGS_THREE} + echo "${SCRIPTS}/4.run_post.bash ${ARGS_FOUR}" + ${SCRIPTS}/4.run_post.bash ${ARGS_FOUR} + + # Final data output directory: + mkdir -p ${DIRFLUSHOUT}/${YYYYMMDDHHi}/ + # Copy post: + cp -fr ${DIRSCRIPTDADOS}/dataout/${YYYYMMDDHHi}/Post/* ${DIRFLUSHOUT}/${YYYYMMDDHHi}/ + # Remove all output files from the original output diretory dataout: + rm -fr ${DIRSCRIPTDADOS}/dataout/${YYYYMMDDHHi} + rm -fr ${DIRSCRIPTDADOS}/datain/${YYYYMMDDHHi} + + # No need to overwrite static fields after the first iteration + OVERWRITE="" + done + + # Update time + YYYYMMDD=$(date -u +%Y%m%d -d "${YYYYMMDD} 1 day") done From 7caa676a93db79c5293812989be2816d93d50e2c Mon Sep 17 00:00:00 2001 From: Marcos Longo Date: Thu, 8 Jan 2026 11:24:42 -0300 Subject: [PATCH 08/11] Function clean_tmp_files no longer exists. Remove option "-c" from all scripts. --- scripts/0.run_all.bash | 18 +++++------------- scripts/2.pre_processing.bash | 18 ++++-------------- scripts/3.run_model.bash | 18 ++++-------------- scripts/4.run_post.bash | 20 +++++--------------- 4 files changed, 18 insertions(+), 56 deletions(-) diff --git a/scripts/0.run_all.bash b/scripts/0.run_all.bash index 7bea026..6f990da 100755 --- a/scripts/0.run_all.bash +++ b/scripts/0.run_all.bash @@ -7,7 +7,7 @@ function show_usage() { echo " Usage: " echo "" - echo " ${0} [-c] [-o] [-bc TAG_CONVERT_MPAS] [ -bm TAG_MONAN ] [-d OUTPUT_DIAG_INT] \\" + echo " ${0} [-o] [-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 "" @@ -17,8 +17,6 @@ function show_usage() { 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 " -c -- Clean files from previous runs. This is used by steps" - echo " 2 and 3." 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" @@ -68,7 +66,6 @@ function show_usage() { #--- Default input variables: STEP=1 -CLEAN="" OVERWRITE="" github_link_MONAN="https://github.com/monanadmin/MONAN-Model.git" tag_or_branch_name_MONAN="release/1.4.1-rc" @@ -98,10 +95,6 @@ do tag_or_branch_name_MONAN="${2}" shift 2 # past flag and argument ;; - -c) - CLEAN="-c" - shift 1 # Past flag - ;; -d) OUTPUT_DIAG_INTERVAL="${2}" shift 2 # Past flag and argument @@ -236,7 +229,7 @@ case ${STEP} in #--- Run step - time ${0} ${CLEAN} ${OVERWRITE} ${dv_VARTABLE} \ + 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} @@ -257,16 +250,15 @@ case ${STEP} in #---~--- # STEP 2: Run the pre-processing step, and make initial/boundary conditions if needed. #---~--- - time 2.pre_processing.bash ${CLEAN} ${OVERWRITE} -e ${EXP} -f ${FCST} -r ${RES} \ - -t ${YYYYMMDDHHi} + 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 ${CLEAN} ${dv_VARTABLE} -d ${OUTPUT_DIAG_INTERVAL} -e ${EXP} \ - -f ${FCST} -l ${NLEV} -r ${RES} -t ${YYYYMMDDHHi} + time 3.run_model.bash ${dv_VARTABLE} -d ${OUTPUT_DIAG_INTERVAL} -e ${EXP} -f ${FCST} \ + -l ${NLEV} -r ${RES} -t ${YYYYMMDDHHi} #---~--- ;; 4) diff --git a/scripts/2.pre_processing.bash b/scripts/2.pre_processing.bash index a34e910..56658aa 100755 --- a/scripts/2.pre_processing.bash +++ b/scripts/2.pre_processing.bash @@ -23,11 +23,10 @@ function show_usage() { echo " Usage: " echo "" - echo " ${0} [-c] [-o] [-e EXP ] [-f FCST] [-r RES] [-t YYYYMMDDHH]" + echo " ${0} [-o] [-e EXP ] [-f FCST] [-r RES] [-t YYYYMMDDHH]" echo "" echo " List of optional flags: " echo "" - echo " -c -- Clean files from previous runs." echo " -o -- Overwrite static files." echo "" echo " List of **required** flags when -c is not set: " @@ -54,7 +53,6 @@ function show_usage() { #--- Default input variables: -CLEAN=false OVERWRITE=true EXP="" RES="" @@ -68,10 +66,6 @@ while [[ ${#} > 0 ]] do key="${1}" case ${key} in - -c) - CLEAN=true - shift 1 # Past flag - ;; -e) EXP="${2}" shift 2 # past flag and argument @@ -104,14 +98,10 @@ done #---~--- -# Make sure all settings were provided (unless this will be to clean up runs). +# Make sure all settings were provided. #---~--- -if ${CLEAN} -then - clean_pre_tmp_files - exit -elif [[ "${EXP}" == "" ]] || [[ "${RES}" == "" ]] || - [[ "${YYYYMMDDHHi}" == "" ]] || [[ "${FCST}" == "" ]] +if [[ "${EXP}" == "" ]] || [[ "${RES}" == "" ]] || + [[ "${YYYYMMDDHHi}" == "" ]] || [[ "${FCST}" == "" ]] then echo " This script requires some arguments to be set through flags." show_usage diff --git a/scripts/3.run_model.bash b/scripts/3.run_model.bash index 5f80e8a..72f6577 100755 --- a/scripts/3.run_model.bash +++ b/scripts/3.run_model.bash @@ -19,12 +19,11 @@ function show_usage() { echo " Usage: " echo "" - echo " ${0} [-c] [-v VARTABLE] [-d OUTPUT_DIAG_INT] [-e EXP ] [-f FCST] [-l NLEV] \\" + echo " ${0} [-v VARTABLE] [-d OUTPUT_DIAG_INT] [-e EXP ] [-f FCST] [-l NLEV] \\" echo " [-r RES] [-t YYYYMMDDHH]" echo "" echo " List of optional flags: " echo "" - echo " -c -- Clean files from previous runs." 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." @@ -56,7 +55,6 @@ function show_usage() { #--- Default input variables: -CLEAN=false EXP="" RES="" YYYYMMDDHHi="" @@ -72,10 +70,6 @@ while [[ ${#} > 0 ]] do key="${1}" case ${key} in - -c) - CLEAN=true - shift 1 # Past flag - ;; -d) OUTPUT_DIAG_INTERVAL="${2}" shift 2 # Past flag and argument @@ -122,13 +116,9 @@ done #---~--- # Make sure all settings were provided (unless this will be to clean up runs). #---~--- -if ${CLEAN} -then - clean_pre_tmp_files - exit -elif [[ "${EXP}" == "" ]] || [[ "${RES}" == "" ]] || - [[ "${YYYYMMDDHHi}" == "" ]] || [[ "${FCST}" == "" ]] || - [[ "${NLEV}" == "" ]] || [[ "${OUTPUT_DIAG_INTERVAL}" == "" ]] +if [[ "${EXP}" == "" ]] || [[ "${RES}" == "" ]] || + [[ "${YYYYMMDDHHi}" == "" ]] || [[ "${FCST}" == "" ]] || + [[ "${NLEV}" == "" ]] || [[ "${OUTPUT_DIAG_INTERVAL}" == "" ]] then echo " This script requires some arguments to be set through flags." show_usage diff --git a/scripts/4.run_post.bash b/scripts/4.run_post.bash index f4455ec..c2151d8 100755 --- a/scripts/4.run_post.bash +++ b/scripts/4.run_post.bash @@ -19,12 +19,11 @@ function show_usage() { echo " Usage: " echo "" - echo " ${0} [-c] [-v VARTABLE] [-d OUTPUT_DIAG_INT] [-e EXP ] [-f FCST] \\" + echo " ${0} [-v VARTABLE] [-d OUTPUT_DIAG_INT] [-e EXP ] [-f FCST] \\" echo " [-l N_MODEL_LEV] [-r RES] [-t YYYYMMDDHH]" echo "" echo " List of optional flags: " echo "" - echo " -c -- Clean files from previous runs." 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." @@ -56,7 +55,6 @@ function show_usage() { #--- Default input variables: -CLEAN=false EXP="" RES="" YYYYMMDDHHi="" @@ -72,10 +70,6 @@ while [[ ${#} > 0 ]] do key="${1}" case ${key} in - -c) - CLEAN=true - shift 1 # Past flag - ;; -d) OUTPUT_DIAG_INTERVAL="${2}" shift 2 # Past flag and argument @@ -120,15 +114,11 @@ done #---~--- -# Make sure all settings were provided (unless this will be to clean up runs). +# Make sure all settings were provided. #---~--- -if ${CLEAN} -then - clean_pre_tmp_files - exit -elif [[ "${EXP}" == "" ]] || [[ "${RES}" == "" ]] || - [[ "${YYYYMMDDHHi}" == "" ]] || [[ "${FCST}" == "" ]] || - [[ "${N_MODEL_LEV}" == "" ]] || [[ "${OUTPUT_DIAG_INTERVAL}" == "" ]] +if [[ "${EXP}" == "" ]] || [[ "${RES}" == "" ]] || + [[ "${YYYYMMDDHHi}" == "" ]] || [[ "${FCST}" == "" ]] || + [[ "${N_MODEL_LEV}" == "" ]] || [[ "${OUTPUT_DIAG_INTERVAL}" == "" ]] then echo " This script requires some arguments to be set through flags." show_usage From c680edda84d6c8e53d60d904e31c49d650cce3d9 Mon Sep 17 00:00:00 2001 From: Marcos Longo Date: Thu, 8 Jan 2026 11:32:23 -0300 Subject: [PATCH 09/11] Replace hardcoded L55 with L${NLEV}. This is used for reporting an error only. --- scripts/3.run_model.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/3.run_model.bash b/scripts/3.run_model.bash index 72f6577..90817a6 100755 --- a/scripts/3.run_model.bash +++ b/scripts/3.run_model.bash @@ -319,7 +319,7 @@ do i=$(printf "%04d" ${ii}) hh=${YYYYMMDDHHi:8:2} currentdate=$(date -d "${YYYYMMDDHHi:0:8} ${hh}:00:00 $(echo "(${i}-1)*${t_strout:0:2}" | bc) hours $(echo "(${i}-1)*${t_strout:3:2}" | bc) minutes $(echo "(${i}-1)*${t_strout:6:2}" | bc) seconds" +"%Y%m%d%H.%M.%S") - file=MONAN_DIAG_G_MOD_${EXP}_${YYYYMMDDHHi}_${currentdate}.x${RES}L55.nc + file=MONAN_DIAG_G_MOD_${EXP}_${YYYYMMDDHHi}_${currentdate}.x${RES}L${NLEV}.nc if [ ! -s ${DATAOUT}/${YYYYMMDDHHi}/Model/${file} ] then From a06d954bdeaac31a17fb4f2239976dea4e2484ae Mon Sep 17 00:00:00 2001 From: Marcos Longo Date: Sat, 10 Jan 2026 09:13:33 -0300 Subject: [PATCH 10/11] Add option -z to 0.run_all.bash that removes all compiled code and output/log files from the path. It is not a complete reset because it does not revert files in the scripts directory. --- scripts/0.run_all.bash | 115 ++++++++++++++++++++++++++++++++--------- 1 file changed, 90 insertions(+), 25 deletions(-) diff --git a/scripts/0.run_all.bash b/scripts/0.run_all.bash index 6f990da..d0941b0 100755 --- a/scripts/0.run_all.bash +++ b/scripts/0.run_all.bash @@ -7,7 +7,7 @@ function show_usage() { echo " Usage: " echo "" - echo " ${0} [-o] [-bc TAG_CONVERT_MPAS] [ -bm TAG_MONAN ] [-d OUTPUT_DIAG_INT] \\" + 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 "" @@ -50,6 +50,9 @@ function show_usage() { 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 "" @@ -79,6 +82,7 @@ FCST=24 NLEV=55 OUTPUT_DIAG_INTERVAL="03:00:00" VARTABLE="" +ZERO_STATE=false #---~--- @@ -147,6 +151,10 @@ do esac shift 2 # past flag and argument ;; + -z) + ZERO_STATE=true + shift 1 # past flag + ;; *) echo "Unknown key-value argument pair." show_usage @@ -157,6 +165,83 @@ 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} +#---~--- + + + + +#---~--- +# 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. #---~--- @@ -182,26 +267,6 @@ esac #---~--- -#--- 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} -#---~--- - - -#--- 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 VARTABLE has the leading "-v" if not empty. if [[ "${VARTABLE}" == "" ]] then @@ -229,10 +294,10 @@ case ${STEP} in #--- 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} + 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 #---~--- From 2b56728437bf59a0db46524cd05633805d28d1e9 Mon Sep 17 00:00:00 2001 From: Marcos Longo Date: Sat, 10 Jan 2026 09:36:14 -0300 Subject: [PATCH 11/11] Slightly revised the calculation of NLON and NLAT when reprojecting the output to a regular longitude/latitude grid. It now accounts for the number of grid cells and the average resolution across the Earth's surface (4*pi steradians). --- scripts/4.run_post.bash | 59 +++++++++++++++++++++++++++----------- scripts/make_template.bash | 59 +++++++++++++++++++++++++++----------- 2 files changed, 86 insertions(+), 32 deletions(-) diff --git a/scripts/4.run_post.bash b/scripts/4.run_post.bash index c2151d8..48400d7 100755 --- a/scripts/4.run_post.bash +++ b/scripts/4.run_post.bash @@ -158,50 +158,77 @@ t_strouthor=`echo "scale=4; (${t_stroutsec}/60)/60" | bc` IFS=":" read -r h m s <<< "${t_strout}" printf -v t_strout "%02d:%02d:%02d" "$h" "$m" "$s" -# Calculate default parameters for different resolutions -# ML: This assumes 1deg ~ 100 km, which is making the post-processed output coarser -# than it needs to be... +# Calculate default parameters for different resolutions. +# ML: The original numbers assumed 1 degree ~ 100 km. Across latitude and near the +# Equator, 1 degree ~ 111.2 km, so the regridded data ended up being slightly coarser +# than it needed to be. To ensure an average grid mesh in regular lon/lat that is +# close to the original resolution, I now calculate the average resolution based on +# the number of points in a full sphere (4*pi steradians), and pick the nearest +# integer number of points per degree. +# delta_xy = sqrt( 4*pi * (180/pi)^2 / NumberOfPoints) +# PointsPerDegree = round(1/delta_xy) +# NLON = 360 * PointsPerDegree + 1 +# NLAT = 180 * PointsPerDegree + 1 case ${RES} in -5898242) #10km - NLAT=1801 #180/0.10 (+1) - NLON=3601 #360/0.10 (+1) +5898242) + #---~--- + # 10 km, use 12 points per degree + #---~--- + NLAT=2161 + NLON=4321 STARTLAT=-90.0 STARTLON=0.0 ENDLAT=90.0 ENDLON=360.0 + #---~--- ;; -2621442) #15Km - NLAT=1200 #180/0.15 - NLON=2400 #360/0.15 +2621442) + #---~--- + # 15 km, use 8 points per degree + #---~--- + NLAT=1441 + NLON=2881 STARTLAT=-90.0 STARTLON=0.0 ENDLAT=90.0 ENDLON=360.0 + #---~--- ;; -1024002) #24Km - NLAT=720 #180/0.25 - NLON=1440 #360/0.25 +1024002) + #---~--- + # 24 km, use 5 points per degree + #---~--- + NLAT=901 + NLON=1801 STARTLAT=-90.0 STARTLON=0.0 ENDLAT=90.0 ENDLON=360.0 + #---~--- ;; -40962) #120Km - NLAT=150 #180/1.2 - NLON=300 #360/1.2 +40962) + #---~--- + # 120 km, use 1 points per degree + #---~--- + NLAT=181 + NLON=361 STARTLAT=-90.0 STARTLON=0.0 ENDLAT=90.0 ENDLON=360.0 + #---~--- ;; *) + #---~--- + # Unrecognised resolution + #---~--- echo -e "${RED}****** FATAL ERROR ******${NC} \n" echo -e "${RED}==>${NC} Provided grid resolution (${RES}) is not recognised.\n" echo -e "${RED}==>${NC} ${0} cannot post-process this MONAN simulation.\n" exit -1 ;; esac -#------------------------------------------------------- +#---~--- # Retrieve N_ISOBARIC_LEV from t_iso_levels in Registry_isobaric.xml: if [ -s ${MONANDIR}/src/core_atmosphere/diagnostics/Registry_isobaric.xml ] diff --git a/scripts/make_template.bash b/scripts/make_template.bash index 41c04cb..3eef4b7 100755 --- a/scripts/make_template.bash +++ b/scripts/make_template.bash @@ -158,50 +158,77 @@ cd ${DIRRUN} IFS=":" read -r h m s <<< "${t_strout}" printf -v t_strout "%02d:%02d:%02d" "$h" "$m" "$s" -# Calculate default parameters for different resolutions -# ML: This assumes 1deg ~ 100 km, which is making the post-processed output coarser -# than it needs to be... +# Calculate default parameters for different resolutions. +# ML: The original numbers assumed 1 degree ~ 100 km. Across latitude and near the +# Equator, 1 degree ~ 111.2 km, so the regridded data ended up being slightly coarser +# than it needed to be. To ensure an average grid mesh in regular lon/lat that is +# close to the original resolution, I now calculate the average resolution based on +# the number of points in a full sphere (4*pi steradians), and pick the nearest +# integer number of points per degree. +# delta_xy = sqrt( 4*pi * (180/pi)^2 / NumberOfPoints) +# PointsPerDegree = round(1/delta_xy) +# NLON = 360 * PointsPerDegree + 1 +# NLAT = 180 * PointsPerDegree + 1 case ${RES} in -5898242) #10km - NLAT=1801 #180/0.10 (+1) - NLON=3601 #360/0.10 (+1) +5898242) + #---~--- + # 10 km, use 12 points per degree + #---~--- + NLAT=2161 + NLON=4321 STARTLAT=-90.0 STARTLON=0.0 ENDLAT=90.0 ENDLON=360.0 + #---~--- ;; -2621442) #15Km - NLAT=1200 #180/0.15 - NLON=2400 #360/0.15 +2621442) + #---~--- + # 15 km, use 8 points per degree + #---~--- + NLAT=1441 + NLON=2881 STARTLAT=-90.0 STARTLON=0.0 ENDLAT=90.0 ENDLON=360.0 + #---~--- ;; -1024002) #24Km - NLAT=720 #180/0.25 - NLON=1440 #360/0.25 +1024002) + #---~--- + # 24 km, use 5 points per degree + #---~--- + NLAT=901 + NLON=1801 STARTLAT=-90.0 STARTLON=0.0 ENDLAT=90.0 ENDLON=360.0 + #---~--- ;; -40962) #120Km - NLAT=150 #180/1.2 - NLON=300 #360/1.2 +40962) + #---~--- + # 120 km, use 1 points per degree + #---~--- + NLAT=181 + NLON=361 STARTLAT=-90.0 STARTLON=0.0 ENDLAT=90.0 ENDLON=360.0 + #---~--- ;; *) + #---~--- + # Unrecognised resolution. + #---~--- echo -e "${RED}****** FATAL ERROR ******${NC} \n" echo -e "${RED}==>${NC} Provided grid resolution (${RES}) is not recognised.\n" echo -e "${RED}==>${NC} ${0} cannot post-process this MONAN simulation.\n" exit -1 ;; esac -#------------------------------------------------------- +#---~--- # Retrieve N_ISOBARIC_LEV from t_iso_levels in Registry_isobaric.xml: if [ -s ${MONANDIR}/src/core_atmosphere/diagnostics/Registry_isobaric.xml ]