Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/inc/gCalcFunc.h b/inc/gCalcFunc.h
- index 2e4dc52..01e109c 100755
- --- a/inc/gCalcFunc.h
- +++ b/inc/gCalcFunc.h
- @@ -22,6 +22,7 @@ namespace calc {
- extern bool flagcalc;
- extern long double dtime_step;
- extern bool flag_collision;
- + extern std::vector<std::ofstream*> ofstreams;
- int calcForce(GravObject* mpmain, GravStep* vmpsinsert, mdv& mdvforcetotal);
- GravStep* calcAcc(GravStep* vmpsinsert, GravStep* vmpsout);
- diff --git a/src/gCalcFunc.cpp b/src/gCalcFunc.cpp
- index f7b41b2..3e909ea 100755
- --- a/src/gCalcFunc.cpp
- +++ b/src/gCalcFunc.cpp
- @@ -14,6 +14,7 @@ std::bitset<ERROR_CALC_MAX> calc::cerrors;
- bool calc::flagcalc = true;
- long double calc::dtime_step = 0;
- bool calc::flag_collision = true;
- +std::vector<std::ofstream*> calc::ofstreams;
- /**
- * Calculcate the force between reference object and all the other
- @@ -453,8 +454,9 @@ std::bitset<ERROR_CALC_MAX> calc::master(std::string filename, GravStep* pgs_sta
- int percent = 0;
- debugout("CalcCode() - Vars initialized, starting", 15);
- savepercentage(FILE_PERCENT,percent);
- - std::ofstream ofs_temp;
- - ofs_temp.open(filename.c_str(), std::ios::out | std::ios::app);
- + ofstreams.push_back(new std::ofstream(filename.c_str(), std::ios::out | std::ios::app));
- + const std::vector<std::ofstream*>::iterator ofs_iterator = ofstreams.end();
- +
- while (dtime_sum < dtime_max && flagcalc == true) {
- @@ -537,7 +539,7 @@ std::bitset<ERROR_CALC_MAX> calc::master(std::string filename, GravStep* pgs_sta
- if (dtime_sum >= lstep*dtime_save) {
- debugout("calcMain() - dtime_sum >= lstep*dtime_save", 10);
- - pgs_temp->savetofile(ofs_temp, ++lstep);
- + pgs_temp->savetofile(**ofs_iterator, ++lstep);
- //to be able to communicate with the frontend
- if((dtime_sum*100.0)/dtime_max > percent+1) {
- if(!savepercentage(FILE_PERCENT,++percent)) {
- @@ -562,7 +564,9 @@ std::bitset<ERROR_CALC_MAX> calc::master(std::string filename, GravStep* pgs_sta
- if(percent < 100 && !savepercentage(FILE_PERCENT, 100))
- error::errors |= error::file_out;
- - ofs_temp.close();
- + (**ofs_iterator).close();
- + delete (**ofs_iterator);
- + ofstreams.erase(ofs_iterator);
- delete pgs_temp;
- return cerrors;
- }
- diff --git a/src/main.cpp b/src/main.cpp
- index 2b39f21..ad0bda6 100755
- --- a/src/main.cpp
- +++ b/src/main.cpp
- @@ -6,6 +6,8 @@
- #include <vector>
- #include <cfloat>
- #include <bitset>
- +#include <signal.h>
- +#include <stdlib.h>
- #define MAIN
- @@ -15,11 +17,34 @@
- #include "gCalcFunc.h"
- #include "gError.h"
- +void sigterm (int param) {
- + printf ("SIGTERM received - flushing file\n");
- +
- + std::vector<std::ofstream*>::iterator ofs;
- + for (ofs = calc::ofstreams.begin(); ofs != calc::ofstreams.end(); ++ofs) {
- + if((**ofs).is_open())
- + (**ofs).close();
- +
- + delete (**ofs);
- + }
- +
- + remove("KILLED.tmp");
- + exit(1);
- +}
- +
- int main(int argc, char* pArgs[]) {
- std::string filename;
- GravDataSet* pgdsStart = new GravDataSet();
- long double dtime_step_default = -1;
- + /* Overwrite SIGTERM in order to flush file */
- + {
- + void (*signal_previous)(int);
- + signal_previous = signal(SIGTERM,sigterm);
- + if (signal_previous==SIG_IGN)
- + signal(SIGTERM,SIG_IGN);
- + }
- +
- for(int i=1; i < argc ; i++) {
- if( (std::string)pArgs[i] == FLAG_DEBUG1 || (std::string)pArgs[i] == FLAG_DEBUG2) {
- std::cout << "Frontend: " << FVERSION << std::endl;
Advertisement
Add Comment
Please, Sign In to add comment