#! /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=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 freeze freeze_thaw thaw frozen wetting drying warm_puddling wet_bulk_den #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 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 a number echo ${colnum} | grep [^0-9] > /dev/null 2>&1 if [ "$?" -eq "0" ] then echo '['${colnum}'] is not a 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 15 ]] then echo "set logscale y" >> temp.plt elif [[ ${colnum} -eq 20 ]] then echo "set yrange [0:1.5]" >> 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