On Wednesday 21 March 2012 09:37:51 [email protected] wrote:
An example would be very welcome. Now I have a new documentation withe more
then 250 pages to read; that's really heavy.
The best would be an example as in the examples code I am attaching to this
Email. THos is short C example which writes data to HDF5 and also creates teh
XML bases XDMF specification file. I can visualize these data using VisIt. I
would like to have such an example for several time steps, and for a mesh
including mesh refinement. Does exits such an example for silo?
Best wishes
Alexander
> The easiest way that I would suggest is to use the silo library. It
> will handle
> writing the hdf files for you.
>
> https://wci.llnl.gov/codes/silo/
>
> It works very well with VisIT.
>
> On 2012-03-21 08:46, Alexander Beck-Ratzka wrote:
> > On Wednesday 21 March 2012 14:05:04 Ekin Akoglu wrote:
> >
> > I am afraid I have not described what I want to have clear enough....
> >
> > I have a 3-d not always regular mesh (we are working with mesh
> > refinement). On
> > this mesh I have several variables, and again for each variable
> > several time
> > steps. To make plots of these variable, and also to create time
> > series plots I
> > would like to use VisIt, which uses XDMF as a reader for HDF5 data.
> >
> > In order to get the plots of VisIt correct, the HDF5 datasets must be
> > populated as follows:
> >
> > 1) x coordinates
> > 2) y coordinates
> > 3) z coordinates
> > (all the coordinates as 3-d arrays)
> >
> > and finally 4) the data.
> >
> > How can I add seveals time steps of these data? Must I always add the
> > coordinates in advance or not? Have I a possiblity to mark the time
> > step?
> >
> > The example given by Ekin only shows how to add one 3-d field,
> > nothing about
> > coordinates and about time steps. I hope my problem is more clear now
> > ..
> >
> > Best wishes
> >
> > Alexander
> >
> >> Dear Alexander,
> >>
> >> Please see if the attached example C code helps. It is an example
> >> from
> >> HDF web site.
> >>
> >> Best,
> >>
> >> Ekin
> >>
> >> On 03/21/2012 01:55 PM, Alexander Beck-Ratzka wrote:
> >> > Hi Folks,
> >> >
> >> > I am a newby in HDF5, and after having already successfully
> >>
> >> written (and
> >>
> >> > also plotted) one singel time step of a variable into an HDF5
> >>
> >> dataset,
> >>
> >> > I would like to know how I can write time series of a 3-d variable
> >>
> >> into
> >>
> >> > one single HDF5 dataset? Do I need to have the tiem as fouhrth
> >> > dimension?
> >> >
> >> > An explaing example in C would be welcome.
> >> >
> >> > Best wishes
> >> >
> >> > Alexander
> >> >
> >> >
> >> > _______________________________________________
> >> > Hdf-forum is for HDF software users discussion.
> >> > [email protected]
> >> > http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org
> >
> > _______________________________________________
> > Hdf-forum is for HDF software users discussion.
> > [email protected]
> > http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org
>
> _______________________________________________
> Hdf-forum is for HDF software users discussion.
> [email protected]
> http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <hdf5.h>
// The number of cells in the X, Y dimensions
#define NX 30
#define NY 20
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
void
write_hdf5_data()
{
hid_t file_id;
file_id = H5Fcreate("xdmf2d.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
// Create the coordinate data.
float *x = (float *) malloc((NX+1)*(NY+1) * sizeof(float));
float *y = (float *) malloc((NX+1)*(NY+1) * sizeof(float));
int ndx = 0;
for (int j = 0; j < NY+1; j++)
{
float yt = (float) j / (float) NY;
float angle = yt * M_PI;
for (int i = 0; i < NX+1; i++)
{
float xt = (float) i / (float) NX;
float R = (1.-xt)*2. + xt*5.;
x[ndx] = R * cos(angle);
y[ndx] = R * sin(angle);
ndx++;
}
}
// Create the scalar data.
float *pressure = (float *) malloc(NX*NY * sizeof(float));
for (int j = 0; j < NY; j++)
{
for (int i = 0; i < NX; i++)
{
int ndx = j * NX + i;
pressure[ndx] = (float) j;
}
}
float *velocityx = (float *) malloc((NX+1)*(NY+1) * sizeof(float));
for (int j = 0; j < NY+1; j++)
{
for (int i = 0; i < NX+1; i++)
{
int ndx = j * (NX+1) + i;
velocityx[ndx] = (float) i;
}
}
// Write the data file.
hid_t dataset_id, dataspace_id;
hsize_t dims[3];
herr_t status;
const char *coordNames[] = {"/X", "/Y"};
/* Write separate coordinate arrays for the x and y coordinates. */
for(int did = 0; did < 2; ++did)
{
dims[0] = (NY + 1);
dims[1] = (NX + 1);
dataspace_id = H5Screate_simple(2, dims, NULL);
dataset_id = H5Dcreate(file_id, coordNames[did], H5T_NATIVE_FLOAT, dataspace_id,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
status = H5Dwrite(dataset_id, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL,
H5P_DEFAULT, did == 0 ? x : y);
status = H5Dclose(dataset_id);
status = H5Sclose(dataspace_id);
}
// Write the scalar data.
dims[0] = NY;
dims[1] = NX;
dataspace_id = H5Screate_simple(2, dims, NULL);
dataset_id = H5Dcreate(file_id, "/Pressure", H5T_NATIVE_FLOAT,
dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
status = H5Dwrite(dataset_id, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL,
H5P_DEFAULT, pressure);
status = H5Dclose(dataset_id);
status = H5Sclose(dataspace_id);
dims[0] = NY + 1;
dims[1] = NX + 1;
dataspace_id = H5Screate_simple(2, dims, NULL);
dataset_id = H5Dcreate(file_id, "/VelocityX", H5T_NATIVE_FLOAT,
dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
status = H5Dwrite(dataset_id, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL,
H5P_DEFAULT, velocityx);
status = H5Dclose(dataset_id);
status = H5Sclose(dataspace_id);
// Free the data.
free(x);
free(y);
free(pressure);
free(velocityx);
status = H5Fclose(file_id);
}
void
write_xdmf_xml()
{
FILE *xmf = 0;
/*
* Open the file and write the XML description of the mesh..
*/
xmf = fopen("xdmf2d.xmf", "w");
fprintf(xmf, "<?xml version=\"1.0\" ?>\n");
fprintf(xmf, "<!DOCTYPE Xdmf SYSTEM \"Xdmf.dtd\" []>\n");
fprintf(xmf, "<Xdmf Version=\"2.0\">\n");
fprintf(xmf, " <Domain>\n");
fprintf(xmf, " <Grid Name=\"mesh1\" GridType=\"Uniform\">\n");
fprintf(xmf, " <Topology TopologyType=\"2DSMesh\" NumberOfElements=\"%d %d\"/>\n", NY+1, NX+1);
fprintf(xmf, " <Geometry GeometryType=\"X_Y\">\n");
fprintf(xmf, " <DataItem Dimensions=\"%d %d\" NumberType=\"Float\" Precision=\"4\" Format=\"HDF\">\n", (NY+1), (NX+1));
fprintf(xmf, " xdmf2d.h5:/X\n");
fprintf(xmf, " </DataItem>\n");
fprintf(xmf, " <DataItem Dimensions=\"%d %d\" NumberType=\"Float\" Precision=\"4\" Format=\"HDF\">\n", (NY+1), (NX+1));
fprintf(xmf, " xdmf2d.h5:/Y\n");
fprintf(xmf, " </DataItem>\n");
fprintf(xmf, " </Geometry>\n");
fprintf(xmf, " <Attribute Name=\"Pressure\" AttributeType=\"Scalar\" Center=\"Cell\">\n");
fprintf(xmf, " <DataItem Dimensions=\"%d %d\" NumberType=\"Float\" Precision=\"4\" Format=\"HDF\">\n", NY, NX);
fprintf(xmf, " xdmf2d.h5:/Pressure\n");
fprintf(xmf, " </DataItem>\n");
fprintf(xmf, " </Attribute>\n");
fprintf(xmf, " <Attribute Name=\"VelocityX\" AttributeType=\"Scalar\" Center=\"Node\">\n");
fprintf(xmf, " <DataItem Dimensions=\"%d %d\" NumberType=\"Float\" Precision=\"4\" Format=\"HDF\">\n", NY+1, NX+1);
fprintf(xmf, " xdmf2d.h5:/VelocityX\n");
fprintf(xmf, " </DataItem>\n");
fprintf(xmf, " </Attribute>\n");
fprintf(xmf, " </Grid>\n");
fprintf(xmf, " </Domain>\n");
fprintf(xmf, "</Xdmf>\n");
fclose(xmf);
}
int
main(int argc, char *argv[])
{
write_hdf5_data();
write_xdmf_xml();
return 0;
}
_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org