Skip to content

Commit cad2c24

Browse files
authored
Do not let grdblend keep all the files open (#4976)
* Explore the open files in grdblen Looks like we are opening files when we only need the header? * Close open grid files after setting the offsets * Delete center_cf_p.png
1 parent 2436de9 commit cad2c24

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/grdblend.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ GMT_LOCAL bool grdblend_overlap_check (struct GMT_CTRL *GMT, struct GRDBLEND_INF
190190
return false;
191191
}
192192

193+
EXTERN_MSC void gmtlib_close_grd (struct GMT_CTRL *GMT, struct GMT_GRID *G);
194+
193195
GMT_LOCAL int grdblend_init_blend_job (struct GMT_CTRL *GMT, char **files, unsigned int n_files, struct GMT_GRID_HEADER **h_ptr, struct GRDBLEND_INFO **blend, bool delayed, struct GMT_GRID *Grid) {
194196
/* Returns how many blend files or a negative error value if something went wrong */
195197
int type, status, not_supported = 0, t_data, k_data = GMT_NOTSET;
@@ -532,7 +534,10 @@ GMT_LOCAL int grdblend_init_blend_job (struct GMT_CTRL *GMT, char **files, unsig
532534
GMT_Report (GMT->parent, GMT_MSG_INFORMATION, "Blend file %s in %.12g/%.12g/%.12g/%.12g with %s weight %g [%d-%d]\n",
533535
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);
534536

535-
if (!B[n].memory && GMT_Destroy_Data (GMT->parent, &B[n].G)) return (-GMT_RUNTIME_ERROR); /* Free grid unless it is a memory grid */
537+
if (!B[n].memory) { /* Free grid unless it is a memory grid */
538+
gmtlib_close_grd (GMT, B[n].G); /* Close the grid file so we don't have lots of them open */
539+
if (GMT_Destroy_Data (GMT->parent, &B[n].G)) return (-GMT_RUNTIME_ERROR);
540+
}
536541
}
537542

538543
if (fabs (sub) > 0.0) { /* Must undo shift earlier */

0 commit comments

Comments
 (0)