Gmtinfo on binary file - incorrect count for non-NaN records

This may be a bug report. If so, I can post to git, if needed.

I have a three-column binary file, which I’ll attach. [Yes, I know, I seem to be Mr. Binary!]

It consists of 483 records, of which 112 possess valid (i.e., non-NaN) values in column 1 (count from 0).

Running the command:

gmt gmtinfo -bi3d tph.bin
tph.bin: N = 483	<0.7504251301/869.4634709954>	<-0.5369415283/0.2736996710>	<59.5208293094/84.4007150779>

The above is as expected: a count of all records.

Next we run with the -s option, specifying to ignore any NaN records in column 1, we get this:

gmt gmtinfo -bi3d -s1 tph.bin
tph.bin: N = 483	<0.7504251301/869.4634709954>	<-0.5369415283/0.2736996710>	<59.5208293094/84.4007150779>

Oops. It gave the total count again. Piping GMT convert into an awk command, and then a wc -l command yields the proper result.

gmt gmtconvert -bi3d tph.bin | awk ' $2 !~ /NaN/ ' | wc -l

Here’s the file: (6.6 KB) .

More feature than bug. Your tph.bin still has 483 record. If you want the number of records in the output you will need to run gmtinfo on that.

All that is wanted is a count of valid records.

So, something like this, where gmtconvert is applied first, seems to work:

[added in edit: this was a slightly different version of the tph.bin file, I originally posted. Please pay no heed to the different min/max values.]

gmt gmtconvert -bi3d -bo3d -s1 tph.bin | gmt gmtinfo -bi3d
<Standard Input>: N = 112	<216.4491174817/607.2815391421>	<-0.5369415283/0.2736996710>	<73.1671031485/83.6766647768>

I think this worth being fixed.

Fixed in #7545

Joaquim, could you please describe the fix you made?

It seems, after your fix, that gmtinfo is now only counting non-NaN values, no matter whether the -s option is requested or not.

There are times when one needs a complete record count with NaNs (i.e., gmtinfo without -s option).

And there are times when one needs record counts without NaNs being included in the count (i.e., specifying -s).

Can the gmtinfo command be set so that -s option can be used for the latter case, i.e., to ignore NaNs in the count?

I think this is now a regression. Check that -s is set before reducing the count.

-s was always ignored before as the code always jumped record when it found one NaN in any of the columns. So, the decision is:

  • report total number of records
  • only the non-NaNs

If it’s possible, it would be great to be able to request -s to suppress the count of NaNs. If the -s is omitted, then count of all lines, NaNs and all. The min/max part of the function should always ignore NaNs.

Might be able to finesse this with a -s modifier, @Joaquim?

Remind us next week (lots of things got pilled up this already half-consumed one).

That’s fine. I’ll update when the dust settles.

In the mean time, I found the offending line in gmtinfo.c. Deleted the - skiped in line 756. Now I’m getting counts of all lines, NaNs included.

That is what I was going to say. On Win I know how to easily revert from Git GUI but don’t know from command line.

Will need to google revert git to previous version