function data = load_bin_floats(filename, channels, numbers_in_record, header, precision)

%function data = load_bin_floats(filename, channels, numbers_in_record, header, precision)
% Loads binary file consisting of floats or doubles in Intel format
% There is totally 'numbers_in_record' amount of numbers in each time stamped
% record. The 'channels' are chosen in the output data. There is 'header' 
% number of (time)header information (not considered as channels).
% by kaj.wiik@hut.fi (4 Mar 1996)
% 

if strcmp(precision, 'float')
	bytes_in_number = 4;
elseif strcmp(precision, 'double')
	bytes_in_number = 8;
else
	error('Unknown precision')
end

%apuli=['wc --bytes ' filename]
%hepuli= system(apuli,1)

bytes = sscanf(system(['wc --bytes ' filename], 1), '%f');
numbers = bytes/bytes_in_number;

fd = fopen(filename, 'r');

[data, count] = fread(fd, numbers, precision);
data = data(1:count);
data = reshape(data, numbers_in_record, count/numbers_in_record);
data = [data(1, :); data(channels + header, :)]';

fclose(fd);
