%
% read_file.m
% 
% -MCW Fall 2016
%

fname = 'exampledata.z2';
myfile = fopen(fname, 'r');
if (myfile == -1)
    error(sprintf('File "%s" open did not work.', fname));
    return
end


[mybuffer, num_read] = fread(myfile, 10, 'uchar');
while (num_read > 0) 
    disp(sprintf('Read %d characters', num_read));
    disp(sprintf('Contents are %s ', mybuffer));
    for i=1:num_read
        disp(sprintf(' %d : %d ', i, mybuffer(i)));
    end
    disp(sprintf('So far, we have read %d characters', ftell(myfile)));
    [mybuffer, num_read] = fread(myfile, 10, 'uchar');

end

if (fclose(myfile) == -1)
    
   error('File did not close');
end
