#!/bin/sh # 9/2013 public domain Wesley Ebisuzaki # 1/2014 use -N for script generations # v1.0 2/2014 updated comments, symbolic variables for gmerge and wgrib2 # cleanup for public release # # wgrib2m is a sh script that runs N copies of wgrib2 for faster speed # or writes a shell script which can run N copies of wgrib2 # Note: only a restricted set of output options are supported # # wgrib2m N (rest of command line) .. runs script # wgrib2m -N (rest of command line) .. writes script # # Only a limited number of output options are supported # # -new_grid, -grib, -grib_out, -small_grib -ijsmall_grib # # checking for unsupported options is not comprehensive # wgrib2 and gmerge are assumed to be on your $PATH # UGRD and VGRD are assumed to be in same message (for interpolation) # Only UGRD/VGRD are supported for vector interpolation (copygb default) # # requires wgrib2, gmerge, seq (unix/linux command) # arg="$*" if [ "$1" -gt 1 ] ; then export ncpu="$1" export X=eval elif [ "$1" -lt -1 ] ; then export ncpu=`expr 0 - $1` export X=echo else echo "$0 N restricted wgrib2 options" echo " if N > 1, runs N copies of wgrib2" echo " if N < 1, writes script for running -N copies of wgrib2" echo " wgrib2 output options supported: -new_grid, -grib, -grib_out, -small_grib -ijsmall_grib" echo " wgrib2 and gmerge must be on your PATH." exit 8 fi shift newarg="" nout=0 # gmerge=$HOME/bin/gmerge gmerge='gmerge' # wgrib2=$HOME/bin/wgrib2 wgrib2='wgrib2' # set -x # echo..to capture script, eval..to run # prefix cannot contain equal sign prefix=/tmp/$$ $X export OMP_NUM_THREADS=1 # process wgrib2 options, change output files to pipe.$nout while [ $# -ge 1 ] do if [ "$1" = "-new_grid" ] ; then nout=`expr $nout + 1` newarg="$newarg \"$1\" \"$2\" \"$3\" \"$4\" _pipe.$nout" eval outfile$nout=$5 if [ $# -lt 5 ] ; then echo "help missing output file" exit 8 fi shift 5 continue fi if [ "$1" = "-grib" -o "$1" = "-grib_out" ] ; then nout=`expr $nout + 1` newarg="$newarg \"$1\" _pipe.$nout" eval outfile$nout=$2 if [ $# -lt 2 ] ; then echo "help missing output file" exit 8 fi shift 2 continue fi if [ "$1" = "-small_grib" -o "$1" = "-ijsmall_grib" ] ; then nout=`expr $nout + 1` newarg="$newarg \"$1\" \"$2\" \"$3\" _pipe.$nout" eval outfile$nout=$4 if [ $# -lt 4 ] ; then echo "help missing output file" exit 8 fi shift 4 continue fi if [ "$1" = "-ave" -o "$1" = "-fcst_ave" -o "$1" = "-grib_ieee" ] ; then echo "$0 doesn't support $1 option" exit 8 fi newarg="$newarg \"$1\"" shift 1 done # for every output file, need to make u/v in single field and gmerge all pipes pipelist= for n in `seq 1 $nout` ; do gmerge_pipes= for i in `seq 1 $ncpu` ; do p1=$prefix.pipe.$i.$n p2=$prefix.pipe.$i.$n.b $X "mkfifo $p1 $p2" $X "$wgrib2 -inv /dev/null $p1 -ncep_uv $p2 &" gmerge_pipes="$gmerge_pipes $p2" pipelist="$pipelist $p1 $p2" done eval out=\$outfile$n $X "$gmerge $out $gmerge_pipes &" done for i in `seq 1 $ncpu` ; do tmp=`echo $newarg | sed "s=_pipe=$prefix.pipe.$i=g" ` $X "$wgrib2 -for $i::$ncpu -new_grid_vectors UGRD:VGRD $tmp &" done $X "wait" [ "$pipelist" != "" ] && $X "rm $pipelist"