static int well_state_get_lgr_well_nr( const well_state_type * well_state , const ecl_file_type * ecl_file) { int well_nr = -1; if (ecl_file_has_kw( ecl_file , ZWEL_KW)) { ecl_rsthead_type * header = ecl_rsthead_alloc( ecl_file ); const ecl_kw_type * zwel_kw = ecl_file_iget_named_kw( ecl_file , ZWEL_KW , 0 ); int num_wells = header->nwells; well_nr = 0; while (true) { bool found = false; { char * lgr_well_name = util_alloc_strip_copy( ecl_kw_iget_ptr( zwel_kw , well_nr * header->nzwelz) ); if ( strcmp( well_state->name , lgr_well_name) == 0) found = true; else well_nr++; free( lgr_well_name ); } if (found) break; else if (well_nr == num_wells) { // The well is not in this LGR at all. well_nr = -1; break; } } ecl_rsthead_free( header ); } return well_nr; }
well_state_type * well_state_alloc_from_file( ecl_file_type * ecl_file , const ecl_grid_type * grid , int report_nr , int global_well_nr ,bool load_segment_information) { if (ecl_file_has_kw( ecl_file , IWEL_KW)) { well_state_type * well_state = NULL; ecl_rsthead_type * global_header = ecl_rsthead_alloc( ecl_file ); const ecl_kw_type * global_iwel_kw = ecl_file_iget_named_kw( ecl_file , IWEL_KW , 0); const ecl_kw_type * global_zwel_kw = ecl_file_iget_named_kw( ecl_file , ZWEL_KW , 0); const int iwel_offset = global_header->niwelz * global_well_nr; { char * name; bool open; well_type_enum type = UNDOCUMENTED_ZERO; { int int_state = ecl_kw_iget_int( global_iwel_kw , iwel_offset + IWEL_STATUS_ITEM ); if (int_state > 0) open = true; else open = false; } { int int_type = ecl_kw_iget_int( global_iwel_kw , iwel_offset + IWEL_TYPE_ITEM); type = well_state_translate_ecl_type_int( int_type ); } { const int zwel_offset = global_header->nzwelz * global_well_nr; name = util_alloc_strip_copy(ecl_kw_iget_ptr( global_zwel_kw , zwel_offset )); // Hardwired max 8 characters in Well Name } well_state = well_state_alloc(name , global_well_nr , open , type , report_nr , global_header->sim_time); free( name ); well_state_add_connections( well_state , grid , ecl_file , global_well_nr); if (ecl_file_has_kw( ecl_file , ISEG_KW)) well_state_add_MSW( well_state , ecl_file , global_well_nr , load_segment_information); } ecl_rsthead_free( global_header ); return well_state; } else /* This seems a bit weird - have come over E300 restart files without the IWEL keyword. */ return NULL; }
ecl_rft_node_type * ecl_rft_node_alloc(const ecl_file_view_type * rft_view) { ecl_kw_type * welletc = ecl_file_view_iget_named_kw(rft_view , WELLETC_KW , 0); ecl_rft_node_type * rft_node = ecl_rft_node_alloc_empty(ecl_kw_iget_ptr(welletc , WELLETC_TYPE_INDEX)); if (rft_node != NULL) { ecl_kw_type * date_kw = ecl_file_view_iget_named_kw( rft_view , DATE_KW , 0); rft_node->well_name = util_alloc_strip_copy( ecl_kw_iget_ptr(welletc , WELLETC_NAME_INDEX)); /* Time information. */ { int * time = ecl_kw_get_int_ptr( date_kw ); rft_node->recording_date = ecl_util_make_date( time[DATE_DAY_INDEX] , time[DATE_MONTH_INDEX] , time[DATE_YEAR_INDEX] ); } rft_node->days = ecl_kw_iget_float( ecl_file_view_iget_named_kw( rft_view , TIME_KW , 0 ) , 0); if (ecl_file_view_has_kw( rft_view , CONLENST_KW)) rft_node->MSW = true; else rft_node->MSW = false; ecl_rft_node_init_cells( rft_node , rft_view ); } return rft_node; }
int main(int argc , char ** argv) { const char * Xfile = argv[1]; ecl_file_type * rst_file = ecl_file_open( Xfile , 0 ); ecl_rsthead_type * rst_head = ecl_rsthead_alloc( ecl_file_get_global_view(rst_file) , ecl_util_filename_report_nr(Xfile)); const ecl_kw_type * iwel_kw = ecl_file_iget_named_kw( rst_file , IWEL_KW , 0 ); const ecl_kw_type * iseg_kw = ecl_file_iget_named_kw( rst_file , ISEG_KW , 0 ); well_rseg_loader_type * rseg_loader = well_rseg_loader_alloc(ecl_file_get_global_view(rst_file)); const ecl_kw_type * icon_kw = ecl_file_iget_named_kw( rst_file , ICON_KW , 0 ); const ecl_kw_type * scon_kw = ecl_file_iget_named_kw( rst_file , SCON_KW , 0 ); const ecl_kw_type * zwel_kw = ecl_file_iget_named_kw( rst_file , ZWEL_KW , 0 ); { int well_nr; for (well_nr = 0; well_nr < rst_head->nwells; well_nr++) { const int zwel_offset = rst_head->nzwelz * well_nr; char * well_name = util_alloc_strip_copy(ecl_kw_iget_ptr( zwel_kw , zwel_offset )); printf("=================================================================\n"); printf("Well: %s ",well_name); { well_conn_collection_type * connections = well_conn_collection_alloc(); well_segment_collection_type * segments = well_segment_collection_alloc(); bool load_segment_information = true; bool is_MSW_well = false; if (well_segment_collection_load_from_kw( segments , well_nr , iwel_kw , iseg_kw , rseg_loader , rst_head , load_segment_information , &is_MSW_well)) { well_branch_collection_type * branches = well_branch_collection_alloc(); well_conn_collection_load_from_kw( connections , iwel_kw , icon_kw , scon_kw , well_nr , rst_head); well_segment_collection_link( segments ); well_segment_collection_add_branches( segments , branches ); well_segment_collection_add_connections( segments , ECL_GRID_GLOBAL_GRID , connections ); printf("\n"); printf("Segments:\n"); { int is; for (is=0; is < well_segment_collection_get_size( segments ); is++) { well_segment_type * segment = well_segment_collection_iget( segments , is ); printf("-----------------------------------------------------------------\n"); printf("ID : %d \n",well_segment_get_id( segment )); printf("Outlet : %d \n",well_segment_get_outlet_id( segment )); printf("Branch : %d \n",well_segment_get_branch_id( segment )); printf("Connections : ["); { const well_conn_collection_type * connections = well_segment_get_global_connections( segment ); if (connections) { int ic; for (ic = 0; ic < well_conn_collection_get_size( connections ); ic++) { const well_conn_type * conn = well_conn_collection_iget( connections , ic ); printf("(%d , %d , %d) ",well_conn_get_i( conn ), well_conn_get_j( conn ), well_conn_get_k( conn )); } } } printf("]\n"); } } well_branch_collection_free( branches ); } else printf("not MSW well\n\n"); well_conn_collection_free( connections ); well_segment_collection_free( segments ); } } } ecl_file_close( rst_file ); ecl_rsthead_free( rst_head ); }