On Thu, Jan 31, 2008 at 09:11:39AM +0000, we recorded a bogon-computron collision of the <[EMAIL PROTECTED]> flavor, containing: > > Tom Russo wrote: > > > The other day I tried to perform an operation with r.mapcalc that didn't > > work the way I expected. > > [...] > > > > if(!isnull(SAO), > > if(!isnull(A)&&A>=11000, > > 1, > > if(!isnull(B)&&B>=11000, > > 1, > > null() > > ) > > ), > > null() > > ) [...] > > It's not so much an issue with the way that if() works (although that > is a factor), but mainly with the way that && and || work. > > If A is null, then !isnull(A) is false and A>=11000 is null (not > false). The result of "false && null" is null (not false[1]), and the > result of if(null,...) is always null. > > [1] This is presumably the part that caught you out.
Yep. That's it. My C/C++ background caught me, coz in those languages the right-hand operand of && isn't evaluated if the left-hand operand is false. > The behaviour of && and || is consistent with most other infix > operators operators, insofar as they return null if either argument is > null. > > In newer versions of r.mapcalc (I don't recall exactly which > versions), you can use the &&& and ||| operators, which behave like && > and || except that they follow the common boolean equivalences: Yes, I saw that &&& and ||| existed in my version of r.mapcalc, but didn't RTFM carefully enough to realize they were what I wanted. > Finally, even with these changes, your r.mapcalc expression isn't > quite the same as the r.patch+r.mapcalc combination, as you're > treating A<11000 the same as null, whereas r.patch only cares about > null/non-null. So, if both A and B are non-null, A<11000 and B>=11000, > you'll get null from r.mapcalc but 1 from r.patch+r.mapcalc. OTOH, if > A and B are disjoint (I'm not sure from your description), then it > doesn't make any difference. Yes, A and B are disjoint DEMs of adjoining USGS quadrangles. -- Tom Russo KM5VY SAR502 DM64ux http://www.swcp.com/~russo/ Tijeras, NM QRPL#1592 K2#398 SOC#236 AHTB#1 http://kevan.org/brain.cgi?DDTNM "And, isn't sanity really just a one-trick pony anyway? I mean all you get is one trick, rational thinking, but when you're good and crazy, oooh, oooh, oooh, the sky is the limit!" --- The Tick _______________________________________________ grass-user mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/grass-user
