diff --git a/python/obitools3/obidms/_obidms.pxd b/python/obitools3/obidms/_obidms.pxd index a25ad03..f29742d 100644 --- a/python/obitools3/obidms/_obidms.pxd +++ b/python/obitools3/obidms/_obidms.pxd @@ -24,7 +24,8 @@ cdef class OBIDMS: index_t nb_lines=*, index_t nb_elements_per_line=*, list elements_names=*, - str array_name=*) + str array_name=*, + str comments=*) cdef class OBIDMS_column: @@ -34,7 +35,7 @@ cdef class OBIDMS_column: cdef str data_type # TODO keep as OBIType_t? both? cdef str dms_name cdef str column_name - cdef index_t nb_elements_per_line + cdef index_t nb_elements_per_line cdef list elements_names # cpdef object get_item(self, index_t line_nb, str element_name) TODO can't declare because not the same in all subclasses @@ -43,5 +44,6 @@ cdef class OBIDMS_column: cpdef str get_data_type(self) cpdef index_t get_nb_lines_used(self) cpdef str get_creation_date(self) + cpdef str get_comments(self) cpdef close(self) diff --git a/python/obitools3/obidms/_obidms.pyx b/python/obitools3/obidms/_obidms.pyx index c9c72a9..5e352e8 100644 --- a/python/obitools3/obidms/_obidms.pyx +++ b/python/obitools3/obidms/_obidms.pyx @@ -120,7 +120,8 @@ cdef class OBIDMS : index_t nb_lines=0, index_t nb_elements_per_line=0, list elements_names=None, - str array_name="default_obiarray"): + str array_name="default_obiarray", + str comments=""): # Declarations cdef OBIDMS_column column @@ -221,7 +222,8 @@ cdef class OBIDMS : create, clone, clone_data, version_number, data_type, nb_lines, nb_elements_per_line, - elements_names, array_name) + elements_names, array_name, + comments) return column @@ -240,13 +242,15 @@ cdef class OBIDMS_column : index_t nb_lines, index_t nb_elements_per_line, list elements_names, - str array_name): + str array_name, + str comments): # Declarations cdef bytes column_name_b cdef bytes dms_name_b cdef bytes array_name_b cdef bytes elements_names_b + cdef bytes comments_b # Fill structure self.dms = dms @@ -259,6 +263,7 @@ cdef class OBIDMS_column : column_name_b = str2bytes(column_name) dms_name_b = str2bytes(self.dms.dms_name) array_name_b = str2bytes(array_name) + comments_b = str2bytes(comments) # Create, clone or open column if create : @@ -268,7 +273,7 @@ cdef class OBIDMS_column : elements_names_b = str2bytes(";".join(elements_names)) self.pointer = obi_create_column(self.dms.pointer, column_name_b, type, nb_lines, nb_elements_per_line, - elements_names_b, array_name_b) + elements_names_b, array_name_b, comments_b) else : if clone : self.pointer = obi_clone_column(self.dms.pointer, column_name_b, version_number, clone_data) @@ -327,6 +332,8 @@ cdef class OBIDMS_column : cpdef str get_creation_date(self): return bytes2str(obi_column_format_date(self.pointer.header.creation_date)) + cpdef str get_comments(self): + return bytes2str(self.pointer.header.comments) cpdef close(self): raise NotImplementedError diff --git a/python/obitools3/obidms/capi/obidmscolumn.pxd b/python/obitools3/obidms/capi/obidmscolumn.pxd index 44163dd..497e03a 100644 --- a/python/obitools3/obidms/capi/obidmscolumn.pxd +++ b/python/obitools3/obidms/capi/obidmscolumn.pxd @@ -43,7 +43,8 @@ cdef extern from "obidmscolumn.h" nogil: index_t nb_lines, index_t nb_elements_per_line, const_char_p elements_names, - const_char_p array_name) + const_char_p array_name, + const_char_p comments) OBIDMS_column_p obi_open_column(OBIDMS_p dms, const_char_p column_name, diff --git a/src/obiarray.h b/src/obiarray.h index df7997f..80f7276 100644 --- a/src/obiarray.h +++ b/src/obiarray.h @@ -25,7 +25,7 @@ #include "obitypes.h" -#define ARRAY_MAX_NAME (2048) /**< The maximum length of an array name. +#define ARRAY_MAX_NAME (1024) /**< The maximum length of an array name. */ #define ARRAY_GROWTH_FACTOR (2) /**< The growth factor when an array is enlarged. */ diff --git a/src/obidmscolumn.c b/src/obidmscolumn.c index 4ae2d4d..c87d8e9 100644 --- a/src/obidmscolumn.c +++ b/src/obidmscolumn.c @@ -495,7 +495,8 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms, index_t nb_lines, index_t nb_elements_per_line, const char* elements_names, - const char* array_name) + const char* array_name, + const char* comments) { OBIDMS_column_p new_column; OBIDMS_column_directory_p column_directory; @@ -682,12 +683,14 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms, header->creation_date = time(NULL); header->version = version_number; header->cloned_from = -1; - header->comments[0] = 0x0; // TODO obi_column_set_elements_names(new_column, elements_names); strncpy(header->name, column_name, OBIDMS_COLUMN_MAX_NAME); + if (comments != NULL) + strncpy(header->comments, comments, COMMENTS_MAX_LENGTH); + // If the data type is OBI_IDX, the associated obi_array is opened or created if (data_type == 5) { @@ -880,7 +883,8 @@ OBIDMS_column_p obi_clone_column(OBIDMS_p dms, nb_lines, nb_elements_per_line, (column_to_clone->header)->elements_names, - (column_to_clone->header)->array_name); + (column_to_clone->header)->array_name, + (column_to_clone->header)->comments); if (new_column == NULL) { @@ -893,7 +897,6 @@ OBIDMS_column_p obi_clone_column(OBIDMS_p dms, } (new_column->header)->cloned_from = version_number; - //memcpy((new_column->header)->comments, (column_to_clone->header)->comments, obi_get_platform_header_size() - //??(column_to_clone->header)->comments); // TODO if (clone_data) { @@ -1284,7 +1287,7 @@ int obi_unmap_header(OBIDMS_column_header_p header) } -// TODO to be rewritten in an optimized and safe way +// TODO to be rewritten in an optimized and safe way if possible index_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const char* element_name) { char* elements_names; diff --git a/src/obidmscolumn.h b/src/obidmscolumn.h index bcf76bb..64d89ae 100644 --- a/src/obidmscolumn.h +++ b/src/obidmscolumn.h @@ -36,9 +36,10 @@ */ #define MAXIMUM_LINE_COUNT (1000000) /**< The maximum line count for the data of a column. //TODO */ -#define FORMATTED_TIME_LENGTH (1024) /**< The length allocated for the character string containing a formatted date +#define FORMATTED_TIME_LENGTH (1024) /**< The length allocated for the character string containing a formatted date. + */ +#define COMMENTS_MAX_LENGTH (2048) /**< The maximum length for comments. */ - typedef int32_t obiversion_t; /**< Used to store the column version number */ @@ -75,8 +76,7 @@ typedef struct OBIDMS_column_header { */ char array_name[ARRAY_MAX_NAME+1]; /**< If there is one, the obi_array name as a NULL terminated string. */ - char comments[1]; /**< Comments stored as a classical zero end C string. - * The size of the comment is only limited by the header size. + char comments[COMMENTS_MAX_LENGTH+1]; /**< Comments stored as a classical zero end C string. */ } OBIDMS_column_header_t, *OBIDMS_column_header_p; @@ -182,7 +182,8 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms, index_t nb_lines, index_t nb_elements_per_line, const char* elements_names, - const char* array_name); + const char* array_name, + const char* comments); /** diff --git a/src/obidmscolumndir.h b/src/obidmscolumndir.h index 2ec8a4f..5d62a6a 100644 --- a/src/obidmscolumndir.h +++ b/src/obidmscolumndir.h @@ -21,7 +21,7 @@ #include "obidms.h" -#define OBIDMS_COLUMN_MAX_NAME (2048) /**< The maximum length of an OBIDMS column name. +#define OBIDMS_COLUMN_MAX_NAME (1024) /**< The maximum length of an OBIDMS column name. */