void
UpdateDatabase(
DbInfo_t *dbInfo, /* [IN/OUT] database info object (currentFile member can be modified) */
int stepNum, /* [IN] the current step number in the sequence starting from zero */
int numSteps, /* [IN] total number of steps to be output (>=1) */
hbool_t do_multifile, /* [IN] boolean to indicate if each step will go to a different supplemental file */
int numFields, /* [IN] the number of fields on the mesh */
SAF_Field *theFields /* [IN] array of length numFields of the field handles */
)
{
char tmpName[32];
static int stepZero = 0;
int i;
float stepVal;
SAF_FieldTmpl *fieldTmpls;
SAF_StateGrp currentStateGrp;
SAF_StateTmpl currentStateTmpl;
SAF_Suite currentSuite;
SAF_Rel rel;
SAF_Unit usec;
/* local vars obtained from dbinfo object */
SAF_Db *db = dbInfo->db;
SAF_Set aggregateMesh = dbInfo->mainMesh;
SAF_Set currentMesh = dbInfo->currentMesh;
SAF_Db *stepFile = dbInfo->currentFile;
/* link currentMesh into aggregate at the current position */
saf_declare_subset_relation(SAF_ALL, db, &aggregateMesh, ¤tMesh, SAF_COMMON(SAF_SELF(db)), SAF_TUPLES,
H5I_INVALID_HID, NULL, H5I_INVALID_HID, NULL, &rel);
saf_write_subset_relation(SAF_ALL, &rel, SAF_INT, &stepNum, H5I_INVALID_HID, NULL, stepFile);
/* get the handle for the seconds unit */
saf_find_one_unit(db, "second", &usec);
/* obtain all the field templates for all the fields */
fieldTmpls = calloc((size_t)numFields, sizeof *fieldTmpls);
for (i = 0; i < numFields; i++)
saf_describe_field(SAF_ALL, theFields+i, fieldTmpls+i, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL);
/* get the handle for the seconds unit */
saf_find_one_unit(db, "second", &usec);
/* create the suite */
sprintf(tmpName, "stateSuite_%03d", stepNum);
saf_declare_suite(SAF_ALL, db, tmpName, ¤tMesh, NULL, ¤tSuite);
/* create a new state template */
sprintf(tmpName, "stateTmpl_%03d", stepNum);
saf_declare_state_tmpl(SAF_ALL, db, tmpName, numFields, fieldTmpls, ¤tStateTmpl);
free(fieldTmpls);
/* create a new state group */
sprintf(tmpName, "stateGrp_%03d", stepNum);
saf_declare_state_group(SAF_ALL, db, tmpName, ¤tSuite, ¤tMesh, ¤tStateTmpl, SAF_QTIME,
&usec, SAF_FLOAT, ¤tStateGrp);
/* Issue: we always write to the 0'th index of this new suite */
stepVal = (float) stepNum;
saf_write_state(SAF_ALL, ¤tStateGrp, stepZero, ¤tMesh, SAF_FLOAT, (void*) &stepVal, theFields);
/* work to do for the next step if there is a next step */
if (stepNum + 1 < numSteps)
{
dbInfo->lastMesh = dbInfo->currentMesh;
/* create a new supplemental file */
if (do_multifile) {
SAF_DbProps *dbprops = saf_createProps_database();
saf_setProps_Clobber(dbprops);
sprintf(tmpName,"step_%03d", stepNum+1);
stepFile = saf_open_database(tmpName, dbprops);
saf_freeProps_database(dbprops);
/* update the currentFile handle in the dbinfo object */
dbInfo->currentFile = stepFile;
}
}
/* flush the database */
saf_update_database(db);
/* keep track of the last mesh */
dbInfo->lastMesh = dbInfo->currentMesh;
}