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; }
/* Will select restart block nr @seqnum_index - without considering report_steps or simulation time. */ bool ecl_file_iselect_rstblock( ecl_file_type * ecl_file , int seqnum_index ) { return ecl_file_select_block( ecl_file , SEQNUM_KW , seqnum_index ); }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RifEclipseOutputFileTools::createReportStepsMetaData(std::vector<ecl_file_type*> ecl_files, std::vector<RifRestartReportStep>* reportSteps) { if (!reportSteps) return; for (auto ecl_file : ecl_files) { if (!ecl_file) continue; int reportStepCount = ecl_file_get_num_named_kw(ecl_file, INTEHEAD_KW); for (int reportStepIndex = 0; reportStepIndex < reportStepCount; reportStepIndex++) { ecl_file_view_type* rst_view = ecl_file_get_global_view(ecl_file); if (!rst_view) continue; ecl_rsthead_type* restart_header = ecl_rsthead_alloc(rst_view, reportStepIndex); if (restart_header) { ecl_file_push_block(ecl_file); { ecl_file_select_block(ecl_file, INTEHEAD_KW, reportStepIndex); RifRestartReportStep reportStep; // Set Date { QDateTime reportDateTime(QDate(restart_header->year, restart_header->month, restart_header->day)); reportStep.dateTime = reportDateTime; } // Find number of keywords withing this report step int numKeywords = ecl_file_get_num_distinct_kw(ecl_file); for (int iKey = 0; iKey < numKeywords; iKey++) { const char* kw = ecl_file_iget_distinct_kw(ecl_file, iKey); int namedKeywordCount = ecl_file_get_num_named_kw(ecl_file, kw); for (int iOcc = 0; iOcc < namedKeywordCount; iOcc++) { ecl_data_type dataType = ecl_file_iget_named_data_type(ecl_file, kw, iOcc); ecl_type_enum dataTypeEmum = ecl_type_get_type(dataType); if (dataTypeEmum != ECL_DOUBLE_TYPE && dataTypeEmum != ECL_FLOAT_TYPE && dataTypeEmum != ECL_INT_TYPE) { continue; } int itemCount = ecl_file_iget_named_size(ecl_file, kw, iOcc); reportStep.m_keywords.appendKeyword(kw, itemCount, iOcc); } } reportSteps->push_back(reportStep); } ecl_file_pop_block(ecl_file); ecl_rsthead_free(restart_header); } } } }
bool ecl_file_select_smryblock( ecl_file_type * ecl_file , int report_step ) { return ecl_file_select_block( ecl_file , SEQHDR_KW , report_step ); }
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); } }