function   [valmax]=value2slider(h1,h2,index,valmin,valmax)
%% display value and slider position conversion
%%     h1 = handle of the object 1
%%     h2 = handle of the object 2
%% index = 1    value to slider position
%%         2    slider position to value
%% valmin= value correspond to slider value of 0
%% valmax= value correspond to slider value of 1

%%  Kriging Software Package  version 1.0 beta,   October 29, 1998
%%  Copyright (c) 1998, property of Dezhang Chu and Woods Hole Oceanographic
%%  Institution.  All Rights Reserved.


global ndigits

switch index
  case 1					% value to slider position
    val=str2num(get(h1,'string'));
    if val >= valmax valmax=1.2*val;end
    if val <= valmin val=valmin;end
    sldpos=(val-valmin)/(valmax-valmin);
    set(h2,'value',sldpos);
  case 2					% slider position to value
    sldpos=get(h1,'value');
    value=sldpos*(valmax-valmin)+valmin;
    valuestr=num2str(value);
    set(h2,'string',valuestr(1:min(ndigits,length(valuestr))));
end
   