herr_t
ss_scope_close(ss_scope_t *scope)
{
SS_ENTER(ss_scope_close, herr_t);
hid_t scope_grp;
unsigned tableidx;
ss_table_t *table=NULL;
const char *scopename=NULL;
SS_ASSERT_MEM(scope, ss_scope_t);
if (NULL==(scopename=ss_string_ptr(SS_SCOPE_P(scope,name)))) scopename="NONAME";
if ((scope_grp = ss_scope_isopen(scope))<0) SS_ERROR_FMT(FAILED, ("scope=\"%s\"", scopename));
if (!scope_grp) SS_ERROR_FMT(NOTFOUND, ("scope is not open: %s", scopename));
/* Should it be possible to close the top scope? Probably only from ss_file_close() and similar! */
/* Close down the tables (except scope table if any) */
for (tableidx=0; tableidx<SS_PERS_NCLASSES; tableidx++) {
table = SS_SCOPE(scope)->m.table[tableidx];
if (!table || tableidx==SS_MAGIC_SEQUENCE(SS_MAGIC(ss_scope_t))) continue;
if (ss_table_dest(table, 0)<0) SS_ERROR_FMT(FAILED, ("scope=\"%s\"", scopename)); /* only partially destroyed */
}
/* Reset the communicator */
if (SS_SCOPE(scope)->m.comm_duped && ss_mpi_comm_free(SS_SCOPE_P(scope,m.comm))<0)
SS_ERROR_FMT(MPI, ("scope=\"%s\"", scopename));
SS_SCOPE(scope)->m.comm = SS_COMM_NULL;
SS_SCOPE(scope)->m.comm_duped = FALSE;
SS_SCOPE(scope)->m.flags = 0;
SS_CLEANUP:
SS_LEAVE(0);
}