bool SpeckleyNodes::writeToSilo(DBfile* dbfile) { #ifdef ESYS_HAVE_SILO if (numNodes == 0) return true; int ret; if (siloPath != "") { ret = DBSetDir(dbfile, siloPath.c_str()); if (ret != 0) return false; } string siloMeshName = getFullSiloName(); // Write node-centered variables ret = DBPutUcdvar1(dbfile, "Nodes_Id", siloMeshName.c_str(), (float*)&nodeID[0], numNodes, NULL, 0, DB_INT, DB_NODECENT, NULL); if (ret == 0) ret = DBPutUcdvar1(dbfile, "Nodes_Tag", siloMeshName.c_str(), (float*)&nodeTag[0], numNodes, NULL, 0, DB_INT, DB_NODECENT, NULL); DBSetDir(dbfile, "/"); return (ret == 0); #else // !ESYS_HAVE_SILO return false; #endif }
int rdparms(DBfile *idbid) { char *me = "rdparms"; char startdir[256]; int i, ndx; int *ints = NULL; double *doubles = NULL; char *chars = NULL, *str = NULL; DBcompoundarray *comparray; if (DBGetDir(idbid,startdir) != 0) ctlerror(me,gv_errmsg_DBGetDir); if (DBSetDir(idbid,"/Global/Parms") != 0) ctlerror(me,gv_errmsg_DBSetDir); comparray = DBGetCompoundarray(idbid, "int_parms"); if ( (comparray == NULL) || (comparray->datatype != DB_INT) ) { ctlerror(me,logic_err); } ints = (int *)comparray->values; for (i=0; i<comparray->nelems; i++) { if (comparray->elemlengths[i] != 1) { ctlerror(me,logic_err); } setparmi(comparray->elemnames[i],ints[i]); } DBFreeCompoundarray(comparray); comparray = DBGetCompoundarray(idbid, "double_parms"); if ( (comparray == NULL) || (comparray->datatype != DB_DOUBLE) ) { ctlerror(me,logic_err); } doubles = (double *)comparray->values; for (i=0; i<comparray->nelems; i++) { if (comparray->elemlengths[i] != 1) { ctlerror(me,logic_err); } setparmf(comparray->elemnames[i],doubles[i]); } DBFreeCompoundarray(comparray); comparray = DBGetCompoundarray(idbid, "char_parms"); if ( (comparray == NULL) || (comparray->datatype != DB_CHAR) ) { ctlerror(me,logic_err); } chars = (char *)comparray->values; ndx = 0; for (i=0; i<comparray->nelems; i++) { setparmc(comparray->elemnames[i], &(chars[ndx]) ); ndx = ndx + comparray->elemlengths[i]; } DBFreeCompoundarray(comparray); if (DBSetDir(idbid, startdir) != 0) ctlerror(me,gv_errmsg_DBSetDir); return(0); }
/*------------------------------------------------------------------------- * 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; }
/*------------------------------------------------------------------------- * Function: test_quadmesh * * Purpose: Tests reading and writing DBquadmesh objects. * * Return: Success: * * Failure: * * Programmer: Robb Matzke * Tuesday, March 30, 1999 * * Modifications: * *------------------------------------------------------------------------- */ static int test_quadmesh(DBfile *dbfile) { int nerrors=0; static int dims[] = {5, 5}; static float coords0[] = {0.11, 0.12, 0.13, 0.14, 0.15}; static float coords1[] = {0.21, 0.22, 0.23, 0.24, 0.25}; static float *coords[] = {coords0, coords1}; static double varA[] = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34}; static double varB[] = {35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59}; static double varC[] = {60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84}; static double *vars[] = {varA, varB, varC}; static char *varnames[] = {"varA", "varB", "varC"}; puts("=== Quadmesh ==="); DBMkDir(dbfile, "/quad"); DBSetDir(dbfile, "/quad"); if (DBPutQuadmesh(dbfile, "qm1", NULL, coords, dims, 2, DB_FLOAT, DB_COLLINEAR, NULL)<0) { puts("DBPutQuadmesh(qm1) failed"); nerrors++; } if (DBPutQuadvar(dbfile, "qv1", "qm1", 3, varnames, (float**)vars, dims, 2, NULL, 0, DB_DOUBLE, DB_NODECENT, NULL)<0) { puts("DBPutQuadmesh(qv1) failed"); nerrors++; } return nerrors; }
/*------------------------------------------------------------------------- * Function: test_curve * * Purpose: Tests reading and writing DBcurve objects. * * Return: Success: 0 * * Failure: number of errors * * Programmer: Robb Matzke * Tuesday, March 23, 1999 * * Modifications: * *------------------------------------------------------------------------- */ static int test_curve(DBfile *dbfile) { int nerrors = 0; static double xvals_d[] = { 1.1, 2.2, 3.3, 4.4, 5.5 }; static double yvals_d[] = {10.01, 20.02, 30.03, 40.04, 50.05}; puts("=== Curves ==="); DBMkDir(dbfile, "/curves"); DBSetDir(dbfile, "/curves"); /* Write an initial curve along with its X and Y arrays */ if (DBPutCurve(dbfile, "curve1", xvals_d, yvals_d, DB_DOUBLE, NELMTS(xvals_d), NULL)<0) { puts("DBPutCurve(curve1) failed"); nerrors++; } return nerrors; }
/*------------------------------------------------------------------------- * Function: build_dbfile * * Purpose: Make a multi-block mesh, multi-block variables, and a * multi-block material * * Return: Success: 0 * Failure: -1 * * Programmer: Jeremy Meredith, Sept 29, 1998 * * Modifications: * *------------------------------------------------------------------------*/ int build_dbfile(DBfile *dbfile) { /* multiblock data */ int nblocks_x=5; int nblocks_y=1; int nblocks = nblocks_x * nblocks_y; char *meshnames[MAXBLOCKS]; int meshtypes[MAXBLOCKS]; char names[7][MAXBLOCKS][STRLEN]; char *varnames[4][MAXBLOCKS]; int vartypes[MAXBLOCKS]; char *matnames[MAXBLOCKS]; char *specnames[MAXBLOCKS]; char dirnames[MAXBLOCKS][STRLEN]; char *meshname, *varname[4], *matname; /* mesh data */ int meshtype=DB_QUADMESH; int vartype=DB_QUADVAR; int coord_type=DB_NONCOLLINEAR; char *coordnames[3]; int ndims; int dims[3], zdims[3]; float *coords[3]; float x[(NX + 1) * (NY + 1)], y[(NX + 1) * (NY + 1)]; /* variables data */ float d[NX * NY], p[NX * NY], u[(NX + 1) * (NY + 1)], v[(NX + 1) * (NY + 1)]; int usespecmf=1; /* (multi)material data */ int nmats; int matnos[3]; int matlist[NX * NY]; /* (multi)species data */ char *specname; int speclist[NX*NY],speclist2[NX*NY]; float species_mf[NX*NY*5]; int nspecies_mf; int nmatspec[3]; /* time data */ int cycle; float time; double dtime; /* option list */ DBoptlist *optlist; /* internal data */ int i, j; float xave, yave; float xcenter, ycenter; float theta, dtheta; float r, dr; float dist; int block; int delta_x, delta_y; int base_x, base_y; int n_x, n_y; /* single block data */ float x2[(NX + 1) * (NY + 1)], y2[(NX + 1) * (NY + 1)]; float d2[NX * NY], p2[NX * NY], u2[(NX + 1) * (NY + 1)], v2[(NX + 1) * (NY + 1)]; int matlist2[NX * NY]; int dims2[3]; /* * Initialize the names and create the directories for the blocks. */ for (i = 0; i < nblocks; i++) { sprintf(names[6][i], "/block%d/mesh1", i); meshnames[i] = names[6][i]; meshtypes[i] = meshtype; sprintf(names[0][i], "/block%d/d", i); sprintf(names[1][i], "/block%d/p", i); sprintf(names[2][i], "/block%d/u", i); sprintf(names[3][i], "/block%d/v", i); varnames[0][i] = names[0][i]; varnames[1][i] = names[1][i]; varnames[2][i] = names[2][i]; varnames[3][i] = names[3][i]; vartypes[i] = vartype; sprintf(names[4][i], "/block%d/mat1", i); matnames[i] = names[4][i]; sprintf(names[5][i], "/block%d/species1",i); specnames[i]= names[5][i]; /* make the directory for the block mesh */ sprintf(dirnames[i], "/block%d", i); if (DBMkDir(dbfile, dirnames[i]) == -1) { fprintf(stderr, "Could not make directory \"%s\"\n", dirnames[i]); return (-1); } /* if */ } /* for */ /* * Initalize species info */ specname = "species1"; nmatspec[0]=3; nmatspec[1]=1; nmatspec[2]=2; /* * Initialize time info */ cycle = 48; time = 4.8; dtime = 4.8; /* * Create the mesh. */ meshname = "mesh1"; coordnames[0] = "xcoords"; coordnames[1] = "ycoords"; coordnames[2] = "zcoords"; coords[0] = x; coords[1] = y; ndims = 2; dims[0] = NX + 1; dims[1] = NY + 1; dtheta = (180. / NX) * (3.1415926 / 180.); dr = 3. / NY; theta = 0; for (i = 0; i < NX + 1; i++) { r = 2.; for (j = 0; j < NY + 1; j++) { x[j * (NX + 1) + i] = r * cos(theta); y[j * (NX + 1) + i] = r * sin(theta); r += dr; } theta += dtheta; } /* * Create the density and pressure arrays. */ varname[0] = "d"; varname[1] = "p"; xcenter = 0.; ycenter = 0.; zdims[0] = NX; zdims[1] = NY; for (i = 0; i < NX; i++) { for (j = 0; j < NY; j++) { xave = (x[(j) * (NX + 1) + i] + x[(j) * (NX + 1) + i + 1] + x[(j + 1) * (NX + 1) + i + 1] + x[(j + 1) * (NX + 1) + i]) / 4.; yave = (y[(j) * (NX + 1) + i] + y[(j) * (NX + 1) + i + 1] + y[(j + 1) * (NX + 1) + i + 1] + y[(j + 1) * (NX + 1) + i]) / 4.; dist = sqrt((xave - xcenter) * (xave - xcenter) + (yave - ycenter) * (yave - ycenter)); d[j * NX + i] = dist*((float)i/(float)NX); p[j * NX + i] = 1. / (dist + .0001); } } /* * Create the velocity component arrays. Note that the indexing * on the x and y coordinates is for rectilinear meshes. It * generates a nice vector field. */ varname[2] = "u"; varname[3] = "v"; xcenter = 0.; ycenter = 0.; for (i = 0; i < NX + 1; i++) { for (j = 0; j < NY + 1; j++) { dist = sqrt((x[i] - xcenter) * (x[i] - xcenter) + (y[j] - ycenter) * (y[j] - ycenter)); u[j * (NX + 1) + i] = (x[i] - xcenter) / dist; v[j * (NX + 1) + i] = (y[j] - ycenter) / dist; } } /* * Create the material array. */ matname = "mat1"; nmats = 3; matnos[0] = 1; matnos[1] = 2; matnos[2] = 3; dims2[0] = NX; dims2[1] = NY; /* * Put in the material in 3 shells. */ nspecies_mf=0; for (i = 0; i < NX; i++) { for (j = 0; j < 10; j++) { matlist[j * NX + i] = 1; speclist[j*NX+i]=nspecies_mf+1; if (i<10) { species_mf[nspecies_mf++]=.2; species_mf[nspecies_mf++]=.3; species_mf[nspecies_mf++]=.5; } else { species_mf[nspecies_mf++]=.9; species_mf[nspecies_mf++]=.1; species_mf[nspecies_mf++]=.0; } } for (j = 10; j < 20; j++) { matlist[j * NX + i] = 2; speclist[j*NX+i]=nspecies_mf+1; species_mf[nspecies_mf++]=1.; } for (j = 20; j < NY; j++) { matlist[j * NX + i] = 3; speclist[j*NX+i]=nspecies_mf+1; if (i<20) { species_mf[nspecies_mf++]=.3; species_mf[nspecies_mf++]=.7; } else { species_mf[nspecies_mf++]=.9; species_mf[nspecies_mf++]=.1; } } } delta_x = NX / nblocks_x; delta_y = NY / nblocks_y; coords[0] = x2; coords[1] = y2; dims[0] = delta_x + 1; dims[1] = delta_y + 1; zdims[0] = delta_x; zdims[1] = delta_y; dims2[0] = delta_x; dims2[1] = delta_y; /* * Create the blocks for the multi-block object. */ for (block = 0; block < nblocks_x * nblocks_y; block++) { fprintf(stdout, "\t%s\n", dirnames[block]); /* * Now extract the data for this block. */ base_x = (block % nblocks_x) * delta_x; base_y = (block / nblocks_x) * delta_y; for (j = 0, n_y = base_y; j < delta_y + 1; j++, n_y++) for (i = 0, n_x = base_x; i < delta_x + 1; i++, n_x++) { x2[j * (delta_x + 1) + i] = x[n_y * (NX + 1) + n_x]; y2[j * (delta_x + 1) + i] = y[n_y * (NX + 1) + n_x]; u2[j * (delta_x + 1) + i] = u[n_y * (NX + 1) + n_x]; v2[j * (delta_x + 1) + i] = v[n_y * (NX + 1) + n_x]; } for (j = 0, n_y = base_y; j < delta_y; j++, n_y++) for (i = 0, n_x = base_x; i < delta_x; i++, n_x++) { d2[j * delta_x + i] = d[n_y * NX + n_x]; p2[j * delta_x + i] = p[n_y * NX + n_x]; matlist2[j * delta_x + i] = matlist[n_y * NX + n_x]; speclist2[j*delta_x+i]=speclist[n_y*NX+n_x]; } if (DBSetDir(dbfile, dirnames[block]) == -1) { fprintf(stderr, "Could not set directory \"%s\"\n", dirnames[block]); return -1; } /* if */ /* Write out the variables. */ optlist = DBMakeOptlist(10); DBAddOption(optlist, DBOPT_CYCLE, &cycle); DBAddOption(optlist, DBOPT_TIME, &time); DBAddOption(optlist, DBOPT_DTIME, &dtime); DBAddOption(optlist, DBOPT_XLABEL, "X Axis"); DBAddOption(optlist, DBOPT_YLABEL, "Y Axis"); DBAddOption(optlist, DBOPT_XUNITS, "cm"); DBAddOption(optlist, DBOPT_YUNITS, "cm"); DBPutQuadmesh(dbfile, meshname, coordnames, coords, dims, ndims, DB_FLOAT, DB_NONCOLLINEAR, optlist); DBPutQuadvar1(dbfile, varname[2], meshname, u2, dims, ndims, NULL, 0, DB_FLOAT, DB_NODECENT, optlist); DBPutQuadvar1(dbfile, varname[3], meshname, v2, dims, ndims, NULL, 0, DB_FLOAT, DB_NODECENT, optlist); DBAddOption(optlist, DBOPT_USESPECMF, &usespecmf); DBPutQuadvar1(dbfile, varname[0], meshname, d2, zdims, ndims, NULL, 0, DB_FLOAT, DB_ZONECENT, optlist); DBPutQuadvar1(dbfile, varname[1], meshname, p2, zdims, ndims, NULL, 0, DB_FLOAT, DB_ZONECENT, optlist); DBPutMaterial(dbfile, matname, meshname, nmats, matnos, matlist2, dims2, ndims, NULL, NULL, NULL, NULL, 0, DB_FLOAT, optlist); DBPutMatspecies(dbfile, specname, matname, nmats, nmatspec, speclist2, dims2, ndims, nspecies_mf, species_mf, NULL, 0, DB_FLOAT, optlist); DBFreeOptlist(optlist); if (DBSetDir(dbfile, "..") == -1) { fprintf(stderr, "Could not return to base directory\n"); return -1; } /* if */ } /* for */ /* create the option lists for the multi-block calls. */ optlist = DBMakeOptlist(10); /* For all calls: */ DBAddOption(optlist, DBOPT_CYCLE, &cycle); DBAddOption(optlist, DBOPT_TIME, &time); DBAddOption(optlist, DBOPT_DTIME, &dtime); /* For multi-materials: */ DBAddOption(optlist, DBOPT_NMATNOS, &nmats); DBAddOption(optlist, DBOPT_MATNOS, matnos); /* For multi-species: */ DBAddOption(optlist, DBOPT_MATNAME, "mat1"); DBAddOption(optlist, DBOPT_NMAT, &nmats); DBAddOption(optlist, DBOPT_NMATSPEC, nmatspec); DBAddOption(optlist, DBOPT_SPECNAMES, species_names); DBAddOption(optlist, DBOPT_SPECCOLORS, speccolors); /* create the multi-block mesh */ if (DBPutMultimesh(dbfile, "mesh1", nblocks, meshnames, meshtypes, optlist) == -1) { DBFreeOptlist(optlist); fprintf(stderr, "Error creating multi mesh\n"); return (-1); } /* if */ /* create the multi-block variables */ if (DBPutMultivar(dbfile, "d", nblocks, varnames[0], vartypes, optlist) == -1) { DBFreeOptlist(optlist); fprintf(stderr, "Error creating multi var d\n"); return (-1); } /* if */ if (DBPutMultivar(dbfile, "p", nblocks, varnames[1], vartypes, optlist) == -1) { DBFreeOptlist(optlist); fprintf(stderr, "Error creating multi var p\n"); return (-1); } /* if */ if (DBPutMultivar(dbfile, "u", nblocks, varnames[2], vartypes, optlist) == -1) { DBFreeOptlist(optlist); fprintf(stderr, "Error creating multi var u\n"); return (-1); } /* if */ if (DBPutMultivar(dbfile, "v", nblocks, varnames[3], vartypes, optlist) == -1) { DBFreeOptlist(optlist); fprintf(stderr, "Error creating multi var v\n"); return (-1); } /* if */ /* create the multi-block material */ if (DBPutMultimat(dbfile, "mat1", nblocks, matnames, optlist) == -1) { DBFreeOptlist(optlist); fprintf(stderr, "Error creating multi material\n"); return (-1); } /* if */ /* create the multi-block species */ if (DBPutMultimatspecies(dbfile, "species1", nblocks, specnames, optlist) == -1) { DBFreeOptlist(optlist); fprintf(stderr, "Error creating multi species\n"); return (-1); } /* if */ DBFreeOptlist(optlist); return (0); }
// // Writes the data to given Silo file under the virtual path provided. // The corresponding mesh must have been written already. // bool DataVar::writeToSilo(DBfile* dbfile, const string& siloPath, const string& units) { #ifdef ESYS_HAVE_SILO if (!initialized) return false; if (numSamples == 0) return true; int ret; if (siloPath != "") { ret = DBSetDir(dbfile, siloPath.c_str()); if (ret != 0) return false; } char* siloMesh = const_cast<char*>(siloMeshName.c_str()); int dcenter = (centering == NODE_CENTERED ? DB_NODECENT : DB_ZONECENT); DBoptlist* optList = DBMakeOptlist(2); if (units.length()>0) { DBAddOption(optList, DBOPT_UNITS, (void*)units.c_str()); } if (rank == 0) { ret = DBPutUcdvar1(dbfile, varName.c_str(), siloMesh, dataArray[0], numSamples, NULL, 0, DB_FLOAT, dcenter, optList); } else if (rank == 1) { const string comps[3] = { varName+string("_x"), varName+string("_y"), varName+string("_z") }; const char* varnames[3] = { comps[0].c_str(), comps[1].c_str(), comps[2].c_str() }; ret = DBPutUcdvar(dbfile, varName.c_str(), siloMesh, shape[0], (char**)varnames, &dataArray[0], numSamples, NULL, 0, DB_FLOAT, dcenter, optList); } else { string tensorDir = varName+string("_comps/"); ret = DBMkdir(dbfile, tensorDir.c_str()); if (ret == 0) { int one = 1; DBAddOption(optList, DBOPT_HIDE_FROM_GUI, &one); for (int i=0; i<shape[1]; i++) { for (int j=0; j<shape[0]; j++) { ostringstream varname; varname << tensorDir << "a_" << i << j; ret = DBPutUcdvar1(dbfile, varname.str().c_str(), siloMesh, dataArray[i*shape[0]+j], numSamples, NULL, 0, DB_FLOAT, dcenter, optList); if (ret != 0) break; } if (ret != 0) break; } } // ret==0 } // rank DBFreeOptlist(optList); DBSetDir(dbfile, "/"); return (ret == 0); #else // !ESYS_HAVE_SILO return false; #endif }
/*------------------------------------------------------------------------- * Function: test_ucdmesh * * Purpose: Test unstructured mesh functions. * * Return: Success: 0 * * Failure: number of errors * * Programmer: Robb Matzke * Thursday, April 1, 1999 * * Modifications: * *------------------------------------------------------------------------- */ static int test_ucdmesh(DBfile *dbfile) { int nerrors = 0; static double coordA[] = {101, 102, 103, 104, 105}; static double coordB[] = {201, 202, 203, 204, 205}; static double coordC[] = {301, 302, 303, 304, 305}; static double *coords[] = {coordA, coordB, coordC}; static char *coordnames[] = {"coordA", "coordB", "coordC"}; static int nnodes = NELMTS(coordA); static int ndims = NELMTS(coords); static int nzones = 3; static float varA[] = {1, 2, 3, 4, 5, 6, 7, 8}; static float *vars[] = {varA}; static char *varnames[] = {"varA"}; static int nels = NELMTS(varA); static int nvars = NELMTS(vars); static float mixA[] = {0.1, 0.2, 0.3}; static float *mixvars[] = {mixA}; static int mixlen = NELMTS(mixA); static int nodelist[] = {500, 501, 502, 503, 504, 505, 506, 507}; static int lnodelist = NELMTS(nodelist); static int shapecnt[] = {1, 1, 2, 2, 3, 3, 4, 4, 5, 5}; static int shapesize[]= {5, 5, 4, 4, 3, 3, 2, 2, 1, 1}; static int nshapes = NELMTS(shapecnt); static int typelist[] = {99, 98, 97, 96, 95, 94}; static int ntypes = NELMTS(typelist); static int types[] = {193, 192, 191, 190, 189, 187, 186}; static int zoneno[] = {185, 184, 183, 182, 181, 180, 179}; static int nfaces = NELMTS(types); static int origin = 1; puts("=== Ucdmesh ==="); DBMkDir(dbfile, "/ucd"); DBSetDir(dbfile, "/ucd"); /* Mesh */ if (DBPutUcdmesh(dbfile, "um1", ndims, coordnames, (float**)coords, nnodes, nzones, "zl1", "fl1", DB_DOUBLE, NULL)<0) { puts("DBPutUcdmesh(um1) failed"); nerrors++; } if (DBPutUcdsubmesh(dbfile, "um2", "um1", nzones, "zl1", "fl1", NULL)<0) { puts("DBPutUcdsubmesh(um2) failed"); nerrors++; } /* Variable */ if (DBPutUcdvar(dbfile, "uv1", "um1", nvars, varnames, vars, nels, mixvars, mixlen, DB_FLOAT, DB_NODECENT, NULL)<0) { puts("DBPutUcdvar(uv1) failed"); nerrors++; } /* Facelist */ if (DBPutFacelist(dbfile, "fl1", nfaces, ndims, nodelist, lnodelist, origin, zoneno, shapesize, shapecnt, nshapes, types, typelist, ntypes)<0) { puts("DBPutFacelist(fl1) failed"); nerrors++; } /* Zonelist */ if (DBPutZonelist(dbfile, "zl1", nzones, ndims, nodelist, lnodelist, origin, shapesize, shapecnt, nshapes)<0) { puts("DBPutZonelist(zl1) failed"); nerrors++; } return nerrors; }
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); }
/* We examine all of Silo's data by traversing the all the "simple" arrays in the file. Ultimately, the data associated with all of Silo's abstract objects, excpet for object headers, is implemented in terms of simple arrays. This function finds all the simple arrays in the current dir and for each float or double array, reads it and examines it for NaNs. To avoid constantly allocating and freeing the buffers for arrays, we simply keep a growing buffer that grows to the largest array in the file and is freed only upon exit. We use Silo's non-allocating simple array read function. To make the loops for checking a NaN as fast as possible, we have two versions of the loop, one where progress is checked and one where progress is not checked. We first examine all the simple arrays in the current dir, then we loop over subdirs and recurse */ static void scanSiloDir(DBfile *siloFile, char *theDir) { char **dirNames; int i,nDirs,nObjects; DBtoc *toc; DBNewToc(siloFile); toc = DBGetToc(siloFile); if (toc == NULL) return ; nObjects = toc->nvar + toc->ndir; if (!nObjects) return ; /* process the simple arrays in this dir */ for (i = 0; i < toc->nvar; i++) { char *varName = toc->var_names[i]; int n = DBGetVarLength(siloFile, varName); int dbType = DBGetVarType(siloFile, varName); int j; if (!disableVerbose) { if (dbType == DB_FLOAT || dbType == DB_DOUBLE) printf("CHECKING array %-56s\r", varName); else printf("skipping array %-56s\r", varName); } /* for float arrays */ if (dbType == DB_FLOAT) { /* increase allocated buffer if necessary */ if (n*sizeof(float) > fBufSize) { if (fBuf != NULL) free(fBuf); fBuf = (float *) malloc(n * sizeof(float)); fBufSize = n; } DBReadVar(siloFile, varName, fBuf); if (disableProgress) { for (j = 0; j < n; j++) if (!IS_VALID_FLOAT(fBuf[j])) handleInvalidValue(theDir, varName, j, (double) fBuf[j]); } else { for (j = 0; j < n; j++) { if (!IS_VALID_FLOAT(fBuf[j])) handleInvalidValue(theDir, varName, j, (double) fBuf[j]); updateProgress(sizeof(float)); } } } /* for double arrays */ if (dbType == DB_DOUBLE) { /* increase allocated buffer if necessary */ if (n*sizeof(double) > dBufSize) { if (dBuf != NULL) free(dBuf); dBuf = (double *) malloc(n * sizeof(double)); dBufSize = n; } DBReadVar(siloFile, varName, dBuf); if (disableProgress) { for (j = 0; j < n; j++) if (!IS_VALID_DOUBLE(dBuf[j])) handleInvalidValue(theDir, varName, j, dBuf[j]); } else { for (j = 0; j < n; j++) { if (!IS_VALID_DOUBLE(dBuf[j])) handleInvalidValue(theDir, varName, j, dBuf[j]); updateProgress(sizeof(double)); } } } } /* for i */ /* save off the dir-stuff out of the toc so we don't loose it during the recursions */ nDirs = toc->ndir; dirNames = (char **) malloc(nDirs * sizeof(char*)); for (i = 0; i < nDirs; i++) { dirNames[i] = (char *) malloc(strlen(toc->dir_names[i])+1); strcpy(dirNames[i], toc->dir_names[i]); } /* recurse on any subdirs */ for (i = 0; i < nDirs; i++) { DBSetDir(siloFile, dirNames[i]); scanSiloDir(siloFile, dirNames[i]); DBSetDir(siloFile, ".."); free(dirNames[i]); } /* free the dir-stuff we set aside */ free(dirNames); }
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); }
int Restart_read_global(DBfile *idbid) { char *me = "Restart_read_global"; int ierr = 0, error = 0; int index, itest ; int i, j, k, n, gblk, irestart, num_ipas, num_fpas; int iblk,len2, length, nsplines; int numGroups, numSpec; int pdmdsav,npsave,nisave,nfsave,nppsave,ifthreadsave; char dirname[128], msg[256], pbnm_save[256], outstring[32]; int nhead[NHEAD_NUM]; int inttemp[100]; double doubtemp[100]; double myflops = 0.0; Stringnam_t *palistn; int *palistv; VersionData_t *file_ver; TimePlot_t *my_tpd; RGST_AttributeElem_t *func; FT_INITIALIZE(me, gv_hash_tbl) genmd = 0 ; pdmdsav = pdmd ; strcpy(pbnm_save,pbnm); if (DBSetDir(idbid, "/Global") != 0) ctlerror(me,gv_errmsg_DBSetDir); file_ver = rgst_read_struct_in_dir(idbid,"Version","VersionData_t",NULL,NULL); if (file_ver == NULL) ctlerror(me,gv_errmsg_rgst_read_struct_in_dir); if (strcmp(file_ver->dump_version,VER_DUMP) != 0) { sprintf(msg,"Dump version %s may be incompatible with current version %s", file_ver->dump_version,VER_DUMP); ctlnotice(me,msg); } VersionData_destruct(file_ver); if (DBReadVar(idbid, "nhead", nhead) != 0) ctlerror(me,gv_errmsg_DBReadVar); ifthreadsave = ifthreads; ierr = rdparms(idbid); if (ierr != 0) { ctlwarning(me,"rdparms failed"); } ifthreads = ifthreadsave; pdmd = pdmdsav ; strcpy(pbnm,pbnm_save); memexp(); DBShowErrors(DB_NONE, NULL); ierr = DBSetDir(idbid,"Nodelists"); if (ierr == 0) { NodeList_rdsilo(idbid,0); ierr = DBSetDir(idbid,"../"); } DBShowErrors(DB_TOP, NULL); DBShowErrors(DB_NONE, NULL); ierr = DBSetDir(idbid,"Tracers"); if (ierr == 0) { ierr = DBSetDir(idbid,"../"); } DBShowErrors(DB_TOP, NULL); DBShowErrors(DB_NONE, NULL); ierr = DBSetDir(idbid,"Probes"); if (ierr == 0) { ierr = DBSetDir(idbid,"../"); } DBShowErrors(DB_TOP, NULL); conditionals_rdsilo(idbid); TimeStepControl_rdsilo(idbid); if (DBSetDir(idbid, "/Global") != 0) ctlerror(me,gv_errmsg_DBSetDir); FunctionTimer_rdsilo(idbid, gv_hash_tbl); spline_rdsilo(idbid); UserList_rdsilo(idbid); func = rgst_list_attr(A_OBJECT, "Function_ReadSilo"); while (func != NULL) { Command_t *cp = (Command_t *) func->rgst_obj->obj; (*(cp->proc))(idbid); func = func->next; } num_ipas = nhead[NHEAD_NUM_IPA]; num_fpas = nhead[NHEAD_NUM_FPA]; n = MAX(num_ipas, num_fpas); if ( n > 0 ) { palistn = ALLOT(Stringnam_t, n); palistv = ALLOT(int, n); }
void perform_write( hpx::lcos::local::channel<void>& sync , octree_server& e , DBfile* file , std::vector<std::string> const& directory_names , std::string const& variable_name , boost::uint64_t variable_index ) { // {{{ boost::uint64_t const bw = science().ghost_zone_length; boost::uint64_t const gnx = config().grid_node_length; boost::uint64_t level = e.get_level(); int nnodes[] = { int(gnx - 2 * bw + 1) , int(gnx - 2 * bw + 1) , int(gnx - 2 * bw + 1) }; int nzones[] = { int(gnx - 2 * bw) , int(gnx - 2 * bw) , int(gnx - 2 * bw) }; //char* coordinate_names[] = { (char*) "X", (char*) "Y", (char*) "Z" }; boost::scoped_array<double*> coordinates(new double* [3]); coordinates[0] = new double [nnodes[0]]; coordinates[1] = new double [nnodes[1]]; coordinates[2] = new double [nnodes[2]]; boost::scoped_array<double> variables (new double [nzones[0] * nzones[1] * nzones[2]]); for (boost::uint64_t i = bw; i < (gnx - bw + 1); ++i) { coordinates[0][i - bw] = e.x_face(i); coordinates[1][i - bw] = e.y_face(i); coordinates[2][i - bw] = e.z_face(i); } for (boost::uint64_t i = bw; i < (gnx - bw); ++i) for (boost::uint64_t j = bw; j < (gnx - bw); ++j) for (boost::uint64_t k = bw; k < (gnx - bw); ++k) { boost::uint64_t index = (i - bw) + (j - bw) * nzones[0] + (k - bw) * nzones[0] * nzones[1]; variables[index] = e(i, j, k)[variable_index]; } array<boost::uint64_t, 3> location = e.get_location(); std::string mesh_name = boost::str( boost::format("mesh_L%i_%i_%i_%i") % level % location[0] % location[1] % location[2]); std::string value_name = boost::str( boost::format("%s_L%i_%i_%i_%i") % variable_name % level % location[0] % location[1] % location[2]); int error = DBSetDir(file, directory_names[level].c_str()); OCTOPUS_ASSERT(error == 0); { DBoptlist* optlist = DBMakeOptlist(1); // REVIEW: Verify this. int type = DB_ROWMAJOR; DBAddOption(optlist, DBOPT_MAJORORDER, &type); error = DBPutQuadmesh(file , mesh_name.c_str() //, coordinate_names , NULL // SILO docs say this is ignored. , coordinates.get() , nnodes , 3, DB_DOUBLE, DB_COLLINEAR, optlist); OCTOPUS_ASSERT(error == 0); } { DBoptlist* optlist = DBMakeOptlist(3); // REVIEW: Verify this. int type = DB_ROWMAJOR; DBAddOption(optlist, DBOPT_MAJORORDER, &type); error = DBPutQuadvar1(file , value_name.c_str() , mesh_name.c_str() , variables.get() , nzones , 3, NULL, 0, DB_DOUBLE, DB_ZONECENT, optlist); OCTOPUS_ASSERT(error == 0); } delete[] coordinates[0]; delete[] coordinates[1]; delete[] coordinates[2]; sync.post(); } // }}}
void perform_merge( hpx::lcos::local::channel<void>& sync , DBfile* file , std::vector<std::string> const& directory_names , std::string const& variable_name , boost::uint64_t& step , double& time ) { // {{{ for (boost::uint64_t level = 0; level < directory_names.size(); ++level) { int error = DBSetDir(file, directory_names[level].c_str()); OCTOPUS_ASSERT(error == 0); // Get a list of all the meshes and variables in that directory. DBtoc* contents = DBGetToc(file); // Make the mesh and variable names. boost::ptr_vector<char> mesh_names(contents->nqmesh); boost::ptr_vector<char> variable_names(contents->nqmesh); double grid_dim = config().spatial_domain; for (boost::uint64_t i = 1; i < level; ++i) grid_dim *= 0.5; for (boost::uint64_t j = 0; j < boost::uint64_t(contents->nqmesh); ++j) { std::string tmp; /////////////////////////////////////////////////////////////////// tmp = directory_names[level]; tmp += "/"; tmp += contents->qmesh_names[j]; // The extra character is for the terminating byte. mesh_names.push_back(new char[tmp.size() + 1]); std::strcpy(&mesh_names[j], tmp.c_str()); /////////////////////////////////////////////////////////////////// tmp = directory_names[level]; tmp += "/"; tmp += contents->qvar_names[j]; // The extra character is for the terminating byte. variable_names.push_back(new char[tmp.size() + 1]); std::strcpy(&variable_names[j], tmp.c_str()); } // when we change directories below, "contents" will go out of scope boost::uint64_t nqmesh = contents->nqmesh; error = DBSetDir(file, "/"); OCTOPUS_ASSERT(error == 0); std::string multi_mesh_name = boost::str( boost::format("mesh_level_%1%") % level); std::string multi_variable_name = boost::str( boost::format("%1%_level_%2%") % variable_name % level); { DBoptlist* optlist = DBMakeOptlist(4); DBObjectType type1 = DB_QUADRECT; DBAddOption(optlist, DBOPT_MB_BLOCK_TYPE, &type1); DBAddOption(optlist, DBOPT_CYCLE, &step); DBAddOption(optlist, DBOPT_DTIME, &time); error = DBPutMultimesh(file , multi_mesh_name.c_str() , nqmesh , mesh_names.c_array() , NULL, optlist); OCTOPUS_ASSERT(error == 0); } { DBoptlist* optlist = DBMakeOptlist(4); DBObjectType type1 = DB_QUADVAR; DBAddOption(optlist, DBOPT_MB_BLOCK_TYPE, &type1); DBAddOption(optlist, DBOPT_CYCLE, &step); DBAddOption(optlist, DBOPT_DTIME, &time); int type2 = DB_ROWMAJOR; DBAddOption(optlist, DBOPT_MAJORORDER, &type2); error = DBPutMultivar(file , multi_variable_name.c_str() , nqmesh , variable_names.c_array() , NULL, optlist); OCTOPUS_ASSERT(error == 0); } } sync.post(); } // }}}
bool SpeckleyElements::writeToSilo(DBfile* dbfile, const string& siloPath, const StringVec& labels, const StringVec& units, bool writeMeshData) { #ifdef ESYS_HAVE_SILO if (numElements == 0) return true; int ret; if (siloPath != "") { ret = DBSetDir(dbfile, siloPath.c_str()); if (ret != 0) return false; } // write out the full mesh in any case nodeMesh->setSiloPath(siloPath); string siloMeshNameStr = nodeMesh->getFullSiloName(); const char* siloMeshName = siloMeshNameStr.c_str(); int arraylen = numElements * nodesPerElement; int eltype = toSiloElementType(type); string varName = name + string("_zones"); ret = DBPutZonelist2(dbfile, varName.c_str(), numElements, nodeMesh->getNumDims(), &nodes[0], arraylen, 0, 0, numGhostElements, &eltype, &nodesPerElement, &numElements, 1, NULL); if (ret == 0) { CoordArray& coordbase = const_cast<CoordArray&>(nodeMesh->getCoords()); DBoptlist* optList = NULL; int nOpts = labels.size()+units.size(); if (nOpts>0) { optList = DBMakeOptlist(nOpts); if (labels.size()>0) DBAddOption(optList, DBOPT_XLABEL, (void*)labels[0].c_str()); if (labels.size()>1) DBAddOption(optList, DBOPT_YLABEL, (void*)labels[1].c_str()); if (labels.size()>2) DBAddOption(optList, DBOPT_ZLABEL, (void*)labels[2].c_str()); if (units.size()>0) DBAddOption(optList, DBOPT_XUNITS, (void*)units[0].c_str()); if (units.size()>1) DBAddOption(optList, DBOPT_YUNITS, (void*)units[1].c_str()); if (units.size()>2) DBAddOption(optList, DBOPT_ZUNITS, (void*)units[2].c_str()); } ret = DBPutUcdmesh(dbfile, siloMeshName, nodeMesh->getNumDims(), NULL, &coordbase[0], nodeMesh->getNumNodes(), numElements, varName.c_str(), /*"facelist"*/NULL, DB_FLOAT, optList); if (optList) DBFreeOptlist(optList); } if (ret != 0) return false; // write out the element-centered variables if enabled if (writeMeshData) { varName = name + string("_Id"); ret = DBPutUcdvar1(dbfile, varName.c_str(), siloMeshName, (float*)&ID[0], numElements, NULL, 0, DB_INT, DB_ZONECENT, NULL); if (ret == 0) { varName = name + string("_Owner"); ret = DBPutUcdvar1(dbfile, varName.c_str(), siloMeshName, (float*)&owner[0], numElements, NULL, 0, DB_INT, DB_ZONECENT, NULL); } } // "Elements" is a special case if (writeMeshData && name == "Elements") { nodeMesh->writeToSilo(dbfile); } return (ret == 0); #else // !ESYS_HAVE_SILO return false; #endif }
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: test_dirs * * Purpose: Test directory operations * * Return: Success: 0 * * Failure: number of errors * * Programmer: Robb Matzke * Wednesday, February 10, 1999 * * Modifications: * Robb Matzke, 2000-01-12 * Changed hyphens to underscores in object names because silo * now fails when underscores are present in the name. *------------------------------------------------------------------------- */ static int test_dirs(DBfile *dbfile) { int nerrors=0; char curdir[1024]; static int in[1]={911}, value[1]={0}; static int dims[1]={1}; puts("=== Directories ==="); /* Make some directories */ if (DBMkDir(dbfile, "dir1")<0) { puts("DBMkDir(dir1) failed"); nerrors++; } if (DBMkDir(dbfile, "dir1/d1a")<0) { puts("DBMkDir(dir1/d1a) failed"); nerrors++; } if (DBMkDir(dbfile, "/dir1/d1b")<0) { puts("DBMkDir(dir1/d1b) failed"); nerrors++; } if (DBMkDir(dbfile, "/dir1/d1c/")<0) { puts("DBMkDir(dir1/d1c) failed"); nerrors++; } if (DBMkdir(dbfile, "//dir2//")<0) { puts("DBMkDir(dir2) failed"); nerrors++; } /* Set the CWD to /dir1/d1c and write a variable */ if (DBSetDir(dbfile, "//dir1//d1c//")<0) { puts("DBSetDir(/dir1/d1c) failed"); nerrors++; } if (DBWrite(dbfile, "d1c_A", value, dims, 1, DB_INT)<0) { puts("DBWrite(d1c_A) failed"); nerrors++; } if (DBGetDir(dbfile, curdir)<0 || strcmp(curdir, "/dir1/d1c")) { puts("DBGetDir() failed"); nerrors++; } if (DBReadVar(dbfile, "../d1c/..//..////dir1/d1c//d1c_A", in)<0 || in[0]!=value[0]) { puts("DBReadVar(d1c_A) failed"); nerrors++; } /* Test table of contents */ if (NULL==DBGetToc(dbfile)) { puts("DBGetToc() failed"); nerrors++; } /* Set CWD to top */ if (DBSetDir(dbfile, "/")<0) { puts("DBSetDir(/) failed"); nerrors++; } if (DBGetDir(dbfile, curdir)<0 || strcmp(curdir, "/")) { puts("DBetDir() failed"); nerrors++; } 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; }
virtual void WriteBoundariesFile(const int *divisions, const double *extents) { std::string filename(BoundariesFile()); DBfile *dbfile = DBCreate(filename.c_str(), DB_CLOBBER, DB_LOCAL, "3D point mesh domain boundaries", DB_HDF5); if(dbfile == NULL) { fprintf(stderr, "Could not create Silo file!\n"); return; } double deltaX = (extents[1] - extents[0]) / double(divisions[0]); double deltaY = (extents[3] - extents[2]) / double(divisions[1]); double deltaZ = (extents[5] - extents[4]) / double(divisions[2]); char domname[30]; double z0 = extents[4]; int dom = 0; std::vector<std::string> names; int nDomains = divisions[0]*divisions[1]*divisions[2]; char **varnames = new char *[nDomains]; int *vartypes = new int[nDomains]; for(int dz = 0; dz < divisions[2]; ++dz) { double y0 = extents[2]; for(int dy = 0; dy < divisions[1]; ++dy) { double x0 = extents[0]; for(int dx = 0; dx < divisions[0]; ++dx, ++dom) { sprintf(domname, "domain%d", dom); DBMkDir(dbfile, domname); DBSetDir(dbfile, domname); sprintf(domname, "domain%d/bounds", dom); names.push_back(domname); varnames[dom] = (char *)names[dom].c_str(); vartypes[dom] = DB_QUADMESH; double thisExtents[6]; thisExtents[0] = x0 + (dx) * deltaX; thisExtents[1] = x0 + (dx+1) * deltaX; thisExtents[2] = y0 + (dy) * deltaX; thisExtents[3] = y0 + (dy+1) * deltaY; thisExtents[4] = z0 + (dz) * deltaZ; thisExtents[5] = z0 + (dz+1) * deltaZ; // Create a simple mesh that shows this domain's boundaries. const int nvals = 4; double x[nvals]; double y[nvals]; double z[nvals]; for(int i = 0; i < nvals; ++i) { double t = double(i) / double(nvals-1); x[i] = (1.-t)*thisExtents[0] + t*thisExtents[1]; y[i] = (1.-t)*thisExtents[2] + t*thisExtents[3]; z[i] = (1.-t)*thisExtents[4] + t*thisExtents[5]; } int dims[3] = {nvals, nvals, nvals}; int ndims = 3; float *coords[3]; coords[0] = (float*)x; coords[1] = (float*)y; coords[2] = (float*)z; DBPutQuadmesh(dbfile, "bounds", NULL, coords, dims, ndims, DB_DOUBLE, DB_COLLINEAR, NULL); DBSetDir(dbfile, ".."); } } } DBPutMultimesh(dbfile, "bounds", nDomains, varnames, vartypes, NULL); delete [] varnames; delete [] vartypes; DBClose(dbfile); }