#!/bin/sh # written by Markus Neteler 18. August 1998 # neteler@geog.uni-hannover.de # # bugfix: 25. Nov.98/20. Jan. 1999 # this script needs gnuplot #%Module #% description: displays spectral response at user specified locations in images #%End #%option #% key: band1 #% type: string #% gisprompt: old,cell,raster #% description: raster input map #% required : yes #%end #%option #% key: band2 #% type: string #% gisprompt: old,cell,raster #% description: raster input map #% required : no #%end #%option #% key: band3 #% type: string #% gisprompt: old,cell,raster #% description: raster input map #% required : no #%end #%option #% key: band4 #% type: string #% gisprompt: old,cell,raster #% description: raster input map #% required : no #%end #%option #% key: band5 #% type: string #% gisprompt: old,cell,raster #% description: raster input map #% required : no #%end #%option #% key: band6 #% type: string #% gisprompt: old,cell,raster #% description: raster input map #% required : no #%end #%option #% key: band7 #% type: string #% gisprompt: old,cell,raster #% description: raster input map #% required : no #%end #%option #% key: band8 #% type: string #% gisprompt: old,cell,raster #% description: raster input map #% required : no #%end if test "$GISBASE" = ""; then echo "You must be in GRASS GIS to run this program." >&2 exit 1 fi PARAM_NUM=$# if [ "$1" != "@ARGS_PARSED@" ] ; then exec g.parser "$0" "$@" fi #check if present GNUPLOT=`type -p gnuplot` if [ -z "$GNUPLOT" ] ; then echo "Requires 'gnuplot' which could not be found in PATH" exit 1 fi # get y-data for gnuplot-data file RASTERMAPS="$GIS_OPT_band1 $GIS_OPT_band2 $GIS_OPT_band3 $GIS_OPT_band4 $GIS_OPT_band5 $GIS_OPT_band6 $GIS_OPT_band7 $GIS_OPT_band8" RASTERMAPS=`echo $RASTERMAPS | sed 's+ $++g' | sed 's+ +,+g'` TMP1="`g.tempfile pid=$$`" TMP2="`g.tempfile pid=$$`" d.where -1 | r.what input=$RASTERMAPS > "$TMP1" cat "$TMP1" | cut -d'|' -f4,5,6,7,8,9,10| tr '|' '\012' > "$TMP2" COORD="`cat "$TMP1" | cut -d'|' -f1,2 | tr '|' ' '`" NUM="`cat "$TMP2" | wc -l`" NUM2=`expr $NUM + 1` # build data file # the x-axis... depending on number of bands rm -f spectrum.data.dum i=1 while [ $i != $NUM2 ] do echo $i >> spectrum.data.dum i=`expr $i + 1` done # paste to data file paste -d' ' spectrum.data.dum "$TMP2" > spectrum.data rm -f "$TMP1" "$TMP2" echo "" echo "Band - DN at $COORD" cat spectrum.data # build gnuplot script echo "set xtics ('$GIS_OPT_band1' 1, '$GIS_OPT_band2' 2, '$GIS_OPT_band3' 3, '$GIS_OPT_band4' 4, '$GIS_OPT_band5' 5, '$GIS_OPT_band6' 6, '$GIS_OPT_band7' 7, '$GIS_OPT_band8' 8)" >> spectrum.gnuplot echo "set grid" >> spectrum.gnuplot echo "set title 'Spectral response at $COORD'" >> spectrum.gnuplot ##echo "set yrange [0:255]" >> spectrum.gnuplot echo "set xrange [0:$NUM2]" >> spectrum.gnuplot echo "set noclabel" >> spectrum.gnuplot echo "set xlabel 'Band number'" >> spectrum.gnuplot echo "set ylabel 'DN Value'" >> spectrum.gnuplot ## if more then 2 points we can draw an interpolated spline: #if [ $PARAM_NUM -gt 2 ] #then # echo "set data style linespoints" >> spectrum.gnuplot # echo "plot 'spectrum.data' with points pt 779, '' smooth csplines t 'spline interpolated'" >> spectrum.gnuplot #else echo "set data style lines" >> spectrum.gnuplot echo "plot 'spectrum.data' with linespoints pt 779" >> spectrum.gnuplot #fi # display it... $GNUPLOT -persist spectrum.gnuplot rm -f spectrum.data spectrum.data.dum spectrum.gnuplot