Commit a8495fc5 authored by js9's avatar js9

Making HDF5 readers close themselves properly upon errors. Also added

error detection and fixed a few bugs.


git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@9352 18c085ea-50e0-402c-830e-de6fd14e8384
parent 49cc44fa
......@@ -229,6 +229,9 @@ avtDatabaseFactory::SetDefaultFileOpenOptions(const FileOpenOptions &opts)
// Jeremy Meredith, Wed Jan 6 15:36:13 EST 2010
// Small fix to warning messages.
//
// Jeremy Meredith, Thu Jan 7 15:36:03 EST 2010
// Fixed a typo.
//
// ****************************************************************************
avtDatabase *
......@@ -529,7 +532,7 @@ avtDatabaseFactory::FileList(DatabasePluginManager *dbmgr,
}
CATCHALL
{
rv = false;
rv = NULL;
}
ENDTRY
}
......
......@@ -374,6 +374,9 @@ avtChomboFileFormat::ActivateTimestep(void)
// Gunther H. Weber, Tue Sep 15 11:26:12 PDT 2009
// Added support for 3D mappings for 2D files.
//
// Jeremy Meredith, Thu Jan 7 15:36:19 EST 2010
// Close all open ids when returning an exception.
//
// ****************************************************************************
extern "C" herr_t
......@@ -419,6 +422,7 @@ avtChomboFileFormat::InitializeReader(void)
hid_t slash = H5Gopen(file_handle, "/");
if (slash < 0)
{
H5Fclose(file_handle);
EXCEPTION1(InvalidDBTypeException, "Cannot be a Chombo file, must "
"have the \"/\" group.");
}
......@@ -450,6 +454,8 @@ avtChomboFileFormat::InitializeReader(void)
hid_t time_id = H5Aopen_name(slash, "time");
if (time_id < 0)
{
H5Gclose(slash);
H5Fclose(file_handle);
EXCEPTION1(InvalidDBTypeException, "Cannot be a Chombo file, must "
"have time in \"/\" group.");
}
......@@ -467,6 +473,8 @@ avtChomboFileFormat::InitializeReader(void)
hid_t cycle_id = H5Aopen_name(slash, "iteration");
if (cycle_id < 0)
{
H5Gclose(slash);
H5Fclose(file_handle);
EXCEPTION1(InvalidDBTypeException, "Cannot be a Chombo file, must "
"have iteration in \"/\" group.");
}
......@@ -486,6 +494,8 @@ avtChomboFileFormat::InitializeReader(void)
hid_t time_id = H5Aopen_name(slash, "data_centering");
if (time_id < 0)
{
H5Gclose(slash);
H5Fclose(file_handle);
EXCEPTION1(InvalidDBTypeException, "Cannot be a Chombo file, must "
"have data_centering in \"/\" group.");
}
......@@ -520,17 +530,21 @@ avtChomboFileFormat::InitializeReader(void)
hid_t nl_id = H5Aopen_name(slash, "num_levels");
if (nl_id < 0)
{
H5Gclose(slash);
H5Fclose(file_handle);
EXCEPTION1(InvalidDBTypeException, "Cannot be a Chombo file, must "
"have num_levels in \"/\" group.");
}
H5Aread(nl_id, H5T_NATIVE_INT, &num_levels);
H5Aclose(nl_id);
if (num_levels <= 0)
{
debug1 << "ERROR: Number of levels (" << num_levels
<< ") must be at least 1" << endl;
H5Gclose(slash);
H5Fclose(file_handle);
EXCEPTION1(InvalidFilesException, filenames[0]);
}
H5Aclose(nl_id);
//
// Determine how many variables there are.
......
......@@ -1497,6 +1497,9 @@ avtFLASHFileFormat::GetVectorVar(int visitDomain, const char *varname)
// Hank Childs, Tue Dec 15 14:02:40 PST 2009
// Calculate some data members here when we read the blocks.
//
// Jeremy Meredith, Thu Jan 7 15:36:19 EST 2010
// Close all open ids when returning an exception.
//
// ****************************************************************************
void
avtFLASHFileFormat::ReadAllMetaData()
......@@ -1528,6 +1531,7 @@ avtFLASHFileFormat::ReadAllMetaData()
if (numParticles == 0 && numBlocks == 0)
{
H5Fclose(fileId);
EXCEPTION1(InvalidFilesException, filename.c_str());
}
......@@ -1584,6 +1588,9 @@ avtFLASHFileFormat::ReadAllMetaData()
// Randy Hudson, Apr 4, 2007
// Added support for (old) files w/o "processor number".
//
// Jeremy Meredith, Thu Jan 7 15:36:19 EST 2010
// Close all open ids when returning an exception.
//
// ****************************************************************************
// Support for files w/o "processor number"
......@@ -1593,6 +1600,7 @@ void avtFLASHFileFormat::ReadProcessorNumbers()
if (rootId < 0)
{
debug5 << "[avtFLASHFileFormat::ReadProcessorNumbers] - Didn't open root group" << endl;
H5Fclose(fileId);
EXCEPTION1(InvalidFilesException, filename.c_str());
}
hsize_t num_obj;
......@@ -1600,6 +1608,8 @@ void avtFLASHFileFormat::ReadProcessorNumbers()
if (errId < 0)
{
debug5 << "[avtFLASHFileFormat::ReadProcessorNumbers] - Can't get # of objects in root group" << endl;
H5Gclose(rootId);
H5Fclose(fileId);
EXCEPTION1(InvalidFilesException, filename.c_str());
}
hsize_t idx;
......@@ -1628,6 +1638,7 @@ void avtFLASHFileFormat::ReadProcessorNumbers()
hid_t procnumId = H5Dopen(fileId, "processor number");
if (procnumId < 0)
{
H5Fclose(fileId);
EXCEPTION1(InvalidFilesException, filename.c_str());
}
......
......@@ -136,6 +136,9 @@ avtGTCFileFormat::FreeUpResources(void)
// Hank Childs, Wed Jul 9 06:34:05 PDT 2008
// Uncomment code disabling error printing.
//
// Jeremy Meredith, Thu Jan 7 15:36:19 EST 2010
// Close all open ids when returning an exception.
//
// ****************************************************************************
bool
......@@ -162,6 +165,7 @@ avtGTCFileFormat::Initialize()
if (particleHandle < 0)
{
debug4 << mName << "Could not open particle_data" << endl;
H5Fclose(fileHandle);
EXCEPTION1(InvalidDBTypeException, "Cannot be a GTC file, "
"since it is does not contain the dataset \"particle_data\"");
}
......
......@@ -120,6 +120,9 @@ static void dbg_string_attrib(hid_t id, const std::string &str)
// Tom Fogal, Wed Apr 29 16:11:41 MDT 2009
// Handle errors when reading string attributes.
//
// Jeremy Meredith, Thu Jan 7 15:36:19 EST 2010
// Close all open ids when returning an exception. Added error detection.
//
// ****************************************************************************
avtH5NimrodFileFormat::avtH5NimrodFileFormat (const char *filename):
......@@ -144,9 +147,21 @@ avtH5NimrodFileFormat::avtH5NimrodFileFormat (const char *filename):
dbg_string_attrib(root_id, "Description");
dbg_string_attrib(root_id, "Source");
H5NIMROD_read_attrib (root_id, "time", &time);
if (H5NIMROD_read_attrib (root_id, "time", &time) == H5NIMROD_ERR)
{
H5Gclose(root_id);
H5Fclose(file);
EXCEPTION1 (InvalidFilesException, filename);
}
debug5 << "time: " << time << std::endl;
hid_t grid_id = H5Gopen (file, "/GRID");
if (grid_id < 0)
{
H5Gclose(root_id);
H5Fclose(file);
EXCEPTION1 (InvalidFilesException, filename);
}
string_attrib = NULL;
H5NIMROD_read_string_attrib (grid_id, "Coordinate System", &string_attrib);
......@@ -156,6 +171,9 @@ avtH5NimrodFileFormat::avtH5NimrodFileFormat (const char *filename):
if (strstr(string_attrib, "Cartesian - XYZ") == NULL)
{
debug5 << "Cannot handle non cartesian coordinates" << std::endl;
H5Gclose(root_id);
H5Gclose(grid_id);
H5Fclose(file);
EXCEPTION2(UnexpectedValueException, "Cartesian - XYZ",
string_attrib);
}
......@@ -173,7 +191,11 @@ avtH5NimrodFileFormat::avtH5NimrodFileFormat (const char *filename):
{
structured = 0;
debug5 << "Cannot handle unstructured mesh" << std::endl;
EXCEPTION2 (UnexpectedValueException, "Structured", string_attrib);
H5Gclose(root_id);
H5Gclose(grid_id);
H5Fclose (file);
EXCEPTION2 (UnexpectedValueException, "Structured",
string_attrib ? string_attrib : "NULL");
}
if(string_attrib)
{
......@@ -186,6 +208,9 @@ avtH5NimrodFileFormat::avtH5NimrodFileFormat (const char *filename):
if (ndims != 3)
{
debug5 << "Cannot handle other than 3 dimensional data" << std::endl;
H5Gclose(root_id);
H5Gclose(grid_id);
H5Fclose (file);
EXCEPTION2 (UnexpectedValueException, 3, ndims);
}
// points
......@@ -375,8 +400,6 @@ avtH5NimrodFileFormat::PopulateDatabaseMetaData (avtDatabaseMetaData * md,
vtkDataSet *
avtH5NimrodFileFormat::GetMesh (int timestate, const char *meshname)
{
//YOU MUST IMPLEMENT THIS
vtkStructuredGrid *dataset = vtkStructuredGrid::New ();
vtkPoints *vtkpoints = vtkPoints::New ();
vtkpoints->SetDataTypeToFloat ();
......
......@@ -65,6 +65,9 @@ using namespace std;
// Clean-up. Support files with only field data (and no particles). Do not
// allocate problem sized memory in constructor.
//
// Jeremy Meredith, Thu Jan 7 15:36:19 EST 2010
// Close all open ids when returning an exception. Added error detection.
//
// ****************************************************************************
avtH5PartFileFormat::avtH5PartFileFormat(const char *filename,
......@@ -137,6 +140,12 @@ avtH5PartFileFormat::avtH5PartFileFormat(const char *filename,
//point vars
int npointvars = H5PartGetNumDatasets(file); /* get number of datasets in timestep 0 */
if (npointvars<0)
{
H5PartCloseFile(file);
EXCEPTION1(VisItException, "Could not read number of datasets.");
}
pointvarnames.resize(npointvars);
debug5 << "constructor: nvariables: " << npointvars << "\n";
......@@ -168,7 +177,10 @@ avtH5PartFileFormat::avtH5PartFileFormat(const char *filename,
status = H5BlockGetFieldInfo (file, idx, name, lenName,
&gridRank, gridDims, &fieldDims);
if ( status != H5PART_SUCCESS )
{
H5PartCloseFile(file);
EXCEPTION1(VisItException, "Could not read field information.");
}
fieldNames.push_back(name);
fieldExtents.push_back((int)fieldDims);
......
......@@ -867,6 +867,9 @@ avtM3DFileFormat::ReadAttribute( hid_t parentID, const char *attr, void *value )
// Dave Pugmire, Tue Jul 21 16:23:42 EDT 2009
// Turn off 2D and 3D planes for now.
//
// Jeremy Meredith, Thu Jan 7 15:36:19 EST 2010
// Close all open ids when returning an exception. Added error detection.
//
// ****************************************************************************
void
avtM3DFileFormat::LoadFile()
......@@ -882,21 +885,36 @@ avtM3DFileFormat::LoadFile()
hid_t rootID = H5Gopen( m_fileID, "/" );
if ( rootID < 0 )
{
H5Fclose(m_fileID);
EXCEPTION2( UnexpectedValueException, "Root Group", "NOT FOUND" );
}
// Read XPClass name and check for validity.
string xpClass;
if ( ! ReadStringAttribute( rootID, "XP_CLASS", &xpClass ) || xpClass != m_XPClassStr)
{
H5Gclose(rootID);
H5Fclose(m_fileID);
EXCEPTION2( UnexpectedValueException, "XP_CLASS", "Not found or wrong type" );
}
// Read in step and time information.
int numTimeSteps;
if ( ! ReadAttribute( rootID, "nsteps", &numTimeSteps ) )
{
H5Gclose(rootID);
H5Fclose(m_fileID);
EXCEPTION2( UnexpectedValueException, "nsteps", "Not found or wrong type" );
}
float *times = new float[numTimeSteps];
if ( ! ReadAttribute( rootID, "time", times ) )
{
H5Gclose(rootID);
H5Fclose(m_fileID);
EXCEPTION2( UnexpectedValueException, "time", "Not found or wrong type" );
}
for ( int i = 0; i < numTimeSteps; i++ )
m_timeSteps.push_back( times[i] );
delete [] times;
......@@ -915,13 +933,25 @@ avtM3DFileFormat::LoadFile()
H5Gclose( groupid );
if ( ! ReadAttribute( rootID, "nnodes", &m_nNodes ) )
{
H5Gclose(rootID);
H5Fclose(m_fileID);
EXCEPTION2( UnexpectedValueException, "nnodes", "Not found or wrong type" );
}
if ( ! ReadAttribute( rootID, "ncell_sets", &m_nCellSets ) )
{
H5Gclose(rootID);
H5Fclose(m_fileID);
EXCEPTION2( UnexpectedValueException, "ncell_sets", "Not found or wrong type" );
}
if ( ! ReadAttribute( rootID, "nnode_data", &m_nVars ) )
{
H5Gclose(rootID);
H5Fclose(m_fileID);
EXCEPTION2( UnexpectedValueException, "nnode_data", "Not found or wrong type" );
}
//Load basic info on variables.
for ( int t = 0; t < m_timeSteps.size(); t++ )
......
......@@ -1368,6 +1368,9 @@ herr_t groupIterator(hid_t locId, const char* name, void* opdata) {
// Programmer: allen -- generated by xml2avt
// Creation: Tue Sep 25 08:49:28 PDT 2007
//
// Modifications:
// Jeremy Meredith, Thu Jan 7 15:36:19 EST 2010
// Close all open ids when returning an exception.
// ****************************************************************************
void
avtM3DC1FileFormat::LoadFile()
......@@ -1383,41 +1386,64 @@ avtM3DC1FileFormat::LoadFile()
hid_t rootID = H5Gopen( m_fileID, "/", H5P_DEFAULT);
if ( rootID < 0 )
{
H5Fclose(m_fileID);
EXCEPTION2( UnexpectedValueException, "Root Group", "NOT FOUND" );
}
// HEADER
// Read in step and time information.
int ntime;
if ( ! ReadAttribute( rootID, "ntime", &ntime ) )
{
H5Gclose(rootID);
H5Fclose(m_fileID);
EXCEPTION2( UnexpectedValueException, "ntime",
"Not found or wrong type" );
}
// Read in linear flag and ntor
int linear;
if ( ! ReadAttribute( rootID, "linear", &linear ) )
{
H5Gclose(rootID);
H5Fclose(m_fileID);
EXCEPTION2( UnexpectedValueException, "linear",
"Not found or wrong type" );
}
m_scalarVarNames.push_back("header/linear");
int ntor;
if ( ! ReadAttribute( rootID, "ntor", &ntor ) )
{
H5Gclose(rootID);
H5Fclose(m_fileID);
EXCEPTION2( UnexpectedValueException, "ntor",
"Not found or wrong type" );
}
m_scalarVarNames.push_back("header/ntor");
// Read in bzero and rzero
double bzero, rzero;
if ( ! ReadAttribute( rootID, "bzero", &bzero ) )
{
H5Gclose(rootID);
H5Fclose(m_fileID);
EXCEPTION2( UnexpectedValueException, "bzero",
"Not found or wrong type" );
}
m_scalarVarNames.push_back("header/bzero");
if ( ! ReadAttribute( rootID, "rzero", &rzero ) )
{
H5Gclose(rootID);
H5Fclose(m_fileID);
EXCEPTION2( UnexpectedValueException, "rzero",
"Not found or wrong type" );
}
m_scalarVarNames.push_back("header/rzero");
......@@ -1428,8 +1454,11 @@ avtM3DC1FileFormat::LoadFile()
// Read in equilibrium mesh element information.
hid_t groupId = H5Gopen( m_fileID, "/equilibrium/mesh", H5P_DEFAULT);
if ( groupId < 0 )
{
H5Fclose(m_fileID);
EXCEPTION2( UnexpectedValueException, "/equilibrium/mesh Group",
"NOT FOUND" );
}
if ( ! ReadAttribute( groupId, "nelms", &nelms ) )
EXCEPTION2( UnexpectedValueException, "nelms",
......
......@@ -152,6 +152,9 @@ avtPFLOTRANFileFormat::GetNTimesteps(void)
// Added an explicit conversion from a char* to a string to make the
// MIPSpro compiler happy.
//
// Jeremy Meredith, Thu Jan 7 15:36:19 EST 2010
// Close all open ids when returning an exception.
//
// ****************************************************************************
void
......@@ -178,6 +181,7 @@ avtPFLOTRANFileFormat::LoadFile(void)
hid_t coordsGID = H5Gopen(fileID, "Coordinates");
if (coordsGID < 0)
{
H5Fclose(fileID);
debug4 << "avtPFLOTRANFileFormat::LoadFile: " << "Could not open the Coordinates group in file " << filename << endl;
EXCEPTION1(InvalidDBTypeException, "Cannot be a PFLOTRAN file since it does not have a Coordinates group.");
}
......@@ -186,18 +190,21 @@ avtPFLOTRANFileFormat::LoadFile(void)
dimID[dim] = H5Dopen(coordsGID, coordNames[dim].c_str());
if (dimID[dim] < 0)
{
H5Fclose(fileID);
debug4 << "avtPFLOTRANFileFormat::LoadFile: " << "Could not open the " << coordNames[dim] << "dataset in file " << filename << endl;
EXCEPTION1(InvalidDBTypeException, "Cannot be a PFLOTRAN file since it does not have valid coordinates data.");
}
hid_t dimSpaceID = H5Dget_space(dimID[dim]);
if (dimSpaceID < 0)
{
H5Fclose(fileID);
debug4 << "avtPFLOTRANFileFormat::LoadFile: " << "Could not get the space information for the " << coordNames[dim] << " coordinate in file " << filename << endl;
EXCEPTION1(InvalidDBTypeException, "Cannot be a PFLOTRAN file since it does not have valid coordinates data.");
}
int ndims = H5Sget_simple_extent_ndims(dimSpaceID);
if (ndims != 1)
{
H5Fclose(fileID);
debug4 << "avtPFLOTRANFileFormat::LoadFile: " << "The " << coordNames[dim] << " coordinate is not one dimensional" << endl;
EXCEPTION1(InvalidDBTypeException, "Cannot be a PFLOTRAN file since some coordinate data is not one dimensional.");
}
......
......@@ -269,6 +269,9 @@ avtPixieFileFormat::FreeUpResources(void)
// Gunther H. Weber, Wed Oct 8 16:50:31 PDT 2008
// Added test for TechX VizSchema
//
// Jeremy Meredith, Thu Jan 7 15:36:19 EST 2010
// Close all open ids when returning an exception. Added error detection.
//
// ****************************************************************************
void
......@@ -300,6 +303,7 @@ avtPixieFileFormat::Initialize()
if (cell_array >= 0)
{
H5Dclose(cell_array);
H5Fclose(fileId);
EXCEPTION1(InvalidDBTypeException,
"Cannot be a Pixie file because it looks like a Tetrad file.");
}
......@@ -307,6 +311,7 @@ avtPixieFileFormat::Initialize()
if (control >= 0)
{
H5Dclose(control);
H5Fclose(fileId);
EXCEPTION1(InvalidDBTypeException,
"Cannot be a Pixie file because it looks like an UNIC file.");
}
......@@ -318,6 +323,7 @@ avtPixieFileFormat::Initialize()
{
H5Aclose(vsVersion);
H5Gclose(runInfo);
H5Fclose(fileId);
EXCEPTION1(InvalidDBTypeException,
"Cannot be a Pixie file because it looks like a VizSchema file.");
}
......@@ -327,6 +333,7 @@ avtPixieFileFormat::Initialize()
{
H5Aclose(vsVsVersion);
H5Gclose(runInfo);
H5Fclose(fileId);
EXCEPTION1(InvalidDBTypeException,
"Cannot be a Pixie file because it looks like a VizSchema file.");
}
......@@ -338,6 +345,7 @@ avtPixieFileFormat::Initialize()
{
H5Aclose(software);
H5Aclose(version);
H5Fclose(fileId);
EXCEPTION1(InvalidDBTypeException,
"Cannot be a Pixie file because it looks like a legacy VizSchema file.");
}
......@@ -349,6 +357,7 @@ avtPixieFileFormat::Initialize()
int gid;
if ((gid = H5Gopen(fileId, "/")) < 0)
{
H5Fclose(fileId);
EXCEPTION1(InvalidFilesException, (const char *)filenames[0]);
}
TraversalInfo info;
......@@ -1563,12 +1572,20 @@ avtPixieFileFormat::ReadCoordinateFields(int timestate, const VarInfo &info,
// Luis Chacon, Wed Feb 25 15:40:06 EST 2009
// Modified the reader to handle time-changing meshes.
//
// Jeremy Meredith, Thu Jan 7 15:35:18 EST 2010
// Skip ".." group names.
//
// ****************************************************************************
herr_t
avtPixieFileFormat::GetVariableList(hid_t group, const char *name,
void *op_data)
{
// Silo files have a ".." group. Don't process that.... Ideally we
// might detect and skip hard links, but this doesn't come up often.
if (string(name)=="..")
return 0;
hid_t obj;
H5G_stat_t statbuf;
......
......@@ -87,6 +87,9 @@ static int TimeIndexPairSorter(const void *, const void *);
// Hank Childs, Wed Jul 9 06:29:53 PDT 2008
// Don't print out a lot of error statements.
//
// Jeremy Meredith, Thu Jan 7 15:36:19 EST 2010
// Close all open ids when returning an exception.
//
// ****************************************************************************
avtTetradFileFormat::avtTetradFileFormat(const char *fname)
......@@ -103,6 +106,7 @@ avtTetradFileFormat::avtTetradFileFormat(const char *fname)
int cell_array = H5Dopen(file_handle, "CellArray");
if (cell_array < 0)
{
H5Fclose(file_handle);
EXCEPTION1(InvalidDBTypeException, "Cannot be a Tetrad file, since "
"it is does not contain the dataset \"cell_array\"");
}
......
......@@ -80,6 +80,10 @@ using std::string;
// Programmer: childs -- generated by xml2avt
// Creation: Wed Jul 9 07:28:15 PDT 2008
//
// Modifications:
// Jeremy Meredith, Thu Jan 7 15:36:19 EST 2010
// Close all open ids when returning an exception.
//
// ****************************************************************************
avtUNICFileFormat::avtUNICFileFormat(const char *filename)
......@@ -94,6 +98,7 @@ avtUNICFileFormat::avtUNICFileFormat(const char *filename)
int control = H5Dopen(file_handle, "CONTROL");
if (control < 0)
{
H5Fclose(file_handle);
EXCEPTION1(InvalidDBTypeException, "Cannot be a UNIC data file, since "
"it is not contain the dataset \"control\".");
}
......
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