Commit 6b0dac6b authored by kicici's avatar kicici

HDF slice filename format option

parent b23564c0
......@@ -98,6 +98,8 @@ namespace SliceTypesMPI
};
}
enum class DumpSliceFilenameFormat { FNAME_SLICE_ID, SLICE_ID_FNAME };
///////////////////////////////////////////////////////////////////////////////
// Dumpers
//
......@@ -106,22 +108,24 @@ namespace SliceTypesMPI
// TStreamer::operate : Data access methods for read and write
// TStreamer::getAttributeName : Attribute name of the date ("Scalar", "Vector", "Tensor")
template<typename TStreamer, typename hdf5Real, typename TSlice>
void DumpSliceHDF5MPI(const TSlice& slice,
const int stepID,
const typename TSlice::GridType::Real t,
const std::string &fname,
const std::string &dpath = ".",
const bool bXMF = true)
void DumpSliceHDF5MPI(
const TSlice& slice,
const int stepID,
const typename TSlice::GridType::Real t,
const std::string &fname,
const std::string &dpath = ".",
const bool bXMF = true,
const DumpSliceFilenameFormat format = DumpSliceFilenameFormat::FNAME_SLICE_ID)
{
#ifdef CUBISM_USE_HDF
typedef typename TSlice::GridType::BlockType B;
// fname is the base filepath tail without file type extension and
// additional identifiers
std::ostringstream filename;
std::ostringstream fullpath;
filename << "slice_" << slice.id() << fname;
fullpath << dpath << "/" << filename.str();
const std::string filename = format == DumpSliceFilenameFormat::FNAME_SLICE_ID
? fname + "_slice" + std::to_string(slice.id())
: "slice_" + std::to_string(slice.id()) + fname;
std::string fullpath = dpath + "/" + filename;
static const unsigned int NCHANNELS = TStreamer::NCHANNELS;
const unsigned int width = slice.localWidth();
......@@ -144,7 +148,7 @@ void DumpSliceHDF5MPI(const TSlice& slice,
{
H5open();
fapl_id = H5Pcreate(H5P_FILE_ACCESS);
file_id = H5Fcreate((fullpath.str()+".h5").c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id);
file_id = H5Fcreate((fullpath+".h5").c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id);
status = H5Pclose(fapl_id);
for (size_t i = 0; i < 2; ++i)
......@@ -179,7 +183,7 @@ void DumpSliceHDF5MPI(const TSlice& slice,
H5open();
fapl_id = H5Pcreate(H5P_FILE_ACCESS);
status = H5Pset_fapl_mpio(fapl_id, comm, MPI_INFO_NULL); if(status<0) H5Eprint1(stdout);
file_id = H5Fopen((fullpath.str()+".h5").c_str(), H5F_ACC_RDWR, fapl_id);
file_id = H5Fopen((fullpath+".h5").c_str(), H5F_ACC_RDWR, fapl_id);
status = H5Pclose(fapl_id); if(status<0) H5Eprint1(stdout);
///////////////////////////////////////////////////////////////////////////
......@@ -250,7 +254,7 @@ void DumpSliceHDF5MPI(const TSlice& slice,
if (bXMF && 0 == myRank)
{
FILE *xmf = 0;
xmf = fopen((fullpath.str()+".xmf").c_str(), "w");
xmf = fopen((fullpath+".xmf").c_str(), "w");
fprintf(xmf, "<?xml version=\"1.0\" ?>\n");
fprintf(xmf, "<!DOCTYPE Xdmf SYSTEM \"Xdmf.dtd\" []>\n");
fprintf(xmf, "<Xdmf Version=\"2.0\">\n");
......@@ -263,15 +267,15 @@ void DumpSliceHDF5MPI(const TSlice& slice,
fprintf(xmf, " %e\n", 0.0);
fprintf(xmf, " </DataItem>\n");
fprintf(xmf, " <DataItem Name=\"mesh_vy\" Dimensions=\"%d\" NumberType=\"Float\" Precision=\"8\" Format=\"HDF\">\n", mesh_dims[0]);
fprintf(xmf, " %s:/vwidth\n",(filename.str()+".h5").c_str());
fprintf(xmf, " %s:/vwidth\n",(filename+".h5").c_str());
fprintf(xmf, " </DataItem>\n");
fprintf(xmf, " <DataItem Name=\"mesh_vz\" Dimensions=\"%d\" NumberType=\"Float\" Precision=\"8\" Format=\"HDF\">\n", mesh_dims[1]);
fprintf(xmf, " %s:/vheight\n",(filename.str()+".h5").c_str());
fprintf(xmf, " %s:/vheight\n",(filename+".h5").c_str());
fprintf(xmf, " </DataItem>\n");
fprintf(xmf, " </Geometry>\n\n");
fprintf(xmf, " <Attribute Name=\"data\" AttributeType=\"%s\" Center=\"Cell\">\n", TStreamer::getAttributeName());
fprintf(xmf, " <DataItem Dimensions=\"%d %d %d\" NumberType=\"Float\" Precision=\"%d\" Format=\"HDF\">\n", (int)dims[0], (int)dims[1], (int)dims[2], (int)sizeof(hdf5Real));
fprintf(xmf, " %s:/data\n",(filename.str()+".h5").c_str());
fprintf(xmf, " %s:/data\n",(filename+".h5").c_str());
fprintf(xmf, " </DataItem>\n");
fprintf(xmf, " </Attribute>\n");
fprintf(xmf, " </Grid>\n");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment