Esempio n. 1
0
int ensemble_config_get_observations( const ensemble_config_type * config , enkf_obs_type * enkf_obs , const char * user_key , int obs_count , time_t * obs_time , double * y , double * std) {
  int num_obs = 0;
  char * index_key;
  const enkf_config_node_type * config_node = ensemble_config_user_get_node( config , user_key , &index_key);
  if (config_node != NULL) {
    num_obs = enkf_config_node_load_obs( config_node , enkf_obs , index_key , obs_count , obs_time , y , std);
    util_safe_free( index_key );
  } 
  return num_obs;
}
Esempio n. 2
0
static void enkf_tui_ranking_create_data__( void * arg , bool sort_increasing) {
  enkf_main_type     * enkf_main         = enkf_main_safe_cast( arg );  
  ranking_table_type * ranking_table     = enkf_main_get_ranking_table( enkf_main );
  enkf_fs_type * fs                      = enkf_main_get_fs( enkf_main );
  ensemble_config_type * ensemble_config = enkf_main_get_ensemble_config( enkf_main );
  //const int history_length               = enkf_main_get_history_length( enkf_main );
  const int    prompt_len   = 60;
  const char * prompt1      = "Data key to use for ranking";
  const char * prompt2      = "Report step of data";
  const char * ranking_name = "Name of new ranking";
  const char * store_prompt = "Name of file to store ranking [Blank - no store]";

  int step;
  state_enum state = FORECAST;
  char * user_key;
  
  util_printf_prompt(prompt1 , prompt_len , '=' , "=> ");
  user_key = util_alloc_stdin_line();
  if (user_key != NULL) {
    util_printf_prompt( prompt2 , prompt_len , '=' , "=> ");
    {
      char * step_char = util_alloc_stdin_line();
      if (step_char == NULL)
        step = 0;
      else {
        if (util_sscanf_int( step_char , &step )) {
          const enkf_config_node_type * config_node;
          char * key_index;
          config_node = ensemble_config_user_get_node( ensemble_config , user_key , &key_index);
          if (config_node) {
            util_printf_prompt(ranking_name , prompt_len , '=' , "=> ");
            char * ranking_key = util_alloc_stdin_line();
            if (ranking_key != NULL) {
              ranking_table_add_data_ranking( ranking_table , sort_increasing , ranking_key , user_key , key_index , fs , config_node, step , state );
              ranking_table_display_ranking( ranking_table , ranking_key );
            }
            util_safe_free( ranking_key );
          }
        }
      }
      util_safe_free( step_char );
    }
  }
  util_safe_free( user_key );
}
Esempio n. 3
0
void enkf_tui_export_scalar2csv(void * arg) {
  enkf_main_type * enkf_main = enkf_main_safe_cast( arg );
  const ensemble_config_type * ensemble_config = enkf_main_get_ensemble_config(enkf_main);
  const enkf_config_node_type * config_node;
  char * user_key, *key_index;

  util_printf_prompt("Scalar to export (KEY:INDEX)" , PROMPT_LEN , '=' , "=> "); user_key = util_alloc_stdin_line();
  config_node = ensemble_config_user_get_node( ensemble_config , user_key , &key_index);
  if (config_node != NULL) {
    int    report_step , first_report, last_report;
    int    iens1 , iens2, iens;
    char * csv_file;

    iens2        = enkf_main_get_ensemble_size( enkf_main ) - 1;
    iens1        = 0;
    first_report = 0;
    last_report  = enkf_main_get_history_length( enkf_main );
    {
      char * path;
      char * prompt = util_alloc_sprintf("File to store \'%s\'", user_key);
      util_printf_prompt(prompt , PROMPT_LEN , '=' , "=> ");
      csv_file = util_alloc_stdin_line();

      util_alloc_file_components( csv_file , &path , NULL , NULL);
      if (path != NULL) {
        if (util_entry_exists( path )) {
          if (!util_is_directory( path )) {
            /* The path component already exists in the filesystem - and it is not a directory - we leave the building. */
            fprintf(stderr,"Sorry: %s already exists - and is not a directory.\n",path);
            free(path);
            free(csv_file);
            free(user_key);
            return ;
          }
        } else {
          /* The path does not exist - we make it. */
          enkf_tui_util_msg("Creating new directory: %s\n" , path);
          util_make_path( path );
        }
      }
      free(prompt);
    }
    {
      /* Seriously manual creation of csv file. */
      enkf_fs_type * fs     = enkf_main_tui_get_fs(enkf_main);
      enkf_node_type * node = enkf_node_alloc( config_node );
      FILE * stream         = util_fopen( csv_file , "w");
      node_id_type node_id;


      /* Header line */
      fprintf(stream , "\"Report step\"");
      for (iens = iens1; iens <= iens2; iens++)
        fprintf(stream , "%s\"%s(%d)\"" , CSV_SEP , user_key , iens);
      fprintf(stream , CSV_NEWLINE);

      for (report_step = first_report; report_step <= last_report; report_step++) {
        fprintf(stream , "%6d" , report_step);
        node_id.report_step = report_step;
        for (iens = iens1; iens <= iens2; iens++) {
          double value;
          char label[32];
          /*
             Have not implemented a choice on forecast/analyzed. Tries
             analyzed first, then forecast.
          */
          node_id.iens = iens;
          sprintf(label , "%03d/%03d" , report_step , iens);

          if (enkf_node_user_get( node , fs , key_index , node_id ,  &value))
            fprintf(stream , "%s%g" , CSV_SEP , value);
          else
            fprintf(stream , "%s%s" , CSV_SEP , CSV_MISSING_VALUE);

        }
        fprintf(stream , CSV_NEWLINE);
      }

      enkf_node_free( node );
      fclose(stream);
    }
  } else
    fprintf(stderr,"Sorry - could not find any nodes with key:%s\n",user_key);

  free(user_key);
}