Skip to content

Commit

Permalink
Eliminate misleading pointer from blend structure (#3548)
Browse files Browse the repository at this point in the history
* Eliminate misleading pointer from blend structure

The HH pointer in the blend array was set to point to the hidden structure in the grid header and used once.  But then we destroy the grid and now the pointer is pointing to junk.  Could be confusing down the road.  So now removed and we use a single variable to get the hidden content in the only place where it is needed.

* Update gmt_init.c

Sory, also add an unrelated debug statend and fix a typo
  • Loading branch information
PaulWessel authored Jun 28, 2020
1 parent 5b11244 commit ed50fc5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/gmt_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -14016,7 +14016,7 @@ struct GMT_CTRL *gmt_init_module (struct GMTAPI_CTRL *API, const char *lib_name,
}
}

if (options) { /* Check if any filename argument is s remote tiled dataset */
if (options) { /* Check if any filename argument is a remote tiled dataset */
bool first_time = true;
int k_data;
unsigned int srtm_flag;
Expand Down Expand Up @@ -14048,6 +14048,7 @@ struct GMT_CTRL *gmt_init_module (struct GMTAPI_CTRL *API, const char *lib_name,

if (opt_R == NULL) { /* In this context we imply -Rd */
wesn[XLO] = -180.0; wesn[XHI] = +180.0; wesn[YLO] = -90.0; wesn[YHI] = +90.0;
GMT_Report (API, GMT_MSG_DEBUG, "Modern: Assuming -Rd since %s was given and no -R specified\n", opt->arg);
}
else {
char codes[3] = {""};
Expand Down
8 changes: 5 additions & 3 deletions src/grdblend.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ struct GRDBLEND_CTRL {

struct GRDBLEND_INFO { /* Structure with info about each input grid file */
struct GMT_GRID *G; /* I/O structure for grid files, including grd header */
struct GMT_GRID_HEADER_HIDDEN *HH;
struct GMT_GRID_ROWBYROW *RbR;
int in_i0, in_i1, out_i0, out_i1; /* Indices of outer and inner x-coordinates (in output grid coordinates) */
int in_j0, in_j1, out_j0, out_j1; /* Indices of outer and inner y-coordinates (in output grid coordinates) */
Expand Down Expand Up @@ -200,6 +199,8 @@ GMT_LOCAL int grdblend_init_blend_job (struct GMT_CTRL *GMT, char **files, unsig
struct GMT_GRID_HEADER *h = *h_ptr; /* Input header may be NULL or preset */
struct GMT_GRID_HIDDEN *GH = NULL;
struct GMT_GRID_HEADER_HIDDEN *HH = NULL;
struct GMT_GRID_HEADER_HIDDEN *HHG = NULL;

char *sense[2] = {"normal", "inverse"}, buffer[GMT_BUFSIZ] = {""}, res[4] = {""};
static char *V_level = GMT_VERBOSE_CODES;
char Iargs[GMT_LEN256] = {""}, Rargs[GMT_LEN256] = {""}, cmd[GMT_LEN256] = {""};
Expand Down Expand Up @@ -314,7 +315,6 @@ GMT_LOCAL int grdblend_init_blend_job (struct GMT_CTRL *GMT, char **files, unsig
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Internal snafu - please report the problem on the GMT issues page\n");
return (-GMT_NOT_A_VALID_LOGMODE);
}
B[n].HH = gmt_get_H_hidden (B[n].G->header);
B[n].weight = L[n].weight;
if (!strcmp (L[n].region, "-"))
gmt_M_memcpy (B[n].wesn, B[n].G->header->wesn, 4, double); /* Set inner = outer region */
Expand Down Expand Up @@ -502,8 +502,10 @@ GMT_LOCAL int grdblend_init_blend_job (struct GMT_CTRL *GMT, char **files, unsig
/* Allocate space for one entire row for this grid */

B[n].z = gmt_M_memory (GMT, NULL, B[n].G->header->n_columns, gmt_grdfloat);
HHG = gmt_get_H_hidden (B[n].G->header);

GMT_Report (GMT->parent, GMT_MSG_INFORMATION, "Blend file %s in %g/%g/%g/%g with %s weight %g [%d-%d]\n",
B[n].HH->name, B[n].wesn[XLO], B[n].wesn[XHI], B[n].wesn[YLO], B[n].wesn[YHI], sense[B[n].invert], B[n].weight, B[n].out_j0, B[n].out_j1);
HHG->name, B[n].wesn[XLO], B[n].wesn[XHI], B[n].wesn[YLO], B[n].wesn[YHI], sense[B[n].invert], B[n].weight, B[n].out_j0, B[n].out_j1);

if (!B[n].memory && GMT_Destroy_Data (GMT->parent, &B[n].G)) return (-GMT_RUNTIME_ERROR); /* Free grid unless it is a memory grid */
}
Expand Down

0 comments on commit ed50fc5

Please sign in to comment.