[GRASS-user] d.* command problems

Hi,

I'm running GRASS 6.4.0RC6 on Windows XP SP1.

Working my way through the book "Open Source GIS a GRASS GIS Approach"
3rd ed. by Markus Neteler and Helena Mitasova, I have noticed problems
with some d.* commands.

For example, when I type d.histogram into the GUI layer manager
command line, I get the response "Command 'd.histogram' not yet
implemented in the GUI. Try adding it as a command layer instead."

When I add the command layer, I can't see what I'm typing and I can't
find a way to adjust the display so that I can see what's going on.

d.histogram is still ok because I can view the output in the msys folder.

However, d.correlate seems to output multiple files that overwrite one another.

Is there a way around this?

Thanks
Hanlie

Hanlie Pretorius wrote:

However, d.correlate seems to output multiple files that overwrite one another.

Is there a way around this?

Try making this change to the d.correlate script:

--- d.correlate (revision 41749)
+++ d.correlate (working copy)
@@ -97,6 +97,8 @@
fi

d.erase
+GRASS_PNG_READ=TRUE
+export GRASS_PNG_READ
if [ $? != 0 ] ; then
  exit 1
fi

--
Glynn Clements <glynn@gclements.plus.com>

Hi Glynn,

This worked, thanks.

2010/5/11, Glynn Clements <glynn@gclements.plus.com>:

Hanlie Pretorius wrote:

I just pasted the code you sent at the end of the d.correlate script

That won't work. The "code" is a patch, indicating changes to be made
to the file. I've attached a complete modified version of the script.

--
Glynn Clements <glynn@gclements.plus.com>

#!/bin/sh
#
############################################################################
#
# MODULE: d.correlate for GRASS 6; based on dcorrelate.sh for GRASS 4,5
# AUTHOR(S): CERL - Michael Shapiro; updated to GRASS 6 by Markus
Neteler 5/2005
# PURPOSE: prints a graph of the correlation between data layers (in pairs)
# derived from <grass5>/src.local/d.correlate.sh
# COPYRIGHT: (C) 2005 by the GRASS Development Team
#
# This program is free software under the GNU General Public
# License (>=v2). Read the file COPYING that comes with GRASS
# for details.
#
# TODO GRASS 7: rename parameters to map1, map2 or better multiple
map=map1[,map2[...]]
#############################################################################

#%Module
#% description: Prints a graph of the correlation between data layers
(in pairs).
#% keywords: display, diagram
#%End
#%option
#% key: layer1
#% type: string
#% gisprompt: old,cell,raster
#% description: raster input map
#% required : yes
#%end
#%option
#% key: layer2
#% type: string
#% gisprompt: old,cell,raster
#% description: raster input map
#% required : yes
#%end
#%option
#% key: layer3
#% type: string
#% gisprompt: old,cell,raster
#% description: raster input map
#% required : no
#%end
#%option
#% key: layer4
#% type: string
#% gisprompt: old,cell,raster
#% description: raster input map
#% required : no
#%end

if [ -z "$GISBASE" ] ; then
    echo "You must be in GRASS GIS to run this program." >&2
    exit 1
fi

if [ "$1" != "@ARGS_PARSED@" ] ; then
    CMDLINE="`basename $0`"
    for arg in "$@" ; do
        CMDLINE="$CMDLINE \"$arg\""
    done
    export CMDLINE
    exec g.parser "$0" "$@"
fi

PROG=`basename $0`

#### check if we have awk
if [ ! -x "`which awk`" ] ; then
    g.message -e "awk required, please install awk or gawk first"
    exit 1
fi

# setting environment, so that awk works properly in all languages
unset LC_ALL
LC_NUMERIC=C
export LC_NUMERIC

if [ $# -gt 4 ] ; then
        g.message -e "max 4 layers allowed"
  exit 1
fi

TMP1="`g.tempfile pid=$$`"

ok=yes
for f in $GIS_OPT_LAYER1 $GIS_OPT_LAYER2 $GIS_OPT_LAYER3 $GIS_OPT_LAYER4
do
  eval `g.findfile element=cell file=$f`
  if [ -z "$name" ] ; then
        g.message -e "$f not found"
  ok=no
  fi
done

if [ "$ok" = "no" ] ; then
exit 1
fi

d.erase
GRASS_PNG_READ=TRUE
export GRASS_PNG_READ
if [ $? != 0 ] ; then
exit 1
fi

# how many cmd line arguments?
ARGNUM=`echo "$CMDLINE" | tr -s ' ' '\n' | wc -l | awk '{print $1 - 1}'`

echo "CORRELATION" | d.text color=white size=4 line=1
colors="red black blue green gray violet"
if [ $ARGNUM -eq 2 ] ; then
  line=4
else
  line=2
fi
iloop=0
jloop=0

# get max in case of two maps for x, y axis
eval `r.univar -g $GIS_OPT_LAYER1`
max_layer1=$max
eval `r.univar -g $GIS_OPT_LAYER2`
max_layer2=$max

for i in $GIS_OPT_LAYER1 $GIS_OPT_LAYER2 $GIS_OPT_LAYER3 $GIS_OPT_LAYER4
do
   iloop=`expr $iloop + 1`
   for j in $GIS_OPT_LAYER1 $GIS_OPT_LAYER2 $GIS_OPT_LAYER3 $GIS_OPT_LAYER4 ; do
    jloop=`expr $jloop + 1`
    if [ "$i" != "$j" -a $iloop -le $jloop ] ; then
      colorstmp1=`echo $colors | cut -d' ' -f1`
      colorstmp2=`echo $colors | cut -d' ' -f2-`
      colors=`echo $colorstmp2 $colorstmp1`

      if [ $ARGNUM -eq 2 ] ; then
        echo $j | d.text color=`echo $colors | cut -d' ' -f1` size=4 at=0,9$line
        echo $i | d.text color=`echo $colors | cut -d' ' -f1` size=4
at=60,0$line
      else
        echo $i $j | d.text color=`echo $colors | cut -d' ' -f1`
size=4 line=$line
      fi
      line=`expr $line + 1`
      r.stats -cnA input=$i,$j > "$TMP1"
      m="`awk '$1>max1{max1=$1} $2>max2{max2=$2}
min1==0||$1<min1{min1=$1} min2==0||$2<min2{min2=$2} END {print
min1,max1,min2,max2}' $TMP1`"
      m1=`echo $m | cut -d' ' -f1`
      m2=`echo $m | cut -d' ' -f2`
      m3=`echo $m | cut -d' ' -f3`
      m4=`echo $m | cut -d' ' -f4`
      awk '{print
"move",($1-min1+1)*100.0/(max1-min1+1),($2-min2+1)*100.0/(max2-min2+1);print
"draw",($1-min1+1)*100.0/(max1-min1+1),($2-min2+1)*100.0/(max2-min2+1)
}' min1=$m1 max1=$m2 min2=$m3 max2=$m4 "$TMP1" | d.graph color=`echo
$colors | cut -d' ' -f1`

      if [ $ARGNUM -eq 2 ] ; then
         d.graph << EOF
size 2 2
move 0 92
text $max_layer1
move 90 2
text $max_layer2
EOF
      fi
    fi
   done
   jloop=0
done

rm -f "$TMP1"

On Mon, May 10, 2010 at 12:37 PM, Glynn Clements
<glynn@gclements.plus.com> wrote:

Hanlie Pretorius wrote:

However, d.correlate seems to output multiple files that overwrite one another.

Is there a way around this?

Try making this change to the d.correlate script:

--- d.correlate (revision 41749)
+++ d.correlate (working copy)
@@ -97,6 +97,8 @@
fi

d.erase
+GRASS_PNG_READ=TRUE
+export GRASS_PNG_READ
if [ $? != 0 ] ; then
exit 1
fi

Should this be submitted?

Markus

Markus Neteler wrote:

> Try making this change to the d.correlate script:
>
> --- d.correlate (revision 41749)
> +++ d.correlate (working copy)
> @@ -97,6 +97,8 @@
> fi
>
> d.erase
> +GRASS_PNG_READ=TRUE
> +export GRASS_PNG_READ
> if [ $? != 0 ] ; then
> exit 1
> fi

Should this be submitted?

I think so.

I'll make the equivalent fix for 7.0.

--
Glynn Clements <glynn@gclements.plus.com>

On Sun, May 16, 2010 at 9:27 PM, Glynn Clements
<glynn@gclements.plus.com> wrote:

Markus Neteler wrote:

> Try making this change to the d.correlate script:
>
> --- d.correlate (revision 41749)
> +++ d.correlate (working copy)
> @@ -97,6 +97,8 @@
> fi
>
> d.erase
> +GRASS_PNG_READ=TRUE
> +export GRASS_PNG_READ
> if [ $? != 0 ] ; then
> exit 1
> fi

Should this be submitted?

I think so.

Done as r42263 (G6.5) and r42264 (G6.4).

Markus

I'll make the equivalent fix for 7.0.

--
Glynn Clements <glynn@gclements.plus.com>

Markus Neteler wrote:
> > Try making this change to the d.correlate
script:
> >
> > --- d.correlate (revision 41749)
> > +++ d.correlate (working copy)
> > @@ -97,6 +97,8 @@
> > fi
> >
> > d.erase
> > +GRASS_PNG_READ=TRUE
> > +export GRASS_PNG_READ
> > if [ $? != 0 ] ; then
> > exit 1
> > fi
>
> Should this be submitted?

I think so.

I'll make the equivalent fix for 7.0.

is this appropriate for Xmon use in grass6?

Hamish

Hamish wrote:

> > > Try making this change to the d.correlate script:
> > >
> > > --- d.correlate (revision 41749)
> > > +++ d.correlate (working copy)
> > > @@ -97,6 +97,8 @@
> > > fi
> > >
> > > d.erase
> > > +GRASS_PNG_READ=TRUE
> > > +export GRASS_PNG_READ
> > > if [ $? != 0 ] ; then
> > > exit 1
> > > fi
> >
> > Should this be submitted?
>
> I think so.
>
> I'll make the equivalent fix for 7.0.

is this appropriate for Xmon use in grass6?

XDRIVER doesn't pay any attention to GRASS_PNG_READ, so it's
unaffected.

GRASS_PNG_READ=TRUE causes the framebuffer contents to be preserved
from one call to the next, rather than each command starting with a
blank "screen". Scripts which run multiple d.* commands typically need
this in order to work correctly with direct rendering.

--
Glynn Clements <glynn@gclements.plus.com>