Skip to content

Commit ac5d35b

Browse files
authored
Fix #8736 (#8739)
There was (and still is a bit) with header contents being fished from the text column. This PR fixes it but, for compat reasons, still fishes first text record and puts it in header too.
1 parent c33c5f5 commit ac5d35b

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

src/grdinterpolate.c

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -506,37 +506,32 @@ EXTERN_MSC int GMT_grdinterpolate (void *V_API, int mode, void *args) {
506506
struct GMT_DATASEGMENT *Si = NULL;
507507

508508
if (Ctrl->S.file) { /* Read a list of points, the list may have trailing text which may be activated by -S...+h */
509-
if ((In = GMT_Read_Data (API, GMT_IS_DATASET, GMT_IS_FILE, GMT_IS_POINT, GMT_READ_NORMAL, NULL, Ctrl->S.file, NULL)) == NULL) {
510-
GMT_Report (API, GMT_MSG_ERROR, "Unable to open or read file %s.\n", Ctrl->S.file);
509+
if ((In = GMT_Read_Data(API, GMT_IS_DATASET, GMT_IS_FILE, GMT_IS_POINT, GMT_READ_NORMAL, NULL, Ctrl->S.file, NULL)) == NULL) {
510+
GMT_Report(API, GMT_MSG_ERROR, "Unable to open or read file %s.\n", Ctrl->S.file);
511511
Return (API->error);
512512
}
513513
if (Ctrl->S.header) { /* Want to use this fixed text to add to the trailing text of all the points */
514514
for (seg = 0; seg < In->n_segments; seg++) {
515515
Si = In->table[0]->segment[seg]; /* Short hand to this segment */
516-
if (Si->text == NULL) /* Input file did not have any trailing text so add array now */
517-
Si->text = gmt_M_memory (GMT, NULL, Si->n_rows, char *);
518-
for (row = 0; row < Si->n_rows; row++) {
519-
if (Si->text[row]) { /* Already has trailing text, combine with user argument */
520-
sprintf (header, "%s %s", Si->text[row], Ctrl->S.header);
521-
gmt_M_str_free (Si->text[row]);
522-
Si->text[row] = strdup (header);
523-
}
524-
else /* Just use user argument */
525-
Si->text[row] = strdup (Ctrl->S.header);
516+
if (Si->text != NULL) { /* Input file did not have any trailing text so add array now */
517+
sprintf(header, "%s %s", Si->text[0], Ctrl->S.header);
518+
Si->header = strdup(header);
526519
}
520+
else
521+
Si->header = strdup(Ctrl->S.header);
527522
}
528523
}
529524
}
530525
else { /* Single point, simplify logic below by making a 1-point dataset */
531-
if ((In = GMT_Create_Data (API, GMT_IS_DATASET, GMT_IS_POINT, (Ctrl->S.header) ? GMT_WITH_STRINGS : 0, dim, NULL, NULL, 0, 0, NULL)) == NULL) {
532-
GMT_Report (API, GMT_MSG_ERROR, "Unable to open or read file %s.\n", Ctrl->S.file);
526+
if ((In = GMT_Create_Data(API, GMT_IS_DATASET, GMT_IS_POINT, (Ctrl->S.header) ? GMT_WITH_STRINGS : 0, dim, NULL, NULL, 0, 0, NULL)) == NULL) {
527+
GMT_Report(API, GMT_MSG_ERROR, "Unable to open or read file %s.\n", Ctrl->S.file);
533528
Return (API->error);
534529
}
535530
Si = In->table[0]->segment[0]; /* Short hand to the first and only segment */
536531
Si->data[GMT_X][0] = Ctrl->S.x;
537532
Si->data[GMT_Y][0] = Ctrl->S.y;
538533
if (Ctrl->S.header) /* Set the fixed header here via trailing text */
539-
Si->text[0] = strdup (Ctrl->S.header);
534+
Si->header = strdup(Ctrl->S.header);
540535
Si->n_rows = 1;
541536
gmt_set_dataset_minmax (GMT, In);
542537
}
@@ -599,11 +594,15 @@ EXTERN_MSC int GMT_grdinterpolate (void *V_API, int mode, void *args) {
599594
for (row = 0; row < Si->n_rows; row++, rec++) { /* For each selected point which matches each output segment */
600595
So = Out->table[0]->segment[rec]; /* Short hand to this output segment */
601596
if (k == start_k) { /* Set the segment header just once */
602-
if (Si->text && Si->text[row])
603-
sprintf (header, "Location %.12g,%.12g %s", Si->data[GMT_X][row], Si->data[GMT_Y][row], Si->text[row]);
604-
else
605-
sprintf (header, "Location %.12g,%.12g", Si->data[GMT_X][row], Si->data[GMT_Y][row]);
606-
So->header = strdup (header);
597+
if (Si->header && Si->header[0])
598+
sprintf(header, "Location %.12g,%.12g %s", Si->data[GMT_X][row], Si->data[GMT_Y][row], Si->header);
599+
else {
600+
if (Si->text && Si->text[row])
601+
sprintf(header, "Location %.12g,%.12g %s", Si->data[GMT_X][row], Si->data[GMT_Y][row], Si->text[row]);
602+
else
603+
sprintf(header, "Location %.12g,%.12g", Si->data[GMT_X][row], Si->data[GMT_Y][row]);
604+
}
605+
So->header = strdup(header);
607606
}
608607
if (Ctrl->S.active) { /* Want x,y,z[,.....],value output */
609608
for (col = 0; col < GMT_Z; col++) /* Copy over x,y */

0 commit comments

Comments
 (0)