void test_config( const char * config_file ) {
  ert_test_context_type * test_context = ert_test_context_alloc( "RUNPATH_FILE" , config_file , NULL );
  enkf_main_type * enkf_main = ert_test_context_get_main( test_context );
  qc_module_type * qc_module = enkf_main_get_qc_module( enkf_main );

  ert_test_context_run_worklow( test_context , "ARGECHO_WF");
  {
    FILE * stream = util_fopen("runpath_list.txt" , "r");
    char runpath_file[256];
    fscanf(stream , "%s" , runpath_file );
    fclose( stream );
    test_assert_string_equal( runpath_file , qc_module_get_runpath_list_file( qc_module ));
  }
  
  ert_test_context_free( test_context );
}
Exemple #2
0
static void enkf_main_export_runpath_file(enkf_main_type * enkf_main,
                                          const int_vector_type * realizations,
                                          const int_vector_type * iterations) {

  ecl_config_type * ecl_config            = enkf_main_get_ecl_config(enkf_main);
  const model_config_type * model_config  = enkf_main_get_model_config(enkf_main);
  const char * basename_fmt               = ecl_config_get_eclbase(ecl_config);
  const char * runpath_fmt                = model_config_get_runpath_as_char(model_config);
  const qc_module_type * qc_module        = enkf_main_get_qc_module( enkf_main );

  runpath_list_type * runpath_list = runpath_list_alloc( qc_module_get_runpath_list_file( qc_module ));

  for (int iter = 0; iter < int_vector_size(iterations); ++iter) {
    for (int iens = 0; iens < int_vector_size(realizations); ++iens) {
      int iter_value = int_vector_iget(iterations, iter);
      int iens_value = int_vector_iget(realizations, iens);
      char * basename;
      char * runpath;

      if (basename_fmt)
        basename = util_alloc_sprintf(basename_fmt, iens_value);
      else
        basename = util_alloc_sprintf("--%d", iens_value);

      if (model_config_runpath_requires_iter(model_config))
        runpath = util_alloc_sprintf(runpath_fmt, iens_value, iter_value);
      else
        runpath = util_alloc_sprintf(runpath_fmt, iens_value);

      runpath_list_add(runpath_list, iens_value, iter_value, runpath, basename);

      free(basename);
      free(runpath);
    }
  }
  runpath_list_fprintf(runpath_list);
  runpath_list_free(runpath_list);
}
Exemple #3
0
void enkf_tui_run_manual_load__( void * arg ) {
  enkf_main_type * enkf_main = enkf_main_safe_cast( arg );
  const int ens_size         = enkf_main_get_ensemble_size( enkf_main );
  bool_vector_type * iactive = bool_vector_alloc( 0 , false );
  run_mode_type run_mode     = ENSEMBLE_EXPERIMENT;
  int iter = 0;
  
  enkf_main_init_run(enkf_main , iactive , run_mode , INIT_NONE);  /* This is ugly */

  {
    char * prompt = util_alloc_sprintf("Which realizations to load  (Ex: 1,3-5) <Enter for all> [M to return to menu] : [ensemble size:%d] : " , ens_size);
    char * select_string;
    util_printf_prompt(prompt , PROMPT_LEN , '=' , "=> ");
    select_string = util_alloc_stdin_line();

    enkf_tui_util_sscanf_active_list( iactive , select_string , ens_size );
    util_safe_free( select_string );
    
    free( prompt );
  }

  {
    const model_config_type * model_config = enkf_main_get_model_config( enkf_main );
    if (model_config_runpath_requires_iter( model_config )) {
      const char * prompt = "Which iteration to load from [0...?) : ";
      char * input;
      bool OK;
      util_printf_prompt(prompt , PROMPT_LEN , '=' , "=> ");

      input = util_alloc_stdin_line();
      if (input == NULL) 
        return;

      OK = util_sscanf_int( input , &iter ); 

      free( input );
      if (!OK)
        return;
    }
  }
  

  if (bool_vector_count_equal( iactive , true )) {
    stringlist_type ** realizations_msg_list = util_calloc( ens_size , sizeof * realizations_msg_list );
    int iens = 0;
    for (; iens < ens_size; ++iens) {
      realizations_msg_list[iens] = stringlist_alloc_new();
    }

    enkf_main_load_from_forward_model(enkf_main, iter , iactive, realizations_msg_list);

    {
      qc_module_type * qc_module = enkf_main_get_qc_module( enkf_main );
      runpath_list_type * runpath_list = qc_module_get_runpath_list( qc_module );

      for (iens = 0; iens < ens_size; ++iens) {
        if (bool_vector_iget(iactive , iens)) {
          const enkf_state_type * state = enkf_main_iget_state( enkf_main , iens );
          runpath_list_add( runpath_list , iens , enkf_state_get_run_path( state ) , enkf_state_get_eclbase( state ));
        }
      }
      qc_module_export_runpath_list( qc_module );
    }

    for (iens = 0; iens < ens_size; ++iens) {
      stringlist_type * msg_list = realizations_msg_list[iens];
      if (bool_vector_iget(iactive, iens)) {
        if (stringlist_get_size( msg_list )) {
          enkf_tui_display_load_msg( iens , msg_list );
        }
      }
      stringlist_free(msg_list);
    }
    free(realizations_msg_list);
  }

  bool_vector_free( iactive );
}
Exemple #4
0
void enkf_tui_run_manual_load__( void * arg ) {
  enkf_main_type * enkf_main                   = enkf_main_safe_cast( arg );
  enkf_fs_type * fs                            = enkf_main_get_fs( enkf_main ); 
  const int last_report                        = -1;
  const int ens_size                           = enkf_main_get_ensemble_size( enkf_main );
  int step1,step2;
  bool_vector_type * iactive = bool_vector_alloc( 0 , false );
  run_mode_type run_mode = ENSEMBLE_EXPERIMENT; 
  
  enkf_main_init_run(enkf_main , run_mode);     /* This is ugly */
  
  step1 = 0;
  step2 = last_report;  /** Observe that for the summary data it will load all the available data anyway. */
  {
    char * prompt = util_alloc_sprintf("Which realizations to load  (Ex: 1,3-5) <Enter for all> [M to return to menu] : [ensemble size:%d] : " , ens_size);
    char * select_string;
    util_printf_prompt(prompt , PROMPT_LEN , '=' , "=> ");
    select_string = util_alloc_stdin_line();

    enkf_tui_util_sscanf_active_list( iactive , select_string , ens_size );
    util_safe_free( select_string );
    
    free( prompt );
  }



  if (bool_vector_count_equal( iactive , true )) {
    int iens;
    arg_pack_type ** arg_list = util_calloc( ens_size , sizeof * arg_list );
    thread_pool_type * tp = thread_pool_alloc( 4 , true );  /* num_cpu - HARD coded. */

    for (iens = 0; iens < ens_size; iens++) {
      arg_pack_type * arg_pack = arg_pack_alloc();
      arg_list[iens] = arg_pack;
      
      if (bool_vector_iget(iactive , iens)) {
        enkf_state_type * enkf_state = enkf_main_iget_state( enkf_main , iens );

        arg_pack_append_ptr( arg_pack , enkf_state);                                        /* 0: */
        arg_pack_append_ptr( arg_pack , fs );                                               /* 1: */
        arg_pack_append_int( arg_pack , step1 );                                            /* 2: This will be the load start parameter for the run_info struct. */
        arg_pack_append_int( arg_pack , step1 );                                            /* 3: Step1 */ 
        arg_pack_append_int( arg_pack , step2 );                                            /* 4: Step2 For summary data it will load the whole goddamn thing anyway.*/
        arg_pack_append_bool( arg_pack , true );                                            /* 5: Interactive */                  
        arg_pack_append_owned_ptr( arg_pack , stringlist_alloc_new() , stringlist_free__);  /* 6: List of interactive mode messages. */
        thread_pool_add_job( tp , enkf_state_load_from_forward_model_mt , arg_pack);
        
      }
    }
    
    thread_pool_join( tp );
    thread_pool_free( tp );
    printf("\n");

    {
      qc_module_type * qc_module = enkf_main_get_qc_module( enkf_main );
      runpath_list_type * runpath_list = qc_module_get_runpath_list( qc_module );

      for (iens = 0; iens < ens_size; iens++) {
        if (bool_vector_iget(iactive , iens)) {
          const enkf_state_type * state = enkf_main_iget_state( enkf_main , iens );
          runpath_list_add( runpath_list , iens , enkf_state_get_run_path( state ) , enkf_state_get_eclbase( state ));
        }
      }

      qc_module_export_runpath_list( qc_module );
    }

    for (iens = 0; iens < ens_size; iens++) {
      if (bool_vector_iget(iactive , iens)) {
        stringlist_type * msg_list = arg_pack_iget_ptr( arg_list[iens] , 6 );
        if (stringlist_get_size( msg_list ))
          enkf_tui_display_load_msg( iens , msg_list );
      }
    }
    
    
    for (iens = 0; iens < ens_size; iens++) 
      arg_pack_free( arg_list[iens]);
    free( arg_list );      
  }
  bool_vector_free( iactive );
}
static void test_export_runpath_file(ert_test_context_type * test_context,
                                    const char * job_name,
                                    const char * job_file,
                                    stringlist_type * args,
                                    int_vector_type * iens_values,
                                    int_vector_type * iter_values) {

  ert_test_context_install_workflow_job( test_context , job_name , job_file );
  test_assert_true( ert_test_context_run_worklow_job( test_context , job_name , args) );

  {
    const enkf_main_type * enkf_main = ert_test_context_get_main(test_context);
    qc_module_type * qc_module       = enkf_main_get_qc_module( enkf_main );
    const char * runpath_file_name   = qc_module_get_runpath_list_file(qc_module);

    ecl_config_type * ecl_config            = enkf_main_get_ecl_config(enkf_main);
    const model_config_type * model_config  = enkf_main_get_model_config(enkf_main);
    const char * base_fmt                   = ecl_config_get_eclbase(ecl_config);
    const char * runpath_fmt                = model_config_get_runpath_as_char(model_config);

    test_assert_true(util_file_exists(runpath_file_name));
    FILE * file = util_fopen(runpath_file_name, "r");

    int file_iens = 0;
    char file_path[256];
    char file_base[256];
    int file_iter = 0;
    char * cwd = util_alloc_cwd();
    int counter = 0;
    int iens_index = 0;
    int iter_index = 0;

    while (4 == fscanf( file , "%d %s %s %d" , &file_iens , file_path , file_base, &file_iter)) {
      ++ counter;

      test_assert_true(int_vector_size(iens_values) >= iens_index+1);
      test_assert_true(int_vector_size(iter_values) >= iter_index+1);

      int iens = int_vector_iget(iens_values, iens_index);
      int iter = int_vector_iget(iter_values, iter_index);

      test_assert_int_equal(file_iens, iens);
      test_assert_int_equal(file_iter, iter);

      char * base = util_alloc_sprintf("--%d", iens);
      if (base_fmt && (util_int_format_count(base_fmt) == 1))
        base = util_alloc_sprintf(base_fmt, iens);

      test_assert_string_equal(base, file_base);

      char * runpath = "";
      if (util_int_format_count(runpath_fmt) == 1)
        runpath = util_alloc_sprintf(runpath_fmt, iens);
      else if (util_int_format_count(runpath_fmt) == 2)
        runpath = util_alloc_sprintf(runpath_fmt, iens,iter);

      test_assert_string_equal(runpath, file_path);

      if (iens_index+1 < int_vector_size(iens_values))
        ++iens_index;
      else if ((iens_index+1 == int_vector_size(iens_values))) {
        ++iter_index;
        iens_index = 0;
      }

      free(base);
      free(runpath);
    }

    int linecount = int_vector_size(iens_values) * int_vector_size(iter_values);
    test_assert_int_equal(linecount, counter);
    free(cwd);
    fclose(file);
  }
}