function updatecursor(fnew,icurs,hslide)
%
%  Name:   updatecursor
%
%  Usage:  updatecursor(fnew,icurs,hslide)
%
%  This m-file is used to update the cursor frequency position
%  and y-direction limits
% 

%  Version SWD970809
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This matlab source code was originally     %
% developed as part of "DIAMOND" at          %
% Los Alamos National Laboratory. It may     %
% be copied, modified, and distributed in    %
% any form, provided:                        %
%  a) This notice accompanies the files and  %
%     appears near the top of all source     %
%     code files.                            %
%  b) No payment or commercial services are  %
%     received in exchange for the code.     %
%                                            %
% Original copyright is reserved by the      %
% Regents of the University of California,   %
% in addition to Scott W. Doebling, Phillip  %
% J. Cornwell, Erik G. Straser, and Charles  %
% R. Farrar.                                 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%

global DISPLAY iaxes inds

%
%  Get maximum and minimum frequencies
%

max_f=get(hslide,'max');
min_f=get(hslide,'min');

%
%  Get vector of valid frequency bins (userdata of slider)
%

binvec = get(hslide,'userdata');

%
%  Round selected frequency to nearest frequency bin
%

[junk,j] = min(abs( binvec - fnew ));

f = binvec(j);

if f == DISPLAY{iaxes}.cursfreq{icurs}  &  j < length(binvec),
   
   f = binvec(j+1);
   
end

%
%  Assign new cursor frequency
%

DISPLAY{iaxes}.cursfreq{icurs} = f;

%
%  Set slider to the rounded frequency
%

set(hslide,'value',DISPLAY{iaxes}.cursfreq{icurs});

%
%  Modify the cursor's and marker's x-axis position data
%

set(DISPLAY{iaxes}.hcursor{icurs},'xdata',[DISPLAY{iaxes}.cursfreq{icurs} DISPLAY{iaxes}.cursfreq{icurs}])
set(DISPLAY{iaxes}.hcursmark{icurs},'xdata',DISPLAY{iaxes}.cursfreq{icurs})

%
%  Modify the cursor's and marker's y-axis position data

ylim = get(DISPLAY{iaxes}.haxes,'ylim');

i1 = find(binvec == DISPLAY{iaxes}.cursfreq{icurs});

if strcmp(get(DISPLAY{iaxes}.haxes,'yscale'),'log'),
   % plot is logarithmic
   % In this case, set ymin to smallest nonzero entry in the plot data
   ylim(1) = min(DISPLAY{iaxes}.displayvec{inds}(find(DISPLAY{iaxes}.displayvec{inds} > 0)));
end

set(DISPLAY{iaxes}.hcursor{icurs},'ydata',ylim);
set(DISPLAY{iaxes}.hcursmark{icurs},'ydata',DISPLAY{iaxes}.displayvec{inds}(i1));

return
