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
|
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
include <pmset.h>
task sum = t_sum
# SUM -- Sum the image pixels lying within the given mask.
procedure t_sum()
char image[SZ_FNAME] # input data image
char mask[SZ_FNAME] # image mask
int npix, mval, totpix, m_flags
long v[PM_MAXDIM]
pointer im, mp, pp
real sum
bool clgetb()
real asumr()
int mio_glsegr()
pointer immap(), mio_open()
begin
call clgstr ("image", image, SZ_FNAME)
call clgstr ("mask", mask, SZ_FNAME)
m_flags = 0
if (clgetb ("invert"))
m_flags = INVERT_MASK
im = immap (image, READ_ONLY, 0)
mp = mio_open (mask, m_flags, im)
sum = 0; totpix = 0
while (mio_glsegr (mp, pp, mval, v, npix) != EOF) {
sum = sum + asumr (Memr[pp], npix)
totpix = totpix + npix
}
call mio_close (mp)
call imunmap (im)
call printf ("%d pixels, sum=%g, mean=%g\n")
call pargi (totpix)
call pargr (sum)
if (totpix > 0)
call pargr (sum / totpix)
else
call pargr (INDEF)
end
|