diff --git a/.shellcheckrc b/.shellcheckrc index 1c80a97072..45e13c2e04 100644 --- a/.shellcheckrc +++ b/.shellcheckrc @@ -1,2 +1,13 @@ # Global settings for Spellcheck (https://github.com/koalaman/shellcheck) enable=all + +external-sources=false + +# Disable variable referenced but not assigned +disable=SC2154 + +# Disable following non-constant source +disable=SC1090 + +# Disable non-existent binary +disable=SC1091 diff --git a/jobs/JGLOBAL_ATMOS_NCEPPOST b/jobs/JGLOBAL_ATMOS_POST similarity index 71% rename from jobs/JGLOBAL_ATMOS_NCEPPOST rename to jobs/JGLOBAL_ATMOS_POST index 56d6ca602e..ab75918aa6 100755 --- a/jobs/JGLOBAL_ATMOS_NCEPPOST +++ b/jobs/JGLOBAL_ATMOS_POST @@ -1,6 +1,6 @@ #! /usr/bin/env bash -source "$HOMEgfs/ush/preamble.sh" +source "${HOMEgfs}/ush/preamble.sh" export RUN_ENVIR=${RUN_ENVIR:-"nco"} @@ -8,31 +8,31 @@ export RUN_ENVIR=${RUN_ENVIR:-"nco"} # Source relevant config files ############################# configs="base post" -export EXPDIR=${EXPDIR:-$HOMEgfs/parm/config} -config_path=${EXPDIR:-$PACKAGEROOT/gfs.${gfs_ver}/parm/config} -for config in $configs; do - . $config_path/config.$config +export EXPDIR=${EXPDIR:-${HOMEgfs}/parm/config} +config_path=${EXPDIR:-${PACKAGEROOT}/gfs.${gfs_ver}/parm/config} +for config in ${configs}; do + . "${config_path}/config.${config}" status=$? - [[ $status -ne 0 ]] && exit $status + (( status != 0 )) && exit "${status}" done ########################################## # Source machine runtime environment ########################################## -. $HOMEgfs/env/${machine}.env post +. "${HOMEgfs}/env/${machine}.env" post status=$? -[[ $status -ne 0 ]] && exit $status +(( status != 0 )) && exit "${status}" ############################################## # Obtain unique process id (pid) and make temp directory ############################################## export pid=${pid:-$$} -export outid=${outid:-"LL$job"} -export DATA=${DATA:-${DATAROOT}/${jobid:?}} -mkdir -p $DATA -cd $DATA +export outid=${outid:-"LL${job}"} +export DATA=${DATA:-${DATAROOT}/${jobid}} +mkdir -p "${DATA}" +cd "${DATA}" || exit 1 ############################################## @@ -68,22 +68,24 @@ export COMPONENT=${COMPONENT:-atmos} ############################################## # Begin JOB SPECIFIC work ############################################## -export APRUNP=${APRUN:-$APRUN_NP} +export APRUNP=${APRUN:-${APRUN_NP}} export RERUN=${RERUN:-NO} -export HOMECRTM=${HOMECRTM:-${PACKAGEROOT:?}/lib/crtm/${crtm_ver:?}} +export HOMECRTM=${HOMECRTM:-${PACKAGEROOT}/lib/crtm/${crtm_ver}} export FIXCRTM=${CRTM_FIX:-${HOMECRTM}/fix} -export PARMpost=${PARMpost:-$HOMEgfs/parm/post} +export PARMpost=${PARMpost:-${HOMEgfs}/parm/post} export INLINE_POST=${WRITE_DOPOST:-".false."} -export COMIN=${COMIN:-$ROTDIR/$RUN.$PDY/$cyc/$COMPONENT} -export COMOUT=${COMOUT:-$ROTDIR/$RUN.$PDY/$cyc/$COMPONENT} +export COMIN=${COMIN:-${ROTDIR}/${RUN}.${PDY}/${cyc}/${COMPONENT}} +export COMOUT=${COMOUT:-${ROTDIR}/${RUN}.${PDY}/${cyc}/${COMPONENT}} -[[ ! -d $COMOUT ]] && mkdir -m 775 -p $COMOUT +# shellcheck disable=SC2174 +[[ ! -d "${COMOUT}" ]] && mkdir -m 775 -p "${COMOUT}" +# shellcheck disable= -if [ $RUN = gfs ];then +if [ "${RUN}" = gfs ];then export FHOUT_PGB=${FHOUT_GFS:-3} #Output frequency of gfs pgb file at 1.0 and 0.5 deg. fi -if [ $RUN = gdas ]; then +if [ "${RUN}" = gdas ]; then export IGEN_GFS="gfs_avn" export IGEN_ANL="anal_gfs" export IGEN_FCST="gfs_avn" @@ -91,7 +93,7 @@ if [ $RUN = gdas ]; then export FHOUT_PGB=${FHOUT:-1} #Output frequency of gfs pgb file at 1.0 and 0.5 deg. fi -if [ $GRIBVERSION = grib2 ]; then +if [ "${GRIBVERSION}" = grib2 ]; then export IGEN_ANL="anal_gfs" export IGEN_FCST="gfs_avn" export IGEN_GFS="gfs_avn" @@ -100,7 +102,7 @@ fi ####################################### # Specify Restart File Name to Key Off ####################################### -export restart_file=$COMIN/${RUN}.t${cyc}z.logf +export restart_file=${COMIN}/${RUN}.t${cyc}z.logf #################################### # Specify Timeout Behavior of Post @@ -117,9 +119,9 @@ export SLEEP_INT=5 ############################################################### # Run relevant exglobal script -$SCRgfs/ex${RUN}_atmos_nceppost.sh +"${SCRgfs}/ex${RUN}_atmos_post.sh" status=$? -[[ $status -ne 0 ]] && exit $status +(( status != 0 )) && exit "${status}" ############################################## # End JOB SPECIFIC work @@ -128,15 +130,15 @@ status=$? ############################################## # Final processing ############################################## -if [ -e "$pgmout" ]; then - cat $pgmout +if [ -e "${pgmout}" ]; then + cat "${pgmout}" fi ########################################## # Remove the Temporary working directory ########################################## -cd $DATAROOT -[[ $KEEPDATA = "NO" ]] && rm -rf $DATA +cd "${DATAROOT}" || exit 1 +[[ "${KEEPDATA:-NO}" = "NO" ]] && rm -rf "${DATA}" exit 0 diff --git a/jobs/rocoto/post.sh b/jobs/rocoto/post.sh index b32e8c511d..a6dfb0fbaf 100755 --- a/jobs/rocoto/post.sh +++ b/jobs/rocoto/post.sh @@ -27,7 +27,7 @@ fi #--------------------------------------------------------------- for fhr in $fhrlst; do export post_times=$fhr - $HOMEgfs/jobs/JGLOBAL_ATMOS_NCEPPOST + $HOMEgfs/jobs/JGLOBAL_ATMOS_POST status=$? [[ $status -ne 0 ]] && exit $status done diff --git a/parm/config/config.post b/parm/config/config.post index a545f0fafc..cdea64e2a3 100755 --- a/parm/config/config.post +++ b/parm/config/config.post @@ -19,13 +19,13 @@ if [ $OUTPUT_FILE = "netcdf" ]; then export MODEL_OUT_FORM=netcdfpara fi -# Post driver job that calls gfs_nceppost.sh and downstream jobs -export POSTJJOBSH="$HOMEpost/jobs/JGLOBAL_NCEPPOST" +# Post driver job that calls gfs_post.sh and downstream jobs +export POSTJJOBSH="$HOMEpost/jobs/JGLOBAL_POST" export GFSDOWNSH="$HOMEpost/ush/fv3gfs_downstream_nems.sh" export GFSDWNSH="$HOMEpost/ush/fv3gfs_dwn_nems.sh" -export POSTGPSH="$HOMEpost/ush/gfs_nceppost.sh" -export POSTGPEXEC="$HOMEpost/exec/gfs_ncep_post" +export POSTGPSH="$HOMEpost/ush/gfs_post.sh" +export POSTGPEXEC="$HOMEpost/exec/upp.x" export GOESF=NO # goes image export FLXF=YES # grib2 flux file written by post diff --git a/scripts/exgdas_atmos_nceppost.sh b/scripts/exgdas_atmos_post.sh similarity index 56% rename from scripts/exgdas_atmos_nceppost.sh rename to scripts/exgdas_atmos_post.sh index 005911db6a..98f109c29a 100755 --- a/scripts/exgdas_atmos_nceppost.sh +++ b/scripts/exgdas_atmos_post.sh @@ -24,15 +24,15 @@ # echo "-----------------------------------------------------" ##################################################################### -source "$HOMEgfs/ush/preamble.sh" +source "${HOMEgfs}/ush/preamble.sh" -cd $DATA +cd "${DATA}" || exit 1 -export POSTGPSH=${POSTGPSH:-$USHgfs/gfs_nceppost.sh} -export GFSDOWNSH=${GFSDOWNSH:-$USHgfs/fv3gfs_downstream_nems.sh} -export GFSDWNSH=${GFSDWNSH:-$USHgfs/fv3gfs_dwn_nems.sh} -export TRIMRH=${TRIMRH:-$USHgfs/trim_rh.sh} -export MODICEC=${MODICEC:-$USHgfs/mod_icec.sh} +export POSTGPSH=${POSTGPSH:-${USHgfs}/gfs_post.sh} +export GFSDOWNSH=${GFSDOWNSH:-${USHgfs}/fv3gfs_downstream_nems.sh} +export GFSDWNSH=${GFSDWNSH:-${USHgfs}/fv3gfs_dwn_nems.sh} +export TRIMRH=${TRIMRH:-${USHgfs}/trim_rh.sh} +export MODICEC=${MODICEC:-${USHgfs}/mod_icec.sh} export INLINE_POST=${INLINE_POST:-".false."} ############################################################ @@ -52,8 +52,8 @@ export OUTTYP=${OUTTYP:-4} export OUTPUT_FILE=${OUTPUT_FILE:-"nemsio"} export TCYC=${TCYC:-".t${cyc}z."} export PREFIX=${PREFIX:-${RUN}${TCYC}} -if [ $OUTTYP -eq 4 ] ; then - if [ $OUTPUT_FILE = "netcdf" ]; then +if (( OUTTYP == 4 )) ; then + if [ "${OUTPUT_FILE}" = "netcdf" ]; then export SUFFIX=".nc" else export SUFFIX=".nemsio" @@ -77,15 +77,16 @@ export IDRT=${IDRT:-0} # IDRT=0 is setting for outputting grib files on lat/lon # Post Analysis Files before starting the Forecast Post ############################################################ # Chuang: modify to process analysis when post_times is 00 -export stime=$(echo $post_times | cut -c1-3) -if [ $OUTTYP -eq 4 ] ; then - export loganl=$COMIN/${PREFIX}atmanl${SUFFIX} +stime="$(echo "${post_times}" | cut -c1-3)" +export stime +if (( OUTTYP == 4 )) ; then + export loganl="${COMIN}/${PREFIX}atmanl${SUFFIX}" else - export loganl=$COMIN/${PREFIX}sanl + export loganl="${COMIN}/${PREFIX}sanl" fi -if [ ${stime} = "anl" ]; then - if [ -f $loganl ]; then +if [ "${stime}" = "anl" ]; then + if [ -f "${loganl}" ]; then # add new environmental variables for running new ncep post # Validation date @@ -105,63 +106,63 @@ if [ ${stime} = "anl" ]; then # specify smaller control file for GDAS because GDAS does not # produce flux file, the default will be /nwprod/parm/gfs_cntrl.parm - if [ $GRIBVERSION = 'grib2' ]; then + if [ "${GRIBVERSION}" = 'grib2' ]; then export POSTGRB2TBL=${POSTGRB2TBL:-${g2tmpl_ROOT}/share/params_grib2_tbl_new} - export PostFlatFile=${PostFlatFile:-$PARMpost/postxconfig-NT-GFS-ANL.txt} - export CTLFILE=$PARMpost/postcntrl_gfs_anl.xml + export PostFlatFile=${PostFlatFile:-${PARMpost}/postxconfig-NT-GFS-ANL.txt} + export CTLFILE=${PARMpost}/postcntrl_gfs_anl.xml fi [[ -f flxfile ]] && rm flxfile ; [[ -f nemsfile ]] && rm nemsfile - if [ $OUTTYP -eq 4 ] ; then - ln -fs $COMIN/${PREFIX}atmanl${SUFFIX} nemsfile + if (( OUTTYP == 4 )) ; then + ln -fs "${COMIN}/${PREFIX}atmanl${SUFFIX}" nemsfile export NEMSINP=nemsfile - ln -fs $COMIN/${PREFIX}sfcanl${SUFFIX} flxfile + ln -fs "${COMIN}/${PREFIX}sfcanl${SUFFIX}" flxfile export FLXINP=flxfile fi export PGBOUT=pgbfile export PGIOUT=pgifile export PGBOUT2=pgbfile.grib2 export PGIOUT2=pgifile.grib2.idx - export IGEN=$IGEN_ANL + export IGEN="${IGEN_ANL}" export FILTER=0 # specify fhr even for analysis because postgp uses it # export fhr=00 - $POSTGPSH + ${POSTGPSH} export err=$?; err_chk - if [ $GRIBVERSION = 'grib2' ]; then - mv $PGBOUT $PGBOUT2 + if [ "${GRIBVERSION}" = 'grib2' ]; then + mv "${PGBOUT}" "${PGBOUT2}" #Proces pgb files export FH=-1 export downset=${downset:-1} - $GFSDOWNSH + ${GFSDOWNSH} export err=$?; err_chk export fhr3=anl fi - if [ $SENDCOM = 'YES' ]; then + if [ "${SENDCOM}" = 'YES' ]; then export fhr3=anl - if [ $GRIBVERSION = 'grib2' ]; then + if [ "${GRIBVERSION}" = 'grib2' ]; then MASTERANL=${PREFIX}master.grb2${fhr3} ##########XXW Accord to Boi, fortran index should use *if${fhr}, wgrib index use .idx #MASTERANLIDX=${RUN}.${cycle}.master.grb2${fhr3}.idx MASTERANLIDX=${PREFIX}master.grb2i${fhr3} - cp $PGBOUT2 $COMOUT/${MASTERANL} - $GRB2INDEX $PGBOUT2 $COMOUT/${MASTERANLIDX} + cp "${PGBOUT2}" "${COMOUT}/${MASTERANL}" + ${GRB2INDEX} "${PGBOUT2}" "${COMOUT}/${MASTERANLIDX}" fi - if [ $SENDDBN = 'YES' ]; then - run=$(echo $RUN | tr '[a-z]' '[A-Z]') - if [ $GRIBVERSION = 'grib2' ]; then - $DBNROOT/bin/dbn_alert MODEL ${run}_MSC_sfcanl $job $COMOUT/${PREFIX}sfc${fhr3}${SUFFIX} - $DBNROOT/bin/dbn_alert MODEL ${run}_SA $job $COMIN/${PREFIX}atm${fhr3}${SUFFIX} - $DBNROOT/bin/dbn_alert MODEL GDAS_PGA_GB2 $job $COMOUT/${PREFIX}pgrb2.1p00.${fhr3} - $DBNROOT/bin/dbn_alert MODEL GDAS_PGA_GB2_WIDX $job $COMOUT/${PREFIX}pgrb2.1p00.${fhr3}.idx + if [ "${SENDDBN}" = 'YES' ]; then + run="$(echo "${RUN}" | tr '[:lower:]' '[:upper:]')" + if [ "${GRIBVERSION}" = 'grib2' ]; then + "${DBNROOT}/bin/dbn_alert" MODEL "${run}_MSC_sfcanl" "${job}" "${COMOUT}/${PREFIX}sfc${fhr3}${SUFFIX}" + "${DBNROOT}/bin/dbn_alert" MODEL "${run}_SA" "${job}" "${COMIN}/${PREFIX}atm${fhr3}${SUFFIX}" + "${DBNROOT}/bin/dbn_alert" MODEL "GDAS_PGA_GB2" "${job}" "${COMOUT}/${PREFIX}pgrb2.1p00.${fhr3}" + "${DBNROOT}/bin/dbn_alert" MODEL "GDAS_PGA_GB2_WIDX" "${job}" "${COMOUT}/${PREFIX}pgrb2.1p00.${fhr3}.idx" fi fi fi @@ -173,32 +174,32 @@ if [ ${stime} = "anl" ]; then err_chk fi else ## not_anl if_stimes - SLEEP_LOOP_MAX=$(expr $SLEEP_TIME / $SLEEP_INT) + SLEEP_LOOP_MAX=$(( SLEEP_TIME / SLEEP_INT )) ############################################################ # Loop Through the Post Forecast Files ############################################################ - for fhr in $post_times; do + for fhr in ${post_times}; do ############################### # Start Looping for the # existence of the restart files ############################### export pgm="postcheck" ic=1 - while [ $ic -le $SLEEP_LOOP_MAX ]; do - if [ -f ${restart_file}${fhr}.txt ]; then + while (( ic <= SLEEP_LOOP_MAX )); do + if [ -f "${restart_file}${fhr}.txt" ]; then break else - ic=$(expr $ic + 1) - sleep $SLEEP_INT + ic=$(( ic + 1 )) + sleep "${SLEEP_INT}" fi ############################### # If we reach this point assume # fcst job never reached restart # period and error exit ############################### - if [ $ic -eq $SLEEP_LOOP_MAX ]; then + if (( ic == SLEEP_LOOP_MAX )); then echo " *** FATAL ERROR: No model output in nemsio for f${fhr} " export err=9 err_chk @@ -211,51 +212,55 @@ else ## not_anl if_stimes ############################### [[ -f flxfile ]] && rm flxfile [[ -f nemsfile ]] && rm nemsfile - if [ $OUTTYP -eq 4 ] ; then - ln -sf $COMIN/${PREFIX}atmf$fhr${SUFFIX} nemsfile + if (( OUTTYP == 4 )) ; then + ln -sf "${COMIN}/${PREFIX}atmf${fhr}${SUFFIX}" nemsfile export NEMSINP=nemsfile - ln -sf $COMIN/${PREFIX}sfcf$fhr${SUFFIX} flxfile + ln -sf "${COMIN}/${PREFIX}sfcf${fhr}${SUFFIX}" flxfile export FLXINP=flxfile fi - if [ $fhr -gt 0 ]; then - export IGEN=$IGEN_FCST + if (( fhr > 0 )); then + export IGEN=${IGEN_FCST} else - export IGEN=$IGEN_ANL + export IGEN=${IGEN_ANL} fi # add new environmental variables for running new ncep post # Validation date - export VDATE=$(${NDATE} +${fhr} ${PDY}${cyc}) + # No shellcheck, NDATE is not a typo + # shellcheck disable=SC2153 + VDATE="$(${NDATE} "+${fhr}" "${PDY}${cyc}")" + # shellcheck disable= + export VDATE # set to 3 to output lat/lon grid export OUTTYP=${OUTTYP:-4} - if [ $GRIBVERSION = 'grib2' ]; then - export POSTGRB2TBL=${POSTGRB2TBL:-${g2tmpl_ROOT}/share/params_grib2_tbl_new} - export PostFlatFile=$PARMpost/postxconfig-NT-GFS.txt - if [ $RUN = gfs ]; then - export IGEN=$IGEN_GFS - if [ $fhr -gt 0 ]; then export IGEN=$IGEN_FCST ; fi + if [ "${GRIBVERSION}" = 'grib2' ]; then + export POSTGRB2TBL="${POSTGRB2TBL:-${g2tmpl_ROOT}/share/params_grib2_tbl_new}" + export PostFlatFile="${PARMpost}/postxconfig-NT-GFS.txt" + if [ "${RUN}" = gfs ]; then + export IGEN="${IGEN_GFS}" + if (( fhr > 0 )); then export IGEN="${IGEN_FCST}" ; fi else - export IGEN=$IGEN_GDAS_ANL - if [ $fhr -gt 0 ]; then export IGEN=$IGEN_FCST ; fi + export IGEN="${IGEN_GDAS_ANL}" + if (( fhr > 0 )); then export IGEN="${IGEN_FCST}" ; fi fi - if [[ $RUN = gfs ]]; then - if [ $fhr -eq 0 ]; then - export PostFlatFile=$PARMpost/postxconfig-NT-GFS-F00.txt - export CTLFILE=$PARMpost/postcntrl_gfs_f00.xml + if [[ "${RUN}" = gfs ]]; then + if (( fhr == 0 )); then + export PostFlatFile="${PARMpost}/postxconfig-NT-GFS-F00.txt" + export CTLFILE="${PARMpost}/postcntrl_gfs_f00.xml" else - export CTLFILE=${CTLFILEGFS:-$PARMpost/postcntrl_gfs.xml} + export CTLFILE="${CTLFILEGFS:-${PARMpost}/postcntrl_gfs.xml}" fi else - if [ $fhr -eq 0 ]; then - export PostFlatFile=$PARMpost/postxconfig-NT-GFS-F00.txt - export CTLFILE=${CTLFILEGFS:-$PARMpost/postcntrl_gfs_f00.xml} + if (( fhr == 0 )); then + export PostFlatFile="${PARMpost}/postxconfig-NT-GFS-F00.txt" + export CTLFILE="${CTLFILEGFS:-${PARMpost}/postcntrl_gfs_f00.xml}" else - export CTLFILE=${CTLFILEGFS:-$PARMpost/postcntrl_gfs.xml} + export CTLFILE="${CTLFILEGFS:-${PARMpost}/postcntrl_gfs.xml}" fi fi fi @@ -266,77 +271,77 @@ else ## not_anl if_stimes export PGBOUT2=pgbfile.grib2 export PGIOUT2=pgifile.grib2.idx export FILTER=0 - export fhr3=$fhr - if [ $GRIBVERSION = 'grib2' ]; then + export fhr3=${fhr} + if [ "${GRIBVERSION}" = 'grib2' ]; then MASTERFHR=${PREFIX}master.grb2f${fhr} MASTERFHRIDX=${PREFIX}master.grb2if${fhr} fi - if [ $INLINE_POST = ".false." ]; then - $POSTGPSH + if [ "${INLINE_POST}" = ".false." ]; then + ${POSTGPSH} else - cp $COMOUT/${MASTERFHR} $PGBOUT + cp "${COMOUT}/${MASTERFHR}" "${PGBOUT}" fi export err=$?; err_chk - if [ $GRIBVERSION = 'grib2' ]; then - mv $PGBOUT $PGBOUT2 + if [ "${GRIBVERSION}" = 'grib2' ]; then + mv "${PGBOUT}" "${PGBOUT2}" fi #wm Process pgb files - export FH=$(expr $fhr + 0) + export FH=$(( 10#${fhr} + 0 )) export downset=${downset:-1} - $GFSDOWNSH + ${GFSDOWNSH} export err=$?; err_chk - if [ $SENDDBN = YES ]; then - run=$(echo $RUN | tr '[a-z]' '[A-Z]') - $DBNROOT/bin/dbn_alert MODEL ${run}_PGB2_0P25 $job $COMOUT/${PREFIX}pgrb2.0p25.f${fhr} - $DBNROOT/bin/dbn_alert MODEL ${run}_PGB2_0P25_WIDX $job $COMOUT/${PREFIX}pgrb2.0p25.f${fhr}.idx - $DBNROOT/bin/dbn_alert MODEL ${run}_PGB_GB2 $job $COMOUT/${PREFIX}pgrb2.1p00.f${fhr} - $DBNROOT/bin/dbn_alert MODEL ${run}_PGB_GB2_WIDX $job $COMOUT/${PREFIX}pgrb2.1p00.f${fhr}.idx + if [ "${SENDDBN}" = "YES" ]; then + run="$(echo "${RUN}" | tr '[:lower:]' '[:upper:]')" + "${DBNROOT}/bin/dbn_alert" MODEL "${run}_PGB2_0P25" "${job}" "${COMOUT}/${PREFIX}pgrb2.0p25.f${fhr}" + "${DBNROOT}/bin/dbn_alert" MODEL "${run}_PGB2_0P25_WIDX ""${job}" "${COMOUT}/${PREFIX}pgrb2.0p25.f${fhr}.idx" + "${DBNROOT}/bin/dbn_alert" MODEL "${run}_PGB_GB2" "${job}" "${COMOUT}/${PREFIX}pgrb2.1p00.f${fhr}" + "${DBNROOT}/bin/dbn_alert" MODEL "${run}_PGB_GB2_WIDX" "${job}" "${COMOUT}/${PREFIX}pgrb2.1p00.f${fhr}.idx" fi - if [ $SENDCOM = 'YES' ]; then - if [ $GRIBVERSION = 'grib2' ] ; then - if [ $INLINE_POST = ".false." ]; then - cp $PGBOUT2 $COMOUT/${MASTERFHR} + if [ "${SENDCOM}" = 'YES' ]; then + if [ "${GRIBVERSION}" = 'grib2' ]; then + if [ "${INLINE_POST}" = ".false." ]; then + cp "${PGBOUT2}" "${COMOUT}/${MASTERFHR}" fi - $GRB2INDEX $PGBOUT2 $COMOUT/${MASTERFHRIDX} + ${GRB2INDEX} "${PGBOUT2}" "${COMOUT}/${MASTERFHRIDX}" fi # Model generated flux files will be in nemsio after FY17 upgrade # use post to generate Grib2 flux files - if [ $OUTTYP -eq 4 ] ; then - export NEMSINP=$COMIN/${PREFIX}atmf${fhr}${SUFFIX} - export FLXINP=$COMIN/${PREFIX}sfcf${fhr}${SUFFIX} - if [ $fhr -eq 0 ]; then - export PostFlatFile=$PARMpost/postxconfig-NT-GFS-FLUX-F00.txt - export CTLFILE=$PARMpost/postcntrl_gfs_flux_f00.xml + if (( OUTTYP == 4 )) ; then + export NEMSINP=${COMIN}/${PREFIX}atmf${fhr}${SUFFIX} + export FLXINP=${COMIN}/${PREFIX}sfcf${fhr}${SUFFIX} + if (( fhr == 0 )); then + export PostFlatFile=${PARMpost}/postxconfig-NT-GFS-FLUX-F00.txt + export CTLFILE=${PARMpost}/postcntrl_gfs_flux_f00.xml else - export PostFlatFile=$PARMpost/postxconfig-NT-GFS-FLUX.txt - export CTLFILE=$PARMpost/postcntrl_gfs_flux.xml + export PostFlatFile=${PARMpost}/postxconfig-NT-GFS-FLUX.txt + export CTLFILE=${PARMpost}/postcntrl_gfs_flux.xml fi export PGBOUT=fluxfile export FILTER=0 FLUXFL=${PREFIX}sfluxgrbf${fhr}.grib2 FLUXFLIDX=${PREFIX}sfluxgrbf${fhr}.grib2.idx - if [ $INLINE_POST = ".false." ]; then - $POSTGPSH + if [ "${INLINE_POST}" = ".false." ]; then + ${POSTGPSH} export err=$?; err_chk - mv fluxfile $COMOUT/${FLUXFL} + mv fluxfile "${COMOUT}/${FLUXFL}" fi - $WGRIB2 -s $COMOUT/${FLUXFL} > $COMOUT/${FLUXFLIDX} + ${WGRIB2} -s "${COMOUT}/${FLUXFL}" > "${COMOUT}/${FLUXFLIDX}" fi - if [ "$SENDDBN" = 'YES' -a \( "$RUN" = 'gdas' \) -a $(expr $fhr % 3) -eq 0 ]; then - $DBNROOT/bin/dbn_alert MODEL ${run}_SF $job $COMOUT/${PREFIX}atmf${fhr}${SUFFIX} - $DBNROOT/bin/dbn_alert MODEL ${run}_BF $job $COMOUT/${PREFIX}sfcf${fhr}${SUFFIX} - $DBNROOT/bin/dbn_alert MODEL ${run}_SGB_GB2 $job $COMOUT/${PREFIX}sfluxgrbf${fhr}.grib2 - $DBNROOT/bin/dbn_alert MODEL ${run}_SGB_GB2_WIDX $job $COMOUT/${PREFIX}sfluxgrbf${fhr}.grib2.idx + if [ "${SENDDBN}" = 'YES' ] && [ "${RUN}" = 'gdas' ] && (( fhr % 3 == 0 )); then + "${DBNROOT}/bin/dbn_alert" MODEL "${run}_SF" "${job}" "${COMOUT}/${PREFIX}atmf${fhr}${SUFFIX}" + "${DBNROOT}/bin/dbn_alert" MODEL "${run}_BF" "${job}" "${COMOUT}/${PREFIX}sfcf${fhr}${SUFFIX}" + "${DBNROOT}/bin/dbn_alert" MODEL "${run}_SGB_GB2" "${job}" "${COMOUT}/${PREFIX}sfluxgrbf${fhr}.grib2" + "${DBNROOT}/bin/dbn_alert" MODEL "${run}_SGB_GB2_WIDX ""${job}" "${COMOUT}/${PREFIX}sfluxgrbf${fhr}.grib2.idx" fi fi diff --git a/scripts/exgfs_atmos_nceppost.sh b/scripts/exgfs_atmos_post.sh similarity index 51% rename from scripts/exgfs_atmos_nceppost.sh rename to scripts/exgfs_atmos_post.sh index ae94472aeb..6777b1a380 100755 --- a/scripts/exgfs_atmos_nceppost.sh +++ b/scripts/exgfs_atmos_post.sh @@ -36,17 +36,17 @@ # echo "-----------------------------------------------------" ##################################################################### -source "$HOMEgfs/ush/preamble.sh" +source "${HOMEgfs}/ush/preamble.sh" -cd $DATA +cd "${DATA}" || exit 1 # specify model output format type: 4 for nemsio, 3 for sigio -export POSTGPSH=${POSTGPSH:-$USHgfs/gfs_nceppost.sh} -export GFSDOWNSH=${GFSDOWNSH:-$USHgfs/fv3gfs_downstream_nems.sh} -export GFSDOWNSHF=${GFSDOWNSHF:-$USHgfs/inter_flux.sh} -export GFSDWNSH=${GFSDWNSH:-$USHgfs/fv3gfs_dwn_nems.sh} -export TRIMRH=${TRIMRH:-$USHgfs/trim_rh.sh} -export MODICEC=${MODICEC:-$USHgfs/mod_icec.sh} +export POSTGPSH=${POSTGPSH:-${USHgfs}/gfs_post.sh} +export GFSDOWNSH=${GFSDOWNSH:-${USHgfs}/fv3gfs_downstream_nems.sh} +export GFSDOWNSHF=${GFSDOWNSHF:-${USHgfs}/inter_flux.sh} +export GFSDWNSH=${GFSDWNSH:-${USHgfs}/fv3gfs_dwn_nems.sh} +export TRIMRH=${TRIMRH:-${USHgfs}/trim_rh.sh} +export MODICEC=${MODICEC:-${USHgfs}/mod_icec.sh} export INLINE_POST=${INLINE_POST:-".false."} ############################################################ @@ -68,8 +68,8 @@ export PGBF=${PGBF:-"YES"} export TCYC=${TCYC:-".t${cyc}z."} export OUTPUT_FILE=${OUTPUT_FILE:-"nemsio"} export PREFIX=${PREFIX:-${RUN}${TCYC}} -if [ $OUTTYP -eq 4 ]; then - if [ $OUTPUT_FILE = "netcdf" ]; then +if (( OUTTYP == 4 )); then + if [ "${OUTPUT_FILE}" = "netcdf" ]; then export SUFFIX=".nc" else export SUFFIX=".nemsio" @@ -77,7 +77,7 @@ if [ $OUTTYP -eq 4 ]; then else export SUFFIX= fi -export machine=${machine:-WCOSS_C} +export machine=${machine:-WCOSS2} ########################### # Specify Output layers @@ -93,15 +93,16 @@ export IDRT=${IDRT:-0} # IDRT=0 is setting for outputting grib files on lat/lon # Post Analysis Files before starting the Forecast Post ############################################################ # Process analysis when post_times is 00 -export stime=$(echo $post_times | cut -c1-3) -if [ $OUTTYP -eq 4 ]; then - export loganl=$COMIN/${PREFIX}atmanl${SUFFIX} +stime="$(echo "${post_times}" | cut -c1-3)" +export stime +if (( OUTTYP == 4 )); then + export loganl="${COMIN}/${PREFIX}atmanl${SUFFIX}" else - export loganl=$COMIN/${PREFIX}sanl + export loganl="${COMIN}/${PREFIX}sanl" fi -if [ ${stime} = "anl" ]; then - if [ -f $loganl ]; then +if [ "${stime}" = "anl" ]; then + if [ -f "${loganl}" ]; then # add new environmental variables for running new ncep post # Validation date export VDATE=${PDY}${cyc} @@ -112,18 +113,18 @@ if [ ${stime} = "anl" ]; then # specify smaller control file for GDAS because GDAS does not # produce flux file, the default will be /nwprod/parm/gfs_cntrl.parm - if [ $GRIBVERSION = 'grib2' ]; then + if [ "${GRIBVERSION}" = 'grib2' ]; then # use grib2 nomonic table in product g2tmpl directory as default export POSTGRB2TBL=${POSTGRB2TBL:-${g2tmpl_ROOT}/share/params_grib2_tbl_new} - export PostFlatFile=${PostFlatFile:-$PARMpost/postxconfig-NT-GFS-ANL.txt} - export CTLFILE=$PARMpost/postcntrl_gfs_anl.xml + export PostFlatFile=${PostFlatFile:-${PARMpost}/postxconfig-NT-GFS-ANL.txt} + export CTLFILE=${PARMpost}/postcntrl_gfs_anl.xml fi [[ -f flxfile ]] && rm flxfile ; [[ -f nemsfile ]] && rm nemsfile - if [ $OUTTYP -eq 4 ]; then - ln -fs $COMIN/${PREFIX}atmanl${SUFFIX} nemsfile + if (( OUTTYP == 4 )); then + ln -fs "${COMIN}/${PREFIX}atmanl${SUFFIX}" nemsfile export NEMSINP=nemsfile - ln -fs $COMIN/${PREFIX}sfcanl${SUFFIX} flxfile + ln -fs "${COMIN}/${PREFIX}sfcanl${SUFFIX}" flxfile export FLXINP=flxfile fi @@ -131,52 +132,51 @@ if [ ${stime} = "anl" ]; then export PGIOUT=pgifile export PGBOUT2=pgbfile.grib2 export PGIOUT2=pgifile.grib2.idx - export IGEN=$IGEN_ANL + export IGEN=${IGEN_ANL} export FILTER=0 - $POSTGPSH + ${POSTGPSH} export err=$?; err_chk - if [ $GRIBVERSION = 'grib2' ]; then - mv $PGBOUT $PGBOUT2 + if [ "${GRIBVERSION}" = 'grib2' ]; then + mv "${PGBOUT}" "${PGBOUT2}" fi # Process pgb files - if [ "$PGBF" = 'YES' ]; then + if [ "${PGBF}" = 'YES' ]; then export FH=-1 export downset=${downset:-2} - $GFSDOWNSH + ${GFSDOWNSH} export err=$?; err_chk fi - if [ "$SENDCOM" = 'YES' ]; then + if [ "${SENDCOM}" = 'YES' ]; then export fhr3=anl - if [ $GRIBVERSION = 'grib2' ]; then + if [ "${GRIBVERSION}" = 'grib2' ]; then MASTERANL=${PREFIX}master.grb2${fhr3} MASTERANLIDX=${PREFIX}master.grb2i${fhr3} - cp $PGBOUT2 $COMOUT/${MASTERANL} - $GRB2INDEX $PGBOUT2 $COMOUT/${MASTERANLIDX} + cp "${PGBOUT2}" "${COMOUT}/${MASTERANL}" + ${GRB2INDEX} "${PGBOUT2}" "${COMOUT}/${MASTERANLIDX}" fi - if [ "$SENDDBN" = 'YES' ]; then - $DBNROOT/bin/dbn_alert MODEL GFS_MSC_sfcanl $job $COMOUT/${PREFIX}sfcanl${SUFFIX} - $DBNROOT/bin/dbn_alert MODEL GFS_SA $job $COMOUT/${PREFIX}atmanl${SUFFIX} - #alert removed in v15.0 $DBNROOT/bin/dbn_alert MODEL GFS_MASTER $job $COMOUT/${MASTERANL} - if [ "$PGBF" = 'YES' ]; then - $DBNROOT/bin/dbn_alert MODEL GFS_PGB2_0P25 $job $COMOUT/${PREFIX}pgrb2.0p25.anl - $DBNROOT/bin/dbn_alert MODEL GFS_PGB2_0P25_WIDX $job $COMOUT/${PREFIX}pgrb2.0p25.anl.idx - $DBNROOT/bin/dbn_alert MODEL GFS_PGB2B_0P25 $job $COMOUT/${PREFIX}pgrb2b.0p25.anl - $DBNROOT/bin/dbn_alert MODEL GFS_PGB2B_0P25_WIDX $job $COMOUT/${PREFIX}pgrb2b.0p25.anl.idx - - $DBNROOT/bin/dbn_alert MODEL GFS_PGB2_0P5 $job $COMOUT/${PREFIX}pgrb2.0p50.anl - $DBNROOT/bin/dbn_alert MODEL GFS_PGB2_0P5_WIDX $job $COMOUT/${PREFIX}pgrb2.0p50.anl.idx - $DBNROOT/bin/dbn_alert MODEL GFS_PGB2B_0P5 $job $COMOUT/${PREFIX}pgrb2b.0p50.anl - $DBNROOT/bin/dbn_alert MODEL GFS_PGB2B_0P5_WIDX $job $COMOUT/${PREFIX}pgrb2b.0p50.anl.idx - - $DBNROOT/bin/dbn_alert MODEL GFS_PGB2_1P0 $job $COMOUT/${PREFIX}pgrb2.1p00.anl - $DBNROOT/bin/dbn_alert MODEL GFS_PGB2_1P0_WIDX $job $COMOUT/${PREFIX}pgrb2.1p00.anl.idx - $DBNROOT/bin/dbn_alert MODEL GFS_PGB2B_1P0 $job $COMOUT/${PREFIX}pgrb2b.1p00.anl - $DBNROOT/bin/dbn_alert MODEL GFS_PGB2B_1P0_WIDX $job $COMOUT/${PREFIX}pgrb2b.1p00.anl.idx + if [ "${SENDDBN}" = 'YES' ]; then + "${DBNROOT}/bin/dbn_alert" MODEL GFS_MSC_sfcanl "${job}" "${COMOUT}/${PREFIX}sfcanl${SUFFIX}" + "${DBNROOT}/bin/dbn_alert" MODEL GFS_SA "${job}" "${COMOUT}/${PREFIX}atmanl${SUFFIX}" + if [ "${PGBF}" = 'YES' ]; then + "${DBNROOT}/bin/dbn_alert" MODEL GFS_PGB2_0P25 "${job}" "${COMOUT}/${PREFIX}pgrb2.0p25.anl" + "${DBNROOT}/bin/dbn_alert" MODEL GFS_PGB2_0P25_WIDX "${job}" "${COMOUT}/${PREFIX}pgrb2.0p25.anl.idx" + "${DBNROOT}/bin/dbn_alert" MODEL GFS_PGB2B_0P25 "${job}" "${COMOUT}/${PREFIX}pgrb2b.0p25.anl" + "${DBNROOT}/bin/dbn_alert" MODEL GFS_PGB2B_0P25_WIDX "${job}" "${COMOUT}/${PREFIX}pgrb2b.0p25.anl.idx" + + "${DBNROOT}/bin/dbn_alert" MODEL GFS_PGB2_0P5 "${job}" "${COMOUT}/${PREFIX}pgrb2.0p50.anl" + "${DBNROOT}/bin/dbn_alert" MODEL GFS_PGB2_0P5_WIDX "${job}" "${COMOUT}/${PREFIX}pgrb2.0p50.anl.idx" + "${DBNROOT}/bin/dbn_alert" MODEL GFS_PGB2B_0P5 "${job}" "${COMOUT}/${PREFIX}pgrb2b.0p50.anl" + "${DBNROOT}/bin/dbn_alert" MODEL GFS_PGB2B_0P5_WIDX "${job}" "${COMOUT}/${PREFIX}pgrb2b.0p50.anl.idx" + + "${DBNROOT}/bin/dbn_alert" MODEL GFS_PGB2_1P0 "${job}" "${COMOUT}/${PREFIX}pgrb2.1p00.anl" + "${DBNROOT}/bin/dbn_alert" MODEL GFS_PGB2_1P0_WIDX "${job}" "${COMOUT}/${PREFIX}pgrb2.1p00.anl.idx" + "${DBNROOT}/bin/dbn_alert" MODEL GFS_PGB2B_1P0 "${job}" "${COMOUT}/${PREFIX}pgrb2b.1p00.anl" + "${DBNROOT}/bin/dbn_alert" MODEL GFS_PGB2B_1P0_WIDX "${job}" "${COMOUT}/${PREFIX}pgrb2b.1p00.anl.idx" fi fi fi @@ -185,39 +185,39 @@ if [ ${stime} = "anl" ]; then ########################## WAFS U/V/T analysis start ########################## # U/V/T on ICAO standard atmospheric pressure levels for WAFS verification - if [ $WAFSF = "YES" ]; then - if [[ $RUN = gfs && $GRIBVERSION = 'grib2' ]]; then + if [ "${WAFSF}" = "YES" ]; then + if [[ "${RUN}" = "gfs" && "${GRIBVERSION}" = 'grib2' ]]; then export OUTTYP=${OUTTYP:-4} - export PostFlatFile=$PARMpost/postxconfig-NT-GFS-WAFS-ANL.txt - export CTLFILE=$PARMpost/postcntrl_gfs_wafs_anl.xml + export PostFlatFile="${PARMpost}/postxconfig-NT-GFS-WAFS-ANL.txt" + export CTLFILE="${PARMpost}/postcntrl_gfs_wafs_anl.xml" export PGBOUT=wafsfile export PGIOUT=wafsifile - $POSTGPSH + ${POSTGPSH} export err=$? - if [ $err -ne 0 ]; then - echo " *** GFS POST WARNING: WAFS output failed for analysis, err=$err" + if (( err != 0 )); then + echo " *** GFS POST WARNING: WAFS output failed for analysis, err=${err}" else # WAFS package doesn't process this part. # Need to be saved for WAFS U/V/T verification, # resolution higher than WAFS 1.25 deg for future compatibility wafsgrid="latlon 0:1440:0.25 90:721:-0.25" - $WGRIB2 $PGBOUT -set_grib_type same -new_grid_winds earth \ + ${WGRIB2} "${PGBOUT}" -set_grib_type same -new_grid_winds earth \ -new_grid_interpolation bilinear -set_bitmap 1 \ - -new_grid $wafsgrid ${PGBOUT}.tmp + -new_grid "${wafsgrid}" "${PGBOUT}.tmp" - if [ $SENDCOM = "YES" ]; then - cp ${PGBOUT}.tmp $COMOUT/${PREFIX}wafs.0p25.anl - $WGRIB2 -s ${PGBOUT}.tmp > $COMOUT/${PREFIX}wafs.0p25.anl.idx + if [ "${SENDCOM}" = "YES" ]; then + cp "${PGBOUT}.tmp" "${COMOUT}/${PREFIX}wafs.0p25.anl" + ${WGRIB2} -s "${PGBOUT}.tmp" > "${COMOUT}/${PREFIX}wafs.0p25.anl.idx" # if [ $SENDDBN = YES ]; then # $DBNROOT/bin/dbn_alert MODEL GFS_WAFS_GB2 $job $COMOUT/${PREFIX}wafs.0p25.anl # $DBNROOT/bin/dbn_alert MODEL GFS_WAFS_GB2__WIDX $job $COMOUT/${PREFIX}wafs.0p25.anl.idx # fi fi - rm $PGBOUT ${PGBOUT}.tmp + rm "${PGBOUT}" "${PGBOUT}.tmp" fi fi fi @@ -229,33 +229,33 @@ if [ ${stime} = "anl" ]; then err_chk fi else ## not_anl if_stime - SLEEP_LOOP_MAX=$(expr $SLEEP_TIME / $SLEEP_INT) + SLEEP_LOOP_MAX=$(( SLEEP_TIME / SLEEP_INT )) ############################################################ # Loop Through the Post Forecast Files ############################################################ - for fhr in $post_times; do - echo 'Start processing fhr='$post_times + for fhr in ${post_times}; do + echo "Start processing fhr=${post_times}" ############################### # Start Looping for the # existence of the restart files ############################### export pgm="postcheck" ic=1 - while [ $ic -le $SLEEP_LOOP_MAX ]; do - if [ -f $restart_file${fhr}.txt ]; then + while (( ic <= SLEEP_LOOP_MAX )); do + if [ -f "${restart_file}${fhr}.txt" ]; then break else - ic=$(expr $ic + 1) - sleep $SLEEP_INT + ic=$(( ic + 1 )) + sleep "${SLEEP_INT}" fi ############################### # If we reach this point assume # fcst job never reached restart # period and error exit ############################### - if [ $ic -eq $SLEEP_LOOP_MAX ]; then + if (( ic == SLEEP_LOOP_MAX )); then echo " *** FATAL ERROR: No model output in nemsio for f${fhr} " export err=9 err_chk @@ -267,47 +267,51 @@ else ## not_anl if_stime # for backup to start Model Fcst ############################### [[ -f flxfile ]] && rm flxfile ; [[ -f nemsfile ]] && rm nemsfile - if [ $OUTTYP -eq 4 ]; then - ln -fs $COMIN/${PREFIX}atmf${fhr}${SUFFIX} nemsfile + if (( OUTTYP == 4 )); then + ln -fs "${COMIN}/${PREFIX}atmf${fhr}${SUFFIX}" nemsfile export NEMSINP=nemsfile - ln -fs $COMIN/${PREFIX}sfcf${fhr}${SUFFIX} flxfile + ln -fs "${COMIN}/${PREFIX}sfcf${fhr}${SUFFIX}" flxfile export FLXINP=flxfile fi - if [ $fhr -gt 0 ]; then - export IGEN=$IGEN_FCST + if (( fhr > 0 )); then + export IGEN=${IGEN_FCST} else - export IGEN=$IGEN_ANL + export IGEN=${IGEN_ANL} fi - export VDATE=$(${NDATE} +${fhr} ${PDY}${cyc}) + # No shellcheck, NDATE is not a typo + # shellcheck disable=SC2153 + VDATE="$(${NDATE} "+${fhr}" "${PDY}${cyc}")" + # shellcheck disable= + export VDATE export OUTTYP=${OUTTYP:-4} - export GFSOUT=${PREFIX}gfsio${fhr} + export GFSOUT="${PREFIX}gfsio${fhr}" - if [ $GRIBVERSION = 'grib2' ]; then - export POSTGRB2TBL=${POSTGRB2TBL:-${g2tmpl_ROOT}/share/params_grib2_tbl_new} - export PostFlatFile=${PostFlatFile:-$PARMpost/postxconfig-NT-GFS.txt} + if [ "${GRIBVERSION}" = 'grib2' ]; then + export POSTGRB2TBL="${POSTGRB2TBL:-${g2tmpl_ROOT}/share/params_grib2_tbl_new}" + export PostFlatFile="${PostFlatFile:-${PARMpost}/postxconfig-NT-GFS.txt}" - if [ $RUN = gfs ]; then - export IGEN=$IGEN_GFS - if [ $fhr -gt 0 ]; then export IGEN=$IGEN_FCST ; fi + if [ "${RUN}" = "gfs" ]; then + export IGEN=${IGEN_GFS} + if (( fhr > 0 )); then export IGEN=${IGEN_FCST} ; fi else - export IGEN=$IGEN_GDAS_ANL - if [ $fhr -gt 0 ]; then export IGEN=$IGEN_FCST ; fi + export IGEN=${IGEN_GDAS_ANL} + if (( fhr > 0 )); then export IGEN=${IGEN_FCST} ; fi fi - if [[ $RUN = gfs ]]; then - if [ $fhr -eq 0 ]; then - export PostFlatFile=$PARMpost/postxconfig-NT-GFS-F00.txt - export CTLFILE=$PARMpost/postcntrl_gfs_f00.xml + if [[ "${RUN}" = "gfs" ]]; then + if (( fhr == 0 )); then + export PostFlatFile="${PARMpost}/postxconfig-NT-GFS-F00.txt" + export CTLFILE="${PARMpost}/postcntrl_gfs_f00.xml" else - export CTLFILE=${CTLFILEGFS:-$PARMpost/postcntrl_gfs.xml} + export CTLFILE="${CTLFILEGFS:-${PARMpost}/postcntrl_gfs.xml}" fi else - if [ $fhr -eq 0 ]; then - export PostFlatFile=$PARMpost/postxconfig-NT-GFS-F00.txt - export CTLFILE=${CTLFILEGFS:-$PARMpost/postcntrl_gfs_f00.xml} + if (( fhr == 0 )); then + export PostFlatFile="${PARMpost}/postxconfig-NT-GFS-F00.txt" + export CTLFILE="${CTLFILEGFS:-${PARMpost}/postcntrl_gfs_f00.xml}" else - export CTLFILE=${CTLFILEGFS:-$PARMpost/postcntrl_gfs.xml} + export CTLFILE="${CTLFILEGFS:-${PARMpost}/postcntrl_gfs.xml}" fi fi fi @@ -318,78 +322,78 @@ else ## not_anl if_stime export PGBOUT2=pgbfile.grib2 export PGIOUT2=pgifile.grib2.idx export FILTER=0 - if [ $GRIBVERSION = 'grib2' ]; then + if [ "${GRIBVERSION}" = 'grib2' ]; then MASTERFL=${PREFIX}master.grb2f${fhr} MASTERFLIDX=${PREFIX}master.grb2if${fhr} fi - if [ $INLINE_POST = ".false." ]; then - $POSTGPSH + if [ "${INLINE_POST}" = ".false." ]; then + ${POSTGPSH} else - cp -p $COMOUT/${MASTERFL} $PGBOUT + cp -p "${COMOUT}/${MASTERFL}" "${PGBOUT}" fi export err=$?; err_chk - if [ $GRIBVERSION = 'grib2' ]; then - mv $PGBOUT $PGBOUT2 + if [ "${GRIBVERSION}" = 'grib2' ]; then + mv "${PGBOUT}" "${PGBOUT2}" fi # Process pgb files - if [ "$PGBF" = 'YES' ]; then - export FH=$(expr $fhr + 0) + if [ "${PGBF}" = 'YES' ]; then + export FH=$(( 10#${fhr} + 0 )) export downset=${downset:-2} - $GFSDOWNSH + ${GFSDOWNSH} export err=$?; err_chk fi - if [ $SENDCOM = "YES" ]; then - if [ $GRIBVERSION = 'grib2' ]; then - if [ $INLINE_POST = ".false." ]; then - cp $PGBOUT2 $COMOUT/${MASTERFL} + if [ "${SENDCOM}" = "YES" ]; then + if [ "${GRIBVERSION}" = 'grib2' ]; then + if [ "${INLINE_POST}" = ".false." ]; then + cp "${PGBOUT2}" "${COMOUT}/${MASTERFL}" fi - $GRB2INDEX $PGBOUT2 $COMOUT/${MASTERFLIDX} + ${GRB2INDEX} "${PGBOUT2}" "${COMOUT}/${MASTERFLIDX}" fi - if [ "$SENDDBN" = 'YES' ]; then - if [ $GRIBVERSION = 'grib2' ]; then - if [ "$PGBF" = 'YES' ]; then - $DBNROOT/bin/dbn_alert MODEL GFS_PGB2_0P25 $job $COMOUT/${PREFIX}pgrb2.0p25.f${fhr} - $DBNROOT/bin/dbn_alert MODEL GFS_PGB2_0P25_WIDX $job $COMOUT/${PREFIX}pgrb2.0p25.f${fhr}.idx - $DBNROOT/bin/dbn_alert MODEL GFS_PGB2B_0P25 $job $COMOUT/${PREFIX}pgrb2b.0p25.f${fhr} - $DBNROOT/bin/dbn_alert MODEL GFS_PGB2B_0P25_WIDX $job $COMOUT/${PREFIX}pgrb2b.0p25.f${fhr}.idx - - if [ -s $COMOUT/${PREFIX}pgrb2.0p50.f${fhr} ]; then - $DBNROOT/bin/dbn_alert MODEL GFS_PGB2_0P5 $job $COMOUT/${PREFIX}pgrb2.0p50.f${fhr} - $DBNROOT/bin/dbn_alert MODEL GFS_PGB2_0P5_WIDX $job $COMOUT/${PREFIX}pgrb2.0p50.f${fhr}.idx - $DBNROOT/bin/dbn_alert MODEL GFS_PGB2B_0P5 $job $COMOUT/${PREFIX}pgrb2b.0p50.f${fhr} - $DBNROOT/bin/dbn_alert MODEL GFS_PGB2B_0P5_WIDX $job $COMOUT/${PREFIX}pgrb2b.0p50.f${fhr}.idx + if [ "${SENDDBN}" = 'YES' ]; then + if [ "${GRIBVERSION}" = 'grib2' ]; then + if [ "${PGBF}" = 'YES' ]; then + "${DBNROOT}/bin/dbn_alert" MODEL GFS_PGB2_0P25 "${job}" "${COMOUT}/${PREFIX}pgrb2.0p25.f${fhr}" + "${DBNROOT}/bin/dbn_alert" MODEL GFS_PGB2_0P25_WIDX "${job}" "${COMOUT}/${PREFIX}pgrb2.0p25.f${fhr}.idx" + "${DBNROOT}/bin/dbn_alert" MODEL GFS_PGB2B_0P25 "${job}" "${COMOUT}/${PREFIX}pgrb2b.0p25.f${fhr}" + "${DBNROOT}/bin/dbn_alert" MODEL GFS_PGB2B_0P25_WIDX "${job}" "${COMOUT}/${PREFIX}pgrb2b.0p25.f${fhr}.idx" + + if [ -s "${COMOUT}/${PREFIX}pgrb2.0p50.f${fhr}" ]; then + "${DBNROOT}/bin/dbn_alert" MODEL GFS_PGB2_0P5 "${job}" "${COMOUT}/${PREFIX}pgrb2.0p50.f${fhr}" + "${DBNROOT}/bin/dbn_alert" MODEL GFS_PGB2_0P5_WIDX "${job}" "${COMOUT}/${PREFIX}pgrb2.0p50.f${fhr}.idx" + "${DBNROOT}/bin/dbn_alert" MODEL GFS_PGB2B_0P5 "${job}" "${COMOUT}/${PREFIX}pgrb2b.0p50.f${fhr}" + "${DBNROOT}/bin/dbn_alert" MODEL GFS_PGB2B_0P5_WIDX "${job}" "${COMOUT}/${PREFIX}pgrb2b.0p50.f${fhr}.idx" fi - if [ -s $COMOUT/${PREFIX}pgrb2.1p00.f${fhr} ]; then - $DBNROOT/bin/dbn_alert MODEL GFS_PGB2_1P0 $job $COMOUT/${PREFIX}pgrb2.1p00.f${fhr} - $DBNROOT/bin/dbn_alert MODEL GFS_PGB2_1P0_WIDX $job $COMOUT/${PREFIX}pgrb2.1p00.f${fhr}.idx - $DBNROOT/bin/dbn_alert MODEL GFS_PGB2B_1P0 $job $COMOUT/${PREFIX}pgrb2b.1p00.f${fhr} - $DBNROOT/bin/dbn_alert MODEL GFS_PGB2B_1P0_WIDX $job $COMOUT/${PREFIX}pgrb2b.1p00.f${fhr}.idx + if [ -s "${COMOUT}/${PREFIX}pgrb2.1p00.f${fhr}" ]; then + "${DBNROOT}/bin/dbn_alert" MODEL GFS_PGB2_1P0 "${job}" "${COMOUT}/${PREFIX}pgrb2.1p00.f${fhr}" + "${DBNROOT}/bin/dbn_alert" MODEL GFS_PGB2_1P0_WIDX "${job}" "${COMOUT}/${PREFIX}pgrb2.1p00.f${fhr}.idx" + "${DBNROOT}/bin/dbn_alert" MODEL GFS_PGB2B_1P0 "${job}" "${COMOUT}/${PREFIX}pgrb2b.1p00.f${fhr}" + "${DBNROOT}/bin/dbn_alert" MODEL GFS_PGB2B_1P0_WIDX "${job}" "${COMOUT}/${PREFIX}pgrb2b.1p00.f${fhr}.idx" fi fi fi fi export fhr - $USHgfs/gfs_transfer.sh + "${USHgfs}/gfs_transfer.sh" fi [[ -f pgbfile.grib2 ]] && rm pgbfile.grib2 # use post to generate GFS Grib2 Flux file as model generated Flux file # will be in nemsio format after FY17 upgrade. - if [ $OUTTYP -eq 4 -a $FLXF = "YES" ]; then - if [ $fhr -eq 0 ]; then - export PostFlatFile=$PARMpost/postxconfig-NT-GFS-FLUX-F00.txt - export CTLFILE=$PARMpost/postcntrl_gfs_flux_f00.xml + if (( OUTTYP == 4 )) && [[ "${FLXF}" == "YES" ]]; then + if (( fhr == 0 )); then + export PostFlatFile="${PARMpost}/postxconfig-NT-GFS-FLUX-F00.txt" + export CTLFILE="${PARMpost}/postcntrl_gfs_flux_f00.xml" else - export PostFlatFile=$PARMpost/postxconfig-NT-GFS-FLUX.txt - export CTLFILE=$PARMpost/postcntrl_gfs_flux.xml + export PostFlatFile="${PARMpost}/postxconfig-NT-GFS-FLUX.txt" + export CTLFILE="${PARMpost}/postcntrl_gfs_flux.xml" fi export PGBOUT=fluxfile export FILTER=0 @@ -397,44 +401,44 @@ else ## not_anl if_stime FLUXFLIDX=${PREFIX}sfluxgrbf${fhr}.grib2.idx #Add extra flux.1p00 file for coupled - if [ "$FLXGF" = 'YES' ]; then - export FH=$(expr $fhr + 0) - $GFSDOWNSHF + if [ "${FLXGF}" = 'YES' ]; then + export FH=$(( 10#${fhr} + 0 )) + ${GFSDOWNSHF} export err=$?; err_chk fi - if [ $INLINE_POST = ".false." ]; then - $POSTGPSH + if [ "${INLINE_POST}" = ".false." ]; then + ${POSTGPSH} export err=$?; err_chk - mv fluxfile $COMOUT/${FLUXFL} + mv fluxfile "${COMOUT}/${FLUXFL}" fi - $WGRIB2 -s $COMOUT/${FLUXFL} > $COMOUT/${FLUXFLIDX} + ${WGRIB2} -s "${COMOUT}/${FLUXFL}" > "${COMOUT}/${FLUXFLIDX}" - if [ "$SENDDBN" = 'YES' ]; then - $DBNROOT/bin/dbn_alert MODEL GFS_SGB_GB2 $job $COMOUT/${FLUXFL} - $DBNROOT/bin/dbn_alert MODEL GFS_SGB_GB2_WIDX $job $COMOUT/${FLUXFLIDX} + if [ "${SENDDBN}" = 'YES' ]; then + "${DBNROOT}/bin/dbn_alert" MODEL GFS_SGB_GB2 "${job}" "${COMOUT}/${FLUXFL}" + "${DBNROOT}/bin/dbn_alert" MODEL GFS_SGB_GB2_WIDX "${job}" "${COMOUT}/${FLUXFLIDX}" fi fi # process satellite look alike separately so that master pgb gets out in time # set outtyp to 2 because master post already generates gfs io files - if [ $GOESF = "YES" ]; then - export OUTTYP=${OUTTYP:-4} + if [ "${GOESF}" = "YES" ]; then + export OUTTYP=${OUTTYP:-4} # specify output file name from chgres which is input file name to nceppost # if model already runs gfs io, make sure GFSOUT is linked to the gfsio file - # new imported variable for global_nceppost.sh + # new imported variable for global_post.sh export GFSOUT=${PREFIX}gfsio${fhr} # link satellite coefficients files, use hwrf version as ops crtm 2.0.5 # does not new coefficient files used by post - export FIXCRTM=${FIXCRTM:-${CRTM_FIX}} - $USHgfs/link_crtm_fix.sh $FIXCRTM + export FIXCRTM="${FIXCRTM:-${CRTM_FIX}}" + "${USHgfs}/link_crtm_fix.sh" "${FIXCRTM}" - if [ $GRIBVERSION = 'grib2' ]; then - export PostFlatFile=$PARMpost/postxconfig-NT-GFS-GOES.txt - export CTLFILE=$PARMpost/postcntrl_gfs_goes.xml + if [ "${GRIBVERSION}" = 'grib2' ]; then + export PostFlatFile="${PARMpost}/postxconfig-NT-GFS-GOES.txt " + export CTLFILE="${PARMpost}/postcntrl_gfs_goes.xml" fi export FLXINP=flxfile export FLXIOUT=flxifile @@ -445,25 +449,25 @@ else ## not_anl if_stime export JO=0 export IGEN=0 - if [ $NET = gfs ]; then - $POSTGPSH + if [ "${NET}" = "gfs" ]; then + ${POSTGPSH} export err=$?; err_chk fi - if [ $GRIBVERSION = 'grib2' ]; then - SPECIALFL=${PREFIX}special.grb2 - SPECIALFLIDX=${PREFIX}special.grb2i + if [ "${GRIBVERSION}" = 'grib2' ]; then + SPECIALFL="${PREFIX}special.grb2" + SPECIALFLIDX="${PREFIX}special.grb2i" fi - fhr3=$fhr + fhr3=${fhr} - if [ $SENDCOM = "YES" ]; then + if [ "${SENDCOM}" = "YES" ]; then # echo "$PDY$cyc$pad$fhr" > $COMOUT/${RUN}.t${cyc}z.master.control - mv goesfile $COMOUT/${SPECIALFL}f$fhr - mv goesifile $COMOUT/${SPECIALFLIDX}f$fhr + mv goesfile "${COMOUT}/${SPECIALFL}f${fhr}" + mv goesifile "${COMOUT}/${SPECIALFLIDX}f${fhr}" - if [ $SENDDBN = YES ]; then - $DBNROOT/bin/dbn_alert MODEL GFS_SPECIAL_GB2 $job $COMOUT/${SPECIALFL}f$fhr + if [ "${SENDDBN}" = "YES" ]; then + "${DBNROOT}/bin/dbn_alert" MODEL GFS_SPECIAL_GB2 "${job}" "${COMOUT}/${SPECIALFL}f${fhr}" fi fi fi @@ -472,17 +476,17 @@ else ## not_anl if_stime ########################## WAFS start ########################## # Generate WAFS products on ICAO standard level. # Do not need to be sent out to public, WAFS package will process the data. - if [[ $WAFSF = "YES" && 10#$fhr -le 120 ]]; then - if [[ $RUN = gfs && $GRIBVERSION = 'grib2' ]]; then + if [[ "${WAFSF}" = "YES" ]] && (( 10#${fhr} <= 120 )); then + if [[ "${RUN}" = gfs && "${GRIBVERSION}" = 'grib2' ]]; then export OUTTYP=${OUTTYP:-4} # Extend WAFS icing and gtg up to 120 hours - export PostFlatFile=$PARMpost/postxconfig-NT-GFS-WAFS.txt - export CTLFILE=$PARMpost/postcntrl_gfs_wafs.xml + export PostFlatFile="${PARMpost}/postxconfig-NT-GFS-WAFS.txt" + export CTLFILE="${PARMpost}/postcntrl_gfs_wafs.xml" # gtg has its own configurations - cp $PARMpost/gtg.config.gfs gtg.config - cp $PARMpost/gtg_imprintings.txt gtg_imprintings.txt + cp "${PARMpost}/gtg.config.gfs" gtg.config + cp "${PARMpost}/gtg_imprintings.txt" gtg_imprintings.txt export PGBOUT=wafsfile export PGIOUT=wafsifile @@ -491,24 +495,24 @@ else ## not_anl if_stime # hourly if fhr<=24 # every 3 forecast hour if 24'$a} -l=$(echo $PGMERR | xargs | cut -c1) -[[ $l = '&' ]]&&a=''||a='>' -export REDERR=${REDERR:-'2>'$a} +l="$(echo "${PGMOUT}" | xargs | cut -c1)" +[[ ${l} = '&' ]]&&a=''||a='>' +export REDOUT=${REDOUT:-'1>'${a}} +l="$(echo "${PGMERR}" | xargs | cut -c1)" +[[ ${l} = '&' ]]&&a=''||a='>' +export REDERR=${REDERR:-'2>'${a}} ################################################################################ # Chuang: Run chgres if OUTTYP=1 or 0 @@ -247,21 +250,21 @@ export REDERR=${REDERR:-'2>'$a} export APRUN=${APRUNP:-${APRUN:-""}} # exit if NEMSINP does not exist -if [ ${OUTTYP} -eq 4 ] ; then - if [ ! -s $NEMSINP -o ! -s $FLXINP ] ; then +if (( OUTTYP == 4 )) ; then + if [ ! -s "${NEMSINP}" ] || [ ! -s "${FLXINP}" ] ; then echo "model files not found, exitting" exit 111 fi fi -export SIGHDR=${SIGHDR:-$NWPROD/exec/global_sighdr} +export SIGHDR=${SIGHDR:-${NWPROD}/exec/global_sighdr} export IDRT=${IDRT:-4} # run post to read nemsio file if OUTTYP=4 -if [ ${OUTTYP} -eq 4 ] ; then - if [ ${OUTPUT_FILE} = "netcdf" ]; then +if (( OUTTYP == 4 )) ; then + if [ "${OUTPUT_FILE}" = "netcdf" ]; then export MODEL_OUT_FORM=${MODEL_OUT_FORM:-netcdfpara} - elif [ ${OUTPUT_FILE} = "nemsio" ]; then + elif [ "${OUTPUT_FILE}" = "nemsio" ]; then export MODEL_OUT_FORM=${MODEL_OUT_FORM:-binarynemsiompiio} else export MODEL_OUT_FORM=${MODEL_OUT_FORM:-binarynemsiompiio} @@ -274,36 +277,37 @@ fi export OMP_NUM_THREADS=${OMP_NUM_THREADS:-1} pwd=$(pwd) -if [[ -d $DATA ]]; then +if [[ -d "${DATA}" ]]; then mkdata=NO else - mkdir -p $DATA + mkdir -p "${DATA}" mkdata=YES fi -cd $DATA||exit 99 +cd "${DATA}" || exit 99 ################################################################################ # Post GRIB -export PGM=$POSTGPEXEC -export pgm=$PGM -$LOGSCRIPT +export PGM=${POSTGPEXEC} +export pgm=${PGM} +${LOGSCRIPT} cat <<-EOF >postgp.inp.nml$$ &NAMPGB - $POSTGPVARS + ${POSTGPVARS} EOF cat <<-EOF >>postgp.inp.nml$$ / EOF -if [[ "$VERBOSE" = "YES" ]]; then +if [[ "${VERBOSE}" = "YES" ]]; then cat postgp.inp.nml$$ fi # making the time stamp format for ncep post -export YY=$(echo $VDATE | cut -c1-4) -export MM=$(echo $VDATE | cut -c5-6) -export DD=$(echo $VDATE | cut -c7-8) -export HH=$(echo $VDATE | cut -c9-10) +YY=$(echo "${VDATE}" | cut -c1-4) +MM=$(echo "${VDATE}" | cut -c5-6) +DD=$(echo "${VDATE}" | cut -c7-8) +HH=$(echo "${VDATE}" | cut -c9-10) +export YY MM DD HH cat > itag <<-EOF &model_inputs @@ -327,54 +331,55 @@ rm -f fort.* #ln -sf $PGBOUT postgp.out.pgb$$ # change model generating Grib number -if [ ${GRIBVERSION} = grib2 ]; then - cp ${POSTGRB2TBL} . - cp ${PostFlatFile} ./postxconfig-NT.txt - if [ ${ens} = "YES" ] ; then - sed < ${PostFlatFile} -e "s#negatively_pert_fcst#${ens_pert_type}#" > ./postxconfig-NT.txt +if [ "${GRIBVERSION}" = "grib2" ]; then + cp "${POSTGRB2TBL}" . + cp "${PostFlatFile}" ./postxconfig-NT.txt + if [ "${ens}" = "YES" ] ; then + sed < "${PostFlatFile}" -e "s#negatively_pert_fcst#${ens_pert_type}#" > ./postxconfig-NT.txt fi # cp ${CTLFILE} postcntrl.xml fi -export CTL=$(basename $CTLFILE) +CTL=$(basename "${CTLFILE}") +export CTL ln -sf griddef.out fort.110 -cp ${PARMpost}/nam_micro_lookup.dat ./eta_micro_lookup.dat +cp "${PARMpost}/nam_micro_lookup.dat" ./eta_micro_lookup.dat -echo "gfs_nceppost.sh OMP_NUM_THREADS= $OMP_NUM_THREADS" -${APRUN:-mpirun.lsf} $POSTGPEXEC < itag > outpost_gfs_${VDATE}_${CTL} +echo "gfs_post.sh OMP_NUM_THREADS= ${OMP_NUM_THREADS}" +${APRUN:-mpirun.lsf} "${POSTGPEXEC}" < itag > "outpost_gfs_${VDATE}_${CTL}" export ERR=$? -export err=$ERR +export err=${ERR} -if [ $err -ne 0 ] ; then - if [ $PGBOUT = "wafsfile" ] ; then - exit $err +if (( err != 0 )) ; then + if [ "${PGBOUT}" = "wafsfile" ] ; then + exit "${err}" fi fi -$ERRSCRIPT||exit 2 +${ERRSCRIPT} || exit 2 -if [ $FILTER = "1" ] ; then +if [ "${FILTER}" = "1" ] ; then # Filter SLP and 500 mb height using copygb, change GRIB ID, and then # cat the filtered fields to the pressure GRIB file, from Iredell - if [ $GRIBVERSION = grib2 ]; then - if [ ${ens} = YES ] ; then - $COPYGB2 -x -i'4,0,80' -k'1 3 0 7*-9999 101 0 0' $PGBOUT tfile + if [ "${GRIBVERSION}" = "grib2" ]; then + if [ "${ens}" = "YES" ] ; then + "${COPYGB2}" -x -i'4,0,80' -k'1 3 0 7*-9999 101 0 0' "${PGBOUT}" tfile export err=$?; err_chk else - $COPYGB2 -x -i'4,0,80' -k'0 3 0 7*-9999 101 0 0' $PGBOUT tfile + "${COPYGB2}" -x -i'4,0,80' -k'0 3 0 7*-9999 101 0 0' "${PGBOUT}" tfile export err=$?; err_chk fi - $WGRIB2 tfile -set_byte 4 11 1 -grib prmsl + ${WGRIB2} tfile -set_byte 4 11 1 -grib prmsl export err=$?; err_chk - if [ ${ens} = YES ] ; then - $COPYGB2 -x -i'4,1,5' -k'1 3 5 7*-9999 100 0 50000' $PGBOUT tfile + if [ "${ens}" = "YES" ] ; then + "${COPYGB2}" -x -i'4,1,5' -k'1 3 5 7*-9999 100 0 50000' "${PGBOUT}" tfile export err=$?; err_chk else - $COPYGB2 -x -i'4,1,5' -k'0 3 5 7*-9999 100 0 50000' $PGBOUT tfile + "${COPYGB2}" -x -i'4,1,5' -k'0 3 5 7*-9999 100 0 50000' "${PGBOUT}" tfile export err=$?; err_chk fi - $WGRIB2 tfile -set_byte 4 11 193 -grib h5wav + ${WGRIB2} tfile -set_byte 4 11 193 -grib h5wav export err=$?; err_chk #cat $PGBOUT prmsl h5wav >> $PGBOUT @@ -388,33 +393,32 @@ fi ################################################################################ # Make GRIB index file -if [[ -n $PGIOUT ]]; then - if [ $GRIBVERSION = grib2 ]; then - # JY $GRBINDEX2 $PGBOUT $PGIOUT - $GRB2INDEX $PGBOUT $PGIOUT +if [[ -n "${PGIOUT}" ]]; then + if [ "${GRIBVERSION}" = "grib2" ]; then + ${GRB2INDEX} "${PGBOUT}" "${PGIOUT}" fi fi -if [[ -r $FLXINP && -n $FLXIOUT && $OUTTYP -le 3 ]]; then - $GRBINDEX $FLXINP $FLXIOUT +if [[ -r ${FLXINP} && -n ${FLXIOUT} && ${OUTTYP} -le 3 ]]; then + ${GRBINDEX} "${FLXINP}" "${FLXIOUT}" fi ################################################################################ # generate psi and chi -echo "GENPSICHI= " $GENPSICHI -if [ $GENPSICHI = YES ] ; then +echo "GENPSICHI = ${GENPSICHI}" +if [ "${GENPSICHI}" = "YES" ] ; then #echo "PGBOUT PGIOUT=" $PGBOUT $PGIOUT #echo "YY MM=" $YY $MM export psichifile=./psichi.grb - $GENPSICHIEXE < postgp.inp.nml$$ + ${GENPSICHIEXE} < postgp.inp.nml$$ rc=$? - if [[ $rc -ne 0 ]] ; then - echo 'Nonzero return code rc= '$rc + if (( rc != 0 )); then + echo "Nonzero return code rc=${rc}" exit 3 fi - cat ./psichi.grb >> $PGBOUT + cat ./psichi.grb >> "${PGBOUT}" fi ################################################################################ # Postprocessing -cd $pwd -[[ $mkdata = YES ]]&&rmdir $DATA +cd "${pwd}" || exit 2 +[[ "${mkdata}" = "YES" ]] && rmdir "${DATA}" -exit $err +exit "${err}" diff --git a/ush/global_nceppost.sh b/ush/global_nceppost.sh deleted file mode 100755 index 2c0711c57f..0000000000 --- a/ush/global_nceppost.sh +++ /dev/null @@ -1,476 +0,0 @@ -#! /usr/bin/env bash - -################################################################################ -#### UNIX Script Documentation Block -# . . -# Script name: global_nceppost.sh -# Script description: Posts the global pressure GRIB file -# -# Author: Mark Iredell Org: NP23 Date: 1999-05-01 -# -# Abstract: This script reads a single global GFS IO file and (optionally) -# a global flux file and creates a global pressure GRIB file. -# The resolution and generating code of the output GRIB file can also -# be set in the argument list. -# -# Script history log: -# 1999-05-01 Mark Iredell -# 2007-04-04 Huiya Chuang: Modify the script to run unified post -# 2012-06-04 Jun Wang: add grib2 option -# 2015-03-20 Lin Gan: add Perl for Post XML performance upgrade -# 2016-02-08 Lin Gan: Modify to use Vertical Structure -# -# Usage: global_postgp.sh SIGINP FLXINP FLXIOUT PGBOUT PGIOUT IGEN -# -# Input script positional parameters: -# 1 Input sigma file -# defaults to $SIGINP -# 2 Input flux file -# defaults to $FLXINP -# 3 Output flux index file -# defaults to $FLXIOUT -# 4 Output pressure GRIB file -# defaults to $PGBOUT -# 5 Output pressure GRIB index file -# defaults to $PGIOUT, then to none -# 8 Model generating code, -# defaults to $IGEN, then to input sigma generating code -# -# Imported Shell Variables: -# SIGINP Input sigma file -# overridden by $1 -# FLXINP Input flux file -# overridden by $2 -# FLXIOUT Output flux index file -# overridden by $3 -# PGBOUT Output pressure GRIB file -# overridden by $4. If not defined, -# post will use the filename specified in -# the control file -# PGIOUT Output pressure GRIB index file -# overridden by $5; defaults to none -# IGEN Model generating code -# overridden by $8; defaults to input sigma generating code -##### Moorthi: Add new imported shell variable for running chgres -# CHGRESSH optional: the script to run chgres -# default to to ${USHglobal}/global_chgres.sh -# SIGLEVEL optional: the coordinate text file -# default to to $HOMEgfs/fix/global_hyblev.l${LEVS}.txt -##### Chuang: Add new imported Shell Variable for ncep post -# OUTTYP Output file type read in by post -# 1: if user has a sigma file and needs post to run chgres to convert to gfs io file -# 2: if user already has a gfs io file -# 3: if user uses post to read sigma file directly -# 0: if user wishes to generate both gfsio and sigma files -# 4: if user uses post to read nemsio file directly -# VDATE Verifying date 10 digits yyyymmddhh -# GFSOUT Optional, output file name from chgres which is input file name to nceppost -# if model already runs gfs io, make sure GFSOUT is linked to the gfsio file -# CTLFILE Optional, Your version of control file if not using operational one -# OVERPARMEXEC Optional, the executable for changing Grib KPDS ID -# default to to ${EXECglobal}/overparm_grib -# CHGRESTHREAD Optional, speed up chgres by using multiple threads -# default to 1 -# FILTER Optional, set to 1 to filter SLP and 500 mb height using copygb -# D3DINP Optional, Inout D3D file, if not defined, post will run -# without processing D3D file -# D3DOUT Optional, output D3D file, if not defined, post will -# use the file name specified in the control file -# IPVOUT Optional, output IPV file, if not defined, post will -# use the file name specified in the control file -# GENPSICHI Optional, set to YES will generate psi and chi and -# append it to the end of PGBOUT. Default to NO -# GENPSICHIEXE Optional, specify where executable is for generating -# psi and chi. -######################################################################## -# EXECglobal Directory for global executables -# defaults to $HOMEgfs/exec -# USHglobal Directory for global scripts -# defaults to $HOMEgfs/ush -# DATA working directory -# (if nonexistent will be made, used and deleted) -# defaults to current working directory -# MP Multi-processing type ("p" or "s") -# defaults to "p", or "s" if LOADL_STEP_TYPE is not PARALLEL -# XC Suffix to add to executables -# defaults to none -# POSTGPEXEC Global post executable -# defaults to ${EXECglobal}/ncep_post -# GRBINDEX GRIB index maker -# ANOMCATSH Global anomaly GRIB script -# defaults to ${USHglobal/global_anomcat.sh -# POSTGPLIST File containing further namelist inputs -# defaults to /dev/null -# INISCRIPT Preprocessing script -# defaults to none -# LOGSCRIPT Log posting script -# defaults to none -# ERRSCRIPT Error processing script -# defaults to 'eval [[ $err = 0 ]]' -# ENDSCRIPT Postprocessing script -# defaults to none -# POSTGPVARS Other namelist inputs to the global post executable -# such as IDRT,KO,PO,KTT,KT,PT,KZZ,ZZ, -# NCPUS,MXBIT,IDS,POB,POT,MOO,MOOA,MOW,MOWA, -# ICEN,ICEN2,IENST,IENSI -# defaults to none set -# NTHREADS Number of threads -# defaults to 1 -# NTHSTACK Size of stack per thread -# defaults to 64000000 -# VERBOSE Verbose flag (YES or NO) -# defaults to NO -# PGMOUT Executable standard output -# defaults to $pgmout, then to '&1' -# PGMERR Executable standard error -# defaults to $pgmerr, then to '&1' -# pgmout Executable standard output default -# pgmerr Executable standard error default -# REDOUT standard output redirect ('1>' or '1>>') -# defaults to '1>', or to '1>>' to append if $PGMOUT is a file -# REDERR standard error redirect ('2>' or '2>>') -# defaults to '2>', or to '2>>' to append if $PGMERR is a file -# -# Exported Shell Variables: -# PGM Current program name -# pgm -# ERR Last return code -# err -# -# Modules and files referenced: -# scripts : $INISCRIPT -# $LOGSCRIPT -# $ERRSCRIPT -# $ENDSCRIPT -# $ANOMCATSH -# -# programs : $POSTGPEXEC -# $GRBINDEX -# -# input data : $1 or $SIGINP -# $2 or $SFCINP -# $POSTGPLIST -# -# output data: $3 or $FLXIOUT -# $4 or $PGBOUT -# $5 or $PGIOUT -# $PGMOUT -# $PGMERR -# -# scratch : ${DATA}/postgp.inp.sig -# ${DATA}/postgp.inp.flx -# ${DATA}/postgp.out.pgb -# -# Remarks: -# -# Condition codes -# 0 - no problem encountered -# >0 - some problem encountered -# -# Control variable resolution priority -# 1 Command line argument. -# 2 Environment variable. -# 3 Inline default. -# -# Attributes: -# Language: POSIX shell -# Machine: IBM SP -# -#### -################################################################################ -# Set environment. -source "$HOMEgfs/ush/preamble.sh" - -# Command line arguments. -export SIGINP=${1:-${SIGINP}} -export FLXINP=${2:-${FLXINP}} -export FLXIOUT=${3:-${FLXIOUT}} -export PGBOUT=${4:-${PGBOUT}} -#export PGIOUT=${5:-${PGIOUT}} -export PGIOUT=${PGIOUT:-pgb.idx} -export IO=${6:-${IO:-0}} -export JO=${7:-${JO:-0}} -export IGEN=${8:-${IGEN:-0}} -# Directories. -export EXECglobal=${EXECglobal:-$HOMEgfs/exec} -export USHglobal=${USHglobal:-$HOMEgfs/ush} -export DATA=${DATA:-$(pwd)} -# Filenames. -export MP=${MP:-$([[ $LOADL_STEP_TYPE = PARALLEL ]]&&echo "p"||echo "s")} -export XC=${XC} -export POSTGPEXEC=${POSTGPEXEC:-${EXECglobal}/ncep_post} -export OVERPARMEXEC=${OVERPARMEXEC:-${EXECglobal}/overparm_grib} -export ANOMCATSH=${ANOMCATSH:-${USHglobal}/global_anomcat.sh} -export CHGRESSH=${CHGRESSH:-${USHglobal}/global_chgres.sh} -export POSTGPLIST=${POSTGPLIST:-/dev/null} -export INISCRIPT=${INISCRIPT} -export ERRSCRIPT=${ERRSCRIPT:-'eval [[ $err = 0 ]]'} -export LOGSCRIPT=${LOGSCRIPT} -export ENDSCRIPT=${ENDSCRIPT} -export GFSOUT=${GFSOUT:-gfsout} -export CTLFILE=${CTLFILE:-$HOMEgfs/parm/post/postcntrl_gfs.xml} -export MODEL_OUT_FORM=${MODEL_OUT_FORM:-binarynemsiompiio} -export GRIBVERSION=${GRIBVERSION:-'grib1'} -# Other variables. -export POSTGPVARS=${POSTGPVARS} -export NTHREADS=${NTHREADS:-1} -export NTHSTACK=${NTHSTACK:-64000000} -export PGMOUT=${PGMOUT:-${pgmout:-'&1'}} -export PGMERR=${PGMERR:-${pgmerr:-'&2'}} -export CHGRESTHREAD=${CHGRESTHREAD:-1} -export FILTER=${FILTER:-1} -export GENPSICHI=${GENPSICHI:-NO} -export GENPSICHIEXE=${GENPSICHIEXE:-${EXECglobal}/genpsiandchi} -export ens=${ens:-NO} -#export D3DINP=${D3DINP:-/dev/null} -l=$(echo $PGMOUT | xargs | cut -c1) -[[ $l = '&' ]]&&a=''||a='>' -export REDOUT=${REDOUT:-'1>'$a} -l=$(echo $PGMERR | xargs | cut -c1) -[[ $l = '&' ]]&&a=''||a='>' -export REDERR=${REDERR:-'2>'$a} -################################################################################ - -# Chuang: Run chgres if OUTTYP=1 or 0 - -export APRUN=${APRUNP:-${APRUN:-""}} - -# exit if SIGINP does not exist -if [ ${OUTTYP} -le 3 ] ; then - if [ ! -s $SIGINP ] ; then - echo "sigma file not found, exitting" - exit 111 - fi -fi - -export SIGHDR=${SIGHDR:-$HOMEgfs/exec/global_sighdr} -export IDRT=${IDRT:-4} - -if [ ${OUTTYP} -le 1 ] ; then - export JCAP=${JCAP:-$(echo jcap|$SIGHDR ${SIGINP})} - export LEVS=${LEVS:-$(echo levs|$SIGHDR ${SIGINP})} - export IDVC=${IDVC:-$(echo idvc|$SIGHDR ${SIGINP})} - export IDVM=${IDVM:-$(echo idvm|$SIGHDR ${SIGINP})} - export NVCOORD=${NVCOORD:-$(echo nvcoord|$SIGHDR ${SIGINP})} - export IVSSIG=${IVSSIG:-$(echo ivs|$SIGHDR ${SIGINP})} - export LATCH=${LATCH:-8} - if [ ${OUTTYP} -eq 1 ] ; then - export CHGRESVARS="IDVC=$IDVC,IDVM=$IDVM,NVCOORD=$NVCOORD,IVSSIG=$IVSSIG,LATCH=$LATCH," - elif [ ${OUTTYP} -eq 0 ] ; then - export CHGRESVARS="LATCH=$LATCH,$CHGRESVARS" - fi - #export SIGLEVEL=${SIGLEVEL:-""} - export SIGLEVEL=${SIGLEVEL:-"$HOMEgfs/fix/global_hyblev.l${LEVS}.txt"} - # specify threads for running chgres - export OMP_NUM_THREADS=$CHGRESTHREAD - export NTHREADS=$OMP_NUM_THREADS - if [ ${JCAP} -eq 574 -a ${IDRT} -eq 4 ]; then - export NTHSTACK=1024000000 - fi - export XLSMPOPTS="parthds=$NTHREADS:stack=$NTHSTACK" - - $CHGRESSH - - export ERR=$? - export err=$ERR - $ERRSCRIPT||exit 1 - -# run post to read sigma file directly if OUTTYP=3 -elif [ ${OUTTYP} -eq 3 ] ; then - export LONB=${LONB:-$(echo lonb|$SIGHDR ${SIGINP})} - export LATB=${LATB:-$(echo latb|$SIGHDR ${SIGINP})} - export MODEL_OUT_FORM=sigio - export GFSOUT=${SIGINP} - -# run post to read nemsio file if OUTTYP=4 -elif [ ${OUTTYP} -eq 4 ] ; then - export nemsioget=${nemsioget:-$EXECglobal/nemsio_get} - export LONB=${LONB:-$($nemsioget $NEMSINP dimx | awk '{print $2}')} - export LATB=${LATB:-$($nemsioget $NEMSINP dimy | awk '{print $2}')} - export JCAP=${JCAP:-$(expr $LATB - 2)} - # export LONB=${LONB:-$($nemsioget $NEMSINP lonf |grep -i "lonf" |awk -F"= " '{print $2}' |awk -F" " '{print $1}')} - # export LATB=${LATB:-$($nemsioget $NEMSINP latg |grep -i "latg" |awk -F"= " '{print $2}' |awk -F" " '{print $1}')} - # export JCAP=${JCAP:-$($nemsioget $NEMSINP jcap |grep -i "jcap" |awk -F"= " '{print $2}' |awk -F" " '{print $1}')} - - export MODEL_OUT_FORM=${MODEL_OUT_FORM:-binarynemsiompiio} - export GFSOUT=${NEMSINP} - ln -sf $FIXglobal/fix_am/global_lonsperlat.t${JCAP}.${LONB}.${LATB}.txt ./lonsperlat.dat - ln -sf $FIXglobal/fix_am/global_hyblev.l${LEVS}.txt ./global_hyblev.txt -fi - -# allow threads to use threading in Jim's sp lib -# but set default to 1 -export OMP_NUM_THREADS=${OMP_NUM_THREADS:-1} - -pwd=$(pwd) -if [[ -d $DATA ]]; then - mkdata=NO -else - mkdir -p $DATA - mkdata=YES -fi -cd $DATA||exit 99 -################################################################################ -# Post GRIB -export PGM=$POSTGPEXEC -export pgm=$PGM -$LOGSCRIPT -cat <<-EOF >postgp.inp.nml$$ - &NAMPGB - $POSTGPVARS -EOF - -cat <<-EOF >>postgp.inp.nml$$ - / -EOF - -if [[ "$VERBOSE" = "YES" ]]; then - cat postgp.inp.nml$$ -fi - -# making the time stamp format for ncep post -export YY=$(echo $VDATE | cut -c1-4) -export MM=$(echo $VDATE | cut -c5-6) -export DD=$(echo $VDATE | cut -c7-8) -export HH=$(echo $VDATE | cut -c9-10) - -cat > itag <<-EOF - $GFSOUT - ${MODEL_OUT_FORM} - ${GRIBVERSION} - ${YY}-${MM}-${DD}_${HH}:00:00 - GFS - $FLXINP - $D3DINP -EOF - -cat postgp.inp.nml$$ >> itag - -cat itag - -rm -f fort.* - -#ln -sf $SIGINP postgp.inp.sig$$ -#ln -sf $FLXINP postgp.inp.flx$$ -#ln -sf $PGBOUT postgp.out.pgb$$ - -# change model generating Grib number -if [ ${GRIBVERSION} = grib1 ]; then - if [ ${IGEN} -le 9 ] ; then - cat ${CTLFILE}|sed s:00082:0000${IGEN}:>./gfs_cntrl.parm - elif [ ${IGEN} -le 99 ] ; then - cat ${CTLFILE}|sed s:00082:000${IGEN}:>./gfs_cntrl.parm - elif [ ${IGEN} -le 999 ] ; then - cat ${CTLFILE}|sed s:00082:00${IGEN}:>./gfs_cntrl.parm - else - ln -sf ${CTLFILE} ./gfs_cntrl.parm - fi - ln -sf ./gfs_cntrl.parm fort.14 -elif [ ${GRIBVERSION} = grib2 ]; then - cp ${POSTGRB2TBL} . - cp ${PostFlatFile} ./postxconfig-NT.txt - if [ ${ens} = "YES" ] ; then - sed < ${PostFlatFile} -e "s#negatively_pert_fcst#${ens_pert_type}#" > ./postxconfig-NT.txt - fi - # cp ${CTLFILE} postcntrl.xml -fi -export CTL=$(basename $CTLFILE) - -ln -sf griddef.out fort.110 -cp ${PARMglobal}/nam_micro_lookup.dat ./eta_micro_lookup.dat - -${APRUN:-mpirun.lsf} $POSTGPEXEC < itag > outpost_gfs_${VDATE}_${CTL} - -export ERR=$? -export err=$ERR -$ERRSCRIPT||exit 2 - -if [ $FILTER = "1" ] ; then - # Filter SLP and 500 mb height using copygb, change GRIB ID, and then - # cat the filtered fields to the pressure GRIB file, from Iredell - - if [ $GRIBVERSION = grib1 ]; then - $COPYGB -x -i'4,0,80' -k'4*-1,1,102' $PGBOUT tfile - ln -s -f tfile fort.11 - ln -s -f prmsl fort.51 - echo 0 2|$OVERPARMEXEC - $COPYGB -x -i'4,1,5' -k'4*-1,7,100,500' $PGBOUT tfile - ln -s -f tfile fort.11 - ln -s -f h5wav fort.51 - echo 0 222|$OVERPARMEXEC - - #cat $PGBOUT prmsl h5wav >> $PGBOUT - cat prmsl h5wav >> $PGBOUT - elif [ $GRIBVERSION = grib2 ]; then - if [ ${ens} = YES ] ; then - $COPYGB2 -x -i'4,0,80' -k'1 3 0 7*-9999 101 0 0' $PGBOUT tfile - else - $COPYGB2 -x -i'4,0,80' -k'0 3 0 7*-9999 101 0 0' $PGBOUT tfile - fi - $WGRIB2 tfile -set_byte 4 11 1 -grib prmsl - if [ ${ens} = YES ] ; then - $COPYGB2 -x -i'4,1,5' -k'1 3 5 7*-9999 100 0 50000' $PGBOUT tfile - else - $COPYGB2 -x -i'4,1,5' -k'0 3 5 7*-9999 100 0 50000' $PGBOUT tfile - fi - $WGRIB2 tfile -set_byte 4 11 193 -grib h5wav - - #cat $PGBOUT prmsl h5wav >> $PGBOUT - - cat prmsl h5wav >> $PGBOUT - fi -fi - -################################################################################ -# Anomaly concatenation -# for now just do anomaly concentration for grib1 -if [ $GRIBVERSION = grib1 ]; then - if [[ -x $ANOMCATSH ]]; then - if [[ -n $PGIOUT ]]; then - $GRBINDEX $PGBOUT $PGIOUT - fi - export PGM=$ANOMCATSH - export pgm=$PGM - $LOGSCRIPT - - eval $ANOMCATSH $PGBOUT $PGIOUT - - export ERR=$? - export err=$ERR - $ERRSCRIPT||exit 3 - fi -fi -################################################################################ -# Make GRIB index file -if [[ -n $PGIOUT ]]; then - if [ $GRIBVERSION = grib2 ]; then - # JY $GRBINDEX2 $PGBOUT $PGIOUT - $GRB2INDEX $PGBOUT $PGIOUT - else - $GRBINDEX $PGBOUT $PGIOUT - fi -fi -if [[ -r $FLXINP && -n $FLXIOUT && $OUTTYP -le 3 ]]; then - $GRBINDEX $FLXINP $FLXIOUT -fi -################################################################################ -# generate psi and chi -echo "GENPSICHI= " $GENPSICHI -if [ $GENPSICHI = YES ] ; then - #echo "PGBOUT PGIOUT=" $PGBOUT $PGIOUT - #echo "YY MM=" $YY $MM - export psichifile=./psichi.grb - $GENPSICHIEXE < postgp.inp.nml$$ - rc=$? - if [[ $rc -ne 0 ]] ; then - echo 'Nonzero return code rc= '$rc - exit 3 - fi - cat ./psichi.grb >> $PGBOUT -fi -################################################################################ -# Postprocessing -cd $pwd -[[ $mkdata = YES ]]&&rmdir $DATA - -exit $err