From 28a01f67862f0bca98215632385082c8c3860425 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <matthieu.schaller@durham.ac.uk>
Date: Sun, 14 Oct 2018 16:56:15 +0100
Subject: [PATCH] Changes to the single i/o mechanism to correctly collect only
 the non-inhibited DM gparts.

---
 src/common_io.c |  5 +++--
 src/single_io.c | 11 ++++++-----
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/common_io.c b/src/common_io.c
index 43119ee82e..fad18b32d1 100644
--- a/src/common_io.c
+++ b/src/common_io.c
@@ -805,8 +805,9 @@ void io_collect_dm_gparts(const struct gpart* const gparts, size_t Ntot,
     /* message("i=%zd count=%zd id=%lld part=%p", i, count, gparts[i].id,
      * gparts[i].part); */
 
-    /* And collect the DM ones */
-    if (gparts[i].type == swift_type_dark_matter) {
+    /* And collect the DM ones that have not been removed */
+    if (gparts[i].type == swift_type_dark_matter && 
+	gparts[i].time_bin != time_bin_inhibited) {
       dmparts[count] = gparts[i];
       count++;
     }
diff --git a/src/single_io.c b/src/single_io.c
index 764d58cf74..a745e66ef7 100644
--- a/src/single_io.c
+++ b/src/single_io.c
@@ -603,15 +603,14 @@ void write_output_single(struct engine* e, const char* baseName,
                          const struct unit_system* snapshot_units) {
 
   hid_t h_file = 0, h_grp = 0;
-  const size_t Ngas = e->s->nr_parts;
-  const size_t Nstars = e->s->nr_sparts;
-  const size_t Ntot = e->s->nr_gparts;
+  const size_t Ngas = e->total_nr_parts - e->nr_inhibited_parts;
+  const size_t Nstars = e->total_nr_sparts - e->nr_inhibited_sparts;
+  const size_t Ntot = e->total_nr_gparts - e->nr_inhibited_gparts;
   int periodic = e->s->periodic;
   int numFiles = 1;
   const struct part* parts = e->s->parts;
   const struct xpart* xparts = e->s->xparts;
   const struct gpart* gparts = e->s->gparts;
-  struct gpart* dmparts = NULL;
   const struct spart* sparts = e->s->sparts;
   const struct cooling_function_data* cooling = e->cooling_func;
   struct swift_params* params = e->parameter_file;
@@ -828,6 +827,8 @@ void write_output_single(struct engine* e, const char* baseName,
     struct io_props list[100];
     size_t N = 0;
 
+    struct gpart* dmparts = NULL;
+  
     /* Write particle fields from the particle structure */
     switch (ptype) {
 
@@ -846,7 +847,7 @@ void write_output_single(struct engine* e, const char* baseName,
           error("Error while allocating temporart memory for DM particles");
         bzero(dmparts, Ndm * sizeof(struct gpart));
 
-        /* Collect the DM particles from gpart */
+        /* Collect the non-inhibited DM particles from gpart */
         io_collect_dm_gparts(gparts, Ntot, dmparts, Ndm);
 
         /* Write DM particles */
-- 
GitLab