Пример #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);
    }
}
Пример #2
0
int test_load_manually_to_new_case(enkf_main_type * enkf_main) {
  int result = 0;
  int iens = 0;
  int iter = 0;
  const char * casename = "new_case";
  enkf_main_select_fs( enkf_main , casename );
  
  
  enkf_fs_type * fs = enkf_main_get_fs( enkf_main );
  run_arg_type * run_arg = run_arg_alloc_ENSEMBLE_EXPERIMENT(fs , iens , iter , "simulations/run0");
  {
    arg_pack_type * arg_pack = arg_pack_alloc();
    arg_pack_append_ptr( arg_pack , enkf_main_iget_state(enkf_main, 0));                
    arg_pack_append_ptr( arg_pack , run_arg );
    arg_pack_append_bool( arg_pack , true );                                            
    arg_pack_append_owned_ptr( arg_pack , stringlist_alloc_new() , stringlist_free__);  
    arg_pack_append_bool( arg_pack, true );                                             
    arg_pack_append_ptr( arg_pack, &result );                                           
    
    enkf_state_load_from_forward_model_mt(arg_pack);
    arg_pack_free(arg_pack);
  }
  
  return result;
}
int main( int argc , char ** argv) {
  const char * model_config = argv[1];
  const char * site_config = NULL;
  ert_test_context_type * test_context = ert_test_context_alloc( "MAGIC-STRINGS" , model_config , site_config);
  enkf_main_type * enkf_main = ert_test_context_get_main( test_context );

  {
    test_has_job( test_context );

    enkf_main_select_fs(enkf_main , "default");
    test_assert_string_equal( "default" , enkf_fs_get_case_name( enkf_main_get_fs( enkf_main )));
    test_magic_strings( test_context );
    
    enkf_main_select_fs(enkf_main , "extraCase");
    test_assert_string_equal( "extraCase" , enkf_fs_get_case_name( enkf_main_get_fs( enkf_main )));
    test_magic_strings( test_context );
  }
  ert_test_context_free( test_context );
}
Пример #4
0
void test_init_case_job(ert_test_context_type * test_context, const char * job_name , const char * job_file) {
  stringlist_type * args = stringlist_alloc_new();
  enkf_main_type * enkf_main = ert_test_context_get_main(test_context);

  test_assert_true( ert_test_context_install_workflow_job( test_context , "JOB" , job_file ) );

  //Test init current case from existing
  {
    enkf_fs_type * cur_fs = enkf_main_mount_alt_fs( enkf_main , "new_current_case" , true );
    enkf_main_select_fs(enkf_main, "new_current_case");

    test_assert_ptr_not_equal(cur_fs , enkf_main_get_fs( enkf_main ));

    stringlist_append_copy( args, "default"); //case to init from
    test_assert_true( ert_test_context_run_worklow_job( test_context , "JOB" , args) );

    enkf_fs_decref(cur_fs);
  }

  {
    const char * current_case = enkf_main_get_current_fs( enkf_main );
    test_assert_string_equal(current_case, "new_current_case");
    test_assert_true(enkf_fs_has_node(enkf_main_get_fs(enkf_main), "PERMZ", PARAMETER, 0, 0, ANALYZED));

    enkf_fs_type * default_fs          = enkf_main_mount_alt_fs( enkf_main , "default" , true  );
    state_map_type * default_state_map = enkf_fs_get_state_map(default_fs);
    state_map_type * current_state_map = enkf_fs_get_state_map(enkf_main_get_fs(enkf_main));
    test_assert_int_equal(state_map_get_size(default_state_map), state_map_get_size(current_state_map));
    enkf_fs_decref(default_fs);
  }


  //Test init case from existing case:
  stringlist_clear(args);
  stringlist_append_copy(args, "default"); //case to init from
  stringlist_append_copy(args, "new_not_current_case");
  test_assert_true( ert_test_context_run_worklow_job( test_context , "JOB" , args) );
  {
    enkf_fs_type * fs = enkf_main_mount_alt_fs(enkf_main, "new_not_current_case", true);
    test_assert_not_NULL( fs );
    test_assert_true( enkf_fs_has_node(fs, "PERMZ", PARAMETER, 0, 0, ANALYZED ));

    enkf_fs_type * default_fs          = enkf_main_mount_alt_fs( enkf_main , "default" , true );
    state_map_type * default_state_map = enkf_fs_get_state_map(default_fs);
    state_map_type * new_state_map     = enkf_fs_get_state_map(fs);
    test_assert_int_equal(state_map_get_size(default_state_map), state_map_get_size(new_state_map));
    enkf_fs_decref(fs);
  }

  stringlist_free( args );
}
Пример #5
0
void enkf_tui_fs_select_case(void * arg)
{
  int    prompt_len = 40;
  char * new_case;
  char * menu_title;

  arg_pack_type  * arg_pack     = arg_pack_safe_cast( arg );
  enkf_main_type * enkf_main    = enkf_main_safe_cast( arg_pack_iget_ptr(arg_pack, 0) );
  menu_type      * menu         = arg_pack_iget_ptr(arg_pack, 1);
  new_case = enkf_tui_fs_alloc_existing_case( enkf_main , "Name of case" , prompt_len);
  if (new_case != NULL) {
    enkf_main_select_fs( enkf_main ,  new_case );
    
    menu_title = util_alloc_sprintf("Manage cases. Current: %s", enkf_main_get_current_fs( enkf_main ));
    menu_set_title(menu, menu_title);
    free(menu_title);
    free(new_case);
  }
}
Пример #6
0
void enkf_tui_fs_create_case(void * arg)
{
  int prompt_len = 50;
  char new_case[256];
  char * menu_title;

  arg_pack_type  * arg_pack     = arg_pack_safe_cast( arg );
  enkf_main_type   * enkf_main  = enkf_main_safe_cast( arg_pack_iget_ptr(arg_pack, 0) );
  menu_type      * menu         = arg_pack_iget_ptr(arg_pack, 1);

  util_printf_prompt("Name of new case" , prompt_len , '=' , "=> ");
  if (fgets(new_case, prompt_len, stdin) != NULL){
    char *newline = strchr(new_case, '\n');
    if (newline)
      *newline = 0;

    if(strlen(new_case) != 0)
      enkf_main_select_fs( enkf_main , new_case );

  }
  menu_title = util_alloc_sprintf("Manage cases. Current: %s", enkf_main_get_current_fs(enkf_main));
  menu_set_title(menu, menu_title);
  free(menu_title);
}
Пример #7
0
/*
   Will create the new case if it does not exist.
*/
void * enkf_main_select_case_JOB( void * self , const stringlist_type * args) {
  enkf_main_type * enkf_main = enkf_main_safe_cast( self );
  const char * new_case = stringlist_iget( args , 0 );
  enkf_main_select_fs( enkf_main , new_case );
  return NULL;
}
Пример #8
0
int main(int argc, char ** argv) {
  const char * config_file = argv[1];
  test_work_area_type * work_area = test_work_area_alloc( "enkf_main_fs" );
  char * model_config;
  util_alloc_file_components( config_file , NULL , &model_config , NULL);
  test_work_area_copy_parent_content( work_area , config_file );
  {
    const char * site_config = "/project/res/etc/ERT/site-config";
    enkf_main_type * enkf_main = enkf_main_bootstrap( site_config , model_config , false , false );

    enkf_main_select_fs( enkf_main , "enkf");
    test_assert_true( enkf_main_case_is_current( enkf_main , "enkf"));
    test_assert_false( enkf_main_case_is_current( enkf_main , "default_fs"));
    test_assert_false( enkf_main_case_is_current( enkf_main , "does_not_exist"));

    test_assert_int_equal( 1 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
    {
      enkf_fs_type * fs_ref = enkf_main_get_fs_ref( enkf_main );
      test_assert_int_equal( 2 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
      enkf_fs_decref( fs_ref );
      test_assert_int_equal( 1 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
    }

    {
      state_map_type * map1 = enkf_fs_get_state_map( enkf_main_get_fs( enkf_main ));
      state_map_type * map2 = enkf_main_alloc_readonly_state_map(enkf_main , "enkf");
      test_assert_true(state_map_equal( map1 , map2 ));
      state_map_free( map2 );
    }
    {
      enkf_fs_type * fs1 = enkf_main_mount_alt_fs( enkf_main , "default" , false );
      enkf_fs_type * fs2 = enkf_main_mount_alt_fs( enkf_main , "enkf" , false );
      
      test_assert_int_equal( 2 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
      test_assert_int_equal( 2 , enkf_fs_get_refcount( fs2 ));
      test_assert_int_equal( 1 , enkf_fs_get_refcount( fs1 ));

      enkf_fs_decref( fs1 );
      enkf_fs_decref( fs2 );
    }

    {
      enkf_fs_type * enkf_fs = enkf_main_mount_alt_fs( enkf_main , "enkf" , false  );
      
      enkf_main_select_fs( enkf_main , "default");
      test_assert_int_equal( 1 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
      enkf_fs_decref( enkf_fs );
    }

    {
      enkf_fs_type * default_fs = enkf_main_mount_alt_fs( enkf_main , "default" , false );
      
      test_assert_int_equal( 2 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
      enkf_main_select_fs( enkf_main , "default");
      test_assert_int_equal( 2 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
      enkf_fs_decref( default_fs );
      test_assert_int_equal( 1 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
    }
    /*****************************************************************/
    {
      enkf_fs_type * fs = enkf_main_mount_alt_fs( enkf_main , "default" , false  );
      test_assert_int_equal( 2 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
      
      enkf_main_set_fs( enkf_main , fs , NULL );
      enkf_fs_decref( fs );
      test_assert_int_equal( 1 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
    }
    {
      enkf_fs_type * fs = enkf_main_mount_alt_fs( enkf_main , "enkf" , false );
      enkf_fs_type * current = enkf_main_mount_alt_fs( enkf_main , "default" , false );
      
      test_assert_int_equal( 2 , enkf_fs_get_refcount( current ));
      test_assert_int_equal( 1 , enkf_fs_get_refcount( fs));
      enkf_main_set_fs( enkf_main , fs , NULL);
      test_assert_int_equal( 2 , enkf_fs_get_refcount( fs));
      test_assert_int_equal( 1 , enkf_fs_get_refcount( current ));

      enkf_fs_decref( current );
      enkf_fs_decref( fs);
    }

    
    

    test_assert_int_equal( 1 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
    enkf_main_free( enkf_main );
  }
  test_work_area_free( work_area );
  exit(0);
}