function hratp = ratpbtns(figNumber)
% Function: ratpbtns.m
% 
% Usage: hratp = ratpbtns(figNumber);
% 
% Description:
%    Initializes the rational polynomial Window
%    Handles and graphics elements.
%    Returns a vector to those elements.
%
% Version SWD970709
%
% Author(s): Scott W. Doebling, doebling@lanl.gov
%
% Institution: Los Alamos National Laboratory, ESA-EA
%
% Copyright (c) 1996-1997, The Regents of the University
%     	of California.


%====================================
% Initialize the buttons
%====================================
top=.95;
left=.84;
btnwd=.15;
btnht=.06;
spacing=.01;

%%====================================
%% For the Rational Polynomial window
%%====================================
%====================================
% Set up the console frame
%=====================================
frmborder=0.01;
ypos=.05-frmborder;
frmpos=[left-frmborder ypos btnwd+2*frmborder .9+2*frmborder];
hratp(1)=uicontrol(figNumber, ...
        'Style','Frame', ...
        'Position',frmpos, ...
        'BackgroundColor',[.5 .5 .5]);


%==================================
% Set up buttons
%==================================
%
% Plot tools button
%
btnnum=1;
ypos=top-(btnnum-1)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd btnht];
hratp(2)=uicontrol(figNumber, ...
      'style','push', ...
      'position',btnpos, ...
      'string','Plot Tools', ...
      'callback',['eval(get(hplttl(11),''call'')),',...
		'set(hplttl(1),''visible'',''on''), figure(hplttl(1))']);


%
%  hratp([3 4 5]) are defunct
%

hratp(3) = uicontrol('position',[0 0 eps eps]);
hratp(4) = uicontrol('position',[0 0 eps eps]);
hratp(5) = uicontrol('position',[0 0 eps eps]);

%
%  sliders
%

%
% Lower frequency
%
hratp(6) = uicontrol(figNumber, ...
        'style','slider', ...
        'pos',[.13 .01 .2 0.04], ...
        'back','w', ...
        'call',['f1_t=get(onHndlVector(6),''value'');',...
      '[f1,onHndlVector(26:27)] = slidfreq(f1_t,onHndlVector(6),',...
		    'onHndlVector(26:27),onHndlVector(25),ymaxm,yminm,lnst(2,:),lnco(2,:));',...    
       'set(onHndlVector(8),''string'',num2str(f1));',...
		'nfitbin = floor(f2/df)-floor(f1/df)+1; set(onHndlVector(34),''string'',num2str(nfitbin)),',...
		' hline(2) = onHndlVector(26);',...
		' rpbinfit']);
		
hratp(7)=uicontrol(figNumber, ...
        'style','text', ...
        'pos',[.13 .05 .1 .04], ...
        'string','Lower');
     
hratp(8)=uicontrol(figNumber, ...
	'style','edit', ...
	'pos',[.23 .05 .1 .04], ...
	'string','fminm', ...
   'back','w', ...
   'fore','r', ...
	'callback',['f1_t=str2num(get(onHndlVector(8),''string''));', ...
		'[f1,onHndlVector(26:27)] = slidfreq(f1_t,onHndlVector(6),',...
		    'onHndlVector(26:27),onHndlVector(25),ymaxm,yminm,lnst(2,:),lnco(2,:));',...    
          'set(onHndlVector(8),''string'',num2str(f1));',...
          'nfitbin = floor(f2/df)-floor(f1/df)+1; set(onHndlVector(34),''string'',num2str(nfitbin)),',...
			 'hline(2) = onHndlVector(26);',...
			 ' rpbinfit']);

%
% Upper frequency
%
hratp(9) = uicontrol(figNumber, ...
        'style','slider', ...
        'pos',[.55 .01 .2 0.04], ...
        'back','w', ...
        'call',['f2_t=get(onHndlVector(9),''value'');',...
      '[f2,onHndlVector(28:29)] = slidfreq(f2_t,onHndlVector(9),',...
		    'onHndlVector(28:29),onHndlVector(25),ymaxm,yminm,lnst(3,:),lnco(3,:));',...    
          'set(onHndlVector(11),''string'',num2str(f2));',...
	       'nfitbin = floor(f2/df)-floor(f1/df)+1; set(onHndlVector(34),''string'',num2str(nfitbin)),',...
		    'hline(3) = onHndlVector(28);',...
		    'rpbinfit']);


hratp(10)=uicontrol(figNumber, ...
        'style','text', ...
        'pos',[.55 .05 .1 .04], ...
        'string','upper');
hratp(11)=uicontrol(figNumber, ...
	'style','edit', ...
   'back','w', ...
   'fore','b', ...
	'pos',[.65 .05 .1 .04], ...
   'callback',['f2_t=str2num(get(onHndlVector(11),''string''));', ...
		'[f2,onHndlVector(28:29)] = slidfreq(f2_t,onHndlVector(9),',...
		    'onHndlVector(28:29),onHndlVector(25),ymaxm,yminm,lnst(3,:),lnco(3,:));',...    
          'set(onHndlVector(11),''string'',num2str(f2));',...
          'nfitbin = floor(f2/df)-floor(f1/df)+1; set(onHndlVector(34),''string'',num2str(nfitbin)),',...
			 'hline(3) = onHndlVector(28);',...
			 ' rpbinfit']);

%
%  hratp(12) is a dummy
%

hratp(12) = uicontrol('position',[0 0 eps eps]);

%
% calculate button
%
btnnum=5;
ypos=top-(btnnum-1)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd btnht];
hratp(13)=uicontrol(figNumber, ...
      'style','pushbutton', ...
      'position',btnpos, ...
      'string','Calculate', ...
      'callback','runRP');
%
% Number of modes to use in fit
%
btnnum=6;
ypos=top-(btnnum-1)*(btnht+spacing);
btnpos=[left ypos-btnht-spacing btnwd btnht];
hratp(14)=uicontrol(figNumber, ...
      'style','text', ...
      'position',btnpos, ...
      'string','Num. Modes');

btnnum=7;
ypos=top-(btnnum-1)*(btnht+spacing)+spacing;
btnpos=[left ypos-btnht-spacing btnwd btnht];
hratp(15)=uicontrol(figNumber, ...
      'style','edit', ...
      'position',btnpos, ...
      'string','1', ...
      'back','white', ...
      'callback','nummod=str2num(get(onHndlVector(15),''string''));');
%
% Extra terms
%
btnnum=8;
ypos=top-(btnnum-1)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd btnht];
hratp(16)=uicontrol(figNumber, ...
      'style','text', ...
      'position',btnpos, ...
      'string','Extra Terms');

btnnum=9;
ypos=top-(btnnum-1)*(btnht+spacing)+spacing;
btnpos=[left ypos-btnht btnwd btnht];
hratp(17)=uicontrol(figNumber, ...
      'style','edit', ...
      'position',btnpos, ...
      'string','4', ...
      'back','white', ...
      'callback','numextra=str2num(get(onHndlVector(17),''string''));');
%
% hratp(19:24) are defunct
%

hratp(19) = uicontrol('position',[0 0 eps eps]);
hratp(20) = uicontrol('position',[0 0 eps eps]);
hratp(21)= uicontrol('position',[0 0 eps eps]);
hratp(22) = uicontrol('position',[0 0 eps eps]);
hratp(23)=uicontrol('position',[0 0 eps eps]);
hratp(24)=uicontrol('position',[0 0 eps eps]);

%====================================
% Set up the axes
%====================================

hratp(25) = axes('position',[.1 .2 .7 .7]);

%====================================
% Set up the cursors
%====================================

hratp(26) = line([0 0],[0 0]);
hratp(27) = text(0,0,'');
hratp(28) = line([0 0],[0 0]);
hratp(29) = text(0,0,'');

%
%  Mouse-based cursor position
%

%  Lower Freq.

hratp(30)=uicontrol(figNumber, ...
        'style','pushbutton', ...
        'pos',[.13 .10 .2 .04], ...
	'string','Use Mouse', ...
	'callback',['[f1_t,temp] = ginput(1);',...
      '[f1,onHndlVector(26:27)] = slidfreq(f1_t,onHndlVector(6),',...
		    'onHndlVector(26:27),onHndlVector(25),ymaxm,yminm,lnst(2,:),lnco(2,:));',...    
       'set(onHndlVector(8),''string'',num2str(f1));',...
		'nfitbin = floor(f2/df)-floor(f1/df)+1; set(onHndlVector(34),''string'',num2str(nfitbin)),',...
		' hline(2) = onHndlVector(26);',...
		' rpbinfit']);



%  Upper Freq.

hratp(31)=uicontrol(figNumber, ...
        'style','pushbutton', ...
        'pos',[.55 .10 .2 .04], ...
	'string','Use Mouse', ...
	'callback',['[f2_t,temp] = ginput(1);',...
			'[f2,onHndlVector(28:29)] = slidfreq(f2_t,onHndlVector(9),',...
		    'onHndlVector(28:29),onHndlVector(25),ymaxm,yminm,lnst(3,:),lnco(3,:));',...    
          'set(onHndlVector(11),''string'',num2str(f2));',...
	       'nfitbin = floor(f2/df)-floor(f1/df)+1; set(onHndlVector(34),''string'',num2str(nfitbin)),',...
		    'hline(3) = onHndlVector(28);',...
		    'rpbinfit']);



%
% Bins to Fit button
%
btnnum=10;
ypos=top-(btnnum-1)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd btnht];
hratp(32)=uicontrol(figNumber, ...
      'style','pushbutton', ...
      'position',btnpos, ...
      'string','Define Fit Bins', ...
      'callback','rpbinfit');		


btnnum=11;
ypos=top-(btnnum-1)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd*2/3 btnht];
hratp(33)=uicontrol(figNumber, ...
      'style','text', ...
      'position',btnpos, ...
	'string','# bins');

btnnum=11;
ypos=top-(btnnum-1)*(btnht+spacing);
btnpos=[left+btnwd*2/3 ypos-btnht btnwd/3 btnht];
hratp(34)=uicontrol(figNumber, ...
      'style','edit', ...
      'position',btnpos, ...
	'back','w',...
      'string','nlines',...
	'callback',['nfitbin_t=str2num(get(onHndlVector(34),''string''));', ...
		' if isempty(nfitbin_t), disp(''Invalid Number of Bins''),',...
  		'    set(onHndlVector(34),''string'',num2str(nfitbin)),',...
		' elseif nfitbin_t > f2/df-f1/df+1,',...
		'    nfitbin = floor(f2/df)-floor(f1/df)+1;',...
		'    set(onHndlVector(34),''string'',num2str(nfitbin)),',...
		' elseif nfitbin_t < 0, disp(''Invalid Number of Bins''),',...
  		'    set(onHndlVector(34),''string'',num2str(nfitbin)),',...
		' else,',...
		'    nfitbin = nfitbin_t;',...
      ' end,']);	
%
%  Statistical Analysis Setup Button
%

btnnum=12;
ypos=top-(btnnum-1)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd btnht];
hratp(18)=uicontrol(figNumber, ...
      'style','pushbutton', ...
      'position',btnpos, ...
      'string','Statistical Analysis', ...
      'callback',['set(hmctl(1),''visible'',''on''),',...
         'figure(hmctl(1)),']);

	
set(hratp,'visible','off')

return