-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck.cpp
More file actions
153 lines (129 loc) · 3.38 KB
/
check.cpp
File metadata and controls
153 lines (129 loc) · 3.38 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
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
#include <iostream>
#include <limits>
#include <fstream>
using namespace std;
#define MAXSTR 256
#define N 81920
float max(float arr[]);
float min(float arr[]);
float mode(float arr[]);
int main()
{
FILE *fin;
float *x, *y, *z, *w, *vx, *vy, *vz;
if ((fin = fopen("dubinski.tab", "r")))
{
char buf[MAXSTR];
float v[7];
// int idx = 0;
// allocate memory
// gPos = (float*)malloc(sizeof(float)*bodies*4);
// gVel = (float*)malloc(sizeof(float)*bodies*4);
x = new float[N];
y = new float[N];
z = new float[N];
vx = new float[N];
vy = new float[N];
vz = new float[N];
w = new float[N];
// total 81920 particles
// 16384 Gal. Disk
// 16384 And. Disk
// 8192 Gal. bulge
// 8192 And. bulge
// 16384 Gal. halo
// 16384 And. halo
int k=0;
for (int i=0; i< N; i++,k++)
{
// depend on input size...
// for (int j=0; j < skip; j++,k++)
fgets (buf, MAXSTR, fin); // lead line
sscanf(buf, "%f %f %f %f %f %f %f", v+0, v+1, v+2, v+3, v+4, v+5, v+6);
// update index
// idx = i * 4;
// // position
// gPos[idx+0] = v[1]*scaleFactor;
// gPos[idx+1] = v[2]*scaleFactor;
// gPos[idx+2] = v[3]*scaleFactor;
// // mass
// gPos[idx+3] = v[0]*massFactor;
// //gPos[idx+3] = 1.0f;
// //printf("mass : %f\n", gPos[idx+3]);
// // velocity
// gVel[idx+0] = v[4]*velFactor;
// gVel[idx+1] = v[5]*velFactor;
// gVel[idx+2] = v[6]*velFactor;
// gVel[idx+3] = 1.0f;
x[i]= v[1];
y[i]=v[2];
z[i]=v[3];
w[i]=v[0];
vx[i]=v[4];
vy[i]=v[5];
vz[i]=v[6];
}
cout << "maxMass = " << max(w) << endl;
cout << "minMass = " << min(w) << endl << endl;
cout << "maxX = " << max(x) << endl;
cout << "minX = " << min(x) << endl << endl;
cout << "maxY = " << max(y) << endl;
cout << "minY = " << min(y) << endl << endl;
cout << "maxZ = " << max(z) << endl;
cout << "minZ = " << min(z) << endl << endl;
cout << "maxVX = " << max(vx) << endl;
cout << "minVX = " << min(vx) << endl << endl;
cout << "maxVY = " << max(vy) << endl;
cout << "minVY = " << min(vy) << endl << endl;
cout << "maxVZ = " << max(vz) << endl;
cout << "minVZ = " << min(vz) << endl << endl;
cout << "ModeX = " << mode(x) << endl << endl;
cout << "ModeY = " << mode(y) << endl << endl;
cout << "ModeZ = " << mode(z) << endl << endl;
}
else
{
printf("cannot find file...: \n");
return 0;
}
return 0;
}
float max(float arr[])
{
float maxValue = numeric_limits<float>::min();
for(int i=0; i<N; ++i)
{
if( arr[i] > maxValue )
maxValue = arr[i];
}
return maxValue;
}
float min(float arr[])
{
float minValue = numeric_limits<float>::max();
for(int i=0; i<N; ++i)
{
if( arr[i] < minValue )
minValue = arr[i];
}
return minValue;
}
float mode(float arr[])
{
const int size=1000;
int temp[size];
int i=0;
int n;
for(i=0; i<size; ++i)
temp[i]=0;
for(i=0; i<N; ++i)
{
n = (int)(((arr[i])*10) + 500); //adding 500 bcoz index cannot be negative
temp[n]++;
}
int max=0;
for(i=0; i<size; i++)
max = (temp[i] > max)?i:max;
return ((max - 500))/10;
// return 0.0;
}