-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_particles.cpp
More file actions
67 lines (53 loc) · 1.52 KB
/
parse_particles.cpp
File metadata and controls
67 lines (53 loc) · 1.52 KB
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
/*
File: parse_particles.cpp
Brief: Script to extract particles from binary simulation output file
Author: Andrea Klein <alklein@alumni.stanford.edu>
Usage: g++ parse_particles.cpp -o parser
./parser > particles.txt
Note: the infile halo_part.z=00.0000 must be in the same directory.
*/
#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;
// Np = number of particles assigned to halos.
// Total number of particles is ~ 1 billion.
int Np = 333796680;
struct _particle
{
int ip;
int ih;
float x, y, z;
float vx, vy, vz;
};
int readsim(string fname, _particle *pp)
{
ifstream infile;
infile.open(fname.c_str(), ios::binary|ios::in);
double * dummy = new double[1];
infile.read( (char *)&dummy[0], 8 ); // read first 8 bytes into dummy
for(int i=0; i<Np; i++)
{
infile.read( (char *)&pp[i].ip, 8 );
infile.read( (char *)&pp[i].ih, 8 );
infile.read( (char *)&pp[i].x, sizeof(float) );
infile.read( (char *)&pp[i].y, sizeof(float) );
infile.read( (char *)&pp[i].z, sizeof(float) );
infile.read( (char *)&pp[i].vx, sizeof(float) );
infile.read( (char *)&pp[i].vy, sizeof(float) );
infile.read( (char *)&pp[i].vz, sizeof(float) );
}
return 0;
}
int main()
{
_particle *pp = new _particle[Np];
readsim("halo_part.z=00.0000", pp);
for (int i=0; i<Np; i++) {
cout << pp[i].ip << ' '
<< pp[i].ih << ' '
<< pp[i].x << ' ' << pp[i].y << ' ' << pp[i].z << ' '
<< pp[i].vx << ' ' << pp[i].vy << ' ' << pp[i].vz << endl;
}
return 0;
}