makecpt and grd2cpt overwrite explicit +c category labels with +k keys

Open Beginner friendly
#9,377 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@yousizaitianqiong is already working on this.

Since Dec 4, 2026.

  • #9379 by @yousizaitianqiong — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c
Domain
backend, cli

Research direction

Start by reading the -F documentation and shared helper in src/gmt_support.c, especially the label and key handling cited in the issue. Reproduce the problem with the provided makecpt command, then check the same behavior in grd2cpt. Done means +kA sets lookup keys A, B, C while the explicit labels remain Wood, Water, Gold in both commands.

Written by the indexing model from the issue text.

Description

Description of the problem

When -F+c supplies display labels and +k supplies lookup keys, the keys also replace the display labels. The one-command example from the PR that introduced +k reproduces this with an ASCII palette. Original example

Full script that reproduces the problem

gmt makecpt -Ccategorical -T0/2/1 -F+cWood,Water,Gold+kA

Actual outcome

A	green	L	;A
B	blue	L	;B
C	red	B	;C
N	128

The command exits 0 with empty stderr. Removing +kA writes ;Wood, ;Water and ;Gold. Removing +cWood,Water,Gold writes the keys as default labels, as expected.

Expected outcome

The first three rows should have lookup keys A, B, C and labels ;Wood, ;Water, ;Gold. The -F documentation describes these two fields separately. On master at 51117ebe, the shared helper assigns the labels and then copies each key over its label. Option documentation · Shared helper

grd2cpt shows the same behavior. The following commands produce A and B as the keys and as the labels, despite the explicit Wood and Water labels.

gmt grdmath -R0/2/0/2 -I0.5 X = grid.nc
gmt grd2cpt grid.nc -Cturbo -T0/2/1 -F+cWood,Water+kA

System information

Windows 11 x86-64, GMT 6.7.0, classic mode.

Dominant language
C
Stars
999
Forks
421
Avg merge
12h 59m
Merged PRs (30d)
58

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from GenericMappingTools/gmt

All issues in GenericMappingTools/gmt

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.