#! /bin/bash # invoke gnuplot to compare decomposition output statistics from the age pools from WEPS generated runs. # file must be a rst??.btmp (created by agedecompbycrop.f95 compile program) # which has blocks for min, max, mean, mean - sd, mean + sd for a single residue # modified to generate all columns into one PDF, with multiple files on a graph for each column # invocation: agedecompstat [file-1] [file-2] ... [file-#] # first six columns # daysim resday resyr doy yr pool # set up column and title correspondence mincol=7 maxcol=36 coltitle[7]=`echo "7) Decomposition Days Standing Cumulative"` coltitle[8]=`echo "8) Decomposition Days Flat Cumulative"` coltitle[9]=`echo "9) Decomposition Days Below Ground (Layer 10) Cumulative"` coltitle[10]=`echo "10) Cover Flat"` coltitle[11]=`echo "11) Cover Standing"` coltitle[12]=`echo "12) Cover Total"` coltitle[13]=`echo "13) Cover Factor"` coltitle[14]=`echo "14) Stem Area Index"` coltitle[15]=`echo "15) Leaf Area Index"` coltitle[16]=`echo "16) Mass All (total)"` coltitle[17]=`echo "17) Mass Flat"` coltitle[18]=`echo "18) Mass Standing"` coltitle[19]=`echo "19) Mass Below Ground Root"` coltitle[20]=`echo "20) Mass Below Ground Shoot"` coltitle[21]=`echo "21) Count Standing Stem"` coltitle[22]=`echo "22) Height Standing Stem"` coltitle[23]=`echo "23) Representative Diameter Stem"` coltitle[24]=`echo "24) Mass Standing Stem"` coltitle[25]=`echo "25) Mass Standing Leaf"` coltitle[26]=`echo "26) Mass Standing Storage"` coltitle[27]=`echo "27) Mass Flat Stem"` coltitle[28]=`echo "28) Mass Flat Leaf"` coltitle[29]=`echo "29) Mass Flat Storage"` coltitle[30]=`echo "30) Mass Flat Storage Root"` coltitle[31]=`echo "31) Mass Flat Fiberous Root"` coltitle[32]=`echo "32) Mass Below Ground Stem"` coltitle[33]=`echo "33) Mass Below Ground Leaf"` coltitle[34]=`echo "34) Mass Below Ground Storage"` coltitle[35]=`echo "35) Mass Below Ground Storage Root"` coltitle[36]=`echo "36) Mass Below Ground Fibrous Root"` # short column titles shortcoltitle[7]=`echo "7) DDstandCum"` shortcoltitle[8]=`echo "8) DDflatCum"` shortcoltitle[9]=`echo "9) DDbgL10Cum"` shortcoltitle[10]=`echo "10) Fcov"` shortcoltitle[11]=`echo "11) Scov"` shortcoltitle[12]=`echo "12) Tcov"` shortcoltitle[13]=`echo "13) CovFac"` shortcoltitle[14]=`echo "14) SAI"` shortcoltitle[15]=`echo "15) LAI"` shortcoltitle[16]=`echo "16) Mtotal"` shortcoltitle[17]=`echo "17) Mflat"` shortcoltitle[18]=`echo "18) Mstand"` shortcoltitle[19]=`echo "19) Mbgroot"` shortcoltitle[20]=`echo "20) Mbgshoot"` shortcoltitle[21]=`echo "21) #stem"` shortcoltitle[22]=`echo "22) Hstem"` shortcoltitle[23]=`echo "23) RDstem"` shortcoltitle[24]=`echo "24) MstandStem"` shortcoltitle[25]=`echo "25) MstandLeaf"` shortcoltitle[26]=`echo "26) MstandStore"` shortcoltitle[27]=`echo "27) MflatStem"` shortcoltitle[28]=`echo "28) MflatLeaf"` shortcoltitle[29]=`echo "29) MflatStore"` shortcoltitle[30]=`echo "30) MflatStoreroot"` shortcoltitle[31]=`echo "31) MflatFiberroot"` shortcoltitle[32]=`echo "32) MbgStem"` shortcoltitle[33]=`echo "33) MbgLeaf"` shortcoltitle[34]=`echo "34) MbgStore"` shortcoltitle[35]=`echo "35) MbgStoreroot"` shortcoltitle[36]=`echo "36) MbgFiberroot"` # set up column groupings tgroups=8 colgroupnum[7]=1 colgroupnum[8]=1 colgroupnum[9]=1 colgroupnum[10]=2 colgroupnum[11]=2 colgroupnum[12]=2 colgroupnum[13]=3 colgroupnum[14]=4 colgroupnum[15]=4 colgroupnum[16]=5 colgroupnum[17]=5 colgroupnum[18]=5 colgroupnum[19]=5 colgroupnum[20]=5 colgroupnum[21]=6 colgroupnum[22]=7 colgroupnum[23]=8 colgroupnum[24]=5 colgroupnum[25]=5 colgroupnum[26]=5 colgroupnum[27]=5 colgroupnum[28]=5 colgroupnum[29]=5 colgroupnum[30]=5 colgroupnum[31]=5 colgroupnum[32]=5 colgroupnum[33]=5 colgroupnum[34]=5 colgroupnum[35]=5 colgroupnum[36]=5 # group y axis labels grouplabel[1]=`echo "Days"` grouplabel[2]=`echo "Cover (m/m)"` grouplabel[3]=`echo "Cover Factor (m^2/kg)"` grouplabel[4]=`echo "Index (m^2/m^2)"` grouplabel[5]=`echo "Mass (kg/m^2)"` grouplabel[6]=`echo "Count (#/m^2)"` grouplabel[7]=`echo "Stem Height (m)"` grouplabel[8]=`echo "Rep Stem Dia (mm)"` # 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: agedecompstat [file-1] [file-2] ... [file-#]' echo 'Valid Column Numbers are:' for num in $( seq $mincol $maxcol ) do echo ${coltitle[num]} done exit fi # parse command arguments checking for valid file names # initialize total number of valid file names parsed (must assume one when column numbers preceed file names) # set up column numbers for range finding let tcols=0 let tfiles=0 for ncmd in $( seq 1 $ncmdarg ) do # check for file name if [ -e "${cmdarg[ncmd]}" ] then # valid file name # increment index counter for file name array let tfiles+=1 # add file name to unique file names list ufilename[tfiles]="${cmdarg[ncmd]}" else # not a valid file name, show error message and exit echo \'"${cmdarg[ncmd]}"\' is not valid file name. exit fi done for num in $( seq 1 ${tfiles} ) do # Find maximum column value for x axis "residue calendar day" column 2 maxresday[num]=`cat ${ufilename[num]} | dm "if x2>0 then x2 else SKIP" | stats max` echo "maxresday: ${maxresday[num]}" # set maximum across all files afmaxresday=`echo "${maxresday[num]} ${afmaxresday}" | stats max` if [[ num -eq 1 ]] then afminresday=${maxresday[num]} else afminresday=`echo "${maxresday[num]} ${afminresday}" | stats min` fi echo "afmaxresday: ${afmaxresday}, afminresday: ${afminresday}" done # find maximum column value for each column and assign that to the maximum for the column #for num in $( seq 1 ${tfiles} ) #do # for ncol in $(seq ${mincol} ${maxcol} ) # do # echo -n " Find maximum value: column ${ncol} in ${ufilename[num]} : " # find selected column maximum value for this file # filemaxval=`dm "if x${ncol}>0 then x${ncol} else SKIP" < ${ufilename[num]} | stats max` # echo "${filemaxval}" # colmaxval[ncol]=`echo "$filemaxval ${colmaxval[ncol]}" | stats max` # echo "colmaxval(${ncol}) now equal to ${colmaxval[ncol]}]}" # done #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. # create text for graph title, using file names graphtitle="Files: " for num in $( seq 1 ${tfiles} ) do graphtitle=`echo "${graphtitle} ${num}) ${ufilename[num]} "` 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]}]} # write single instance lines top plot file ##--- start pdf --- #echo "set terminal pdf font 'Helvetica,4'" > temp.plt #echo "set output 'agedecompstat.pdf'" >> temp.plt #view_pause=0 ##--- end pdf --- #--- start emf --- # create temporary directory for files if needed tempdir="agedecompstattemp" mkdir -p ${tempdir} # clear any files rm ${tempdir}/*.emf echo "set terminal emf monochrome dashed" > temp.plt view_pause=0 echo "set style line 1 lt 1 lw 1" >> temp.plt echo "set style line 2 lt 2 lw 1" >> temp.plt echo "set style line 3 lt 3 lw 1" >> temp.plt echo "set style line 4 lt 4 lw 1" >> temp.plt echo "set style line 5 lt 5 lw 1" >> temp.plt echo "set style line 6 lt 1 lw 3" >> temp.plt echo "set style line 7 lt 2 lw 3" >> temp.plt echo "set style line 8 lt 3 lw 3" >> temp.plt echo "set style line 9 lt 4 lw 3" >> temp.plt echo "set style line 10 lt 5 lw 3" >> temp.plt echo "set style line 11 lt 1 lw 5" >> temp.plt # SET OUTPUT FILE BELOW!!!! #--- 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:${afmaxresday}]" >> temp.plt echo "set xrange [0:${afminresday}]" >> temp.plt #echo "set xrange [0:100]" >> temp.plt # changes here since blocks are min, max, mean, sd # so the index will be used to plot each of these on the same graph # with sd being added and subtracted from mean # change so we graph all columns into set of graphs for ncol in $(seq ${mincol} ${maxcol} ) do echo "Creating plot for ${coltitle[ncol]}" # # --- emf output files --- echo "set output '${tempdir}/${ncol}_stat.emf'" >> temp.plt # create graph title line echo "set title '${shortcoltitle[ncol]}, ${graphtitle}'" >> temp.plt # set x axis labels echo "set format x '% g'" >> temp.plt echo "set xlabel 'Days After Start of Decomposition'" >> temp.plt # set axis scales, labels echo "set yrange [0:]" >> temp.plt echo "set ylabel '${grouplabel[${colgroupnum[ncol]}]}'" >> temp.plt # this group of 5 blocks contains min, max, mean and +/-SD blocks for each day. # create plot lines for each column and file in this group # for all files let index=0 for nfil in $( seq 1 ${tfiles} ) do # skip max, min, sd if total number of files is more than 2, graph gets really busy if [[ tfiles -le 2 ]] then # plot minimum let index+=1 plotline[index]="'${ufilename[nfil]}' index 0 using 2:${ncol} with lines title '${nfil})Min', \\" # plot maximum let index+=1 plotline[index]="'${ufilename[nfil]}' index 1 using 2:${ncol} with lines title '${nfil})Max', \\" fi # plot mean let index+=1 plotline[index]="'${ufilename[nfil]}' index 2 using 2:${ncol} with lines title '${nfil})Mean', \\" # skip max, min, sd if total number of files is more than 2, graph gets really busy if [[ tfiles -le 2 ]] then # plot mean minus SD let index+=1 plotline[index]="'${ufilename[nfil]}' index 3 using 2:${ncol} with lines title '${nfil})Mean-SD', \\" # plot mean plus SD let index+=1 plotline[index]="'${ufilename[nfil]}' index 4 using 2:${ncol} with lines title '${nfil})Mean+SD', \\" 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 # this group of 5 blocks contains min, max, median and uppper and lower quartile curves # based on the DDstand value in the last day of a block # # --- emf output files --- echo "set output '${tempdir}/${ncol}_stand.emf'" >> temp.plt # create plot lines for each column and file in this group # for all files let index=0 for nfil in $( seq 1 ${tfiles} ) do # skip max, min, sd if total number of files is more than 2, graph gets really busy if [[ tfiles -le 2 ]] then # plot minimum let index+=1 plotline[index]="'${ufilename[nfil]}' index 5 using 2:${ncol} with lines title '${nfil})Min', \\" # plot maximum let index+=1 plotline[index]="'${ufilename[nfil]}' index 6 using 2:${ncol} with lines title '${nfil})Max', \\" fi # plot mean let index+=1 plotline[index]="'${ufilename[nfil]}' index 7 using 2:${ncol} with lines title '${nfil})Median DDstand curve', \\" # skip max, min, sd if total number of files is more than 2, graph gets really busy if [[ tfiles -le 2 ]] then # plot mean minus SD let index+=1 plotline[index]="'${ufilename[nfil]}' index 8 using 2:${ncol} with lines title '${nfil})Lower Quartile', \\" # plot mean plus SD let index+=1 plotline[index]="'${ufilename[nfil]}' index 9 using 2:${ncol} with lines title '${nfil})Upper Quartile', \\" 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 # this group of 5 blocks contains min, max, median and uppper and lower quartile curves # based on the DDflat value in the last day of a block # # --- emf output files --- echo "set output '${tempdir}/${ncol}_flat.emf'" >> temp.plt # create plot lines for each column and file in this group # for all files let index=0 for nfil in $( seq 1 ${tfiles} ) do # skip max, min, sd if total number of files is more than 2, graph gets really busy if [[ tfiles -le 2 ]] then # plot minimum let index+=1 plotline[index]="'${ufilename[nfil]}' index 10 using 2:${ncol} with lines title '${nfil})Min', \\" # plot maximum let index+=1 plotline[index]="'${ufilename[nfil]}' index 11 using 2:${ncol} with lines title '${nfil})Max', \\" fi # plot mean let index+=1 plotline[index]="'${ufilename[nfil]}' index 12 using 2:${ncol} with lines title '${nfil})Median DDflat curve', \\" # skip max, min, sd if total number of files is more than 2, graph gets really busy if [[ tfiles -le 2 ]] then # plot mean minus SD let index+=1 plotline[index]="'${ufilename[nfil]}' index 13 using 2:${ncol} with lines title '${nfil})Lower Quartile', \\" # plot mean plus SD let index+=1 plotline[index]="'${ufilename[nfil]}' index 14 using 2:${ncol} with lines title '${nfil})Upper Quartile', \\" 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 # this group of 5 blocks contains min, max, median and uppper and lower quartile curves # based on the DDbgL10 value in the last day of a block # # --- emf output files --- echo "set output '${tempdir}/${ncol}_bgL10.emf'" >> temp.plt # create plot lines for each column and file in this group # for all files let index=0 for nfil in $( seq 1 ${tfiles} ) do # skip max, min, sd if total number of files is more than 2, graph gets really busy if [[ tfiles -le 2 ]] then # plot minimum let index+=1 plotline[index]="'${ufilename[nfil]}' index 15 using 2:${ncol} with lines title '${nfil})Min', \\" # plot maximum let index+=1 plotline[index]="'${ufilename[nfil]}' index 16 using 2:${ncol} with lines title '${nfil})Max', \\" fi # plot mean let index+=1 plotline[index]="'${ufilename[nfil]}' index 17 using 2:${ncol} with lines title '${nfil})Median DDbgL10 curve', \\" # skip max, min, sd if total number of files is more than 2, graph gets really busy if [[ tfiles -le 2 ]] then # plot mean minus SD let index+=1 plotline[index]="'${ufilename[nfil]}' index 18 using 2:${ncol} with lines title '${nfil})Lower Quartile', \\" # plot mean plus SD let index+=1 plotline[index]="'${ufilename[nfil]}' index 19 using 2:${ncol} with lines title '${nfil})Upper Quartile', \\" 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 echo "pause ${view_pause}" >> temp.plt done gnuplot temp.plt #rm temp.plt exit