Exemple #1
0
void ecl_util_alloc_summary_data_files(const char * path , const char * base , bool fmt_file , stringlist_type * filelist) {
  char  * unif_data_file = ecl_util_alloc_exfilename(path , base , ECL_UNIFIED_SUMMARY_FILE , fmt_file , -1);
  int files = ecl_util_select_filelist( path , base , ECL_SUMMARY_FILE , fmt_file , filelist);

  if ((files > 0) && (unif_data_file != NULL)) {
    /* 
       We have both a unified file AND a list of files: BASE.S0000,
       BASE.S0001, BASE.S0002, ..., must check which is newest and
       load accordingly.
    */
    bool unified_newest = true;
    int file_nr = 0;
    while (unified_newest && (file_nr < files)) {
      if (util_file_difftime( stringlist_iget(filelist , file_nr) , unif_data_file ) > 0) 
        unified_newest = false;
      file_nr++;
    }
    
    if (unified_newest) {
      stringlist_clear( filelist ); /* Clear out all the BASE.Snnnn selections. */
      stringlist_append_copy( filelist , unif_data_file );
    } 
  } else if (unif_data_file != NULL) {
    /* Found a unified summary file :  Clear out all the BASE.Snnnn selections. */
    stringlist_clear( filelist );      /* Clear out all the BASE.Snnnn selections. */
    stringlist_append_copy( filelist , unif_data_file );
  } 
  util_safe_free( unif_data_file );
}
Exemple #2
0
void sched_kw_gruptree_init_child_parent_list( const sched_kw_gruptree_type * kw , stringlist_type * child , stringlist_type * parent) {
  stringlist_clear( child );
  stringlist_clear( parent );
  {
    hash_iter_type * iter = hash_iter_alloc( kw->gruptree_hash );
    while (!hash_iter_is_complete( iter )) {
      const char * child_group  = hash_iter_get_next_key( iter );
      const char * parent_group = hash_get_string( kw->gruptree_hash , child_group );
      
      stringlist_append_copy( child , child_group );       /* <- The iterator keys go out of scope when hash_iter_free() is called. */
      stringlist_append_ref( parent , parent_group );
    }
    hash_iter_free( iter );
  }
}
Exemple #3
0
void stringlist_buffer_fread( stringlist_type * s , buffer_type * buffer ) {
  int size = buffer_fread_int( buffer );
  int i;
  stringlist_clear(s);
  for (i=0; i < size; i++)
    stringlist_append_owned_ref( s , buffer_fread_alloc_string( buffer ));
}
Exemple #4
0
/*
   When a stringlist is loaded from file the current content of the
   stringlist is discarded; and the stringlist becomes the owner of
   all the data read in.
*/
void  stringlist_fread(stringlist_type * s, FILE * stream) {
  int size = util_fread_int(stream);
  int i;
  stringlist_clear(s);
  for (i=0; i < size; i++)
    stringlist_append_owned_ref( s , util_fread_alloc_string( stream ));
}
Exemple #5
0
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
}
Exemple #6
0
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);
  }
}
Exemple #7
0
void site_config_clear_pathvar( site_config_type * site_config ) {
  stringlist_clear( site_config->path_variables_user );
  stringlist_clear( site_config->path_values_user );
  {
    /* Recover the original values. */
    hash_iter_type * hash_iter = hash_iter_alloc( site_config->path_variables_site );
    while (!hash_iter_is_complete( hash_iter )) {
      const char * var       = hash_iter_get_next_key( hash_iter );
      const char * site_value = hash_get( site_config->path_variables_site , var );
      
      if (site_value == NULL)
        util_unsetenv( var );
      else
        util_setenv( var , site_value );
    }
  }
}
Exemple #8
0
void stringlist_deep_copy( stringlist_type * target , const stringlist_type * src) {
  stringlist_clear( target );
  {
    int i;
    for ( i=0; i < stringlist_get_size( src ); i++)
      stringlist_append_copy( target , stringlist_iget( src , i ));
  }
}
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 );
}
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 );
}
void test_init_case_job(ert_test_context_type * test_context, const char * job_name , const char * job_file) {
  stringlist_type * args = stringlist_alloc_new();
  enkf_main_type * enkf_main = ert_test_context_get_main(test_context);

  test_assert_true( ert_test_context_install_workflow_job( test_context , "JOB" , job_file ) );

  //Test init current case from existing
  {
    enkf_fs_type * cur_fs = enkf_main_mount_alt_fs( enkf_main , "new_current_case" , true );
    enkf_main_select_fs(enkf_main, "new_current_case");

    test_assert_ptr_not_equal(cur_fs , enkf_main_get_fs( enkf_main ));

    stringlist_append_copy( args, "default"); //case to init from
    test_assert_true( ert_test_context_run_worklow_job( test_context , "JOB" , args) );

    enkf_fs_decref(cur_fs);
  }

  {
    const char * current_case = enkf_main_get_current_fs( enkf_main );
    test_assert_string_equal(current_case, "new_current_case");
    test_assert_true(enkf_fs_has_node(enkf_main_get_fs(enkf_main), "PERMZ", PARAMETER, 0, 0, ANALYZED));

    enkf_fs_type * default_fs          = enkf_main_mount_alt_fs( enkf_main , "default" , true  );
    state_map_type * default_state_map = enkf_fs_get_state_map(default_fs);
    state_map_type * current_state_map = enkf_fs_get_state_map(enkf_main_get_fs(enkf_main));
    test_assert_int_equal(state_map_get_size(default_state_map), state_map_get_size(current_state_map));
    enkf_fs_decref(default_fs);
  }


  //Test init case from existing case:
  stringlist_clear(args);
  stringlist_append_copy(args, "default"); //case to init from
  stringlist_append_copy(args, "new_not_current_case");
  test_assert_true( ert_test_context_run_worklow_job( test_context , "JOB" , args) );
  {
    enkf_fs_type * fs = enkf_main_mount_alt_fs(enkf_main, "new_not_current_case", true);
    test_assert_not_NULL( fs );
    test_assert_true( enkf_fs_has_node(fs, "PERMZ", PARAMETER, 0, 0, ANALYZED ));

    enkf_fs_type * default_fs          = enkf_main_mount_alt_fs( enkf_main , "default" , true );
    state_map_type * default_state_map = enkf_fs_get_state_map(default_fs);
    state_map_type * new_state_map     = enkf_fs_get_state_map(fs);
    test_assert_int_equal(state_map_get_size(default_state_map), state_map_get_size(new_state_map));
    enkf_fs_decref(fs);
  }

  stringlist_free( args );
}
Exemple #12
0
int stringlist_select_matching(stringlist_type * names , const char * pattern) {
  int match_count = 0;
  stringlist_clear( names );

  {
    int i;
    glob_t * pglob = util_malloc( sizeof * pglob );
    int glob_flags = 0;
    glob( pattern , glob_flags , NULL , pglob);
    match_count = pglob->gl_pathc;
    for (i=0; i < pglob->gl_pathc; i++)
      stringlist_append_copy( names , pglob->gl_pathv[i] );
    globfree( pglob );  /* Only frees the _internal_ data structures of the pglob object. */
    free( pglob );
  }
  return match_count;
}
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 );
}
Exemple #14
0
static bool custom_kw_config_read_data__(const custom_kw_config_type * config, const char * result_file, stringlist_type * result) {
    FILE * stream = util_fopen__(result_file, "r");
    if (stream != NULL) {
        bool read_ok = true;

        stringlist_clear(result);
        stringlist_iset_ref(result, hash_get_size(config->custom_keys) - 1, NULL);
        hash_type * read_keys = hash_alloc();

        char key[128];
        char value[128];
        int read_count;
        while ((read_count = fscanf(stream, "%s %s", key, value)) != EOF) {
            if (read_count == 1) {
                fprintf(stderr ,"[%s] Warning: Key: '%s:%s' missing value in file: %s!\n", __func__, config->name, key, result_file);
                read_ok = false;
                break;
            }

            if (custom_kw_config_has_key(config, key)) {
                if (hash_has_key(read_keys, key)) {
                    fprintf(stderr ,"[%s] Warning:  Key: '%s:%s' has appeared multiple times. Only the last occurrence will be used!\n", __func__, config->name, key);
                }

                hash_insert_int(read_keys, key, 1);
                int index = custom_kw_config_index_of_key(config, key);
                stringlist_iset_copy(result, index, value);

            } else {
                fprintf(stderr ,"[%s] Warning: Key: '%s:%s' not in the available set. Ignored!\n", __func__, config->name, key);
            }
        }

        fclose(stream);

        if (read_ok) {
            read_ok = hash_key_list_compare(read_keys, config->custom_keys);
        }

        return read_ok;
    }
    return false;
}
Exemple #15
0
static void file_map_make_index( file_map_type * file_map ) {
  stringlist_clear( file_map->distinct_kw );
  hash_clear( file_map->kw_index );
  {
    int i;
    for (i=0; i < vector_get_size( file_map->kw_list ); i++) {
      const ecl_file_kw_type * file_kw = vector_iget_const( file_map->kw_list , i);
      const char             * header  = ecl_file_kw_get_header( file_kw );
      if ( !hash_has_key( file_map->kw_index , header )) {
        int_vector_type * index_vector = int_vector_alloc( 0 , -1 );
        hash_insert_hash_owned_ref( file_map->kw_index , header , index_vector , int_vector_free__);
        stringlist_append_copy( file_map->distinct_kw , header);
      }
      
      {
        int_vector_type * index_vector = hash_get( file_map->kw_index , header);
        int_vector_append( index_vector , i);
      }
    }
  }
}
Exemple #16
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);
}
Exemple #17
0
void ecl_config_clear_static_kw( ecl_config_type * ecl_config ) {
  ecl_config->include_all_static_kw = false;
  stringlist_clear( ecl_config->user_static_kw );
}
Exemple #18
0
void enkf_config_node_clear_obs_keys(enkf_config_node_type * config_node) {
  stringlist_clear( config_node->obs_keys );
}
Exemple #19
0
void stringlist_free(stringlist_type * stringlist) {
  stringlist_clear(stringlist);
  vector_free(stringlist->strings);
  free(stringlist);
}
void test_export_runpath_files(const char * config_file,
                               const char * config_file_iterations,
                               const char * job_file_export_runpath) {

  stringlist_type * args = stringlist_alloc_new();
  const char * job_name  = "export_job";

  ert_test_context_type * test_context_iterations = create_context( config_file_iterations, "enkf_workflow_job_test_export_runpath_iter" );

  {
    int_vector_type * iens_values = int_vector_alloc(5,0);
    const int iens[5] = {0,1,2,3,4};
    int_vector_set_many(iens_values, 0, &iens[0], 5);
    int_vector_type * iter_values = int_vector_alloc(1,0);

    test_export_runpath_file(test_context_iterations, job_name, job_file_export_runpath, args, iens_values, iter_values);

    int_vector_free(iens_values);
    int_vector_free(iter_values);
  }
  {
    stringlist_append_copy( args, "0-2"); //realization range

    int_vector_type * iens_values = int_vector_alloc(3,0);
    const int iens[] = {0,1,2};
    int_vector_set_many(iens_values, 0, &iens[0], 3);
    int_vector_type * iter_values = int_vector_alloc(1,0);

    test_export_runpath_file(test_context_iterations, job_name, job_file_export_runpath, args, iens_values, iter_values);

    int_vector_free(iens_values);
    int_vector_free(iter_values);

    stringlist_clear(args);
  }
  {
    stringlist_append_copy( args, "0,3-5"); //realization range

    int_vector_type * iens_values = int_vector_alloc(4,0);
    const int iens[] = {0,3,4,5};
    int_vector_set_many(iens_values, 0, &iens[0], 4);
    int_vector_type * iter_values = int_vector_alloc(1,0);

    test_export_runpath_file(test_context_iterations, job_name, job_file_export_runpath, args, iens_values, iter_values);

    int_vector_free(iens_values);
    int_vector_free(iter_values);

    stringlist_clear(args);
  }
  {
    stringlist_append_copy( args, "1-2"); //realization range
    stringlist_append_copy( args, "|");   //delimiter
    stringlist_append_copy( args, "1-3"); //iteration range

    int_vector_type * iens_values = int_vector_alloc(2,0);
    int iens[] = {1,2};
    int_vector_set_many(iens_values, 0, &iens[0], 2);
    int_vector_type * iter_values = int_vector_alloc(3,0);
    int iter[] = {1,2,3};
    int_vector_set_many(iter_values, 0, &iter[0], 3);

    test_export_runpath_file(test_context_iterations, job_name, job_file_export_runpath, args, iens_values, iter_values);

    int_vector_free(iens_values);
    int_vector_free(iter_values);

    stringlist_clear(args);
  }
  {
    stringlist_append_copy( args, "*");   //realization range
    stringlist_append_copy( args, "|");   //delimiter
    stringlist_append_copy( args, "*");   //iteration range

    int_vector_type * iens_values = int_vector_alloc(5,0);
    int iens[] = {0,1,2,3,4};
    int_vector_set_many(iens_values, 0, &iens[0], 5);
    int_vector_type * iter_values = int_vector_alloc(4,0);
    int iter[] = {0,1,2,3};
    int_vector_set_many(iter_values, 0, &iter[0], 4);

    test_export_runpath_file(test_context_iterations, job_name, job_file_export_runpath, args, iens_values, iter_values);

    int_vector_free(iens_values);
    int_vector_free(iter_values);

    stringlist_clear(args);
  }

  ert_test_context_free(test_context_iterations);
  ert_test_context_type * test_context = create_context( config_file, "enkf_workflow_job_test_export_runpath" );

  {
    int_vector_type * iens_values = int_vector_alloc(1,0);
    int_vector_init_range(iens_values, 0, 25, 1);
    int_vector_type * iter_values = int_vector_alloc(1,0);

    test_export_runpath_file(test_context, job_name, job_file_export_runpath, args, iens_values, iter_values);

    int_vector_free(iens_values);
    int_vector_free(iter_values);

    stringlist_clear(args);
  }
  {
    stringlist_append_copy( args, "1-3"); //realization range

    int_vector_type * iens_values = int_vector_alloc(3,0);
    int iens[] = {1,2,3};
    int_vector_set_many(iens_values, 0, &iens[0], 3);
    int_vector_type * iter_values = int_vector_alloc(1,0);

    test_export_runpath_file(test_context, job_name, job_file_export_runpath, args, iens_values, iter_values);

    int_vector_free(iens_values);
    int_vector_free(iter_values);

    stringlist_clear(args);
  }
  {
    stringlist_append_copy( args, "1,2"); //realization range
    stringlist_append_copy( args, "|");   //delimiter
    stringlist_append_copy( args, "1-3"); //iteration range

    int_vector_type * iens_values = int_vector_alloc(2,0);
    int iens[] = {1,2};
    int_vector_set_many(iens_values, 0, &iens[0], 2);
    int_vector_type * iter_values = int_vector_alloc(1,0);

    test_export_runpath_file(test_context, job_name, job_file_export_runpath, args, iens_values, iter_values);

    int_vector_free(iens_values);
    int_vector_free(iter_values);

    stringlist_clear(args);
  }


  ert_test_context_free(test_context);


  stringlist_free( args );
}
Exemple #21
0
  int stringlist_select_matching_elements(stringlist_type * target , const stringlist_type * src , const char * pattern) {
  stringlist_clear( target );
  return stringlist_append_matching_elements( target , src , pattern );
}