void test_get_tranLL(const char * name) { char * grid_file_name = ecl_util_alloc_filename(NULL , name , ECL_EGRID_FILE , false , -1); char * init_file_name = ecl_util_alloc_filename(NULL , name , ECL_INIT_FILE , false , -1); ecl_grid_type * grid = ecl_grid_alloc( grid_file_name ); ecl_file_type * grid_file = ecl_file_open( grid_file_name , 0 ); ecl_file_type * init_file = ecl_file_open( init_file_name , 0 ); test_tranLL( grid , init_file , ecl_grid_get_lgr_nr_from_name( grid , "LG003017" ), ecl_grid_get_lgr_nr_from_name( grid , "LG003018" ), 172 , 5.3957253 , 1.0099934); test_tranLL( grid , init_file , ecl_grid_get_lgr_nr_from_name( grid , "LG002016" ), ecl_grid_get_lgr_nr_from_name( grid , "LG002017" ), 93 , 1.4638059 , 0.36407200 ); test_tranLL( grid , init_file , ecl_grid_get_lgr_nr_from_name( grid , "LG002016" ), ecl_grid_get_lgr_nr_from_name( grid , "LG003016" ), 56 , 2.7360380 , 10.053267); test_tranLL( grid , init_file , ecl_grid_get_lgr_nr_from_name( grid , "LG009027" ), ecl_grid_get_lgr_nr_from_name( grid , "LG009026" ), 152 , 155.47754, 219.23553); test_tranLL( grid , init_file , ecl_grid_get_lgr_nr_from_name( grid , "LG009027" ), ecl_grid_get_lgr_nr_from_name( grid , "LG008027" ), 317 , 0.040260997 , 0.0066288318); free( init_file_name ); free(grid_file_name); ecl_grid_free( grid ); ecl_file_close( grid_file ); ecl_file_close( init_file ); }
static void ecl_sum_data_fread__( ecl_sum_data_type * data , time_t load_end , const stringlist_type * filelist) { ecl_file_enum file_type; if (stringlist_get_size( filelist ) == 0) util_abort("%s: internal error - function called with empty list of data files.\n",__func__); file_type = ecl_util_get_file_type( stringlist_iget( filelist , 0 ) , NULL , NULL); if ((stringlist_get_size( filelist ) > 1) && (file_type != ECL_SUMMARY_FILE)) util_abort("%s: internal error - when calling with more than one file - you can not supply a unified file - come on?! \n",__func__); { int filenr; if (file_type == ECL_SUMMARY_FILE) { /* Not unified. */ for (filenr = 0; filenr < stringlist_get_size( filelist ); filenr++) { const char * data_file = stringlist_iget( filelist , filenr); ecl_file_enum file_type; int report_step; file_type = ecl_util_get_file_type( data_file , NULL , &report_step); /** ECLIPSE starts a report step by writing an empty summary file, therefor we must verify that the ecl_file instance returned by ecl_file_fread_alloc() is different from NULL before adding it to the ecl_sum_data instance. */ if (file_type != ECL_SUMMARY_FILE) util_abort("%s: file:%s has wrong type \n",__func__ , data_file); { ecl_file_type * ecl_file = ecl_file_open( data_file ); ecl_sum_data_add_ecl_file( data , load_end , report_step , ecl_file , data->smspec); ecl_file_close( ecl_file ); } } } else if (file_type == ECL_UNIFIED_SUMMARY_FILE) { ecl_file_type * ecl_file = ecl_file_open( stringlist_iget(filelist ,0 )); int report_step = 1; /* <- ECLIPSE numbering - starting at 1. */ while (true) { /* Observe that there is a number discrepancy between ECLIPSE and the ecl_file_select_smryblock() function. ECLIPSE starts counting report steps at 1; whereas the first SEQHDR block in the unified summary file is block zero (in ert counting). */ if (ecl_file_select_smryblock( ecl_file , report_step - 1)) { ecl_sum_data_add_ecl_file( data , load_end , report_step , ecl_file , data->smspec); report_step++; } else break; } ecl_file_close( ecl_file ); } else util_abort("%s: invalid file type:%s \n",__func__ , ecl_util_file_type_name(file_type )); } ecl_sum_data_build_index( data ); }
void test_write_header() { int nx = 10; int ny = 10; int nz = 5; int_vector_type * actnum = int_vector_alloc( nx*ny*nz , 1 ); test_work_area_type * test_area = test_work_area_alloc( "ecl_init_file" ); time_t start_time = util_make_date(15 , 12 , 2010 ); ecl_grid_type * ecl_grid; int_vector_iset( actnum , 10 , 0 ); int_vector_iset( actnum , 100 , 0 ); ecl_grid = ecl_grid_alloc_rectangular(nx, ny, nz, 1, 1, 1, int_vector_get_ptr( actnum )); // Write poro with global size. { fortio_type * f = fortio_open_writer( "FOO1.INIT" , false , ECL_ENDIAN_FLIP ); ecl_kw_type * poro = ecl_kw_alloc( "PORO" , ecl_grid_get_global_size( ecl_grid ) , ECL_FLOAT_TYPE ); ecl_kw_scalar_set_float( poro , 0.10 ); ecl_init_file_fwrite_header( f , ecl_grid , poro , 7 , start_time ); ecl_kw_free( poro ); fortio_fclose( f ); } // Write poro with nactive size. { fortio_type * f = fortio_open_writer( "FOO2.INIT" , false , ECL_ENDIAN_FLIP ); ecl_kw_type * poro = ecl_kw_alloc( "PORO" , ecl_grid_get_global_size( ecl_grid ) , ECL_FLOAT_TYPE ); ecl_kw_scalar_set_float( poro , 0.10 ); ecl_init_file_fwrite_header( f , ecl_grid , poro , 7 , start_time ); ecl_kw_free( poro ); fortio_fclose( f ); } { ecl_file_type * file1 = ecl_file_open( "FOO1.INIT" , 0 ); ecl_file_type * file2 = ecl_file_open( "FOO2.INIT" , 0 ); test_assert_true( ecl_kw_equal( ecl_file_iget_named_kw( file1 , "PORV" , 0 ) , ecl_file_iget_named_kw( file2 , "PORV" , 0))); ecl_file_close( file2 ); ecl_file_close( file1 ); } // Poro == NULL { fortio_type * f = fortio_open_writer( "FOO3.INIT" , false , ECL_ENDIAN_FLIP ); ecl_init_file_fwrite_header( f , ecl_grid , NULL , 7 , start_time ); fortio_fclose( f ); } test_work_area_free( test_area ); }
int main(int argc , char ** argv) { const char * case_path = argv[1]; char * grid_file = ecl_util_alloc_filename( NULL , case_path , ECL_EGRID_FILE , false , 0 ); char * init_file = ecl_util_alloc_filename( NULL , case_path , ECL_INIT_FILE , false , 0 ); char * rst_file = ecl_util_alloc_filename( NULL , case_path , ECL_RESTART_FILE , false , 0 ); ecl_grid_type * ecl_grid = ecl_grid_alloc( grid_file ); ecl_file_type * RST_file = ecl_file_open( rst_file , 0); ecl_file_type * INIT_file = ecl_file_open( init_file , 0 ); ecl_file_type * GRID_file = ecl_file_open( grid_file , 0); { ecl_kw_type * actnum = ecl_file_iget_named_kw( GRID_file , "ACTNUM" , 0 ); ecl_kw_type * swat = ecl_file_iget_named_kw( RST_file , "SWAT" , 0 ); ecl_kw_type * permx = ecl_file_iget_named_kw( INIT_file , "PERMX" , 0 ); int fracture_size = ecl_grid_get_nactive_fracture( ecl_grid ); int matrix_size = ecl_grid_get_nactive( ecl_grid ); test_assert_int_equal( fracture_size + matrix_size , ecl_kw_get_size( swat )); test_assert_int_equal( fracture_size + matrix_size , ecl_kw_get_size( permx )); { int gi; int matrix_index = 0; int fracture_index = 0; for (gi = 0; gi < ecl_grid_get_global_size( ecl_grid ); gi++) { if (ecl_kw_iget_int( actnum , gi ) & CELL_ACTIVE_MATRIX) { test_assert_int_equal( ecl_grid_get_active_index1( ecl_grid , gi ) , matrix_index); test_assert_int_equal( ecl_grid_get_global_index1A( ecl_grid , matrix_index ) , gi); matrix_index++; } if (ecl_kw_iget_int( actnum , gi ) & CELL_ACTIVE_FRACTURE) { test_assert_int_equal( ecl_grid_get_active_fracture_index1( ecl_grid , gi ) , fracture_index); test_assert_int_equal( ecl_grid_get_global_index1F( ecl_grid , fracture_index ) , gi); fracture_index++; } } } } ecl_file_close( RST_file ); ecl_file_close( INIT_file ); ecl_grid_free( ecl_grid ); exit(0); }
TEST(RigReservoirTest, DISABLED_FileOutputToolsTest) { cvf::DebugTimer timer("test"); // QString filename("d:/Models/Statoil/testcase_juli_2011/data/TEST10K_FLT_LGR_NNC.EGRID"); // QString filename("d:/Models/Statoil/testcase_juli_2011/data/TEST10K_FLT_LGR_NNC.UNRST"); // QString filename("d:/Models/Statoil/troll_MSW/T07-4A-W2012-16-F3.UNRST"); QString filename("c:/tmp/troll_MSW/T07-4A-W2012-16-F3.UNRST"); ecl_file_type* ertFile = ecl_file_open(filename.toAscii().data(), ECL_FILE_CLOSE_STREAM); EXPECT_TRUE(ertFile); QStringList keywords; std::vector<size_t> keywordDataItemCounts; RifEclipseOutputFileTools::findKeywordsAndDataItemCounts(ertFile, &keywords, &keywordDataItemCounts); EXPECT_TRUE(keywords.size() == keywordDataItemCounts.size()); qDebug() << "Keyword - Number of data items"; for (int i = 0; i < keywords.size(); i++) { QString paddedKeyword = QString("%1").arg(keywords[i], 8); qDebug() << paddedKeyword << " - " << keywordDataItemCounts[i]; } ecl_file_close(ertFile); ertFile = NULL; timer.reportTime(); //qDebug() << timer.lapt; }
void restoreSOLUTION(const std::string& restart_filename, int reportstep, bool unified, EclipseStateConstPtr eclipseState, int numcells, const PhaseUsage& phaseUsage, SimulatorState& simulator_state) { const char* filename = restart_filename.c_str(); ecl_file_type* file_type = ecl_file_open(filename, 0); if (file_type) { bool block_selected = unified ? ecl_file_select_rstblock_report_step(file_type , reportstep) : true; if (block_selected) { restorePressureData(file_type, eclipseState, numcells, simulator_state); restoreTemperatureData(file_type, eclipseState, numcells, simulator_state); restoreSaturation(file_type, phaseUsage, numcells, simulator_state); BlackoilState* blackoilState = dynamic_cast<BlackoilState*>(&simulator_state); if (blackoilState) { SimulationConfigConstPtr sim_config = eclipseState->getSimulationConfig(); restoreRSandRV(file_type, sim_config, numcells, blackoilState); } } else { std::string error_str = "Restart file " + restart_filename + " does not contain data for report step " + std::to_string(reportstep) + "!\n"; throw std::runtime_error(error_str); } ecl_file_close(file_type); } else { std::string error_str = "Restart file " + restart_filename + " not found!\n"; throw std::runtime_error(error_str); } }
TEST(RigReservoirTest, FileOutputToolsTest) { cvf::ref<RifReaderEclipseOutput> readerInterfaceEcl = new RifReaderEclipseOutput; cvf::ref<RigReservoir> reservoir = new RigReservoir; // QString filename("d:/Models/Statoil/testcase_juli_2011/data/TEST10K_FLT_LGR_NNC.EGRID"); QString filename("d:/Models/Statoil/testcase_juli_2011/data/TEST10K_FLT_LGR_NNC.UNRST"); ecl_file_type* ertFile = ecl_file_open(filename.toAscii().data()); EXPECT_TRUE(ertFile); QStringList keywords; std::vector<size_t> keywordDataItemCounts; RifEclipseOutputFileTools::findKeywordsAndDataItemCounts(ertFile, &keywords, &keywordDataItemCounts); EXPECT_TRUE(keywords.size() == keywordDataItemCounts.size()); qDebug() << "Keyword - Number of data items"; for (int i = 0; i < keywords.size(); i++) { QString paddedKeyword = QString("%1").arg(keywords[i], 8); qDebug() << paddedKeyword << " - " << keywordDataItemCounts[i]; } ecl_file_close(ertFile); ertFile = NULL; }
//-------------------------------------------------------------------------------------------------- /// Destructor //-------------------------------------------------------------------------------------------------- RifEclipseUnifiedRestartFileAccess::~RifEclipseUnifiedRestartFileAccess() { if (m_ecl_file) { ecl_file_close(m_ecl_file); } }
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 test_truncated() { test_work_area_type * work_area = test_work_area_alloc("ecl_file_truncated" ); { ecl_grid_type * grid = ecl_grid_alloc_rectangular(20,20,20,1,1,1,NULL); ecl_grid_fwrite_EGRID2( grid , "TEST.EGRID", ECL_METRIC_UNITS ); ecl_grid_free( grid ); } { ecl_file_type * ecl_file = ecl_file_open("TEST.EGRID" , 0 ); test_assert_true( ecl_file_is_instance( ecl_file ) ); ecl_file_close( ecl_file ); } { offset_type file_size = util_file_size( "TEST.EGRID"); FILE * stream = util_fopen("TEST.EGRID" , "r+"); util_ftruncate( stream , file_size / 2 ); fclose( stream ); } { ecl_file_type * ecl_file = ecl_file_open("TEST.EGRID" , 0 ); test_assert_NULL( ecl_file ); } test_work_area_free( work_area ); }
int main( int argc , char ** argv) { const char * egrid_file = argv[1]; ecl_grid_type * grid = ecl_grid_alloc( egrid_file ); ecl_file_type * gfile = ecl_file_open( egrid_file , 0 ); const ecl_kw_type * nnc1_kw = ecl_file_iget_named_kw( gfile , "NNC1" ,0 ); const ecl_kw_type * nnc2_kw = ecl_file_iget_named_kw( gfile , "NNC2" ,0 ); const int_vector_type * index_list = ecl_grid_get_nnc_index_list( grid ); { int_vector_type * nnc = int_vector_alloc(0,0); int_vector_set_many( nnc , 0 , ecl_kw_get_ptr( nnc1_kw ) , ecl_kw_get_size( nnc1_kw )); int_vector_append_many( nnc , ecl_kw_get_ptr( nnc2_kw ) , ecl_kw_get_size( nnc2_kw )); int_vector_select_unique( nnc ); test_assert_int_equal( int_vector_size( index_list ) , int_vector_size( nnc )); { int i; for (i=0; i < int_vector_size( nnc ); i++) test_assert_int_equal( int_vector_iget( nnc , i ) - 1 , int_vector_iget(index_list , i )); } int_vector_free( nnc ); } ecl_file_close( gfile ); ecl_grid_free( grid ); exit(0); }
void restoreOPM_XWELKeyword(const std::string& restart_filename, int reportstep, bool unified, WellState& wellstate) { const char * keyword = "OPM_XWEL"; const char* filename = restart_filename.c_str(); ecl_file_type* file_type = ecl_file_open(filename, 0); if (file_type != NULL) { bool block_selected = unified ? ecl_file_select_rstblock_report_step(file_type , reportstep) : true; if (block_selected) { ecl_kw_type* xwel = ecl_file_iget_named_kw(file_type , keyword, 0); const double* xwel_data = ecl_kw_get_double_ptr(xwel); std::copy_n(xwel_data + wellstate.getRestartTemperatureOffset(), wellstate.temperature().size(), wellstate.temperature().begin()); std::copy_n(xwel_data + wellstate.getRestartBhpOffset(), wellstate.bhp().size(), wellstate.bhp().begin()); std::copy_n(xwel_data + wellstate.getRestartPerfPressOffset(), wellstate.perfPress().size(), wellstate.perfPress().begin()); std::copy_n(xwel_data + wellstate.getRestartPerfRatesOffset(), wellstate.perfRates().size(), wellstate.perfRates().begin()); std::copy_n(xwel_data + wellstate.getRestartWellRatesOffset(), wellstate.wellRates().size(), wellstate.wellRates().begin()); } else { std::string error_str = "Restart file " + restart_filename + " does not contain data for report step " + std::to_string(reportstep) + "!\n"; throw std::runtime_error(error_str); } ecl_file_close(file_type); } else { std::string error_str = "Restart file " + restart_filename + " not found!\n"; throw std::runtime_error(error_str); } }
void test_loadall(const char * src_file , const char * target_file ) { util_copy_file( src_file , target_file ); { ecl_file_type * ecl_file = ecl_file_open( target_file , ECL_FILE_CLOSE_STREAM ); test_assert_true( ecl_file_load_all( ecl_file ) ); ecl_file_close( ecl_file ); } { ecl_file_type * ecl_file = ecl_file_open( target_file , ECL_FILE_CLOSE_STREAM ); unlink( target_file ); test_assert_false( ecl_file_load_all( ecl_file ) ); ecl_file_close( ecl_file ); } }
static ecl_file_type * ecl_file_open_rstblock_report_step__( const char * filename , int report_step , int flags) { ecl_file_type * ecl_file = ecl_file_open__( filename , flags ); if (!ecl_file_select_rstblock_report_step( ecl_file , report_step )) { ecl_file_close( ecl_file ); ecl_file = NULL; } return ecl_file; }
static ecl_file_type * ecl_file_open_rstblock_sim_time__( const char * filename , time_t sim_time, int flags ) { ecl_file_type * ecl_file = ecl_file_open__( filename , flags ); if (!ecl_file_select_rstblock_sim_time( ecl_file , sim_time)) { ecl_file_close( ecl_file ); ecl_file = NULL; } return ecl_file; }
static ecl_file_type * ecl_file_iopen_rstblock__( const char * filename , int seqnum_index, int flags ) { ecl_file_type * ecl_file = ecl_file_open__( filename , flags ); if (!ecl_file_iselect_rstblock( ecl_file , seqnum_index )) { ecl_file_close( ecl_file ); ecl_file = NULL; } return ecl_file; }
int main(int argc , char ** argv) { const char * path_case = argv[1]; char * grid_file = ecl_util_alloc_filename( NULL , path_case , ECL_EGRID_FILE , false , 0 ); char * init_file = ecl_util_alloc_filename( NULL , path_case , ECL_INIT_FILE , false , 0 ); ecl_file_type * init = ecl_file_open( init_file , 0 ); ecl_grid_type * grid = ecl_grid_alloc( grid_file ); const ecl_kw_type * poro_kw = ecl_file_iget_named_kw( init , "PORO" , 0 ); const ecl_kw_type * porv_kw = ecl_file_iget_named_kw( init , "PORV" , 0 ); ecl_kw_type * multpv = NULL; ecl_kw_type * NTG = NULL; bool error_found = false; double total_volume = 0; double total_diff = 0; int error_count = 0; int iactive; if (ecl_file_has_kw( init , "NTG")) NTG = ecl_file_iget_named_kw( init , "NTG" , 0); if (ecl_file_has_kw( init , "MULTPV")) multpv = ecl_file_iget_named_kw( init , "MULTPV" , 0); for (iactive = 0; iactive < ecl_grid_get_nactive( grid ); ++iactive) { int iglobal = ecl_grid_get_global_index1A( grid , iactive ); double grid_volume = ecl_grid_get_cell_volume1( grid , iglobal ); double eclipse_volume = ecl_kw_iget_float( porv_kw , iglobal ) / ecl_kw_iget_float( poro_kw , iactive ); if (NTG) eclipse_volume /= ecl_kw_iget_float( NTG , iactive ); if (multpv) eclipse_volume *= ecl_kw_iget_float( multpv , iactive); total_volume += grid_volume; total_diff += fabs( eclipse_volume - grid_volume ); if (!util_double_approx_equal__( grid_volume , eclipse_volume , 2.5e-3, 0.00)) { double diff = 100 * (grid_volume - eclipse_volume) / eclipse_volume; printf("Error in cell: %d V1: %g V2: %g diff:%g %% \n", iglobal , grid_volume , eclipse_volume , diff); error_count++; error_found = true; } } printf("Total volume difference: %g %% \n", 100 * total_diff / total_volume ); ecl_grid_free( grid ); ecl_file_close( init ); free( grid_file ); free( init_file ); if (error_found) { printf("Error_count: %d / %d \n",error_count , ecl_grid_get_nactive( grid )); exit(1); } else exit(0); }
void test_close_stream2(const char * src_file , const char * target_file ) { util_copy_file( src_file , target_file ); ecl_file_type * ecl_file = ecl_file_open( target_file , ECL_FILE_CLOSE_STREAM ); ecl_file_load_all( ecl_file ); unlink( target_file ); ecl_kw_type * kw2 = ecl_file_iget_kw( ecl_file , 2 ); test_assert_not_NULL( kw2 ); ecl_file_close( ecl_file ); }
int main(int argc , char ** argv) { const char * case_path = argv[1]; char * egrid_file = ecl_util_alloc_filename( NULL , case_path , ECL_EGRID_FILE , false , 0 ); char * rst_file = ecl_util_alloc_filename( NULL , case_path , ECL_RESTART_FILE , false , 0 ); char * init_file = ecl_util_alloc_filename( NULL , case_path , ECL_INIT_FILE , false , 0 ); ecl_grid_type * GRID = ecl_grid_alloc(egrid_file ); ecl_file_type * RST_file = ecl_file_open( rst_file , 0); ecl_file_type * INIT_file = ecl_file_open( init_file , 0); { test_assert_true( ecl_grid_have_coarse_cells( GRID ) ); test_assert_int_equal( ecl_grid_get_num_coarse_groups( GRID ) , 3384); } { const ecl_kw_type * swat0 = ecl_file_iget_named_kw( RST_file , "SWAT" , 0 ); const ecl_kw_type * porv = ecl_file_iget_named_kw( INIT_file , "PORV" , 0 ); test_assert_int_equal( ecl_kw_get_size( swat0 ) , ecl_grid_get_active_size( GRID ) ); test_assert_int_equal( ecl_kw_get_size( porv ) , ecl_grid_get_global_size( GRID ) ); } { int ic; for (ic = 0; ic < ecl_grid_get_num_coarse_groups(GRID); ic++) { ecl_coarse_cell_type * coarse_cell = ecl_grid_iget_coarse_group( GRID , ic ); test_coarse_cell( GRID , coarse_cell ); } } ecl_file_close( INIT_file ); ecl_file_close( RST_file ); ecl_grid_free( GRID ); exit(0); }
int main(int argc , char ** argv) { const char * grid_file = argv[1]; ecl_grid_type * ecl_grid = ecl_grid_alloc( grid_file ); ecl_file_type * ecl_file = ecl_file_open( grid_file , 0); ecl_grid_test_lgr_consistency( ecl_grid ); if (ecl_file_get_num_named_kw( ecl_file , COORD_KW )) test_assert_int_equal( ecl_file_get_num_named_kw( ecl_file , COORD_KW ) - 1, ecl_grid_get_num_lgr( ecl_grid )); ecl_grid_free( ecl_grid ); ecl_file_close( ecl_file); exit(0); }
void test_flags( const char * filename) { int FLAG1 = 1; int FLAG2 = 2; int FLAG3 = 4; int FLAG4 = 8; int FLAGS = FLAG1 + FLAG2 + FLAG3; ecl_file_type * ecl_file = ecl_file_open( filename , FLAGS ); test_assert_int_equal( ecl_file_get_flags( ecl_file ) , FLAGS ); test_assert_true( ecl_file_flags_set( ecl_file , FLAG1 )); test_assert_true( ecl_file_flags_set( ecl_file , FLAG1 | FLAG2)); test_assert_true( ecl_file_flags_set( ecl_file , FLAG1 | FLAG3 )); test_assert_true( ecl_file_flags_set( ecl_file , FLAG1 | FLAG3 | FLAG2 )); test_assert_false( ecl_file_flags_set( ecl_file , FLAG1 | FLAG3 | FLAG4 )); ecl_file_close( ecl_file ); }
void test_close_stream1(const char * src_file , const char * target_file ) { util_copy_file( src_file , target_file ); ecl_file_type * ecl_file = ecl_file_open( target_file , ECL_FILE_CLOSE_STREAM ); ecl_kw_type * kw0 = ecl_file_iget_kw( ecl_file , 0 ); ecl_kw_type * kw1 = ecl_file_iget_kw( ecl_file , 1 ); unlink( target_file ); ecl_kw_type * kw1b = ecl_file_iget_kw( ecl_file , 1 ); test_assert_not_NULL( kw0 ); test_assert_not_NULL( kw1 ); test_assert_ptr_equal( kw1 , kw1b ); ecl_kw_type * kw2 = ecl_file_iget_kw( ecl_file , 2 ); test_assert_NULL( kw2 ); test_assert_false( ecl_file_writable( ecl_file )); ecl_file_close( ecl_file ); }
void test_writable(const char * src_file ) { test_work_area_type * work_area = test_work_area_alloc("ecl_file_writable" ); char * fname = util_split_alloc_filename( src_file ); test_work_area_copy_file( work_area , src_file ); { ecl_file_type * ecl_file = ecl_file_open( fname , ECL_FILE_WRITABLE); ecl_kw_type * swat = ecl_file_iget_named_kw( ecl_file , "SWAT" , 0 ); ecl_kw_type * swat0 = ecl_kw_alloc_copy( swat ); test_assert_true( ecl_kw_equal( swat , swat0 )); ecl_kw_iset_float( swat , 0 , 1000.0 ); ecl_file_save_kw( ecl_file , swat ); test_assert_true( ecl_file_writable( ecl_file )); ecl_file_close( ecl_file ); ecl_file = ecl_file_open( fname , 0); swat = ecl_file_iget_named_kw( ecl_file , "SWAT" , 0 ); test_assert_true( util_double_approx_equal( ecl_kw_iget_float( swat , 0 ) , 1000 )); } test_work_area_free( work_area ); }
// Inspired by the ecl_pack application in the ERT library void concatenateRestart(const std::string& basename) { std::string inputPath, inputBase; splitBasename(basename, inputPath, inputBase); stringlist_type* inputFiles = stringlist_alloc_new(); const int numFiles = ecl_util_select_filelist(inputPath.c_str(), inputBase.c_str(), ECL_RESTART_FILE, false, inputFiles); const char* target_file_name = ecl_util_alloc_filename(inputPath.c_str(), inputBase.c_str(), ECL_UNIFIED_RESTART_FILE, false, -1); fortio_type* target = fortio_open_writer(target_file_name, false, ECL_ENDIAN_FLIP); int dummy; ecl_kw_type* seqnum_kw = ecl_kw_alloc_new("SEQNUM", 1, ECL_INT, &dummy); int reportStep = 0; for (int i = 0; i < numFiles; ++i) { ecl_util_get_file_type(stringlist_iget(inputFiles, i), nullptr, &reportStep); ecl_file_type* src_file = ecl_file_open(stringlist_iget(inputFiles, i), 0); ecl_kw_iset_int(seqnum_kw, 0, reportStep); ecl_kw_fwrite(seqnum_kw, target); ecl_file_fwrite_fortio(src_file, target, 0); ecl_file_close(src_file); } fortio_fclose(target); stringlist_free(inputFiles); }
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( rst_file ); 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 ); const ecl_kw_type * rseg_kw = ecl_file_iget_named_kw( rst_file , RSEG_KW , 0 ); const ecl_kw_type * icon_kw = ecl_file_iget_named_kw( rst_file , ICON_KW , 0 ); test_install_SIGNALS(); test_assert_not_NULL( rst_file ); test_assert_not_NULL( rst_head ); { int well_nr; for (well_nr = 0; well_nr < rst_head->nwells; well_nr++) { well_conn_collection_type * connections = well_conn_collection_alloc(); well_conn_collection_load_from_kw( connections , iwel_kw , icon_kw , well_nr , rst_head); { well_segment_collection_type * segments = well_segment_collection_alloc(); if (well_segment_collection_load_from_kw( segments , well_nr , iwel_kw , iseg_kw , rseg_kw , rst_head )) { well_branch_collection_type * branches = well_branch_collection_alloc(); test_assert_true( well_segment_well_is_MSW( well_nr , iwel_kw , rst_head)); well_segment_collection_link( segments ); { int is; for (is=0; is < well_segment_collection_get_size( segments ); is++) { well_segment_type * segment = well_segment_collection_iget( segments , is ); if (well_segment_nearest_wellhead( segment )) test_assert_NULL( well_segment_get_outlet( segment )); else test_assert_not_NULL( well_segment_get_outlet( segment )); test_assert_ptr_not_equal( segment , well_segment_get_outlet( segment )); } } well_segment_collection_add_branches( segments , branches ); { int ib; for (ib = 0; ib < well_branch_collection_get_size( branches ); ib++) { const well_segment_type * start_segment = well_branch_collection_iget_start_segment( branches , ib ); const well_segment_type * segment = start_segment; printf("Branch %d/%d " , ib , well_branch_collection_get_size( branches ) ); while (segment) { printf("[%p]%d -> \n",segment , well_segment_get_id( segment )); segment = well_segment_get_outlet( segment ); } printf("\n"); sleep(1); } } well_segment_collection_add_connections( segments , ECL_GRID_GLOBAL_GRID , connections ); well_branch_collection_free( branches ); } else test_assert_false( well_segment_well_is_MSW( well_nr , iwel_kw , rst_head )); well_segment_collection_free( segments ); } well_conn_collection_free( connections ); } } ecl_file_close( rst_file ); ecl_rsthead_free( rst_head ); exit(0); }
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 ); }
void well_info_load_rstfile( well_info_type * well_info , const char * filename, bool load_segment_information) { ecl_file_type * ecl_file = ecl_file_open( filename , 0); well_info_load_rst_eclfile(well_info, ecl_file, load_segment_information); ecl_file_close( ecl_file ); }
void unpack_file(const char * filename) { ecl_file_enum target_type = ECL_OTHER_FILE; ecl_file_enum file_type; bool fmt_file; file_type = ecl_util_get_file_type(filename , &fmt_file , NULL); if (file_type == ECL_UNIFIED_SUMMARY_FILE) target_type = ECL_SUMMARY_FILE; else if (file_type == ECL_UNIFIED_RESTART_FILE) target_type = ECL_RESTART_FILE; else util_exit("Can only unpack unified ECLIPSE summary and restart files\n"); if (target_type == ECL_SUMMARY_FILE) { printf("** Warning: when unpacking unified summary files it as ambigous - starting with 0001 -> \n"); } { ecl_file_type * src_file = ecl_file_open( filename , 0 ); int size; int offset; int report_step = 0; int block_index = 0; char * path; char * base; msg_type * msg; util_alloc_file_components( filename , &path , &base , NULL); { char * label = util_alloc_sprintf("Unpacking %s => ", filename); msg = msg_alloc( label , false); free( label ); } msg_show(msg); if (target_type == ECL_SUMMARY_FILE) size = ecl_file_get_num_named_kw( src_file , "SEQHDR" ); else size = ecl_file_get_num_named_kw( src_file , "SEQNUM" ); while (true) { if (block_index == size) break; if (target_type == ECL_SUMMARY_FILE) { ecl_file_select_block( src_file , SEQHDR_KW , block_index ); report_step += 1; offset = 0; } else { ecl_kw_type * seqnum_kw; ecl_file_select_block( src_file , SEQNUM_KW , block_index ); seqnum_kw = ecl_file_iget_named_kw( src_file , SEQNUM_KW , 0); report_step = ecl_kw_iget_int( seqnum_kw , 0); offset = 1; } /** Will unpack to cwd, even though the source files might be somewhere else. To unpack to the same directory as the source files, just send in @path as first argument when creating the target_file. */ { char * target_file = ecl_util_alloc_filename( NULL , base , target_type , fmt_file , report_step); fortio_type * fortio_target = fortio_open_writer( target_file , fmt_file , ECL_ENDIAN_FLIP ); msg_update(msg , target_file); ecl_file_fwrite_fortio( src_file , fortio_target , offset); fortio_fclose(fortio_target); free(target_file); } block_index++; } ecl_file_close( src_file ); util_safe_free(path); free(base); msg_free(msg , true); } }
ECLFilesComparator::~ECLFilesComparator() { ecl_file_close(ecl_file1); ecl_file_close(ecl_file2); ecl_grid_free(ecl_grid1); ecl_grid_free(ecl_grid2); }
int main(int argc, char ** argv) { int num_files = argc - 1; if (num_files >= 1) { /* File type and formatted / unformatted is determined from the first argument on the command line. */ char * ecl_base; char * path; ecl_file_enum file_type , target_type; bool fmt_file; /** Look at the first command line argument to determine type and formatted/unformatted status. */ file_type = ecl_util_get_file_type( argv[1] , &fmt_file , NULL); if (file_type == ECL_SUMMARY_FILE) target_type = ECL_UNIFIED_SUMMARY_FILE; else if (file_type == ECL_RESTART_FILE) target_type = ECL_UNIFIED_RESTART_FILE; else { util_exit("The ecl_pack program can only be used with ECLIPSE restart files or summary files.\n"); target_type = -1; } util_alloc_file_components( argv[1] , &path , &ecl_base , NULL); /** Will pack to cwd, even though the source files might be somewhere else. To unpack to the same directory as the source files, just send in @path as first argument when creating the target_file. */ { msg_type * msg; int i , report_step , prev_report_step; char * target_file_name = ecl_util_alloc_filename( NULL , ecl_base , target_type , fmt_file , -1); stringlist_type * filelist = stringlist_alloc_argv_copy( (const char **) &argv[1] , num_files ); ecl_kw_type * seqnum_kw = NULL; fortio_type * target = fortio_open_writer( target_file_name , fmt_file , ECL_ENDIAN_FLIP); if (target_type == ECL_UNIFIED_RESTART_FILE) { int dummy; seqnum_kw = ecl_kw_alloc_new("SEQNUM" , 1 , ECL_INT_TYPE , &dummy); } { char * msg_format = util_alloc_sprintf("Packing %s <= " , target_file_name); msg = msg_alloc( msg_format , false); free( msg_format ); } msg_show( msg ); stringlist_sort( filelist , ecl_util_fname_report_cmp); prev_report_step = -1; for (i=0; i < num_files; i++) { ecl_file_enum this_file_type; this_file_type = ecl_util_get_file_type( stringlist_iget(filelist , i) , NULL , &report_step); if (this_file_type == file_type) { if (report_step == prev_report_step) util_exit("Tried to write same report step twice: %s / %s \n", stringlist_iget(filelist , i-1) , stringlist_iget(filelist , i)); prev_report_step = report_step; msg_update(msg , stringlist_iget( filelist , i)); { ecl_file_type * src_file = ecl_file_open( stringlist_iget( filelist , i) , 0 ); if (target_type == ECL_UNIFIED_RESTART_FILE) { /* Must insert the SEQNUM keyword first. */ ecl_kw_iset_int(seqnum_kw , 0 , report_step); ecl_kw_fwrite( seqnum_kw , target ); } ecl_file_fwrite_fortio( src_file , target , 0); ecl_file_close( src_file ); } } /* Else skipping file of incorrect type. */ } msg_free(msg , false); fortio_fclose( target ); free(target_file_name); stringlist_free( filelist ); if (seqnum_kw != NULL) ecl_kw_free(seqnum_kw); } free(ecl_base); util_safe_free(path); } }