#! /bin/bash # invoke gnuplot to compare decomposition output from WEPS generated runs. # invocation: alldecomp [Col_num-1 Col_num-2 ... Colnum-# file-1] [Col_num-1 Col_num-2 ... Colnum-# file-2] ... [Col_num-1 Col_num-2 ... Colnum-# file-#] # set up column and title correspondence mincol=4 maxcol=59 coltitle[4]=`echo "4) Minimum Temperature"` coltitle[5]=`echo "5) Maximum Temperature"` coltitle[6]=`echo "6) Average Temperature"` coltitle[7]=`echo "7) Temperature Factor Above Ground"` coltitle[8]=`echo "8) Water (rain, irrigation, snow melt)"` coltitle[9]=`echo "9) Water Factor Standing Residue"` coltitle[10]=`echo "10) Water Factor Flat Residue"` coltitle[11]=`echo "11) Decomposition Days Standing Residue"` coltitle[12]=`echo "12) Decomposition Days Flat Residue"` coltitle[13]=`echo "13) Mass Standing Age Pool 1"` coltitle[14]=`echo "14) Mass Standing Age Pool 2"` coltitle[15]=`echo "15) Mass Standing Age Pool 3"` coltitle[16]=`echo "16) Mass Standing All Age Pools"` coltitle[17]=`echo "17) Mass Flat Age Pool 1"` coltitle[18]=`echo "18) Mass Flat Age Pool 2"` coltitle[19]=`echo "19) Mass Flat Age Pool 3"` coltitle[20]=`echo "20) Mass Flat All Age Pools"` coltitle[21]=`echo "21) Mass All Above Ground"` coltitle[22]=`echo "22) Mass Buried Age Pool 1"` coltitle[23]=`echo "23) Mass Buried Age Pool 2"` coltitle[24]=`echo "24) Mass Buried Age Pool 3"` coltitle[25]=`echo "25) Mass Buried All Age Pools"` coltitle[26]=`echo "26) Mass Roots Age Pool 1"` coltitle[27]=`echo "27) Mass Roots Age Pool 2"` coltitle[28]=`echo "28) Mass Roots Age Pool 3"` coltitle[29]=`echo "29) Mass Roots All Age Pools"` coltitle[30]=`echo "30) Cover Standing Age Pool 1"` coltitle[31]=`echo "31) Cover Standing Age Pool 2"` coltitle[32]=`echo "32) Cover Standing Age Pool 3"` coltitle[33]=`echo "33) Cover Standing All Age Pools"` coltitle[34]=`echo "34) Cover Flat Age Pool 1"` coltitle[35]=`echo "35) Cover Flat Age Pool 2"` coltitle[36]=`echo "36) Cover Flat Age Pool 3"` coltitle[37]=`echo "37) Cover Flat All Age Pools"` coltitle[38]=`echo "38) Cover Standing + Flat Age Pool 1"` coltitle[39]=`echo "39) Cover Standing + Flat Age Pool 2"` coltitle[40]=`echo "40) Cover Standing + Flat Age Pool 3"` coltitle[41]=`echo "41) Cover Standing + Flat All Age Pools"` coltitle[42]=`echo "42) Stem Area Index Age Pool 1"` coltitle[43]=`echo "43) Stem Area Index Age Pool 2"` coltitle[44]=`echo "44) Stem Area Index Age Pool 3"` coltitle[45]=`echo "45) Stem Area Index All Age Pools"` coltitle[46]=`echo "46) Leaf Area Index Age Pool 1"` coltitle[47]=`echo "47) Leaf Area Index Age Pool 2"` coltitle[48]=`echo "48) Leaf Area Index Age Pool 3"` coltitle[49]=`echo "49) Leaf Area Index All Age Pools"` coltitle[50]=`echo "50) Stem and Leaf Biodrag"` coltitle[51]=`echo "51) Stem Count Age Pool 1"` coltitle[52]=`echo "52) Stem Count Age Pool 2"` coltitle[53]=`echo "53) Stem Count Age Pool 3"` coltitle[54]=`echo "54) Stem Count All Age Pools"` coltitle[55]=`echo "55) Stem Height Age Pool 1"` coltitle[56]=`echo "56) Stem Height Age Pool 2"` coltitle[57]=`echo "57) Stem Height Age Pool 3"` coltitle[58]=`echo "58) Stem Height All Age Pools"` coltitle[59]=`echo "59) Mass Roots Top 4 Inches Soil"` # short column titles shortcoltitle[4]=`echo "4) Tmin"` shortcoltitle[5]=`echo "5) Tmax"` shortcoltitle[6]=`echo "6) Tavg"` shortcoltitle[7]=`echo "7) Tfac above"` shortcoltitle[8]=`echo "8) Water"` shortcoltitle[9]=`echo "9) Wfac stand"` shortcoltitle[10]=`echo "10) Wfac flat"` shortcoltitle[11]=`echo "11) Dday stand"` shortcoltitle[12]=`echo "12) Dday flat"` shortcoltitle[13]=`echo "13) Mstand 1"` shortcoltitle[14]=`echo "14) Mstand 2"` shortcoltitle[15]=`echo "15) Mstand 3"` shortcoltitle[16]=`echo "16) Mstand All"` shortcoltitle[17]=`echo "17) Mflat 1"` shortcoltitle[18]=`echo "18) Mflat 2"` shortcoltitle[19]=`echo "19) Mflat 3"` shortcoltitle[20]=`echo "20) Mflat All"` shortcoltitle[21]=`echo "21) Mabove All"` shortcoltitle[22]=`echo "22) Mburied 1"` shortcoltitle[23]=`echo "23) Mburied 2"` shortcoltitle[24]=`echo "24) Mburied 3"` shortcoltitle[25]=`echo "25) Mburied All"` shortcoltitle[26]=`echo "26) Mroot 1"` shortcoltitle[27]=`echo "27) Mroot 2"` shortcoltitle[28]=`echo "28) Mroot 3"` shortcoltitle[29]=`echo "29) Mroot All"` shortcoltitle[30]=`echo "30) Cstand 1"` shortcoltitle[31]=`echo "31) Cstand 2"` shortcoltitle[32]=`echo "32) Cstand 3"` shortcoltitle[33]=`echo "33) Cstand All"` shortcoltitle[34]=`echo "34) Cflat 1"` shortcoltitle[35]=`echo "35) Cflat 2"` shortcoltitle[36]=`echo "36) Cflat 3"` shortcoltitle[37]=`echo "37) Cflat All"` shortcoltitle[38]=`echo "38) Cstand+flat 1"` shortcoltitle[39]=`echo "39) Cstand+flat 2"` shortcoltitle[40]=`echo "40) Cstand+flat 3"` shortcoltitle[41]=`echo "41) Cstand+flat All"` shortcoltitle[42]=`echo "42) SAI 1"` shortcoltitle[43]=`echo "43) SAI 2"` shortcoltitle[44]=`echo "44) SAI 3"` shortcoltitle[45]=`echo "45) SAI All"` shortcoltitle[46]=`echo "46) LAI 1"` shortcoltitle[47]=`echo "47) LAI 2"` shortcoltitle[48]=`echo "48) LAI 3"` shortcoltitle[49]=`echo "49) LAI All"` shortcoltitle[50]=`echo "50) Biodrag"` shortcoltitle[51]=`echo "51) #stem 1"` shortcoltitle[52]=`echo "52) #stem 2"` shortcoltitle[53]=`echo "53) #stem 3"` shortcoltitle[54]=`echo "54) #stem All"` shortcoltitle[55]=`echo "55) Hstem 1"` shortcoltitle[56]=`echo "56) Hstem 2"` shortcoltitle[57]=`echo "57) Hstem 3"` shortcoltitle[58]=`echo "58) Hstem All"` shortcoltitle[59]=`echo "59) Mroot Top 4"` # set up column groupings tgroups=10 colgroupnum[4]=1 colgroupnum[5]=1 colgroupnum[6]=1 colgroupnum[7]=2 colgroupnum[8]=3 colgroupnum[9]=2 colgroupnum[10]=2 colgroupnum[11]=4 colgroupnum[12]=4 colgroupnum[13]=5 colgroupnum[14]=5 colgroupnum[15]=5 colgroupnum[16]=5 colgroupnum[17]=5 colgroupnum[18]=5 colgroupnum[19]=5 colgroupnum[20]=5 colgroupnum[21]=5 colgroupnum[22]=5 colgroupnum[23]=5 colgroupnum[24]=5 colgroupnum[25]=5 colgroupnum[26]=5 colgroupnum[27]=5 colgroupnum[28]=5 colgroupnum[29]=5 colgroupnum[30]=6 colgroupnum[31]=6 colgroupnum[32]=6 colgroupnum[33]=6 colgroupnum[34]=6 colgroupnum[35]=6 colgroupnum[36]=6 colgroupnum[37]=6 colgroupnum[38]=6 colgroupnum[39]=6 colgroupnum[40]=6 colgroupnum[41]=6 colgroupnum[42]=7 colgroupnum[43]=7 colgroupnum[44]=7 colgroupnum[45]=7 colgroupnum[46]=7 colgroupnum[47]=7 colgroupnum[48]=7 colgroupnum[49]=7 colgroupnum[50]=8 colgroupnum[51]=9 colgroupnum[52]=9 colgroupnum[53]=9 colgroupnum[54]=9 colgroupnum[55]=10 colgroupnum[56]=10 colgroupnum[57]=10 colgroupnum[58]=10 colgroupnum[59]=5 # group y axis labels grouplabel[1]=`echo "Temperature (C)"` grouplabel[2]=`echo "Decomp factor (0-1)"` grouplabel[3]=`echo "Water (mm)"` grouplabel[4]=`echo "Decomp Days"` grouplabel[5]=`echo "Mass (kg/m^2)"` grouplabel[6]=`echo "Cover Fraction"` grouplabel[7]=`echo "Stem/Leam Area Index (m^2/m^2)"` grouplabel[8]=`echo "Drag Coeff"` grouplabel[9]=`echo "Stem Count (#/m^2)"` grouplabel[10]=`echo "Height (m)"` # define range for special group with stacked lines sumgroupmin=45 sumgroupmax=48 sumgrouptotcnt=0 # create column number, file name pairs # screen column numbers for valid values # determine number of index blocks in each series # grab and count command arguments let ncmdarg=0 for ncmd in $* do let ncmdarg=ncmdarg+1 cmdarg[ncmdarg]="$ncmd" # echo "Command argument $ncmdarg = ${cmdarg[ncmdarg]}" done # check command argument count, zero means none if [[ ncmdarg -eq 0 ]] then echo 'invocation: alldecomp [Col_num-1 Col_num-2 ... Colnum-# file-1] [Col_num-1 Col_num-2 ... Colnum-# file-2] ... [Col_num-1 Col_num-2 ... Colnum-# file-#]' echo 'Valid Column Numbers are:' for num in $( seq $mincol $maxcol ) do echo ${coltitle[num]} done exit fi # parse command arguments checking for numbers and when not a number checking for a valid file name # initialize total number of columns parsed tcols=0 # initialize total number of valid file names parsed (must assume one when column numbers preceed file names) tfiles=1 # initialize column count for first file name tcolfile[tfiles]=0 for ncmd in $( seq 1 $ncmdarg ) do # test if it is an integer number echo "${cmdarg[ncmd]}" | grep [^0-9] > /dev/null 2>&1 if [ "$?" -eq "0" ] then # not a column number, check for file name if [ -e "${cmdarg[ncmd]}" ] then # valid file name, check for preceeding columns if [[ tcolfile[tfiles] -gt 0 ]] then # columns are listed in front of this name # back fill column file name pairings for ncol in $( seq 1 ${tcolfile[tfiles]} ) do # write file name let index=(tcols-tcolfile[tfiles])+ncol filename[index]="${cmdarg[ncmd]}" done # add file name to unique file names list ufilename[tfiles]="${cmdarg[ncmd]}" # Increment file number counter let tfiles+=1 # zero out count of special stacked columns sumgrouptotcnt=0 fi # find number of index blocks in this file linecount=`wc -l < ${ufilename[tfiles-1]}` lineswithnumbers=`grep -c '\.' < ${ufilename[tfiles-1]}` let fileindex=(linecount-lineswithnumbers-1)/2 #echo "fileindex = ${fileindex}" # check to use minimum of all files numindex=`echo "$fileindex $numindex" | stats min` #echo "numindex now equal to $numindex" else # not a valid file name, show error message and exit echo \'"${cmdarg[ncmd]}"\' is not valid file name. exit fi else # it is an integer number, check for valid column number if [[ ${cmdarg[ncmd]} -lt $mincol ]] then echo \'"${cmdarg[ncmd]}"\' is a Bad Column Number echo 'invocation: alldecomp [Col_num-1 Col_num-2 ... Colnum-# file-1] [Col_num-1 Col_num-2 ... Colnum-# file-2] ... [Col_num-1 Col_num-2 ... Colnum-# file-#]' echo 'Valid Column Numbers are:' for num in $( seq $mincol $maxcol ) do echo ${coltitle[num]} done exit elif [[ ${cmdarg[ncmd]} -gt $maxcol ]] then echo \'"${cmdarg[ncmd]}"\' is a Bad Column Number echo 'invocation: alldecomp [Col_num-1 Col_num-2 ... Colnum-# file-1] [Col_num-1 Col_num-2 ... Colnum-# file-2] ... [Col_num-1 Col_num-2 ... Colnum-# file-#]' echo 'Valid Column Numbers are:' for num in $( seq $mincol $maxcol ) do echo ${coltitle[num]} done exit fi # valid column number, add into colum number array and increment indexes let tcols+=1 let tcolfile[tfiles]+=1 colnum[tcols]="${cmdarg[ncmd]}" # set column group number colgroup[tcols]=${colgroupnum[${colnum[tcols]}]} # set column file number colfilenum[tcols]=${tfiles} # create column listing for plotting special column group if [ ${colnum[tcols]} -ge ${sumgroupmin} ] && [ ${colnum[tcols]} -le ${sumgroupmax} ] then # add the number of columns that fall into the sum group let "sumgrouptotcnt = sumgrouptotcnt + 1" let "sumgroupcnt[tcols] = sumgrouptotcnt" # stack the values on top of the first one in the order entered if [ ${sumgrouptotcnt} -eq 1 ] then sumgrouplist[tcols]="\$${colnum[tcols]}" else sumgrouplist[tcols]="${sumgrouplist[tcols-1]}+\$${colnum[tcols]}" fi fi fi done # screen for terminating valid file name if [ ! -e "${filename[tcols]}" ] then echo "No terminating file name." echo 'invocation: alldecomp [Col_num-1 Col_num-2 ... Colnum-# file-1] [Col_num-1 Col_num-2 ... Colnum-# file-2] ... [Col_num-1 Col_num-2 ... Colnum-# file-#]' fi # set tfiles to the correct count let tfiles-=1 # echo the resulting arrays of column numbers and file names # echo "The input command line results in the following columns and file names:" # for num in $( seq 1 ${tcols} ) # do # echo "${colnum[num]} ${colgroup[num]} ${filename[num]}" # done # exit # set up graph to column group correspondence # sort group list (result is zero reference array) colgroupsort=(`echo ${colgroup[@]} | transpose | sort | transpose`) # total number of column groups to be plotted tgroups=1 # list of groups represented groupnum[1]=${colgroupsort[0]} let tindex=tcols-1 for num in $( seq 1 ${tindex} ) do let index=num-1 if [[ ${colgroupsort[num]} -ne ${colgroupsort[index]} ]] then let tgroups+=1 groupnum[tgroups]=${colgroupsort[num]} fi done # show groups # echo "unique group numbers" # echo ${groupnum[@]} # exit # find maximum column value for each column and assign that to the maximum for the group for num in $( seq 1 $tcols ) do echo -n " Find maximum value: column ${colnum[num]} in ${filename[num]} : " # find selected column maximum value for this file filemaxval=`dm "if x${colnum[num]}>0 then x${colnum[num]} else SKIP" < ${filename[num]} | stats max` echo "${filemaxval}" # special case for displaying friction velocity and threshold # do not scale according to the soil wetness threshold increase if [ ${colnum[num]} -ne 47 ] && [ ${colnum[num]} -ne 49 ] || [ ${tcols} -eq 1 ] then # check for maximum for this column group for all files if [ ${tcols} -ne 1 ] && [ ${colnum[num]} -ge 45 ] && [ ${colnum[num]} -le 49 ] then # expand maximum a little since not scaled to all maximum filemaxval=$( echo "scale=4; ${filemaxval}*1.2" | bc -l ) fi groupmaxval[${colgroup[num]}]=`echo "$filemaxval ${groupmaxval[${colgroup[num]}]}" | stats max` echo "groupmaxval(${colgroup[num]}) now equal to ${groupmaxval[${colgroup[num]}]}" fi 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[1]}]} # create text for graph title, using file names graphtitle="Files: " for num in $( seq 1 ${tfiles} ) do graphtitle=`echo "${graphtitle} ${num}) ${ufilename[num]} "` done # Set up plot sizes for multiple plots (ie. groups) if [[ $tgroups -gt 1 ]] then # plot sizes for each group psizebase=$( echo "scale=4; 0.9/${tgroups}" | bc -l ) for num in $( seq 1 $tgroups ) do # create coordinates # y size for plot (x is 1.0) if [[ $num -eq 1 ]] then # increase the size of the first plot psize[num]=$( echo "scale=4; ${psizebase}+0.05" | bc -l ) # place plots from the top down in the order specified porigin[num]=$( echo "scale=4; 0.05+($tgroups-$num)*${psizebase}" | bc -l ) elif [[ $num -eq $tgroups ]] then # increase the size of the last plot psize[num]=$( echo "scale=4; ${psizebase}+0.05" | bc -l ) porigin[num]=0 else psize[num]=${psizebase} porigin[num]=$( echo "scale=4; 0.05+($tgroups-$num)*${psizebase}" | bc -l ) fi done 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[1]}]} # write single instance lines top plot file #--- start pdf --- echo "set terminal pdf font 'Helvetica,4'" > temp.plt echo "set output 'alldecomp.pdf'" >> temp.plt view_pause=0 #--- end pdf --- ##--- start emf --- ## create temporary directory for files if needed #tempdir="dtemp" #mkdir -p ${tempdir} ## clear any files #rm ${tempdir}/*.emf #echo "set terminal emf monochrome dashed" > temp.plt #view_pause=0 #echo "set line style 1 lt 1 lw 1" >> temp.plt #echo "set line style 2 lt 2 lw 1" >> temp.plt #echo "set line style 3 lt 3 lw 1" >> temp.plt #echo "set line style 4 lt 4 lw 1" >> temp.plt #echo "set line style 5 lt 5 lw 1" >> temp.plt #echo "set line style 6 lt 1 lw 3" >> temp.plt #echo "set line style 7 lt 2 lw 3" >> temp.plt #echo "set line style 8 lt 3 lw 3" >> temp.plt #echo "set line style 9 lt 4 lw 3" >> temp.plt #echo "set line style 10 lt 5 lw 3" >> temp.plt #echo "set line style 11 lt 1 lw 5" >> temp.plt ##--- end emf --- #--- start screen --- #view_pause=-1 #echo "" > temp.plt #--- end screen --- # set legend location echo "set key left top" >> temp.plt echo "set xrange [0:366]" >> temp.plt #echo "set xrange [0:100]" >> temp.plt for year in $(seq $numindex) do echo "Simulation Year = $year" # # --- emf output files --- # echo "set output '${tempdir}/${year}.emf'" >> temp.plt # zero out special group counter sumgroupcnt=0 # create graph title line echo "set title 'Simulation Yr ${year}, ${graphtitle}'" >> temp.plt # set up single or multiple plot windows if [[ $tgroups -gt 1 ]] then echo "multiple plots" echo "set size 1.0, 1.0" >> temp.plt echo "set origin 0.0, 0.0" >> temp.plt echo "set multiplot" >> temp.plt fi # create plot commands for each group for idx in $( seq 1 $tgroups ) do # only print title once, above first graph if [[ $idx -gt 1 ]] then echo "set title ''" >> temp.plt fi # remove x axis from all but last graph if [[ $idx -lt $tgroups ]] then # remove x axis labels echo "set format x ''" >> temp.plt echo "set xlabel ''" >> temp.plt else # remove x axis labels echo "set format x '% g'" >> temp.plt echo "set xlabel 'Days After Planting'" >> temp.plt fi # individual sizes for multiplots if [[ $tgroups -gt 1 ]] then # set plot size echo "set size 1.0, ${psize[idx]}" >> temp.plt echo "set origin 0.0, ${porigin[idx]}" >> temp.plt fi # set axis scales, labels echo "set yrange [0:${groupmaxval[${groupnum[idx]}]}]" >> temp.plt echo "set ylabel '${grouplabel[${groupnum[idx]}]}'" >> temp.plt # create plot lines for each column and file in this group index=0 for num in $(seq 1 $tcols) do if [[ colgroup[num] -eq groupnum[idx] ]] then let index+=1 let yearm=year-1 # create plotlines for special columns if [ ${colnum[num]} -ge ${sumgroupmin} ] && [ ${colnum[num]} -le ${sumgroupmax} ] then # stack the values on top of the first one in the order entered if [ ${sumgroupcnt[num]} -eq 1 ] then plotline[index]="'${filename[num]}' index ${yearm} using 2:${colnum[num]} with lines title '${colfilenum[num]}) ${shortcoltitle[${colnum[num]}]}', \\" else plotline[index]="'${filename[num]}' index ${yearm} using 2:(${sumgrouplist}) with lines title '${colfilenum[num]}) Plus ${shortcoltitle[${colnum[num]}]}', \\" fi else plotline[index]="'${filename[num]}' index ${yearm} using 2:${colnum[num]} with lines title '${colfilenum[num]}) ${shortcoltitle[${colnum[num]}]}', \\" fi fi done # add plot command to first plotline plotline[1]=`echo "${plotline[1]}" | sed -e 's/^.*/plot &/'` # strip last plotline of 3 extra characters plotline[index]=`echo "${plotline[index]}" | sed -e 's/...$//'` # write out plot lines to file for num in $(seq 1 $index) do echo ${plotline[num]} >> temp.plt done done # check multiple plots if [[ $tgroups -gt 1 ]] then # this command necessary to display all plots on some terminals echo "unset multiplot" >> temp.plt fi echo "pause ${view_pause}" >> temp.plt done gnuplot temp.plt #rm temp.plt exit