def _rkwquery(gfile, kws, name, swap):
    """Local function for _import_roff_v2, single data."""

    kwtypedict = {"int": 1, "float": 2}
    iresult = _cxtgeo.new_intpointer()
    presult = _cxtgeo.new_floatpointer()

    dtype = 0
    reclen = 0
    bytepos = 1
    for items in kws:
        if name in items[0]:
            dtype = kwtypedict.get(items[1])
            reclen = items[2]
            bytepos = items[3]
            break

    logger.debug("DTYPE is %s", dtype)

    if dtype == 0:
        raise ValueError("Cannot find property <{}> in file".format(name))

    if reclen != 1:
        raise SystemError("Stuff is rotten here...")

    _cxtgeo.grd3d_imp_roffbin_data(
        gfile.get_cfhandle(), swap, dtype, bytepos, iresult, presult
    )

    gfile.cfclose()

    # -1 indicates that it is the swap flag which is looked for!
    if dtype == 1:
        xresult = _cxtgeo.intpointer_value(iresult)
        if swap == -1:
            if xresult == 1:
                return 0
            return 1

    elif dtype == 2:
        xresult = _cxtgeo.floatpointer_value(presult)

    return xresult
Exemplo n.º 2
0
def _import_segy_xtgeo(sfile,
                       scanheadermode=False,
                       scantracemode=False,
                       outfile=None):
    """Import SEGY via XTGeo's C library. OLD NOT UPDATED!!

    Args:
        sfile (str): File name of SEGY file
        scanheadermode (bool, optional): If true, will scan header
        scantracemode (bool, optional): If true, will scan trace headers
        outfile (str, optional): Output file for scan dump (default None)

    Returns:
        A dictionary with relevant data.
    """
    # pylint: disable=too-many-statements, too-many-locals

    sdata = dict()

    logger.info("Import SEGY via XTGeo CLIB")

    if outfile is None:
        outfile = "/dev/null"

    ptr_gn_bitsheader = _cxtgeo.new_intpointer()
    ptr_gn_formatcode = _cxtgeo.new_intpointer()
    ptr_gf_segyformat = _cxtgeo.new_floatpointer()
    ptr_gn_samplespertrace = _cxtgeo.new_intpointer()
    ptr_gn_measuresystem = _cxtgeo.new_intpointer()

    option = 0
    if scantracemode:
        option = 0
    if scanheadermode:
        option = 1

    _cxtgeo.cube_scan_segy_hdr(
        sfile,
        ptr_gn_bitsheader,
        ptr_gn_formatcode,
        ptr_gf_segyformat,
        ptr_gn_samplespertrace,
        ptr_gn_measuresystem,
        option,
        outfile,
    )

    # get values
    gn_bitsheader = _cxtgeo.intpointer_value(ptr_gn_bitsheader)
    gn_formatcode = _cxtgeo.intpointer_value(ptr_gn_formatcode)
    gf_segyformat = _cxtgeo.floatpointer_value(ptr_gf_segyformat)
    gn_samplespertrace = _cxtgeo.intpointer_value(ptr_gn_samplespertrace)

    if scanheadermode:
        logger.info("Scan SEGY header ... %s bytes ... DONE", gn_bitsheader)
        return None

    # next is to scan first and last trace, in order to allocate
    # cube size

    ptr_ncol = _cxtgeo.new_intpointer()
    ptr_nrow = _cxtgeo.new_intpointer()
    ptr_nlay = _cxtgeo.new_intpointer()
    ptr_xori = _cxtgeo.new_doublepointer()
    ptr_yori = _cxtgeo.new_doublepointer()
    ptr_zori = _cxtgeo.new_doublepointer()
    ptr_xinc = _cxtgeo.new_doublepointer()
    ptr_yinc = _cxtgeo.new_doublepointer()
    ptr_zinc = _cxtgeo.new_doublepointer()
    ptr_rotation = _cxtgeo.new_doublepointer()
    ptr_minval = _cxtgeo.new_doublepointer()
    ptr_maxval = _cxtgeo.new_doublepointer()
    ptr_dummy = _cxtgeo.new_floatpointer()
    ptr_yflip = _cxtgeo.new_intpointer()
    ptr_zflip = _cxtgeo.new_intpointer()

    optscan = 1

    if scantracemode:
        option = 1

    logger.debug("Scan via C wrapper...")
    _cxtgeo.cube_import_segy(
        sfile,
        # input
        gn_bitsheader,
        gn_formatcode,
        gf_segyformat,
        gn_samplespertrace,
        # result (as pointers)
        ptr_ncol,
        ptr_nrow,
        ptr_nlay,
        ptr_dummy,
        ptr_xori,
        ptr_xinc,
        ptr_yori,
        ptr_yinc,
        ptr_zori,
        ptr_zinc,
        ptr_rotation,
        ptr_yflip,
        ptr_zflip,
        ptr_minval,
        ptr_maxval,
        # options
        optscan,
        option,
        outfile,
    )

    logger.debug("Scan via C wrapper... done")

    ncol = _cxtgeo.intpointer_value(ptr_ncol)
    nrow = _cxtgeo.intpointer_value(ptr_nrow)
    nlay = _cxtgeo.intpointer_value(ptr_nlay)

    if scantracemode:
        return None

    nrcl = ncol * nrow * nlay

    ptr_cval_v = _cxtgeo.new_floatarray(nrcl)

    # next is to do the actual import of the cube
    optscan = 0

    logger.debug("Import via C wrapper...")
    _cxtgeo.cube_import_segy(
        sfile,
        # input
        gn_bitsheader,
        gn_formatcode,
        gf_segyformat,
        gn_samplespertrace,
        # result (as pointers)
        ptr_ncol,
        ptr_nrow,
        ptr_nlay,
        ptr_cval_v,
        ptr_xori,
        ptr_xinc,
        ptr_yori,
        ptr_yinc,
        ptr_zori,
        ptr_zinc,
        ptr_rotation,
        ptr_yflip,
        ptr_zflip,
        ptr_minval,
        ptr_maxval,
        # options
        optscan,
        option,
        outfile,
    )

    logger.debug("Import via C wrapper...")

    sdata["ncol"] = ncol
    sdata["nrow"] = nrow
    sdata["nlay"] = nlay

    sdata["xori"] = _cxtgeo.doublepointer_value(ptr_xori)
    sdata["yori"] = _cxtgeo.doublepointer_value(ptr_yori)
    sdata["zori"] = _cxtgeo.doublepointer_value(ptr_zori)

    sdata["xinc"] = _cxtgeo.doublepointer_value(ptr_xinc)
    sdata["yinc"] = _cxtgeo.doublepointer_value(ptr_yinc)
    sdata["zinc"] = _cxtgeo.doublepointer_value(ptr_zinc)

    sdata["yflip"] = _cxtgeo.intpointer_value(ptr_yflip)
    sdata["zflip"] = _cxtgeo.intpointer_value(ptr_zflip)

    sdata["rotation"] = _cxtgeo.doublepointer_value(ptr_rotation)

    sdata["minval"] = _cxtgeo.doublepointer_value(ptr_minval)
    sdata["maxval"] = _cxtgeo.doublepointer_value(ptr_maxval)

    sdata["zmin"] = sdata["zori"]
    sdata["zmax"] = sdata["zori"] + sdata["zflip"] * sdata["zinc"] * (nlay - 1)

    # the pointer to 1D C array
    sdata["cvalues"] = ptr_cval_v
    sdata["values"] = None

    return sdata