function Tedit(ID);
%TEDIT
%
% Tedit(ID)
%
%Manages edit windows for Tconvert.  ID indicates
%which editor was used:
%
%    1=Kelvin
%    2=Celsius
%    3=Fahrenheit

this=gcbo;%callback object
h=get(gcbf,'userdata');%matrix of handles

val=get(this,'string');  %The string entered by the user
val=str2num(val);        %numerical equivalent of string
if(isempty(val))
	%The string is not a valid number
   %
   %Return a note to the user and set the value to the default
  mn=get(h(3,ID),'min');
  mx=get(h(3,ID),'max');
  switch ID
    case 1
      disp(['Kelvin values must be between ',num2str(mn,'%6.2f'),...
          ' and ',num2str(mx, '%6.2f')]);
    case 2
      disp(['Celsius values must be between ',num2str(mn,'%6.2f'),...
          ' and ',num2str(mx,'%6.2f')]);
    case 3
      disp(['Fahrenheit values must be between ',num2str(mn,'%6.2f'),...
          ' and ',num2str(mx,'%6.2f')]);
    otherwise
      error('Unknown ID passed to Tedit');
  end
  disp('      Resetting to default');
  val=0.5*(mx+mn);
  set(this,'string',num2str(val,'%6.2f'));
end

%Make sure value is between MIN and MAX (defined by slider)
if(val<get(h(3,ID),'min'));
  val=get(h(3,ID),'min');
  set(this,'string',num2str(val,'%6.2f'));
elseif(val>get(h(3,ID),'max'));
  val=get(h(3,ID),'max');
  set(this,'string',num2str(val,'%6.2f'));
end

%set the slider's value to agree with the edit string
set(h(3,ID),'value',val);

Tconvert(h,ID,val);%perform conversions and update others
