mirror of https://github.com/ecmwf/eccodes.git
solved ECC-85, ECC-118
This commit is contained in:
parent
c467ce890b
commit
5f8f69908b
|
@ -57,14 +57,14 @@ def example():
|
|||
print ' Number of values: %ld' % (numObs)
|
||||
|
||||
#Get latitude (for all the subsets)
|
||||
lat=codes_get_double_array(gid,"latitude")
|
||||
lat=codes_get_array(gid,"latitude")
|
||||
|
||||
#Get longitude (for all the subsets)
|
||||
lon=codes_get_double_array(gid,"longitude")
|
||||
lon=codes_get_array(gid,"longitude")
|
||||
|
||||
#Get backScatter for beam two. We use an access by condition for this key.
|
||||
#(for all the subsets)
|
||||
bscat=codes_get_double_array(gid,"/beamIdentifier=2/backscatter")
|
||||
bscat=codes_get_array(gid,"/beamIdentifier=2/backscatter")
|
||||
|
||||
# Check that all arrays are same size
|
||||
if len(lat) != numObs or len(lon) != numObs or len(bscat) != numObs :
|
||||
|
|
|
@ -62,16 +62,16 @@ def example():
|
|||
print ' Number of temperature significant levels %ld' % (numSigT)
|
||||
|
||||
# Get pressure
|
||||
sigt_pres=codes_get_double_array(gid,"/verticalSoundingSignificance=4/pressure")
|
||||
sigt_pres=codes_get_array(gid,"/verticalSoundingSignificance=4/pressure")
|
||||
|
||||
# Get gepotential
|
||||
sigt_geo=codes_get_double_array(gid,"/verticalSoundingSignificance=4/geopotential")
|
||||
sigt_geo=codes_get_array(gid,"/verticalSoundingSignificance=4/geopotential")
|
||||
|
||||
# Get temperature
|
||||
sigt_t=codes_get_double_array(gid,"/verticalSoundingSignificance=4/airTemperature")
|
||||
sigt_t=codes_get_array(gid,"/verticalSoundingSignificance=4/airTemperature")
|
||||
|
||||
# Get dew point
|
||||
sigt_td=codes_get_double_array(gid,"/verticalSoundingSignificance=4/dewpointTemperature")
|
||||
sigt_td=codes_get_array(gid,"/verticalSoundingSignificance=4/dewpointTemperature")
|
||||
|
||||
# Check that all arrays are same size
|
||||
if len(sigt_pres) != numSigT or len(sigt_geo) != numSigT or len(sigt_t) != numSigT or len(sigt_td) != numSigT :
|
||||
|
|
|
@ -26,15 +26,15 @@ def example():
|
|||
codes_set(gid,'dataDate',int(today))
|
||||
codes_set(gid,'centre',80)
|
||||
|
||||
centreIntVal = codes_get(gid,'centre',int)
|
||||
centreStrVal = codes_get(gid,'centre',str)
|
||||
dateStrVal = codes_get(gid,'dataDate',str)
|
||||
assert(centreIntVal == 80)
|
||||
assert(centreStrVal == 'cnmc')
|
||||
assert(dateStrVal == today)
|
||||
print 'get centre as an integer - centre = %d' % centreIntVal
|
||||
print 'get centre as a string - centre = %s' % centreStrVal
|
||||
print 'get date as a string - date = %s' % dateStrVal
|
||||
centreIntVal = codes_get_array(gid,'centre',int)
|
||||
centreStrVal = codes_get_array(gid,'centre',str)
|
||||
dateStrVal = codes_get_array(gid,'dataDate',str)
|
||||
assert(centreIntVal[0] == 80)
|
||||
assert(centreStrVal[0] == 'cnmc')
|
||||
assert(dateStrVal[0] == today)
|
||||
print 'get centre as an integer - centre = %d' % centreIntVal[0]
|
||||
print 'get centre as a string - centre = %s' % centreStrVal[0]
|
||||
print 'get date as a string - date = %s' % dateStrVal[0]
|
||||
|
||||
# Now do the same but using set_key_vals, setting keys all at once
|
||||
codes_set_key_vals(gid, 'level=1,centre=98') # with a String
|
||||
|
|
|
@ -32,6 +32,7 @@ import_array();
|
|||
}
|
||||
|
||||
%pointer_class(int, intp);
|
||||
%pointer_class(size_t, sizetp);
|
||||
%pointer_class(long, longp);
|
||||
%pointer_class(double, doublep);
|
||||
%array_functions(double, doubleArray);
|
||||
|
|
|
@ -1820,6 +1820,18 @@ int grib_c_get_string(int* gid, char* key, char* val, size_t *lsize){
|
|||
return err;
|
||||
}
|
||||
|
||||
int grib_c_get_string_array(int* gid, char* key, char** val, size_t *lsize){
|
||||
|
||||
grib_handle *h = get_handle(*gid);
|
||||
int err = GRIB_SUCCESS;
|
||||
|
||||
if(!h) return GRIB_INVALID_GRIB;
|
||||
|
||||
err = grib_get_string_array(h, key, val, lsize);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int grib_c_set_string(int* gid, char* key, char* val, int len2){
|
||||
|
||||
grib_handle *h = get_handle(*gid);
|
||||
|
|
|
@ -860,6 +860,31 @@ def grib_get_double_array(gribid,key):
|
|||
|
||||
return result
|
||||
|
||||
@require(gribid=int,key=str)
|
||||
def grib_get_string_array(gribid,key):
|
||||
"""
|
||||
@brief Get the value of the key as an array of strings.
|
||||
|
||||
@param gribid id of the grib loaded in memory
|
||||
@param key key name
|
||||
@return numpy.ndarray or array
|
||||
@exception GribInternalError
|
||||
"""
|
||||
nval = grib_get_size(gribid,key)
|
||||
a = _internal.new_stringArray(nval)
|
||||
s = _internal.sizetp()
|
||||
s.assign(nval)
|
||||
|
||||
GRIB_CHECK(_internal.grib_c_get_string_array(gribid,key,a,s))
|
||||
|
||||
result = list()
|
||||
for i in range(nval):
|
||||
result.append(_internal.stringArray_getitem(a,i))
|
||||
|
||||
_internal.delete_stringArray(a)
|
||||
|
||||
return result
|
||||
|
||||
@require(gribid=int,key=str)
|
||||
def grib_set_long_array(gribid, key, inarray):
|
||||
"""
|
||||
|
@ -1504,6 +1529,8 @@ def grib_get_array(gribid,key, ktype=None):
|
|||
result = grib_get_long_array(gribid, key)
|
||||
elif ktype is float:
|
||||
result = grib_get_double_array(gribid, key)
|
||||
elif ktype is str:
|
||||
result = grib_get_string_array(gribid, key)
|
||||
|
||||
return result
|
||||
|
||||
|
|
|
@ -32,11 +32,13 @@ import_array();
|
|||
}
|
||||
|
||||
%pointer_class(int, intp);
|
||||
%pointer_class(size_t, sizetp);
|
||||
%pointer_class(long, longp);
|
||||
%pointer_class(double, doublep);
|
||||
%array_functions(double, doubleArray);
|
||||
%array_functions(long, longArray);
|
||||
%array_functions(int, intArray);
|
||||
%array_functions(char*, stringArray);
|
||||
|
||||
// creation
|
||||
int grib_c_new_from_file(FILE* f, int* INOUT, int headers_only);
|
||||
|
@ -125,6 +127,7 @@ int grib_c_iterator_next(int* iterid, double* OUTPUT, double* OUTPUT, double* OU
|
|||
// getting/setting key values
|
||||
%cstring_output_withsize(char* string_val, size_t* string_size)
|
||||
int grib_c_get_string(int* gid, char* key, char* string_val, size_t* string_size);
|
||||
int grib_c_get_string_array(int* gid, char* key, char** array_string_val, size_t* size);
|
||||
int grib_c_set_string(int* gid, char* key, char* sval, int len2);
|
||||
int grib_c_get_long(int* gid, char* key, long* OUTPUT);
|
||||
int grib_c_set_long(int* gid, char* key, long* INPUT);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,9 +1,10 @@
|
|||
# This file was automatically generated by SWIG (http://www.swig.org).
|
||||
# Version 1.3.40
|
||||
# Version 2.0.10
|
||||
#
|
||||
# Do not make changes to this file unless you know what you are doing--modify
|
||||
# the SWIG interface file instead.
|
||||
# This file is compatible with both classic and new-style classes.
|
||||
|
||||
|
||||
|
||||
from sys import version_info
|
||||
if version_info >= (2,6,0):
|
||||
|
@ -39,7 +40,7 @@ def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
|
|||
return
|
||||
method = class_type.__swig_setmethods__.get(name,None)
|
||||
if method: return method(self,value)
|
||||
if (not static) or hasattr(self,name):
|
||||
if (not static):
|
||||
self.__dict__[name] = value
|
||||
else:
|
||||
raise AttributeError("You cannot add attributes to %s" % self)
|
||||
|
@ -138,6 +139,7 @@ GRIB_NULL_POINTER = _gribapi_swig.GRIB_NULL_POINTER
|
|||
GRIB_ATTRIBUTE_CLASH = _gribapi_swig.GRIB_ATTRIBUTE_CLASH
|
||||
GRIB_TOO_MANY_ATTRIBUTES = _gribapi_swig.GRIB_TOO_MANY_ATTRIBUTES
|
||||
GRIB_ATTRIBUTE_NOT_FOUND = _gribapi_swig.GRIB_ATTRIBUTE_NOT_FOUND
|
||||
GRIB_UNSUPPORTED_EDITION = _gribapi_swig.GRIB_UNSUPPORTED_EDITION
|
||||
class intp(_object):
|
||||
__swig_setmethods__ = {}
|
||||
__setattr__ = lambda self, name, value: _swig_setattr(self, intp, name, value)
|
||||
|
@ -162,6 +164,30 @@ def intp_frompointer(*args):
|
|||
return _gribapi_swig.intp_frompointer(*args)
|
||||
intp_frompointer = _gribapi_swig.intp_frompointer
|
||||
|
||||
class sizetp(_object):
|
||||
__swig_setmethods__ = {}
|
||||
__setattr__ = lambda self, name, value: _swig_setattr(self, sizetp, name, value)
|
||||
__swig_getmethods__ = {}
|
||||
__getattr__ = lambda self, name: _swig_getattr(self, sizetp, name)
|
||||
__repr__ = _swig_repr
|
||||
def __init__(self):
|
||||
this = _gribapi_swig.new_sizetp()
|
||||
try: self.this.append(this)
|
||||
except: self.this = this
|
||||
__swig_destroy__ = _gribapi_swig.delete_sizetp
|
||||
__del__ = lambda self : None;
|
||||
def assign(self, *args): return _gribapi_swig.sizetp_assign(self, *args)
|
||||
def value(self): return _gribapi_swig.sizetp_value(self)
|
||||
def cast(self): return _gribapi_swig.sizetp_cast(self)
|
||||
__swig_getmethods__["frompointer"] = lambda x: _gribapi_swig.sizetp_frompointer
|
||||
if _newclass:frompointer = staticmethod(_gribapi_swig.sizetp_frompointer)
|
||||
sizetp_swigregister = _gribapi_swig.sizetp_swigregister
|
||||
sizetp_swigregister(sizetp)
|
||||
|
||||
def sizetp_frompointer(*args):
|
||||
return _gribapi_swig.sizetp_frompointer(*args)
|
||||
sizetp_frompointer = _gribapi_swig.sizetp_frompointer
|
||||
|
||||
class longp(_object):
|
||||
__swig_setmethods__ = {}
|
||||
__setattr__ = lambda self, name, value: _swig_setattr(self, longp, name, value)
|
||||
|
@ -259,6 +285,22 @@ def intArray_setitem(*args):
|
|||
return _gribapi_swig.intArray_setitem(*args)
|
||||
intArray_setitem = _gribapi_swig.intArray_setitem
|
||||
|
||||
def new_stringArray(*args):
|
||||
return _gribapi_swig.new_stringArray(*args)
|
||||
new_stringArray = _gribapi_swig.new_stringArray
|
||||
|
||||
def delete_stringArray(*args):
|
||||
return _gribapi_swig.delete_stringArray(*args)
|
||||
delete_stringArray = _gribapi_swig.delete_stringArray
|
||||
|
||||
def stringArray_getitem(*args):
|
||||
return _gribapi_swig.stringArray_getitem(*args)
|
||||
stringArray_getitem = _gribapi_swig.stringArray_getitem
|
||||
|
||||
def stringArray_setitem(*args):
|
||||
return _gribapi_swig.stringArray_setitem(*args)
|
||||
stringArray_setitem = _gribapi_swig.stringArray_setitem
|
||||
|
||||
def grib_c_new_from_file(*args):
|
||||
return _gribapi_swig.grib_c_new_from_file(*args)
|
||||
grib_c_new_from_file = _gribapi_swig.grib_c_new_from_file
|
||||
|
@ -471,6 +513,10 @@ def grib_c_get_string(*args):
|
|||
return _gribapi_swig.grib_c_get_string(*args)
|
||||
grib_c_get_string = _gribapi_swig.grib_c_get_string
|
||||
|
||||
def grib_c_get_string_array(*args):
|
||||
return _gribapi_swig.grib_c_get_string_array(*args)
|
||||
grib_c_get_string_array = _gribapi_swig.grib_c_get_string_array
|
||||
|
||||
def grib_c_set_string(*args):
|
||||
return _gribapi_swig.grib_c_set_string(*args)
|
||||
grib_c_set_string = _gribapi_swig.grib_c_set_string
|
||||
|
@ -562,5 +608,6 @@ grib_c_gts_header_on = _gribapi_swig.grib_c_gts_header_on
|
|||
def grib_c_gts_header_off():
|
||||
return _gribapi_swig.grib_c_gts_header_off()
|
||||
grib_c_gts_header_off = _gribapi_swig.grib_c_gts_header_off
|
||||
# This file is compatible with both classic and new-style classes.
|
||||
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,9 +1,10 @@
|
|||
# This file was automatically generated by SWIG (http://www.swig.org).
|
||||
# Version 1.3.40
|
||||
# Version 2.0.10
|
||||
#
|
||||
# Do not make changes to this file unless you know what you are doing--modify
|
||||
# the SWIG interface file instead.
|
||||
# This file is compatible with both classic and new-style classes.
|
||||
|
||||
|
||||
|
||||
from sys import version_info
|
||||
if version_info >= (2,6,0):
|
||||
|
@ -39,7 +40,7 @@ def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
|
|||
return
|
||||
method = class_type.__swig_setmethods__.get(name,None)
|
||||
if method: return method(self,value)
|
||||
if (not static) or hasattr(self,name):
|
||||
if (not static):
|
||||
self.__dict__[name] = value
|
||||
else:
|
||||
raise AttributeError("You cannot add attributes to %s" % self)
|
||||
|
@ -138,6 +139,7 @@ GRIB_NULL_POINTER = _gribapi_swig.GRIB_NULL_POINTER
|
|||
GRIB_ATTRIBUTE_CLASH = _gribapi_swig.GRIB_ATTRIBUTE_CLASH
|
||||
GRIB_TOO_MANY_ATTRIBUTES = _gribapi_swig.GRIB_TOO_MANY_ATTRIBUTES
|
||||
GRIB_ATTRIBUTE_NOT_FOUND = _gribapi_swig.GRIB_ATTRIBUTE_NOT_FOUND
|
||||
GRIB_UNSUPPORTED_EDITION = _gribapi_swig.GRIB_UNSUPPORTED_EDITION
|
||||
class intp(_object):
|
||||
__swig_setmethods__ = {}
|
||||
__setattr__ = lambda self, name, value: _swig_setattr(self, intp, name, value)
|
||||
|
@ -162,6 +164,30 @@ def intp_frompointer(*args):
|
|||
return _gribapi_swig.intp_frompointer(*args)
|
||||
intp_frompointer = _gribapi_swig.intp_frompointer
|
||||
|
||||
class sizetp(_object):
|
||||
__swig_setmethods__ = {}
|
||||
__setattr__ = lambda self, name, value: _swig_setattr(self, sizetp, name, value)
|
||||
__swig_getmethods__ = {}
|
||||
__getattr__ = lambda self, name: _swig_getattr(self, sizetp, name)
|
||||
__repr__ = _swig_repr
|
||||
def __init__(self):
|
||||
this = _gribapi_swig.new_sizetp()
|
||||
try: self.this.append(this)
|
||||
except: self.this = this
|
||||
__swig_destroy__ = _gribapi_swig.delete_sizetp
|
||||
__del__ = lambda self : None;
|
||||
def assign(self, *args): return _gribapi_swig.sizetp_assign(self, *args)
|
||||
def value(self): return _gribapi_swig.sizetp_value(self)
|
||||
def cast(self): return _gribapi_swig.sizetp_cast(self)
|
||||
__swig_getmethods__["frompointer"] = lambda x: _gribapi_swig.sizetp_frompointer
|
||||
if _newclass:frompointer = staticmethod(_gribapi_swig.sizetp_frompointer)
|
||||
sizetp_swigregister = _gribapi_swig.sizetp_swigregister
|
||||
sizetp_swigregister(sizetp)
|
||||
|
||||
def sizetp_frompointer(*args):
|
||||
return _gribapi_swig.sizetp_frompointer(*args)
|
||||
sizetp_frompointer = _gribapi_swig.sizetp_frompointer
|
||||
|
||||
class longp(_object):
|
||||
__swig_setmethods__ = {}
|
||||
__setattr__ = lambda self, name, value: _swig_setattr(self, longp, name, value)
|
||||
|
@ -259,6 +285,22 @@ def intArray_setitem(*args):
|
|||
return _gribapi_swig.intArray_setitem(*args)
|
||||
intArray_setitem = _gribapi_swig.intArray_setitem
|
||||
|
||||
def new_stringArray(*args):
|
||||
return _gribapi_swig.new_stringArray(*args)
|
||||
new_stringArray = _gribapi_swig.new_stringArray
|
||||
|
||||
def delete_stringArray(*args):
|
||||
return _gribapi_swig.delete_stringArray(*args)
|
||||
delete_stringArray = _gribapi_swig.delete_stringArray
|
||||
|
||||
def stringArray_getitem(*args):
|
||||
return _gribapi_swig.stringArray_getitem(*args)
|
||||
stringArray_getitem = _gribapi_swig.stringArray_getitem
|
||||
|
||||
def stringArray_setitem(*args):
|
||||
return _gribapi_swig.stringArray_setitem(*args)
|
||||
stringArray_setitem = _gribapi_swig.stringArray_setitem
|
||||
|
||||
def grib_c_new_from_file(*args):
|
||||
return _gribapi_swig.grib_c_new_from_file(*args)
|
||||
grib_c_new_from_file = _gribapi_swig.grib_c_new_from_file
|
||||
|
@ -471,6 +513,10 @@ def grib_c_get_string(*args):
|
|||
return _gribapi_swig.grib_c_get_string(*args)
|
||||
grib_c_get_string = _gribapi_swig.grib_c_get_string
|
||||
|
||||
def grib_c_get_string_array(*args):
|
||||
return _gribapi_swig.grib_c_get_string_array(*args)
|
||||
grib_c_get_string_array = _gribapi_swig.grib_c_get_string_array
|
||||
|
||||
def grib_c_set_string(*args):
|
||||
return _gribapi_swig.grib_c_set_string(*args)
|
||||
grib_c_set_string = _gribapi_swig.grib_c_set_string
|
||||
|
@ -586,5 +632,6 @@ grib_c_gts_header_on = _gribapi_swig.grib_c_gts_header_on
|
|||
def grib_c_gts_header_off():
|
||||
return _gribapi_swig.grib_c_gts_header_off()
|
||||
grib_c_gts_header_off = _gribapi_swig.grib_c_gts_header_off
|
||||
# This file is compatible with both classic and new-style classes.
|
||||
|
||||
|
||||
|
|
|
@ -355,7 +355,16 @@ static int unpack_string(grib_accessor*a , char* v, size_t *len){
|
|||
}
|
||||
|
||||
static int unpack_string_array(grib_accessor*a , char** v, size_t *len){
|
||||
return GRIB_NOT_IMPLEMENTED;
|
||||
int err=0;
|
||||
size_t length=0;
|
||||
|
||||
err= _grib_get_string_length(a,&length);
|
||||
if (err) return err;
|
||||
v[0]=grib_context_malloc_clear(a->parent->h->context,length);
|
||||
grib_unpack_string(a,v[0],&length);
|
||||
*len=1;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static int pack_expression(grib_accessor* a, grib_expression *e){
|
||||
|
|
|
@ -926,14 +926,23 @@ int grib_get_bytes(grib_handle* h, const char* name, unsigned char* val, size_t
|
|||
|
||||
int grib_get_native_type(grib_handle* h, const char* name,int* type)
|
||||
{
|
||||
grib_accessor* act = grib_find_accessor(h, name);
|
||||
*type = GRIB_TYPE_UNDEFINED;
|
||||
grib_accessors_list* al=NULL;
|
||||
grib_accessor* a =NULL;
|
||||
*type = GRIB_TYPE_UNDEFINED;
|
||||
|
||||
if (name[0] == '/' ) {
|
||||
al=grib_find_accessors_list(h,name);
|
||||
if (!al) return GRIB_NOT_FOUND;
|
||||
*type = grib_accessor_get_native_type(al->accessor);
|
||||
grib_context_free(h->context,al);
|
||||
} else {
|
||||
a=grib_find_accessor(h, name);
|
||||
if(!a) return GRIB_NOT_FOUND;
|
||||
*type = grib_accessor_get_native_type(a);
|
||||
}
|
||||
|
||||
return GRIB_SUCCESS;
|
||||
|
||||
if(act) {
|
||||
*type = grib_accessor_get_native_type(act);
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
return GRIB_NOT_FOUND;
|
||||
}
|
||||
|
||||
const char* grib_get_accessor_class_name(grib_handle* h, const char* name)
|
||||
|
|
|
@ -49,7 +49,7 @@ ${tools_dir}bufr_dump -js $fBufr > $fJsonTmp
|
|||
diff $fJsonTmp $fJsonRef >$REDIRECT 2> $REDIRECT
|
||||
|
||||
#==============================================
|
||||
# Testing a malformed bufr file (see ECC-110)
|
||||
# Testing change of scale (see ECC-111)
|
||||
#==============================================
|
||||
|
||||
echo "Test: operator 207003 " >> $fLog
|
||||
|
|
Loading…
Reference in New Issue