Skip to content

Commit

Permalink
update to support both "layered" binary files and flat binary files
Browse files Browse the repository at this point in the history
  • Loading branch information
jlarsen-usgs committed Feb 11, 2022
1 parent c2556ad commit 201971d
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions flopy/mf6/data/mffileaccess.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__(
self._simulation_data = simulation_data
self._path = path
self._current_key = current_key
self._pos = 0

@staticmethod
def _get_bintype(modelgrid):
Expand Down Expand Up @@ -408,18 +409,32 @@ def read_binary_data_from_file(
bintype=self._get_bintype(modelgrid), precision="double"
)
if read_multi_layer and len(data_shape) > 1:
all_data = np.empty(data_shape, numpy_type)
headers = []
layer_shape = data_shape[1:]
data_size = int(data_size / data_shape[0])
for index in range(0, data_shape[0]):
layer_data = self._read_binary_file_layer(
fd, fname, header_dtype, numpy_type, data_size, layer_shape
try:
all_data = np.empty(data_shape, numpy_type)
headers = []
layer_shape = data_shape[1:]
layer_data_size = int(data_size / data_shape[0])
for index in range(0, data_shape[0]):
layer_data = self._read_binary_file_layer(
fd,
fname,
header_dtype,
numpy_type,
layer_data_size,
layer_shape,
)
all_data[index, :] = layer_data[0]
headers.append(layer_data[1])
fd.close()
return all_data, headers
except MFDataException:
fd.seek(self._pos, 0)
bin_data = self._read_binary_file_layer(
fd, fname, header_dtype, numpy_type, data_size, data_shape
)
all_data[index, :] = layer_data[0]
headers.append(layer_data[1])
fd.close()
return all_data, headers
self._pos = fd.tell()
fd.close()
return bin_data
else:
bin_data = self._read_binary_file_layer(
fd, fname, header_dtype, numpy_type, data_size, data_shape
Expand Down

0 comments on commit 201971d

Please sign in to comment.