function h_axes=create_Ctrlfig(programme,h,ds,m,t,e,method)
% create_Ctrlfig   Creates the Control figure for the CRP Toolbox
%    Used by CRP Toolbox

% Copyright (c) 1998-2004 by AMRON
% Norbert Marwan, Potsdam University, Germany
% http://www.agnld.uni-potsdam.de
%
% $Date$
% $Revision$
%
% $Log$
% Revision 4.7  2004/11/10 07:04:29  marwan
% initial import
%
%
% This program is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License
% as published by the Free Software Foundation; either version 2
% of the License, or any later version.

global props

  scr=get(0,'ScreenSize'); 
  h9=figure('Tag','CRPFig',...			% Control Figure
            'Position',[5*scr(3)/8+10 scr(4)/8 1*scr(3)/6 3*scr(4)/4 ],...
	    'Color',props.window.Color,...
            'NumberTitle','off',...
	    'Name',['Control (' h ')'],...
	    'MenuBar','None',...
	    'DeleteFcn',[programme,' handlevisON'],...
	    'BusyAction','cancel',...
	    'Resize','Off');
  set(h9,props.window,'Units','Norm')

  h0=uicontrol(props.frame, ... % Frame Embedding
            'Units','Normalized',...
	    'Position',[.1 .525 .8 .445]);

  h0=uicontrol(props.text,...	% Text Embedding
            'Units','Normalized', ...
	    'FontAngle','italic', ...
	    'Position',[.12 .939 .6 .02], ...
	    'String','Embedding');
  h1=get(h0,'Extent'); h2=get(h0,'Position'); set(h0,'Position',[h2(1) h2(2) h1(3) h1(4)])

  h0=uicontrol(props.text,...		% Text Dimension
            'Units','Normalized',...
	    'Tag','Dimtext',...
	    'String','Dimension:',...
	    'Position',[.16 .895 .35 .02]);
  h1=get(h0,'Extent'); h2=get(h0,'Position'); set(h0,'Position',[h2(1) h2(2) h2(3) h1(4)])
  if method==7, set(h0,'Enable','Off'); end

  h0=uicontrol(props.popup,...		% Input Dimension
            'Units','Normalized',...
	    'Tag','Dim',...
	    'String','1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20',...
	    'Position',[.58 .9 .249 .026], ...
	    'Value',m,...
	    'UserData', ds,...
	    'Callback',[programme,' fitdim'],...
	    'ToolTip','Select the embedding dimension.');
  h1=get(h0,'Extent'); h2=get(h0,'Position'); set(h0,'Position',[h2(1) h2(2) h2(3) h1(4)])
  if method==7, set(h0,'Enable','Off'); end

  h0=uicontrol(props.text,...		% Text Delay
            'Units','Normalized',...
	    'Tag','Delaytext',...
	    'String','Delay:',...
	    'Position',[.16 .847 .35 .02]);
  h1=get(h0,'Extent'); h2=get(h0,'Position'); set(h0,'Position',[h2(1) h2(2) h2(3) h1(4)])
  if method==7, set(h0,'Enable','Off'); end

  h0=uicontrol(props.edit,...		% Input Delay
            'Units','Normalized',...
	    'Tag','Delay',...
	    'String',t,...
	    'Position',[.58 .85 .249 .026],...
	    'ToolTip','Insert the embedding delay time.');
  h1=get(h0,'Extent'); h2=get(h0,'Position'); set(h0,'Position',[h2(1) h2(2) h2(3) h1(4)])
  if method==7, set(h0,'Enable','Off'); end

  h0=uicontrol(props.text,...		% Text Vector Switching
            'Units','Normalized',...
	    'String','Vector Switching:',...
	    'Position',[.16 .8 .6 .02]);
  h1=get(h0,'Extent'); h2=get(h0,'Position'); set(h0,'Position',[h2(1) h2(2) h2(3) h1(4)])

  for i=1:5, for j=1:4				% Input Vector Switching
     h0 = uicontrol(props.button,...
            'Units','normalized', ...
	    'Callback',[programme,' vectorswitch'], ...
	    'Position',[.18+(j-1)*0.167 0.765-(i-1)*0.034 .14 0.028], ...
	    'String',(i-1)*4+j, ...
	    'ToolTip','Switch this vector.',...
	    'Tag',['DimShift' num2str((i-1)*4+j)]);
     h1=get(h0,'Extent'); h2=get(h0,'Position'); set(h0,'Position',[h2(1) h2(2) h2(3) h1(4)])
  end, end

  for i=1:20
     if i>m, set(findobj('Tag',['DimShift' num2str(i)]), 'Enable', 'off');				
       else, set(findobj('Tag',['DimShift' num2str(i)]), 'Enable', 'on'); end
  end
  
  h0=uicontrol(props.text,...		% Text Copyright
            'Units','Normalized',...
	    'HorizontalAlignment','center',...
	    'Position',[.15 .534 .7 .06]);
  h2=textwrap(h0,{'© AGNLD','University of Potsdam','1998-2004'});
  set(h0,'String',h2)
  h1=get(h0,'Extent'); h2=get(h0,'Position'); set(h0,'Position',[h2(1) h2(2) h2(3) h1(4)])

  h0=uicontrol(props.frame, ...  % Frame Neighbourhood
            'Units','Normalized',...
	    'Position',[.1 .279 .8 .22]);

  h0=uicontrol(props.text,...		% Text Neighbourhood
            'Units','Normalized',...
	    'FontAngle','italic', ...
	    'String','Neighbourhood',...
	    'Position',[.12 .466 .6 .02]);
  h1=get(h0,'Extent'); h2=get(h0,'Position'); set(h0,'Position',[h2(1) h2(2) h1(3) h1(4)])

  h0=uicontrol(props.checkbox, ...		% Button Unthresholded
            'Units','Normalized',...
	    'Position',[.16 .415 .51 .032], ...
	    'String','Unthresholded', ...
	    'CallBack',[programme,' unthresh'],...
	    'Tag','Unthresh',...
	    'ToolTip','Switch between thresholded and unthresholded CRP.' );

  if method==9, set(h0,'Value',1); end
  if method==7 | method==8, set(h0,'Enable','Off'); end

  h1=uicontrol(props.popup, ...		% Button Unthresholded Scale
            'Units','Normalized',...
	    'Position',[.69 .415 .14 .032], ...
	    'String','1|1/2|1/4|1/6|1/8', ...
	    'Value',1,...
	    'CallBack',[programme,' log'],...
	    'Enable','off',...
	    'Tag','Log',...
	    'ToolTip','Switch between various scaled CRP.' );

  if method==9, set(h1,'Enable','On'); end


  h2=uicontrol(props.popup,...		% Input Neighbourhood Method
            'Units','Normalized',...
	    'String','Maximum Norm|Euclidean Norm|Minimum Norm|Normalized Norm|Fixed Amount|Interdependent|Order Matrix|Order Pattern',...
	    'Position',[.16 .363 .67 .032],...
	    'Tag','Method',...
	    'CallBack',[programme,' unthresh'],...
	    'ToolTip','Select the method of finding neighbours.');

  if method==9, set(h2,'Enable','Off'); else, set(h2,'Value',method); end
  
  h0=uicontrol(props.text,...		% Text Threshold
            'Units','Normalized',...
	    'Tag','Sizetext',...
	    'String','Threshold:',...
	    'Position',[.16 .311 .35 .02]);
  h1=get(h0,'Extent'); h2=get(h0,'Position'); set(h0,'Position',[h2(1) h2(2) h2(3) h1(4)])

  if method==9 | method==8, set(h0,'Enable','Off'); end


  h0=uicontrol(props.edit,...		% Input Threshold
            'Units','Normalized',...
	    'Tag','Size',...
	    'Position',[.58 .315 .249 .026],...
	    'String',e,...
	    'ToolTip','Insert the size of neighbourhood.' );
  h1=get(h0,'Extent'); h2=get(h0,'Position'); set(h0,'Position',[h2(1) h2(2) h2(3) h1(4)])

  if method==9 | method==8, set(h0,'Enable','Off'); end

  if ~isunix
    h0=uicontrol(props.frame, ... % Frame Embedding
            'Units','Normalized',...
	    'Position',[.1 .21 .8 .045]);
  end

  h0=uicontrol(props.checkbox, ...		% Checkbox Stretch Plot
            'Units','Normalized',...
	    'Position',[.1 .21 .8 .045], ...
	    'String','Streched Plot', ...
	    'Tag','Stretch',...
	    'CallBack',[programme,' stretch'],...
	    'Value',1,...
	    'ToolTip','Streches the plotted CRP to a squared plot.' );

  h0=uicontrol(props.button, ...		% Button Store Matrix
            'Units','Normalized',...
	    'Position',[.1 .15 .38 .045], ...
	    'String','Store Matrix', ...
	    'Tag','Store',...
	    'CallBack',[programme,' store'],...
	    'Value',1,...
	    'ToolTip','Stores the CRP matrix into variable X in the workspace.' );

  h0=uicontrol(props.button,...		% Button Help
            'Units','Normalized',...
	    'String','Help',...
	    'Position',[.52 .15 .38 .045],...
	    'Tag','Help',...
	    'Callback',['helpwin ',programme],...
	    'ToolTip','Opens the helpwindow.');

  h0=uicontrol(props.button,...		% Button Apply
            'Units','Normalized',...
	    'String','Apply',...
	    'Position',[.1 .09 .8 .045],...
	    'Tag','Apply',...
	    'Callback',[programme,' compute'],...
	    'ToolTip','Starts the computation - be patient.');

  h0=uicontrol(props.button,...		% Button Close
            'Units','Normalized',...
	    'String','Close',...
	    'Position',[.1 .03 .8 .045],...
	    'Tag','Close',...
	    'BusyAction','cancel',...
	    'Callback',[programme,' close'],...
	    'ToolTip','Closes CRP windows.');

  set(h9, 'HandleVis','CallBack')
