% reads a string from a pgm file, skipping comments (between # and eol)

function s=readstring(fid)

s=fscanf(fid,'%s',1);
while s(1)=='#',
  fgetl(fid);
  s=fscanf(fid,'%s',1);
end
