Exemplo n.º 1
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);
    }
}
Exemplo n.º 2
0
stringlist_type * enkf_main_alloc_caselist( const enkf_main_type * enkf_main ) {
    stringlist_type * case_list = stringlist_alloc_new( );
    {
        const char * ens_path = model_config_get_enspath( enkf_main->model_config );
        DIR * ens_dir = opendir( ens_path );
        if (ens_dir != NULL) {
            int ens_fd = dirfd( ens_dir );
            if (ens_fd != -1) {
                struct dirent * dp;
                do {
                    dp = readdir( ens_dir );
                    if (dp != NULL) {
                        if (!(util_string_equal( dp->d_name , ".") || util_string_equal(dp->d_name , ".."))) {
                            if (!util_string_equal( dp->d_name , CURRENT_CASE_FILE)) {
                                char * full_path = util_alloc_filename( ens_path , dp->d_name , NULL);
                                if (util_is_directory( full_path ))
                                    stringlist_append_copy( case_list , dp->d_name );
                                free( full_path);
                            }
                        }
                    }
                } while (dp != NULL);
            }
        }
        closedir( ens_dir );
    }
    return case_list;
}
Exemplo n.º 3
0
static bool enkf_main_current_case_file_exists( const enkf_main_type * enkf_main) {
    const char * ens_path = model_config_get_enspath( enkf_main->model_config);
    char * current_case_file = util_alloc_filename(ens_path, CURRENT_CASE_FILE, NULL);
    bool exists = util_file_exists(current_case_file);
    free(current_case_file);
    return exists;
}
Exemplo n.º 4
0
char * enkf_main_alloc_mount_point( const enkf_main_type * enkf_main , const char * case_path) {
    char * mount_point;
    if (util_is_abs_path( case_path ))
        mount_point = util_alloc_string_copy( case_path );
    else
        mount_point = util_alloc_filename( model_config_get_enspath( enkf_main->model_config) , case_path , NULL);
    return mount_point;
}
Exemplo n.º 5
0
static void enkf_main_write_current_case_file( const enkf_main_type * enkf_main, const char * case_path) {
    const char * ens_path = model_config_get_enspath( enkf_main->model_config);
    const char * base = CURRENT_CASE_FILE;
    char * current_case_file = util_alloc_filename(ens_path , base, NULL);
    FILE * stream = util_fopen( current_case_file  , "w");
    fprintf(stream, "%s", case_path);
    util_fclose(stream);
    free(current_case_file);
}
Exemplo n.º 6
0
char* enkf_main_read_alloc_current_case_name(const enkf_main_type * enkf_main) {
    char * current_case = NULL;
    const char * ens_path = model_config_get_enspath( enkf_main->model_config);
    char * current_case_file = util_alloc_filename(ens_path, CURRENT_CASE_FILE, NULL);
    if (enkf_main_current_case_file_exists(enkf_main)) {
        FILE * stream = util_fopen( current_case_file  , "r");
        current_case = util_fscanf_alloc_token(stream);
        util_fclose(stream);
    } else {
        util_abort("%s: File: storage/current_case not found, aborting! \n",__func__);
    }
    free(current_case_file);
    return current_case;
}
Exemplo n.º 7
0
void test_case_initialized() {
  test_work_area_type * work_area = test_work_area_alloc("enkf_main_case_initialized" );
  {
    enkf_main_type * enkf_main = enkf_main_alloc_empty();
    model_config_type * model_config = enkf_main_get_model_config(enkf_main);
    const char * new_case = "fs/case";
    char * mount_point = util_alloc_sprintf("%s/%s" , model_config_get_enspath(model_config) , new_case);
    enkf_fs_create_fs(mount_point , BLOCK_FS_DRIVER_ID , NULL);

    test_assert_false(enkf_main_case_is_initialized(enkf_main , "does/not/exist" , NULL));
    test_assert_true(enkf_main_case_is_initialized(enkf_main , new_case , NULL));

    enkf_main_free(enkf_main);
  }
  test_work_area_free(work_area);
}
Exemplo n.º 8
0
void enkf_main_select_fs( enkf_main_type * enkf_main , const char * case_path ) {
    if (enkf_main_case_is_current( enkf_main , case_path ))
        return;  /* We have tried to select the currently selected case - just return. */
    else {
        enkf_fs_type * new_fs = enkf_main_mount_alt_fs( enkf_main , case_path , true );
        if (enkf_main->dbase == new_fs)
            util_abort("%s : return reference to current FS in situation where that should not happen.\n",__func__);

        if (new_fs != NULL)
            enkf_main_set_fs( enkf_main , new_fs , case_path);
        else {
            const char * ens_path = model_config_get_enspath( enkf_main->model_config );
            util_exit("%s: select filesystem %s:%s failed \n",__func__ , ens_path , case_path );
        }
        enkf_fs_decref( new_fs );
    }
}
Exemplo n.º 9
0
static void update_case_log(enkf_main_type * enkf_main , const char * case_path) {
    /*  : Update a small text file with the name of the host currently
          running ert, the pid number of the process, the active case
          and when it started.

          If the previous shutdown was unclean the file will be around,
          and we will need the info from the previous invocation which
          is in the file. For that reason we open with mode 'a' instead
          of 'w'.
    */

    const char * ens_path = model_config_get_enspath( enkf_main->model_config);

    {
        int buffer_size = 256;
        char * current_host = util_alloc_filename( ens_path , CASE_LOG , NULL );
        FILE * stream = util_fopen( current_host , "a");

        fprintf(stream , "CASE:%-16s  " , case_path );
        fprintf(stream , "PID:%-8d  " , getpid());
        {
            char hostname[buffer_size];
            gethostname( hostname , buffer_size );
            fprintf(stream , "HOST:%-16s  " , hostname );
        }


        {
            int year,month,day,hour,minute,second;
            time_t now = time( NULL );

            util_set_datetime_values( now , &second , &minute , &hour , &day , &month , &year );

            fprintf(stream , "TIME:%02d/%02d/%4d-%02d.%02d.%02d\n" , day , month ,  year , hour , minute , second);
        }
        fclose( stream );
        free( current_host );
    }
}
Exemplo n.º 10
0
const char * enkf_main_get_mount_root( const enkf_main_type * enkf_main) {
    return model_config_get_enspath( enkf_main->model_config);
}