コード例 #1
0
ファイル: ensemble_config.c プロジェクト: danielfmva/ert
void ensemble_config_init(ensemble_config_type * ensemble_config , const config_type * config , ecl_grid_type * grid, const ecl_sum_type * refcase) {
  int i;
  ensemble_config_set_refcase( ensemble_config , refcase );

  if (config_item_set( config , GEN_KW_TAG_FORMAT_KEY))
    ensemble_config_set_gen_kw_format( ensemble_config , config_iget( config , GEN_KW_TAG_FORMAT_KEY , 0 , 0 ));
  
  ensemble_config_init_GEN_PARAM( ensemble_config , config );
  ensemble_config_init_GEN_DATA( ensemble_config , config );
  ensemble_config_init_GEN_KW(ensemble_config , config ); 
  ensemble_config_init_SURFACE( ensemble_config , config );
  
  ensemble_config_init_SUMMARY( ensemble_config , config , refcase );
  
  ensemble_config_init_FIELD( ensemble_config , config , grid );
  
  
  /* Containers - this must come last, to ensure that the other nodes have been added. */
  {
    for (i=0; i < config_get_occurences(config , CONTAINER_KEY ); i++) {
      const stringlist_type * container_kw_list = config_iget_stringlist_ref(config , CONTAINER_KEY , i);
      const char * container_key = stringlist_iget( container_kw_list , 0 );
      enkf_config_node_type * container_node = ensemble_config_add_container( ensemble_config , container_key );
      
      for (int j= 1; j < stringlist_get_size( container_kw_list ); j++) {
        const char * child_key = stringlist_iget( container_kw_list , j); 
        enkf_config_node_update_container( container_node , ensemble_config_get_node( ensemble_config , child_key ));
      }
    }
  }

  /*****************************************************************/
}
コード例 #2
0
ファイル: stringlist.c プロジェクト: akva2/ert
void stringlist_fprintf_fmt(const stringlist_type * stringlist, const stringlist_type * fmt_list , FILE * stream) {
  if (stringlist_get_size(stringlist) == stringlist_get_size( fmt_list )) {
    int i;
    for (i=0; i < stringlist_get_size( stringlist); i++)
      fprintf(stream , stringlist_iget( fmt_list , i) , stringlist_iget( stringlist , i ));
  } util_abort("%s: length of stringlist:%d   length of fmt_list:%d - must be equal \n",__func__ , stringlist_get_size( stringlist ) , stringlist_get_size( fmt_list ));
}
コード例 #3
0
ファイル: enkf_main_jobs.c プロジェクト: atgeirr/ResInsight
void * enkf_main_init_case_from_existing_JOB( void * self , const stringlist_type * args) {
  enkf_main_type * enkf_main = enkf_main_safe_cast( self );

  const char * source_case = stringlist_iget( args , 0 );
  enkf_fs_type * source_fs = enkf_main_mount_alt_fs( enkf_main , source_case , true );
  {
    enkf_fs_type * target_fs;

    if (stringlist_get_size(args) > 1) {
      const char * current_case = enkf_main_get_current_fs(enkf_main);
      const char * target_case = stringlist_iget( args , 1 );
      if (0 != strcmp(current_case, target_case)) {
        target_fs = enkf_main_mount_alt_fs( enkf_main , target_case , true );
      } else
        target_fs = enkf_fs_get_ref( enkf_main_get_fs(enkf_main) );  // Using get_ref so that we can unconditionally call decref() further down.
    } else
      target_fs = enkf_fs_get_ref( enkf_main_get_fs(enkf_main) );    // Using get_ref so that we can unconditionally call decref() further down.

    enkf_main_init_case_from_existing(enkf_main, source_fs, 0, ANALYZED, target_fs);
    enkf_fs_decref(target_fs);
  }
  enkf_fs_decref(source_fs);

  return NULL;
}
コード例 #4
0
ファイル: enkf_main_jobs.c プロジェクト: atgeirr/ResInsight
void * enkf_main_rank_on_data_JOB(void * self, const stringlist_type * args) {
  enkf_main_type * enkf_main = enkf_main_safe_cast( self );
  const char * ranking_name  = stringlist_iget(args, 0);
  const char * data_key      = stringlist_iget(args, 1);
  bool valid = true;
  bool sort_increasing       = stringlist_iget_as_bool(args, 2, &valid);

  if (!valid) {
    fprintf(stderr,"** Third argument \"sort increasing\" not recognized as bool value, job not started\n");
    return NULL;
  }

  int report_step = (stringlist_get_size(args) > 3) ? stringlist_iget_as_int(args, 3, &valid) : enkf_main_get_history_length(enkf_main) ;
  if (!valid) {
    fprintf(stderr,"** Fourth argument \"step\" not recognized as integer value, job not started\n");
    return NULL;
  }

  if (report_step < 0) {
    fprintf(stderr,"** Negative report step, job not started\n");
    return NULL;
  }

  enkf_main_rank_on_data(enkf_main, ranking_name, data_key, sort_increasing, report_step);
  return NULL;
}
コード例 #5
0
ファイル: enkf_main_jobs.c プロジェクト: atgeirr/ResInsight
void * enkf_main_std_scale_correlated_obs_JOB(void * self, const stringlist_type * args)  {

  if (stringlist_get_size(args) > 0) {
    enkf_main_type * enkf_main              = enkf_main_safe_cast( self );
    int ensemble_size                       = enkf_main_get_ensemble_size(enkf_main);
    enkf_fs_type * fs                       = enkf_main_get_fs( enkf_main );
    enkf_obs_type * obs                     = enkf_main_get_obs( enkf_main );
    int_vector_type * realizations          = int_vector_alloc(1, 0);
    local_obsdata_type * obsdata = local_obsdata_alloc( "OBS-JOB" );

    int_vector_init_range(realizations, 0, ensemble_size, 1);

    for (int iarg = 0; iarg < stringlist_get_size(args); iarg++) {
      const char * arg_key = stringlist_iget( args , iarg );
      stringlist_type * key_list = enkf_obs_alloc_matching_keylist(obs, arg_key);
      for (int iobs=0; iobs < stringlist_get_size( key_list ); iobs++) {
        const char * obs_key = stringlist_iget( key_list , iobs);
        const obs_vector_type * obs_vector = enkf_obs_get_vector(obs, obs_key);
        local_obsdata_add_node( obsdata , obs_vector_alloc_local_node(obs_vector) );
      }
      stringlist_free( key_list );
    }

    if (local_obsdata_get_size(obsdata) > 0)
      enkf_obs_scale_correlated_std(obs, fs, realizations, obsdata );

    local_obsdata_free( obsdata );
  }

  return NULL;
}
コード例 #6
0
ファイル: stringlist.c プロジェクト: akva2/ert
char * stringlist_alloc_joined_substring( const stringlist_type * s , int start_index , int end_index , const char * sep ) {
  if (start_index >= stringlist_get_size( s ))
    return NULL;
  {
    char * string = NULL;
    int i;

    /* Start with allocating a string long enough to hold all the substrings. */
    {
      int sep_length   = strlen( sep );
      int total_length = 0;
      for (i=start_index; i < end_index; i++)
        total_length += (strlen(stringlist_iget( s , i)) + sep_length);

      total_length += (1 - sep_length);
      string    = util_malloc( total_length * sizeof * string );
      string[0] = '\0';
    }

    for (i = start_index; i < end_index; i ++) {
      strcat( string , stringlist_iget( s , i));
      if (i < (end_index - 1))
        strcat( string , sep );
    }

    return string;
  }
}
コード例 #7
0
ファイル: stringlist.c プロジェクト: akva2/ert
void stringlist_insert_stringlist_copy(stringlist_type * stringlist, const stringlist_type * src, int pos) {
  int size_old  = stringlist_get_size(stringlist);

  /** Cannot use assert_index here. */
  if(pos < 0 || pos > size_old)
    util_abort("%s: Position %d is out of bounds. Min: 0 Max: %d\n", pos, size_old);
  {
  stringlist_type * start = stringlist_alloc_new();
  stringlist_type * end   = stringlist_alloc_new();
  stringlist_type * newList   = stringlist_alloc_new();
  int i;

  for( i=0; i<pos; i++)
    stringlist_append_ref(start, stringlist_iget(stringlist, i));

  for( i=pos; i<size_old; i++)
    stringlist_append_ref(end  , stringlist_iget(stringlist, i));

  stringlist_append_stringlist_copy(newList, start);
  stringlist_append_stringlist_copy(newList, src  );
  stringlist_append_stringlist_copy(newList, end  );

  stringlist_clear(stringlist);
  stringlist_append_stringlist_copy(stringlist, newList);

  stringlist_free(newList);
  stringlist_free(start);
  stringlist_free(end);
  }
}
コード例 #8
0
ファイル: enkf_main_jobs.c プロジェクト: atgeirr/ResInsight
void * enkf_main_export_ranking_JOB(void * self, const stringlist_type * args) {
  enkf_main_type * enkf_main = enkf_main_safe_cast( self );
  const char * ranking_name  = stringlist_iget(args, 0);
  const char * ranking_file  = stringlist_iget(args, 1);

  enkf_main_export_ranking(enkf_main, ranking_name, ranking_file);
  return NULL;
}
コード例 #9
0
ファイル: misfit_ranking.c プロジェクト: blattms/ert
void misfit_ranking_fprintf( const misfit_ranking_type * misfit_ranking , const char * filename) {
  FILE * stream                       = util_mkdir_fopen( filename , "w");
  const int ens_size                  = misfit_ranking->ens_size;
  const int * permutations            = misfit_ranking->sort_permutation;
  double summed_up = 0.0;
  {
    // All this whitespace is finely tuned and highly significant .... 
    const char * key_fmt       = " %18s ";                                
    const char * value_fmt     = " %10.3f %8.3f";
    const char * start_fmt     = " %2d       %3d     %7.3f %8.3f";  

    hash_type * obs_hash       = vector_iget( misfit_ranking->ensemble , 0);
    stringlist_type * obs_keys = hash_alloc_stringlist( obs_hash );
    int num_obs                = stringlist_get_size( obs_keys );
    int iobs;
    int num_obs_total = num_obs * ens_size;

    stringlist_sort( obs_keys , enkf_util_compare_keys__ );
    fprintf(stream , "                       Overall  ");
    for (iobs =0; iobs < num_obs; iobs++) 
      fprintf(stream , key_fmt , stringlist_iget( obs_keys , iobs ));

    fprintf(stream , "\n");
    fprintf(stream , "  #    Realization  Norm    Total");
    for (iobs =0; iobs < num_obs; iobs++) 
      fprintf(stream , "       Norm    Total");
    
    fprintf(stream , "\n");
    for (int i = 0; i < ens_size; i++) {
      int iens = permutations[i];
      hash_type * obs_hash = vector_iget( misfit_ranking->ensemble , iens );
      double total_value   = double_vector_iget( misfit_ranking->total , iens );
      double normalized_misfit = sqrt(total_value / num_obs_total);
      summed_up = summed_up+total_value;
      fprintf(stream , start_fmt , i , iens , normalized_misfit , total_value);
      for (iobs =0; iobs < num_obs; iobs++){
        double single_value = hash_get_double( obs_hash , stringlist_iget( obs_keys , iobs ));
        double single_value_normalized = sqrt(single_value / (num_obs_total));
        fprintf(stream , value_fmt , single_value_normalized , single_value);
      }
      fprintf(stream , "\n");
    }
    double summed_up_normalized = sqrt(summed_up / (num_obs_total * ens_size));
    fprintf(stream , "           All    %7.3f %8.3f" , summed_up_normalized , summed_up);
    for (iobs = 0; iobs < num_obs; iobs++){
      double single_value_summed_up = 0.0;      
      for (int i = 0; i < ens_size; i++) {  
        single_value_summed_up = single_value_summed_up + hash_get_double( obs_hash , stringlist_iget( obs_keys , iobs ));
      }
      double single_value_summed_up_normalized=sqrt(single_value_summed_up / (num_obs_total * ens_size));
      fprintf(stream , value_fmt , single_value_summed_up_normalized , single_value_summed_up);
    }
    fprintf(stream , "\n");
  }
  fclose( stream );
}
コード例 #10
0
ファイル: site_config.c プロジェクト: akva2/ResInsight
static void site_config_add_jobs(site_config_type * site_config , const config_type * config) {
  int  i;
  
  stringlist_type *item_list = config_alloc_complete_stringlist(config , INSTALL_JOB_KEY);

  for (i=0; i < stringlist_get_size(item_list); i+=2) 
    site_config_install_job(site_config , stringlist_iget(item_list , i) , stringlist_iget(item_list , i + 1));

  stringlist_free(item_list);
}
コード例 #11
0
ファイル: enkf_main_jobs.c プロジェクト: chflo/ert
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);
}
コード例 #12
0
ファイル: ecl_sum_data.c プロジェクト: akva2/ResInsight
static void ecl_sum_data_fread__( ecl_sum_data_type * data , time_t load_end , const stringlist_type * filelist) {
  ecl_file_enum file_type;

  if (stringlist_get_size( filelist ) == 0)
    util_abort("%s: internal error - function called with empty list of data files.\n",__func__);
  
  file_type = ecl_util_get_file_type( stringlist_iget( filelist , 0 ) , NULL , NULL);
  if ((stringlist_get_size( filelist ) > 1) && (file_type != ECL_SUMMARY_FILE))
    util_abort("%s: internal error - when calling with more than one file - you can not supply a unified file - come on?! \n",__func__);
  {
    int filenr;
    if (file_type == ECL_SUMMARY_FILE) {
      
      /* Not unified. */
      for (filenr = 0; filenr < stringlist_get_size( filelist ); filenr++) {
        const char * data_file = stringlist_iget( filelist , filenr);
        ecl_file_enum file_type;
        int report_step;
        file_type = ecl_util_get_file_type( data_file , NULL , &report_step);
        /** 
            ECLIPSE starts a report step by writing an empty summary
            file, therefor we must verify that the ecl_file instance
            returned by ecl_file_fread_alloc() is different from NULL
            before adding it to the ecl_sum_data instance.
        */
        if (file_type != ECL_SUMMARY_FILE)
          util_abort("%s: file:%s has wrong type \n",__func__ , data_file);
        {
          ecl_file_type * ecl_file = ecl_file_open( data_file );
          ecl_sum_data_add_ecl_file( data , load_end , report_step , ecl_file , data->smspec);
          ecl_file_close( ecl_file );
        }
      }
    } else if (file_type == ECL_UNIFIED_SUMMARY_FILE) {
      ecl_file_type * ecl_file = ecl_file_open( stringlist_iget(filelist ,0 ));
      int report_step = 1;   /* <- ECLIPSE numbering - starting at 1. */
      while (true) {
        /*
          Observe that there is a number discrepancy between ECLIPSE
          and the ecl_file_select_smryblock() function. ECLIPSE
          starts counting report steps at 1; whereas the first
          SEQHDR block in the unified summary file is block zero (in
          ert counting). 
        */
        if (ecl_file_select_smryblock( ecl_file , report_step - 1)) {
          ecl_sum_data_add_ecl_file( data , load_end , report_step , ecl_file , data->smspec); 
          report_step++; 
        } else break; 
      }
      ecl_file_close( ecl_file ); 
    } else 
      util_abort("%s: invalid file type:%s \n",__func__ , ecl_util_file_type_name(file_type )); 
  } 
  ecl_sum_data_build_index( data );
}
コード例 #13
0
ファイル: enkf_main_jobs.c プロジェクト: Ensembles/ert
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   * source_fs = enkf_main_mount_alt_fs( enkf_main , stringlist_iget(args , 0 ) , false);
  enkf_fs_type   * target_fs = enkf_main_mount_alt_fs( enkf_main , stringlist_iget(args , 1 ) , true);

  enkf_main_smoother_update( enkf_main , source_fs , target_fs);

  enkf_fs_decref( source_fs );
  enkf_fs_decref( target_fs );
  return NULL;
}
コード例 #14
0
ファイル: stringlist.c プロジェクト: akva2/ert
static void stringlist_fprintf__(const stringlist_type * stringlist, const char * sep , FILE * stream) {
  int length = vector_get_size( stringlist->strings );
  if (length > 0) {
    int i;
    for (i=0; i < length - 1; i++) {
      const char * s = stringlist_iget(stringlist , i);
      fprintf(stream , "%s%s", s  , sep);
    }

    fprintf(stream , "%s", stringlist_iget( stringlist , length - 1 ));
  }
}
コード例 #15
0
ファイル: sched_history.c プロジェクト: Ensembles/ert
static void sched_history_add_groups_welspecs( sched_history_type * sched_history , const sched_kw_welspecs_type * welspecs , int report_step , const stringlist_type * wells, const stringlist_type * groups) {
  for (int i = 0; i < stringlist_get_size( groups ); i++) {
    const char * group_name  = stringlist_iget( groups , i );
    const char * well_name   = stringlist_iget( wells , i );
    well_history_type * well = sched_history_get_well( sched_history , well_name );
    group_history_type * group;
    if (!hash_has_key( sched_history->group_history , group_name )) 
      sched_history_add_group( sched_history , group_history_alloc( group_name , sched_history->time , report_step ) , NULL , report_step );
    
    group = sched_history_get_group( sched_history , group_name );
    group_history_add_child( group , well , well_name , report_step);
  }
}
コード例 #16
0
ファイル: ecl_quantile.c プロジェクト: akva2/ResInsight
void output_table_init( const ecl_sum_type * refcase, hash_type * output_table , const config_type * config ) {
  int i,j;
  for (i=0; i < config_get_occurences( config , "OUTPUT" ); i++) {
    const stringlist_type * tokens = config_iget_stringlist_ref( config , "OUTPUT" , i);
    const char * file              = stringlist_iget( tokens , 0 );
    const char * format_string     = stringlist_iget( tokens , 1 );
    output_type * output           = output_alloc( file , format_string );
    
    /* All the keys are just added - without any check. */
    for (j = 2; j < stringlist_get_size( tokens ); j++)
      output_add_key( refcase , output , stringlist_iget( tokens , j));
    
    hash_insert_hash_owned_ref( output_table , file , output , output_free__ );
  }
}
コード例 #17
0
ファイル: enkf_main_jobs.c プロジェクト: atgeirr/ResInsight
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;
}
コード例 #18
0
ファイル: ecl_quantile.c プロジェクト: akva2/ResInsight
void ensemble_init( ensemble_type * ensemble , config_type * config) {

  /*1 : Loading ensembles and settings from the config instance */
  /*1a: Loading the eclipse summary cases. */
  {
    thread_pool_type * tp = thread_pool_alloc( LOAD_THREADS , true );
    {
      int i,j;
      for (i=0; i < config_get_occurences( config , "CASE_LIST"); i++) {
        const stringlist_type * case_list = config_iget_stringlist_ref( config , "CASE_LIST" , i );
        for (j=0; j < stringlist_get_size( case_list ); j++) 
          ensemble_load_from_glob( ensemble , stringlist_iget( case_list , j ) , tp);
      }
    }
    thread_pool_join( tp );
    thread_pool_free( tp );
  }
  
  {
    const sum_case_type * tmp = vector_iget_const( ensemble->data , 0 );
    ensemble->refcase = tmp->ecl_sum;
  }
  
  /*1b: Other config settings */
  if (config_item_set( config , "NUM_INTERP" ))
    ensemble->num_interp  = config_iget_as_int( config , "NUM_INTERP" , 0 , 0 );
  
  
  /*2: Remaining initialization */
  ensemble_init_time_interp( ensemble );
  if (vector_get_size( ensemble->data ) < MIN_SIZE )
    util_exit("Sorry - quantiles make no sense with with < %d realizations; should have ~> 100.\n" , MIN_SIZE);
}
コード例 #19
0
ファイル: summary_key_set.c プロジェクト: Ensembles/ert
bool summary_key_set_fread(summary_key_set_type * set, const char * filename) {
    bool file_exists = false;
    pthread_rwlock_wrlock( &set->rw_lock );
    {
        hash_clear(set->key_set);

        if (util_file_exists(filename)) {
            FILE * stream = util_fopen(filename, "r");
            if (stream) {
                stringlist_type * key_set = stringlist_fread_alloc(stream);

                for (int i = 0; i < stringlist_get_size(key_set); i++) {
                    hash_insert_int(set->key_set, stringlist_iget(key_set, i), 1);
                }
                stringlist_free(key_set);
                fclose( stream );
            } else {
                util_abort("%s: failed to open: %s for reading \n",__func__ , filename );
            }
            file_exists = true;
        }
    }
    pthread_rwlock_unlock( &set->rw_lock );
    return file_exists;
}
コード例 #20
0
void test_reverse() {
  const char *s0 = "AAA";
  const char *s1 = "BBB";
  const char *s2 = "CCC";

  stringlist_type * s = stringlist_alloc_new();
  stringlist_append_copy( s , s0 );
  stringlist_append_copy( s , s1 );
  stringlist_append_copy( s , s2 );

  stringlist_reverse(s);

  test_assert_string_equal( s2 , stringlist_iget(s , 0 ));
  test_assert_string_equal( s1 , stringlist_iget(s , 1 ));
  test_assert_string_equal( s0 , stringlist_iget(s , 2 ));
}
コード例 #21
0
ファイル: enkf_main_jobs.c プロジェクト: atgeirr/ResInsight
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);
}
コード例 #22
0
ファイル: enkf_main_jobs.c プロジェクト: atgeirr/ResInsight
static void * enkf_main_smoother_JOB__( void * self , int iter , const stringlist_type * args ) {
  enkf_main_type   * enkf_main = enkf_main_safe_cast( self );
  int ens_size                 = enkf_main_get_ensemble_size( enkf_main );
  bool_vector_type * iactive   = bool_vector_alloc( ens_size , true );
  bool valid                   = true;
  const char * target_case;
  enkf_fs_type * target_fs     = enkf_main_get_fs( enkf_main );


  // Argument 0: Which case to write to. Default current case.
  if (stringlist_get_size(args)) {
    target_case = stringlist_iget( args , 0 );
    if (strcmp( target_case , CURRENT_CASE_STRING) == 0)
      target_case = enkf_fs_get_case_name(target_fs);
  } else
    target_case = enkf_fs_get_case_name(target_fs);

  //Argument 1: Rerun. Default false.
  bool rerun = (stringlist_get_size(args) >= 2) ? stringlist_iget_as_bool(args, 1, &valid) : false;

  if (!valid) {
      fprintf(stderr, "** Warning: Function %s : Second argument must be a bool value. Exiting job\n", __func__);
      return NULL;
  }
  enkf_main_run_smoother( enkf_main , target_case , iactive , iter , rerun);
  bool_vector_free( iactive );
  return NULL;
}
コード例 #23
0
ファイル: enkf_main_jobs.c プロジェクト: atgeirr/ResInsight
void * enkf_main_create_case_JOB( void * self , const stringlist_type * args) {
  enkf_main_type * enkf_main = enkf_main_safe_cast( self );
  const char * new_case = stringlist_iget( args , 0 );
  enkf_fs_type * fs = enkf_main_mount_alt_fs( enkf_main , new_case , true );
  enkf_fs_decref( fs );
  return NULL;
}
コード例 #24
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RifEclipseOutputFileTools::readGridDimensions(const QString& gridFileName, std::vector< std::vector<int> >& gridDimensions)
{
    ecl_grid_type * grid         = ecl_grid_alloc(RiaStringEncodingTools::toNativeEncoded(gridFileName).data());                               // bootstrap ecl_grid instance
    stringlist_type * lgr_names  = ecl_grid_alloc_lgr_name_list( grid );                                   // get a list of all the lgr names.

    //printf("grid:%s has %d a total of %d lgr's \n", grid_filename , stringlist_get_size( lgr_names ));
    for (int lgr_nr = 0; lgr_nr < stringlist_get_size( lgr_names); lgr_nr++)
    {
        ecl_grid_type * lgr_grid  = ecl_grid_get_lgr( grid , stringlist_iget( lgr_names , lgr_nr ));    // get the ecl_grid instance of the lgr - by name.

        int nx,ny,nz,active_size;
        ecl_grid_get_dims( lgr_grid , &nx , &ny , &nz , &active_size);                             // get some size info from this lgr.

        std::vector<int> values;
        values.push_back(nx);
        values.push_back(ny);
        values.push_back(nz);
        values.push_back(active_size);

        gridDimensions.push_back(values);
    }

    ecl_grid_free( grid );
    stringlist_free( lgr_names );

}
コード例 #25
0
ファイル: misfit_ranking.c プロジェクト: blattms/ert
misfit_ranking_type *  misfit_ranking_alloc(const misfit_ensemble_type * misfit_ensemble , const stringlist_type * sort_keys , const int_vector_type * steps, const char * ranking_key) {
  const int ens_size = misfit_ensemble_get_ens_size( misfit_ensemble );
  int iens;
  misfit_ranking_type * ranking = misfit_ranking_alloc_empty(ens_size);
  
  for (iens = 0; iens < ens_size; iens++) {
    const misfit_member_type * misfit_member = misfit_ensemble_iget_member( misfit_ensemble , iens );  /* Lookup in the master ensemble. */
    
    {
      double iens_valid = true;
      double total = 0;
      hash_type * obs_hash = hash_alloc();
      for (int ikey = 0; ikey < stringlist_get_size( sort_keys ); ikey++) {
        const char * obs_key        = stringlist_iget( sort_keys , ikey );
        if (misfit_member_has_ts( misfit_member , obs_key )) {
          misfit_ts_type * ts = misfit_member_get_ts( misfit_member , obs_key );
          double value        = misfit_ts_eval( ts , steps );  /* Sum up the misfit for this key - and these timesteps. */
          hash_insert_double( obs_hash , obs_key , value);
          total += value;
        } else
          iens_valid = true;
      }
      if (iens_valid) 
        misfit_ranking_iset( ranking , iens , obs_hash , total );
      else
        misfit_ranking_iset_invalid( ranking , iens );
    }
  }
  ranking->sort_permutation = double_vector_alloc_sort_perm( ranking->total );

  return ranking;
}
コード例 #26
0
ファイル: custom_kw_config.c プロジェクト: Ensembles/ert
void custom_kw_config_deserialize(custom_kw_config_type * config, stringlist_type * config_set) {
    pthread_rwlock_wrlock(& config->rw_lock);
    {
        custom_kw_config_reset__(config);

        for (int i = 0; i < stringlist_get_size(config_set); i++) {
            const char * items = stringlist_iget(config_set, i);

            char key[128];
            int index;
            int is_double;

            int count = sscanf(items, "%s %d %d", key, &index, &is_double);
            
            if (count == 3) {
              hash_insert_int(config->custom_keys, key, index);
              hash_insert_int(config->custom_key_types, key, is_double);
            } else
              util_abort("%s: internal error - deserialize failed\n",__func__);
        }
        config->undefined = false;
        config->key_definition_file = util_alloc_string_copy("from storage"); //Todo: Handle this differently?
    }
    pthread_rwlock_unlock(& config->rw_lock);
}
コード例 #27
0
ファイル: ensemble_config.c プロジェクト: danielfmva/ert
void ensemble_config_init_SUMMARY( ensemble_config_type * ensemble_config , const config_type * config , const ecl_sum_type * refcase) {
  const config_content_item_type * item = config_get_content_item( config , SUMMARY_KEY );

  if (item != NULL) {
    int i;
    for (i=0; i < config_content_item_get_size( item ); i++) {
      const 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 * key = config_content_node_iget( node , j );
        
        if (util_string_has_wildcard( key )) {
          if (ensemble_config->refcase != NULL) {
            int k;
            stringlist_type * keys = stringlist_alloc_new ( );

            ecl_sum_select_matching_general_var_list( ensemble_config->refcase , key , keys );   /* expanding the wildcard notatition with help of the refcase. */
            for (k=0; k < stringlist_get_size( keys ); k++) 
              ensemble_config_add_summary(ensemble_config , stringlist_iget(keys , k) , LOAD_FAIL_SILENT );

            stringlist_free( keys );
          } else
            util_exit("error: when using summary wildcards like: \"%s\" you must supply a valid refcase.\n",key);
        } else 
          ensemble_config_add_summary(ensemble_config , key , LOAD_FAIL_SILENT);
      }
    }
  }
}
コード例 #28
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
std::vector<std::string> RifEclipseSummaryTools::findSummaryDataFiles(const std::string& caseFile)
{
    std::vector<std::string> fileNames;

    std::string path;
    std::string base;

    findSummaryHeaderFileInfo(caseFile, NULL, &path, &base, NULL);
    if (path.empty() || base.empty()) return fileNames;

    char* header_file = NULL;
    stringlist_type* summary_file_list = stringlist_alloc_new();

    ecl_util_alloc_summary_files(path.data(), base.data(), NULL, &header_file, summary_file_list);
    if (stringlist_get_size( summary_file_list ) > 0)
    {
        for (int i = 0; i < stringlist_get_size(summary_file_list); i++)
        {
            fileNames.push_back(stringlist_iget(summary_file_list, i));
        }
    }

    util_safe_free(header_file);
    stringlist_free(summary_file_list);

    return fileNames;
}
コード例 #29
0
ファイル: sched_history.c プロジェクト: Ensembles/ert
void sched_history_fprintf( const sched_history_type * sched_history , const stringlist_type * key_list , FILE * stream) {
  int step = 1;
  time_t start_time = time_t_vector_iget( sched_history->time , 0);
  int total_length = bool_vector_size( sched_history->historical );
  while (true) {
    if (bool_vector_safe_iget( sched_history->historical , step)) {
      {
        int mday,month,year;
        time_t t = time_t_vector_iget( sched_history->time , step );
        double days = (t - start_time) * 1.0 / 86400;
        util_set_date_values_utc( t , &mday , &month , &year);
        //fprintf(stream , "%02d-%02d-%4d  " , mday , month , year );
        fprintf(stream , " %5.0f " , days);
      }
      
      for (int ikey =0; ikey < stringlist_get_size( key_list ); ikey++) 
        fprintf(stream , "%16.3f " , sched_history_iget( sched_history , stringlist_iget( key_list , ikey) , step));
      
      fprintf( stream, "\n");
    } else
      break; // We have completed the historical period - and switched to prediction
    step++;

    if (step == total_length)
      break;
  }
}
コード例 #30
0
ファイル: ecl_quantile.c プロジェクト: YingfangZhou/ert
static void output_add_key( const ecl_sum_type * refcase , output_type * output , const char * qkey) {
  int tokens;
  double  quantile;
  char ** tmp;
  char  * sum_key;

  util_split_string( qkey , SUMMARY_JOIN , &tokens , &tmp);
  if (tokens == 1)
    util_exit("Hmmm - the key:%s is malformed - must be of the form SUMMARY_KEY:QUANTILE.\n",qkey);

  if (!util_sscanf_double( tmp[tokens - 1] , &quantile))
    util_exit("Hmmmm - failed to interpret:%s as a quantile - must be a number (0,1).\n",tmp[tokens-1]);

  if (quantile <= 0 || quantile >= 1.0)
    util_exit("Invalid quantile value:%g - must be in interval (0,1)\n", quantile);

  sum_key = util_alloc_joined_string( (const char **) tmp , tokens - 1 , SUMMARY_JOIN);
  {
    stringlist_type * matching_keys = stringlist_alloc_new();
    int i;
    ecl_sum_select_matching_general_var_list( refcase , sum_key , matching_keys );
    for (i=0; i < stringlist_get_size( matching_keys ); i++)
      vector_append_owned_ref( output->keys , quant_key_alloc( stringlist_iget( matching_keys , i ) , quantile) , quant_key_free__ );

    if (stringlist_get_size( matching_keys ) == 0)
      fprintf(stderr,"** Warning: No summary vectors matching:\'%s\' found?? \n", sum_key);
    stringlist_free( matching_keys );
  }

  util_free_stringlist( tmp, tokens );
}