Example #1
0
/*-------------------------------------------------------------------------
 * Function:    main
 *
 * Purpose:     Test various issues in interactions with underlying
 *              filesystem
 *
 * Return:      0
 *
 * Programmer:  Mark C. Miller, Wed Aug 29 11:07:16 PDT 2012
 *-------------------------------------------------------------------------
 */
int main(int argc, char *argv[])
{
    int            i, driver = DB_PDB;
    int            show_all_errors = FALSE;
    DBfile        *dbfile;

    for (i=1; i<argc; i++) {
        if (!strncmp(argv[i], "DB_PDB",6)) {
            driver = StringToDriver(argv[i]);
        } else if (!strncmp(argv[i], "DB_HDF5", 7)) {
            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]);
        }
    }
    
    DBShowErrors(show_all_errors?DB_ALL_AND_DRVR:DB_NONE, NULL);

    /* Test opening a file in a non-existent directory */
    {
        char *filename = "testfs_dir/testfs.silo";
        dbfile = DBCreate(filename, 0, DB_LOCAL, "filesytem tests", driver);
        assert(!dbfile);
    }

    CleanupDriverStuff();
    return 0;
}
Example #2
0
/***********************************************************************
 *  Program
 *
 *      ucdsamp3
 *
 *  Purpose
 *
 *      Sample program illustrating use of SILO for writing 3D
 *      unstructured cell data.
 *
 *  Modifications
 *
 * 	Robb Matzke, 1999-04-09
 *	Added argument parsing to control the driver which is used.
 ***********************************************************************/
int
main(int argc, char *argv[])
{
    DBfile        *dbfile;
    int		  i, driver=DB_PDB;
    char	  *filename="ucdsamp3.pdb";
    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 = "ucdsamp3.pdb";
	} else if (!strncmp(argv[i], "DB_HDF5", 7)) {
            driver = StringToDriver(argv[i]);
	    filename = "ucdsamp3.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_ALL, NULL);

    dbfile = DBCreate(filename, 0, DB_LOCAL, "ucd test file", driver);
    printf("Creating file: '%s'...\n", filename);
    build_ucd3(dbfile, "mesh1");
    DBClose(dbfile);

    CleanupDriverStuff();
    exit(0);
}
Example #3
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;
}
/*--------------------*/
int main(int argc, char **argv) {
    DBfile *db;
    int            i, driver = DB_PDB;
    char          *filename = "csg.pdb";
    int            show_all_errors = FALSE;
    char  *coordnames[3];
    float *coord[3];

    for (i=1; i<argc; i++) {
        if (!strncmp(argv[i], "DB_PDB",6)) {
            driver = StringToDriver(argv[i]);
            filename = "mat3d_3across.pdb";
        } else if (!strncmp(argv[i], "DB_HDF5", 7)) {
            driver = StringToDriver(argv[i]);
            filename = "mat3d_3across.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]);
        }
    }

  if (show_all_errors) DBShowErrors(DB_ALL_AND_DRVR, 0);

  coordnames[0]=strdup("x");
  coordnames[1]=strdup("y");
  coordnames[2]=strdup("z");

  coord[0] = x;
  coord[1] = y;
  coord[2] = z;

  dims[0]=nx;
  dims[1]=ny;
  dims[2]=nz;

  db=DBCreate(filename, DB_CLOBBER, DB_LOCAL,
              "Mixed zone 3d test", driver);

  DBPutQuadmesh(db, "mesh", coordnames, coord, dims, 3, 
                DB_FLOAT, DB_NONCOLLINEAR, NULL);

  dims[0]=zx;
  dims[1]=zy;
  dims[2]=zz;

  DBPutMaterial(db, "material", "mesh", nmat, matnos, matlist, dims, 3, 
		mix_next, mix_mat, mix_zone, mix_vf, mixlen, DB_FLOAT, NULL);

  DBClose(db);
 
  free(coordnames[0]);
  free(coordnames[1]);
  free(coordnames[2]);

  CleanupDriverStuff();
  return 0;
}
Example #5
0
int
main(int argc, char *argv[])
{
    DBfile         *dbfile = NULL;
    int             i;
    int		    driver = DB_PDB;
    char 	    *filename = "majorder.silo";
    void           *coords[2];
    int             ndims = 2;
    int             dims[2] = {3,2}; 
    int             dims1[2] = {4,3}; 
    int             colmajor = DB_COLMAJOR;
    DBoptlist      *optlist;

    /* Parse command-line */
    for (i=1; i<argc; i++) {
	if (!strncmp(argv[i], "DB_", 3)) {
	    driver = StringToDriver(argv[i]);
	} else if (argv[i][0] != '\0') {
	    fprintf(stderr, "%s: ignored argument `%s'\n", argv[0], argv[i]);
	}
    }
    
    dbfile = DBCreate(filename, DB_CLOBBER, DB_LOCAL, "test major order on quad meshes and vars", driver);

    coords[0] = row_maj_x_data;
    coords[1] = row_maj_y_data;
    DBPutQuadmesh(dbfile, "row_major_mesh", 0, coords, dims1, ndims, DB_FLOAT, DB_NONCOLLINEAR, 0);
    DBPutQuadvar1(dbfile, "row_major_var", "row_major_mesh", row_maj_v_data, dims, ndims, 0, 0, DB_INT, DB_ZONECENT, 0);

    optlist = DBMakeOptlist(1);
    DBAddOption(optlist, DBOPT_MAJORORDER, &colmajor);
    coords[0] = col_maj_x_data;
    coords[1] = col_maj_y_data;
    DBPutQuadmesh(dbfile, "col_major_mesh", 0, coords, dims1, ndims, DB_FLOAT, DB_NONCOLLINEAR, optlist);
    DBPutQuadvar1(dbfile, "col_major_var", "col_major_mesh", col_maj_v_data, dims, ndims, 0, 0, DB_INT, DB_ZONECENT, optlist);
    DBFreeOptlist(optlist);

    DBClose(dbfile);

    CleanupDriverStuff();

    return 0;
}
Example #6
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;
}
Example #7
0
/*----------------------------------------------------------------------------
 *----------------------------------------------------------------------------
 *                              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;
}
Example #8
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;
}
Example #9
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;
}
Example #10
0
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);   
}
Example #11
0
/*-------------------------------------------------------------------------
 * Function:	main
 *
 * Purpose:	
 *
 * Return:	0
 *
 * Programmer:	
 *
 * Modifications:
 * 	Robb Matzke, 1999-04-09
 *	Added argument parsing to control the driver which is used.
 *
 *-------------------------------------------------------------------------
 */
int
main(int argc, char *argv[])
{
    int            i,j;
    DBfile        *file = NULL;
    char          *coordnames[2];  /* Name the axes */
    float          xcoords[NX + 1];
    float          ycoords[NY + 1];
    float         *coordinates[2];
    int            dims[2];
    float          float_var[NX*NY];
    float          dist_var[NX*NY];
    float          density_var[NX*NY];
    float          total_length, frac_length;
    int            matnos[2];
    int            nmatspec[2];
    float          species_mf[MAX_MIX_LEN];
    int            matlist[MAX_MIX_LEN];
    int            speclist[MAX_MIX_LEN];
    int            nspecies_mf;
    float          dist;
    DBoptlist      *optlist;
    int            value;
    int		   driver=DB_PDB;
    char	   *filename="species.silo";
    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 = "species.pdb";
	} else if (!strncmp(argv[i], "DB_HDF5", 7)) {
            driver = StringToDriver(argv[i]);
	    filename = "species.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]);
	}
    }
    
    if (show_all_errors) DBShowErrors(DB_ALL_AND_DRVR, 0);

    printf("Creating a 2D rectilinear SILO file `%s'...\n", filename);

    /* Create the SILO file */
    if ((file = DBCreate(filename, DB_CLOBBER, DB_LOCAL, NULL,
			 driver)) == NULL)
    {
        fprintf(stderr, "Unable to create SILO file\n");
        exit(1);
    }

    /* Name the coordinate axes 'X' and 'Y' */
    coordnames[0] = (char *) _db_safe_strdup("X");
    coordnames[1] = (char *) _db_safe_strdup("Y");

    /* Set up the coordinate values */

    /* X Coordinates */
    for(i=0;i<NX+1;i++)
        xcoords[i] = ((double)i)/NX;

    /* Y Coordinates */
    for(j=0;j<NY+1;j++)
        ycoords[j] = ((double)j)/NY;

    coordinates[0] = xcoords;
    coordinates[1] = ycoords;

    /* Enumerate the dimensions (4 values in x direction, 3 in y) */
    dims[0] = NX + 1;
    dims[1] = NY + 1;

    /* Write out the mesh to the file */
    DBPutQuadmesh(file, "quad_mesh", (DBCAS_t) coordnames,
        coordinates, dims, 2, DB_FLOAT, DB_COLLINEAR, NULL);

    /* Set up the material and species information */

    /* Material numbers */
    matnos[0] = 1;
    matnos[1] = 2;

    /* Material species numbers */
    nmatspec[0] = 3;
    nmatspec[1] = 1;

    printf("Calculating material information.\n");
    /* Mixed species array */
    nspecies_mf = 0;
    for(j=0;j<NY;j++)
    {
        for(i=0;i<NX;i++)
        {
            if (xcoords[i] >= 0.8)
            {
                matlist[j*NX+i] = 2;

                /* All one species */
                speclist[j*NX+i] = nspecies_mf + 1;
                species_mf[nspecies_mf++] = 1.0;
            }
            else
            {
                matlist[j*NX+i] = 1;

                speclist[j*NX+i] = nspecies_mf + 1;

                if (xcoords[i+1] < (1.0/3.0))
                {
                    /* All on left - All species 1 */
                    species_mf[nspecies_mf++] = 1.0;
                    species_mf[nspecies_mf++] = 0.0;
                    species_mf[nspecies_mf++] = 0.0;
                } else if ((xcoords[i] > (1.0/3.0)) && (xcoords[i+1] < (2.0/3.0)))
                {
                    /* All in middle - All species 2 */
                    species_mf[nspecies_mf++] = 0.0;
                    species_mf[nspecies_mf++] = 1.0;
                    species_mf[nspecies_mf++] = 0.0;
                } else if (xcoords[i] > (2.0/3.0))
                {
                    /* All on right - All species 3 */
                    species_mf[nspecies_mf++] = 0.0;
                    species_mf[nspecies_mf++] = 0.0;
                    species_mf[nspecies_mf++] = 1.0;
                } else
                {
                    /* Somewhere on a boundary */
                    if (xcoords[i] < (1.0/3.0))
                    {
                        /* Left boundary */
                        total_length = (xcoords[i+1] - xcoords[i]);
                        frac_length = ((1.0/3.0) - xcoords[i]);
                        species_mf[nspecies_mf++] = (frac_length/total_length);
                        species_mf[nspecies_mf++] = 1 - (frac_length/total_length);
                        species_mf[nspecies_mf++] = 0.0;
                    } else
                    {
                        /* Right boundary */
                        total_length = (xcoords[i+1] - xcoords[i]);
                        frac_length = ((2.0/3.0) - xcoords[i]);
                        species_mf[nspecies_mf++] = 0.0;
                        species_mf[nspecies_mf++] = (frac_length/total_length);
                        species_mf[nspecies_mf++] = 1 - (frac_length/total_length);
                    }
                }
            }
        }
    }

    /* The dimensions have changed since materials are defined for zones,
     * not for nodes */
    dims[0] = NX;
    dims[1] = NY;

    if (nspecies_mf>MAX_MIX_LEN)
    {
        fprintf(stderr,"Length %d of mixed species arrays exceeds the max %d.\n",
            nspecies_mf,MAX_MIX_LEN);
        fprintf(stderr,"Memory may have been corrupted, and the SILO\n");
        fprintf(stderr,"file may be invalid.\n");
    }

    /* Write out the material to the file */
    DBPutMaterial(file, "mat1", "quad_mesh", 2, matnos, matlist, dims, 2, NULL,
                  NULL, NULL, NULL, 0, DB_FLOAT, NULL);

    /* Write out the material species to the file */
    DBPutMatspecies(file, "matspec1", "mat1", 2, nmatspec, speclist, dims,
                    2, nspecies_mf, species_mf, NULL, 0, DB_FLOAT, NULL);

    free(coordnames[0]);
    free(coordnames[1]);

    printf("Calculating variables.\n");
    /* Set up the variables */
    for(j=0;j<NY;j++)
        for(i=0;i<NX;i++)
        {
            dist = distance((xcoords[i]+xcoords[i+1])/2,(ycoords[j]+ycoords[j+1])/2,0.5,0.5);
            float_var[j*NX+i] = cos(SCALE*dist)/exp(dist*DAMP);
            dist_var[j*NX+i] = dist;
            if (xcoords[i]<(1.0/3.0))
                density_var[j*NX+i] = 30.0;
            else if ((xcoords[i]<(2.0/3.0)) || (xcoords[i] >= 0.8))
                density_var[j*NX+i] = 1000.0;
            else
                density_var[j*NX+i] = 200.0;
        }

    /* Make a DBoptlist so that we can tell the variables to use the
       material species stuff */

    optlist = DBMakeOptlist(1);
    value = DB_ON;
    DBAddOption(optlist, DBOPT_USESPECMF, &value);

    /* Write the data variables to the file */
    DBPutQuadvar1(file, "float_var", "quad_mesh", float_var, dims, 2, NULL,
                  0, DB_FLOAT, DB_ZONECENT, optlist);
    DBPutQuadvar1(file, "dist_var", "quad_mesh", dist_var, dims, 2, NULL,
                  0, DB_FLOAT, DB_ZONECENT, optlist);
    DBPutQuadvar1(file, "density_var", "quad_mesh", density_var, dims, 2, NULL,
                  0, DB_FLOAT, DB_ZONECENT, optlist);

    DBFreeOptlist(optlist);
    DBClose(file);

    printf("Finished.\n");

    CleanupDriverStuff();
    return (0);
}
Example #12
0
int
main(int argc, char *argv[])
{
    DBfile         *dbfile = NULL;
    char           *coordnames[3];
    float          *coords[3];
    float           x[64], y[64], z[64];
    int             shapesize[1];
    int             shapecnt[1];
    DBfacelist     *facelist = NULL;
    int             matnos[1], matlist[1], dims[3];
    int             i, j, k, len;
    float           evar2d[2*16], evar3d[3*64], fvar3d[3*64];
    int		    driver = DB_PDB;
    char 	    *filename = "efcentering.silo";
    int             layer, zone;
    int             nodelist2[9*4] = {0,1,5,4,    1,2,6,5,    2,3,7,6,
                                      4,5,9,8,    5,6,10,9,   6,7,11,10,
                                      8,9,13,12,  9,10,14,13, 10,11,15,14};
    int st2 = DB_ZONETYPE_QUAD;
    int ss2 = 4;
    int sc2 = 9;
    int nodelist3[27*8];
    int st3 = DB_ZONETYPE_HEX;
    int ss3 = 8;
    int sc3 = 27;

    int nedges;
    int *edges;
    int nfaces;
    int *faces;
    int ndims;
    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]);
	} else if (!strncmp(argv[i], "DB_HDF5", 7)) {
	    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]);
	}
    }
    
    DBShowErrors(show_all_errors?DB_ALL_AND_DRVR:DB_ABORT, NULL);
    dbfile = DBCreate(filename, DB_CLOBBER, DB_LOCAL, "edge and face centered data", driver);

    coordnames[0] = "xcoords";
    coordnames[1] = "ycoords";
    coordnames[2] = "zcoords";

    dims[0] = 4;
    dims[1] = 4;
    dims[2] = 4;
    for (k = 0; k < 4; k++)
    {
        for (j = 0; j < 4; j++)
        {
            for (i = 0; i < 4; i++)
            {
                x[k*4*4+j*4+i] = (float) i;
                y[k*4*4+j*4+i] = (float) j;
                z[k*4*4+j*4+i] = (float) k;
                evar2d[0*16+j*4+i] = (float) i;
                evar2d[1*16+j*4+i] = (float) j;
                evar3d[0*64+k*4*4+j*4+i] = (float) i;
                evar3d[1*64+k*4*4+j*4+i] = (float) j;
                evar3d[2*64+k*4*4+j*4+i] = (float) k;
                fvar3d[0*64+k*4*4+j*4+i] = (float) 10*i;
                fvar3d[1*64+k*4*4+j*4+i] = (float) 100*j;
                fvar3d[2*64+k*4*4+j*4+i] = (float) 1000*k;
            }
        }
    }

    coords[0] = x;
    coords[1] = y;
    coords[2] = z;

    /* build 3d zonelist by layering 2d zonelist */
    for (layer = 0; layer < 3; layer++)
    {
        for (zone = 0; zone < 9; zone++)
        {
            nodelist3[layer*9*8+zone*8+0] = nodelist2[zone*4+0]+(layer+1)*16;
            nodelist3[layer*9*8+zone*8+1] = nodelist2[zone*4+0]+layer*16;
            nodelist3[layer*9*8+zone*8+2] = nodelist2[zone*4+1]+layer*16;
            nodelist3[layer*9*8+zone*8+3] = nodelist2[zone*4+1]+(layer+1)*16;
            nodelist3[layer*9*8+zone*8+4] = nodelist2[zone*4+3]+(layer+1)*16;
            nodelist3[layer*9*8+zone*8+5] = nodelist2[zone*4+3]+layer*16;
            nodelist3[layer*9*8+zone*8+6] = nodelist2[zone*4+2]+layer*16;
            nodelist3[layer*9*8+zone*8+7] = nodelist2[zone*4+2]+(layer+1)*16;
        }
    }

    DBPutQuadmesh(dbfile, "qmesh2", (DBCAS_t) coordnames, coords, dims, 2, DB_FLOAT, DB_NONCOLLINEAR, 0);
    DBPutQuadmesh(dbfile, "qmesh3", (DBCAS_t) coordnames, coords, dims, 3, DB_FLOAT, DB_NONCOLLINEAR, 0);
    DBPutQuadvar1(dbfile, "qevar2", "qmesh2", evar2d, dims, 2, 0, 0, DB_FLOAT, DB_EDGECENT, 0);
    DBPutQuadvar1(dbfile, "qevar3", "qmesh3", evar3d, dims, 3, 0, 0, DB_FLOAT, DB_EDGECENT, 0);
    DBPutQuadvar1(dbfile, "qfvar3", "qmesh3", fvar3d, dims, 3, 0, 0, DB_FLOAT, DB_FACECENT, 0);

    DBPutUcdmesh(dbfile, "umesh2", 2, (DBCAS_t) coordnames, coords, 16, 9,  "um2zl", 0, DB_FLOAT, 0);
    DBPutUcdmesh(dbfile, "umesh3", 3, (DBCAS_t) coordnames, coords, 64, 27, "um3zl", 0, DB_FLOAT, 0);
    DBPutZonelist2(dbfile, "um2zl", 9, 2, nodelist2, ss2*sc2, 0, 0, 0, &st2, &ss2, &sc2, 1, 0);
    DBPutZonelist2(dbfile, "um3zl", 27, 3, nodelist3, ss3*sc3, 0, 0, 0, &st3, &ss3, &sc3, 1, 0);

    /* Only reason we build an edgelist is so we know the number of unique edges in the mesh */
    build_edgelist(27, 3, nodelist3, ss3*sc3, 0, 0, 0, &st3, &ss3, &sc3, 1, &nedges, &edges);
    for (i = 0; i < nedges; i++)
        evar3d[i] = i;
    DBPutUcdvar1(dbfile, "uevar3", "umesh3", evar3d, nedges, 0, 0, DB_FLOAT, DB_EDGECENT, 0);
    ndims = 2;
    dims[0] = nedges;
    dims[1] = 2;
    DBWrite(dbfile, "edges", edges, dims, ndims, DB_INT);
    free(edges);

    /* Only reason we build a facelist is so we know the number of unique faces in the mesh */
    build_facelist(27, 3, nodelist3, ss3*sc3, 0, 0, 0, &st3, &ss3, &sc3, 1, &nfaces, &faces);
    for (i = 0; i < nfaces; i++)
        fvar3d[i] = i;
    DBPutUcdvar1(dbfile, "ufvar3", "umesh3", fvar3d, nfaces, 0, 0, DB_FLOAT, DB_FACECENT, 0);
    dims[0] = nfaces;
    dims[1] = 4;
    DBWrite(dbfile, "faces", faces, dims, ndims, DB_INT);
    free(faces);

    DBClose(dbfile);

    CleanupDriverStuff();
    return (0);
}
Example #13
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;
}