@@ -5204,7 +5204,7 @@ GMT_LOCAL struct GMT_GRID * gmtapi_import_grid (struct GMTAPI_CTRL *API, int obj
5204
5204
5205
5205
int item, new_item, new_ID;
5206
5206
bool done = true, new = false, row_by_row;
5207
- uint64_t row, col, i0, i1, j0, j1, ij, ij_orig;
5207
+ uint64_t row, col, kol, i0, i1, j0, j1, ij, ij_orig;
5208
5208
size_t size;
5209
5209
unsigned int both_set = (GMT_CONTAINER_ONLY | GMT_DATA_ONLY);
5210
5210
unsigned int method;
@@ -5231,7 +5231,7 @@ GMT_LOCAL struct GMT_GRID * gmtapi_import_grid (struct GMTAPI_CTRL *API, int obj
5231
5231
GMT_Report (API, GMT_MSG_ERROR, "Can only use method GMT_IS_FILE when row-by-row reading of grid is selected\n");
5232
5232
return_null (API, GMT_NOT_A_VALID_METHOD);
5233
5233
}
5234
- if ((mode & GMT_CONTAINER_ONLY) && S_obj->region) {
5234
+ if ((mode & GMT_CONTAINER_ONLY) && S_obj->region && S_obj->method == GMT_IS_FILE ) {
5235
5235
GMT_Report (API, GMT_MSG_ERROR, "Cannot request a subset when just inquiring about the grid header\n");
5236
5236
return_null (API, GMT_SUBSET_NOT_ALLOWED);
5237
5237
}
@@ -5466,8 +5466,9 @@ GMT_LOCAL struct GMT_GRID * gmtapi_import_grid (struct GMTAPI_CTRL *API, int obj
5466
5466
5467
5467
for (row = j0; row <= j1; row++) {
5468
5468
for (col = i0; col <= i1; col++, ij++) {
5469
- ij_orig = GMT_2D_to_index (row, col, M_obj->dim); /* Position of this (row,col) in input matrix organization */
5470
- ij = gmt_M_ijp (G_obj->header, row, col); /* Position of this (row,col) in output grid organization */
5469
+ kol = col % M_obj->n_columns;
5470
+ ij_orig = GMT_2D_to_index (row, kol, M_obj->dim); /* Position of this (row,col) in input matrix organization */
5471
+ ij = gmt_M_ijp (G_obj->header, row, kol); /* Position of this (row,col) in output grid organization */
5471
5472
api_get_val (&(M_obj->data), ij_orig, &d); /* Get the next item from the matrix */
5472
5473
G_obj->data[ij] = (gmt_grdfloat)d;
5473
5474
if (gmt_M_is_dnan (d))
@@ -5478,6 +5479,10 @@ GMT_LOCAL struct GMT_GRID * gmtapi_import_grid (struct GMTAPI_CTRL *API, int obj
5478
5479
}
5479
5480
}
5480
5481
}
5482
+ if (gmt_M_is_geographic (GMT, GMT_IN) && gmt_M_360_range (M_obj->range[XLO], M_obj->range[XHI]) && gmt_M_360_range (G_obj->header->wesn[XLO], G_obj->header->wesn[XHI])) {
5483
+ /* Global grids passed via matrix are not rotated to fit the desired global region, so we need to correct the wesn for this grid to match the matrix */
5484
+ gmt_M_memcpy (G_obj->header->wesn, M_obj->range, 4U, double);
5485
+ }
5481
5486
gmt_BC_init (GMT, G_obj->header); /* Initialize grid interpolation and boundary condition parameters */
5482
5487
if (gmt_M_err_pass (GMT, gmt_grd_BC_set (GMT, G_obj, GMT_IN), "Grid memory"))
5483
5488
return_null (API, GMT_GRID_BC_ERROR); /* Set boundary conditions */
@@ -5492,7 +5497,7 @@ GMT_LOCAL struct GMT_GRID * gmtapi_import_grid (struct GMTAPI_CTRL *API, int obj
5492
5497
//if (S_obj->region) return_null (API, GMT_SUBSET_NOT_ALLOWED);
5493
5498
/* This method requires the input data to be a GMT_GRD_FORMAT matrix - otherwise we should be DUPLICATING */
5494
5499
MH = gmt_get_M_hidden (M_obj);
5495
- if (!(M_obj->shape == GMT_IS_ROW_FORMAT && M_obj->type == GMT_GRDFLOAT && MH->alloc_mode == GMT_ALLOC_EXTERNALLY && (mode & GMT_GRID_IS_COMPLEX_MASK) == 0))
5500
+ if (!(M_obj->shape == GMT_IS_ROW_FORMAT && M_obj->type == GMT_GRDFLOAT && (mode & GMT_GRID_IS_COMPLEX_MASK) == 0))
5496
5501
return_null (API, GMT_NOT_A_VALID_IO_ACCESS);
5497
5502
if (grid == NULL) { /* Only allocate when not already allocated. Note cannot have pad since input matrix wont have one */
5498
5503
uint64_t dim[3] = {M_obj->n_rows, M_obj->n_columns, 1};
0 commit comments