function [imatch,jmatch,dist_km]=near2d(lon,lat,loni,lati)
% function [imatch,jmatch,dist_km]=near2d(lon,lat,loni,lati)
%
% finds imatch and jmatch such that lon(imatch,jmatch), 
% lat(imatch,jmatch) are closest [lon,lat] to [loni,lati]

%
% ckharris@vims.edu
% may 2004.
% 
[ii,jj]=size(lon);

for iind = 1:ii
  for jind = 1:jj
    
    distv(iind,jind)=sw_dist([lati, lat(iind,jind)], ...
	[loni, lon(iind,jind)],'km');
    
  end
end

mindist=min(min(distv));

[imatch,jmatch]=find(distv == mindist);

dist_km=mindist;
