-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathmake_calculus.c
More file actions
66 lines (59 loc) · 1.31 KB
/
make_calculus.c
File metadata and controls
66 lines (59 loc) · 1.31 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
/*
* make_calculus
*
* This program reads the contents of the binary WDSP file "calculus"
* and dumps the data as two arrays of floating-point numbers
*
* The output is intended to be part of the file "calculus.c" which
* initializes these arrays (static data) for use with "memcpy"
* in emnr.c.
*
* Should the WDSP file "calculus" be changed, "calculus.c" should
* be re-generated using this program.
*
* return values of main()
*
* 0 all OK
* -1 sizeof(double) is not 8
* -2 error opening file "calculus"
* -3 read error
*/
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
int main() {
int fd;
int i,j;
double d;
if (sizeof(double) != 8) {
printf("Data type DOUBLE is not 8-byte. Please check!\n");
return -1;
}
fd=open ("calculus", O_RDONLY);
if (fd < 0) {
printf("Could not open file 'calculus'\n");
return -2;
}
for (j=0; j<2; j++) {
switch (j) {
case 0:
printf("double GG[241*241]={\n");
break;
case 1:
printf("double GGS[241*241]={\n");
break;
}
for (i=0; i< 241*241; i++) {
if (read(fd, &d, 8) != 8) {
printf("READ ERROR\n");
return -3;
}
if (i == 241*241 -1) {
printf("%30.25f};\n", d);
} else {
printf("%30.25f,\n", d);
}
}
return 0;
}
}