# Strangeness in gmtselect

**URL:** <https://forum.generic-mapping-tools.org/t/strangeness-in-gmtselect/4746>\
**Category:** Q&A\
**Created:** [March 25, 2024, 3:43pm UTC](https://forum.generic-mapping-tools.org/t/strangeness-in-gmtselect/4746 "2024-03-25T15:43:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Geodesy](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/john_geodesy/32/116_2.png) [@John\_Geodesy](https://forum.generic-mapping-tools.org/u/John_Geodesy)\
**Post date:** [March 25, 2024, 3:43pm UTC](https://forum.generic-mapping-tools.org/t/strangeness-in-gmtselect/4746/1 "2024-03-25T15:43:42Z")

</div>

Not sure if this is a bug, or if I’m mis-using GMT (again!).

Given this little table (named test.txt as used in my command, below)

```auto
118.50397466300	1.14055858528	0001	85.924400
118.49500219520	1.23044468348	0002	85.924400
118.48602913077	1.32033067073	0003	85.924400
118.47705542608	1.41021653890	0004	85.924400
118.46808103746	1.50010227991	0005	85.924400

```

And running this set of commands:

```auto
trk=0002
gmt gmtset FORMAT_FLOAT_OUT="%.11f %.11f %04i %.6f"
gmt gmtselect test.txt -Z${trk}

```

yields this:

```auto
118.49500219520	1.23044468348	0001	85.924400

```

This is the correct row, but the value of column 2 (“0001”) has been changed from what it was in the original file, test.txt. Why does this happen?

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [March 25, 2024, 4:06pm UTC](https://forum.generic-mapping-tools.org/t/strangeness-in-gmtselect/4746/2 "2024-03-25T16:06:00Z")

</div>

What is `i`? (sorry don’t remember this flag). Shouldn’t it be `%04d`?

---

<div class="post-metadata">

**Author:** ![John\_Geodesy](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/john_geodesy/32/116_2.png) [@John\_Geodesy](https://forum.generic-mapping-tools.org/u/John_Geodesy)\
**Post date:** [March 25, 2024, 4:25pm UTC](https://forum.generic-mapping-tools.org/t/strangeness-in-gmtselect/4746/3 "2024-03-25T16:25:14Z")

</div>

Ack. Probably got caught by the fact that awk accepts d and i as being equivalent.

However, changing to:

```auto
gmt gmtset FORMAT_FLOAT_OUT="%.11f %.11f %04d %.6f"

```

yields the same result, i.e., column 2 is returned with “0002” replaced with “0001”.

But it has to be related to the gmtset command because if I set gmtset to %g, gmtselect returns the correct value, but without leading zeros.

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [March 25, 2024, 4:47pm UTC](https://forum.generic-mapping-tools.org/t/strangeness-in-gmtselect/4746/4 "2024-03-25T16:47:00Z")

</div>

> [@John\_Geodesy](#):
>
> column 2 is returned with “0002”

You mean _row 2_ right? And what about row 3, does it have “0002”?

---

<div class="post-metadata">

**Author:** ![John\_Geodesy](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/john_geodesy/32/116_2.png) [@John\_Geodesy](https://forum.generic-mapping-tools.org/u/John_Geodesy)\
**Post date:** [March 25, 2024, 5:12pm UTC](https://forum.generic-mapping-tools.org/t/strangeness-in-gmtselect/4746/5 "2024-03-25T17:12:39Z")

</div>

No, Joaquim. Here’s the whole sequence with resulting output:

```auto
> trk=0002
gmt gmtset FORMAT_FLOAT_OUT="%.11f %.11f %04d %.6f"
> gmt gmtselect test.txt -Z${trk}
118.49500219520	1.23044468348	0001	85.924400

```

The line returned is indeed row 2, but the third value of that row has been changed from “0002” to “0001”. See the table in my original post.

When doing the following, it comes back correct (but I need the leading zeros and additional decimal values in the first two columns):

```auto
> gmt gmtset FORMAT_FLOAT_OUT=%g
> gmt gmtselect test.txt -Z${trk}
118.495	1.23044	2	85.9244

```

---

<div class="post-metadata">

**Author:** ![jjg](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/jjg/32/2822_2.png) [@jjg](https://forum.generic-mapping-tools.org/u/jjg)\
**Post date:** [March 25, 2024, 5:30pm UTC](https://forum.generic-mapping-tools.org/t/strangeness-in-gmtselect/4746/6 "2024-03-25T17:30:17Z")

</div>

According to [the docs](https://docs.generic-mapping-tools.org/dev/gmt.conf.html#term-FORMAT_FLOAT_OUT), `FORMAT_FLOAT_OUT` only supports “ **f** , **e** , **E** , **g** or **G** ” type specifiers – try `%04.0f`

---

<div class="post-metadata">

**Author:** ![John\_Geodesy](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/john_geodesy/32/116_2.png) [@John\_Geodesy](https://forum.generic-mapping-tools.org/u/John_Geodesy)\
**Post date:** [March 25, 2024, 5:46pm UTC](https://forum.generic-mapping-tools.org/t/strangeness-in-gmtselect/4746/7 "2024-03-25T17:46:32Z")

</div>

Thanks jjg. That corrects my mis-use. Glad it wasn’t a bug!
