From c3bb89ab3292413493ad16bd1fb3a60ffc49cae7 Mon Sep 17 00:00:00 2001
From: James Willis <james.s.willis@durham.ac.uk>
Date: Mon, 6 Aug 2018 10:04:56 +0100
Subject: [PATCH] Use enum for structure finding output format.

---
 src/common_io.h              | 11 +++++++++--
 src/engine.c                 | 12 ++++++------
 src/velociraptor_interface.c |  4 ++--
 3 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/src/common_io.h b/src/common_io.h
index 4a9779974c..fc391b4726 100644
--- a/src/common_io.h
+++ b/src/common_io.h
@@ -30,8 +30,6 @@
 #define PARTICLE_GROUP_BUFFER_SIZE 50
 #define FILENAME_BUFFER_SIZE 150
 #define IO_BUFFER_ALIGNMENT 1024
-#define IO_STF_OUTPUT_FREQ_FORMAT_STEPS 0
-#define IO_STF_OUTPUT_FREQ_FORMAT_TIME 1
 
 /* Avoid cyclic inclusion problems */
 struct part;
@@ -58,6 +56,15 @@ enum IO_DATA_TYPE {
   CHAR
 };
 
+/**
+ * @brief The different formats for when to run structure finding.
+ *
+ */
+enum IO_STF_OUTPUT_FORMAT {
+  STEPS = 0,
+  TIME
+};
+
 #if defined(HAVE_HDF5)
 
 hid_t io_hdf5_type(enum IO_DATA_TYPE type);
diff --git a/src/engine.c b/src/engine.c
index bb576bbd5c..cffe1d9ce9 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -4616,9 +4616,9 @@ void engine_step(struct engine *e) {
 
   /* Do we want to perform structure finding? */
   if ((e->policy & engine_policy_structure_finding)) {
-    if(e->stf_output_freq_format == IO_STF_OUTPUT_FREQ_FORMAT_STEPS && e->step%(int)e->deltaTimeSTF == 0) 
+    if(e->stf_output_freq_format == STEPS && e->step%(int)e->deltaTimeSTF == 0) 
       e->run_stf = 1;
-    else if(e->stf_output_freq_format == IO_STF_OUTPUT_FREQ_FORMAT_TIME && e->ti_end_min >= e->ti_nextSTF && e->ti_nextSTF > 0)
+    else if(e->stf_output_freq_format == TIME && e->ti_end_min >= e->ti_nextSTF && e->ti_nextSTF > 0)
       e->run_stf = 1; 
   }
 
@@ -4653,7 +4653,7 @@ void engine_step(struct engine *e) {
     //velociraptor_invoke(e);
     
     /* ... and find the next output time */
-    if(e->stf_output_freq_format == IO_STF_OUTPUT_FREQ_FORMAT_TIME) engine_compute_next_stf_time(e);
+    if(e->stf_output_freq_format == TIME) engine_compute_next_stf_time(e);
     
     e->run_stf = 0;
   }
@@ -5562,10 +5562,10 @@ void engine_config(int restart, struct engine *e, struct swift_params *params,
     e->a_first_stf = parser_get_opt_param_double(params, "StructureFinding:a_time_first", 0.1);
     //velociraptor_init(e);
     e->stf_output_freq_format = parser_get_param_int(params, "StructureFinding:output_time_format");
-    if(e->stf_output_freq_format == IO_STF_OUTPUT_FREQ_FORMAT_STEPS) {
+    if(e->stf_output_freq_format == STEPS) {
       e->deltaTimeSTF = (double)parser_get_param_int(params, "StructureFinding:delta_time");
     }
-    else if(e->stf_output_freq_format == IO_STF_OUTPUT_FREQ_FORMAT_TIME) {
+    else if(e->stf_output_freq_format == TIME) {
       e->deltaTimeSTF = parser_get_param_double(params, "StructureFinding:delta_time");
     }
     else error("Invalid flag (%d) set for output time format of structure finding.", e->stf_output_freq_format);
@@ -5896,7 +5896,7 @@ void engine_config(int restart, struct engine *e, struct swift_params *params,
 
   if (e->policy & engine_policy_structure_finding) {
     /* Find the time of the first stf output */
-    if(e->stf_output_freq_format == IO_STF_OUTPUT_FREQ_FORMAT_TIME) { 
+    if(e->stf_output_freq_format == TIME) { 
       engine_compute_next_stf_time(e);
       message("Next STF step will be: %lld", e->ti_nextSTF);
     }
diff --git a/src/velociraptor_interface.c b/src/velociraptor_interface.c
index 8efe043f95..ef72b8adb9 100644
--- a/src/velociraptor_interface.c
+++ b/src/velociraptor_interface.c
@@ -178,11 +178,11 @@ void velociraptor_invoke(struct engine *e) {
     
     /* Append base name with either the step number or time depending on what format is specified in the parameter file. */
     char outputFileName[PARSER_MAX_LINE_SIZE + 128];
-    if(e->stf_output_freq_format == IO_STF_OUTPUT_FREQ_FORMAT_STEPS) {
+    if(e->stf_output_freq_format == STEPS) {
         snprintf(outputFileName, PARSER_MAX_LINE_SIZE + 128, "%s_%04i.VELOCIraptor", e->stfBaseName,
              e->step);
     }
-    else if(e->stf_output_freq_format == IO_STF_OUTPUT_FREQ_FORMAT_TIME) {
+    else if(e->stf_output_freq_format == TIME) {
         snprintf(outputFileName, PARSER_MAX_LINE_SIZE + 128, "%s_%04e.VELOCIraptor", e->stfBaseName,
              e->time);
     }
-- 
GitLab