function ratpwindow
%
%  Name:  ratpwindow.m
%
%  Usage:  ratpwindow.m
%
%  This m-file sets up the window to do
%  a rational polynomial fit to the FRF's 
%

%  Version SWD970823
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This matlab source code was originally     %
% developed as part of "DIAMOND" at          %
% Los Alamos National Laboratory. It may     %
% be copied, modified, and distributed in    %
% any form, provided:                        %
%  a) This notice accompanies the files and  %
%     appears near the top of all source     %
%     code files.                            %
%  b) No payment or commercial services are  %
%     received in exchange for the code.     %
%                                            %
% Original copyright is reserved by the      %
% Regents of the University of California,   %
% in addition to Scott W. Doebling, Phillip  %
% J. Cornwell, Erik G. Straser, and Charles  %
% R. Farrar.                                 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

global HANDLES DISPLAY DATA MODES iaxesvec indsvec iaxes inds

%
% Activate the appropriate handles
%

hideallbtns
showall(HANDLES.hratpb)

%  If display parameters are not defined, define them

if isempty(DISPLAY),
   DISPLAY{1}.specfun{1} = 'FRF';
   DISPLAY{1}.displayfun{1} = 'SISO';
   DISPLAY{1}.iyscale  = 'MAG';
   DISPLAY{1}.iylog = 1;
   DISPLAY{1}.idatafile{1} = 1;
   DISPLAY{1}.iavg{1} = 1;   % Number of the average to display
   DISPLAY{1}.lnst{1} = '- ';
   DISPLAY{1}.lnco{1} = 'y';
   DISPLAY{1}.marker{1} = 'none';
   DISPLAY{1}.xlim = [DATA{1}.cf - DATA{1}.sp/2 , DATA{1}.cf + DATA{1}.sp/2];
   DISPLAY{1}.iresp{1} = 1;
   DISPLAY{1}.iref{1} = 1;
   DISPLAY{1}.lnlab{1} = 'Primary Data';
   
end

DISPLAY{1}.hcursor{1} = 1;
DISPLAY{1}.hcursor{2} = 1;
DISPLAY{1}.haxes = HANDLES.hratpb(25);
DISPLAY{1}.hlegax = [];
DISPLAY{1}.ioverlay = 0;  % 

DISPLAY{1}.curslnco{1} = 'r';
DISPLAY{1}.curslnco{2} = 'b';


%
%  Make the Initial Plot
%

indsvec = 1; % Only 1 line is visible on this plot
iaxesvec = 1; % Only 1 axis is visible 

iaxes = 1;   % Default axis is number 1
inds = 1;    % Default plot line is number 1

defspecdatavec(1)  % Define the spectral data vector in DISPLAY

%  Set initial cursor values

DISPLAY{1}.cursfreq{1} = DISPLAY{1}.xvec((end-1)*0.25);
DISPLAY{1}.cursfreq{2} = DISPLAY{1}.xvec((end-1)*0.75);
DISPLAY{1}.dx = DISPLAY{1}.xvec(2) - DISPLAY{1}.xvec(1);

defdisplay(1)      % Apply the display function and the yscale selection to the spectral data vector in DISPLAY
plotdisplay(1)      % Plot the data in the DISPLAY global variable in the display window

%  Configure plot tools based on DISPLAY characteristics

configplttl(1,1)

%%
%%  CURSOR SETUP
%%

%  Set edit box string for low freq slider

set(HANDLES.hratpb(8),'string',num2str(DISPLAY{iaxes}.cursfreq{1}))

%  Set slider parameters for low freq slider

set(HANDLES.hratpb(6),'max',max(DISPLAY{iaxes}.xvec));
set(HANDLES.hratpb(6),'min',min(DISPLAY{iaxes}.xvec));
set(HANDLES.hratpb(6),'userdata',DISPLAY{iaxes}.xvec);
set(HANDLES.hratpb(6),'sliderstep',[DISPLAY{iaxes}.dx/(max(DISPLAY{iaxes}.xvec)- min(DISPLAY{iaxes}.xvec)) 0.1]);
set(HANDLES.hratpb(6),'value',DISPLAY{iaxes}.cursfreq{1});


%  Set edit box string for high freq slider

set(HANDLES.hratpb(11),'string',num2str(DISPLAY{iaxes}.cursfreq{2}))

%  Set slider parameters for high freq slider

set(HANDLES.hratpb(9),'max',max(DISPLAY{iaxes}.xvec));
set(HANDLES.hratpb(9),'min',min(DISPLAY{iaxes}.xvec));
set(HANDLES.hratpb(9),'userdata',DISPLAY{iaxes}.xvec);
set(HANDLES.hratpb(9),'sliderstep',[DISPLAY{iaxes}.dx/(max(DISPLAY{iaxes}.xvec)- min(DISPLAY{iaxes}.xvec)) 0.1]);
set(HANDLES.hratpb(9),'value',DISPLAY{iaxes}.cursfreq{2});

%  Set number of modes and extra terms

set(HANDLES.hratpb(15),'string','1');
set(HANDLES.hratpb(17),'string','4');


%  Set the default values of the ratp fit parameters

if ~isfield(MODES,'nmodfit'), MODES.nmodfit = 1; end
if ~isfield(MODES,'nkterms'), MODES.nkterms = 4; end

return