function pgm_convert(fn);

% This matlab function reads in a Joebob Havlicek binary image and writes
% it back out as a PGM-type image.  The function call must supply an image
% name with a valid Joebob Havlivek style binary image (namely, X bytes of
% 'uchar' data).
%
% fn = 'filename.bin'

% Create string for pgm output filename
fn_pgm = [fn(1:length(fn)-3) 'pgm'];

% Open the binary file and read it in to a vector (sequential data), then
% close the file.
fid = fopen(fn,'r');
[A, numbytes] = fread(fid,inf,'uchar');
fclose(fid);
if numbytes ~= 65536
    error('Wrong size file, dope!');
end;

% Open the output file for PGM, add header data to the start, then write
% and close.
fid = fopen(fn_pgm,'w');
data = [80 53 10 50 53 54 32 50 53 54 10 50 53 53 10]';
fwrite(fid,data,'uchar');
fwrite(fid,A,'uchar');
fclose(fid);