#! /bin/bash # invoke gnuplot to compare volumetric soil water content profiles # from WEPS generated runs. (or a file with the same format) # files are checked for matching day, month and year and then plotted # on individual days. # invocation: profileplotsoil [colnum file-1 file-2 ... file-#] # set up column and title correspondence mincol=7 maxcol=28 #daysim idoy yr layer depth bszlyt bsdblk bseags bseagmn bseagm bseagmx bslagn bslmin bslagm bslmax bslagx bs0ags bsdagd rel_ag_stab rel_geo_mean coltitle[7]=`echo "7) Bulk Density (Mg/m^3)"` coltitle[8]=`echo "8) Aggregate Stability ln(J/kg)"` coltitle[9]=`echo "9) Minimum Aggregate Stability ln(J/kg)"` coltitle[10]=`echo "10) Mean Aggregate Stability ln(J/kg)"` coltitle[11]=`echo "11) Maximum Aggregate Stability ln(J/kg)"` coltitle[12]=`echo "12) Minimum Aggregate Size (mm)"` coltitle[13]=`echo "13) Minimum GMD Aggregate Size (mm)"` coltitle[14]=`echo "14) GMD Aggregate Size (mm)"` coltitle[15]=`echo "15) Maximum GMD Aggregate Size (mm)"` coltitle[16]=`echo "16) Maximum Aggregate Size (mm)"` coltitle[17]=`echo "17) GSD Aggregate Size (mm)"` coltitle[18]=`echo "18) Aggregate Density (Mg/m^3"` coltitle[19]=`echo "19) Relative Aggregate Stability"` coltitle[20]=`echo "20) Relative GMD Aggregate Size"` coltitle[21]=`echo "21) Freeze Transition"` coltitle[22]=`echo "22) Freeze-Thaw Transition"` coltitle[23]=`echo "23) Thaw Transition"` coltitle[24]=`echo "24) Soil Remains Frozen"` coltitle[25]=`echo "25) Wetting Transition"` coltitle[26]=`echo "26) Drying Transition"` coltitle[27]=`echo "27) Warm Puddling Transition"` coltitle[28]=`echo "28) Bulk Density Change with Wetting"` # grab column number and shift command arguments colnum=$1 shift if [[ ${colnum} = "" ]] then echo 'invocation: profileplot [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: profileplot [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: profileplot [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" # find number of year blocks (output has years separated by 2 blank lines making these index blocks as well) fileindex=`uniq -d ${ufilename[nfile]} | wc -l` #fileindex=`dm "if x3>0 then x3 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" 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 [0:500] reverse" >> temp.plt if [[ ${colnum} -eq 14 ]] then echo "set logscale x" >> temp.plt echo "set xrange [:${allmaxval}]" >> temp.plt elif [[ ${colnum} -eq 15 ]] then echo "set logscale x" >> temp.plt echo "set xrange [:${allmaxval}]" >> temp.plt elif [[ ${colnum} -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}: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