ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/md_code/DumpWriter.cpp
Revision: 162
Committed: Thu Oct 31 21:20:49 2002 UTC (21 years, 8 months ago) by mmeineke
File size: 3030 byte(s)
Log Message:
*** empty log message ***

File Contents

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