[GRASSLIST:2089] Re: GRASS and r.reclass in a batch

Hi Hamish,
thanks a lot for the attached.
Is it possible that the script has an error?
I've run it and I receive a lot of messages like:

./reclass_scrip.sh: : command not found
./reclass_scrip.sh: : command not found
./reclass_scrip.sh: : command not found

Best regards,

Javier
-----------------------------------------------------------------------
The problem is to pass values of reclassification rules

> to r.reclass. I've tried:

[...]

> But this doesn't work. I think that this could be also with a bash
> script, but I don't know anything about bash.

It is actually pretty clean with Bash, try the attached.

regards,
Hamish

--------------------------------------
#!/bin/bash
# reclass script

i=1
while [ $i -le 25 ] ; do

     r.reclass input=imagen$i output=imarec$i << EOF
        253 = 192
        252 = 96
        251 = 48
        250 = 24
        249 = 12
        221 = 8
        193 = 7
        165 = 6
        133 = 4
        102 = 3
        70 = 2
        39 = 1
        * = NULL
        end
EOF

     i=`expr $i + 1`
done
-------------------------------------

On Thu, 18 Dec 2003 10:12:51 +0100
"javier garcia - CEBAS" <rn001@cebas.csic.es> wrote:

Hi Hamish,
thanks a lot for the attached.
Is it possible that the script has an error?
I've run it and I receive a lot of messages like:

./reclass_scrip.sh: : command not found
./reclass_scrip.sh: : command not found
./reclass_scrip.sh: : command not found

Best regards,

Javier
---------------------------------------------------------------------

Yes, very likely there's an error. I didn't actually test the script.

try replacing
   i=`expr $i + 1`
with
   i=$(($i + 1))

and see if that works.

Hamish

> > The problem is to pass values of reclassification rules
> > to r.reclass. I've tried:
>
> [...]
>
> > But this doesn't work. I think that this could be also with a bash
> > script, but I don't know anything about bash.
>
> It is actually pretty clean with Bash, try the attached.
>
--------------------------------------
#!/bin/bash
# reclass script

i=1
while [ $i -le 25 ] ; do

     r.reclass input=imagen$i output=imarec$i << EOF
        253 = 192
        252 = 96
        251 = 48
        250 = 24
        249 = 12
        221 = 8
        193 = 7
        165 = 6
        133 = 4
        102 = 3
        70 = 2
        39 = 1
        * = NULL
        end
EOF

     i=`expr $i + 1`
done
-------------------------------------

Hi all,
I'm sorry, Hamish. This still does an error. I even have commented nearly
everything to find out the source of the error. But even doing it for a
single map gives an error:
----------------------------
#!/bin/bash
# reclass script
# i=1
# while [ $i -le 25 ] ; do
r.reclass input=imagen1end output=imarec1end << EOF
253 = 192
252 = 96
251 = 48
250 = 24
249 = 12
221 = 8
193 = 7
165 = 6
133 = 4
102 = 3
70 = 2
39 = 1
* = NULL
end
EOF
# i=$(($i + 1))
# done
# if you want the maps to be 01,02,03,..,09,10,11 add this line:
# MAP=`echo $i | awk '{printf "%02i", $1}'`
# echo $MAP
----------------------------------------
ERROR: 253 = 192
       - invalid reclass rule

Perhaps a modification in the format for reclassification rules?

Javier
-----------------------------------------------------------------
-----------------------------------------------------------------
El Jue 18 Dic 2003 13:17, escribió:

On Thu, 18 Dec 2003 10:12:51 +0100

"javier garcia - CEBAS" <rn001@cebas.csic.es> wrote:
> Hi Hamish,
> thanks a lot for the attached.
> Is it possible that the script has an error?
> I've run it and I receive a lot of messages like:
>
> ./reclass_scrip.sh: : command not found
> ./reclass_scrip.sh: : command not found
> ./reclass_scrip.sh: : command not found
>
> Best regards,
>
> Javier
> ---------------------------------------------------------------------

Yes, very likely there's an error. I didn't actually test the script.

try replacing
   i=`expr $i + 1`
with
   i=$(($i + 1))

and see if that works.

Hamish

> > > The problem is to pass values of reclassification rules
> > > to r.reclass. I've tried:
> >
> > [...]
> >
> > > But this doesn't work. I think that this could be also with a bash
> > > script, but I don't know anything about bash.
> >
> > It is actually pretty clean with Bash, try the attached.
>
> --------------------------------------
> #!/bin/bash
> # reclass script
>
> i=1
> while [ $i -le 25 ] ; do
>
> r.reclass input=imagen$i output=imarec$i << EOF
> 253 = 192
> 252 = 96
> 251 = 48
> 250 = 24
> 249 = 12
> 221 = 8
> 193 = 7
> 165 = 6
> 133 = 4
> 102 = 3
> 70 = 2
> 39 = 1
> * = NULL
> end
> EOF
>
> i=`expr $i + 1`
> done
> -------------------------------------

javier garcia - CEBAS wrote:

I'm sorry, Hamish. This still does an error. I even have commented nearly
everything to find out the source of the error. But even doing it for a
single map gives an error:
----------------------------
#!/bin/bash
# \240reclass script
# i=1
# while [ $i -le 25 ] ; do
r.reclass input=imagen1end output=imarec1end << EOF
\240 \240 \240 \240253 = 192
\240 \240 \240 \240252 = 96
\240 \240 \240 \240251 = 48
\240 \240 \240 \240250 = 24
\240 \240 \240 \240249 = 12
\240 \240 \240 \240221 = 8
\240 \240 \240 \240193 = 7
\240 \240 \240 \240165 = 6
\240 \240 \240 \240133 = 4
\240 \240 \240 \240102 = 3
\240 \240 \240 \24070 = 2
\240 \240 \240 \24039 = 1
\240 \240 \240 \240* = NULL
\240 \240 \240 \240end
EOF

The problem is that you have non-breaking space characters (octal 240,
decimal 160) in the script, which r.reclass won't understand. These
characters are shown as \240 above.

Those characters probably look like spaces in a text editor, but won't
be treated as such by many programs (including r.reclass). You need to
change them to spaces or remove them.

--
Glynn Clements <glynn.clements@virgin.net>

Hi Hamish and Glynn,

Now it works wonderfully!

The problem were the non-breaking space characters

I think I should learn bash

Thanks, and best regards

Javier
--------------------------------------------------------------------------
El Jue 18 Dic 2003 22:22, Glynn Clements escribió:

javier garcia - CEBAS wrote:
> I'm sorry, Hamish. This still does an error. I even have commented nearly
> everything to find out the source of the error. But even doing it for a
> single map gives an error:
> ----------------------------
> #!/bin/bash
> # \240reclass script
> # i=1
> # while [ $i -le 25 ] ; do
> r.reclass input=imagen1end output=imarec1end << EOF
> \240 \240 \240 \240253 = 192
> \240 \240 \240 \240252 = 96
> \240 \240 \240 \240251 = 48
> \240 \240 \240 \240250 = 24
> \240 \240 \240 \240249 = 12
> \240 \240 \240 \240221 = 8
> \240 \240 \240 \240193 = 7
> \240 \240 \240 \240165 = 6
> \240 \240 \240 \240133 = 4
> \240 \240 \240 \240102 = 3
> \240 \240 \240 \24070 = 2
> \240 \240 \240 \24039 = 1
> \240 \240 \240 \240* = NULL
> \240 \240 \240 \240end
> EOF

The problem is that you have non-breaking space characters (octal 240,
decimal 160) in the script, which r.reclass won't understand. These
characters are shown as \240 above.

Those characters probably look like spaces in a text editor, but won't
be treated as such by many programs (including r.reclass). You need to
change them to spaces or remove them.