@@ -216,7 +216,7 @@ GMT_LOCAL int grdblend_init_blend_job(struct GMT_CTRL *GMT, char **files, unsign
216216 struct GMT_GRID_HEADER_HIDDEN * HH = NULL ;
217217 struct GMT_GRID_HEADER_HIDDEN * HHG = NULL ;
218218
219- char * sense [2 ] = {"normal" , "inverse" }, buffer [GMT_BUFSIZ ] = {"" }, res [4 ] = {"" };
219+ char * sense [2 ] = {"normal" , "inverse" }, buffer [PATH_MAX ] = {"" }, res [4 ] = {"" };
220220 static char * V_level = GMT_VERBOSE_CODES ;
221221 char Iargs [GMT_LEN256 ] = {"" }, Rargs [GMT_LEN256 ] = {"" }, cmd [GMT_LEN256 ] = {"" };
222222 double wesn [4 ], sub = 0.0 ;
@@ -439,15 +439,23 @@ GMT_LOCAL int grdblend_init_blend_job(struct GMT_CTRL *GMT, char **files, unsign
439439 /* The goal below is to come up with a wesn that a proper subset of the output grid while still not
440440 * exceeding the bounds of the current tile grid. The wesn below will be compatible with the output grid
441441 * but is not compatible with the input grid. grdsample will make the adjustment */
442+
443+ /* Tinny roundoff differences between wesn and t->wesn could cause jumps of one grid step and being
444+ responsible for what's reported in the forum topic (issue #8576)
445+ https://forum.generic-mapping-tools.org/t/lines-appear-when-the-resolution-is-increased/6011/3
446+ For percaution we limit the adjustment to be within half a grid increment and apply only x|y_min.
447+ */
442448 k = (unsigned int )rint ((MAX (h -> wesn [XLO ], t -> wesn [XLO ]) - h -> wesn [XLO ]) / h -> inc [GMT_X ] - h -> xy_off );
443449 wesn [XLO ] = h -> wesn [XLO ] + k * h -> inc [GMT_X ];
444- while (wesn [XLO ] < t -> wesn [XLO ]) wesn [XLO ] += t -> inc [GMT_X ]; /* Make sure we are not outside this grid */
450+ //while (wesn[XLO] < t->wesn[XLO]) wesn[XLO] += t->inc[GMT_X]; /* Make sure we are not outside this grid */
451+ while ((wesn [XLO ] - t -> wesn [XLO ]) < - t -> inc [GMT_X ] / 2 ) wesn [XLO ] += t -> inc [GMT_X ];
445452 k = (unsigned int )rint ((MIN (h -> wesn [XHI ], t -> wesn [XHI ]) - h -> wesn [XLO ]) / h -> inc [GMT_X ] - h -> xy_off );
446453 wesn [XHI ] = h -> wesn [XLO ] + k * h -> inc [GMT_X ];
447454 while (wesn [XHI ] > t -> wesn [XHI ]) wesn [XHI ] -= t -> inc [GMT_X ]; /* Make sure we are not outside this grid */
448455 k = (unsigned int )rint ((MAX (h -> wesn [YLO ], t -> wesn [YLO ]) - h -> wesn [YLO ]) / h -> inc [GMT_Y ] - h -> xy_off );
449456 wesn [YLO ] = h -> wesn [YLO ] + k * h -> inc [GMT_Y ];
450- while (wesn [YLO ] < t -> wesn [YLO ]) wesn [YLO ] += t -> inc [GMT_Y ]; /* Make sure we are not outside this grid */
457+ //while (wesn[YLO] < t->wesn[YLO]) wesn[YLO] += t->inc[GMT_Y]; /* Make sure we are not outside this grid */
458+ while ((wesn [YLO ] - t -> wesn [YLO ]) < - t -> inc [GMT_Y ] / 2 ) wesn [YLO ] += t -> inc [GMT_Y ]; /* Make sure we are not outside this grid */
451459 k = (unsigned int )rint ((MIN (h -> wesn [YHI ], t -> wesn [YHI ]) - h -> wesn [YLO ]) / h -> inc [GMT_Y ] - h -> xy_off );
452460 wesn [YHI ] = h -> wesn [YLO ] + k * h -> inc [GMT_Y ];
453461 while (wesn [YHI ] > t -> wesn [YHI ]) wesn [YHI ] -= t -> inc [GMT_Y ]; /* Make sure we are not outside this grid */
@@ -469,8 +477,13 @@ GMT_LOCAL int grdblend_init_blend_job(struct GMT_CTRL *GMT, char **files, unsign
469477 gmt_filename_set (B [n ].file ); /* Replace any spaces in filename with ASCII 29 */
470478 GMT -> common .V .active = false; /* Since we will parse again below */
471479 if (do_sample & 1 ) { /* Resampling of the grid into a netcdf grid */
472-
473- if (gmt_get_tempname (GMT -> parent , "grdblend_resampled" , ".nc" , buffer ))
480+ char template [GMT_LEN32 ] = {"" };
481+ /* We need different template name be cause MSVC is shamelessly ignoring what it states in the _mktemp_s man page
482+ https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/mktemp-s-wmktemp-s?view=msvc-170*
483+ and returns the same temp name over and over again causing that the sampled grids overwrite each other
484+ */
485+ sprintf (template , "grdblend_resampled_%d" , n );
486+ if (gmt_get_tempname (GMT -> parent , template , ".nc" , buffer ))
474487 return GMT_RUNTIME_ERROR ;
475488 snprintf (cmd , GMT_LEN256 , "%s %s %s %s -G%s -V%c" , B [n ].file , res ,
476489 Iargs , Rargs , buffer , V_level [GMT -> current .setting .verbose ]);
@@ -1038,12 +1051,14 @@ EXTERN_MSC int GMT_grdblend (void *V_API, int mode, void *args) {
10381051 /* Last case BLEND_LAST is always true in that we always update z[col] */
10391052 }
10401053 switch (Ctrl -> C .sign ) { /* Check if sign of input grid should be considered in decision */
1041- case -1 : if (first_grid ) {z [col ] = blend [k ].z [kk ]; first_grid = false; continue ; break ;} /* Must initialize with first grid in case nothing passes */
1042- else if (blend [k ].z [kk ] > 0.0 ) continue ; /* Only pick grids value if negative or zero */
1043- break ;
1044- case +1 : if (first_grid ) { z [col ] = blend [k ].z [kk ]; first_grid = false; continue ; break ;} /* Must initialize with first grid in case nothing passes */
1045- else if (blend [k ].z [kk ] < 0.0 ) continue ; /* Only pick grids value if positive or zero */
1046- break ;
1054+ case -1 :
1055+ if (first_grid ) {z [col ] = blend [k ].z [kk ]; first_grid = false; continue ; break ;} /* Must initialize with first grid in case nothing passes */
1056+ else if (blend [k ].z [kk ] > 0.0 ) continue ; /* Only pick grids value if negative or zero */
1057+ break ;
1058+ case +1 :
1059+ if (first_grid ) { z [col ] = blend [k ].z [kk ]; first_grid = false; continue ; break ;} /* Must initialize with first grid in case nothing passes */
1060+ else if (blend [k ].z [kk ] < 0.0 ) continue ; /* Only pick grids value if positive or zero */
1061+ break ;
10471062 default : break ; /* Always use the grid value */
10481063
10491064 }
0 commit comments