Skip to content

Commit 7a2805e

Browse files
authored
Address bug in grdseamount -M option (#3711)
The writing of the filenames etc to the list file with -M crashed because we did not pass theGMT_WITH_STRINGS when creating the dataset. I also added time as the first column since the initial version of this went back to text output days (it was all a string record) but it makes sense to write the time as a floating point, followed by the filename and the formatted time label.
1 parent e9b0b35 commit 7a2805e

File tree

1 file changed

+22
-39
lines changed

1 file changed

+22
-39
lines changed

src/potential/grdseamount.c

Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ EXTERN_MSC int GMT_grdseamount (void *V_API, int mode, void *args) {
506506

507507
/*---------------------------- This is the grdseamount main code ----------------------------*/
508508

509-
/* Specify inputexpected columns */
509+
/* Specify expected columns */
510510
n_expected_fields = ((Ctrl->E.active) ? 6 : 4) + ((Ctrl->F.mode == TRUNC_FILE) ? 1 : 0);
511511
if (Ctrl->T.active) n_expected_fields += 2; /* The two cols with start and stop time */
512512
if ((error = GMT_Set_Columns (API, GMT_IN, (unsigned int)n_expected_fields, GMT_COL_FIX_NO_TEXT)) != GMT_NOERROR) {
@@ -570,16 +570,10 @@ EXTERN_MSC int GMT_grdseamount (void *V_API, int mode, void *args) {
570570

571571
if (Ctrl->L.active) { /* Just list area, volume, etc. for each seamount; no grid needed */
572572
n_out = (unsigned int)n_expected_fields + 3;
573-
if ((error = GMT_Set_Columns (API, GMT_OUT, n_out, GMT_COL_FIX_NO_TEXT)) != GMT_NOERROR) {
574-
gmt_M_free (GMT, V); gmt_M_free (GMT, V_sum);
575-
gmt_M_free (GMT, h); gmt_M_free (GMT, h_sum);
576-
Return (error);
577-
}
578-
if (GMT_Init_IO (API, GMT_IS_DATASET, GMT_IS_POINT, GMT_OUT, GMT_ADD_DEFAULT, 0, options) != GMT_NOERROR) { /* Registers default output destination, unless already set */
579-
gmt_M_free (GMT, V); gmt_M_free (GMT, V_sum);
580-
gmt_M_free (GMT, h); gmt_M_free (GMT, h_sum);
581-
Return (API->error);
582-
}
573+
if ((error = GMT_Set_Columns (API, GMT_OUT, n_out, GMT_COL_FIX_NO_TEXT)) != GMT_NOERROR)
574+
goto wrap_up;
575+
if (GMT_Init_IO (API, GMT_IS_DATASET, GMT_IS_POINT, GMT_OUT, GMT_ADD_DEFAULT, 0, options) != GMT_NOERROR) /* Registers default output destination, unless already set */
576+
goto wrap_up;
583577
}
584578

585579
/* 0. DETERMINE THE NUMBER OF TIME STEPS */
@@ -590,13 +584,12 @@ EXTERN_MSC int GMT_grdseamount (void *V_API, int mode, void *args) {
590584
}
591585

592586
if (Ctrl->M.active) { /* Must create dataset to hold names of all output grids */
593-
uint64_t dim[GMT_DIM_SIZE] = {1, 1, Ctrl->T.n_times, 0};
587+
uint64_t dim[GMT_DIM_SIZE] = {1, 1, Ctrl->T.n_times, 1};
594588
unsigned int k, j;
595-
if ((L = GMT_Create_Data (API, GMT_IS_DATASET, GMT_IS_NONE, 0, dim, NULL, NULL, 0, 0, NULL)) == NULL) {
589+
if ((L = GMT_Create_Data (API, GMT_IS_DATASET, GMT_IS_NONE, GMT_WITH_STRINGS, dim, NULL, NULL, 0, 0, NULL)) == NULL) {
596590
GMT_Report (API, GMT_MSG_INFORMATION, "Failure while creating text set for file %s\n", Ctrl->M.file);
597-
gmt_M_free (GMT, V); gmt_M_free (GMT, V_sum);
598-
gmt_M_free (GMT, h); gmt_M_free (GMT, h_sum);
599-
Return (GMT_RUNTIME_ERROR);
591+
API->error = GMT_RUNTIME_ERROR;
592+
goto wrap_up;
600593
}
601594
L->table[0]->segment[0]->n_rows = Ctrl->T.n_times;
602595
for (k = j = 0; Ctrl->G.file[k] && Ctrl->G.file[k] != '%'; k++); /* Find first % */
@@ -649,14 +642,9 @@ EXTERN_MSC int GMT_grdseamount (void *V_API, int mode, void *args) {
649642
}
650643
gmt_M_free (GMT, Out);
651644
if (Ctrl->L.active) { /* OK, that was all we wanted */
652-
if (GMT_End_IO (API, GMT_OUT, 0) != GMT_NOERROR) { /* Disables further data output */
653-
gmt_M_free (GMT, V); gmt_M_free (GMT, V_sum);
654-
gmt_M_free (GMT, h); gmt_M_free (GMT, h_sum);
655-
Return (API->error);
656-
}
657-
gmt_M_free (GMT, V); gmt_M_free (GMT, V_sum);
658-
gmt_M_free (GMT, h); gmt_M_free (GMT, h_sum);
659-
Return (GMT_NOERROR);
645+
if (GMT_End_IO (API, GMT_OUT, 0) != GMT_NOERROR) /* Disables further data output */
646+
goto wrap_up;
647+
goto wrap_up;
660648
}
661649

662650
/* Set up and allocate output grid */
@@ -892,6 +880,7 @@ EXTERN_MSC int GMT_grdseamount (void *V_API, int mode, void *args) {
892880
}
893881
else
894882
strcpy (record, file);
883+
L->table[0]->segment[0]->data[GMT_X][t_use] = Ctrl->T.time[t].value;
895884
L->table[0]->segment[0]->text[t_use++] = strdup (record);
896885
L->table[0]->segment[0]->n_rows++;
897886
}
@@ -902,29 +891,23 @@ EXTERN_MSC int GMT_grdseamount (void *V_API, int mode, void *args) {
902891
for (ij = 0; ij < Grid->header->size; ij++) Grid->data[ij] *= (gmt_grdfloat)n_scl;
903892
}
904893

905-
if (GMT_Set_Comment (API, GMT_IS_GRID, GMT_COMMENT_IS_OPTION | GMT_COMMENT_IS_COMMAND, options, Grid)) {
906-
gmt_M_free (GMT, d_col); gmt_M_free (GMT, V); gmt_M_free (GMT, h);
907-
gmt_M_free (GMT, V_sum); gmt_M_free (GMT, h_sum); gmt_M_free (GMT, data);
908-
Return (API->error);
909-
}
894+
if (GMT_Set_Comment (API, GMT_IS_GRID, GMT_COMMENT_IS_OPTION | GMT_COMMENT_IS_COMMAND, options, Grid))
895+
goto wrap_up;
910896
gmt_M_memcpy (data, Grid->data, Grid->header->size, gmt_grdfloat); /* This will go away once gmt_nc.c is fixed to leave array alone */
911-
if (GMT_Write_Data (API, GMT_IS_GRID, GMT_IS_FILE, GMT_IS_SURFACE, GMT_CONTAINER_AND_DATA, NULL, file, Grid) != GMT_NOERROR) {
912-
gmt_M_free (GMT, d_col); gmt_M_free (GMT, V); gmt_M_free (GMT, h);
913-
gmt_M_free (GMT, V_sum); gmt_M_free (GMT, h_sum); gmt_M_free (GMT, data);
914-
Return (API->error);
915-
}
897+
if (GMT_Write_Data (API, GMT_IS_GRID, GMT_IS_FILE, GMT_IS_SURFACE, GMT_CONTAINER_AND_DATA, NULL, file, Grid) != GMT_NOERROR)
898+
goto wrap_up;
916899
gmt_M_memcpy (Grid->data, data, Grid->header->size, gmt_grdfloat);
917900
}
918-
if (Ctrl->M.active) L->table[0]->n_records = t_use;
901+
if (Ctrl->M.active) L->table[0]->n_records = L->table[0]->segment[0]->n_rows = t_use;
919902
if (Ctrl->M.active && GMT_Write_Data (API, GMT_IS_DATASET, GMT_IS_FILE, GMT_IS_NONE, 0, NULL, Ctrl->M.file, L) != GMT_NOERROR) {
920903
GMT_Report (API, GMT_MSG_ERROR, "Failure while writing list of grid files to %s\n", Ctrl->M.file);
921-
gmt_M_free (GMT, d_col); gmt_M_free (GMT, V); gmt_M_free (GMT, h);
922-
gmt_M_free (GMT, V_sum); gmt_M_free (GMT, h_sum); gmt_M_free (GMT, data);
923-
Return (API->error);
904+
goto wrap_up;
924905
}
925906

907+
wrap_up:
908+
926909
gmt_M_free (GMT, d_col); gmt_M_free (GMT, V); gmt_M_free (GMT, h);
927910
gmt_M_free (GMT, V_sum); gmt_M_free (GMT, h_sum); gmt_M_free (GMT, data);
928911

929-
Return (GMT_NOERROR);
912+
Return (API->error);
930913
}

0 commit comments

Comments
 (0)