#! /bin/bash # invoke gnuplot to compare soil states (special created by extacting one layer from soillay.out) # invocation: allsoil [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=6 maxcol=28 coltitle[6]=`echo "6) Soil Layer Thickness (mm)"` 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"` # short column titles shortcoltitle[6]=`echo "Thick"` shortcoltitle[7]=`echo "BDen"` shortcoltitle[8]=`echo "AgSt"` shortcoltitle[9]=`echo "AgSt min"` shortcoltitle[10]=`echo "Agst mean"` shortcoltitle[11]=`echo "Agst max"` shortcoltitle[12]=`echo "AgSz min"` shortcoltitle[13]=`echo "AgGMD min"` shortcoltitle[14]=`echo "AgGMD"` shortcoltitle[15]=`echo "AgGMD max"` shortcoltitle[16]=`echo "AgSz max"` shortcoltitle[17]=`echo "AgGSD"` shortcoltitle[18]=`echo "AgDen"` shortcoltitle[19]=`echo "AgSt (0-1)"` shortcoltitle[20]=`echo "AgGMD (0-1)"` shortcoltitle[21]=`echo "Freeze"` shortcoltitle[22]=`echo "Frez-thaw"` shortcoltitle[23]=`echo "Thaw"` shortcoltitle[24]=`echo "Frozen"` shortcoltitle[25]=`echo "Wetting"` shortcoltitle[26]=`echo "Drying"` shortcoltitle[27]=`echo "WarmPud"` shortcoltitle[28]=`echo "BDwet"` # set up column groupings tgroups=5 colgroupnum[6]=1 colgroupnum[7]=2 colgroupnum[8]=3 colgroupnum[9]=3 colgroupnum[10]=3 colgroupnum[11]=3 colgroupnum[12]=1 colgroupnum[13]=1 colgroupnum[14]=1 colgroupnum[15]=1 colgroupnum[16]=1 colgroupnum[17]=1 colgroupnum[18]=2 colgroupnum[19]=4 colgroupnum[20]=4 colgroupnum[21]=5 colgroupnum[22]=5 colgroupnum[22]=5 colgroupnum[23]=5 colgroupnum[24]=5 colgroupnum[25]=5 colgroupnum[26]=5 colgroupnum[27]=5 colgroupnum[28]=5 # group y axis labels grouplabel[1]=`echo "(mm)"` grouplabel[2]=`echo "Density (Mg/m^3)"` grouplabel[3]=`echo "Stability ln(J/kg)"` grouplabel[4]=`echo "Nondimensional"` grouplabel[5]=`echo "Binary (0-1)"` # 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: allsoil [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 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: allsoil [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: allsoil [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} fi done # screen for terminating valid file name if [ ! -e "${filename[tcols]}" ] then echo "No terminating file name." echo 'invocation: allsoil [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}" # check for maximum for this column group for all files groupmaxval[${colgroup[num]}]=`echo "$filemaxval ${groupmaxval[${colgroup[num]}]}" | stats max` echo "groupmaxval(${colgroup[num]}) now equal to ${groupmaxval[${colgroup[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]}]} # 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 # write single instance lines top plot file #--- start pdf --- echo "set terminal pdf" > temp.plt echo "set output 'allsoil.pdf'" >> temp.plt #echo "set xrange [0:366]" >> temp.plt echo "set xrange [90:150]" >> temp.plt view_pause=0 #--- end pdf --- #--- start emf --- # create temporary directory for files if needed #tempdir="htemp" #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 for year in $(seq $numindex) do echo "Simulation Year = $year" # # --- emf output files --- # echo "set output '${tempdir}/${year}.emf'" >> temp.plt # 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 plotline[index]="'${filename[num]}' index ${yearm} using 2:${colnum[num]} with lines title '${colfilenum[num]}) ${shortcoltitle[${colnum[num]}]}', \\" 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