Skip to content
Snippets Groups Projects
Commit b25b4153 authored by Andreas Gattringer's avatar Andreas Gattringer
Browse files

logging: added log level LOG_RAW and converted calls to printf to the new log level

parent 35c4d20f
No related branches found
No related tags found
No related merge requests found
Showing
with 92 additions and 92 deletions
...@@ -40,7 +40,7 @@ enum action_status action_save_adults(struct cats_grid *grid, struct cats_config ...@@ -40,7 +40,7 @@ enum action_status action_save_adults(struct cats_grid *grid, struct cats_config
assert(grid != NULL); assert(grid != NULL);
if (conf->command_line_options.lambda_test) { if (conf->command_line_options.lambda_test) {
if (grid->param.parametrization == PARAM_HYBRID) { if (grid->param.parametrization == PARAM_HYBRID) {
printf("POP,%d,%d,%f,%LF,%Lf,%d\n", conf->time.year_current, get_adult_population(grid, 0, 0), log_message(LOG_RAW, "POP,%d,%d,%f,%LF,%Lf,%d\n", conf->time.year_current, get_adult_population(grid, 0, 0),
get_suitability(grid, 0, 0), grid->param.OT, get_suitability(grid, 0, 0), grid->param.OT,
grid->param.scale_factor, get_adult_carrying_capacity(grid, 0, 0)); grid->param.scale_factor, get_adult_carrying_capacity(grid, 0, 0));
} }
......
...@@ -130,7 +130,7 @@ void load_modules(struct cats_configuration *conf) ...@@ -130,7 +130,7 @@ void load_modules(struct cats_configuration *conf)
{ {
for (int32_t i = 0; i < conf->modules.found_count; i++) { for (int32_t i = 0; i < conf->modules.found_count; i++) {
int32_t id = load_module(conf, &conf->modules.module[i]); int32_t id = load_module(conf, &conf->modules.module[i]);
printf("%s: %d/%d-> %d (%d)\n", conf->modules.module[i].name, i, conf->modules.count, id, log_message(LOG_RAW, "%s: %d/%d-> %d (%d)\n", conf->modules.module[i].name, i, conf->modules.count, id,
conf->modules.module[i].flags); conf->modules.module[i].flags);
} }
......
...@@ -145,16 +145,16 @@ void print_usage(const char *name, const char *error_msg) ...@@ -145,16 +145,16 @@ void print_usage(const char *name, const char *error_msg)
/// @brief prints CATS version info (git version, compiler, build and library information) /// @brief prints CATS version info (git version, compiler, build and library information)
void print_version_info(void) void print_version_info(void)
{ {
printf("CATS version %s\n\n", VERSION); log_message(LOG_RAW, "CATS version %s\n\n", VERSION);
printf("using libraries:\n"); log_message(LOG_RAW, "using libraries:\n");
printf("\tGSL version: %s\n", GSL_VERSION); log_message(LOG_RAW, "\tGSL version: %s\n", GSL_VERSION);
printf("\tGDAL version: %d.%d.%d\n", GDAL_VERSION_MAJOR, GDAL_VERSION_MINOR, GDAL_VERSION_REV); log_message(LOG_RAW, "\tGDAL version: %d.%d.%d\n", GDAL_VERSION_MAJOR, GDAL_VERSION_MINOR, GDAL_VERSION_REV);
printf("\n"); log_message(LOG_RAW, "\n");
printf("compilation info:\n"); log_message(LOG_RAW, "compilation info:\n");
printf("\tdate: %s\n",__DATE__); log_message(LOG_RAW, "\tdate: %s\n",__DATE__);
printf("\ttime: %s\n",__TIME__); log_message(LOG_RAW, "\ttime: %s\n",__TIME__);
printf("\tcompiler: %s\n", COMPILER); log_message(LOG_RAW, "\tcompiler: %s\n", COMPILER);
printf("\n"); log_message(LOG_RAW, "\n");
} }
...@@ -173,7 +173,7 @@ void print_runtime_information(int argc, char **argv) ...@@ -173,7 +173,7 @@ void print_runtime_information(int argc, char **argv)
char buffer[100]; char buffer[100];
time_string(buffer, 100); time_string(buffer, 100);
printf("run time information:\n"); log_message(LOG_RAW, "run time information:\n");
char *node_name; char *node_name;
#ifdef CATS_ON_WINDOWS #ifdef CATS_ON_WINDOWS
...@@ -187,24 +187,24 @@ void print_runtime_information(int argc, char **argv) ...@@ -187,24 +187,24 @@ void print_runtime_information(int argc, char **argv)
#ifdef CATS_ON_WINDOWS #ifdef CATS_ON_WINDOWS
char cwd_buffer[MAX_PATH]; char cwd_buffer[MAX_PATH];
GetCurrentDirectory(MAX_PATH, cwd_buffer); GetCurrentDirectory(MAX_PATH, cwd_buffer);
printf("\tcwd: %s\n", cwd_buffer); log_message(LOG_RAW, "\tcwd: %s\n", cwd_buffer);
#else #else
char *cwd = get_current_dir_name(); char *cwd = get_current_dir_name();
printf(" cwd: %s\n", cwd); log_message(LOG_RAW, " cwd: %s\n", cwd);
free(cwd); free(cwd);
#endif #endif
printf(" date: %s\n", buffer); log_message(LOG_RAW, " date: %s\n", buffer);
printf(" command: %s\n", argv[0]); log_message(LOG_RAW, " command: %s\n", argv[0]);
printf(" arguments (%d): ", argc - 1); log_message(LOG_RAW, " arguments (%d): ", argc - 1);
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
printf("%s ", argv[i]); log_message(LOG_RAW, "%s ", argv[i]);
} }
printf("\n"); log_message(LOG_RAW, "\n");
// HOSTNAME // HOSTNAME
printf(" host: %s\n", node_name); log_message(LOG_RAW, " host: %s\n", node_name);
printf("\n"); log_message(LOG_RAW, "\n");
} }
......
...@@ -71,7 +71,7 @@ void print_environments(struct cats_configuration *conf, int32_t indent) // FIXM ...@@ -71,7 +71,7 @@ void print_environments(struct cats_configuration *conf, int32_t indent) // FIXM
print_string(indent, "Environment registry", ""); print_string(indent, "Environment registry", "");
for (int32_t i = 0; i < conf->environment_registry.count; i++) { for (int32_t i = 0; i < conf->environment_registry.count; i++) {
print_environment(&conf->environment_registry.environment[i], indent + 1); print_environment(&conf->environment_registry.environment[i], indent + 1);
printf("\n"); log_message(LOG_RAW, "\n");
} }
} }
...@@ -79,7 +79,7 @@ void print_environments(struct cats_configuration *conf, int32_t indent) // FIXM ...@@ -79,7 +79,7 @@ void print_environments(struct cats_configuration *conf, int32_t indent) // FIXM
void print_config_summary(struct cats_configuration *conf) void print_config_summary(struct cats_configuration *conf)
{ {
if (get_log_level() > LOG_INFO) return; if (get_log_level() > LOG_INFO) return;
printf("%s\n", TEXT_DIVIDER); log_message(LOG_RAW, "%s\n", TEXT_DIVIDER);
// GENERAL // GENERAL
...@@ -167,7 +167,7 @@ void print_config_summary(struct cats_configuration *conf) ...@@ -167,7 +167,7 @@ void print_config_summary(struct cats_configuration *conf)
print_string(2, "save lambda grid (density)", bool_to_string(param->save_lambda_grid_density)); print_string(2, "save lambda grid (density)", bool_to_string(param->save_lambda_grid_density));
print_rate(2, "hapaxanthy", param->hapaxanthy); print_rate(2, "hapaxanthy", param->hapaxanthy);
print_rate(2, "demographic slope", param->demographic_slope); print_rate(2, "demographic slope", param->demographic_slope);
printf("\n"); log_message(LOG_RAW, "\n");
// DISPERSAL // DISPERSAL
if (param->custom_dispersal == false) { if (param->custom_dispersal == false) {
...@@ -179,7 +179,7 @@ void print_config_summary(struct cats_configuration *conf) ...@@ -179,7 +179,7 @@ void print_config_summary(struct cats_configuration *conf)
print_rate(2, "LRD probability", dispersal->long_range_prob); print_rate(2, "LRD probability", dispersal->long_range_prob);
print_integer(2, "LRD radius ", dispersal->long_range_radius); print_integer(2, "LRD radius ", dispersal->long_range_radius);
print_integer(2, "LRD target count", dispersal->long_range_target_count); print_integer(2, "LRD target count", dispersal->long_range_target_count);
printf("\n"); log_message(LOG_RAW, "\n");
} }
...@@ -194,16 +194,16 @@ void print_config_summary(struct cats_configuration *conf) ...@@ -194,16 +194,16 @@ void print_config_summary(struct cats_configuration *conf)
print_rate(3, "prob min", dispersal->prob_min[j]); print_rate(3, "prob min", dispersal->prob_min[j]);
print_rate(3, "prob max", dispersal->prob_max[j]); print_rate(3, "prob max", dispersal->prob_max[j]);
printf("\n"); log_message(LOG_RAW, "\n");
} }
} }
} }
printf("%s\n", TEXT_DIVIDER); log_message(LOG_RAW, "%s\n", TEXT_DIVIDER);
print_environments(conf, 0); print_environments(conf, 0);
printf("%s\n", TEXT_DIVIDER); log_message(LOG_RAW, "%s\n", TEXT_DIVIDER);
print_environment_sets(conf); print_environment_sets(conf);
printf("%s\n", TEXT_DIVIDER); log_message(LOG_RAW, "%s\n", TEXT_DIVIDER);
} }
......
...@@ -103,7 +103,7 @@ void debug_vital_rates(struct cats_configuration *conf) ...@@ -103,7 +103,7 @@ void debug_vital_rates(struct cats_configuration *conf)
struct cats_species_param *param = &grid->param; struct cats_species_param *param = &grid->param;
set_param_values(param, 0.5, 0.25, 0.5); set_param_values(param, 0.5, 0.25, 0.5);
struct cats_vital_rate *cc = &param->carrying_capacity; struct cats_vital_rate *cc = &param->carrying_capacity;
printf("K %Lf\n", param->carrying_capacity.func->func(cc, param, 0.5, 0, 0)); log_message(LOG_RAW, "K %Lf\n", param->carrying_capacity.func->func(cc, param, 0.5, 0, 0));
enum cats_density_dependence density_dep[] = {NO_DENSITY_DEP, DENSITY_DEP_NEGATIVE}; enum cats_density_dependence density_dep[] = {NO_DENSITY_DEP, DENSITY_DEP_NEGATIVE};
int32_t dens_count = sizeof(density_dep) / sizeof(density_dep[0]); int32_t dens_count = sizeof(density_dep) / sizeof(density_dep[0]);
...@@ -143,7 +143,7 @@ void debug_vital_rates(struct cats_configuration *conf) ...@@ -143,7 +143,7 @@ void debug_vital_rates(struct cats_configuration *conf)
f = fopen(filename, "w"); f = fopen(filename, "w");
ENSURE_FILE_OPENED(f, filename) ENSURE_FILE_OPENED(f, filename)
free(filename); free(filename);
printf("%s - density %d - ZT %Lf - OT %Lf - scale %Lf\n", log_message(LOG_RAW, "%s - density %d - ZT %Lf - OT %Lf - scale %Lf\n",
vr.func->short_name, vr.func->short_name,
dens_idx, dens_idx,
param->ZT, param->ZT,
......
...@@ -85,21 +85,21 @@ void print_environment_set(struct cats_environment *set, int32_t indent) ...@@ -85,21 +85,21 @@ void print_environment_set(struct cats_environment *set, int32_t indent)
break; break;
} }
printf("\n"); log_message(LOG_RAW, "\n");
} }
void print_environment_sets(struct cats_configuration *conf) void print_environment_sets(struct cats_configuration *conf)
{ {
printf("Environment sets\n"); log_message(LOG_RAW, "Environment sets\n");
print_integer(1, "Number of sets", conf->environment.count); print_integer(1, "Number of sets", conf->environment.count);
printf("\n"); log_message(LOG_RAW, "\n");
for (int32_t i = 0; i < conf->environment.count; i++) { for (int32_t i = 0; i < conf->environment.count; i++) {
print_environment_set(&conf->environment.environment_sets[i], 1); print_environment_set(&conf->environment.environment_sets[i], 1);
} }
printf("\n"); log_message(LOG_RAW, "\n");
printf("\n"); log_message(LOG_RAW, "\n");
} }
......
...@@ -38,24 +38,24 @@ void print_eigen_system(gsl_complex eigen_value, gsl_vector_complex_view *eigen_ ...@@ -38,24 +38,24 @@ void print_eigen_system(gsl_complex eigen_value, gsl_vector_complex_view *eigen_
{ {
log_message(LOG_IMPORTANT, "Eigenvalue: %g + %gi", GSL_REAL(eigen_value), GSL_IMAG(eigen_value)); log_message(LOG_IMPORTANT, "Eigenvalue: %g + %gi", GSL_REAL(eigen_value), GSL_IMAG(eigen_value));
log_message(LOG_IMPORTANT, "Eigenvector"); log_message(LOG_IMPORTANT, "Eigenvector");
printf("\n"); log_message(LOG_RAW, "\n");
const int32_t seed_persistence = get_vital_age_from_param(param, VA_SEED_PERSISTENCE); const int32_t seed_persistence = get_vital_age_from_param(param, VA_SEED_PERSISTENCE);
for (int32_t j = 0; j < N; ++j) { for (int32_t j = 0; j < N; ++j) {
char *name = NULL; char *name = NULL;
gsl_complex vector_entry = gsl_vector_complex_get(&eigen_vector->vector, j); gsl_complex vector_entry = gsl_vector_complex_get(&eigen_vector->vector, j);
if (j < seed_persistence) { if (j < seed_persistence) {
printf("EV::S%d::%g::%gi\n", j + 1, GSL_REAL(vector_entry), GSL_IMAG(vector_entry)); log_message(LOG_RAW, "EV::S%d::%g::%gi\n", j + 1, GSL_REAL(vector_entry), GSL_IMAG(vector_entry));
} else if (j < N - 1) { } else if (j < N - 1) {
printf("EV::J%d::%g::%gi\n", j - seed_persistence + 1, GSL_REAL(vector_entry), log_message(LOG_RAW, "EV::J%d::%g::%gi\n", j - seed_persistence + 1, GSL_REAL(vector_entry),
GSL_IMAG(vector_entry)); GSL_IMAG(vector_entry));
} else { } else {
printf("EV::A::%g::%gi\n", GSL_REAL(vector_entry), GSL_IMAG(vector_entry)); log_message(LOG_RAW, "EV::A::%g::%gi\n", GSL_REAL(vector_entry), GSL_IMAG(vector_entry));
} }
free(name); free(name);
} }
printf("\n"); log_message(LOG_RAW, "\n");
} }
...@@ -99,7 +99,7 @@ gsl_complex get_largest_eigen_value(double *matrix, int32_t N, bool silent, stru ...@@ -99,7 +99,7 @@ gsl_complex get_largest_eigen_value(double *matrix, int32_t N, bool silent, stru
for (int32_t i = 0; i < N; i++) { for (int32_t i = 0; i < N; i++) {
gsl_complex evec = gsl_vector_complex_get(eigen_values, i); gsl_complex evec = gsl_vector_complex_get(eigen_values, i);
printf("EV %d: %+0.17e %+0.17e i\n", i, GSL_REAL(evec), GSL_IMAG(evec)); log_message(LOG_RAW, "EV %d: %+0.17e %+0.17e i\n", i, GSL_REAL(evec), GSL_IMAG(evec));
} }
} }
......
...@@ -69,21 +69,21 @@ cats_dt_rates calculate_lambda(struct cats_configuration *conf, struct lambda_pa ...@@ -69,21 +69,21 @@ cats_dt_rates calculate_lambda(struct cats_configuration *conf, struct lambda_pa
bool e_val_ok = are_eigen_value_and_vector_real(largest_eigen_value, eigen_vector, N) && GSL_REAL(largest_eigen_value) > 0; bool e_val_ok = are_eigen_value_and_vector_real(largest_eigen_value, eigen_vector, N) && GSL_REAL(largest_eigen_value) > 0;
//printf("%d\n", conf->command_line_options.debug_flags & DEBUG_LAMBDA); //printf("%d\n", conf->command_line_options.debug_flags & DEBUG_LAMBDA);
if (!e_val_ok && (silent == false || conf->command_line_options.debug_flags & DEBUG_LAMBDA)) { if (!e_val_ok && (silent == false || conf->command_line_options.debug_flags & DEBUG_LAMBDA)) {
printf("============================\n"); log_message(LOG_RAW, "============================\n");
log_message(LOG_ERROR, "Eigenvalue or eigenvector not real and positive"); log_message(LOG_ERROR, "Eigenvalue or eigenvector not real and positive");
print_eigen_system(largest_eigen_value, &eigen_vector, N, &conf->param[species_id]); print_eigen_system(largest_eigen_value, &eigen_vector, N, &conf->param[species_id]);
printf("Original matrix\n"); log_message(LOG_RAW, "Original matrix\n");
print_matrix(matrix_copy, N, N); print_matrix(matrix_copy, N, N);
printf("Schur form T:\n"); log_message(LOG_RAW, "Schur form T:\n");
print_matrix(matrix, N, N); print_matrix(matrix, N, N);
debug_lambda_1_found(conf, species_id, largest_eigen_value, matrix_copy, N, l_param); debug_lambda_1_found(conf, species_id, largest_eigen_value, matrix_copy, N, l_param);
printf("============================\n"); log_message(LOG_RAW, "============================\n");
} }
if (silent == false && l_param->calculate_scale == true) { if (silent == false && l_param->calculate_scale == true) {
if (fabs(GSL_REAL(largest_eigen_value) - 1.0) < LAMBDA_EPS) { if (fabs(GSL_REAL(largest_eigen_value) - 1.0) < LAMBDA_EPS) {
printf("Final matrix\n"); log_message(LOG_RAW, "Final matrix\n");
print_matrix(matrix_copy, N, N); print_matrix(matrix_copy, N, N);
debug_lambda_1_found(conf, species_id, largest_eigen_value, matrix_copy, N, l_param); debug_lambda_1_found(conf, species_id, largest_eigen_value, matrix_copy, N, l_param);
} }
...@@ -133,7 +133,7 @@ void debug_lambda_1_found(struct cats_configuration *conf, int32_t species_id, g ...@@ -133,7 +133,7 @@ void debug_lambda_1_found(struct cats_configuration *conf, int32_t species_id, g
const int32_t stages_seeds = seed_persistence; const int32_t stages_seeds = seed_persistence;
const int32_t stages_juveniles = mat_max; const int32_t stages_juveniles = mat_max;
printf("\n"); log_message(LOG_RAW, "\n");
log_message(LOG_IMPORTANT, "found lambda within %f of 1.0: %f", log_message(LOG_IMPORTANT, "found lambda within %f of 1.0: %f",
LAMBDA_EPS, LAMBDA_EPS,
GSL_REAL(largest_eigen_value)); GSL_REAL(largest_eigen_value));
......
...@@ -131,10 +131,10 @@ create_leslie_matrix(struct cats_configuration *conf, struct lambda_parameters * ...@@ -131,10 +131,10 @@ create_leslie_matrix(struct cats_configuration *conf, struct lambda_parameters *
if (print_rate) { if (print_rate) {
for (int32_t i = 0; i < mat_max + 1; i++) { for (int32_t i = 0; i < mat_max + 1; i++) {
printf("m%d = %f\n", i, log_message(LOG_RAW, "m%d = %f\n", i,
(double) age_specific_maturation_rate(i, juvenile_survival, mat_min, mat_max)); (double) age_specific_maturation_rate(i, juvenile_survival, mat_min, mat_max));
} }
printf("d = %f\n", d); log_message(LOG_RAW, "d = %f\n", d);
} }
// special case: // special case:
...@@ -187,10 +187,10 @@ create_leslie_matrix(struct cats_configuration *conf, struct lambda_parameters * ...@@ -187,10 +187,10 @@ create_leslie_matrix(struct cats_configuration *conf, struct lambda_parameters *
if (row * N + s < N * N) { if (row * N + s < N * N) {
} else { } else {
printf("N = %d\n", N); log_message(LOG_RAW, "N = %d\n", N);
printf("s = %d\n", s); log_message(LOG_RAW, "s = %d\n", s);
printf("row = %d\n", row); log_message(LOG_RAW, "row = %d\n", row);
exit(1); exit(EXIT_FAILURE);
} }
matrix[row * N + s] = (double) (germination_rate * (1.0 - m0) * juvenile_survival); matrix[row * N + s] = (double) (germination_rate * (1.0 - m0) * juvenile_survival);
} }
......
...@@ -34,19 +34,19 @@ void print_matrix(double *matrix, int32_t rows, int32_t cols) ...@@ -34,19 +34,19 @@ void print_matrix(double *matrix, int32_t rows, int32_t cols)
assert(matrix != NULL); assert(matrix != NULL);
assert(rows > 0); assert(rows > 0);
assert(cols > 0); assert(cols > 0);
printf("[\n"); log_message(LOG_RAW, "[\n");
for (int32_t row = 0; row < rows; row++) { for (int32_t row = 0; row < rows; row++) {
printf(" "); log_message(LOG_RAW, " ");
for (int32_t col = 0; col < cols; col++) { for (int32_t col = 0; col < cols; col++) {
printf("%+0.17e", matrix[row * cols + col]); log_message(LOG_RAW, "%+0.17e", matrix[row * cols + col]);
if (col < cols -1) {printf(", ");} if (col < cols -1) {log_message(LOG_RAW, ", ");}
if (row < rows -1 && col == cols -1) printf(";"); if (row < rows -1 && col == cols -1) log_message(LOG_RAW, ";");
} }
printf("\n"); log_message(LOG_RAW, "\n");
} }
printf("]\n"); log_message(LOG_RAW, "]\n");
} }
......
...@@ -63,7 +63,7 @@ void print_modules(struct cats_configuration *conf) ...@@ -63,7 +63,7 @@ void print_modules(struct cats_configuration *conf)
for (int i = 0; i < conf->modules.count; i++) { for (int i = 0; i < conf->modules.count; i++) {
print_module(&conf->modules.module[i], i); print_module(&conf->modules.module[i], i);
print_module_species_data(&conf->param->module_data[i]); print_module_species_data(&conf->param->module_data[i]);
printf("\n\n"); log_message(LOG_RAW, "\n\n");
} }
} }
......
...@@ -71,7 +71,7 @@ void mpi_save_locally_dispersed_seeds(struct cats_configuration *conf, struct ca ...@@ -71,7 +71,7 @@ void mpi_save_locally_dispersed_seeds(struct cats_configuration *conf, struct ca
int rows_after = 0; int rows_after = 0;
get_rows_around(conf, &rows_before, &rows_after, &radius, grid->id); get_rows_around(conf, &rows_before, &rows_after, &radius, grid->id);
offset.rows = conf->geometry.row_offset - rows_before; offset.rows = conf->geometry.row_offset - rows_before;
printf("rank %d, rows %d cols %d, rows before %d, rows after %d, row offset %d\n\n", conf->mpi.world_rank, log_message(LOG_RAW, "rank %d, rows %d cols %d, rows before %d, rows after %d, row offset %d\n\n", conf->mpi.world_rank,
grid->dimension.rows, grid->dimension.rows,
grid->dimension.cols, rows_before, rows_after, conf->geometry.row_offset); grid->dimension.cols, rows_before, rows_after, conf->geometry.row_offset);
struct cats_dimension dimension; struct cats_dimension dimension;
......
...@@ -30,7 +30,7 @@ void juvenile_start_status_old(int32_t age, cats_dt_rates start, cats_dt_rates n ...@@ -30,7 +30,7 @@ void juvenile_start_status_old(int32_t age, cats_dt_rates start, cats_dt_rates n
cats_dt_rates juveniles, cats_dt_rates start_pop) cats_dt_rates juveniles, cats_dt_rates start_pop)
{ {
printf("Start of year %02d: %08.4Lf: %08.4Lf (%06.4Lf) new adults, %08.4Lf remaining discarded \n", log_message(LOG_RAW, "Start of year %02d: %08.4Lf: %08.4Lf (%06.4Lf) new adults, %08.4Lf remaining discarded \n",
age, start, new_adults, m, juveniles); age, start, new_adults, m, juveniles);
} }
...@@ -38,14 +38,14 @@ void juvenile_start_status_old(int32_t age, cats_dt_rates start, cats_dt_rates n ...@@ -38,14 +38,14 @@ void juvenile_start_status_old(int32_t age, cats_dt_rates start, cats_dt_rates n
void juvenile_dead_old(int32_t age, cats_dt_rates juveniles, cats_dt_rates start_pop) void juvenile_dead_old(int32_t age, cats_dt_rates juveniles, cats_dt_rates start_pop)
{ {
printf("ABC:nodes.append(['J%d', 'D', %Lf])\n", age - 1, juveniles / start_pop); log_message(LOG_RAW, "ABC:nodes.append(['J%d', 'D', %Lf])\n", age - 1, juveniles / start_pop);
} }
void juvenile_start_status(int32_t age, cats_dt_rates start, cats_dt_rates new_adults, cats_dt_rates m, void juvenile_start_status(int32_t age, cats_dt_rates start, cats_dt_rates new_adults, cats_dt_rates m,
cats_dt_rates surviving, cats_dt_rates survival_rate) cats_dt_rates surviving, cats_dt_rates survival_rate)
{ {
printf("Start of year %02d: %08.4Lf: %08.4Lf (%06.4Lf) new adults, %08.4Lf (%06.4Lf) surviving \n", log_message(LOG_RAW, "Start of year %02d: %08.4Lf: %08.4Lf (%06.4Lf) new adults, %08.4Lf (%06.4Lf) surviving \n",
age, start, new_adults, m, surviving, age, start, new_adults, m, surviving,
survival_rate); survival_rate);
} }
...@@ -54,9 +54,9 @@ void juvenile_start_status(int32_t age, cats_dt_rates start, cats_dt_rates new_a ...@@ -54,9 +54,9 @@ void juvenile_start_status(int32_t age, cats_dt_rates start, cats_dt_rates new_a
void print_juvenile_dead(cats_dt_rates dead, cats_dt_rates start_pop, int32_t age) void print_juvenile_dead(cats_dt_rates dead, cats_dt_rates start_pop, int32_t age)
{ {
if (age == 0) { if (age == 0) {
printf("ABC:nodes.append(['G', 'D', %Lf])\n", dead / start_pop); log_message(LOG_RAW, "ABC:nodes.append(['G', 'D', %Lf])\n", dead / start_pop);
} else { } else {
printf("ABC:nodes.append(['J%d', 'D', %Lf])\n", age, dead / start_pop); log_message(LOG_RAW, "ABC:nodes.append(['J%d', 'D', %Lf])\n", age, dead / start_pop);
} }
} }
...@@ -64,10 +64,10 @@ void print_juvenile_dead(cats_dt_rates dead, cats_dt_rates start_pop, int32_t ag ...@@ -64,10 +64,10 @@ void print_juvenile_dead(cats_dt_rates dead, cats_dt_rates start_pop, int32_t ag
void print_juvenile_adults(cats_dt_rates new_adults, cats_dt_rates start_pop, int32_t age) void print_juvenile_adults(cats_dt_rates new_adults, cats_dt_rates start_pop, int32_t age)
{ {
if (age == 0) { if (age == 0) {
printf("ABC:nodes.append(['G', 'A', %Lf])\n", new_adults / start_pop); log_message(LOG_RAW, "ABC:nodes.append(['G', 'A', %Lf])\n", new_adults / start_pop);
} else { } else {
printf("ABC:nodes.append(['J%d', 'A', %Lf])\n", age, new_adults / start_pop); log_message(LOG_RAW, "ABC:nodes.append(['J%d', 'A', %Lf])\n", age, new_adults / start_pop);
} }
} }
...@@ -75,9 +75,9 @@ void print_juvenile_adults(cats_dt_rates new_adults, cats_dt_rates start_pop, in ...@@ -75,9 +75,9 @@ void print_juvenile_adults(cats_dt_rates new_adults, cats_dt_rates start_pop, in
void print_juvenile_trans(cats_dt_rates juveniles, cats_dt_rates start_pop, int32_t age) void print_juvenile_trans(cats_dt_rates juveniles, cats_dt_rates start_pop, int32_t age)
{ {
if (age == 0) { if (age == 0) {
printf("ABC:nodes.append(['G', 'J1', %Lf])\n", juveniles / start_pop); log_message(LOG_RAW, "ABC:nodes.append(['G', 'J1', %Lf])\n", juveniles / start_pop);
} else { } else {
printf("ABC:nodes.append(['J%d', 'J%d', %Lf])\n", age, age + 1, log_message(LOG_RAW, "ABC:nodes.append(['J%d', 'J%d', %Lf])\n", age, age + 1,
juveniles / start_pop); juveniles / start_pop);
} }
} }
...@@ -91,7 +91,7 @@ calculate_total_survival(cats_dt_rates survival_rate, int32_t age_min, int32_t a ...@@ -91,7 +91,7 @@ calculate_total_survival(cats_dt_rates survival_rate, int32_t age_min, int32_t a
cats_dt_rates adults = 0.0; cats_dt_rates adults = 0.0;
if (print) { if (print) {
printf("Testing juvenile survival rate of %Lf\n", survival_rate); log_message(LOG_RAW, "Testing juvenile survival rate of %Lf\n", survival_rate);
} }
for (int32_t age = 0; age < age_max + 1; age++) { for (int32_t age = 0; age < age_max + 1; age++) {
...@@ -145,19 +145,19 @@ cats_dt_rates calculate_survival_rate(cats_dt_rates total_survival, int32_t age_ ...@@ -145,19 +145,19 @@ cats_dt_rates calculate_survival_rate(cats_dt_rates total_survival, int32_t age_
cats_dt_rates high = 1.0; cats_dt_rates high = 1.0;
cats_dt_rates s = total_survival / 2; cats_dt_rates s = total_survival / 2;
if (verbose) { if (verbose) {
printf("finding year-to-year survival for total survival rate %Lf from germination to adult with age min and %d age max %d\n", log_message(LOG_RAW, "finding year-to-year survival for total survival rate %Lf from germination to adult with age min and %d age max %d\n",
total_survival, age_min, age_max); total_survival, age_min, age_max);
} }
int32_t count = 0; int32_t count = 0;
while (true) { while (true) {
count++; count++;
cats_dt_rates ts = calculate_total_survival(s, age_min, age_max, false); cats_dt_rates ts = calculate_total_survival(s, age_min, age_max, false);
if (verbose) { printf("year survival %Lf -> total survival %Lf\n", s, ts); } if (verbose) { log_message(LOG_RAW, "year survival %Lf -> total survival %Lf\n", s, ts); }
//printf("ts %Lf\n", fabsl(ts - total_survival)/1e-5); //printf("ts %Lf\n", fabsl(ts - total_survival)/1e-5);
if (fabsl(ts - total_survival) < JUV_SURV_DELTA) { if (fabsl(ts - total_survival) < JUV_SURV_DELTA) {
//printf("year survival %0.5Lf -> total survival %0.5Lf\n", s, ts); //printf("year survival %0.5Lf -> total survival %0.5Lf\n", s, ts);
if (verbose) { printf("done\n"); } if (verbose) { log_message(LOG_RAW, "done\n"); }
break; break;
} }
...@@ -183,7 +183,7 @@ cats_dt_rates calculate_survival_rate(cats_dt_rates total_survival, int32_t age_ ...@@ -183,7 +183,7 @@ cats_dt_rates calculate_survival_rate(cats_dt_rates total_survival, int32_t age_
} }
if (verbose) { if (verbose) {
printf("%Lf\n", s); log_message(LOG_RAW, "%Lf\n", s);
} }
//printf("done\n"); //printf("done\n");
......
...@@ -182,7 +182,7 @@ germinate_seeds0(struct cats_grid *grid, const cats_dt_coord row, const cats_dt_ ...@@ -182,7 +182,7 @@ germinate_seeds0(struct cats_grid *grid, const cats_dt_coord row, const cats_dt_
{ {
// how many seeds of the first year germinate? // how many seeds of the first year germinate?
if (grid->dispersed_seeds[row][col] > 0) { if (grid->dispersed_seeds[row][col] > 0) {
printf("%f\n", grid->dispersed_seeds[row][col]); log_message(LOG_RAW, "%f\n", grid->dispersed_seeds[row][col]);
abort(); abort();
} }
cats_dt_population germinated = poisson(ts->rng, grid->dispersed_seeds[row][col] * germination_rate); cats_dt_population germinated = poisson(ts->rng, grid->dispersed_seeds[row][col] * germination_rate);
...@@ -223,7 +223,7 @@ void clean_seeds_0_mpi_area(struct cats_grid *grid, struct cats_configuration *c ...@@ -223,7 +223,7 @@ void clean_seeds_0_mpi_area(struct cats_grid *grid, struct cats_configuration *c
int rows_after = 0; int rows_after = 0;
int radius; int radius;
get_rows_around(conf, &rows_before, &rows_after, &radius, grid->id); get_rows_around(conf, &rows_before, &rows_after, &radius, grid->id);
printf("%d %d %d\n", rows_before, rows_after, radius); log_message(LOG_RAW, "%d %d %d\n", rows_before, rows_after, radius);
for (cats_dt_coord row = 0; row < grid->dimension.rows + rows_before + rows_after; row++) { for (cats_dt_coord row = 0; row < grid->dimension.rows + rows_before + rows_after; row++) {
for (cats_dt_coord col = 0; col < grid->dimension.cols; col++) { for (cats_dt_coord col = 0; col < grid->dimension.cols; col++) {
grid->seeds_0_all[row][col] = 0.0f; grid->seeds_0_all[row][col] = 0.0f;
......
...@@ -117,10 +117,10 @@ scale_down_juveniles2(struct cats_grid *grid, cats_dt_coord row, cats_dt_coord c ...@@ -117,10 +117,10 @@ scale_down_juveniles2(struct cats_grid *grid, cats_dt_coord row, cats_dt_coord c
weighted_juvenile_sum = get_weighted_juvenile_sum(grid, row, col); weighted_juvenile_sum = get_weighted_juvenile_sum(grid, row, col);
if (weighted_juvenile_sum > juvenile_cc) { if (weighted_juvenile_sum > juvenile_cc) {
log_message(LOG_ERROR, "%s: weighted juvenile sum > juvenile CC", __func__); log_message(LOG_ERROR, "%s: weighted juvenile sum > juvenile CC", __func__);
printf("sum: %"PRId64", cc %"PRId64"\n", weighted_juvenile_sum, juvenile_cc); log_message(LOG_RAW, "sum: %"PRId64", cc %"PRId64"\n", weighted_juvenile_sum, juvenile_cc);
printf("factor %Lf\n", factor); log_message(LOG_RAW, "factor %Lf\n", factor);
for (int32_t i = 0; i < mat_max + 1 - 1; i++) { for (int32_t i = 0; i < mat_max + 1 - 1; i++) {
printf("juvenile stage %d: %d - multiplier %Lf\n", i, grid->juveniles[row][col][i], log_message(LOG_RAW, "juvenile stage %d: %d - multiplier %Lf\n", i, grid->juveniles[row][col][i],
juvenile_cc_multiplier(&grid->param, i)); juvenile_cc_multiplier(&grid->param, i));
} }
fflush(stdout); fflush(stdout);
......
...@@ -214,7 +214,7 @@ increase_population_by(struct cats_grid *grid, cats_dt_coord row, cats_dt_coord ...@@ -214,7 +214,7 @@ increase_population_by(struct cats_grid *grid, cats_dt_coord row, cats_dt_coord
// existing juveniles still fit into the cell? also no problem. // existing juveniles still fit into the cell? also no problem.
cats_dt_population_sum max_allowed_juveniles = round_population_sum_safe((cats_dt_rates) K * JUVENILE_CC_MULTI) - N; cats_dt_population_sum max_allowed_juveniles = round_population_sum_safe((cats_dt_rates) K * JUVENILE_CC_MULTI) - N;
if (max_allowed_juveniles <0 ) { if (max_allowed_juveniles <0 ) {
printf("%d %Lf %d %ld %ld\n", K, (cats_dt_rates) K * JUVENILE_CC_MULTI, N, round_population_sum_safe((cats_dt_rates) K * JUVENILE_CC_MULTI), max_allowed_juveniles); log_message(LOG_RAW, "%d %Lf %d %ld %ld\n", K, (cats_dt_rates) K * JUVENILE_CC_MULTI, N, round_population_sum_safe((cats_dt_rates) K * JUVENILE_CC_MULTI), max_allowed_juveniles);
} }
assert(max_allowed_juveniles >= 0); assert(max_allowed_juveniles >= 0);
......
...@@ -309,7 +309,7 @@ print_vital_rate(const struct cats_vital_rate *vital_rate, const struct cats_spe ...@@ -309,7 +309,7 @@ print_vital_rate(const struct cats_vital_rate *vital_rate, const struct cats_spe
break; break;
} }
print_rate(4, "adult population density suitability threshold", vital_rate->density_ts); print_rate(4, "adult population density suitability threshold", vital_rate->density_ts);
printf("\n"); log_message(LOG_RAW, "\n");
} }
......
...@@ -30,7 +30,7 @@ void print_vital_rates(struct cats_configuration *conf) ...@@ -30,7 +30,7 @@ void print_vital_rates(struct cats_configuration *conf)
{ {
for (int sp_idx = 0; sp_idx < conf->param_count; sp_idx++) { for (int sp_idx = 0; sp_idx < conf->param_count; sp_idx++) {
const struct cats_species_param *param = &conf->param[sp_idx]; const struct cats_species_param *param = &conf->param[sp_idx];
printf("Vital rates for %s\n", conf->param->species_name); log_message(LOG_RAW, "Vital rates for %s\n", conf->param->species_name);
print_vital_rate(&param->carrying_capacity, param); print_vital_rate(&param->carrying_capacity, param);
if (param->custom_vital_rates == false) { if (param->custom_vital_rates == false) {
......
...@@ -55,9 +55,9 @@ void print_accesses(struct cats_ini *ini) ...@@ -55,9 +55,9 @@ void print_accesses(struct cats_ini *ini)
for (int32_t sec = 0; sec < SECTIONS; sec++) { for (int32_t sec = 0; sec < SECTIONS; sec++) {
const int32_t KEYS = ini->n_keys[sec]; const int32_t KEYS = ini->n_keys[sec];
for (int key = 0; key < KEYS; key++) { for (int key = 0; key < KEYS; key++) {
printf("%s::%s has value '%s' and was accessed", ini->sections[sec], ini->keys[sec][key], log_message(LOG_RAW, "%s::%s has value '%s' and was accessed", ini->sections[sec], ini->keys[sec][key],
ini->values[sec][key]); ini->values[sec][key]);
printf("% d times\n", ini->values_accessed[sec][key]); log_message(LOG_RAW, "% d times\n", ini->values_accessed[sec][key]);
} }
} }
} }
......
...@@ -54,7 +54,7 @@ int add_section(struct cats_ini *ini, char *section_name) ...@@ -54,7 +54,7 @@ int add_section(struct cats_ini *ini, char *section_name)
ini->values_accessed[N] = NULL; ini->values_accessed[N] = NULL;
ini->values[N] = NULL; ini->values[N] = NULL;
DBG(printf("SECTION: %s\n", ini->sections[N]);) DBG(log_message(LOG_RAW, "SECTION: %s\n", ini->sections[N]);)
ini->n_sections++; ini->n_sections++;
return N; return N;
...@@ -139,7 +139,7 @@ int32_t add_key_val(struct cats_ini *ini, int32_t section_idx, char *key, char * ...@@ -139,7 +139,7 @@ int32_t add_key_val(struct cats_ini *ini, int32_t section_idx, char *key, char *
ini->keys[section_idx][KEY] = key; ini->keys[section_idx][KEY] = key;
ini->values[section_idx][KEY] = value; ini->values[section_idx][KEY] = value;
ini->n_keys[section_idx] += 1; ini->n_keys[section_idx] += 1;
DBG(printf("\tKEY: %s VALUE: %s\n", key, val)) DBG(log_message(LOG_RAW, "\tKEY: %s VALUE: %s\n", key, val))
return KEY; return KEY;
} }
...@@ -154,7 +154,7 @@ void maybe_add_key_val(char *line, struct cats_ini *ini) ...@@ -154,7 +154,7 @@ void maybe_add_key_val(char *line, struct cats_ini *ini)
int32_t N_secs = ini->n_sections; int32_t N_secs = ini->n_sections;
int32_t SECTION = N_secs - 1; int32_t SECTION = N_secs - 1;
if (N_secs == 0) { if (N_secs == 0) {
DBG(printf("IGNORED: line outside of section \"%s\"\n", line);) DBG(log_message(LOG_RAW, "IGNORED: line outside of section \"%s\"\n", line);)
return; return;
} }
...@@ -182,7 +182,7 @@ void maybe_add_key_val(char *line, struct cats_ini *ini) ...@@ -182,7 +182,7 @@ void maybe_add_key_val(char *line, struct cats_ini *ini)
fflush(stdout); fflush(stdout);
if (line == NULL || (found && strlen(found) == 0)) { if (line == NULL || (found && strlen(found) == 0)) {
DBG(printf("\tIGNORED: empty or invalid line \"%s\"\n", found);) DBG(log_message(LOG_RAW, "\tIGNORED: empty or invalid line \"%s\"\n", found);)
return; return;
} }
if (found == NULL) return; if (found == NULL) return;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment