Skip to content

Allow for longer history and remark strings #6078

Closed

Description

@PaulWessel

Description of the desired feature

Since last century, the grid header strings title, history and remake (as well as units) have been defined as

char x_units[GMT_GRID_UNIT_LEN80];     /* units in x-direction */
char y_units[GMT_GRID_UNIT_LEN80];     /* units in y-direction */
char z_units[GMT_GRID_UNIT_LEN80];     /* grid value units */
char title[GMT_GRID_TITLE_LEN80];      /* name of data set */
char command[GMT_GRID_COMMAND_LEN320]; /* name of generating command */
char remark[GMT_GRID_REMARK_LEN160];   /* comments re this data set */

Hence, any GMT native binary grids are limited to those lengths. However, there is no good reasons to limit these strings for the more typical format such as netCDF. I am currently trying to set a remark to contain a citation and running into the 160 limit, which is silly. Also, many netCDF files have a series of concatenated command histories and even 320 becomes too small.

I think this is a backwards compatible change:

  1. Replace the above fixed length char arrays with char pointers.
  2. Let GMT->session.readinfo[] be the places where we allocate these strings based on what we find in the file
  3. When writing native grids and any other format with a limit on string length, ensure we max write the length as indicated above.
  4. When a grid header is freed, we free these strings as well.

Any unforeseen consequences with this, @GenericMappingTools/gmt-team?

Activity

  1. added
    feature request
    on Dec 2, 2021
  2. self-assigned this
    on Dec 2, 2021
  3. joa-quim commented on Dec 2, 2021

    @joa-quim
    Member

    Will break Julia and MEX that have fixed sizes in the GRID_HEADER structs

  4. PaulWessel commented on Dec 2, 2021

    @PaulWessel
    ContributorAuthor

    Yes true. Just thought of an alternative solution. When we detect longer strings that can be held, we truncate then as we do now but store the full version in new pointers in either the grid header or the hidden grid header. I understand this may also mean an update to the Julia structs but this is where some sort of versioning must come in, right? There must be a way to address upgrades when necessary.

  5. joa-quim commented on Dec 2, 2021

    @joa-quim
    Member

    Following the semantic version that breaking change alone, that also breaks the API, would imply a GMT7

  6. PaulWessel commented on Dec 2, 2021

    @PaulWessel
    ContributorAuthor

    That is a valid point. We will wait for GMT 7 on that.

  7. anbj commented on Dec 2, 2021

    @anbj
    Contributor

    When these strings get increased length, would it be possible to keep a history of e.g. commands that the grid has been through? As it is now, only the last command will be 'saved' in command[], I think?

    Basically; append to the string; don't replace it.

  8. anbj commented on Dec 2, 2021

    @anbj
    Contributor

    Also, converting a netcdf file to .e.g. geotiff strips off this information:

    $ gmt grdinfo loke-utm31-inv.nc 
    loke-utm31-inv.nc: Title: Produced by grdmath
    loke-utm31-inv.nc: Command: grdmath loke-utm31.nc -1 MUL = loke-utm31-inv.nc
    loke-utm31-inv.nc: Remark: Hello
    loke-utm31-inv.nc: Gridline node registration used [Cartesian grid]
    loke-utm31-inv.nc: Grid file format: nf = GMT netCDF format (32-bit float), CF-1.7
    loke-utm31-inv.nc: x_min: 662330 x_max: 663040 x_inc: 1 name: x n_columns: 711
    loke-utm31-inv.nc: y_min: 8170380 y_max: 8171050 y_inc: 1 name: y n_rows: 671
    loke-utm31-inv.nc: v_min: -2457.73510742 v_max: -2303.93994141 name: z
    loke-utm31-inv.nc: scale_factor: 1 add_offset: 0
    loke-utm31-inv.nc: format: netCDF-4 chunk_size: 143,135 shuffle: on deflation_level: 3
    
    $ gmt grdconvert loke-utm31-inv.nc -Gloke-utm31-inv.tif=gd:GTiff
    
    $ gmt grdinfo loke-utm31-inv.tif
    loke-utm31-inv.tif: Title: Grid imported via GDAL
    loke-utm31-inv.tif: Command: 
    loke-utm31-inv.tif: Remark: 
    loke-utm31-inv.tif: Gridline node registration used [Cartesian grid]
    loke-utm31-inv.tif: Grid file format: gd = Import/export through GDAL
    loke-utm31-inv.tif: x_min: 662330 x_max: 663040 x_inc: 1 name: x n_columns: 711
    loke-utm31-inv.tif: y_min: 8170380 y_max: 8171050 y_inc: 1 name: y n_rows: 671
    loke-utm31-inv.tif: v_min: -2457.73510742 v_max: -2303.93994141 name: z
    loke-utm31-inv.tif: scale_factor: 1 add_offset: 0
    

    It would be nice if this information was kept.

  9. maxrjones commented on Dec 2, 2021

    @maxrjones
    Member

    Would adding a new element to the header to store the citation history also be a breaking change?

  10. joa-quim commented on Dec 2, 2021

    @joa-quim
    Member

    Anything that changes the structures starting at is a breaking change. But the C struct GMT_GRID_HEADER { ends with a non-public void *hidden; that could eventually be used to add/read new attributes in the nc files with extended info. Doing it this way would not break anything.

  11. PaulWessel commented on Dec 2, 2021

    @PaulWessel
    ContributorAuthor

    Yes, I was going to ask you if you were also wrapping the HIDDEN structs, but if you don't then that gives me wiggle room to add things there. OK?

  12. joa-quim commented on Dec 2, 2021

    @joa-quim
    Member

    No wrapping of that void pointer. It just lays there wasting the 8 bytes of the pointer address. Feel free to stuff in that hidden jungle.

  13. PaulWessel commented on Dec 2, 2021

    @PaulWessel
    ContributorAuthor

    Oh boy, I will add in a link to a 2 Gb hidden grid just to bring your laptop to a halt.

  14. joa-quim commented on Dec 2, 2021

    @joa-quim
    Member

    Ah, that's a dwarf. Nothing like a good 3.6 GB Docker that wraps the monstrous (mini)Conda

  15. PaulWessel commented on Dec 5, 2021

    @PaulWessel
    ContributorAuthor

    In the spirit of Christmas I did not add any hidden grids, this time.

  16. maxrjones commented on Mar 18, 2022

    @maxrjones
    Member

    Longer history and remark strings were implemented in #6084, so I am closing this issue. Please reopen if there is more to be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

feature request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions