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 ); }
static bool custom_kw_config_setup__(custom_kw_config_type * config, const char * result_file) { FILE * stream = util_fopen__(result_file, "r"); if (stream != NULL) { bool read_ok = true; config->key_definition_file = util_alloc_string_copy(result_file); int counter = 0; char key[128]; char value[128]; int read_count; while ((read_count = fscanf(stream, "%s %s", key, value)) != EOF) { if (read_count == 1) { fprintf(stderr ,"[%s] Warning: Key: '%s:%s' is missing value in file: '%s'\n", __func__, config->name, key, result_file); read_ok = false; break; } if (custom_kw_config_has_key(config, key)) { fprintf(stderr ,"[%s] Warning: Key: '%s:%s' already defined!\n", __func__, config->name, key); } else { hash_insert_int(config->custom_keys, key, counter++); hash_insert_int(config->custom_key_types, key, util_sscanf_double(value, NULL)); } } fclose(stream); return read_ok; } return false; }
void * enkf_main_scale_obs_std_JOB(void * self, const stringlist_type * args ) { enkf_main_type * enkf_main = enkf_main_safe_cast( self ); double scale_factor; if (util_sscanf_double(stringlist_iget(args, 0), &scale_factor)) { analysis_config_type * analysis_config = enkf_main_get_analysis_config( enkf_main ); analysis_config_set_global_std_scaling( analysis_config , scale_factor ); } return NULL; }
void * enkf_main_scale_obs_std_JOB(void * self, const stringlist_type * args ) { enkf_main_type * enkf_main = enkf_main_safe_cast( self ); double scale_factor; util_sscanf_double(stringlist_iget(args, 0), &scale_factor); if (enkf_main_have_obs(enkf_main)) { enkf_obs_type * observations = enkf_main_get_obs(enkf_main); enkf_obs_scale_std(observations, scale_factor); } return NULL; }
double stringlist_iget_as_double( const stringlist_type * stringlist , int index , bool * valid) { const char * string_value = stringlist_iget( stringlist , index ); double value = -1.0; if (valid != NULL) *valid = false; if (util_sscanf_double(string_value , &value)) if (valid != NULL) *valid = true; return value; }
bool config_schema_item_valid_string(config_item_types value_type , const char * value) { switch(value_type) { case(CONFIG_ISODATE): return util_sscanf_isodate( value , NULL ); break; case(CONFIG_INT): return util_sscanf_int( value , NULL ); break; case(CONFIG_FLOAT): return util_sscanf_double( value , NULL ); break; case(CONFIG_BOOL): return util_sscanf_bool( value , NULL ); break; case(CONFIG_BYTESIZE): return util_sscanf_bytesize( value , NULL); break; default: return true; } }
bool analysis_module_set_var( analysis_module_type * module , const char * var_name , const char * string_value ) { bool set_ok = false; { int int_value; if (util_sscanf_int( string_value , &int_value )) set_ok = analysis_module_set_int( module , var_name , int_value ); if (set_ok) return true; } { double double_value; if (util_sscanf_double( string_value , &double_value )) set_ok = analysis_module_set_double( module , var_name , double_value ); if (set_ok) return true; } { bool bool_value; if (util_sscanf_bool( string_value , &bool_value)) set_ok = analysis_module_set_bool( module , var_name , bool_value ); if (set_ok) return true; } set_ok = analysis_module_set_string( module , var_name , string_value ); if (!set_ok) fprintf(stderr,"** Warning: failed to set %s=%s for analysis module:%s\n", var_name , string_value , module->user_name); return set_ok; }
double config_content_item_iget_as_double(const config_content_item_type * item, int occurence , int index) { double value; config_schema_item_assure_type(item->schema , index , CONFIG_FLOAT); util_sscanf_double( config_content_item_iget(item , occurence , index) , &value ); return value; }
bool config_schema_item_validate_set(const config_schema_item_type * item , stringlist_type * token_list , const char * config_file, const config_path_elm_type * path_elm , config_error_type * error_list) { bool OK = true; int argc = stringlist_get_size( token_list ) - 1; if (item->validate->argc_min >= 0) { if (argc < item->validate->argc_min) { OK = false; { char * error_message; if (config_file != NULL) error_message = util_alloc_sprintf("Error when parsing config_file:\"%s\" Keyword:%s must have at least %d arguments.",config_file , item->kw , item->validate->argc_min); else error_message = util_alloc_sprintf("Error:: Keyword:%s must have at least %d arguments.",item->kw , item->validate->argc_min); config_error_add( error_list , error_message ); } } } if (item->validate->argc_max >= 0) { if (argc > item->validate->argc_max) { OK = false; { char * error_message; if (config_file != NULL) error_message = util_alloc_sprintf("Error when parsing config_file:\"%s\" Keyword:%s must have maximum %d arguments.",config_file , item->kw , item->validate->argc_max); else error_message = util_alloc_sprintf("Error:: Keyword:%s must have maximum %d arguments.",item->kw , item->validate->argc_max); config_error_add( error_list , error_message ); } } } /* OK - now we have verified that the number of arguments is correct. Then we start actually looking at the values. */ if (OK) { /* Validating selection set - first common, then indexed */ if (item->validate->common_selection_set) { for (int iarg = 0; iarg < argc; iarg++) { if (!set_has_key(item->validate->common_selection_set , stringlist_iget( token_list , iarg + 1))) { config_error_add( error_list , util_alloc_sprintf("%s: is not a valid value for: %s.",stringlist_iget( token_list , iarg + 1) , item->kw)); OK = false; } } } else if (item->validate->indexed_selection_set != NULL) { for (int iarg = 0; iarg < argc; iarg++) { if ((item->validate->argc_max > 0) || (iarg < item->validate->argc_min)) { /* Without this test we might go out of range on the indexed selection set. */ const set_type * selection_set = validate_iget_selection_set( item->validate , iarg); if (selection_set) { if (!set_has_key( selection_set, stringlist_iget( token_list , iarg + 1))) { config_error_add( error_list , util_alloc_sprintf("%s: is not a valid value for item %d of \'%s\'.",stringlist_iget( token_list , iarg + 1) , iarg + 1 , item->kw)); OK = false; } } } } } /* Observe that the following code might rewrite the content of argv for arguments referring to path locations. */ /* Validate the TYPE of the various argumnents */ { for (int iarg = 0; iarg < argc; iarg++) { const char * value = stringlist_iget(token_list , iarg + 1); switch (validate_iget_type( item->validate , iarg)) { case(CONFIG_STRING): /* This never fails ... */ break; case(CONFIG_ISODATE): if (!util_sscanf_isodate( value , NULL )) config_error_add( error_list , util_alloc_sprintf("Failed to parse:%s as an ISO date: YYYY-MM-DD.",value)); break; case(CONFIG_INT): if (!util_sscanf_int( value , NULL )) config_error_add( error_list , util_alloc_sprintf("Failed to parse:%s as an integer.",value)); break; case(CONFIG_FLOAT): if (!util_sscanf_double( value , NULL )) { config_error_add( error_list , util_alloc_sprintf("Failed to parse:%s as a floating point number.", value)); OK = false; } break; case(CONFIG_PATH): // As long as we do not reuqire the path to exist it is just a string. break; case(CONFIG_EXISTING_PATH): { char * path = config_path_elm_alloc_abspath( path_elm , value ); if (!util_entry_exists(path)) { config_error_add( error_list , util_alloc_sprintf("Can not find entry %s in %s ",value , config_path_elm_get_relpath( path_elm) )); OK = false; } free( path ); } break; case(CONFIG_EXECUTABLE): { /* 1. If the supplied value is an abolute path - do nothing. 2. If the supplied is _not_ an absolute path: a. Try if the relocated exists - then use that. b. Else - try if the util_alloc_PATH_executable() exists. */ if (!util_is_abs_path( value )) { char * relocated = __alloc_relocated__(path_elm , value); char * path_exe = util_alloc_PATH_executable( value ); if (util_file_exists(relocated)) { if (util_is_executable(relocated)) stringlist_iset_copy( token_list , iarg , relocated); } else if (path_exe != NULL) stringlist_iset_copy( token_list , iarg , path_exe); else config_error_add( error_list , util_alloc_sprintf("Could not locate executable:%s ", value)); free(relocated); util_safe_free(path_exe); } else { if (!util_is_executable( value )) config_error_add( error_list , util_alloc_sprintf("Could not locate executable:%s ", value)); } } break; case(CONFIG_BOOL): if (!util_sscanf_bool( value , NULL )) { config_error_add( error_list , util_alloc_sprintf("Failed to parse:%s as a boolean.", value)); OK = false; } break; case(CONFIG_BYTESIZE): if (!util_sscanf_bytesize( value , NULL)) { config_error_add( error_list , util_alloc_sprintf("Failed to parse:\"%s\" as number of bytes." , value)); OK = false; } break; default: util_abort("%s: config_item_type:%d not recognized \n",__func__ , validate_iget_type(item->validate , iarg)); } } } } return OK; }