Skip to content

Commit

Permalink
Add exception handling when hdf file is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielKotik committed Nov 29, 2018
1 parent d550e7f commit 4d5678f
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions Laguerre_Gauss_3d/plot_2d_matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import numpy as np
import h5py
import gc
import sys


def free_memory(*objects):
Expand Down Expand Up @@ -81,13 +82,21 @@ def free_memory(*objects):
filename_real = path + "e_real2_mixed-000001500.h5" # "e_real2_s-000010.00.h5"
filename_imag = path + "e_imag2_mixed-000001500.h5" # "e_imag2_s-000010.00.h5"

with h5py.File(filename_real, 'r') as hf:
# print("keys: %s" % hf.keys())
data_real = hf[list(hf.keys())[0]][:]

with h5py.File(filename_imag, 'r') as hf:
# print("keys: %s" % hf.keys())
data_imag = hf[list(hf.keys())[0]][:]
try:
with h5py.File(filename_real, 'r') as hf:
# print("keys: %s" % hf.keys())
data_real = hf[list(hf.keys())[0]][:]
except EnvironmentError as e:
print(e)
sys.exit()

try:
with h5py.File(filename_imag, 'r') as hf:
# print("keys: %s" % hf.keys())
data_imag = hf[list(hf.keys())[0]][:]
except EnvironmentError as e:
print(e)
sys.exit()

data = data_real + data_imag
free_memory("data_real", "data_imag")
Expand Down

0 comments on commit 4d5678f

Please sign in to comment.