int
saf_find_coords(SAF_ParMode pmode, /* The parallel mode. */
SAF_Db *db, /* Database in which to limit the search. */
SAF_Set *base, /* The base space for which coordinate fields are desired. */
int *num, /* For this and the succeeding argument [see Returned Handles]. */
SAF_Field **found /* For this and the preceding argument [see Returned Handles]. */
)
{
SAF_ENTER(saf_find_coords, SAF_PRECONDITION_ERROR);
SAF_KEYMASK(SAF_Field, key, mask);
size_t nfound;
ss_scope_t scope;
SAF_REQUIRE(_saf_valid_pmode(pmode), SAF_LOW_CHK_COST, SAF_PRECONDITION_ERROR,
_saf_errmsg("PMODE must be valid"));
if (!_saf_is_participating_proc(pmode)) SAF_RETURN(-1);
SAF_REQUIRE(SS_SET(base) || _saf_is_universe(base), SAF_LOW_CHK_COST, SAF_PRECONDITION_ERROR,
_saf_errmsg("BASE must be either a valid set handle or the universe set for all participating processes"));
SAF_REQUIRE(_saf_valid_memhints(num, (void**)found), SAF_LOW_CHK_COST, SAF_PRECONDITION_ERROR,
_saf_errmsg("NUM and FOUND must be compatible for return value allocation"));
ss_file_topscope(db, &scope);
if (base && !_saf_is_universe(base)) SAF_SEARCH(SAF_Field, key, mask, base_space, *base);
SAF_SEARCH(SAF_Field, key, mask, is_coord_field, TRUE);
if (!found) {
/* Count the matches */
assert(num);
nfound = SS_NOSIZE;
ss_pers_find(&scope, (ss_pers_t*)key, mask_count?(ss_persobj_t*)&mask:NULL, 0, &nfound, SS_PERS_TEST, NULL);
*num = nfound;
} else if (!*found) {
/* Find all matches; library allocates results */
nfound = SS_NOSIZE;
*found = (ss_field_t*)ss_pers_find(&scope, (ss_pers_t*)key, mask_count?(ss_persobj_t*)&mask:NULL, 0, &nfound, NULL, NULL);
if (num) *num = nfound;
} else {
/* Find limited matches; client allocates result buffer */
assert(num);
nfound = *num;
if (NULL==ss_pers_find(&scope, (ss_pers_t*)key, mask_count?(ss_persobj_t*)&mask:NULL, 0, &nfound, (ss_pers_t*)*found,
_SAF_GLOBALS.find_detect_overflow)) {
SAF_ERROR(SAF_CONSTRAINT_ERROR, _saf_errmsg("found too many matchine objects"));
}
*num = nfound;
}
SAF_LEAVE(SAF_SUCCESS);
}