diff --git a/python/obitools3/obidms/_obidms.pxd b/python/obitools3/obidms/_obidms.pxd index 34a40b0..92f5f29 100644 --- a/python/obitools3/obidms/_obidms.pxd +++ b/python/obitools3/obidms/_obidms.pxd @@ -20,7 +20,7 @@ cdef class OBIDMS: bint create=*, bint clone=*, bint clone_data=*, obiversion_t version_number=*, - OBIType_t data_type=*, + str type=*, index_t nb_lines=*, index_t nb_elements_per_line=*, list elements_names=*, diff --git a/python/obitools3/obidms/_obidms.pyx b/python/obitools3/obidms/_obidms.pyx index ae35f80..6e0b71e 100644 --- a/python/obitools3/obidms/_obidms.pyx +++ b/python/obitools3/obidms/_obidms.pyx @@ -16,6 +16,13 @@ from .capi.obidmscolumn cimport obi_column_get_header_from_name, \ obi_column_format_date, \ OBIDMS_column_header_p from .capi.obitypes cimport const_char_p, \ + OBIType_t, \ + OBI_INT, \ + OBI_FLOAT, \ + OBI_BOOL, \ + OBI_CHAR, \ + OBI_STR, \ + OBI_SEQ, \ name_data_type @@ -121,7 +128,7 @@ cdef class OBIDMS : bint create=False, bint clone=False, bint clone_data=True, obiversion_t version_number=-1, - OBIType_t data_type= 0, + str type='', index_t nb_lines=0, index_t nb_elements_per_line=0, list elements_names=None, @@ -133,7 +140,8 @@ cdef class OBIDMS : cdef object subclass # TODO object? cdef bytes column_name_b cdef OBIDMS_column_header_p header - + cdef OBIType_t data_type + header = NULL # Format the character string to send to C function @@ -141,15 +149,30 @@ cdef class OBIDMS : # Get the header of the latest version of the column if # some needed informations are not provided - if ((not data_type or not nb_elements_per_line) and not create) : + if ((not type or not nb_elements_per_line) and not create) : header = obi_column_get_header_from_name(self.pointer, column_name_b, version_number) # Get the data type if not provided - if not data_type : + if not type : if create : raise Exception("A data type must be specified") else : data_type = header.data_type + else : + if type == 'OBI_INT' : + data_type = OBI_INT + elif type == 'OBI_FLOAT' : + data_type = OBI_FLOAT + elif type == 'OBI_BOOL' : + data_type = OBI_BOOL + elif type == 'OBI_CHAR' : + data_type = OBI_CHAR + elif type == 'OBI_STR' : + data_type = OBI_STR + elif type == 'OBI_SEQ' : + data_type = OBI_SEQ + else : + raise Exception("Invalid provided data type") # Get the number of elements per line if not provided and needed if not nb_elements_per_line : @@ -165,7 +188,7 @@ cdef class OBIDMS : # Open the column with the right subclass depending on the data type, the mode # (read-only or writable) and whether there are multiple elements per line or not - if data_type == 1 : + if data_type == OBI_INT : if (create or clone) : if nb_elements_per_line == 1 : subclass = OBIDMS_column_int_writable @@ -176,7 +199,7 @@ cdef class OBIDMS : subclass = OBIDMS_column_int else : subclass = OBIDMS_column_int_multi_elts - elif data_type == 2 : + elif data_type == OBI_FLOAT : if (create or clone) : if nb_elements_per_line == 1 : subclass = OBIDMS_column_float_writable @@ -187,7 +210,7 @@ cdef class OBIDMS : subclass = OBIDMS_column_float else : subclass = OBIDMS_column_float_multi_elts - elif data_type == 3 : + elif data_type == OBI_BOOL : if (create or clone) : if nb_elements_per_line == 1 : subclass = OBIDMS_column_bool_writable @@ -198,7 +221,7 @@ cdef class OBIDMS : subclass = OBIDMS_column_bool else : subclass = OBIDMS_column_bool_multi_elts - elif data_type == 4 : + elif data_type == OBI_CHAR : if (create or clone) : if nb_elements_per_line == 1 : subclass = OBIDMS_column_char_writable @@ -209,7 +232,7 @@ cdef class OBIDMS : subclass = OBIDMS_column_char else : subclass = OBIDMS_column_char_multi_elts - elif data_type == 5 : + elif data_type == OBI_STR : if (create or clone) : if nb_elements_per_line == 1 : subclass = OBIDMS_column_str_writable @@ -220,7 +243,7 @@ cdef class OBIDMS : subclass = OBIDMS_column_str else : subclass = OBIDMS_column_str_multi_elts - elif data_type == 6 : + elif data_type == OBI_SEQ : if (create or clone) : if nb_elements_per_line == 1 : subclass = OBIDMS_column_seq_writable @@ -254,7 +277,7 @@ cdef class OBIDMS_column : bint create, bint clone, bint clone_data, obiversion_t version_number, - OBIType_t type, # There's a problem with this with the OBI_IDX columns as there are 2 subtypes + OBIType_t type, index_t nb_lines, index_t nb_elements_per_line, list elements_names, @@ -267,7 +290,7 @@ cdef class OBIDMS_column : cdef bytes array_name_b cdef bytes elements_names_b cdef bytes comments_b - + # Fill structure self.dms = dms self.data_type = bytes2str(name_data_type(type)) diff --git a/python/obitools3/obidms/capi/obitypes.pxd b/python/obitools3/obidms/capi/obitypes.pxd index dae404c..374c7ee 100644 --- a/python/obitools3/obidms/capi/obitypes.pxd +++ b/python/obitools3/obidms/capi/obitypes.pxd @@ -17,7 +17,14 @@ cdef extern from "obidmscolumn.h" nogil: cdef extern from "obitypes.h" nogil: enum OBIType: - pass + OBI_VOID, + OBI_INT, + OBI_FLOAT, + OBI_BOOL, + OBI_CHAR, + OBI_STR, + OBI_SEQ + ctypedef OBIType OBIType_t