static void gen_data_ecl_write_ASCII(const gen_data_type * gen_data , const char * file , gen_data_file_format_type export_format) { FILE * stream = util_fopen(file , "w"); char * template_buffer; int template_data_offset, template_buffer_size , template_data_skip; if (export_format == ASCII_TEMPLATE) { gen_data_config_get_template_data( gen_data->config , &template_buffer , &template_data_offset , &template_buffer_size , &template_data_skip); util_fwrite( template_buffer , 1 , template_data_offset , stream , __func__); } { ecl_data_type internal_type = gen_data_config_get_internal_data_type(gen_data->config); const int size = gen_data_config_get_data_size( gen_data->config , gen_data->current_report_step ); int i; if (ecl_type_is_float(internal_type)) { float * float_data = (float *) gen_data->data; for (i=0; i < size; i++) fprintf(stream , "%g\n",float_data[i]); } else if (ecl_type_is_double(internal_type)) { double * double_data = (double *) gen_data->data; for (i=0; i < size; i++) fprintf(stream , "%lg\n",double_data[i]); } else util_abort("%s: internal error - wrong type \n",__func__); } if (export_format == ASCII_TEMPLATE) { int new_offset = template_data_offset + template_data_skip; util_fwrite( &template_buffer[new_offset] , 1 , template_buffer_size - new_offset , stream , __func__); } fclose(stream); }
void gen_data_serialize(const gen_data_type * gen_data , node_id_type node_id , const active_list_type * active_list , matrix_type * A , int row_offset , int column) { const gen_data_config_type *config = gen_data->config; const int data_size = gen_data_config_get_data_size( gen_data->config , gen_data->current_report_step ); ecl_data_type data_type = gen_data_config_get_internal_data_type( config ); enkf_matrix_serialize( gen_data->data , data_size , data_type , active_list , A , row_offset , column ); }
void gen_data_isqrt(gen_data_type * gen_data) { const int data_size = gen_data_config_get_data_size( gen_data->config , gen_data->current_report_step ); const ecl_data_type internal_type = gen_data_config_get_internal_data_type(gen_data->config); if (ecl_type_is_float(internal_type)) { float * data = (float *) gen_data->data; for (int i=0; i < data_size; i++) data[i] = sqrtf( data[i] ); } else if (ecl_type_is_double(internal_type)) { double * data = (double *) gen_data->data; for (int i=0; i < data_size; i++) data[i] = sqrt( data[i] ); } }
void gen_data_isqrt(gen_data_type * gen_data) { const int data_size = gen_data_config_get_data_size( gen_data->config , gen_data->current_report_step ); const ecl_type_enum internal_type = gen_data_config_get_internal_type(gen_data->config); if (internal_type == ECL_FLOAT_TYPE) { float * data = (float *) gen_data->data; for (int i=0; i < data_size; i++) data[i] = sqrtf( data[i] ); } else if (internal_type == ECL_DOUBLE_TYPE) { double * data = (double *) gen_data->data; for (int i=0; i < data_size; i++) data[i] = sqrt( data[i] ); } }
bool gen_data_user_get(const gen_data_type * gen_data, const char * index_key, int report_step , double * value) { int index; *value = 0.0; if (index_key != NULL) { if (util_sscanf_int(index_key , &index)) { if (index < gen_data_config_get_data_size( gen_data->config , gen_data->current_report_step )) { *value = gen_data_iget_double( gen_data , index ); return true; } } } return false; }
void gen_data_scale(gen_data_type * gen_data, double scale_factor) { //gen_data_config_assert_unary(gen_data->config, __func__); { const int data_size = gen_data_config_get_data_size( gen_data->config , gen_data->current_report_step ); const ecl_data_type internal_type = gen_data_config_get_internal_data_type(gen_data->config); int i; if (ecl_type_is_float(internal_type)) { float * data = (float *) gen_data->data; for (i = 0; i < data_size; i++) data[i] *= scale_factor; } else if (ecl_type_is_double(internal_type)) { double * data = (double *) gen_data->data; for (i = 0; i < data_size; i++) data[i] *= scale_factor; } } }
void gen_data_set_inflation(gen_data_type * inflation , const gen_data_type * std , const gen_data_type * min_std) { const gen_data_config_type * config = inflation->config; ecl_data_type data_type = gen_data_config_get_internal_data_type( config ); const int data_size = gen_data_config_get_data_size( std->config , std->current_report_step ); if (ecl_type_is_float(data_type)) { float * inflation_data = (float *) inflation->data; const float * std_data = (const float *) std->data; const float * min_std_data = (const float *) min_std->data; INFLATE(inflation_data , std_data , min_std_data ); } else { double * inflation_data = (double *) inflation->data; const double * std_data = (const double *) std->data; const double * min_std_data = (const double *) min_std->data; INFLATE(inflation_data , std_data , min_std_data ); } }
void gen_data_iaddsqr(gen_data_type * gen_data1, const gen_data_type * gen_data2) { //gen_data_config_assert_binary(gen_data1->config , gen_data2->config , __func__); { const int data_size = gen_data_config_get_data_size( gen_data1->config , gen_data1->current_report_step ); const ecl_data_type internal_type = gen_data_config_get_internal_data_type(gen_data1->config); int i; if (ecl_type_is_float(internal_type)) { float * data1 = (float *) gen_data1->data; const float * data2 = (const float *) gen_data2->data; for (i = 0; i < data_size; i++) data1[i] += data2[i] * data2[i]; } else if (ecl_type_is_double(internal_type)) { double * data1 = (double *) gen_data1->data; const double * data2 = (const double *) gen_data2->data; for (i = 0; i < data_size; i++) data1[i] += data2[i] * data2[i]; } } }
bool gen_data_write_to_buffer(const gen_data_type * gen_data , buffer_type * buffer , int report_step) { const bool write_zero_size = true; /* true:ALWAYS write a file false:only write files with size > 0. */ { bool write = write_zero_size; int size = gen_data_config_get_data_size( gen_data->config , report_step ); if (size > 0) write = true; if (write) { int byte_size = gen_data_config_get_byte_size( gen_data->config , report_step ); buffer_fwrite_int( buffer , GEN_DATA ); buffer_fwrite_int( buffer , size ); buffer_fwrite_int( buffer , report_step); /* Why the heck do I need to store this ???? It was a mistake ...*/ buffer_fwrite_compressed( buffer , gen_data->data , byte_size); return true; } else return false; /* When false is returned - the (empty) file will be removed */ } }
void gen_data_imul(gen_data_type * gen_data1, const gen_data_type * gen_data2) { //gen_data_config_assert_binary(gen_data1->config , gen_data2->config , __func__); { const int data_size = gen_data_config_get_data_size( gen_data1->config , gen_data1->current_report_step ); const ecl_type_enum internal_type = gen_data_config_get_internal_type(gen_data1->config); int i; if (internal_type == ECL_FLOAT_TYPE) { float * data1 = (float *) gen_data1->data; const float * data2 = (const float *) gen_data2->data; for (i = 0; i < data_size; i++) data1[i] *= data2[i]; } else if (internal_type == ECL_DOUBLE_TYPE) { double * data1 = (double *) gen_data1->data; const double * data2 = (const double *) gen_data2->data; for (i = 0; i < data_size; i++) data1[i] *= data2[i]; } } }
int enkf_config_node_get_data_size( const enkf_config_node_type * node , int report_step) { if (node->impl_type == GEN_DATA) return gen_data_config_get_data_size( node->data , report_step); else return node->get_data_size( node->data ); }
int gen_data_config_get_byte_size( const gen_data_config_type * config , int report_step) { int byte_size = gen_data_config_get_data_size( config , report_step ) * ecl_util_get_sizeof_ctype( config->internal_type ); return byte_size; }
int gen_data_get_size( const gen_data_type * gen_data ) { return gen_data_config_get_data_size( gen_data->config , gen_data->current_report_step ); }
static void gen_data_assert_index(const gen_data_type * gen_data, int index) { int current_size = gen_data_config_get_data_size( gen_data->config , gen_data->current_report_step ); if ((index < 0) || (index >= current_size )) util_abort("%s: index:%d invalid. Valid range: [0,%d) \n",__func__ , index , current_size); }
static void gen_data_ecl_write_binary(const gen_data_type * gen_data , const char * file , ecl_data_type export_type) { FILE * stream = util_fopen(file , "w"); int sizeof_ctype = ecl_type_get_sizeof_ctype( export_type ); util_fwrite( gen_data->data , sizeof_ctype , gen_data_config_get_data_size( gen_data->config , gen_data->current_report_step) , stream , __func__); fclose(stream); }