%COMP 256 Assignment 1
%Adrian Ilie



% savepgmraw.m 
% -----------
%
% function savepgmraw(filename,pic,maxgray)
%
%
%  AUTHOR: Adrian Ilie
%    DATE: Sept 17, 2003
% PURPOSE:
%         Writes gray scale PGM (raw) images.
%
% ARGUMENTS: 
%         pic: The gray scale image in an array.
%         maxgray: The maximum pixel value in pic. Usually 255.
%         filename: A string containing the name of the image file to be saved.
%
  
function savepgmraw(filename,pic,maxgray)



%% Open file.
%
 filename(findstr(filename,' '))=[];
 fid=fopen(filename,'w');

 imsize = size(pic);
 fprintf(fid,'P5\n%d %d\n%d\n',imsize(2),imsize(1),maxgray);

 pic2 = pic';
 fwrite(fid,pic2);
 

 fclose(fid);


%%%%

