Example #1
0
bool ecl_sum_vector_add_key( ecl_sum_vector_type * ecl_sum_vector, const char * key){
  if (ecl_sum_has_general_var( ecl_sum_vector->ecl_sum , key)) {
    const smspec_node_type * node = ecl_sum_get_general_var_node( ecl_sum_vector->ecl_sum , key );
    int params_index = smspec_node_get_params_index( node );
    bool is_rate_key = smspec_node_is_rate( node);

    int_vector_append(ecl_sum_vector->node_index_list, params_index);
    bool_vector_append(ecl_sum_vector->is_rate_list, is_rate_key);
    return true;
  } else
    return false;
}
Example #2
0
File: ecl_sum.c Project: 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 );
}
Example #3
0
enkf_config_node_type * ensemble_config_add_summary(ensemble_config_type * ensemble_config , const char * key , load_fail_type load_fail) {
  enkf_config_node_type * config_node = NULL;

  if (hash_has_key(ensemble_config->config_nodes, key)) {
    config_node = hash_get(ensemble_config->config_nodes, key);
    if (enkf_config_node_get_impl_type( config_node ) != SUMMARY)
      util_abort("%s: ensemble key:%s already exists - but it is not of summary type\n",__func__ , key);
    {
      summary_config_type * summary_config = enkf_config_node_get_ref( config_node );
      summary_config_update_load_fail_mode( summary_config , load_fail );
    }
  } else {
    if ((ensemble_config->refcase == NULL) || (ecl_sum_has_general_var( ensemble_config->refcase , key ))) {
      config_node = enkf_config_node_alloc_summary( key , load_fail);
      ensemble_config_add_node(ensemble_config , config_node );
    } else
      fprintf(stderr,"** warning: the refcase:%s does not contain the summary key:\"%s\" - will be ignored.\n", ecl_sum_get_case( ensemble_config->refcase ) , key);
  }

  return config_node;
}
Example #4
0
File: ecl_sum.c Project: flikka/ert
bool ecl_sum_has_key(const ecl_sum_type * ecl_sum , const char * lookup_kw) {
  return ecl_sum_has_general_var( ecl_sum , lookup_kw );
}
Example #5
0
void output_run_line( const output_type * output , ensemble_type * ensemble) {

  const int    data_columns = vector_get_size( output->keys );
  const int    data_rows    = time_t_vector_size( ensemble->interp_time );
  double     ** data;
  int row_nr, column_nr;

  data = util_calloc( data_rows , sizeof * data );
  /*
    time-direction, i.e. the row index is the first index and the
    column number (i.e. the different keys) is the second index.
  */
  for (row_nr=0; row_nr < data_rows; row_nr++)
    data[row_nr] = util_calloc( data_columns , sizeof * data[row_nr] );

  printf("Creating output file: %s \n",output->file );


  /*
     Go through all the cases and check that they have this key;
     exit if missing. Could also ignore the missing keys and just
     continue; and even defer the checking to the inner loop.
  */
  for (column_nr = 0; column_nr < vector_get_size( output->keys ); column_nr++) {
    const quant_key_type * qkey = vector_iget( output->keys , column_nr );
    {
      bool OK = true;

      for (int iens = 0; iens < vector_get_size( ensemble->data ); iens++) {
        const sum_case_type * sum_case = vector_iget_const( ensemble->data , iens );

        if (!ecl_sum_has_general_var(sum_case->ecl_sum , qkey->sum_key)) {
          OK = false;
          fprintf(stderr,"** Sorry: the case:%s does not have the summary key:%s \n", ecl_sum_get_case( sum_case->ecl_sum ), qkey->sum_key);
        }
      }

      if (!OK)
        util_exit("Exiting due to missing summary vector(s).\n");
    }
  }


  /* The main loop - outer loop is running over time. */
  {
    /**
       In the quite typical case that we are asking for several
       quantiles of the quantity, i.e.

       WWCT:OP_1:0.10  WWCT:OP_1:0.50  WWCT:OP_1:0.90

       the interp_data_cache construction will ensure that the
       underlying ecl_sum object is only queried once; and also the
       sorting will be performed once.
    */

    hash_type * interp_data_cache = hash_alloc();

    for (row_nr = 0; row_nr < data_rows; row_nr++) {
      time_t interp_time = time_t_vector_iget( ensemble->interp_time , row_nr);
      for (column_nr = 0; column_nr < vector_get_size( output->keys ); column_nr++) {
        const quant_key_type * qkey = vector_iget( output->keys , column_nr );
        double_vector_type * interp_data;

        /* Check if we have the vector in the cache table - if not create it. */
        if (!hash_has_key( interp_data_cache , qkey->sum_key)) {
          interp_data = double_vector_alloc(0 , 0);
          hash_insert_hash_owned_ref( interp_data_cache , qkey->sum_key , interp_data , double_vector_free__);
        }
        interp_data = hash_get( interp_data_cache , qkey->sum_key );

        /* Check if the vector has data - if not initialize it. */
        if (double_vector_size( interp_data ) == 0) {
          for (int iens = 0; iens < vector_get_size( ensemble->data ); iens++) {
            const sum_case_type * sum_case = vector_iget_const( ensemble->data , iens );

            if ((interp_time >= sum_case->start_time) && (interp_time <= sum_case->end_time))  /* We allow the different simulations to have differing length */
              double_vector_append( interp_data , ecl_sum_get_general_var_from_sim_time( sum_case->ecl_sum , interp_time , qkey->sum_key)) ;

            double_vector_sort( interp_data );
          }
        }
        data[row_nr][column_nr] = statistics_empirical_quantile__( interp_data , qkey->quantile );
      }
      hash_apply( interp_data_cache , double_vector_reset__ );
    }
    hash_free( interp_data_cache );
  }

  output_save( output , ensemble , (const double **) data);
  for (row_nr=0; row_nr < data_rows; row_nr++)
    free( data[row_nr] );
  free( data );
}