% GUIselect
% Function for the MODIS GUI
% Copyright by Jasmine S Nahorniak, Oregon State University.
% Feb 28 2000

function [xpos,ypos]=GUIselect(action,xpos,ypos)

xpos
ypos

switch(action)
  case 1,
     xpos=[NaN NaN];
     ypos=[NaN NaN];
     currpt=get(gca,'CurrentPoint');     
     xpos(1)=currpt(1,1);
     ypos(1)=currpt(1,2); 
     plotm(xpos(1),ypos(1),'o')
     set(gcbf,'WindowButtonMotionFcn','');
   %set(gcbf,'WindowButtonMotionFcn','[xpos,ypos]=GUIselect(2,xpos,ypos);');
     set(gcbf,'WindowButtonUpFcn','[xpos,ypos]=GUIselect(3,xpos,ypos);');
  case 2,
     currpt=get(gca,'CurrentPoint');     
     xpos(2)=currpt(1,1);
     ypos(2)=currpt(1,2);
     DrawSquare(xpos,ypos);
  case 3,   
     currpt=get(gca,'CurrentPoint');     
     xpos(2)=currpt(1,1);
     ypos(2)=currpt(1,2);
     DrawSquare(xpos,ypos);
     %set(gcbf,'WindowButtonMotionFcn','');
     set(gcbf,'WindowButtonUpFcn','');
end


% draw the selected square
function DrawSquare(xpos,ypos)

squareh=findobj('Tag','selection');

if ~isempty(squareh),
  %set(squareh,'Xdata',[xpos(1) xpos(2)]);
  %set(squareh,'Ydata',[ypos(1) ypos(2)]);
  delete(squareh);
end

xsquare=[xpos(1) xpos(2) xpos(2) xpos(1) xpos(1)];
ysquare=[ypos(1) ypos(1) ypos(2) ypos(2) ypos(1)];
h=plotm(xsquare,ysquare,'w--');
set(h,'Tag','selection');



