-
Notifications
You must be signed in to change notification settings - Fork 0
/
snapshot.c
633 lines (586 loc) · 18.6 KB
/
snapshot.c
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
#include "snapshot.h"
#include <stdbool.h>
#define COPY(type) int copy_ ## type (type * a, type * b) { \
if (a==NULL || b==NULL) return 255; \
memcpy(a,b,sizeof(type)); \
return 0; \
}
COPY(Atom);
COPY(Box3);
const char s_timestep[] = "ITEM: TIMESTEP";
const char s_n_atoms[] = "ITEM: NUMBER OF ATOMS";
const char s_box_bounds[] = "ITEM: BOX BOUNDS pp pp pp";
const char s_box_bounds_z[] = "ITEM: BOX BOUNDS pp pp ff";
const char s_box_bounds_xy[] = "ITEM: BOX BOUNDS ff ff pp";
const char s_box_bounds_xyz[] = "ITEM: BOX BOUNDS ff ff ff";
const char s_atoms_dipole[] = "ITEM: ATOMS id type xu yu zu mux muy muz";
const char s_atoms_vel[] = "ITEM: ATOMS id type xu yu zu vx vy vz";
const char s_atoms_all[] = "ITEM: ATOMS id type xu yu zu mux muy muz vx vy vz";
const char s_atoms[] = "ITEM: ATOMS id type xu yu zu";
const char delimeter[] = " ";
char * strtok_null_safe ( char * str, const char * delimiters );
int ReadDumpForOnlyCheck(FILE *fp) {
const int i_timestep = strlen(s_timestep);
const int i_n_atoms = strlen(s_n_atoms);
const int i_box_bounds = strlen(s_box_bounds);
const int i_atoms = strlen(s_atoms);
const int i_atoms_vel = strlen(s_atoms_vel);
const int i_atoms_dipole = strlen(s_atoms_dipole);
const int i_atoms_all = strlen(s_atoms_all);
bigint timestep;
int n_atoms;
real xlow, xhigh, ylow, yhigh, zlow, zhigh;
error_code = 0;
/* atom_column atom_ids = {
* .id = -1 ,.type=-1,
* .x= -1,.y=-1,.z=-1,
* .mux=-1,.muy=-1,.muz=-1,
* .vx = -1,.vy=-1,.vz =-1
* };
*/
int id, type;
real xu, yu, zu;
real mux, muy, muz;
real vx, vy, vz;
int i;
Atom *p_atom;
#define FAIL false
#define SUCCESS n_atoms
read_lines(1,fp);
if( strncmp(s_timestep,line,i_timestep) !=0) {
return FAIL;
}
read_lines(1,fp);
timestep = atol(line);
#ifndef NDEBUG
fprintf(stderr,"atol(line) = %ld\n"
"atoi(line) = %d\n"
, timestep,atoi(line));
#endif
read_lines(1,fp);
if( strncmp(s_n_atoms,line,i_n_atoms) !=0)
return FAIL;
read_lines(1,fp);
n_atoms = atoi(line);
// int pbc[3]={0,0,0};
int pbcTYPE=0;
read_lines(1,fp);
if( strncmp(s_box_bounds,line,i_box_bounds) ==0) {
pbcTYPE = PBC_X|PBC_Y|PBC_Z;
// pbc[0] = 1; pbc[1]=1; pbc[2]=1;
}
else if( strncmp(s_box_bounds_z,line,i_box_bounds) ==0) {
pbcTYPE = PBC_X|PBC_Y;
// pbc[0] = 1; pbc[1]=1; pbc[2]=0;
}
else if( strncmp(s_box_bounds_xy,line,i_box_bounds) ==0) {
pbcTYPE = PBC_Z;
// pbc[0] = 0; pbc[1]=0; pbc[2]=1;
}
else if( strncmp(s_box_bounds_xyz,line,i_box_bounds) ==0) {
pbcTYPE =0;
}
else
return FAIL;
read_lines(1,fp);
xlow = atof(strtok_null_safe(line,delimeter));
xhigh = atof(strtok_null_safe(NULL,delimeter));
read_lines(1,fp);
ylow = atof(strtok_null_safe(line,delimeter));
yhigh = atof(strtok_null_safe(NULL,delimeter));
read_lines(1,fp);
zlow = atof(strtok_null_safe(line,delimeter));
zhigh = atof(strtok_null_safe(NULL,delimeter));
Snapshot *snap = NewSnapshot(timestep, n_atoms);
Box3 box = {xlow,xhigh,ylow,yhigh,zlow,zhigh, pbcTYPE};
// Box3 box = {xlow,xhigh,ylow,yhigh,zlow,zhigh, {pbc[0],pbc[1],pbc[2]}};
copy_Box3(&snap->Box, &box);
// error( (char*)s_timestep);
// fprintf(stderr,"%ld\n", timestep);
// error((char*)s_n_atoms);
// fprintf(stderr,"%d\n", snap->n_atoms);
// error((char*)s_box_bounds);
// fprintf(stderr,"%f %f\n", snap->box.xlow,snap->box.xhigh);
// fprintf(stderr,"%f %f\n", snap->box.ylow,snap->box.yhigh);
// fprintf(stderr,"%f %f\n", snap->box.zlow,snap->box.zhigh);
read_lines(1,fp);
if( strncmp(s_atoms,line,i_atoms) ==0) {
for (i=0; i<n_atoms; i++){
read_lines(1,fp);
/* fprintf(stderr,"%d %d %f %f %f %f %f %f\n",
id,type,
xu,yu,zu,
mux,muy,muz);*/
if (error_code == 1) return FAIL;
}
}
else if (strncmp(s_atoms_vel,line,i_atoms_vel) ==0 ) {
for (i=0; i<n_atoms; i++){
read_lines(1,fp);
if (error_code == 1) return FAIL;
/* fprintf(stderr,"%d %d %f %f %f %f %f %f\n",
id,type,
xu,yu,zu,
mux,muy,muz);*/
}
}
else if (strncmp(s_atoms_dipole,line,i_atoms_dipole) ==0 ) {
for (i=0; i<n_atoms; i++){
read_lines(1,fp);
if (error_code == 1) return FAIL;
/* fprintf(stderr,"%d %d %f %f %f %f %f %f\n",
id,type,
xu,yu,zu,
mux,muy,muz);*/
}
}
else if (strncmp(s_atoms_all,line,i_atoms_all) ==0 ) {
for (i=0; i<n_atoms; i++){
read_lines(1,fp);
if (error_code == 1) return FAIL;
/* fprintf(stderr,"%d %d %f %f %f %f %f %f\n",
id,type,
xu,yu,zu,
mux,muy,muz);*/
}
}
else {
return FAIL;
}
return SUCCESS;
}
Snapshot *ReadDump(FILE *fp) {
const char s_timestep[] = "ITEM: TIMESTEP";
const char s_n_atoms[] = "ITEM: NUMBER OF ATOMS";
const char s_box_bounds[] = "ITEM: BOX BOUNDS pp pp pp";
const char s_box_bounds_z[] = "ITEM: BOX BOUNDS pp pp ff";
const char s_box_bounds_xy[] = "ITEM: BOX BOUNDS ff ff pp";
const char s_box_bounds_xyz[] = "ITEM: BOX BOUNDS ff ff ff";
const char s_atoms_dipole[] = "ITEM: ATOMS id type xu yu zu mux muy muz";
const char s_atoms_vel[] = "ITEM: ATOMS id type xu yu zu vx vy vz";
const char s_atoms_all[] =
"ITEM: ATOMS id type xu yu zu mux muy muz vx vy vz";
const char s_atoms[] = "ITEM: ATOMS id type xu yu zu";
const int i_timestep = strlen(s_timestep);
const int i_n_atoms = strlen(s_n_atoms);
const int i_box_bounds = strlen(s_box_bounds);
const int i_atoms = strlen(s_atoms);
const int i_atoms_vel = strlen(s_atoms_vel);
const int i_atoms_dipole = strlen(s_atoms_dipole);
const int i_atoms_all = strlen(s_atoms_all);
const char delimeter[] = " ";
bigint timestep;
int n_atoms;
real xlow, xhigh, ylow, yhigh, zlow, zhigh;
int id, type;
real xu, yu, zu, mux, muy, muz;
real vx, vy, vz;
int i;
Atom *p_atom;
error_code = 0;
read_lines(1, fp);
if (strncmp(s_timestep, line, i_timestep) != 0) {
return (Snapshot *)(error("not ITEM: TIMESTEP"));
}
read_lines(1, fp);
timestep = atol(line);
#ifndef NDEBUG
fprintf(stderr,"atol(line) = %ld\n"
"atoi(line) = %d\n"
, timestep,atoi(line));
#endif
read_lines(1,fp);
if( strncmp(s_n_atoms,line,i_n_atoms) !=0)
return (Snapshot*)(error("not ITEM: NUMBER OF ATOMS"));
read_lines(1,fp);
n_atoms = atoi(line);
int pbcTYPE=0;
read_lines(1,fp);
if( strncmp(s_box_bounds,line,i_box_bounds) ==0) {
pbcTYPE = PBC_X|PBC_Y|PBC_Z;
// pbc[0] = 1; pbc[1]=1; pbc[2]=1;
}
else if( strncmp(s_box_bounds_z,line,i_box_bounds) ==0) {
pbcTYPE = PBC_X|PBC_Y;
// pbc[0] = 1; pbc[1]=1; pbc[2]=0;
}
else if( strncmp(s_box_bounds_xy,line,i_box_bounds) ==0) {
pbcTYPE = PBC_Z;
// pbc[0] = 0; pbc[1]=0; pbc[2]=1;
}
else if( strncmp(s_box_bounds_xyz,line,i_box_bounds) ==0) {
pbcTYPE =0;
}
else
return (Snapshot*)(error("not ITEM: BOX BOUNDS pp pp pp(ff)"));
read_lines(1,fp);
xlow = atof(strtok_null_safe(line,delimeter));
xhigh = atof(strtok_null_safe(NULL,delimeter));
read_lines(1,fp);
ylow = atof(strtok_null_safe(line,delimeter));
yhigh = atof(strtok_null_safe(NULL,delimeter));
read_lines(1,fp);
zlow = atof(strtok_null_safe(line,delimeter));
zhigh = atof(strtok_null_safe(NULL,delimeter));
Snapshot *snap = NewSnapshot(timestep, n_atoms);
// Box3 box = {xlow,xhigh,ylow,yhigh,zlow,zhigh,
//{pbc[0],pbc[1],pbc[2]}};
Box3 box = {xlow,xhigh,ylow,yhigh,zlow,zhigh, pbcTYPE};
copy_Box3(&snap->Box, &box);
error( (char*)s_timestep);
// fprintf(stderr,"%ld\n", timestep);
error((char*)s_n_atoms);
// fprintf(stderr,"%d\n", snap->n_atoms);
error((char*)s_box_bounds);
// fprintf(stderr,"%f %f\n", snap->box.xlow,snap->box.xhigh);
// fprintf(stderr,"%f %f\n", snap->box.ylow,snap->box.yhigh);
// fprintf(stderr,"%f %f\n", snap->box.zlow,snap->box.zhigh);
read_lines(1,fp);
if( strncmp(s_atoms_dipole,line,i_atoms_dipole) ==0) {
#ifndef NDEBUG
fprintf(stderr,"s_atoms_dipole style snapshot\n");
#endif
for (i=0; i<n_atoms; i++){
read_lines(1,fp);
if (error_code == 1) return FAIL;
id =atoi(strtok_null_safe(line, delimeter));
type = atoi(strtok_null_safe(NULL,delimeter));
xu = atof(strtok_null_safe(NULL,delimeter));
yu = atof(strtok_null_safe(NULL,delimeter));
zu = atof(strtok_null_safe(NULL,delimeter));
mux = atof(strtok_null_safe(NULL,delimeter));
muy = atof(strtok_null_safe(NULL,delimeter));
muz = atof(strtok_null_safe(NULL,delimeter));
p_atom = &(snap->atoms[i]);
make_atom_dipole( p_atom,id,type,xu,yu,zu,mux,muy,muz);
}
}
else if (strncmp(s_atoms_vel,line,i_atoms_vel) ==0 ) {
#ifndef NDEBUG
fprintf(stderr,"s_atoms_vel style snapshot\n");
#endif
for (i=0; i<n_atoms; i++){
read_lines(1,fp);
if (error_code == 1) return FAIL;
id =atoi(strtok_null_safe(line, delimeter));
type = atoi(strtok_null_safe(NULL,delimeter));
xu = atof(strtok_null_safe(NULL,delimeter));
yu = atof(strtok_null_safe(NULL,delimeter));
zu = atof(strtok_null_safe(NULL,delimeter));
vx = atof(strtok_null_safe(NULL,delimeter));
vy = atof(strtok_null_safe(NULL,delimeter));
vz = atof(strtok_null_safe(NULL,delimeter));
p_atom = &(snap->atoms[i]);
make_atom_vel( p_atom,id,type,xu,yu,zu,vx,vy,vz);
/* fprintf(stderr,"%d %d %f %f %f %f %f %f\n",
id,type,
xu,yu,zu,
mux,muy,muz);*/
}
}
else if (strncmp(s_atoms_all,line,i_atoms_all) ==0 ) {
#ifndef NDEBUG
fprintf(stderr,"s_atoms_all style snapshot\n");
#endif
for (i=0; i<n_atoms; i++){
read_lines(1,fp);
if (error_code == 1) return FAIL;
id =atoi(strtok_null_safe(line, delimeter));
type = atoi(strtok_null_safe(NULL,delimeter));
xu = atof(strtok_null_safe(NULL,delimeter));
yu = atof(strtok_null_safe(NULL,delimeter));
zu = atof(strtok_null_safe(NULL,delimeter));
mux = atof(strtok_null_safe(NULL,delimeter));
muy = atof(strtok_null_safe(NULL,delimeter));
muz = atof(strtok_null_safe(NULL,delimeter));
vx = atof(strtok_null_safe(NULL,delimeter));
vy = atof(strtok_null_safe(NULL,delimeter));
vz = atof(strtok_null_safe(NULL,delimeter));
p_atom = &(snap->atoms[i]);
make_atom_all( p_atom,id,type,xu,yu,zu,mux,muy,muz,vx,vy,vz);
}
}
else if (strncmp(s_atoms_vel,line,i_atoms_vel) ==0 ) {
#ifndef NDEBUG
fprintf(stderr,"s_atoms_vel style snapshot\n");
#endif
for (i=0; i<n_atoms; i++){
read_lines(1,fp);
if (error_code == 1) return FAIL;
id =atoi(strtok_null_safe(line, delimeter));
type = atoi(strtok_null_safe(NULL,delimeter));
xu = atof(strtok_null_safe(NULL,delimeter));
yu = atof(strtok_null_safe(NULL,delimeter));
zu = atof(strtok_null_safe(NULL,delimeter));
vx = atof(strtok_null_safe(NULL,delimeter));
vy = atof(strtok_null_safe(NULL,delimeter));
vz = atof(strtok_null_safe(NULL,delimeter));
p_atom = &(snap->atoms[i]);
make_atom_vel( p_atom,id,type,xu,yu,zu,vx,vy,vz);
/* fprintf(stderr,"%d %d %f %f %f %f %f %f\n",
id,type,
xu,yu,zu,
mux,muy,muz);*/
}
}
else if (strncmp(s_atoms,line,i_atoms) ==0 ) {
for (i=0; i<n_atoms; i++){
read_lines(1,fp);
if (error_code == 1) return FAIL;
id =atoi(strtok_null_safe(line, delimeter));
type = atoi(strtok_null_safe(NULL,delimeter));
xu = atof(strtok_null_safe(NULL,delimeter));
yu = atof(strtok_null_safe(NULL,delimeter));
zu = atof(strtok_null_safe(NULL,delimeter));
p_atom = &(snap->atoms[i]);
make_atom( p_atom,id,type,xu,yu,zu);
/* fprintf(stderr,"%d %d %f %f %f %f %f %f\n",
id,type,
xu,yu,zu,
mux,muy,muz);*/
}
}
else {
return (Snapshot*)(error("not ITEM: ATOMS id type xu yu zu mux muy muz"));
}
error_code =0;
return snap;
}
void* error( char string[MAXLINE] ) {
#ifndef NDEBUG
fputs( string, stderr );
fputs( "\n", stderr );
#endif
return NULL;
// exit(1);
}
char * strtok_null_safe ( char * str, const char * delimiters ) {
char* ret_str = strtok(str,delimiters);
if (ret_str == NULL ) {
error_code = 1 ;
return "0";
}
return ret_str;
}
void read_lines(int n,FILE* fp) // from lammps reader_native.cpp
{
char *eof;int i;
memset(line, 0, sizeof(line));
for (i = 0; i < n; i++) eof = fgets(line,MAXLINE,fp);
if (eof == NULL) {
error_code = 1;
error("Unexpected end of dump file");
}
}
Snapshot *NewSnapshot(bigint timestep, int n) {
Snapshot *snap = (Snapshot *)malloc(sizeof(Snapshot));
snap->timestep = timestep;
snap->NumAtoms = n;
snap->atoms = (Atom *)malloc(sizeof(Atom) * n);
return snap;
}
void FreeSnapshot(Snapshot *snap) {
if (snap->atoms != NULL)
free(snap->atoms);
if (snap != NULL)
free(snap);
}
int make_atom(Atom *col, int id, int type, real x, real y, real z) {
real mu1;
if (col == NULL)
return 255;
col->id = id;
col->type = type;
col->x = x;
col->y = y;
col->z = z;
col->atomType = 0;
return 0;
}
int make_atom_dipole(Atom *col, int id, int type, real x, real y, real z,
real mux, real muy, real muz) {
real mu1;
if (col == NULL)
return 255;
col->id = id;
col->type = type;
col->x = x;
col->y = y;
col->z = z;
mu1 = sqrt(mux * mux + muy * muy + muz * muz);
col->mu1 = mu1;
if (mu1 > 0.001) {
col->mux = mux / mu1;
col->muy = muy / mu1;
col->muz = muz / mu1;
}
col->atomType = ATOM_DIPOLE;
return 0;
}
int make_atom_vel(Atom *col, int id, int type, real x, real y, real z, real vx,
real vy, real vz) {
real mu1;
if (col == NULL)
return 255;
col->id = id;
col->type = type;
col->x = x;
col->y = y;
col->z = z;
col->vx = vx;
col->vy = vy;
col->vz = vz;
col->atomType = ATOM_VEL;
return 0;
}
int make_atom_all(Atom *col, int id, int type, real x, real y, real z, real mux,
real muy, real muz, real vx, real vy, real vz) {
real mu1;
if (col == NULL)
return 255;
col->id = id;
col->type = type;
col->x = x;
col->y = y;
col->z = z;
mu1 = sqrt(mux * mux + muy * muy + muz * muz);
col->mu1 = mu1;
col->vx = vx;
col->vy = vy;
col->vz = vz;
col->atomType = ATOM_ALL;
if (mu1 > 0.001) {
col->mux = mux / mu1;
col->muy = muy / mu1;
col->muz = muz / mu1;
}
return 0;
}
int DumpAtomStream(AtomStream *stream, FILE *fp, int nTime, int n_atoms,
int s_id, int s_type) {
int id, type;
real xu, yu, zu, mux, muy, muz;
real vx, vy, vz;
Atom *p_atom;
const int i_atoms = strlen(s_atoms);
const int i_atoms_vel = strlen(s_atoms_vel);
const int i_atoms_dipole = strlen(s_atoms_dipole);
const int i_atoms_all = strlen(s_atoms_all);
fseek(fp, 0, SEEK_SET); //
int i;
for (i = 0; i < nTime; i++) {
read_lines(9, fp);
if (strncmp(s_atoms_dipole, line, i_atoms_dipole) == 0) {
for (i = 0; i < n_atoms; i++) {
read_lines(1, fp);
if (error_code == 1)
return FAIL;
id = atoi(strtok_null_safe(line, delimeter));
type = atoi(strtok_null_safe(NULL, delimeter));
if (s_id == id && s_type == type) {
xu = atof(strtok_null_safe(NULL, delimeter));
yu = atof(strtok_null_safe(NULL, delimeter));
zu = atof(strtok_null_safe(NULL, delimeter));
mux = atof(strtok_null_safe(NULL, delimeter));
muy = atof(strtok_null_safe(NULL, delimeter));
muz = atof(strtok_null_safe(NULL, delimeter));
stream->x[i] = xu;
stream->y[i] = yu;
stream->z[i] = zu;
stream->mux[i] = mux;
stream->muy[i] = muy;
stream->muz[i] = muz;
stream->atomType = ATOM_DIPOLE;
}
}
} else if (strncmp(s_atoms_vel, line, i_atoms_vel) == 0) {
for (i = 0; i < n_atoms; i++) {
read_lines(1, fp);
if (error_code == 1)
return FAIL;
id = atoi(strtok_null_safe(line, delimeter));
type = atoi(strtok_null_safe(NULL, delimeter));
if (s_id == id && s_type == type) {
xu = atof(strtok_null_safe(NULL, delimeter));
yu = atof(strtok_null_safe(NULL, delimeter));
zu = atof(strtok_null_safe(NULL, delimeter));
vx = atof(strtok_null_safe(NULL, delimeter));
vy = atof(strtok_null_safe(NULL, delimeter));
vz = atof(strtok_null_safe(NULL, delimeter));
stream->x[i] = xu;
stream->y[i] = yu;
stream->z[i] = zu;
stream->vx[i] = vx;
stream->vy[i] = vy;
stream->vz[i] = vz;
stream->atomType = ATOM_VEL;
}
}
} else if (strncmp(s_atoms_all, line, i_atoms_all) == 0) {
for (i = 0; i < n_atoms; i++) {
read_lines(1, fp);
if (error_code == 1)
return FAIL;
id = atoi(strtok_null_safe(line, delimeter));
type = atoi(strtok_null_safe(NULL, delimeter));
if (s_id == id && s_type == type) {
xu = atof(strtok_null_safe(NULL, delimeter));
yu = atof(strtok_null_safe(NULL, delimeter));
zu = atof(strtok_null_safe(NULL, delimeter));
mux = atof(strtok_null_safe(NULL, delimeter));
muy = atof(strtok_null_safe(NULL, delimeter));
muz = atof(strtok_null_safe(NULL, delimeter));
vx = atof(strtok_null_safe(NULL, delimeter));
vy = atof(strtok_null_safe(NULL, delimeter));
vz = atof(strtok_null_safe(NULL, delimeter));
stream->x[i] = xu;
stream->y[i] = yu;
stream->z[i] = zu;
stream->vx[i] = vx;
stream->vy[i] = vy;
stream->vz[i] = vz;
stream->mux[i] = mux;
stream->muy[i] = muy;
stream->muz[i] = muz;
stream->atomType = ATOM_ALL;
}
}
} else if (strncmp(s_atoms, line, i_atoms) == 0) {
for (i = 0; i < n_atoms; i++) {
read_lines(1, fp);
if (error_code == 1)
return FAIL;
id = atoi(strtok_null_safe(line, delimeter));
type = atoi(strtok_null_safe(NULL, delimeter));
if (s_id == id && s_type == type) {
xu = atof(strtok_null_safe(NULL, delimeter));
yu = atof(strtok_null_safe(NULL, delimeter));
zu = atof(strtok_null_safe(NULL, delimeter));
stream->x[i] = xu;
stream->y[i] = yu;
stream->z[i] = zu;
stream->atomType = 0;
}
}
}
}
return 0;
}
int MallocAtomStream(AtomStream *stream, int nTime) {
stream->x = (real *)malloc(nTime * sizeof(real));
stream->y = (real *)malloc(nTime * sizeof(real));
stream->z = (real *)malloc(nTime * sizeof(real));
stream->mux = (real *)malloc(nTime * sizeof(real));
stream->muy = (real *)malloc(nTime * sizeof(real));
stream->muz = (real *)malloc(nTime * sizeof(real));
}
int FreeAtomStream(AtomStream *stream) {
free(stream->x);
free(stream->y);
free(stream->z);
free(stream->mux);
free(stream->muy);
free(stream->muz);
}
#undef FAIL
#undef SUCCESS