Skip to content

GMT grdblend: inputs that need reformatting or resampling come back garbled #9248

Description

@joa-quim

A bit long report By Claude but confirmed by me that it is true

GMT grdblend: inputs that need reformatting or resampling come back garbled (Windows)

Found 2026-10-08 blending two DGT MDS-2m GeoTIFF tiles (2 m, pixel registered, ETRS89 / PT-TM06):
MDS-2m-196014-04-2024.tiff + MDS-2m-196015-04-2024.tiff, -R-4000/-3000/-287000/-285000 -I2.

Symptoms

inputs output nodes with data (should be 445196 / ~446392)
the two .tiff, -r pixel 140000, all crammed into x -3999..-3721
the two .tiff, no -r gridline 135923
same grids saved as .nc, -r pixel 445196 (correct)
same grids saved as .nc, no -r gridline 135923 (wrong: goes through the resample branch)
in memory, already on the output lattice either correct

Also printed: Failed to remove c:\TMP/grdblend_reformatted_XXXX.nc! [remove error: Permission denied].

Cause (grdblend.c, grdblend_init_blend_job)

  1. Reformat branch (non-netCDF input -> grdconvert):
    gmt_get_tempname(GMT->parent, "grdblend_reformatted", ".nc", buffer) uses ONE fixed template.
    With MSVC _mktemp_s returning the same name every time (the comment in the resample branch
    says so), every reformatted input is written into the same file: the second overwrites the
    first while it is still open (hence the failed delete). The resample branch already works
    around this with sprintf(template, "grdblend_resampled_%d", n); the reformat branch does not.
    Probable fix: the same per-input template, e.g. "grdblend_reformatted_%d".
  2. After either branch the re-read grid goes through
    grdblend_overlap_check (GMT, &B[n], h, 0) UNCONDITIONALLY. That is the longitude +-360 check
    (its earlier calls are guarded by gmt_M_x_is_lon); on a Cartesian/projected grid it "adjusts"
    x by 360 (-Vi: "grid region needed longitude adjustment", -Vd: out: -360/140), so only
    140 of the tile's 500 columns land on the output. This is the main cause of the wrong output.

MWE (Julia, GMT.jl)

using GMT
a = raw"C:\Users\j\.gmt\DGT\MDS-2m\MDS-2m-196014-04-2024.tiff"
b = raw"C:\Users\j\.gmt\DGT\MDS-2m\MDS-2m-196015-04-2024.tiff"
R = grdblend("\"$a\" \"$b\""; R="-4000/-3000/-287000/-285000", I=2, r=true)
count(!isnan, R.z)            # 140000, expected 445196

Activity

  1. added a commit that references this issue on Oct 8, 2026
  2. joa-quim commented on Oct 8, 2026

    @joa-quim
    MemberAuthor

    Fixed

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    add-changelogAdd PR to the changelogbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions