function h=converttemp()
% CONVERTTEMP.m--Temperature conversion GUI
%
% h=converttemp();
%
% Creates a GUI to perform temperature conversion between
% Kelvin, Celsius, and Fahrenheit.  Each temperature unit
% is controlled by 3 objects: a radio button, text edit, 
% and a slider.  The edits and sliders allow the user to
% specify the temperature in one set of units.  The value
% of the other edits is automatically updated with the current
% temperature in the appropriate units.  The radio buttons
% control which units the user is working with.  When a button
% is pressed, its corresponding slider appears and the other sliders
% disappear.
%
% Programming notes: This GUI was layed out with GUIDE from 
% V5.3 and then edited manually.  It uses callback functions:
%
%		Tradio.m -- controls radio buttons
%     Tedit.m  -- controls edit windows
%     Tslide.m -- controls sliders
%
% Both Tedit and Tslide synchronize the values and strings for the unit
% corresponding to the callback object.  They then call Tconvert which
% performs the conversions and updates the sliders and edits of the other
% units.
%

%1) Create the figure

h0 = figure('Color',[0.8 0.8 0.8], ...
    'units','normalized',...   %Changed units from points to normalized
	'Position',[0.3896    0.2240    0.5488    0.6797], ...
	'Tag','Fig1', ...
	'ToolBar','none');

h=zeros(3,3); % matrix to store the handles to the 9 objects
%
% UICONTROLS for KELVIN units
%
% Callback functions are passed ID=1 to indicate Kelvin
%
val=273.15; %Initial value = 0 C

% Radio button (KELVIN)
h(1,1) = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'ListboxTop',0, ...
	'Position',[41.28 320.64 75.84 35.52], ...
	'String','Kelvin', ...  %Label the button
	'Style','radiobutton', ...
  'callback','Tradio(1)',... %Call Tradio with ID for these units
  'value',0,...            %make sure it is off
	'Tag','1');
   
% Edit window (KELVIN)
h(2,1) = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[1 1 1], ...
	'ListboxTop',0, ...
	'Position',[41.76000000000001 281.28 74.88 28.8], ...
	'Style','edit', ...
  'string',num2str(val),...  %Convert value to string
  'callback','Tedit(1)',...  %Call Tedit with ID for these units
	'Tag','1');
   
% Slider (KELVIN)
h(3,1) = uicontrol('Parent',h0, ...
	'Units','points', ...
	'ListboxTop',0, ...
	'Position',[58.56 88.31999999999999 41.28 184.32], ...
	'Style','slider', ...
  'callback','Tslide(1)',...  %Call Tslide with ID for these units
  'min',173.15,...		      %Set min & max values == -100 & 100 C
  'max',373.15,...
  'value',val,...             %set value
  'visible','off',...         %since button is off (0), this is invisible
	'Tag','1');

%
% UICONTROLS for CELSIUS units
%
% Callback functions are passed ID=2 to indicate CELSIUS
%

val=0;  %Initial value = 0 C
h(1,2) = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'ListboxTop',0, ...
	'Position',[169.92 320.64 75.84 35.52], ...
	'String','Celsius', ...  %Label the button
	'Style','radiobutton', ...
  'callback','Tradio(2)',...  %Call Tradio with ID for these units
  'value',1,...            %make sure it is ON
	'Tag','2');
   
% Edit window (CELSIUS)
h(2,2) = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[1 1 1], ...
	'ListboxTop',0, ...
	'Position',[170.88 281.28 74.88 28.8], ...
	'Style','edit', ...
  'string',num2str(val),...  %Convert value to string
  'callback','Tedit(2)',...  %Call Tedit with ID for these units
	'Tag','2');
   
% Slider (KELVIN)
h(3,2) = uicontrol('Parent',h0, ...
	'Units','points', ...
	'ListboxTop',0, ...
	'Position',[187.2 88.31999999999999 41.28 184.32], ...
	'Style','slider', ...
  'callback','Tslide(2)',... %Call Tslide with ID for these units
  'min',-100,...             %Set min & max values == -100 & 100 C
  'max',100,...
  'value',val,...            %set value
	'Tag','2');               %ON by default
  
%
% UICONTROLS for FAHRENHEIT units
%
% Callback functions are passed ID=1 to indicate Fahrenheit
%
%Fahrenheit
val=32; %Initial value = 0 C

% Radio buttion (FAHRENHEIT)
h(1,3) = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'ListboxTop',0, ...
	'Position',[293.76 320.64 75.84 35.52], ...
	'String','Fahrenheit', ... %Label the button
	'Style','radiobutton', ...
  'callback','Tradio(3)',... %Call Tradio with ID for these units
  'value',0,...            %make sure it is off
	'Tag','3');
   
% Edit window (FAHRENHEIT)
h(2,3) = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[1 1 1], ...
	'ListboxTop',0, ...
	'Position',[294.72 281.28 74.88 28.8], ...
	'Style','edit', ...
  'string',num2str(val),...  %Convert value to string
  'callback','Tedit(3)',...  %Call Tedit with ID for these units
	'Tag','3');
   
% Slider (FAHRENHEIT)
h(3,3) = uicontrol('Parent',h0, ...
	'Units','points', ...
	'ListboxTop',0, ...
	'Position',[311.04 88.31999999999999 41.28 184.32], ...
	'Style','slider', ...
  'callback','Tslide(3)',...   %Call Tslide with ID for these units
  'min',-148,...               %Set min & max values == -100 & 100 C
  'max',212,...
  'value',val,...              %set value
  'visible','off',...          %since button is off (0), this is invisible
	'Tag','3');

set(h0,'userdata',h);  %Stuff the handle matrix into the figure's userdata
