#!/bin/bash # create matrix files for plotting # input file name prefix to be processed # processes .egrd and .sgrd files # graphing function (not working at present, arguments don't pass well) # requires the following to be defined and passed in this order infile=${1}.egrd pause_flg=-1 if [ ! -e ${infile} ] then echo "Bad input file name. ${infile} does not exist" exit else echo "Processing ${infile}" fi # read field dimensions from file angle,x0,y0,x1,y1 into coordxy[0]...coordxy[4] coordxy=($(cat ${infile} | grep -A 1 "" | grep -v "")) # Read grid dimensions from file gridxy=($(cat ${infile} | grep "Total grid size:" | sed -e "s/ //g" -e "s/(/ /g" -e "s/)/ /g" -e "s/,/ /g" | dm x5 x6)) echo x: ${gridxy[0]}, y: ${gridxy[1]} # single grid cell width - x cellxy[0]=$(echo "scale=5; (${coordxy[3]}-${coordxy[1]})/${gridxy[0]}" | bc) # single grid cell width - y cellxy[1]=$(echo "scale=5; (${coordxy[4]}-${coordxy[2]})/${gridxy[1]}" | bc) echo "cell x: ${cellxy[0]}, cell y: ${cellxy[1]}" # number of lines required to read in one grid matrix let "contextxy = ${gridxy[1]}+1" for group in totmat salcre suspen pm_10 pm_2-5 #for group in pm_2-5 do # create grid file for total erosion for this event outfile=${1}.${group} if [ "${group}" == "totmat" ] then header=' | |Total Soil Loss|soil loss|(kg/m^2)' mtitle="Total Erosion - ${infile}" elif [ "${group}" == "salcre" ] then header=' | |Saltation/Creep Soil Loss|salt/creep soil loss|(kg/m^2)' mtitle='Saltation/Creep' elif [ "${group}" == "suspen" ] then header=' | |Suspension Soil Loss|suspension soil loss|(kg/m^2)' mtitle='Suspension' elif [ "${group}" == "pm_10" ] then header=' | |PM10 Soil Loss|PM10 soil loss|(kg/m^2)' mtitle='PM10' elif [ "${group}" == "pm_2-5" ] then header=' | |PM2_5 Soil Loss|PM2_5 soil loss|(kg/m^2)' mtitle='PM2_5' fi echo "Creating ${mtitle} matrix file: ${outfile}" cat ${infile} | grep -A ${contextxy} "${header}" | sed -e 's//#/' -e 's/<\/grid data>/#<\/grid data>/' > ${outfile} # find data min and max and range d_min=$(cat ${outfile} | grep -v "#" | stats min) d_max=$(cat ${outfile} | grep -v "#" | stats max) d_range=$( echo "scale=6; ${d_max} - ${d_min}" | bc ) if (( $(bc <<< "${d_range} == 0") == 1 )) then echo "Max = Min" exit fi echo "data min, max, range: ${d_min} ${d_max} ${d_range}" mtitle="${mtitle} Max cell loss: ${d_min}" # calculate color bar scaling cb_min=0 cb_d0m=$(echo "scale=6; (0 - 0.0002 - ${d_min})/${d_range}" | bc) cb_d0=$(echo "scale=6; (0 - ${d_min})/${d_range}" | bc) cb_d0p=$(echo "scale=6; (0 + 0.0002 - ${d_min})/${d_range}" | bc) cb_d0pp=$(echo "scale=6; (0 + (${d_max}/3) - ${d_min})/${d_range}" | bc) cb_d0ppp=$(echo "scale=6; (0 + (2*${d_max}/3) - ${d_min})/${d_range}" | bc) cb_max=1 if (( $(bc <<< "${cb_d0p} > ${cb_d0pp}") == 1 )) then cb_d0p=$(echo "scale=6; (0 + (${d_max}/6) - ${d_min})/${d_range}" | bc) fi # create gnuplot script and plot data echo "set term wxt size 1200,750" > plot.plt echo "set title '${mtitle}'" >> plot.plt echo "set cblabel '(kg/m^2)'" >> plot.plt echo "stats '${outfile}' matrix nooutput" >> plot.plt #echo "cb_val = (abs(STATS_min) < abs(STATS_max) ? abs(STATS_max) : abs(STATS_min))" >> plot.plt echo "set cbrange [${d_min} : ${d_max}]" >> plot.plt echo "set palette defined ( ${cb_min} 'red', ${cb_d0m} '#90EE90', ${cb_d0} 'green', ${cb_d0p} 'greenyellow', ${cb_d0pp} 'yellow', ${cb_d0ppp} 'goldenrod', ${cb_max} 'brown')" >> plot.plt echo 'set hidden3d' >> plot.plt echo 'set pm3d' >> plot.plt echo 'unset xtics' >> plot.plt echo 'unset ytics' >> plot.plt echo 'unset ztics' >> plot.plt echo 'unset border' >> plot.plt echo 'set view equal xyz' >> plot.plt echo 'set xyplane at 0.0' >> plot.plt echo 'set view 0.0,0.0' >> plot.plt echo "splot '${outfile}' using (\$1*${cellxy[0]}+${cellxy[0]}/2):((${gridxy[1]}-\$2-1)*${cellxy[1]}+${cellxy[1]}/2):3 matrix with lines notitle" >> plot.plt echo "pause ${pause_flg}" >> plot.plt gnuplot plot.plt rm plot.plt rm ${outfile} exit done exit # create grid file for Saltation/Creep for this event outfile=${1}.salcre header=' | |Saltation/Creep Soil Loss|salt/creep soil loss|(kg/m^2)' mtitle='Saltation/Creep' echo "Creating ${mtitle} matrix file: ${outfile}" cat ${infile} | grep -A ${contextxy} "${header}" | sed -e 's//#/' -e 's/<\/grid data>/#<\/grid data>/' > ${outfile} # find data min and max and range d_min=$(cat ${outfile} | grep -v "#" | stats min) d_max=$(cat ${outfile} | grep -v "#" | stats max) d_range=$( echo "scale=6; ${d_max} - ${d_min}" | bc ) echo "data min, max, range: ${d_min} ${d_max} ${d_range}" mtitle="${mtitle} Max cell loss: ${d_min}" # calculate color bar scaling cb_min=0 cb_d0m=$(echo "scale=6; (0 - 0.0002 - ${d_min})/${d_range}" | bc) cb_d0=$(echo "scale=6; (0 - ${d_min})/${d_range}" | bc) cb_d0p=$(echo "scale=6; (0 + 0.0002 - ${d_min})/${d_range}" | bc) cb_d0pp=$(echo "scale=6; (0 + (${d_max}/3) - ${d_min})/${d_range}" | bc) cb_d0ppp=$(echo "scale=6; (0 + (2*${d_max}/3) - ${d_min})/${d_range}" | bc) cb_max=1 # create gnuplot script and plot data echo "set term wxt size 1200,750" > plot.plt echo "set title '${mtitle}'" >> plot.plt echo "set cblabel '(kg/m^2)'" >> plot.plt echo "stats '${outfile}' matrix nooutput" >> plot.plt #echo "cb_val = (abs(STATS_min) < abs(STATS_max) ? abs(STATS_max) : abs(STATS_min))" >> plot.plt echo "set cbrange [${d_min} : ${d_max}]" >> plot.plt echo "set palette defined ( ${cb_min} 'red', ${cb_d0m} '#90EE90', ${cb_d0} 'green', ${cb_d0p} 'greenyellow', ${cb_d0pp} 'yellow', ${cb_d0ppp} 'goldenrod', ${cb_max} 'brown')" >> plot.plt echo 'set hidden3d' >> plot.plt echo 'set pm3d' >> plot.plt echo 'unset xtics' >> plot.plt echo 'unset ytics' >> plot.plt echo 'unset ztics' >> plot.plt echo 'unset border' >> plot.plt echo 'set view equal xyz' >> plot.plt echo 'set xyplane at 0.0' >> plot.plt echo 'set view 0.0,0.0' >> plot.plt echo "splot '${outfile}' using (\$1*${cellxy[0]}+${cellxy[0]}/2):((${gridxy[1]}-\$2-1)*${cellxy[1]}+${cellxy[1]}/2):3 matrix with lines notitle" >> plot.plt echo 'pause -1' >> plot.plt gnuplot plot.plt rm plot.plt rm ${outfile} # create grid file for Saltation/Creep for this event outfile=${1}.suspen header=' | |Suspension Soil Loss|suspension soil loss|(kg/m^2)' mtitle='Suspension' echo "Creating ${mtitle} matrix file: ${outfile}" cat ${infile} | grep -A ${contextxy} "${header}" | sed -e 's//#/' -e 's/<\/grid data>/#<\/grid data>/' > ${outfile} # find data min and max and range d_min=$(cat ${outfile} | grep -v "#" | stats min) d_max=$(cat ${outfile} | grep -v "#" | stats max) d_range=$( echo "scale=6; ${d_max} - ${d_min}" | bc ) echo "data min, max, range: ${d_min} ${d_max} ${d_range}" mtitle="${mtitle} Max cell loss: ${d_min}" # calculate color bar scaling cb_min=0 cb_d0m=$(echo "scale=6; (0 - 0.0002 - ${d_min})/${d_range}" | bc) cb_d0=$(echo "scale=6; (0 - ${d_min})/${d_range}" | bc) cb_d0p=$(echo "scale=6; (0 + 0.0002 - ${d_min})/${d_range}" | bc) cb_d0pp=$(echo "scale=6; (0 + (${d_max}/3) - ${d_min})/${d_range}" | bc) cb_d0ppp=$(echo "scale=6; (0 + (2*${d_max}/3) - ${d_min})/${d_range}" | bc) cb_max=1 # create gnuplot script and plot data echo "set term wxt size 1200,750" > plot.plt echo "set title '${mtitle}'" >> plot.plt echo "set cblabel '(kg/m^2)'" >> plot.plt echo "stats '${outfile}' matrix nooutput" >> plot.plt #echo "cb_val = (abs(STATS_min) < abs(STATS_max) ? abs(STATS_max) : abs(STATS_min))" >> plot.plt echo "set cbrange [${d_min} : ${d_max}]" >> plot.plt echo "set palette defined ( ${cb_min} 'red', ${cb_d0m} '#90EE90', ${cb_d0} 'green', ${cb_d0p} 'greenyellow', ${cb_d0pp} 'yellow', ${cb_d0ppp} 'goldenrod', ${cb_max} 'brown')" >> plot.plt echo 'set hidden3d' >> plot.plt echo 'set pm3d' >> plot.plt echo 'unset xtics' >> plot.plt echo 'unset ytics' >> plot.plt echo 'unset ztics' >> plot.plt echo 'unset border' >> plot.plt echo 'set view equal xyz' >> plot.plt echo 'set xyplane at 0.0' >> plot.plt echo 'set view 0.0,0.0' >> plot.plt echo "splot '${outfile}' using (\$1*${cellxy[0]}+${cellxy[0]}/2):((${gridxy[1]}-\$2-1)*${cellxy[1]}+${cellxy[1]}/2):3 matrix with lines notitle" >> plot.plt echo 'pause -1' >> plot.plt gnuplot plot.plt rm plot.plt rm ${outfile}