diff --git a/scripts/0.run_all.bash b/scripts/0.run_all.bash index c020acc..d0941b0 100755 --- a/scripts/0.run_all.bash +++ b/scripts/0.run_all.bash @@ -1,32 +1,171 @@ #!/bin/bash -#if [ $# -ne 5 ] -#then -# echo "" -# echo "Instructions: execute the command below" -# echo "" -# echo "${0} GitHubUserRepo EXP_NAME RESOLUTION LABELI FCST" -# echo "" -# echo "GitHubUserRepo :: GitHub link for your personal fork, eg: https://github.com/MYUSER/MONAN-Model.git" -# echo "EXP_NAME :: Forcing: GFS" -# echo "RESOLUTION :: number of points in resolution model grid, e.g: 1024002 (24 km)" -# echo "LABELI :: Initial date YYYYMMDDHH, e.g.: 2024010100" -# echo "FCST :: Forecast hours, e.g.: 24 or 36, etc." -# echo "" -# echo "24 hour forcast example:" -# echo "${0} https://github.com/MYUSER/MONAN-Model.git GFS 1024002 2024010100 24" -# echo "" -# exit -#fi - -# Set environment variables exports: -echo "" -echo -e "\033[1;32m==>\033[0m Moduling environment for MONAN model...\n" + + +#--- Function that shows usage. +function show_usage() { + echo " Usage: " + echo "" + echo " ${0} [-o] [-z] [-bc TAG_CONVERT_MPAS] [ -bm TAG_MONAN ] [-d OUTPUT_DIAG_INT] \\" + echo " [-e EXP ] [-f FCST] [-gc GIT_CONVERT_MPAS] [-gm GIT_MONAN ] [-i INPUT_PATH] \\" + echo " [-l NLEV] [-r RES] [-s STEP] [-t YYYYMMDDHH] [-v VARTABLE]" + echo "" + echo " List of optional flags: " + echo "" + echo " -bc TAG_CONVERT -- branch or tag name of the MONAN repository. For example:" + echo " \"develop\". This is used only by step 1." + echo " -bm TAG_MONAN -- branch or tag name of the MONAN repository. For example:" + echo " \"develop\". This is used only by step 1." + echo " -d OUTPUT_DIAG_INT -- Output interval for diagnostic. The format must be" + echo " \"HH:MM:SS\". This is used by steps 3 and 4." + echo " -e EXP -- Meteorological drivers. For example, GFS" + echo " -f FCST -- Simulation length in hours, e.g., 24 or 48." + echo " -gc GIT_CONVERT -- GitHub handle for MONAN. For example:" + echo " https://github.com/monanadmin/MONAN-Model.git" + echo " This is used only by step 1." + echo " -gm GIT_MONAN -- GitHub handle for MONAN. For example:" + echo " https://github.com/monanadmin/MONAN-Model.git" + echo " This is used only by step 1." + echo " -i INPUT_PATH -- Path containing input data for MONAN. If left empty, the" + echo " default path defined in setenv.bash will be used" + echo " -l NLEV -- Number of vertical levels for the output. This is used" + echo " by steps 3 and 4." + echo " -o -- Overwrite static files. This is used only by step 2." + echo " -r RES -- grid resolution. Supported options are:" + echo " 5898242 (~ 10 km)" + echo " 2621442 (~ 15 km)" + echo " 1024002 (~ 24 km)" + echo " 40962 (~ 120 km)" + echo " -s STEP -- Step to run. Options are:" + echo " 1 - Compile MONAN executables." + echo " 2 - Run pre-processing." + echo " 3 - Run atmospheric model." + echo " 4 - Run post-processing." + echo " 0 - Run all steps 1-4." + echo " -t YYYYMMDDHH -- Initial time. For example if 22 Sept 2025 00 UTC, the" + echo " argument should be 2025092200. This is used by steps" + echo " 2, 3 and 4." + echo " -v VARTABLE -- Suffix for defining which version of the" + echo " stream_list_atmosphere.diagnostics template to use." + echo " The default is to not use any suffix. This is used only" + echo " by steps 3 and 4." + echo " -z -- This will remove all files generated by all scripts and" + echo " reset the directory to the original state, except for" + echo " directory \"scripts\"." + echo "" + echo " All settings can be defined directly in the script." + echo "" +} +#---~--- + + +#--- Set environment variables exports: . setenv.bash +#---~--- + + + + +#--- Default input variables: +STEP=1 +OVERWRITE="" +github_link_MONAN="https://github.com/monanadmin/MONAN-Model.git" +tag_or_branch_name_MONAN="release/1.4.1-rc" +github_link_CONVERT_MPAS="https://github.com/monanadmin/convert_mpas.git" +tag_or_branch_name_CONVERT_MPAS="release/1.2.0" +EXP="GFS" +INPUT_PATH="" +RES=1024002 +YYYYMMDDHHi=2024010100 +FCST=24 +NLEV=55 +OUTPUT_DIAG_INTERVAL="03:00:00" +VARTABLE="" +ZERO_STATE=false +#---~--- -# Standart directories variables:--------------------------------------- +#--- Parse arguments. +while [[ ${#} > 0 ]] +do + key="${1}" + case ${key} in + -bc) + tag_or_branch_name_CONVERT_MPAS="${2}" + shift 2 # past flag and argument + ;; + -bm) + tag_or_branch_name_MONAN="${2}" + shift 2 # past flag and argument + ;; + -d) + OUTPUT_DIAG_INTERVAL="${2}" + shift 2 # Past flag and argument + ;; + -e) + EXP="${2}" + shift 2 # past flag and argument + ;; + -f) + FCST="${2}" + shift 2 # past flag and argument + ;; + -gc) + github_link_CONVERT_MPAS="${2}" + shift 2 # past flag and argument + ;; + -gm) + github_link_MONAN="${2}" + shift 2 # past flag and argument + ;; + -i) + INPUT_PATH="${2}" + shift 2 # Past flag and argument + ;; + -l) + NLEV="${2}" + shift 2 # Past flag and argument + ;; + -o) + OVERWRITE="-o" + shift 1 # past flag + ;; + -r) + RES="${2}" + shift 2 # past flag and argument + ;; + -s) + STEP="${2}" + shift 2 # past flag and argument + ;; + -t) + YYYYMMDDHHi="${2}" + shift 2 # past flag and argument + ;; + -v) + VFIRST=$(echo ${2} | cut -c 1-1) + case "${VFIRST}" in + .) VARTABLE="${2}" ;; + *) VARTABLE=".${2}" ;; + esac + shift 2 # past flag and argument + ;; + -z) + ZERO_STATE=true + shift 1 # past flag + ;; + *) + echo "Unknown key-value argument pair." + show_usage + exit 2 + ;; + esac +done +#---~--- + + +#--- Set and create standard directories DIRHOMES=${DIR_SCRIPTS}/scripts_CD-CT; mkdir -p ${DIRHOMES} DIRHOMED=${DIR_DADOS}/scripts_CD-CT; mkdir -p ${DIRHOMED} SCRIPTS=${DIRHOMES}/scripts; mkdir -p ${SCRIPTS} @@ -34,35 +173,166 @@ DATAIN=${DIRHOMED}/datain; mkdir -p ${DATAIN} DATAOUT=${DIRHOMED}/dataout; mkdir -p ${DATAOUT} SOURCES=${DIRHOMES}/sources; mkdir -p ${SOURCES} EXECS=${DIRHOMED}/execs; mkdir -p ${EXECS} -#---------------------------------------------------------------------- +#---~--- -# Input variables:----------------------------------------------------- -github_link="https://github.com/monanadmin/MONAN-Model.git" -monan_branch=release/1.4.1-rc -convertmpas_branch=release/1.2.0 -EXP=GFS -RES=1024002 -YYYYMMDDHHi=2024010100 -FCST=24 -#---------------------------------------------------------------------- + +#---~--- +# If the user has set -z, we ask for confirmation before all work is deleted... +#---~--- +if ${ZERO_STATE} +then + echo -e "" + echo -e "${ORANGE}!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!${NC}" + echo -e "${ORANGE}!!! WARNING !!! WARNING !!! WARNING !!! WARNING !!!${NC}" + echo -e "${ORANGE}!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!${NC}" + echo -e "${ORANGE}==>${NC} This script is about to reset this working case." + read -p " Are you sure about this? [y|N] " proceed + proceed=$(echo ${proceed:-N} | tr [:upper:] [:lower:]) + case "${proceed}" in + y|yes) + #---~--- + # Give one last chance to avoid accidental file deletion. + #---~--- + echo -e "" + echo -e "" + echo -e "${ORANGE}==>${NC} Alright, but mind that this cannot be undone." + echo -e "${ORANGE}==>${NC} I am giving you a few seconds to cancel this script" + echo -e " in case you change your mind. Hit Ctrl+C before the countdown ends." + echo -e "" + echo -e "" + count=11 + while [[ ${count} -gt 1 ]] + do + let count=${count}-1 + echo -e "${ORANGE}==>${NC} File deletion will begin in ${count} seconds." + sleep 1 + done + /bin/rm -frv ${DATAIN} + /bin/rm -frv ${DATAOUT} + /bin/rm -frv ${SOURCES} + /bin/rm -frv ${EXECS} + /bin/rm -frv ${DIR_SCRIPTS}/run.?????????? + ;; + *) + #--- Keep files. + echo -e "" + echo -e "${GREEN}==>${NC} Keeping all files. To run MONAN, call this script again" + echo -e " without the \"-z\" option." + #---~--- + ;; + esac + + #---~--- + # We do not run the scripts when -z is set. + #---~--- + exit 0 + #---~--- +fi +#---~--- + + +#--- If INPUT_PATH is provided, replace the path in setenv.bash +if [[ "${INPUT_PATH}" != "" ]] && [[ -d "${INPUT_PATH}" ]] +then + sed -i.bck "s,^export DIRDADOS=.*,export DIRDADOS=${INPUT_PATH},g" ${SCRIPTS}/setenv.bash + /bin/rm -f ${SCRIPTS}/setenv.bash.bck +fi +#---~--- + + +#---~--- +# Make sure the grid resolution settings are valid. +#---~--- +case "${RES}" in +5898242) + echo -e "${GREEN}==>${NC} Grid resolution ${RES} (~ 10 km).\n" + ;; +2621442) + echo -e "${GREEN}==>${NC} Grid resolution ${RES} (~ 15 km).\n" + ;; +1024002) + echo -e "${GREEN}==>${NC} Grid resolution ${RES} (~ 24 km).\n" + ;; +40962) + echo -e "${GREEN}==>${NC} Grid resolution ${RES} (~ 120 km).\n" + ;; +*) + echo -e "${ORANGE}****** WARNING ******${NC} \n" + echo -e "${ORANGE}==>${NC} Provided grid resolution (${RES}) is not recognised.\n" + echo -e "${ORANGE}==>${NC} We cannot guarantee that MONAN will run fine.\n" + ;; +esac +#---~--- -# STEP 1: Installing and compiling the A-MONAN model and utility programs: -#time ${SCRIPTS}/1.install_monan.bash ${github_link} ${monan_branch} ${convertmpas_branch} -#exit +#--- Make sure VARTABLE has the leading "-v" if not empty. +if [[ "${VARTABLE}" == "" ]] +then + dv_VARTABLE="" +else + dv_VARTABLE="-v ${VARTABLE}" +fi +#---~--- -# STEP 2: Executing the pre-processing fase. Preparing all CI/CC files needed: -#time ${SCRIPTS}/2.pre_processing.bash ${EXP} ${RES} ${YYYYMMDDHHi} ${FCST} -#exit -# STEP 3: Executing the Model run: -time ${SCRIPTS}/3.run_model.bash ${EXP} ${RES} ${YYYYMMDDHHi} ${FCST} -exit +#---~--- +# Select step. +#---~--- +case ${STEP} in +0) + #---~--- + # Call the script itself four times, passing all the configuration. + #---~--- + step_now=0 + while [[ ${step_now} -lt 4 ]] + do + #--- Update step + let step_now=${step_now}+1 + #---~--- -# STEP 4: Executing the Post of Model run: -time ${SCRIPTS}/4.run_post.bash ${EXP} ${RES} ${YYYYMMDDHHi} ${FCST} -exit -time ${SCRIPTS}/make_template.bash ${EXP} ${RES} ${YYYYMMDDHHi} ${FCST} + #--- Run step + time ${0} ${OVERWRITE} ${dv_VARTABLE} -bc ${tag_or_branch_name_CONVERT_MPAS} \ + -bm ${tag_or_branch_name_MONAN} -d ${OUTPUT_DIAG_INTERVAL} -e ${EXP} -f ${FCST} \ + -gc ${github_link_CONVERT_MPAS} -gm ${github_link_MONAN} -l ${NLEV} -r ${RES} \ + -s ${step_now} -t ${YYYYMMDDHHi} + #---~--- + done + #---~--- + ;; +1) + #---~--- + # STEP 1: Install and compile MONAN and its utility programs. + #---~--- + time 1.install_monan.bash -bc ${tag_or_branch_name_CONVERT_MPAS} \ + -bm ${tag_or_branch_name_MONAN} -gc ${github_link_CONVERT_MPAS} \ + -gm ${github_link_MONAN} + #---~--- + ;; +2) + #---~--- + # STEP 2: Run the pre-processing step, and make initial/boundary conditions if needed. + #---~--- + time 2.pre_processing.bash ${OVERWRITE} -e ${EXP} -f ${FCST} -r ${RES} -t ${YYYYMMDDHHi} + #---~--- + ;; +3) + #---~--- + # STEP 3: Run the model. + #---~--- + time 3.run_model.bash ${dv_VARTABLE} -d ${OUTPUT_DIAG_INTERVAL} -e ${EXP} -f ${FCST} \ + -l ${NLEV} -r ${RES} -t ${YYYYMMDDHHi} + #---~--- + ;; +4) + #---~--- + # STEP 4: Run the post-processing step. + #---~--- + time 4.run_post.bash ${dv_VARTABLE} -d ${OUTPUT_DIAG_INTERVAL} -e ${EXP} -f ${FCST} \ + -l ${NLEV} -r ${RES} -t ${YYYYMMDDHHi} + #---~--- + ;; +esac +#---~--- diff --git a/scripts/1.install_monan.bash b/scripts/1.install_monan.bash index 5cb3f22..7aa8518 100755 --- a/scripts/1.install_monan.bash +++ b/scripts/1.install_monan.bash @@ -16,9 +16,28 @@ # #-----------------------------------------------------------------------------# -#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} -bc TAG_CONVERT_MPAS -bm TAG_MONAN -gm GIT_MONAN -gc GIT_CONVERT_MPAS" + echo "" + echo " List of **required** flags: " + echo "" + 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 " -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 "" +} +#---~--- + + #Functions -------------------------------------------------------------------# function checkout_system() { @@ -50,27 +69,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 +143,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}" #---------------------------------------------------------------------- @@ -242,7 +299,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 34458f3..56658aa 100755 --- a/scripts/2.pre_processing.bash +++ b/scripts/2.pre_processing.bash @@ -17,37 +17,101 @@ # #-----------------------------------------------------------------------------# -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} [-o] [-e EXP ] [-f FCST] [-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 " :: 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 " -o -- Overwrite static files." 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 " 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 " -t YYYYMMDDHH -- Initial time. For example if 22 Sept 2025 00 UTC, set it to:" + echo " 2025092200" + 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: +OVERWRITE=true +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 + ;; + -o) + OVERWRITE=true + shift 1 # past flag + ;; + -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. +#---~--- +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:--------------------------------------- +#--- 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 +119,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,25 +150,25 @@ 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} + echo -e "${GREEN}==>${NC} Creating static.bash for submitting init_atmosphere to create x1.${RES}.static.nc...\n" + time ./make_static.bash -e ${EXP} -f ${FCST} -r ${RES} -t ${YYYYMMDDHHi} 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 #---------------------------------------------------------------------------------- # Degrib phase:--------------------------------------------------------------------- -echo -e "${GREEN}==>${NC} Submiting Degrib...\n" -time ./make_degrib.bash ${EXP} ${RES} ${YYYYMMDDHHi} ${FCST} +echo -e "${GREEN}==>${NC} Submitting Degrib...\n" +time ./make_degrib.bash -e ${EXP} -f ${FCST} -r ${RES} -t ${YYYYMMDDHHi} #---------------------------------------------------------------------------------- # Init Atmosphere phase:------------------------------------------------------------ -echo -e "${GREEN}==>${NC} Submiting Init Atmosphere...\n" -time ./make_initatmos.bash ${EXP} ${RES} ${YYYYMMDDHHi} ${FCST} +echo -e "${GREEN}==>${NC} Submitting Init Atmosphere...\n" +time ./make_initatmos.bash -e ${EXP} -f ${FCST} -r ${RES} -t ${YYYYMMDDHHi} #---------------------------------------------------------------------------------- diff --git a/scripts/3.run_model.bash b/scripts/3.run_model.bash index 8aa323f..90817a6 100755 --- a/scripts/3.run_model.bash +++ b/scripts/3.run_model.bash @@ -15,35 +15,120 @@ # #-----------------------------------------------------------------------------# -if [ $# -ne 4 -a $# -ne 1 ] -then +#--- Function that shows usage. +function show_usage() { + echo " Usage: " + echo "" + echo " ${0} [-v VARTABLE] [-d OUTPUT_DIAG_INT] [-e EXP ] [-f FCST] [-l NLEV] \\" + echo " [-r RES] [-t YYYYMMDDHH]" echo "" - echo "Instructions: execute the command below" + echo " List of optional flags: " echo "" - echo "${0} [EXP_NAME/OP] RESOLUTION LABELI FCST" + 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 "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 " -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," + echo " set it to: 2025092200" 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: +EXP="" +RES="" +YYYYMMDDHHi="" +FCST="" +NLEV="" +OUTPUT_DIAG_INTERVAL="" +VARTABLE="" +#---~--- + + +#--- Parse arguments. +while [[ ${#} > 0 ]] +do + key="${1}" + case ${key} in + -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 + ;; + -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 + exit 2 + ;; + esac +done +#---~--- + + + +#---~--- +# Make sure all settings were provided (unless this will be to clean up runs). +#---~--- +if [[ "${EXP}" == "" ]] || [[ "${RES}" == "" ]] || + [[ "${YYYYMMDDHHi}" == "" ]] || [[ "${FCST}" == "" ]] || + [[ "${NLEV}" == "" ]] || [[ "${OUTPUT_DIAG_INTERVAL}" == "" ]] +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,32 +136,23 @@ 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-------------------------------------- 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" -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') +# 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) +t_strouthor=`echo "scale=4; (${t_stroutsec}/60)/60" | bc` #------------------------------------------------------------------------------------ # Format to HH:MM:SS t_strout (output_interval) @@ -85,26 +161,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 +220,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 @@ -153,7 +242,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} @@ -229,11 +319,11 @@ 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 - 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..48400d7 100755 --- a/scripts/4.run_post.bash +++ b/scripts/4.run_post.bash @@ -15,34 +15,119 @@ # #-----------------------------------------------------------------------------# -if [ $# -ne 4 -a $# -ne 1 ] -then +#--- Function that shows usage. +function show_usage() { + echo " Usage: " + echo "" + echo " ${0} [-v VARTABLE] [-d OUTPUT_DIAG_INT] [-e EXP ] [-f FCST] \\" + echo " [-l N_MODEL_LEV] [-r RES] [-t YYYYMMDDHH]" echo "" - echo "Instructions: execute the command below" + echo " List of optional flags: " echo "" - echo "${0} ]EXP_NAME/OP] RESOLUTION LABELI FCST" + 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 "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 " -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 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)" + 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 "" +} +#---~--- - 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: +EXP="" +RES="" +YYYYMMDDHHi="" +FCST="" +N_MODEL_LEV="" +OUTPUT_DIAG_INTERVAL="" +VARTABLE="" +#---~--- + + +#--- Parse arguments. +while [[ ${#} > 0 ]] +do + key="${1}" + case ${key} in + -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 + ;; + -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 + exit 2 + ;; + esac +done +#---~--- + +#---~--- +# Make sure all settings were provided. +#---~--- +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 + 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,75 +135,107 @@ 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-------------------------------------- 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) +# 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` #------------------------------------------------------------------------------------ # Format to HH:MM:SS t_strout (output_interval) 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: 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) + #---~--- + # 10 km, use 12 points per degree + #---~--- + NLAT=2161 + NLON=4321 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) + #---~--- + # 15 km, use 8 points per degree + #---~--- + NLAT=1441 + NLON=2881 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) + #---~--- + # 24 km, use 5 points per degree + #---~--- + NLAT=901 + NLON=1801 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) + #---~--- + # 120 km, use 1 points per degree + #---~--- + NLAT=181 + NLON=361 STARTLAT=-90.0 STARTLON=0.0 ENDLAT=90.0 ENDLON=360.0 -fi -#------------------------------------------------------- - -# NLEVS get from t_iso_levels in Registry_isobaric.xml: + #---~--- + ;; +*) + #---~--- + # 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 ] 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 @@ -127,14 +244,14 @@ 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 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} @@ -144,7 +261,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}) @@ -154,7 +271,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 @@ -163,7 +280,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)) @@ -182,7 +299,7 @@ cat > ${DIRRUN}/PostAtmos_node.${node}.sh < 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 & @@ -243,7 +360,7 @@ done -# Dependencias JobId: +# JobId dependencies: dependency="afterok" for job_id in "${jobid[@]}" do @@ -251,7 +368,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 <\033[0m Moduling environment for MONAN model...\n" . 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} @@ -39,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 0c28dde..588fe5e 100755 --- a/scripts/make_initatmos.bash +++ b/scripts/make_initatmos.bash @@ -1,32 +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: -echo "" -echo -e "\033[1;32m==>\033[0m Moduling environment for MONAN model...\n" . 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} @@ -38,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 f5e0ee0..2571d85 100755 --- a/scripts/make_static.bash +++ b/scripts/make_static.bash @@ -1,32 +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: -echo "" -echo -e "\033[1;32m==>\033[0m Moduling environment for MONAN model...\n" . 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} @@ -38,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 c71eb6a..3eef4b7 100755 --- a/scripts/make_template.bash +++ b/scripts/make_template.bash @@ -15,33 +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: -echo "" -echo -e "\033[1;32m==>\033[0m Moduling environment for MONAN model...\n" . 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} @@ -51,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 @@ -66,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} @@ -85,44 +158,91 @@ 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: 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) + #---~--- + # 10 km, use 12 points per degree + #---~--- + NLAT=2161 + NLON=4321 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) + #---~--- + # 15 km, use 8 points per degree + #---~--- + NLAT=1441 + NLON=2881 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) + #---~--- + # 24 km, use 5 points per degree + #---~--- + NLAT=901 + NLON=1801 STARTLAT=-90.0 STARTLON=0.0 ENDLAT=90.0 ENDLON=360.0 -fi -#------------------------------------------------------- + #---~--- + ;; +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 +#---~--- -# 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 < + output_interval="#OUTPUT_DIAG_INTERVAL#" > diff --git a/scripts/run_past2now.bash b/scripts/run_past2now.bash index 8b93e86..278ac5f 100755 --- a/scripts/run_past2now.bash +++ b/scripts/run_past2now.bash @@ -1,54 +1,214 @@ #!/bin/bash -yyyymmddi=20241001 -yyyymmddf=20241005 -yyyymmdd=${yyyymmddi} + + +#--- Function that shows usage. +function show_usage() { + echo " Usage: " + echo "" + echo " ${0} [-o] [-d OUTPUT_DIAG_INT] [-e EXP ] [-f00 FCST_ZERO] [-f12 FCST_TWELVE] \\" + echo " [-i INPUT_PATH] [-l NLEV] [-r RES] [-ti YYYYMMDDi] [-tf YYYYMMDDf] \\" + echo " [-v VARTABLE]" + echo "" + echo " List of optional flags: " + 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 " -f00 FCST_ZERO -- Simulation length in hours for runs starting at 00 UTC" + echo " e.g., 24 or 48." + echo " -f12 FCST_TWELVE -- Simulation length in hours for runs starting at 12 UTC" + echo " e.g., 24 or 48." + 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." + echo " -o -- Overwrite static files. If set, this will be done only" + echo " once." + 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 " -ti YYYYMMDDi -- First initial date to run the script. For example if the" + echo " first run's initial time is on 22 Sept 2025, the" + echo " argument should be 20250922." + echo " -tf YYYYMMDDf -- Last initial date to run the script. For example if the" + echo " last run's initial time is on 31 Dec 2025, the" + echo " argument should be 20251231." + 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 " 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" +INPUT_PATH="" +RES=1024002 +YYYYMMDDi=2024100100 +YYYYMMDDf=2024100500 +FCST_ZERO=240 +FCST_TWELVE=120 +NLEV=55 +OUTPUT_DIAG_INTERVAL="03:00:00" +VARTABLE="" +#---~--- + + +#--- Parse arguments. +while [[ ${#} > 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 diff --git a/scripts/setenv.bash b/scripts/setenv.bash index 793df23..1e9cbf8 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,9 +37,9 @@ 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: +# Submission variables: # PRE-Static phase: export STATIC_QUEUE="batch" @@ -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}"