Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • bdc/cats
1 result
Select Git revision
Show changes
Showing
with 75 additions and 66 deletions
......@@ -25,7 +25,7 @@
#include <assert.h>
#include <cats_ini/cats_ini.h>
#include <logging/logging.h>
#include <bdc_logging/logging.h>
#ifdef USEMPI
#include "mpi/mpi_cats.h"
......@@ -48,6 +48,7 @@
#include "load_configuration_modules.h"
#include "test/test_ini.h"
#include "debug/debug_vital_rates.h"
#include "bdc_io/bdc_io.h"
void load_configuration_elements(struct cats_configuration *conf, struct cats_ini *ini);
......
......@@ -26,8 +26,8 @@
#include <string.h>
#include <stdbool.h>
#include <logging/logging.h>
#include <cats_strings/cats_strings.h>
#include <bdc_logging/logging.h>
#include <bdc_strings/bdc_strings.h>
#include "data/species_parameters.h"
#include "load_configuration_helper.h"
......@@ -42,10 +42,13 @@ bool load_dispersal_info(struct cats_configuration *conf, struct cats_ini *ini,
struct string_array *prob_min = get_char_array_from_conf2(ini, dispersal_section, "minimum weights");
struct string_array *prob_max = get_char_array_from_conf2(ini, dispersal_section, "maximum weights");
if (!((file_names->count == prob_min->count) && (file_names->count == prob_max->count))) {
if (!((get_string_count(file_names) == get_string_count(prob_min)) &&
(get_string_count(file_names) == get_string_count(prob_max)))) {
log_message(LOG_ERROR, "CONF: count mismatch: %d file names, %d minimum weights, "
"%d maximum weights. Expected all counts to be equal.", file_names->count,
prob_min->count, prob_max->count);
"%d maximum weights. Expected all counts to be equal.",
get_string_count(file_names),
get_string_count(prob_min),
get_string_count(prob_max));
exit(EXIT_FAILURE);
}
......@@ -64,20 +67,20 @@ bool load_dispersal_info(struct cats_configuration *conf, struct cats_ini *ini,
dispersal->long_range_enabled = true;
}
for (int32_t i = 0; i < file_names->count; i++) {
for (int32_t i = 0; i <get_string_count(file_names); i++) {
dispersal->types[i] = DISPERSAL_KERNEL;
bool pmin_succ = string_to_long_double(prob_min->string[i], &pmin);
bool pmax_succ = string_to_long_double(prob_max->string[i], &pmax);
bool pmin_succ = string_to_long_double(get_string(prob_min, i), &pmin);
bool pmax_succ = string_to_long_double(get_string(prob_min, i), &pmax);
if (pmin_succ == false || pmax_succ == false) {
log_message(LOG_ERROR, "CONF: error reading minimum and maximum probability: "
"'%s' and '%s'",
prob_min->string[i], prob_max->string[i]);
get_string(prob_min, i), get_string(prob_min, i));
exit(EXIT_FAILURE);
}
if (file_names->count > i && file_names->string[i]) {
dispersal->filenames[i] = strdup(file_names->string[i]);
if (get_string_count(file_names) > i && get_string(file_names, i)) {
dispersal->filenames[i] = strdup(get_string(file_names, i));
}
if ((pmax >= 0 && pmax <= 1.0 && pmin >= 0 && pmin <= 1.0 && pmax >= pmin) ||
......
......@@ -42,7 +42,7 @@ enum environment_variable_type get_environment_variable_type_from_string(const c
}
void add_environment_variable_from_conf(struct cats_configuration *conf, struct cats_ini *ini, char *environment_section)
void add_environment_variable_from_conf(struct cats_configuration *conf, struct cats_ini *ini, const char *environment_section)
{
struct array_dimension *dimension = &conf->geometry.dimension;
char *name = remove_0th_token(environment_section, ":");
......@@ -126,14 +126,16 @@ void load_environments_configuration(struct cats_configuration *conf, struct cat
//struct string_array *suitability_variables = get_sections_with_prefix(ini, "suitability");
struct string_array *glms = get_sections_with_prefix(ini, "glm");
size_t count = get_string_count(env_variables);
for (int32_t i = 0; i < count; i++) {
for (int32_t i = 0; i < env_variables->count; i++) {
add_environment_variable_from_conf(conf, ini, env_variables->string[i]);
add_environment_variable_from_conf(conf, ini, get_string(env_variables, i));
}
for (int32_t i = 0; i < glms->count; i++) {
add_glm_from_conf(conf, ini, glms->string[i]);
count = get_string_count(glms);
for (int32_t i = 0; i < count; i++) {
char *name = strdup(get_string(glms, i)); // FIXME, make add_glm_from_conf argument const
add_glm_from_conf(conf, ini, name);
}
......
......@@ -115,14 +115,14 @@ void add_glm_from_conf(struct cats_configuration *conf, struct cats_ini *ini, ch
}
struct glm_params glm = {0};
struct string_array *predictors = get_char_array_from_conf2(ini, environment_section, "predictors");
if (predictors->count == 0) {
if (get_string_count(predictors) == 0) {
log_message(LOG_ERROR, "%s: section [%s] does not contain any predictor names", __func__, environment_section);
exit_cats(EXIT_FAILURE);
}
if (predictors->count > MAX_ENVIRONMENTS) {
if (get_string_count(predictors) > MAX_ENVIRONMENTS) {
log_message(LOG_ERROR, "%s: section [%s]: more predictors (%d) found than the allowed maximum %d",
__func__, environment_section,
predictors->count, MAX_ENVIRONMENTS);
get_string_count(predictors), MAX_ENVIRONMENTS);
exit_cats(EXIT_FAILURE);
}
enum environment_type type = get_environment_glm_type(type_name);
......@@ -142,15 +142,15 @@ void add_glm_from_conf(struct cats_configuration *conf, struct cats_ini *ini, ch
free(family_name);
for (int32_t i = 0; i < predictors->count; i++) {
get_environment_from_registry(&conf->environment_registry, predictors->string[i]);
char *predictor_linear = compound_string(predictors->string[i], "linear", " ");
for (int32_t i = 0; i < get_string_count(predictors); i++) {
get_environment_from_registry(&conf->environment_registry, get_string(predictors,i));
char *predictor_linear = compound_string(get_string(predictors, i), "linear", " ");
load_conf_value(true, ini, environment_section, predictor_linear, &glm.linear[i]);
free(predictor_linear);
glm.count += 1;
if (glm.type == GLM_QUADRATIC) {
char *predictor_quadratic = compound_string(predictors->string[i], "quadratic", " ");
char *predictor_quadratic = compound_string(get_string(predictors, i), "quadratic", " ");
load_conf_value(true, ini, environment_section, predictor_quadratic, &glm.quadratic[i]);
free(predictor_quadratic);
}
......@@ -160,9 +160,9 @@ void add_glm_from_conf(struct cats_configuration *conf, struct cats_ini *ini, ch
struct cats_environment *set = add_environment(conf, name, type, &glm);
load_conf_value(false, ini, environment_section, "save environment", &set->save_environment);
for (int32_t i = 0; i < predictors->count; i++) {
for (int32_t i = 0; i < get_string_count(predictors); i++) {
struct cats_environment_variable *env = get_environment_from_registry(&conf->environment_registry,
predictors->string[i]);
get_string(predictors, i));
add_to_environment(set, env);
}
......
......@@ -60,7 +60,7 @@ void reset_same_dispersals(bool all_same, struct cats_configuration_counts *coun
}
int32_t count_kernel_dispersal_for_species(struct cats_ini *ini, char *species_section)
int32_t count_kernel_dispersal_for_species(struct cats_ini *ini, const char *species_section)
{
int32_t dispersal_count = 0;
char *dispersal_name = NULL;
......@@ -77,14 +77,14 @@ int32_t count_kernel_dispersal_for_species(struct cats_ini *ini, char *species_s
struct string_array *dispersal_kernel_filenames = get_char_array_from_conf2(ini, dispersal_section_name,
"kernel filenames");
if (!dispersal_kernel_filenames->count) {
if (!get_string_count(dispersal_kernel_filenames)) {
log_message(LOG_ERROR,
"Error creating configuration structures: could not load dispersal information for species '%s': '%s' [%s]",
species_section, dispersal_name, dispersal_section_name);
exit_cats(EXIT_FAILURE);
}
dispersal_count = dispersal_kernel_filenames->count;
dispersal_count = get_string_count(dispersal_kernel_filenames);
free(dispersal_section_name);
free_string_array(&dispersal_kernel_filenames);
......@@ -100,13 +100,13 @@ struct cats_configuration_counts get_counts_from_config(struct cats_ini *ini)
// required
struct string_array *species = get_sections_with_prefix(ini, "species");
counts.species = species->count;
counts.species = get_string_count(species);
counts.dispersals = new_raw_1d_array(counts.species, sizeof(int));
for (int i = 0; i < counts.species; i++) {
counts.dispersals[i] = count_kernel_dispersal_for_species(ini, species->string[i]);
counts.dispersals[i] = count_kernel_dispersal_for_species(ini, get_string(species, i));
}
free_string_array(&species);
......
......@@ -29,9 +29,9 @@
void load_configuration_modules(struct cats_configuration *conf, struct cats_ini *ini)
{
struct string_array *modules = get_sections_with_prefix(ini, "module");
for (int32_t i = 0; i < modules->count; i++) {
for (int32_t i = 0; i < get_string_count(modules); i++) {
char *module_section = modules->string[i];
const char *module_section = get_string(modules, i);
char *name = remove_0th_token(module_section, ":");
if (i >= MAX_MODULES) {
log_message(LOG_ERROR, "too many modules, limit is %d", MAX_MODULES);
......
......@@ -24,8 +24,8 @@
#include <string.h>
#include <math.h>
#include <logging/logging.h>
#include <cats_strings/cats_strings.h>
#include <bdc_logging/logging.h>
#include <bdc_strings/bdc_strings.h>
#include "load_configuration_overlays.h"
#include "overlays/overlay_habitat_type_cc.h"
#include "grids/grid_setup.h"
......@@ -36,15 +36,15 @@ void load_overlay_configuration(struct cats_configuration *conf, struct cats_ini
if (conf->command_line_options.no_input_rasters_required) return;
struct string_array *overlay_names = get_sections_with_prefix(ini, "overlay");
for (int32_t i = 0; i < overlay_names->count; i++) {
char *overlay_section = overlay_names->string[i];
for (int32_t i = 0; i < get_string_count(overlay_names); i++) {
const char *overlay_section = get_string(overlay_names, i);
bool enabled = true;
load_conf_value(false, ini, overlay_section, "enabled", &enabled);
if (enabled == false) {
continue;
}
char *overlay_name = remove_0th_token(overlay_names->string[i], ":");
char *overlay_name = remove_0th_token(get_string(overlay_names, i), ":");
char *type_name = NULL;
......
......@@ -30,7 +30,7 @@
#include "bdc_memory/bdc_memory.h"
#include <cats_ini/cats_ini.h>
#include <logging/logging.h>
#include <bdc_logging/logging.h>
#include "configuration/configuration.h"
#include "load_configuration_dispersal.h"
......@@ -46,7 +46,7 @@ enum sexuality_type get_sexuality_from_string(const char *string)
}
void preload_default_vital_rates_for_presets(struct cats_configuration *conf, struct cats_ini *ini, char *species_section,
void preload_default_vital_rates_for_presets(struct cats_configuration *conf, struct cats_ini *ini, const char *species_section,
struct cats_species_param *p)
{
// load values that could be used for presets -- e.g. some presets could depend on these values
......@@ -62,7 +62,7 @@ void preload_default_vital_rates_for_presets(struct cats_configuration *conf, st
}
void preload_default_vital_ages_for_presets(struct cats_configuration *conf, struct cats_ini *ini, char *species_section,
void preload_default_vital_ages_for_presets(struct cats_configuration *conf, struct cats_ini *ini, const char *species_section,
struct cats_species_param *p)
{
for (enum cats_vital_age_id age_id = VA_MIN + 1; age_id < VA_MAX; age_id++) {
......@@ -73,7 +73,7 @@ void preload_default_vital_ages_for_presets(struct cats_configuration *conf, str
}
void load_conf_vital_ages(struct cats_configuration *conf, struct cats_ini *ini, char *species_section,
void load_conf_vital_ages(struct cats_configuration *conf, struct cats_ini *ini, const char *species_section,
struct cats_species_param *p)
{
for (enum cats_vital_age_id age_id = VA_MIN + 1; age_id < VA_MAX; age_id++) {
......@@ -125,7 +125,7 @@ void load_conf_vital_rate(struct cats_vital_rate *vr, struct cats_configuration
void load_plant_species_parameter(struct cats_configuration *conf, struct cats_ini *ini,
char *species_name, struct cats_species_param *p)
const char *species_name, struct cats_species_param *p)
{
char *preset_string = NULL;
......@@ -182,7 +182,7 @@ void load_plant_species_parameter(struct cats_configuration *conf, struct cats_i
void load_config_species_parameter(struct cats_configuration *conf, struct cats_ini *ini, int species_idx,
char *species_section)
const char *species_section)
{
struct cats_species_param *p = &conf->param[species_idx];
......@@ -290,7 +290,7 @@ void load_config_species_parameter(struct cats_configuration *conf, struct cats_
}
void load_parameter_sets_all_same(struct cats_configuration *conf, struct cats_ini *ini, int species_idx, char *name)
void load_parameter_sets_all_same(struct cats_configuration *conf, struct cats_ini *ini, int species_idx, const char *name)
{
assert(species_idx >= 0);
char *species_name = strdup(conf->param[0].species_name);
......@@ -313,8 +313,8 @@ void load_all_species(struct cats_configuration *conf, struct cats_ini *ini)
{
struct string_array *species = get_sections_with_prefix(ini, "species");
for (int32_t i = 0; i < species->count; i++) {
char *species_section = species->string[i];
for (int32_t i = 0; i < get_string_count(species); i++) {
const char *species_section = get_string(species, i);
load_config_species_parameter(conf, ini, i, species_section);
if (conf->all_species_same && i == 0) {
......
......@@ -35,7 +35,7 @@ const char *false_values[] = {"0", "n", "f"};
const int true_counts = (int) (sizeof(true_values) / sizeof(char *));
const int false_counts = (int) (sizeof(false_values) / sizeof(char *));
/*
bool string_to_double(char *string, double *value)
{
if (string == NULL || strlen(string) == 0) return false;
......@@ -149,5 +149,5 @@ bool string_to_integer(char *string, int32_t *value)
}
return false;
}
*/
......@@ -58,6 +58,6 @@ struct cats_coordinates {
// conversion functions
#include <cats_strings/string_converters.h>
#include <bdc_strings/bdc_strings.h>
#endif
\ No newline at end of file
......@@ -24,7 +24,7 @@
#include "misc/misc.h"
#include "defaults.h"
#include "bdc_memory/bdc_memory.h"
#include <logging/logging.h>
#include <bdc_logging/logging.h>
#include <stdlib.h>
......
......@@ -23,7 +23,7 @@
#include "cats_global.h"
#include <math.h>
#include "simulation_geometry.h"
#include <logging/logging.h>
#include <bdc_logging/logging.h>
void init_simulation_geometry(struct simulation_geometry *geo)
{
......
......@@ -24,8 +24,9 @@
#include "bdc_memory/bdc_memory.h"
#include "debug/debug.h"
#include "threading/threading-helpers.h"
#include <cats_strings/cats_strings.h>
#include <bdc_strings/bdc_strings.h>
#include "misc/misc.h"
#include "bdc_io/bdc_io.h"
#define DEBUG_DIR "debug"
......
......@@ -26,6 +26,7 @@
#include "inline_carrying_capacity.h"
#include "grids/grid_setup.h"
#include "paths/directory_helper.h"
#include "bdc_io/bdc_io.h"
struct cats_environment *minimal_suitability_environment(void)
......
......@@ -26,7 +26,7 @@
#endif
#include <assert.h>
#include <logging/logging.h>
#include <bdc_logging/logging.h>
#include "configuration/configuration.h"
#include "memory.h"
......
......@@ -25,7 +25,7 @@
#include <limits.h>
#include "environment/environment_structures.h"
#include "bdc_memory/bdc_memory.h"
#include <logging/logging.h>
#include <bdc_logging/logging.h>
void reset_environment_registry(struct cats_environment_registry *reg)
{
......@@ -125,10 +125,10 @@ add_environment_to_registry(struct cats_environment_registry *registry, const ch
}
struct cats_environment_variable *get_environment_from_registry(struct cats_environment_registry *reg, char *name)
struct cats_environment_variable *get_environment_from_registry(struct cats_environment_registry *reg, const char *name)
{
int32_t idx = string_array_index(reg->name, name);
int32_t idx = string_array_string_index(reg->name, name);
if (idx < 0) {
log_message(LOG_ERROR, "%s: could not find environment '%s' in registry.", __func__, name);
exit(EXIT_FAILURE);
......@@ -148,7 +148,7 @@ void cleanup_environment_registry(struct cats_environment_registry *reg)
{
for (int32_t i = 0; i < reg->count; i++) {
log_message(LOG_INFO, "%s: cleaning up %s", __func__, reg->name->string[i]);
log_message(LOG_INFO, "%s: cleaning up %s", __func__, get_string(reg->name, i));
cleanup_cats_environment_variable(&reg->environment[i]);
}
......
......@@ -38,7 +38,7 @@ add_environment_to_registry(struct cats_environment_registry *registry, const ch
enum environment_variable_type type, const char *file_name_pattern, int32_t reload_interval,
int32_t interpolation, const struct array_dimension *dimension);
struct cats_environment_variable *get_environment_from_registry(struct cats_environment_registry *reg, char *name);
struct cats_environment_variable *get_environment_from_registry(struct cats_environment_registry *reg, const char *name);
void cleanup_environment_registry(struct cats_environment_registry *reg);
......
......@@ -177,12 +177,12 @@ void add_to_environment(struct cats_environment *environment, struct cats_enviro
void failed_to_find_environment(const struct cats_configuration *conf, const char *name)
{
log_message(LOG_ERROR, "%s: could not find environment set '%s' in registry", __func__, name);
if (conf->environment.names == NULL || conf->environment.names->count == 0) {
if (conf->environment.names == NULL || get_string_count(conf->environment.names) == 0) {
log_message(LOG_ERROR, "%s: registry empty ('%s')", __func__, name);
} else {
for (int32_t i = 0; i < conf->environment.names->count; i++) {
for (int32_t i = 0; i < get_string_count(conf->environment.names); i++) {
log_message(LOG_INFO, "%s: have registry entry: '%s'", __func__,
conf->environment.names->string[i]);
get_string(conf->environment.names, i));
}
}
......@@ -193,10 +193,10 @@ void failed_to_find_environment(const struct cats_configuration *conf, const cha
struct cats_environment *get_environment(const struct cats_configuration *conf, const char *name)
{
if (conf->environment.names == NULL || conf->environment.names->count == 0) {
if (conf->environment.names == NULL || get_string_count(conf->environment.names) == 0) {
failed_to_find_environment(conf, name);
}
int32_t idx = string_array_index(conf->environment.names, name);
int32_t idx = string_array_string_index(conf->environment.names, name);
if (idx < 0) failed_to_find_environment(conf, name);
......
......@@ -76,7 +76,7 @@ enum action_status update_environment_warmup(struct cats_configuration *conf, in
time);
} else if (time == start) {
log_message(LOG_INFO, " ENV: loading environment %s for year %d as static predictor",
conf->environment_registry.name->string[i],
get_string(conf->environment_registry.name, i),
time);
load_environment_raster(conf, &conf->environment_registry.environment[i], INTERPOLATION_CURRENT,
time);
......
......@@ -55,6 +55,7 @@
#include "paths/output_paths.h"
#include "stats/global_stats.h"
#include "actions/setup.h"
#include "bdc_io/bdc_io.h"
struct cats_grid **create_and_initialize_grids(struct cats_configuration *conf, const int32_t count)
......