#! /bin/bash # invoke gnuplot to compare single layers out of the volumetric soil water content profiles # from WEPS generated runs. (or a file with the same format) # files are checked for matching years and then plotted for each year # invocation: singlelayersoil [laynum colnum file-1 file-2 ... file-#] # 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)"` # grab layer number and shift command arguments laynum=$1 shift # test if it is a number echo ${laynum} | grep [^0-9] > /dev/null 2>&1 if [ "$?" -eq "0" ] then # laynum is not a number echo '['${laynum}'] is not an integer' echo 'invocation: singlelayersoil [laynum colnum file-1 file-2 ... file-#]' echo 'Please enter a Layer Number as the first value.' exit elif [[ ${laynum} -lt 1 ]] then echo 'invocation: singlelayersoil [laynum colnum file-1 file-2 ... file-#]' echo 'Valid Layer Numbers are 1 to the maximum layers in file.' exit fi # grab column number and shift command arguments colnum=$1 shift # test if it is an integer number echo ${colnum} | grep [^0-9] > /dev/null 2>&1 if [ "$?" -eq "0" ] then echo '['${colnum}'] is not an integer number' echo 'invocation: singlelayersoil [laynum colnum 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: singlelayersoil [laynum colnum 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: singlelayersoil [laynum colnum file-1 file-2 ... file-#]' echo 'Valid Column Numbers are:' for num in $( seq $mincol $maxcol ) do echo ${coltitle[num]} done exit fi # loop through all file names # extract specified layer from each soil layer file and create temporary files let nfile=0 for nf in $* do # create filename array let nfile=nfile+1 filename[nfile]="$nf" selname[nfile]="selfile${nfile}" #echo ${filename[nfile]} ${selname[nfile]} # check for existence of input file if [ -f ${filename[nfile]} ] then # file exists echo "Extracting layer info for file: ${filename[nfile]}" # extract specified layer from file and put results in temporary file # preserve empty lines dm "if (x4=${laynum}) OR (N=0) then INPUT else SKIP" < ${filename[nfile]} > temp # remove single blank lines only and first blank line of double blank line # remove first blank line since script below doesn't dm "if INLINE>1 then INPUT else SKIP" < temp > temp1 # move modifed file back to old location mv temp1 temp # make sure empty lines are blank lines (critical for following scripts) sed 's/ *$//' temp > temp1 # move modifed file back to old location mv temp1 temp # create necessary sed script file # match range of lines containing letters and numbers and ending in blank line echo '/[0-9A-Za-z]/,/^$/{' > sed.tmp # delete the blank line echo '/^$/d' >> sed.tmp echo '}' >> sed.tmp # execute sed script file sed -f sed.tmp temp > temp1 # move modifed file back to old location mv temp1 temp # double remaining blank lines # create necessary sed script file # matches blank line, backslash and newline in file force substitution to include newline echo 's/^$/\' > sed.tmp echo '/' >> sed.tmp # execute sed script file putting result in file to be graphed. sed -f sed.tmp temp > ${selname[nfile]} # find number of index blocks in this file linecount=`wc -l < ${selname[nfile]}` lineswithnumbers=`grep -c '\.' < ${selname[nfile]}` let fileindex=(linecount-lineswithnumbers)/2 #echo "fileindex = ${fileindex}" # check to use minimum of all files numindex=`echo "$fileindex $numindex" | stats min` #echo "numindex now equal to $numindex" # remove temporary files created above rm sed.tmp rm temp else # file does not exist echo "File does not exist. Check the name: ${filename[nfile]}" echo "Continuing without this file." let nfile=nfile-1 fi done # check file count if [ $nfile -eq 0 ] then echo "No valid file names. Check your command line and try again." exit fi # rather than loop within gnuplot, create specific plot lines # for each year so these parameters can be added to the # title of the graph. # associate graph title name with column number specified titlebase=${coltitle[${colnum}]} # write single instance lines top plot file #--- start pdf --- # echo "set terminal pdf" > temp.plt # echo "set output 'soil_lay${laynum}_col${colnum}.pdf'" >> temp.plt # echo "set xrange [0:366]" >> temp.plt # view_pause=0 #--- end pdf --- #--- start screen --- view_pause=-1 echo "set xrange [0:366]" > temp.plt #--- end screen --- if [[ ${colnum} -eq 14 ]] then echo "set logscale y" >> temp.plt elif [[ ${colnum} -eq 13 ]] then echo "set yrange [:]" >> temp.plt else echo "set yrange [0:]" >> temp.plt fi for year in $(seq $numindex) do echo "year = $year" # create graph title line echo "set title '${titlebase}, Year ${year}'" >> temp.plt #create plot lines for each file for num in $(seq $nfile) do let yearm=year-1 plotline[num]="'${selname[num]}' index ${yearm} using 2:${colnum} with lines 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]} >> temp.plt done echo "pause ${view_pause}" >> temp.plt done gnuplot temp.plt #rm temp.plt