From 2a8ab9770945aa11d9be075a51cf4fed8ebd8f30 Mon Sep 17 00:00:00 2001 From: "Bo.Cui" Date: Thu, 30 May 2024 12:05:10 -0400 Subject: [PATCH 1/5] Add restart capability to job JGFS_ATMOS_POSTSND --- jobs/JGFS_ATMOS_POSTSND | 4 ++ scripts/exgfs_atmos_postsnd.sh | 20 +++++++++ ush/gfs_bufr.sh | 78 ++++++++++++++++++++++++++++++++-- 3 files changed, 98 insertions(+), 4 deletions(-) diff --git a/jobs/JGFS_ATMOS_POSTSND b/jobs/JGFS_ATMOS_POSTSND index a038fca9e6..57d93638f8 100755 --- a/jobs/JGFS_ATMOS_POSTSND +++ b/jobs/JGFS_ATMOS_POSTSND @@ -29,6 +29,10 @@ YMD=${PDY} HH=${cyc} declare_from_tmpl -rx COM_ATMOS_HISTORY COM_ATMOS_BUFR \ [[ ! -d ${COM_ATMOS_GEMPAK} ]] && mkdir -p "${COM_ATMOS_GEMPAK}" [[ ! -d ${COM_ATMOS_WMO} ]] && mkdir -p "${COM_ATMOS_WMO}" +# Create a restart directory in ptmp to hold temporary output from the job JGFS_ATMOS_POSTSND + +export DATA_ATMOS_RESTART=${DATAROOT}/${RUN}.${PDY}/${cyc}/products/atmos/restart +if [[ ! -d ${DATA_ATMOS_RESTART} ]]; then mkdir -p ${DATA_ATMOS_RESTART}; fi ######################################################## # Execute the script. diff --git a/scripts/exgfs_atmos_postsnd.sh b/scripts/exgfs_atmos_postsnd.sh index 23c41157fe..f83fcb778f 100755 --- a/scripts/exgfs_atmos_postsnd.sh +++ b/scripts/exgfs_atmos_postsnd.sh @@ -18,6 +18,7 @@ # 7) 2018-07-18 Guang Ping Lou Generalize this version to other platforms # 8) 2019-10-18 Guang Ping Lou Transition to reading in NetCDF model data # 9) 2019-12-18 Guang Ping Lou generalizing to reading in NetCDF or nemsio +# 10) 2024_05_15 Bo Cui Add restart capability ################################################################ source "${USHgfs}/preamble.sh" @@ -48,9 +49,28 @@ GETDIM="${USHgfs}/getncdimlen" LEVS=$(${GETDIM} "${COM_ATMOS_HISTORY}/${RUN}.${cycle}.atmf000.${atmfm}" pfull) declare -x LEVS +# Assume there was no run before and hence this is not a RESTART for job postsnd + +export RESTART_postsnd="NO" + +# However, if there was a run before, a directory DATA_ATMOS_RESTART must exist with data in it. + +nrestarts=$(find "$DATA_ATMOS_RESTART" -maxdepth 1 -type f -name '*.bufr.logf*' | wc -l) + +echo ${nrestarts} + +if (( nrestarts == 0 )); then + echo "No restarts found in '${DATA_ATMOS_RESTART}', RESTART_postsnd='${RESTART_postsnd}'" + +else + echo "Restarts found in '${DATA_ATMOS_RESTART}', RESTART_postsnd='YES'" + export RESTART_postsnd="YES" +fi + ### Loop for the hour and wait for the sigma and surface flux file: export FSTART=$STARTHOUR # + while [ $FSTART -lt $ENDHOUR ] do export FINT=$NINT1 diff --git a/ush/gfs_bufr.sh b/ush/gfs_bufr.sh index 287365ba88..9b007c9898 100755 --- a/ush/gfs_bufr.sh +++ b/ush/gfs_bufr.sh @@ -18,6 +18,7 @@ # 2018-05-30 Guang Ping Lou: Make sure all files are available. # 2019-10-10 Guang Ping Lou: Read in NetCDF files # 2024-03-03 Bo Cui: Add options to use different bufr table for different resolution NetCDF files +# 2024_05_15 Bo Cui: Add restart capability # echo "History: February 2003 - First implementation of this utility script" # source "${USHgfs}/preamble.sh" @@ -88,19 +89,88 @@ case "${CASE}" in ${NLN} "${PARMgfs}/product/bufr_ij9km.txt" fort.7 ;; *) - echo "WARNING: No bufr table for this resolution, using the one for C768" - ${NLN} "${PARMgfs}/product/bufr_ij13km.txt" fort.7 + echo "FATAL ERROR: Unrecognized bufr_ij*km.txt For CASE ${CASE}, ABORT!" + exit 1 ;; esac -${APRUN_POSTSND} "${EXECgfs}/${pgm}" < gfsparm > "out_gfs_bufr_${FEND}" -export err=$? + +if [[ ${RESTART_postsnd} == "YES" ]]; then + + if [ -f "${DATA_ATMOS_RESTART}/${RUN}.${cycle}.bufr.logf${FEND}.${logfm}" ]; then + + echo "Copy job postsnd files from restart directory" + + cp -p ${DATA_ATMOS_RESTART}/${RUN}.${cycle}.bufr.logf${FEND}.${logfm} . + while IFS= read -r fortname; do +# echo "Copy job postsnd files from restart directory: $fortname" + cp -p ${DATA_ATMOS_RESTART}/${RUN}.${cycle}.bufr_${fortname} ${fortname} + done < ${RUN}.${cycle}.bufr.logf${FEND}.${logfm} + err=0 + + if [ ${FEND} -eq ${ENDHOUR} ]; then + ${APRUN_POSTSND} "${EXECgfs}/${pgm}" < gfsparm > "out_gfs_bufr_${FEND}" + export err=$? + fi + + else + + echo "No more job postsnd restart file found in '${DATA_ATMOS_RESTART}'" + export RESTART_postsnd="NO" + echo "set RESTART_postsnd='${RESTART_postsnd}'" + ${APRUN_POSTSND} "${EXECgfs}/${pgm}" < gfsparm > "out_gfs_bufr_${FEND}" + export err=$? + fi + +else + + ${APRUN_POSTSND} "${EXECgfs}/${pgm}" < gfsparm > "out_gfs_bufr_${FEND}" + export err=$? +fi if [ $err -ne 0 ]; then echo "GFS postsnd job error, Please check files " echo "${COM_ATMOS_HISTORY}/${RUN}.${cycle}.atmf${hh2}.${atmfm}" echo "${COM_ATMOS_HISTORY}/${RUN}.${cycle}.sfcf${hh2}.${atmfm}" err_chk + +else + + # Count the number of restart files + nrestarts=$(find ./ -maxdepth 1 -type f -name 'fort.*' | wc -l) + echo "Number of restart fort.* files found: ${nrestarts}" + + # Check if there are restart files + if [ "$nrestarts" -gt 0 ]; then + echo "Copying GFS postsnd files to restart directory..." + + # Exclude specific files and save the rest to a log file + #ls fort.* | grep -v -e 'fort\.1' -e 'fort\.7' -e 'fort\.8' > "${RUN}.${cycle}.bufr.logf${FEND}.${logfm}" + + # Initialize an empty array to store fort file names + files=() + + # Loop through files in the directory + for file in fort.*; do + # Check if the file is not fort.1 or fort.7 or fort.8 + if [[ $file != "fort.1" && $file != "fort.7" && $file != "fort.8" ]]; then + files+=("$file") + fi + done + + # Write the list of fort files to the log file + printf "%s\n" "${files[@]}" > "${RUN}.${cycle}.bufr.logf${FEND}.${logfm}" + + # Copy each restart file to the restart directory + while IFS= read -r fortname; do + # echo "Copying restart file: $fortname" + cp -p "${fortname}" "${DATA_ATMOS_RESTART}/${RUN}.${cycle}.bufr_${fortname}" + done < "${RUN}.${cycle}.bufr.logf${FEND}.${logfm}" + fi + + # Copy the log file to the restart directory + cp -p "${RUN}.${cycle}.bufr.logf${FEND}.${logfm}" "${DATA_ATMOS_RESTART}/" + fi exit ${err} From b684e0c7fce556ac553713bd688e1f3d30478fd7 Mon Sep 17 00:00:00 2001 From: "Bo.Cui" Date: Thu, 30 May 2024 15:22:32 -0400 Subject: [PATCH 2/5] Update job JGFS_ATMOS_POSTSND package --- jobs/JGFS_ATMOS_POSTSND | 2 +- scripts/exgfs_atmos_postsnd.sh | 7 +++++-- ush/gfs_bufr.sh | 24 +++++++++++++++--------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/jobs/JGFS_ATMOS_POSTSND b/jobs/JGFS_ATMOS_POSTSND index 57d93638f8..2d9c3a8196 100755 --- a/jobs/JGFS_ATMOS_POSTSND +++ b/jobs/JGFS_ATMOS_POSTSND @@ -32,7 +32,7 @@ YMD=${PDY} HH=${cyc} declare_from_tmpl -rx COM_ATMOS_HISTORY COM_ATMOS_BUFR \ # Create a restart directory in ptmp to hold temporary output from the job JGFS_ATMOS_POSTSND export DATA_ATMOS_RESTART=${DATAROOT}/${RUN}.${PDY}/${cyc}/products/atmos/restart -if [[ ! -d ${DATA_ATMOS_RESTART} ]]; then mkdir -p ${DATA_ATMOS_RESTART}; fi +if [[ ! -d ${DATA_ATMOS_RESTART} ]]; then mkdir -p "${DATA_ATMOS_RESTART}"; fi ######################################################## # Execute the script. diff --git a/scripts/exgfs_atmos_postsnd.sh b/scripts/exgfs_atmos_postsnd.sh index f83fcb778f..37f399b273 100755 --- a/scripts/exgfs_atmos_postsnd.sh +++ b/scripts/exgfs_atmos_postsnd.sh @@ -57,7 +57,7 @@ export RESTART_postsnd="NO" nrestarts=$(find "$DATA_ATMOS_RESTART" -maxdepth 1 -type f -name '*.bufr.logf*' | wc -l) -echo ${nrestarts} +echo "${nrestarts}" if (( nrestarts == 0 )); then echo "No restarts found in '${DATA_ATMOS_RESTART}', RESTART_postsnd='${RESTART_postsnd}'" @@ -118,7 +118,10 @@ done ############################################################## cd "${COM_ATMOS_BUFR}" || exit 2 tar -cf - . | /usr/bin/gzip > "${RUN}.${cycle}.bufrsnd.tar.gz" -cd "${DATA}" || exit 2 +cd "${DATA}" +if [ $? -ne 0 ]; then + exit 2 +fi ######################################## # Send the single tar file to OSO diff --git a/ush/gfs_bufr.sh b/ush/gfs_bufr.sh index 9b007c9898..21a5060e8f 100755 --- a/ush/gfs_bufr.sh +++ b/ush/gfs_bufr.sh @@ -101,14 +101,14 @@ if [[ ${RESTART_postsnd} == "YES" ]]; then echo "Copy job postsnd files from restart directory" - cp -p ${DATA_ATMOS_RESTART}/${RUN}.${cycle}.bufr.logf${FEND}.${logfm} . + cp -p "${DATA_ATMOS_RESTART}/${RUN}.${cycle}.bufr.logf${FEND}.${logfm}" . while IFS= read -r fortname; do # echo "Copy job postsnd files from restart directory: $fortname" - cp -p ${DATA_ATMOS_RESTART}/${RUN}.${cycle}.bufr_${fortname} ${fortname} - done < ${RUN}.${cycle}.bufr.logf${FEND}.${logfm} + cp -p "${DATA_ATMOS_RESTART}/${RUN}.${cycle}.bufr_${fortname}" ${fortname} + done < "${RUN}.${cycle}.bufr.logf${FEND}.${logfm}" err=0 - if [ ${FEND} -eq ${ENDHOUR} ]; then + if [[ ${FEND} -eq ${ENDHOUR} ]]; then ${APRUN_POSTSND} "${EXECgfs}/${pgm}" < gfsparm > "out_gfs_bufr_${FEND}" export err=$? fi @@ -128,7 +128,7 @@ else export err=$? fi -if [ $err -ne 0 ]; then +if [[ $err -ne 0 ]]; then echo "GFS postsnd job error, Please check files " echo "${COM_ATMOS_HISTORY}/${RUN}.${cycle}.atmf${hh2}.${atmfm}" echo "${COM_ATMOS_HISTORY}/${RUN}.${cycle}.sfcf${hh2}.${atmfm}" @@ -138,10 +138,16 @@ else # Count the number of restart files nrestarts=$(find ./ -maxdepth 1 -type f -name 'fort.*' | wc -l) - echo "Number of restart fort.* files found: ${nrestarts}" + find_exit_code=$? + if [ $find_exit_code -ne 0 ]; then + # handle the error, set the number of restart file is 0 + nrestarts=0 + else + echo "Number of restart fort.* files found: ${nrestarts}" + fi # Check if there are restart files - if [ "$nrestarts" -gt 0 ]; then + if [[ "${nrestarts}" -gt 0 ]]; then echo "Copying GFS postsnd files to restart directory..." # Exclude specific files and save the rest to a log file @@ -153,8 +159,8 @@ else # Loop through files in the directory for file in fort.*; do # Check if the file is not fort.1 or fort.7 or fort.8 - if [[ $file != "fort.1" && $file != "fort.7" && $file != "fort.8" ]]; then - files+=("$file") + if [[ ${file} != "fort.1" && $file != "fort.7" && $file != "fort.8" ]]; then + files+=("${file}") fi done From cb1ce3a1168eb671bfb08b83b6247e67f7dca035 Mon Sep 17 00:00:00 2001 From: "Bo.Cui" Date: Fri, 31 May 2024 12:15:40 -0400 Subject: [PATCH 3/5] Update job JGFS_ATMOS_POSTSND package --- scripts/exgfs_atmos_postsnd.sh | 9 +++------ ush/gfs_bufr.sh | 15 +++++---------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/scripts/exgfs_atmos_postsnd.sh b/scripts/exgfs_atmos_postsnd.sh index 37f399b273..62622fb517 100755 --- a/scripts/exgfs_atmos_postsnd.sh +++ b/scripts/exgfs_atmos_postsnd.sh @@ -55,7 +55,7 @@ export RESTART_postsnd="NO" # However, if there was a run before, a directory DATA_ATMOS_RESTART must exist with data in it. -nrestarts=$(find "$DATA_ATMOS_RESTART" -maxdepth 1 -type f -name '*.bufr.logf*' | wc -l) +nrestarts=$(find "$DATA_ATMOS_RESTART" -maxdepth 1 -type f -name '*.bufr.logf*' | wc -l || true) echo "${nrestarts}" @@ -118,10 +118,7 @@ done ############################################################## cd "${COM_ATMOS_BUFR}" || exit 2 tar -cf - . | /usr/bin/gzip > "${RUN}.${cycle}.bufrsnd.tar.gz" -cd "${DATA}" -if [ $? -ne 0 ]; then - exit 2 -fi +cd "${DATA}" || exit ######################################## # Send the single tar file to OSO @@ -136,7 +133,7 @@ fi # add appropriate WMO Headers. ######################################## rm -rf poe_col -for (( m = 1; m <= NUM_SND_COLLECTIVES ; m++ )); do +for (( m = 1; m <10 ; m++ )); do echo "sh ${USHgfs}/gfs_sndp.sh ${m} " >> poe_col done diff --git a/ush/gfs_bufr.sh b/ush/gfs_bufr.sh index 21a5060e8f..5315233c43 100755 --- a/ush/gfs_bufr.sh +++ b/ush/gfs_bufr.sh @@ -104,7 +104,7 @@ if [[ ${RESTART_postsnd} == "YES" ]]; then cp -p "${DATA_ATMOS_RESTART}/${RUN}.${cycle}.bufr.logf${FEND}.${logfm}" . while IFS= read -r fortname; do # echo "Copy job postsnd files from restart directory: $fortname" - cp -p "${DATA_ATMOS_RESTART}/${RUN}.${cycle}.bufr_${fortname}" ${fortname} + cp -p "${DATA_ATMOS_RESTART}/${RUN}.${cycle}.bufr_${fortname}" "${fortname}" done < "${RUN}.${cycle}.bufr.logf${FEND}.${logfm}" err=0 @@ -137,14 +137,9 @@ if [[ $err -ne 0 ]]; then else # Count the number of restart files - nrestarts=$(find ./ -maxdepth 1 -type f -name 'fort.*' | wc -l) - find_exit_code=$? - if [ $find_exit_code -ne 0 ]; then - # handle the error, set the number of restart file is 0 - nrestarts=0 - else - echo "Number of restart fort.* files found: ${nrestarts}" - fi + nrestarts=0 + nrestarts=$(find ./ -maxdepth 1 -type f -name 'fort.*' | wc -l || true) + echo "Number of restart fort.* files found: ${nrestarts}" # Check if there are restart files if [[ "${nrestarts}" -gt 0 ]]; then @@ -159,7 +154,7 @@ else # Loop through files in the directory for file in fort.*; do # Check if the file is not fort.1 or fort.7 or fort.8 - if [[ ${file} != "fort.1" && $file != "fort.7" && $file != "fort.8" ]]; then + if [[ "${file}" != "fort.1" && "${file}" != "fort.7" && "${file}" != "fort.8" ]]; then files+=("${file}") fi done From c0248c7ca1f844aa35fdce684d5328930f24528a Mon Sep 17 00:00:00 2001 From: "Bo.Cui" Date: Fri, 31 May 2024 13:29:44 -0400 Subject: [PATCH 4/5] Update job JGFS_ATMOS_POSTSND package --- scripts/exgfs_atmos_postsnd.sh | 8 ++++---- ush/gfs_bufr.sh | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/exgfs_atmos_postsnd.sh b/scripts/exgfs_atmos_postsnd.sh index 62622fb517..28905dfa70 100755 --- a/scripts/exgfs_atmos_postsnd.sh +++ b/scripts/exgfs_atmos_postsnd.sh @@ -105,12 +105,12 @@ export FINT=$NINT1 done ## 1-hourly output before $NEND1, 3-hourly output after - if [ $FEND -gt $NEND1 ]; then - export FINT=$NINT3 + if [[ "${FEND}" -gt "${NEND1}" ]]; then + export FINT="${NINT3}" fi - ${USHgfs}/gfs_bufr.sh + "${USHgfs}/gfs_bufr.sh" - export FSTART=$FEND + export FSTART="${FEND}" done ############################################################## diff --git a/ush/gfs_bufr.sh b/ush/gfs_bufr.sh index 5315233c43..45fdbb1d4d 100755 --- a/ush/gfs_bufr.sh +++ b/ush/gfs_bufr.sh @@ -103,7 +103,6 @@ if [[ ${RESTART_postsnd} == "YES" ]]; then cp -p "${DATA_ATMOS_RESTART}/${RUN}.${cycle}.bufr.logf${FEND}.${logfm}" . while IFS= read -r fortname; do -# echo "Copy job postsnd files from restart directory: $fortname" cp -p "${DATA_ATMOS_RESTART}/${RUN}.${cycle}.bufr_${fortname}" "${fortname}" done < "${RUN}.${cycle}.bufr.logf${FEND}.${logfm}" err=0 From 5df733f071b6193185af10d696421411dadab310 Mon Sep 17 00:00:00 2001 From: "Bo.Cui" Date: Fri, 31 May 2024 14:01:26 -0400 Subject: [PATCH 5/5] update exgfs_atmos_postsnd.sh to use NUM_SND_COLLECTIVES --- scripts/exgfs_atmos_postsnd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/exgfs_atmos_postsnd.sh b/scripts/exgfs_atmos_postsnd.sh index 28905dfa70..ccc9e6990e 100755 --- a/scripts/exgfs_atmos_postsnd.sh +++ b/scripts/exgfs_atmos_postsnd.sh @@ -133,7 +133,7 @@ fi # add appropriate WMO Headers. ######################################## rm -rf poe_col -for (( m = 1; m <10 ; m++ )); do +for (( m = 1; m <= NUM_SND_COLLECTIVES ; m++ )); do echo "sh ${USHgfs}/gfs_sndp.sh ${m} " >> poe_col done