-
Notifications
You must be signed in to change notification settings - Fork 0
/
landscape.c
112 lines (90 loc) · 2.4 KB
/
landscape.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
#include <time.h>
#include <complex.h>
#include "FFT.h"
#include "randunif.h"
#include "array.h"
#define Pi 3.14159265358979323846264338327
/* Define complex numbers */
typedef struct _complex{
double real;
double img;
} Complex;
/* Can now use complex numbers */
Complex PrepFFT(double S_f, double phi){
Complex x2;
x2.real = pow(S_f,0.5) * (cos(2.0*Pi*phi));
x2.img = pow(S_f,0.5) * (sin(2.0*Pi*phi));
return x2;
}
int landscape(double *LS, double BETA, int X){
int i, j;
int LG = log(X*X)/log(2);
size_t x = X;
size_t L = X*X;
double *phi, **u, **v, **S_f, **p, *w, *y;
double z, s;
Complex **q;
MAKE_1ARRAY(phi,L);
MAKE_1ARRAY(w,L);
MAKE_1ARRAY(y,L);
MAKE_2ARRAY(u,x,x);
MAKE_2ARRAY(v,x,x);
MAKE_2ARRAY(S_f,x,x);
MAKE_2ARRAY(p,x,x);
MAKE_2ARRAY(q,x,x);
/* Below makes u and its trandpose, v */
for(i=0; i<X; i++){
z = 0;
for(j=0; j<(X/2); j++){
u[i][j] = z/X;
v[j][i] = z/X;
z++;
}
for(j=(X/2); j<X; j++){
u[i][j] = z/X;
v[j][i] = z/X;
z--;
}
} /* Now have matrices u and v */
/* Get the matrix S_f */
for(i=0; i<X; i++){
for(j=0; j<X; j++){
s = (u[i][j]*u[i][j] + v[i][j]*v[i][j]);
if(s > 0){
S_f[i][j] = pow(s,(BETA/2));
}else{
S_f[i][j] = 0;
}
}
} /*Matrix S_f made from u and v */
/*Below makes random unifs, phi */
for(i=0; i<L; i++){
phi[i] = randunif();
}
/* Puts the random unifs in a matrix */
for(i=0; i<X; i++){
for(j=0; j<X; j++){
p[i][j] = phi[(X*i)+j];
q[i][j] = PrepFFT(S_f[i][j],p[i][j]);
w[(X*i)+j] = q[i][j].real;
y[(X*i)+j] = q[i][j].img;
}
} /* Matrix made */
/*Below runs the fast Fourier transformation */
FFT(1,LG,w,y);
/*Below puts this in the vector LS */
for(i=0; i<X; i++){
for(j=0; j<X; j++){
LS[(X*i)+j] = w[(X*i)+j];
}
}
FREE_1ARRAY(w);
FREE_1ARRAY(y);
FREE_1ARRAY(phi);
FREE_2ARRAY(u);
FREE_2ARRAY(v);
FREE_2ARRAY(S_f);
FREE_2ARRAY(p);
FREE_2ARRAY(q);
return EXIT_SUCCESS;
}