function [ pixval ] = datHdrConv(filenameCore)
% read image from .hdr and .dat files
%   filenameCore is a string
%   the .hdr and .dat files are the out put of Agata's script

% open the header file
fid = fopen([filenameCore '.hdr'], 'r'); 

% get height and width from the header file
% change this as needed depending on what your .hdr file is 
line = fgets(fid);  
while ischar(line)   
    heightaux = sscanf(line, 'i       Height    %d', 1);  
    if (size(heightaux)==1)
        height=heightaux;
    end
    widthaux = sscanf(line, 'i       Width    %d', 1);  
    if (size(widthaux)==1)
        width=widthaux;
    end
    line = fgets(fid); 
end 

% print height and width
% [height, width]

% close file; free memory
fclose(fid); 

% open image (.dat) file
fid = fopen([filenameCore '.dat'], 'r'); 

for i = 1:height  
    for j = 1:width
        line = fgets(fid); 
        pixval(i, j) = sscanf(line, '%f'); 
    end 
end

% close file; free memory
fclose(fid); 

% display matrix as image
% imshow(pixval, []) 

end