Grdmath: invert NAN operator

Problem: I need to set everything except a specified value to NaN to be able to dump relevant grid nodes with grd2xyz -s.

  • Using grdmath, is there a way of “inverting” the NAN operator (NaN if A == B, else A) such that the result is “A if A == B, else NaN”?

  • Alternatively, if grd2xyz had an argument/option/directive to only output grid nodes containing a specified value. I don’t think this exists (grep-ing kind of works, but clutters). A -s idea could be to add: To only output grid nodes containing the number -5: grd2xyz -s+r+n-5.

Maybe -qo can help, e.g. -qo-5.00000001/-4.9999999+c2 or similar

If you want to turn -5 in a grid to NaN then I would do

gmt grdmath my.grd DUP -5 NEQ 0 NAN = new.grd

Thanks for good tips, Paul. I ended up using a simple EQ to get the values I want.

I must’ve missed this one, because the description for the NAN option, in grdmath, has changed.

Was: NAN: NaN if A = B; else A
Now: NAN: Replace NaNs in A with values from B

That description indicates a very different operation.

Did the NAN operator change? If not, then please update the on-line documentation to reflect what it really does.

I have a suspicion. Will check later.

Code comments remain

/*OPERATOR: NAN 2 1 NaN if A == B, else A. */

and no change in the code. But docs have changed, maybe during the reformatting of table?

Replace NaNs in A with values from B

Hmm, the DNAN operator was introduced at 8/12/2015

SHA-1: c7a233b4a9c37eb1061f719760780f845704f604

  • Added DENAN operator to g*math

and had already the Replace NaNs in A with values from B

EDIT: Sorry my mistake the NAN operator descrition indeed changed in

SHA-1: d7982ca98cef31648d34a7b4e5c5e4689fd67ab9

  • Update grdmath.rst table of operators (#7500)

(Fixed directly in master)

Thanks guys! I use that NAN operator quite a bit, and when I was perusing the latest documentation, it threw me! Thanks for confirming it does what it always did!