From: Alexander Schmidt Date: Fri, 5 Dec 2014 13:36:20 +0000 (+0100) Subject: Implemented startconfig. X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/commitdiff_plain/07516f0b1615a95f3e68d073adf4cfda584b99fa Implemented startconfig. --- diff --git a/o815/CMakeLists.txt b/o815/CMakeLists.txt index f941c10..60daa3b 100644 --- a/o815/CMakeLists.txt +++ b/o815/CMakeLists.txt @@ -14,7 +14,7 @@ endif() SET(CMAKE_BUILD_TYPE Release) add_library(o815 o815.cpp obs.cpp sim.cpp) -target_link_libraries(o815 ${MPI_LIBRARIES} lat_paraq lat_writeout lat_hypercache lat_progress) +target_link_libraries(o815 ${MPI_LIBRARIES} lat_paraq lat_writeout lat_hypercache lat_progress lat_datread) if(DEFINED ENV{MPI_DISABLED}) set_target_properties(o815 PROPERTIES COMPILE_DEFINITIONS "MPI_DISABLED") endif() diff --git a/o815/o815.cpp b/o815/o815.cpp index 36d9fb0..648dbb3 100644 --- a/o815/o815.cpp +++ b/o815/o815.cpp @@ -145,7 +145,7 @@ void o815::mainLoop() { Sim->_newParas(); - Sim->_resetConfig(); + Sim->resetConfig(); progress measProg(comargs.nmeas); diff --git a/o815/o815.h b/o815/o815.h index 0505387..0e2a611 100644 --- a/o815/o815.h +++ b/o815/o815.h @@ -42,13 +42,16 @@ class o815 { class sim { public: sim(o815 *_O815, const int& _confmemSize); + ~sim (); void nextConfig(); char *confMem; virtual void _newParas()=0; - virtual void _resetConfig()=0; int nequi, nskip; + void resetConfig(); private: virtual void _makeSweep()=0; + virtual void _resetConfig()=0; + char *startConfiguration; protected: o815 *O815; ostream *log; diff --git a/o815/sim.cpp b/o815/sim.cpp index ec1ca89..70fe482 100644 --- a/o815/sim.cpp +++ b/o815/sim.cpp @@ -3,6 +3,8 @@ #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; @@ -10,6 +12,35 @@ o815::sim::sim(o815 *_O815, const int& _confmemSize) { nequi = O815->comargs.nequi; nskip = O815->comargs.nskip; 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 = new char[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(); +}