Exemple #1
0
void enkf_tui_init(enkf_main_type * enkf_main, bool all_members , bool all_parameters , bool interval ) {
  const int prompt_len                         = 35;
  const ensemble_config_type * ensemble_config = enkf_main_get_ensemble_config(enkf_main);
  int   ens_size                               = enkf_main_get_ensemble_size( enkf_main );
  int iens1, iens2;
  init_mode_enum init_mode = INIT_FORCE;
  bool iens_valid = false;
  
  /* iens2 should be interpreted as __inclusive__ */
  if ( all_members ) {
    iens1 = 0;
    iens2 = ens_size - 1;
    iens_valid = true;
  } else {
    if( interval ) {
      char * iens1char = util_scanf_int_with_limits_return_char("First ensemble member in interval"  , prompt_len , 0 , ens_size - 1);
      if (strlen(iens1char)) {
        util_sscanf_int(iens1char , &iens1);
        char * iens2char = util_scanf_int_with_limits_return_char("Second ensemble member in interval" , prompt_len , iens1 , ens_size - 1);
        if (strlen(iens2char)) {
          util_sscanf_int(iens2char , &iens2);
          iens_valid = true;
        }
        free(iens2char);
      }
      free(iens1char);
    } else {
      char * iens1char = util_scanf_int_with_limits_return_char("Initialize ensemble member" , prompt_len , 0 , ens_size - 1);
      if (strlen(iens1char)) {
        util_sscanf_int(iens1char , &iens1);
        iens2 = iens1;
        iens_valid = true;
      }
      free(iens1char);
    }
  }
  
  if (iens_valid) {
    stringlist_type * param_list = NULL;
    if (all_parameters) 
      param_list = ensemble_config_alloc_keylist_from_var_type( ensemble_config , PARAMETER );
    else {
      const enkf_config_node_type * config_node = NULL;
      param_list = stringlist_alloc_new();
      config_node = enkf_tui_util_scanf_key(ensemble_config , prompt_len , INVALID , INVALID_VAR);
      if( config_node != NULL )
        stringlist_append_copy( param_list , enkf_config_node_get_key(config_node));
    }

    if (param_list != NULL) {
      enkf_main_initialize_from_scratch(enkf_main , param_list , iens1 , iens2 , init_mode);
      stringlist_free( param_list );
    }
  }
}
Exemple #2
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);
}
Exemple #3
0
void enkf_tui_run_restart__(void * enkf_main) {
  const int ens_size    = enkf_main_get_ensemble_size( enkf_main );
  const int last_report = enkf_main_get_history_length( enkf_main );
  int start_report;
  char * start_report_as_char;
  bool wronginput = false;
  state_enum state;
  bool_vector_type * iactive = bool_vector_alloc(0,true);
  bool_vector_iset( iactive , ens_size - 1 , true );
  
  start_report_as_char = util_scanf_int_with_limits_return_char("Report step",PROMPT_LEN , 0 , last_report);
  if(strlen(start_report_as_char) != 0){
    util_sscanf_int(start_report_as_char , &start_report);
  }
  else
    wronginput = true;
  
  if(!wronginput){
    state        = enkf_tui_util_scanf_state("Analyzed/forecast" , PROMPT_LEN , false);
    if(state == UNDEFINED)
      wronginput = true;
  }
  
  if(!wronginput)
    enkf_main_run_assimilation(enkf_main ,  iactive , start_report , start_report  , state);
  
  bool_vector_free(iactive);
  free(start_report_as_char);
}
Exemple #4
0
static int ecl_util_get_num_parallel_cpu__(parser_type* parser, FILE* stream, const char * data_file) {
  int num_cpu = 1;
  char * buffer;  
  long int start_pos = util_ftell( stream );
  int buffer_size;

  /* Look for terminating '/' */
  if (!parser_fseek_string( parser , stream , "/" , false , true))
    util_abort("%s: sorry - could not find \"/\" termination of PARALLEL keyword in data_file: \n",__func__ , data_file);

  buffer_size = (util_ftell(stream) - start_pos)  ;
  buffer = util_calloc( buffer_size + 1  , sizeof * buffer );
  util_fseek( stream , start_pos , SEEK_SET);
  util_fread( buffer , sizeof * buffer , buffer_size ,stream ,  __func__);
  buffer[buffer_size] = '\0';

  {
    stringlist_type * tokens = parser_tokenize_buffer( parser , buffer , true );
    
    if (stringlist_get_size( tokens ) > 0) {
      const char * num_cpu_string = stringlist_iget( tokens , 0 );
      if (!util_sscanf_int( num_cpu_string , &num_cpu))
        fprintf(stderr,"** Warning: failed to interpret:%s as integer - assuming one CPU\n",num_cpu_string);
    } else
      fprintf(stderr,"** Warning: failed to load data for PARALLEL keyword - assuming one CPU\n");

    stringlist_free( tokens );
  }  
  free( buffer );
  return num_cpu; 
}
Exemple #5
0
void * enkf_main_analysis_enkf_update_JOB( void * self , const stringlist_type * args) {
  enkf_main_type   * enkf_main = enkf_main_safe_cast( self );
  enkf_fs_type * target_fs = enkf_main_get_fs( enkf_main );
  int target_step;
  int_vector_type * step_list;


  // Argument 0: The number of the step to write to
  if (stringlist_get_size(args) > 1)
    util_sscanf_int(stringlist_iget( args , 1) , &target_step);
  else
    target_step = 0;

  // Argument 1 - ??: The timesteps to use in the update
  if (stringlist_get_size( args ) > 2) {
    char * step_args = stringlist_alloc_joined_substring(args , 2 , stringlist_get_size(args) , " ");
    step_list = string_util_alloc_active_list( step_args );
    free( step_args );
  } else
    step_list = int_vector_alloc(1,target_step);

  enkf_main_UPDATE( enkf_main , step_list , target_fs , target_step , SMOOTHER_UPDATE);

  int_vector_free( step_list );
  return NULL;
}
Exemple #6
0
static int site_config_get_queue_max_running_option(queue_driver_type * driver) {
  const char * max_running_string = queue_driver_get_option(driver, MAX_RUNNING);
  int max_running = 0;
  if(!util_sscanf_int(max_running_string, &max_running)) {
    fprintf(stderr, "** Warning: String:%s for max_running is not parsable as int, using 0\n", max_running_string);
  }
  return max_running;
}
Exemple #7
0
int job_queue_get_max_running_option(queue_driver_type * driver) {
  char * max_running_string = (char*)queue_driver_get_option(driver, MAX_RUNNING);
  int max_running;
  if (!util_sscanf_int(max_running_string, &max_running)) {
    fprintf(stderr, "%s: Unable to parse option MAX_RUNNING with value %s to an int", __func__, max_running_string);
  }
  return max_running;
}
Exemple #8
0
static bool util_addr2line_lookup__(const void * bt_addr , char ** func_name , char ** file_name , int * line_nr, bool subtract_base_adress) {
  *func_name = NULL;    // If dladdr() succeeds, but addr2line fails the func_name pointer will be set, but the function will return false anyway.
  *file_name = NULL;
  *line_nr   = 0;
  {
    bool  address_found = false;
    Dl_info dl_info;
#if defined(__APPLE__)
    return false;
#else
    if (dladdr(bt_addr , &dl_info)) {
      const char * executable = dl_info.dli_fname;
      *func_name = util_alloc_string_copy( dl_info.dli_sname );
      if (util_file_exists( executable )) {
        char *stdout_file = util_alloc_tmp_file("/tmp" , "addr2line" , true);
        /* 1: Run addr2line application */
        {
          char ** argv = util_calloc(3 , sizeof * argv );
          argv[0] = util_alloc_string_copy("--functions");
          argv[1] = util_alloc_sprintf("--exe=%s" , executable );
          {
            char * rel_address = (char *) bt_addr;
            if (subtract_base_adress)
              rel_address -= (size_t) dl_info.dli_fbase;
            argv[2] = util_alloc_sprintf("%p" , (void *) rel_address);
          }
          util_spawn_blocking("addr2line", 3, (const char **) argv, stdout_file, NULL);
          util_free_stringlist(argv , 3);
        }

        /* 2: Parse stdout output */
        {
          bool at_eof;
          FILE * stream = util_fopen(stdout_file , "r");
          char * tmp_fname = util_fscanf_alloc_line(stream , &at_eof);

          if (strcmp(tmp_fname , UNDEFINED_FUNCTION) != 0) {
            char * stdout_file_name = util_fscanf_alloc_line(stream , &at_eof);
            char * line_string = NULL;
            util_binary_split_string( stdout_file_name , ":" , false , file_name , &line_string);
            if (line_string && util_sscanf_int( line_string , line_nr))
              address_found = true;

            free( stdout_file_name );
            util_safe_free( line_string );
          }
          free( tmp_fname );
          fclose(stream);
        }
        util_unlink_existing(stdout_file);
        free( stdout_file );
      }
    }
    return address_found;
#endif
  }
}
Exemple #9
0
void * enkf_main_smoother_with_iter_JOB( void * self , const stringlist_type * args ) {
  int iter;
  stringlist_type * sub_args = stringlist_alloc_shallow_copy_with_limits( args , 1 , stringlist_get_size( args ) - 1);
  util_sscanf_int( stringlist_iget(args , 0 ) , &iter );

  enkf_main_smoother_JOB__( self , iter , sub_args );

  stringlist_free( sub_args );
  return NULL;
}
Exemple #10
0
static void enkf_main_jobs_export_field(const enkf_main_type * enkf_main, const stringlist_type * args, field_file_format_type file_type) {
  const char *      field            = stringlist_iget(args, 0);
  const char *      file_name        = stringlist_iget(args, 1);
  int               report_step      = 0;
  util_sscanf_int(stringlist_iget(args,2), &report_step);

  bool_vector_type * iactive = alloc_iactive_vector_from_range(args, 4, stringlist_get_size(args), enkf_main_get_ensemble_size(enkf_main));
  enkf_main_export_field(enkf_main,field, file_name, iactive, file_type, report_step ) ;
  bool_vector_free(iactive);
}
Exemple #11
0
time_t ecl_util_get_start_date(const char * data_file) { 
  parser_type * parser = parser_alloc(" \t\r\n" , "\"\'" , NULL , NULL , "--" , "\n");
  time_t start_date  = -1;
  FILE * stream      = util_fopen(data_file , "r");
  char * buffer;
  
  if (!parser_fseek_string( parser , stream , "START" , true , true))   /* Seeks case insensitive. */
    util_abort("%s: sorry - could not find START in DATA file %s \n",__func__ , data_file);
  
  {
    long int start_pos = util_ftell( stream );
    int buffer_size;

    /* Look for terminating '/' */
    if (!parser_fseek_string( parser , stream , "/" , false , true))
      util_abort("%s: sorry - could not find \"/\" termination of START keyword in data_file: \n",__func__ , data_file);
    
    buffer_size = (util_ftell(stream) - start_pos)  ;
    buffer = util_calloc( buffer_size + 1 , sizeof * buffer  );
    util_fseek( stream , start_pos , SEEK_SET);
    util_fread( buffer , sizeof * buffer , buffer_size ,stream ,  __func__);
    buffer[buffer_size] = '\0';
  }
  
  
  {
    stringlist_type * tokens = parser_tokenize_buffer( parser , buffer , true );
    int day, year, month_nr;
    if ( util_sscanf_int( stringlist_iget( tokens , 0 ) , &day)   &&   util_sscanf_int( stringlist_iget(tokens , 2) , &year)) {
      month_nr   = ecl_util_get_month_nr(stringlist_iget( tokens , 1));
      start_date = ecl_util_make_date(day , month_nr , year );
    } else
      util_abort("%s: failed to parse DAY MONTH YEAR from : \"%s\" \n",__func__ , buffer);
    stringlist_free( tokens );
  }
  
  free( buffer );
  parser_free( parser );
  fclose(stream);
  
  return start_date;
}
Exemple #12
0
void * enkf_main_load_results_iter_JOB( void * self , const stringlist_type * args) {
  enkf_main_type * enkf_main = enkf_main_safe_cast( self );
  stringlist_type * iens_args = stringlist_alloc_shallow_copy_with_limits( args , 1 , stringlist_get_size( args ) - 1);
  int iter;

  util_sscanf_int( stringlist_iget( args , 0 ) , &iter);
  enkf_main_load_results_JOB__(enkf_main , iter , iens_args );
  stringlist_free( iens_args );

  return NULL;
}
Exemple #13
0
int stringlist_iget_as_int( const stringlist_type * stringlist , int index , bool * valid) {
  const char * string_value = stringlist_iget( stringlist , index );
  int value = -1;

  if (valid != NULL)
    *valid = false;

  if (util_sscanf_int(string_value , &value))
    if (valid != NULL)
      *valid = true;

  return value;
}
Exemple #14
0
bool gen_data_user_get(const gen_data_type * gen_data, const char * index_key, int report_step , double * value)
{
  int index;
  *value = 0.0;

  if (index_key != NULL) {
    if (util_sscanf_int(index_key , &index)) {
      if (index < gen_data_config_get_data_size( gen_data->config , gen_data->current_report_step )) {
        *value = gen_data_iget_double( gen_data , index );
        return true;
      }
    }
  }

  return false;
}
Exemple #15
0
static void enkf_main_jobs_export_field(const enkf_main_type * enkf_main, const stringlist_type * args, field_file_format_type file_type) {
  const char *      field            = stringlist_iget(args, 0);
  const char *      file_name        = stringlist_iget(args, 1);
  int               report_step      = 0;
  util_sscanf_int(stringlist_iget(args,2), &report_step);
  state_enum        state            = enkf_types_get_state_enum(stringlist_iget(args, 3));

  if (BOTH == state) {
      fprintf(stderr,"** Field export jobs only supports state_enum ANALYZED or FORECAST, not BOTH.\n");
      return;
  }

  bool_vector_type * iactive = alloc_iactive_vector_from_range(args, 4, stringlist_get_size(args), enkf_main_get_ensemble_size(enkf_main));
  enkf_main_export_field(enkf_main,field, file_name, iactive, file_type, report_step, state) ;
  bool_vector_free(iactive);
}
Exemple #16
0
static bool queue_driver_set_generic_option__(queue_driver_type * driver, const char * option_key, const void * value) {
  bool option_set = true;
  {
    if (strcmp(MAX_RUNNING, option_key) == 0) {
      int max_running_int = 0;
      if (util_sscanf_int(value, &max_running_int)) {
        queue_driver_set_max_running(driver, max_running_int);
        option_set = true;
      }
      else
        option_set = false;
    } else
      option_set = false;
  }
  return option_set;
}
Exemple #17
0
static int_vector_type * string_util_sscanf_alloc_active_list(const char * range_string ) {
  int_vector_type *active_list = NULL;
  bool valid = valid_characters( range_string );

  if (valid)
  {
    parser_type * parser = parser_alloc( ","   , /* No ordinary split characters. */
                                         NULL  , /* No quoters. */
                                         NULL  , /* No special split */
                                         " \t" , /* Removing ' ' and '\t' */
                                         NULL  , /* No comment */
                                         NULL  );
    stringlist_type * tokens;
    int item;
    active_list = int_vector_alloc(0,0);
    tokens = parser_tokenize_buffer( parser , range_string , true);
    
    for (item = 0; item < stringlist_get_size( tokens ); item++) {
      const char * string_item = stringlist_iget( tokens , item );
      char * pos_ptr = (char *) string_item;
      int value1 , value2;
      
      value1 = strtol( string_item , &pos_ptr , 10);
      if (*pos_ptr == '\0') 
        // The pos_ptr points to the end of the string, i.e. this was a single digit.
        value2 = value1;
      else {
        // OK - this is a range; skip spaces and the range dash '-'
        while (isspace(*pos_ptr) || *pos_ptr == '-')
          pos_ptr++;
        util_sscanf_int( pos_ptr , &value2);
      } 
      
      {
        int value;
        for (value = value1; value <= value2; value++) 
          int_vector_append( active_list , value );
      }
    }
    
    
    stringlist_free( tokens );
    parser_free( parser );
  }
  
  return active_list;
}
Exemple #18
0
void * enkf_main_analysis_update_JOB( void * self , const stringlist_type * args) {
  enkf_main_type   * enkf_main = enkf_main_safe_cast( self );
  enkf_fs_type * target_fs;
  int target_step;
  int_vector_type * step_list;
  bool decrease_ref = false;

  // Argument 0: Which case to write to
  if (stringlist_get_size(args)) {
    const char * target_fs_name = stringlist_iget( args , 0 );
    if (strcmp( target_fs_name , CURRENT_CASE_STRING) == 0)
      target_fs = enkf_main_get_fs( enkf_main );
    else {
      target_fs = enkf_main_mount_alt_fs( enkf_main , target_fs_name , true);
      decrease_ref = true;
    }
  } else
      target_fs = enkf_main_get_fs( enkf_main );
  {


    // Argument 1: The number of the step to write to
    if (stringlist_get_size(args) > 1)
      util_sscanf_int(stringlist_iget( args , 1) , &target_step);
    else
      target_step = 0;

    // Argument 2 - ??: The timesteps to use in the update
    if (stringlist_get_size( args ) > 2) {
      char * step_args = stringlist_alloc_joined_substring(args , 2 , stringlist_get_size(args) , " ");
      step_list = string_util_alloc_active_list( step_args );
      free( step_args );
    } else {
      int stride = 1;
      time_map_type * time_map = enkf_fs_get_time_map( enkf_main_get_fs( enkf_main ));
      step_list = enkf_main_update_alloc_step_list( enkf_main , 0 , time_map_get_last_step( time_map ) , stride);
    }

    enkf_main_UPDATE( enkf_main , step_list , target_fs , target_step , SMOOTHER_UPDATE);

    int_vector_free( step_list );

    if (decrease_ref)
      enkf_fs_decref( target_fs );
  }
  return NULL;
}
Exemple #19
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 );
}
Exemple #20
0
bool config_schema_item_valid_string(config_item_types value_type , const char * value)
{
  switch(value_type) {
  case(CONFIG_ISODATE):
    return util_sscanf_isodate( value , NULL );
    break;
  case(CONFIG_INT):
    return util_sscanf_int( value , NULL );
    break;
  case(CONFIG_FLOAT):
    return util_sscanf_double( value , NULL );
    break;
  case(CONFIG_BOOL):
    return util_sscanf_bool( value , NULL );
    break;
  case(CONFIG_BYTESIZE):
    return util_sscanf_bytesize( value , NULL);
    break;
  default:
    return true;
  }
}
Exemple #21
0
bool analysis_module_set_var( analysis_module_type * module , const char * var_name , const char * string_value ) {
  bool set_ok = false;
  {
    int  int_value;
    
    if (util_sscanf_int( string_value , &int_value )) 
      set_ok = analysis_module_set_int( module , var_name , int_value );
    
    
    if (set_ok)
      return true;
  }
  
  {
    double double_value;
    if (util_sscanf_double( string_value , &double_value )) 
      set_ok = analysis_module_set_double( module , var_name , double_value );
    
    if (set_ok)
      return true;
  }
  
  {
    bool bool_value;
    if (util_sscanf_bool( string_value , &bool_value)) 
      set_ok = analysis_module_set_bool( module , var_name , bool_value );

    if (set_ok)
      return true;
  }
  

  set_ok = analysis_module_set_string( module , var_name , string_value );
  if (!set_ok)
    fprintf(stderr,"** Warning: failed to set %s=%s for analysis module:%s\n", var_name , string_value , module->user_name);
  
  return set_ok;
}
Exemple #22
0
void enkf_tui_init(enkf_main_type * enkf_main, bool all_members , bool all_parameters , bool interval ) {
  const int prompt_len                         = 35;
  const ensemble_config_type * ensemble_config = enkf_main_get_ensemble_config(enkf_main);
  int   ens_size                               = enkf_main_get_ensemble_size( enkf_main );
  int iens1, iens2;
  bool iens_valid = false;

  /* iens2 should be interpreted as __inclusive__ */
  if ( all_members ) {
    iens1 = 0;
    iens2 = ens_size - 1;
    iens_valid = true;
  } else {
    if( interval ) {
      char * iens1char = util_scanf_int_with_limits_return_char("First ensemble member in interval"  , prompt_len , 0 , ens_size - 1);
      if (strlen(iens1char)) {
        util_sscanf_int(iens1char , &iens1);
        char * iens2char = util_scanf_int_with_limits_return_char("Second ensemble member in interval" , prompt_len , iens1 , ens_size - 1);
        if (strlen(iens2char)) {
          util_sscanf_int(iens2char , &iens2);
          iens_valid = true;
        }
        free(iens2char);
      }
      free(iens1char);
    } else {
      char * iens1char = util_scanf_int_with_limits_return_char("Initialize ensemble member" , prompt_len , 0 , ens_size - 1);
      if (strlen(iens1char)) {
        util_sscanf_int(iens1char , &iens1);
        iens2 = iens1;
        iens_valid = true;
      }
      free(iens1char);
    }
  }

  if (iens_valid) {
    stringlist_type * param_list = NULL;
    if (all_parameters)
      param_list = ensemble_config_alloc_keylist_from_var_type( ensemble_config , PARAMETER );
    else {
      const enkf_config_node_type * config_node = NULL;
      param_list = stringlist_alloc_new();
      config_node = enkf_tui_util_scanf_key(ensemble_config , prompt_len , INVALID , INVALID_VAR);
      if( config_node != NULL )
        stringlist_append_copy( param_list , enkf_config_node_get_key(config_node));
    }

    if (param_list != NULL) {
      enkf_fs_type * init_fs = enkf_main_tui_get_fs( enkf_main );
      bool_vector_type * iens_mask = bool_vector_alloc( ens_size , false );
      path_fmt_type * runpath_fmt = model_config_get_runpath_fmt(enkf_main_get_model_config(enkf_main));
      subst_list_type * subst_list = enkf_main_get_data_kw(enkf_main);
      int iter = 0;
      bool_vector_iset_block( iens_mask , iens1 , iens2 - iens1 + 1, true );
      {
        ert_run_context_type * run_context = ert_run_context_alloc_INIT_ONLY(init_fs, INIT_CONDITIONAL, iens_mask, runpath_fmt, subst_list , iter );
        enkf_main_initialize_from_scratch(enkf_main , param_list , run_context);
        ert_run_context_free(run_context);
      }
      stringlist_free( param_list );
      bool_vector_free( iens_mask );
    }
  }
}
Exemple #23
0
void util_abort(const char * fmt , ...) {
  pthread_mutex_lock( &__abort_mutex ); /* Abort before unlock() */
  {
    va_list ap;

    va_start(ap , fmt);
    printf("\n\n");
    fprintf(stderr,"\n\n");
    vfprintf(stderr , fmt , ap);
    va_end(ap);

    /*
      The backtrace is based on calling the external program
      addr2line; the call is based on util_fork_exec() which is
      currently only available on POSIX.
    */

    const bool include_backtrace = true;
    if (include_backtrace) {
      const int max_bt = 50;
      char *executable;
      void *array[max_bt];
      char **strings;
      char ** func_list;
      char ** file_line_list;
      int    max_func_length = 0;
      int    size,i;
  
      if (__abort_program_message != NULL) {
        fprintf(stderr,"--------------------------------------------------------------------------------\n");
        fprintf(stderr,"%s",__abort_program_message);
        fprintf(stderr,"--------------------------------------------------------------------------------\n");
      }

      fprintf(stderr,"\n");
      fprintf(stderr,"****************************************************************************\n");
      fprintf(stderr,"**                                                                        **\n");
      fprintf(stderr,"**           A fatal error occured, and we have to abort.                 **\n");
      fprintf(stderr,"**                                                                        **\n");
      fprintf(stderr,"**  We now *try* to provide a backtrace, which would be very useful       **\n");
      fprintf(stderr,"**  when debugging. The process of making a (human readable) backtrace    **\n");
      fprintf(stderr,"**  is quite complex, among other things it involves several calls to the **\n");
      fprintf(stderr,"**  external program addr2line. We have arrived here because the program  **\n");
      fprintf(stderr,"**  state is already quite broken, so the backtrace might be (seriously)  **\n");
      fprintf(stderr,"**  broken as well.                                                       **\n");
      fprintf(stderr,"**                                                                        **\n");
      fprintf(stderr,"****************************************************************************\n");
      size       = backtrace(array , max_bt);
      strings    = backtrace_symbols(array , size);    
      executable = util_bt_alloc_current_executable(strings[0]);
      if (executable != NULL) {
        fprintf(stderr,"Current executable : %s \n",executable);
        
        func_list      = util_calloc(size , sizeof * func_list      );
        file_line_list = util_calloc(size , sizeof * file_line_list );
        
        for (i=0; i < size; i++) {
          util_addr2line_lookup(executable , strings[i] , &func_list[i] , &file_line_list[i]);
          max_func_length = util_int_max(max_func_length , strlen(func_list[i]));
        }
        
        {
          char string_fmt[64];
          sprintf(string_fmt, " #%s02d %s-%ds(..) in %ss   \n" , "%" , "%" , max_func_length , "%");
          fprintf(stderr , "--------------------------------------------------------------------------------\n");
          for (i=0; i < size; i++) {
            
            int line_nr;
            if (util_sscanf_int(file_line_list[i] , &line_nr))
              fprintf(stderr, string_fmt , i , func_list[i], file_line_list[i]);
            else
              fprintf(stderr, string_fmt , i , func_list[i], file_line_list[i]);
          }
          fprintf(stderr , "--------------------------------------------------------------------------------\n");
          util_free_stringlist(func_list      , size);
          util_free_stringlist(file_line_list , size);
        }
      } else
        fprintf(stderr,"Could not determine executable file for:%s - no backtrace. \n",strings[0]);
      
      free(strings);
      util_safe_free(executable);
    }

    if (getenv("UTIL_ABORT") != NULL) {
      fprintf(stderr , "Aborting ... \n");
      abort();
    } else {
      fprintf(stderr , "Exiting ... \n");
      exit(1);
    }
    // Would have preferred abort() here - but that comes in conflict with the SIGABRT signal.
  }
  pthread_mutex_unlock( &__abort_mutex );
}
Exemple #24
0
bool config_schema_item_validate_set(const config_schema_item_type * item , stringlist_type * token_list , const char * config_file, const config_path_elm_type * path_elm , config_error_type * error_list) {
  bool OK = true;
  int argc = stringlist_get_size( token_list ) - 1;
  if (item->validate->argc_min >= 0) {
    if (argc < item->validate->argc_min) {
      OK = false;
      {
        char * error_message;
        if (config_file != NULL)
          error_message = util_alloc_sprintf("Error when parsing config_file:\"%s\" Keyword:%s must have at least %d arguments.",config_file , item->kw , item->validate->argc_min);
        else
          error_message = util_alloc_sprintf("Error:: Keyword:%s must have at least %d arguments.",item->kw , item->validate->argc_min);

        config_error_add( error_list , error_message );
      }
    }
  }

  if (item->validate->argc_max >= 0) {
    if (argc > item->validate->argc_max) {
      OK = false;
      {
        char * error_message;

        if (config_file != NULL)
          error_message = util_alloc_sprintf("Error when parsing config_file:\"%s\" Keyword:%s must have maximum %d arguments.",config_file , item->kw , item->validate->argc_max);
        else
          error_message = util_alloc_sprintf("Error:: Keyword:%s must have maximum %d arguments.",item->kw , item->validate->argc_max);

        config_error_add( error_list , error_message );
      }
    }
  }

  /*
     OK - now we have verified that the number of arguments is correct. Then
     we start actually looking at the values.
  */
  if (OK) {
    /* Validating selection set - first common, then indexed */
    if (item->validate->common_selection_set) {
      for (int iarg = 0; iarg < argc; iarg++) {
        if (!set_has_key(item->validate->common_selection_set , stringlist_iget( token_list , iarg + 1))) {
          config_error_add( error_list , util_alloc_sprintf("%s: is not a valid value for: %s.",stringlist_iget( token_list , iarg + 1) , item->kw));
          OK = false;
        }
      }
    } else if (item->validate->indexed_selection_set != NULL) {
      for (int iarg = 0; iarg < argc; iarg++) {
        if ((item->validate->argc_max > 0) || (iarg < item->validate->argc_min)) {  /* Without this test we might go out of range on the indexed selection set. */
          const set_type * selection_set = validate_iget_selection_set( item->validate , iarg);
          if (selection_set) {
            if (!set_has_key( selection_set, stringlist_iget( token_list , iarg + 1))) {
              config_error_add( error_list , util_alloc_sprintf("%s: is not a valid value for item %d of \'%s\'.",stringlist_iget( token_list , iarg + 1) , iarg + 1 , item->kw));
              OK = false;
            }
          }
        }
      }
    }

    /*
      Observe that the following code might rewrite the content of
      argv for arguments referring to path locations.
    */


    /* Validate the TYPE of the various argumnents */
    {
      for (int iarg = 0; iarg < argc; iarg++) {
        const char * value = stringlist_iget(token_list , iarg + 1);
        switch (validate_iget_type( item->validate , iarg)) {
        case(CONFIG_STRING): /* This never fails ... */
          break;
        case(CONFIG_ISODATE):
          if (!util_sscanf_isodate( value , NULL ))
            config_error_add( error_list , util_alloc_sprintf("Failed to parse:%s as an ISO date: YYYY-MM-DD.",value));
          break;
        case(CONFIG_INT):
          if (!util_sscanf_int( value , NULL ))
            config_error_add( error_list , util_alloc_sprintf("Failed to parse:%s as an integer.",value));
          break;
        case(CONFIG_FLOAT):
          if (!util_sscanf_double( value , NULL )) {
            config_error_add( error_list , util_alloc_sprintf("Failed to parse:%s as a floating point number.", value));
            OK = false;
          }
          break;
        case(CONFIG_PATH):
          // As long as we do not reuqire the path to exist it is just a string.
          break;
        case(CONFIG_EXISTING_PATH):
          {
            char * path = config_path_elm_alloc_abspath( path_elm , value );
            if (!util_entry_exists(path)) {
              config_error_add( error_list , util_alloc_sprintf("Can not find entry %s in %s ",value , config_path_elm_get_relpath( path_elm) ));
              OK = false;
            }
            free( path );
          }
          break;
        case(CONFIG_EXECUTABLE):
          {
            /*
              1. If the supplied value is an abolute path - do nothing.
              2. If the supplied is _not_ an absolute path:

                 a. Try if the relocated exists - then use that.
                 b. Else - try if the util_alloc_PATH_executable() exists.
            */
            if (!util_is_abs_path( value )) {
              char * relocated  = __alloc_relocated__(path_elm , value);
              char * path_exe   = util_alloc_PATH_executable( value );

              if (util_file_exists(relocated)) {
                if (util_is_executable(relocated))
                  stringlist_iset_copy( token_list , iarg , relocated);
              } else if (path_exe != NULL)
                stringlist_iset_copy( token_list , iarg , path_exe);
              else
                config_error_add( error_list , util_alloc_sprintf("Could not locate executable:%s ", value));

              free(relocated);
              util_safe_free(path_exe);
            } else {
              if (!util_is_executable( value ))
                config_error_add( error_list , util_alloc_sprintf("Could not locate executable:%s ", value));
            }
          }
          break;
        case(CONFIG_BOOL):
          if (!util_sscanf_bool( value , NULL )) {
            config_error_add( error_list , util_alloc_sprintf("Failed to parse:%s as a boolean.", value));
            OK = false;
          }
          break;
        case(CONFIG_BYTESIZE):
          if (!util_sscanf_bytesize( value , NULL)) {
            config_error_add( error_list , util_alloc_sprintf("Failed to parse:\"%s\" as number of bytes." , value));
            OK = false;
          }
          break;
        default:
          util_abort("%s: config_item_type:%d not recognized \n",__func__ , validate_iget_type(item->validate , iarg));
        }
      }
    }
  }
  return OK;
}
Exemple #25
0
ecl_file_enum ecl_util_inspect_extension(const char * ext , bool *_fmt_file, int * _report_nr) {
  ecl_file_enum file_type = ECL_OTHER_FILE;
  bool fmt_file = true;
  int report_nr = -1;
  
  if (strcmp(ext , "UNRST") == 0) {
    file_type = ECL_UNIFIED_RESTART_FILE;
    fmt_file = false;
  } else if (strcmp(ext , "FUNRST") == 0) {
    file_type = ECL_UNIFIED_RESTART_FILE;
    fmt_file = true;
  } else if (strcmp(ext , "UNSMRY") == 0) {
    file_type = ECL_UNIFIED_SUMMARY_FILE;
    fmt_file  = false;
  } else if (strcmp(ext , "FUNSMRY") == 0) {
    file_type = ECL_UNIFIED_SUMMARY_FILE;
    fmt_file  = true;
  } else if (strcmp(ext , "SMSPEC") == 0) {
    file_type = ECL_SUMMARY_HEADER_FILE;
    fmt_file  = false;
  } else if (strcmp(ext , "FSMSPEC") == 0) {
    file_type = ECL_SUMMARY_HEADER_FILE;
    fmt_file  = true;
  } else if (strcmp(ext , "GRID") == 0) {
    file_type = ECL_GRID_FILE;
    fmt_file  = false;
  } else if (strcmp(ext , "FGRID") == 0) {
    file_type = ECL_GRID_FILE;
    fmt_file  = true;
  } else if (strcmp(ext , "EGRID") == 0) {
    file_type = ECL_EGRID_FILE;
    fmt_file  = false;
  } else if (strcmp(ext , "FEGRID") == 0) {
    file_type = ECL_EGRID_FILE;
    fmt_file  = true;
  } else if (strcmp(ext , "INIT") == 0) {
    file_type = ECL_INIT_FILE;
    fmt_file  = false;
  } else if (strcmp(ext , "FINIT") == 0) {
    file_type = ECL_INIT_FILE;
    fmt_file  = true;
  } else if (strcmp(ext , "FRFT") == 0) {
    file_type = ECL_RFT_FILE;
    fmt_file  = true;
  } else if (strcmp(ext , "RFT") == 0) {
    file_type = ECL_RFT_FILE;
    fmt_file  = false;
  } else if (strcmp(ext , "DATA") == 0) {
    file_type = ECL_DATA_FILE;
    fmt_file  = true;  /* Not really relevant ... */
  } else {
    switch (ext[0]) {
    case('X'):
      file_type = ECL_RESTART_FILE;
      fmt_file  = false;
      break;
    case('F'):
      file_type = ECL_RESTART_FILE;
      fmt_file  = true;
      break;
    case('S'):
      file_type = ECL_SUMMARY_FILE;
      fmt_file  = false;
      break;
    case('A'):
      file_type = ECL_SUMMARY_FILE;
      fmt_file  = true;
      break;
    default:
      file_type = ECL_OTHER_FILE;
    }
    if (file_type != ECL_OTHER_FILE) 
      if (!util_sscanf_int(&ext[1] , &report_nr))
        file_type = ECL_OTHER_FILE;
  }
  
  if (_fmt_file != NULL)
    *_fmt_file  = fmt_file;
  
  if (_report_nr != NULL)  
    *_report_nr = report_nr;
  
  return file_type;
}
Exemple #26
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 #27
0
int main( int argc, char ** argv) {
  if (argc == 1)
    util_exit("block_node  node1  node2  node3:2  \n");
  
  /* Initialize lsf environment */
  util_setenv( "LSF_BINDIR"    , "/prog/LSF/9.1/linux2.6-glibc2.3-x86_64/bin" );
  util_setenv( "LSF_LINDIR"    , "/prog/LSF/9.1/linux2.6-glibc2.3-x86_64/lib" );
  util_setenv( "XLSF_UIDDIR"   , "/prog/LSF/9.1/linux2.6-glibc2.3-x86_64/lib/uid" );
  util_setenv( "LSF_SERVERDIR" , "/prog/LSF/9.1/linux2.6-glibc2.3-x86_64/etc");
  util_setenv( "LSF_ENVDIR"    , "/prog/LSF/conf");
  
  util_update_path_var( "PATH"               , "/prog/LSF/9.1/linux2.6-glibc2.3-x86_64/bin" , false);
  util_update_path_var( "LD_LIBRARY_PATH"    , "/prog/LSF/9.1/linux2.6-glibc2.3-x86_64/lib" , false);

  
  lsf_driver = lsf_driver_alloc();
  if (lsf_driver_get_submit_method( lsf_driver ) != LSF_SUBMIT_INTERNAL)
    util_exit("Sorry - the block_node program must be invoked on a proper LSF node \n");

  {
    
    int iarg;
    int total_blocked_target = 0;
    nodes       = hash_alloc();
    for (iarg = 1; iarg < argc; iarg++) {
      char   *node_name;
      int    num_slots;
      
      {
        char * num_slots_string;
        util_binary_split_string( argv[iarg] , ":" , true , &node_name , &num_slots_string);
        if (num_slots_string)
          util_sscanf_int( num_slots_string , &num_slots);
        else
          num_slots = 1;
      }
      
      if (!hash_has_key( nodes , node_name))
        hash_insert_hash_owned_ref( nodes , node_name , count_pair_alloc() , free);

      {
        count_pair_type * pair = hash_get( nodes , node_name);
        pair->target += num_slots;
      }
      total_blocked_target += num_slots;
    }

    signal(SIGINT , block_node_exit );
    {
      const int sleep_time    = 5;
      const int chunk_size    = 10;    /* We submit this many at a time. */
      const int max_pool_size = 1000;  /* The absolute total maximum of jobs we will submit. */  

      bool           cont        = true;
      int            pending     = 0;   
      bool           all_blocked;
      job_pool                   = vector_alloc_new();

      while (cont) {
        printf("[Ctrl-C to give up] "); fflush( stdout );
        if (cont) sleep( sleep_time );
        if (pending == 0) {
          if (vector_get_size( job_pool ) < max_pool_size)
            add_jobs( chunk_size );
        }
        
        update_pool_status( &all_blocked , &pending);
        print_status();

        if (all_blocked)
          cont = false;
      }
      if (!all_blocked)
        printf("Sorry - failed to block all the nodes \n");
      
      block_node_exit( 0 );
      hash_free( nodes );
    }
  }
}
Exemple #28
0
bool version_is_ert_devel_version() {
  return util_sscanf_int( ERT_VERSION_MICRO  , NULL);
}
Exemple #29
0
int config_content_item_iget_as_int(const config_content_item_type * item, int occurence , int index) {
  int value;
  config_schema_item_assure_type(item->schema , index , CONFIG_INT);
  util_sscanf_int( config_content_item_iget(item , occurence , index) , &value );
  return value;
}
Exemple #30
0
bool ecl_version_is_devel_version() {
  return util_sscanf_int(str(ECL_VERSION_MICRO), NULL);
}