Skip to content
Merged
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
43 changes: 29 additions & 14 deletions flopy/utils/util_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
import warnings
import numpy as np

try:
from numpy.lib import NumpyVersion
numpy114 = NumpyVersion(np.__version__) >= '1.14.0'
except ImportError:
numpy114 = False


class MfList(object):
"""
Expand Down Expand Up @@ -213,9 +219,10 @@ def mxact(self):
mxact = max(mxact, self.get_itmp(kper))
return mxact

# Get the numpy savetxt-style fmt string that corresponds to the dtype
@property
def fmt_string(self):
"""Returns a C-style fmt string for numpy savetxt that corresponds to
the dtype"""
if self.list_free_format is not None:
use_free = self.list_free_format
else:
Expand All @@ -225,32 +232,40 @@ def fmt_string(self):
# mt3d list data is fixed format
if 'mt3d' in self.package.parent.version.lower():
use_free = False
fmt_string = ''
fmts = []
for field in self.dtype.descr:
vtype = field[1][1].lower()
if vtype == 'i':
if use_free:
fmt_string += ' %9d'
fmts.append('%9d')
else:
fmt_string += '%10d'
fmts.append('%10d')
elif vtype == 'f':
if use_free:
fmt_string += ' %15.7E'
if numpy114:
# Use numpy's floating-point formatter (Dragon4)
fmts.append('%15s')
else:
fmts.append('%15.7E')
else:
fmt_string += '%10G'

fmts.append('%10G')
elif vtype == 'o':
if use_free:
fmt_string += ' %9s'
fmts.append('%9s')
else:
fmt_string += '%10s'
fmts.append('%10s')
elif vtype == 's':
raise Exception("MfList error: '\str\' type found it dtype." + \
" This gives unpredictable results when " + \
"recarray to file - change to \'object\' type")
raise TypeError(
"MfList.fmt_string error: 'str' type found in dtype. "
"This gives unpredictable results when "
"recarray to file - change to 'object' type")
else:
raise Exception("MfList.fmt_string error: unknown vtype " + \
"in dtype:" + vtype)
raise TypeError("MfList.fmt_string error: unknown vtype in "
"field: {}".format(field))
if use_free:
fmt_string = ' ' + ' '.join(fmts)
else:
fmt_string = ''.join(fmts)
return fmt_string

# Private method to cast the data argument
Expand Down