MCPcopy Create free account
hub / github.com/GenericMappingTools/gmt / gmtapi_is_registered

Function gmtapi_is_registered

src/gmt_api.c:3384–3431  ·  view source on GitHub ↗

! . */

Source from the content-addressed store, hash-verified

3382
3383/*! . */
3384GMT_LOCAL int gmtapi_is_registered (struct GMTAPI_CTRL *API, int family, int geometry, int direction, unsigned int mode, char *filename, void *resource) {
3385 /* Checks to see if the given data pointer has already been registered.
3386 * This can happen for grids which first gets registered reading the header
3387 * and then is registered again when reading the whole grid. In those cases
3388 * we don't want to register them twice.
3389 */
3390 unsigned int i;
3391 int item;
3392 struct GMTAPI_DATA_OBJECT *S_obj = NULL;
3393
3394 if (API->n_objects == 0) return (GMT_NOTSET); /* There are no known resources yet */
3395
3396 if ((item = gmtapi_memory_registered (API, family, direction, filename)) != GMT_NOTSET)
3397 return (item); /* OK, return the object ID */
3398
3399 /* Search for the object in the active list. However, if object_ID == GMT_NOTSET we instead pick the first in that direction */
3400
3401 for (i = 0, item = GMT_NOTSET; item == GMT_NOTSET && i < API->n_objects; i++) {
3402 if (!(S_obj = API->object[i])) continue; /* Skip empty objects */
3403 if (S_obj->status != GMT_IS_UNUSED) { /* Has already been read - do we wish to reset this status ? */
3404 if (family == GMT_IS_GRID && (mode & GMT_DATA_ONLY)) { /* Requesting data only means we already did the header so OK to reset status */
3405 if (mode & GMT_GRID_IS_COMPLEX_MASK) { /* Complex grids are read in stages so handled separately */
3406 /* Check if complex grid already has one layer and that we are reading the next layer */
3407 struct GMT_GRID *G = gmtapi_get_grid_data (resource); /* Get pointer to this grid */
3408 unsigned int cmplx = mode & GMT_GRID_IS_COMPLEX_MASK;
3409 if (G->header->complex_mode & GMT_GRID_IS_COMPLEX_MASK && G->header->complex_mode != cmplx && filename) {
3410 /* Apparently so, either had real and now getting imag, or vice versa. */
3411 gmt_M_str_free (S_obj->filename); /* Free previous grid name and replace with current name */
3412 S_obj->filename = strdup (filename);
3413 mode |= GMT_IO_RESET; /* Reset so we may read in the 2nd component grid */
3414 }
3415 }
3416 else /* Just read the header earlier, do the reset */
3417 mode |= GMT_IO_RESET; /* Reset so we may read in the grid data */
3418 }
3419 else if (family == GMT_IS_IMAGE && (mode & GMT_DATA_ONLY)) /* Requesting data only means we already did the header so OK to reset status */
3420 mode |= GMT_IO_RESET; /* Reset so we may read in the image data */
3421
3422 if (!(mode & GMT_IO_RESET)) continue; /* No reset above so we refuse to do the work */
3423 S_obj->status = GMT_IS_UNUSED; /* Reset so we may continue to read it */
3424 }
3425 if (direction != GMT_NOTSET && (int)S_obj->direction != direction) continue; /* Wrong direction */
3426 if (family != GMT_NOTSET && (int)S_obj->family != family) continue; /* Wrong family */
3427 if (geometry != GMT_NOTSET && (int)S_obj->geometry != geometry) continue; /* Wrong geometry */
3428 if (resource && S_obj->resource == resource) item = S_obj->ID; /* Yes: already registered. */
3429 }
3430 return (item); /* The ID of the object (or GMT_NOTSET) */
3431}
3432
3433/*! . */
3434GMT_LOCAL struct GMT_PALETTE * gmtapi_import_palette (struct GMTAPI_CTRL *API, int object_ID, unsigned int mode) {

Callers 2

GMT_Register_IOFunction · 0.85
GMT_Read_DataFunction · 0.85

Calls 3

gmtapi_memory_registeredFunction · 0.85
gmtapi_get_grid_dataFunction · 0.85
strdupFunction · 0.85

Tested by

no test coverage detected