function void = gen_figure (what);
%GEN_FIGURE	Generate figures for fit-ell-lsq
%
%	produces figure for 'what'. (named <what>.ps)
%

  if (nargin < 1), what = []; end;
  if (what == []), what = str2mat(...
    'fig1',...
    'rotinv1',...
    'rotinv2',...
    'fig2',...
    'lyle1',...
    'lyle2',...
    'ageom1');
  end;

  for i=1:size(what,1),
    str = deblank(what(i,:));

    clf
    clear global
    if     (strcmp(str, 'rotinv1') | ...
            strcmp(str, 'rotinv2') | ...
            strcmp(str, 'rotinv3')),
      axis ([-10,10,-8,12]);
    elseif (strcmp(str, 'fig1')),
      axis ([-2, 12, -2, 12]);
    elseif (strcmp(str, 'fig2')),
      axis ([-10, 40, -25, 20]);
    elseif (strcmp(str, 'lyle1')),
      axis ([-10, 40, -25, 20]);
    elseif (strcmp(str, 'lyle2')),
      axis ([0, 20, 0, 20]);
    elseif (strcmp(str, 'ageom1')),
      axis ([-25 25 -15 15]);
    else
      error ('unknown figure');
    end;
    axis ('equal');
    hold
    grid

%----------------------------------------
    if     (strcmp(str, 'rotinv1') | ...
            strcmp(str, 'rotinv2') | ...
            strcmp(str, 'rotinv3')),
      X = gen_points ('spec2'); X1 = X;
      plot (X(:,1), X(:,2), 'o');
      if (strcmp(str, 'rotinv1')),
        [z1, a1, b1, alpha1] = bookstein (X);
      elseif (strcmp(str, 'rotinv2')),
        [z1, a1, b1, alpha1] = algellipse (X);
      elseif (strcmp(str, 'rotinv3')),
        [z1, a1, b1, alpha1] = alge_simple (X);
      end  
      drawellipse (z1, a1, b1, alpha1, '-');
      if (strcmp(str, 'rotinv1')),
        [z1, a1, b1, alpha1] = alge_simple (X);
	drawellipse (z1, a1, b1, alpha1, '--');
      end
      X = X1;
      t = [-6;-6]; phi = 0;
      X = X + ones(size(X,1),1)*t';
      Q = [cos(phi) -sin(phi); sin(phi) cos(phi)];
      X = X*Q';
      plot (X(:,1), X(:,2), 'o');
      if (strcmp(str, 'rotinv1')),
        [z, a, b, alpha] = bookstein (X);
      elseif (strcmp(str, 'rotinv2')),
        [z, a, b, alpha] = algellipse (X);
      elseif (strcmp(str, 'rotinv3')),
        [z, a, b, alpha] = alge_simple (X);
      else
      end        
      drawellipse (z, a, b, alpha, '-');
      if (strcmp(str, 'rotinv1')),
        [z, a, b, alpha] = alge_simple (X);
	drawellipse (z, a, b, alpha, '--');
      end
%% compare
      z2 = Q*(z1 + t);
      alpha2 = alpha1 + phi;
      drawellipse (z2, a1, b1, alpha2, '--');
%%
      X = X1;
      t = [-4;4]; phi = pi/4;
      X = X + ones(size(X,1),1)*t';
      Q = [cos(phi) -sin(phi); sin(phi) cos(phi)];
      X = X*Q';
      plot (X(:,1), X(:,2), 'o');
      if (strcmp(str, 'rotinv1')),
        [z, a, b, alpha] = bookstein (X);
      elseif (strcmp(str, 'rotinv2')),
        [z, a, b, alpha] = algellipse (X);
      elseif (strcmp(str, 'rotinv3')),
        [z, a, b, alpha] = alge_simple (X);
      end        
      drawellipse (z, a, b, alpha, '-');
      if (strcmp(str, 'rotinv1')),
        [z, a, b, alpha] = alge_simple (X);
	drawellipse (z, a, b, alpha, '--');
      end
%% compare
      z2 = Q*(z1 + t);
      alpha2 = alpha1 + phi;
      drawellipse (z2, a1, b1, alpha2, '--');
%----------------------------------------
    elseif (strcmp(str, 'fig1')),
      X = [[1 2 5 7 9 3]', [7 6 8 7 5 7]'];
      [z, a] = circle (X, [4;5], 2);
      drawcircle (z, a);
      [z, a] = algcircle (X);
      drawcircle (z, a, '--');
%----------------------------------------
    elseif (strcmp(str, 'fig2')),
      X = [[1 2 5 7 9 3 6 8]', [7 6 8 7 5 7 2 4]'];
      [z, a, b, alpha] = algellipse (X);
      drawellipse (z, a, b, alpha, '--');
      Y = ellipse_residual (X, z, a, b, alpha);
      res_algellipse = norm(Y)
      [z, a] = parcircle (X, [4;5], 2, 0);
      b = a/2; alpha = 0;
      [z, a, b, alpha, phi, step] = pare (X, z, a, b, alpha, 3, 0);
      drawellipse (z, a, b, alpha);
      Y = ellipse_residual (X, z, a, b, alpha);
      res_pare = norm(Y)
%----------------------------------------
    elseif (strcmp(str, 'lyle1')),
      X = gen_points ('spec1');
      [z, a, b, alpha, step] = lyle (X, 1);
      drawellipse (z, a, b, alpha, '--');
      Y = ellipse_residual (X, z, a, b, alpha);
      res_lyle = norm(Y) 
%----------------------------------------
    elseif (strcmp(str, 'lyle2')),
      X = gen_points ('ginput1');
      [z, a, b, alpha, step] = wate2 (X, 0);
      drawellipse (z, a, b, alpha, '-.');
      Y = ellipse_residual (X, z, a, b, alpha);
      res_wate2 = norm(Y)
      [z, a, b, alpha] = algellipse (X);
      drawellipse (z, a, b, alpha, ':');
      Y = ellipse_residual (X, z, a, b, alpha);
      res_algellipse = norm(Y)
      [z, a, b, alpha, step] = lyle (X, 1);
      drawellipse (z, a, b, alpha);
      Y = ellipse_residual (X, z, a, b, alpha);
      res_lyle = norm(Y) 
      [z, a, b, alpha, phi, step] = pare (X, z, a, b, alpha, 2, 0);
      drawellipse (z, a, b, alpha, '--');
      Y = ellipse_residual (X, z, a, b, alpha);
      res_pare = norm(Y) 
%----------------------------------------
    elseif (strcmp(str, 'ageom1')),
      X = gen_points ('ellipse_rand', 20, 10, 8, 0.2);
      [z, a, b, alpha, step] = wate2 (X, 3);
      drawellipse (z, a, b, alpha);
      Y = ellipse_residual (X, z, a, b, alpha);
      res_wate2 = norm(Y) 
      [z, a, b, alpha, phi, step] = pare (X, z, a, b, alpha, 2, 0);
      drawellipse (z, a, b, alpha, '--'); 
      Y = ellipse_residual (X, z, a, b, alpha);
      res_pare = norm(Y) 
%----------------------------------------
    else
      error ('fatal');
    end

    plot (X(:,1), X(:,2), 'o'); 

    cmdstr = ['print -deps ', str, '.ps'];
    eval (cmdstr);

  end

end % gen_figure
