GenericMappingTools / gmt

The Generic Mapping Tools
https://www.generic-mapping-tools.org
Other
844 stars 353 forks source link

Comment lines in text files not starting with a hash, get lost in GMTdataset #6737

Open joa-quim opened 2 years ago

joa-quim commented 2 years ago

The tut_quakes.ngdc starts with

Historical Tsunami Earthquakes from the NGDC Database

 Year Mo Da Lat+N Long+E   Dep Mag
 1987 01 04  49.77  149.29 489 4.1
...

If I read it to Julia the two comment lines are lost

julia> D = gmtread("@tut_quakes.ngdc", table=true);

julia> D.comment
2-element Vector{String}:
 ""
 ""

Adding # to the tut_... file

#Historical Tsunami Earthquakes from the NGDC Database

#Year Mo Da Lat+N Long+E   Dep Mag
 1987 01 04  49.77  149.29 489 4.1
...

now shows

julia> D.comment
2-element Vector{String}:
 "Historical Tsunami Earthquakes from the NGDC Database"
 "Year Mo Da Lat+N Long+E   Dep Mag"
PaulWessel commented 2 years ago

The GMT doc example using that file uses -h3 to tell GMT that there are 3 non-standard record of header to consider. For example, this command works fine:

gmt convert @tut_quakes.ngdc -h3 
# Historical Tsunami Earthquakes from the NGDC Database
# 
# Year Mo Da Lat+N Long+E   Dep Mag
# Command : gmt gmtconvert /Users/pwessel/.gmt/cache/tut_quakes.ngdc -h3
1987    1       4       49.77   149.29  489     4.1
...
joa-quim commented 2 years ago

But they are comment lines (they are skipped automatically), so should show up in D.comment, as they do if prefixed with a #

PaulWessel commented 2 years ago

Well, yes and no. They are not comment lines as GMT sees it. So what you propose would not be backwards compatible behavior. I think after I introduced the _gmtio_examine_currentrecord function we may handle such records better than in the past (when that command without -h3 would complain and exit). So not sure what you want to do here? Eliminate -h entirely?

joa-quim commented 2 years ago

Remember that this started with the idea that Matlab wanted a % sign to signal a comment, but *nix wants a # and batch a REM so what about accepting anything that's a string to mean a comment? But now (and then) are comments different from headers?

I don't particularly care about this issue. Just seemed incomprehensible why some are considered comments and other not.

joa-quim commented 3 months ago

Funny that it only take -h1 to make it recognize all leading text lines as comments.

julia> gmtread("@tut_quakes.ngdc", table=true, h=1)
Comment:        ["Historical Tsunami Earthquakes from the NGDC Database", "Year Mo Da Lat+N Long+E   Dep Mag"]
BoundingBox: [1987.0, 1988.0, 1.0, 12.0, 1.0, 31.0, 35.02, 49.77, 132.29, 149.89, 10.0, 576.0, 4.0, 6.8]

115×7 GMTdataset{Float64, 2}
 Row │   Year    Mo    Da  Lat+N  Long+E    Dep  Mag
─────┼───────────────────────────────────────────────
   1 │ 1987.0   1.0   4.0  49.77  149.29  489.0  4.1