Esempio n. 1
0
void ecl_config_init( ecl_config_type * ecl_config , const config_type * config ) {
  if (config_item_set( config , ECLBASE_KEY ))
    ecl_config_set_eclbase( ecl_config , config_iget(config , ECLBASE_KEY ,0,0) );
  
  if (config_item_set( config , DATA_FILE_KEY ))
    ecl_config_set_data_file( ecl_config , config_iget( config , DATA_FILE_KEY ,0,0));
  
  if (config_item_set( config , SCHEDULE_FILE_KEY ))
    ecl_config_set_schedule_file( ecl_config , config_iget( config , SCHEDULE_FILE_KEY ,0,0));

  
  if (config_item_set(config , GRID_KEY))
    ecl_config_set_grid( ecl_config , config_iget(config , GRID_KEY , 0,0) );
  
  if (config_item_set( config , ADD_FIXED_LENGTH_SCHEDULE_KW_KEY)) {
    int iocc;
    for (iocc = 0; iocc < config_get_occurences(config , ADD_FIXED_LENGTH_SCHEDULE_KW_KEY); iocc++) 
      ecl_config_add_fixed_length_schedule_kw( ecl_config , 
                                               config_iget(config , ADD_FIXED_LENGTH_SCHEDULE_KW_KEY , iocc , 0) , 
                                               config_iget_as_int(config , ADD_FIXED_LENGTH_SCHEDULE_KW_KEY , iocc , 1));
  }
  
  
  if (config_item_set( config , REFCASE_KEY)) {
    const char * refcase_path = config_get_value_as_path( config , REFCASE_KEY );
    if (!ecl_config_load_refcase( ecl_config , refcase_path))
      fprintf(stderr,"** Warning: loading refcase:%s failed \n", refcase_path);
  }
  

  if (config_item_set( config , REFCASE_LIST_KEY)) {
    config_content_item_type * item = config_get_content_item( config , REFCASE_LIST_KEY);
    int i;
    for (i=0; i < config_content_item_get_size( item ); i++) {
      config_content_node_type * node = config_content_item_iget_node( item , i );
      int j;
      for (j=0; j < config_content_node_get_size( node ); j++) {
        const char * case_glob = config_content_node_iget_as_path( node , j );
        ecl_refcase_list_add_matching( ecl_config->refcase_list , case_glob );
      }
    }
  }
  
  /* Deprecated */
  if (config_item_set( config , PLOT_REFCASE_LIST_KEY)) {
    const char * case_list_file = config_get_value( config , PLOT_REFCASE_LIST_KEY);
    FILE * stream = util_fopen(case_list_file , "r");
    bool at_eof;
    do {
      char * case_name = util_fscanf_alloc_line(stream , &at_eof);
      if (case_name) {
        ecl_refcase_list_add_case( ecl_config->refcase_list , case_name);
        free( case_name );
      }
    } while (!at_eof);
    
    fclose( stream );
  }
  
  if (config_item_set(config , INIT_SECTION_KEY)) 
    ecl_config_set_init_section( ecl_config , config_get_value( config , INIT_SECTION_KEY ));
  else 
    if (ecl_config->can_restart) 
      /** 
          This is a hard error - the datafile contains <INIT>, however
          the config file does NOT contain INIT_SECTION, i.e. we have
          no information to fill in for the <INIT> section. This case
          will not be able to initialize an ECLIPSE model, and that is
          broken behaviour. 
      */
      util_exit("Sorry: when the datafile contains <INIT> the config file MUST have the INIT_SECTION keyword. \n");
  
  /*
      The user has not supplied a INIT_SECTION keyword whatsoever, 
      this essentially means that we can not restart - because:

      1. The EQUIL section must be inlined in the DATAFILE without any
         special markup.
      
      2. ECLIPSE will fail hard if the datafile contains both an EQUIL
         section and a restart statement, and when we have not marked
         the EQUIL section specially with the INIT_SECTION keyword it
         is impossible for ERT to dynamically change between a
         datafile with initialisation and a datafile for restart.
         
      IFF the user has no intentitions of any form of restart, this is
      perfectly legitemate.
  */
  if (config_item_set( config , END_DATE_KEY )) {
    const char * date_string = config_get_value( config , END_DATE_KEY );
    time_t end_date;
    if (util_sscanf_date( date_string , &end_date))
      ecl_config_set_end_date( ecl_config , end_date );
    else
      fprintf(stderr,"** WARNING **: Failed to parse %s as a date - should be in format dd/mm/yyyy \n",date_string);
  }
}
Esempio n. 2
0
void ecl_config_init(ecl_config_type * ecl_config, const config_content_type * config)
{
  if (config_content_has_item(config, ECLBASE_KEY)) {
    ui_return_type * ui_return = ecl_config_validate_eclbase(ecl_config, config_content_iget(config, ECLBASE_KEY, 0, 0));
    if (ui_return_get_status(ui_return) == UI_RETURN_OK)
      ecl_config_set_eclbase(ecl_config, config_content_iget(config, ECLBASE_KEY, 0, 0));
    else
      util_abort("%s: failed to set eclbase format. Error:%s\n", __func__ , ui_return_get_last_error(ui_return));
    ui_return_free(ui_return);
  }

  if (config_content_has_item(config, DATA_FILE_KEY))
  {
    ui_return_type * ui_return = ecl_config_validate_data_file(ecl_config, config_content_iget(config, DATA_FILE_KEY, 0, 0));
    if (ui_return_get_status( ui_return ) == UI_RETURN_OK)
      ecl_config_set_data_file( ecl_config, config_content_iget(config, DATA_FILE_KEY, 0, 0) );
    else
      util_abort("%s: problem setting ECLIPSE data file\n",__func__ , ui_return_get_last_error(ui_return));

    ui_return_free(ui_return);
  }

  if (config_content_has_item(config, SCHEDULE_FILE_KEY)) {
    const char * schedule_target_file = config_content_safe_iget(config, SCHEDULE_FILE_KEY, 0, 1);
    if (schedule_target_file) {
      ui_return_type * ui_return_sched_target_file = ecl_config_validate_schedule_file(ecl_config, schedule_target_file);
      if (!ui_return_get_status(ui_return_sched_target_file) == UI_RETURN_OK) {
         util_abort("%s: failed to set target schedule file. Error:%s\n",__func__ , ui_return_get_last_error(ui_return_sched_target_file));
      }
      ui_return_free(ui_return_sched_target_file);
    }

    ui_return_type * ui_return = ecl_config_validate_schedule_file(ecl_config, config_content_iget(config, SCHEDULE_FILE_KEY, 0, 0));
    if (ui_return_get_status(ui_return) == UI_RETURN_OK)
      ecl_config_set_schedule_file(ecl_config, config_content_iget(config, SCHEDULE_FILE_KEY, 0, 0), schedule_target_file);
    else
      util_abort("%s: failed to set schedule file. Error:%s\n",__func__ , ui_return_get_last_error(ui_return));

    ui_return_free(ui_return);
  }

  if (config_content_has_item(config, GRID_KEY)) {
    const char * grid_file = config_content_iget(config, GRID_KEY, 0, 0);
    ui_return_type * ui_return = ecl_config_validate_grid( ecl_config , grid_file);
    if (ui_return_get_status(ui_return) == UI_RETURN_OK)
      ecl_config_set_grid(ecl_config, grid_file );
    else
      util_abort("%s: failed to set grid file:%s  Error:%s \n",__func__ , grid_file , ui_return_get_last_error(ui_return));

    ui_return_free( ui_return );
  }


  if (config_content_has_item(config, ADD_FIXED_LENGTH_SCHEDULE_KW_KEY))
  {
    int iocc;
    for (iocc = 0; iocc < config_content_get_occurences(config, ADD_FIXED_LENGTH_SCHEDULE_KW_KEY); iocc++)
      ecl_config_add_fixed_length_schedule_kw(ecl_config,
                                              config_content_iget(config, ADD_FIXED_LENGTH_SCHEDULE_KW_KEY, iocc, 0),
                                              config_content_iget_as_int(config, ADD_FIXED_LENGTH_SCHEDULE_KW_KEY, iocc, 1));
  }

  if (config_content_has_item(config, REFCASE_KEY))
  {
    const char * refcase_path = config_content_get_value_as_path(config, REFCASE_KEY);
    if (!ecl_config_load_refcase(ecl_config, refcase_path))
      fprintf(stderr, "** Warning: loading refcase:%s failed \n", refcase_path);
  }

  if (config_content_has_item(config, REFCASE_LIST_KEY))
  {
    config_content_item_type * item = config_content_get_item(config, REFCASE_LIST_KEY);
    int i;
    for (i = 0; i < config_content_item_get_size(item); i++)
    {
      config_content_node_type * node = config_content_item_iget_node(item, i);
      int j;
      for (j = 0; j < config_content_node_get_size(node); j++)
      {
        const char * case_glob = config_content_node_iget_as_path(node, j);
        ecl_refcase_list_add_matching(ecl_config->refcase_list, case_glob);
      }
    }
  }

  if (config_content_has_item(config, INIT_SECTION_KEY))
    ecl_config_set_init_section(ecl_config, config_content_get_value(config, INIT_SECTION_KEY));
  else if (ecl_config->can_restart)
    /**
     This is a hard error - the datafile contains <INIT>, however
     the config file does NOT contain INIT_SECTION, i.e. we have
     no information to fill in for the <INIT> section. This case
     will not be able to initialize an ECLIPSE model, and that is
     broken behaviour.
     */
    util_exit("Sorry: when the datafile contains <INIT> the config file MUST have the INIT_SECTION keyword. \n");

  /*
   The user has not supplied a INIT_SECTION keyword whatsoever,
   this essentially means that we can not restart - because:

   1. The EQUIL section must be inlined in the DATAFILE without any
   special markup.

   2. ECLIPSE will fail hard if the datafile contains both an EQUIL
   section and a restart statement, and when we have not marked
   the EQUIL section specially with the INIT_SECTION keyword it
   is impossible for ERT to dynamically change between a
   datafile with initialisation and a datafile for restart.

   IFF the user has no intentitions of any form of restart, this is
   perfectly legitemate.
   */
  if (config_content_has_item(config, END_DATE_KEY))
  {
    const char * date_string = config_content_get_value(config, END_DATE_KEY);
    time_t end_date;
    if (util_sscanf_date_utc(date_string, &end_date))
      ecl_config_set_end_date(ecl_config, end_date);
    else
      fprintf(stderr, "** WARNING **: Failed to parse %s as a date - should be in format dd/mm/yyyy \n", date_string);
  }
}