aboutsummaryrefslogtreecommitdiff
path: root/noao/digiphot/apphot/phot/apmeasure.x
blob: 6d64db5e84d882d9d5c00d88827b1b8c051224bb (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# APMEASURE -- Procedure to measure the fluxes and effective areas of a set of
# apertures.

procedure apmeasure (im, wx, wy, c1, c2, l1, l2, aperts, sums, areas, naperts)

pointer	im			# pointer to image
real	wx, wy			# center of subraster
int	c1, c2			# column limits
int	l1, l2			# line limits
real	aperts[ARB]		# array of apertures
double	sums[ARB]		# array of sums
double	areas[ARB]		# aperture areas
int	naperts			# number of apertures

int	i, j, k, nx, yindex
double	fctn
pointer	buf
real	xc, yc, apmaxsq, dy2, r2, r
pointer	imgs2r()

begin
	# Initialize.
	nx = c2 - c1 + 1
	xc = wx - c1 + 1
	yc = wy - l1 + 1
	apmaxsq = (aperts[naperts] + 0.5) ** 2
	call aclrd (sums, naperts)
	call aclrd (areas, naperts)

	# Loop over the pixels.
	do j = l1, l2 {
	    buf = imgs2r (im, c1, c2, j, j)
	    if (buf == NULL)
		return
	    yindex = j - l1 + 1
	    dy2 = (yindex - yc) ** 2
	    do i = 1, nx {
		r2 = (i - xc) ** 2 + dy2
		if (r2 > apmaxsq)
		    next
		r = sqrt (r2) - 0.5
		do k = 1, naperts {
		    if (r > aperts[k])
			next
		    fctn = max (0.0, min (1.0, aperts[k] - r))
		    sums[k] = sums[k] + fctn * Memr[buf+i-1]
		    areas[k] = areas[k] + fctn
		}
	    }
	}
end


# APBMEASURE -- Procedure to measure the fluxes and effective areas of a set of
# apertures.

procedure apbmeasure (im, wx, wy, c1, c2, l1, l2, datamin, datamax, aperts,
	sums, areas, naperts, minapert)

pointer	im			# pointer to image
real	wx, wy			# center of subraster
int	c1, c2			# column limits
int	l1, l2			# line limits
real	datamin			# minimum good data value
real	datamax			# maximum good data value
real	aperts[ARB]		# array of apertures
double	sums[ARB]		# array of sums
double	areas[ARB]		# aperture areas
int	naperts			# number of apertures
int	minapert		# minimum apertures

int	i, j, k, nx, yindex, kindex
double	fctn
pointer	buf
real	xc, yc, apmaxsq, dy2, r2, r, pixval
pointer	imgs2r()

begin
	# Initialize.
	nx = c2 - c1 + 1
	xc = wx - c1 + 1
	yc = wy - l1 + 1
	apmaxsq = (aperts[naperts] + 0.5) ** 2
	call aclrd (sums, naperts)
	call aclrd (areas, naperts)
	minapert = naperts + 1

	# Loop over the pixels.
	do j = l1, l2 {
	    buf = imgs2r (im, c1, c2, j, j)
	    if (buf == NULL)
		return
	    yindex = j - l1 + 1
	    dy2 = (yindex - yc) ** 2
	    do i = 1, nx {
		r2 = (i - xc) ** 2 + dy2
		if (r2 > apmaxsq)
		    next
		r = sqrt (r2) - 0.5
		pixval = Memr[buf+i-1]
		kindex = naperts + 1
		do k = 1, naperts {
		    if (r > aperts[k])
			next
		    kindex = min (k, kindex)
		    fctn = max (0.0, min (1.0, aperts[k] - r))
		    sums[k] = sums[k] + fctn * pixval
		    areas[k] = areas[k] + fctn
		}
		if (kindex < minapert) {
		    if (pixval < datamin || pixval > datamax)
		        minapert = kindex
		}
	    }
	}
end