ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/mmeineke/dumpCat/dumpCat.c
Revision: 47
Committed: Wed Jul 24 16:51:43 2002 UTC (21 years, 11 months ago) by mmeineke
Content type: text/plain
File size: 5553 byte(s)
Log Message:
little utility for catting together dump files.

File Contents

# Content
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <unistd.h>
5
6
7 void usage( void );
8
9 char* program_name;
10
11
12 int main( int argc, char* argv[] ){
13
14 double realTime, currentTime, lastTime;
15 double boxX, boxY, boxZ;
16 char* foo;
17 char* in_name;
18 char* out_name;
19 char readBuffer[2000];
20 int i,j,k;
21 int lineNum;
22
23 FILE *in_file;
24 FILE *out_file;
25
26 program_name = argv[0];
27
28 out_name = argv[1];
29
30 if( !access( out_name, F_OK ) ){
31
32 in_file = fopen( out_name, "r" );
33 lineNum =0;
34 if( in_file == NULL ){
35 printf( "Error opening \"%s\"\n", out_name );
36 exit(8);
37 }
38
39 fgets( readBuffer, sizeof( readBuffer ), in_file );
40 lineNum++;
41 if( feof( in_file ) ){
42 printf( "File %s ended unexpectedly at line %d\n", out_name, lineNum );
43 exit(8);
44 }
45
46 while( !feof( in_file ) ){
47
48 i = atoi(readBuffer);
49
50 fgets( readBuffer, sizeof( readBuffer ), in_file );
51 lineNum++;
52 if( feof( in_file ) ){
53 printf( "File %s ended unexpectedly at line %d\n",
54 out_name, lineNum);
55 exit(8);
56 }
57
58 foo = strtok( readBuffer, " \t;,\n" );
59 lastTime = atof( foo );
60
61 for(j=0; j<i; j++){
62
63 fgets( readBuffer, sizeof( readBuffer ), in_file );
64 lineNum++;
65 if( feof( in_file ) ){
66 printf( "File %s ended unexpectedly at line %d,"
67 " with atom %d\n", out_name, lineNum, j);
68 exit(8);
69 }
70
71 }
72
73 fgets( readBuffer, sizeof( readBuffer ), in_file );
74 lineNum++;
75 }
76
77 fclose( in_file );
78
79 out_file = fopen( out_name, "a" );
80 }
81
82 else{
83
84 out_file = fopen( out_name, "w" );
85 lastTime = 0.0;
86
87 in_name = argv[2];
88
89 in_file = fopen( in_name, "r" );
90 lineNum = 0;
91 if( in_file == NULL ){
92 printf( "Error opening \"%s\"\n", in_name );
93 exit(8);
94 }
95
96 fgets( readBuffer, sizeof( readBuffer ), in_file );
97 lineNum++;
98 if( feof( in_file ) ){
99 printf( "File %s ended unexpectedly at line %d\n", in_name, lineNum );
100 exit(8);
101 }
102
103 fprintf( out_file, "%s", readBuffer );
104
105 i = atoi(readBuffer);
106
107 fgets(readBuffer, sizeof(readBuffer), in_file);
108 lineNum++;
109 if( feof( in_file ) ){
110 printf( "File %s ended unexpectedly at line %d\n", in_name, lineNum );
111 exit(8);
112 }
113
114 fprintf( out_file, "%s", readBuffer );
115
116 for(j=0; j<i; j++){
117
118 fgets( readBuffer, sizeof( readBuffer ), in_file );
119 lineNum++;
120 if( feof( in_file ) ){
121 printf( "File %s ended unexpectedly at line %d,"
122 " with atom %d\n", in_name, lineNum, j);
123 exit(8);
124 }
125
126 fprintf( out_file, "%s", readBuffer );
127 }
128
129 fclose( in_file );
130 }
131
132 for( k=2; k<argc; k++ ){
133
134 in_name = argv[k];
135
136 in_file = fopen( in_name, "r" );
137 lineNum = 0;
138 if( in_file == NULL ){
139 printf( "Error opening \"%s\"\n", in_name );
140 exit(8);
141 }
142
143
144 // skip the zero frame
145
146 fgets( readBuffer, sizeof( readBuffer ), in_file );
147 lineNum++;
148 if( feof( in_file ) ){
149 printf( "File %s ended unexpectedly at line %d\n", in_name, lineNum );
150 exit(8);
151 }
152
153 i = atoi(readBuffer);
154
155 fgets(readBuffer, sizeof(readBuffer), in_file);
156 lineNum++;
157 if( feof( in_file ) ){
158 printf( "File %s ended unexpectedly at line %d\n", in_name, lineNum );
159 exit(8);
160 }
161
162 for(j=0; j<i; j++){
163
164 fgets( readBuffer, sizeof( readBuffer ), in_file );
165 lineNum++;
166 if( feof( in_file ) ){
167 printf( "File %s ended unexpectedly at line %d,"
168 " with atom %d\n", in_name, lineNum, j);
169 exit(8);
170 }
171 }
172
173 // now start reading and writing
174
175 fgets( readBuffer, sizeof( readBuffer ), in_file );
176 lineNum++;
177 if( feof( in_file ) ){
178 printf( "File %s ended unexpectedly at line %d\n", in_name, lineNum );
179 exit(8);
180 }
181
182 while( !feof( in_file ) ){
183
184 fprintf( out_file, "%s", readBuffer );
185
186 i = atoi(readBuffer);
187
188 fgets(readBuffer, sizeof(readBuffer), in_file);
189 lineNum++;
190 if( feof( in_file ) ){
191 printf( "File %s ended unexpectedly at line %d\n", in_name, lineNum );
192 exit(8);
193 }
194
195
196 foo = strtok(readBuffer, " ,;\t");
197 if(foo == NULL){
198 printf("error in reading time at line %d in %s\n", lineNum, in_name);
199 exit(8);
200 }
201
202 currentTime = atof( foo );
203 realTime = currentTime + lastTime;
204
205
206 foo = strtok(NULL, " ,;\t");
207 if(foo == NULL){
208 printf("error in reading boxX at line %d in %s\n", lineNum, in_name);
209 exit(8);
210 }
211
212 boxX = atof( foo );
213
214 foo = strtok(NULL, " ,;\t");
215 if(foo == NULL){
216 printf("error in reading boxY at line %d in %s\n", lineNum, in_name);
217 exit(8);
218 }
219
220 boxY = atof( foo );
221
222 foo = strtok(NULL, " ,;\t");
223 if(foo == NULL){
224 printf("error in reading boxZ at line %d in %s\n", lineNum, in_name);
225 exit(8);
226 }
227
228 boxZ = atof( foo );
229
230 fprintf( out_file, "%lf\t%lf\t%lf\t%lf\n",
231 realTime, boxX, boxY, boxZ );
232
233 for(j=0; j<i; j++){
234
235 fgets( readBuffer, sizeof( readBuffer ), in_file );
236 lineNum++;
237 if( feof( in_file ) ){
238 printf( "File %s ended unexpectedly at line %d,"
239 " with atom %d\n", in_name, lineNum, j);
240 exit(8);
241 }
242
243 fprintf( out_file, "%s", readBuffer );
244
245 }
246
247 fgets( readBuffer, sizeof( readBuffer ), in_file );
248 lineNum++;
249 }
250
251 lastTime = realTime;
252 fclose( in_file );
253 }
254
255 fclose( out_file );
256
257 return 0;
258 }