Skip to content

bug: CLN package list output has no separator between fields #2788

Description

@jdhughes-dev

The CLN list arrays are written with np.savetxt(..., delimiter="") and a format string built by fmt_string, which joins the field formats with no separator. Fields are held apart only by the padding in each format, so a value that fills its width runs into the next value and the record can no longer be read with URWORD.

Affects the four np.savetxt calls in MfUsgCln.write_file, flopy/mfusg/mfusgcln.py:547-563 (node_prop, cln_gwc, cln_circ, cln_rect).

To reproduce

import sys
import numpy as np
from flopy.mfusg.cln_dtypes import MfUsgClnDtypes
from flopy.mfusg.mfusg import fmt_string

node_prop = np.zeros(1, dtype=MfUsgClnDtypes.get_clnnode_dtype())
node_prop[0]["ifno"] = 1234567890
node_prop[0]["iftyp"] = 1234567890
np.savetxt(sys.stdout, node_prop, fmt=fmt_string(node_prop, False), delimiter="")
12345678901234567890         0  0.00e+00 ...

The first two fields merge into one token, so the record has 13 tokens where the dtype has 14 fields.

Expected behavior

Every field is written as a separate token.

Additional context

Only the integer fields can fill their width. %10d is filled by a value of 1e9 or greater, or -1e8 or less. The float fields cannot fill theirs, because a float32 never produces more than 9 characters under %10.2e or 15 under %16.9G. A CLN model would therefore need on the order of 1e9 nodes to hit this, so it is a robustness problem rather than one that shows up in practice.

The GNC package writer had the same defect. It was fixed in #2787 by adding a sep argument to flopy.mfusg.mfusg.fmt_string, which defaults to the existing behavior, and writing the list with sep=" ". The same change applies here once that is merged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions