Skip to content

Commit

Permalink
BUG: ensure raising a ValueError if return -1 (#788)
Browse files Browse the repository at this point in the history
The C function surf_import_ijxyz_tmpl may return -1
which means that using a template fails. Earlier this
was not handled; now a ValueError is raised in the
receiving python code. Context: Auto4D bug report.
  • Loading branch information
jcrivenaes authored Jun 16, 2022
1 parent 6500ce4 commit 6a557c6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/clib/xtg/surf_import_ijxyz_tmpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ surf_import_ijxyz_tmpl(FILE *fd,
/* some sanity tests first */
if (iline < ilines[0] || iline > ilines[nncol - 1] || xline < xlines[0] ||
xline > xlines[nnrow - 1]) {
logger_error(LI, FI, FU, "ILINE or XLINE in file outside template ranges");
return -1;
return -1; // handle this code as error in client
}

found = 0;
Expand Down
19 changes: 14 additions & 5 deletions src/xtgeo/surface/_regsurf_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@

import json
from collections import OrderedDict
from struct import unpack

import h5py
import numpy as np
import numpy.ma as ma
from struct import unpack
import h5py

from xtgeo.common.constants import UNDEF_MAP_IRAPB, UNDEF_MAP_IRAPA
import xtgeo
import xtgeo.common.sys as xsys
import xtgeo.cxtgeo._cxtgeo as _cxtgeo # pylint: disable=no-name-in-module
from xtgeo.common import XTGeoDialog
from xtgeo.common.constants import UNDEF_MAP_IRAPA, UNDEF_MAP_IRAPB
from xtgeo.surface._zmap_parser import parse_zmap

xtg = XTGeoDialog()
Expand Down Expand Up @@ -331,10 +330,20 @@ def _import_ijxyz_tmpl(mfile, template):
raise ValueError("Template is of wrong type: {}".format(type(template)))

nxy = template.ncol * template.nrow
_, val = _cxtgeo.surf_import_ijxyz_tmpl(
ier, val = _cxtgeo.surf_import_ijxyz_tmpl(
cfhandle, template.ilines, template.xlines, nxy, 0
)

if ier == -1:
raise ValueError(
f"The file {mfile.name} and template map or cube has inconsistent "
"inline and/or xlines numbering. Try importing without template "
"and use e.g. resampling instead."
)

elif ier != 0:
raise RuntimeError("Unknown error when trying to import the IJXYZ based file!")

val = ma.masked_greater(val, xtgeo.UNDEF_LIMIT)

args = {}
Expand Down

0 comments on commit 6a557c6

Please sign in to comment.