;===================================================================== ; PV-WAVE ARL ; ; PV-Wave Advanced Rendering Library ; 11/90 D. Carr ; ; (c) Copyright Precision Visuals, Inc., 1990 ; Boulder, Colorado, U.S.A. ; ; All Rights Reserved. ; ; This software is confidential information which is proprietary to ; and a trade secret of Precision Visuals, Inc. Use, duplication or ; disclosure is subject to the terms of an appropriate license ; agreement. ; ------------------------------------------------------------------ ; Use, duplication, or disclosure by the Government is subject to ; restrictions set forth in paragraph (b)(3)(B) of the Rights in ; Technical Data and Computer Software clause in DAR 7-104.9(a). ; ; Contractor : Precision Visuals, Inc., Boulder, Colorado, U.S.A. ; ------------------------------------------------------------------- ; ; Program Overview : FUNCTION Grid_2d ; ; Grid_2d takes random X-Y coordinates and returns a gridded ; 1 dimensional array containing Y values. This gridded array is ; suitable for use with the "Plot" function. ; Grid_2d uses a weighted neighborhood averaging technique to ; interpolate missing data values. ; ; SEE ALSO : Grid_3d Grid_4d Grid_Sphere ; ; MANDATORY INPUTS : ; ; points : A (2, n) array containing random X-Y points to ; be gridded. ; ; grid_x : The size of the vector to return. ; ; OPTIONAL INPUTS (Keywords) : ; ; order : The order of the weighing function to use for ; neighborhood averaging. The default is 2 . ; Points are weighted by the function : ; w = 1.0 / (dist^order) ; where dist is the distance to the point. ; ;===================================================================== ; FUNCTION Grid_2d, points, grid_x, order=order sp = Size(points) IF (sp(0) NE 2) THEN BEGIN Print, "Invalid points array." STOP ENDIF IF (grid_x(0) LT 2) THEN BEGIN Print, "X dimension of grid must be 2 or greater." STOP ENDIF p_order = 2.0 IF (N_Elements(order) GT 0) THEN p_order = Float(order(0)) > 0.0 points = Float(points) n_points = sp(1) grid_x = Fix(grid_x(0)) lox = Min(points(0, *)) hix = Max(points(0, *)) xrange = hix - lox IF (xrange LE 0.0) THEN BEGIN Print, "Unable to grid points." Print, "All points have the same X value." STOP ENDIF y_val = Fltarr(grid_x) xinc = xrange / Float(grid_x) xs = Fix((points(0, *) - lox) / xinc) < (grid_x - 1) grid_xm1 = grid_x - 1 FOR i=0, grid_xm1 DO BEGIN dx = Float(xs - i) distances = (ABS(dx))^(p_order) ind = Where(distances EQ 0.0) IF (ind(0) EQ (-1)) THEN BEGIN y_val(i) = Total(points(1, *) / distances) / Total(1.0 / distances) ENDIF ELSE BEGIN y_val(i) = AVG(points(1, ind)) ENDELSE ENDFOR RETURN, y_val END