static int ProcessArgs_silo(int argc, char *argv[]) { int i,n,nerrors=0; for (i=1; i<argc; i++) { errno=0; if (!strcmp(argv[i], "--driver")) { i++; if (!strcmp(argv[i], "DB_HDF5")) driver = DB_HDF5; else if (!strcmp(argv[i], "DB_HDF5_SEC2")) driver = DB_HDF5_SEC2; else if (!strcmp(argv[i], "DB_HDF5_STDIO")) driver = DB_HDF5_STDIO; else if (!strcmp(argv[i], "DB_HDF5_CORE")) { int meminc = i<argc-1?strtol(argv[i+1], (char **)NULL, 10):0; if (errno==0 && meminc>0) { i++; } else { errno = 0; meminc = 512; } driver = (meminc<<11)|DB_HDF5_STDIO; } else if (!strcmp(argv[i], "DB_PDB")) driver = DB_PDB; else goto fail; } else if (!strcmp(argv[i], "--checksums")) { DBSetEnableChecksums(1); } else if (!strcmp(argv[i], "--hdf5friendly")) { DBSetFriendlyHDF5Names(1); } else if (!strcmp(argv[i], "--compression")) { char compstr[256]; i++; sprintf(compstr, "METHOD=%s", argv[i]); DBSetCompression(compstr); } } return 0; fail: fprintf(stderr, "%s: bad argument `%s' (\"%s\")\n", argv[0], argv[i], errno?strerror(errno):""); return 1; }
int main(int argc, char **argv) { float x[1000],y[1000],z[1000]; float *coords[3]; int nodelist[2000]; int zoneno[1000]; int shapetype[1] = {DB_ZONETYPE_BEAM}; int shapesize[1] = {2}; int shapecnt[1]; /* fill this in later after we count the zones */ int nzones = 0; int nnodes = 0; int l; float zval[1000]; float nval[1000]; DBfile *db; int i,j, driver = DB_PDB, reorder = 0, friendly = 0; char *filename = "ucd1d.pdb"; int show_all_errors = FALSE; for (i=1; i<argc; i++) { if (!strncmp(argv[i], "DB_PDB", 6)) { driver = StringToDriver(argv[i]); filename = "ucd1d.pdb"; } else if (!strncmp(argv[i], "DB_HDF5", 7)) { driver = StringToDriver(argv[i]); filename = "ucd1d.h5"; } else if (!strcmp(argv[i], "reorder")) { reorder = 1; } else if (!strcmp(argv[i], "friendly")) { friendly = 1; } 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]); } } if (show_all_errors) DBShowErrors(DB_ALL_AND_DRVR, 0); /* Create the coordinate arrays and the nodal variable */ for (i=0; i<30; i++) { for (j=0; j<=30; j++) { x[i*31+j] = (float)i-14.5; y[i*31+j] = sin(2*M_PI*(float)j/30)*5; z[i*31+j] = cos(2*M_PI*(float)j/30)*5; nval[nnodes] = sqrt(x[i*31+j]*x[i*31+j]*.2 + y[i*31+j]*y[i*31+j]*.5 + z[i*31+j]*z[i*31+j]*1.); nnodes++; } } if (reorder) { float tmp = nval[0]; nval[0] = nval[1]; nval[1] = tmp; } coords[0]=x; coords[1]=y; coords[2]=z; /* Create the connectivity arrays and teh zonal variable */ l=0; for (i=0; i<30; i++) { for (j=0; j<30; j++) { if (! (abs(i-j)<5 || abs(i-j+30)<5 || abs(i-j-30)<5)) { nodelist[l++] = (i*31 + j); nodelist[l++] = (i*31 + j+1); zoneno[nzones]=nzones; zval[nzones] = i+j; nzones++; } } } if (reorder) { float tmp = zval[nzones-1]; zval[nzones-1] = zval[nzones-2]; zval[nzones-2] = tmp; } shapecnt[0] = nzones; if (friendly && (driver&0xF) == DB_HDF5) DBSetFriendlyHDF5Names(1); /* Write out the mesh */ printf("Creating test file: \"%s\".\n", filename); db = DBCreate(filename, DB_CLOBBER, DB_LOCAL, "UCD mesh test", driver); DBPutUcdmesh(db,"mesh",3, NULL, coords, nnodes, nzones, NULL, "fl", DB_FLOAT, NULL); DBPutFacelist(db,"fl",nzones,3, nodelist,l, 0, zoneno, shapesize,shapecnt, 1, NULL,NULL,0); if (reorder) { DBPutUcdvar1(db, "nval", "mesh", nval, nnodes, NULL,0, DB_FLOAT, DB_NODECENT, NULL); DBPutUcdvar1(db, "zval", "mesh", zval, nzones, NULL,0, DB_FLOAT, DB_ZONECENT, NULL); } else { DBPutUcdvar1(db, "zval", "mesh", zval, nzones, NULL,0, DB_FLOAT, DB_ZONECENT, NULL); DBPutUcdvar1(db, "nval", "mesh", nval, nnodes, NULL,0, DB_FLOAT, DB_NODECENT, NULL); } DBClose(db); CleanupDriverStuff(); return(0); }
int main(int argc, char *argv[]) { int nnodes = NNODES; int nzones = NZONES; int nodelist[23]; int shapesize[] = {8, 4, 5, 6}; int shapecnt[] = {1, 1, 1, 1}; char mesh_command[256]; int len; char *filename = "alltypes.silo"; int driver = DB_PDB; DBfile *dbfile = NULL; int ndims = NDIMS; int dims[NDIMS]; double *coords[NDIMS]; double x[NNODES]; double y[NNODES]; double z[NNODES]; DBfacelist *facelist = NULL; double nodal[NNODES]; double zonal[NZONES]; int matlist[NZONES]; int mats[] = {1,2,3,4}; int i,j; const int origin = 0; int show_all_errors = FALSE; /* Parse command-line options */ for (i=1; i<argc; i++) { if (!strncmp(argv[i], "DB_PDB",6)) { driver = StringToDriver(argv[i]); filename = "alltypes.pdb"; } else if (!strncmp(argv[i], "DB_HDF5", 7)) { driver = StringToDriver(argv[i]); filename = "alltypes.h5"; } else if (!strcmp(argv[i], "show-all-errors")) { show_all_errors = 1; } else if (argv[i][0] != '\0') { fprintf(stderr, "unknown option: %s\n", argv[i]); exit(1); } } /* Turn on error handling */ DBShowErrors(show_all_errors?DB_ALL_AND_DRVR:DB_ABORT, NULL); DBSetFriendlyHDF5Names(2); /* Create file */ printf("Creating test file \"%s\".\n", filename); dbfile = DBCreate(filename, DB_CLOBBER, DB_LOCAL, "3D ucd", driver); i = 0; /* 0 */ x[i] = 0.5; y[i] = 1.0; z[i++] = 0.0; /* 1 */ x[i] = 1.5; y[i] = 1.0; z[i++] = 0.0; /* 2 */ x[i] = 1.5; y[i] = 1.0; z[i++] = 1.0; /* 3 */ x[i] = 0.5; y[i] = 1.0; z[i++] = 1.0; /* 4 */ x[i] = 0.5; y[i] = 2.0; z[i++] = 0.0; /* 5 */ x[i] = 1.5; y[i] = 2.0; z[i++] = 0.0; /* 6 */ x[i] = 2.5; y[i] = 2.0; z[i++] = 0.0; /* 7 */ x[i] = 2.5; y[i] = 2.0; z[i++] = 1.0; /* 8 */ x[i] = 1.5; y[i] = 2.0; z[i++] = 1.0; /* 9 */ x[i] = 0.5; y[i] = 2.0; z[i++] = 1.0; /* 10 */ x[i] = 0.0; y[i] = 3.0; z[i++] = 0.5; /* 11 */ x[i] = 1.0; y[i] = 3.0; z[i++] = 0.5; /* 12 */ x[i] = 2.0; y[i] = 3.0; z[i++] = 0.5; coords[0] = x; coords[1] = y; coords[2] = z; DBPutUcdmesh(dbfile, "mesh", 3, NULL, (void *)coords, nnodes, nzones, "zonelist", "facelist", DB_DOUBLE, NULL); i = 0; /* Hex */ nodelist[i++] = 4; nodelist[i++] = 5; nodelist[i++] = 8; nodelist[i++] = 9; nodelist[i++] = 0; nodelist[i++] = 1; nodelist[i++] = 2; nodelist[i++] = 3; /* Tet */ nodelist[i++] = 10; nodelist[i++] = 4; nodelist[i++] = 11; nodelist[i++] = 9; /* Pyramid */ nodelist[i++] = 4; nodelist[i++] = 5; nodelist[i++] = 8; nodelist[i++] = 9; nodelist[i++] = 11; /* Prism */ nodelist[i++] = 5; nodelist[i++] = 6; nodelist[i++] = 7; nodelist[i++] = 8; nodelist[i++] = 11; nodelist[i++] = 12; for (j=0; j<i; j++) nodelist[j] += origin; DBSetDeprecateWarnings(0); DBPutZonelist(dbfile, "zonelist", nzones, ndims, nodelist, 23, origin, shapesize, shapecnt, 4); DBSetDeprecateWarnings(3); facelist = DBCalcExternalFacelist(nodelist, nnodes, origin, shapesize, shapecnt, 4, NULL, 0); DBPutFacelist(dbfile, "facelist", facelist->nfaces, facelist->ndims, facelist->nodelist, facelist->lnodelist, facelist->origin, facelist->zoneno, facelist->shapesize, facelist->shapecnt, facelist->nshapes, facelist->types, facelist->typelist, facelist->ntypes); for(i=0;i<nnodes;i++) nodal[i] = x[i]; zonal[0] = 4.0; zonal[1] = 2.0; zonal[2] = 0.0; zonal[3] = 7.0; DBPutUcdvar1(dbfile, "nodal", "mesh", (void*)nodal, nnodes, NULL, 0, DB_DOUBLE, DB_NODECENT, NULL); DBPutUcdvar1(dbfile, "zonal", "mesh", (void*)zonal, nzones, NULL, 0, DB_DOUBLE, DB_ZONECENT, NULL); matlist[0] = 1; matlist[1] = 2; matlist[2] = 3; matlist[3] = 4; dims[0] = nzones; DBPutMaterial(dbfile, "mat", "mesh", 4, mats, matlist, dims, 1, NULL, NULL, NULL, NULL, 0, DB_DOUBLE, NULL); sprintf(mesh_command, "mesh mesh"); len = strlen(mesh_command) + 1; DBWrite(dbfile, "_meshtvinfo", mesh_command, &len, 1, DB_CHAR); DBClose(dbfile); DBFreeFacelist(facelist); CleanupDriverStuff(); return 0; }