From fd7c7c6dabc84429490cf7e8e231f388fba58bbd Mon Sep 17 00:00:00 2001 From: Paul Wessel Date: Mon, 15 May 2023 10:11:26 +0200 Subject: [PATCH 1/2] Check if slice dz is negative as well Given the dumb arc CPT posted in the forum, I found that the very last record (#21000!) missed the zmax and thus GMT read red (255) as the upper z, while zmin was 20999. But, because our check for error only checks if dz == 0 we dont catch his snafu. THis PR now checks that dz is not zero nor negative. --- src/gmt_support.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gmt_support.c b/src/gmt_support.c index d8f4f42ff65..d653c7d48ae 100644 --- a/src/gmt_support.c +++ b/src/gmt_support.c @@ -8517,8 +8517,8 @@ struct GMT_PALETTE * gmtlib_read_cpt (struct GMT_CTRL *GMT, void *source, unsign } if (!X->categorical) { dz = X->data[n].z_high - X->data[n].z_low; - if (dz == 0.0) { - GMT_Report (GMT->parent, GMT_MSG_ERROR, "Z-slice with dz = 0\n"); + if (dz <= 0.0) { + GMT_Report (GMT->parent, GMT_MSG_ERROR, "Z-slice around line %d with dz <= 0\n", n); if (Z) gmt_M_free (GMT, Z); gmtlib_free_palette (GMT, &X); if (close_file) fclose (fp); From af7fa707236211ba86d6ac358395c1465a8f15fa Mon Sep 17 00:00:00 2001 From: Paul Wessel Date: Mon, 15 May 2023 10:18:57 +0200 Subject: [PATCH 2/2] Two more places also fixed --- src/gmt_support.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gmt_support.c b/src/gmt_support.c index d653c7d48ae..1afdd867d7e 100644 --- a/src/gmt_support.c +++ b/src/gmt_support.c @@ -8592,8 +8592,8 @@ struct GMT_PALETTE * gmtlib_read_cpt (struct GMT_CTRL *GMT, void *source, unsign for (i = 0; i < X->n_colors; i++) { X->data[i].z_high = (i == (X->n_colors-1)) ? X->data[i].z_low + dz : X->data[i+1].z_low; dz = X->data[i].z_high - X->data[i].z_low; - if (dz == 0.0) { - GMT_Report (GMT->parent, GMT_MSG_ERROR, "Z-slice with dz = 0\n"); + if (dz <= 0.0) { + GMT_Report (GMT->parent, GMT_MSG_ERROR, "Z-slice around line %d with dz <= 0\n", i); return (NULL); } X->data[i].i_dz = 1.0 / dz; @@ -9317,11 +9317,11 @@ struct GMT_PALETTE *gmt_sample_cpt (struct GMT_CTRL *GMT, struct GMT_PALETTE *Pi if (P->data[i].hsv_diff[0] > 180.0) P->data[i].hsv_diff[0] -= 360.0; } f = P->data[i].z_high - P->data[i].z_low; - if (f == 0.0) { + if (f <= 0.0) { gmt_M_free (GMT, x); gmt_M_free (GMT, lut); if (log_mode) gmt_M_free (GMT, z_out); - GMT_Report (GMT->parent, GMT_MSG_ERROR, "Z-slice with dz = 0\n"); + GMT_Report (GMT->parent, GMT_MSG_ERROR, "Z-slice around line %d with dz <= 0\n", i); return (NULL); } P->data[i].i_dz = 1.0 / f;