function [y, masknum]=readbits(filename)
fid=fopen(filename,'rb');
masknum=fread(fid, 1, 'ubit3');
mask=findmask(masknum);     

maskX = [mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
 mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
 mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
 mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
 mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
 mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
 mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
 mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
 mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
 mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
 mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
 mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
 mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
 mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
 mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
 mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
 mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
 mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
 mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
  mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask; 
mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
 mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
 mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
 mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
 mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
 mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
 mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
 mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
 mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask;
 mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask mask];


y=zeros(length(maskX));
for (j = 1:length(maskX)^2)
	if (maskX(j) ~= 0)
		w2 = strcat('ubit', int2str(maskX(j)));
		y(j) = fread(fid, 1, w2);
	else
		w2 = 'ubit1';
	end
end



