#! /bin/bash # invoke gnuplot to compare crop output from WEPS generated runs. # invocation: allshoot [Col num] [file-1 file-2 ... file-#] # set up column and title correspondence mincol=5 maxcol=19 calcol=19 coltitle[5]=`echo "5) Shoot Heat Unit Index (end of shoot grow) (C)"` coltitle[6]=`echo "6) Storage root mass sum (total in all layers) (kg/m^2)"` coltitle[7]=`echo "7) Fibrous root mass sum (total in all layers) (kg/m^2)"` coltitle[8]=`echo "8) Mass required from root mass for one shoot (mg/shoot)"` coltitle[9]=`echo "9) Total shoot mass at end of shoot growth period (mg/shoot)"` coltitle[10]=`echo "10) Total root mass at end of shoot growth period (mg/shoot)"` coltitle[11]=`echo "11) Mass increment added to roots for the present day (mg/shoot)"` coltitle[12]=`echo "12) Mass increment added to shoot for the present day (mg/shoot)"` coltitle[13]=`echo "13) Mass increment removed from storage roots for the present day (mg/shoot)"` coltitle[14]=`echo "14) Total stem mass at end of shoot growth period (mg/shoot)"` coltitle[15]=`echo "15) Total stem area at end of shoot growth period (m^2/shoot)"` coltitle[16]=`echo "16) Total shoot length at end of shoot growth period (m)"` coltitle[17]=`echo "17) Length of actively growing shoot from root biomass (m)"` coltitle[18]=`echo "18) Crop shoot mass grown from root storage (kg/m^2)"` coltitle[19]=`echo "19) Number of crop stems per unit area (#/m^2)"` # grab column number and shift command arguments colnum=$1 shift if [[ ${colnum} = "" ]] then echo 'invocation: allcrop [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: allcrop [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 $calcol ]] then echo 'invocation: allcrop [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 $maxcol ]] then # special case calculated from columns let nfile=0 for nf in $* do # create filename array let nfile=nfile+1 filename[nfile]="$nf" # find number of index blocks linecount=`wc -l < ${nf}` lineswithnumbers=`grep -c '\.' < ${nf}` let fileindex=(linecount-lineswithnumbers-2)/2 #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 # write single instance lines top plot file echo "" > temp.plt echo "set yrange [0:${allmaxval}]" >> temp.plt # echo "set yrange [0:0.2]" >> temp.plt for ind in $(seq $numindex) do echo "index = $ind" # create graph title line echo "set title 'Crop Year ${ind}'" >> temp.plt #create plot lines for each file for num in $(seq $nfile) do let indm=ind-1 plotline[num]="'${filename[num]}' index ${indm} using 4:$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 -1" >> temp.plt done gnuplot temp.plt exit fi # determine number of index blocks in each series by looping through # command arguments 1 to # let nfile=0 for nf in $* do # create filename array let nfile=nfile+1 filename[nfile]="$nf" # find number of index blocks linecount=`wc -l < ${nf}` lineswithnumbers=`grep -c '\.' < ${nf}` let fileindex=(linecount-lineswithnumbers-2)/2 #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" echo " ${nf} checking number of days maximum value" # find selected column maximum value for this file filemaxdays=`dm "if x4 then x4 else SKIP" < ${nf} | stats max` #echo "filemaxdays now equal to $filemaxdays" # check for maximum of all files allmaxdays=`echo "$filemaxdays $allmaxdays" | stats max` echo "allmaxdays now equal to $allmaxdays" done # 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 echo "set xrange [0:${allmaxdays}]" > temp.plt echo "set yrange [0:${allmaxval}]" >> temp.plt for ind in $(seq $numindex) do echo "index = $ind" # create graph title line echo "set title '${titlebase}, Crop Year ${ind}'" >> temp.plt #create plot lines for each file for num in $(seq $nfile) do let indm=ind-1 plotline[num]="'${filename[num]}' index ${indm} using 4:$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 -1" >> temp.plt done gnuplot temp.plt #rm temp.plt