aboutsummaryrefslogtreecommitdiff
path: root/sys/vops/lz/amed4i.x
blob: f39d01b6577fd38c9659d30a30c4df63599b486e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

# AMED4 -- Median of four vectors.  Each output point M[i] is the median of the
# four input points A[i],B[i],C[i],D[i].  The vector min and max are also
# computed and returned in the A and D vectors.  The input vectors are modifed
# in place.

procedure amed4i (a, b, c, d, m, npix)

int	a[ARB], b[ARB]		# input vectors
int	c[ARB], d[ARB]		# input vectors
int	m[ARB]				# output vector (median)
int	npix

int	i
int	temp
define	swap {temp=$1;$1=$2;$2=temp}

begin
	do i = 1, npix {
	    # Move the minimum value to A[i].
	    if (b[i] < a[i])
		swap (b[i], a[i])
	    if (c[i] < a[i])
		swap (c[i], a[i])
	    if (d[i] < a[i])
		swap (d[i], a[i])

	    # Move the maximum value to D[i].
	    if (b[i] > d[i])
		swap (b[i], d[i])
	    if (c[i] > d[i])
		swap (c[i], d[i])

	    # Return the median value.
	    if (b[i] < c[i])
		m[i] = b[i]
	    else
		m[i] = c[i]
	}
end