#! /bin/bash # invoke gnuplot to compare volumetric soil water content by layer # from either UNSAT-H generated runs or WEPS generated runs. # File types are identified and proper columns selected automatically. # invocation: layplot [file-1 file-2 ... file-#] # determine file types and maximum number of layers by looping through # command arguments 1 to # # set up file types to be screened filetypescreen=(unsat-h theta\(1:layrsn\)) let maxn=0 let numlayers=1000 let numyears=1000 for nf in $* do # check input files for screen in ${filetypescreen[@]} do if `grep -q -s "${screen}" ${nf}` then let maxn=maxn+1 filename[maxn]="$nf" case $screen in unsat-h) filetype[maxn]="unsat-h" # get year span from file minyear=`head < $nf | dm x2 | stats max` maxyear=`tail < $nf | dm x2 | stats max` #echo "Found minyear = $minyear, maxyear = $maxyear" ;; theta\(1:layrsn\)) filetype[maxn]="weps" # get year span from file minyear=`head < $nf | dm x3 | stats max` maxyear=`tail < $nf | dm x3 | stats max` #echo "Found minyear = $minyear, maxyear = $maxyear" ;; esac echo "${filename[maxn]} is ${filetype[maxn]} file" # check number of years in file and use minimum let ny=maxyear-minyear+1 #echo "reduce numyears from $numyears to $ny" numyears=`echo "$ny $numyears" | stats min` #echo "numyears now equal to $numyears" # check number of layers in file and use minimum nl=`sed -n '1p' < ${filename[maxn]} | sed 's/.*numlay =//'` # echo "reduce numlayers from $numlayers to $nl" numlayers=`echo "$nl $numlayers" | stats min` # echo "numlayers now equal to $numlayers" fi done done # now that all file types are known, check types for display options # since UNSAT-H sets it's nodes differently, a direct comparison requires # skipping the first layer if comparison with WEPS files is to be done testtype="${filetype[1]}" for tf in ${filetype[@]} do if [ "$testtype" == "$tf" ] then matchtype="same" else matchtype="diff" fi done #echo "matchtype = $matchtype" #check file types to determine columns selection offset for num in $(seq $maxn) do if [ "${filetype[num]}" == "unsat-h" ] then colx[num]=1 if [ "$matchtype" == "same" ] then colsel[num]=2 elif [ "$matchtype" == "diff" ] then colsel[num]=3 fi elif [ "${filetype[num]}" == "weps" ] then colx[num]=2 colsel[num]=3 fi done # rather than loop within gnuplot, create specific plot lines # for each year and layer so these parameters can be added to the # title of the graph. # write single instance lines top plot file echo "set xrange [0:366]" > temp.plt echo "set yrange [0:0.3]" >>temp.plt for year in $(seq $numyears) do echo "year = $year" for layer in $(seq $numlayers) do echo "set title 'Volumetric Water Content, Year ${year}, Layer ${layer}'" >> temp.plt #create plot lines for each file for num in $(seq $maxn) do let yearm=year-1 plotline[num]="'${filename[num]}' index ${yearm} using ${colx[num]}:${layer}+${colsel[num]} 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[maxn]=`echo "${plotline[maxn]}" | sed -e 's/...$//'` # write out plot lines to file for num in $(seq $maxn) do echo ${plotline[num]} >> temp.plt done echo "pause -1 'next plot?'" >> temp.plt done done gnuplot temp.plt #rm temp.plt exit # this section loops through years and layers using the looping # capabilities of gnuplot (and three separate plot files) #create plot lines for each file for num in $(seq $maxn) do #check file types to determine columns selction offset if [ "${filetype[num]}" == "unsat-h" ] then colx=1 if [ "$matchtype" == "same" ] then colsel=2 elif [ "$matchtype" == "diff" ] then colsel=3 fi elif [ "${filetype[num]}" == "weps" ] then colx=2 colsel=3 fi plotline[num]="'${filename[num]}' index year using ${colx}:layer+$colsel 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[maxn]=`echo "${plotline[maxn]}" | sed -e 's/...$//'` # write out plot files echo "year = 0" > multfile.plt echo "nlay = $numlayers" >> multfile.plt echo "set xrange [0:366]" >> multfile.plt echo "call 'multyearlay.plt'" >> multfile.plt echo "print \"year: \", year+1" > multyearlay.plt echo "layer = 0" >> multyearlay.plt echo "set title 'Volumetric Water Content'" >> multyearlay.plt echo "call 'multlayer.plt'" >> multyearlay.plt echo "year = year + 1" >> multyearlay.plt echo "if(year < $numyears) reread" >> multyearlay.plt echo "layer = layer + 1" > multlayer.plt echo "print \"layer: \", layer" >> multlayer.plt for num in $(seq $maxn) do echo ${plotline[num]} >> multlayer.plt done echo "pause -1 'next plot?'" >> multlayer.plt echo "if(layer < nlay) reread" >> multlayer.plt gnuplot multfile.plt rm multfile.plt rm multyearlay.plt rm multlayer.plt