Skip to content

Fix dropped fractional digit in latitude annotations for FORMAT_GEO_MAP with 3 decimals - #9155

Merged
Esteban82 merged 2 commits into
masterfrom
fix-9154
Aug 27, 2026
Merged

Fix dropped fractional digit in latitude annotations for FORMAT_GEO_MAP with 3 decimals#9155
Esteban82 merged 2 commits into
masterfrom
fix-9154

Conversation

@Esteban82

Copy link
Copy Markdown
Member

Summary

Fixes #9154.

gmtlib_get_annot_label() (in gmt_support.c) shrinks the leading degree field of the plot format string from 3 digits to 2 for latitudes (max 90°, vs 360° for longitudes) by doing a text substitution: replace every "%3.3d" in the format string with "%2.2d".

The bug: when FORMAT_GEO_MAP requests exactly 3 fractional digits (e.g. ddd.xxxF), the fractional-part printf format built for that case is also literally "%3.3d" — same text, unrelated purpose. The blind, whole-string gmt_strrep() call corrupted that fractional format too, shrinking it from 3 digits to 2. This silently dropped the leading zero of any fraction that happened to be 0** (e.g. .024 became .24), while leaving the value visually plausible (9.0209.20 → rendered as if only two decimals had been requested).

This only manifests for latitudes with exactly 3 fractional digits — ddd.xxF (2 digits) and ddd.xxxxF (4 digits) don't produce the literal string "%3.3d" anywhere else in the format, so they were unaffected. That matches the issue report exactly (3rd panel wrong, 4th panel correct).

Fix

Only replace the leading degree field — which is always at position 0 of the format string — instead of replacing every occurrence of "%3.3d" anywhere in the string.

Test plan

  • Reproduced the bug with the PyGMT snippet from the issue, translated to plain GMT (FORMAT_GEO_MAP=ddd.xxxF, -Ba0.0001) — before the fix, y-axis annotations read 9.24°N, 9.23°N, 9.21°N, ... (2 digits, leading zero dropped); after the fix they correctly read 9.024°N, 9.023°N, 9.021°N, ... (3 digits).
  • Confirmed ddd.xxF / ddd.xxxxF (2 and 4 decimals) were unaffected before and after.
  • Built with ninja gmt (warnings-only, pre-existing and unrelated to this file).
  • Ran the doc/scripts ctest suite's -B_geo tests; GMT_-B_geo_2 fails identically on master and on this branch (pre-existing, unrelated font-rendering baseline diff), GMT_-B_geo_1 passes on both.

Assisted-by: Claude Sonnet 5 (medium effort)

…AP with 3 decimals

gmtlib_get_annot_label() used gmt_strrep() to shrink the leading degree
field from 3 to 2 digits for latitudes (max 90, vs 360 for longitudes),
by replacing every "%3.3d" in the plot format string with "%2.2d".

When FORMAT_GEO_MAP requests exactly 3 fractional digits (e.g.
"ddd.xxxF"), the fractional-part format is also literally "%3.3d", so
gmt_strrep corrupted it too: a latitude fraction of e.g. .024 got
padded to only 2 digits and printed as "24" instead of "024", turning
"9.024" into "9.24" (i.e. the leading zero after the decimal point was
dropped).

Only replace the leading degree field (which is always at the start of
the format string) instead of every occurrence of "%3.3d" anywhere in
the string.

Fixes #9154

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@Esteban82 Esteban82 added AI-assisted All (or most) of the code was written by Artificial Intelligence. add-changelog Add PR to the changelog labels Aug 27, 2026
@Esteban82 Esteban82 changed the title Fix dropped fractional digit in latitude annotations for FORMAT_GEO_MAP with 3 decimals WIP Fix dropped fractional digit in latitude annotations for FORMAT_GEO_MAP with 3 decimals Aug 27, 2026
Comment thread src/gmt_support.c Outdated
@Esteban82

Esteban82 commented Aug 27, 2026

Copy link
Copy Markdown
Member Author

I tested with this script

R="38/38.0002/9/9.0002"

gmt begin test_9154 png
	gmt set FORMAT_GEO_MAP=ddd.xxF
	gmt basemap -R$R -JM4c -Ba0.0001

	gmt set FORMAT_GEO_MAP=ddd.xxxF
	gmt basemap -R$R -Ba0.0001 -X6c

	gmt set FORMAT_GEO_MAP=ddd.xxxxF
	gmt basemap -R$R -Ba0.0001 -X6c
gmt end
test_9154

Trim the multi-line comment explaining the historical bug down to a
single line describing the non-obvious WHY of the code as it stands.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@Esteban82 Esteban82 changed the title WIP Fix dropped fractional digit in latitude annotations for FORMAT_GEO_MAP with 3 decimals Fix dropped fractional digit in latitude annotations for FORMAT_GEO_MAP with 3 decimals Aug 27, 2026
@joa-quim

Copy link
Copy Markdown
Member

We need to revise the walls of text produced by the Agents. That is why I think we should not accept PR submitted by them. The "Test Plan" is clearly not needed here.

@Esteban82

Copy link
Copy Markdown
Member Author

We need to revise the walls of text produced by the Agents. That is why I think we should not accept PR submitted by them. The "Test Plan" is clearly not needed here.

Yes, I agree.

@Esteban82
Esteban82 merged commit 86a7acc into master Aug 27, 2026
8 of 12 checks passed
@Esteban82
Esteban82 deleted the fix-9154 branch August 27, 2026 16:51
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 AI-assisted All (or most) of the code was written by Artificial Intelligence.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

zero after comma are skipped in frame annotations

3 participants