Skip to content

Commit

Permalink
fix(comma delimited, scientific notation): modflowpy#2053 (modflowpy#…
Browse files Browse the repository at this point in the history
…2144)

* fix(comma delimited, scientific notation): modflowpy#2053

Fixed issue with flopy not reading a mix of space and comma delimited text and an issue where flopy does not read scientific notation when a capital "D" is used instead of "e" (1D-4).

* fix(formatting)

---------

Co-authored-by: scottrp <45947939+scottrp@users.noreply.github.com>
  • Loading branch information
spaulins-usgs and scottrp authored Apr 11, 2024
1 parent 9e87acd commit 5aaa5ff
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/data/mf6/test001a_Tharmonic/flow15.tdis
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ BEGIN Dimensions
END Dimensions

BEGIN PERIODDATA
1.00000000 1 1.00000000 Items: PERLEN NSTP TSMULT
1.00000000,1,1.00000000 Items: PERLEN NSTP TSMULT
END PERIODDATA
2 changes: 1 addition & 1 deletion examples/data/mf6/test001a_Tharmonic/flow15_constant.chd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ BEGIN Dimensions
END Dimensions

BEGIN Period 1
1 1 1 10.0000000
1 1 1 1D1
1 1 10 0.0000000
END Period
1 change: 1 addition & 0 deletions flopy/mf6/data/mfdatautil.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def convert_data(data, data_dimensions, data_type, data_item=None, sub_amt=1):
if isinstance(data, str):
# fix any scientific formatting that python can't handle
data = data.replace("d", "e")
data = data.replace("D", "e")
return float(data)
except (ValueError, TypeError):
try:
Expand Down
12 changes: 11 additions & 1 deletion flopy/utils/datautil.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,21 @@ def split_data_line(line, external_file=False, delimiter_conf_length=15):
max_split_type = delimiter
max_split_list = alt_split

if max_split_type is None and max_split_size > 0:
split_first = max_split_list[0].strip().split(",")
if len(split_first) > 1:
max_split_list = split_first + max_split_list[1:]
max_split_size = len(max_split_list)
max_split_type = "combo"

if max_split_type is not None and max_split_size > 1:
clean_line = max_split_list
if PyListUtil.line_num == 0:
PyListUtil.delimiter_used = max_split_type
elif PyListUtil.delimiter_used != max_split_type:
elif (
PyListUtil.delimiter_used != max_split_type
or max_split_type == "combo"
):
PyListUtil.consistent_delim = False
if max_split_size > 1:
PyListUtil.line_num += 1
Expand Down

0 comments on commit 5aaa5ff

Please sign in to comment.