#! /bin/bash # invoke gnuplot to compare hydrology output from WEPS generated runs. # invocation: profileplot [Col_num file-1] [Col_num file-2] ... [Col_num file-#] # set up column and title correspondence # set up column and title correspondence mincol=6 maxcol=19 coltitle[6]=`echo "6) Volumetric Water Content (m/m)"` coltitle[7]=`echo "7) Saturated Vol Water Cont (m/m)"` coltitle[8]=`echo "8) Field Capacity Vol Water Cont (m/m)"` coltitle[9]=`echo "9) Permanent Wilting Point Vol Water Cont (m/m)"` coltitle[10]=`echo "10) Residual Vol Water Cont (m/m)"` coltitle[11]=`echo "11) Fraction Crop Available Water"` coltitle[12]=`echo "12) Saturation Ratio"` coltitle[13]=`echo "13) Soil Temperature (C)"` coltitle[14]=`echo "14) Unsaturated hydraulic Conductivity (m/s)"` coltitle[15]=`echo "15) Matric Potential (m)"` coltitle[16]=`echo "16) Soil Relative Humidity (fraction)"` coltitle[17]=`echo "17) Bulk Density (Mg/m^3)"` coltitle[18]=`echo "18) Air Entry Potential (m)"` coltitle[19]=`echo "19) Brooks and Corey Exponent b =(1/lambda)"` # create column number, file name pairs # screen column numbers for valid values # determine number of index blocks in each series # check for presence of command arguments if [ ! -n "$1" ] then echo 'invocation: profileplot [Col_num file-1] [Col_num file-2] ... [Col_num file-#]' echo 'Valid Column Numbers are:' for num in $( seq $mincol $maxcol ) do echo ${coltitle[num]} done exit fi # grab and count command arguments let ncmdarg=0 for ncmd in $* do let ncmdarg=ncmdarg+1 cmdarg[ncmdarg]="$ncmd" # echo "Command argument $ncmdarg = ${cmdarg[ncmdarg]}" done # create paired column number, file name list # sequence counts by 2 let nfile=0 for ncol in $( seq 1 2 $ncmdarg ) do # increment paired index let nfile=nfile+1 # create column number array colnum[nfile]="${cmdarg[ncol]}" # create index to second member of pair let narg=ncol+1 # create filename array filename[nfile]="${cmdarg[narg]}" #echo "Column number = ${colnum[nfile]} File name = ${filename[nfile]}" # find number of index blocks in this file linecount=`wc -l < ${filename[nfile]}` lineswithnumbers=`grep -c '\.' < ${filename[nfile]}` let fileindex=(linecount-lineswithnumbers-1)/2 #echo "fileindex = ${fileindex}" # check to use minimum of all files numindex=`echo "$fileindex $numindex" | stats min` #echo "numindex now equal to $numindex" if [[ ${colnum[nfile]} = "" ]] then echo 'invocation: allhydro [Col_num file-1] [Col_num file-2] ... [Col_num file-#]' echo 'Valid Column Numbers are:' for num in $( seq $mincol $maxcol ) do echo ${coltitle[num]} done exit elif [[ ${colnum[nfile]} -lt $mincol ]] then echo 'invocation: allhydro [Col_num file-1] [Col_num file-2] ... [Col_num file-#]' echo 'Valid Column Numbers are:' for num in $( seq $mincol $maxcol ) do echo ${coltitle[num]} done exit elif [[ ${colnum[nfile]} -gt $maxcol ]] then echo 'invocation: allhydro [Col_num file-1] [Col_num file-2] ... [Col_num file-#]' echo 'Valid Column Numbers are:' for num in $( seq $mincol $maxcol ) do echo ${coltitle[num]} done exit fi done # rather than loop within gnuplot, create specific plot lines # for each year so these parameters can be added to the # title of the graph. # determine number of index blocks in each series by looping through # command arguments 1 to # for num in $(seq $nfile) do echo "${filename[num]} checking index count" # find number of year blocks (output has years separated by 2 blank lines making these index blocks as well) fileindex=`dm "if x3>0 then x3 else SKIP" < ${filename[num]} | dm y2 x1 | dm "if x1=x2 then SKIP else 1" | stats sum` #echo "fileindex = ${fileindex}" # check to use minimum of all files numindex=`echo "$fileindex $numindex" | stats min` #echo "numindex now equal to $numindex" echo " ${filename[num]} checking column maximum value" # find selected column maximum value for this file filemaxval=`dm "if x${colnum[num]}>0 then x${colnum[num]} else SKIP" < ${filename[num]} | stats max` #echo "filemaxval now equal to $filemaxval" # check for maximum of all files allmaxval=`echo "$filemaxval $allmaxval" | stats max` echo "allmaxval now equal to $allmaxval" done # creates multiple files to loop through years and day blocks using # the looping capabilities of gnuplot # clears plot file if it exists echo '' > temp.plt # write single instance lines top first plot file echo "year = 0" >> temp.plt echo "set yrange [:] reverse" >> temp.plt if [[ ${colnum[1]} -eq 14 ]] then echo "set logscale x" >> temp.plt echo "set xrange [:${allmaxval}]" >> temp.plt elif [[ ${colnum[1]} -eq 15 ]] then echo "set logscale x" >> temp.plt echo "set xrange [:${allmaxval}]" >> temp.plt elif [[ ${colnum[1]} -eq 13 ]] then echo "set xrange [:${allmaxval}]" >> temp.plt else echo "set xrange [0:${allmaxval}]" >> temp.plt fi # create call to second control file echo "call 'temp0.plt'" >> temp.plt # create year control file as second plot file # clears plot file if it exists echo '' > temp0.plt echo "yday = 0" >> temp0.plt echo "call 'temp1.plt' year" >> temp0.plt echo "year = year + 1" >> temp0.plt echo "if(year < ${numindex}) reread" >> temp0.plt # create day control file as third plot file # clears plot file if it exists echo '' > temp1.plt echo "call 'temp2.plt' year yday" >> temp1.plt echo "print \"year: \", year+1, \" day: \", yday+1" >> temp1.plt echo "pause -1" >> temp1.plt echo "yday = yday + 1" >> temp1.plt echo "if(yday < 365) reread" >> temp1.plt # create plot lines for each data input file as fourth plot file # clears plot file if it exists echo '' > temp2.plt for num in $(seq $nfile) do plotline[num]="'${filename[num]}' index year every :::\$1::\$1 using ${colnum[num]}:5 with linespoints title '${filename[num]}', \\" done # add plot command to first plotline plotline[1]=`echo "${plotline[1]}" | sed -e 's/^.*/plot &/'` # strip last plotline of 3 extra characters plotline[nfile]=`echo "${plotline[nfile]}" | sed -e 's/...$//'` # write out plot lines to file for num in $(seq $nfile) do echo ${plotline[num]} >> temp2.plt done gnuplot temp.plt #rm temp.plt #rm temp0.plt #rm temp1.plt #rm temp2.plt