#!/bin/bash # plots out summary statistics by month from cligen input files # USEAGE: clistatplot [cligen file 1]... [cligen file #] # cligen file can be either a single location entry extracted from the cligen database # or a file generated by cligen version 5 or later. # clear plot file since all writes are appends rm -f temp.plt # create array of values to compare valname=(Tmax Tmin Tdew) # create array of statistics to compare valstat=(mean sd) # loop through all combinations for vname in ${valname[@]} do for vstat in ${valstat[@]} do # set screening variables based on vname vstat selection case $vname in Tmax) clicol=8 case $vstat in mean) gtoken="TMAX AV" outfile="tmaxmean";; sd) gtoken="SD TMAX" outfile="tmaxsd";; esac;; Tmin) clicol=9 case $vstat in mean) gtoken="TMIN AV" outfile="tminmean";; sd) gtoken="SD TMIN" outfile="tminsd";; esac;; Tdew) clicol=13 case $vstat in mean) gtoken="DEW PT" outfile="tdewmean";; sd) gtoken="SD TMAX" outfile="tdewsd";; esac;; esac case $vstat in mean) basecon=32;; sd) basecon=0;; esac # 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 "CLIGEN VER. 5" ${namefile}` then # valid cligen file let maxn=maxn+1 echo "valid cligen generated file" maxmon=12 rm -f temp1 for month in $(seq $maxmon) do dm "if INLINE > 15 then INPUT else NEXT" < ${namefile} | \ dm "if x2==$month then INPUT else NEXT" | \ dm x$clicol | stats $vstat >> temp1 done let maxnp=maxn+1 plotline[maxn]="'$outfile' using 1:$maxnp with linespoints title '$namefile', \\" elif `grep -q -s "LATT=.*LONG=.*YEARS=.*TYPE=" ${namefile}` then # cligen input record let maxn=maxn+1 echo "valid cligen data record file" # grab line, # strip text, add space where columns touch (tmax>100degF, tmin<-10), # convert from line to column format, convert from deg F to deg C grep "$gtoken" ${namefile} | \ sed -e "s/$gtoken//" -e 's/1..\./ &/g' -e 's/-/ -/g' | \ transpose | dm "(x1-$basecon)*5/9" > temp1 # for dew point standard deviation, grab Tmin sd line, convert and average with Tmax sd if [ "$vname" == "Tdew" ] then if [ "$vstat" == "sd" ] then gtoken="SD TMIN" grep "$gtoken" ${namefile} | \ sed -e "s/$gtoken//" -e 's/1..\./ &/g' -e 's/-/ -/g' | \ transpose | dm "(x1-$basecon)*5/9" > temp2 abut temp2 temp1 | dm '(x1+x2)/2' > temp3 cp temp3 temp1 fi fi let maxnp=maxn+1 plotline[maxn]="'$outfile' using 1:$maxnp with linespoints title '$namefile', \\" 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 $vstat'" >> temp.plt echo "set xdata time" >> temp.plt echo 'set timefmt "%b"' >> temp.plt echo 'set format x "%b"' >> temp.plt for num in $(seq $maxn) do echo ${plotline[num]} >> temp.plt done echo "pause -1 'next plot?'" >> temp.plt done done # and do two correlations valname=(Correl_Tmax_Tmin Correl_Tmin_Tdew) # loop through all combinations for vname in ${valname[@]} do # set up parameters case $vname in Correl_Tmax_Tmin) clicol1=8 clicol2=9 outfile="cortmaxtmin";; Correl_Tmin_Tdew) clicol1=9 clicol2=13 outfile="cortmintdew";; esac # 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 "CLIGEN VERSION 5" ${namefile}` then # valid cligen file let maxn=maxn+1 echo "valid cligen generated file" maxmon=12 rm -f temp1 for month in $(seq $maxmon) do dm "if INLINE > 15 then INPUT else NEXT" < ${namefile} | \ dm "if x2==$month then INPUT else NEXT" | \ dm x$clicol1 x$clicol2 | pair | dm 'if INLINE=13 then x1 else SKIP' >> temp1 done let maxnp=maxn+1 plotline[maxn]="'$outfile' using 1:$maxnp with linespoints title '$namefile', \\" elif `grep -q -s "LATT=.*LONG=.*YEARS=.*TYPE=" ${namefile}` then # cligen input record echo "valid cligen data record file" rm -f temp1 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 temp.plt exit $maxn fi # add columns to outfile if generated if [ -e temp1 ] then abut $outfile temp1 > temp2 cp temp2 $outfile fi 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 for num in $(seq $maxn) do echo ${plotline[num]} >> temp.plt done echo "pause -1 'next plot?'" >> temp.plt done # plot graph gnuplot temp.plt # remove temporary files #rm temp.plt rm temp1 rm temp2 rm -f temp3 #outfile1=(tmaxmean tmaxsd tminmean tminsd tdewmean tdewsd cortmaxtmin cortmintdew) #for ofile in ${outfile1[@]} #do # rm $ofile #done exit