function interpshow(XData, YData)

  if nargin < 2
    XData = [.4 .1 .3 .5 .7 .9 .6];
    YData = [.1 .5 .9 .7 .9 .5 .1];
  end;

  fig = figure( ...
    'MenuBar', 'none', ... 
    'Name', 'Interp Show', ...
    'DoubleBuffer', 'on', ...
    'NumberTitle', 'off', ...
    'WindowButtonUpFcn', @ButtonUp, ...
    'Position', [200, 200, 600, 500]);

  ax = axes('ButtonDownFcn',@NewPoint,...
    'XLim', [0, 1], 'YLim', [0, 1]);

  cmenu = uicontextmenu;
  uimenu(cmenu, 'Label', 'Delete', 'Callback', @DeletePoint);

  pnts = line( ...
    'XData', XData, ...
    'YData', YData, ...
    'ButtonDownFcn', @ButtonDown, ...
    'Marker', 'o', ...
    'MarkerFaceColor', 'w', ...
    'MarkerEdgeColor', 'b', ...
    'Color', 'k', ...
    'UIContextMenu', cmenu, ...
    'Visible', 'On', ...
    'LineStyle', '-.');

  Pchip = line('HitTest', 'Off', 'Color', [1/2 1/2 0], 'Visible' , 'on');

  Spline = line('HitTest', 'Off', 'Color', 'r', 'Visible' , 'off');

  BSpline = line('HitTest', 'Off', 'Color', 'b', 'Visible' , 'off');
  
  Bezier = line('HitTest', 'Off', 'Color', [0 1/2 1/2], 'Visible' , 'off');

  xc = 455;
  yc = 320;

  uicontrol('Position', [xc yc 80 133], ...
   'Style','Frame', ...
   'BackGroundColor', 'w' ...
   );

  uicontrol('Position', [xc+10 yc+110 50 10], ...
   'Style','Check','String', 'Points', 'Value', 1, ...
   'BackGroundColor', 'w', ...
   'CallBack', @PntsVisible);

  uicontrol('Position', [xc+10 yc+90 50 10], ...
   'Style','Check','String', 'Line', 'Value', 1, ...
   'BackGroundColor', 'w', ...
   'CallBack', @LineVisible);

  uicontrol('Position', [xc+10 yc+70 50 10], ...
   'Style','Check','String', 'Pchip', 'Value', 1, ...
   'ForegroundColor', get(Pchip, 'Color'), ...
   'BackGroundColor', 'w', ...
   'CallBack', {@MakeVisible, Pchip});

  uicontrol('Position', [xc+10 yc+50 50 10], ...
   'Style','Check','String', 'Spline', 'Value', 0, ...
   'ForegroundColor', get(Spline, 'Color'), ...
   'BackGroundColor', 'w', ...
   'CallBack', {@MakeVisible, Spline});

  uicontrol('Position', [xc+10 yc+30 60 10], ...
   'Style','Check','String', 'B-spline', 'Value', 0, ...
   'ForegroundColor', get(BSpline, 'Color'), ...
   'BackGroundColor', 'w', ...
   'CallBack', {@MakeVisible, BSpline});

  uicontrol('Position', [xc+10 yc+10 50 10], ...
   'Style','Check','String', 'Bezier', 'Value', 0, ...
   'ForegroundColor', get(Bezier, 'Color'), ...
   'BackGroundColor', 'w', ...
   'CallBack', {@MakeVisible, Bezier});

  redraw;

  function PntsVisible(h, eventdata)
    if get(h, 'Value') == 1
      set(pnts, 'Marker', 'o');
    else
      set(pnts, 'Marker', 'None');
    end;
    redraw;
  end;

  function LineVisible(h, eventdata)
    if get(h, 'Value') == 1
      set(pnts, 'LineStyle', '-.');
    else
      set(pnts, 'LineStyle', 'None');
    end;
    redraw;
  end;

  function MakeVisible(h, eventdata, obj)
    if get(h, 'Value') == 1
      set(obj, 'Visible', 'On');
    else
      set(obj, 'Visible', 'Off');
    end;
    redraw;
  end;

  function redraw

    XData = get(pnts, 'XData');
    YData = get(pnts, 'YData');

    m = length(XData);
    if m <= 1
      SplineX = [];
      SplineY = [];
      PchipX = [];
      PchipY = [];
      bsp = zeros(0,2);
      bez = zeros(0,2);
    else
      t = 1:m; tt = 1:0.1:m;

      SplineX = spline(t, XData, tt);
      SplineY = spline(t, YData, tt);

      PchipX = pchip(t, XData, tt)';
      PchipY = pchip(t, YData, tt)';

      bsp = bspline([XData(1) YData(1); XData' YData'; XData(end) YData(end)]);
%      bsp = bspline([XData' YData']);

      bez = bezier([XData' YData']);
    end;
    set(Pchip, 'XData', PchipX,  'YData', PchipY);
    set(Spline, 'XData', SplineX,  'YData', SplineY);
    set(BSpline, 'XData', bsp(:,1),  'YData', bsp(:,2));
    set(Bezier, 'XData', bez(:,1),  'YData', bez(:,2));
  end;

  function NewPoint(h, eventdata)

      p = get(ax, 'CurrentPoint');

      XData = get(pnts, 'XData');
      YData = get(pnts, 'YData');
      XData = [XData, p(1,1)];
      YData = [YData, p(1,2)];
      set(pnts, 'XData', XData, 'YData', YData);

      redraw;
  end;


  function ButtonDown(h, eventdata)
   
    p = get(ax, 'CurrentPoint');
    p = p(1, 1:2);
    XData = get(pnts, 'XData');
    YData = get(pnts, 'YData');

    moving_point = FindPoint(p, XData, YData);

    set(fig, 'WindowButtonMotionFcn', @MovePoint, ...
      'Pointer', 'Circle');

    function MovePoint(h, eventdata)
     
      p = get(ax, 'CurrentPoint');
      p = p(1, 1:2);

      XData(moving_point) = p(1);
      YData(moving_point) = p(2);
      set(pnts, 'XData', XData, 'YData', YData);

      redraw;
    end;

  end;

  function ButtonUp(h, eventdata)
   
    set(fig, 'WindowButtonMotionFcn', '', ...
      'Pointer', 'Arrow');

  end;


  function DeletePoint(h, eventdata)
   
    p = get(ax,'CurrentPoint');
    p = p(1, 1:2);
    XData = get(pnts, 'XData');
    YData = get(pnts, 'YData');

    i = FindPoint(p, XData, YData);
    XData(i) = [];
    YData(i) = [];
    set(pnts, 'XData', XData, 'YData', YData);

    redraw;

  end;

  function i = FindPoint(p, XData, YData);

    [m, i] = min((XData - p(1)).^2 + (YData - p(2)).^2);

  end;

end



