Skip to content

grdview: Fix the bug when -N is set but level is not specified - #9123

Open
seisman wants to merge 1 commit into
masterfrom
grdview/default-z-plane
Open

grdview: Fix the bug when -N is set but level is not specified#9123
seisman wants to merge 1 commit into
masterfrom
grdview/default-z-plane

Conversation

@seisman

@seisman seisman commented Aug 8, 2026

Copy link
Copy Markdown
Member

According to the documentation (https://docs.generic-mapping-tools.org/dev/grdview#n), when -N is set but -R isn't, the default level should be the minimum value in the grid.

-N[level][+gfill]
Draws a plane at this z-level. If the optional color is provided via the +g modifier, and the projection is not oblique, the frontal facade between the plane and the data perimeter is colored. See -Wf for setting the pen used for the outline. If no level is set then we default to the minimum value in the reliefgrid. However, if -R was used to set zmin/zmax then we use that value if it is less than the grid minimum value.

However, the default level is set to 0 due to a bug. This can be verified by the following test:

gmt begin map
    gmt grdview @static_earth_relief.nc -Jz0.005 -Wf0.5p,blue,dashed -p225/30 -Baf -Bzaf -N
    gmt grdview @static_earth_relief.nc -Jz0.005 -Wf0.5p,blue,dashed -p225/30 -Baf -Bzaf -N -R-55/-47/-24/-10/0/1000 -Xw+1c
    gmt grdview @static_earth_relief.nc -Jz0.005 -Wf0.5p,blue,dashed -p225/30 -Baf -Bzaf -N190 -Xw+1c
gmt end show
Actual output Expected output
map map

When -R is not specified, GMT first determines the z-range based on the grid min/max values, then checks if Ctrl->N.level is set and updates zmin to Ctrl->N.level if zmin<level, as shown below:

gmt/src/grdview.c

Lines 990 to 996 in d52a1e5

/* Set default z-range for plot to be that of the grid if not specified via -R */
if (GMT->common.R.wesn[ZLO] == 0.0 && GMT->common.R.wesn[ZHI] == 0.0) {
GMT->common.R.wesn[ZLO] = Topo->header->z_min;
GMT->common.R.wesn[ZHI] = Topo->header->z_max;
if (Ctrl->N.active && Ctrl->N.level < GMT->common.R.wesn[ZLO]) GMT->common.R.wesn[ZLO] = Ctrl->N.level;
if (Ctrl->N.active && Ctrl->N.level > GMT->common.R.wesn[ZHI]) GMT->common.R.wesn[ZHI] = Ctrl->N.level;
}

However, when -N is set without any level, Ctrl->N.implicit is true and Ctrl->N.level is not set until

gmt/src/grdview.c

Line 1320 in d52a1e5

Ctrl->N.level = Topo->header->z_min;

so, Ctrl->N.level still has the initial value (0.0), and then zmin is updated to 0.0 in this case.

This PR fixes the issue.

@seisman seisman added the add-changelog Add PR to the changelog label Aug 8, 2026
@seisman seisman added this to the 6.8.0 milestone Aug 8, 2026
@seisman seisman added the bug Something isn't working label Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

add-changelog Add PR to the changelog bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant