Example #1
0
File: main.c Project: pgdr/ert
int main (int argc, char ** argv) {
  text_splash();
  init_debug(argv[0]);
  printf("\n");
  printf("Documentation : %s \n","http://ert.nr.no");
  printf("git commit    : %s \n",ert_version_get_git_commit( ));
  printf("compile time  : %s \n",ert_version_get_build_time( ));
  printf("site config   : %s \n", site_config_get_location());

  enkf_main_install_SIGNALS();                     /* Signals common to both tui and gui. */
  signal(SIGINT, util_abort_signal);              /* Control C - tui only.               */
  if (argc < 2) {
    enkf_usage();
    exit(1);
  } else {
    const char * model_config_file = argv[1];
    stringlist_type * workflow_list = stringlist_alloc_new();

    parse_workflows(argc, argv, workflow_list);
    if (!(util_entry_readable(model_config_file) && util_is_file(model_config_file)))
      util_exit("Can not read file %s - exiting \n", model_config_file);

    {
      char * abs_config = util_alloc_realpath(model_config_file);
      printf("model config  : %s \n\n", abs_config);
      free(abs_config);
    }
    enkf_welcome(model_config_file);
    {
      res_config_type * res_config = res_config_alloc_load(model_config_file);
      util_chdir( res_config_get_config_directory( res_config ));
      {
        enkf_main_type * enkf_main = enkf_main_alloc(res_config, true, true);
        enkf_main_run_workflows(enkf_main, workflow_list);
        enkf_tui_main_menu(enkf_main);
        enkf_main_free(enkf_main);
        res_config_free(res_config);
      }
    }

    stringlist_free(workflow_list);
    util_abort_free_version_info(); /* No f*****g leaks ... */
  }
  exit(0);
}
Example #2
0
ert_run_context_type * ert_run_context_alloc_ENSEMBLE_EXPERIMENT(enkf_fs_type * fs , const bool_vector_type * iactive ,
                                                                 path_fmt_type * runpath_fmt ,
                                                                 subst_list_type * subst_list ,
                                                                 int iter) {

  ert_run_context_type * context = ert_run_context_alloc( iactive , ENSEMBLE_EXPERIMENT , fs , fs , NULL , iter);
  {
    stringlist_type * runpath_list = ert_run_context_alloc_runpath_list( iactive , runpath_fmt , subst_list , iter );
    for (int iens = 0; iens < bool_vector_size( iactive ); iens++) {
      if (bool_vector_iget( iactive , iens )) {
        run_arg_type * arg = run_arg_alloc_ENSEMBLE_EXPERIMENT( fs , iens , iter , stringlist_iget( runpath_list , iens));
        vector_append_owned_ref( context->run_args , arg , run_arg_free__);
      }
    }
    stringlist_free( runpath_list );
  }
  return context;
}
Example #3
0
void ensemble_config_update_custom_kw_config(ensemble_config_type * config, custom_kw_config_set_type * config_set) {
    stringlist_type * keys = custom_kw_config_set_get_keys_alloc(config_set);

    for(int i = 0; i < stringlist_get_size(keys); i++) {
        const char * key = stringlist_iget(keys, i);
        if(!ensemble_config_has_key(config, key)) {
            ensemble_config_add_custom_kw(config, key, NULL, NULL);
            printf("[%s] CustomKW key: '%s' not in ensemble! Adding from storage.\n", __func__, key);
        }

        enkf_config_node_type * config_node = ensemble_config_get_node(config, key);
        custom_kw_config_type * custom_kw_config = (custom_kw_config_type*) enkf_config_node_get_ref(config_node);

        custom_kw_config_set_update_config(config_set, custom_kw_config);
    }

    stringlist_free(keys);
}
void test_rank_realizations_on_data_job(ert_test_context_type * test_context , const char * job_name , const char * job_file) {
  stringlist_type * args = stringlist_alloc_new();
  ert_test_context_install_workflow_job( test_context , job_name , job_file );

  stringlist_append_copy( args , "NameOfDataRanking");
  stringlist_append_copy( args , "PORO:1,2,3");
  stringlist_append_copy( args , "false");
  stringlist_append_copy( args , "0");
  test_assert_true( ert_test_context_run_worklow_job( test_context , job_name , args) );

  stringlist_clear(args);
  stringlist_append_copy( args , "NameOfDataRanking2");
  stringlist_append_copy( args , "PORO:1,2,3");
  stringlist_append_copy( args , "false");
  test_assert_true( ert_test_context_run_worklow_job( test_context , job_name , args) );

  stringlist_free( args );
}
Example #5
0
stringlist_type * local_ministep_alloc_data_keys( const local_ministep_type * ministep ) {
  stringlist_type * keys = stringlist_alloc_new();
  {
    hash_iter_type * dataset_iter = hash_iter_alloc( ministep->datasets );
    while (!hash_iter_is_complete( dataset_iter )) {
      const local_dataset_type * dataset = hash_iter_get_next_value( dataset_iter );
      stringlist_type * node_keys = local_dataset_alloc_keys( dataset );
      for (int i=0; i < stringlist_get_size( node_keys ); i++) {
        const char * data_key = stringlist_iget( node_keys , i );
        if (!stringlist_contains(keys , data_key ))
          stringlist_append_copy( keys , data_key );
      }
      stringlist_free( node_keys );
    }
    hash_iter_free( dataset_iter );
  }
  return keys;
}
void test_rank_realizations_on_observations_job(ert_test_context_type * test_context , const char * job_name , const char * job_file) {
  stringlist_type * args = stringlist_alloc_new();
  ert_test_context_install_workflow_job( test_context , job_name , job_file );

  stringlist_append_copy( args , "NameOfObsRanking1");
  stringlist_append_copy( args , "|");
  stringlist_append_copy( args , "WOPR:*");
  test_assert_true( ert_test_context_run_worklow_job( test_context , job_name , args) );

  stringlist_clear(args);
  stringlist_append_copy( args , "NameOfObsRanking2");
  stringlist_append_copy( args, "1-5");
  stringlist_append_copy( args, "55");
  stringlist_append_copy( args , "|");
  stringlist_append_copy( args , "WWCT:*");
  stringlist_append_copy( args , "WOPR:*");
  test_assert_true( ert_test_context_run_worklow_job( test_context , job_name , args) );

  stringlist_clear(args);
  stringlist_append_copy( args , "NameOfObsRanking3");
  stringlist_append_copy( args, "5");
  stringlist_append_copy( args, "55");
  stringlist_append_copy( args, "|");
  test_assert_true( ert_test_context_run_worklow_job( test_context , job_name , args) );

  stringlist_clear(args);
  stringlist_append_copy( args , "NameOfObsRanking4");
  stringlist_append_copy( args, "1,3,5-10");
  stringlist_append_copy( args, "55");
  test_assert_true( ert_test_context_run_worklow_job( test_context , job_name , args) );

  stringlist_clear(args);
  stringlist_append_copy( args , "NameOfObsRanking5");
  test_assert_true( ert_test_context_run_worklow_job( test_context , job_name , args) );

  stringlist_clear(args);
  stringlist_append_copy( args , "NameOfObsRanking6");
  stringlist_append_copy( args, "|");
  stringlist_append_copy( args , "UnrecognizableObservation");
  test_assert_true( ert_test_context_run_worklow_job( test_context , job_name , args) );

  stringlist_free( args );
}
Example #7
0
ert_run_context_type * ert_run_context_alloc_SMOOTHER_RUN(enkf_fs_type * simulate_fs , enkf_fs_type * target_update_fs ,
                                                          const bool_vector_type * iactive ,
                                                          path_fmt_type * runpath_fmt ,
                                                          subst_list_type * subst_list ,
                                                          int iter) {

  ert_run_context_type * context = ert_run_context_alloc( iactive , SMOOTHER_UPDATE , simulate_fs , simulate_fs , target_update_fs , iter);
  {
    stringlist_type * runpath_list = ert_run_context_alloc_runpath_list( iactive , runpath_fmt , subst_list , iter );
    for (int iens = 0; iens < bool_vector_size( iactive ); iens++) {
      if (bool_vector_iget( iactive , iens )) {
        run_arg_type * arg = run_arg_alloc_SMOOTHER_RUN( simulate_fs , target_update_fs , iens , iter , stringlist_iget( runpath_list , iens));
        vector_append_owned_ref( context->run_args , arg , run_arg_free__);
      }
    }
    stringlist_free( runpath_list );
  }
  return context;
}
Example #8
0
File: ecl_sum.c Project: flikka/ert
bool ecl_sum_case_exists( const char * input_file ) {
  char * smspec_file = NULL;
  stringlist_type * data_files = stringlist_alloc_new();
  char * path;
  char * basename;
  char * extension;
  bool   case_exists;

  util_alloc_file_components( input_file , &path , &basename , &extension);
  case_exists = ecl_util_alloc_summary_files( path , basename , extension , &smspec_file , data_files );

  util_safe_free( path );
  util_safe_free( basename );
  util_safe_free( extension );
  util_safe_free( smspec_file );
  stringlist_free( data_files );

  return case_exists;
}
Example #9
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;
}
Example #10
0
File: ecl_sum.c Project: edbru/ert
static void ecl_sum_fread_data( ecl_sum_type * ecl_sum , const stringlist_type * data_files , bool include_restart) {
  if (ecl_sum->data != NULL)
    ecl_sum_free_data( ecl_sum );
  ecl_sum->data = ecl_sum_data_alloc( ecl_sum->smspec );
  ecl_sum_data_fread( ecl_sum->data , data_files );

  if (include_restart) {
    const char * path                     = ecl_sum->path;
    const stringlist_type * restart_cases = ecl_smspec_get_restart_list( ecl_sum->smspec );
    stringlist_type       * restart_files = stringlist_alloc_new();

    int restart_nr;
    for (restart_nr = 0; restart_nr < stringlist_get_size( restart_cases ); restart_nr++) {
      ecl_util_alloc_summary_data_files(path , stringlist_iget( restart_cases , restart_nr ) , ecl_sum->fmt_case , restart_files );
      ecl_sum_data_fread_restart( ecl_sum->data , restart_files );
    }
    stringlist_free( restart_files );
  }

}
void test_export_ranking(ert_test_context_type * test_context , const char * job_name , const char * job_file) {
  stringlist_type * args = stringlist_alloc_new();
  ert_test_context_install_workflow_job( test_context , job_name , job_file );

  stringlist_append_copy( args , "NameOfDataRanking");
  stringlist_append_copy( args , "/tmp/fileToSaveDataRankingIn.txt");
  test_assert_true( ert_test_context_run_worklow_job( test_context , job_name , args) );

  stringlist_clear(args);
  stringlist_append_copy( args , "NameOfObsRanking1");
  stringlist_append_copy( args , "/tmp/fileToSaveObservationRankingIn1.txt");
  test_assert_true( ert_test_context_run_worklow_job( test_context , job_name , args) );

  stringlist_clear(args);
  stringlist_append_copy( args , "NameOfObsRanking6");
  stringlist_append_copy( args , "/tmp/fileToSaveObservationRankingIn6.txt");
  test_assert_true( ert_test_context_run_worklow_job( test_context , job_name , args) );

  stringlist_free( args );
}
Example #12
0
sched_kw_gruptree_type * sched_kw_gruptree_alloc(const stringlist_type * tokens , int * token_index ) {
  sched_kw_gruptree_type * kw = sched_kw_gruptree_alloc_empty();
  int eokw                    = false;
  do {
    stringlist_type * line_tokens = sched_util_alloc_line_tokens( tokens , false , 0 , token_index );
    if (line_tokens == NULL)
      eokw = true;
    else {
      const char * parent_group = "FIELD";
      const char * child_group  =  stringlist_iget( line_tokens , 0 );
      if (stringlist_get_size( line_tokens ) == 2) 
        parent_group = stringlist_iget( line_tokens , 1 );
      
      sched_kw_gruptree_add_well(kw , child_group , parent_group );
      
      stringlist_free( line_tokens );
    } 
    
  } while (!eokw);
  return kw;
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RifEclipseSummaryTools::findSummaryFiles(const std::string& inputFile, 
                                                   std::string* headerFile, 
                                                   std::vector<std::string>* dataFiles)
{
    dataFiles->clear();
    headerFile->clear();

    char* myPath = NULL;
    char* myBase = NULL;
    char* myExtention = NULL;

    util_alloc_file_components(inputFile.data(), &myPath, &myBase, &myExtention);

    std::string path; if(myPath) path = myPath;
    std::string base; if(myBase) base = myBase;
    std::string extention; if(myExtention) extention = myExtention;

    if(path.empty() || base.empty()) return ;

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

    ecl_util_alloc_summary_files(path.data(), base.data(), extention.data(), &myHeaderFile, summary_file_list);
    if(myHeaderFile)
    {
        (*headerFile) = myHeaderFile;
        util_safe_free(myHeaderFile);
    }

    if(stringlist_get_size(summary_file_list) > 0)
    {
        for(int i = 0; i < stringlist_get_size(summary_file_list); i++)
        {
            dataFiles->push_back(stringlist_iget(summary_file_list,i));
        }
    }
    stringlist_free(summary_file_list);

    return;
}
Example #14
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RifEclipseSummaryTools::findSummaryFiles(const QString& inputFile, 
                                                   QString* headerFile, 
                                                   QStringList* dataFiles)
{
    dataFiles->clear();
    headerFile->clear();

    char* myPath = nullptr;
    char* myBase = nullptr;
    char* myExtention = nullptr;

    util_alloc_file_components(RiaStringEncodingTools::toNativeEncoded(inputFile).data(), &myPath, &myBase, &myExtention);

    QString path; if(myPath) path = RiaStringEncodingTools::fromNativeEncoded(myPath);
    QString base; if(myBase) base = RiaStringEncodingTools::fromNativeEncoded(myBase);
    std::string extention; if(myExtention) extention = myExtention;

    if(path.isEmpty() || base.isEmpty()) return ;

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

    ecl_util_alloc_summary_files(RiaStringEncodingTools::toNativeEncoded(path).data(), RiaStringEncodingTools::toNativeEncoded(base).data(), extention.data(), &myHeaderFile, summary_file_list);
    if(myHeaderFile)
    {
        (*headerFile) = RiaStringEncodingTools::fromNativeEncoded(myHeaderFile);
        util_safe_free(myHeaderFile);
    }

    if(stringlist_get_size(summary_file_list) > 0)
    {
        for(int i = 0; i < stringlist_get_size(summary_file_list); i++)
        {
            dataFiles->push_back(RiaStringEncodingTools::fromNativeEncoded(stringlist_iget(summary_file_list,i)));
        }
    }
    stringlist_free(summary_file_list);

    return;
}
Example #15
0
static bool enkf_main_case_is_initialized__( const enkf_main_type * enkf_main , enkf_fs_type * fs , bool_vector_type * __mask) {
    stringlist_type  * parameter_keys = ensemble_config_alloc_keylist_from_var_type( enkf_main->ensemble_config , PARAMETER );
    bool_vector_type * mask;
    bool initialized = true;
    int ikey = 0;
    if (__mask != NULL)
        mask = __mask;
    else
        mask = bool_vector_alloc(0 , true );

    while ((ikey < stringlist_get_size( parameter_keys )) && (initialized)) {
        const enkf_config_node_type * config_node = ensemble_config_get_node( enkf_main->ensemble_config , stringlist_iget( parameter_keys , ikey) );
        int iens = 0;
        do {
            if (bool_vector_safe_iget( mask , iens)) {
                node_id_type node_id = {.report_step = 0 , .iens = iens , .state = ANALYZED };
                initialized = enkf_config_node_has_node( config_node , fs , node_id);
            }
            iens++;
        } while ((iens < enkf_main->ens_size) && (initialized));
        ikey++;
    }

    stringlist_free( parameter_keys );
    if (__mask == NULL)
        bool_vector_free( mask );
    return initialized;
}



bool enkf_main_case_is_initialized( const enkf_main_type * enkf_main , const char * case_name ,  bool_vector_type * __mask) {
    enkf_fs_type * fs = enkf_main_mount_alt_fs(enkf_main , case_name , false );
    if (fs) {
        bool initialized = enkf_main_case_is_initialized__(enkf_main , fs , __mask);
        enkf_fs_decref( fs );
        return initialized;
    } else
        return false;
}
Example #16
0
void enkf_tui_workflow_list( void * arg ) {
  enkf_main_type * enkf_main = enkf_main_safe_cast( arg );
  {
    ert_workflow_list_type * workflow_list = enkf_main_get_workflow_list( enkf_main );
    stringlist_type * name_list = ert_workflow_list_alloc_namelist( workflow_list );
    
    printf("Available workflows: \n");
    {
      int i;
      for (i=0; i < stringlist_get_size( name_list ); i++) {
        if ((i % 5) == 0)
          printf("\n   ");
        else
          printf("  ");

        printf( stringlist_iget( name_list , i ));
      }
    }
    stringlist_free( name_list );
    printf("\n\n");
  }
}
//--------------------------------------------------------------------------------------------------
/// Get set of Eclipse files based on an input file and its path
//--------------------------------------------------------------------------------------------------
bool RifEclipseOutputFileTools::findSiblingFilesWithSameBaseName(const QString& fullPathFileName, QStringList* baseNameFiles)
{
    CVF_ASSERT(baseNameFiles);
    baseNameFiles->clear();

    QString filePath = QFileInfo(fullPathFileName).absoluteFilePath();
    filePath = QFileInfo(filePath).path();
    QString fileNameBase = QFileInfo(fullPathFileName).completeBaseName();

    stringlist_type* eclipseFiles = stringlist_alloc_new();
    ecl_util_select_filelist(RiaStringEncodingTools::toNativeEncoded(filePath).data(), RiaStringEncodingTools::toNativeEncoded(fileNameBase).data(), ECL_OTHER_FILE, false, eclipseFiles);

    int i;
    for (i = 0; i < stringlist_get_size(eclipseFiles); i++)
    {
        baseNameFiles->append(RiaStringEncodingTools::fromNativeEncoded(stringlist_safe_iget(eclipseFiles, i)));
    }

    stringlist_free(eclipseFiles);

    return baseNameFiles->count() > 0;
}
void test_predicate_matching() {
  test_work_area_type * work_area = test_work_area_alloc("predicate_test");
  stringlist_type * s = stringlist_alloc_new();
  stringlist_append_copy(s, "s");
  stringlist_select_files(s, "does/not/exist", NULL, NULL);
  test_assert_int_equal(stringlist_get_size(s), 0);


  {
    FILE * f = util_fopen("FILE.txt", "w");
    fclose(f);
  }
  stringlist_select_files(s , test_work_area_get_cwd(work_area), NULL, NULL);
  test_assert_int_equal(1, stringlist_get_size(s));
  {
    char * exp = util_alloc_abs_path("FILE.txt");
    test_assert_string_equal( exp, stringlist_iget(s, 0));
    free(exp);
  }

  stringlist_select_files(s , NULL, NULL, NULL);
  test_assert_int_equal(1, stringlist_get_size(s));
  test_assert_string_equal( "FILE.txt", stringlist_iget(s, 0));

  stringlist_select_files(s , test_work_area_get_cwd(work_area), FILE_predicate, NULL);
  test_assert_int_equal(1, stringlist_get_size(s));
  {
    char * exp = util_alloc_abs_path("FILE.txt");
    test_assert_string_equal( exp, stringlist_iget(s, 0));
    free(exp);
  }

  stringlist_select_files(s , test_work_area_get_cwd(work_area), not_FILE_predicate, NULL);
  test_assert_int_equal(0, stringlist_get_size(s));

  stringlist_free(s);
  test_work_area_free(work_area);
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
bool RifReaderEclipseSummary::open(const std::string& headerFileName, const std::vector<std::string>& dataFileNames)
{
    assert(ecl_sum == NULL); 
    
    if (headerFileName.empty() || dataFileNames.size() == 0) return false;

    assert(!headerFileName.empty());
    assert(dataFileNames.size() > 0);

    stringlist_type* dataFiles = stringlist_alloc_new();
    for (size_t i = 0; i < dataFileNames.size(); i++)
    {
        stringlist_append_copy(dataFiles, dataFileNames[i].data());
    }

    std::string itemSeparatorInVariableNames = ":";
    ecl_sum = ecl_sum_fread_alloc(headerFileName.data(), dataFiles, itemSeparatorInVariableNames.data());

    stringlist_free(dataFiles);

    if (ecl_sum)
    {
        eclSmSpec = ecl_sum_get_smspec(ecl_sum);
        assert(eclSmSpec != NULL);

        assert(ecl_sum != NULL);

        for ( int time_index = 0; time_index < timeStepCount(); time_index++ )
        {
            time_t sim_time = ecl_sum_iget_sim_time(ecl_sum, time_index);
            m_timeSteps.push_back(sim_time);
        }

        return true;
    }

    return false;
}
Example #20
0
void model_config_free(model_config_type * model_config) {
  if (model_config->enkf_sched != NULL)
    enkf_sched_free( model_config->enkf_sched );
  free( model_config->enspath );
  free( model_config->rftpath );
  util_safe_free( model_config->jobname_fmt );
  util_safe_free( model_config->enkf_sched_file );
  util_safe_free( model_config->select_case );
  util_safe_free( model_config->case_table_file );
  util_safe_free( model_config->current_path_key);

  if (model_config->history != NULL)
    history_free(model_config->history);

  if (model_config->forward_model != NULL)
    forward_model_free(model_config->forward_model);

  bool_vector_free(model_config->internalize_state);
  bool_vector_free(model_config->__load_state);
  hash_free(model_config->runpath_map);
  if (model_config->case_names != NULL) stringlist_free( model_config->case_names );
  free(model_config);
}
Example #21
0
void custom_kw_config_serialize(const custom_kw_config_type * config, stringlist_type * config_set) {
    pthread_rwlock_t * rw_lock = (pthread_rwlock_t *)& config->rw_lock;
    pthread_rwlock_rdlock(rw_lock);
    {
        stringlist_clear(config_set);

        stringlist_type * configured_keys = custom_kw_config_get_keys(config);

        for (int i = 0; i < stringlist_get_size(configured_keys); i++) {
            const char * key = stringlist_iget(configured_keys, i);
            bool double_type = custom_kw_config_key_is_double(config, key);
            int index = custom_kw_config_index_of_key(config, key);
            char buffer[256];

            sprintf(buffer, "%s %d %d", key, index, double_type);
            stringlist_append_copy(config_set, buffer);
        }

        stringlist_free(configured_keys);

    }
    pthread_rwlock_unlock(rw_lock);
}
Example #22
0
static void * enkf_main_load_results_JOB__( enkf_main_type * enkf_main , int iter , const stringlist_type * args) {
  bool_vector_type * iactive = alloc_iactive_vector_from_range(args, 0, stringlist_get_size(args), enkf_main_get_ensemble_size(enkf_main));
  int ens_size = enkf_main_get_ensemble_size(enkf_main);
  stringlist_type ** realizations_msg_list = util_calloc(ens_size, sizeof * realizations_msg_list);
  for (int iens = 0; iens < ens_size; ++iens)
    realizations_msg_list[iens] = stringlist_alloc_new();

  enkf_main_load_from_forward_model(enkf_main, iter , iactive, realizations_msg_list);

  for (int iens = 0; iens < ens_size; ++iens) {
    stringlist_type * msg = realizations_msg_list[iens];
    if (stringlist_get_size(msg)) {
      int msg_count = 0;
      for (; msg_count < stringlist_get_size(msg); ++msg_count)
        fprintf(stderr, "** Warning: Function %s : Load of realization number %d returned the following warning: %s\n", __func__, iens, stringlist_iget(msg, msg_count));
    }
    stringlist_free(msg);
  }

  free(realizations_msg_list);
  bool_vector_free(iactive);
  return NULL;
}
Example #23
0
// Inspired by the ecl_pack application in the ERT library
void concatenateRestart(const std::string& basename) {
    std::string inputPath, inputBase;
    splitBasename(basename, inputPath, inputBase);
    stringlist_type* inputFiles = stringlist_alloc_new();
    const int numFiles = ecl_util_select_filelist(inputPath.c_str(), inputBase.c_str(), ECL_RESTART_FILE, false, inputFiles);

    const char* target_file_name = ecl_util_alloc_filename(inputPath.c_str(), inputBase.c_str(), ECL_UNIFIED_RESTART_FILE, false, -1);
    fortio_type* target = fortio_open_writer(target_file_name, false, ECL_ENDIAN_FLIP);
    int dummy;
    ecl_kw_type* seqnum_kw = ecl_kw_alloc_new("SEQNUM", 1, ECL_INT, &dummy);

    int reportStep = 0;
    for (int i = 0; i < numFiles; ++i) {
        ecl_util_get_file_type(stringlist_iget(inputFiles, i), nullptr, &reportStep);
        ecl_file_type* src_file = ecl_file_open(stringlist_iget(inputFiles, i), 0);
        ecl_kw_iset_int(seqnum_kw, 0, reportStep);
        ecl_kw_fwrite(seqnum_kw, target);
        ecl_file_fwrite_fortio(src_file, target, 0);
        ecl_file_close(src_file);
    }
    fortio_fclose(target);
    stringlist_free(inputFiles);
}
Example #24
0
ert_run_context_type * ert_run_context_alloc_ENKF_ASSIMILATION(enkf_fs_type * fs , 
                                                               const bool_vector_type * iactive , 
                                                               path_fmt_type * runpath_fmt , 
                                                               subst_list_type * subst_list ,
                                                               init_mode_type init_mode , 
                                                               state_enum init_state_parameter ,
                                                               state_enum init_state_dynamic   ,
                                                               int step1                       , 
                                                               int step2                       ,
                                                               int iter) {
  
  ert_run_context_type * context = ert_run_context_alloc( iactive , SMOOTHER_UPDATE , fs , fs , fs , init_mode , iter);
  {
    stringlist_type * runpath_list = ert_run_context_alloc_runpath_list( iactive , runpath_fmt , subst_list , iter );
    for (int iens = 0; iens < bool_vector_size( iactive ); iens++) {
      if (bool_vector_iget( iactive , iens )) {
        run_arg_type * arg = run_arg_alloc_ENKF_ASSIMILATION( fs , iens , init_state_parameter , init_state_dynamic , step1 , step2 , stringlist_iget( runpath_list , iens));
        vector_append_owned_ref( context->run_args , arg , run_arg_free__);
      }
    }
    stringlist_free( runpath_list );
  }
  return context;
}
Example #25
0
void enkf_main_init_case_from_existing(const enkf_main_type * enkf_main,
                                       enkf_fs_type * source_case_fs,
                                       int source_report_step,
                                       enkf_fs_type * target_case_fs ) {

  stringlist_type * param_list = ensemble_config_alloc_keylist_from_var_type( enkf_main_get_ensemble_config(enkf_main) , PARAMETER ); /* Select only paramters - will fail for GEN_DATA of type DYNAMIC_STATE. */
  int target_report_step  = 0;
  bool_vector_type * iactive = bool_vector_alloc( 0 , true );

  enkf_main_copy_ensemble(enkf_main,
                          source_case_fs,
                          source_report_step,
                          target_case_fs,
                          target_report_step,
                          iactive,
                          NULL,
                          param_list);


  enkf_fs_fsync(target_case_fs);

  bool_vector_free(iactive);
  stringlist_free(param_list);
}
Example #26
0
void enkf_config_node_free(enkf_config_node_type * node) {
  /* Freeing the underlying node object. */
  if (node->freef   != NULL) node->freef(node->data);
  free(node->key);
  stringlist_free(node->obs_keys);

  if (node->enkf_infile_fmt != NULL) 
    path_fmt_free( node->enkf_infile_fmt );

  if (node->enkf_outfile_fmt != NULL) 
    path_fmt_free( node->enkf_outfile_fmt );
  
  if (node->init_file_fmt != NULL)
    path_fmt_free( node->init_file_fmt );

  if (node->internalize != NULL)
    bool_vector_free( node->internalize );
  
  if (node->min_std != NULL)
    enkf_node_free( node->min_std );

  vector_free( node->container_nodes );
  free(node);
}
Example #27
0
custom_kw_config_type * custom_kw_config_alloc_with_definition(const char * key, const hash_type * definition) {
    custom_kw_config_type * custom_kw_config = custom_kw_config_alloc_empty(key, NULL, NULL);

    stringlist_type * keys = hash_alloc_stringlist((hash_type *) definition);

    for(int index = 0; index < stringlist_get_size(keys); index++) {
        const char * definition_key = stringlist_iget_copy(keys, index);
        int type_value = hash_get_int(definition, definition_key);

        if(type_value < 0 || type_value > 1) {
            fprintf(stderr ,"[%s] Warning: Value type not 0 or 1 for key: '%s', defaulting to string!\n", __func__, key);
            type_value = 0;
        }
        hash_insert_int(custom_kw_config->custom_keys, definition_key, index);
        hash_insert_int(custom_kw_config->custom_key_types, definition_key, type_value);
    }

    custom_kw_config->undefined = false;
    custom_kw_config->key_definition_file = util_alloc_string_copy("custom definition");

    stringlist_free(keys);

    return custom_kw_config;
}
Example #28
0
static void cmd_free( cmd_type * cmd ){
  stringlist_free( cmd->arglist );
  free( cmd );
}
Example #29
0
int main(int argc , char ** argv) {
  enkf_main_install_SIGNALS();
  const char * root_path = argv[1];
  const char * config_file = argv[2];
  const char * forward_init_string = argv[3];
  test_work_area_type * work_area = test_work_area_alloc(config_file , false);
  test_work_area_copy_directory_content( work_area , root_path );
  {
    bool forward_init;
    bool strict = true;
    enkf_main_type * enkf_main;
    
    test_assert_true( util_sscanf_bool( forward_init_string , &forward_init));

    util_clear_directory( "Storage" , true , true );
    enkf_main = enkf_main_bootstrap( NULL , config_file , strict , true );
    {
      enkf_state_type * state   = enkf_main_iget_state( enkf_main , 0 );
      enkf_node_type * gen_param_node = enkf_state_get_node( state , "PARAM" );
      {
        const enkf_config_node_type * gen_param_config_node = enkf_node_get_config( gen_param_node );
        char * init_file1 = enkf_config_node_alloc_initfile( gen_param_config_node , NULL , 0);
        char * init_file2 = enkf_config_node_alloc_initfile( gen_param_config_node , "/tmp", 0);

        test_assert_bool_equal( enkf_config_node_use_forward_init( gen_param_config_node ) , forward_init );
        test_assert_string_equal( init_file1 , "PARAM_INIT");
        test_assert_string_equal( init_file2 , "/tmp/PARAM_INIT");

        free( init_file1 );
        free( init_file2 );
      }
  
      test_assert_bool_equal( enkf_node_use_forward_init( gen_param_node ) , forward_init );
      if (forward_init)
        test_assert_bool_not_equal( enkf_node_initialize( gen_param_node , 0 , enkf_state_get_rng( state )) , forward_init);
      // else hard_failure()
    }
    test_assert_bool_equal( forward_init, ensemble_config_have_forward_init( enkf_main_get_ensemble_config( enkf_main )));
    
    if (forward_init) {
      enkf_state_type * state   = enkf_main_iget_state( enkf_main , 0 );
      enkf_fs_type * fs = enkf_main_get_fs( enkf_main );
      enkf_node_type * gen_param_node = enkf_state_get_node( state , "PARAM" );
      node_id_type node_id = {.report_step = 0 ,  
                              .iens = 0,
                              .state = ANALYZED };

      create_runpath( enkf_main );
      test_assert_true( util_is_directory( "simulations/run0" ));
      
      {
        run_mode_type run_mode = ENSEMBLE_EXPERIMENT; 
        enkf_main_init_run(enkf_main , run_mode);     /* This is ugly */
        
        
        test_assert_false( enkf_node_has_data( gen_param_node , fs, node_id ));
        util_unlink_existing( "simulations/run0/PARAM_INIT" );
      }
      


      {
        FILE * stream = util_fopen("simulations/run0/PARAM_INIT" , "w");
        fprintf(stream , "0\n1\n2\n3\n" );
        fclose( stream );
      }
      
      {
        bool loadOK = true;
        stringlist_type * msg_list = stringlist_alloc_new();

        {
          run_mode_type run_mode = ENSEMBLE_EXPERIMENT; 
          enkf_main_init_run(enkf_main , run_mode);     /* This is ugly */
        }
        
        test_assert_true( enkf_node_forward_init( gen_param_node , "simulations/run0" , 0 ));
        enkf_state_forward_init( state , fs , &loadOK );
        test_assert_true( loadOK );
        enkf_state_load_from_forward_model( state , fs , &loadOK , false , msg_list );
        stringlist_free( msg_list );
        test_assert_true( loadOK );

        {
          double value;
          test_assert_true( enkf_node_user_get( gen_param_node , fs , "0" , node_id , &value)); 
          test_assert_double_equal( 0 , value);

          test_assert_true( enkf_node_user_get( gen_param_node , fs , "1" , node_id , &value)); 
          test_assert_double_equal( 1 , value);

          test_assert_true( enkf_node_user_get( gen_param_node , fs , "2" , node_id , &value)); 
          test_assert_double_equal( 2 , value);
        }
      }
      util_clear_directory( "simulations" , true , true );
      create_runpath( enkf_main );
      test_assert_true( util_is_directory( "simulations/run0" ));
      test_assert_true( util_is_file( "simulations/run0/PARAM.INC" ));
      {
        FILE * stream = util_fopen("simulations/run0/PARAM.INC" , "r");
        double v0,v1,v2,v3;
        fscanf(stream , "%lg %lg %lg %lg" , &v0,&v1,&v2,&v3);
        fclose( stream );                
        test_assert_double_equal( 0 , v0);
        test_assert_double_equal( 1 , v1);
        test_assert_double_equal( 2 , v2);
        test_assert_double_equal( 3 , v3);
      }
      util_clear_directory( "simulations" , true , true );
    }
    enkf_main_free( enkf_main );
  }
  test_work_area_free( work_area );
}
Example #30
0
static void enkf_tui_fs_copy_ensemble__(
  enkf_main_type * enkf_main,
  const char     * source_case,
  const char     * target_case,
  int              report_step_from,
  state_enum       state_from,
  int              report_step_to,
  state_enum       state_to,
  bool             only_parameters)
{
  msg_type       * msg          = msg_alloc("Copying: " , false);
  ensemble_config_type * config = enkf_main_get_ensemble_config(enkf_main);
  int ens_size                  = enkf_main_get_ensemble_size(enkf_main);
  char * ranking_key;
  const int  * ranking_permutation = NULL;
  int  * identity_permutation;
  ranking_table_type * ranking_table = enkf_main_get_ranking_table( enkf_main );
  

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

  if (ranking_permutation == NULL)
    ranking_permutation = identity_permutation;
  

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