% octave function loadframe.m
% loads image from dataset of pictures i took of soldier's tower
%
% Use: f1=loadframe(1); % converts to grey and loads first frame in sequence
%    : [r2 g2 b2]=loadframe(2); % loads second frame in sequence

function [R, G, B] = loadframe(k);

%filename = sprintf('v%03d.jpg',k);
if k<100
 filename = sprintf('/mann/a/a/htdocs/orbits/hart_house_soldiers_tower_newer/r%03d.jpg',k);
end%if
if k>=100
 filename = sprintf('/mann/a/a/htdocs/orbits/hart_house_soldiers_tower_newer/v%03d.jpg',k);
end%if
if nargin ~=1
  error('loadframe: must have 1 input argument k')
end%if nargin
if nargout~=3
  if nargout ~= 1
    error('loadframe: must have 1 or 3 output arguments (Y or R, G, B)')
  end%if nargout
end%if nargout

if nargout == 3
%  commandstr=['djpeg ' filename ' > deleteme_deleteme_loadframe.ppm'];
  %ans = djpeg v001.jpg > deleteme_deleteme_loadframe.ppm
%  systemstr=["system(""" commandstr """)"];
%  systemstr=['system("' commandstr '")'];
  %ans = system("djpeg v001.jpg > deleteme_deleteme_loadframe.ppm")
%  eval(systemstr);
  eval(sprintf('!djpeg %s > deleteme_deleteme_loadframe.ppm', filename));
  [R G B] = loadpnm('deleteme_deleteme_loadframe.ppm');
end%if
if nargout == 1
%  commandstr=['djpeg -grey ' filename ' > deleteme_deleteme_loadframe.pgm'];
%  systemstr=['system("' commandstr '")'];
%  eval(systemstr);
  eval(sprintf('!djpeg -grey %s > deleteme_deleteme_loadframe.pgm',filename));
  R = loadpnm('deleteme_deleteme_loadframe.pgm');
end%if

