function f=putbytes(b,fname)
%PUTBYTES Write bytes stored in a vector to a file
%	PUTBYTES(b,'filename') writes the bytes stored in vector 'b' to the 
%  file 'filename'. Each element of vector 'b' corresponds to one byte
%  of the file. Elements in 'b' must lie in the range 0 to 255.
 
%  Created 1998 Feb 23
%  Ed.Doering@Rose-Hulman.Edu
%  Department of Electrical and Computer Engineering
%  Rose-Hulman Institute of Technology
%  Terre Haute, IN 47803-3999
%
%  Copyright (c) 1998 by Ed Doering.
 

% Verify that elements in byte array are within the 0-255 range
if (max(b)>255 | min(b)<0)
   disp('PUTBYTES: Array elements must be within the range 0 to 255')
   return
end

% Open the file
[fid emessage] = fopen(fname,'w');
if fid == -1
    disp(['PUTBYTES: ', emessage])
    return
end

% Write the file contents and close the file
count=fwrite(fid,b,'uchar');
fclose(fid);

% Verify that correct number of bytes were written
if count ~= length(b)
   disp('PUTBYTES: Actual number of bytes written differed from expected count')
   return
end

return