function fig = eb_demo(Keyword,Handle)
% GUI Eclipsing Binary light-curve demo.
% Package: AstroUtil.binary
% Description: GUI Eclipsing Binary light-curve demo.
% Input  : null
% Output : null
% Tested : Matlab 5.3
%     By : Eran O. Ofek                    Aug 2001
%    URL : http://weizmann.ac.il/home/eofek/matlab/
% Example: eb_demo
% Reliable: 2
%------------------------------------------------------------------------------

RAD = 180./pi;

import AstroUtil.binary.*

global L1;
global L2;
global L;
global M1;
global M2;
global R1;
global R2;
global T;
global E;
global Q;
global A;
global Omega;
global W;
global Inc;
global LimbF;
global LD1;
global LD2;
global Ref1;
global Ref2;


% set default values
if (nargin==0)
   L1    = 100;
   L2    = 10;
   L     = L2./L1;
   M1    = 1.0;
   M2    = 0.3;
   R1    = 0.01;
   R2    = 0.005;
   T     = 0;
   E     = 0;
   Q     = 0.1;
   A     = 0.1;
   Omega = 0;
   W     = 0;
   Inc   = 90;
   LimbF = 'limb_darkening';
   LD1   = 0.0;
   LD2   = 0.0;
   Ref1  = 0.0;
   Ref2  = 0.0;
end

%VecAll = [L1, L2, L, M1, M2, R1, R2, T, E, Q, A, Omega, W, Inc, LimbF, LD1, LD2, Ref1, Ref2];


load eb_demo


if (nargin==0)
   
   Xpos   = 40.0;
   Ypos   = 330.0;
   Xsize  = 138;
   Ysize  = 12;
   XsizeE = 35;
   YsizeE = 18;
   DY     = 35.0;
   Dt     = 15.0;

   close(gcf);
   close(gcf);
   %figure(1);   
   h0 = figure('Color',[0.8 0.8 0.8], ...
	   'Colormap',mat0, ...
   	'FileName','C:\home\eran\matlab\new_lap\eb_demo.m', ...
	   'PaperPosition',[18 180 576 432], ...
	   'PaperUnits','points', ...
	   'Position',[661 179 270 400], ...
	   'Tag','Fig1', ...
	   'ToolBar','none');
   
   %--- title ---
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos Ypos+1.8.*Dt 130 10], ...
      'Style','text', ...
      'String','EB - demo', ...
      'Tag','StaticText1');
   
   
   %--- Inclination ---
   h_Inc = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ...
	   'Callback','eb_demo(''Inclination'',gcbo);', ...
	   'CreateFcn','', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos Ypos Xsize Ysize], ...
	   'Style','slider', ...
	   'Tag','Slider1', ...
	   'UserData','[ ]', ...
      'Value',1);
   
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos+0.0.*Xsize Ypos-Dt 20 12], ...
      'Style','text', ...
      'String','70', ...
      'Tag','StaticText1');
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos+0.425.*Xsize Ypos-Dt 20 12], ...
      'Style','text', ...
      'String','80', ...
      'Tag','StaticText1');
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos+0.85.*Xsize Ypos-Dt 20 12], ...
      'Style','text', ...
      'String','90', ...
      'Tag','StaticText1');
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos-20 Ypos 15 15], ...
      'Style','text', ...
      'String','i', ...
      'Tag','StaticText1');

   %--- longitude of periastron --- 
   Ypos = Ypos - DY;
   h_W = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ...
	   'Callback','eb_demo(''omega'',gcbo);', ...
	   'CreateFcn','', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos Ypos Xsize Ysize], ...
	   'Style','slider', ...
	   'Tag','Slider2', ...
	   'UserData','[ ]', ...
      'Value',0);
   
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos+0.*Xsize Ypos-Dt 20 12], ...
      'Style','text', ...
      'String','0', ...
      'Tag','StaticText1');
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos+0.425.*Xsize Ypos-Dt 20 12], ...
      'Style','text', ...
      'String','90', ...
      'Tag','StaticText1');
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos+0.85.*Xsize Ypos-Dt 23 12], ...
      'Style','text', ...
      'String','180', ...
      'Tag','StaticText1');
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos-20 Ypos 15 15], ...
      'Style','text', ...
      'String','w', ...
      'Tag','StaticText1');


   %--- eccentricity --- 
   Ypos = Ypos - DY;
   h_W = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ...
	   'Callback','eb_demo(''Ecc'',gcbo);', ...
	   'CreateFcn','', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos Ypos Xsize Ysize], ...
	   'Style','slider', ...
	   'Tag','Slider2', ...
	   'UserData','[ ]', ...
      'Value',0);
   
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos+0.*Xsize Ypos-Dt 22 12], ...
      'Style','text', ...
      'String','0.0', ...
      'Tag','StaticText1');
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos+0.425.*Xsize Ypos-Dt 22 12], ...
      'Style','text', ...
      'String','0.4', ...
      'Tag','StaticText1');
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos+0.85.*Xsize Ypos-Dt 22 12], ...
      'Style','text', ...
      'String','0.8', ...
      'Tag','StaticText1');
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos-20 Ypos 15 15], ...
      'Style','text', ...
      'String','e', ...
      'Tag','StaticText1');

   %--- R1 ---
   Ypos = Ypos - DY;
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'BackgroundColor',[1 1 1], ...
	   'Callback','eb_demo(''R1'',gcbo);', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos Ypos XsizeE YsizeE], ...
	   'String',num2str(R1), ...
	   'Style','edit', ...
	   'Tag','EditText1');
   
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos-20 Ypos 18 12], ...
      'Style','text', ...
      'String','R1', ...
      'Tag','StaticText1');
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos+XsizeE+1 Ypos 18 12], ...
      'Style','text', ...
      'String','au', ...
      'Tag','StaticText1');


   %--- R2 ---
   Ypos = Ypos - 0.*DY;
   Xoff = 90;
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'BackgroundColor',[1 1 1], ...
	   'Callback','eb_demo(''R2'',gcbo);', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos+Xoff Ypos XsizeE YsizeE], ...
	   'String',num2str(R2), ...
	   'Style','edit', ...
	   'Tag','EditText1');
   
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos+Xoff-20 Ypos 18 12], ...
      'Style','text', ...
      'String','R2', ...
      'Tag','StaticText1');
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos+XsizeE+Xoff+1 Ypos 18 12], ...
      'Style','text', ...
      'String','au', ...
      'Tag','StaticText1');
   
   %--- q ---
   Ypos = Ypos - DY;
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'BackgroundColor',[1 1 1], ...
	   'Callback','eb_demo(''Q'',gcbo);', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos Ypos XsizeE YsizeE], ...
	   'String',num2str(Q), ...
	   'Style','edit', ...
	   'Tag','EditText1');
   
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos-20 Ypos 18 12], ...
      'Style','text', ...
      'String','q', ...
      'Tag','StaticText1');
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos+XsizeE+1 Ypos 18 12], ...
      'Style','text', ...
      'String','au', ...
      'Tag','StaticText1');
   
   
   %--- L2/L1 ---
   Ypos = Ypos - DY;
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'BackgroundColor',[1 1 1], ...
	   'Callback','eb_demo(''L'',gcbo);', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos Ypos XsizeE YsizeE], ...
	   'String',num2str(L), ...
	   'Style','edit', ...
	   'Tag','EditText1');
   
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos-35 Ypos 35 12], ...
      'Style','text', ...
      'String','L2/L1', ...
      'Tag','StaticText1');
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos+XsizeE+1 Ypos 28 12], ...
      'Style','text', ...
      'String','', ...
      'Tag','StaticText1');
   
   %--- LD1 ---
   Ypos = Ypos - DY;
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'BackgroundColor',[1 1 1], ...
	   'Callback','eb_demo(''LD1'',gcbo);', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos Ypos XsizeE YsizeE], ...
	   'String',num2str(LD1), ...
	   'Style','edit', ...
	   'Tag','EditText1');
   
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos-25 Ypos 25 12], ...
      'Style','text', ...
      'String','LD1', ...
      'Tag','StaticText1');
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos+XsizeE+1 Ypos 25 12], ...
      'Style','text', ...
      'String','', ...
      'Tag','StaticText1');
   
   
   %--- LD2 ---
   Ypos = Ypos - 0.*DY;
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'BackgroundColor',[1 1 1], ...
	   'Callback','eb_demo(''LD2'',gcbo);', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos+Xoff Ypos XsizeE YsizeE], ...
	   'String',num2str(LD2), ...
	   'Style','edit', ...
	   'Tag','EditText1');
   
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos+Xoff-25 Ypos 25 12], ...
      'Style','text', ...
      'String','LD2', ...
      'Tag','StaticText1');
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos+Xoff+XsizeE+1 Ypos 25 12], ...
      'Style','text', ...
      'String','', ...
      'Tag','StaticText1');
   
   
   %--- Ref1 ---
   Ypos = Ypos - DY;
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'BackgroundColor',[1 1 1], ...
	   'Callback','eb_demo(''Ref1'',gcbo);', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos Ypos XsizeE YsizeE], ...
	   'String',num2str(Ref1), ...
	   'Style','edit', ...
	   'Tag','EditText1');
   
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos-27 Ypos 27 12], ...
      'Style','text', ...
      'String','Ref1', ...
      'Tag','StaticText1');
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos+XsizeE+1 Ypos 12 12], ...
      'Style','text', ...
      'String','', ...
      'Tag','StaticText1');
   
   
   %--- Ref2 ---
   Ypos = Ypos - 0.*DY;
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'BackgroundColor',[1 1 1], ...
	   'Callback','eb_demo(''Ref2'',gcbo);', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos+Xoff Ypos XsizeE YsizeE], ...
	   'String',num2str(Ref2), ...
	   'Style','edit', ...
	   'Tag','EditText1');
   
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos+Xoff-27 Ypos 27 12], ...
      'Style','text', ...
      'String','Ref2', ...
      'Tag','StaticText1');
   h1 = uicontrol('Parent',h0, ...
	   'Units','points', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos+Xoff+XsizeE+1 Ypos 12 12], ...
      'Style','text', ...
      'String','', ...
      'Tag','StaticText1');
   

   
   %--- Exit ---  
   Ypos = Ypos - 1.3.*DY;
   h1 = uicontrol('Parent',h0, ...
   	'Units','points', ...
	   'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ...
   	'Callback','eb_demo(''Exit'',gcbo);', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos-20 Ypos 60 20], ...
	   'String','Exit', ...
	   'Tag','Pushbutton1');
   
   %--- Hold on ---
   Ypos = Ypos - 0.*DY;
   h1 = uicontrol('Parent',h0, ...
   	'Units','points', ...
	   'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ...
   	'Callback','eb_demo(''holdon'',gcbo);', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos+60 Ypos 45 20], ...
	   'String','Hold On', ...
	   'Tag','Pushbutton1');
   
   %--- Hold off ---  
   Ypos = Ypos - 0.*DY;
   h1 = uicontrol('Parent',h0, ...
   	'Units','points', ...
	   'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ...
   	'Callback','eb_demo(''holdoff'',gcbo);', ...
	   'ListboxTop',0, ...
	   'Position',[Xpos+110 Ypos 45 20], ...
	   'String','Hold Off', ...
	   'Tag','Pushbutton1');
   

   figure(2);
   LD1p = {'Milne',LD1};
   LD2p = {'Milne',LD2};

   plot_eb_lc_ph([1 L],[M1 M2],[R1 R2], ...
                 [T Q E Omega./RAD W./RAD Inc./RAD], ...
                 LimbF,LD1p,LD2p,Ref1,Ref2);

   if nargout > 0, fig = h0; end


else
   figure(2);
   LD1p = {'Milne',LD1};
   LD2p = {'Milne',LD2};

   switch Keyword
    case 'Inclination'
       Inc = get(Handle,'Value');
       Inc = 70 + Inc.*20;
       
       plot_eb_lc_ph([1 L],[M1 M2],[R1 R2], ...
                     [T Q E Omega./RAD W./RAD Inc./RAD], ...
                     LimbF,LD1p,LD2p,Ref1,Ref2);
    case 'omega'
       W   = get(Handle,'Value');
       W   = W.*180;

       plot_eb_lc_ph([1 L],[M1 M2],[R1 R2], ...
                     [T Q E Omega./RAD W./RAD Inc./RAD], ...
                     LimbF,LD1p,LD2p,Ref1,Ref2);
    case 'Ecc'
       E   = get(Handle,'Value');
       E   = E.*0.8;

       plot_eb_lc_ph([1 L],[M1 M2],[R1 R2], ...
                     [T Q E Omega./RAD W./RAD Inc./RAD], ...
                     LimbF,LD1p,LD2p,Ref1,Ref2);
    case 'R1'
       R1  = get(Handle,'String');
       R1  = str2num(R1);

       plot_eb_lc_ph([1 L],[M1 M2],[R1 R2], ...
                     [T Q E Omega./RAD W./RAD Inc./RAD], ...
                     LimbF,LD1p,LD2p,Ref1,Ref2);
    case 'R2'
       R2  = get(Handle,'String');
       R2  = str2num(R2);

       plot_eb_lc_ph([1 L],[M1 M2],[R1 R2], ...
                     [T Q E Omega./RAD W./RAD Inc./RAD], ...
                     LimbF,LD1p,LD2p,Ref1,Ref2);
    case 'Q'
       Q   = get(Handle,'String');
       Q   = str2num(Q);

       plot_eb_lc_ph([1 L],[M1 M2],[R1 R2], ...
                     [T Q E Omega./RAD W./RAD Inc./RAD], ...
                     LimbF,LD1p,LD2p,Ref1,Ref2);
    case 'L'
       L   = get(Handle,'String');
       L   = str2num(L);

       plot_eb_lc_ph([1 L],[M1 M2],[R1 R2], ...
                     [T Q E Omega./RAD W./RAD Inc./RAD], ...
                     LimbF,LD1p,LD2p,Ref1,Ref2);
    case 'LD1'
       LD1 = get(Handle,'String');
       LD1 = str2num(LD1);

       plot_eb_lc_ph([1 L],[M1 M2],[R1 R2], ...
                     [T Q E Omega./RAD W./RAD Inc./RAD], ...
                     LimbF,LD1p,LD2p,Ref1,Ref2);
    case 'LD2'
       LD2 = get(Handle,'String');
       LD2 = str2num(LD2);

       plot_eb_lc_ph([1 L],[M1 M2],[R1 R2], ...
                     [T Q E Omega./RAD W./RAD Inc./RAD], ...
                     LimbF,LD1p,LD2p,Ref1,Ref2);
    case 'Ref1'
       Ref1= get(Handle,'String');
       Ref1= str2num(Ref1);

       plot_eb_lc_ph([1 L],[M1 M2],[R1 R2], ...
                     [T Q E Omega./RAD W./RAD Inc./RAD], ...
                     LimbF,LD1p,LD2p,Ref1,Ref2);
    case 'Ref2'
       Ref2= get(Handle,'String');
       Ref2= str2num(Ref2);

       plot_eb_lc_ph([1 L],[M1 M2],[R1 R2], ...
                     [T Q E Omega./RAD W./RAD Inc./RAD], ...
                     LimbF,LD1p,LD2p,Ref1,Ref2);
    case 'Exit'
       close(1);
       close(2);
    case 'holdon'
       hold on;
    case 'holdoff'
       hold off;
       
    otherwise
       error('Unknown Keyword type');
   end
end
