/** Return NULL if no action should be performed. */ static char * enkf_tui_fs_alloc_existing_case(enkf_main_type * enkf_main , const char * prompt , int prompt_len) { char * name; while (true) { util_printf_prompt(prompt , prompt_len , '=' , "=> "); name = util_alloc_stdin_line(); if (name == NULL) /* The user entered a blank string */ break; else { char * mount_point = enkf_main_alloc_mount_point( enkf_main , name ); if (enkf_fs_exists( mount_point )) break; else { printf("** can not find case: \"%s\" \n",name); free(name); } free( mount_point ); } } return name; }
bool enkf_main_fs_exists(const enkf_main_type * enkf_main, const char * input_case) { bool exists = false; char * new_mount_point = enkf_main_alloc_mount_point( enkf_main , input_case); if(enkf_fs_exists( new_mount_point )) exists = true; free( new_mount_point ); return exists; }
static void enkf_main_create_fs( const enkf_main_type * enkf_main , const char * case_path ) { char * new_mount_point = enkf_main_alloc_mount_point( enkf_main , case_path ); enkf_fs_create_fs( new_mount_point, model_config_get_dbase_type( enkf_main->model_config ) , model_config_get_dbase_args( enkf_main->model_config )); free( new_mount_point ); }
bool enkf_main_case_is_current(const enkf_main_type * enkf_main , const char * case_path) { char * mount_point = enkf_main_alloc_mount_point( enkf_main , case_path ); const char * current_mount_point = NULL; bool is_current; if (enkf_main->dbase != NULL) current_mount_point = enkf_fs_get_mount_point( enkf_main->dbase ); is_current = util_string_equal( mount_point , current_mount_point ); free( mount_point ); return is_current; }
enkf_fs_type * enkf_main_mount_alt_fs(const enkf_main_type * enkf_main , const char * case_path , bool create) { if (enkf_main_case_is_current( enkf_main , case_path )) { // Fast path - we just return a reference to the currently selected case; // with increased refcount. enkf_fs_incref( enkf_main->dbase ); return enkf_main->dbase; } else { // We have asked for an alterantive fs - must mount and possibly create that first. enkf_fs_type * new_fs = NULL; if (case_path != NULL) { char * new_mount_point = enkf_main_alloc_mount_point( enkf_main , case_path ); if (!enkf_fs_exists( new_mount_point )) { if (create) enkf_main_create_fs( enkf_main , case_path ); } new_fs = enkf_fs_mount( new_mount_point ); free( new_mount_point ); } return new_fs; } }
enkf_fs_type * enkf_main_mount_alt_fs(const enkf_main_type * enkf_main , const char * case_path , bool create) { if (enkf_main_case_is_current( enkf_main , case_path )) { // Fast path - we just return a reference to the currently selected case; // with increased refcount. enkf_fs_incref( enkf_main->dbase ); return enkf_main->dbase; } else { // We have asked for an alterantive fs - must mount and possibly create that first. enkf_fs_type * new_fs = NULL; if (case_path != NULL) { char * new_mount_point = enkf_main_alloc_mount_point( enkf_main , case_path ); if (!enkf_fs_exists( new_mount_point )) { if (create) enkf_main_create_fs( enkf_main , case_path ); } new_fs = enkf_fs_mount( new_mount_point ); if (new_fs) { const model_config_type * model_config = enkf_main_get_model_config( enkf_main ); const ecl_sum_type * refcase = model_config_get_refcase( model_config ); if (refcase) { time_map_type * time_map = enkf_fs_get_time_map( new_fs ); if (time_map_attach_refcase( time_map , refcase)) time_map_set_strict( time_map , false ); else ert_log_add_fmt_message(1 , stderr , "Warning mismatch between refcase:%s and existing case:%s" , ecl_sum_get_case( refcase ) , new_mount_point); } } free( new_mount_point ); } return new_fs; } }
time_map_type * enkf_main_alloc_readonly_time_map( const enkf_main_type * enkf_main , const char * case_path ) { char * mount_point = enkf_main_alloc_mount_point( enkf_main , case_path ); time_map_type * time_map = enkf_fs_alloc_readonly_time_map( mount_point ); free( mount_point ); return time_map; }