Skip to content

Commit

Permalink
Updates to GLDAS scripts
Browse files Browse the repository at this point in the history
- Convert from ksh to bash.
- Convert backticks to substitutions.
- Add preamble.
- Remove announcements and general cleanup.

Refs NOAA-EMC#1014
  • Loading branch information
KateFriedman-NOAA committed Sep 8, 2022
1 parent 858cbfc commit 8f45611
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 141 deletions.
15 changes: 3 additions & 12 deletions jobs/JGDAS_ATMOS_GLDAS
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#!/bin/ksh
set -x
#! /usr/bin/env bash

#export RUN_ENVIR=${RUN_ENVIR:-"nco"}
export PS4='$SECONDS + '
date
source "$HOMEgfs/ush/preamble.sh"

#############################
# Source relevant config files
Expand Down Expand Up @@ -96,14 +93,11 @@ export COMINgdas=${COMINgdas:-$ROTDIR}
export DCOMIN=${DCOMIN:-${DCOMROOT:-"/lfs/h1/ops/prod/dcom"}}

export model=${model:-noah}
export MODEL=${MODEL:-`echo $model |tr '[a-z]' '[A-Z]'`}
export MODEL=${MODEL:-$(echo $model |tr '[a-z]' '[A-Z]')}


###############################################################
# Run relevant exglobal script
env
msg="HAS BEGUN on `hostname`"
$LOGSCRIPT

${GLDASSH:-$HOMEgldas/scripts/exgdas_atmos_gldas.sh}
status=$?
Expand All @@ -120,14 +114,11 @@ if [ -e "$pgmout" ] ; then
cat $pgmout
fi

msg="ENDED NORMALLY."

##########################################
# Remove the Temporary working directory
##########################################
cd $DATAROOT
[[ $KEEPDATA = "NO" ]] && rm -rf $DATA

date
exit 0

40 changes: 16 additions & 24 deletions scripts/exgdas_atmos_gldas.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/ksh
#! /usr/bin/env bash

################################################################################
#### UNIX Script Documentation Block
# . .
Expand All @@ -10,12 +11,7 @@
# 20191123 Fanglin Yang, restructure for global workflow
################################################################################

# Set environment
export VERBOSE=${VERBOSE:-"YES"}
if [ $VERBOSE = "YES" ]; then
echo $(date) EXECUTING $0 $* >&2
set -x
fi
source "$HOMEgfs/ush/preamble.sh"

#################################
# Set up UTILITIES
Expand All @@ -42,20 +38,20 @@ export COMPONENT=${COMPONENT:-atmos}
export assim_freq=${assim_freq:-6}
export gldas_spinup_hours=${gldas_spinup_hours:-72}
export gldas_cdate=$CDATE
export gldas_eymd=`echo $gldas_cdate |cut -c 1-8`
export gldas_ecyc=`echo $gldas_cdate |cut -c 9-10`
export gldas_sdate=`$NDATE -$gldas_spinup_hours $CDATE`
export gldas_symd=`echo $gldas_sdate |cut -c 1-8`
export gldas_scyc=`echo $gldas_sdate |cut -c 9-10`
export gldas_eymd=$(echo $gldas_cdate |cut -c 1-8)
export gldas_ecyc=$(echo $gldas_cdate |cut -c 9-10)
export gldas_sdate=$($NDATE -$gldas_spinup_hours $CDATE)
export gldas_symd=$(echo $gldas_sdate |cut -c 1-8)
export gldas_scyc=$(echo $gldas_sdate |cut -c 9-10)

export iau_cdate=$CDATE
if [ "$DOIAU" = "YES" ]; then
IAU_OFFSET=${IAU_OFFSET:-0}
IAUHALH=$((IAU_OFFSET/2))
export iau_cdate=`$NDATE -$IAUHALH $CDATE`
export iau_cdate=$($NDATE -$IAUHALH $CDATE)
fi
export iau_eymd=`echo $iau_cdate |cut -c 1-8`
export iau_ecyc=`echo $iau_cdate |cut -c 9-10`
export iau_eymd=$(echo $iau_cdate |cut -c 1-8)
export iau_ecyc=$(echo $iau_cdate |cut -c 9-10)
echo "GLDAS runs from $gldas_sdate to $iau_cdate"

export CASE=${CASE:-C768}
Expand Down Expand Up @@ -119,15 +115,15 @@ elif [ $JCAP -eq 382 ]; then
elif [ $JCAP -eq 190 ]; then
gds='255 4 384 192 89284 0 128 -89284 -938 938 96 0 0 0 0 0 0 0 0 0 255 0 0 0 0 0'
else
echo "JCAP=$JCAP no supportted, exit"
echo "JCAP=$JCAP not supported, exit"
export err=4
$ERRSCRIPT || exit 4
fi

echo $JCAP
echo $gds
ymdpre=`sh $FINDDATE $gldas_symd d-1`
ymdend=`sh $FINDDATE $gldas_eymd d-2`
ymdpre=$(sh $FINDDATE $gldas_symd d-1)
ymdend=$(sh $FINDDATE $gldas_eymd d-2)
ymd=$ymdpre

if [ $USE_CFP = "YES" ] ; then
Expand All @@ -154,7 +150,7 @@ while [ $ymd -le $ymdend ]; do
$COPYGB -i3 -g"$gds" -x $GDAS/cpc.$ymd/precip.gldas.${ymd}18 $RUNDIR/cmap.gdas.${ymd}18
fi
fi
ymd=`sh $FINDDATE $ymd d+1`
ymd=$(sh $FINDDATE $ymd d+1)
done

if [ $USE_CFP = "YES" ] ; then
Expand Down Expand Up @@ -258,7 +254,7 @@ $ERRSCRIPT || exit 8

# 5c) use gldas_post to replace soil moisture and temperature

yyyy=`echo $iau_eymd | cut -c1-4`
yyyy=$(echo $iau_eymd | cut -c1-4)
gbin=$RUNDIR/EXP901/NOAH/$yyyy/$iau_eymd/LIS.E901.${iau_eymd}${iau_ecyc}.NOAHgbin
sfcanl=sfc.gaussian.nemsio
rm -rf fort.11 fort.12
Expand Down Expand Up @@ -320,9 +316,5 @@ fi
# Clean up before leaving
if [ $mkdata = "YES" ]; then rm -rf $DATA; fi

set +x
if [ $VERBOSE = "YES" ] ; then
echo $(date) EXITING $0 with return code $err >&2
fi
exit $err

38 changes: 14 additions & 24 deletions ush/gldas_archive.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/ksh
#! /usr/bin/env bash
#
#########################################################
# This script collects gldas output to archive directory
Expand All @@ -13,44 +13,34 @@
# RUNDIR - run directory
# GDAS - /lfs/h1/ops/prod/com/gfs/prod
#
# gldas runs 72 hrs, from day1.00z to day4.00z
# first 36 hr obs precip forcing
# second 36 hrs gdas model forcing to bring it to realtime.
#
# save all output to day1 directory
# save noah.rst.day2 to day2 directory for next day restart
# save gdas.t00z.sfcanl.nemsio.gldas.day4 to day4 directory for gfs restart
#
# script history:
# 20190604 Jesse Meng - first version
# 20191010 Youlong Xia - modified
#########################################################
set -ux

source "$HOMEgfs/ush/preamble.sh"

if [ $# -lt 1 ]; then
echo "usage: ksh $0 sdate [edate]"
exit $?
echo "usage: $0 sdate [edate]"
exit $?
fi

sdate=$1
edate=`sh $FINDDATE $1 d+1`
edate=$(sh $FINDDATE $1 d+1)
if [ $# -gt 1 ]; then edate=$2 ; fi

yyyy=`echo $sdate | cut -c1-4`
yyyy=$(echo $sdate | cut -c1-4)

### save all output to day1 directory
export COMDIR=${COM_OUT}

mkdir -p $COMDIR/gldas.$sdate
yyyymmdd=`sh $FINDDATE $sdate d+1`
yyyymmdd=$(sh $FINDDATE $sdate d+1)
while [ $yyyymmdd -le $edate ]; do

mkdir -p $COMDIR/gldas.$yyyymmdd

yyyy=`echo $yyyymmdd | cut -c1-4`
yyyy=$(echo $yyyymmdd | cut -c1-4)
cp $RUNDIR/EXP901/NOAH/$yyyy/$yyyymmdd/* $COMDIR/gldas.$sdate

yyyymmdd=`sh $FINDDATE $yyyymmdd d+1`
yyyymmdd=$(sh $FINDDATE $yyyymmdd d+1)
done

cp $RUNDIR/sfc.gaussian.nemsio.$sdate $COMDIR/gldas.$sdate
Expand All @@ -61,16 +51,16 @@ yyyymmdd=$sdate
while [ $yyyymmdd -lt $edate ]; do

day1=$yyyymmdd
day2=`sh $FINDDATE $yyyymmdd d+1`
day2=$(sh $FINDDATE $yyyymmdd d+1)
mv $COMDIR/gldas.$sdate/LIS.E901.${day2}00.NOAH.grb $COMDIR/gldas.$sdate/LIS.E901.${day1}00.NOAH.grb

yyyymmdd=`sh $FINDDATE $yyyymmdd d+1`
yyyymmdd=$(sh $FINDDATE $yyyymmdd d+1)
done

### save noah.rst.day2 to day2 directory for next day gldas restart

yyyymmdd=`sh $FINDDATE $sdate d+1`
yyyy=`echo $yyyymmdd | cut -c1-4`
yyyymmdd=$(sh $FINDDATE $sdate d+1)
yyyy=$(echo $yyyymmdd | cut -c1-4)
mkdir -p $COMDIR/gldas.$edate
cp $RUNDIR/EXP901/NOAH/$yyyy/$edate/LIS.E901.${edate}00.Noahrst $COMDIR/gldas.$yyyymmdd/noah.rst.$edate

Expand Down
22 changes: 7 additions & 15 deletions ush/gldas_forcing.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
#!/bin/ksh
#! /usr/bin/env bash
###########################################################################
# this script gets cpc daily precipitation and using gdas hourly precipitation
# to disaggregate daily value into hourly value
# 20190509 Jesse Meng - first version
# 20191008 Youlong Xia - modified
# 20191123 Fanglin Yang - restructured for global-workflow
###########################################################################

source "$HOMEgfs/ush/preamble.sh"

bdate=$1
edate=$2

# Set environment
export VERBOSE=${VERBOSE:-"YES"}
if [ $VERBOSE = "YES" ]; then
echo $(date) EXECUTING $0 $* >&2
set -x
fi

# HOMEgldas - gldas directory
# EXECgldas - gldas exec directory
# PARMgldas - gldas param directory
Expand All @@ -29,11 +21,11 @@ export ERRSCRIPT=${ERRSCRIPT:-'eval [[ $err = 0 ]]'}
#-------------------------------
#--- extract variables of each timestep and create forcing files
sdate=$bdate
edate=`sh $FINDDATE $edate d-1`
edate=$(sh $FINDDATE $edate d-1)
while [ $sdate -lt $edate ]; do
#-------------------------------

sdat0=`sh $FINDDATE $sdate d-1`
sdat0=$(sh $FINDDATE $sdate d-1)
[[ ! -d $xpath/cpc.${sdate} ]] && mkdir -p $xpath/cpc.${sdate}
[[ ! -d $xpath/cpc.${sdat0} ]] && mkdir -p $xpath/cpc.${sdat0}

Expand All @@ -43,7 +35,7 @@ rm -f fort.* grib.*
COMPONENT=${COMPONENT:-"atmos"}
pathp1=$CPCGAUGE/gdas.$sdate/00/$COMPONENT
pathp2=$DCOMIN/$sdate/wgrbbul/cpc_rcdas
yyyy=`echo $sdate |cut -c 1-4`
yyyy=$(echo $sdate |cut -c 1-4)
cpc_precip="PRCP_CU_GAUGE_V1.0GLB_0.125deg.lnx.$sdate.RT"
if [ $RUN_ENVIR = "emc" ] && [ $sdate -gt $bdate ]; then
cpc_precip="PRCP_CU_GAUGE_V1.0GLB_0.125deg.lnx.$sdate.RT_early"
Expand Down Expand Up @@ -116,7 +108,7 @@ cp fort.24 $xpath/cpc.$sdate/precip.gldas.${sdate}06
rm -f fort.* grib.*

#-------------------------------
sdate=`sh $FINDDATE $sdate d+1`
sdate=$(sh $FINDDATE $sdate d+1)
done
#-------------------------------

Expand Down
19 changes: 6 additions & 13 deletions ush/gldas_get_data.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
#!/bin/ksh
#! /usr/bin/env bash
#########################################################
# This script generate gldas forcing from gdas prod sflux
# script history:
# 20190509 Jesse Meng - first version
# 20191008 Youlong Xia - modified
# 20191123 Fanglin Yang - restructured for global-workflow
#########################################################

export VERBOSE=${VERBOSE:-"YES"}
if [ $VERBOSE = "YES" ]; then
echo $(date) EXECUTING $0 $* >&2
set -x
fi
source "$HOMEgfs/ush/preamble.sh"

bdate=$1
edate=$2
Expand All @@ -32,15 +25,15 @@ cycint=${assim_freq:-6}
# get gdas flux files to force gldas.
# CPC precipitation is from 12z to 12z. One more day of gdas data is
# needed to disaggregate daily CPC precipitation values to hourly values
cdate=`$NDATE -12 $bdate`
cdate=$($NDATE -12 $bdate)

iter=0

#-------------------------------
while [ $cdate -lt $edate ]; do
#-------------------------------
ymd=`echo $cdate |cut -c 1-8`
cyc=`echo $cdate |cut -c 9-10`
ymd=$(echo $cdate |cut -c 1-8)
cyc=$(echo $cdate |cut -c 9-10)
[[ ! -d $fpath/gdas.${ymd} ]] && mkdir -p $fpath/gdas.${ymd}
[[ ! -d $gpath/gdas.${ymd} ]] && mkdir -p $gpath/gdas.${ymd}

Expand Down Expand Up @@ -73,7 +66,7 @@ while [ $f -le $cycint ]; do
done

#-------------------------------
cdate=`$NDATE +$cycint $cdate`
cdate=$($NDATE +$cycint $cdate)
done
#-------------------------------

Expand Down
25 changes: 14 additions & 11 deletions ush/gldas_liscrd.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
#!/bin/sh
#! /usr/bin/env bash

source "$HOMEgfs/ush/preamble.sh"

if [ $# -lt 3 ]; then
echo usage $0 yyyymmddhh1 yyyymmddhh2 126/382/574/1534
exit $?
echo usage $0 yyyymmddhh1 yyyymmddhh2 126/382/574/1534
exit $?
fi

date1=$1
date2=$2
grid=$3

export yyyy1=`echo $date1 | cut -c 1-4`
export mm1=`echo $date1 | cut -c 5-6`
export dd1=`echo $date1 | cut -c 7-8`
export hh1=`echo $date1 | cut -c 9-10`
export yyyy2=`echo $date2 | cut -c 1-4`
export mm2=`echo $date2 | cut -c 5-6`
export dd2=`echo $date2 | cut -c 7-8`
export hh2=`echo $date2 | cut -c 9-10`
export yyyy1=$(echo $date1 | cut -c 1-4)
export mm1=$(echo $date1 | cut -c 5-6)
export dd1=$(echo $date1 | cut -c 7-8)
export hh1=$(echo $date1 | cut -c 9-10)
export yyyy2=$(echo $date2 | cut -c 1-4)
export mm2=$(echo $date2 | cut -c 5-6)
export dd2=$(echo $date2 | cut -c 7-8)
export hh2=$(echo $date2 | cut -c 9-10)
export grid=$grid
export PARM_LM=${PARMgldas}
export LISCARD=lis.crd
Expand Down
16 changes: 7 additions & 9 deletions ush/gldas_post.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#/bin/sh
set -x
#! /usr/bin/env bash

source "$HOMEgfs/ush/preamble.sh"

if [ $# -lt 2 ]; then
echo "usage: $0 gldas.gbin gdas.sfcanl"
err_exit 99
echo "usage: $0 gldas.gbin gdas.sfcanl"
err_exit 99
fi

cd $RUNDIR
Expand All @@ -18,12 +19,9 @@ rm -f fort.11 fort.12 fort.22
cp $gbin fort.11
cp $sfcanl fort.12

echo 'running NOAH model'
startmsg
${EXECgldas}/gldas_post >>$pgmout 2>errfile
export err=$?; err_chk
${EXECgldas}/gldas_post >>$pgmout 2>errfile
export err=$?; err_chk

##cp fort.22 ${sfcanl}.gldas
cp fort.22 ./gldas.nemsio
cp fort.22 ${sfcanl}.gldas
rm -f fort.11 fort.12 fort.22
Expand Down
Loading

0 comments on commit 8f45611

Please sign in to comment.