Re-order the operations around i/o to cope with stop files
Fixes #624 (closed) and #768 (closed).
The problem originates from the small drift we add when dumping a snapshot to match the exact time demanded by the user. This was all done in engine_step()
. This leads to particles being drifted slighly ahead of ti_current
(but before the next step)
So, if we then make a decision about dumping a restart file outside of engine_step()
, here in main()
, then we have to drift backwards, which is forbidden.
The new version makes all the decision about dumping a check point file before the decision to write a snapshot. This leads to no extra drift being applied in the restart files.
Also, if we reach a time limit, we do not write a snapshot; we just stop. The snapshot will be written upon restart before the next step is done.