Skip to content
This repository was archived by the owner on Sep 30, 2020. It is now read-only.

New eclipse data type #1439

Merged
joakim-hove merged 53 commits intoEnsembles:masterfrom
markusdregi:ecl_string_type
Apr 3, 2017
Merged

New eclipse data type #1439
joakim-hove merged 53 commits intoEnsembles:masterfrom
markusdregi:ecl_string_type

Conversation

@markusdregi
Copy link
Contributor

@markusdregi markusdregi commented Mar 10, 2017

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.


// In case of ECL_STRING_TYPE:
// length denotes the number of characters in the string
const size_t length;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. length should be renamed element_size or something like that.
  2. element_size should be correctly initialized for all the types, i.e.
#define ECL_INT (ecl_data_type) {.type = ECL_INT_TYPE, .element_size = 4}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree!

@joakim-hove
Copy link
Contributor

Hmmm - where is the tests/ecl_type_test.c file?:smile:

free(ecl_type);
}

ecl_data_type ecl_type_get_data_type(const ecl_type_enum type, const size_t element_size) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 / ....

}

void ecl_type_free(ecl_data_type * ecl_type) {
if(ecl_type == NULL)
Copy link
Contributor

@joakim-hove joakim-hove Mar 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling free( NULL ) is a safe no-op.

#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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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( ).

return *ecl_type;
}

ecl_data_type ecl_type_get_data_type_from_type(const ecl_type_enum type) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not get but rather make.

}

ecl_data_type ecl_type_get_data_type_from_type(const ecl_type_enum type) {
ecl_data_type * ecl_type = NULL;
Copy link
Contributor

@joakim-hove joakim-hove Mar 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
   ...

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm - should not be necessary with such a set function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree

#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}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sizeof(char) is equal to 1 - by definition.

* 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) {
Copy link
Contributor

@joakim-hove joakim-hove Mar 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the python a suffix - i.e. ecl_kw_fscanf_alloc_grdecl_dynamic_python__( ) - what a name!


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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sizeof(char) is 1.

* Functions only to be used by the *PYTHON* prototype!
*
*/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So many python functions they could get a file of their own.

@joakim-hove
Copy link
Contributor

Can we create some wrapping magic in Python so the old enum based way will continue to work, with a big fat warning?

@markusdregi
Copy link
Contributor Author

@joakim-hove: All of your suggestions are implemented

@markusdregi markusdregi changed the title WIP: Ecl variable length string WIP: New eclipse data type Mar 21, 2017
@markusdregi markusdregi changed the title WIP: New eclipse data type New eclipse data type Mar 21, 2017
return ecl_type.element_size;
}

const char * ecl_type_get_type_name(const ecl_data_type ecl_type) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I have the slightly shorter: ecl_type_get_name( )?

@joakim-hove
Copy link
Contributor

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

pgdr and others added 3 commits March 27, 2017 09:48
* added an explicit flaky test; find out why it occasionally fails
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants