Ejemplo n.º 1
0
void enkf_tui_analysis_update_module__(void * arg) {
  enkf_main_type * enkf_main = enkf_main_safe_cast( arg );
  int prompt_len = 50;
  {
    const analysis_config_type * analysis_config = enkf_main_get_analysis_config( enkf_main );
    analysis_module_type * analysis_module = analysis_config_get_active_module( analysis_config );
    char var_name[256];
    char value[256];
    
    util_printf_prompt("Variable to modify" , prompt_len , '=' , "=> "); 
    scanf("%s", var_name);
    {
      char * value_prompt = util_alloc_sprintf("New value for %s" , var_name);
      util_printf_prompt(value_prompt , prompt_len , '=' , "=> "); 
      free( value_prompt );
    }
    scanf("%s", value);

    if (analysis_module_set_var( analysis_module , var_name , value))
      printf("\'%s\' successfully set to \'%s\' \n",var_name , value);
    else
      printf("** Variable/type combination: %s/%s not recognized \n", var_name , value);
    
  }
}
Ejemplo n.º 2
0
void enkf_tui_util_scanf_report_steps(int last_report , int prompt_len , int * __step1 , int * __step2) {
  char * prompt = util_alloc_sprintf("Report steps (0 - %d)" , last_report);
  bool OK = false;

  util_printf_prompt(prompt , prompt_len , '=' , "=> ");
  
  while (!OK) {
    char * input = util_alloc_stdin_line();
    const char * current_ptr = input;
    int step1 , step2;
    OK = true;
    if(input == NULL){
      step1=0;
      step2=last_report;
    }
    else{
      current_ptr = util_parse_int(current_ptr , &step1 , &OK);
      current_ptr = util_skip_sep(current_ptr , " ,-:" , &OK);
      current_ptr = util_parse_int(current_ptr , &step2 , &OK);
    }
    if (!OK) 
      printf("Failed to parse two integers from: \"%s\". Example: \"0 - 19\" to get the 20 first report steps.\n",input);
    free(input);

    step1 = util_int_min(step1 , last_report);
    step2 = util_int_min(step2 , last_report);
    if (step1 > step2) 
      util_exit("%s: ohh come on - must have a finite interval forward in time - no plots for you.\n",__func__);
    *__step1 = step1;
    *__step2 = step2;
    
  }
  free(prompt);
}
Ejemplo n.º 3
0
void enkf_tui_util_scanf_iens_range(const char * prompt_fmt , int ens_size , int prompt_len , int * iens1 , int * iens2) {
  char * prompt = util_alloc_sprintf(prompt_fmt , ens_size - 1);
  bool OK = false;

  util_printf_prompt(prompt , prompt_len , '=' , "=> ");
  
  while (!OK) {
    char * input = util_alloc_stdin_line();
    const char * current_ptr = input;
    OK = true;

    if (input != NULL) {
      current_ptr = util_parse_int(current_ptr , iens1 , &OK);
      current_ptr = util_skip_sep(current_ptr , " ,-:" , &OK);
      current_ptr = util_parse_int(current_ptr , iens2 , &OK);
      
      if (!OK) 
        printf("Failed to parse two integers from: \"%s\". Example: \"0 - 19\" to get the 20 first members.\n",input);
      free(input);
    } else {
      *iens1 = 0;
      *iens2 = ens_size - 1;
    }
  }
  free(prompt);
}
Ejemplo n.º 4
0
const enkf_config_node_type * enkf_tui_util_scanf_key(const ensemble_config_type * config , int prompt_len , ert_impl_type impl_type ,  enkf_var_type var_type) {
  char * kw;
  bool OK;
  const enkf_config_node_type * config_node = NULL;
  do {
    OK = true;
    util_printf_prompt("Keyword" , prompt_len , '=' , "=> ");
    kw = util_alloc_stdin_line();
    if(kw==NULL){
      OK = true;
  }
    else if (ensemble_config_has_key(config , kw)) {
      config_node = ensemble_config_get_node(config , kw);
      
      if (impl_type != INVALID) 
        if (enkf_config_node_get_impl_type(config_node) != impl_type) 
          OK = false;
      
      if (var_type != INVALID_VAR)
        if (enkf_config_node_get_var_type(config_node) != var_type) 
          OK = false;
    } else OK = false;
    free(kw);
  } while (!OK);
  return config_node;
}
Ejemplo n.º 5
0
/**
   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;
}
Ejemplo n.º 6
0
void enkf_tui_run_exp(void * enkf_main) {
  const int ens_size          = enkf_main_get_ensemble_size( enkf_main );
  bool_vector_type * iactive  = bool_vector_alloc(0,false);

  state_enum init_state    = ANALYZED; 
  int start_report         = 0;
  int init_step_parameters = 0;
  
  {

    char * prompt = util_alloc_sprintf("Which realizations to simulate (Ex: 1,3-5) <Enter for all> [M to return to menu] : " , 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))
    enkf_main_run_exp(enkf_main , iactive , true , init_step_parameters , start_report , init_state, true);
  
  bool_vector_free(iactive);
}
Ejemplo n.º 7
0
void enkf_tui_fs_initialize_case_for_predictions(void * arg)
{
  int prompt_len = 35;
  char source_case[256];
  int report_step_from;
  int report_step_to;
  state_enum state_from;
  state_enum state_to;

  enkf_main_type * enkf_main = enkf_main_safe_cast( arg );
  
  state_from       = ANALYZED;
  state_to         = ANALYZED;
  report_step_from = enkf_main_get_history_length( enkf_main ); 
  report_step_to   = enkf_main_get_history_length( enkf_main );


  {
    char * target_case = util_alloc_string_copy( NULL );
    
    util_printf_prompt("Source case" , prompt_len , '=' , "=> ");
    fgets(source_case, prompt_len, stdin);
    char *newline = strchr(source_case,'\n');
    if(newline)
      *newline = 0;
    
    if(strlen(source_case) !=0)
      enkf_tui_fs_copy_ensemble__(enkf_main, source_case, target_case, report_step_from, state_from, report_step_to, state_to, false);

    free(target_case);
  }
}
Ejemplo n.º 8
0
void field_config_scanf_ijk(const field_config_type * config , bool active_only , const char * _prompt , int prompt_len , int *_i , int *_j , int *_k , int * _global_index) {
    const char * sep_set = " ,.:";
    char * prompt = util_alloc_sprintf("%s (%d,%d,%d)" , _prompt , config->nx , config->ny , config->nz);
    bool OK;
    int i,j,k,global_index;
    global_index = -1; /* Keep the compiler happy. */

    do {
        char         *input;
        const  char  *current_ptr;
        util_printf_prompt(prompt , prompt_len , '=' , "=> ");
        input = util_alloc_stdin_line();


        i = -1;
        j = -1;
        k = -1;

        OK = true;
        current_ptr = input;
        current_ptr = util_parse_int(current_ptr , &i , &OK);
        current_ptr = util_skip_sep(current_ptr , sep_set , &OK);
        current_ptr = util_parse_int(current_ptr , &j , &OK);
        current_ptr = util_skip_sep(current_ptr , sep_set , &OK);
        current_ptr = util_parse_int(current_ptr , &k , &OK);
        if (OK)
            if (current_ptr[0] != '\0') OK = false; /* There was something more at the end */

        /* Now we have three valid integers. */

        if (OK) {
            if (i <= 0 || i > config->nx) OK = false;
            if (j <= 0 || j > config->ny) OK = false;
            if (k <= 0 || k > config->nz) OK = false;
            i--;
            j--;
            k--;
        }
        /* Now we have three integers in the right interval. */


        if (OK) {
            global_index = field_config_active_index(config , i,j,k);
            if (active_only) {
                if (global_index < 0) {
                    OK = false;
                    printf("Sorry the point: (%d,%d,%d) corresponds to an inactive cell\n" , i + 1 , j+ 1 , k + 1);
                }
            }
        }
        free(input);
    } while (!OK);

    if (_i != NULL) *_i = i;
    if (_j != NULL) *_j = j;
    if (_k != NULL) *_k = k;
    if (_global_index != NULL) *_global_index = global_index;

    free(prompt);
}
Ejemplo n.º 9
0
static void enkf_tui_ranking_create_obs( void * arg ) {
  enkf_main_type    * enkf_main       = enkf_main_safe_cast( arg );  
  enkf_obs_type     * enkf_obs        = enkf_main_get_obs( enkf_main );
  enkf_fs_type      * fs              = enkf_main_get_fs( enkf_main );
  misfit_ensemble_type * misfit_ensemble    = enkf_fs_get_misfit_ensemble( fs );
  
  if (!misfit_ensemble_initialized( misfit_ensemble )) {
    fprintf(stderr,"Sorry: must initialzie the misfit table first \n");
    return;
  } else {
    ranking_table_type * ranking_table = enkf_main_get_ranking_table( enkf_main );
    const int history_length    = enkf_main_get_history_length( enkf_main );
    const int    prompt_len = 50;
    const char * prompt1      = "Observations to use for ranking";
    const char * prompt2      = "Name to store ranking under";
    const char * store_prompt = "Name of file to store ranking";
    int step1,step2;
    stringlist_type * ranking_keys;
    char * obs_keys_input;
    char * ranking_key;
    char * ranking_file;
    util_printf_prompt(prompt1 , prompt_len , '=' , "=> ");
    obs_keys_input = util_alloc_stdin_line();
    ranking_keys   = enkf_obs_alloc_matching_keylist( enkf_obs , obs_keys_input );
    enkf_tui_util_scanf_report_steps(history_length , prompt_len , &step1 , &step2);

    util_printf_prompt(prompt2 , prompt_len , '=' , "=> ");
    ranking_key = util_alloc_stdin_line();
    if (ranking_key == NULL) 
      ranking_key = util_alloc_string_copy( MISFIT_DEFAULT_RANKING_KEY );
    
    util_printf_prompt(store_prompt , prompt_len , '=' , "=> ");
    ranking_file = util_alloc_stdin_line();
        
    if (stringlist_get_size( ranking_keys ) > 0) {
      ranking_table_add_misfit_ranking( ranking_table , misfit_ensemble , ranking_keys , step1 , step2 , ranking_key );
      ranking_table_display_ranking( ranking_table , ranking_key);
    } else
      fprintf(stderr,"The input string : \"%s\" did not resolve to any valid observation keys \n", obs_keys_input);
    
    free( obs_keys_input );
    stringlist_free( ranking_keys );
    free( ranking_key );
    util_safe_free( ranking_file );
  }
}
Ejemplo n.º 10
0
static void enkf_tui_ranking_create_data__( void * arg , bool sort_increasing) {
  enkf_main_type     * enkf_main         = enkf_main_safe_cast( arg );  
  ranking_table_type * ranking_table     = enkf_main_get_ranking_table( enkf_main );
  enkf_fs_type * fs                      = enkf_main_get_fs( enkf_main );
  ensemble_config_type * ensemble_config = enkf_main_get_ensemble_config( enkf_main );
  //const int history_length               = enkf_main_get_history_length( enkf_main );
  const int    prompt_len   = 60;
  const char * prompt1      = "Data key to use for ranking";
  const char * prompt2      = "Report step of data";
  const char * ranking_name = "Name of new ranking";
  const char * store_prompt = "Name of file to store ranking [Blank - no store]";

  int step;
  state_enum state = FORECAST;
  char * user_key;
  
  util_printf_prompt(prompt1 , prompt_len , '=' , "=> ");
  user_key = util_alloc_stdin_line();
  if (user_key != NULL) {
    util_printf_prompt( prompt2 , prompt_len , '=' , "=> ");
    {
      char * step_char = util_alloc_stdin_line();
      if (step_char == NULL)
        step = 0;
      else {
        if (util_sscanf_int( step_char , &step )) {
          const enkf_config_node_type * config_node;
          char * key_index;
          config_node = ensemble_config_user_get_node( ensemble_config , user_key , &key_index);
          if (config_node) {
            util_printf_prompt(ranking_name , prompt_len , '=' , "=> ");
            char * ranking_key = util_alloc_stdin_line();
            if (ranking_key != NULL) {
              ranking_table_add_data_ranking( ranking_table , sort_increasing , ranking_key , user_key , key_index , fs , config_node, step , state );
              ranking_table_display_ranking( ranking_table , ranking_key );
            }
            util_safe_free( ranking_key );
          }
        }
      }
      util_safe_free( step_char );
    }
  }
  util_safe_free( user_key );
}
Ejemplo n.º 11
0
void enkf_tui_export_fieldP(void * arg) {
  enkf_main_type * enkf_main                   = enkf_main_safe_cast( arg );
  const ensemble_config_type * ensemble_config = enkf_main_get_ensemble_config(enkf_main);
  const enkf_config_node_type * config_node    = enkf_tui_util_scanf_key(ensemble_config , PROMPT_LEN ,  FIELD  , INVALID_VAR );
  int iens1                                    = 0;
  int iens2                                    = enkf_main_get_ensemble_size( enkf_main );
  const int last_report                        = enkf_main_get_history_length( enkf_main );
  int report_step                              = util_scanf_int_with_limits("Report step: ", PROMPT_LEN , 0 , last_report);
  double lower_limit                           = util_scanf_double("Lower limit", PROMPT_LEN);
  double upper_limit                           = util_scanf_double("Upper limit", PROMPT_LEN);
  char * export_file;
  util_printf_prompt("Filename to store file: " , PROMPT_LEN , '=' , "=> ");
  export_file = util_alloc_stdin_line();
  {
    enkf_fs_type   * fs        = enkf_main_tui_get_fs(enkf_main);
    enkf_node_type ** ensemble = enkf_node_load_alloc_ensemble( config_node , fs , report_step , iens1 , iens2 );
    enkf_node_type *  sum      = enkf_node_alloc( config_node );
    int active_ens_size        = 0;
    int iens;

    enkf_node_clear( sum );
    {
      /* OK going low level */
      field_type * sum_field = (field_type *) enkf_node_value_ptr( sum );

      for (iens = iens1; iens < iens2; iens++) {
        if (ensemble[iens - iens1] != NULL) {
          field_type * field     = (field_type *) enkf_node_value_ptr( ensemble[iens - iens1] );
          field_update_sum( sum_field , field , lower_limit , upper_limit);
          active_ens_size++;
        }
      }
      if (active_ens_size > 0) {
        field_scale( sum_field , 1.0 / active_ens_size );
        {
          char * path;
          util_alloc_file_components( export_file , &path , NULL , NULL);
          if (path != NULL) {
            util_make_path( path );
            free( path );
          }
        }
        field_export(sum_field , export_file , NULL , RMS_ROFF_FILE , false, NULL);
      } else fprintf(stderr,"Warning: no data found \n");
    }

    for (iens = iens1; iens < iens2; iens++) {
      if (ensemble[iens - iens1] != NULL)
        enkf_node_free( ensemble[iens - iens1] );
    }

    free( ensemble );
    enkf_node_free( sum );
  }
  free( export_file );
}
Ejemplo n.º 12
0
void enkf_tui_analysis_select_module__(void * arg) {
  int prompt_len = 50;
  arg_pack_type * arg_pack = arg_pack_safe_cast( arg );
  enkf_main_type * enkf_main = arg_pack_iget_ptr( arg_pack , 0 );
  menu_type * menu = arg_pack_iget_ptr( arg_pack , 1 );

  const analysis_config_type * analysis_config = enkf_main_get_analysis_config(enkf_main);
  char module_name[256];
  util_printf_prompt("Name module to select" , prompt_len , '=' , "=> ");
  scanf("%s", module_name);
  if (analysis_config_select_module( analysis_config , module_name ))
    enkf_tui_analysis_update_title( enkf_main , menu );
}
Ejemplo n.º 13
0
void enkf_tui_export_gen_data(void * arg) {
  enkf_main_type * enkf_main = enkf_main_safe_cast( arg );
  const ensemble_config_type * ensemble_config = enkf_main_get_ensemble_config(enkf_main);
  {
    int report_step;
    int iens1 , iens2;
    const int last_report = enkf_main_get_history_length( enkf_main );

    const enkf_config_node_type * config_node;
    path_fmt_type * file_fmt;

    config_node    = enkf_tui_util_scanf_key(ensemble_config , PROMPT_LEN ,  GEN_DATA , INVALID_VAR);


    report_step = util_scanf_int_with_limits("Report step: ", PROMPT_LEN , 0 , last_report);
    enkf_tui_util_scanf_iens_range("Realizations members to export(0 - %d)" , enkf_main_get_ensemble_size( enkf_main ) , PROMPT_LEN , &iens1 , &iens2);
    {
      char path_fmt[512];
      util_printf_prompt("Filename to store files in (with %d) in: " , PROMPT_LEN , '=' , "=> ");
      scanf("%s" , path_fmt);
      file_fmt = path_fmt_alloc_path_fmt( path_fmt );
    }

    {
      enkf_fs_type   * fs   = enkf_main_tui_get_fs(enkf_main);
      enkf_node_type * node = enkf_node_alloc(config_node);
      gen_data_file_format_type export_type = gen_data_guess_export_type( (const gen_data_type *) enkf_node_value_ptr(node) );
      int iens;

      for (iens = iens1; iens <= iens2; iens++) {
        node_id_type node_id = {.report_step = report_step , .iens = iens};
        if (enkf_node_try_load(node , fs, node_id)) {
          char * full_path = path_fmt_alloc_path( file_fmt , false , iens);
          char * path;
          util_alloc_file_components(full_path , &path , NULL , NULL);
          if (path != NULL) util_make_path( path );

          {
            const gen_data_type * gen_data = (const gen_data_type *) enkf_node_value_ptr(node);
            gen_data_export(gen_data , full_path , export_type);
          }

          free(full_path);
          free(path);
        }
      }
      enkf_node_free(node);
    }
  }
}
Ejemplo n.º 14
0
void enkf_tui_export_field(const enkf_main_type * enkf_main , field_file_format_type file_type) {
  const ensemble_config_type * ensemble_config = enkf_main_get_ensemble_config(enkf_main);
  const bool output_transform = true;
  const enkf_config_node_type * config_node;
  const int last_report = enkf_main_get_history_length( enkf_main );
  int        iens1 , iens2 , iens , report_step;
  path_fmt_type * export_path;

  config_node    = enkf_tui_util_scanf_key(ensemble_config , PROMPT_LEN ,  FIELD  , INVALID_VAR );

  report_step = util_scanf_int_with_limits("Report step: ", PROMPT_LEN , 0 , last_report);
  enkf_tui_util_scanf_iens_range("Realizations members to export(0 - %d)" , enkf_main_get_ensemble_size( enkf_main ) , PROMPT_LEN , &iens1 , &iens2);

  {
    char * path_fmt;
    util_printf_prompt("Filename to store files in (with %d) in: " , PROMPT_LEN , '=' , "=> ");
    path_fmt = util_alloc_stdin_line();
    export_path = path_fmt_alloc_path_fmt( path_fmt );
    free( path_fmt );
  }

  {
    enkf_fs_type   * fs   = enkf_main_tui_get_fs(enkf_main);
    enkf_node_type * node = enkf_node_alloc(config_node);

    for (iens = iens1; iens <= iens2; iens++) {
      node_id_type node_id = {.report_step = report_step , .iens = iens };
      if (enkf_node_try_load(node , fs , node_id)) {
        char * filename = path_fmt_alloc_path( export_path , false , iens);
        {
          char * path;
          util_alloc_file_components(filename , &path , NULL , NULL);
          if (path != NULL) {
            util_make_path( path );
            free( path );
          }
        }

        {
          const field_type * field = (const field_type *) enkf_node_value_ptr(node);
          field_export(field , filename , NULL , file_type , output_transform, NULL);
        }
        free(filename);
      } else
        printf("Warning: could not load realization:%d \n", iens);
    }
    enkf_node_free(node);
  }
}
Ejemplo n.º 15
0
void enkf_tui_fs_copy_ensemble_of_parameters(void * arg)
{
  int prompt_len = 35;
  char * source_case;
  
  int last_report;
  int report_step_from;
  char * report_step_from_as_char;
  int report_step_to;
  state_enum state_from;
  state_enum state_to;
  
  enkf_main_type * enkf_main = enkf_main_safe_cast( arg );
  
  source_case = util_alloc_string_copy(enkf_main_get_current_fs( enkf_main ));
  last_report  = enkf_main_get_history_length( enkf_main );
  
  report_step_from_as_char = util_scanf_int_with_limits_return_char("Source report step",prompt_len , 0 , last_report);
  if(strlen(report_step_from_as_char) !=0){
    util_sscanf_int(report_step_from_as_char , &report_step_from);
    state_from = enkf_tui_util_scanf_state("Source analyzed/forecast [a|f]" , prompt_len , false);
    if(state_from != UNDEFINED){

      util_printf_prompt("Target case" , prompt_len , '=' , "=> ");
      char target_case[256];

      if ( fgets(target_case, prompt_len, stdin) ) {
        char *newline = strchr(target_case, '\n');
        if (newline)
          *newline = 0;
      }

      if (strlen(target_case)) {
        char * report_step_to_as_char = util_scanf_int_with_limits_return_char("Target report step",prompt_len , 0 , last_report);
        if(strlen(report_step_to_as_char) !=0){
          util_sscanf_int(report_step_to_as_char , &report_step_to);
          state_to       = enkf_tui_util_scanf_state("Target analyzed/forecast [a|f]" , prompt_len , false);
          if(state_to != UNDEFINED){
            enkf_tui_fs_copy_ensemble__(enkf_main, source_case, target_case, report_step_from, state_from, report_step_to, state_to, true);
          }
        }
        free(report_step_to_as_char);
      }
    }
  }
  free(source_case);
  free(report_step_from_as_char);
}
Ejemplo n.º 16
0
static void enkf_tui_ranking_display( void * arg ) {
  enkf_main_type    * enkf_main       = enkf_main_safe_cast( arg );  
  ranking_table_type * ranking_table  = enkf_main_get_ranking_table( enkf_main );

  const int prompt_len  = 50;
  const char * prompt1  = "Ranking to display";
  char * ranking_key;
  
  util_printf_prompt(prompt1 , prompt_len , '=' , "=> ");
  ranking_key    = util_alloc_stdin_line();
  if (ranking_key == NULL) 
    ranking_key = util_alloc_string_copy( MISFIT_DEFAULT_RANKING_KEY);
  if (ranking_table_has_ranking( ranking_table , ranking_key))
    ranking_table_display_ranking( ranking_table , ranking_key);
  else
    fprintf(stderr,"Sorry: could not find ranking key: %s \n", ranking_key );
  
  free( ranking_key );
}
Ejemplo n.º 17
0
void enkf_tui_workflow_run( void * arg ) {
  enkf_main_type * enkf_main = enkf_main_safe_cast( arg );
  {
    ert_workflow_list_type * workflow_list = enkf_main_get_workflow_list( enkf_main );
    util_printf_prompt("Name of workflow" , PROMPT_LEN , '=' , "=> ");
    {
      char * workflow_name = util_alloc_stdin_line();
      if (workflow_name != NULL) {
        if (ert_workflow_list_has_workflow( workflow_list , workflow_name )) {
          bool runOK = ert_workflow_list_run_workflow_blocking( workflow_list , workflow_name , enkf_main);
          if (!runOK) {
            printf("Errors in workflow:%s \n", workflow_name );
            printf("-----------------------------------------------------------------\n");
            config_error_fprintf( ert_workflow_list_get_last_error( workflow_list ) , true , stdout);
            printf("-----------------------------------------------------------------\n");
          }
        }
      }
      util_safe_free( workflow_name );
    }
  }
}
Ejemplo n.º 18
0
void enkf_tui_run_create_runpath__(void * __enkf_main) {
  enkf_main_type * enkf_main = enkf_main_safe_cast(__enkf_main);
  const int ens_size         = enkf_main_get_ensemble_size( enkf_main );
  bool_vector_type * iactive = bool_vector_alloc(0,false);

  state_enum init_state    = ANALYZED; 
  int start_report         = 0;
  int init_step_parameters = 0;
  {
    char * prompt = util_alloc_sprintf("Which realizations to create[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 );
  }
  enkf_main_run_exp(enkf_main , iactive , false , init_step_parameters , start_report , init_state, true);
  bool_vector_free(iactive);
}
Ejemplo n.º 19
0
state_enum enkf_tui_util_scanf_state(const char * prompt, int prompt_len, bool accept_both) {
  char analyzed_string[64];
  bool OK;
  state_enum state;
  do {
    OK = true;
    util_printf_prompt(prompt , prompt_len , '=' , "=> ");
    //scanf("%s" , analyzed_string);
    fgets(analyzed_string, prompt_len, stdin);
    char *newline = strchr(analyzed_string,'\n');
    if(newline)
      *newline = 0;
    //getchar(); /* Discards trailing <RETURN> from standard input buffer? */
    if (strlen(analyzed_string) == 0){
      OK = true;
      state = UNDEFINED;
    }
    else if (strlen(analyzed_string) == 1) {
      char c = toupper(analyzed_string[0]);
      if (c == 'A')
        state = ANALYZED;
      else if (c == 'F')
        state = FORECAST;
      else {
        if (accept_both) {
          if (c == 'B') 
            state = BOTH;
          else
            OK = false;
        } else
          OK = false;
      }
    } else
      OK = false;
  } while ( !OK );
  return state;
}
Ejemplo n.º 20
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);
}
Ejemplo n.º 21
0
void enkf_tui_export_scalar2csv(void * arg) {
  enkf_main_type * enkf_main = enkf_main_safe_cast( arg );
  const ensemble_config_type * ensemble_config = enkf_main_get_ensemble_config(enkf_main);
  const enkf_config_node_type * config_node;
  char * user_key, *key_index;

  util_printf_prompt("Scalar to export (KEY:INDEX)" , PROMPT_LEN , '=' , "=> "); user_key = util_alloc_stdin_line();
  config_node = ensemble_config_user_get_node( ensemble_config , user_key , &key_index);
  if (config_node != NULL) {
    int    report_step , first_report, last_report;
    int    iens1 , iens2, iens;
    char * csv_file;

    iens2        = enkf_main_get_ensemble_size( enkf_main ) - 1;
    iens1        = 0;
    first_report = 0;
    last_report  = enkf_main_get_history_length( enkf_main );
    {
      char * path;
      char * prompt = util_alloc_sprintf("File to store \'%s\'", user_key);
      util_printf_prompt(prompt , PROMPT_LEN , '=' , "=> ");
      csv_file = util_alloc_stdin_line();

      util_alloc_file_components( csv_file , &path , NULL , NULL);
      if (path != NULL) {
        if (util_entry_exists( path )) {
          if (!util_is_directory( path )) {
            /* The path component already exists in the filesystem - and it is not a directory - we leave the building. */
            fprintf(stderr,"Sorry: %s already exists - and is not a directory.\n",path);
            free(path);
            free(csv_file);
            free(user_key);
            return ;
          }
        } else {
          /* The path does not exist - we make it. */
          enkf_tui_util_msg("Creating new directory: %s\n" , path);
          util_make_path( path );
        }
      }
      free(prompt);
    }
    {
      /* Seriously manual creation of csv file. */
      enkf_fs_type * fs     = enkf_main_tui_get_fs(enkf_main);
      enkf_node_type * node = enkf_node_alloc( config_node );
      FILE * stream         = util_fopen( csv_file , "w");
      node_id_type node_id;


      /* Header line */
      fprintf(stream , "\"Report step\"");
      for (iens = iens1; iens <= iens2; iens++)
        fprintf(stream , "%s\"%s(%d)\"" , CSV_SEP , user_key , iens);
      fprintf(stream , CSV_NEWLINE);

      for (report_step = first_report; report_step <= last_report; report_step++) {
        fprintf(stream , "%6d" , report_step);
        node_id.report_step = report_step;
        for (iens = iens1; iens <= iens2; iens++) {
          double value;
          char label[32];
          /*
             Have not implemented a choice on forecast/analyzed. Tries
             analyzed first, then forecast.
          */
          node_id.iens = iens;
          sprintf(label , "%03d/%03d" , report_step , iens);

          if (enkf_node_user_get( node , fs , key_index , node_id ,  &value))
            fprintf(stream , "%s%g" , CSV_SEP , value);
          else
            fprintf(stream , "%s%s" , CSV_SEP , CSV_MISSING_VALUE);

        }
        fprintf(stream , CSV_NEWLINE);
      }

      enkf_node_free( node );
      fclose(stream);
    }
  } else
    fprintf(stderr,"Sorry - could not find any nodes with key:%s\n",user_key);

  free(user_key);
}
Ejemplo n.º 22
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 );
}
Ejemplo n.º 23
0
static void enkf_tui_fs_copy_ensemble__(
  enkf_main_type * enkf_main,
  const char     * source_case,
  const char     * target_case,
  int              report_step_from,
  state_enum       state_from,
  int              report_step_to,
  state_enum       state_to,
  bool             only_parameters)
{
  msg_type       * msg          = msg_alloc("Copying: " , false);
  ensemble_config_type * config = enkf_main_get_ensemble_config(enkf_main);
  int ens_size                  = enkf_main_get_ensemble_size(enkf_main);
  char * ranking_key;
  const int  * ranking_permutation = NULL;
  int  * identity_permutation;
  ranking_table_type * ranking_table = enkf_main_get_ranking_table( enkf_main );
  

  if (ranking_table_get_size( ranking_table ) > 0) {
    util_printf_prompt("Name of ranking to resort by (or blank)" , 50  , '=' , "=> ");
    ranking_key = util_alloc_stdin_line();
    if (ranking_table_has_ranking( ranking_table , ranking_key )) 
      ranking_permutation = ranking_table_get_permutation( ranking_table , ranking_key );
    else {
      fprintf(stderr," Sorry: ranking:%s does not exist \n", ranking_key );
      return;
    }
  }
  identity_permutation = util_calloc( ens_size , sizeof * identity_permutation );
  {
    int iens;
    for (iens =0; iens < ens_size; iens++) 
      identity_permutation[iens] = iens;
  }

  if (ranking_permutation == NULL)
    ranking_permutation = identity_permutation;
  

  {
    /* If the current target_case does not exist it is automatically created by the select_write_dir function */
    enkf_fs_type * src_fs    = enkf_main_mount_alt_fs( enkf_main , source_case , false );
    enkf_fs_type * target_fs = enkf_main_mount_alt_fs( enkf_main , target_case , true );
    
    stringlist_type * nodes = ensemble_config_alloc_keylist_from_var_type(config, PARAMETER);
    
    {
      int num_nodes = stringlist_get_size(nodes);
      msg_show(msg);
      for(int i = 0; i < num_nodes; i++) {
        const char * key = stringlist_iget(nodes, i);
        enkf_config_node_type * config_node = ensemble_config_get_node(config , key);
        msg_update(msg , key);
        enkf_node_copy_ensemble(config_node, src_fs , target_fs , report_step_from, state_from, report_step_to , state_to , ens_size , ranking_permutation);
      }
    }
    
    enkf_fs_decref( src_fs );
    enkf_fs_decref( target_fs );
    
    msg_free(msg , true);
    stringlist_free(nodes);
  }
  free( identity_permutation );
}
Ejemplo n.º 24
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 );
}