From e4eecd416e022c6dbdb836f17c7509c186bd9645 Mon Sep 17 00:00:00 2001 From: "Oddvar Lia (ST MSU GEO)" Date: Tue, 21 Nov 2023 13:24:56 +0100 Subject: [PATCH] Added script to convert from roff to grdecl ascii format --- .../example_case/scripts/roff_to_grdecl.py | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 tests/jobs/localisation/example_case/scripts/roff_to_grdecl.py diff --git a/tests/jobs/localisation/example_case/scripts/roff_to_grdecl.py b/tests/jobs/localisation/example_case/scripts/roff_to_grdecl.py new file mode 100755 index 000000000..ce8e293a5 --- /dev/null +++ b/tests/jobs/localisation/example_case/scripts/roff_to_grdecl.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python +""" +Script converting a grid parameter file from ROFF to GRDECL +""" + +import sys +from pathlib import PurePath + +import xtgeo + + +def main(argv): + """ + Convert a grid parameter file from ROFF to GRDECL + and can also take as input a GRDECL file and write + to another GRDECL file with fixed format + """ + input_file = argv[1] + output_file = argv[2] + grid_file = argv[3] + param_name = "FIELDPAR" + grid_obj = xtgeo.grid_from_file(grid_file, fformat="egrid") + # Check extension to find input format + suffix = PurePath(input_file).suffix + if suffix.upper() == ".ROFF": + print(f"Read file: {input_file} in ROFF format") + field_obj = xtgeo.gridproperty_from_file( + input_file, fformat="roff", name=param_name, grid=grid_obj + ) + print(f"Write file: {output_file} in GRDECL format") + field_obj.to_file(output_file, fformat="grdecl", fmt="%8.4f") + elif suffix.upper() == ".GRDECL": + # Ensure the grdecl file use a fixed format for the values + # to more easily compare it with a reference + print(f"Read file: {input_file} in GRDECL format") + field_obj = xtgeo.gridproperty_from_file( + input_file, fformat="grdecl", name=param_name, grid=grid_obj + ) + print(f"Write file: {output_file} in GRDECL format") + field_obj.to_file(output_file, fformat="grdecl", fmt="%8.4f") + + +if __name__ == "__main__": + args = sys.argv + if len(args) < 4: + print( + "Usage: roff_to_grdecl.py " + " " + ) + else: + main(args)