//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RifEclipseSummaryTools::findSummaryHeaderFileInfo(const std::string& inputFile, std::string* headerFile, std::string* path, std::string* base, bool* isFormatted) { char* myPath = NULL; char* myBase = NULL; bool formattedFile = true; util_alloc_file_components(inputFile.data(), &myPath, &myBase, NULL); char* myHeaderFile = ecl_util_alloc_exfilename(myPath, myBase, ECL_SUMMARY_HEADER_FILE, true, -1); if (!myHeaderFile) { myHeaderFile = ecl_util_alloc_exfilename(myPath, myBase, ECL_SUMMARY_HEADER_FILE, false, -1); if (myHeaderFile) { formattedFile = false; } } if (myHeaderFile && headerFile) *headerFile = myHeaderFile; if (myPath && path) *path = myPath; if (myBase && base) *base = myBase; if (isFormatted) *isFormatted = formattedFile; util_safe_free(myHeaderFile); util_safe_free(myBase); util_safe_free(myPath); }
void ecl_sum_set_case( ecl_sum_type * ecl_sum , const char * ecl_case) { util_safe_free( ecl_sum->ecl_case ); util_safe_free( ecl_sum->path ); util_safe_free( ecl_sum->abs_path ); util_safe_free( ecl_sum->base ); util_safe_free( ecl_sum->ext ); { char *path , *base, *ext; util_alloc_file_components( ecl_case , &path , &base , &ext); ecl_sum->ecl_case = util_alloc_string_copy( ecl_case ); ecl_sum->path = util_alloc_string_copy( path ); ecl_sum->base = util_alloc_string_copy( base ); ecl_sum->ext = util_alloc_string_copy( ext ); if (path != NULL) ecl_sum->abs_path = util_alloc_abs_path( path ); else ecl_sum->abs_path = util_alloc_cwd(); util_safe_free( base ); util_safe_free( path ); util_safe_free( ext ); } }
void ecl_config_set_schedule_file( ecl_config_type * ecl_config , const char * schedule_file ) { if (ecl_config->start_date == -1) util_abort("%s: must set ecl_data_file first \n",__func__); { char * base; /* The schedule target file will be without any path component */ char * ext; util_alloc_file_components(schedule_file , NULL , &base , &ext); ecl_config->schedule_target_file = util_alloc_filename(NULL , base , ext); free(ext); free(base); } ecl_config->sched_file = sched_file_alloc( ecl_config->start_date ); sched_file_parse(ecl_config->sched_file , schedule_file ); ecl_config->last_history_restart = sched_file_get_num_restart_files( ecl_config->sched_file ) - 1; /* We keep track of this - so we can stop assimilation at the end of history */ { hash_iter_type * iter = hash_iter_alloc( ecl_config->fixed_length_kw ); while (!hash_iter_is_complete( iter )) { const char * key = hash_iter_get_next_key( iter ); int length = hash_get_int( ecl_config->fixed_length_kw , key ); sched_file_add_fixed_length_kw( ecl_config->sched_file , key , length); } hash_iter_free( iter ); } }
char * ecl_rft_file_alloc_case_filename(const char * case_input ) { ecl_file_enum file_type; bool fmt_file; file_type = ecl_util_get_file_type( case_input , &fmt_file , NULL); if (file_type == ECL_RFT_FILE) return util_alloc_string_copy (case_input ); else { char * return_file = NULL; char * path; char * basename; util_alloc_file_components( case_input , &path , &basename , NULL); if ((file_type == ECL_OTHER_FILE) || (file_type == ECL_DATA_FILE)) { /* Impossible to infer formatted/unformatted from the case_input */ char * RFT_file = ecl_util_alloc_filename( path , basename , ECL_RFT_FILE , false , -1 ); char * FRFT_file = ecl_util_alloc_filename( path , basename , ECL_RFT_FILE , true , -1 ); if (util_file_exists( RFT_file )) return_file = util_alloc_string_copy( RFT_file ); else if (util_file_exists( FRFT_file )) return_file = util_alloc_string_copy( FRFT_file ); free( RFT_file ); free( FRFT_file ); } else { char * RFT_file = ecl_util_alloc_filename( path , basename , ECL_RFT_FILE , fmt_file , -1 ); if (util_file_exists( RFT_file )) return_file = util_alloc_string_copy( RFT_file ); free( RFT_file ); } return return_file; } }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- QString RifEclipseSummaryTools::findGridCaseFileFromSummaryHeaderFile(const QString& summaryHeaderFile) { char* myPath = nullptr; char* myBase = nullptr; bool formattedFile = true; util_alloc_file_components(RiaStringEncodingTools::toNativeEncoded(QDir::toNativeSeparators(summaryHeaderFile)).data(), &myPath, &myBase, nullptr); char* caseFile = ecl_util_alloc_exfilename(myPath, myBase, ECL_EGRID_FILE, true, -1); if (!caseFile) { caseFile= ecl_util_alloc_exfilename(myPath, myBase, ECL_EGRID_FILE, false, -1); if (caseFile) { formattedFile = false; } } QString gridCaseFile; if (caseFile) gridCaseFile = caseFile; util_safe_free(caseFile); util_safe_free(myBase); util_safe_free(myPath); return RiaFilePathTools::toInternalSeparator(gridCaseFile); }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RifEclipseSummaryTools::findSummaryHeaderFileInfo(const QString& inputFile, QString* headerFile, QString* path, QString* base, bool* isFormatted) { char* myPath = nullptr; char* myBase = nullptr; bool formattedFile = true; util_alloc_file_components(RiaStringEncodingTools::toNativeEncoded(QDir::toNativeSeparators(inputFile)).data(), &myPath, &myBase, nullptr); char* myHeaderFile = ecl_util_alloc_exfilename(myPath, myBase, ECL_SUMMARY_HEADER_FILE, true, -1); if (!myHeaderFile) { myHeaderFile = ecl_util_alloc_exfilename(myPath, myBase, ECL_SUMMARY_HEADER_FILE, false, -1); if (myHeaderFile) { formattedFile = false; } } if (myHeaderFile && headerFile) *headerFile = RiaFilePathTools::toInternalSeparator(myHeaderFile); if (myPath && path) *path = RiaFilePathTools::toInternalSeparator(myPath); if (myBase && base) *base = RiaFilePathTools::toInternalSeparator(myBase); if (isFormatted) *isFormatted = formattedFile; util_safe_free(myHeaderFile); util_safe_free(myBase); util_safe_free(myPath); }
void ecl_config_set_init_section(ecl_config_type * ecl_config, const char * input_init_section) { if (ecl_config->can_restart) { /* The <INIT> tag is set. */ ecl_config->input_init_section = util_realloc_string_copy(ecl_config->input_init_section, input_init_section); /* input_init_section = path/to/init_section */ if (util_file_exists(ecl_config->input_init_section)) { /* init_section = $CWD/path/to/init_section */ util_safe_free(ecl_config->init_section); ecl_config->init_section = util_alloc_realpath(input_init_section); } else { char * path; util_alloc_file_components(ecl_config->input_init_section, &path, NULL, NULL ); if (path != NULL ) fprintf(stderr, "** Warning: %s: When INIT_SECTION:%s points to a non-existing file - you can not have any path components.\n", __func__, input_init_section); else ecl_config->init_section = util_alloc_string_copy(input_init_section); util_safe_free(path); } } else /* The <INIT> tag is not set - we can not utilize the input_init_section info, and we just ignore it. */ fprintf(stderr, "** Warning: <INIT> tag was not found in datafile - can not utilize INIT_SECTION keyword - ignored.\n"); }
void enkf_tui_export_fieldP(void * arg) { enkf_main_type * enkf_main = enkf_main_safe_cast( arg ); const ensemble_config_type * ensemble_config = enkf_main_get_ensemble_config(enkf_main); const enkf_config_node_type * config_node = enkf_tui_util_scanf_key(ensemble_config , PROMPT_LEN , FIELD , INVALID_VAR ); int iens1 = 0; int iens2 = enkf_main_get_ensemble_size( enkf_main ); const int last_report = enkf_main_get_history_length( enkf_main ); int report_step = util_scanf_int_with_limits("Report step: ", PROMPT_LEN , 0 , last_report); double lower_limit = util_scanf_double("Lower limit", PROMPT_LEN); double upper_limit = util_scanf_double("Upper limit", PROMPT_LEN); char * export_file; util_printf_prompt("Filename to store file: " , PROMPT_LEN , '=' , "=> "); export_file = util_alloc_stdin_line(); { enkf_fs_type * fs = enkf_main_tui_get_fs(enkf_main); enkf_node_type ** ensemble = enkf_node_load_alloc_ensemble( config_node , fs , report_step , iens1 , iens2 ); enkf_node_type * sum = enkf_node_alloc( config_node ); int active_ens_size = 0; int iens; enkf_node_clear( sum ); { /* OK going low level */ field_type * sum_field = (field_type *) enkf_node_value_ptr( sum ); for (iens = iens1; iens < iens2; iens++) { if (ensemble[iens - iens1] != NULL) { field_type * field = (field_type *) enkf_node_value_ptr( ensemble[iens - iens1] ); field_update_sum( sum_field , field , lower_limit , upper_limit); active_ens_size++; } } if (active_ens_size > 0) { field_scale( sum_field , 1.0 / active_ens_size ); { char * path; util_alloc_file_components( export_file , &path , NULL , NULL); if (path != NULL) { util_make_path( path ); free( path ); } } field_export(sum_field , export_file , NULL , RMS_ROFF_FILE , false, NULL); } else fprintf(stderr,"Warning: no data found \n"); } for (iens = iens1; iens < iens2; iens++) { if (ensemble[iens - iens1] != NULL) enkf_node_free( ensemble[iens - iens1] ); } free( ensemble ); enkf_node_free( sum ); } free( export_file ); }
void qc_module_set_workflow( qc_module_type * qc_module , const char * qc_workflow ) { char * workflow_name; util_alloc_file_components( qc_workflow , NULL , &workflow_name , NULL ); { workflow_type * workflow = ert_workflow_list_add_workflow( qc_module->workflow_list , qc_workflow , workflow_name); if (workflow != NULL) { ert_workflow_list_add_alias( qc_module->workflow_list , workflow_name , QC_WORKFLOW_NAME ); qc_module->qc_workflow = workflow; } } free( workflow_name ); }
void ert_workflow_list_add_job( ert_workflow_list_type * workflow_list , const char * job_name , const char * config_file ) { char * name = (char *) job_name; if (job_name == NULL) util_alloc_file_components( config_file , NULL , &name , NULL ); if (!workflow_joblist_add_job_from_file( workflow_list->joblist , name , config_file )) fprintf(stderr,"** Warning: failed to add workflow job:%s from:%s \n",name , config_file ); if (job_name == NULL) free(name); }
void enkf_tui_export_gen_data(void * arg) { enkf_main_type * enkf_main = enkf_main_safe_cast( arg ); const ensemble_config_type * ensemble_config = enkf_main_get_ensemble_config(enkf_main); { int report_step; int iens1 , iens2; const int last_report = enkf_main_get_history_length( enkf_main ); const enkf_config_node_type * config_node; path_fmt_type * file_fmt; config_node = enkf_tui_util_scanf_key(ensemble_config , PROMPT_LEN , GEN_DATA , INVALID_VAR); report_step = util_scanf_int_with_limits("Report step: ", PROMPT_LEN , 0 , last_report); enkf_tui_util_scanf_iens_range("Realizations members to export(0 - %d)" , enkf_main_get_ensemble_size( enkf_main ) , PROMPT_LEN , &iens1 , &iens2); { char path_fmt[512]; util_printf_prompt("Filename to store files in (with %d) in: " , PROMPT_LEN , '=' , "=> "); scanf("%s" , path_fmt); file_fmt = path_fmt_alloc_path_fmt( path_fmt ); } { enkf_fs_type * fs = enkf_main_tui_get_fs(enkf_main); enkf_node_type * node = enkf_node_alloc(config_node); gen_data_file_format_type export_type = gen_data_guess_export_type( (const gen_data_type *) enkf_node_value_ptr(node) ); int iens; for (iens = iens1; iens <= iens2; iens++) { node_id_type node_id = {.report_step = report_step , .iens = iens}; if (enkf_node_try_load(node , fs, node_id)) { char * full_path = path_fmt_alloc_path( file_fmt , false , iens); char * path; util_alloc_file_components(full_path , &path , NULL , NULL); if (path != NULL) util_make_path( path ); { const gen_data_type * gen_data = (const gen_data_type *) enkf_node_value_ptr(node); gen_data_export(gen_data , full_path , export_type); } free(full_path); free(path); } } enkf_node_free(node); } } }
void enkf_tui_export_field(const enkf_main_type * enkf_main , field_file_format_type file_type) { const ensemble_config_type * ensemble_config = enkf_main_get_ensemble_config(enkf_main); const bool output_transform = true; const enkf_config_node_type * config_node; const int last_report = enkf_main_get_history_length( enkf_main ); int iens1 , iens2 , iens , report_step; path_fmt_type * export_path; config_node = enkf_tui_util_scanf_key(ensemble_config , PROMPT_LEN , FIELD , INVALID_VAR ); report_step = util_scanf_int_with_limits("Report step: ", PROMPT_LEN , 0 , last_report); enkf_tui_util_scanf_iens_range("Realizations members to export(0 - %d)" , enkf_main_get_ensemble_size( enkf_main ) , PROMPT_LEN , &iens1 , &iens2); { char * path_fmt; util_printf_prompt("Filename to store files in (with %d) in: " , PROMPT_LEN , '=' , "=> "); path_fmt = util_alloc_stdin_line(); export_path = path_fmt_alloc_path_fmt( path_fmt ); free( path_fmt ); } { enkf_fs_type * fs = enkf_main_tui_get_fs(enkf_main); enkf_node_type * node = enkf_node_alloc(config_node); for (iens = iens1; iens <= iens2; iens++) { node_id_type node_id = {.report_step = report_step , .iens = iens }; if (enkf_node_try_load(node , fs , node_id)) { char * filename = path_fmt_alloc_path( export_path , false , iens); { char * path; util_alloc_file_components(filename , &path , NULL , NULL); if (path != NULL) { util_make_path( path ); free( path ); } } { const field_type * field = (const field_type *) enkf_node_value_ptr(node); field_export(field , filename , NULL , file_type , output_transform, NULL); } free(filename); } else printf("Warning: could not load realization:%d \n", iens); } enkf_node_free(node); } }
void hook_manager_init_hook( hook_manager_type * hook_manager , const config_content_type * config) { if (config_content_has_item( config , HOOK_WORKFLOW_KEY)) { const char * file_name = config_content_iget( config , HOOK_WORKFLOW_KEY, 0, 0 ); char * workflow_name; util_alloc_file_components( file_name , NULL , &workflow_name , NULL ); { workflow_type * workflow = ert_workflow_list_add_workflow( hook_manager->workflow_list , file_name , workflow_name); if (workflow != NULL) { ert_workflow_list_add_alias( hook_manager->workflow_list , workflow_name , HOOK_WORKFLOW_KEY ); hook_workflow_set_workflow( hook_manager->hook_workflow , workflow); } hook_workflow_set_run_mode( hook_manager->hook_workflow , config_content_iget( config , HOOK_WORKFLOW_KEY, 0, 1 )); } } }
char * util_split_alloc_filename( const char * input_path ) { char * filename = NULL; { char * basename; char * extension; util_alloc_file_components( input_path , NULL , &basename , &extension); if (basename) filename = util_alloc_filename( NULL , basename , extension ); util_safe_free( basename ); util_safe_free( extension ); } return filename; }
void test_case_no_path( const char * sum_case , bool expected_exist) { path_stack_type * path_stack = path_stack_alloc(); path_stack_push_cwd( path_stack ); { char * basename , *path; util_alloc_file_components( sum_case , &path , &basename , NULL ); if (path) chdir( path ); test_assert_bool_equal(expected_exist , ecl_sum_case_exists( basename )); free( path ); free( basename ); } path_stack_pop( path_stack ); path_stack_free( path_stack ); }
int main(int argc , char ** argv) { const char * case_path = argv[1]; char * grid_file = util_alloc_filename(NULL , case_path, "EGRID"); stringlist_type * file_list = stringlist_alloc_new( ); ecl_grid_type * grid = ecl_grid_alloc( grid_file ); ecl_util_select_filelist( NULL , case_path , ECL_RESTART_FILE , false , file_list); printf("Searching in:%s \n",case_path); test_assert_int_equal( 4 , stringlist_get_size( file_list )); stringlist_sort( file_list , (string_cmp_ftype *) util_strcmp_int ); { int i; for (i=0; i < stringlist_get_size( file_list); i++) { char * ext; char * target_ext = util_alloc_sprintf("X%04d" , i); util_alloc_file_components( stringlist_iget( file_list , i ) , NULL , NULL , &ext); test_assert_string_equal( ext , target_ext); free( ext ); free( target_ext ); } } { well_info_type * well_info = well_info_alloc( grid ); int i; for (i=0; i < stringlist_get_size( file_list ); i++) { printf("Loading file:%s \n",stringlist_iget( file_list , i )); well_info_load_rstfile( well_info , stringlist_iget(file_list , i)); } well_info_free( well_info ); } { well_info_type * well_info = well_info_alloc( grid ); int i; stringlist_reverse( file_list ); for (i=0; i < stringlist_get_size( file_list ); i++) well_info_load_rstfile( well_info , stringlist_iget(file_list , i)); well_info_free( well_info ); } exit(0); }
void test_copy_parent_directory( const char * path ) { test_work_area_type * work_area = test_work_area_alloc( "copy-parent-directory" ); char * parent_path; { char * full_path = util_alloc_abs_path( path ); util_alloc_file_components( path , &parent_path , NULL , NULL); free( full_path ); } test_assert_false( test_work_area_copy_parent_directory( work_area , "Does/not/exist") ); test_assert_true( test_work_area_copy_parent_directory( work_area , path ) ); test_assert_true( util_entry_exists( parent_path )); test_assert_true( util_is_directory( parent_path )); test_work_area_free( work_area ); free( parent_path ); }
void hook_manager_init_post_hook( hook_manager_type * hook_manager , const config_content_type * config) { if (config_content_has_item( config , QC_PATH_KEY )) hook_manager_set_path( hook_manager, config_content_get_value( config , QC_PATH_KEY )); if (config_content_has_item( config , QC_WORKFLOW_KEY)) { const char * file_name = config_content_get_value_as_path(config , QC_WORKFLOW_KEY); char * workflow_name; util_alloc_file_components( file_name , NULL , &workflow_name , NULL ); { workflow_type * workflow = ert_workflow_list_add_workflow( hook_manager->workflow_list , file_name , workflow_name); if (workflow != NULL) { ert_workflow_list_add_alias( hook_manager->workflow_list , workflow_name , QC_WORKFLOW_NAME ); hook_workflow_set_workflow( hook_manager->post_hook_workflow, workflow ); } hook_workflow_set_run_mode( hook_manager->post_hook_workflow, RUN_MODE_POST_SIMULATION_NAME); } } }
bool ecl_sum_case_exists( const char * input_file ) { char * smspec_file = NULL; stringlist_type * data_files = stringlist_alloc_new(); char * path; char * basename; char * extension; bool case_exists; util_alloc_file_components( input_file , &path , &basename , &extension); case_exists = ecl_util_alloc_summary_files( path , basename , extension , &smspec_file , data_files ); util_safe_free( path ); util_safe_free( basename ); util_safe_free( extension ); util_safe_free( smspec_file ); stringlist_free( data_files ); return case_exists; }
int main(int argc, char ** argv) { if (argc != 5) { fprintf(stderr,"%s: basename nx ny nz \n",argv[0]); exit(1); } { const char * base_input = argv[1]; int nx = atoi(argv[2]); int ny = atoi(argv[3]); int nz = atoi(argv[4]); char * path , *basename; ecl_grid_type * ecl_grid; util_alloc_file_components( base_input , &path , &basename , NULL ); ecl_grid = ecl_grid_alloc_rectangular(nx,ny,nz , 1 ,1 ,1 , NULL ); { char * EGRID_file = util_alloc_filename( path , basename , "EGRID"); printf("Writing file: %s ...",EGRID_file); fflush(stdout); ecl_grid_fwrite_EGRID2( ecl_grid , EGRID_file, ERT_ECL_METRIC_UNITS); free( EGRID_file ); } { char * grdecl_file = util_alloc_filename( path , basename , "grdecl"); FILE * stream = util_fopen( grdecl_file , "w"); printf("\nWriting file: %s ...",grdecl_file); fflush(stdout); ecl_grid_fprintf_grdecl( ecl_grid , stream ); fclose( stream ); free( grdecl_file ); printf("\n"); } free( basename ); util_safe_free( path ); ecl_grid_free( ecl_grid ); } }
bool ecl_sum_same_case( const ecl_sum_type * ecl_sum , const char * input_file ) { bool same_case = false; { char * path; char * base; util_alloc_file_components( input_file , &path , &base , NULL); { bool fmt_file = ecl_smspec_get_formatted( ecl_sum->smspec ); char * header_file = ecl_util_alloc_exfilename( path , base , ECL_SUMMARY_HEADER_FILE , fmt_file , -1 ); if (header_file != NULL) { same_case = util_same_file( header_file , ecl_smspec_get_header_file( ecl_sum->smspec )); free( header_file ); } } util_safe_free( path ); util_safe_free( base ); } return same_case; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RifEclipseSummaryTools::findSummaryFiles(const QString& inputFile, QString* headerFile, QStringList* dataFiles) { dataFiles->clear(); headerFile->clear(); char* myPath = nullptr; char* myBase = nullptr; char* myExtention = nullptr; util_alloc_file_components(RiaStringEncodingTools::toNativeEncoded(inputFile).data(), &myPath, &myBase, &myExtention); QString path; if(myPath) path = RiaStringEncodingTools::fromNativeEncoded(myPath); QString base; if(myBase) base = RiaStringEncodingTools::fromNativeEncoded(myBase); std::string extention; if(myExtention) extention = myExtention; if(path.isEmpty() || base.isEmpty()) return ; char* myHeaderFile = nullptr; stringlist_type* summary_file_list = stringlist_alloc_new(); ecl_util_alloc_summary_files(RiaStringEncodingTools::toNativeEncoded(path).data(), RiaStringEncodingTools::toNativeEncoded(base).data(), extention.data(), &myHeaderFile, summary_file_list); if(myHeaderFile) { (*headerFile) = RiaStringEncodingTools::fromNativeEncoded(myHeaderFile); util_safe_free(myHeaderFile); } if(stringlist_get_size(summary_file_list) > 0) { for(int i = 0; i < stringlist_get_size(summary_file_list); i++) { dataFiles->push_back(RiaStringEncodingTools::fromNativeEncoded(stringlist_iget(summary_file_list,i))); } } stringlist_free(summary_file_list); return; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RifEclipseSummaryTools::findSummaryFiles(const std::string& inputFile, std::string* headerFile, std::vector<std::string>* dataFiles) { dataFiles->clear(); headerFile->clear(); char* myPath = NULL; char* myBase = NULL; char* myExtention = NULL; util_alloc_file_components(inputFile.data(), &myPath, &myBase, &myExtention); std::string path; if(myPath) path = myPath; std::string base; if(myBase) base = myBase; std::string extention; if(myExtention) extention = myExtention; if(path.empty() || base.empty()) return ; char* myHeaderFile = NULL; stringlist_type* summary_file_list = stringlist_alloc_new(); ecl_util_alloc_summary_files(path.data(), base.data(), extention.data(), &myHeaderFile, summary_file_list); if(myHeaderFile) { (*headerFile) = myHeaderFile; util_safe_free(myHeaderFile); } if(stringlist_get_size(summary_file_list) > 0) { for(int i = 0; i < stringlist_get_size(summary_file_list); i++) { dataFiles->push_back(stringlist_iget(summary_file_list,i)); } } stringlist_free(summary_file_list); return; }
workflow_type * ert_workflow_list_add_workflow( ert_workflow_list_type * workflow_list , const char * workflow_file , const char * workflow_name) { if (util_file_exists( workflow_file )) { workflow_type * workflow = workflow_alloc( workflow_file , workflow_list->joblist ); char * name; if (workflow_name == NULL) util_alloc_file_components( workflow_file , NULL , &name , NULL ); else name = (char *) workflow_name; hash_insert_hash_owned_ref( workflow_list->workflows , name , workflow , workflow_free__); if (hash_has_key( workflow_list->alias_map , name)) hash_del( workflow_list->alias_map , name); if (workflow_name == NULL) free( name ); return workflow; } else return NULL; }
field_file_format_type field_config_default_export_format(const char * filename) { field_file_format_type export_format = FILE_FORMAT_NULL; if (filename != NULL) { export_format = ECL_KW_FILE_ALL_CELLS; /* Suitable for PERMX/PORO/... ; when this export format is used IMPORT must be used in the datafile instead of INCLUDE. This gives faster ECLIPSE startup time, but is (unfortunately) quite unstandard. */ char * extension; util_alloc_file_components(filename , NULL,NULL,&extension); if (extension != NULL) { util_strupr(extension); if (strcmp(extension , "GRDECL") == 0) export_format = ECL_GRDECL_FILE; else if (strcmp(extension , "ROFF") == 0) export_format = RMS_ROFF_FILE; free(extension); } } return export_format; }
char * ecl_util_alloc_base_guess(const char * path) { char * base = NULL; stringlist_type * data_files = stringlist_alloc_new( ); stringlist_type * DATA_files = stringlist_alloc_new( ); stringlist_select_matching_files( data_files , path , "*.data"); stringlist_select_matching_files( DATA_files , path , "*.DATA"); if ((stringlist_get_size( data_files ) + stringlist_get_size( DATA_files)) == 1) { const char * path_name; if (stringlist_get_size( data_files ) == 1) path_name = stringlist_iget( data_files , 0 ); else path_name = stringlist_iget( DATA_files , 0 ); util_alloc_file_components( path_name , NULL , &base , NULL ); } // Else - found either 0 or more than 1 file with extension DATA - impossible to guess. stringlist_free( data_files ); stringlist_free( DATA_files ); return base; }
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); } }
void ecl_config_set_init_section( ecl_config_type * ecl_config , const char * input_init_section ) { /* The semantic regarding INIT_SECTION is as follows: 1. If the INIT_SECTION points to an existing file - the ecl_config->input_init_section is set to the absolute path of this file. 2. If the INIT_SECTION points to a not existing file: a. We assert that INIT_SECTION points to a pure filename, i.e. /some/path/which/does/not/exist is NOT accepted. In the case the input argument contain a path a error message will be printed on stderr and the ->init_section will not be set. b. The ecl_config->input_init_section is set to point to this file. c. WE TRUST THE USER TO SUPPLY CONTENT (THROUGH SOME FUNKY FORWARD MODEL) IN THE RUNPATH. This can unfortunately not be checked/verified before the ECLIPSE simulation fails. The INIT_SECTION keyword and <INIT> in the datafile (checked with ecl_config->can_restart) interplay as follows: CASE | INIT_SECTION | <INIT> | OK ? --------------------------------------------- 0 | Present | Present | Yes 1 | Not Present | Present | No 2 | Present | Not present| No 3 | Not Present | Not present| Yes --------------------------------------------- Case 0: This is the most flexible case, which can do arbitrary restart. Case 1: In this case the datafile will contain a <INIT> tag, we we do not have the info to replace that tag with for initialisation, and ECLIPSE will fail. Strictly speaking this case can actually restart, but that is not enough - we let this case fail hard. Case 2: We have some INIT_SECTION infor, but no tag in he datafile to update. If the datafile has embedded initialisation info this case will work for init; but it is logically flawed, and not accepted. Currently only a warning. Case 3: This case has just the right amount of information for initialisation, but it is 'consistently unable' to restart. */ if (ecl_config->can_restart) { /* The <INIT> tag is set. */ ecl_config->input_init_section = util_realloc_string_copy( ecl_config->input_init_section , input_init_section ); /* input_init_section = path/to/init_section */ if (util_file_exists( ecl_config->input_init_section )) { /* init_section = $CWD/path/to/init_section */ util_safe_free( ecl_config->init_section ); ecl_config->init_section = util_alloc_realpath(input_init_section); } else { char * path; util_alloc_file_components( ecl_config->input_init_section , &path , NULL , NULL ); if (path != NULL) fprintf(stderr,"** Warning: %s: When INIT_SECTION:%s points to a non-existing file - you can not have any path components.\n",__func__ , input_init_section); else ecl_config->init_section = util_alloc_string_copy(input_init_section); util_safe_free( path ); } } else /* The <INIT> tag is not set - we can not utilize the input_init_section info, and we just ignore it. */ fprintf(stderr,"** Warning: <INIT> tag was not found in datafile - can not utilize INIT_SECTION keyword - ignored.\n"); }
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); } }
void output_save_S3Graph( const output_type * output, ensemble_type * ensemble , const double ** data ) { FILE * stream = util_mkdir_fopen( output->file , "w"); const char * kw_fmt = "\t%s"; const char * unit_fmt = "\t%s"; const char * wgname_fmt = "\t%s"; const char * num_fmt = "\t%d"; const char * float_fmt = "\t%0.4f"; const char * days_fmt = "\t%0.2f"; const char * empty_fmt = "\t"; const char * date_fmt = "%d/%d/%d"; const char * time_header = "DATE\tTIME"; const char * time_unit = "\tDAYS"; const char * time_blank = "\t"; const int data_columns = vector_get_size( output->keys ); const int data_rows = time_t_vector_size( ensemble->interp_time ); int row_nr,column_nr; { char * origin; util_alloc_file_components( output->file , NULL ,&origin , NULL); fprintf(stream , "ORIGIN %s\n", origin ); free( origin ); } /* 1: Writing first header line with variables. */ fprintf(stream , time_header ); for (column_nr = 0; column_nr < data_columns; column_nr++) { const quant_key_type * qkey = vector_iget( output->keys , column_nr ); print_var( stream , ecl_sum_get_keyword( ensemble->refcase , qkey->sum_key ) , qkey->quantile , kw_fmt); } fprintf(stream , "\n"); /* 2: Writing second header line with units. */ fprintf(stream , time_unit ); for (column_nr = 0; column_nr < data_columns; column_nr++) { const quant_key_type * qkey = vector_iget( output->keys , column_nr ); fprintf(stream , unit_fmt , ecl_sum_get_unit( ensemble->refcase , qkey->sum_key ) ); } fprintf(stream , "\n"); /*3: Writing third header line with WGNAMES / NUMS - extra information - breaks completely down with LGR information. */ fprintf(stream , time_blank ); { for (column_nr = 0; column_nr < data_columns; column_nr++) { const quant_key_type * qkey = vector_iget( output->keys , column_nr ); const char * ecl_key = qkey->sum_key; const char * wgname = ecl_sum_get_wgname( ensemble->refcase , ecl_key ); int num = ecl_sum_get_num( ensemble->refcase , ecl_key ); ecl_smspec_var_type var_type = ecl_sum_get_var_type( ensemble->refcase , ecl_key); bool need_num = ecl_smspec_needs_num( var_type ); bool need_wgname = ecl_smspec_needs_wgname( var_type ); if (need_num && need_wgname) { /** Do not know how to include both - will just create a mangled name as a combination. */ char * wgname_num = util_alloc_sprintf("%s:%d" , wgname , num); fprintf(stream , wgname_fmt , wgname_num); free( wgname_num ); } else if (need_num) fprintf(stream , num_fmt , num); else if (need_wgname) fprintf(stream , wgname_fmt , wgname); else fprintf(stream , empty_fmt ); } fprintf(stream , "\n"); } /*4: Writing the actual data. */ for (row_nr = 0; row_nr < data_rows; row_nr++) { time_t interp_time = time_t_vector_iget( ensemble->interp_time , row_nr); { int mday,month,year; util_set_datetime_values(interp_time , NULL , NULL , NULL , &mday , &month , &year); fprintf(stream , date_fmt , mday , month , year); } fprintf(stream , days_fmt , 1.0*(interp_time - ensemble->start_time) / 86400); for (column_nr = 0; column_nr < data_columns; column_nr++) { fprintf(stream , float_fmt , data[row_nr][column_nr]); } fprintf( stream , "\n"); } }