function writebits(x, masknum, filename);

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];


fid = fopen(filename,'wb');
fwrite(fid, masknum, 'ubit3');
for(i=1:length(maskX)^2)
	if (maskX(i) ~= 0)
		w1=strcat('ubit', int2str(maskX(i)));
		fwrite(fid, x(i), w1);
	end
end
fclose('all');


