Ejemplo n.º 1
0
stringlist_type * enkf_main_alloc_caselist( const enkf_main_type * enkf_main ) {
    stringlist_type * case_list = stringlist_alloc_new( );
    {
        const char * ens_path = model_config_get_enspath( enkf_main->model_config );
        DIR * ens_dir = opendir( ens_path );
        if (ens_dir != NULL) {
            int ens_fd = dirfd( ens_dir );
            if (ens_fd != -1) {
                struct dirent * dp;
                do {
                    dp = readdir( ens_dir );
                    if (dp != NULL) {
                        if (!(util_string_equal( dp->d_name , ".") || util_string_equal(dp->d_name , ".."))) {
                            if (!util_string_equal( dp->d_name , CURRENT_CASE_FILE)) {
                                char * full_path = util_alloc_filename( ens_path , dp->d_name , NULL);
                                if (util_is_directory( full_path ))
                                    stringlist_append_copy( case_list , dp->d_name );
                                free( full_path);
                            }
                        }
                    }
                } while (dp != NULL);
            }
        }
        closedir( ens_dir );
    }
    return case_list;
}
Ejemplo n.º 2
0
static int smspec_node_cmp_MISC( const smspec_node_type * node1, const smspec_node_type * node2) {
  static const char* early_vars[] = {"TIME",
                                     "DAYS",
                                     "DAY",
                                     "MONTH",
                                     "YEAR",
                                     "YEARS"};

  if (smspec_node_equal_MISC( node1, node2) )
    return 0;

  bool node1_early = false;
  bool node2_early = false;

  for (int i=0; i < 6; i++) {
    if (util_string_equal( node1->keyword, early_vars[i] ))
      node1_early = true;

    if (util_string_equal( node2->keyword, early_vars[i] ))
      node2_early = true;

  }
  if (node1_early && !node2_early)
    return -1;

  if (!node1_early && node2_early)
    return 1;

  return strcmp( node1->keyword, node2->keyword);
}
Ejemplo n.º 3
0
rng_type * rng_config_init_rng__(const rng_config_type * rng_config, rng_type * rng) {
    const char * seed_load  = rng_config_get_seed_load_file( rng_config );
    const char * seed_store = rng_config_get_seed_store_file( rng_config );

    if (seed_load != NULL) {
        if (util_file_exists( seed_load)) {
            FILE * stream = util_fopen( seed_load , "r");
            rng_fscanf_state( rng , stream );
            fclose( stream );
        } else {
            /*
               In the special case that seed_load == seed_store; we accept a
               seed_load argument pointing to a non-existant file.
            */
            if (seed_store) {
                if (util_string_equal( seed_store , seed_load))
                    rng_init( rng , INIT_DEV_URANDOM );
                else
                    util_abort("%s: tried to load random seed from non-existing file:%s \n",__func__ , seed_load);
            }
        }
    } else
        rng_init( rng , INIT_DEV_URANDOM );


    if (seed_store != NULL) {
        FILE * stream = util_mkdir_fopen( seed_store , "w");
        rng_fprintf_state( rng , stream );
        fclose( stream );
    }

    return rng;
}
Ejemplo n.º 4
0
plot_type * plot_alloc(const char * __driver_type , void * init_arg , bool logx , bool logy)
{
  plot_type * plot = util_malloc(sizeof *plot );
  {
    /*
      Loading the driver:
    */
    char * driver_type = util_alloc_string_copy( __driver_type );
    util_strupr( driver_type );

    if (util_string_equal( driver_type , "PLPLOT"))
      plot->driver  = plplot_driver_alloc(init_arg);
    else if (util_string_equal( driver_type , "TEXT"))
      plot->driver  = text_driver_alloc(init_arg);
    else
      util_abort("%s: plot driver:%s not implemented ... \n",__func__ , __driver_type);
    
    plot_driver_assert( plot->driver );

    free( driver_type );
  }

  /* Initializing plot data which is common to all drivers. */
  plot->is_histogram    = false;
  plot->dataset         = vector_alloc_new();
  plot->dataset_hash    = hash_alloc();
  plot->range           = plot_range_alloc();
  plot->timefmt         = NULL;
  plot->xlabel          = NULL;
  plot->ylabel          = NULL;
  plot->title           = NULL;
  
  /* 
     These functions only manipulate the internal plot_state
     variables, and do not call the driver functions.
  */
  plot_set_window_size(plot , PLOT_DEFAULT_WIDTH , PLOT_DEFAULT_HEIGHT);
  plot_set_box_color(plot , PLOT_DEFAULT_BOX_COLOR);
  plot_set_label_color(plot , PLOT_DEFAULT_LABEL_COLOR);
  plot_set_label_fontsize(plot , 1.0);
  plot_set_axis_fontsize(plot , 1.0);
  plot_set_labels(plot , "" , "" , ""); /* Initializeing with empty labels. */
  plot_set_log( plot , logx , logy); /* Default - no log on the axis. */
  return plot;
}
Ejemplo n.º 5
0
void test_assert_file_content__( const char * input_file , const char * expected, const char * src_file , int line) {
  if (util_file_exists( input_file )) {
    char * content = util_fread_alloc_file_content(input_file, NULL);
    if (!util_string_equal( content , expected))
      test_error_exit("%s:%d  content difference \n",src_file , line);
    free( content );
  } else
    test_error_exit("%s:%d => No such file:%s \n", src_file , line , input_file);
}
Ejemplo n.º 6
0
bool enkf_main_case_is_current(const enkf_main_type * enkf_main , const char * case_path) {
    char * mount_point               = enkf_main_alloc_mount_point( enkf_main , case_path );
    const char * current_mount_point = NULL;
    bool is_current;

    if (enkf_main->dbase != NULL)
        current_mount_point = enkf_fs_get_mount_point( enkf_main->dbase );

    is_current = util_string_equal( mount_point , current_mount_point );
    free( mount_point );
    return is_current;
}
Ejemplo n.º 7
0
void ensemble_config_set_gen_kw_format( ensemble_config_type * ensemble_config , const char * gen_kw_format_string) {
  if (!util_string_equal( gen_kw_format_string , ensemble_config->gen_kw_format_string)) {
    stringlist_type * gen_kw_keys = ensemble_config_alloc_keylist_from_impl_type( ensemble_config , GEN_KW );
    int i;
    ensemble_config->gen_kw_format_string = util_realloc_string_copy( ensemble_config->gen_kw_format_string , gen_kw_format_string );
    for (i=0; i < stringlist_get_size( gen_kw_keys ); i++) {
      enkf_config_node_type * config_node = ensemble_config_get_node( ensemble_config , stringlist_iget( gen_kw_keys , i ));
      gen_kw_config_update_tag_format( enkf_config_node_get_ref( config_node ) , gen_kw_format_string );
    }
    stringlist_free( gen_kw_keys );
  }
}
Ejemplo n.º 8
0
static output_type * output_alloc( const char * file , const char * format_string) {
  output_type * output = util_malloc( sizeof * output );
  output->keys = vector_alloc_new();
  output->file = util_alloc_string_copy( file );
  {
    format_type  format;

    if ( util_string_equal(format_string , S3GRAPH_STRING))
      format = S3GRAPH;
    else if ( util_string_equal( format_string , HEADER_STRING))
      format = HEADER;
    else if ( util_string_equal( format_string , PLAIN_STRING) )
      format = PLAIN;
    else {
      format = PLAIN;  /* Compiler shut up. */
      util_abort("%s: unrecognized format string:%s \n",__func__ , format_string);
    }
    output->format = format;
  }

  return output;
}
Ejemplo n.º 9
0
bool ecl_file_kw_equal( const ecl_file_kw_type * kw1 , const ecl_file_kw_type * kw2)
{
  if (kw1->file_offset != kw2->file_offset)
    return false;

  if (kw1->kw_size != kw2->kw_size)
    return false;

  if (!ecl_type_is_equal( kw1->data_type, kw2->data_type))
    return false;

  return util_string_equal( kw1->header , kw2->header );
}
Ejemplo n.º 10
0
const char * util_update_path_var(const char * variable, const char * value, bool append) {
  const char * current_value = getenv( variable );
  if (current_value == NULL)
    /* The (path) variable is not currently set. */
    util_setenv( variable , value );
  else {
    bool    update = true; 

    {
      char ** path_list;
      int     num_path;
      util_split_string( current_value , ":" , &num_path , &path_list);
      if (append) {
        int i;
        for (i = 0; i < num_path; i++) {
          if (util_string_equal( path_list[i] , value)) 
            update = false;                            /* The environment variable already contains @value - no point in appending it at the end. */
        } 
      } else {
        if (util_string_equal( path_list[0] , value)) 
          update = false;                              /* The environment variable already starts with @value. */
      }
      util_free_stringlist( path_list , num_path );
    }
    
    if (update) {
      char  * new_value;
      if (append)
        new_value = util_alloc_sprintf("%s:%s" , current_value , value);
      else
        new_value = util_alloc_sprintf("%s:%s" , value , current_value);
      util_setenv( variable , new_value );
      free( new_value );
    }
    
  }
  return getenv( variable );
}
Ejemplo n.º 11
0
void enkf_config_node_update_min_std( enkf_config_node_type * config_node , const char * min_std_file ) {
  if (!util_string_equal( config_node->min_std_file , min_std_file )) {
    /* The current min_std_file and the new input are different, and
       the min_std node must be cleared. */
    if (config_node->min_std != NULL) {
      enkf_node_free( config_node->min_std );
      config_node->min_std = NULL;
      free( config_node->min_std_file );
    }
  }
  config_node->min_std_file = util_realloc_string_copy( config_node->min_std_file , min_std_file );
  if (config_node->min_std_file != NULL) {
    config_node->min_std = enkf_node_alloc( config_node );
    enkf_node_fload( config_node->min_std , min_std_file );
  }
}
Ejemplo n.º 12
0
Archivo: ecl_sum.c Proyecto: flikka/ert
void ecl_sum_fmt_init_summary_x( const ecl_sum_type * ecl_sum , ecl_sum_fmt_type * fmt ) {
  fmt->locale     = NULL;
  fmt->sep        = "";
  fmt->date_fmt   = "%d/%m/%Y   ";
  fmt->value_fmt  = " %15.6g ";

  if (util_string_equal( ecl_sum_get_unit( ecl_sum , "TIME") , "DAYS"))
    fmt->days_fmt   = "%7.2f   ";
  else
    fmt->days_fmt   = "%7.4f   ";

  fmt->header_fmt = " %15s ";

  fmt->newline = "\n";
  fmt->print_header= true;
  fmt->print_dash = true;
  fmt->date_dash  = "-----------------------";
  fmt->value_dash = "-----------------";
  fmt->date_header= "-- Days   dd/mm/yyyy   ";
}
Ejemplo n.º 13
0
bool not_FILE_predicate(const char * name, const void * arg) {
  return !util_string_equal("FILE.txt", name);
}
Ejemplo n.º 14
0
trans_func_type * trans_func_alloc( const char * func_name ) {
  trans_func_type * trans_func = trans_func_alloc_empty( func_name );
  {
    if (util_string_equal(func_name , "NORMAL")) {
      stringlist_append_ref( trans_func->param_names , "MEAN");
      stringlist_append_ref( trans_func->param_names , "STD" );
      arg_pack_append_double( trans_func->params , 0 );
      arg_pack_append_double( trans_func->params , 0 );
      trans_func->func = trans_normal;
    }  
    
    if (util_string_equal( func_name , "LOGNORMAL")) {
      stringlist_append_ref( trans_func->param_names , "MEAN");
      stringlist_append_ref( trans_func->param_names , "STD" );
      arg_pack_append_double( trans_func->params , 0 );
      arg_pack_append_double( trans_func->params , 0 );
      trans_func->func = trans_lognormal;
    }
    
    if (util_string_equal( func_name , "UNIFORM")) {
      stringlist_append_ref( trans_func->param_names , "MIN");
      stringlist_append_ref( trans_func->param_names , "MAX" );
      arg_pack_append_double( trans_func->params , 0 );
      arg_pack_append_double( trans_func->params , 0 );
      trans_func->func = trans_unif;
    }


    if (util_string_equal( func_name , "DUNIF")) {
      stringlist_append_ref( trans_func->param_names , "STEPS");
      stringlist_append_ref( trans_func->param_names , "MIN");
      stringlist_append_ref( trans_func->param_names , "MAX" );
      arg_pack_append_int( trans_func->params , 0 );
      arg_pack_append_double( trans_func->params , 0 );
      arg_pack_append_double( trans_func->params , 0 );
      
      trans_func->func = trans_dunif;
    }


    if (util_string_equal( func_name , "ERRF")) {
      stringlist_append_ref( trans_func->param_names , "MIN");
      stringlist_append_ref( trans_func->param_names , "MAX" );
      stringlist_append_ref( trans_func->param_names , "SKEWNESS");
      stringlist_append_ref( trans_func->param_names , "WIDTH" );
      arg_pack_append_double( trans_func->params , 0 );
      arg_pack_append_double( trans_func->params , 0 );
      arg_pack_append_double( trans_func->params , 0 );
      arg_pack_append_double( trans_func->params , 0 );

      trans_func->func = trans_errf;
    }
    

    if (util_string_equal( func_name , "DERRF")) {
      stringlist_append_ref( trans_func->param_names , "STEPS");
      stringlist_append_ref( trans_func->param_names , "MIN");
      stringlist_append_ref( trans_func->param_names , "MAX" );
      stringlist_append_ref( trans_func->param_names , "SKEWNESS");
      stringlist_append_ref( trans_func->param_names , "WIDTH" );
      arg_pack_append_int( trans_func->params , 0 );
      arg_pack_append_double( trans_func->params , 0 );
      arg_pack_append_double( trans_func->params , 0 );
      arg_pack_append_double( trans_func->params , 0 );
      arg_pack_append_double( trans_func->params , 0 );

      trans_func->func = trans_derrf;
    }


    if (util_string_equal( func_name , "LOGUNIF")) {
      stringlist_append_ref( trans_func->param_names , "MIN");
      stringlist_append_ref( trans_func->param_names , "MAX" );
      
      arg_pack_append_double( trans_func->params , 0 );
      arg_pack_append_double( trans_func->params , 0 );
      trans_func->func = trans_logunif;
    }


    if (util_string_equal( func_name , "CONST")) {
      stringlist_append_ref( trans_func->param_names , "VALUE");
      arg_pack_append_double( trans_func->params , 0 );
      trans_func->func = trans_const;
    }
    
    if (util_string_equal( func_name , "NONE")) 
      trans_func->func = trans_const;


    if (trans_func->func == NULL) 
      util_exit("%s: Sorry: function name:%s not recognized \n",__func__ , func_name);
  }
  return trans_func;
}
Ejemplo n.º 15
0
bool stringlist_iequal( const stringlist_type * stringlist , int index, const char * s ) {
  return util_string_equal( stringlist_iget( stringlist , index ) , s);
}
Ejemplo n.º 16
0
static bool smspec_node_equal_MISC( const smspec_node_type * node1, const smspec_node_type * node2) {
  return util_string_equal( node1->keyword , node2->keyword);
}
Ejemplo n.º 17
0
/*
  This *should* become static.
*/
void smspec_node_init( smspec_node_type * smspec_node,
                       ecl_smspec_var_type var_type ,
                       const char * wgname  ,
                       const char * keyword ,
                       const char * unit    ,
                       const char * key_join_string ,
                       const int grid_dims[3] ,
                       int num) {

  bool initOK    = true;
  bool wgnameOK = true;
  if ((wgname != NULL) && (IS_DUMMY_WELL(wgname)))
    wgnameOK = false;

  smspec_node_common_init( smspec_node , var_type , keyword , unit );
  switch (var_type) {
  case(ECL_SMSPEC_COMPLETION_VAR):
    /* Completion variable : WGNAME & NUM */
    smspec_node_set_num( smspec_node , grid_dims , num );
    smspec_node_set_wgname( smspec_node , wgname );
    if (!wgnameOK || num < 0)
      initOK = false;
    break;
  case(ECL_SMSPEC_GROUP_VAR):
    /* Group variable : WGNAME */
    smspec_node_set_wgname( smspec_node , wgname );
    initOK = wgnameOK;
    break;
  case(ECL_SMSPEC_WELL_VAR):
    /* Well variable : WGNAME */
    smspec_node_set_wgname( smspec_node , wgname );
    initOK = wgnameOK;
    break;
  case(ECL_SMSPEC_SEGMENT_VAR):
    smspec_node_set_wgname( smspec_node , wgname );
    smspec_node_set_num( smspec_node , grid_dims , num );
    if (!wgnameOK || num < 0)
      initOK = false;
    break;
  case(ECL_SMSPEC_FIELD_VAR):
    /* Field variable : */
    /* Fully initialized with the smspec_common_init() function */
    break;
  case(ECL_SMSPEC_REGION_VAR):
    /* Region variable : NUM */
    smspec_node_set_num( smspec_node , grid_dims , num );
    break;
  case(ECL_SMSPEC_REGION_2_REGION_VAR):
    /* Region 2 region variable : NUM */
    smspec_node_set_num( smspec_node , grid_dims , num );
    break;
  case(ECL_SMSPEC_BLOCK_VAR):
    /* A block variable : NUM*/
    smspec_node_set_num( smspec_node , grid_dims , num );
    break;
  case(ECL_SMSPEC_MISC_VAR):
    /* Misc variable : */

    /*
       For some keywords the SMSPEC files generated by Eclipse have a
       non zero NUMS value although; it seems that value is required
       for the generatd summaryfiles to display nicely in
       e.g. S3GRAF.
    */

    if (util_string_equal( keyword ,SMSPEC_TIME_KEYWORD))
      smspec_node_set_num( smspec_node , grid_dims , SMSPEC_TIME_NUMS_VALUE );

    if (util_string_equal( keyword ,SMSPEC_YEARS_KEYWORD))
      smspec_node_set_num( smspec_node , grid_dims , SMSPEC_YEARS_NUMS_VALUE );

    break;
  case(ECL_SMSPEC_AQUIFER_VAR):
    smspec_node_set_num( smspec_node , grid_dims , num );
    break;
  default:
    /* Lots of legitimate alternatives which are not internalized. */
    initOK = false;
    break;
  }

  if (initOK)
    smspec_node_set_gen_keys( smspec_node , key_join_string );
}
Ejemplo n.º 18
0
void site_config_fprintf_config( const site_config_type * site_config , FILE * stream ) {
  fprintf( stream , CONFIG_COMMENTLINE_FORMAT );
  fprintf( stream , CONFIG_COMMENT_FORMAT , "Here comes system related information - which typically");
  fprintf( stream , CONFIG_COMMENT_FORMAT , "overrides information from the site-wide configuration file.");
  /* Starting with the user defined jobs. */
  {
    stringlist_type * joblist = ext_joblist_alloc_list( site_config->joblist );
    char * fmt_key     = util_alloc_sprintf(CONFIG_KEY_FORMAT , INSTALL_JOB_KEY);
    char * install_fmt = util_alloc_sprintf("%s%s%s" , fmt_key , CONFIG_VALUE_FORMAT , CONFIG_ENDVALUE_FORMAT);
    
    for (int i=0; i < stringlist_get_size( joblist ); i++) {
      ext_job_type * ext_job = ext_joblist_get_job( site_config->joblist ,stringlist_iget( joblist , i ));
      if (ext_job_is_private( ext_job ))
        ext_job_fprintf_config( ext_job , install_fmt , stream );
      
    }
    
    free( install_fmt );
    free( fmt_key );
  }

  
  /* Storing the env variables set with SETENV */
  {
    hash_iter_type * iter = hash_iter_alloc( site_config->env_variables_user );
    while (!hash_iter_is_complete( iter )) {
      const char * var        = hash_iter_get_next_key( iter );
      const char * user_value = hash_get( site_config->env_variables_user , var );
      const char * site_value = hash_safe_get( site_config->env_variables_site , var );
      
      if (!util_string_equal( user_value , site_value)) {
        fprintf(stream , CONFIG_KEY_FORMAT      , SETENV_KEY );
        fprintf(stream , CONFIG_VALUE_FORMAT    , var );
        fprintf(stream , CONFIG_ENDVALUE_FORMAT , user_value );
      }
    }
  }

  /* Storing the driver type setting: */
  if ( site_config->driver_type != site_config->driver_type_site) {
    fprintf(stream , CONFIG_KEY_FORMAT , QUEUE_SYSTEM_KEY );
    fprintf(stream , CONFIG_ENDVALUE_FORMAT , site_config_get_queue_name( site_config ));
  }
  
  /* Storing UMASK setting */
  if ( site_config->umask != site_config->umask_site) {
    fprintf(stream , CONFIG_KEY_FORMAT , UMASK_KEY );
    fprintf(stream , "%o\n" , site_config->umask );
  }

  /* Storing MAX_SUBMIT setting */
  if ( site_config->max_submit != site_config->max_submit_site) {
    fprintf(stream , CONFIG_KEY_FORMAT , MAX_SUBMIT_KEY );
    fprintf(stream , "%d\n" , site_config->max_submit );
  }
  
  /* Storing LICENSE_ROOT_PATH */
  if (!util_string_equal( site_config->license_root_path , site_config->license_root_path_site)) {
    fprintf(stream , CONFIG_KEY_FORMAT      , LICENSE_PATH_KEY );
    fprintf(stream , CONFIG_ENDVALUE_FORMAT , site_config->license_root_path);
  }

  /* Storing jobscript */
  if (!util_string_equal( site_config->job_script , site_config->job_script_site)) {
    fprintf(stream , CONFIG_KEY_FORMAT      , LICENSE_PATH_KEY );
    fprintf(stream , CONFIG_ENDVALUE_FORMAT , site_config->job_script);
  }

  /* Storing local settings. */
  if (site_config_get_max_running_local(site_config) != site_config->max_running_local_site) {
    fprintf(stream , CONFIG_KEY_FORMAT , MAX_RUNNING_LOCAL_KEY );
    fprintf(stream , CONFIG_INT_FORMAT , site_config_get_max_running_local( site_config ));
    fprintf( stream , "\n");
  }

  /* Storing LSF settings. */
  {
    if (site_config_get_max_running_lsf( site_config ) != site_config->max_running_lsf_site) {
      fprintf(stream , CONFIG_KEY_FORMAT , MAX_RUNNING_LSF_KEY );
      fprintf(stream , CONFIG_INT_FORMAT , site_config_get_max_running_lsf( site_config ));
      fprintf( stream , "\n");
    } 
    
    if (!util_string_equal( site_config_get_lsf_queue(site_config) , site_config->lsf_queue_name_site)) {
      fprintf(stream , CONFIG_KEY_FORMAT      , LSF_QUEUE_KEY );
      fprintf(stream , CONFIG_ENDVALUE_FORMAT , site_config_get_lsf_queue( site_config ));
    }

    if (!util_string_equal( site_config_get_lsf_request( site_config ) , site_config->lsf_request_site)) {
      fprintf(stream , CONFIG_KEY_FORMAT      , LSF_RESOURCES_KEY );
      fprintf(stream , CONFIG_ENDVALUE_FORMAT , site_config_get_lsf_request( site_config ));
    }
  }

  
  /* Storing RSH settings. */
  {
    if (site_config_get_max_running_rsh(site_config) != site_config->max_running_rsh_site) {
      fprintf(stream , CONFIG_KEY_FORMAT , MAX_RUNNING_RSH_KEY );
      fprintf(stream , CONFIG_INT_FORMAT , site_config_get_max_running_rsh( site_config ));
      fprintf( stream , "\n");
    }
    
    if (!util_string_equal( site_config_get_rsh_command( site_config ) , site_config->rsh_command_site)) {
      fprintf(stream , CONFIG_KEY_FORMAT      , LICENSE_PATH_KEY );
      fprintf(stream , CONFIG_ENDVALUE_FORMAT , site_config_get_rsh_command( site_config ));
    }

    {
      queue_driver_type * rsh_driver = site_config_get_queue_driver( site_config , RSH_DRIVER_NAME );
      const hash_type * host_list = queue_driver_get_option( rsh_driver , RSH_HOSTLIST );
      hash_iter_type * iter = hash_iter_alloc( host_list );
      while (!hash_iter_is_complete( iter )) {
        const char * host_name = hash_iter_get_next_key( iter );
        fprintf(stream , CONFIG_KEY_FORMAT      , RSH_HOST_KEY );
        fprintf(stream , "%s:%d\n"  , host_name , hash_get_int( host_list , host_name));
      }
      hash_iter_free( iter );
    }
  }
  
  fprintf(stream , "\n\n");
}
Ejemplo n.º 19
0
void ert_workflow_list_add_alias( ert_workflow_list_type * workflow_list , const char * real_name , const char * alias) {
  if (!util_string_equal( real_name , alias))
    hash_insert_ref( workflow_list->alias_map , alias , real_name );
}