Skip to content

Preserve grid data when writing NetCDF grids through the API - #9322

Open
traitimtrongvag wants to merge 1 commit into
GenericMappingTools:masterfrom
traitimtrongvag:fix/grid-write
Open

traitimtrongvag wants to merge 1 commit into
GenericMappingTools:masterfrom
traitimtrongvag:fix/grid-write

Conversation

@traitimtrongvag

Copy link
Copy Markdown

Summary

Writing a grid through GMT_Write_Data can modify the caller-owned grid, including its data and metadata. This change prevents those side effects for ordinary full-grid file writes through an external API session.

Changes

  • Write through a private grid copy so writer-side transformations do not alter the caller's grid.
  • Release the copy on both successful and failed writes.
  • Add regression tests covering scaled NetCDF writes, repeated writes, write failures, and preservation of the original grid.
  • Ensure the API test script reports helper failures correctly.

Testing

  • Fresh CMake configure and build completed successfully.
  • testapi_gmtgrid passed.
  • ctest -R 'apigmtgrid|test_grid_io' passed (2/2 tests).
  • Valgrind invalid-access checks reported no errors.

Limitations

Full leak analysis, ASan/UBSan, and Fortran coverage have not been completed.

Keep caller-owned grid data and metadata unchanged when writing ordinary full-grid files through an external API session.
Use a private grid copy for the writer path and release it after writing, including error returns.
Add regression coverage for scaled NetCDF writes, repeated writes, write failures, and caller-state preservation. Ensure the API test script propagates helper failures.
Validation: fresh configure/build succeeded; direct grid API tests and the apigmtgrid and test_grid_io CTest tests passed. Valgrind invalid-access checks reported no errors. Full leak analysis, sanitizer validation, and Fortran coverage remain outstanding.
@joa-quim

Copy link
Copy Markdown
Member

If you have a concrete case where this happens, please report it (we know of a case and have even a issue open on it), but we are not going to accept AI long code changes like this.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants