예제 #1
0
def test_grd3d_export_grdeclprop_no_file():
    fname = "random_file_name"
    with open(fname, "w"):
        pass
    os.chmod(fname, stat.S_IREAD)
    with pytest.raises(xtgeo.XTGeoCLibError, match="Could not open file"):
        # The input here is not very important, what is important
        # is that "existing_file" can not be opened.
        _cxtgeo.grd3d_export_grdeclprop2(
            1,
            1,
            1,
            1,
            _cxtgeo.new_intpointer(),
            _cxtgeo.new_floatpointer(),
            _cxtgeo.new_doublepointer(),
            "name",
            " %d",
            fname,
            1,
            0,
        )

    os.chmod(fname, stat.S_IWRITE)
    os.remove(fname)
예제 #2
0
def export_grdecl(self, pfile, name, append=False, binary=False, dtype=None):

    logger.info("Exporting %s to file %s, GRDECL format", name, pfile)

    if dtype is None:
        if self._isdiscrete:
            dtype = "int32"
        else:
            dtype = "float32"

    carray = _gridprop_lowlevel.update_carray(self, dtype=dtype)

    iarr = _cxtgeo.new_intpointer()
    farr = _cxtgeo.new_floatpointer()
    darr = _cxtgeo.new_doublepointer()

    if "double" in str(carray):
        ptype = 3
        darr = carray

    elif "float" in str(carray):
        ptype = 2
        farr = carray

    else:
        ptype = 1
        iarr = carray

    mode = 0
    if not binary:
        mode = 1

    appendmode = 0
    if append:
        appendmode = 1

    _cxtgeo.grd3d_export_grdeclprop2(
        self._ncol,
        self._nrow,
        self._nlay,
        ptype,
        iarr,
        farr,
        darr,
        name,
        pfile,
        mode,
        appendmode,
        XTGDEBUG,
    )

    _gridprop_lowlevel.delete_carray(self, carray)
예제 #3
0
def test_grd3d_export_grdeclprop_no_file(unreadable_file):
    with pytest.raises(xtgeo.XTGeoCLibError, match="Could not open file"):
        # The input here is not very important, what is important
        # is that "existing_file" can not be opened.
        _cxtgeo.grd3d_export_grdeclprop2(
            1,
            1,
            1,
            1,
            _cxtgeo.new_intpointer(),
            _cxtgeo.new_floatpointer(),
            _cxtgeo.new_doublepointer(),
            "name",
            " %d",
            unreadable_file,
            1,
            0,
        )