Skip to content

Instantly share code, notes, and snippets.

@tenomoto
Created January 22, 2016 02:01
Show Gist options
  • Save tenomoto/7bccb67f5a9319f3840e to your computer and use it in GitHub Desktop.
Save tenomoto/7bccb67f5a9319f3840e to your computer and use it in GitHub Desktop.
Split JMA one-week ensemble using wgrib
#!/bin/bash
N=25 # number of ensembles
NFT0=9 # number of forecast time (including FT=0)
NFT=9
VNAME=""
while getopts ":v:n:" opt; do
case $opt in
v) VNAME=$OPTARG ;;
n) NFT=$OPTARG ;;
\?) echo 'usage:: splitwfm [-v VARNAME -n NFT] FNAME'
exit 1
esac
done
shift $(($OPTIND-1))
FNAME=$1
if [ -z "$FNAME" ]; then
echo 'usage:: splitwfm [-v VARNAME -n NFT] FNAME'
exit 1
fi
ONAME=`basename $FNAME`
case $ONAME in
WFM12*PLL) NVAR=5 ;;
*) NVAR=4 ;;
esac
echo $ONAME $NVAR
I=1
while ((I<=N)); do
II=`printf %0.2i $I`
if [[ -n $VNAME ]]; then
wgrib $FNAME | grep $VNAME | head -$((NFT0*(I-1)+NFT)) | tail -$NFT | wgrib $FNAME -i -grib -o ${ONAME}_$II.grb
else
wgrib $FNAME | head -$((NFT0*NVAR*(I-1)+NFT*NVAR)) | tail -$((NFT*NVAR)) | wgrib $FNAME -i -grib -o ${ONAME}_$II.grb
fi
((I=I+1))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment