diff options
Diffstat (limited to 'SD-VBS/common/c/fSelfCheck.c')
-rw-r--r-- | SD-VBS/common/c/fSelfCheck.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/SD-VBS/common/c/fSelfCheck.c b/SD-VBS/common/c/fSelfCheck.c new file mode 100644 index 0000000..fe146b5 --- /dev/null +++ b/SD-VBS/common/c/fSelfCheck.c | |||
@@ -0,0 +1,59 @@ | |||
1 | /******************************** | ||
2 | Author: Sravanthi Kota Venkata | ||
3 | ********************************/ | ||
4 | |||
5 | #include "sdvbs_common.h" | ||
6 | |||
7 | int fSelfCheck(F2D* in1, char* path, float tol) | ||
8 | { | ||
9 | int r1, c1, ret=1; | ||
10 | float *buffer; | ||
11 | FILE* fd; | ||
12 | int count=0, i, j; | ||
13 | char file[256]; | ||
14 | |||
15 | r1 = in1->height; | ||
16 | c1 = in1->width; | ||
17 | |||
18 | buffer = (float*)malloc(sizeof(float)*r1*c1); | ||
19 | |||
20 | sprintf(file, "%s", path); | ||
21 | fd = fopen(file, "r"); | ||
22 | |||
23 | if(fd == NULL) | ||
24 | { | ||
25 | printf("Error: Expected file not opened %s\n", file); | ||
26 | return -1; | ||
27 | } | ||
28 | |||
29 | while(!feof(fd)) | ||
30 | { | ||
31 | fscanf(fd, "%f", &buffer[count]); | ||
32 | count++; | ||
33 | } | ||
34 | count--; | ||
35 | |||
36 | if(count != (r1*c1)) | ||
37 | { | ||
38 | printf("Checking error: dimensions mismatch. Expected = %d, Observed = %d \n", count, (r1*c1)); | ||
39 | return -1; | ||
40 | } | ||
41 | |||
42 | for(i=0; i<r1*c1; i++) | ||
43 | { | ||
44 | float inVal = asubsref(in1,i); | ||
45 | |||
46 | if( (inVal-buffer[i])>tol || (buffer[i]-inVal)>tol ) | ||
47 | { | ||
48 | printf("Mismatch %d: (%f, %f)\n", i, buffer[i], inVal); | ||
49 | return -1; | ||
50 | } | ||
51 | } | ||
52 | |||
53 | fclose(fd); | ||
54 | printf("Verification\t\t- Successful\n"); | ||
55 | free(buffer); | ||
56 | return ret; | ||
57 | } | ||
58 | |||
59 | |||