Conversation
libecl/include/ert/ecl/ecl_type.h
Outdated
|
|
||
| // In case of ECL_STRING_TYPE: | ||
| // length denotes the number of characters in the string | ||
| const size_t length; |
There was a problem hiding this comment.
If we introudcue this structure I think we should use it consistently - i.e. the sizeof_ctype field should be removed from the struct ecl_kw_struct - and:
lengthshould be renamedelement_sizeor something like that.element_sizeshould be correctly initialized for all the types, i.e.
#define ECL_INT (ecl_data_type) {.type = ECL_INT_TYPE, .element_size = 4}
|
Hmmm - where is the |
libecl/src/ecl_type.c
Outdated
| free(ecl_type); | ||
| } | ||
|
|
||
| ecl_data_type ecl_type_get_data_type(const ecl_type_enum type, const size_t element_size) { |
There was a problem hiding this comment.
This is function creates a new object - i.e. it is not a get function. I would suggest ecl_type / ecl_type_make / ecl_type_create / ....
libecl/src/ecl_type.c
Outdated
| } | ||
|
|
||
| void ecl_type_free(ecl_data_type * ecl_type) { | ||
| if(ecl_type == NULL) |
There was a problem hiding this comment.
Calling free( NULL ) is a safe no-op.
libecl/src/ecl_type.c
Outdated
| #define ECL_TYPE_NAME_BOOL "LOGI" | ||
| #define ECL_TYPE_NAME_MESSAGE "MESS" | ||
|
|
||
| ecl_data_type * ecl_type_alloc_copy(const ecl_data_type * src_type) { |
There was a problem hiding this comment.
As I see it the plan here is to use value semantics - with a publicly available struct definition. I would therefor suggest we just avoid implementing pointer specific functions like ecl_type_alloc_copy( ) and ecl_type_free( ).
libecl/src/ecl_type.c
Outdated
| return *ecl_type; | ||
| } | ||
|
|
||
| ecl_data_type ecl_type_get_data_type_from_type(const ecl_type_enum type) { |
There was a problem hiding this comment.
It is not get but rather make.
libecl/src/ecl_type.c
Outdated
| } | ||
|
|
||
| ecl_data_type ecl_type_get_data_type_from_type(const ecl_type_enum type) { | ||
| ecl_data_type * ecl_type = NULL; |
There was a problem hiding this comment.
No reason to go through the pointer, addressof and dereferencing - this should cut it:
switch(type) {
case(ECL_CHAR_TYPE) : return ECL_CHAR;
case(ECL_INT_TYPE) : return ECL_INT;
...
libecl/include/ert/ecl/ecl_kw.h
Outdated
| ecl_kw_type * ecl_kw_alloc_empty(void); | ||
| ecl_read_status_enum ecl_kw_fread_header(ecl_kw_type *, fortio_type *); | ||
| void ecl_kw_set_header_name(ecl_kw_type * , const char * ); | ||
| void ecl_kw_set_data_type(ecl_kw_type * , ecl_data_type); |
There was a problem hiding this comment.
Hmmm - should not be necessary with such a set function?
libecl/include/ert/ecl/ecl_type.h
Outdated
| #define ECL_FLOAT (ecl_data_type) {.type = ECL_FLOAT_TYPE, .element_size = sizeof(float)/sizeof(char)} | ||
| #define ECL_DOUBLE (ecl_data_type) {.type = ECL_DOUBLE_TYPE, .element_size = sizeof(double)/sizeof(char)} | ||
| #define ECL_BOOL (ecl_data_type) {.type = ECL_BOOL_TYPE, .element_size = sizeof(int)/sizeof(char)} | ||
| #define ECL_MESS (ecl_data_type) {.type = ECL_MESS_TYPE, .element_size = 1} |
There was a problem hiding this comment.
element_size = 0for ECL_MESS
| typedef struct ecl_type_struct ecl_data_type; | ||
|
|
||
|
|
||
| #define ECL_CHAR (ecl_data_type) {.type = ECL_CHAR_TYPE, .element_size = 8+1} |
There was a problem hiding this comment.
sizeof(char) is equal to 1 - by definition.
libecl/src/ecl_kw_grdecl.c
Outdated
| * Functions only to be used by the *PYTHON* prototype! | ||
| * | ||
| */ | ||
| ecl_kw_type * python_ecl_kw_fscanf_alloc_grdecl_dynamic__( FILE * stream , const char * kw , bool strict , const ecl_data_type * data_type) { |
There was a problem hiding this comment.
Make the python a suffix - i.e. ecl_kw_fscanf_alloc_grdecl_dynamic_python__( ) - what a name!
libecl/src/ecl_type.c
Outdated
|
|
||
| int ecl_type_get_sizeof_ctype_fortio(const ecl_data_type ecl_type) { | ||
| if(ecl_type_is_char(ecl_type) || ecl_type_is_C010(ecl_type)) | ||
| return (ecl_type.element_size - 1) * sizeof(char); |
libecl/src/ecl_type.c
Outdated
| * Functions only to be used by the *PYTHON* prototype! | ||
| * | ||
| */ | ||
|
|
There was a problem hiding this comment.
So many python functions they could get a file of their own.
|
Can we create some wrapping magic in Python so the old enum based way will continue to work, with a big fat warning? |
|
@joakim-hove: All of your suggestions are implemented |
76c1878 to
cd2c06f
Compare
libecl/src/ecl_type.c
Outdated
| return ecl_type.element_size; | ||
| } | ||
|
|
||
| const char * ecl_type_get_type_name(const ecl_data_type ecl_type) { |
There was a problem hiding this comment.
Can I have the slightly shorter: ecl_type_get_name( )?
|
OK - this is ready to be merged, but it will also affect opm (more than I thought ...) - so the merging must be coordinated. See: OPM/opm-output#176 |
version.__repr__ and test eq
* added an explicit flaky test; find out why it occasionally fails
fe0023e to
2958cbb
Compare
The first step towards supporting variable string length eclipse keywords (aka. Cxxx). The new data type ecl_data_type is a struct encapsulating the old ecl_type_enum, describing the type of the data, together with the length (that now can vary).
While propagating the new data type, the functionality of the type, both new and old, is moved to ecl_type.c.