aboutsummaryrefslogtreecommitdiff
path: root/sys/vops/lz/amed5i.x
blob: 9738be6ae92ef158d3770ee9ff15c8ff377f7e2c (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

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

procedure amed5i (a, b, c, d, e, m, npix)

int	a[ARB], b[ARB]		# input vectors
int	c[ARB], d[ARB], e[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])
	    if (e[i] < a[i])
		swap (e[i], a[i])

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

	    # Return the median value of the central three points.
	    if (b[i] < c[i]) {
		if (c[i] < d[i])		# bcd
		    m[i] = c[i]
		else if (b[i] < d[i])		# bdc
		    m[i] = d[i]
		else				# dbc
		    m[i] = b[i]
	    } else {
		if (c[i] > d[i])		# dcb
		    m[i] = c[i]
		else if (b[i] > d[i])		# cdb
		    m[i] = d[i]
		else				# cbd
		    m[i] = b[i]
	    }
	}
end