From a173527e897ac45fb03ae212cf477829dfda5fba Mon Sep 17 00:00:00 2001
From: Josh Borrow <joshua.borrow@durham.ac.uk>
Date: Fri, 29 May 2020 17:32:29 +0100
Subject: [PATCH] Added Header/SelectOutput attribute to tell us what type of
 snapshot this is

---
 src/distributed_io.c | 18 +++++++++++-------
 src/parallel_io.c    | 18 +++++++++++-------
 src/serial_io.c      | 18 +++++++++++-------
 src/single_io.c      | 18 +++++++++++-------
 4 files changed, 44 insertions(+), 28 deletions(-)

diff --git a/src/distributed_io.c b/src/distributed_io.c
index d37873f406..34cfe9c51e 100644
--- a/src/distributed_io.c
+++ b/src/distributed_io.c
@@ -354,6 +354,16 @@ void write_output_distributed(struct engine* e,
                          e->s->dim[1] * factor_length,
                          e->s->dim[2] * factor_length};
 
+  /* Determine if we are writing a reduced snapshot, and if so which
+   * output selection type to use */
+  char current_selection_name[FIELD_BUFFER_SIZE] = "Default";
+  if (output_list) {
+    /* Users could have specified a different Select Output scheme for each
+     * snapshot. */
+    output_list_get_current_select_output(output_list,
+                                          &current_selection_name[0]);
+  }
+
   /* Print the relevant information and print status */
   io_write_attribute(h_grp, "BoxSize", DOUBLE, dim, 3);
   io_write_attribute(h_grp, "Time", DOUBLE, &dblTime, 1);
@@ -393,6 +403,7 @@ void write_output_distributed(struct engine* e,
   io_write_attribute_i(h_grp, "NumFilesPerSnapshot", numFiles);
   io_write_attribute_i(h_grp, "ThisFile", mpi_rank);
   io_write_attribute_s(h_grp, "OutputType", "Snapshot");
+  io_write_attribute_s(h_grp, "SelectOutput", current_selection_name);
 
   /* Close header */
   H5Gclose(h_grp);
@@ -706,13 +717,6 @@ void write_output_distributed(struct engine* e,
 
     /* Write everything that is not cancelled */
 
-    char current_selection_name[FIELD_BUFFER_SIZE] = "Default";
-    if (output_list) {
-      /* Users could have specified a different Select Output scheme for each
-       * snapshot. */
-      output_list_get_current_select_output(output_list,
-                                            &current_selection_name[0]);
-    }
     for (int i = 0; i < num_fields; ++i) {
 
       /* Did the user cancel this field? */
diff --git a/src/parallel_io.c b/src/parallel_io.c
index 5961c919d6..9f4fee1038 100644
--- a/src/parallel_io.c
+++ b/src/parallel_io.c
@@ -1102,6 +1102,16 @@ void prepare_file(struct engine* e, const char* fileName,
                          e->s->dim[1] * factor_length,
                          e->s->dim[2] * factor_length};
 
+  /* Determine if we are writing a reduced snapshot, and if so which
+   * output selection type to use */
+  char current_selection_name[FIELD_BUFFER_SIZE] = "Default";
+  if (output_list) {
+    /* Users could have specified a different Select Output scheme for each
+     * snapshot. */
+    output_list_get_current_select_output(output_list,
+                                          &current_selection_name[0]);
+  }
+
   /* Print the relevant information and print status */
   io_write_attribute(h_grp, "BoxSize", DOUBLE, dim, 3);
   io_write_attribute(h_grp, "Time", DOUBLE, &dblTime, 1);
@@ -1142,6 +1152,7 @@ void prepare_file(struct engine* e, const char* fileName,
   io_write_attribute(h_grp, "NumFilesPerSnapshot", INT, &numFiles, 1);
   io_write_attribute_i(h_grp, "ThisFile", 0);
   io_write_attribute_s(h_grp, "OutputType", "Snapshot");
+  io_write_attribute_s(h_grp, "SelectOutput", current_selection_name);
 
   /* Close header */
   H5Gclose(h_grp);
@@ -1260,13 +1271,6 @@ void prepare_file(struct engine* e, const char* fileName,
 
     /* Prepare everything that is not cancelled */
 
-    char current_selection_name[FIELD_BUFFER_SIZE] = "Default";
-    if (output_list) {
-      /* Users could have specified a different Select Output scheme for each
-       * snapshot. */
-      output_list_get_current_select_output(output_list,
-                                            &current_selection_name[0]);
-    }
     for (int i = 0; i < num_fields; ++i) {
 
       /* Did the user cancel this field? */
diff --git a/src/serial_io.c b/src/serial_io.c
index 63318487a0..7782644489 100644
--- a/src/serial_io.c
+++ b/src/serial_io.c
@@ -969,6 +969,16 @@ void write_output_serial(struct engine* e,
                            e->s->dim[1] * factor_length,
                            e->s->dim[2] * factor_length};
 
+    /* Determine if we are writing a reduced snapshot, and if so which
+     * output selection type to use */
+    char current_selection_name[FIELD_BUFFER_SIZE] = "Default";
+    if (output_list) {
+      /* Users could have specified a different Select Output scheme for each
+       * snapshot. */
+      output_list_get_current_select_output(output_list,
+                                            &current_selection_name[0]);
+    }
+
     /* Print the relevant information and print status */
     io_write_attribute(h_grp, "BoxSize", DOUBLE, dim, 3);
     io_write_attribute(h_grp, "Time", DOUBLE, &dblTime, 1);
@@ -1009,6 +1019,7 @@ void write_output_serial(struct engine* e,
     io_write_attribute(h_grp, "NumFilesPerSnapshot", INT, &numFiles, 1);
     io_write_attribute_i(h_grp, "ThisFile", 0);
     io_write_attribute_s(h_grp, "OutputType", "Snapshot");
+    io_write_attribute_s(h_grp, "SelectOutput", current_selection_name);
 
     /* Close header */
     H5Gclose(h_grp);
@@ -1389,13 +1400,6 @@ void write_output_serial(struct engine* e,
 
         /* Write everything that is not cancelled */
 
-        char current_selection_name[FIELD_BUFFER_SIZE] = "Default";
-        if (output_list) {
-          /* Users could have specified a different Select Output scheme for
-           * each snapshot. */
-          output_list_get_current_select_output(output_list,
-                                                &current_selection_name[0]);
-        }
         for (int i = 0; i < num_fields; ++i) {
 
           /* Did the user cancel this field? */
diff --git a/src/single_io.c b/src/single_io.c
index 056c8d1b84..1d104f0aec 100644
--- a/src/single_io.c
+++ b/src/single_io.c
@@ -815,6 +815,16 @@ void write_output_single(struct engine* e,
                          e->s->dim[1] * factor_length,
                          e->s->dim[2] * factor_length};
 
+  /* Determine if we are writing a reduced snapshot, and if so which
+   * output selection type to use */
+  char current_selection_name[FIELD_BUFFER_SIZE] = "Default";
+  if (output_list) {
+    /* Users could have specified a different Select Output scheme for each
+     * snapshot. */
+    output_list_get_current_select_output(output_list,
+                                          &current_selection_name[0]);
+  }
+
   /* Print the relevant information and print status */
   io_write_attribute(h_grp, "BoxSize", DOUBLE, dim, 3);
   io_write_attribute(h_grp, "Time", DOUBLE, &dblTime, 1);
@@ -855,6 +865,7 @@ void write_output_single(struct engine* e,
   io_write_attribute(h_grp, "NumFilesPerSnapshot", INT, &numFiles, 1);
   io_write_attribute_i(h_grp, "ThisFile", 0);
   io_write_attribute_s(h_grp, "OutputType", "Snapshot");
+  io_write_attribute_s(h_grp, "SelectOutput", current_selection_name);
 
   /* Close header */
   H5Gclose(h_grp);
@@ -1173,13 +1184,6 @@ void write_output_single(struct engine* e,
 
     /* Write everything that is not cancelled */
 
-    char current_selection_name[FIELD_BUFFER_SIZE] = "Default";
-    if (output_list) {
-      /* Users could have specified a different Select Output scheme for each
-       * snapshot. */
-      output_list_get_current_select_output(output_list,
-                                            &current_selection_name[0]);
-    }
     for (int i = 0; i < num_fields; ++i) {
 
       /* Did the user cancel this field? */
-- 
GitLab