1 |
#ifndef __READWRITE_H__ |
2 |
#define __READWRITE_H__ |
3 |
|
4 |
#include <iostream> |
5 |
#include <fstream> |
6 |
|
7 |
#include <string.h> |
8 |
#include <stdio.h> |
9 |
#include <stdlib.h> |
10 |
#include <unistd.h> |
11 |
#include <sys/types.h> |
12 |
#include <sys/stat.h> |
13 |
|
14 |
|
15 |
#include "Atom.hpp" |
16 |
#include "SimInfo.hpp" |
17 |
#include "Thermo.hpp" |
18 |
|
19 |
using namespace std; |
20 |
|
21 |
class FilePos{ |
22 |
|
23 |
public: |
24 |
FilePos(){ |
25 |
myPos = NULL; |
26 |
next = NULL; |
27 |
} |
28 |
FilePos( fpos_t* thePos ) { |
29 |
myPos = thePos; |
30 |
next = NULL; |
31 |
} |
32 |
~FilePos(){ |
33 |
if( next != NULL ) delete next; |
34 |
if( myPos != NULL ) delete myPos; |
35 |
} |
36 |
|
37 |
void add( fpos_t *thePos ){ |
38 |
if( next != NULL ) |
39 |
next->add( thePos ); |
40 |
else |
41 |
next = new FilePos( thePos ); |
42 |
} |
43 |
|
44 |
FilePos &operator=(fpos_t *thePos){ myPos = thePos; return *this; } |
45 |
|
46 |
void setPos( fpos_t *thePos ){ myPos = thePos; } |
47 |
fpos_t *getPos( void ){ return myPos; } |
48 |
|
49 |
FilePos* getNext( void ) { return next; } |
50 |
private: |
51 |
|
52 |
fpos_t *myPos; |
53 |
FilePos* next; |
54 |
|
55 |
}; |
56 |
|
57 |
class DumpWriter{ |
58 |
|
59 |
public: |
60 |
DumpWriter( SimInfo* the_entry_plug ); |
61 |
~DumpWriter(); |
62 |
|
63 |
void writeDump( double currentTime ); |
64 |
void writeFinal( double currentTime); |
65 |
void writeFrame( ofstream& outFile, double finalTime ); |
66 |
|
67 |
#ifdef IS_MPI |
68 |
void update(); |
69 |
#endif |
70 |
|
71 |
private: |
72 |
|
73 |
#ifdef IS_MPI |
74 |
void sortByGlobalIndex(); |
75 |
#endif |
76 |
|
77 |
SimInfo* entry_plug; |
78 |
ofstream dumpFile; |
79 |
vector<pair<int, int> > indexArray; |
80 |
}; |
81 |
|
82 |
class StatWriter{ |
83 |
|
84 |
public: |
85 |
StatWriter( SimInfo* the_entry_plug ); |
86 |
~StatWriter(); |
87 |
|
88 |
void writeStat( double currentTime ); |
89 |
|
90 |
private: |
91 |
|
92 |
SimInfo* entry_plug; |
93 |
ofstream outFile; |
94 |
char outName[500]; |
95 |
Thermo* tStats; |
96 |
|
97 |
}; |
98 |
|
99 |
class InitializeFromFile{ |
100 |
|
101 |
public: |
102 |
InitializeFromFile( char *in_name ); |
103 |
~InitializeFromFile(); |
104 |
|
105 |
void readInit( SimInfo* the_entry_plug ); |
106 |
|
107 |
private: |
108 |
char* parseDumpLine(char* line, int atomIndex); |
109 |
char* parseCommentLine(char* line, SimInfo* entry_plug); |
110 |
FILE *c_in_file; |
111 |
char c_in_name[500]; |
112 |
SimInfo* simnfo; |
113 |
}; |
114 |
|
115 |
class DumpReader{ |
116 |
|
117 |
public: |
118 |
DumpReader( char *in_name ); |
119 |
~DumpReader(); |
120 |
|
121 |
int getNframes(); |
122 |
void scanFile( void ); |
123 |
|
124 |
void getNextFrame() {} |
125 |
void readFrame(SimInfo* the_simnfo, int whichFrame); |
126 |
|
127 |
private: |
128 |
|
129 |
void readSet( int whichFrame ); |
130 |
char* parseDumpLine(char* line, int atomIndex); |
131 |
char* parseCommentLine(char* line, double &time, double boxMat[9] ); |
132 |
FILE *inFile; |
133 |
char inName[500]; |
134 |
bool isScanned; |
135 |
int nFrames; |
136 |
|
137 |
FilePos** frameStart; |
138 |
FilePos* headFP; |
139 |
|
140 |
SimInfo *simnfo; |
141 |
}; |
142 |
|
143 |
|
144 |
|
145 |
#endif |