]> git.treefish.org Git - phys/latlib.git/blobdiff - o815/sim.cpp
Made c++11 standard dependency obsolete.
[phys/latlib.git] / o815 / sim.cpp
index ec1ca89bcbecf959148d5caffeaf47ec42dcf39a..ec47339a7266e088af7881cbb0e7ae12c9fccb2b 100644 (file)
@@ -3,13 +3,44 @@
 #include "latlib/hypercache.h"
 #include "latlib/progress.h"
 
+#include "latlib/datread.h"
+
 o815::sim::sim(o815 *_O815, const int& _confmemSize) {
   O815 = _O815;
   log = O815->out->log;
   hypercache::initC(O815->programid, O815->comargs.nequi, O815->comargs.nskip, O815->comargs.confcache.first, &confMem, _confmemSize, O815->comargs.confcache.second, log);
   nequi = O815->comargs.nequi;
   nskip = O815->comargs.nskip;
-  confmemSize = confmemSize;
+  confmemSize = _confmemSize;
+
+  startConfiguration = NULL;
+  
+  if ( O815->comargs.startconfig != "" ) {
+    *log << "SIM: Fetching startconfig from " << O815->comargs.startconfig << endl;
+    
+    datread dataReader(confmemSize);
+    dataReader.openFile(O815->comargs.startconfig);
+    
+    if ( dataReader.fisopen() ) {
+      startConfiguration = (char*)malloc(confmemSize);
+      
+      if ( dataReader.readFullBlock(startConfiguration) < 0 ) {
+       *log << "SIM: Error while reading config from " << O815->comargs.startconfig << endl;
+       delete[] startConfiguration;
+       startConfiguration = NULL;
+      }     
+    }
+    else {
+      *log << "SIM: Could not open startconfigfile " << O815->comargs.startconfig << endl;
+    }
+  }
+  
+}
+
+o815::sim::~sim ()
+{
+  if (startConfiguration != NULL)
+    delete[] startConfiguration;
 }
 
 void o815::sim::nextConfig() {
@@ -35,3 +66,10 @@ void o815::sim::nextConfig() {
     hypercache::writeC();
   }
 }
+
+void o815::sim::resetConfig() {
+  if ( startConfiguration != NULL )
+    memcpy(confMem, startConfiguration, confmemSize);
+  else
+    _resetConfig();
+}