#!/bin/bash # plots out summary statistics by month from hydrology output files # USEAGE: hydrostatplot [hydro.out file 1]... [hydro.out file #] # hydro.out file is file generated by WEPS with hydro submodel output option set # clear plot file since all writes are appends rm -f temp.plt # create table of break points to extract month from day of year monday=(0 31 59 90 120 151 181 212 243 273 304 334 365) # create array of columns to compare #valname=(ahzetp ahzep ahzptp ahzea ahzpta bhzper bhzirr bwzdpt dh2o bhzrun bhzinf lswc swc bhzsnd bhzsno check bczrtd rootwc rootwcap bhfwsf surfdry bwtdav evaplimit vaptrans) # loop through all combinations #for vname in ${valname[@]} #do # grab name of column to be evaluated from command line and shift vname=$1 shift # set screening variables based on vname selection case $vname in ahzetp) hydrocol=4 ;; ahzep) hydrocol=5 ;; ahzptp) hydrocol=6 ;; ahzea) hydrocol=7 ;; ahzpta) hydrocol=8 ;; bhzper) hydrocol=9 ;; bhzirr) hydrocol=10 ;; bwzdpt) hydrocol=11 ;; dh2o) hydrocol=12 ;; bhzrun) hydrocol=13 ;; bhzinf) hydrocol=14 ;; lswc) hydrocol=15 ;; swc) hydrocol=16 ;; bhzsnd) hydrocol=17 ;; bhzsno) hydrocol=18 ;; check) hydrocol=19 ;; bczrtd) hydrocol=20 ;; rootwc) hydrocol=21 ;; rootwcap) hydrocol=22 ;; bhfwsf) hydrocol=23 ;; surfdry) hydrocol=24 ;; bwtdav) hydrocol=25 ;; evaplimit) hydrocol=26 ;; vaptrans) hydrocol=27 ;; *) echo "Possible arguments are: ahzetp ahzep ahzptp ahzea ahzpta bhzper bhzirr bwzdpt dh2o bhzrun bhzinf lswc swc bhzsnd bhzsno check bczrtd rootwc rootwcap bhfwsf surfdry bwtdav evaplimit vaptrans" exit ;; esac outfile="whatever.out" # create base file with column of month names echo "Jan" > $outfile echo "Feb" >> $outfile echo "Mar" >> $outfile echo "Apr" >> $outfile echo "May" >> $outfile echo "Jun" >> $outfile echo "Jul" >> $outfile echo "Aug" >> $outfile echo "Sep" >> $outfile echo "Oct" >> $outfile echo "Nov" >> $outfile echo "Dec" >> $outfile # test input files and save monthly values for each file # loop through command arguments 1 to # let maxn=0 for namefile in $* do echo processing ${namefile} # check input files if `grep -q -s "daysim doy yr" ${namefile}` then # valid cligen file let maxn=maxn+1 echo "valid hydro.out WEPS file" maxmon=12 rm -f temp1 for month in $(seq $maxmon) do begday=${monday[${month}-1]} endday=${monday[${month}]} echo "begday = $begday, endday = $endday" # create data lines for box and whisker plot (mean mean-sd min max mean+sd) dm "if INLINE > 2 then INPUT else NEXT" < ${namefile} | \ dm "if x2>${begday} AND x2<=${endday} then INPUT else NEXT" | \ dm x$hydrocol | stats mean sd min max | \ dm x1 x1-x2 x3 x4 x1+x2 >> temp1 done let maxnp="5*($maxn-1)+2" let maxnp1=$maxnp+1 let maxnp2=$maxnp+2 let maxnp3=$maxnp+3 let maxnp4=$maxnp+4 plotline[maxn]="'$outfile' using 1:${maxnp}:${maxnp1}:${maxnp2} with errorbars lt ${maxn} title '$namefile', '' using 1:${maxnp}:${maxnp3}:${maxnp4} with errorbars lt ${maxn} notitle, \\" #'' using 1:${maxnp} with lines lt ${maxnp} notitle, \\" else # not a valid input file for this plotting routine echo ${namefile} is not a valid input file # remove temporary files rm $outfile rm temp1 rm temp2 rm -f temp3 rm temp.plt exit $maxn fi abut $outfile temp1 > temp2 cp temp2 $outfile done # add plot command to first plotline plotline[1]=`echo "${plotline[1]}" | sed -e 's/^.*/plot &/'` # strip last plotline of 3 extra characters plotline[maxn]=`echo "${plotline[maxn]}" | sed -e 's/...$//'` # create file of plotting commands echo "set title '$vname'" >> temp.plt echo "set xdata time" >> temp.plt echo 'set timefmt "%b"' >> temp.plt echo 'set format x "%b"' >> temp.plt echo 'set bars 10' >> temp.plt for num in $(seq $maxn) do echo ${plotline[num]} >> temp.plt done echo "pause -1 'next plot?'" >> temp.plt # plot graph gnuplot temp.plt # remove temporary files #rm temp.plt rm temp1 rm temp2 rm -f temp3 #rm $outfile #outfile1=(tmaxmean tmaxsd tminmean tminsd tdewmean tdewsd cortmaxtmin cortmintdew) #for ofile in ${outfile1[@]} #do # rm $ofile #done exit