Skip to content

Pass GMT_GRID_NEEDS_PAD1 flag to GMT_Read_Data in grdfill - #6418

Merged
maxrjones merged 6 commits into
masterfrom
fix-grdfill-bug
Mar 23, 2022
Merged

maxrjones merged 6 commits into
masterfrom
fix-grdfill-bug

Conversation

@maxrjones

Copy link
Copy Markdown
Member

Description of proposed changes

This PR fixes the bug reported by GenericMappingTools/pygmt#1745. This crash occurred in cases where Grid->header->pad[YHI]> Grid->header->pad[YLO].

Fixes #

Reminders

  • Make sure that your code follows our style. Use the other functions/files as a basis.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Describe changes to function behavior and arguments in a comment below the function declaration.
  • If adding new functionality, add a detailed description to the documentation and/or an example.

Comment thread src/grdfill.c Resolved
Comment thread src/testapi_matrix_grdfill.c Resolved
@PaulWessel

Copy link
Copy Markdown
Contributor

I am not sure this will work. If I understand, you wish to pass in a grid that then should have these odd pads. Once you read it in the array is allocated. I think you have to doctor this by

  1. set the pad as you do
  2. Modify the header->wesn to reflect that (ie., extend region if pad < 2 and shrink if > 2. Then call those two functions.
  3. Once that is done you call the virtual file
    You should be able to verify by looking at the header and sizes etc that the grid/matrix has the properties you want before doing the module call.

Sorry, bedtime for Bonzo here now.

@maxrjones maxrjones added this to the 6.4.0 milestone Mar 23, 2022
@maxrjones maxrjones added the bug Something isn't working label Mar 23, 2022
@maxrjones maxrjones changed the title Fix issue with grdfill when pad is asymmetric WIP: Fix issue with grdfill when pad is asymmetric Mar 23, 2022
@maxrjones maxrjones changed the title WIP: Fix issue with grdfill when pad is asymmetric Fix issue with grdfill when pad is asymmetric Mar 23, 2022
@maxrjones

Copy link
Copy Markdown
Member Author

I revised this PR to use a simpler fix by requiring a pad of at least 1 for grdfill. I also removed the C API test because the pad kept getting set as 2 regardless of adjustments to the order of setting the pad, adjusting the header, and calling the virtual file. I will add a PyGMT regression test instead.

@maxrjones maxrjones changed the title Fix issue with grdfill when pad is asymmetric Pass GMT_GRID_NEEDS_PAD1 flag to GMT_Read_Data in grdfill Mar 23, 2022
@maxrjones
maxrjones requested a review from PaulWessel March 23, 2022 18:14
Comment thread src/grdfill.c
offset = (uint64_t)(Grid->header->pad[YHI] + Grid->header->n_rows) * Grid->header->mx;
for (node = 0; node < (openmp_int)Grid->header->mx; node++) ID[node] = ID[node+offset] = 1;
/* Set the left and right boundary columns to UINT_MAX */
for (node = 0; node < (uint64_t)Grid->header->pad[YHI]*Grid->header->mx; node++) ID[node] = ID[node+offset] = 1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit makes me some tickles. Just wondering. What if the grid received was written top-down (netCDF grids can be either bottom-up or top-down). Shouldn't it then use pad[YLO]?
Ofc, this may have no sense but seeing something depending on the axis direction when we can have both directions makes my bug bell to ring.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the top/bottom order is dealt with in gmt_nc when the file is read. By the time GMT modules get grids they are in the expected orientation.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarification (just in case), this commit is reverting my changes back to the original code. I could go back to modifying the code to only set one boundary column/row on each side to 1.

@maxrjones
maxrjones merged commit c6e738c into master Mar 23, 2022
@maxrjones
maxrjones deleted the fix-grdfill-bug branch March 23, 2022 21:24

This branch was previously deployed

1 inactive deployment
Preview — ec6616e9 Deployed Mar 23, 2022 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants