From 338b5a4ba53d7faf98e8b9a71d3221989bcc0690 Mon Sep 17 00:00:00 2001
From: "armindamon.riess" <armindamon.riess@uzh.ch>
Date: Wed, 7 Dec 2022 11:16:35 +0100
Subject: [PATCH] corrected saveState2file

---
 lib/nBodySim.cpp | 2 +-
 main.cpp         | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/nBodySim.cpp b/lib/nBodySim.cpp
index eeb28e3..93d225b 100644
--- a/lib/nBodySim.cpp
+++ b/lib/nBodySim.cpp
@@ -181,7 +181,7 @@ void nBodySim::write2file(const double* array, std::string filename, unsigned di
 void nBodySim::saveState2file(unsigned step, std::string filename) const {
     std::ofstream file(filename);
     // save step number
-    file << "step = " << step;
+    file << "step: " << step << std::endl;
     // save number of particles
     file << nParticles_ << std::endl;
     // save masses
diff --git a/main.cpp b/main.cpp
index 5224b29..525473d 100644
--- a/main.cpp
+++ b/main.cpp
@@ -56,12 +56,14 @@ int main(int argc, char** argv) {
     try {
         sim.runSimulation(dt, nSteps);
     } catch (std::exception& e) {
+        // save state of simulation
+        sim.saveState2file(nSteps, "../out/errstate.txt");
         std::cerr << e.what() << std::endl;
         return 1;
     }
 
     // save state of simulation
-    sim.saveState2file(nSteps, "../out/state.txt");
+    sim.saveState2file(nSteps, "../out/endstate.txt");
 
     return 0;
 }
\ No newline at end of file
-- 
GitLab