Skip to content

Commit 1026362

Browse files
authored
Merge pull request #2478 from mjreno/grb_string
feat(grb): support reading data strings from binary grid file
2 parents 0eba4ba + 378684f commit 1026362

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

flopy/mf6/utils/binarygrid_util.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ def __init__(self, filename, precision="double", verbose=False):
9696
# read text strings
9797
for idx in range(self._ntxt):
9898
line = self.read_text(self._lentxt).strip()
99+
if line.startswith("#"):
100+
continue
99101
t = line.split()
100102
key = t[0]
101103
dt = t[1]
@@ -105,6 +107,8 @@ def __init__(self, filename, precision="double", verbose=False):
105107
dtype = np.float32
106108
elif dt == "DOUBLE":
107109
dtype = np.float64
110+
elif dt == "CHARACTER":
111+
dtype = str
108112
else:
109113
dtype = None
110114
nd = int(t[3])
@@ -122,7 +126,7 @@ def __init__(self, filename, precision="double", verbose=False):
122126
print(f" File contains data for {key} with shape {s}")
123127

124128
if self.verbose:
125-
print(f"Attempting to read {self._ntxt} records from {filename}")
129+
print(f"Attempting to read {len(self._recordkeys)} records from {filename}")
126130

127131
for key in self._recordkeys:
128132
if self.verbose:
@@ -133,7 +137,10 @@ def __init__(self, filename, precision="double", verbose=False):
133137
count = 1
134138
for v in shp:
135139
count *= v
136-
v = self.read_record(count=count, dtype=dt)
140+
if dt == str:
141+
v = self.read_text(nchar=count)
142+
else:
143+
v = self.read_record(count=count, dtype=dt)
137144
# read variable data
138145
else:
139146
if dt == np.int32:

0 commit comments

Comments
 (0)