ecl_rft_file_type * ecl_rft_file_alloc(const char * filename) { ecl_rft_file_type * rft_vector = ecl_rft_file_alloc_empty( filename ); ecl_file_type * ecl_file = ecl_file_open( filename , 0); int global_index = 0; int block_nr = 0; while (true) { if (ecl_file_select_block( ecl_file , TIME_KW , block_nr)) { ecl_rft_node_type * rft_node = ecl_rft_node_alloc( ecl_file ); if (rft_node != NULL) { const char * well_name = ecl_rft_node_get_well_name( rft_node ); ecl_rft_file_add_node(rft_vector , rft_node); if (!hash_has_key( rft_vector->well_index , well_name)) hash_insert_hash_owned_ref( rft_vector->well_index , well_name , int_vector_alloc( 0 , 0 ) , int_vector_free__); { int_vector_type * index_list = hash_get( rft_vector->well_index , well_name ); int_vector_append(index_list , global_index); } global_index++; } } else break; block_nr++; } ecl_file_close( ecl_file ); return rft_vector; }
void ecl_rft_file_update(const char * rft_file_name, ecl_rft_node_type ** nodes,int num_nodes, ert_ecl_unit_enum unit_set){ ecl_rft_file_type * rft_file; if(util_file_exists(rft_file_name)){ int node_index; rft_file = ecl_rft_file_alloc( rft_file_name ); for(node_index = 0; node_index < num_nodes; node_index++) { ecl_rft_node_type * new_node = nodes[node_index]; int storage_index = ecl_rft_file_get_node_index_time_rft(rft_file, ecl_rft_node_get_well_name(new_node), ecl_rft_node_get_date(new_node)); if (storage_index == -1) { ecl_rft_file_add_node(rft_file, new_node); } else { vector_iset_owned_ref(rft_file->data, storage_index, new_node,ecl_rft_node_free__); } } }else{ int node_index; rft_file = ecl_rft_file_alloc_empty( rft_file_name ); for(node_index = 0; node_index < num_nodes; node_index++) { ecl_rft_file_add_node(rft_file, nodes[node_index]); } } { bool fmt_file = false; fortio_type * fortio = fortio_open_writer( rft_file_name , fmt_file , ECL_ENDIAN_FLIP ); int node_index; /** The sorting here works directly on the internal node storage rft_file->data; that might in principle ruin the indexing of the ecl_file object - it is therefor absolutely essential that this ecl_rft_file object does not live beyond this function, and also that the ecl_rft_file api functions are avoided for the rest of this function. */ vector_sort(rft_file->data,(vector_cmp_ftype *) ecl_rft_node_cmp); for(node_index=0; node_index < vector_get_size( rft_file->data ); node_index++) { const ecl_rft_node_type *new_node = vector_iget_const(rft_file->data, node_index); ecl_rft_node_fwrite(new_node, fortio, unit_set); } fortio_fclose( fortio ); } ecl_rft_file_free(rft_file); }
int ecl_rft_file_get_size__( const ecl_rft_file_type * rft_file, const char * well_pattern , time_t recording_time) { if ((well_pattern == NULL) && (recording_time < 0)) return vector_get_size( rft_file->data ); else { int match_count = 0; int i; for ( i=0; i < vector_get_size( rft_file->data ); i++) { const ecl_rft_node_type * rft = vector_iget_const( rft_file->data , i); if (well_pattern) { if (util_fnmatch( well_pattern , ecl_rft_node_get_well_name( rft )) != 0) continue; } /*OK - we either do not care about the well, or alternatively the well matches. */ if (recording_time >= 0) { if (recording_time != ecl_rft_node_get_date( rft )) continue; } match_count++; } return match_count; } }
void ecl_rft_node_fwrite(const ecl_rft_node_type * rft_node, fortio_type * fortio, ert_ecl_unit_enum unit_set){ ecl_rft_enum type = ecl_rft_node_get_type(rft_node); if (type != RFT) util_abort("%s: sorry - only writing of simple RFT is currently implemented",__func__); { ecl_kw_type * time = ecl_kw_alloc(TIME_KW, 1, ECL_FLOAT_TYPE); ecl_kw_iset_float(time, 0, ecl_rft_node_get_days(rft_node)); ecl_kw_fwrite(time, fortio); ecl_kw_free(time); } { ecl_kw_type * datevalue = ecl_kw_alloc(DATE_KW, 3, ECL_INT_TYPE); time_t date = ecl_rft_node_get_date(rft_node); int day; int month; int year; ecl_util_set_date_values(date , &day , &month , &year); ecl_kw_iset_int(datevalue, 0, day); ecl_kw_iset_int(datevalue, 1, month); ecl_kw_iset_int(datevalue, 2, year); ecl_kw_fwrite(datevalue, fortio); ecl_kw_free(datevalue); } { ecl_kw_type * welletc = ecl_kw_alloc(WELLETC_KW, 16, ECL_CHAR_TYPE); ecl_rft_enum type = ecl_rft_node_get_type(rft_node); ecl_kw_iset_string8(welletc, 1, ecl_rft_node_get_well_name(rft_node)); if(type == PLT) { ecl_kw_iset_string8(welletc, 5, "P"); }else if(type == RFT){ ecl_kw_iset_string8(welletc, 5, "R"); }else if(type == SEGMENT){ ecl_kw_iset_string8(welletc, 5, "S"); } ecl_rft_node_fill_welletc(welletc, unit_set); ecl_kw_fwrite(welletc, fortio); ecl_kw_free(welletc); } { int size_cells = ecl_rft_node_get_size(rft_node); ecl_kw_type * conipos = ecl_kw_alloc(CONIPOS_KW, size_cells, ECL_INT_TYPE); ecl_kw_type * conjpos = ecl_kw_alloc(CONJPOS_KW, size_cells, ECL_INT_TYPE); ecl_kw_type * conkpos = ecl_kw_alloc(CONKPOS_KW, size_cells, ECL_INT_TYPE); ecl_kw_type * hostgrid = ecl_kw_alloc(HOSTGRID_KW, size_cells, ECL_CHAR_TYPE); ecl_kw_type * depth = ecl_kw_alloc(DEPTH_KW, size_cells, ECL_FLOAT_TYPE); ecl_kw_type * pressure = ecl_kw_alloc(PRESSURE_KW, size_cells, ECL_FLOAT_TYPE); ecl_kw_type * swat = ecl_kw_alloc(SWAT_KW, size_cells, ECL_FLOAT_TYPE); ecl_kw_type * sgas = ecl_kw_alloc(SGAS_KW, size_cells, ECL_FLOAT_TYPE); int i; for(i =0;i<size_cells;i++){ const ecl_rft_cell_type * cell = vector_iget_const( rft_node->cells , i); ecl_kw_iset_int(conipos, i, ecl_rft_cell_get_i(cell)+1); ecl_kw_iset_int(conjpos, i, ecl_rft_cell_get_j(cell)+1); ecl_kw_iset_int(conkpos, i, ecl_rft_cell_get_k(cell)+1); ecl_kw_iset_float(depth, i, ecl_rft_cell_get_depth(cell)); ecl_kw_iset_float(pressure, i, ecl_rft_cell_get_pressure(cell)); ecl_kw_iset_float(swat, i, ecl_rft_cell_get_swat(cell)); ecl_kw_iset_float(sgas, i, ecl_rft_cell_get_sgas(cell)); } ecl_kw_fwrite(conipos, fortio); ecl_kw_fwrite(conjpos, fortio); ecl_kw_fwrite(conkpos, fortio); ecl_kw_fwrite(hostgrid, fortio); ecl_kw_fwrite(depth, fortio); ecl_kw_fwrite(pressure, fortio); ecl_kw_fwrite(swat, fortio); ecl_kw_fwrite(sgas, fortio); ecl_kw_free(conipos); ecl_kw_free(conjpos); ecl_kw_free(conkpos); ecl_kw_free(hostgrid); ecl_kw_free(depth); ecl_kw_free(pressure); ecl_kw_free(swat); ecl_kw_free(sgas); } }