diff --git a/examples/parameter_example.yml b/examples/parameter_example.yml index a2506b8c62147627f590d09939616f929819ec0f..4879738bb09a8bdfec73ca760bdf6e1d38e75416 100644 --- a/examples/parameter_example.yml +++ b/examples/parameter_example.yml @@ -75,8 +75,7 @@ Snapshots: time_first: 0. # (Optional) Time of the first output if non-cosmological time-integration (in internal units) delta_time: 0.01 # Time difference between consecutive outputs (in internal units) compression: 0 # (Optional) Set the level of compression of the HDF5 datasets [0-9]. 0 does no compression. - label_first: 0 # (Optional) An additional offset for the snapshot output label - label_delta: 1 # (Optional) Set the integer increment between snapshot output labels + int_time_label_on: 0 # (Optional) Enable to label the snapshots using the time rounded to an integer (in internal units) UnitMass_in_cgs: 1 # (Optional) Unit system for the outputs (Grams) UnitLength_in_cgs: 1 # (Optional) Unit system for the outputs (Centimeters) UnitVelocity_in_cgs: 1 # (Optional) Unit system for the outputs (Centimeters per second) diff --git a/src/engine.c b/src/engine.c index 85d26c959d41dfb29dfbcce9d7622518edc60169..a9c96c573a635a4de00c75c444553350210ed1d9 100644 --- a/src/engine.c +++ b/src/engine.c @@ -5898,12 +5898,8 @@ void engine_init(struct engine *e, struct space *s, struct swift_params *params, parser_get_param_string(params, "Snapshots:basename", e->snapshot_base_name); e->snapshot_compression = parser_get_opt_param_int(params, "Snapshots:compression", 0); - e->snapshot_label_first = - parser_get_opt_param_int(params, "Snapshots:label_first", 0); - if (e->snapshot_label_first < 0) - error("Snapshots:label_first must be zero or positive"); - e->snapshot_label_delta = - parser_get_opt_param_int(params, "Snapshots:label_delta", 1); + e->snapshot_int_time_label_on = + parser_get_opt_param_int(params, "Snapshots:int_time_label_on", 0); e->snapshot_units = (struct unit_system *)malloc(sizeof(struct unit_system)); units_init_default(e->snapshot_units, params, "Snapshots", internal_units); e->snapshot_output_count = 0; @@ -6265,6 +6261,10 @@ void engine_config(int restart, struct engine *e, struct swift_params *params, "(t_beg = %e)", e->time_end, e->time_begin); + /* Check we don't have inappropriate time labels */ + if ((e->snapshot_int_time_label_on == 1) && (e->time_end <= 1.f)) + error("Snapshot integer time labels enabled but end time <= 1"); + /* Check we have sensible time-step values */ if (e->dt_min > e->dt_max) error( diff --git a/src/engine.h b/src/engine.h index 65cb7f22a715d01c745268948c796db3a1f735ab..2253e8ae8d93f65cc355c500b433126b72248153 100644 --- a/src/engine.h +++ b/src/engine.h @@ -223,8 +223,7 @@ struct engine { char snapshot_base_name[PARSER_MAX_LINE_SIZE]; int snapshot_compression; - int snapshot_label_first; - int snapshot_label_delta; + int snapshot_int_time_label_on; struct unit_system *snapshot_units; int snapshot_output_count; diff --git a/src/parallel_io.c b/src/parallel_io.c index 00aeb5c3210c96646e8130283b9ee42008cfba2b..64cb6ecdf12e50248741679ada96eda18ecb922d 100644 --- a/src/parallel_io.c +++ b/src/parallel_io.c @@ -931,13 +931,12 @@ void prepare_file(struct engine* e, const char* baseName, long long N_total[6], /* HDF5 File name */ char fileName[FILENAME_BUFFER_SIZE]; - if (e->snapshot_label_delta == 1) - snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName, - e->snapshot_output_count + e->snapshot_label_first); - else + if (e->snapshot_int_time_label_on) snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%06i.hdf5", baseName, - e->snapshot_output_count * e->snapshot_label_delta + - e->snapshot_label_first); + (int)round(e->time)); + else + snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName, + e->snapshot_output_count); /* Open HDF5 file with the chosen parameters */ hid_t h_file = H5Fcreate(fileName, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); @@ -1212,13 +1211,12 @@ void write_output_parallel(struct engine* e, const char* baseName, /* HDF5 File name */ char fileName[FILENAME_BUFFER_SIZE]; - if (e->snapshot_label_delta == 1) - snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName, - e->snapshot_output_count + e->snapshot_label_first); - else + if (e->snapshot_int_time_label_on) snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%06i.hdf5", baseName, - e->snapshot_output_count * e->snapshot_label_delta + - e->snapshot_label_first); + (int)round(e->time)); + else + snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName, + e->snapshot_output_count); /* Prepare some file-access properties */ hid_t plist_id = H5Pcreate(H5P_FILE_ACCESS); diff --git a/src/serial_io.c b/src/serial_io.c index fa7fbb220b9b56a3b5ea87660f618dc1a47bb886..14ed5f88477f8c92b9311c47121fa82d6e402bd6 100644 --- a/src/serial_io.c +++ b/src/serial_io.c @@ -758,13 +758,12 @@ void write_output_serial(struct engine* e, const char* baseName, /* File name */ char fileName[FILENAME_BUFFER_SIZE]; - if (e->snapshot_label_delta == 1) - snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName, - e->snapshot_output_count + e->snapshot_label_first); - else + if (e->snapshot_int_time_label_on) snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%06i.hdf5", baseName, - e->snapshot_output_count * e->snapshot_label_delta + - e->snapshot_label_first); + (int)round(e->time)); + else + snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName, + e->snapshot_output_count); /* Compute offset in the file and total number of particles */ size_t N[swift_type_count] = {Ngas, Ndm, 0, 0, Nstars, 0}; diff --git a/src/single_io.c b/src/single_io.c index 0238c21b10b7f35bd2e2618868ce8126562f736e..577400fd877d6267e8aa3d0d5dc23032f53dd348 100644 --- a/src/single_io.c +++ b/src/single_io.c @@ -624,13 +624,12 @@ void write_output_single(struct engine* e, const char* baseName, /* File name */ char fileName[FILENAME_BUFFER_SIZE]; - if (e->snapshot_label_delta == 1) - snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName, - e->snapshot_output_count + e->snapshot_label_first); - else + if (e->snapshot_int_time_label_on) snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%06i.hdf5", baseName, - e->snapshot_output_count * e->snapshot_label_delta + - e->snapshot_label_first); + (int)round(e->time)); + else + snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName, + e->snapshot_output_count); /* First time, we need to create the XMF file */ if (e->snapshot_output_count == 0) xmf_create_file(baseName); diff --git a/tests/testSelectOutput.c b/tests/testSelectOutput.c index 0b0adfa4e5a96f3431b27052bbb079f9be8838f2..7a02b7fb7ed0542036c60b125dcbe9a36a331e6d 100644 --- a/tests/testSelectOutput.c +++ b/tests/testSelectOutput.c @@ -44,7 +44,6 @@ void select_output_engine_init(struct engine *e, struct space *s, e->time = 0; e->snapshot_output_count = 0; e->snapshot_compression = 0; - e->snapshot_label_delta = 1; }; void select_output_space_init(struct space *s, double *dim, int periodic,