gmt icon indicating copy to clipboard operation
gmt copied to clipboard

gmt convert -N and -E confusion

Open PaulWessel opened this issue 3 years ago • 2 comments

I think this is more unintended consequences than a bug, but certainly confusing: I wanted to sort a data table into ascending order based on values in column 4, then only output the first row (with lowest value in col 4) but only get columns 7 and 1:

gmt convert -N4+a A.txt -Ef -o7,1

Problem is that -E is processed during reading, and it thus only picked the first input record. This is of course not the record with the lowest value in column 4. So after pointlessly sorting that single record data set I output its two coordinates which are not what I wanted.

Clearly, if -N for sorting is selected then the -E action would need to happen after the sorting has completed. However, given what -E can do I cannot rule out that a user may wish to select every 3rd record (-E3) on input, then sort those records, and finally output the first sorted record only. Thus, maybe we need a separate scheme to only output one record after the search. Since -N can sort into ascending or descending, we could simply add a modifier +o[rec] which would output only record number rec [0] after sorting. This would allow us to get the second best record via +o1, for example, instead of +o (or +o0) which would give the best record.

Since I think -N is used to either sort the entire table and report that, or (as I do) only get a single record (the "best" or "worst") I think +o is a reasonable solution. If someone really wanted every 3rd record from the sorted list they would have to run convert twice.

Thoughts?

PaulWessel avatar Aug 16 '22 12:08 PaulWessel

a user may wish to select every 3rd record (-E3) on input

I am confused. Shouldn't -q be used for this? What is the difference?

Esteban82 avatar Aug 16 '22 12:08 Esteban82

No, I am the one that is confused: I forgot about -q entirely! So the solution to my problem is

gmt convert -N4+a A.txt -o7,1 -qo0

but I think a brief discussion of -E -q is warranted in gmt convert man page.

PaulWessel avatar Aug 16 '22 13:08 PaulWessel