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

butterflies: also save eggs

parent d02f8233
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,7 @@ void bf_register_actions(struct cats_configuration *conf)
register_action_function(conf, bf_action_dispersal, "butterfly_action_dispersal", "egg dispersal");
register_action_function(conf, bf_action_save_grid, "bf_action_save_grid", "output");
register_action_function(conf, bf_action_save_eggs_grid, "bf_action_save_egg_grid", "egg output");
register_action_function(conf, bf_action_stats_gather, "bf_action_stats_gather", "gather stats");
register_action_function(conf, bf_action_stats_reset, "bf_action_stats_reset", "reset stats");
register_action_function(conf, bf_action_stats_write, "bf_action_stats_write", "write stats");
......@@ -69,6 +70,7 @@ void bf_add_actions(struct cats_configuration *conf)
bf_add_generation_action(conf, bf_action_save_grid, "output", generation);
bf_add_generation_action(conf, bf_action_stats_gather, "gather stats", generation);
bf_add_generation_action(conf, bf_action_dispersal, "dispersal", generation);
bf_add_generation_action(conf, bf_action_save_eggs_grid, "output eggs", generation);
bf_add_generation_action(conf, bf_action_generation_finish, "finish generation", generation);
bf_add_generation_action(conf, bf_action_stats_write, "write stats", generation);
}
......
......@@ -73,6 +73,8 @@ void butterflies_area_dispersal(struct cats_grid *grid, struct cats_thread_info
}
}
if (ts->temp) printf("thread %d: %ld random walks (%ld cells) avg %f\n", ts->id, ts->temp, ts->temp1, (float) ts->temp / (float) ts->temp1);
}
......@@ -95,6 +97,18 @@ enum action_status bf_action_save_grid(struct cats_grid *grid, struct cats_confi
}
enum action_status bf_action_save_eggs_grid(struct cats_grid *grid, struct cats_configuration *conf)
{
int32_t id = grid->id;
int module_id = CATS_MODULE_ID;
struct grid_data_butterflies *module_data = grid->grid_modules[module_id].module_data;
char *filename = bf_population_eggs_filename(conf, grid);
struct grid_wrapper data = gridwrapper(module_data->eggs, grid->dimension);
save_grid_to_gdal(&data, GDT_Int32, conf, filename, conf->param[id].species_name);
free(filename);
return ACTION_RUN;
}
enum action_status bf_action_dispersal(struct cats_grid *grid, struct cats_configuration *conf)
......
......@@ -23,4 +23,5 @@ enum action_status bf_action_generation_start(struct cats_grid *grid, __attribut
enum action_status bf_action_generation_update(struct cats_grid *grid, struct cats_configuration *conf);
enum action_status bf_action_save_eggs_grid(struct cats_grid *grid, struct cats_configuration *conf);
#endif //CATS_BUTTERFLIES_ACTIONS_H
......@@ -37,6 +37,32 @@ char *bf_population_filename(struct cats_configuration *conf, struct cats_grid *
return filename;
}
char *bf_population_eggs_filename(struct cats_configuration *conf, struct cats_grid *grid)
{
assert(grid != NULL);
assert(conf != NULL);
assert(conf->grid_count == 1);
struct conf_data_butterflies *module_conf = CATS_MODULE_DATA;
int32_t max_generation = module_conf->generations_max;
int module_id = CATS_MODULE_ID;
struct grid_data_butterflies *data = grid->grid_modules[module_id].module_data;
struct string_array *path = get_output_directory(conf, "butterfly-eggs"); // FIXME MAKE DIRECTORY
char *extension = get_extension(conf, "eggs");
struct string_array *name = standard_output_file_name(conf, NULL, NULL, NULL);
string_array_add_int(name, max_generation - data->generation_current, "g%03d");
char *filename = assemble_filename(path, name, "_", extension);
free_string_array(&path);
free_string_array(&name);
free(extension);
return filename;
}
char *bf_stats_filename(struct cats_configuration *conf, struct cats_grid *grid)
{
struct string_array *path = get_output_directory(conf, "stats");
......
......@@ -2,7 +2,7 @@
#define CATS_BUTTERFLIES_FILENAMES_H
#include "configuration/configuration.h"
char *bf_population_eggs_filename(struct cats_configuration *conf, struct cats_grid *grid);
char *bf_population_filename(struct cats_configuration *conf, struct cats_grid *grid);
char *bf_stats_filename(struct cats_configuration *conf, struct cats_grid *grid);
#endif //CATS_BUTTERFLIES_FILENAMES_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment