コード例 #1
0
ファイル: defvars.c プロジェクト: burlen/visit_vtk_7_src
void
write_curv3d(DBfile *dbfile)
{
    /* Write a curvilinear mesh. */
    float x[2][3][4] = {
       {{0.,1.,2.,3.},{0.,1.,2.,3.}, {0.,1.,2.,3.}},
       {{0.,1.,2.,3.},{0.,1.,2.,3.}, {0.,1.,2.,3.}}
    };
    float y[2][3][4] = {
       {{0.5,0.,0.,0.5},{1.,1.,1.,1.}, {1.5,2.,2.,1.5}},
       {{0.5,0.,0.,0.5},{1.,1.,1.,1.}, {1.5,2.,2.,1.5}}
    };
    float z[2][3][4] = {
       {{0.,0.,0.,0.},{0.,0.,0.,0.},{0.,0.,0.,0.}},
       {{1.,1.,1.,1.},{1.,1.,1.,1.},{1.,1.,1.,1.}}
    };
    int dims[] = {4, 3, 2};
    int ndims = 3;
    float *coords[3];
    coords[0] = (float*)x;
    coords[1] = (float*)x;
    coords[2] = (float*)x;
    DBPutQuadmesh(dbfile, "quadmesh", NULL, coords, dims, ndims,
                  DB_FLOAT, DB_NONCOLLINEAR, NULL);

    /* Write coordinates also as nodal vars. */
    DBPutQuadvar1(dbfile, "xc", "quadmesh", (float *)x, dims,
                  ndims, NULL, 0, DB_FLOAT, DB_NODECENT, NULL);
    DBPutQuadvar1(dbfile, "yc", "quadmesh", (float *)y, dims,
                  ndims, NULL, 0, DB_FLOAT, DB_NODECENT, NULL);
    DBPutQuadvar1(dbfile, "zc", "quadmesh", (float *)z, dims,
                  ndims, NULL, 0, DB_FLOAT, DB_NODECENT, NULL);
}
コード例 #2
0
ファイル: meshorigin.C プロジェクト: maxhutch/visit
void
write_curv3d(DBfile *dbfile, const char *meshname, int origin)
{
    /* Write a curvilinear mesh. */
    DBoptlist *opt = NULL;
    float x[2][3][4] = {
       {{0.,1.,2.,3.},{0.,1.,2.,3.}, {0.,1.,2.,3.}},
       {{0.,1.,2.,3.},{0.,1.,2.,3.}, {0.,1.,2.,3.}}
    };
    float y[2][3][4] = {
       {{0.5,0.,0.,0.5},{1.,1.,1.,1.}, {1.5,2.,2.,1.5}},
       {{0.5,0.,0.,0.5},{1.,1.,1.,1.}, {1.5,2.,2.,1.5}}
    };
    float z[2][3][4] = {
       {{0.,0.,0.,0.},{0.,0.,0.,0.},{0.,0.,0.,0.}},
       {{1.,1.,1.,1.},{1.,1.,1.,1.},{1.,1.,1.,1.}}
    };
    int dims[] = {4, 3, 2};
    int ndims = 3;
    float *coords[] = {(float*)x, (float*)y, (float*)z};
    opt = MakeOptList(origin);
    DBPutQuadmesh(dbfile, meshname, NULL, coords, dims, ndims,
                  DB_FLOAT, DB_NONCOLLINEAR, opt);
    DBFreeOptlist(opt);
}
コード例 #3
0
static int Write_silo(void *buf, size_t nbytes)
{
    static int n = 0;
    int dims[3] = {1, 1, 1};
    int status;

    dims[0] = nbytes / sizeof(double);
    if (!has_mesh)
    {
        char *coordnames[] = {"x"};
        void *coords[3] = {0, 0, 0};
        coords[0] = buf;
        has_mesh = 1;
        status = DBPutQuadmesh(dbfile, "mesh", coordnames, coords, dims, 1, DB_DOUBLE, DB_COLLINEAR, 0);
    }
    else
    {
        char dsname[64];
        sprintf(dsname, "data_%07d", n++);
        status = DBPutQuadvar1(dbfile, dsname, "mesh", buf, dims, 1, 0, 0, DB_DOUBLE, DB_NODECENT, 0);
    }

    if (status < 0) return 0;
    return nbytes;
}
コード例 #4
0
/*--------------------*/
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;
}
コード例 #5
0
ファイル: majorder.c プロジェクト: drhansj/polymec-dev
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;
}
コード例 #6
0
/*--------------------*/
int main(int argc, char **argv) {
    DBfile *db;
    int            i, driver = DB_PDB;
    char          *filename = "csg.pdb";
    char  *coordnames[3];
    float *coord[3];

    for (i=1; i<argc; i++) {
        if (!strcmp(argv[i], "DB_PDB")) {
            driver = DB_PDB;
            filename = "mat3d_3across.pdb";
        } else if (!strcmp(argv[i], "DB_HDF5")) {
            driver = DB_HDF5;
            filename = "mat3d_3across.h5";
        } else {
            fprintf(stderr, "%s: ignored argument `%s'\n", argv[0], argv[i]);
        }
    }

  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);

  return 0;
}
コード例 #7
0
ファイル: meshorigin.C プロジェクト: maxhutch/visit
void
write_rect3d(DBfile *dbfile, const char *meshname, int origin)
{
    /* Write a rectilinear mesh. */
    DBoptlist *opt = NULL;
    float x[] = {0., 1., 2.5, 5.};
    float y[] = {0., 2., 2.25, 2.55,  5.};
    float z[] = {0., 1., 3.};
    int dims[] = {4, 5, 3};
    int ndims = 3;
    float *coords[] = {x, y, z};
    opt = MakeOptList(origin);
    DBPutQuadmesh(dbfile, meshname, NULL, coords, dims, ndims,
                  DB_FLOAT, DB_COLLINEAR, opt);
    DBFreeOptlist(opt);
}
コード例 #8
0
/*-------------------------------------------------------------------------
 * 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;
}
コード例 #9
0
ファイル: optlist.c プロジェクト: burlen/visit_vtk_7_src
void
write_rect2d(DBfile *dbfile)
{
    /* Write a rectilinear mesh. */
    float x[] = {0., 1., 2.5, 5.};
    float y[] = {0., 2., 2.25, 2.55,  5.};
    int dims[] = {4, 5};
    int ndims = 2;
    float *coords[2];
    /* Create an option list for saving cycle and time values. */
    int cycle = 100;
    double dtime = 1.23456789;
    DBoptlist *optlist = DBMakeOptlist(2);
    coords[0] = x; coords[1] = y;
    DBAddOption(optlist, DBOPT_CYCLE, (void *)&cycle);
    DBAddOption(optlist, DBOPT_DTIME, (void *)&dtime);
    /* Write a quadmesh with an option list. */
    DBPutQuadmesh(dbfile, "quadmesh", NULL, coords, dims, ndims,
                  DB_FLOAT, DB_COLLINEAR, optlist);
    /* Free the option list. */
    DBFreeOptlist(optlist);
}
コード例 #10
0
ファイル: vectorvar.c プロジェクト: ahota/visit_intel
void
write_curv3d(DBfile *dbfile)
{
    /* Write a curvilinear mesh. */
    float x[2][3][4] = {
       {{0.,1.,2.,3.},{0.,1.,2.,3.}, {0.,1.,2.,3.}},
       {{0.,1.,2.,3.},{0.,1.,2.,3.}, {0.,1.,2.,3.}}
    };
    float y[2][3][4] = {
       {{0.5,0.,0.,0.5},{1.,1.,1.,1.}, {1.5,2.,2.,1.5}},
       {{0.5,0.,0.,0.5},{1.,1.,1.,1.}, {1.5,2.,2.,1.5}}
    };
    float z[2][3][4] = {
       {{0.,0.,0.,0.},{0.,0.,0.,0.},{0.,0.,0.,0.}},
       {{1.,1.,1.,1.},{1.,1.,1.,1.},{1.,1.,1.,1.}}
    };
    int dims[] = {4, 3, 2};
    int ndims = 3;
    float *coords[3];
    coords[0] = (float*)x; coords[1] = (float*)y; coords[2] = (float*)z;
    DBPutQuadmesh(dbfile, "quadmesh", NULL, coords, dims, ndims,
                  DB_FLOAT, DB_NONCOLLINEAR, NULL);
}
コード例 #11
0
void
write_domains(void)
{
    float x[] = {0., 1., 2.5, 5.};
    float y[] = {0., 2., 2.25, 2.55,  5.};
    int dims[] = {4, 5};
    int dom, i, ndims = 2;

    float tx[] = {0., -5., -5., 0.};
    float ty[] = {0., 0., -5., -5.};

    for(dom = 0; dom < 4; ++dom)
    {
        DBfile *dbfile = NULL;
        float xc[4], yc[5];
        float *coords[] = {xc, yc};
        char filename[100];

        for(i = 0; i < 4; ++i)
            xc[i] = x[i] + tx[dom];
        for(i = 0; i < 5; ++i)
            yc[i] = y[i] + ty[dom];

        /* Open the Silo file */
        sprintf(filename, "multimesh.%d", dom);
        dbfile = DBCreate(filename, DB_CLOBBER, DB_LOCAL,
        "domain data", DB_HDF5);    

        /* Write a rectilinear mesh. */
        DBPutQuadmesh(dbfile, "quadmesh", NULL, coords, dims, ndims,
                      DB_FLOAT, DB_COLLINEAR, NULL);

        /* Close the Silo file. */
        DBClose(dbfile);
    }
}
コード例 #12
0
/*----------------------------------------------------------------------
 *  Routine                                                   build_quad
 *
 *  Purpose
 *
 *      Build quad-mesh, quad-var, and material data objects; return
 *      the mesh ID.
 *
 * Arguments
 *    name      Name to assign mesh.
 *
 * Modifications
 *
 *    Lisa J. Roberts, Fri Apr  7 09:35:52 PDT 2000
 *    Changed the prototype to ANSI standard and explicitly indicated
 *    the function returns an int.  Got rid of varid and matid, which
 *    were unused.
 *
 *--------------------------------------------------------------------*/
int
build_quad(DBfile *dbfile, char *name)
{
    int            i, dims[3], zones[3], ndims, cycle, meshid;
    float          time;
    double         dtime;
    int            zdims[3];
    float          x[10], y[8], d[80], *coords[3], *vars[3];
    float          u[80], v[80];
    int            matnos[3], matlist[63], nmat, mixlen;
    char          *coordnames[3], *varnames[3];
    DBoptlist     *optlist;

    optlist = DBMakeOptlist(10);
    DBAddOption(optlist, DBOPT_CYCLE, &cycle);
    DBAddOption(optlist, DBOPT_TIME, &time);
    DBAddOption(optlist, DBOPT_DTIME, &dtime);

    ndims = 2;
    dims[0] = 10;
    dims[1] = 8;

    zones[0] = 9;
    zones[1] = 7;

    cycle = 44;
    time = 4.4;
    dtime = 4.4;
    coords[0] = x;
    coords[1] = y;
    coordnames[0] = "xcoords";
    coordnames[1] = "ycoords";

    for (i = 0; i < dims[0]; i++)
        x[i] = (float)i;
    for (i = 0; i < dims[1]; i++)
        y[i] = (float)i + .1;

    meshid = DBPutQuadmesh(dbfile, name, coordnames, coords, dims, ndims,
                           DB_FLOAT, DB_COLLINEAR, optlist);

    varnames[0] = "d";
    vars[0] = d;
    zdims[0] = dims[0] - 1;
    zdims[1] = dims[1] - 1;

    for (i = 0; i < zdims[0] * zdims[1]; i++)
        d[i] = (float)i *.2;

    (void)DBPutQuadvar1(dbfile, "d", name, d, zdims, ndims,
                        NULL, 0, DB_FLOAT, DB_ZONECENT, optlist);

    for (i = 0; i < dims[0] * dims[1]; i++) {
        u[i] = (float)i *.1;
        v[i] = (float)i *.1;
    }

    (void)DBPutQuadvar1(dbfile, "ucomp", name, u, dims, ndims,
                        NULL, 0, DB_FLOAT, DB_NODECENT, optlist);
    (void)DBPutQuadvar1(dbfile, "vcomp", name, v, dims, ndims,
                        NULL, 0, DB_FLOAT, DB_NODECENT, optlist);

    vars[0] = u;
    vars[1] = v;
    varnames[0] = "u";
    varnames[1] = "v";

    (void)DBPutQuadvar(dbfile, "velocity", name, 2, varnames, vars,
                       dims, ndims, NULL, 0, DB_FLOAT, DB_NODECENT,
                       optlist);

    /*
     *  Build material data.
     */
    nmat = 3;
    mixlen = 0;
    matnos[0] = 1;
    matnos[1] = 2;
    matnos[2] = 3;

    for (i = 0; i < 27; i++)
        matlist[i] = 1;
    for (i = 27; i < 45; i++)
        matlist[i] = 2;
    for (i = 45; i < 63; i++)
        matlist[i] = 3;

    (void)DBPutMaterial(dbfile, "material", name, nmat, matnos,
                        matlist, zones, ndims, NULL, NULL, NULL, NULL,
                        mixlen, DB_FLOAT, NULL);

    return (meshid);
}
コード例 #13
0
ファイル: bounce.C プロジェクト: maxhutch/visit
    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);
    }
コード例 #14
0
ファイル: dataextents.c プロジェクト: burlen/visit_vtk_7_src
void
write_domains(double extents[4][2])
{
    float x[] = {0., 1., 2.5, 5.};
    float y[] = {0., 2., 2.25, 2.55,  5.};
    float var[20];
    int dims[] = {4, 5};
    int dom, i, j, ndims = 2;

    float tx[] = {0., -5., -5., 0.};
    float ty[] = {0., 0., -5., -5.};

    for(dom = 0; dom < 4; ++dom)
    {
        DBfile *dbfile = NULL;
        float xc[4], yc[5];
        float *coords[2];
        char filename[100];
        int index = 0;

        coords[0] = xc;
        coords[1] = yc;
        for(i = 0; i < 4; ++i)
            xc[i] = x[i] + tx[dom];
        for(i = 0; i < 5; ++i)
            yc[i] = y[i] + ty[dom];

        for(j = 0; j < 5; ++j)
        {
            for(i = 0; i < 4; ++i)
            {
                float dx, dy;
                dx = xc[i] - 5.;
                dy = yc[j] - 5.;
                var[index++] = (float)sqrt(dx*dx + dy*dy);
            }
        }

        /* Figure out the extents for the domain. */
        extents[dom][0] = extents[dom][1] = var[0];
        for(i = 1; i < 4*5; ++i)
        {
            extents[dom][0] = (var[i] < extents[dom][0]) ? var[i] : extents[dom][0];
            extents[dom][1] = (var[i] > extents[dom][1]) ? var[i] : extents[dom][1];
        }

        /* Open the Silo file */
        sprintf(filename, "dataextents.%d", dom);
        dbfile = DBCreate(filename, DB_CLOBBER, DB_LOCAL,
        "domain data", DB_HDF5);    

        /* Write a rectilinear mesh. */
        DBPutQuadmesh(dbfile, "quadmesh", NULL, coords, dims, ndims,
                      DB_FLOAT, DB_COLLINEAR, NULL);

        /* Write a node-centered var. */
        DBPutQuadvar1(dbfile, "var", "quadmesh", var, dims,
                      ndims, NULL, 0, DB_FLOAT, DB_NODECENT, NULL);

        /* Close the Silo file. */
        DBClose(dbfile);
    }
}
コード例 #15
0
ファイル: oct2cell.c プロジェクト: domaubert/EMMA
/*

 mpicc  -I./silo/include -DPIC -DWGRAV -DTESTCOSMO -DFASTGRAV -DGRAFIC -DONFLYRED -DGPUAXL -o ./oct2grid ./oct2grid.c ./silo/lib/libsilo.a

avconv -i mpeg_link%04d.jpeg -r 24 -b 65536k video.mp4

 */
int main(int argc, char *argv[])
{
    //(int lmap,struct OCT **firstoct,int field,char filename[],REAL tsim)
    int status;
    int I;
    int lmap;
    float *map;
    int imap,jmap,kmap;
    int nmap;
    REAL dxmap,dxcur;
    int icur,ii,jj,kk,ic,icell;
    int level;
    struct LOCT * nextoct;
    struct LOCT oct;
    FILE *fp;
    REAL xc,yc,zc;
    int field;
    REAL tsim=0.;
    float tsimf;
    char fname[256];
    char format[256];
    char fname2[256];
    int ncpu;
    long int nc;
    int icpu;
    struct OCT *zerooct;
#ifdef WRAD
    struct UNITS unit;
#endif

    size_t dummy;

    if(argc<7) {
        printf("USAGE: /a.out input level field output nproc\n");
        printf("Ex : data/grid.00002 7 101 data/grid.den 8\n");
        printf("field values :\n");
        printf(" case 0 oct.level;\n case 1 density;\n case 2 pot;\n case 3 cpu;\n case 4 marked;\n case 5 temp;\n case 101 field.d;\n case 102 field.u;\n case 103 field.v;\n case 104 field.w;\n case 105 field.p;\n");
        return 0;
    }

    // getting the field
    sscanf(argv[3],"%d",&field);

    //getting the resolution
    sscanf(argv[2],"%d",&lmap);
    nmap=pow(2,lmap);
    dxmap=1./nmap;

    // getting the number of CPUs
    sscanf(argv[5],"%d",&ncpu);
    printf("ncpu=%d\n",ncpu);

    // silo file
    int dumpsilo=0;
    sscanf(argv[6],"%d",&dumpsilo);
    REAL zmin,zmax;
    int nmapz;
    int k0;

    int mono;
    sscanf(argv[7],"%d",&mono);
    printf("mono=%d\n",mono);

    if(argc>8) {
        sscanf(argv[8],"%f",&zmin);
        sscanf(argv[9],"%f",&zmax);
    }
    else {
        zmin=0;
        zmax=1.;
    }

    nmapz=(zmax-zmin)/dxmap;
    k0=zmin/dxmap;

    if((dumpsilo==1)&&(nmapz!=nmap)) {
        printf("Silo can only handle cubic data !\n");
        abort();
    }

    // scanning the cpus

    int icpustart,icpustop;
    if(mono<0) {
        icpustart=0;
        icpustop=ncpu;
    }
    else {
        icpustart=mono;
        icpustop=mono+1;
        printf("Cast single cpu #%d\n",mono) ;
    }


    nc=0;
    for(icpu=icpustart; icpu<icpustop; icpu++) {


        // building the input file name
        strcpy(format,argv[1]);
        strcat(format,".p%05d");
        sprintf(fname,format,icpu);

        // building the output file name
        strcpy(format,argv[4]);

        sprintf(fname2,format,icpu);

        // counting cells

        fp=fopen(fname,"rb");

        if(fp==NULL) {
            printf("--ERROR -- file not found\n");
            return 1;
        }

        // reading the time
        dummy=fread(&tsim,sizeof(REAL),1,fp);
#ifdef WRAD
        dummy=fread(&unit.unit_l,sizeof(REAL),1,fp);
        printf("unit=%e\n",unit.unit_l);
        dummy=fread(&unit.unit_v,sizeof(REAL),1,fp);
        dummy=fread(&unit.unit_t,sizeof(REAL),1,fp);
        dummy=fread(&unit.unit_n,sizeof(REAL),1,fp);
        dummy=fread(&unit.unit_mass,sizeof(REAL),1,fp);
#endif

        // reading the zerooct
        dummy=fread(&zerooct,sizeof(struct OCT *),1,fp);


        dummy=fread(&oct,sizeof(struct LOCT),1,fp);
        while(!feof(fp)) {
            for(icell=0; icell<8; icell++) // looping over cells in oct
            {
                if(oct.cell[icell].child==0)
                {
                    if((zc<zmin)||(zc>zmax)) {
                        continue;
                    }

                    int flag;
                    if(mono>=0) {
                        flag=(oct.cpu>=0);
                    }
                    else {
                        flag=(oct.cpu==icpu);
                    }

                    if(flag) {
                        //printf("helo\n,");
                        nc++;
                        //printf("nc=%d\n",nc);
                    }
                }
            }
            dummy=fread(&oct,sizeof(struct OCT),1,fp); //reading next oct
        }
        fclose(fp);
    }
    printf("Found %ld leaf cells\n",nc);

    map=(float *)calloc(nc*NREAL,sizeof(float)); // NREAL=5 3 for pos, 1 for level, 1 for data

    ic=0;
    for(icpu=icpustart; icpu<icpustop; icpu++) {


        // building the input file name
        strcpy(format,argv[1]);
        strcat(format,".p%05d");
        sprintf(fname,format,icpu);

        // building the output file name
        strcpy(format,argv[4]);

        sprintf(fname2,format,icpu);

        // getting data
        printf("Looking for data in %s\n",fname);
        fp=fopen(fname,"rb");

        if(fp==NULL) {
            printf("--ERROR -- file not found\n");
            return 1;
        }


        // reading the time
        dummy=fread(&tsim,sizeof(REAL),1,fp);
#ifdef WRAD
        dummy=fread(&unit.unit_l,sizeof(REAL),1,fp);
        printf("unit=%e\n",unit.unit_l);
        dummy=fread(&unit.unit_v,sizeof(REAL),1,fp);
        dummy=fread(&unit.unit_t,sizeof(REAL),1,fp);
        dummy=fread(&unit.unit_n,sizeof(REAL),1,fp);
        dummy=fread(&unit.unit_mass,sizeof(REAL),1,fp);
#endif

        printf("tsim=%e\n",tsim);
        tsimf=tsim;
        // reading the zerooct
        dummy=fread(&zerooct,sizeof(struct OCT *),1,fp);
        //printf("0oct=%p\n",zerooct);

        //printf("size of the OCT=%ld\n",sizeof(struct OCT));


        dummy=fread(&oct,sizeof(struct OCT),1,fp);
        while(!feof(fp)) {
            dxcur=1./pow(2.,oct.level);
            for(icell=0; icell<8; icell++) // looping over cells in oct
            {
                if(oct.cell[icell].child==0)
                {
                    xc=oct.x+( icell   %2)*dxcur+0.5*dxcur;
                    yc=oct.y+((icell/2)%2)*dxcur+0.5*dxcur;
                    zc=oct.z+( icell/4   )*dxcur+0.5*dxcur;
                    if((zc<zmin)||(zc>zmax)) {
                        continue;
                    }

                    int flag;
                    if(mono>=0) {
                        flag=(oct.cpu>=0);
                    }
                    else {
                        flag=(oct.cpu==icpu);
                    }
                    if(flag) {
                        map[ic*NREAL+0]=xc;
                        map[ic*NREAL+1]=yc;
                        map[ic*NREAL+2]=zc;
                        map[ic*NREAL+3]=(float)oct.level;
                        switch(field) {
                        case 0:
                            map[ic*NREAL+4]=oct.level;
                            break;
#ifdef WGRAV
                        case 1:
                            map[ic*NREAL+4]=oct.cell[icell].den;
                            break;
#ifdef PIC
                        case -1:
                            map[ic*NREAL+4]=oct.cell[icell].density;
                            break;
#endif
                        case 2:
                            map[ic*NREAL+4]=oct.cell[icell].pot;
                            break;
                        case 6:
                            map[ic*NREAL+4]+=oct.cell[icell].res;
                            break;
                        case 201:
                            map[ic*NREAL+4]=oct.cell[icell].f[0];
                            break;
                        case 202:
                            map[ic*NREAL+4]=oct.cell[icell].f[1];
                            break;
                        case 203:
                            map[ic*NREAL+4]=oct.cell[icell].f[2];
                            break;
#endif
                        case 3:
                            map[ic*NREAL+4]=oct.cpu;
                            break;
                        case 4:
                            map[ic*NREAL+4]=oct.cell[icell].marked;
                            break;
#ifdef WHYDRO2
                        case 101:
                            map[ic*NREAL+4]=oct.cell[icell].d;
                            //printf("%f\n",oct.cell[icell].d);
                            break;
                        case 102:
                            map[ic*NREAL+4]=oct.cell[icell].u;
                            break;
                        case 103:
                            map[ic*NREAL+4]=oct.cell[icell].v;
                            break;
                        case 104:
                            map[ic*NREAL+4]=oct.cell[icell].w;
                            break;
                        case 105:
                            map[ic*NREAL+4]=oct.cell[icell].p;
                            break;
#endif

#ifdef WRAD
                        case 701:
                            map[ic*NREAL+4]=log10(oct.cell[icell].e[0]);
                            break;
                        case 702:
                            map[ic*NREAL+4]=oct.cell[icell].fx[0];
                            break;
                        case 703:
                            map[ic*NREAL+4]=oct.cell[icell].fy[0];
                            break;
                        case 704:
                            map[ic*NREAL+4]=oct.cell[icell].fz[0];
                            break;
                        case 705:
                            map[ic*NREAL+4]=oct.cell[icell].src;
                            break;
#ifdef WCHEM
                        case 706:
                            map[ic*NREAL+4]=oct.cell[icell].xion;
                            break;
                        case 707:
                            map[ic*NREAL+4]=oct.cell[icell].temp;
                            break;
                        case 708:
                            map[ic*NREAL+4]=oct.cell[icell].d/pow(unit.unit_l,3.);
                            break;
#endif
#endif

                        }
                        ic++;
                    }
                }
            }
            dummy=fread(&oct,sizeof(struct OCT),1,fp); //reading next oct
        }
        fclose(fp);
    }
    printf("done with %d cells\n",ic);

    //============= dump

    if(!dumpsilo) {
        printf("dumping %s with nleaf=%d\n",fname2,nc);
        fp=fopen(fname2,"wb");
        fwrite(&nc,1,sizeof(int),fp);
        fwrite(&tsimf,1,sizeof(float),fp);
        for(I=0; I<nc; I++) fwrite(map+I*NREAL,sizeof(float),NREAL,fp);
        status=ferror(fp);
        fclose(fp);
    }
    else {
        DBfile *dbfile=NULL;
        dbfile=DBCreate(strcat(fname2,".silo"),DB_CLOBBER, DB_LOCAL,"silo file created by Quartz",DB_PDB);
        if(dbfile==NULL) {
            printf("Error while writing file");
        }


        float *x;
        float *y;
        float *z;
        int dims[]= {nmap+1,nmap+1,nmap+1};
        int ndims=3;

        x=(float*)malloc(sizeof(float)*(nmap+1));
        y=(float*)malloc(sizeof(float)*(nmap+1));
        z=(float*)malloc(sizeof(float)*(nmap+1));

        float *coords[]= {x,y,z};

        int i;
        for(i=0; i<=nmap; i++) {
            x[i]=((i*1.0)/nmap-0.);
            y[i]=((i*1.0)/nmap-0.);
            z[i]=((i*1.0)/nmap-0.);
        }

        int dimsvar[]= {nmap,nmap,nmap};
        int ndimsvar=3;

        DBPutQuadmesh(dbfile,"quadmesh",NULL,coords,dims,ndims,DB_FLOAT,DB_COLLINEAR,NULL);
        DBPutQuadvar1(dbfile,"monvar","quadmesh",map,dimsvar,ndimsvar,NULL,0,DB_FLOAT,DB_ZONECENT,NULL);

        DBClose(dbfile);
    }
    printf("status=%d\n",status);
    free(map);

}
コード例 #16
0
ファイル: efcentering.c プロジェクト: drhansj/polymec-dev
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);
}
コード例 #17
0
ファイル: SILO_CycObj.cpp プロジェクト: jdhare/hym_silo
void WriteMesh_SILO(DBfile *dbfile, char *mesh_name, int *dims, 
                    float **mesh_coords, int cycle, double time) {
    int i, j, k, n, Ntot;
    int Nq = dims[0], Nr = dims[1], Ns = dims[2];
    float *q = mesh_coords[0], *r = mesh_coords[1], *s = mesh_coords[2];
    float *s_ghost = NULL;
    

    //if halfcyl, just extend array. else ie. periodic, add ghost zones/
    if(half_cyl){
         Ns+=1;
         s_ghost=new float[Ns];
         //copy array across into new slightly alrger array
         for(k=0;k<Ns-1;k++){
                    s_ghost[k]=s[k];
         }
         //add final phi=pi point
         s_ghost[Ns-1]=s_ghost[Ns-2]+s_ghost[1];
    }else{
         AddGhostZones_Coord(s,s_ghost,Ns);               
    }
    Ntot = Nq*Nr*Ns;
    
    float *xg=NULL, *yg=NULL, *zg=NULL;
    xg = new float[Ntot];
    yg = new float[Ntot];
    zg = new float[Ntot];
    
    n = 0;
    for(k=0; k<Ns; k++) { 
        for(j=0; j<Nr; j++) {
            for(i=0; i<Nq; i++) {
                xg[n] = r[j]*cos(s_ghost[k]);
                yg[n] = r[j]*sin(s_ghost[k]);
                zg[n] = q[i];
                n++;
            } 
        }
    }
    
    delete [] s_ghost;
    
    // Create the arrays to write to the .silo database:
    int silodims[ndims] = {Nq,Nr,Ns};
    float *coords[ndims] = {(float*)xg, (float*)yg, (float*)zg};
    
    // Create an option list to save cycle and time values:
    DBoptlist *optlist = DBMakeOptlist(4);
    if(!half_cyl){
          int offset_low[ndims] = {0,0,Nghost};
          int offset_high[ndims] = {0,0,Nghost};
          DBAddOption(optlist, DBOPT_LO_OFFSET, offset_low);
          DBAddOption(optlist, DBOPT_HI_OFFSET, offset_high);                  
    }
    DBAddOption(optlist, DBOPT_DTIME, &time);
    DBAddOption(optlist, DBOPT_CYCLE, &cycle);

    // DBAddOption(optlist, DBOPT_COORDSYS, DB_CYLINDRICAL);

    // Write the mesh to the .silo file:
    DBPutQuadmesh(dbfile, mesh_name, NULL, coords, silodims, ndims,
                  DB_FLOAT, DB_NONCOLLINEAR, optlist);
                  
    DBFreeOptlist(optlist);
    
    delete [] xg;
    delete [] yg;
    delete [] zg;
    
}
コード例 #18
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;
}
コード例 #19
0
ファイル: specmix.c プロジェクト: drhansj/polymec-dev
/*----------------------------------------------------------------------------
 * Function: writemesh_curv2d()
 *
 * Inputs:   db (DBfile*): the Silo file handle
 *
 * Returns:  (void)
 *
 * Abstract: Write the mesh and variables stored in the global Mesh 
 *           to the Silo file as a quadmesh and quadvars
 *
 * Modifications:
 *---------------------------------------------------------------------------*/
void writemesh_curv2d(DBfile *db, int mixc, int reorder) {

  float f1[1000],f2[1000], fm[1000];
  int x,y,c;

  char  *coordnames[2];
  char  *varnames[6];
  void *varbufs[6];
  float *coord[2];
  int dims[2];

  char *cnvar, *czvar;
  short *snvar, *szvar;
  int *invar, *izvar;
  long *lnvar, *lzvar;
  long long *Lnvar, *Lzvar;
  float *fnvar, *fzvar;
  double *dnvar, *dzvar;

  int nnodes=mesh.nx*mesh.ny;
  int nzones=mesh.zx*mesh.zy;
  
  /* do mesh */
  c=0;
  for (x=0;x<mesh.nx;x++) {
    for (y=0;y<mesh.ny;y++) {
      f1[c]=mesh.node[x][y].x;
      f2[c]=mesh.node[x][y].y;
      c++;
    }
  }

  coordnames[0]=NEW(char,20);
  coordnames[1]=NEW(char,20);
  strcpy(coordnames[0],"x");
  strcpy(coordnames[1],"y");

  coord[0]=f1;
  coord[1]=f2;

  dims[0]=mesh.nx;
  dims[1]=mesh.ny;

  DBPutQuadmesh(db, "Mesh", (DBCAS_t) coordnames, coord,
      dims, 2, DB_FLOAT, DB_NONCOLLINEAR, NULL);

  /* Test outputting of ghost node and zone labels */
  {
      int i;
      int nnodes = mesh.nx * mesh.ny;
      int nzones = (mesh.nx-1) * (mesh.ny-1);
      char *gn = (char *) calloc(nnodes,1);
      char *gz = (char *) calloc(nzones,1);
      DBoptlist *ol = DBMakeOptlist(5);

      for (i = 0; i < nnodes; i++)
      {
          if (!(i % 3)) gn[i] = 1;
      }
      for (i = 0; i < nzones; i++)
      {
          if (!(i % 7)) gz[i] = 1;
      }

      strcpy(coordnames[0],"xn");
      strcpy(coordnames[1],"yn");
      DBAddOption(ol, DBOPT_GHOST_NODE_LABELS, gn);
      DBPutQuadmesh(db, "Mesh_gn", (DBCAS_t) coordnames,
          coord, dims, 2, DB_FLOAT, DB_NONCOLLINEAR, ol);
      DBClearOption(ol, DBOPT_GHOST_NODE_LABELS);

      strcpy(coordnames[0],"xz");
      strcpy(coordnames[1],"yz");
      DBAddOption(ol, DBOPT_GHOST_ZONE_LABELS, gz);
      DBPutQuadmesh(db, "Mesh_gz", (DBCAS_t) coordnames,
          coord, dims, 2, DB_FLOAT, DB_NONCOLLINEAR, ol);

      strcpy(coordnames[0],"xnz");
      strcpy(coordnames[1],"ynz");
      DBAddOption(ol, DBOPT_GHOST_NODE_LABELS, gn);
      DBPutQuadmesh(db, "Mesh_gnz", (DBCAS_t) coordnames,
          coord, dims, 2, DB_FLOAT, DB_NONCOLLINEAR, ol);

      DBFreeOptlist(ol);
      free(gn);
      free(gz);
  }

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

  /* do Node vars */

  cnvar = (char *)        malloc(sizeof(char)*nnodes); 
  snvar = (short *)       malloc(sizeof(short)*nnodes); 
  invar = (int *)         malloc(sizeof(int)*nnodes); 
  lnvar = (long *)        malloc(sizeof(long)*nnodes); 
  Lnvar = (long long *)   malloc(sizeof(long long)*nnodes); 
  fnvar = (float *)       malloc(sizeof(float)*nnodes); 
  dnvar = (double *)      malloc(sizeof(double)*nnodes); 
  c=0;
  for (x=0;x<mesh.nx;x++) {
    for (y=0;y<mesh.ny;y++) {
      f1[c]=mesh.node[x][y].vars[NV_U];
      f2[c]=mesh.node[x][y].vars[NV_V];
      cnvar[c] = (char)        (x<y?x:y);
      snvar[c] = (short)       (x<y?x:y);
      invar[c] = (int)         (x<y?x:y);
      lnvar[c] = (long)        (x<y?x:y);
      Lnvar[c] = (long long)   (x<y?x:y);
      fnvar[c] = (float)       (x<y?x:y);
      dnvar[c] = (double)      (x<y?x:y);
      c++;
    }
  }

  DBPutQuadvar1(db, "u", "Mesh", f1, dims, 2, NULL, 0, DB_FLOAT, DB_NODECENT, NULL);
  DBPutQuadvar1(db, "v", "Mesh", f2, dims, 2, NULL, 0, DB_FLOAT, DB_NODECENT, NULL);
  DBPutQuadvar1(db, "cnvar", "Mesh", cnvar, dims, 2, NULL, 0, DB_CHAR, DB_NODECENT, NULL);
  DBPutQuadvar1(db, "snvar", "Mesh", snvar, dims, 2, NULL, 0, DB_SHORT, DB_NODECENT, NULL);
  DBPutQuadvar1(db, "invar", "Mesh", invar, dims, 2, NULL, 0, DB_INT, DB_NODECENT, NULL);
  DBPutQuadvar1(db, "lnvar", "Mesh", lnvar, dims, 2, NULL, 0, DB_LONG, DB_NODECENT, NULL);
  DBPutQuadvar1(db, "Lnvar", "Mesh", Lnvar, dims, 2, NULL, 0, DB_LONG_LONG, DB_NODECENT, NULL);
  DBPutQuadvar1(db, "fnvar", "Mesh", fnvar, dims, 2, NULL, 0, DB_FLOAT, DB_NODECENT, NULL);
  DBPutQuadvar1(db, "dnvar", "Mesh", dnvar, dims, 2, NULL, 0, DB_DOUBLE, DB_NODECENT, NULL);
  free(cnvar);
  free(snvar);
  free(invar);
  free(lnvar);
  free(Lnvar);
  free(fnvar);
  free(dnvar);

  /* test writing a quadvar with many components */
  varnames[0] = "u0";
  varnames[1] = "v0";
  varnames[2] = "u1";
  varnames[3] = "v1";
  varnames[4] = "u2";
  varnames[5] = "v2";
  varbufs[0] = f1;
  varbufs[1] = f2;
  varbufs[2] = f1;
  varbufs[3] = f2;
  varbufs[4] = f1;
  varbufs[5] = f2;
  DBPutQuadvar(db, "manyc", "Mesh", 6, (DBCAS_t) varnames,
      varbufs, dims, 2, NULL, 0, DB_FLOAT, DB_NODECENT, NULL);

  /* do Zone vars */

  dims[0]--;
  dims[1]--;

  czvar = (char *)        malloc(sizeof(char)*nzones); 
  szvar = (short *)       malloc(sizeof(short)*nzones); 
  izvar = (int *)         malloc(sizeof(int)*nzones); 
  lzvar = (long *)        malloc(sizeof(long)*nzones); 
  Lzvar = (long long *)   malloc(sizeof(long long)*nzones); 
  fzvar = (float *)       malloc(sizeof(float)*nzones); 
  dzvar = (double *)      malloc(sizeof(double)*nzones); 
  c=0;
  for (x=0;x<mesh.zx;x++) {
    for (y=0;y<mesh.zy;y++) {
      f1[c]=mesh.zone[x][y].vars[ZV_P];
      f2[c]=mesh.zone[x][y].vars[ZV_D];
      czvar[c] = (char)        (x<y?x:y);
      szvar[c] = (short)       (x<y?x:y);
      izvar[c] = (int)         (x<y?x:y);
      lzvar[c] = (long)        (x<y?x:y);
      Lzvar[c] = (long long)   (x<y?x:y);
      fzvar[c] = (float)       (x<y?x:y);
      dzvar[c] = (double)      (x<y?x:y);
      c++;
    }
  }

  for (c=0; c<mixc; c++)
      fm[c] = 2.0/mixc*c;
  if (reorder)
  {
    float tmp=fm[mixc-1];
    fm[mixc-1]=fm[mixc-2];
    fm[mixc-2]=tmp;
  }

  DBPutQuadvar1(db, "p", "Mesh", f1, dims, 2, NULL, 0, DB_FLOAT, DB_ZONECENT, NULL);
  DBPutQuadvar1(db, "d", "Mesh", f2, dims, 2, fm, mixc, DB_FLOAT, DB_ZONECENT, NULL);
  DBPutQuadvar1(db, "czvar", "Mesh", czvar, dims, 2, NULL, 0, DB_CHAR, DB_ZONECENT, NULL);
  DBPutQuadvar1(db, "szvar", "Mesh", szvar, dims, 2, NULL, 0, DB_SHORT, DB_ZONECENT, NULL);
  DBPutQuadvar1(db, "izvar", "Mesh", izvar, dims, 2, NULL, 0, DB_INT, DB_ZONECENT, NULL);
  DBPutQuadvar1(db, "lzvar", "Mesh", lzvar, dims, 2, NULL, 0, DB_LONG, DB_ZONECENT, NULL);
  DBPutQuadvar1(db, "Lzvar", "Mesh", Lzvar, dims, 2, NULL, 0, DB_LONG_LONG, DB_ZONECENT, NULL);
  DBPutQuadvar1(db, "fzvar", "Mesh", fzvar, dims, 2, NULL, 0, DB_FLOAT, DB_ZONECENT, NULL);
  DBPutQuadvar1(db, "dzvar", "Mesh", dzvar, dims, 2, NULL, 0, DB_DOUBLE, DB_ZONECENT, NULL);
  free(czvar);
  free(szvar);
  free(izvar);
  free(lzvar);
  free(Lzvar);
  free(fzvar);
  free(dzvar);
}
コード例 #20
0
/*-------------------------------------------------------------------------
 * 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);
}
コード例 #21
0
/*----------------------------------------------------------------------------
 * Function: writemesh_curv2d()
 *
 * Inputs:   db (DBfile*): the Silo file handle
 *
 * Returns:  (void)
 *
 * Abstract: Write the mesh and variables stored in the global Mesh 
 *           to the Silo file as a quadmesh and quadvars
 *
 * Modifications:
 *---------------------------------------------------------------------------*/
void writemesh_curv2d(DBfile *db, int mixc, int reorder) {

  float f1[1000],f2[1000], fm[1000];
  int x,y,c;

  char  *coordnames[2];
  char  *varnames[6];
  void *varbufs[6];
  float *coord[2];
  int dims[2];

  char *cnvar, *czvar;
  short *snvar, *szvar;
  int *invar, *izvar;
  long *lnvar, *lzvar;
  long long *Lnvar, *Lzvar;
  float *fnvar, *fzvar;
  double *dnvar, *dzvar;

  int nnodes=mesh.nx*mesh.ny;
  int nzones=mesh.zx*mesh.zy;
  
  /* do mesh */
  c=0;
  for (x=0;x<mesh.nx;x++) {
    for (y=0;y<mesh.ny;y++) {
      f1[c]=mesh.node[x][y].x;
      f2[c]=mesh.node[x][y].y;
      c++;
    }
  }

  coordnames[0]=NEW(char,20);
  coordnames[1]=NEW(char,20);
  strcpy(coordnames[0],"x");
  strcpy(coordnames[1],"y");

  coord[0]=f1;
  coord[1]=f2;

  dims[0]=mesh.nx;
  dims[1]=mesh.ny;

  DBPutQuadmesh(db, "Mesh", coordnames, coord, dims, 2, 
		DB_FLOAT, DB_NONCOLLINEAR, NULL);


  /* do Node vars */

  cnvar = (char *)        malloc(sizeof(char)*nnodes); 
  snvar = (short *)       malloc(sizeof(short)*nnodes); 
  invar = (int *)         malloc(sizeof(int)*nnodes); 
  lnvar = (long *)        malloc(sizeof(long)*nnodes); 
  Lnvar = (long long *)   malloc(sizeof(long long)*nnodes); 
  fnvar = (float *)       malloc(sizeof(float)*nnodes); 
  dnvar = (double *)      malloc(sizeof(double)*nnodes); 
  c=0;
  for (x=0;x<mesh.nx;x++) {
    for (y=0;y<mesh.ny;y++) {
      f1[c]=mesh.node[x][y].vars[NV_U];
      f2[c]=mesh.node[x][y].vars[NV_V];
      cnvar[c] = (char)        (x<y?x:y);
      snvar[c] = (short)       (x<y?x:y);
      invar[c] = (int)         (x<y?x:y);
      lnvar[c] = (long)        (x<y?x:y);
      Lnvar[c] = (long long)   (x<y?x:y);
      fnvar[c] = (float)       (x<y?x:y);
      dnvar[c] = (double)      (x<y?x:y);
      c++;
    }
  }

  DBPutQuadvar1(db, "u", "Mesh", f1, dims, 2, NULL, 0, DB_FLOAT, DB_NODECENT, NULL);
  DBPutQuadvar1(db, "v", "Mesh", f2, dims, 2, NULL, 0, DB_FLOAT, DB_NODECENT, NULL);
  DBPutQuadvar1(db, "cnvar", "Mesh", cnvar, dims, 2, NULL, 0, DB_CHAR, DB_NODECENT, NULL);
  DBPutQuadvar1(db, "snvar", "Mesh", snvar, dims, 2, NULL, 0, DB_SHORT, DB_NODECENT, NULL);
  DBPutQuadvar1(db, "invar", "Mesh", invar, dims, 2, NULL, 0, DB_INT, DB_NODECENT, NULL);
  DBPutQuadvar1(db, "lnvar", "Mesh", lnvar, dims, 2, NULL, 0, DB_LONG, DB_NODECENT, NULL);
  DBPutQuadvar1(db, "Lnvar", "Mesh", Lnvar, dims, 2, NULL, 0, DB_LONG_LONG, DB_NODECENT, NULL);
  DBPutQuadvar1(db, "fnvar", "Mesh", fnvar, dims, 2, NULL, 0, DB_FLOAT, DB_NODECENT, NULL);
  DBPutQuadvar1(db, "dnvar", "Mesh", dnvar, dims, 2, NULL, 0, DB_DOUBLE, DB_NODECENT, NULL);
  free(cnvar);
  free(snvar);
  free(invar);
  free(lnvar);
  free(Lnvar);
  free(fnvar);
  free(dnvar);

  /* test writing a quadvar with many components */
  varnames[0] = "u0";
  varnames[1] = "v0";
  varnames[2] = "u1";
  varnames[3] = "v1";
  varnames[4] = "u2";
  varnames[5] = "v2";
  varbufs[0] = f1;
  varbufs[1] = f2;
  varbufs[2] = f1;
  varbufs[3] = f2;
  varbufs[4] = f1;
  varbufs[5] = f2;
  DBPutQuadvar(db, "manyc", "Mesh", 6, varnames, varbufs, dims, 2, NULL, 0,
    DB_FLOAT, DB_NODECENT, NULL);

  /* do Zone vars */

  dims[0]--;
  dims[1]--;

  czvar = (char *)        malloc(sizeof(char)*nzones); 
  szvar = (short *)       malloc(sizeof(short)*nzones); 
  izvar = (int *)         malloc(sizeof(int)*nzones); 
  lzvar = (long *)        malloc(sizeof(long)*nzones); 
  Lzvar = (long long *)   malloc(sizeof(long long)*nzones); 
  fzvar = (float *)       malloc(sizeof(float)*nzones); 
  dzvar = (double *)      malloc(sizeof(double)*nzones); 
  c=0;
  for (x=0;x<mesh.zx;x++) {
    for (y=0;y<mesh.zy;y++) {
      f1[c]=mesh.zone[x][y].vars[ZV_P];
      f2[c]=mesh.zone[x][y].vars[ZV_D];
      czvar[c] = (char)        (x<y?x:y);
      szvar[c] = (short)       (x<y?x:y);
      izvar[c] = (int)         (x<y?x:y);
      lzvar[c] = (long)        (x<y?x:y);
      Lzvar[c] = (long long)   (x<y?x:y);
      fzvar[c] = (float)       (x<y?x:y);
      dzvar[c] = (double)      (x<y?x:y);
      c++;
    }
  }

  for (c=0; c<mixc; c++)
      fm[c] = 2.0/mixc*c;
  if (reorder)
  {
    float tmp=fm[mixc-1];
    fm[mixc-1]=fm[mixc-2];
    fm[mixc-2]=tmp;
  }

  DBPutQuadvar1(db, "p", "Mesh", f1, dims, 2, NULL, 0, DB_FLOAT, DB_ZONECENT, NULL);
  DBPutQuadvar1(db, "d", "Mesh", f2, dims, 2, fm, mixc, DB_FLOAT, DB_ZONECENT, NULL);
  DBPutQuadvar1(db, "czvar", "Mesh", czvar, dims, 2, NULL, 0, DB_CHAR, DB_ZONECENT, NULL);
  DBPutQuadvar1(db, "szvar", "Mesh", szvar, dims, 2, NULL, 0, DB_SHORT, DB_ZONECENT, NULL);
  DBPutQuadvar1(db, "izvar", "Mesh", izvar, dims, 2, NULL, 0, DB_INT, DB_ZONECENT, NULL);
  DBPutQuadvar1(db, "lzvar", "Mesh", lzvar, dims, 2, NULL, 0, DB_LONG, DB_ZONECENT, NULL);
  DBPutQuadvar1(db, "Lzvar", "Mesh", Lzvar, dims, 2, NULL, 0, DB_LONG_LONG, DB_ZONECENT, NULL);
  DBPutQuadvar1(db, "fzvar", "Mesh", fzvar, dims, 2, NULL, 0, DB_FLOAT, DB_ZONECENT, NULL);
  DBPutQuadvar1(db, "dzvar", "Mesh", dzvar, dims, 2, NULL, 0, DB_DOUBLE, DB_ZONECENT, NULL);
  free(czvar);
  free(szvar);
  free(izvar);
  free(lzvar);
  free(Lzvar);
  free(fzvar);
  free(dzvar);
}
コード例 #22
0
ファイル: SubMesh.c プロジェクト: ngholka/patki-power
static void SubMesh_wtdomain_quad ( DBfile *idbid, Domain_t *domain, SubMesh_t *subm) {
   char *me = "SubMesh_wtdomain_quad";
   int i, j, k, m;
   int imax, jmax, kmax;
   int ii, jj, kk, ip;
   int error = 0;
   int dims[3];
   int node_c;
   int len = 0;
   int *ndx = NULL;
   double *x, *y, *z;
   double *val;
   double *coords[3];
   int gblk = domain->gblk;
   char name[MAXLINE];
   char meshnm[MAXLINE];
   UserList_t *ul;
   NodeWindow_t *ndxin;
   Extents_t ext1, ext2, ext3, newext;
      for(i=0; i<ndims; i++)
          dims[i] = 0;
      CPYEXT(ext2, gmap[gblk]);
      ndxin = subm->ndxin;
      m = 0;
      sprintf(meshnm, "SubMesh_%s", subm->name);
      while(ndxin != NULL){
          if(gmap[gblk].ublk == ndxin->ublk){
              CPYEXT(ext1, (*ndxin));
              len = extents_overlap(&ext2, &ext1, &ext3);
              if(len > 0){
                  sprintf(name,"SubMesh_%s_%d", subm->name, m);
                  dims[0] = ext3.imax - ext3.imin + 1;
                  dims[1] = ext3.jmax - ext3.jmin + 1;
                  if(ndims > 2)
                      dims[2] = ext3.kmax - ext3.kmin + 1;
             x   = MALLOT(double, len);
             y   = MALLOT(double, len);
             z   = MALLOT(double, len);
             val = MALLOT(double, len);
             TRSEXT(newext, ext3, gmap[gblk]);
             k = 0;
             if(ndims == 2){
                 for(jj = newext.jmin; jj <= newext.jmax; jj++){
                     for(ii = newext.imin; ii <= newext.imax; ii++){
                         ip = ii + domain->jp*jj;
                         x[k] = domain->x[ip];
                         y[k] = domain->y[ip];
                         k++;
                     }
                 }
                coords[0] = x;
                coords[1] = y;
                coords[2] = NULL;
             }
             else{
                for(kk = newext.kmin; kk <= newext.kmax; kk++){
                    for(jj = newext.jmin; jj <= newext.jmax; jj++){
                        for(ii = newext.imin; ii <= newext.imax; ii++){
                            ip = ii + domain->jp*jj + domain->kp*kk;
                            x[k] = domain->x[ip];
                            y[k] = domain->y[ip];
                            z[k] = domain->z[ip];
                            k++;
                        }
                    }
                }
                coords[0] = x;
                coords[1] = y;
                coords[2] = z;
             }
             error += DBPutQuadmesh(idbid, name, NULL, (float **) coords, dims,
                                ndims, DB_DOUBLE, DB_NONCOLLINEAR, NULL);
             ul = UserList_find(meshnm);
             while (ul != NULL) {
                char varn[MAXLINE];
                double *ptr = (double *)ProblemArray_ptr(ul->name, domain->hash);
                sprintf(varn,"SubMesh_%s_%s_%d",subm->name, ul->name, m);
                if (ptr != NULL) {
                   k = 0;
                   if(ndims == 2){
                         if((node_c = RGST_QUERY_OBJECT_ATTR(ul->name, "Nodal")) == TRUE){
                             jmax = newext.jmax;
                             imax = newext.imax;
                         }
                         else{
                             jmax = newext.jmax - 1;
                             imax = newext.imax - 1;
                         }
                         for(jj = newext.jmin; jj <= jmax; jj++){
                             for(ii = newext.imin; ii <= imax; ii++){
                                 ip = ii + domain->jp*jj;
                                 val[k] = ptr[ip];
                                 k++;
                             }
                         }
                     }
                   else{
                         if((node_c = RGST_QUERY_OBJECT_ATTR(ul->name, "Nodal")) == TRUE){
                             kmax = newext.kmax;
                             jmax = newext.jmax;
                             imax = newext.imax;
                         }
                         else{
                             kmax = newext.kmax - 1;
                             jmax = newext.jmax - 1;
                             imax = newext.imax - 1;
                         }
                        for(kk = newext.kmin; kk <= kmax; kk++){
                            for(jj = newext.jmin; jj <= jmax; jj++){
                                for(ii = newext.imin; ii <= imax; ii++){
                                    ip = ii + domain->jp*jj + domain->kp*kk;
                                    val[k] = ptr[ip];
                                    k++;
                                }
                            }
                        }
                   }
                   if(node_c)
                       error += DBPutQuadvar1(idbid, varn, name, (float *) val,
                                              dims, ndims, NULL, 0, DB_DOUBLE,
                                              DB_NODECENT, NULL);
                   else
                       error += DBPutQuadvar1(idbid, varn, name, (float *) val,
                                              dims, ndims, NULL, 0, DB_DOUBLE,
                                              DB_ZONECENT, NULL);
                }
                ul = ul->next;
             }
             FREEMEM(x);
             FREEMEM(y);
             FREEMEM(z);
             FREEMEM(val);
             FREEMEM(ndx);
          }
          m++;
       } 
コード例 #23
0
ファイル: silo.cpp プロジェクト: STEllAR-GROUP/octopus
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();
} // }}}
コード例 #24
0
ファイル: mat_3x3x3_3across.C プロジェクト: zetwal/visit
/*--------------------*/
int main(int argc, char **argv) {
    DBfile *db;
    int            i, driver = DB_PDB;
    char          *filename = "mat_3x3x3_3across.silo";
    char  *coordnames[3];
    float *coord[3];

    i=1;
    while (i < argc)
    {
        if (strcmp(argv[i], "-driver") == 0)
        {
            i++;

            if (strcmp(argv[i], "DB_HDF5") == 0)
            {
                driver = DB_HDF5;
            }
            else if (strcmp(argv[i], "DB_PDB") == 0)
            {
                driver = DB_PDB;
            }
            else
            {
               fprintf(stderr,"Uncrecognized driver name \"%s\"\n",
                   argv[i]);
               exit(-1);
            }
        }
        i++;
    }

  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 2d 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);



  char *expNames[3] = {"mat1", "mat2", "mat3"};
  char *expDefs[3] = {"matvf(<material>, 1)", "matvf(<material>, 2)", "matvf(<material>, 3)"};
  int   expTypes[3] = {DB_VARTYPE_SCALAR, DB_VARTYPE_SCALAR, DB_VARTYPE_SCALAR};
  DBoptlist *optlists[3] = {NULL, NULL, NULL};

  DBPutDefvars(db, "_visit_defvars", 3, expNames, expTypes, expDefs, optlists);

  DBClose(db);

  return 0;
}
コード例 #25
0
ファイル: spec.c プロジェクト: drhansj/polymec-dev
/*-------------------------------------------------------------------------
 * 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);
}