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

more helper functions and fixes

parent 543314c1
No related branches found
No related tags found
1 merge request!1preparations for multi-scale simulations
......@@ -27,6 +27,7 @@
#include "configuration/configuration.h"
void debug_vital_rates(struct cats_configuration *conf, const struct program_options *command_line_options);
struct cats_environment *minimal_suitability_environment(void);
struct cats_grid *minimal_grid(struct cats_configuration *conf, struct cats_environment *env);
#endif //CATS_DEBUG_VITAL_RATES_H
#include <assert.h>
#include "dimensions.h"
......@@ -9,17 +8,6 @@ void copy_dimensions_from_to(const struct cats_dimension *from, struct cats_dime
}
bool valid_coordinates(const struct cats_dimension *dim, cats_dt_coord row, cats_dt_coord col)
{
assert(dim != NULL);
assert(row >= 0 && row < dim->rows);
assert(col >= 0 && col < dim->cols);
if (row < 0 || col < 0) return false;
if (row >= dim->rows || col >= dim->cols) return false;
return true;
}
bool dimensions_match(const struct cats_dimension *dim1, const struct cats_dimension *dim2)
{
if (dim1->rows == dim2->rows && dim1->cols == dim2->cols) {
......
......@@ -2,6 +2,19 @@
#define CATS_DIMENSIONS_H
#include "memory/arrays.h"
#include "assert.h"
static inline bool valid_coordinates(const struct cats_dimension *dim, cats_dt_coord row, cats_dt_coord col)
{
assert(dim != NULL);
assert(row >= 0 && row < dim->rows);
assert(col >= 0 && col < dim->cols);
if (row < 0 || col < 0) return false;
if (row >= dim->rows || col >= dim->cols) return false;
return true;
}
void copy_dimensions_from_to(const struct cats_dimension *from, struct cats_dimension *to);
......
......@@ -52,6 +52,15 @@ static inline bool valid_dispersed_seed_grid(const struct cats_grid *grid, cats_
return true;
}
static inline bool valid_produced_seed_grid(const struct cats_grid *grid, cats_dt_coord row)
{
if (grid == NULL) return false;
if (grid->seeds_produced == NULL) return false;
if (grid->seeds_produced[row] == NULL) return false; // validator [valid_produced_seed_grid]
return true;
}
static inline cats_dt_environment
get_suitability_from_env(const struct cats_environment *set, cats_dt_coord row, cats_dt_coord col)
......@@ -70,6 +79,14 @@ get_dispersed_seeds(const struct cats_grid *grid, cats_dt_coord row, cats_dt_coo
return grid->dispersed_seeds[row][col]; // get [get_dispersed_seeds]
}
static inline cats_dt_seeds
get_produced_seeds(const struct cats_grid *grid, cats_dt_coord row, cats_dt_coord col)
{
assert(valid_coordinates(&grid->dimension, row, col));
assert(valid_produced_seed_grid(grid, row));
return grid->seeds_produced[row][col]; // get [get_produced_seeds]
}
static inline void
set_suitability(struct cats_grid *grid, cats_dt_coord row, cats_dt_coord col, cats_dt_environment value)
......
......@@ -64,5 +64,17 @@ cell_excluded_by_overlay(const struct cats_configuration *config, cats_dt_coord
exit_cats(EXIT_FAILURE);
}
static inline double get_overlay_habitat_cc_value(const struct cats_configuration *conf, cats_dt_coord row, cats_dt_coord col)
{
assert(conf->overlays.overlay[OL_HABITAT_TYPE_CC].enabled);
return conf->overlays.habitat_cc->data[row][col]; // getter [get_overlay_habitat_cc_value]
}
static inline double get_overlay_resource_value(const struct cats_configuration *conf, cats_dt_coord row, cats_dt_coord col)
{
assert(conf->overlays.overlay[OL_RESOURCE].enabled);
return conf->overlays.resources->data[row][col]; // getter [get_overlay_resource_value]
}
#endif //CATS_INLINE_OVERLAYS_H
......@@ -44,6 +44,23 @@ static inline bool valid_population_grid(const struct cats_grid *grid, cats_dt_c
return true;
}
static inline bool valid_juvenile_grid(const struct cats_grid *grid, cats_dt_coord row)
{
if (grid == NULL) return false;
if (grid->juveniles == NULL) return false;
if (grid->juveniles[row] == NULL) return false; // validator [valid_juvenile_grid]
return true;
}
static inline cats_dt_population get_juveniles(const struct cats_grid *grid, cats_dt_coord row, cats_dt_coord col, int year)
{
assert(valid_juvenile_grid(grid, row));
assert(valid_coordinates(&grid->dimension, row, col));
if (grid->juveniles[row][col] == NULL) return 0;
return grid->juveniles[row][col][year];
}
static inline cats_dt_population
get_adult_population(const struct cats_grid *grid, cats_dt_coord row, cats_dt_coord col)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment