コード例 #1
0
void test_split() {
  stringlist_type *  s1 = stringlist_alloc_from_split("My Name    is Joakim Hove" , " ");
  test_assert_int_equal( 5 , stringlist_get_size( s1 ));
  test_assert_string_equal( "My" , stringlist_iget( s1 , 0 ));
  test_assert_string_equal( "Name" , stringlist_iget( s1  , 1 ));
  test_assert_string_equal( "is" , stringlist_iget( s1  , 2 ));
  test_assert_string_equal( "Joakim" , stringlist_iget( s1  , 3 ));
  test_assert_string_equal( "Hove" , stringlist_iget( s1  , 4 ));
  stringlist_free( s1 );


  s1 = stringlist_alloc_from_split("StringWithNoSPlit" , " ");
  test_assert_int_equal( 1 , stringlist_get_size( s1 ));
  test_assert_string_equal( "StringWithNoSPlit" , stringlist_iget( s1 , 0 ));
  stringlist_free( s1 );

  s1 = stringlist_alloc_from_split("A:B::C:D:" , ":");
  test_assert_int_equal( 4 , stringlist_get_size( s1 ));
  test_assert_string_equal( "A" , stringlist_iget( s1 , 0 ));
  test_assert_string_equal( "B" , stringlist_iget( s1 , 1 ));
  test_assert_string_equal( "C" , stringlist_iget( s1 , 2 ));
  test_assert_string_equal( "D" , stringlist_iget( s1 , 3 ));
  stringlist_free( s1 );

  s1 = stringlist_alloc_from_split("A:B::C:D:" , "::");
  test_assert_int_equal( 4 , stringlist_get_size( s1 ));
  test_assert_string_equal( "A" , stringlist_iget( s1 , 0 ));
  test_assert_string_equal( "B" , stringlist_iget( s1 , 1 ));
  test_assert_string_equal( "C" , stringlist_iget( s1 , 2 ));
  test_assert_string_equal( "D" , stringlist_iget( s1 , 3 ));
  stringlist_free( s1 );
}
コード例 #2
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;
}
コード例 #3
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 ));
}
コード例 #4
0
ファイル: summaryComparator.cpp プロジェクト: rolk/opm-cmake
SummaryComparator::SummaryComparator(const std::string& basename1,
                                     const std::string& basename2,
                                     double absoluteTol, double relativeTol){
    ecl_sum1 = ecl_sum_fread_alloc_case(basename1.c_str(), ":");
    ecl_sum2 = ecl_sum_fread_alloc_case(basename2.c_str(), ":");
    if (ecl_sum1 == nullptr || ecl_sum2 == nullptr) {
        OPM_THROW(std::runtime_error, "Not able to open files");
    }
    absoluteTolerance = absoluteTol;
    relativeTolerance = relativeTol;
    keys1 = stringlist_alloc_new();
    keys2 = stringlist_alloc_new();
    ecl_sum_select_matching_general_var_list( ecl_sum1 , "*" , this->keys1);
    stringlist_sort(this->keys1 , nullptr );
    ecl_sum_select_matching_general_var_list( ecl_sum2 , "*" , this->keys2);
    stringlist_sort(this->keys2 , nullptr );

    if(stringlist_get_size(keys1) <= stringlist_get_size(keys2)){
        this->keysShort = this->keys1;
        this->keysLong = this->keys2;
    }else{
        this->keysShort = this->keys2;
        this->keysLong = this->keys1;
    }
}
コード例 #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
ファイル: 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 );
}
コード例 #7
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
QStringList RifEclipseSummaryTools::findSummaryDataFiles(const QString& caseFile)
{
    QStringList fileNames;

    QString path;
    QString base;

    findSummaryHeaderFileInfo(caseFile, nullptr, &path, &base, nullptr);
    if (path.isEmpty() || base.isEmpty()) return fileNames;

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

    ecl_util_alloc_summary_files(RiaStringEncodingTools::toNativeEncoded(path).data(), RiaStringEncodingTools::toNativeEncoded(base).data(), nullptr, &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(RiaStringEncodingTools::fromNativeEncoded(stringlist_iget(summary_file_list, i)));
        }
    }

    util_safe_free(header_file);
    stringlist_free(summary_file_list);

    return fileNames;
}
コード例 #8
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;
}
コード例 #9
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;
}
コード例 #10
0
ファイル: enkf_main_jobs.c プロジェクト: atgeirr/ResInsight
void * enkf_main_rank_on_observations_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);

  bool step_arguments = false;
  bool obs_arguments  = false;
  int  delimiter      = 0;
  {
    delimiter = stringlist_find_first(args, "|");
    if (delimiter > -1) {
      step_arguments = (delimiter > 1) ? true : false;
      obs_arguments  = (stringlist_get_size(args) > delimiter + 1) ? true : false;
    } else if (stringlist_get_size(args) > 1) {
        step_arguments = true;
        delimiter     = stringlist_get_size(args);
    }
  }

  int_vector_type * steps_vector = NULL;
  {
    char * report_steps = NULL;

    if (step_arguments)
      report_steps = stringlist_alloc_joined_substring(args, 1, delimiter, ",");
    else
      report_steps = util_alloc_sprintf("0-%d", enkf_main_get_history_length(enkf_main));

    steps_vector = string_util_alloc_value_list(report_steps);

    free(report_steps);
  }


  stringlist_type * obs_ranking_keys = NULL;
  {
    char * obs_key_char = NULL;
    if (obs_arguments)
      obs_key_char = stringlist_alloc_joined_substring( args , delimiter+1 , stringlist_get_size(args) , " ");

    enkf_obs_type * enkf_obs = enkf_main_get_obs(enkf_main);
    obs_ranking_keys = enkf_obs_alloc_matching_keylist( enkf_obs , obs_key_char );

    if ((obs_arguments) && (stringlist_get_size(obs_ranking_keys) == 0)) {
      fprintf(stderr,"The input string : \"%s\" did not resolve to any valid observation keys. Job not started\n", obs_key_char);
      return NULL;
    }

    if (obs_arguments)
      free(obs_key_char);
  }


  enkf_main_rank_on_observations(enkf_main, ranking_name, obs_ranking_keys, steps_vector);

  stringlist_free(obs_ranking_keys);
  int_vector_free(steps_vector);
  return NULL;
}
コード例 #11
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 );
}
コード例 #12
0
ファイル: enkf_main_jobs.c プロジェクト: shulNN/ert
static bool_vector_type * alloc_iactive_vector_from_range(const stringlist_type * range, int startindex, int ens_size) {
  bool_vector_type * iactive;
  if (stringlist_get_size(range) > startindex) {
    char * arg_string = stringlist_alloc_joined_substring( range, startindex, stringlist_get_size(range), "");
    iactive = bool_vector_alloc(ens_size, false);
    string_util_update_active_mask( arg_string, iactive );
    free ( arg_string );
  } else {
    iactive = bool_vector_alloc(ens_size, true);
  }
  return iactive;
}
コード例 #13
0
ファイル: ecl_sum.c プロジェクト: flikka/ert
void ecl_sum_fprintf(const ecl_sum_type * ecl_sum , FILE * stream , const stringlist_type * var_list , bool report_only , const ecl_sum_fmt_type * fmt) {
  bool_vector_type  * has_var   = bool_vector_alloc( stringlist_get_size( var_list ), false );
  int_vector_type   * var_index = int_vector_alloc( stringlist_get_size( var_list ), -1 );
  char * date_string            = util_malloc( DATE_STRING_LENGTH * sizeof * date_string);

  char * current_locale = NULL;
  if (fmt->locale != NULL)
    current_locale = setlocale(LC_NUMERIC , fmt->locale);

  {
    int ivar;
    for (ivar = 0; ivar < stringlist_get_size( var_list ); ivar++) {
      if (ecl_sum_has_general_var( ecl_sum , stringlist_iget( var_list , ivar) )) {
        bool_vector_iset( has_var , ivar , true );
        int_vector_iset( var_index , ivar , ecl_sum_get_general_var_params_index( ecl_sum , stringlist_iget( var_list , ivar) ));
      } else {
        fprintf(stderr,"** Warning: could not find variable: \'%s\' in summary file \n", stringlist_iget( var_list , ivar));
        bool_vector_iset( has_var , ivar , false );
      }
    }
  }

  if (fmt->print_header)
    ecl_sum_fprintf_header( ecl_sum , var_list , has_var , stream , fmt);

  if (report_only) {
    int first_report = ecl_sum_get_first_report_step( ecl_sum );
    int last_report  = ecl_sum_get_last_report_step( ecl_sum );
    int report;

    for (report = first_report; report <= last_report; report++) {
      if (ecl_sum_data_has_report_step(ecl_sum->data , report)) {
        int time_index;
        time_index = ecl_sum_data_iget_report_end( ecl_sum->data , report );
        __ecl_sum_fprintf_line( ecl_sum , stream , time_index , has_var , var_index , date_string , fmt);
      }
    }
  } else {
    int time_index;
    for (time_index = 0; time_index < ecl_sum_get_data_length( ecl_sum ); time_index++)
      __ecl_sum_fprintf_line( ecl_sum , stream , time_index , has_var , var_index , date_string , fmt);
  }

  int_vector_free( var_index );
  bool_vector_free( has_var );
  if (current_locale != NULL)
    setlocale( LC_NUMERIC , current_locale);
  free( date_string );
}
コード例 #14
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);
      }
    }
  }
}
コード例 #15
0
ファイル: ecl_util.c プロジェクト: danielfmva/ert
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; 
}
コード例 #16
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;
  }
}
コード例 #17
0
ファイル: ecl_util.c プロジェクト: danielfmva/ert
static int ecl_util_get_num_slave_cpu__(parser_type* parser, FILE* stream, const char * data_file) {
  int num_cpu = 0;
  int linecount = 0; 

  parser_fseek_string( parser , stream , "\n" , true , true);  /* Go to next line after the SLAVES keyword*/

  while (true) {
    char * buffer = util_fscanf_alloc_line( stream , NULL);
    ++linecount; 
    if (linecount > 10) 
      util_abort("%s: Did not find ending \"/\" character after SLAVES keyword, aborting \n", __func__);

    {
      stringlist_type * tokens = parser_tokenize_buffer( parser , buffer , true );
      if (stringlist_get_size(tokens) > 0 ) {
        
        const char * first_item = stringlist_iget(tokens, 0);
        
        if (first_item[0] == '/') {
          break; 
        }
        else 
          ++num_cpu;
      }
      stringlist_free( tokens );
    }
      
    free( buffer );
  } 
  
  if (0 == num_cpu)
    util_abort("%s: Did not any CPUs after SLAVES keyword, aborting \n", __func__);
  return num_cpu; 
}
コード例 #18
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);
}
コード例 #19
0
ファイル: stringlist.c プロジェクト: akva2/ert
int stringlist_select_matching_files(stringlist_type * names , const char * path , const char * file_pattern) {
#ifdef ERT_HAVE_GLOB
  char * pattern  = util_alloc_filename( path , file_pattern , NULL );
  int match_count = stringlist_select_matching( names , pattern );
  free( pattern );
  return match_count;
#else
  {
    WIN32_FIND_DATA file_data;
    HANDLE          file_handle;
    char * pattern  = util_alloc_filename( path , file_pattern , NULL );

    stringlist_clear( names );
    file_handle = FindFirstFile( pattern , &file_data );
    if (file_handle != INVALID_HANDLE_VALUE) {
      do {
        char * full_path = util_alloc_filename( path , file_data.cFileName , NULL);
        stringlist_append_owned_ref( names , full_path );
      } while (FindNextFile( file_handle , &file_data) != 0);
    }
    FindClose( file_handle );
    free( pattern );

    return stringlist_get_size( names );
  }
#endif
}
コード例 #20
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 ));
      }
    }
  }

  /*****************************************************************/
}
コード例 #21
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;
}
コード例 #22
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);
}
コード例 #23
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 );

}
コード例 #24
0
ファイル: ensemble_config.c プロジェクト: chflo/ert
void ensemble_config_init_SUMMARY( ensemble_config_type * ensemble_config , const config_content_type * config , const ecl_sum_type * refcase) {
  if (config_content_has_item(config , SUMMARY_KEY)) {
    const config_content_item_type * item = config_content_get_item( config , SUMMARY_KEY );
    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 );
        summary_key_matcher_add_summary_key(ensemble_config->summary_key_matcher, key);

        if (util_string_has_wildcard( key )) {
            //todo: DEPRECATED. In the Future the matcher should take care of this.
          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 notation 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
          ensemble_config_add_summary(ensemble_config , key , LOAD_FAIL_SILENT);
      }
    }
  }
}
コード例 #25
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;
}
コード例 #26
0
ファイル: stringlist.c プロジェクト: akva2/ert
void stringlist_buffer_fwrite( const stringlist_type * s , buffer_type * buffer ) {
  int i;
  int size = stringlist_get_size( s );
  buffer_fwrite_int( buffer , size );
  for (i=0; i < size; i++)
    buffer_fwrite_string(buffer , stringlist_iget(s , i) );
}
コード例 #27
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;
}
コード例 #28
0
ファイル: stringlist.c プロジェクト: akva2/ert
void stringlist_fwrite(const stringlist_type * s, FILE * stream) {
  int i;
  int size = stringlist_get_size( s );
  util_fwrite_int( size , stream);
  for (i=0; i < size; i++)
    util_fwrite_string(stringlist_iget(s , i) , stream);
}
コード例 #29
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;
}
コード例 #30
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;
  }
}