Skip to content

Commit

Permalink
Will now raise an exception so hdf5 errors may be trapped.
Browse files Browse the repository at this point in the history
  • Loading branch information
llnl-fesp committed Jun 23, 2020
1 parent f4254af commit 1878b7e
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions pyscripts/hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ def hdf5_restore(file):
"""
try:
hf = h5py.File(file, 'r')
except ValueError as error:
print("Couldn't open hdf5 file ", file)
print(error)
except:
print("Couldn't open hdf5 file ", file)
return False
raise

try:
dummy = hf['bbb'] # force an exception if the group not there
hfb = hf.get('bbb')
hdf5_restore_dump(file,hdffile=hf)
try:
hdf5_restore_dump(file,hdffile=hf)
except:
raise


except:
Expand Down Expand Up @@ -132,6 +132,7 @@ def hdf5_save(file, varlist=['bbb.ngs', 'bbb.ng',
except ValueError as error:
print("HDF5 file open failed to ", file)
print(error)
raise
except:
print("HDF5 file open failed to ", file)
raise
Expand All @@ -157,8 +158,10 @@ def hdf5_save(file, varlist=['bbb.ngs', 'bbb.ng',
except ValueError as error:
print("HDF5 write failed to ", file, ' var ', vt[1])
print(error)
raise
except:
print("HDF5 write failed to ", file, ' var ', vt[1])
raise

for lvt in addvarlist:
try:
Expand All @@ -181,10 +184,13 @@ def hdf5_save(file, varlist=['bbb.ngs', 'bbb.ng',
except ValueError as error:
print("HDF5 write failed to ", file, ' var ', vt[1])
print(error)
raise
except:
print("HDF5 write failed to ", file, ' var ', vt[1])
raise

hf.close()
return True


def hdf5_dump(file, packages=list_packages(objects=1), vars=None, globals=None):
Expand All @@ -198,8 +204,10 @@ def hdf5_dump(file, packages=list_packages(objects=1), vars=None, globals=None):
except ValueError as error:
print("Couldn't open hdf5 file ", file)
print(error)
raise
except:
print("Couldn't open hdf5 file ", file)
raise
for p in packages:
hfg = hf.create_group(p.name())
hfg.attrs['time'] = time.time()
Expand All @@ -219,8 +227,10 @@ def hdf5_dump(file, packages=list_packages(objects=1), vars=None, globals=None):
except ValueError as error:
print("Couldn't write out: "+p.name()+'.'+v)
print(error)
raise
except:
print("Couldn't write out: "+p.name()+'.'+v)
raise
else:
print(p.name()+'.'+v+" is not allocated")
if globals != None:
Expand All @@ -241,10 +251,13 @@ def hdf5_dump(file, packages=list_packages(objects=1), vars=None, globals=None):
except ValueError as error:
print("Couldn't write out: "+p.name()+'.'+v)
print(error)
raise
except:
print("Couldn't write out: "+p.name()+'.'+v)
raise

hf.close()
return True


def h5py_dataset_iterator(g, prefix=''):
Expand Down Expand Up @@ -300,8 +313,12 @@ def hdf5_restore_dump(file, scope=globals(),hdffile=None):
setattr(pck,vt[2],dset[()])
except:
print('Couldn\'t read dataset ', path)
raise
except:
print("Couldn't read hdf5 file ", file)
raise

if hdffile == None:
hf.close()

return True

0 comments on commit 1878b7e

Please sign in to comment.