-
Notifications
You must be signed in to change notification settings - Fork 5
/
allotarrays.c
51 lines (40 loc) · 1015 Bytes
/
allotarrays.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
#include<stdlib.h>
#include<fftw3.h>
float ***allocate_fftwf_3d(long N1,long N2,long N3)
{
long ii,jj;
long asize,index;
float ***phia, *phi;
phia=(float ***) fftwf_malloc (N1 * sizeof(float **));
for(ii=0;ii<N1;++ii)
phia[ii]=(float **) fftwf_malloc (N2 * sizeof(float *));
asize = N1*N2;
asize = asize*N3;
if(!(phi = (float *) calloc(asize,sizeof(float))))
{
printf("error in allocate_fftwf_3d");
exit(0);
}
for(ii=0;ii<N1;++ii)
for(jj=0;jj<N2;++jj)
{
index = N2*N3;
index = index*ii + N3*jj;
phia[ii][jj]=phi+ index;
}
return(phia);
}
float **allocate_float_2d(long N1,int N2) /* Typically N1 is number of particles and N2 is number of dimensions namely 3 */
{
float **xxa, *xx;
long ii;
xxa=(float**)malloc(N1 * sizeof(float*));
if(!(xx = (float *) calloc((size_t)(N1*N2),sizeof(float))))
{
printf("error in allocate_float_2d");
exit(0);
}
for(ii=0;ii<N1;++ii)
xxa[ii]=xx + N2*ii ;
return(xxa);
}