ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/md_code/DumpWriter.cpp
Revision: 10
Committed: Tue Jul 9 18:40:59 2002 UTC (22 years ago) by mmeineke
Original Path: branches/mmeineke/mdtools/md_code/DumpWriter.cpp
File size: 2900 byte(s)
Log Message:
everything you need to make libmdtools

File Contents

# Content
1 #include <cstring>
2 #include <iostream>
3 #include <fstream>
4
5 #include "ReadWrite.hpp"
6
7
8
9 DumpWriter::DumpWriter( SimInfo* the_entry_plug ){
10
11 entry_plug = the_entry_plug;
12
13 strcpy( outName, entry_plug->sampleName );
14 outFile.open(outName, ios::out | ios::trunc );
15
16 if( !outFile ){
17
18 cerr << "Could not open \"" << outName << "\" for dump output.\n";
19 exit(8);
20 }
21
22 //outFile.setf( ios::scientific );
23 }
24
25 DumpWriter::~DumpWriter( ){
26
27 outFile.close();
28 }
29
30 void DumpWriter::writeDump( double currentTime ){
31
32 int i;
33 double q[4];
34 DirectionalAtom* dAtom;
35 int nAtoms = entry_plug->n_atoms;
36 Atom** atoms = entry_plug->atoms;
37
38
39 outFile << nAtoms << "\n";
40
41 outFile << currentTime << "\t"
42 << entry_plug->box_x << "\t"
43 << entry_plug->box_y << "\t"
44 << entry_plug->box_z << "\n";
45
46 for( i=0; i<nAtoms; i++ ){
47
48 outFile
49 << atoms[i]->getType() << "\t"
50 << atoms[i]->getX() << "\t"
51 << atoms[i]->getY() << "\t"
52 << atoms[i]->getZ() << "\t"
53 << atoms[i]->get_vx() << "\t"
54 << atoms[i]->get_vy() << "\t"
55 << atoms[i]->get_vz() << "\t";
56
57 if( atoms[i]->isDirectional() ){
58
59 dAtom = (DirectionalAtom *)atoms[i];
60 dAtom->getQ( q );
61
62 outFile
63 << q[0] << "\t"
64 << q[1] << "\t"
65 << q[2] << "\t"
66 << q[3] << "\t"
67 << dAtom->getJx() << "\t"
68 << dAtom->getJy() << "\t"
69 << dAtom->getJz() << "\n";
70 }
71 else{
72 outFile
73 << 0.0 << "\t"
74 << 0.0 << "\t"
75 << 0.0 << "\t"
76 << 0.0 << "\t"
77 << 0.0 << "\t"
78 << 0.0 << "\t"
79 << 0.0 << "\n";
80 }
81 }
82 outFile.flush();
83 }
84
85
86 void DumpWriter::writeFinal(){
87
88 char finalName[500];
89 strcpy( finalName, entry_plug->finalName );
90
91 ofstream finalOut( finalName );
92 if( !finalOut ){
93 cerr << "Could not open \"" << finalName << "\" for final dump output.\n";
94 exit(8);
95 }
96
97 // finalOut.setf( ios::scientific );
98
99
100 int i;
101 double q[4];
102 DirectionalAtom* dAtom;
103 int nAtoms = entry_plug->n_atoms;
104 Atom** atoms = entry_plug->atoms;
105
106
107 finalOut << nAtoms << "\n";
108
109 finalOut << 0.0 << "\t"
110 << entry_plug->box_x << "\t"
111 << entry_plug->box_y << "\t"
112 << entry_plug->box_z << "\n";
113
114 for( i=0; i<nAtoms; i++ ){
115
116 finalOut
117 << atoms[i]->getType() << "\t"
118 << atoms[i]->getX() << "\t"
119 << atoms[i]->getY() << "\t"
120 << atoms[i]->getZ() << "\t"
121 << atoms[i]->get_vx() << "\t"
122 << atoms[i]->get_vy() << "\t"
123 << atoms[i]->get_vz() << "\t";
124
125 if( atoms[i]->isDirectional() ){
126
127 dAtom = (DirectionalAtom *)atoms[i];
128 dAtom->getQ( q );
129
130 finalOut
131 << q[0] << "\t"
132 << q[1] << "\t"
133 << q[2] << "\t"
134 << q[3] << "\t"
135 << dAtom->getJx() << "\t"
136 << dAtom->getJy() << "\t"
137 << dAtom->getJz() << "\n";
138 }
139 else{
140 finalOut
141 << 0.0 << "\t"
142 << 0.0 << "\t"
143 << 0.0 << "\t"
144 << 0.0 << "\t"
145 << 0.0 << "\t"
146 << 0.0 << "\t"
147 << 0.0 << "\n";
148 }
149 }
150 finalOut.close();
151 }