From 26c388328264c03727ded9434491e27a2c683f24 Mon Sep 17 00:00:00 2001 From: Chris Green Date: Thu, 28 May 2026 07:26:33 +1000 Subject: [PATCH] Escapes quotes in units to correctly pick them up --- readers/eclipse.py | 9 +- test/eclipse/simple_cube_quoted_unit.grdecl | 105 ++++++++++++++++++++ test/eclipse/tests | 10 ++ 3 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 test/eclipse/simple_cube_quoted_unit.grdecl diff --git a/readers/eclipse.py b/readers/eclipse.py index ab219aa..b57aec6 100644 --- a/readers/eclipse.py +++ b/readers/eclipse.py @@ -163,8 +163,13 @@ def readEclipse(f, eclipse, extra_keywords=()): eclipse.mapaxes = readBlock(file) elif line.startswith('GRIDUNIT'): - eclipse.gridunit = next(file).split() - eclipse.gridunit.pop() + # Eclipse string keywords are conventionally written with + # single quotes (e.g. 'METRES' 'MAP' /). Strip the quotes so + # downstream comparisons against bare values like 'METRES' or + # 'GRID' work whether the file quotes the strings or not. + tokens = next(file).split() + tokens.pop() # drop the trailing '/' + eclipse.gridunit = [t.strip("'\"") for t in tokens] elif line.startswith('COORD') and 'COORDSYS' not in line: eclipse.coord = readBlock(file) diff --git a/test/eclipse/simple_cube_quoted_unit.grdecl b/test/eclipse/simple_cube_quoted_unit.grdecl new file mode 100644 index 0000000..b3d706e --- /dev/null +++ b/test/eclipse/simple_cube_quoted_unit.grdecl @@ -0,0 +1,105 @@ +-- Same numbers as simple_cube.grdecl but with the GRIDUNIT value quoted +-- ('METRES' rather than METRES) -- the convention many real-world tools +-- (e.g. Petrel) emit. The output should be identical to simple_cube.e; +-- if the reader fails to strip the quotes, the unit check misfires and +-- triggers a spurious "unrecognised GRIDUNIT" info note. + +SPECGRID +3 3 3 1 F / + +GRIDUNIT + 'METRES' / + +COORD + 0.000 0.000 0.000 0.000 0.000 1.000 + 0.500 0.000 0.000 0.500 0.000 1.000 + 1.000 0.000 0.000 1.000 0.000 1.000 + 1.500 0.000 0.000 1.500 0.000 1.000 + 0.000 0.500 0.000 0.000 0.500 1.000 + 0.500 0.500 0.000 0.500 0.500 1.000 + 1.000 0.500 0.000 1.000 0.500 1.000 + 1.500 0.500 0.000 1.500 0.500 1.000 + 0.000 1.000 0.000 0.000 1.000 1.000 + 0.500 1.000 0.000 0.500 1.000 1.000 + 1.000 1.000 0.000 1.000 1.000 1.000 + 1.500 1.000 0.000 1.500 1.000 1.000 + 0.000 1.500 0.000 0.000 1.500 1.000 + 0.500 1.500 0.000 0.500 1.500 1.000 + 1.000 1.500 0.000 1.000 1.500 1.000 + 1.500 1.500 0.000 1.500 1.500 1.000 +/ + +ZCORN +0.000 0.000 0.000 0.000 0.000 0.000 +0.000 0.000 0.000 0.000 0.000 0.000 +0.000 0.000 0.000 0.000 0.000 0.000 +0.000 0.000 0.000 0.000 0.000 0.000 +0.000 0.000 0.000 0.000 0.000 0.000 +0.000 0.000 0.000 0.000 0.000 0.000 +0.500 0.500 0.500 0.500 0.500 0.500 +0.500 0.500 0.500 0.500 0.500 0.500 +0.500 0.500 0.500 0.500 0.500 0.500 +0.500 0.500 0.500 0.500 0.500 0.500 +0.500 0.500 0.500 0.500 0.500 0.500 +0.500 0.500 0.500 0.500 0.500 0.500 +0.500 0.500 0.500 0.500 0.500 0.500 +0.500 0.500 0.500 0.500 0.500 0.500 +0.500 0.500 0.500 0.500 0.500 0.500 +0.500 0.500 0.500 0.500 0.500 0.500 +0.500 0.500 0.500 0.500 0.500 0.500 +0.500 0.500 0.500 0.500 0.500 0.500 +1.000 1.000 1.000 1.000 1.000 1.000 +1.000 1.000 1.000 1.000 1.000 1.000 +1.000 1.000 1.000 1.000 1.000 1.000 +1.000 1.000 1.000 1.000 1.000 1.000 +1.000 1.000 1.000 1.000 1.000 1.000 +1.000 1.000 1.000 1.000 1.000 1.000 +1.000 1.000 1.000 1.000 1.000 1.000 +1.000 1.000 1.000 1.000 1.000 1.000 +1.000 1.000 1.000 1.000 1.000 1.000 +1.000 1.000 1.000 1.000 1.000 1.000 +1.000 1.000 1.000 1.000 1.000 1.000 +1.000 1.000 1.000 1.000 1.000 1.000 +1.500 1.500 1.500 1.500 1.500 1.500 +1.500 1.500 1.500 1.500 1.500 1.500 +1.500 1.500 1.500 1.500 1.500 1.500 +1.500 1.500 1.500 1.500 1.500 1.500 +1.500 1.500 1.500 1.500 1.500 1.500 +1.500 1.500 1.500 1.500 1.500 1.500 +/ + +ACTNUM +1 1 1 1 1 1 1 1 1 +1 1 1 1 1 1 1 1 1 +1 1 1 1 1 1 1 1 1 +/ + +PERMX +1 2 3 4 5 6 7 8 9 +1 2 3 4 5 6 7 8 9 +1 2 3 4 5 6 7 8 9 +/ + +PERMY +1 2 3 4 5 6 7 8 9 +1 2 3 4 5 6 7 8 9 +1 2 3 4 5 6 7 8 9 +/ + +PERMZ +1 2 3 4 5 6 7 8 9 +1 2 3 4 5 6 7 8 9 +1 2 3 4 5 6 7 8 9 +/ + +PORO +0.2 0.2 0.4 0.4 0.6 0.6 0.8 0.8 0.5 +0.2 0.2 0.4 0.4 0.6 0.6 0.8 0.8 0.5 +0.2 0.2 0.4 0.4 0.6 0.6 0.8 0.8 0.5 +/ + +SATNUM +1 1 1 1 1 1 1 1 1 +2 2 2 2 2 2 2 2 2 +3 3 3 3 3 3 3 3 3 +/ diff --git a/test/eclipse/tests b/test/eclipse/tests index 4150468..2565a9e 100644 --- a/test/eclipse/tests +++ b/test/eclipse/tests @@ -141,6 +141,16 @@ simple_cube_feet_converted: cli_args: --convert-to-m gold: simple_cube_feet_converted.e +# Same numbers as simple_cube.grdecl but the GRIDUNIT value is single-quoted +# ('METRES' rather than METRES) -- the convention many real-world tools +# (Petrel, etc.) emit. Output should match simple_cube.e; if the reader +# fails to strip the quotes the unit check would misfire with an +# "unrecognised GRIDUNIT" note. +simple_cube_quoted_unit: + filename: simple_cube_quoted_unit.grdecl + type: exodiff + gold: simple_cube.e + # Z-up convention file (pillar tops at z=1, bots at z=0). em2ex's default # corner ordering treats this as inverted; --strict-jacobians should error # out rather than write a mesh