From dca9facb1df6b6d7c54a0b2d4b98e5c6079f4cf5 Mon Sep 17 00:00:00 2001
From: "Peter W. Draper" <p.w.draper@durham.ac.uk>
Date: Wed, 17 Jan 2018 17:40:00 +0000
Subject: [PATCH] Dump engine units

---
 src/engine.c |  5 ++---
 src/units.c  | 25 +++++++++++++++++++++++++
 src/units.h  |  4 ++++
 3 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/src/engine.c b/src/engine.c
index a0b2ec53f9..27fcb11810 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -5641,10 +5641,9 @@ void engine_struct_dump(struct engine *e, FILE *stream) {
   /* Now for the other pointers, these use their own save functions. */
   space_struct_dump(e->s, stream);
   e->s->e = e;
+  units_struct_dump(e->internal_units, stream);
+  units_struct_dump(e->snapshotUnits, stream);
 
-
-  /* internal units */
-  /* snapshot units */
   /* repartition */
   /* physical constants */
   /* hydro props */
diff --git a/src/units.c b/src/units.c
index c9038924fa..7997181592 100644
--- a/src/units.c
+++ b/src/units.c
@@ -39,6 +39,7 @@
 /* Includes. */
 #include "adiabatic_index.h"
 #include "error.h"
+#include "restart.h"
 
 /**
  * @brief Initialises the unit_system structure with CGS system
@@ -602,3 +603,27 @@ void units_print(const struct unit_system* us) {
   message("\tUnit Current:     %g", us->UnitCurrent_in_cgs);
   message("\tUnit Temperature: %g", us->UnitTemperature_in_cgs);
 }
+
+
+/**
+ * @brief Write a units struct to the given FILE as a stream of bytes.
+ *
+ * @param us the units
+ * @param stream the file stream
+ */
+void units_struct_dump(const struct unit_system *us, FILE *stream) {
+  restart_write_blocks((void *)us, sizeof(struct unit_system), 1, stream,
+                       "units");
+}
+
+
+/**
+ * @brief Restore a units struct from the given FILE as a stream of bytes.
+ *
+ * @param us the units
+ * @param stream the file stream
+ */
+void units_struct_restore(const struct unit_system *us, FILE *stream) {
+  restart_read_blocks((void *)us, sizeof(struct unit_system), 1, stream,
+                      "units");
+}
diff --git a/src/units.h b/src/units.h
index 657b29c070..7f74e2b19f 100644
--- a/src/units.h
+++ b/src/units.h
@@ -139,4 +139,8 @@ double units_conversion_factor(const struct unit_system* from,
 
 void units_print(const struct unit_system* us);
 
+/* Dump/restore. */
+void units_struct_dump(const struct unit_system *us, FILE *stream);
+void units_struct_restore(const struct unit_system *us, FILE *stream);
+
 #endif /* SWIFT_UNITS_H */
-- 
GitLab