int main(int argc , char ** argv) { test_install_SIGNALS(); { const char * grid_file = argv[1]; const char * rst_file_name = argv[2]; ecl_grid_type * grid = ecl_grid_alloc( grid_file ); ecl_file_type * rst_file = ecl_file_open( rst_file_name , 0); ecl_rsthead_type * header = ecl_rsthead_alloc( ecl_file_get_global_view( rst_file ) , ecl_util_filename_report_nr(rst_file_name) ); const char * well_name = "WELL"; int report_nr = 100; time_t valid_from = -1; bool open = false; well_type_enum type = ERT_GAS_INJECTOR; int global_well_nr = 0; bool load_segment_information = true; ecl_file_view_type * rst_view = ecl_file_get_global_view( rst_file ); for (global_well_nr = 0; global_well_nr < header->nwells; global_well_nr++) { well_state_type * well_state = well_state_alloc(well_name , global_well_nr , open , type , report_nr , valid_from); test_assert_true( well_state_is_instance( well_state) ); well_state_add_connections2( well_state , grid , rst_view , 0 ); test_assert_true( well_state_has_grid_connections( well_state , ECL_GRID_GLOBAL_GRID )); test_assert_false( well_state_has_grid_connections( well_state , "???" )); test_assert_true( well_state_has_global_connections( well_state )); well_state_add_MSW2( well_state , rst_view , global_well_nr , load_segment_information ); { const well_segment_collection_type * segments = well_state_get_segments( well_state ); const well_branch_collection_type * branches = well_state_get_branches( well_state ); if (well_state_is_MSW( well_state )) { test_assert_true( ecl_file_has_kw( rst_file , ISEG_KW )); test_assert_int_not_equal( well_segment_collection_get_size( segments ) , 0); test_assert_int_not_equal( well_branch_collection_get_size( branches ) , 0); } else { test_assert_int_equal( well_segment_collection_get_size( segments ) , 0); test_assert_int_equal( well_branch_collection_get_size( branches ) , 0); test_assert_false( well_state_is_MSW( well_state )); } } well_state_free( well_state ); } } exit(0); }
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; }