forked from andeplane/molecular-dynamics-fys3150
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathio.cpp
42 lines (35 loc) · 1.05 KB
/
io.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "io.h"
#include "system.h"
#include "atom.h"
#include "unitconverter.h"
#include <cstdlib>
using std::endl; using std::cout;
IO::IO()
{
}
IO::~IO() {
close();
}
void IO::open(const char *filename) {
if(file.is_open()) {
std::cout << "<IO.cpp> Error, tried to open file " << filename << ", but some file is already open." << endl;
exit(1);
}
file.open(filename);
}
void IO::close() {
if(file.is_open()) {
file.close();
}
}
// This saves the current state to a file following the xyz-standard (see http://en.wikipedia.org/wiki/XYZ_file_format )
void IO::saveState(System *system)
{
if(file.is_open()) {
file << system->atoms().size() << endl;
file << "The is an optional comment line that can be empty." << endl;
for(Atom *atom : system->atoms()) {
file << "Ar " << UnitConverter::lengthToAngstroms(atom->position.x()) << " " << UnitConverter::lengthToAngstroms(atom->position.y()) << " " << UnitConverter::lengthToAngstroms(atom->position.z()) << endl;
}
}
}