3
from ecbufr.ctables cimport BUFR_Tables
4
from cpython.pycapsule cimport *
6
from ecbufr.tables import EntryTableB
7
from ecbufr.tables import EntryTableD
9
from ecbufr cimport ctemplate
10
from libc.stdlib cimport malloc, free
12
cdef class BUFR_Template:
13
cdef ctemplate.BUFR_Template* _this_ptr
14
cdef ctemplate.BUFR_Template* _this
18
self._this=self._this_ptr
20
def __dealloc__(self):
21
if self._this_ptr is not NULL:
22
ctemplate.bufr_free_template(self._this_ptr)
24
cdef load(self,basestring filename, tbl):
25
cdef BUFR_Tables *tbl_ptr
28
tbl_ptr = <BUFR_Tables *>PyCapsule_GetPointer(tobj,"BUFR_Tables")
29
self._this_ptr = ctemplate.bufr_load_template( filename.encode(), tbl_ptr )
31
def save(self,basestring filename):
32
ctemplate.bufr_save_template( filename.encode(), self._this )
34
def allocate(self,BufrDescValue dv, tbl, int edition):
35
cdef BUFR_Tables *tbl_ptr
39
print "edition=", edition
41
tbl_ptr = <BUFR_Tables *>PyCapsule_GetPointer(tobj,"BUFR_Tables")
42
self._this_ptr = ctemplate.bufr_create_template(dv._this,nb,tbl_ptr,edition)
43
if self._this_ptr is NULL:
45
self._this=self._this_ptr
47
def compare(self, BUFR_Template other):
48
return ctemplate.bufr_compare_template( self._this, other._this )
52
bt._this_ptr = ctemplate.bufr_copy_template( self._this )
53
bt._this = bt._this_ptr
56
def add(self,BufrDescValue dv,tbl):
57
cdef ctemplate.BufrDescValue *descs
62
dsc=descs[i].descriptor
63
tbe=tbl.fetch_tableB( dsc )
64
if not isinstance(tbe,EntryTableB):
65
tde=tbl.fetch_tableD( dsc )
66
if not isinstance(tbe,EntryTableD):
67
print "Error Not a Descriptor:",dsc
70
ctemplate.bufr_template_add_DescValue( self._this, dv._this, len(dv) )
73
ctemplate.bufr_finalize_template(self._this)
75
cdef class BufrDescValue:
76
cdef ctemplate.BufrDescValue* _this_ptr
77
cdef ctemplate.BufrDescValue* _this
80
def __cinit__(self,int nb):
82
self._this=self._this_ptr
84
cdef ctemplate.BufrDescValue *descs
86
descs = <ctemplate.BufrDescValue *>malloc(nb*sizeof(BufrDescValue))
91
self._this=self._this_ptr
93
ctemplate.bufr_init_DescValue ( &descs[i] )
96
def __dealloc__(self):
97
if self._this_ptr is not NULL:
106
def set_desc(self,pos,desc):
107
cdef ctemplate.BufrDescValue *descs
109
descs[pos].descriptor=desc
111
def get_desc(self,pos):
112
cdef ctemplate.BufrDescValue *descs
114
return descs[pos].descriptor