function mouseMove(refreshAxis,displayAxis,latDisp,lonDisp,latitude,longitude,valDisp,dataToPlot)

% callback for region.fig 'WindowButtonMotionFcn'
% Inputs: Refresh position flag
%          1=Main figure
%          2=RGB figure
%          3=Region figure
%          4=Scatterplot values of region figure
%          5=Line figure
%          6=Pseudochannel figure
%         Axis on which image is displayed
%         latitude and longitude to display
%         value to display
%         data of image plot
%  Outputs: none
%  Kevin Baggett
%  Tue Aug 23 22:19:08 UTC 2001     

persistent pos1;
persistent pos2;
persistent pos3;
persistent pos4;
persistent pos5;
persistent pos6;

currentPos=['pos' num2str(refreshAxis)];

if nargin==1
    eval(['clear ' currentPos ';']);
    return;
end

[row col]=size(dataToPlot);

if isempty(eval(currentPos))
    axes(displayAxis);
    pos=get(gca,'Position');
    eval([currentPos '=pos;']);
else
    eval(['pos=' currentPos ';']);
end

x=get(gcf,'CurrentPoint');

if (x(1) > pos(1) & x(1)<pos(1)+pos(3)) & (x(2)>pos(2))&(x(2)<pos(2)+pos(4))
    xcoord=col*(x(1)-pos(1))/pos(3);
    ycoord=row*(x(2)-pos(2))/pos(4);
    invy=((1-row)*(x(2)-pos(2)-pos(4))/pos(4))+1;
    %remember imagedata is on its side
    if round(xcoord)==0
        xcoord=1;
    end
    if round(invy)==0
        invy=1;
    end
%     set(latDisp,'String',num2str(latitude(round(invy),round(xcoord))));
%     set(lonDisp,'String',num2str(longitude(round(invy),round(xcoord))));
    set(valDisp,'String',num2str(dataToPlot(round(invy),round(xcoord))));
else
%     set(latDisp,'String',' ');
%     set(lonDisp,'String',' ');
    set(valDisp,'String',' ');
end

% an attempt to do in Java which didn't go so well
% import java.awt.*
% import java.awt.event.*
% 
% f=Frame;
% f.setSize(200,200);
% f.setLocation(300,300);
% f.setTitle('Bobby Bobaloo');
% f.show;
% 
% b=Button;
% b.setLocation(100,100);
% b.setSize(50,50);
% b.setLabel('hi');
% f.add(b);
% %b.show;
% %e=Event(f,1,b);
% m=MouseEvent(f,1,1,1,1,1,1,1);
% %f.addMouseMotionListener(f);
% 
% function mouseMoved(m,b)
% 
% x=m.getX;
% y=m.getY;
% b.setLabel([num2str(x) ',' num2str(y)]);
% b.repaint;
% %f.repaint;
