summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/c/fSelfCheck.c
blob: fe146b58fcf4759fb1dfcd44dea93a27a7b46bc8 (plain) (blame)
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
/********************************
Author: Sravanthi Kota Venkata
********************************/

#include "sdvbs_common.h"

int fSelfCheck(F2D* in1, char* path, float tol)
{
    int r1, c1, ret=1;
    float *buffer;
    FILE* fd;
    int count=0, i, j;
    char file[256];
    
    r1 = in1->height;
    c1 = in1->width;

    buffer = (float*)malloc(sizeof(float)*r1*c1);

    sprintf(file, "%s", path);
    fd = fopen(file, "r");
    
    if(fd == NULL)
    {
        printf("Error: Expected file not opened %s\n", file);
        return -1;
    }
   
    while(!feof(fd))
    {
        fscanf(fd, "%f", &buffer[count]);
        count++;
    }
    count--;

    if(count != (r1*c1))
    {
        printf("Checking error: dimensions mismatch. Expected = %d, Observed = %d \n", count, (r1*c1));
        return -1;
    }
    
    for(i=0; i<r1*c1; i++)
    {
        float inVal = asubsref(in1,i);

        if( (inVal-buffer[i])>tol || (buffer[i]-inVal)>tol )
        {
            printf("Mismatch %d: (%f, %f)\n", i, buffer[i], inVal);
            return -1;
        }
    }

    fclose(fd);
    printf("Verification\t\t- Successful\n");
    free(buffer);
    return ret;
}