Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions flopy/mfusg/mfusg.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,22 +535,29 @@ def _send_load_messages(model, files_successfully_loaded, files_not_loaded):
print(f" {os.path.basename(fname)}")


def fmt_string(array):
def fmt_string(array, free=False):
"""
Returns a C-style fmt string for numpy savetxt that corresponds to
the dtype.

Parameters
----------
array : numpy array
free : bool, optional
If True, use high-precision format (%16.9G) for floats which requires
FREE format in the BAS file. If False (default), use fixed 10-character
format (%10.2e) compatible with MODFLOW-USG's fixed-width input format.
"""
fmts = []
# When FREE format is enabled in BAS, we can use high-precision output.
# Without FREE, MODFLOW-USG expects 10-character fixed-width fields.
float_fmt = "%16.9G" if free else "%10.2e"
for field in array.dtype.descr:
vtype = field[1][1].lower()
if vtype in {"i", "b"}:
fmts.append("%10d")
elif vtype == "f":
fmts.append("%10.2e")
fmts.append(float_fmt)
elif vtype == "o":
fmts.append("%10s")
elif vtype == "s":
Expand Down
13 changes: 9 additions & 4 deletions flopy/mfusg/mfusgcln.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,18 +543,23 @@ def write_file(self, f=None, check=False):
f_cln.write(self.iac_cln.get_file_entry())
f_cln.write(self.ja_cln.get_file_entry())

np.savetxt(f_cln, self.node_prop, fmt=fmt_string(self.node_prop), delimiter="")
free = self.parent.free_format_input
np.savetxt(
f_cln, self.node_prop, fmt=fmt_string(self.node_prop, free), delimiter=""
)

np.savetxt(f_cln, self.cln_gwc, fmt=fmt_string(self.cln_gwc), delimiter="")
np.savetxt(
f_cln, self.cln_gwc, fmt=fmt_string(self.cln_gwc, free), delimiter=""
)

if self.nconduityp > 0:
np.savetxt(
f_cln, self.cln_circ, fmt=fmt_string(self.cln_circ), delimiter=""
f_cln, self.cln_circ, fmt=fmt_string(self.cln_circ, free), delimiter=""
)

if self.nrectyp > 0:
np.savetxt(
f_cln, self.cln_rect, fmt=fmt_string(self.cln_rect), delimiter=""
f_cln, self.cln_rect, fmt=fmt_string(self.cln_rect, free), delimiter=""
)

f_cln.write(self.ibound.get_file_entry())
Expand Down
Loading