示例#1
0
文件: enkf_tui_fs.c 项目: akva2/ert
/**
   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;
}
示例#2
0
void enkf_main_user_select_fs(enkf_main_type * enkf_main , const char * input_case ) {
    const char * ens_path = model_config_get_enspath( enkf_main->model_config);
    int root_version = enkf_fs_get_version104( ens_path );
    if (root_version == -1 || root_version == 105) {
        if (input_case == NULL) {
            char * current_mount_point = util_alloc_filename( ens_path , CURRENT_CASE , NULL);

            if (enkf_main_current_case_file_exists(enkf_main)) {
                char * current_case = enkf_main_read_alloc_current_case_name(enkf_main);
                enkf_main_select_fs(enkf_main, current_case);
                free (current_case);
            } else if (enkf_fs_exists( current_mount_point ) && util_is_link( current_mount_point )) {
                /*If the current_case file does not exists, but the 'current' symlink does we use readlink to
                  get hold of the actual target before calling the  enkf_main_select_fs() function. We then
                  write the current_case file and delete the symlink.*/
                char * target_case = util_alloc_atlink_target( ens_path , CURRENT_CASE );
                enkf_main_select_fs( enkf_main , target_case );
                unlink(current_mount_point);
                enkf_main_write_current_case_file(enkf_main, target_case);
                free( target_case );
            } else
                enkf_main_select_fs( enkf_main , DEFAULT_CASE );  // Selecting (a new) default case

            free( current_mount_point );
        } else
            enkf_main_select_fs( enkf_main , input_case );
    } else {
        fprintf(stderr,"Sorry: the filesystem located in %s must be upgraded before the current ERT version can read it.\n" , ens_path);
        exit(1);
    }
}
示例#3
0
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;
}
示例#4
0
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;
  }
}
示例#5
0
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;
    }
}