[GRASSLIST:5828] mapcalc region growing

Hallo,
I'm trying to provide some region-growing r.mapcalc script. But that thing does
not work properly and I don't know why.

The script look's like

rg1 = if(sum.spicky[-1,-1] >= 1 && (sum[-1,-1] > sum[1,1]),1, \
             if(sum.spicky[-1,0] >= 1 && (sum[-1,0] > sum[1,0]),1, \
             if(sum.spicky[-1,1] >= 1 && (sum[-1,1] > sum[1,-1]),1, \
             if(sum.spicky[0,-1] >= 1 && (sum[0,-1] > sum[0,1]),1, \
             if(sum.spicky[0,1] >= 1 && (sum[0,1] > sum[0,-1]),1, \
            if(sum.spicky[1,-1] >= 1 && (sum[1,-1] > sum[-1,1]),1,\
            if(sum.spicky[1,0] >= 1 && (sum[1,0] > sum[-1,0]),1, \
            if(sum.spicky[1,1] >= 1 && (sum[1,1] > sum[-1,-1]),1,null()))))))))

It shloud be 3x3 matrix:
If one of the boundary (not-central) pixel from the seed map (sum.spicky)
is >= 1
    If there is gradient on the input (sum) map in the right direction
        1
    else
        null()
else
    null()

Some pictures to see, what is happening:
    black and white input raster (sum) with green seeds (sum.spicky)
    http://www.fle.czu.cz/~jachym/tmp/sum.png
    
    the same rasters with red rg1 map
    http://www.fle.czu.cz/~jachym/tmp/sum_rg1.png

The 'growth region' (red points) matches only the first line of the script

    if(sum.spicky[-1,-1] >= 1 && (sum[-1,-1] > sum[1,1]),1,

If I try to run e.g. the thirth line separately from the others

    "rg1 = if(sum.spicky[0,-1] >= 1 && (sum[0,-1] > sum[0,1]),1,null())"

it works fine, but not if there some other 'if' in front of it...

Please, where could be the problem?

Jáchym
--
Jachym Cepicky
e-mail: jachym.cepicky@centrum.cz
URL: http://les-ejk.cz
GPG: http://www.fle.czu.cz/~jachym/gnupg_public_key/