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)
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:
trk=0002
gmt gmtset FORMAT_FLOAT_OUT="%.11f %.11f %04i %.6f"
gmt gmtselect test.txt -Z${trk}
yields this:
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?
What is i
? (sorry don’t remember this flag). Shouldn’t it be %04d
?
Ack. Probably got caught by the fact that awk accepts d and i as being equivalent.
However, changing to:
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.
You mean row 2 right? And what about row 3, does it have “0002”?
No, Joaquim. Here’s the whole sequence with resulting output:
> 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):
> gmt gmtset FORMAT_FLOAT_OUT=%g
> gmt gmtselect test.txt -Z${trk}
118.495 1.23044 2 85.9244
jjg
6
According to the docs, FORMAT_FLOAT_OUT
only supports “f, e, E, g or G” type specifiers – try %04.0f
Thanks jjg. That corrects my mis-use. Glad it wasn’t a bug!