summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/c/readFile.c
blob: 2c16abd6fba51ea56ef96cd5569acc5f1434778c (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
/********************************
Author: Sravanthi Kota Venkata
********************************/

#include "sdvbs_common.h"

F2D* readFile(unsigned char* fileName)
{
    FILE* fp;
    F2D *fill;
    float temp;
    int rows, cols;
    int i, j;

    fp = fopen(fileName, "r");
    if(fp == NULL)
    {
        printf("Error in file %s\n", fileName);
        return NULL;
    }

    fscanf(fp, "%d", &cols);
    fscanf(fp, "%d", &rows);

    fill = fSetArray(rows, cols, 0);

    for(i=0; i<rows; i++)
    {
        for(j=0; j<cols; j++)
        {
            fscanf(fp, "%f", &(subsref(fill,i,j)) );
        }
    }

    fclose(fp);    
    return fill;
}