~libecbufr-dev/libecbufr/trunk

« back to all changes in this revision

Viewing changes to Bindings/python/ecbufr/af.pyx

  • Committer: vanh.souvanlasy at canada
  • Date: 2019-11-05 21:50:59 UTC
  • Revision ID: vanh.souvanlasy@canada.ca-20191105215059-0a0yolehj3jcmm67
add python bindings

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# file: ecbufr.pyx
 
2
 
 
3
from libc.stdlib cimport malloc, free
 
4
 
 
5
from ecbufr cimport caf
 
6
 
 
7
cdef class BufrAF:
 
8
   cdef caf.BufrAF* _this_ptr
 
9
   cdef caf.BufrAF* _this
 
10
 
 
11
   def __cinit__(self):
 
12
      self._this_ptr=NULL
 
13
      self._this=self._this_ptr
 
14
 
 
15
   def __dealloc__(self):
 
16
      if self._this_ptr is not NULL:
 
17
          caf.bufr_free_af(self._this_ptr)
 
18
 
 
19
   def allocate(self,blens):
 
20
      cdef int *my_ints
 
21
 
 
22
      dlen = len(blens)
 
23
      my_ints = <int *>malloc(dlen*4)
 
24
      if my_ints is NULL:
 
25
         raise MemoryError()
 
26
      for i in xrange(dlen):
 
27
         my_ints[i] = blens[i]
 
28
 
 
29
      self._this_ptr=caf.bufr_create_af( my_ints, dlen )
 
30
      if self._this_ptr is NULL:
 
31
         raise MemoryError()
 
32
      self._this=self._this_ptr
 
33
      free(my_ints)
 
34
 
 
35
   def get_value(self,int pos):
 
36
      return caf.bufr_af_get_value(self._this,pos)
 
37
 
 
38
   def get_sig(self, int pos):
 
39
      return caf.bufr_af_get_sig(self._this,pos)
 
40
 
 
41
   def set_value(self,int pos,int val):
 
42
      return caf.bufr_af_set_value(self._this,pos,val)
 
43
 
 
44
   def set_sig(self,int pos,int sig):
 
45
      return caf.bufr_af_set_sig(self._this,pos,sig)
 
46
 
 
47
   def sprint(self):
 
48
      cdef  char string[2048]
 
49
      cdef  char *s
 
50
 
 
51
      caf.bufr_print_af(string,self._this)
 
52
      ps = string
 
53
      return  ps