FUNCTION nndist,x,y ; ;Nearest-neighbour distance. ;Having in X,Y (1D input arrays with equal length) 2D coordinates ;representing objects, the routine calculates for each object ;the distance to its nearest object. ;The resulting FLOAT array is of the same length like X,Y. ; ;EXAMPLE: result = NNDIST(x,y) ; ;14 September 2004, Michal on_error,1 six=size(x) siy=size(y) if (six(0) ne 1) or (siy(0) ne 1) then message,'Input arrays must be 1D' if six(1) ne siy(1) then message,'Input arrays must have equal size' if six(2) ne siy(2) then message,'Input arrays must be of equal type' if six(1) lt 2 then message,'Only one object in input arrays' n=six(1) ;Loop over objects out=fltarr(n) for i=0,n-1 do begin di=sqrt(float((x-x(i))^2+(y-y(i))^2)) ;calculate distances di=di(where(di)) ;eliminate zero distance out(i)=min(di) ;find minimum distance endfor RETURN,out END