Skip to content

Commit

Permalink
Fix IPL float issue when using e syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrivenaes committed Dec 19, 2019
1 parent 589177e commit e6705dd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/fmu/config/_configparserfmu_ipl.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ def _freeform_handle_entry(variable, myvalue, myvalues, dtype, template):
# inner function
def _fixtheentry(variable, myval, subtype, count=None, template=False):

logger.info("Fix freeform entry %s", variable)
logger.info("Fix freeform entry %s (subtype %s)", variable, subtype)
tmpvalue = str(myval)
if "~" in tmpvalue:
val, var = tmpvalue.split("~")
Expand All @@ -414,6 +414,13 @@ def _fixtheentry(variable, myval, subtype, count=None, template=False):
if val in ("False", "no", "NO", "No", "false", "FALSE"):
val = "FALSE"

if subtype == "Float":
logger.info("Input float value is %s (%s)", val, variable)
if "e" in str(val).lower():
val = "{0:E}".format(float(val))

logger.info("Updated float value is %s (%s)", val, variable)

if subtype == "String":
val = '"{}"'.format(val)
if var:
Expand Down
14 changes: 11 additions & 3 deletions src/fmu/config/configparserfmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import datetime
import json

import pdb

# for ordered dicts!
from collections import OrderedDict, Counter

Expand Down Expand Up @@ -208,7 +210,7 @@ def to_yaml(
>>> config.to_yaml('global_variables', destination='../')
"""

logger.info("To YAML")
if not destination and not template:
raise ValueError(
"Both destination and template are None."
Expand All @@ -233,6 +235,8 @@ def to_yaml(
mystream = re.sub(r"\s+~", "~", mystream)
mystream = re.sub(r"~\s+", "~", mystream)

# pdb.set_trace()

cfg1 = self._get_dest_form(mystream)
cfg2 = self._get_tmpl_form(mystream)

Expand Down Expand Up @@ -622,7 +626,9 @@ def _get_required_form(stream, template=False, ipl=False):
def _get_tmpl_form(stream):
"""Get template form (<...> if present, not numbers)."""

pattern = "-*[a-zA-Z0-9.]+~"
pattern = "\\-*[\\-a-zA-Z0-9.]+~"

# pdb.set_trace()

if isinstance(stream, list):
logger.info("STREAM is a list object")
Expand All @@ -646,7 +652,8 @@ def _get_tmpl_form(stream):
def _get_dest_form(stream):
"""Get destination form (numbers, not <...>)"""

pattern = "~<.+?>"
logger.info("TRY DEST %s", stream)
pattern = "~.*<.+?>"

if isinstance(stream, list):
logger.info("STREAM is a list object")
Expand All @@ -662,4 +669,5 @@ def _get_dest_form(stream):
else:
raise ValueError("Input for templateconversion neither string " "or list")

logger.info("DEST %s", result)
return result

0 comments on commit e6705dd

Please sign in to comment.