diff --git a/applications/CMakeLists.txt b/applications/CMakeLists.txt index 3b23ba6d3..1b8c9935c 100644 --- a/applications/CMakeLists.txt +++ b/applications/CMakeLists.txt @@ -51,19 +51,6 @@ if(BUILD_APPLICATIONS) set_target_properties(summary PROPERTIES SUFFIX ".x") endif() - # This minor eclipse application depends on the config parser library and - # should be moved to the libres repository - it can not be built here. - if(BUILD_ERT) - add_executable(ecl_quantile ecl/ecl_quantile.c) - target_link_libraries(ecl_quantile config) - list(APPEND apps ecl_quantile) - endif() - if(PTHREAD_LIBRARY) - add_executable(bls block_fs/bls.c) - target_link_libecl(bls) - list(APPEND apps bls) - endif() - add_executable(segment_info well/segment_info.c) add_executable(CF_dump well/well_CF_dump.c) add_executable(ri_well_test well/ri_well_test.c) diff --git a/applications/ecl/ecl_quantile.c b/applications/ecl/ecl_quantile.c deleted file mode 100644 index 73b4c77ee..000000000 --- a/applications/ecl/ecl_quantile.c +++ /dev/null @@ -1,889 +0,0 @@ -/* - Copyright (C) 2011 Equinor ASA, Norway. - - The file 'ecl_quantile.c' is part of ERT - Ensemble based Reservoir Tool. - - ERT is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#define _GNU_SOURCE /* Must define this to get access to pthread_rwlock_t */ -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include - -#define DEFAULT_NUM_INTERP 50 -#define SUMMARY_JOIN ":" -#define MIN_SIZE 10 -#define LOAD_THREADS 4 - -typedef enum { - S3GRAPH = 1, - HEADER = 2, /* Columns of numbers like summary.x - with a header */ - PLAIN = 3 /* Columns of numbers like summary.x - no header */ -} format_type; - -typedef struct { - ecl_sum_type *ecl_sum; - double_vector_type *interp_data; - const time_t_vector_type *interp_time; - time_t start_time; - time_t end_time; -} sum_case_type; - -/** - Microscopic data structure representing one column of data; - i.e. one ECLIPSE summary key and one accompanying quantile value. -*/ - -typedef struct { - char *sum_key; - double quantile; -} quant_key_type; - -typedef struct { - vector_type *keys; /* Vector of quant_key_type instances. */ - char *file; - format_type format; -} output_type; - -typedef struct { - vector_type *data; - time_t_vector_type *interp_time; - int num_interp; - time_t start_time; - time_t end_time; - const ecl_sum_type * - refcase; /* Pointer to an arbitrary ecl_sum instance in the ensemble - to have access to indexing functions. */ - pthread_rwlock_t rwlock; -} ensemble_type; - -#define S3GRAPH_STRING "S3GRAPH" -#define HEADER_STRING "HEADER" -#define PLAIN_STRING "PLAIN" - -static quant_key_type *quant_key_alloc(const char *sum_key, double quantile) { - quant_key_type *qkey = util_malloc(sizeof *qkey); - qkey->sum_key = util_alloc_string_copy(sum_key); - qkey->quantile = quantile; - return qkey; -} - -static void quant_key_free(quant_key_type *qkey) { - free(qkey->sum_key); - free(qkey); -} - -static void quant_key_free__(void *qkey) { - quant_key_free((quant_key_type *)qkey); -} - -sum_case_type *sum_case_fread_alloc(const char *data_file, - const time_t_vector_type *interp_time) { - sum_case_type *sum_case = util_malloc(sizeof *sum_case); - - sum_case->ecl_sum = ecl_sum_fread_alloc_case(data_file, SUMMARY_JOIN); - sum_case->interp_data = double_vector_alloc(0, 0); - sum_case->interp_time = interp_time; - sum_case->start_time = ecl_sum_get_start_time(sum_case->ecl_sum); - sum_case->end_time = ecl_sum_get_end_time(sum_case->ecl_sum); - return sum_case; -} - -void sum_case_free(sum_case_type *sum_case) { - ecl_sum_free(sum_case->ecl_sum); - double_vector_free(sum_case->interp_data); - free(sum_case); -} - -void sum_case_free__(void *sum_case) { - sum_case_free((sum_case_type *)sum_case); -} - -void ensemble_add_case(ensemble_type *ensemble, const char *data_file) { - sum_case_type *sum_case = - sum_case_fread_alloc(data_file, ensemble->interp_time); - - pthread_rwlock_wrlock(&ensemble->rwlock); - { - printf("Loading case: %s \n", data_file); - vector_append_owned_ref(ensemble->data, sum_case, sum_case_free__); - if (ensemble->start_time > 0) - ensemble->start_time = - util_time_t_min(ensemble->start_time, sum_case->start_time); - else - ensemble->start_time = ecl_sum_get_start_time(sum_case->ecl_sum); - - ensemble->end_time = - util_time_t_max(ensemble->end_time, sum_case->end_time); - } - pthread_rwlock_unlock(&ensemble->rwlock); -} - -void *ensemble_add_case__(void *arg) { - arg_pack_type *arg_pack = arg_pack_safe_cast(arg); - ensemble_type *ensemble = arg_pack_iget_ptr(arg, 0); - const char *data_file = arg_pack_iget_ptr(arg, 1); - ensemble_add_case(ensemble, data_file); - arg_pack_free(arg_pack); - return NULL; -} - -void ensemble_init_time_interp(ensemble_type *ensemble) { - int i; - for (i = 0; i < ensemble->num_interp; i++) - time_t_vector_append( - ensemble->interp_time, - ensemble->start_time + - i * (ensemble->end_time - ensemble->start_time) / - (ensemble->num_interp - 1)); -} - -void ensemble_load_from_glob(ensemble_type *ensemble, const char *pattern, - thread_pool_type *tp) { - glob_t pglob; - int i; - glob(pattern, GLOB_NOSORT, NULL, &pglob); - - for (i = 0; i < pglob.gl_pathc; i++) { - arg_pack_type *arg_pack = arg_pack_alloc(); - arg_pack_append_ptr(arg_pack, ensemble); - arg_pack_append_owned_ptr( - arg_pack, util_alloc_string_copy(pglob.gl_pathv[i]), free); - thread_pool_add_job(tp, ensemble_add_case__, arg_pack); - } - - globfree(&pglob); -} - -ensemble_type *ensemble_alloc() { - ensemble_type *ensemble = util_malloc(sizeof *ensemble); - - ensemble->num_interp = DEFAULT_NUM_INTERP; - ensemble->start_time = -1; - ensemble->end_time = -1; - ensemble->data = vector_alloc_new(); - ensemble->interp_time = time_t_vector_alloc(0, -1); - pthread_rwlock_init(&ensemble->rwlock, NULL); - return ensemble; -} - -void ensemble_init(ensemble_type *ensemble, config_content_type *config) { - - /*1 : Loading ensembles and settings from the config instance */ - /*1a: Loading the eclipse summary cases. */ - { - thread_pool_type *tp = thread_pool_alloc(LOAD_THREADS, true); - { - int i, j; - if (config_content_has_item(config, "CASE_LIST")) { - const config_content_item_type *case_item = - config_content_get_item(config, "CASE_LIST"); - for (j = 0; j < config_content_item_get_size(case_item); j++) { - const config_content_node_type *case_node = - config_content_item_iget_node(case_item, j); - for (i = 0; i < config_content_node_get_size(case_node); - i++) { - const char *case_glob = - config_content_node_iget(case_node, i); - ensemble_load_from_glob(ensemble, case_glob, tp); - } - } - } - } - thread_pool_join(tp); - thread_pool_free(tp); - } - - { - const sum_case_type *tmp = vector_iget_const(ensemble->data, 0); - ensemble->refcase = tmp->ecl_sum; - } - - /*1b: Other config settings */ - if (config_content_has_item(config, "NUM_INTERP")) - ensemble->num_interp = - config_content_iget_as_int(config, "NUM_INTERP", 0, 0); - - /*2: Remaining initialization */ - ensemble_init_time_interp(ensemble); - if (vector_get_size(ensemble->data) < MIN_SIZE) - util_exit("Sorry - quantiles make no sense with with < %d " - "realizations; should have ~> 100.\n", - MIN_SIZE); -} - -const ecl_sum_type *ensemble_get_refcase(const ensemble_type *ensemble) { - return ensemble->refcase; -} - -void ensemble_free(ensemble_type *ensemble) { - vector_free(ensemble->data); - time_t_vector_free(ensemble->interp_time); - free(ensemble); -} - -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; -} - -static void output_free(output_type *output) { - vector_free(output->keys); - free(output->file); - free(output); -} - -static void output_free__(void *arg) { output_free((output_type *)arg); } - -/** - The @qkey input argument can contain wildcards in the summary key; - i.e. to get 75% quantile of all wells starting with 'B' you can use - qkey == 'WOPR:B*:0.75' - the expansion is done based on the refcase - provided. -*/ - -static void output_add_key(const ecl_sum_type *refcase, output_type *output, - const char *qkey) { - int tokens; - double quantile; - char **tmp; - char *sum_key; - - util_split_string(qkey, SUMMARY_JOIN, &tokens, &tmp); - if (tokens == 1) - util_exit("Hmmm - the key:%s is malformed - must be of the form " - "SUMMARY_KEY:QUANTILE.\n", - qkey); - - if (!util_sscanf_double(tmp[tokens - 1], &quantile)) - util_exit("Hmmmm - failed to interpret:%s as a quantile - must be a " - "number (0,1).\n", - tmp[tokens - 1]); - - if (quantile <= 0 || quantile >= 1.0) - util_exit("Invalid quantile value:%g - must be in interval (0,1)\n", - quantile); - - sum_key = - util_alloc_joined_string((const char **)tmp, tokens - 1, SUMMARY_JOIN); - { - stringlist_type *matching_keys = stringlist_alloc_new(); - int i; - ecl_sum_select_matching_general_var_list(refcase, sum_key, - matching_keys); - for (i = 0; i < stringlist_get_size(matching_keys); i++) - vector_append_owned_ref( - output->keys, - quant_key_alloc(stringlist_iget(matching_keys, i), quantile), - quant_key_free__); - - if (stringlist_get_size(matching_keys) == 0) - fprintf(stderr, - "** Warning: No summary vectors matching:\'%s\' found?? \n", - sum_key); - stringlist_free(matching_keys); - } - - util_free_stringlist(tmp, tokens); -} - -/** - Each output line should be of the format: - - OUTPUT output_file key.q key.q key.q key.q ... -*/ - -void output_table_init(const ecl_sum_type *refcase, hash_type *output_table, - const config_content_type *config) { - int i, j; - if (config_content_has_item(config, "OUTPUT")) { - const config_content_item_type *output_item = - config_content_get_item(config, "OUTPUT"); - for (i = 0; i < config_content_item_get_size(output_item); i++) { - const config_content_node_type *output_node = - config_content_item_iget_node(output_item, i); - - const char *file = config_content_node_iget(output_node, 0); - const char *format_string = - config_content_node_iget(output_node, 1); - output_type *output = output_alloc(file, format_string); - - /* All the keys are just added - without any check. */ - for (j = 2; j < config_content_node_get_size(output_node); j++) - output_add_key(refcase, output, - config_content_node_iget(output_node, j)); - - hash_insert_hash_owned_ref(output_table, file, output, - output_free__); - } - } -} - -/** - Will print the string variable @var and the numerical variable @q - padded to a total width of @w: - - 'var:0.001 ' -*/ - -static void print_var(FILE *stream, const char *var, double q, - const char *kw_fmt) { - char *qvar = util_alloc_sprintf("%s:%3.1f", var, q); - fprintf(stream, kw_fmt, qvar); - free(qvar); -} - -/* - ** The columns are separated! ** - - An ECLIPSE summary variable is generally characterized by three - variable values from SMSPEC vectors; the three vectors are - KEYWORDS, WGNAMES and NUMS. - - The main variable is the KEYWORDS variable which says what type of - variable it is. Examples of KEYWORDS variable values are 'WWCT', - 'WOPR' and 'GWPT'. To make the variable unique we then need - additional information from one, or both of WGNAMES and NUMS. For - instance for a well variable or group variable we will need the - well name from WGNAMES and for a block property we will need the - block number (as i + j*nx + k*nx*ny) from the NUMS vector. - - When writing the S3Graph header I don't understand how to enter the - different parts of header information. The current implementation, - which seems to work reasonably well[*] , does the following: - - 1. Write a line like this: - - DATE TIME KEYWORD1:xxx KEYWORD2:xxx KEYWORD3:xxxx - - Here KEYWORD is an eclipse variable memnonic from the KEYWORDS - array, i.e. FOPT or WWCT. The :xxx part is the quantile we are - looking at, i.e. 0.10 or 0.90. It seems adding the quantile - does not confuse S3Graph. - - 2. Write a line with units: - - DATE TIME KEYWORD1:xxx KEYWORD2:xxx KEYWORD3:xxxx - DAYS UNIT1 UNIT2 UNIT2 <---- New line - - - 3. Write a line with keyword qualifiers, i.e. extra information: - - DATE TIME WOPR:xxx FOPT:xxxx BPR - DAYS UNIT1 UNIT2 UNIT2 - OP1 1000 <---- New line - - Now - the totally confusing part is that it is not clear what - S3Graph expects on this third line, in the case of well/group - variables it is a well/group name from the WGNAMES array, - whereas for e.g. a region or block varaiable it wants an - element from the NUMS array, and for e.g. a field variable it - wants nothing extra. When it comes to variables which need - both NUMS and WGNAMES to become unique (e.g completion - variables) it is not clear how - if at all possible - to - support it. In the current implementation a string - concatenation of WGNAMES and NUMS is used. - - - [*] : I do not really understand why it seems to work. - -*/ - -void output_save_S3Graph(const output_type *output, ensemble_type *ensemble, - const double **data) { - FILE *stream = util_mkdir_fopen(output->file, "w"); - const char *kw_fmt = "\t%s"; - const char *unit_fmt = "\t%s"; - const char *wgname_fmt = "\t%s"; - const char *num_fmt = "\t%d"; - const char *float_fmt = "\t%0.4f"; - const char *days_fmt = "\t%0.2f"; - - const char *empty_fmt = "\t"; - const char *date_fmt = "%d/%d/%d"; - const char *time_header = "DATE\tTIME"; - const char *time_unit = "\tDAYS"; - const char *time_blank = "\t"; - const int data_columns = vector_get_size(output->keys); - const int data_rows = time_t_vector_size(ensemble->interp_time); - int row_nr, column_nr; - - { - char *origin; - util_alloc_file_components(output->file, NULL, &origin, NULL); - fprintf(stream, "ORIGIN %s\n", origin); - free(origin); - } - - /* 1: Writing first header line with variables. */ - fprintf(stream, time_header); - for (column_nr = 0; column_nr < data_columns; column_nr++) { - const quant_key_type *qkey = vector_iget(output->keys, column_nr); - print_var(stream, ecl_sum_get_keyword(ensemble->refcase, qkey->sum_key), - qkey->quantile, kw_fmt); - } - fprintf(stream, "\n"); - - /* 2: Writing second header line with units. */ - fprintf(stream, time_unit); - for (column_nr = 0; column_nr < data_columns; column_nr++) { - const quant_key_type *qkey = vector_iget(output->keys, column_nr); - fprintf(stream, unit_fmt, - ecl_sum_get_unit(ensemble->refcase, qkey->sum_key)); - } - fprintf(stream, "\n"); - - /*3: Writing third header line with WGNAMES / NUMS - extra information - - breaks completely down with LGR information. */ - fprintf(stream, time_blank); - { - for (column_nr = 0; column_nr < data_columns; column_nr++) { - const quant_key_type *qkey = vector_iget(output->keys, column_nr); - const char *ecl_key = qkey->sum_key; - const char *wgname = ecl_sum_get_wgname(ensemble->refcase, ecl_key); - int num = ecl_sum_get_num(ensemble->refcase, ecl_key); - ecl_smspec_var_type var_type = - ecl_sum_get_var_type(ensemble->refcase, ecl_key); - bool need_num = ecl_smspec_needs_num(var_type); - bool need_wgname = ecl_smspec_needs_wgname(var_type); - - if (need_num && need_wgname) { - /** Do not know how to include both - will just create a - mangled name as a combination. */ - char *wgname_num = util_alloc_sprintf("%s:%d", wgname, num); - fprintf(stream, wgname_fmt, wgname_num); - free(wgname_num); - } else if (need_num) - fprintf(stream, num_fmt, num); - else if (need_wgname) - fprintf(stream, wgname_fmt, wgname); - else - fprintf(stream, empty_fmt); - } - fprintf(stream, "\n"); - } - - /*4: Writing the actual data. */ - for (row_nr = 0; row_nr < data_rows; row_nr++) { - time_t interp_time = time_t_vector_iget(ensemble->interp_time, row_nr); - { - int mday, month, year; - ecl_util_set_date_values(interp_time, &mday, &month, &year); - fprintf(stream, date_fmt, mday, month, year); - } - fprintf(stream, days_fmt, - 1.0 * (interp_time - ensemble->start_time) / 86400); - - for (column_nr = 0; column_nr < data_columns; column_nr++) { - fprintf(stream, float_fmt, data[row_nr][column_nr]); - } - fprintf(stream, "\n"); - } -} - -void output_save_plain__(const output_type *output, ensemble_type *ensemble, - const double **data, bool add_header) { - FILE *stream = util_mkdir_fopen(output->file, "w"); - const char *key_fmt = " %18s:%4.2f "; - const char *time_header = "-- DAYS DATE "; - const char *time_dash = "------------------------"; - const char *key_dash = "-------------------------"; - const char *float_fmt = "%24.5f "; - const char *days_fmt = "%10.2f "; - const char *date_fmt = " %02d/%02d/%04d "; - const int data_columns = vector_get_size(output->keys); - const int data_rows = time_t_vector_size(ensemble->interp_time); - int row_nr, column_nr; - - if (add_header) { - fprintf(stream, time_header); - for (int i = 0; i < vector_get_size(output->keys); i++) { - const quant_key_type *qkey = vector_iget(output->keys, i); - fprintf(stream, key_fmt, qkey->sum_key, qkey->quantile); - } - fprintf(stream, "\n"); - - fprintf(stream, time_dash); - for (int i = 0; i < vector_get_size(output->keys); i++) - fprintf(stream, key_dash); - fprintf(stream, "\n"); - } - - /*4: Writing the actual data. */ - for (row_nr = 0; row_nr < data_rows; row_nr++) { - time_t interp_time = time_t_vector_iget(ensemble->interp_time, row_nr); - fprintf(stream, days_fmt, - 1.0 * (interp_time - ensemble->start_time) / 86400); - { - int mday, month, year; - ecl_util_set_date_values(interp_time, &mday, &month, &year); - fprintf(stream, date_fmt, mday, month, year); - } - - for (column_nr = 0; column_nr < data_columns; column_nr++) { - fprintf(stream, float_fmt, data[row_nr][column_nr]); - } - fprintf(stream, "\n"); - } -} - -void output_save(const output_type *output, ensemble_type *ensemble, - const double **data) { - switch (output->format) { - case (S3GRAPH): - output_save_S3Graph(output, ensemble, data); - break; - case (PLAIN): - output_save_plain__(output, ensemble, data, false); - break; - case (HEADER): - output_save_plain__(output, ensemble, data, true); - break; - default: - util_exit("Sorry: output_format:%d not supported \n", output->format); - } -} - -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); -} - -void output_table_run(hash_type *output_table, ensemble_type *ensemble) { - hash_iter_type *iter = hash_iter_alloc(output_table); - - while (!hash_iter_is_complete(iter)) { - const char *output_file = hash_iter_get_next_key(iter); - const output_type *output = hash_get(output_table, output_file); - output_run_line(output, ensemble); - } -} - -void config_init(config_parser_type *config) { - - config_add_schema_item(config, "CASE_LIST", true); - config_add_key_value(config, "NUM_INTERP", false, CONFIG_INT); - - { - config_schema_item_type *item; - item = config_add_schema_item(config, "OUTPUT", true); - config_schema_item_set_argc_minmax(item, 2, CONFIG_DEFAULT_ARG_MAX); - config_schema_item_set_indexed_selection_set( - item, 1, 3, - (const char *[3]){S3GRAPH_STRING, HEADER_STRING, PLAIN_STRING}); - } -} - -void usage() { - fprintf(stderr, "\nUse:\n\n ecl_quantile config_file\n\n"); - - printf("Help\n"); - printf("----\n"); - printf("\n"); - printf( - "The ecl_quantile program will load an ensemble of ECLIPSE summary\n"); - printf("files, it can then output quantiles of summary vectors over the " - "time\n"); - printf("span of the simulation. The program is based on a simple " - "configuration\n"); - printf("file which must be given as a commandline argument. The " - "configuration\n"); - printf("file only has three keywords:\n"); - printf("\n"); - printf("\n"); - printf(" CASE_LIST simulation*X/run*X/CASE*.DATA\n"); - printf(" CASE_LIST extra_simulation.DATA " - "even/more/simulations*GG/run*.DATA\n"); - printf(" OUTPUT FILE1 S3GRAPH WWCT:OP_1:0.10 WWCT:OP_1:0.50 " - "WOPR:OP_3\n"); - printf(" OUTPUT FILE2 PLAIN FOPT:0.10 FOPT:0.90 FGPT:0.10 " - "FGPT:0.90 FWPT:0.10 FWPT:0.90\n"); - printf(" NUM_INTERP 100\n"); - printf("\n"); - printf("\n"); - printf("CASE_LIST: This keyword is used to give the path to ECLIPSE data " - "files\n"); - printf(" corresponding to summaries which you want to load, observe that " - "the\n"); - printf( - " argument given to the CASE_LIST keyword can contain unix-style\n"); - printf(" wildcards like '*'. One CASE_LIST keyword can point to several " - "cases, \n"); - printf(" and in addition you can have several CASE_LIST keywords.\n"); - printf("\n"); - printf("\n"); - printf("OUTPUT: This keyword is used to denote what output you want from " - "the\n"); - printf(" program. The first argument to the OUTPUT keyword is the name " - "output\n"); - printf(" file you want to produce, in the example above we will create " - "two\n"); - printf(" output files (FILE1 and FILE2 respectively). The second argument " - "is \n"); - printf(" the wanted type of the output file, the three types currently " - "supported\n"); - printf(" are: \n\n"); - printf(" S3GRAPH: S3GRAPH user format - at least quite close...\n"); - printf(" PLAIN: Columns of data without any header information\n"); - printf(" HEADER: Like plain, but with a header at the top\n\n"); - printf( - " The remaining arguments on the output line corresponds to the \n"); - printf(" summary vector & quantile you are interested in. Each of these " - "values\n"); - printf(" is a \":\" separated string consting of:\n"); - printf(" \n"); - printf(" VAR: The ECLIPSE summary variable we are interested in, " - "(nearly)\n"); - printf( - " all variables found in the summary file are available,\n"); - printf(" e.g. RPR, WWCT or GOPT. \n"); - printf("\n"); - printf(" WG?: This is extra information added to the variable to make " - "it\n"); - printf(" unique, e.g. the name of a well or group for rate " - "variables\n"); - printf(" and the region number for a region. Not all variables, " - "in\n"); - printf(" particalar the field rates, Fxxx, have this string.\n"); - printf("\n"); - printf(" Q: The quantile we are interested in, e.g 0.10 to get the " - "P10\n"); - printf(" quantile and 0.90 to get the P90 quantile.\n"); - printf("\n"); - printf(" For the 'VAR' and 'WG?' parts of the keys you can use " - "shell-style\n"); - printf( - " wildcards to get all summary vectors matching a criteria, i.e. \n"); - printf(" 'WOPR:A-*:0.50' will give the P50 quantile of WOPR for all wells " - "\n"); - printf(" starting with 'A-'\n"); - printf("\n"); - printf(" Examples are:\n"); - printf("\n"); - printf(" WWCT:OPX:0.75 The P75 quantile of the watercut in well " - "OPX.\n"); - printf(" BPR:10,10,5:0.50 The P50 quantile of the Block Pressure in " - "block 10,10,5\n"); - printf(" FOPT:0.90 The P90 quantile of the field oil " - "production total.\n"); - printf(" RPR:*:0.50 The P50 quantile of all regions.\n"); - printf("\n"); - printf("\n"); - printf("NUM_INTERP: Before the program can calculate quantiles it must\n"); - printf(" interpolate all the simulated data down on the same time axis. " - "This\n"); - printf(" keyword regulates how many points should be used when " - "interpolating\n"); - printf(" the time axis; the default is 50 which is probably quite OK. " - "Observe\n"); - printf(" that for rate variable the program will not do linear " - "interpolation\n"); - printf(" between ECLIPSE report steps, the might therefore look a bit " - "jagged\n"); - printf(" if NUM_INTERP is set too high. This keyword is optional.\n"); - printf("\n"); - printf("All filenames in the configuration file will be interpreted " - "relative to\n"); - printf("the location of the configuration file, i.e. irrespective of the " - "current\n"); - printf("working directory when invoking the ecl_quantile program.\n\n"); - exit(0); -} - -int main(int argc, char **argv) { - if (argc != 2) - usage(); - else { - hash_type *output_table = hash_alloc(); - ensemble_type *ensemble = ensemble_alloc(); - { - config_parser_type *config = config_alloc(); - config_content_type *content; - const char *config_arg = argv[1]; - - config_init(config); - content = config_parse(config, config_arg, "--", NULL, NULL, NULL, - CONFIG_UNRECOGNIZED_WARN, true); - - if (config_content_is_valid(content)) { - char *config_path; - util_alloc_file_components(config_arg, &config_path, NULL, - NULL); - if (config_path != NULL) { - util_chdir(config_path); - free(config_path); - } - } else { - config_error_type *error = config_content_get_errors(content); - config_error_fprintf(error, true, stderr); - exit(1); - } - - ensemble_init(ensemble, content); - output_table_init(ensemble_get_refcase(ensemble), output_table, - content); - config_content_free(content); - config_free(config); - } - output_table_run(output_table, ensemble); - ensemble_free(ensemble); - hash_free(output_table); - } -} diff --git a/applications/ecl/grid_layer.c b/applications/ecl/grid_layer.c deleted file mode 100644 index 1f158328f..000000000 --- a/applications/ecl/grid_layer.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - Copyright (C) 2011 Equinor ASA, Norway. - - The file 'grid_layer.c' is part of ERT - Ensemble based Reservoir Tool. - - ERT is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#include -#include - -static void usage() { exit(1); } - -int main(int argc, char **argv) { - if (argc < 3) - usage(); - { - ecl_grid_type *ecl_grid = ecl_grid_alloc(argv[1]); - int nx, ny, nz; - int iarg; - { - const ecl_grid_type *lgr = ecl_grid_get_lgr(ecl_grid, "TROLLA"); - int i, j, k; - int global_cell; - global_cell = ecl_grid_get_parent_cell3(lgr, 9, 9, 5); - ecl_grid_get_ijk1(ecl_grid, global_cell, &i, &j, &k); - printf("Global cell(TROLLA , 10,10,6) = %d,%d,%d\n", i + 1, j + 1, - k + 1); - - global_cell = ecl_grid_get_parent_cell3(lgr, 9, 9, 2); - ecl_grid_get_ijk1(ecl_grid, global_cell, &i, &j, &k); - printf("Global cell(TROLLA , 10,10,3) = %d,%d,%d\n", i + 1, j + 1, - k + 1); - - global_cell = ecl_grid_get_parent_cell3(lgr, 25, 11, 0); - ecl_grid_get_ijk1(ecl_grid, global_cell, &i, &j, &k); - printf("Global cell(TROLLA , 26,12,1) = %d,%d,%d\n", i + 1, j + 1, - k + 1); - - lgr = ecl_grid_get_lgr(ecl_grid, "TROLLA2"); - global_cell = ecl_grid_get_parent_cell3(lgr, 9, 9, 2); - ecl_grid_get_ijk1(ecl_grid, global_cell, &i, &j, &k); - printf("Global cell(TROLLA2 , 10,10,3) = %d,%d,%d\n", i + 1, j + 1, - k + 1); - } - exit(1); - - ecl_grid_get_dims(ecl_grid, &nx, &ny, &nz, NULL); - for (iarg = 2; iarg < argc; iarg++) { - int k; - if (util_sscanf_int(argv[iarg], &k)) { - int i, j; - k--; - for (j = (ny - 1); j >= 0; j--) { - for (i = 0; i < nx; i++) { - if (ecl_grid_get_active_index3(ecl_grid, i, j, k) >= - 0) { - if ((i % 10) == 0) - printf("*"); - else - printf("X"); - } else - printf(" "); - } - printf("\n"); - } - } - } - } -} diff --git a/applications/ecl/key_list.c b/applications/ecl/key_list.c deleted file mode 100644 index f26df7692..000000000 --- a/applications/ecl/key_list.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - Copyright (C) 2011 Equinor ASA, Norway. - - The file 'key_list.c' is part of ERT - Ensemble based Reservoir Tool. - - ERT is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#include -#include -#include -#include -#include -#include -#include - -int main(int argc, char **argv) { - const char *data_file = argv[1]; - - ecl_sum_type *ecl_sum = ecl_sum_fread_alloc_case(data_file, ":"); - if (ecl_sum != NULL) { - stringlist_type *keys = stringlist_alloc_new(); - - if (argc == 2) - ecl_sum_select_matching_general_var_list(ecl_sum, "*", keys); - else { - for (int iarg = 2; iarg < argc; iarg++) { - printf("Matchging:%s \n", argv[iarg]); - ecl_sum_select_matching_general_var_list(ecl_sum, argv[iarg], - keys); - } - } - - stringlist_sort(keys, NULL); - { - int i; - for (i = 0; i < stringlist_get_size(keys); i++) - printf("%s \n", stringlist_iget(keys, i)); - } - - stringlist_free(keys); - ecl_sum_free(ecl_sum); - } else - fprintf(stderr, "key_list.x: No summary data found for case:%s\n", - data_file); -} diff --git a/applications/ecl/run_gravity.c b/applications/ecl/run_gravity.c deleted file mode 100644 index b1c39cb21..000000000 --- a/applications/ecl/run_gravity.c +++ /dev/null @@ -1,1094 +0,0 @@ -/* - Copyright (C) 2011 Equinor ASA, Norway. - - The file 'run_gravity.c' is part of ERT - Ensemble based Reservoir Tool. - - ERT is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define WATER 1 -#define GAS 2 -#define OIL 4 - -#define ECLIPSE300 2 -#define ECLIPSE100 1 - -int simulator = ECLIPSE100; - -typedef struct { - double utm_x; - double utm_y; - double depth; - double grav_diff; - char *name; - bool has_obs; - double obs_gdiff; /* Measured difference in g. */ - double std_gdiff; /* Uncertainty in the observed g difference. */ -} grav_station_type; - -static void truncate_saturation(float *value) { - util_apply_float_limits(value, 0.0, 1.0); -} - -static bool has_phase(int phase_sum, int phase) { - if ((phase_sum & phase) == 0) - return false; - else - return true; -} - -static const float *safe_get_float_ptr(const ecl_kw_type *ecl_kw, - const float *alternative) { - if (ecl_kw != NULL) - return ecl_kw_get_float_ptr(ecl_kw); - else - return alternative; -} - -void print_usage(int line) { - printf("LINE: %d \n", line); - fprintf(stderr, "This program is used to calculate the change in " - "graviational response\n"); - fprintf(stderr, "between two timesteps in an eclipse simulation. To do the " - "calculations\n"); - fprintf(stderr, "the program needs the following information:\n"); - fprintf(stderr, "\n"); - fprintf(stderr, - " 1. Restart file(s) with solution data for the two timesteps.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " 2. An EGRID or GRID file.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " 3. An INIT file.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " 4. A configuration file which lists at which " - "geographical locations\n"); - fprintf(stderr, " you want to measure the gravitational response. This " - "file should\n"); - fprintf(stderr, - " contain one position on each line, formatted as this:\n"); - fprintf(stderr, "\n"); - fprintf(stderr, "\n"); - fprintf(stderr, - " name1 utm_x utm_y depth g_obs g_std \n"); - fprintf(stderr, - " name2 utm_x utm_y depth g_obs g_std \n"); - fprintf(stderr, " .....\n"); - fprintf(stderr, "\n"); - fprintf( - stderr, - " The name string is completely arbitrary - but can NOT contain\n"); - fprintf(stderr, " spaces. The two last columns - g_obs and g_std ar " - "optional, but\n"); - fprintf(stderr, " must be present on all lines - or on no lines. \n"); - fprintf(stderr, "\n"); - fprintf(stderr, "\n"); - fprintf(stderr, "The required information should be passed from the user " - "with the help\n"); - fprintf( - stderr, - "of commandline arguments. This can be done in roughly speaking two\n"); - fprintf(stderr, "different ways:\n"); - fprintf(stderr, "\n"); - fprintf(stderr, "All ECLIPSE files in one directory\n"); - fprintf(stderr, "----------------------------------\n"); - fprintf( - stderr, - "In the case where all the files are found in one directory you can\n"); - fprintf( - stderr, - "just give an ECLIPSE basename, and the run_gravity program will by\n"); - fprintf(stderr, "itself find the required restart/init/grid files. Observe " - "that both\n"); - fprintf(stderr, "unified and non-unified restart files will be checked. In " - "addition to\n"); - fprintf(stderr, "the ECLIPSE basename you must give two numbers indicating " - "which report\n"); - fprintf(stderr, "steps you are interested in comparing, and finally the " - "configuration\n"); - fprintf(stderr, "file with all the measurement positions.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, "Example:\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " bash%% run_gravity.x BASE_CASE 10 178 " - "../config/grav_stations\n"); - fprintf(stderr, "\n"); - fprintf(stderr, "This will look up restart/grid/init files in the current " - "dirtectory,\n"); - fprintf( - stderr, - "for a simulation with baseame 'BASE_CASE'. It will compare report\n"); - fprintf(stderr, - "steps 10 and 178, and load station locations from the file\n"); - fprintf(stderr, "'../config/grav_stations'. \n"); - fprintf(stderr, "\n"); - fprintf(stderr, "\n"); - fprintf(stderr, "\n"); - fprintf(stderr, "ECLIPSE files NOT in same directory\n"); - fprintf(stderr, "-----------------------------------\n"); - fprintf(stderr, "\n"); - fprintf(stderr, "If the different ECLIPSE files are not in the same " - "directory you can\n"); - fprintf(stderr, "not let the run_gravity program find the required files " - "automatically,\n"); - fprintf(stderr, "and you must give all the required files as arguments on " - "the command\n"); - fprintf(stderr, "line. This is the most flexible approach, in addition to " - "files stored\n"); - fprintf( - stderr, - "different places this also allows to combine files with different\n"); - fprintf( - stderr, - "ECLISPE basenames. There are two different ways to enter restart\n"); - fprintf( - stderr, - "information, depending on whether you use unified or non-unified\n"); - fprintf(stderr, "restart files.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, "Example 1 (unified restart):\n"); - fprintf(stderr, "\n"); - fprintf(stderr, - " bash%% run_gravity.x /path/to/restart_files/CASE_3.UNRST 10 " - "178 /path/init/BASE_CASE.INIT /path/to/grid/BASE_CASE.EGRID " - "../config/stations.txt\n"); - fprintf(stderr, "\n"); - fprintf(stderr, "\n"); - fprintf(stderr, "\n"); - fprintf(stderr, "Example 2 (non-unified restart):\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " bash%% run_gravity.x CASE_3.X0010 " - "../path/CASE_2.X0178 /path/init/BASE_CASE.INIT " - "/path/to/grid/BASE_CASE.EGRID ../config/stations.txt\n"); - fprintf(stderr, " \n"); - fprintf(stderr, "\n"); - fprintf(stderr, " When the program has completed succesfully it will " - "write the changes\n"); - fprintf(stderr, " in local gravity to a file 'RUN_GRAVITY.out', in " - "addition the same\n"); - fprintf(stderr, - " information (with something more) will be sent to stdout.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, "\n"); - exit(1); -} - -static void grav_station_free__(void *arg) { - grav_station_type *grav = (grav_station_type *)arg; - free(grav->name); - free(grav); -} - -static grav_station_type *grav_station_alloc_new(const char *name, double x, - double y, double d) { - grav_station_type *s = util_malloc(sizeof *s); - s->name = util_alloc_string_copy(name); - s->utm_x = x; - s->utm_y = y; - s->depth = d; - s->grav_diff = 0.0; - s->obs_gdiff = 0.0; - s->std_gdiff = 0.0; - s->has_obs = false; - return s; -} - -static void grav_station_add_obs(grav_station_type *g, double obs, double std) { - g->obs_gdiff = obs; - g->std_gdiff = std; - g->has_obs = true; -} - -/** - The station information is in a file with the following rules: - - 1. Each station on a seperate line. - 2. For each station we have four items: ------ - name utm_x utm_y depth - - name is an arbitrary string - without spaces. -*/ - -static void load_stations(vector_type *grav_stations, const char *filename) { - printf("Loading from file:%s \n", filename); - { - int target_width; - FILE *stream = util_fopen(filename, "r"); - bool at_eof = false; - /** - When reading the first line we determine how many columns the - file contains. - */ - { - char *first_line = util_fscanf_alloc_line(stream, &at_eof); - char **token_list; - util_split_string(first_line, " \t", &target_width, &token_list); - util_free_stringlist(token_list, target_width); - fseek(stream, 0, SEEK_SET); - } - - while (!(at_eof)) { - double x, y, d; - double obs_gdiff, std_gdiff; - char station_name[32]; - int fscanf_return; - - if (target_width == 4) - fscanf_return = - fscanf(stream, "%s %lg %lg %lg", station_name, &x, &y, &d); - else - fscanf_return = - fscanf(stream, "%s %lg %lg %lg %lg %lg", station_name, &x, - &y, &d, &obs_gdiff, &std_gdiff); - - if (fscanf_return == target_width) { - grav_station_type *g = - grav_station_alloc_new(station_name, x, y, d); - if (target_width == 6) - grav_station_add_obs(g, obs_gdiff, std_gdiff); - - vector_append_owned_ref(grav_stations, g, grav_station_free__); - } else - at_eof = true; - } - fclose(stream); - } -} - -/** - This function will load, and return two ecl_file_type instances with the - restart information from the two relevant times. The input to this - function is a (char **) pointer, taken directly from the argv input - pointer. - - The function will start by calling ecl_util_get_file_type(input[0]), and - depending on the return value from this call it will follow three - different code-paths: - - - ECL_FILE_OTHER: This means that the first argument should be - interpreted not as an existing file name, but rather as an ECLIPSE - base name. The program will look for restart info in files in the - working directory with the following order: - - 1. Unified restart file - unformatted. - 2. Non unified restart files - unformatted. - 3. Unified restart file - formatted. - 4. Non unified restart files - formatted. - - The search will stop at the first success, if no restart - information is found the function will exit. The remaining - arguments in input[] will not be considered, but observe that the - use of ecl_base is signalled back to calling scope (through - reference), and the calling scope will look for GRID file and INIT - file also based on the ECLBASE found input[0]; formatted / - unformatted will be as returned from the four-way switch above. - - Example: - - bash% run_gravity ECLIPSE 10 128 xxxx - - - - ECL_RESTART_FILE: This means that input[0] is a non unified eclipse - restart file, this file will be loaded. And it is ASSUMED that - input[1] is the next non - unified restart file, loaded for the - next report step. - - Example: - - bash% run_gravity ECLIPSE.X0010 ECLIPSE.X0128 xxx - - - - ECL_UNIFIED_RESTART_FILE: This means that input[1] and input[2] are - interpreted as integers (i.e. report steps), and those two report - steps will be loaded from the unified restart file pointed to by - input[0]. - - Example: - - bash% run_gravity ECLIPSE.UNRST 10 128 xxx - - - - Observe that in all the examples above 'xxx' signifies argv arguments - which this function does not care about. The return the *arg_offset - variable will be set to indicate this index: - - char ** input = argv[1]; - int input_offset; - ecl_restart_file_type ** restart_info = load_restart_info(input , &input_offset, ...); - - Then the next argument is: input[input_offset]; -*/ - -ecl_file_type **load_restart_info( - const char **input, /* Input taken directly from argv */ - int input_length, /* The length of input. */ - int * - arg_offset, /* Integer - value corresponding to the *NEXT* element in input which should be used by the calling scope. */ - bool - *use_eclbase, /* Should input[0] be interpreted as an ECLBASE string? */ - bool * - fmt_file) { /* Only relevant if (*use_eclbase == true): was formatted file used? */ - - ecl_file_type **restart_files = util_calloc(2, sizeof *restart_files); - int report_nr; - ecl_file_enum file_type; - - *use_eclbase = false; - file_type = ecl_util_get_file_type(input[0], fmt_file, &report_nr); - - if (file_type == ECL_RESTART_FILE) { - /* Loading from two non-unified restart files. */ - if (input_length >= 2) { - file_type = ecl_util_get_file_type(input[1], fmt_file, &report_nr); - if (file_type == ECL_RESTART_FILE) { - restart_files[0] = ecl_file_open(input[0]); - restart_files[1] = ecl_file_open(input[1]); - *arg_offset = 2; - } else - print_usage(__LINE__); - } else - print_usage(__LINE__); - } else if (file_type == ECL_UNIFIED_RESTART_FILE) { - /* Loading from one unified restart file. */ - if (input_length >= 3) { - int report1, report2; - if ((util_sscanf_int(input[1], &report1) && - util_sscanf_int(input[2], &report2))) { - restart_files[0] = ecl_file_open(input[0]); - restart_files[1] = ecl_file_open(input[0]); - - ecl_file_select_rstblock_report_step(restart_files[0], report1); - ecl_file_select_rstblock_report_step(restart_files[1], report2); - *arg_offset = 3; - } else - print_usage(__LINE__); - } else - print_usage(__LINE__); - } else if (file_type == ECL_OTHER_FILE) { - if (input_length >= 3) { - int report1, report2; - if (!(util_sscanf_int(input[1], &report1) && - util_sscanf_int(input[2], &report2))) - print_usage(__LINE__); - else { - /* - input[0] is interpreted as an eclbase string, and not as the name of - an existing file. Go through various combinations of - unified/non-unified formatted/unformatted to find data. - */ - ecl_storage_enum storage_mode = ECL_INVALID_STORAGE; - const char *eclbase = input[0]; - char *unified_file = NULL; - char *file1 = NULL; - char *file2 = NULL; - - unified_file = ecl_util_alloc_filename( - NULL, eclbase, ECL_UNIFIED_RESTART_FILE, false, -1); - if (util_file_exists(unified_file)) - /* Binary unified */ - storage_mode = ECL_BINARY_UNIFIED; - else { - /* Binary non-unified */ - file1 = ecl_util_alloc_filename( - NULL, eclbase, ECL_RESTART_FILE, false, report1); - file2 = ecl_util_alloc_filename( - NULL, eclbase, ECL_RESTART_FILE, false, report2); - if ((util_file_exists(file1) && util_file_exists(file2))) - storage_mode = ECL_BINARY_NON_UNIFIED; - else { - free(unified_file); - /* ASCII unified */ - unified_file = ecl_util_alloc_filename( - NULL, eclbase, ECL_UNIFIED_RESTART_FILE, true, -1); - if (util_file_exists(unified_file)) - storage_mode = ECL_FORMATTED_UNIFIED; - else { - /* ASCII non unified */ - free(file1); - free(file2); - file1 = ecl_util_alloc_filename( - NULL, eclbase, ECL_RESTART_FILE, true, report1); - file2 = ecl_util_alloc_filename( - NULL, eclbase, ECL_RESTART_FILE, true, report2); - if ((util_file_exists(file1) && - util_file_exists(file2))) - storage_mode = ECL_FORMATTED_UNIFIED; - } - } - } - - if (storage_mode == ECL_INVALID_STORAGE) { - char *cwd = util_alloc_cwd(); - util_exit("Could not find any restart information for " - "ECLBASE:%s in %s \n", - eclbase, cwd); - free(cwd); - } - - if ((storage_mode == ECL_BINARY_UNIFIED) || - (storage_mode == ECL_FORMATTED_UNIFIED)) { - restart_files[0] = ecl_file_open(input[0]); - restart_files[1] = ecl_file_open(input[0]); - - if (!ecl_file_select_rstblock_report_step(restart_files[0], - report1)) - util_exit("Failed to load report:%d from %s \n", - report1, unified_file); - - if (!ecl_file_select_rstblock_report_step(restart_files[1], - report2)) - util_exit("Failed to load report:%d from %s \n", - report2, unified_file); - } else { - restart_files[0] = ecl_file_open(file1); - restart_files[1] = ecl_file_open(file2); - } - - *use_eclbase = true; - if ((storage_mode == ECL_BINARY_UNIFIED) || - (storage_mode == ECL_BINARY_NON_UNIFIED)) - *fmt_file = false; - else - *fmt_file = true; - - *arg_offset = 3; - - free(file1); - free(file2); - free(unified_file); - } - } - } - return restart_files; -} - -/* - This function calculates the gravimetric response for the - gravitation station given as input parameter grav_station. - - For code cleanliness the code is written in a way where this - function is called for every position we are interested in, - performance-wise it would be smarter to loop over the interesting - locations as the inner loop. - - This function does NOT check whether the restart_file / init_file - contains the necessary keywords - and will fail HARD if a required - keyword is not present. That the the input is well-formed should be - checked PRIOR to calling this function. -*/ - -static double gravity_response(const ecl_grid_type *ecl_grid, - const ecl_file_type *init_file, - const ecl_file_type *restart_file1, - const ecl_file_type *restart_file2, - const grav_station_type *grav_station, - int model_phases, int file_phases) { - - ecl_kw_type *rporv1_kw = NULL; - ecl_kw_type *rporv2_kw = NULL; - ecl_kw_type *oil_den1_kw = NULL; - ecl_kw_type *oil_den2_kw = NULL; - ecl_kw_type *gas_den1_kw = NULL; - ecl_kw_type *gas_den2_kw = NULL; - ecl_kw_type *wat_den1_kw = NULL; - ecl_kw_type *wat_den2_kw = NULL; - ecl_kw_type *sgas1_kw = NULL; - ecl_kw_type *sgas2_kw = NULL; - ecl_kw_type *swat1_kw = NULL; - ecl_kw_type *swat2_kw = NULL; - ecl_kw_type *aquifern_kw = NULL; - double local_deltag = 0; - - /* Extracting the pore volumes */ - rporv1_kw = ecl_file_iget_named_kw(restart_file1, "RPORV", 0); - rporv2_kw = ecl_file_iget_named_kw(restart_file2, "RPORV", 0); - - /** Extracting the densities */ - { - // OIL_DEN - if (has_phase(model_phases, OIL)) { - if (simulator == ECLIPSE100) { - oil_den1_kw = - ecl_file_iget_named_kw(restart_file1, "OIL_DEN", 0); - oil_den2_kw = - ecl_file_iget_named_kw(restart_file2, "OIL_DEN", 0); - } else { // ECLIPSE300 - oil_den1_kw = ecl_file_iget_named_kw(restart_file1, "DENO", 0); - oil_den2_kw = ecl_file_iget_named_kw(restart_file2, "DENO", 0); - }; - } - - // GAS_DEN - if (has_phase(model_phases, GAS)) { - if (simulator == ECLIPSE100) { - gas_den1_kw = - ecl_file_iget_named_kw(restart_file1, "GAS_DEN", 0); - gas_den2_kw = - ecl_file_iget_named_kw(restart_file2, "GAS_DEN", 0); - } else { // ECLIPSE300 - gas_den1_kw = ecl_file_iget_named_kw(restart_file1, "DENG", 0); - gas_den2_kw = ecl_file_iget_named_kw(restart_file2, "DENG", 0); - }; - } - - // WAT_DEN - if (has_phase(model_phases, WATER)) { - if (simulator == ECLIPSE100) { - wat_den1_kw = - ecl_file_iget_named_kw(restart_file1, "WAT_DEN", 0); - wat_den2_kw = - ecl_file_iget_named_kw(restart_file2, "WAT_DEN", 0); - } else { // ECLIPSE300 - wat_den1_kw = ecl_file_iget_named_kw(restart_file1, "DENW", 0); - wat_den2_kw = ecl_file_iget_named_kw(restart_file2, "DENW", 0); - }; - } - } - - /* Extracting the saturations */ - { - // SGAS - if (has_phase(file_phases, GAS)) { - sgas1_kw = ecl_file_iget_named_kw(restart_file1, "SGAS", 0); - sgas2_kw = ecl_file_iget_named_kw(restart_file2, "SGAS", 0); - } - - // SWAT - if (has_phase(file_phases, WATER)) { - swat1_kw = ecl_file_iget_named_kw(restart_file1, "SWAT", 0); - swat2_kw = ecl_file_iget_named_kw(restart_file2, "SWAT", 0); - } - } - - /* The numerical aquifer information */ - if (ecl_file_has_kw(init_file, "AQUIFERN")) - aquifern_kw = ecl_file_iget_named_kw(init_file, "AQUIFERN", 0); - { - int nactive = ecl_grid_get_active_size(ecl_grid); - float *zero = util_calloc( - nactive, - sizeof *zero); /* Fake vector of zeros used for densities / sturations when you do not have data. */ - int *int_zero = util_calloc( - nactive, - sizeof *int_zero); /* Fake vector of zeros used for AQUIFER when the init file does not supply data. */ - /* - Observe that the fake vectors are only a coding simplification, - they should not be really used. - */ - - { - int i; - for (i = 0; i < nactive; i++) { - zero[i] = 0; - int_zero[i] = 0; - } - } - { - const float *sgas1_v = safe_get_float_ptr(sgas1_kw, NULL); - const float *swat1_v = safe_get_float_ptr(swat1_kw, NULL); - const float *oil_den1 = safe_get_float_ptr(oil_den1_kw, zero); - const float *gas_den1 = safe_get_float_ptr(gas_den1_kw, zero); - const float *wat_den1 = safe_get_float_ptr(wat_den1_kw, zero); - - const float *sgas2_v = safe_get_float_ptr(sgas2_kw, NULL); - const float *swat2_v = safe_get_float_ptr(swat2_kw, NULL); - const float *oil_den2 = safe_get_float_ptr(oil_den2_kw, zero); - const float *gas_den2 = safe_get_float_ptr(gas_den2_kw, zero); - const float *wat_den2 = safe_get_float_ptr(wat_den2_kw, zero); - - const float *rporv1 = ecl_kw_get_float_ptr(rporv1_kw); - const float *rporv2 = ecl_kw_get_float_ptr(rporv2_kw); - double utm_x = grav_station->utm_x; - double utm_y = grav_station->utm_y; - double tvd = grav_station->depth; - - int *aquifern; - int global_index; - - if (aquifern_kw != NULL) - aquifern = ecl_kw_get_int_ptr(aquifern_kw); - else - aquifern = int_zero; - - for (global_index = 0; - global_index < ecl_grid_get_global_size(ecl_grid); - global_index++) { - const int act_index = - ecl_grid_get_active_index1(ecl_grid, global_index); - if (act_index >= 0) { - - // Not numerical aquifer - if (aquifern[act_index] >= 0) { - float swat1 = swat1_v[act_index]; - float swat2 = swat2_v[act_index]; - float sgas1 = 0; - float sgas2 = 0; - float soil1 = 0; - float soil2 = 0; - - truncate_saturation(&swat1); - truncate_saturation(&swat2); - - if (has_phase(model_phases, GAS)) { - if (has_phase(file_phases, GAS)) { - sgas1 = sgas1_v[act_index]; - sgas2 = sgas2_v[act_index]; - truncate_saturation(&sgas1); - truncate_saturation(&sgas2); - } else { - sgas1 = 1 - swat1; - sgas2 = 1 - swat2; - } - } - - if (has_phase(model_phases, OIL)) { - soil1 = 1 - sgas1 - swat1; - soil2 = 1 - sgas2 - swat2; - truncate_saturation(&soil1); - truncate_saturation(&soil2); - } - - /* - We have found all the info we need for one cell. - */ - - { - double mas1, mas2; - double xpos, ypos, zpos; - - mas1 = rporv1[act_index] * - (soil1 * oil_den1[act_index] + - sgas1 * gas_den1[act_index] + - swat1 * wat_den1[act_index]); - mas2 = rporv2[act_index] * - (soil2 * oil_den2[act_index] + - sgas2 * gas_den2[act_index] + - swat2 * wat_den2[act_index]); - - ecl_grid_get_xyz1(ecl_grid, global_index, &xpos, - &ypos, &zpos); - { - double dist_x = xpos - utm_x; - double dist_y = ypos - utm_y; - double dist_d = zpos - tvd; - double dist_sq = dist_x * dist_x + - dist_y * dist_y + - dist_d * dist_d; - - if (dist_sq == 0) { - exit(1); - } - local_deltag += - 6.67428E-3 * (mas2 - mas1) * dist_d / - pow(dist_sq, - 1.5); // Gravity in units of \mu Gal = 10^{-8} m/s^2 - } - } - } - } - } - } - free(zero); - free(int_zero); - } - return local_deltag; -} - -static void *gravity_response_mt(void *arg) { - arg_pack_type *arg_pack = arg_pack_safe_cast(arg); - vector_type *grav_stations = arg_pack_iget_ptr(arg_pack, 0); - const ecl_grid_type *ecl_grid = arg_pack_iget_ptr(arg_pack, 1); - const ecl_file_type *init_file = arg_pack_iget_ptr(arg_pack, 2); - ecl_file_type **restart_files = arg_pack_iget_ptr(arg_pack, 3); - int station1 = arg_pack_iget_int(arg_pack, 4); - int station2 = arg_pack_iget_int(arg_pack, 5); - int model_phases = arg_pack_iget_int(arg_pack, 6); - int file_phases = arg_pack_iget_int(arg_pack, 7); - - int station_nr; - for (station_nr = station1; station_nr < station2; station_nr++) { - grav_station_type *gs = vector_iget(grav_stations, station_nr); - - gs->grav_diff = - gravity_response(ecl_grid, init_file, restart_files[0], - restart_files[1], gs, model_phases, file_phases); - } - return NULL; -} - -/* - Validate input: - --------------- - This function tries to verify that the restart_files contain all - the necessary information. The required keywords are: - - 1. The restart files must contain RPORV and XXX_DEN (see info - about phases below). - - 2. The init file must contain the PORV keyword - this is only used - to check for the ECLIPSE_2008 bug in RPORV calculations. - - - - Determine phases: - ----------------- - Look at the restart files to determine which phases are - present. The restart files generally only contain (n - 1) phases, - i.e. for a WATER-OIL-GAS system the restart files will contain SGAS - and SWAT, but not SOIL. - - We must determine which phases are in the model, that is determined - by looking for the densities OIL_DEN, WAT_DEN and GAS_DEN. This is - stored in the variable model_phases. In addition we must determine - which saturations can be found in the restart files, that is stored - in the file_phases variable. The variables model_phases and - file_phases are returned by reference. - - - If the input is valid, the function will return zero, otherwise it - will return a non-zero error code: (ehhh - it will exit currently). - -*/ - -static int gravity_check_input(const ecl_grid_type *ecl_grid, - const ecl_file_type *init_file, - const ecl_file_type *restart_file1, - const ecl_file_type *restart_file2, - int *__model_phases, int *__file_phases) { - { - int model_phases = 0; - int file_phases = 0; - - /* Check which phases are present in the model */ - if (ecl_file_has_kw(restart_file1, "OIL_DEN")) { - model_phases += OIL; - simulator = ECLIPSE100; - } else if (ecl_file_has_kw(restart_file1, "DENO")) { - model_phases += OIL; - simulator = ECLIPSE300; - }; - - if (ecl_file_has_kw(restart_file1, "WAT_DEN")) { - model_phases += WATER; - simulator = ECLIPSE100; - } else if (ecl_file_has_kw(restart_file1, "DENW")) { - model_phases += WATER; - simulator = ECLIPSE300; - }; - - if (ecl_file_has_kw(restart_file1, "GAS_DEN")) { - model_phases += GAS; - simulator = ECLIPSE100; - } else if (ecl_file_has_kw(restart_file1, "DENG")) { - model_phases += GAS; - simulator = ECLIPSE300; - }; - - /* Check which phases are present in the restart files. We assume the restart file NEVER has SOIL information */ - if (ecl_file_has_kw(restart_file1, "SWAT")) - file_phases += WATER; - if (ecl_file_has_kw(restart_file1, "SGAS")) - file_phases += GAS; - - /* Consiency check */ - { - /** - The following assumptions are made: - - 1. All restart files should have water, i.e. the SWAT keyword. - 2. All phases present in the restart file should also be present as densities, - in addition the model must contain one additional phase. - 3. The restart files can never contain oil saturation. - - */ - if (!has_phase(file_phases, WATER)) - util_exit("Could not locate SWAT keyword in restart files\n"); - - if (has_phase(file_phases, OIL)) - util_exit("Can not handle restart files with SOIL keyword\n"); - - if (!has_phase(model_phases, WATER)) - util_exit( - "Could not locate WAT_DEN keyword in restart files\n"); - - if (has_phase(file_phases, GAS)) { - /** Restart file has both water and gas - means we need all three densities. */ - if (!(has_phase(model_phases, GAS) && - has_phase(model_phases, OIL))) - util_exit("Could not find GAS_DEN and OIL_DEN keywords in " - "restart files\n"); - } else { - /* This is (water + oil) or (water + gas) system. We enforce one of the densities.*/ - if (!has_phase(model_phases, GAS + OIL)) - util_exit("Could not find either GAS_DEN or OIL_DEN " - "kewyords in restart files\n"); - } - } - *__model_phases = model_phases; - *__file_phases = file_phases; - } - - /* Check that the restart files have RPORV information. This is ensured by giving the argument RPORV to the RPTRST keyword. */ - if (!(ecl_file_has_kw(restart_file1, "RPORV") && - ecl_file_has_kw(restart_file2, "RPORV"))) - util_exit("Sorry: the restartfiles do not contain RPORV\n"); - - /** - Check that the rporv values are in the right ballpark. For - ECLIPSE version 2008.2 they are way off. Check PORV - versus RPORV for ten 'random' locations in the grid. - */ - { - const ecl_kw_type *rporv1_kw = - ecl_file_iget_named_kw(restart_file1, "RPORV", 0); - const ecl_kw_type *rporv2_kw = - ecl_file_iget_named_kw(restart_file2, "RPORV", 0); - const ecl_kw_type *init_porv_kw = - ecl_file_iget_named_kw(init_file, "PORV", 0); - - int active_index; - int active_delta; - int active_size; - - ecl_grid_get_dims(ecl_grid, NULL, NULL, NULL, &active_size); - active_delta = active_size / 12; - for (active_index = active_delta; active_index < active_size; - active_index += active_delta) { - int global_index = - ecl_grid_get_global_index1A(ecl_grid, active_index); - double init_porv = ecl_kw_iget_as_double( - init_porv_kw, - global_index); /* NB - this uses global indexing. */ - double rporv1 = ecl_kw_iget_as_double(rporv1_kw, active_index); - double rporv2 = ecl_kw_iget_as_double(rporv2_kw, active_index); - double rporv12 = 0.5 * (rporv1 + rporv2); - double fraction = util_double_min(init_porv, rporv12) / - util_double_max(init_porv, rporv12); - - if (fraction < 0.50) { - fprintf(stderr, "----------------------------------------------" - "-------------------\n"); - fprintf(stderr, "INIT PORV: %g \n", init_porv); - fprintf(stderr, "RPORV1 : %g \n", rporv1); - fprintf(stderr, "RPORV2 : %g \n", rporv2); - fprintf(stderr, "Hmmm - the RPORV values extracted from the " - "restart file seem to be \n"); - fprintf(stderr, "veeery different from the initial rporv " - "value. This might indicated\n"); - fprintf(stderr, "an ECLIPSE bug. Version 2007.2 is known to be " - "ok in this respect, \n"); - fprintf(stderr, - "whereas version 2008.2 is known to have a bug. \n"); - fprintf(stderr, "----------------------------------------------" - "-------------------\n"); - exit(1); - } - } - } - - return 0; -} - -void install_SIGNALS(void) { - signal( - SIGSEGV, - util_abort_signal); /* Segmentation violation, i.e. overwriting memory ... */ - signal(SIGINT, util_abort_signal); /* Control C */ - signal( - SIGTERM, - util_abort_signal); /* If killing the program with SIGTERM (the default kill signal) you will get a backtrace. - Killing with SIGKILL (-9) will not give a backtrace.*/ -} - -int main(int argc, char **argv) { - install_SIGNALS(); - - if (argc > 1) { - if (strcmp(argv[1], "-h") == 0) - print_usage(__LINE__); - } - - if (argc < 2) - print_usage(__LINE__); - - else { - char **input = &argv[1]; /* Skipping the name of the executable */ - int input_length = argc - 1; - int input_offset = 0; - bool use_eclbase, fmt_file; - - const char *report_filen = "RUN_GRAVITY.out"; - - ecl_file_type **restart_files; - ecl_file_type *init_file; - ecl_grid_type *ecl_grid; - - int model_phases; - int file_phases; - vector_type *grav_stations = vector_alloc_new(); - - /* Restart info */ - restart_files = - load_restart_info((const char **)input, input_length, &input_offset, - &use_eclbase, &fmt_file); - - /* INIT and GRID/EGRID files */ - { - char *grid_filename = NULL; - char *init_filename = NULL; - if (use_eclbase) { - /* - The first command line argument is interpreted as ECLBASE, and we - search for grid and init files in cwd. - */ - init_filename = ecl_util_alloc_exfilename_anyfmt( - NULL, input[0], ECL_INIT_FILE, fmt_file, -1); - grid_filename = ecl_util_alloc_exfilename_anyfmt( - NULL, input[0], ECL_EGRID_FILE, fmt_file, -1); - if (grid_filename == NULL) - grid_filename = ecl_util_alloc_exfilename_anyfmt( - NULL, input[0], ECL_GRID_FILE, fmt_file, -1); - - if ((init_filename == NULL) || - (grid_filename == NULL)) /* Means we could not find them. */ - util_exit("Could not find INIT or GRID|EGRID file \n"); - } else { - if ((input_length - input_offset) > 1) { - init_filename = util_alloc_string_copy(input[input_offset]); - grid_filename = - util_alloc_string_copy(input[input_offset + 1]); - input_offset += 2; - } else - print_usage(__LINE__); - } - - init_file = ecl_file_open(init_filename); - ecl_grid = ecl_grid_alloc(grid_filename); - free(init_filename); - free(grid_filename); - } - - // Load the station_file - if (input_length > input_offset) { - char *station_file = input[input_offset]; - if (util_file_exists(station_file)) - load_stations(grav_stations, station_file); - else - util_exit("Can not find file:%s \n", station_file); - } else - print_usage(__LINE__); - - /** - OK - now everything is loaded - check that all required - keywords+++ are present. - */ - gravity_check_input(ecl_grid, init_file, restart_files[0], - restart_files[1], &model_phases, &file_phases); - - /* - OK - now it seems the provided files have all the information - we need. Let us start using it. The main loop is run in - parallell on four threads - most people have four cores these - days. - */ - { - int i; - int num_threads = 4; - thread_pool_type *tp = thread_pool_alloc(num_threads, true); - arg_pack_type **arg_list = - util_calloc(num_threads, sizeof *arg_list); - { - int station_delta = - vector_get_size(grav_stations) / num_threads; - for (i = 0; i < num_threads; i++) { - int station1 = i * station_delta; - int station2 = station1 + station_delta; - if (i == num_threads) - station2 = vector_get_size(grav_stations); - - arg_list[i] = arg_pack_alloc(); - - arg_pack_append_ptr(arg_list[i], grav_stations); - arg_pack_append_ptr(arg_list[i], ecl_grid); - arg_pack_append_ptr(arg_list[i], init_file); - arg_pack_append_ptr(arg_list[i], restart_files); - arg_pack_append_int(arg_list[i], station1); - arg_pack_append_int(arg_list[i], station2); - arg_pack_append_int(arg_list[i], model_phases); - arg_pack_append_int(arg_list[i], file_phases); - - thread_pool_add_job(tp, gravity_response_mt, arg_list[i]); - } - } - thread_pool_join(tp); - for (i = 0; i < num_threads; i++) - arg_pack_free(arg_list[i]); - free(arg_list); - } - - { - FILE *stream = util_fopen(report_filen, "w"); - int station_nr; - double total_chisq = 0; - for (station_nr = 0; station_nr < vector_get_size(grav_stations); - station_nr++) { - const grav_station_type *g_s = - vector_iget_const(grav_stations, station_nr); - fprintf(stream, "%f", g_s->grav_diff); - printf("DELTA_G %4s[%02d]: %12.6f %12.6f %12.6f %12.6f", - g_s->name, station_nr, g_s->grav_diff, g_s->utm_x, - g_s->utm_y, g_s->depth); - - if (g_s->has_obs) { - double y = - (g_s->grav_diff - g_s->obs_gdiff) / g_s->std_gdiff; - double chi_sq = y * y; - total_chisq += chi_sq; - fprintf(stream, " %g", chi_sq); - printf(" %g", chi_sq); - } - - fprintf(stream, " \n"); - printf("\n"); - } - if (total_chisq > 0) { - printf("Total chisq misfit: %g \n", total_chisq); - } - fclose(stream); - } - - vector_free(grav_stations); - ecl_grid_free(ecl_grid); - ecl_file_close(restart_files[0]); - ecl_file_close(restart_files[1]); - free(restart_files); - ecl_file_close(init_file); - } -} diff --git a/applications/ecl/summary2csv2.c b/applications/ecl/summary2csv2.c deleted file mode 100644 index a96831fed..000000000 --- a/applications/ecl/summary2csv2.c +++ /dev/null @@ -1,157 +0,0 @@ -/* - Copyright (C) 2013 Equinor ASA, Norway. - The file 'summary2csv2.c' is part of ERT - Ensemble based Reservoir Tool. - - ERT is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#include -#include -#include -#include - -#include -#include - -#include - -static void fprintf_line(const ecl_sum_type *ecl_sum, - const ecl_sum_fmt_type *fmt, const char *well, - int time_index, const stringlist_type *var_list, - FILE *stream) { - /* WELL */ - fprintf(stream, fmt->header_fmt, well); - fprintf(stream, fmt->sep); - - /* DAYS */ - fprintf(stream, fmt->days_fmt, ecl_sum_iget_sim_days(ecl_sum, time_index)); - fprintf(stream, fmt->sep); - - /* DATE */ - { - struct tm ts; - const int DATE_STRING_LENGTH = 128; - char *date_string = - util_malloc(DATE_STRING_LENGTH * sizeof *date_string); - time_t sim_time = ecl_sum_iget_sim_time(ecl_sum, time_index); - util_localtime(&sim_time, &ts); - strftime(date_string, DATE_STRING_LENGTH - 1, fmt->date_fmt, &ts); - fprintf(stream, date_string); - free(date_string); - } - - { - int ivar; - for (ivar = 0; ivar < stringlist_get_size(var_list); ivar++) { - const char *var = stringlist_iget(var_list, ivar); - double value = 0; - if (ecl_sum_has_well_var(ecl_sum, well, var)) - value = ecl_sum_get_well_var(ecl_sum, time_index, well, var); - else - fprintf(stderr, - "Missing variable:%s for well:%s - substituting 0.0 \n", - var, well); - - fprintf(stream, fmt->sep); - fprintf(stream, fmt->value_fmt, value); - } - fprintf(stream, fmt->newline); - } -} - -int main(int argc, char **argv) { - { - ecl_sum_fmt_type fmt; - bool include_restart = true; - int arg_offset = 1; - - if (argc != 2) { - printf("You must supply the name of a case as:\n\n " - "summary2csv.exe ECLIPSE_CASE\n\nThe case can optionally " - "contain a leading path component.\n"); - exit(1); - } - - { - char *data_file = argv[arg_offset]; - ecl_sum_type *ecl_sum; - stringlist_type *var_list = stringlist_alloc_new(); - - stringlist_append_ref(var_list, "WOPR"); - stringlist_append_ref(var_list, "WOPT"); - stringlist_append_ref(var_list, "WGPR"); - stringlist_append_ref(var_list, "WGPT"); - stringlist_append_ref(var_list, "WWPR"); - stringlist_append_ref(var_list, "WWPT"); - - ecl_sum_fmt_init_csv(&fmt); - ecl_sum = - ecl_sum_fread_alloc_case__(data_file, ":", include_restart); - if (ecl_sum != NULL) { - char *csv_file = util_alloc_filename( - NULL, ecl_sum_get_base(ecl_sum), - "txt"); // Will save to current path; can use ecl_sum_get_path() to save to target path instead. - FILE *stream = util_fopen(csv_file, "w"); - - stringlist_type *well_list = - ecl_sum_alloc_well_list(ecl_sum, NULL); - stringlist_type *key_list = stringlist_alloc_new(); - - fprintf(stream, fmt.header_fmt, "WELLNAME"); - - fprintf(stream, fmt.sep); - fprintf(stream, fmt.header_fmt, "DAYS"); - - fprintf(stream, fmt.sep); - fprintf(stream, fmt.header_fmt, "DATES"); - - { - int ivar; - for (ivar = 0; ivar < stringlist_get_size(var_list); - ivar++) { - const char *var = stringlist_iget(var_list, ivar); - fprintf(stream, fmt.sep); - fprintf(stream, fmt.header_fmt, var); - } - fprintf(stream, "\n"); - } - - { - int iw; - for (iw = 0; iw < stringlist_get_size(well_list); iw++) { - const char *well = stringlist_iget(well_list, iw); - if (ecl_sum_is_oil_producer(ecl_sum, well)) { - int time_index; - for (time_index = 0; - time_index < ecl_sum_get_data_length(ecl_sum); - time_index++) - fprintf_line(ecl_sum, &fmt, well, time_index, - var_list, stream); - } - } - } - - stringlist_free(well_list); - stringlist_free(key_list); - ecl_sum_free(ecl_sum); - fclose(stream); - free(csv_file); - } else - fprintf(stderr, - "summary2csv2: No summary data found for case:%s\n", - data_file); - - stringlist_free(var_list); - } - } -} diff --git a/applications/ecl/view_restart.c b/applications/ecl/view_restart.c deleted file mode 100644 index 9f248311e..000000000 --- a/applications/ecl/view_restart.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - Copyright (C) 2011 Equinor ASA, Norway. - - The file 'view_restart.c' is part of ERT - Ensemble based Reservoir Tool. - - ERT is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#include -#include -#include -#include - -int main(int argc, char **argv) { - if (argc < 3) - util_exit("Usage: PRESSURE:10,5,17 SWAT:10,5,7 ...\n"); - { - // Broken ... ecl_grid_type * ecl_grid = NULL; - // Broken ... int num_restart_files; - // Broken ... char ** restart_files; - // Broken ... { - // Broken ... const char * first_arg = argv[1]; - // Broken ... char * base; - // Broken ... char * path; - // Broken ... ecl_file_enum file_type; - // Broken ... - // Broken ... ecl_util_get_file_type(first_arg , &file_type , NULL , NULL); - // Broken ... if (file_type == ecl_grid_file || file_type == ecl_egrid_file) - // Broken ... ecl_grid = ecl_grid_alloc( first_arg , true ); - // Broken ... - // Broken ... util_alloc_file_components(first_arg , &path , &base , NULL); - // Broken ... - // Broken ... ecl_util_alloc_restart_files(path , base , &restart_files , &num_restart_files , NULL , NULL); - // Broken ... ecl_util_get_file_type(restart_files[0] , &file_type , NULL , NULL); - // Broken ... { - // Broken ... const char ** arg_list = (const char **) &argv[2]; - // Broken ... char ** kw_list; - // Broken ... int * index_list; - // Broken ... int num_kw = argc - 2; - // Broken ... ecl_fstate_type * fstate = ecl_fstate_fread_alloc(num_restart_files , (const char **) restart_files , file_type , true , true); - // Broken ... int num_blocks = ecl_fstate_get_size(fstate); - // Broken ... int iblock; - // Broken ... - // Broken ... /* - // Broken ... Finding the indices ... - // Broken ... */ - // Broken ... kw_list = util_malloc(num_kw * sizeof * kw_list , __func__); - // Broken ... index_list = util_malloc(num_kw * sizeof * index_list , __func__); - // Broken ... { - // Broken ... char ** tokens; - // Broken ... int num_tokens; - // Broken ... for (int ikw = 0; ikw < num_kw; ikw++) { - // Broken ... util_split_string(arg_list[ikw] , ":" , &num_tokens , &tokens); - // Broken ... if (num_tokens != 2) - // Broken ... util_exit("Failed to parse \"%s\" as KEWYORD:INDEX \n", arg_list[ikw]); - // Broken ... kw_list[ikw] = util_alloc_string_copy( tokens[0] ); - // Broken ... { - // Broken ... int *ijk , num_coord; - // Broken ... ijk = util_sscanf_alloc_active_list( tokens[1] , &num_coord ); - // Broken ... if (ecl_grid == NULL) { - // Broken ... if (num_coord != 1) - // Broken ... util_exit("Failed to extract one integer from: %s \n",tokens[1]); - // Broken ... else - // Broken ... index_list[ikw] = ijk[0]; - // Broken ... } else { - // Broken ... if (num_coord == 1) - // Broken ... index_list[ikw] = ecl_grid_get_active_index_from_global(ecl_grid , ijk[0]); - // Broken ... else if (num_coord == 3) { - // Broken ... int i = ijk[0] - 1; - // Broken ... int j = ijk[1] - 1; - // Broken ... int k = ijk[2] - 1; - // Broken ... - // Broken ... index_list[ikw] = ecl_grid_get_active_index(ecl_grid , i,j,k); - // Broken ... } else - // Broken ... util_exit("Failed to parse \"%s\" as one or three integers.\n",tokens[1]); - // Broken ... } - // Broken ... free(ijk); - // Broken ... } - // Broken ... - // Broken ... - // Broken ... index_list[ikw] = 100; /* ... */ - // Broken ... util_free_stringlist(tokens , num_tokens); - // Broken ... } - // Broken ... } - // Broken ... - // Broken ... for (iblock = 0; iblock < num_blocks; iblock++) { - // Broken ... ecl_block_type * ecl_block = ecl_fstate_iget_block( fstate , iblock); - // Broken ... time_t sim_time = ecl_block_get_sim_time(ecl_block); - // Broken ... int day,month,year , report_step; - // Broken ... double sim_days; - // Broken ... - // Broken ... sim_days = ecl_block_get_sim_days(ecl_block); - // Broken ... report_step = ecl_block_get_report_nr( ecl_block ); - // Broken ... util_set_date_values( sim_time , &day , &month , &year); - // Broken ... printf("%04d %02d/%02d/%04d %9.3f ",report_step , day , month , year , sim_days ); - // Broken ... - // Broken ... for (int ikw = 0; ikw < num_kw; ikw++) { - // Broken ... ecl_kw_type * ecl_kw = ecl_block_iget_kw(ecl_block , kw_list[ikw] , 0); - // Broken ... printf(" %14.6f ", ecl_kw_iget_float(ecl_kw , index_list[ikw])); - // Broken ... } - // Broken ... printf("\n"); - // Broken ... } - // Broken ... ecl_fstate_free(fstate); - // Broken ... } - // Broken ... } - } -} diff --git a/applications/ecl/view_rft.c b/applications/ecl/view_rft.c deleted file mode 100644 index 9dd7b406f..000000000 --- a/applications/ecl/view_rft.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - Copyright (C) 2011 Equinor ASA, Norway. - - The file 'view_rft.c' is part of ERT - Ensemble based Reservoir Tool. - - ERT is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#include -#include -#include -#include - -int main(int argc, char **argv) { - - if (argc != 2) - util_exit("Usage: rft.x BASENAME \n"); - { - char *input_file = argv[1]; - char *file_name = NULL; - ecl_file_enum input_type; - - ecl_rft_file_type *rft_file; - - input_type = ecl_util_get_file_type(input_file, NULL, NULL); - if (input_type == ECL_RFT_FILE) - file_name = util_alloc_string_copy(input_file); - else { - char *base; - char *path; - char *rft_file_formatted; - char *rft_file_unformatted; - - util_alloc_file_components(input_file, &path, &base, NULL); - rft_file_formatted = - ecl_util_alloc_filename(path, base, ECL_RFT_FILE, true, -1); - rft_file_unformatted = - ecl_util_alloc_filename(path, base, ECL_RFT_FILE, false, -1); - - if (util_file_exists(rft_file_formatted) && - util_file_exists(rft_file_unformatted)) - file_name = util_alloc_string_copy( - util_newest_file(rft_file_formatted, rft_file_unformatted)); - else if (util_file_exists(rft_file_formatted)) - file_name = util_alloc_string_copy(rft_file_formatted); - else if (util_file_exists(rft_file_unformatted)) - file_name = util_alloc_string_copy(rft_file_unformatted); - else - util_exit("Could not find RFT files: %s/%s \n", - rft_file_formatted, rft_file_unformatted); - - free(rft_file_formatted); - free(rft_file_unformatted); - free(base); - free(path); - } - - rft_file = ecl_rft_file_alloc(file_name); - ecl_rft_file_summarize(rft_file, true); - ecl_rft_file_free(rft_file); - } -} diff --git a/applications/ecl/vprofile.c b/applications/ecl/vprofile.c deleted file mode 100644 index 935dd8f01..000000000 --- a/applications/ecl/vprofile.c +++ /dev/null @@ -1,266 +0,0 @@ -/* - Copyright (C) 2011 Equinor ASA, Norway. - - The file 'vprofile.c' is part of ERT - Ensemble based Reservoir Tool. - - ERT is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ -#include - -#include -#include -#include - -#include -#include -#include -#include - -static void usage() { - printf( - "-----------------------------------------------------------------\n"); - printf( - "This little program can be used to extract vertical properties of\n"); - printf("solution data from ECLIPSE restart files. The program needs the\n"); - printf("following input, from the commandline:\n"); - printf("\n"); - printf(" 1. The i,j coordinates you are interested in.\n"); - printf("\n"); - printf(" 2. The ECLIPSE basename - this can either be just the basename, " - "or an\n"); - printf(" arbitrary ECLIPSE file with the correct basename. (Can contain " - "a\n"); - printf(" leading path part).\n"); - printf("\n"); - printf(" 3. The keyword you want to extract, this will typically be SWAT, " - "SGAS\n"); - printf(" or PRESSURE.\n"); - printf("\n"); - printf(" 4. A filename (can contain a path component) for the profile\n"); - printf(" files. This filename MUST contain a %%d format specifier which " - "will\n"); - printf(" be replaced with the report step.\n"); - printf("\n"); - printf(" 5. The timesteps you want to consider.\n"); - printf("\n"); - printf("\n"); - printf("Example:\n"); - printf("--------\n"); - printf("\n"); - printf(" bash%% vprofile 10 5 MODEL1.DATA SWAT profiles/SWAT_%%04d 0 10 " - "20 30 40 50 60 \n"); - printf("\n"); - printf("This will load vertical profiles for i=10 and j=5. The results " - "will be\n"); - printf( - "loaded from a simulation with basename 'MODEL1'. It will load the\n"); - printf("keyword 'SWAT', the profiles will be written to the the files:\n"); - printf("\n"); - printf(" profiles/swat_0000\n"); - printf(" profiles/swat_0010\n"); - printf(" profiles/swat_0020\n"); - printf(" ....\n"); - printf(" profiles/swat_0060\n"); - printf("\n"); - printf( - "The profile files will contain two columns, the keyword you have\n"); - printf("have asked for and the depth. The i,j must be from the global " - "grid, but (if\n"); - printf("available) LGR information will be used for the profiles. The " - "program\n"); - printf("works roughly as follows:\n"); - printf("\n"); - printf(" 1. Based on the ECLIPSE basename the program will look for an " - "EGRID,\n"); - printf(" alternatively GRID file, and load this.\n"); - printf("\n"); - printf(" 2. Will load restart information based on the timesteps given by " - "the\n"); - printf(" user. The program will first look for a unified restart file, " - "and\n"); - printf(" then subsequently for non unified files.\n"); - printf("\n"); - printf(" 3. Scans thorough the timesteps/profiles and creates output " - "files. \n"); - printf(" \n"); - printf("Observe that the program ONLY looks for unformatted files.\n"); - printf( - "-----------------------------------------------------------------\n"); - exit(1); -} - -static void vprofile__(int i, int j, const ecl_grid_type *ecl_grid, - const ecl_file_type *ecl_file, const char *kw, - double_vector_type *depth, double_vector_type *profile) { - int k; - int nz = ecl_grid_get_nz(ecl_grid); - ecl_kw_type *ecl_kw = - ecl_file_iget_named_kw(ecl_file, kw, ecl_grid_get_grid_nr(ecl_grid)); - for (k = 0; k < nz; k++) { - int active_index = ecl_grid_get_active_index3(ecl_grid, i, j, k); - if (active_index >= 0) { - ecl_grid_type *lgr = ecl_grid_get_cell_lgr3(ecl_grid, i, j, k); - if (lgr != NULL) { - /* Recursive dive .. */ - double x, y, z; - int lgr_i, lgr_j, lgr_k, lgr_global; - - ecl_grid_get_xyz3(ecl_grid, i, j, k, &x, &y, &z); - lgr_global = - ecl_grid_get_global_index_from_xyz(lgr, x, y, z, 0); - if (lgr_global < 0) - util_exit( - "Hmmmm - could not locate point: %g,%g,%g in lgr:%s \n", - x, y, z, ecl_grid_get_name(lgr)); - - ecl_grid_get_ijk1(lgr, lgr_global, &lgr_i, &lgr_j, &lgr_k); - vprofile__(lgr_i, lgr_j, lgr, ecl_file, kw, depth, profile); - } - - double_vector_append(depth, - ecl_grid_get_cdepth3(ecl_grid, i, j, k)); - double_vector_append(profile, - ecl_kw_iget_as_double(ecl_kw, active_index)); - } - } -} - -static void vprofile(int i, int j, const ecl_grid_type *ecl_grid, - const ecl_file_type *ecl_file, const char *kw, int tstep, - path_fmt_type *output_fmt) { - if (ecl_file_has_kw(ecl_file, kw)) { - double_vector_type *depth = double_vector_alloc(0, 0); - double_vector_type *profile = double_vector_alloc(0, 0); - vprofile__(i, j, ecl_grid, ecl_file, kw, depth, profile); - - { - char *filename = path_fmt_alloc_file(output_fmt, true, tstep); - int *perm = double_vector_alloc_sort_perm(depth); - FILE *stream = util_fopen(filename, "w"); - int l; - double_vector_permute(depth, perm); - double_vector_permute(profile, perm); - for (l = 0; l < double_vector_size(depth); l++) - fprintf(stream, "%12.5f %12.5f\n", - double_vector_iget(profile, l), - -double_vector_iget(depth, l)); - - free(perm); - fclose(stream); - free(filename); - } - } -} - -int main(int argc, char **argv) { - if (argc < 6) - usage(); - { - const char *base_file = argv[3]; - const char *kw = argv[4]; - const char *fmt = argv[5]; - const char **tlist = (const char **)&argv[6]; - const int num_tstep = argc - 6; - int i, j; - - if (util_sscanf_int(argv[1], &i) && util_sscanf_int(argv[2], &j)) { - bool unified; - path_fmt_type *output_fmt; - char *restart_file; - char *path; - char *eclbase; - ecl_grid_type *ecl_grid; - - util_alloc_file_components(base_file, &path, &eclbase, NULL); - { - char *grid_file = ecl_util_alloc_filename( - path, eclbase, ECL_EGRID_FILE, false, -1); - if (util_file_exists(grid_file)) { - ecl_grid = ecl_grid_alloc(grid_file); - printf("Loading grid file: %s \n", grid_file); - } else { - free(grid_file); - grid_file = ecl_util_alloc_filename( - path, eclbase, ECL_GRID_FILE, false, -1); - if (util_file_exists(grid_file)) { - ecl_grid = ecl_grid_alloc(grid_file); - printf("Loading grid file: %s \n", grid_file); - } else { - fprintf(stderr, - "Could not locate %s.EGRID or %s.GRID file in " - "%s.\n", - eclbase, eclbase, path); - exit(1); - } - } - free(grid_file); - } - - restart_file = ecl_util_alloc_filename( - path, eclbase, ECL_UNIFIED_RESTART_FILE, false, -1); - if (util_file_exists(restart_file)) - unified = true; - else { - unified = false; - free(restart_file); - } - - output_fmt = path_fmt_alloc_path_fmt(fmt); - - { - int it; - for (it = 0; it < num_tstep; it++) { - int tstep; - if (util_sscanf_int(tlist[it], &tstep)) { - ecl_file_type *ecl_file = NULL; - - if (unified) { - ecl_file = ecl_file_open(restart_file); - if (!ecl_file_select_rstblock_report_step(ecl_file, - tstep)) { - fprintf(stderr, - "** Failed to load restart information " - "for step:%d \n", - tstep); - exit(1); - } else - printf("Loading report step:%d from:%s \n", - tstep, restart_file); - } else { - restart_file = ecl_util_alloc_exfilename( - path, eclbase, ECL_RESTART_FILE, false, tstep); - if (restart_file != NULL) { - ecl_file = ecl_file_open(restart_file); - printf("Loading report step:%d from:%s \n", - tstep, restart_file); - } - } - - vprofile(i - 1, j - 1, ecl_grid, ecl_file, kw, tstep, - output_fmt); - - if (!unified) - free(restart_file); - } else - fprintf(stderr, - "** The string: \'%s\' was not interpreted as " - "a time-step - ignored \n", - tlist[it]); - } - } - } else - fprintf(stderr, - "Failed to interpret \'%s\' and \'%s\' as integers.\n", - argv[1], argv[2]); - } -} diff --git a/applications/example_ens_plot_batch_file b/applications/example_ens_plot_batch_file deleted file mode 100644 index 615be1c0d..000000000 --- a/applications/example_ens_plot_batch_file +++ /dev/null @@ -1,48 +0,0 @@ -/project/idi/personlig/eism/sandbox/eclplot/Plotpath -c -hist -/project/idi/proj/HMprojects/gurbat/debug/Simulations/ROUND_1_NR_0 -_stop_ -c -post -/project/idi/proj/HMprojects/gurbat/debug/Simulations/ROUND_1_NR_0 -/project/idi/proj/HMprojects/gurbat/debug/Simulations/ROUND_1_NR_1 -/project/idi/proj/HMprojects/gurbat/debug/Simulations/ROUND_1_NR_2 -_stop_ -c -prior -/project/idi/proj/HMprojects/gurbat/debug/Simulations/PRIOR_DEBUG_0_0 -/project/idi/proj/HMprojects/gurbat/debug/Simulations/PRIOR_DEBUG_0_1 -/project/idi/proj/HMprojects/gurbat/debug/Simulations/PRIOR_DEBUG_0_2 -_stop_ -a -post -1 -a -hist -15 -p -BPR:15,28,1 -post -prior -_meas_points_ -xxy 1843.213203435596 1800.786796 300.05 -xyy 21/09/2002 100.3313 200.26064 -xy 21/09/2003 150.33 -_stop_ -_set_range_ -XMIN 01/01/2000 XMAX 01/01/2010 YMAX 100.0 YMAX 400.0 -_stop_ -p -RFT:WI_1:2/9/2000 -prior -post -_set_range_ -XMIN 300 XMAX 400 -_meas_points_ -rft 15 28 1 340.0 345.2 -rft 15 28 10 345 350 -rft 15 28 14 350 352 -_stop_ -_stop_ -q \ No newline at end of file diff --git a/applications/irap_test.c b/applications/irap_test.c deleted file mode 100644 index 5323c7a2c..000000000 --- a/applications/irap_test.c +++ /dev/null @@ -1,30 +0,0 @@ - - -#include -#include -#include -#include - -int main(int argc, char **argv) { - const char *irap_file = "surface.irap"; - { - geo_surface_type *surface = - geo_surface_fload_alloc_irap(irap_file, true); - geo_surface_fprintf_irap(surface, "surface2.irap"); - geo_surface_free(surface); - } - - { - geo_surface_type *surface = - geo_surface_fload_alloc_irap(irap_file, false); - - { - double *zlist = - util_calloc(geo_surface_get_size(surface), sizeof *zlist); - geo_surface_fload_irap_zcoord(surface, irap_file, zlist); - free(zlist); - } - - geo_surface_free(surface); - } -} diff --git a/applications/polygon_test.c b/applications/polygon_test.c deleted file mode 100644 index d9420ae9c..000000000 --- a/applications/polygon_test.c +++ /dev/null @@ -1,15 +0,0 @@ - - -#include -#include -#include -#include -#include - -int main(int argc, char **argv) { - const char *irap_file = "polygontest.irap"; - - geo_polygon_type *polygon = geo_polygon_fload_alloc_irap(irap_file); - - geo_polygon_free(polygon); -}