Added the --save-energy flag to save the total energy to a file.
Using atexit() to print any error messages.