#! /bin/bash # invoke gnuplot to compare soil layer profile values from WEPS # generated runs. (typically water.out or a file with the same format) # files are checked for matching day, month and year and then plotted # on individual days. # invocation: hprofileplot [colnum file-1 file-2 ... file-#] # set up column and title correspondence mincol=7 maxcol=9 coltitle[7]=`echo "7) Layer Water Content (m)"` coltitle[8]=`echo "8) Net Layer Flux (m/s)"` coltitle[9]=`echo "9) Volumetric Water Content (m/m)"` # grab column number and shift command arguments colnum=$1 shift if [[ ${colnum} = "" ]] then echo 'invocation: hprofileplot [Col num] [file-1 file-2 ... file-#]' echo 'Valid Column Numbers are:' for num in $( seq $mincol $maxcol ) do echo ${coltitle[num]} done exit elif [[ ${colnum} -lt $mincol ]] then echo 'invocation: hprofileplot [Col num] [file-1 file-2 ... file-#]' echo 'Valid Column Numbers are:' for num in $( seq $mincol $maxcol ) do echo ${coltitle[num]} done exit elif [[ ${colnum} -gt $maxcol ]] then echo 'invocation: hprofileplot [Col num] [file-1 file-2 ... file-#]' echo 'Valid Column Numbers are:' for num in $( seq $mincol $maxcol ) do echo ${coltitle[num]} done exit fi # determine number of index blocks in each series by looping through # command arguments 1 to # let nfile=0 for nf in $* do echo "${nf} checking index count" # create filename array let nfile=nfile+1 filename[nfile]="$nf" # check number of lines in each block from first line of file neq=`sed -n '1p' < ${nf} | sed 's/.*numlay =//'` # echo "reduce numlayers from $numlayers to $nl" numeq=`echo "$neq $numeq" | stats min` let lastline=numeq-1 # echo "lastline now equal to $lastline" # find number of year blocks (output has years separated by 2 blank lines making these index blocks as well) fileindex=`dm "if x4>0 then x4 else SKIP" < ${nf} | 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 " ${nf} checking column maximum value" # find selected column maximum value for this file filemaxval=`dm "if x${colnum}>0 then x${colnum} else SKIP" < ${nf} | 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" # find selected column minimum value for this file fileminval=`dm "if x${colnum}<0 then x${colnum} else SKIP" < ${nf} | stats min` #echo "fileminval now equal to $fileminval" # check for minimum of all files allminval=`echo "$fileminval $allminval" | stats min` echo "allminval now equal to $allminval" 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 echo "set yrange [0:50] reverse" >> temp.plt if [[ ${allminval} -lt 0 ]] then echo "set xrange [${allminval}:${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 "hblock = 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 hblock" >> temp1.plt echo "print \"year: \", year+1, \" block: \", hblock+1" >> temp1.plt echo "pause -1" >> temp1.plt echo "hblock = hblock + 1" >> temp1.plt echo "if(hblock < 9125) 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 if [[ ${colnum} -eq 9 ]] then # volumetric water content includes surface content (modified every to capture) plotline[num]="'${filename[num]}' index year every ::5:\$1:${lastline}:\$1 using ${colnum}:6 with linespoints title '${filename[num]}', \\" else plotline[num]="'${filename[num]}' index year every ::6:\$1:${lastline}:\$1 using ${colnum}:6 with linespoints title '${filename[num]}', \\" 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[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