aboutsummaryrefslogtreecommitdiff
path: root/noao/nproto/ir/irmedr.x
blob: 436a36738d5e9d5e714b6a61b4133bc6764fc336 (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
# IRMEDR -- Procedure to compute the median of an array in which some
# elements are undefined.

real procedure irmedr (a, aindex, npts)

real	a[ARB]		# input array
int	aindex[ARB]	# definition array
int	npts		# number of points

int	i, n
pointer	sp, b
real	med
real	asokr()

begin
	call smark (sp)
	call salloc (b, npts, TY_REAL)

	n = 0
	do i = 1, npts {
	    if (aindex[i] > 0) {
		Memr[b+n] = a[i]
		n = n + 1
	    }
	}

	if (n == 0)
	    med = INDEFR
	else
	    med = asokr (Memr[b], n, (n + 1) / 2)

	call sfree (sp)

	return (med)
end