コード例 #1
0
def grib_get_long_array(gribid,key):
    """
    @brief Get the integer array of values for a key from a grib message.
    
    If NumPy is enabled, the integer array will be stored in a NumPy ndarray.
    Otherwise, Python's native array type will be used.
    
    @param gribid      id of the grib loaded in memory
    @param key         key name
    @return numpy.ndarray or array
    @exception GribInternalError 
    """
    if with_numpy():
        nval = grib_get_size(gribid,key)
        err,result = _internal.grib_get_long_ndarray(gribid,key,nval)
        GRIB_CHECK(err)
        return result
    else:
        nval = grib_get_size(gribid,key)
        a = _internal.new_longArray(nval)
        s = _internal.intp()
        s.assign(nval)

        GRIB_CHECK(_internal.grib_c_get_long_array(gribid,key,a,s))

        result = array("l")
        for i in range(nval):
            result.append(_internal.longArray_getitem(a,i))

        _internal.delete_longArray(a)
        _internal.delete_intp(s)

        return result
コード例 #2
0
def grib_index_get_long(indexid,key):
    """
    @brief Get the distinct values of the key in argument contained in the index. The key must belong to the index. 
    
    This function is used when the type of the key was explicitly defined as long or when the native type of the key is long.
    
    \b Examples: \ref index.py "index.py"
    
    @param indexid   id of an index created from a file. The index must have been created with the key in argument.
    @param key       key for wich the values are returned
    @return tuple with values of key in index
    @exception GribInternalError 
    """
    nval = grib_index_get_size(indexid,key)

    a = _internal.new_longArray(nval)
    s = _internal.intp()
    s.assign(nval)

    GRIB_CHECK(_internal.grib_c_index_get_long(indexid,key,a,s))

    result = []
    for i in range(nval):
        result.append(_internal.longArray_getitem(a,i))

    _internal.delete_longArray(a)
    _internal.delete_intp(s)

    return tuple(result)
コード例 #3
0
def grib_set_long_array(gribid,key,value):
    """
    @brief Set the value of the key to an integer array.

    If NumPy is enabled, the wrapper will internally try to convert the input to a NumPy array
    before extracting its data and length. This is possible as NumPy
    allows the construction of arrays from arbitrary python sequences.

    The elements of the input sequence need to be convertible to an int.
    
    @param gribid      id of the grib loaded in memory
    @param key         key name
    @param value       tuple,list,python array,numpy array
    @exception GribInternalError 
    """
    if with_numpy():
        GRIB_CHECK(_internal.grib_set_long_ndarray(gribid,key,value))
    else:
        nval = len(inarray)
        a = _internal.new_longArray(nval)
        s = _internal.intp()
        s.assign(nval)

        for i in range(nval):
            _internal.longArray_setitem(a,i,inarray[i])

        GRIB_CHECK(_internal.grib_c_set_long_array(gribid,key,a,s))

        _internal.delete_longArray(a)
        _internal.delete_intp(s)