# Grdtrack -s behavior

**URL:** <https://forum.generic-mapping-tools.org/t/grdtrack-s-behavior/3559>\
**Category:** Q&A\
**Created:** [December 21, 2022, 2:56pm UTC](https://forum.generic-mapping-tools.org/t/grdtrack-s-behavior/3559 "2022-12-21T14:56:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![thwbecker](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/thwbecker/32/1215_2.png) [@thwbecker](https://forum.generic-mapping-tools.org/u/thwbecker)\
**Post date:** [December 21, 2022, 2:56pm UTC](https://forum.generic-mapping-tools.org/t/grdtrack-s-behavior/3559/1 "2022-12-21T14:56:18Z")

</div>

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:

```auto
  #!/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

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [December 22, 2022, 3:36pm UTC](https://forum.generic-mapping-tools.org/t/grdtrack-s-behavior/3559/2 "2022-12-22T15:36:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![thwbecker](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/thwbecker/32/1215_2.png) [@thwbecker](https://forum.generic-mapping-tools.org/u/thwbecker)\
**Post date:** [December 22, 2022, 4:48pm UTC](https://forum.generic-mapping-tools.org/t/grdtrack-s-behavior/3559/3 "2022-12-22T16:48:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [December 22, 2022, 5:04pm UTC](https://forum.generic-mapping-tools.org/t/grdtrack-s-behavior/3559/4 "2022-12-22T17:04:18Z")

</div>

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