diff --git a/src/fmu/config/_configparserfmu_ipl.py b/src/fmu/config/_configparserfmu_ipl.py index 721809e..66833a3 100644 --- a/src/fmu/config/_configparserfmu_ipl.py +++ b/src/fmu/config/_configparserfmu_ipl.py @@ -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("~") @@ -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: diff --git a/src/fmu/config/configparserfmu.py b/src/fmu/config/configparserfmu.py index 1f52242..c2253c8 100644 --- a/src/fmu/config/configparserfmu.py +++ b/src/fmu/config/configparserfmu.py @@ -19,6 +19,8 @@ import datetime import json +import pdb + # for ordered dicts! from collections import OrderedDict, Counter @@ -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." @@ -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) @@ -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") @@ -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") @@ -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