function gisdata=m2ll(vec,ijdat)

% M2LL        Map matrix to Long./Lat. co-ordinates.
% 
%             Example: m=ceil(10*rand(7));
%                      data=genspace(m);
%                      ijdat=zdens(m,data);
%                      gisdata=m2ll([16.4 32.7 -35 -22],ijdat);
% 
%             M2LL(VEC,IJDAT) maps the densities in IJDAT onto a
%             Long./Lat. grid defined by the vector VEC.  
%
%             VEC should have the form [XMIN XMAX YMIN YMAX].
%
%             Christian C. Beardah 1996

[r,c]=size(ijdat);

gisdata=zeros(r*c,3);
gisdata(:,3)=ijdat(:);

xmin=vec(1);
xmax=vec(2);
ymin=vec(3);
ymax=vec(4);

xinc=abs((xmax-xmin)/c);
yinc=abs((ymax-ymin)/r);

xc=(xmin+xinc/2):xinc:(xmin+xinc/2+(c-1)*xinc);
yc=(ymin+yinc/2):yinc:(ymin+yinc/2+(r-1)*yinc);

[X,Y]=meshgrid(xc,yc);

Y=flipud(Y);

gisdata(:,1)=X(:);
gisdata(:,2)=Y(:);