forked from locklin/spatial-trees
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileoper.c
62 lines (46 loc) · 1.34 KB
/
fileoper.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
#include <stdlib.h>
#include <stdio.h>
/*************************************************************************/
float **ReadInputFile(filename,dimension,numpoints)
/*************************************************************************/
char *filename;
int *dimension,*numpoints;
{
int j,k;
FILE *f;
float **A;
float *center;
f=fopen(filename,"r");
if (f==NULL) {
*dimension = -1;
printf("file not found\n");
return(NULL);
}
fscanf(f,"%d\n",numpoints); /* read number of points */
fscanf(f,"%d\n",dimension); /* read dimension */
center = (float *)malloc((*dimension)*sizeof(float));
for (j=0; j < *dimension; j++) {
center[j]=0.0;
} /* used for center of gravity calculations */
A = (float **)malloc((*numpoints)*sizeof(float *));
for (k=0; k < *numpoints; k++) {
A[k] = (float *)malloc((*dimension)*sizeof(float));
}
for (k=0;k<*numpoints;k++) {
for (j=0; j < *dimension; j++) {
fscanf(f,"%f\n",&A[k][j]);
center[j]+=A[k][j];
}
}
for (j=0; j < *dimension; j++) {
center[j]=center[j]/(*numpoints);
}
/* I have no idea why they were doing this -SCL */
/* for (k=0;k<*numpoints;k++) { */
/* for (j=0; j < *dimension; j++) { */
/* A[k][j]=A[k][j]-center[j]; */
/* } */
/* } /\* make center of gravity the origin *\/ */
fclose(f);
return(A);
}