Skip to content

Commit b67bee4

Browse files
feat(arrays): add model.free_format_npl to control values-per-line in free-format array output
When free_format_npl is set (e.g., model.free_format_npl = 10), free-format arrays are written with that many values per line instead of all values on a single line. This produces block-format output matching Groundwater Vistas style, improving readability for large unstructured models. Affects both INTERNAL arrays (Util2d.string) and EXTERNAL/OPENCLOSE arrays (Util2d.get_file_entry). Default is None (no change in behavior).
1 parent ae1533f commit b67bee4

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

flopy/mbase.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ def __init__(
453453
# external option stuff
454454
self.array_free_format = True
455455
self.free_format_input = True
456+
self.free_format_npl = None
456457
self.parameter_load = False
457458
self.array_format = None
458459
self.external_fnames = []

flopy/utils/util_array.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2475,11 +2475,23 @@ def get_file_entry(self, how=None):
24752475
self.shape, self.python_file_path, self._array, bintype="head"
24762476
)
24772477
else:
2478+
# Override npl for free format if model specifies free_format_npl
2479+
python_format = None
2480+
if (
2481+
self.format.free
2482+
and self._model is not None
2483+
and getattr(self._model, "free_format_npl", None) is not None
2484+
):
2485+
python_format = (
2486+
self._model.free_format_npl,
2487+
self.format.py[1],
2488+
)
24782489
self.write_txt(
24792490
self.shape,
24802491
self.python_file_path,
24812492
self._array,
24822493
fortran_format=self.format.fortran,
2494+
python_format=python_format,
24832495
)
24842496

24852497
elif self.__value != self.python_file_path:
@@ -2536,8 +2548,16 @@ def string(self):
25362548
25372549
"""
25382550
# convert array to string with specified format
2551+
python_format = self.format.py
2552+
# Override npl for free format if model specifies free_format_npl
2553+
if (
2554+
self.format.free
2555+
and self._model is not None
2556+
and getattr(self._model, "free_format_npl", None) is not None
2557+
):
2558+
python_format = (self._model.free_format_npl, python_format[1])
25392559
a_string = self.array2string(
2540-
self.shape, self._array, python_format=self.format.py
2560+
self.shape, self._array, python_format=python_format
25412561
)
25422562
return a_string
25432563

0 commit comments

Comments
 (0)