DBfile *openpdmp( char* kern, int cyc, int num, int mode, char* dmpname) { char *me = "openpdmp"; DBfile *idbidin; int ierr; char infotmp[30], msg[128]; char fullname[MAXLINE]; if (num >= 0) { if (cyc >= 0) { sprintf(dmpname, "%s-%04d-%05d.silo", kern, num, cyc) ; } else { sprintf(dmpname, "%s-%04d.silo", kern, num) ; } } else { if (cyc >= 0) { sprintf(dmpname, "%s%05d.silo", kern, cyc) ; } else { sprintf(dmpname, "%s.silo", kern) ; } } if (mode == 2) return(NULL); DBShowErrors(DB_NONE, NULL); if (mode == 0) { idbidin = DBOpen (dmpname, DB_PDB, DB_READ); if (idbidin == NULL) ctlerror(me,gv_errmsg_DBOpen); } else { sprintf(infotmp, "%s dump file", meshlink_codesys); strcpy(fullname,outpath); strcat(fullname,dmpname); idbidin = DBCreate(fullname, DB_CLOBBER, DB_LOCAL, infotmp, DB_PDB ); } DBShowErrors(DB_TOP, NULL); return(idbidin); }
XTDBError XTDBInitHandle(const char* dbName,const char* dir,XTDBHandle** out) { XTDBError rv; XTDBHandle* h = malloc(sizeof(XTDBHandle)); int rc; //InitQueryModule(); if (!h) { return XTDB_NO_MEM; } memset(h,0,sizeof(*h)); StrInit(&h->dbName); if (StrAppend(&h->dbName,dbName)) { rv = XTDB_NO_MEM; goto error; } StrInit(&h->dataDir); if (StrAppend(&h->dataDir,dir)) { rv = XTDB_NO_MEM; goto error; } StrInit(&h->descName); if (StrAppendFmt(&h->descName,"%s/%s.desc",dir,dbName)) { rv = XTDB_NO_MEM; goto error; } StrInit(&h->mainDbFileName); if (StrAppendFmt(&h->mainDbFileName,"%s/%s.main.data",dir,dbName)) { rv = XTDB_NO_MEM; goto error; } h->indexes = tcmapnew2(23); if (!h->indexes) { rv = XTDB_NO_MEM; goto error; } //h->indexes = hash_table_new(stringhash,string_equal); //hash_table_register_free_functions(h->indexes,free,NULL); if (!(h->mainDB = DBInit(h->mainDbFileName.ptr,BDBOCREAT|BDBOWRITER))) { rv = XTDB_NO_MEM; goto error; } if (!(rc=DBOpen(h->mainDB,BDBOCREAT|BDBOWRITER))) { rv = DBGetLastError(h->mainDB); goto error; } if (!XTDBLoadIndexes(h)) { rv = h->error; goto error; } *out = h; return XTDB_OK; error: XTDBFreeHandle(h); *out = NULL; return rv; }
/*------------------------------------------------------------------------- * Function: main * * Purpose: Test various read operations. * * Return: 0 * * Programmer:Mark C. Miller, Thu Jul 15 08:23:56 PDT 2010 *------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { int driver = DB_PDB, driverType = DB_PDB; int i, err = 0; DBfile *dbfile; int show_all_errors = FALSE; char filename[256]; char *obj_names[13]; int ordering[13]; /* Parse command-line */ for (i=1; i<argc; i++) { if (!strncmp(argv[i], "DB_PDB", 6)) { driver = StringToDriver(argv[i]); driverType = DB_PDB; } else if (!strncmp(argv[i], "DB_HDF5", 7)) { driver = StringToDriver(argv[i]); driverType = DB_HDF5; } else if (!strcmp(argv[i], "show-all-errors")) { show_all_errors = 1; } else if (argv[i][0] != '\0') { fprintf(stderr, "%s: ignored argument `%s'\n", argv[0], argv[i]); } } DBShowErrors(show_all_errors?DB_ALL_AND_DRVR:DB_TOP, NULL); DBForceSingle(1); sprintf(filename, "multi_rect2d.%s", driverType==DB_PDB?"pdb":"h5"); dbfile = DBOpen(filename, DB_UNKNOWN, DB_READ); DBSetDir(dbfile, "block7"); obj_names[0] = "cycle"; obj_names[1] = "d"; obj_names[2] = "../_fileinfo"; obj_names[3] = "otherfile:block7/u"; obj_names[4] = "v"; obj_names[5] = "u"; obj_names[6] = "/.silo/#000005"; obj_names[7] = "../block7/d"; obj_names[8] = "../block9/d"; obj_names[9] = "../block4/d"; obj_names[10] = "../mesh1_hidden"; obj_names[11] = "../mesh1"; obj_names[12] = "../block11/u"; DBSortObjectsByOffset(dbfile, 13, obj_names, ordering); printf("UNsorted objects...\n"); for (i = 0; i < 13; i++) printf("\t\"%s\"\n", obj_names[i]); printf("Sorted objects...\n"); for (i = 0; i < 13; i++) printf("\t\"%s\"\n", obj_names[ordering[i]]); DBClose(dbfile); return err; }
logical CTX_DBBase :: ExecuteAction (DB_Event intevent ) { logical term = NO; BEGINSEQ if ( !this ) LEAVESEQ switch ( intevent ) { case DBO_Opened : term = DBOpened(); break; case DBO_Initialize : term = DBInitialize(); break; case DBO_Created : if ( !(term = DBCreated()) ) intern_states.data_state = DAT_Filled; break; case DBO_NotCreated : term = DBNotCreated(); break; case DBO_Read : if ( !(term = DBRead()) ) intern_states.data_state = DAT_Filled; break; case DBO_Reset : term = DBReset(); break; case DBO_Stored : term = DBStored(); break; case DBO_Inserted : if ( !(term = DBInserted()) ) intern_states.data_state = DAT_Filled; break; case DBO_NotInserted: term = DBNotInserted(); break; case DBO_Removed : term = DBRemoved(); break; case DBO_NotRemoved : term = DBNotRemoved(); break; case DBO_Deleted : term = DBDeleted(); break; case DBO_NotDeleted : term = DBNotDeleted(); break; case DBO_Refresh : term = DBRefresh(); break; case DBO_NotOpened : term = DBNotOpened(); break; case DBO_Close : term = DBClose(); break; case DBP_Read : term = DBBeforeRead(); break; case DBP_Create : term = DBCreate(); break; case DBP_Modify : term = DBModify(); break; case DBP_Store : term = DBStore(); break; case DBP_Insert : term = DBInsert(); break; case DBP_Open : term = DBOpen(); break; case DBP_Remove : term = DBRemove(); break; case DBP_Delete : term = DBDelete(); break; case DBP_Select : term = DBSelect(); break; case DB_undefined : LEAVESEQ default : ERROR } RECOVER term = YES; ENDSEQ return(term); }
static uint8_t XTDBAddIndex(XTDBHandle* h,char* fieldName) { String idxDBName; BinaryStr out; uint8_t success=False; DataBaseBE* db; DataBaseBE* be = XTDBGetIndex(h,fieldName); if (be) { // XXX Set error // Index already exists assert(0); return False; } StrToBStr(fieldName,&out); GetIndexDBName(h,fieldName,&idxDBName); db = DBInit(STR(&idxDBName),BDBOWRITER); //print_trace(); if (db) { uint8_t rv = DBOpen(db,BDBOWRITER); //printf("Return value %d,%s\n",rv,tcbdberrmsg(rv)); if (!rv) { //h->error = DBErrorToXTDBError(rv); h->error = DBGetLastError(db); DBFree(db); assert(0); return False; } // No error for this function tcmapput(h->indexes,out.data,out.len,&db,sizeof(db)); int a; assert(tcmapget(h->indexes,out.data,out.len,&a)); /*char* newStr = strdup(fieldName); if(hash_table_insert(h->indexes,newStr,db)) { } assert(hash_table_lookup(h->indexes,newStr));*/ } else { h->error = XTDB_NO_MEM; return False; } StrFree(&idxDBName); assert(tcmaprnum(h->indexes)); return True; }
// checked uint8_t XTDBLoadIndexes(XTDBHandle* h) { void* idxList = NULL; BinaryStr bStr,out; uint8_t rv; h->descDB = DBInit(STR(&h->descName),BDBOCREAT|BDBOWRITER); if (!h->descDB) { h->error = XTDB_NO_MEM; return False; } rv = DBOpen(h->descDB,BDBOCREAT|BDBOWRITER|BDBOTSYNC); if (!rv) { // XXX revisit h->error = DBGetLastError(h->descDB); if (h->error == XTDB_FILE_NOT_FOUND) { h->error = XTDB_DESC_NOT_FOUND; } return False; } StrToBStr(IDXFIELDNAME,&bStr); if (DBGetList(h->descDB,&bStr,&idxList)) { int idxLen = DBListLen(h->descDB,idxList); int i; for (i=0; i<idxLen; i++) { DBListVal(h->descDB,idxList,i,&out); char* idxName = BStrData(&out); //printf("IDX in descriptor %s\n",idxName); if (!XTDBAddIndex(h,idxName)) { return False; } assert(XTDBGetIndex(h,idxName)); } DBListFree(h->descDB,idxList); } return True; }
bool BRCWriter::write() { Symbols &syms = loader.GetSymbols(); bool ok = DBOpen((char *)outputFile.c_str()); if (ok) { ok = false; // if (Begin()) if (WriteFileList()) if (WriteDictionary(syms)) if (WriteMapping(syms)) if (WriteLineData(syms)) if (WriteUsageData(syms)) if (WriteJumpTable(syms)) ok = true; // if (!End()) ok = false; } if (dbPointer) sqlite3_close(dbPointer); return ok; }
/*---------------------------------------------------------------------------- *---------------------------------------------------------------------------- * Main Program *---------------------------------------------------------------------------- *---------------------------------------------------------------------------- * Modifications: * Robb Matzke, 1999-04-09 * Added argument parsing to control the driver which is used. * *---------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { int x,y; int m,s; int err, mixc; int i, driver=DB_PDB, reorder=0; char filename[64], *file_ext=".pdb"; int show_all_errors = FALSE; DBfile *db; /* Parse command-line */ for (i=1; i<argc; i++) { if (!strncmp(argv[i], "DB_PDB", 6)) { driver = StringToDriver(argv[i]); file_ext = ".pdb"; } else if (!strncmp(argv[i], "DB_HDF5", 7)) { driver = StringToDriver(argv[i]); file_ext = ".h5"; } else if (!strcmp(argv[i], "reorder")) { reorder = 1; } else if (!strcmp(argv[i], "show-all-errors")) { show_all_errors = 1; } else if (!strcmp(argv[i], "difftol")) { difftol = strtod(argv[i+1], 0); i++; } else if (argv[i][0] != '\0') { fprintf(stderr, "%s: ignored argument `%s'\n", argv[0], argv[i]); } } if (show_all_errors) DBShowErrors(DB_ALL_AND_DRVR, 0); Mesh_Create(&mesh,20,20); /* -=-=-=-=-=-=-=-=-=- */ /* Setup Coordinates */ /* -=-=-=-=-=-=-=-=-=- */ printf("Creating the mesh\n"); for (x=0;x<mesh.nx;x++) { for (y=0;y<mesh.ny;y++) { float xx = (x-10); float yy = ((xx-8.5)*xx*(xx+8.5))/40. + (y-10); mesh.node[x][y].x = xx*2+(yy*yy/50 - 3); mesh.node[x][y].y = yy; } } /* -=-=-=-=-=-=-=-=-=- */ /* Do Mesh Variables */ /* -=-=-=-=-=-=-=-=-=- */ printf("Creating the variables\n"); /* do zone vars */ for (x=0;x<mesh.zx;x++) { for (y=0;y<mesh.zy;y++) { mesh.zone[x][y].vars[ZV_P] = sqrt((mesh.node[x][y].x*mesh.node[x][y].x) + (mesh.node[x][y].y*mesh.node[x][y].y)); mesh.zone[x][y].vars[ZV_D] = 10. / (mesh.zone[x][y].vars[ZV_P]+5); } } /* do node vars */ for (x=0;x<mesh.nx;x++) { for (y=0;y<mesh.ny;y++) { mesh.node[x][y].vars[NV_U] = mesh.node[x][y].x; mesh.node[x][y].vars[NV_V] = mesh.node[x][y].y; } } /* -=-=-=-=-=-=-=-=-=- */ /* Do Materials */ /* -=-=-=-=-=-=-=-=-=- */ printf("Overlaying materials\n"); /* initialize */ for (x=0;x<mesh.zx;x++) { for (y=0;y<mesh.zy;y++) { mesh.zone[x][y].nmats=0; } } /* do it */ for (m=1; m<=nmat; m++) { for (x=0;x<mesh.zx;x++) { for (y=0;y<mesh.zy;y++) { float x00=mesh.zone[x][y].n[0][0]->x; float y00=mesh.zone[x][y].n[0][0]->y; float x10=mesh.zone[x][y].n[1][0]->x; float y10=mesh.zone[x][y].n[1][0]->y; float x01=mesh.zone[x][y].n[0][1]->x; float y01=mesh.zone[x][y].n[0][1]->y; float x11=mesh.zone[x][y].n[1][1]->x; float y11=mesh.zone[x][y].n[1][1]->y; int i,j; int c=0; float vf=0.; double vfd=0.; const int RES=40; /* subsampling resolution */ /* Subsample the zone at RESxRES to * * get a more accurate volume fraction */ for (i=0;i<=RES;i++) { for (j=0;j<=RES;j++) { float ii=(float)i/(float)RES; float jj=(float)j/(float)RES; float xc = (x00*ii + x10*(1.-ii))*jj + (x01*ii + x11*(1.-ii))*(1.-jj); float yc = (y00*ii + y10*(1.-ii))*jj + (y01*ii + y11*(1.-ii))*(1.-jj); switch (m) { case 1: if (xc>-15 && yc>2) vf++; break; case 2: if (xc>-15 && yc<=2 && xc-5>yc) vf++; break; case 3: if (xc>-15 && yc<=2 && xc-5<=yc) vf++; break; case 4: if (xc<= -15) vf++; break; default: break; } c++; } } vfd = vf; vf /= (float)c; vfd /= (double)c; mesh.zone[x][y].matvf[m]=vf; mesh.zone[x][y].matvfd[m]=vfd; if (vf) mesh.zone[x][y].nmats++; } } } /* check for errors in mat-assigning code! */ err=0; for (x=0;x<mesh.zx;x++) { for (y=0;y<mesh.zy;y++) { float vf=0; for (m=1; m<=nmat; m++) { vf += mesh.zone[x][y].matvf[m]; } if (vf<.99 || vf>1.01) { printf("Error in zone x=%d y=%d: vf = %f\n",x,y,vf); err++; } } } if (err) exit(err); /* -=-=-=-=-=-=-=-=-=- */ /* do species stuff! */ /* -=-=-=-=-=-=-=-=-=- */ printf("Overlaying material species\n"); err=0; for (m=1;m<=nmat;m++) { for (x=0;x<mesh.zx;x++) { for (y=0;y<mesh.zy;y++) { if (mesh.zone[x][y].matvf[m]>0.) { float mftot=0.; for (s=0; s<nspec[m-1]; s++) { float x00=mesh.zone[x][y].n[0][0]->x; float y00=mesh.zone[x][y].n[0][0]->y; float x10=mesh.zone[x][y].n[1][0]->x; float y10=mesh.zone[x][y].n[1][0]->y; float x01=mesh.zone[x][y].n[0][1]->x; float y01=mesh.zone[x][y].n[0][1]->y; float x11=mesh.zone[x][y].n[1][1]->x; float y11=mesh.zone[x][y].n[1][1]->y; float xx=(x00+x10+x01+x11)/4.; float yy=(y00+y10+y01+y11)/4.; double xxd=(x00+x10+x01+x11)/4.; double yyd=(y00+y10+y01+y11)/4.; float mf=0.; double mfd=0.; float g,g1,g2; /* gradient values */ double gd,g1d,g2d; /* gradient values */ switch (m) { case 1: g=lim01((xx+20.)/40.); gd=lim01((xxd+20.)/40.); switch (s) { case 0: mf=g; mfd=gd; break; case 1: mf=1.-g; mfd=1.-gd; break; default: exit(-1); } break; case 2: g=lim01((yy+20.)/40.); gd=lim01((yyd+20.)/40.); switch (s) { case 0: mf=.2+g/2.; mfd=.2+gd/2.; break; case 1: mf=.5-g/2.; mfd=.5-gd/2.; break; case 2: mf=.2; mfd=.2; break; case 3: mf=.1; mfd=.1; break; default: exit(-1); } break; case 3: g1=lim01((xx-5+yy+40.)/80.); g2=lim01((xx-5-yy+40.)/80.); g1d=lim01((xxd-5+yyd+40.)/80.); g2d=lim01((xxd-5-yyd+40.)/80.); switch (s) { case 0: mf=g1/2.; mfd=g1d/2.; break; case 1: mf=g2/4.; mfd=g2d/4.; break; case 2: mf=.5-g1/2.; mfd=.5-g1d/2.; break; case 3: mf=.25-g2/4.; mfd=.25-g2d/4.; break; case 4: mf=.25; mfd=.25; break; default: exit(-1); } break; case 4: switch (s) { case 0: mf=1.0; mfd=1.0; break; default: exit(-1); } break; default: exit(-1); break; } mesh.zone[x][y].specmf[m][s] = mf; mesh.zone[x][y].specmfd[m][s] = mfd; mftot += mf; } if (mftot < .99 || mftot > 1.01) { printf("Error in zone x=%d y=%d mat=%d: mf = %f\n",x,y,m,mftot); err++; } } } } } if (err) exit(err); /* -=-=-=-=-=-=-=-=-=- */ /* write to silo files */ /* -=-=-=-=-=-=-=-=-=- */ sprintf(filename, "specmix_quad%s", file_ext); printf("Writing %s using curvilinear mesh.\n", filename); db=DBCreate(filename, DB_CLOBBER, DB_LOCAL, "Mixed zone species test", driver); mixc=domatspec(db, doWrite, 0); writemesh_curv2d(db,mixc,reorder); DBClose(db); sprintf(filename, "specmix_ucd%s", file_ext); printf("Writing %s using unstructured mesh.\n", filename); db=DBCreate(filename, DB_CLOBBER, DB_LOCAL, "Mixed zone species test", driver); mixc=domatspec(db, doWrite, 0); writemesh_ucd2d(db,mixc,reorder); DBClose(db); /* Test read-back of species */ printf("Reading %s with Force Single off.\n", filename); db=DBOpen(filename, driver, DB_READ); domatspec(db, doReadAndCheck, 0); DBClose(db); printf("Reading %s with Force Single ON.\n", filename); DBForceSingle(1); db=DBOpen(filename, driver, DB_READ); domatspec(db, doReadAndCheck, 1); DBClose(db); printf("Done!\n"); for (x=0;x<mesh.nx;x++) free(mesh.node[x]); free(mesh.node); for (x=0;x<mesh.zx;x++) free(mesh.zone[x]); free(mesh.zone); CleanupDriverStuff(); return 0; }
static AirspaceDBType *OpenDatabase(char *intName) { AirspaceDBType *db = PFMalloc(sizeof(AirspaceDBType)); char extName[64]; ModErrThrowIf(!db); /* * check for external database first * */ StrPrintF(extName, "/PALM/Launcher/%s.pdb", intName); if ((db->extDB = PFOpenFile(extName, pfFileReadOnly))) { LOGTAG("External airspace"); db->numRecords = DBFGetNumRecords(db->extDB) - lastIdxRec; if (db->numRecords > 0) { db->lat1Idx = DBFRecordGet(db->extDB, lat1IdxRec, false); db->lon1Idx = DBFRecordGet(db->extDB, lon1IdxRec, false); db->lat3Idx = DBFRecordGet(db->extDB, lat3IdxRec, false); db->lon3Idx = DBFRecordGet(db->extDB, lon3IdxRec, false); db->typeIdx = DBFRecordGet(db->extDB, typeIdxRec, false); } else { PFCloseFile(db->extDB); } db->external = true; } else { /* * check internal... * */ LOGTAG("Internal airspace"); db->external = false; db->intDB = DBOpen(intName, false, true); db->numRecords = DBGetNumRecords(db->intDB) - lastIdxRec; if (db->numRecords > 0) { db->lat1Idx = DBRecordGet(db->intDB, lat1IdxRec, false); db->lon1Idx = DBRecordGet(db->intDB, lon1IdxRec, false); db->lat3Idx = DBRecordGet(db->intDB, lat3IdxRec, false); db->lon3Idx = DBRecordGet(db->intDB, lon3IdxRec, false); db->typeIdx = DBRecordGet(db->intDB, typeIdxRec, false); } else { DBClose(db->intDB); } } LOGINT16(db->numRecords); if (db->numRecords < 1) { PFMemFree(db); db = NULL; } return db; }
static Boolean AsImportDB(PFFileRef f, const char *dbname, UInt32 dbType, void (*cb)(const char *)) { DmOpenRef db; UInt16 j; UInt16 numRecords; LOGENTRY; LOGSTR(dbname); LOGINT32(dbType); db = DBOpen(dbname, false, true); ModErrThrowIf(!db); LOGLINE; /* * purge any existing records * */ numRecords = DBGetNumRecords(db); LOGINT16(numRecords); if (numRecords) { (*cb)(StrPurgingDatabase); DBClose(db); DBDelete(dbname); db = DBOpen(dbname, false, true); } /* * dimension new database. * * 5 index records * */ LOGLINE; (*cb)(StrCreatingdatabaseStructure); for (j=0;j<lastIdxRec;j++) { UInt16 recnum = DBNewRecord; (void)DBRecordCreate(db, recnum, NULL, 1); } /* * import records from file * */ ErrTry { LOGINT16(numRecords); for (j=0;;j++) { AirspaceType *as; UInt16 recNum = j+lastIdxRec; // skip past db headers Int16 lat1, lon1, lat3, lon3; LOGTAG("Adding:"); LOGINT16(j); as = ImportRecord(f, &lat1, &lon1, &lat3, &lon3, cb); if (as == NULL) { LOGTAG("End of file mark"); break; } LOGINT16(PFMallocSize(as)); /* * add record to the database * */ (void)DBRecordCreate(db, recNum, as, PFMallocSize(as)); LOGTAG("Bounds:"); LOGINT16(lat1); LOGINT16(lon1); LOGINT16(lat3); LOGINT16(lon3); /* * store bounding coordinates and airspace type * */ AddIntToRecord(db, lat1IdxRec, lat1); AddIntToRecord(db, lon1IdxRec, lon1); AddIntToRecord(db, lat3IdxRec, lat3); AddIntToRecord(db, lon3IdxRec, lon3); AddIntToRecord(db, typeIdxRec, as->type); PFMemFree(as); } } ErrCatch(errNo) { (*cb)(StrErrorDetectedPurgingDatabase); DBClose(db); DBDelete(dbname); errNo = 0; return false; } ErrEndCatch; DBClose(db); LOGEXIT; return true; }
Databox *ReadSilo(char *filename, double default_value) { #ifdef HAVE_SILO Databox *v; double X, Y, Z; int NX, NY, NZ; double DX, DY, DZ; int x, y, z; int nx, ny, nz; int j, k; double *ptr; int err = -1; DBfile *db; double epsi = 1.0E-16; char *current_path = NULL; char *path = NULL; char *slash = strchr(filename, '/'); float *localcoords[3]; if(slash) { path = (char *)malloc(MAXPATHLEN); strncpy(path, filename, slash - filename); path[slash - filename] = 0; filename = strdup(slash + 1); } else { filename = strdup(filename); } if(path) { current_path = (char *)malloc(MAXPATHLEN); getwd(current_path); chdir(path); } // db = DBOpen(filename, DB_PDB, DB_READ); db = DBOpen(filename, DB_UNKNOWN, DB_READ); if(db == NULL) { printf("Failed to open SILO file %s\n", filename); return NULL; } double origin[3]; err = DBReadVar(db, "origin", &origin); if(err < 0) { printf("Failed to read meta data\n"); return NULL; } X = origin[0]; Y = origin[1]; Z = origin[2]; int size[3]; err = DBReadVar(db, "size", &size); if(err < 0) { printf("Failed to read meta data\n"); return NULL; } NX = size[0]; NY = size[1]; NZ = size[2]; double delta[3]; err = DBReadVar(db, "delta", &delta); if(err < 0) { printf("Failed to read meta data\n"); return NULL; } DX = delta[0]; DY = delta[1]; DZ = delta[2]; /* create the new databox structure */ if ((v = NewDataboxDefault(NX, NY, NZ, X, Y, Z, DX, DY, DZ, default_value)) == NULL) { return((Databox *)NULL); } DBtoc *toc = DBGetToc(db); if ( toc == NULL ) { printf("Error: Silo get get TOC failed for %s\n", filename); return NULL; } char **multivar_names = toc -> multivar_names; int nmultivar = toc -> nmultivar; /* Check to see if file has a multivar in it to determine file format being used */ if(nmultivar == 0) { DBquadvar *var = DBGetQuadvar(db, "variable"); if(var == NULL) { printf("Error: Silo failed to get quadvar %s \n", "variable"); return NULL; } memcpy(DataboxCoeff(v, 0, 0, 0), var -> vals[0], NX*NY*NZ * sizeof(double)); DBFreeQuadvar(var); } else { DBmultivar *multivar = DBGetMultivar(db, multivar_names[0]); if ( multivar == NULL ) { printf("Error: Silo get multivar failed for %s\n", multivar_names[0]); return NULL; } int nvars = multivar -> nvars; char **varnames = multivar -> varnames; int i; int m; for(m = 0; m < nvars; m++) { char *proc_filename; char *seperator = ":"; proc_filename = strtok(varnames[m], seperator); char *proc_varname; proc_varname = strtok(NULL, seperator); /* printf("multivar nvar: %d \n", nvars); printf("multivar proc_varname: %s \n", proc_varname); printf("multivar proc_filename: %s \n", proc_filename); */ if(proc_filename == NULL) { printf("Error malformed multivar name %s in SILO file \n", varnames[m]); return NULL; } DBfile *proc_db; // proc_db = DBOpen(proc_filename, DB_PDB, DB_READ); proc_db = DBOpen(proc_filename, DB_UNKNOWN, DB_READ); if(db == NULL) { printf("Failed to open SILO file %s\n", filename); return NULL; } if(proc_varname == NULL) { printf("Error malformed multivar name %s in SILO file \n", varnames[m]); return NULL; } DBquadvar *var = DBGetQuadvar(proc_db, proc_varname); if(var == NULL) { printf("Error: Silo failed to get quadvar %s \n", varnames[m]); return NULL; } /* now we need to get the mesh, for PMPIO compat */ DBquadmesh *mesh = DBGetQuadmesh(proc_db, var -> meshname); if(mesh == NULL) { printf("Error: Silo failed to get quadmesh %s \n", varnames[m]); return NULL; } nx = var -> dims[0]; ny = var -> dims[1]; nz = var -> dims[2]; /* Casting here is a dangerous */ localcoords[0] = (float *)mesh -> coords[0]; localcoords[1] = (float *)mesh -> coords[1]; localcoords[2] = (float *)mesh -> coords[2]; int index_origin[3]; err = DBReadVar(proc_db, "index_origin", &index_origin); if(err < 0) { printf("Failed to read meta data\n"); return NULL; } /* becuase of multi or single file compatibility we need to * grab the actual mesh from that variable. Then we need to * determine the origin from the mesh[0][0], [1][0] and [2][0] * divided by DX, DY and DZ since there are multiple origins * in a single file and this is now ambiguous. */ x = index_origin[0]; y = index_origin[1]; z = index_origin[2]; x = round( (localcoords[0][0] - (X - DX / 2.0)) / DX); y = round( (localcoords[1][0] - (Y - DY / 2.0)) / DY); z = round( (localcoords[2][0] - (Z - DZ / 2.0)) / DZ); int index = 0; double *vals = (double *)var -> vals[0]; for (k = 0; k < nz; k++) { for (j = 0; j < ny; j++) { for (i = 0; i < nx; i++) { ptr = DataboxCoeff(v, x + i, y + j, z + k); *ptr = vals[index]; index++; } } } DBFreeQuadvar(var); DBClose(proc_db); } DBFreeMultivar(multivar); } DBClose(db); if(path) { free(path); } if(current_path) { chdir(current_path); free(current_path); } free(filename); /* free(localcoords[0]); free(localcoords[1]); free(localcoords[2]); */ return v; #else #endif }
int main(int argc, char *argv[]) { int nerrors = 0; int i, j, ndims=1; int driver=DB_HDF5; char *filename="largefile.h5"; DBfile *dbfile; /* Parse command-line */ for (i=1; i<argc; i++) { if (!strcmp(argv[i], "DB_PDB")) { fprintf(stderr, "This test only supported on HDF5 driver\n"); exit(1); } else if (!strcmp(argv[i], "DB_HDF5")) { driver = DB_HDF5; filename = "largefile.h5"; } else { fprintf(stderr, "%s: ignored argument '%s'\n", argv[0], argv[i]); } } DBShowErrors(DB_TOP, NULL); DBForceSingle(1); /* * Create a file that contains a simple variables. */ printf("Creating file: '%s'\n", filename); dbfile = DBCreate(filename, 0, DB_LOCAL, "Simple Test", driver); for (j = 0; j < 2500; j++) { char tmpname[64]; if (j % 100 == 0) printf("Iterations %04d to %04d of %04d\n", j, j+100-1, 2500); sprintf(tmpname, "simple_%04d", j); for (i = 0; i < dims[0]; i++) val[i] = (float) dims[0] * j + i; if (DBWrite(dbfile, tmpname, val, dims, ndims, DB_FLOAT) != 0) { DBClose(dbfile); exit(1); } } /* * Put some objects VisIt can process at the end of the file */ build_curve(dbfile, driver); DBClose(dbfile); /* * Now try opening the file again and reading the simple * variable. */ printf("Reopening '%s'\n", filename); dbfile = DBOpen(filename, driver, DB_READ); if (dbfile == 0) { printf("Unable to Reopen file for reading\n"); exit(1); } /* * Randomly examine 50 arrays from the first and last 500 */ srand(0xBabeFace); for (j = 0; j < 100; j++) { char tmpname[64]; int n = rand() % 500 + (j >= 50 ? 200 : 0); sprintf(tmpname, "simple_%04d", n); if (DBReadVar(dbfile, tmpname, rval) < 0) { nerrors++; if (nerrors < 10) printf("DBReadVar for \"%s\" failed\n", tmpname); if (nerrors == 10) printf("Further errors will be suppressed\n"); } for (i = 0; i < dims[0]; i++) { val[i] = (float) dims[0] * n + i; if (val[i] != rval[i]) { nerrors++; if (nerrors < 10) printf("Read error in \"%s\" at position %04d. Expected %f, got %f\n", tmpname, i, val[i], rval[i]); if (nerrors == 10) printf("Further errors will be suppressed\n"); break; } } } DBClose(dbfile); exit(nerrors > 0); }
// XXX revisit after DB eror uint8_t XTDBCreateIndex(XTDBHandle* handle,char* fieldName) { String idxDBName; String descKey; bson idxDesc; BinaryStr key,value,data; DataBaseBE* db; int rc; StrInit(&descKey); if(StrAppendFmt(&descKey,"index.value.%s",fieldName)) { handle->error = XTDB_NO_MEM; return False; } StrToBStr(descKey.ptr,&key); if (DBGet(handle->descDB,&key,&value)) { // Index already exists printf("Index already exists.\n"); StrFree(&descKey); BinaryStrFree(&value); handle->error= XTDB_INDEX_EXISTS; return False; } bson_init(&idxDesc); if (bson_append_string(&idxDesc,"name",fieldName)) { handle->error = XTDB_NO_MEM; bson_destroy(&idxDesc); StrFree(&descKey); return False; } if (bson_finish(&idxDesc)) { handle->error = XTDB_NO_MEM; bson_destroy(&idxDesc); StrFree(&descKey); return False; } BsonToBStr(&idxDesc,&value); if (!DBSet(handle->descDB,&key,&value,False)) { printf("Error Adding to index names list\n"); handle->error = DBGetLastError(handle->descDB); bson_destroy(&idxDesc); StrFree(&descKey); return False; } StrFree(&descKey); StrToBStr(IDXFIELDNAME,&key); StrToBStr(fieldName,&value); if (!DBSet(handle->descDB,&key,&value,True)) { //printf("Error Adding to index names list\n"); handle->error = DBGetLastError(handle->descDB); //handle->error = XTDB_IO_ERR; bson_destroy(&idxDesc); return False; } bson_destroy(&idxDesc); if (GetIndexDBName(handle,fieldName,&idxDBName)) { handle->error = XTDB_NO_MEM; return False; } db = DBInit(STR(&idxDBName),BDBOWRITER | BDBOCREAT); StrFree(&idxDBName); if (!db) { handle->error = XTDB_NO_MEM; return False; } rc = DBOpen(db,BDBOCREAT|BDBOWRITER); if (!rc) { handle->error = DBGetLastError(db); DBFree(db); return False; } DBClose(db); DBFree(db); if (!XTDBAddIndex(handle,fieldName)) { // AddIndex failed return printf("Error Adding to index names list\n"); return False; } assert(XTDBGetIndex(handle,fieldName)); void* iter = DBIter(handle->mainDB); while (DBIterCur(handle->mainDB,iter,&key,&data)) { //printf("Adding value to index\n"); bson obj; BStrToBson(&data,&obj); if (!XTDBInsertToIndex(handle,&key,&data)) { return False; } BinaryStrFree(&key); BinaryStrFree(&data); DBIterNext(handle->mainDB,iter); } DBIterFree(handle->mainDB,iter); return True; }
/*------------------------------------------------------------------------- * Function: main * * Purpose: * * Return: Success: * * Failure: * * Programmer: Robb Matzke * Tuesday, February 9, 1999 * * Modifications: * Eric Brugger, Fri Apr 14 09:30:47 PDT 2000 * I modified the routine to not perform some tests that are not valid * when using the PDB driver. There was already code to not do those * tests when using the pdb driver but it wasn't quite correct. * *------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { DBfile *dbfile; int i, nerrors=0, driver=DB_PDB; char *filename="sami.pdb"; for (i=1; i<argc; i++) { if (!strcmp(argv[i], "DB_PDB")) { driver = DB_PDB; filename = "sami.pdb"; } else if (!strcmp(argv[i], "DB_HDF5")) { driver = DB_HDF5; filename = "sami.h5"; } else if (!strcmp(argv[i], "DB_LOCAL")) { arch_g = DB_LOCAL; } else if (!strcmp(argv[i], "DB_SUN3")) { arch_g = DB_SUN3; } else if (!strcmp(argv[i], "DB_SUN4")) { arch_g = DB_SUN4; } else if (!strcmp(argv[i], "DB_SGI")) { arch_g = DB_SGI; } else if (!strcmp(argv[i], "DB_RS6000")) { arch_g = DB_RS6000; } else if (!strcmp(argv[i], "DB_CRAY")) { arch_g = DB_CRAY; } else { fprintf(stderr, "%s: ignored argument `%s'\n", argv[0], argv[i]); } } /* turn of deprecate warnings */ DBSetDeprecateWarnings(0); /* * Create a new file (clobbering any old file), write some variables to * the file, then read them and compare with what was written. */ puts("=== Creating file ==="); if (NULL==(dbfile=DBCreate(filename, DB_CLOBBER, arch_g, "testing SAMI HDF5 silo driver", driver))) { puts("DBCreate() failed"); nerrors++; } /* Write the first time, creating variables */ nerrors += test_write_all(dbfile); nerrors += test_read_all(dbfile); nerrors += test_get_all(dbfile); nerrors += test_inqvar(dbfile); /* Write a second time, writing new values to existing variables */ nerrors += test_write_all(dbfile); nerrors += test_read_all(dbfile); /* Rewrite with different memory data type and verify results */ if (DB_PDB != driver) { nerrors += test_type_conv(dbfile); } /* * Do some illegal things to make sure they fail. Make sure we can still * read data. */ if (DB_PDB != driver) { nerrors += test_write_bad(dbfile); nerrors += test_read_all(dbfile); } if (DBClose(dbfile)<0) { puts("DBClose() failed"); nerrors++; } /* Open the file for read only and read all variables */ puts("=== Opening for read-only ==="); if (NULL==(dbfile=DBOpen(filename, DB_UNKNOWN, DB_READ))) { puts("DBOpen() failed for read-only access"); nerrors++; } nerrors += test_read_all(dbfile); if (DBClose(dbfile)<0) { puts("DBClose() failed"); nerrors++; } /* Open the file for read-write and test slicing */ puts("=== Opening for read-write ==="); if (NULL==(dbfile=DBOpen(filename, driver, DB_APPEND))) { puts("DBOpen() failed for read-write access"); nerrors++; } nerrors += test_read_all(dbfile); nerrors += test_write_slice(dbfile); nerrors += test_read_all(dbfile); nerrors += test_read_slice(dbfile); nerrors += test_dirs(dbfile); nerrors += test_curve(dbfile); nerrors += test_quadmesh(dbfile); nerrors += test_ucdmesh(dbfile); if (DBClose(dbfile)<0) { puts("DBClose() failed"); nerrors++; } if (nerrors) { printf("*** %d error%s detected ***\n", nerrors, 1==nerrors?"":"s"); } else { puts("All sami tests passed."); } return nerrors?1:0; }
int Restart_read_driver(char *dmpname, int mdmpflag, int memflag) { char *me = "Restart_read_driver"; char *kern, *rem, *infostr; char msg[MAXLINE]; int i, error = 0, ierr; int num, mycyc, iblk, gblk, namelen; int mynblk; int numBlocks, numDomains; int *domainFiles; DBfile *idbid; RGST_AttributeElem_t *func; if (memflag == 1) { memclr() ; } comlock(dmp_nbaton); if (mdmpflag) { kern = strtok(dmpname,"-"); rem = strtok(NULL,"-"); mycyc = atoi(rem); RestartCycle = mycyc; strcpy(RestartKernel,kern); rootfile_read(kern,mycyc); } else { namelen = strlen(dmpname); if (namelen > 10) { memset(msg,'\0',MAXLINE); strncpy(RestartKernel,dmpname,namelen - 10); RestartKernel[namelen - 9] = '\0'; i = strlen(dmpname) - 10; strncpy(msg,&(dmpname[i]), 5); RestartCycle = atoi(msg); } else { } idbid = DBOpen (dmpname, DB_PDB, DB_READ); if (idbid == NULL) { error = 1 ; sprintf(msg,"Can't open dump %s\n",dmpname); ctlwarning(me,msg); return(error) ; } infostr = DBGetVar (idbid, "_fileinfo"); namelen = strlen(codename); if (strncmp (infostr, codename, namelen) != 0) { sprintf(msg,"Restarting from a dump which is not %s. This is EVIL!\n", codename); ctlwarning(me,msg); } FREEMEM(infostr); decomp_setdir(idbid); ierr = DBReadVar(idbid,"NumBlocks",&numBlocks); ierr += DBReadVar(idbid,"NumDomains",&numDomains); if (ierr != 0) ctlerror(me,gv_errmsg_DBReadVar); decomp_new(numBlocks, numDomains); decomp_read(idbid, msg, 0, 0); if (DBSetDir(idbid, "/") != 0) ctlerror(me,gv_errmsg_DBSetDir); error += Restart_read_global(idbid); dmpattr_set(); domainFiles = MALLOT(int, gnblk); for (gblk = 0; gblk < gnblk; gblk++) { domainFiles[gblk] = gmap[gblk].lblk; } calculate_mappings(); mynblk = 0; for (gblk = 0; gblk < gnblk; gblk++) { if (gmap[gblk].proc != myid) continue; iblk = gmap[gblk].lblk; Restart_read_domain(idbid, domainFiles[gblk], iblk); mynblk++; } nblk = mynblk; DBClose(idbid); FREEMEM(domainFiles); } dmpattr_unset(); comunlock(dmp_nbaton); ifparallel = 0; nblk = gnblk; initcom(NULL,0); sprintf(msg,"dump '%s' read",dmpname); ctlmsg(msg); printtc() ; func = rgst_list_attr(A_OBJECT, "Function_Gen"); while (func != NULL) { Command_t *cp = (Command_t *) func->rgst_obj->obj; (*(cp->proc))(); func = func->next; } blknum = 0 ; genmd = -1; error += qbnd(FULL_STEP,COM_RECV); error += qbnd(FULL_STEP,COM_SEND); error += qbnd(FULL_STEP,COM_WAIT_RECV); TimeStepControl_initialize() ; for ( iblk = 0 ; iblk < nblk ; iblk++ ) { updateblk( &domains[iblk], 0, 0.0 ) ; } ; error += qbnd(FULL_STEP,COM_WAIT_SEND); editor(FULL_STEP); genmd = 0; hash_optimize_all(); return(0); }
/*------------------------------------------------------------------------- * Function: main * * Purpose: * * Return: 0 * * Programmer: * * Modifications: * Robb Matzke, 1999-04-09 * Added argument parsing to control the driver which is used. * * Mark C. Miller, Mon Sep 21 15:20:30 PDT 2009 * Added code to test long long type. * * Mark C. Miller, Wed Sep 23 11:57:24 PDT 2009 * Added logic to test DBInqFile. * * Mark C. Miller, Fri Nov 13 15:40:35 PST 2009 * Test long long on PDB driver too. *------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { int i, j, k; int ndims, dims[3]; float val[NX * NY * NZ]; long long lval[NX * NY * NZ]; int offset[3], length[3], stride[3]; float val2[NX * NY * NZ]; long long *lval2 = 0; int cnt, driver=DB_PDB; char *filename="simple.pdb"; int k1, k2; int err = 0; int inqval; DBfile *dbfile; int show_all_errors = FALSE; /* Parse command-line */ for (i=1; i<argc; i++) { if (!strncmp(argv[i], "DB_PDB", 6)) { driver = StringToDriver(argv[i]); filename = "simple.pdb"; } else if (!strncmp(argv[i], "DB_HDF5", 7)) { driver = StringToDriver(argv[i]); filename = "simple.h5"; } else if (!strcmp(argv[i], "show-all-errors")) { show_all_errors = 1; } else if (argv[i][0] != '\0') { fprintf(stderr, "%s: ignored argument `%s'\n", argv[0], argv[i]); } } DBShowErrors(show_all_errors?DB_ALL_AND_DRVR:DB_TOP, NULL); DBForceSingle(1); /* * Build a simple variables. */ ndims = 3; dims[0] = NZ; dims[1] = NY; dims[2] = NX; for (k = 0; k < NZ; k++) { for (j = 0; j < NY; j++) { for (i = 0; i < NX; i++) { val[i + j * NX + k * NX * NY] = i + j * NX + k * NX * NY; lval[i + j * NX + k * NX * NY] = ((long long) 1 << 35) + i + j * NX + k * NX * NY; } } } /* Test InqFile on a PDB (but not Silo) file */ if (driver == DB_PDB) inqval = DBInqFile("not_a_silo_file.pdb"); else inqval = DBInqFile("not_a_silo_file.h5"); if (inqval < 0) { fprintf(stderr, "Error in InqFile attempting to identify not_a_silo_file"); err = 1; } else if (inqval > 0) { fprintf(stderr, "InqFile incorrectly identified not_a_silo_file"); err = 1; } /* Create empty silo file to test InqFile */ dbfile = DBCreate(filename, 0, DB_LOCAL, "Empty Silo File", driver); DBClose(dbfile); if (DBInqFile(filename) <= 0) { fprintf(stderr, "InqFile says file created via DBCreate is NOT a silo file"); err = 1; } unlink(filename); /* * Create a file that contains a simple variables. */ printf("Creating file: `%s'\n", filename); dbfile = DBCreate(filename, 0, DB_LOCAL, "Simple Test", driver); DBWrite(dbfile, "simple", val, dims, ndims, DB_FLOAT); DBWrite(dbfile, "longlong", lval, dims, ndims, DB_LONG_LONG); DBClose(dbfile); /* * Now try opening the file again and reading the simple * variable. */ printf("Reopening `%s'\n", filename); dbfile = DBOpen(filename, driver, DB_READ); offset[0] = 0; offset[1] = 0; offset[2] = 0; length[0] = NZ2; length[1] = NY2; length[2] = NX2; stride[0] = 1; stride[1] = 1; stride[2] = 1; for (i = 0; i < NX * NY * NZ; i++) val2[i] = 0; DBReadVarSlice(dbfile, "simple", offset, length, stride, ndims, val2); lval2 = DBGetVar(dbfile, "longlong"); DBClose(dbfile); /* * Check the data. */ cnt = 0; for (k = 0; k < NZ2; k++) { for (j = 0; j < NY2; j++) { for (i = 0; i < NX2; i++) { if (val2[i + j * NX2 + k * NX2 * NY2] != val[i + j * NX + k * NX * NY]) cnt++; } } } err += cnt; printf("%d values don't match\n", cnt); cnt = 0; k1 = NX2 * NY2 * NZ2; k2 = NX * NY * NZ; for (i = k1; i < k2; i++) if (val2[i] != 0) cnt++; printf("%d values were overwritten\n", cnt); cnt = 0; for (k = 0; k < NZ && lval2; k++) { for (j = 0; j < NY; j++) { for (i = 0; i < NX; i++) { if (lval2[i + j * NX + k * NX * NY] != lval[i + j * NX + k * NX * NY]) cnt++; } } } err += cnt; printf("%d long long values don't match\n", cnt); if (lval2) free(lval2); CleanupDriverStuff(); return err; }
int main(int argc, char *argv[]) { DBfile *dbfile; DBmultimeshadj *foo; int i, driver = DB_PDB; char *filename = "adjacency.pdb"; DBShowErrors(DB_ALL, NULL); for (i=1; i<argc; i++) { if (!strcmp(argv[i], "DB_PDB")) { driver = DB_PDB; filename = "adjacency.pdb"; } else if (!strcmp(argv[i], "DB_HDF5")) { driver = DB_HDF5; filename = "adjacency.h5"; } else { fprintf(stderr, "%s: ignored argument `%s'\n", argv[0], argv[i]); } } printf("Creating test file: \"%s\".\n", filename); dbfile = DBCreate(filename, 0, DB_LOCAL, "multi-mesh adjacency test file", driver); /* this is a really basic test of DBPutMultimeshadj. It tests only that the API behaves as expected, not the contents of the object */ { int meshtypes[] = {DB_UCDMESH, DB_UCDMESH, DB_UCDMESH, DB_UCDMESH, DB_UCDMESH}; int nneighbors[] = {3, 3, 3, 3, 4}; int neighbors[] = {1,3,4, 0,2,4, 1,3,4, 0,2,4, 0,1,2,3}; int lnodelists[] = {3,3,3, 3,3,3, 3,3,3, 3,3,3, 3,3,3,3}; /* note, we're using global indexing here. Its just a test. */ static int nodelistA[] = {4,13,22}; /* 0 & 1 */ static int nodelistB[] = {35,36,37}; /* 0 & 3 */ static int nodelistC[] = {22,30,37}; /* 0 & 4 */ static int nodelistD[] = {4,13,22}; /* 1 & 0 */ static int nodelistE[] = {41,42,43}; /* 1 & 2 */ static int nodelistF[] = {22,31,41}; /* 1 & 4 */ static int nodelistG[] = {41,42,43}; /* 2 & 1 */ static int nodelistH[] = {56,65,74}; /* 2 & 3 */ static int nodelistI[] = {41,48,56}; /* 2 & 4 */ static int nodelistJ[] = {35,36,37}; /* 3 & 0 */ static int nodelistK[] = {56,65,74}; /* 3 & 2 */ static int nodelistL[] = {37,47,56}; /* 3 & 4 */ static int nodelistM[] = {22,30,37}; /* 4 & 0 */ static int nodelistN[] = {22,31,41}; /* 4 & 1 */ static int nodelistO[] = {41,48,56}; /* 4 & 2 */ static int nodelistP[] = {37,47,56}; /* 4 & 3 */ static int *nodelists[] = {nodelistA, nodelistB, nodelistC, nodelistD, nodelistE, nodelistF, nodelistG, nodelistH, nodelistI, nodelistJ, nodelistK, nodelistL, nodelistM, nodelistN, nodelistO, nodelistP}; static int *nodelists2[] = {nodelistA, nodelistB, nodelistC, NULL, NULL, NULL, NULL, NULL, NULL, nodelistJ, nodelistK, nodelistL, nodelistM, nodelistN, nodelistO, nodelistP}; static int *nodelists3[] = { NULL, NULL, NULL, nodelistD, nodelistE, nodelistF, nodelistG, nodelistH, nodelistI, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; int nblocks = sizeof(meshtypes) / sizeof(meshtypes[0]); DBPutMultimeshadj(dbfile, "mmadjacency", nblocks, meshtypes, nneighbors, neighbors, NULL, lnodelists, nodelists, NULL, NULL, NULL); /* now try writing the same object with repeated calls */ DBPutMultimeshadj(dbfile, "mmadjacency2", nblocks, meshtypes, nneighbors, neighbors, NULL, lnodelists, nodelists2, NULL, NULL, NULL); DBPutMultimeshadj(dbfile, "mmadjacency2", nblocks, meshtypes, nneighbors, neighbors, NULL, lnodelists, nodelists3, NULL, NULL, NULL); } DBClose(dbfile); dbfile = DBOpen(filename, DB_UNKNOWN, DB_READ); /* test reading a multimesh adj object */ foo = DBGetMultimeshadj(dbfile, "mmadjacency", -1, NULL); DBClose(dbfile); return 0; }
int main(int argc, char *argv[]) { int driver = DB_PDB; char *filename = "empty.silo"; int show_all_errors = FALSE; int i, pass; char const * const cnames[3] = {"x","y","z"}; void *coords[3] = {(void*)1,(void*)2,(void*)3}; /* really funky dummy pointers */ void *vars[3] = {(void*)1,(void*)2,(void*)3}; /* really funky dummy pointers */ void const * const vvars[3] = {(void*)1,(void*)2,(void*)3}; /* really funky dummy pointers */ void *var = (void*)1; int iarr[3] = {1,1,1}; /* dummy int array */ int ZDIMS[3] = {0,0,0}; double exts[4] = {0,0,0,0}; DBoptlist *ol = 0; double dtime = 0.0; int hide_from_gui=0; int *gnodeno = 0; int *gzoneno = 0; char *ghostn = 0; char *ghostz = 0; /* Parse command-line */ for (i=1; i<argc; i++) { if (!strncmp(argv[i], "DB_", 3)) { driver = StringToDriver(argv[i]); } else if (!strcmp(argv[i], "show-all-errors")) { show_all_errors = 1; } else if (argv[i][0] != '\0') { fprintf(stderr, "%s: ignored argument `%s'\n", argv[0], argv[i]); } } DBSetDeprecateWarnings(0); DBShowErrors(show_all_errors?DB_ALL_AND_DRVR:DB_NONE, NULL); printf("Creating test file \"%s\".\n", filename); dbfile = DBCreate(filename, DB_CLOBBER, DB_LOCAL, "test empty silo objects", driver); ol = DBMakeOptlist(10); DBAddOption(ol, DBOPT_DTIME, &dtime); DBAddOption(ol, DBOPT_HIDE_FROM_GUI, &hide_from_gui); DBAddOption(ol, DBOPT_NODENUM, gnodeno); DBAddOption(ol, DBOPT_ZONENUM, gzoneno); DBAddOption(ol, DBOPT_GHOST_NODE_LABELS, ghostn); DBAddOption(ol, DBOPT_GHOST_ZONE_LABELS, ghostz); /* first pass confirms we catch bad arguments; second pass confirms we permit empty objects */ for (pass = 0; pass < 2; pass++) { const int dt = DB_FLOAT; const int ct = DB_ZONECENT; const int ZZ = 0; /* Used for sole arg causing emptiness */ if (pass) DBSetAllowEmptyObjects(1); /* Because references to the following objects will not ever appear in a multi-xxx object, we do not currently test for support of empties... DBPutUcdsubmesh, DBPutMrgtree, DBPutMrgvar, DBPutGroupelmap Note: 'ZZ' or 'ZDIMS' is the key argument in each call that triggers an empty */ /* empty curve objects */ ASSERT(DBPutCurve(dbfile,"empty_curvea",coords[0],coords[0],dt,ZZ,OL(ol)),retval<0,retval==0); ASSERT(DBPutCurve(dbfile,"empty_curveb", 0,coords[0],dt,ZZ,OL(ol)),retval<0,retval==0); ASSERT(DBPutCurve(dbfile,"empty_curvec",coords[0], 0,dt,ZZ,OL(ol)),retval<0,retval==0); /* empty point meshes and vars */ ASSERT(DBPutPointmesh(dbfile,"empty_pointmesha",1,coords,ZZ,dt,OL(ol)),retval<0,retval==0); ASSERT(DBPutPointmesh(dbfile,"empty_pointmeshb",3, 0,ZZ,dt,OL(ol)),retval<0,retval==0); ASSERT(DBPutPointvar(dbfile,"pva","empty_pointmesha",1,vars,ZZ,dt,OL(ol)),retval<0,retval==0); ASSERT(DBPutPointvar(dbfile,"pvb","empty_pointmesha",3, 0,ZZ,dt,OL(ol)),retval<0,retval==0); ASSERT(DBPutPointvar1(dbfile,"pv1a","empty_pointmesha",var,ZZ,dt,OL(ol)),retval<0,retval==0); ASSERT(DBPutPointvar1(dbfile,"pv1b","empty_pointmesha", 0,ZZ,dt,OL(ol)),retval<0,retval==0); /* empty quad meshes and vars (ZDIMS is the magic zero'ing arg) */ ASSERT(DBPutQuadmesh(dbfile,"empty_quadmesha", 0,coords,ZDIMS,1,dt,DB_COLLINEAR,OL(ol)),retval<0,retval==0); ASSERT(DBPutQuadmesh(dbfile,"empty_quadmeshb",cnames, 0,ZDIMS,2,dt,DB_COLLINEAR,OL(ol)),retval<0,retval==0); ASSERT(DBPutQuadmesh(dbfile,"empty_quadmeshc",cnames,coords,ZDIMS,3,dt,DB_COLLINEAR,OL(ol)),retval<0,retval==0); ASSERT(DBPutQuadvar(dbfile,"qva","empty_quadmesha",2, 0,vars,ZDIMS,2,0,0,dt,ct,OL(ol)),retval<0,retval==0); ASSERT(DBPutQuadvar(dbfile,"qvb","empty_quadmesha",3,cnames, 0,ZDIMS,3,0,0,dt,ct,OL(ol)),retval<0,retval==0); ASSERT(DBPutQuadvar1(dbfile,"qv1a","empty_quadmesha", 0,ZDIMS,ZZ,var,0,dt,ct,OL(ol)),retval<0,retval==0); ASSERT(DBPutQuadvar1(dbfile,"qv1b","empty_quadmesha",var,ZDIMS,ZZ, 0,0,dt,ct,OL(ol)),retval<0,retval==0); /* empty ucd meshes, facelists, zonelists and vars */ ASSERT(DBPutUcdmesh(dbfile,"empty_ucdmesh1",3,cnames,coords,ZZ,1,"foo","bar",dt,OL(ol)),retval<0,retval==0); ASSERT(DBPutUcdmesh(dbfile,"empty_ucdmesh2",1, 0,coords,ZZ,1,"foo","bar",dt,OL(ol)),retval<0,retval==0); ASSERT(DBPutUcdmesh(dbfile,"empty_ucdmesh3",2,cnames, 0,ZZ,0,"foo","bar",dt,OL(ol)),retval<0,retval==0); ASSERT(DBPutUcdmesh(dbfile,"empty_ucdmesh3",0, 0, 0,ZZ,0, 0, 0,dt,OL(ol)),retval<0,retval==0); ASSERT(DBPutFacelist(dbfile,"empty_facelista",ZZ,0,iarr,1,1,iarr,iarr,iarr,1,iarr,iarr,1),retval<0,retval==0); ASSERT(DBPutFacelist(dbfile,"empty_facelistb",ZZ,0, 0,1,1,iarr,iarr,iarr,1,iarr,iarr,1),retval<0,retval==0); ASSERT(DBPutFacelist(dbfile,"empty_facelistc",ZZ,0,iarr,1,1, 0,iarr,iarr,1,iarr,iarr,1),retval<0,retval==0); ASSERT(DBPutFacelist(dbfile,"empty_facelistd",ZZ,0,iarr,1,1,iarr, 0,iarr,1,iarr,iarr,1),retval<0,retval==0); ASSERT(DBPutFacelist(dbfile,"empty_faceliste",ZZ,0,iarr,1,1,iarr,iarr, 0,1,iarr,iarr,1),retval<0,retval==0); ASSERT(DBPutFacelist(dbfile,"empty_facelistf",ZZ,0,iarr,1,1,iarr,iarr,iarr,1, 0,iarr,1),retval<0,retval==0); ASSERT(DBPutFacelist(dbfile,"empty_facelistg",ZZ,0,iarr,1,1,iarr,iarr,iarr,1,iarr, 0,1),retval<0,retval==0); ASSERT(DBPutZonelist(dbfile,"empty_zonelista",ZZ,1,iarr,10,0,iarr,iarr,10),retval<0,retval==0); ASSERT(DBPutZonelist(dbfile,"empty_zonelistb",ZZ,1, 0,10,0,iarr,iarr,10),retval<0,retval==0); ASSERT(DBPutZonelist(dbfile,"empty_zonelistc",ZZ,1,iarr,10,0, 0,iarr,10),retval<0,retval==0); ASSERT(DBPutZonelist(dbfile,"empty_zonelistd",ZZ,1,iarr,10,0,iarr, 0,10),retval<0,retval==0); ASSERT(DBPutZonelist2(dbfile,"empty_zonelist2a",ZZ,1,iarr,1,0,0,0,iarr,iarr,iarr,1,OL(ol)),retval<0,retval==0); ASSERT(DBPutZonelist2(dbfile,"empty_zonelist2b",ZZ,0, 0,1,3,3,3,iarr,iarr,iarr,1,OL(ol)),retval<0,retval==0); ASSERT(DBPutZonelist2(dbfile,"empty_zonelist2c",ZZ,1,iarr,0,3,3,3, 0,iarr,iarr,1,OL(ol)),retval<0,retval==0); ASSERT(DBPutZonelist2(dbfile,"empty_zonelist2d",ZZ,1,iarr,1,0,3,0,iarr, 0,iarr,0,OL(ol)),retval<0,retval==0); ASSERT(DBPutZonelist2(dbfile,"empty_zonelist2e",ZZ,1,iarr,1,3,0,0,iarr,iarr, 0,1,OL(ol)),retval<0,retval==0); ASSERT(DBPutPHZonelist(dbfile,"empty_phzonelista",ZZ,iarr,1,iarr,cnames[0],1,iarr,1,iarr,0,0,0,OL(ol)),retval<0,retval==0); ASSERT(DBPutPHZonelist(dbfile,"empty_phzonelistb",ZZ, 0,1,iarr,cnames[0],1,iarr,1,iarr,0,0,0,OL(ol)),retval<0,retval==0); ASSERT(DBPutPHZonelist(dbfile,"empty_phzonelistc",ZZ,iarr,1, 0,cnames[0],1,iarr,1,iarr,0,0,0,OL(ol)),retval<0,retval==0); ASSERT(DBPutPHZonelist(dbfile,"empty_phzonelistd",ZZ,iarr,1,iarr, 0,1,iarr,1,iarr,0,0,0,OL(ol)),retval<0,retval==0); ASSERT(DBPutPHZonelist(dbfile,"empty_phzoneliste",ZZ,iarr,1,iarr,cnames[0],1, 0,1,iarr,0,0,0,OL(ol)),retval<0,retval==0); ASSERT(DBPutPHZonelist(dbfile,"empty_phzonelistf",ZZ,iarr,1,iarr,cnames[0],1,iarr,1, 0,0,0,0,OL(ol)),retval<0,retval==0); ASSERT(DBPutUcdvar(dbfile,"uva","empty_ucdmesh1",0,cnames,vars,ZZ,vars,1,dt,ct,OL(ol)),retval<0,retval==0); ASSERT(DBPutUcdvar(dbfile,"uvb","empty_ucdmesh1",1, 0,vars,ZZ,vars,1,dt,ct,OL(ol)),retval<0,retval==0); ASSERT(DBPutUcdvar(dbfile,"uvc","empty_ucdmesh1",2,cnames, 0,ZZ,vars,1,dt,ct,OL(ol)),retval<0,retval==0); ASSERT(DBPutUcdvar(dbfile,"uvd","empty_ucdmesh1",3,cnames,vars,ZZ, 0,1,dt,ct,OL(ol)),retval<0,retval==0); ASSERT(DBPutUcdvar(dbfile,"uve","empty_ucdmesh1",3, 0, 0,ZZ, 0,1,dt,ct,OL(ol)),retval<0,retval==0); ASSERT(DBPutUcdvar1(dbfile,"uv1a","empty_ucdmesh1",var,ZZ,vars[0],1,dt,ct,OL(ol)),retval<0,retval==0); ASSERT(DBPutUcdvar1(dbfile,"uv1b","empty_ucdmesh1", 0,ZZ,vars[0],1,dt,ct,OL(ol)),retval<0,retval==0); ASSERT(DBPutUcdvar1(dbfile,"uv1c","empty_ucdmesh1",var,ZZ, 0,1,dt,ct,OL(ol)),retval<0,retval==0); ASSERT(DBPutUcdvar1(dbfile,"uv1d","empty_ucdmesh1", 0,ZZ, 0,1,dt,ct,OL(ol)),retval<0,retval==0); /* csg meshes and vars */ ASSERT(DBPutCsgmesh(dbfile,"empty_csgmesh1",2,ZZ, 0,iarr,var,1,dt,exts,"foo",OL(ol)),retval<0,retval==0); ASSERT(DBPutCsgmesh(dbfile,"empty_csgmesh2",2,ZZ,iarr, 0,var,2,dt,exts,"foo",OL(ol)),retval<0,retval==0); ASSERT(DBPutCsgmesh(dbfile,"empty_csgmesh3",3,ZZ,iarr,iarr, 0,3,dt,exts,"foo",OL(ol)),retval<0,retval==0); ASSERT(DBPutCsgmesh(dbfile,"empty_csgmesh4",3,ZZ,iarr,iarr,var,0,dt,exts,"foo",OL(ol)),retval<0,retval==0); ASSERT(DBPutCSGZonelist(dbfile,"empty_csgzonelista",0,iarr,iarr,iarr,0,0,dt,ZZ,iarr,OL(ol)),retval<0,retval==0); ASSERT(DBPutCSGZonelist(dbfile,"empty_csgzonelistb",1, 0,iarr,iarr,0,0,dt,ZZ,iarr,OL(ol)),retval<0,retval==0); ASSERT(DBPutCSGZonelist(dbfile,"empty_csgzonelistc",1,iarr, 0,iarr,0,0,dt,ZZ,iarr,OL(ol)),retval<0,retval==0); ASSERT(DBPutCSGZonelist(dbfile,"empty_csgzonelistd",1,iarr,iarr, 0,0,0,dt,ZZ,iarr,OL(ol)),retval<0,retval==0); ASSERT(DBPutCSGZonelist(dbfile,"empty_csgzoneliste",1,iarr,iarr,iarr,0,0,dt,ZZ, 0,OL(ol)),retval<0,retval==0); ASSERT(DBPutCsgvar(dbfile,"csgva","empty_csgmesh1",0,cnames,vvars,ZZ,dt,ct,OL(ol)),retval<0,retval==0); ASSERT(DBPutCsgvar(dbfile,"csgvb","empty_csgmesh1",1, 0,vvars,ZZ,dt,ct,OL(ol)),retval<0,retval==0); ASSERT(DBPutCsgvar(dbfile,"csgvc","empty_csgmesh1",1,cnames, 0, ZZ,dt,ct,OL(ol)),retval<0,retval==0); ASSERT(DBPutCsgvar(dbfile,"csgvd","empty_csgmesh1",1,cnames,vvars,ZZ,dt,ct,OL(ol)),retval<0,retval==0); /* empty materials and species */ ASSERT(DBPutMaterial(dbfile,"empty_mata","foo",1,iarr,iarr,ZDIMS,1,iarr,iarr,iarr,vars[0],1,dt,OL(ol)),retval<0,retval==0); ASSERT(DBPutMaterial(dbfile,"empty_matb","foo",1, 0,iarr,ZDIMS,1,iarr,iarr,iarr,vars[0],1,dt,OL(ol)),retval<0,retval==0); ASSERT(DBPutMaterial(dbfile,"empty_matc","foo",1,iarr, 0,ZDIMS,1,iarr,iarr,iarr,vars[0],1,dt,OL(ol)),retval<0,retval==0); ASSERT(DBPutMaterial(dbfile,"empty_matd","foo",1,iarr,iarr,ZDIMS,1, 0,iarr,iarr,vars[0],1,dt,OL(ol)),retval<0,retval==0); ASSERT(DBPutMaterial(dbfile,"empty_mate","foo",1,iarr,iarr,ZDIMS,1,iarr, 0,iarr,vars[0],1,dt,OL(ol)),retval<0,retval==0); ASSERT(DBPutMaterial(dbfile,"empty_matf","foo",1,iarr,iarr,ZDIMS,1,iarr,iarr, 0,vars[0],1,dt,OL(ol)),retval<0,retval==0); ASSERT(DBPutMaterial(dbfile,"empty_matg","foo",1,iarr,iarr,ZDIMS,1,iarr,iarr,iarr, 0,1,dt,OL(ol)),retval<0,retval==0); /* empty matspecies via dims[i] == 0 */ ASSERT(DBPutMatspecies(dbfile,"empty_speca","empty_mata",1,iarr,iarr,ZDIMS,1,1,var,iarr,1,dt,OL(ol)),retval<0,retval==0); ASSERT(DBPutMatspecies(dbfile,"empty_specb","empty_mata",1,iarr,iarr,ZDIMS,2,1,var,iarr,1,dt,OL(ol)),retval<0,retval==0); ASSERT(DBPutMatspecies(dbfile,"empty_specc","empty_mata",1,iarr,iarr,ZDIMS,3,1,var,iarr,1,dt,OL(ol)),retval<0,retval==0); ASSERT(DBPutMatspecies(dbfile,"empty_specd","empty_mata",1,iarr,iarr,ZDIMS,1,1, 0,iarr,1,dt,OL(ol)),retval<0,retval==0); ASSERT(DBPutMatspecies(dbfile,"empty_spece","empty_mata",1,iarr,iarr,ZDIMS,1,1,var, 0,0,dt,OL(ol)),retval<0,retval==0); /* empty matspeces via nspecies_mf==0 */ { int nd=2, d[2]={3,2}, slm[6]={0,0,-1,-3,0,0}, ml=4, msl[4]={1,2,1,2}, slc[6]={0,0,0,0,0,0}; ASSERT(DBPutMatspecies(dbfile,"empty_specf","empty_mata",1,iarr,slc,d,nd,ZZ,var, 0, 0,dt,OL(ol)),retval<0,retval==0); ASSERT(DBPutMatspecies(dbfile,"empty_specg","empty_mata",1,iarr,slm,d,nd,ZZ,var,msl,ml,dt,OL(ol)),retval<0,retval==0); } } DBClose(dbfile); dbfile = 0; /* Ok, now try to read each empty object to make sure we get what we expect and nothing fails */ dbfile = DBOpen(filename, DB_UNKNOWN, DB_READ); /* test read back of empty curves */ { int i=0; char *cnames[] = {"empty_curvea", "empty_curveb", "empty_curvec", 0}; DBSetDir(dbfile, "DBPutCurve"); while (cnames[i]) { DBcurve *curve = DBGetCurve(dbfile, cnames[i++]); assert(DBIsEmptyCurve(curve)); DBFreeCurve(curve); } DBSetDir(dbfile, ".."); } /* test read back of empty point meshes and vars */ { int i=0; char *pmnames[] = {"empty_pointmesha", "empty_pointmeshb", 0}; DBSetDir(dbfile, "DBPutPointmesh"); while (pmnames[i]) { DBpointmesh *pointmesh = DBGetPointmesh(dbfile, pmnames[i++]); assert(DBIsEmptyPointmesh(pointmesh)); DBFreePointmesh(pointmesh); } DBSetDir(dbfile, ".."); } { int i=0; char *vnames[] = {"pva", "pvb", "pv1a", "pv1b", 0}; DBSetDir(dbfile, "DBPutPointvar"); while (vnames[i]) { DBpointvar *pointvar = DBGetPointvar(dbfile, vnames[i++]); assert(DBIsEmptyPointvar(pointvar)); DBFreePointvar(pointvar); } DBSetDir(dbfile, ".."); } /* test read back of empty quad meshes and vars */ { int i=0; char *qmnames[] = {"empty_quadmesha", "empty_quadmeshb", "empty_quadmeshc", 0}; DBSetDir(dbfile, "DBPutQuadmesh"); while (qmnames[i]) { DBquadmesh *quadmesh = DBGetQuadmesh(dbfile, qmnames[i++]); assert(DBIsEmptyQuadmesh(quadmesh)); DBFreeQuadmesh(quadmesh); } DBSetDir(dbfile, ".."); } { int i=0; char *vnames[] = {"qva" , "qvb", "qv1a", "qv1b", 0}; DBSetDir(dbfile, "DBPutQuadvar"); while (vnames[i]) { DBquadvar *quadvar = DBGetQuadvar(dbfile, vnames[i++]); assert(DBIsEmptyQuadvar(quadvar)); DBFreeQuadvar(quadvar); } DBSetDir(dbfile, ".."); } /* test read back of empty ucd meshes, zonelists and vars */ { int i=0; char *mnames[] = {"empty_ucdmesh1", "empty_ucdmesh2", "empty_ucdmesh3", 0}; DBSetDir(dbfile, "DBPutUcdmesh"); while (mnames[i]) { DBucdmesh *ucdmesh = DBGetUcdmesh(dbfile, mnames[i++]); assert(DBIsEmptyUcdmesh(ucdmesh)); DBFreeUcdmesh(ucdmesh); } DBSetDir(dbfile, ".."); } { int i=0; char *flnames[] = {"empty_facelista", "empty_facelistb", "empty_facelistc", "empty_facelistd", "empty_faceliste", "empty_facelistf", "empty_facelistg", 0}; DBSetDir(dbfile, "DBPutFacelist"); while (flnames[i]) { DBfacelist *fl = DBGetFacelist(dbfile, flnames[i++]); assert(DBIsEmptyFacelist(fl)); DBFreeFacelist(fl); } DBSetDir(dbfile, ".."); } { int i=0; char *zlnames[] = {"empty_zonelista", "empty_zonelistb", "empty_zonelistc", "empty_zonelistd", "empty_zonelist2a", "empty_zonelist2b", "empty_zonelist2c", "empty_zonelist2d", "empty_zonelist2e", 0}; DBSetDir(dbfile, "DBPutZonelist"); while (zlnames[i]) { DBzonelist *zl = DBGetZonelist(dbfile, zlnames[i++]); assert(DBIsEmptyZonelist(zl)); DBFreeZonelist(zl); } DBSetDir(dbfile, ".."); } { int i=0; char *zlnames[] = {"empty_phzonelista", "empty_phzonelistb", "empty_phzonelistc", "empty_phzonelistd", "empty_phzoneliste", "empty_phzonelistf", 0}; DBSetDir(dbfile, "DBPutPHZonelist"); while (zlnames[i]) { DBphzonelist *zl = DBGetPHZonelist(dbfile, zlnames[i++]); assert(DBIsEmptyPHZonelist(zl)); DBFreePHZonelist(zl); } DBSetDir(dbfile, ".."); } { int i=0; char *vnames[] = { "uva", "uvb", "uvc", "uvd", "uve", "uv1a", "uv1b", "uv1c", "uv1d", 0}; DBSetDir(dbfile, "DBPutUcdvar"); while (vnames[i]) { DBucdvar *ucdvar = DBGetUcdvar(dbfile, vnames[i++]); assert(DBIsEmptyUcdvar(ucdvar)); DBFreeUcdvar(ucdvar); } DBSetDir(dbfile, ".."); } /* test read back of empty csg meshes and vars */ { int i=0; char *mnames[] = {"empty_csgmesh1", "empty_csgmesh2", "empty_csgmesh3", 0}; DBSetDir(dbfile, "DBPutCsgmesh"); while (mnames[i]) { DBcsgmesh *csgmesh = DBGetCsgmesh(dbfile, mnames[i++]); assert(DBIsEmptyCsgmesh(csgmesh)); DBFreeCsgmesh(csgmesh); } DBSetDir(dbfile, ".."); } { int i=0; char *zlnames[] = {"empty_csgzonelista", "empty_csgzonelistb", "empty_csgzonelistc", "empty_csgzonelistd", "empty_csgzoneliste", 0}; DBSetDir(dbfile, "DBPutCSGZonelist"); while (zlnames[i]) { DBcsgzonelist *zl = DBGetCSGZonelist(dbfile, zlnames[i++]); assert(DBIsEmptyCSGZonelist(zl)); DBFreeCSGZonelist(zl); } DBSetDir(dbfile, ".."); } { int i=0; char *vnames[] = {"csgva", "csgvb", "csgvc", "csgvd", 0}; DBSetDir(dbfile, "DBPutCsgvar"); while (vnames[i]) { DBcsgvar *csgvar = DBGetCsgvar(dbfile, vnames[i++]); assert(DBIsEmptyCsgvar(csgvar)); DBFreeCsgvar(csgvar); } DBSetDir(dbfile, ".."); } /* test read back of empty materials and matspecies */ { int i=0; char *vnames[] = {"empty_mata", "empty_matb", "empty_matc", "empty_matd", "empty_mate", "empty_matf", "empty_matg", 0}; DBSetDir(dbfile, "DBPutMaterial"); while (vnames[i]) { DBmaterial *mat = DBGetMaterial(dbfile, vnames[i++]); assert(DBIsEmptyMaterial(mat)); DBFreeMaterial(mat); } DBSetDir(dbfile, ".."); } { int i=0; char *vnames[] = {"empty_speca", "empty_specb", "empty_specc", "empty_specd", "empty_spece", "empty_specf", "empty_specg", 0}; DBSetDir(dbfile, "DBPutMatspecies"); while (vnames[i]) { DBmatspecies *spec = DBGetMatspecies(dbfile, vnames[i++]); assert(DBIsEmptyMatspecies(spec)); DBFreeMatspecies(spec); } DBSetDir(dbfile, ".."); } DBClose(dbfile); CleanupDriverStuff(); return 0; }
/*------------------------------------------------------------------------- * Function: main * * Purpose: * * Return: 0 * * Programmer: * Thomas R. Treadway, Mon Mar 12 14:13:51 PDT 2007 * Test of HDF5 compression. * * Modifications: * *------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { int nerrors = 0; int verbose = 0; int usefloat = 0; int readonly = 0; int i, j, ndims=1; int fdims[]= {ONE_MEG/sizeof(float)}; int ddims[]= {ONE_MEG/sizeof(double)}; float *fval; float *frval; double *dval; double *drval; int driver=DB_HDF5; char *filename="compression.h5"; char *ptr; char tmpname[64]; DBfile *dbfile; #if !defined(_WIN32) struct timeval tim; double t1, t2; #endif struct stat buffer; off_t fsize; int has_loss = 0; int show_errors = DB_TOP; /* Parse command-line */ for (i=1; i<argc; i++) { if (!strncmp(argv[i], "DB_PDB",6)) { fprintf(stderr, "This test only supported on HDF5 driver\n"); exit(1); } else if (!strncmp(argv[i], "DB_HDF5", 7)) { driver = StringToDriver(argv[i]); filename = "compression.h5"; } else if (!strcmp(argv[i], "compress")) { if ((i+1<argc) && ((ptr=strstr(argv[i+1], "METHOD=")) != NULL)) { DBSetCompression(argv[i+1]); i++; } else DBSetCompression("METHOD=GZIP"); } else if (!strcmp(argv[i], "szip")) { DBSetCompression("METHOD=SZIP"); } else if (!strcmp(argv[i], "gzip")) { DBSetCompression("METHOD=GZIP"); } else if (!strcmp(argv[i], "fpzip")) { DBSetCompression("METHOD=FPZIP"); } else if (!strcmp(argv[i], "single")) { usefloat = 1; } else if (!strcmp(argv[i], "verbose")) { verbose = 1; } else if (!strcmp(argv[i], "lossy1")) { DBSetCompression("METHOD=FPZIP LOSS=1"); has_loss = 1; } else if (!strcmp(argv[i], "lossy2")) { DBSetCompression("METHOD=FPZIP LOSS=2"); has_loss = 1; } else if (!strcmp(argv[i], "lossy3")) { DBSetCompression("METHOD=FPZIP LOSS=3"); has_loss = 1; } else if (!strcmp(argv[i], "minratio1000")) { DBSetCompression("ERRMODE=FAIL MINRATIO=1000 METHOD=FPZIP"); } else if (!strcmp(argv[i], "minratio1001")) { DBSetCompression("ERRMODE=FALLBACK MINRATIO=1000 METHOD=FPZIP"); } else if (!strcmp(argv[i], "readonly")) { readonly = 1; } else if (!strcmp(argv[i], "help")) { printf("Usage: %s [compress [\"METHOD=...\"]|single|verbose|readonly]\n",argv[0]); printf("Where: compress - enables compression, followed by compression information string\n"); printf(" default is compress \"METHOD=GZIP LEVEL=1\"\n"); printf(" single - writes data as floats not doubles\n"); printf(" verbose - displays more feedback\n"); printf(" readonly - checks an existing file (used for cross platform test)\n"); printf(" DB_HDF5 - enable HDF5 driver, the default\n"); return (0); } else if (!strcmp(argv[i], "show-all-errors")) { show_errors = DB_ALL_AND_DRVR; } else if (argv[i][0] != '\0') { fprintf(stderr, "%s: ignored argument `%s'\n", argv[0], argv[i]); } } /* get some temporary memory */ fval = (float*) malloc(ONE_MEG); frval = (float*) malloc(ONE_MEG); dval = (double*) malloc(ONE_MEG); drval = (double*) malloc(ONE_MEG); DBShowErrors(show_errors, 0); if (!readonly) { /* * Create a file that contains a simple variables. */ if (verbose) printf("Creating file: `%s'\n", filename); dbfile = DBCreate(filename, 0, DB_LOCAL, "Compression Test", driver); #if !defined(_WIN32) gettimeofday(&tim, NULL); t1=tim.tv_sec+(tim.tv_usec/1000000.0); #endif if (usefloat) { for (j = 0; j < INTERATE; j++) { if (verbose) if (j % 100 == 0) printf("Iterations %04d to %04d of %04d\n", j,j+100-1,INTERATE); sprintf(tmpname, "compression_%04d", j); for (i = 0; i < fdims[0]; i++) fval[i] = (float) fdims[0] * j + i; if (DBWrite(dbfile, tmpname, fval, fdims, ndims, DB_FLOAT) < 0) { nerrors++; break; } } } else { for (j = 0; j < INTERATE; j++) { if (verbose) if (j % 100 == 0) printf("Iterations %04d to %04d of %04d\n",j,j+100-1,INTERATE); sprintf(tmpname, "compression_%04d", j); for (i = 0; i < ddims[0]; i++) dval[i] = (double) ddims[0] * j + i; if (DBWrite(dbfile, tmpname, dval, ddims, ndims, DB_DOUBLE) < 0) { nerrors++; break; } } } #if !defined(_WIN32) gettimeofday(&tim, NULL); t2=tim.tv_sec+(tim.tv_usec/1000000.0); stat(filename, &buffer); fsize = buffer.st_size; printf("Write took %.6lf seconds and %.6g bytes/second\n", t2-t1,fsize/(t2-t1)); #endif DBClose(dbfile); } else { stat(filename, &buffer); fsize = buffer.st_size; } if (nerrors) return nerrors; /* * Now try opening the file again and verify the simple * variable. */ if (verbose) printf("Reopening `%s'\n", filename); dbfile = DBOpen(filename, driver, DB_READ); if (dbfile == 0) { printf("Unable to Open file for reading\n"); exit(1); } #if !defined(_WIN32) gettimeofday(&tim, NULL); t1=tim.tv_sec+(tim.tv_usec/1000000.0); #endif if (usefloat) { for (j = 0; j < INTERATE; j++) { if (verbose) if (j % 100 == 0) printf("Iterations %04d to %04d of %04d\n", j,j+100-1,INTERATE); sprintf(tmpname, "compression_%04d", j); if (DBReadVar(dbfile, tmpname, frval) < 0) { if (!has_loss) nerrors++; if (!has_loss && nerrors <= 10) printf("DBReadVar for \"%s\" failed\n", tmpname); if (!has_loss && nerrors == 10) printf("Further errors will be suppressed\n"); } for (i = 0; i < fdims[0]; i++) { fval[i] = (float) fdims[0] * j + i; if (fval[i] != frval[i]) { if (!has_loss) nerrors++; if (!has_loss && nerrors <= 10) printf("Read error in \"%s\" at position %04d. Expected %f, got %f\n", tmpname, i, fval[i], frval[i]); if (!has_loss && nerrors == 10) printf("Further errors will be suppressed\n"); break; } } } } else { for (j = 0; j < INTERATE; j++) { if (verbose) if (j % 100 == 0) printf("Iterations %04d to %04d of %04d\n",j,j+100-1,INTERATE); sprintf(tmpname, "compression_%04d", j); if (DBReadVar(dbfile, tmpname, drval) < 0) { if (!has_loss) nerrors++; if (!has_loss && nerrors <= 10) printf("DBReadVar for \"%s\" failed\n", tmpname); if (!has_loss && nerrors == 10) printf("Further errors will be suppressed\n"); } for (i = 0; i < ddims[0]; i++) { dval[i] = (double) ddims[0] * j + i; if (dval[i] != drval[i]) { if (!has_loss) nerrors++; if (!has_loss && nerrors <= 10) printf("Read error in \"%s\" at position %04d. Expected %f, got %f\n", tmpname, i, dval[i], drval[i]); if (!has_loss && nerrors == 10) printf("Further errors will be suppressed\n"); break; } } } } #if !defined(_WIN32) gettimeofday(&tim, NULL); t2=tim.tv_sec+(tim.tv_usec/1000000.0); printf("Read took %.6lf seconds and %.6g bytes/second\n", t2-t1,fsize/(t2-t1)); #endif DBClose(dbfile); free(fval); free(frval); free(dval); free(drval); CleanupDriverStuff(); return nerrors; }
int main(int argc, char *argv[]) { int i; DBfile *siloFile; /* set default values */ disableProgress = False; disableVerbose = False; /* initialization */ fBufSize = 0; dBufSize = 0; fBuf = NULL; dBuf = NULL; /* here's where we issue an error message if we have no isnan() test */ #ifndef HAVE_ISNAN fprintf(stderr,"silock cannot operate on this platform.\n"); fprintf(stderr,"No isnan() function was found during configure\n"); exit(-1); #endif /* process the command line */ for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-progress")) disableProgress = True; else if (!strcmp(argv[i], "-q")) disableVerbose = True; else if (!strcmp(argv[i], "-help")) { fprintf(stderr,"Scan a silo file for NaN/Inf floating point data\n"); fprintf(stderr,"Warning: As a precaution, you should use this tool\n"); fprintf(stderr," only on the same class of platform the\n"); fprintf(stderr," data was generated on.\n"); fprintf(stderr,"usage: silock [-q] [-progress]" " silofile\n"); fprintf(stderr,"available options...\n"); fprintf(stderr," -progress: Disable progress display\n"); fprintf(stderr," -q: Quiet. Report only if bad values\n"); fprintf(stderr," exist and exit on first occurence\n"); exit(-1); } else /* assume its a file and try to open it */ { struct stat stat_buf; strncpy(fileName, argv[i], sizeof(fileName)-1); if (stat(fileName, &stat_buf) != 0) { fprintf(stderr,"unrecognized option \"%s\". Use -help for usage\n", fileName); exit(-1); } totalBytes = stat_buf.st_size; } } /* initialize progress meter */ updateProgress(0); DBShowErrors(DB_NONE, NULL); siloFile = DBOpen(fileName, DB_UNKNOWN, DB_READ); if (siloFile == NULL) { fprintf(stderr, "unable to open silo file \"%s\"\n", fileName); exit(-1); } DBShowErrors(DB_TOP, NULL); if (DBGetDriverType(siloFile) == DB_HDF5 && !DBGuessHasFriendlyHDF5Names(siloFile)) { fprintf(stderr,"WARNING: This is an HDF5 file without \"Friendly\" HDF5 array names.\n"); fprintf(stderr,"WARNING: Consequently, while %s will be able to find/detect nans/infs,\n", strrchr(argv[0],'/')?strrchr(argv[0],'/')+1:argv[0]); fprintf(stderr,"WARNING: the names of the arrays in which it finds them will be cryptic.\n"); fprintf(stderr,"WARNING: You will most likely have to use h5ls/h5dump to determine which\n"); fprintf(stderr,"WARNING: Silo objects are involved.\n"); DBSetDir(siloFile, "/.silo"); scanSiloDir(siloFile, "/.silo"); } else { scanSiloDir(siloFile, "/"); } DBClose(siloFile); if (fBuf != NULL) free(fBuf); if (dBuf != NULL) free(dBuf); if (!disableProgress) printf("\n*** 100 %% completed ***\n"); if (!disableVerbose) printf("\n"); return 0; }
int rdsilogrid( void ) { char *me = "rdsilogrid"; char msg[MAXLINE]; char op[MAXLINE]; char name[MAXLINE]; int i; int gblk; int nlocaldom; int error; int *localdom; DBfile *idbid; Extents_t ext; geta(op); if (genmd != 1) { sprintf(msg, "Attempting to read silo mesh before memory has been allocated.\n\t\tAre you in merge phase?\n\t\t Did you forget the -sew on the command line?"); ctlerror(me,msg); } comlock(dmp_nbaton); idbid = DBOpen (op, DB_PDB, DB_READ); if (idbid == NULL) { sprintf(msg,"Cannot open silo file %s.\n",op); ctlerror(me,msg); } decomp_setdir(idbid); decomp_read(idbid, name, 0, 0); error = DBSetDir(idbid,"/"); DBShowErrors(DB_NONE, NULL); error = DBSetDir(idbid,"/Global/Nodelists"); if (error != 0) error = DBSetDir(idbid,"Nodelists"); if (error == 0) { NodeList_rdsilo(idbid,0); } DBShowErrors(DB_TOP, NULL); error = DBSetDir(idbid,"/"); nlocaldom = 0; localdom = MALLOT(int,gnblk); for (gblk = 0; gblk < gnblk; gblk++) { if (gmap[gblk].lblk >= 0) { localdom[nlocaldom++] = gblk; } } calculate_mappings(); for (i = 0; i < nlocaldom; i++) { gblk = localdom[i]; if (gmap[gblk].proc == myid) { sprintf(op,"/%s%i",name,i); error = DBSetDir(idbid,op); TRSEXT(domains[nblk],gmap[gblk],gmap[gblk]); if (ndims == 2) { domains[nblk].kmin = 0; domains[nblk].kmax = 0; domains[nblk].type = QUAD2D; } else { domains[nblk].type = HEX3D; } domains[nblk].sclnamix = sclnamix; initblk(nblk,&domains[nblk]); domains[nblk].gblk = gblk; domain_hash_tbl_rgst(&(domains[nblk])); CPYEXT(ext,domains[nblk]); rdsilomesh(idbid, "hydro_mesh", domains[nblk].x, domains[nblk].y, domains[nblk].z, domains[nblk].node, ext, domains[nblk].jp, domains[nblk].kp); nblk++; error = DBSetDir(idbid,"/"); } } FREEMEM(localdom); DBClose(idbid); comunlock(dmp_nbaton); if (ifparallel) { bndry_init(); initcom( NULL, 0); varcom_bufinit(); } return(0); }