Commit 0a2b981e authored by Dan Lipsa's avatar Dan Lipsa

Fix 'open an HDF5 file without H5F_CLOSE_SEMI' warning for Chombo and Enzo

parent 6de2bd2d
set(Kit_SRCS
vtkAvtFileFormatAlgorithm.h
vtkAvtFileFormatAlgorithm.cxx
vtkAvtMTSDFileFormatAlgorithm.h
vtkAvtMTSDFileFormatAlgorithm.cxx
vtkAvtMTMDFileFormatAlgorithm.h
vtkAvtMTMDFileFormatAlgorithm.cxx
vtkAvtSTSDFileFormatAlgorithm.h
vtkAvtSTSDFileFormatAlgorithm.cxx
vtkAvtSTMDFileFormatAlgorithm.h
vtkAvtSTMDFileFormatAlgorithm.cxx
vtkAvtFileFormatAlgorithm.cxx
vtkAvtMTSDFileFormatAlgorithm.cxx
vtkAvtMTMDFileFormatAlgorithm.cxx
vtkAvtSTSDFileFormatAlgorithm.cxx
vtkAvtSTMDFileFormatAlgorithm.cxx
)
set(FullPath_SRCS)
......
......@@ -956,5 +956,3 @@ void vtkAvtFileFormatAlgorithm::PrintSelf(ostream& os, vtkIndent indent)
this->Superclass::PrintSelf(os, indent);
os << indent << "Output Type: " << this->OutputType << "\n";
}
......@@ -30,8 +30,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
========================================================================*/
#ifndef _vtkVisItReader_h
#define _vtkVisItReader_h
#ifndef _vtkAvtFileFormatAlgorithm_h
#define _vtkAvtFileFormatAlgorithm_h
#include "vtkIOVisItBridgeModule.h" //for export macro
......@@ -74,7 +74,7 @@ public:
static vtkAvtFileFormatAlgorithm *New();
vtkTypeMacro(vtkAvtFileFormatAlgorithm,vtkCompositeDataSetAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Get the number of point or cell arrays available in the input.
int GetNumberOfPointArrays();
......@@ -147,7 +147,7 @@ protected:
// see algorithm for more info
virtual int FillOutputPortInformation(int port, vtkInformation* info);
//methods that setup selection arrays that the client will interact with
//methods that setup selection arrays that the client will interact with
void SetupDataArraySelections();
void SetupMeshSelections();
void SetupMaterialSelections();
......@@ -155,8 +155,8 @@ protected:
//method to setup the proper block bounds for the data.
//this method is needed to support dynamic block loading
//for certain streaming pipelines
virtual void SetupBlockBoundsInformation(vtkInformation *outInfo);
virtual void SetupBlockBoundsInformation(vtkInformation *outInfo);
//method setups the number of timesteps that the file has
void SetupTemporalInformation(vtkInformation *outInfo);
......
#ifndef _vtkFileCloseSemiProperty_h
#define _vtkFileCloseSemiProperty_h
/*
* Needs <hdf5.h>, so include this header only after you include the
* hdf5 header. Because you might need to select the right API for hdf5 (such
* as with H5_USE_16_API) the hdf5 header is not included here.
*/
class vtkFileCloseSemiProperty
{
public:
vtkFileCloseSemiProperty ()
{
this->Fapl = H5Pcreate(H5P_FILE_ACCESS);
H5Pset_fclose_degree(this->Fapl, H5F_CLOSE_SEMI);
}
~vtkFileCloseSemiProperty ()
{
H5Pclose(this->Fapl);
}
operator hid_t() const
{
return this->Fapl;
}
private:
hid_t Fapl;
};
#endif
......@@ -95,6 +95,7 @@
#define H5_USE_16_API
#include <hdf5.h>
#include <visit-hdf5.h>
#include "vtkFileCloseSemiProperty.h"
#include <boost/cstdint.hpp>
// using boost::boost::int32_t; // This conflicts with Visual Studio 10
using std::string;
......@@ -448,7 +449,8 @@ avtChomboFileFormat::InitializeReader(void)
//
// Open file
//
file_handle = H5Fopen(filenames[0], H5F_ACC_RDONLY, H5P_DEFAULT);
file_handle = H5Fopen(filenames[0], H5F_ACC_RDONLY,
vtkFileCloseSemiProperty ());
if (file_handle < 0)
{
EXCEPTION1(InvalidDBTypeException, "Cannot be a Chombo file, since "
......@@ -1344,7 +1346,7 @@ avtChomboFileFormat::InitializeReader(void)
VisItStat_t fs;
if (VisItStat(mappingFilename.c_str(), &fs) == 0)
{
hid_t mapping_file_handle = H5Fopen(mappingFilename.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
hid_t mapping_file_handle = H5Fopen(mappingFilename.c_str(), H5F_ACC_RDONLY, vtkFileCloseSemiProperty ());
if (mapping_file_handle > 0)
{
hid_t slash = H5Gopen(mapping_file_handle, "/");
......@@ -2620,7 +2622,8 @@ avtChomboFileFormat::GetMesh(int patch, const char *meshname)
if (file_handle < 0)
{
file_handle = H5Fopen(filenames[0], H5F_ACC_RDONLY, H5P_DEFAULT);
file_handle = H5Fopen(filenames[0], H5F_ACC_RDONLY,
vtkFileCloseSemiProperty ());
if (file_handle < 0)
{
EXCEPTION1(InvalidDBTypeException, "Cannot be a Chombo file, since "
......@@ -3084,7 +3087,8 @@ avtChomboFileFormat::GetVar(int patch, const char *varname)
SNPRINTF(name, 1024, "level_%d", level);
if (file_handle < 0)
{
file_handle = H5Fopen(filenames[0], H5F_ACC_RDONLY, H5P_DEFAULT);
file_handle = H5Fopen(filenames[0], H5F_ACC_RDONLY,
vtkFileCloseSemiProperty ());
if (file_handle < 0)
{
EXCEPTION1(InvalidDBTypeException, "Cannot be a Chombo file, since "
......@@ -3189,7 +3193,8 @@ avtChomboFileFormat::GetVar(int patch, const char *varname)
{
if (file_handle < 0)
{
file_handle = H5Fopen(filenames[0], H5F_ACC_RDONLY, H5P_DEFAULT);
file_handle = H5Fopen(filenames[0], H5F_ACC_RDONLY,
vtkFileCloseSemiProperty ());
if (file_handle < 0)
{
EXCEPTION1(InvalidDBTypeException, "Cannot be a Chombo file, since "
......@@ -3425,7 +3430,8 @@ avtChomboFileFormat::GetVectorVar(int patch, const char *varname)
SNPRINTF(name, 1024, "level_%d", level);
if (file_handle < 0)
{
file_handle = H5Fopen(filenames[0], H5F_ACC_RDONLY, H5P_DEFAULT);
file_handle = H5Fopen(filenames[0], H5F_ACC_RDONLY,
vtkFileCloseSemiProperty ());
if (file_handle < 0)
{
EXCEPTION1(InvalidDBTypeException, "Cannot be a Chombo file, since "
......
......@@ -80,6 +80,7 @@
#define H5_USE_16_API
#include <hdf5.h>
#include <visit-hdf5.h>
#include "vtkFileCloseSemiProperty.h"
#endif
using std::string;
......@@ -629,7 +630,8 @@ avtEnzoFileFormat::DetermineVariablesFromGridFile()
#endif
{
#ifdef HAVE_LIBHDF5
hid_t fileId = H5Fopen(gridFileName.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
hid_t fileId = H5Fopen(gridFileName.c_str(), H5F_ACC_RDONLY,
vtkFileCloseSemiProperty ());
if (fileId < 0)
{
#ifdef HAVE_LIBHDF4
......@@ -1434,7 +1436,8 @@ avtEnzoFileFormat::GetMesh(int domain, const char *meshname)
return NULL;
}
hid_t fileId = H5Fopen(particleFileName.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
hid_t fileId = H5Fopen(particleFileName.c_str(), H5F_ACC_RDONLY,
vtkFileCloseSemiProperty ());
if (fileId < 0)
{
EXCEPTION1(InvalidFilesException, particleFileName.c_str());
......@@ -1870,7 +1873,8 @@ avtEnzoFileFormat::GetVar(int domain, const char *varname)
// HDF5 STUFF
string gridFileName = grids[domain+1].gridFileName;
hid_t fileId = H5Fopen(gridFileName.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
hid_t fileId = H5Fopen(gridFileName.c_str(), H5F_ACC_RDONLY,
vtkFileCloseSemiProperty ());
if (fileId < 0)
{
EXCEPTION1(InvalidFilesException, gridFileName.c_str());
......
......@@ -61,6 +61,7 @@
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
using std::istringstream;
using std::string;
......@@ -133,10 +134,7 @@ avtLAMMPSDumpFileFormat::GetNTimesteps(void)
void
avtLAMMPSDumpFileFormat::FreeUpResources(void)
{
for (int i=0; i<vars.size(); i++)
vars[i].clear();
vars.clear();
varNames.clear();
atomVars.Clear();
}
......@@ -206,7 +204,7 @@ avtLAMMPSDumpFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md, int t
avtMeshMetaData *mmd_bbox = new avtMeshMetaData("unitCell", 1, 0,0,0,
3, 1,
AVT_UNSTRUCTURED_MESH);
AVT_POINT_MESH);
for (int i=0; i<9; i++)
mmd_bbox->unitCellVectors[i] = 0;
mmd_bbox->unitCellVectors[0] = xMax - xMin;
......@@ -231,13 +229,22 @@ avtLAMMPSDumpFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md, int t
mmd->unitCellOrigin[2] = zMin;
md->Add(mmd);
AddScalarVarToMetaData(md, "species", "mesh", AVT_NODECENT);
for (int v=0; v<nVars; v++)
{
if (v == idIndex || v == speciesIndex)
continue;
AddScalarVarToMetaData(md, varNames[v], "mesh", AVT_NODECENT);
}
if(atomVars.HasIds())
{
AddScalarVarToMetaData(md, "id", "mesh", AVT_NODECENT);
}
if(atomVars.HasTypes())
{
AddScalarVarToMetaData(md, "species", "mesh", AVT_NODECENT);
}
for(AtomInfo::name_iterator v = atomVars.GetVariableNamesBegin();
v != atomVars.GetVariableNamesEnd();
++v)
{
AddScalarVarToMetaData(md, *v, "mesh", AVT_NODECENT);
}
md->SetCycles(cycles);
md->SetCyclesAreAccurate(true);
......@@ -302,35 +309,35 @@ avtLAMMPSDumpFileFormat::GetMesh(int timestep, const char *name)
z = zMax;
pts->SetPoint(j, x,y,z);
}
vtkCellArray *lines = vtkCellArray::New();
pd->SetLines(lines);
lines->Delete();
for (int k = 0 ; k < 12 ; k++)
{
lines->InsertNextCell(2);
lines->InsertCellPoint(voxVerticesFromEdges[k][0]);
lines->InsertCellPoint(voxVerticesFromEdges[k][1]);
}
lines->FastDelete();
return pd;
}
if (meshname != "mesh")
{
return NULL;
}
vtkPolyData *pd = vtkPolyData::New();
vtkPoints *pts = vtkPoints::New();
pts->SetNumberOfPoints(nAtoms[timestep]);
pd->SetPoints(pts);
pts->Delete();
for (int j = 0 ; j < nAtoms[timestep] ; j++)
for (vtkIdType j = 0 ; j < nAtoms[timestep] ; j++)
{
double x = vars[xIndex][j];
double y = vars[yIndex][j];
double z = vars[zIndex][j];
double x = atomVars[xIndex][j];
double y = atomVars[yIndex][j];
double z = atomVars[zIndex][j];
if (xScaled)
x = xMin + (xMax-xMin) * x;
if (yScaled)
......@@ -339,16 +346,30 @@ avtLAMMPSDumpFileFormat::GetMesh(int timestep, const char *name)
z = zMin + (zMax-zMin) * z;
pts->SetPoint(j, x, y, z);
}
vtkCellArray *verts = vtkCellArray::New();
pd->SetVerts(verts);
verts->Delete();
for (int k = 0 ; k < nAtoms[timestep] ; k++)
pd->SetPoints(pts);
pts->FastDelete();
const vtkIdType numCells = nAtoms[timestep];
const vtkIdType arrayLen = numCells * 2; //since these are verts
vtkIdTypeArray* rawCellArray = vtkIdTypeArray::New();
rawCellArray->SetNumberOfValues(arrayLen);
vtkIdType pointId=0;
for (vtkIdType k = 0 ; k < arrayLen ; k+=2,++pointId)
{
verts->InsertNextCell(1);
verts->InsertCellPoint(k);
rawCellArray->SetValue(k,1);
rawCellArray->SetValue(k+1,pointId);
}
vtkCellArray *verts = vtkCellArray::New();
verts->SetCells(numCells,rawCellArray);
pd->SetVerts(verts);
rawCellArray->FastDelete();
verts->FastDelete();
return pd;
}
......@@ -387,26 +408,24 @@ avtLAMMPSDumpFileFormat::GetVar(int timestep, const char *varname)
// element is a built-in variable
if (string(varname) == "species")
{
vtkFloatArray *scalars = vtkFloatArray::New();
scalars->SetNumberOfTuples(nAtoms[timestep]);
float *ptr = (float *) scalars->GetVoidPointer(0);
for (int i=0; i<nAtoms[timestep]; i++)
{
ptr[i] = speciesVar[i];
}
return scalars;
vtkIntArray *species = vtkIntArray::New();
species->SetNumberOfTuples(nAtoms[timestep]);
int *ptr = (int *) species->GetVoidPointer(0);
std::copy(atomVars.GetTypes().begin(), atomVars.GetTypes().end(),ptr);
return species;
}
int varIndex = -1;
for (int v=0; v<nVars; v++)
else if (string(varname) == "id")
{
if (varNames[v] == varname)
{
varIndex = v;
break;
}
vtkIntArray *ids = vtkIntArray::New();
ids->SetNumberOfTuples(nAtoms[timestep]);
int *ptr = (int *) ids->GetVoidPointer(0);
std::copy(atomVars.GetIds().begin(), atomVars.GetIds().end(),ptr);
return ids;
}
int varIndex = atomVars.GetVarIndex(varname);
if (varIndex == -1)
{
EXCEPTION1(InvalidVariableException, varname);
......@@ -416,10 +435,7 @@ avtLAMMPSDumpFileFormat::GetVar(int timestep, const char *varname)
vtkFloatArray *scalars = vtkFloatArray::New();
scalars->SetNumberOfTuples(nAtoms[timestep]);
float *ptr = (float *) scalars->GetVoidPointer(0);
for (int i=0; i<nAtoms[timestep]; i++)
{
ptr[i] = vars[varIndex][i];
}
std::copy(atomVars[varIndex].begin(),atomVars[varIndex].end(),ptr);
return scalars;
}
......@@ -485,42 +501,44 @@ avtLAMMPSDumpFileFormat::ReadTimeStep(int timestep)
OpenFileAtBeginning();
in.seekg(file_positions[timestep]);
speciesVar.resize(nAtoms[timestep]);
for (int v=0; v<vars.size(); v++)
{
// id and species are ints; don't bother with the float arrays for them
if (v == idIndex || v == speciesIndex)
continue;
vars[v].resize(nAtoms[timestep]);
}
std::vector<double> tmpVars(nVars);
int tmpID, tmpSpecies;
atomVars.SetNumberOfAtoms(nAtoms[timestep]);
int tmpID=0, tmpSpecies=0;
char buff[1000];
// read all the atoms
// the atoms aren't in ascending id order. Instead
// they are just N atoms with unique ids that can be any positive value
// for now we drop the ids completely
for (int a=0; a<nAtoms[timestep]; a++)
{
in.getline(buff,1000);
istringstream sin(buff);
for (int v=0; v<nVars; v++)
{
if (v==speciesIndex)
sin >> tmpSpecies;
else if (v==idIndex)
sin >> tmpID;
else
sin >> tmpVars[v];
}
--tmpID; // 1-origin; we need 0-origin
for (int v=0; v<nVars; v++)
int lineIndex=0;
int atomVarIndex=0;
while(sin.good())
{
if (v == idIndex || v == speciesIndex)
continue;
vars[v][tmpID] = tmpVars[v];
if (lineIndex==speciesIndex)
{
sin >> tmpSpecies;
atomVars.SetType(a,tmpSpecies-1);
}
else if (lineIndex == idIndex)
{
//skip the id
//they arent consecutive or all below the number
//of atoms + 1
sin >> tmpID;
atomVars.SetId(a,tmpID);
}
else
{
sin >> atomVars[atomVarIndex][a];
++atomVarIndex;
}
++lineIndex;
}
speciesVar[tmpID] = tmpSpecies - 1;
}
}
......@@ -567,7 +585,6 @@ avtLAMMPSDumpFileFormat::ReadAllMetaData()
char buff[1000];
nTimeSteps = 0;
nVars = -1;
while (in)
{
......@@ -607,54 +624,57 @@ avtLAMMPSDumpFileFormat::ReadAllMetaData()
{
istream::pos_type current_pos = in.tellg();
file_positions.push_back(current_pos);
if (nVars == -1)
if (atomVars.GetNumberOfVariables() == 0)
{
istringstream sin(&buff[11]);
string varName;
xScaled = yScaled = zScaled = false;
int variableIndex = 0;
int lineIndex = 0;
while (sin >> varName)
{
if (varName == "id")
idIndex = (int)varNames.size();
idIndex = lineIndex;
else if (varName == "type")
speciesIndex = (int)varNames.size();
else if (varName == "x" || varName == "xs" ||
speciesIndex = lineIndex;
else if (varName == "x" || varName == "xs" ||
varName == "xu" || varName == "xsu" )
xIndex = (int)varNames.size();
xIndex = variableIndex++;
else if (varName == "y" || varName == "ys" ||
varName == "yu" || varName == "ysu" )
yIndex = (int)varNames.size();
yIndex = variableIndex++;
else if (varName == "z" || varName == "zs" ||
varName == "zu" || varName == "zsu" )
zIndex = (int)varNames.size();
zIndex = variableIndex++;
if (varName == "xs" || "xsu")
if (varName == "xs" || varName == "xsu")
xScaled = true;
if (varName == "ys" || "ysu")
if (varName == "ys" || varName == "ysu")
yScaled = true;
if (varName == "zs" || "zsu")
if (varName == "zs" || varName == "zsu")
zScaled = true;
varNames.push_back(varName);
atomVars.AddVariable(varName);
++lineIndex;
}
nVars = (int)varNames.size();
if (nVars == 0)
if (atomVars.GetNumberOfVariables() == 0)
{
// OLD FORMAT: Assume "id type x y z"
varNames.push_back("id");
varNames.push_back("type");
varNames.push_back("x");
varNames.push_back("y");
varNames.push_back("z");
atomVars.AddVariable("id");
atomVars.AddVariable("type");
atomVars.AddVariable("x");
atomVars.AddVariable("y");
atomVars.AddVariable("z");
idIndex = 0;
speciesIndex = 1;
xIndex = 2; xScaled = false;
yIndex = 3; yScaled = false;
zIndex = 4; zScaled = false;
nVars = (int)varNames.size();
//these indices are in the atomVars, id and species
//are line based indices
xIndex = 0; xScaled = false;
yIndex = 1; yScaled = false;
zIndex = 2; zScaled = false;
}
vars.resize(nVars);
}
}
}
......
......@@ -34,7 +34,92 @@
class avtLAMMPSDumpFileFormat : public avtMTSDFileFormat
{
public:
private:
struct AtomInfo
{
AtomInfo():vars(),names(),types(),ids(),
enableType(false),enableIds(false),numVars(0){}
void Clear()
{ vars.resize(0); names.resize(0); types.resize(0); ids.resize(0);
enableType = false; enableIds = false; numVars = 0;
};
void AddVariable(const std::string& name)
{
//if it is id or type we don't push back since it is stored separately
if(name == "id")
{
enableIds = true;
}
if(name == "type")
{
enableType = true;
}
else
{
names.push_back(name);
vars.resize(names.size());
}
++numVars;
}
int GetNumberOfVariables() const
{
return numVars;
}
void SetNumberOfAtoms(std::size_t size)
{
if(HasIds()) { ids.resize(size); }
if(HasTypes()) { types.resize(size); }
for(std::size_t i=0; i < vars.size(); ++i) { vars[i].resize(size); }
}
//helper methods to get the variable names
typedef std::vector<std::string>::const_iterator name_iterator;
name_iterator GetVariableNamesBegin() const { return names.begin(); }
name_iterator GetVariableNamesEnd() const { return names.end(); }
int GetVarIndex(const std::string& n) const</