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