From ae21e4811f96c3a20a3deaad1f1a5920e582d86c Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <matthieu.schaller@durham.ac.uk>
Date: Mon, 23 Jan 2017 12:50:14 +0000
Subject: [PATCH] No need to discard particles any more. This is done at
 reading time.

---
 examples/main.c | 20 ++++----------------
 src/single_io.c |  6 ++++--
 2 files changed, 8 insertions(+), 18 deletions(-)

diff --git a/examples/main.c b/examples/main.c
index 54e67237b1..78e94da4c1 100644
--- a/examples/main.c
+++ b/examples/main.c
@@ -404,30 +404,18 @@ int main(int argc, char *argv[]) {
     fflush(stdout);
   }
 
-  /* Discard gparts if we don't have gravity
-   * (Better implementation of i/o will come)*/
-  if (!with_external_gravity && !with_self_gravity) {
-    free(gparts);
-    gparts = NULL;
-    for (size_t k = 0; k < Ngas; ++k) parts[k].gpart = NULL;
-    for (size_t k = 0; k < Nspart; ++k) sparts[k].gpart = NULL;
-    Ngpart = 0;
-  }
+#ifdef SWIFT_DEBUG_CHECKS
+  /* Check once and for all that we don't have unwanted links */
   if (!with_stars) {
-    free(sparts);
-    sparts = NULL;
     for (size_t k = 0; k < Ngpart; ++k)
       if (gparts[k].type == swift_type_star) error("Linking problem");
-    Nspart = 0;
   }
   if (!with_hydro) {
-    free(parts);
-    parts = NULL;
     for (size_t k = 0; k < Ngpart; ++k)
       if (gparts[k].type == swift_type_gas) error("Linking problem");
-    Ngas = 0;
   }
-
+#endif
+  
   /* Get the total number of particles across all nodes. */
   long long N_total[3] = {0, 0, 0};
 #if defined(WITH_MPI)
diff --git a/src/single_io.c b/src/single_io.c
index 324a76208a..76cd69be11 100644
--- a/src/single_io.c
+++ b/src/single_io.c
@@ -321,8 +321,10 @@ void writeArray(struct engine* e, hid_t grp, char* fileName, FILE* xmfFile,
  * @param Nstars (output) The number of #spart read.
  * @param periodic (output) 1 if the volume is periodic, 0 if not.
  * @param flag_entropy (output) 1 if the ICs contained Entropy in the
- * InternalEnergy
- * field
+ * InternalEnergy field
+ * @param with_hydro Are we reading gas particles ?
+ * @param with_hydro Are we reading/creating #gpart arrays ?
+ * @param with_stars Are we reading star particles ?
  * @param dry_run If 1, don't read the particle. Only allocates the arrays.
  *
  * Opens the HDF5 file fileName and reads the particles contained
-- 
GitLab