%%%%%%%%%%
% draw.m %
%%%%%%%%%%

if exist('fname_draw')==0
  fname_draw = 'draw.out';
end;

[tokens,times,values] = textread(fname_draw,'%s %f %f');
fprintf(1, 'fname_draw = ''%s''; %d entries.\n', ...
        fname_draw, size(times,1));

clf;
ColorOrder = get(gca,'ColorOrder');
while(1)
  mytoken = input('> Load variable = ', 's');
  if (strcmp(mytoken,'on'))
    fprintf(1, 'hold on.\n');
    hold on;
  elseif (strcmp(mytoken,'off'))
    fprintf(1, 'hold off.\n');
    hold off;
  elseif (strcmp(mytoken,''))
    fprintf(1, 'quit.\n');
    break;
  else
    myidx = find(strcmp(tokens,mytoken));
    if (size(myidx) == 0)
      fprintf(1, '%s entry does not exist.\n', mytoken);
    else
      x = times(myidx);
      y = values(myidx);
      eval ([mytoken ' = [x y];']);
      if ~ishold
        clf;
      else 
        myidx = [2:7 1];
        ColorOrder = ColorOrder(myidx,:);
        set(gca, 'ColorOrder', ColorOrder);
      end;
      plot(x,y);
      xlabel ('time [s]');
      if ~ishold, ylabel (mytoken); end;
      fprintf(1, '%s drawn, (%.2f %.2f %.2f).\n', mytoken, ColorOrder(1,:));
    end;
  end;
end;
