diff --git a/src/Makefile.am b/src/Makefile.am index 7e54ecab60a5b97a585bd560a04836e4e6f78336..35d691737fe8b0f8bef6a00cdd6a866e25dc7f74 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -48,7 +48,7 @@ include_HEADERS = space.h runner.h queue.h task.h lock.h cell.h part.h const.h \ dump.h logger.h active.h timeline.h xmf.h gravity_properties.h gravity_derivatives.h \ gravity_softened_derivatives.h vector_power.h collectgroup.h hydro_space.h sort_part.h \ chemistry.h chemistry_io.h chemistry_struct.h cosmology.h restart.h space_getsid.h utilities.h \ - mesh_gravity.h cbrt.h velociraptor_interface.h swift_velociraptor_part.h + mesh_gravity.h cbrt.h velociraptor_interface.h swift_velociraptor_part.h snaplist.h # Common source files AM_SOURCES = space.c runner.c queue.c task.c cell.c engine.c \ @@ -60,7 +60,8 @@ AM_SOURCES = space.c runner.c queue.c task.c cell.c engine.c \ statistics.c runner_doiact_vec.c profiler.c dump.c logger.c \ part_type.c xmf.c gravity_properties.c gravity.c \ collectgroup.c hydro_space.c equation_of_state.c \ - chemistry.c cosmology.c restart.c mesh_gravity.c velociraptor_interface.c + chemistry.c cosmology.c restart.c mesh_gravity.c velociraptor_interface.c \ + snaplist.c # Include files for distribution, not installation. nobase_noinst_HEADERS = align.h approx_math.h atomic.h barrier.h cycle.h error.h inline.h kernel_hydro.h kernel_gravity.h \ diff --git a/src/common_io.c b/src/common_io.c index f30eef1cff5afdc7188e047a2e58ef1d068a7d7b..68311107575a89ce8a2990a8e0f7a8eeb5d2d644 100644 --- a/src/common_io.c +++ b/src/common_io.c @@ -966,83 +966,3 @@ void io_write_output_field_parameter(const char* filename) { "'%s'.\n", filename); } - - -void time_array_read_file(struct time_array *times, const char* filename, - struct cosmology *cosmo) { - /* initialize times */ - times->size = 0; - - /* Open file */ - FILE* file = fopen(filename, "r"); - if (file == NULL) error("Error opening file '%s'", filename); - - /* Read header */ - ssize_t read; - size_t len = 0; - char *line = NULL; - if((read = getline(&line, &len, file)) == -1) - error("Unable to read header in file '%s'", filename); - - /* Remove end of line character */ - line[strcspn(line, "\n")] = 0; - - /* Find type of data in file */ - int type; - if (!strcmp(line, "# Redshift")) - type = TIME_ARRAY_REDSHIFT; - else if (!strcmp(line, "# Time")) - type = TIME_ARRAY_AGE; - else if (!strcmp(line, "# Scale Factor")) - type = TIME_ARRAY_SCALE_FACTOR; - else - error("Unable to interpret the header (%s) in file '%s'", - line, filename); - - if (!cosmo && - (type == TIME_ARRAY_SCALE_FACTOR || type == TIME_ARRAY_REDSHIFT)) - error("Unable to compute a redshift or a scale factor without cosmology. " - "Please change the header in '%s'", filename); - - - /* Read file */ - while ((read = getline(&line, &len, file)) != -1) { - - /* Check data size */ - if (times->size == TIME_ARRAY_MAX_SIZE) - error("Not enough memory to write the time array buffer. " - "Please decrease the number of time required in '%s'.", - filename); - - double *time = ×->times[times->size]; - /* Write data to time array */ - if (sscanf(line, "%lf", time) != 1) { - error( - "Tried parsing double but found '%s' with illegal double " - "characters in file '%s'.", - line, filename); - } - - /* Transform input into correct time (e.g. ages or scale factor) */ - if (type == TIME_ARRAY_REDSHIFT) - *time = cosmology_get_a_from_z(cosmo, *time); - - if (cosmo && type == TIME_ARRAY_AGE) - *time = cosmology_get_scale_factor(cosmo, *time); - - /* Update size */ - times->size += 1; - } - - time_array_print(times); - - fclose(file); -} - -void time_array_print(const struct time_array *times) { - - printf("/*\t Time Array\t */\n"); - for(size_t ind = 0; ind < times->size; ind++) { - printf("\t%lf\n", times->times[ind]); - } -} diff --git a/src/common_io.h b/src/common_io.h index cb6308c46d37c3da5f59a4fdcf5d8ead258d1e3e..fe69dd0b753c8bdced38c97e155247f117b01590 100644 --- a/src/common_io.h +++ b/src/common_io.h @@ -30,7 +30,6 @@ #define PARTICLE_GROUP_BUFFER_SIZE 50 #define FILENAME_BUFFER_SIZE 150 #define IO_BUFFER_ALIGNMENT 1024 -#define TIME_ARRAY_MAX_SIZE 8192 /* Avoid cyclic inclusion problems */ struct cosmology; @@ -126,7 +125,4 @@ void io_check_output_fields(const struct swift_params* params, void io_write_output_field_parameter(const char* filename); -void time_array_read_file(struct time_array *times, const char* filename, struct cosmology *cosmo); -void time_array_print(const struct time_array *times); - #endif /* SWIFT_COMMON_IO_H */ diff --git a/src/engine.c b/src/engine.c index 2b1b4804f2889c83c4abc4151ae1828e5f6d1080..9392b2ff97027f90a6df65721cc7220e7c8aa70c 100644 --- a/src/engine.c +++ b/src/engine.c @@ -78,6 +78,7 @@ #include "runner.h" #include "serial_io.h" #include "single_io.h" +#include "snaplist.h" #include "sort_part.h" #include "sourceterms.h" #include "statistics.h" @@ -5765,7 +5766,7 @@ void engine_init(struct engine *e, struct space *s, struct swift_params *params, parser_get_opt_param_double(params, "Snapshots:time_first", 0.); e->delta_time_snapshot = parser_get_param_double(params, "Snapshots:delta_time"); - e->time_array_snapshots = NULL; + e->snaplist_snapshots = NULL; e->ti_next_snapshot = 0; parser_get_param_string(params, "Snapshots:basename", e->snapshot_base_name); e->snapshot_compression = @@ -6439,7 +6440,7 @@ void engine_print_policy(struct engine *e) { */ void engine_compute_next_snapshot_time(struct engine *e) { /* Do snaplist file case */ - if (e->time_array_snapshots) { + if (e->snaplist_snapshots) { engine_read_next_snapshot_time(e); return; } @@ -6743,8 +6744,8 @@ void engine_clean(struct engine *e) { } free(e->runners); free(e->snapshot_units); - if (e->time_array_snapshots) - free(e->time_array_snapshots); + if (e->snaplist_snapshots) + free(e->snaplist_snapshots); free(e->links); free(e->cell_loc); scheduler_clean(&e->sched); @@ -6895,7 +6896,7 @@ void engine_read_time_files(struct engine *e, const struct swift_params *params) cosmo = e->cosmology; /* Read snapshot time array */ - e->time_array_snapshots = (struct time_array*) malloc(sizeof(struct time_array)); + e->snaplist_snapshots = (struct snaplist*) malloc(sizeof(struct snaplist)); strcpy(filename, ""); parser_get_opt_param_string(params, "Snapshots:snaplist", @@ -6903,14 +6904,14 @@ void engine_read_time_files(struct engine *e, const struct swift_params *params) if (strcmp(filename, "")) { message("Reading snaplist file."); - time_array_read_file(e->time_array_snapshots, filename, cosmo); + snaplist_read_file(e->snaplist_snapshots, filename, cosmo); } } void engine_read_next_snapshot_time(struct engine *e) { int is_cosmo = e->policy & engine_policy_cosmology; - const struct time_array *t = e->time_array_snapshots; + const struct snaplist *t = e->snaplist_snapshots; /* Find upper-bound on last output */ double time_end; diff --git a/src/engine.h b/src/engine.h index 7f2bcc020487d4eb3a6e2c49433212c8b3c6034d..fffa2b7826e44dfa37e70a16fc9fdefcdece1afe 100644 --- a/src/engine.h +++ b/src/engine.h @@ -214,7 +214,7 @@ struct engine { double a_first_snapshot; double time_first_snapshot; double delta_time_snapshot; - struct time_array *time_array_snapshots; + struct snaplist *snaplist_snapshots; /* Integer time of the next snapshot */ integertime_t ti_next_snapshot; diff --git a/src/swift.h b/src/swift.h index 3222376888bada072114f58ac5294f4567e8659a..b6b7ed68ef0f9f37f960b7166678d866eb1b40ca 100644 --- a/src/swift.h +++ b/src/swift.h @@ -63,6 +63,7 @@ #include "scheduler.h" #include "serial_io.h" #include "single_io.h" +#include "snaplist.h" #include "sourceterms.h" #include "space.h" #include "task.h"