From ce6c492431b4396f537c27754fa297f3c6be523d Mon Sep 17 00:00:00 2001
From: Jacob Kegerreis <jacob.kegerreis@durham.ac.uk>
Date: Fri, 11 May 2018 12:54:10 +0100
Subject: [PATCH] Add optional parameter label_delta to set the increment
 between snapshot output labels

---
 examples/parameter_example.yml | 5 +++--
 src/engine.c                   | 2 ++
 src/engine.h                   | 1 +
 src/serial_io.c                | 8 ++++++--
 src/single_io.c                | 8 ++++++--
 5 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/examples/parameter_example.yml b/examples/parameter_example.yml
index 363dfe5fac..c9bc981180 100644
--- a/examples/parameter_example.yml
+++ b/examples/parameter_example.yml
@@ -33,7 +33,7 @@ SPH:
   initial_temperature:   0        # (Optional) Initial temperature (in internal units) to set the gas particles at start-up. Value is ignored if set to 0.
   minimal_temperature:   0        # (Optional) Minimal temperature (in internal units) allowed for the gas particles. Value is ignored if set to 0.
   H_mass_fraction:       0.76     # (Optional) Hydrogen mass fraction used for initial conversion from temp to internal energy.
-  
+
 # Parameters for the self-gravity scheme
 Gravity:
   eta:          0.025               # Constant dimensionless multiplier for time integration.
@@ -64,7 +64,7 @@ TimeIntegration:
   dt_min:            1e-6  # The minimal time-step size of the simulation (in internal units).
   dt_max:            1e-2  # The maximal time-step size of the simulation (in internal units).
   max_dt_RMS_factor: 0.25  # (Optional) Dimensionless factor for the maximal displacement allowed based on the RMS velocities.
-  
+
 # Parameters governing the snapshots
 Snapshots:
   basename:   output      # Common part of the name of output files
@@ -72,6 +72,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_delta: 1          # (Optional) Set the integer increment between snapshot output labels
   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 5dafce3ce1..afd514d748 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -5422,6 +5422,8 @@ void engine_init(struct engine *e, struct space *s,
   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_delta =
+      parser_get_opt_param_int(params, "Snapshots:label_delta", 1);
   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;
diff --git a/src/engine.h b/src/engine.h
index db3db31587..4c6a8453a3 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -207,6 +207,7 @@ struct engine {
 
   char snapshot_base_name[PARSER_MAX_LINE_SIZE];
   int snapshot_compression;
+  int snapshot_label_delta;
   struct unit_system *snapshot_units;
   int snapshot_output_count;
 
diff --git a/src/serial_io.c b/src/serial_io.c
index ab08537948..9403caad76 100644
--- a/src/serial_io.c
+++ b/src/serial_io.c
@@ -734,8 +734,12 @@ void write_output_serial(struct engine* e, const char* baseName,
 
   /* File name */
   char fileName[FILENAME_BUFFER_SIZE];
-  snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
-           e->snapshot_output_count);
+  if (e->snapshot_label_delta == 1)
+    snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
+             e->snapshot_output_count);
+  else
+    snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%06i.hdf5", baseName,
+             e->snapshot_output_count * e->snapshot_label_delta);
 
   /* 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 f5b7d33187..d7afdd4a88 100644
--- a/src/single_io.c
+++ b/src/single_io.c
@@ -602,8 +602,12 @@ void write_output_single(struct engine* e, const char* baseName,
 
   /* File name */
   char fileName[FILENAME_BUFFER_SIZE];
-  snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
-           e->snapshot_output_count);
+  if (e->snapshot_label_delta == 1)
+    snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
+             e->snapshot_output_count);
+  else
+    snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%06i.hdf5", baseName,
+             e->snapshot_output_count * e->snapshot_label_delta);
 
   /* First time, we need to create the XMF file */
   if (e->snapshot_output_count == 0) xmf_create_file(baseName);
-- 
GitLab