Merge the code of writeFinal and writeDump; Adding sortingIndex into DumpWriter; Fix a bug of writing last frame twice in integrator