function converttemp;
%CONVERTTEMP--temperature conversion GUI
%
% converttemp
%
%Typing "converttemp" launches a GUI to perform
%conversions between Kelvin, Celsius, and Farenheitl
%

F=openfig('convertlayout.fig');%open the .fig file which lays out the UIcontrols

val=[273.15, 0, 32]; %Initial value = 273.15K == 0 C == 32 F
vr=[50, 50, 1.8*50];

h=zeros(3,3);%matrix to store handles to controls;

strs=['Kel';'Cel';'Far']; %temp units used to tag controls
strs=lower(strs);%force lowercase


%Radio Buttons
g=findobj(F,'style','radiobutton');%Get the radio buttons

tags=lower(get(g,'tag'));
for j=1:3;
    I=strmatch(strs(j,:),tags);
    h(1,j)=g(I);
    %Set the value to 0 (off) and the callback to Tradio(j)
    set(g(I),'value',0,'callback',['Tradio(',int2str(j),')']);
end
set(h(1,2),'value',1);%Turn celsius on

%Text Boxes
g=findobj(F,'style','edit');%Get the radio buttons

tags=lower(get(g,'tag'));
for j=1:3;
    I=strmatch(strs(j,:),tags);
    h(2,j)=g(I);
    %Set the value to the string representation of val(j) and the callback to Tedit(j)
    set(g(I),'string',num2str(val(j),'%6.2f'),'callback',['Tedit(',int2str(j),')']);
end

%Slider
g=findobj(F,'style','slider');%Get the radio buttons

tags=lower(get(g,'tag'));
for j=1:3;
    I=strmatch(strs(j,:),tags);
    h(3,j)=g(I);
    %Set the value to val(j) and the callback to Tslide(j)
    set(g(I),'value',val(j),'callback',['Tslide(',int2str(j),')']);
    %Set the min and max to val(j)+/-vr(j)
    set(g(I),'min',val(j)-vr(j),'max',val(j)+vr(j));
end

set(F,'userdata',h,'Name','Convert Temp');
set(h(3,[1,3]),'visible','off'); %turn other sliders off