Grdtrack -s behavior

Hi,

after reading the man page for the -s option of grdtrack, I wonder if the behavior generated by the script below is really the intention - I might be confused here, so sorry if this is dumb.

If I have two columns on input, -s does what it should, remove the NaN output. If I have three input columns, then I would have expected -s to operate on the last, i.e. the interpolated, new, 4th value, instead (consistent with the man pages, but not clear about the logic there to me), it lets NaNs through, unless I use -s3. But why 3? that’s the input column, which isn’t NaN, and I guess I’m not sure where to start counting. Seems like a feature, but maybe a confusing one?

Thanks!

T

Script:

  #!/bin/bash
    cat <<EOF | xyz2grd -R0/1/0/1 -I1 -Gtmp.grd
    0 0 1
    0 1 NaN
    1 0 NaN
    1 1 1
    EOF
    echo original grid
    grd2xyz tmp.grd
    sup=-s
    echo grdtrack two columns NaN suppressed -s
    cat <<EOF | grdtrack -Gtmp.grd -s
    0 0
    0 1
    1 0
    1 1 
    EOF
    echo 
    for sup in -s -s2 -s3 -s4;do
        echo grdtrack three columns NaN suppressed $sup
        cat <<EOF | grdtrack -Gtmp.grd $sup
    0 0 0
    0 1 0
    1 0 0
    1 1 0
    EOF
    done

Output:

./test_nan
original grid
0 1 NaN
1 1 1
0 0 1
1 0 NaN
grdtrack two columns NaN suppressed -s
0 0 1
1 1 1

grdtrack three columns NaN suppressed -s
0 0 0 1
0 1 0 NaN
1 0 0 NaN
1 1 0 1
grdtrack three columns NaN suppressed -s2
0 0 0 1
0 1 0 NaN
1 0 0 NaN
1 1 0 1
grdtrack three columns NaN suppressed -s3
0 0 0 1
1 1 0 1
grdtrack three columns NaN suppressed -s4
0 0 0 1
0 1 0 NaN
1 0 0 NaN
1 1 0 1

The -s column setting refers to the output. Once you run x y z through grdtrack you pick up another output column w from your grid, and possibly many w values from many grids (-G is repeatable).

Since the z-column is the 3rd column [2 in GMT parlance] and that is the default, if you pass more than 2 columns into grdtrack then you would need to specify which output column should be examined for NaNs. In your case that is the 4th column, i…e, 3. So -s3 is the right answer.

It would be nice if -s4 gave a warning and said ignored but -s is processed way before we know how many columns we have. So that means another place to insert a check to issue such a message.

To make it clearer I have added the word output to the -s description to make it clear that we are talking about output columns and not input.

Thanks much, Paul, got it. Bit of a bummer that the -S from GMT4 isn’t backward compatible, but I guess grep -v NaN can keep one on the safe side.

Hm, what did -S do differently? Perhaps we can fix that as part of backwards compatibility