aboutsummaryrefslogtreecommitdiff
path: root/noao/digiphot/daophot/psf/dplocstar.x
blob: 9925f44b91b99e0cb679372b103c33d06e485b59 (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
include <mach.h>
include <imhdr.h>
include "../lib/daophotdef.h"
include	"../lib/apseldef.h"
include	"../lib/psfdef.h"

# DP_LOCSTAR -- Given an x,y position locate the star in the aperture
# photometry list which is within a critical radius of the input position.

int procedure dp_locstar (dao, im, x, y)

pointer	dao			# pointer to the daophot structure
pointer	im			# pointer to the input image
real	x, y			# input position

int	i
pointer	psf, apsel
real	crit_rad, fitrad, rad, ax, ay

begin
	# Set up some constants.
	psf = DP_PSF(dao)
	apsel = DP_APSEL(dao)
	crit_rad = DP_MATCHRAD(dao) * DP_MATCHRAD(dao)
	fitrad = DP_FITRAD(dao)

	# Search the list.
	do i = 1, DP_APNUM(apsel) {

	    # Compute distance of star from the cursur position.
	    ax = Memr[DP_APXCEN(apsel)+i-1]
	    ay = Memr[DP_APYCEN(apsel)+i-1]
	    if (! IS_INDEFR(ax) && ! IS_INDEFR(ay))
	        rad = (ax - x) * (ax - x) + (ay - y) * (ay - y)
	    else 
		rad = MAX_REAL

	    # Found the star.
	    if (rad <= crit_rad) {

		DP_CUR_PSF(psf) = i
		DP_CUR_PSFID(psf) = Memi[DP_APID(apsel)+i-1]
		DP_CUR_PSFX(psf) = ax
		DP_CUR_PSFY(psf) = ay
		DP_CUR_PSFSKY(psf) = Memr[DP_APMSKY(apsel)+i-1]
		DP_CUR_PSFMAG(psf) = Memr[DP_APMAG(apsel)+i-1]

		# Is the star too close to the edge ?
		if (int (ax - fitrad) < 0 || int (ax + fitrad) > IM_LEN(im,1) ||
		    int (ay - fitrad) < 0 || int (ay + fitrad) > IM_LEN(im,2))
		    return (-i)
		else
		    return (i)
	    }
	}

	return (0)
end


# DP_IDSTAR -- Given an id number locate the star in the aperture
# photometry list.

int procedure dp_idstar (dao, im, idnum)

pointer	dao			# pointer to the daophot structure
pointer	im			# pointer to the input image
int	idnum			# id number from photometry list

int	i
pointer	psf, apsel
real	fitrad, x, y

begin
	# Set up some constants.
	psf = DP_PSF(dao)
	apsel = DP_APSEL(dao)
	fitrad = DP_FITRAD(dao)

	# Search the list.
	do i = 1, DP_APNUM (apsel) {

	    # Test the id number.
	    if (idnum != Memi[DP_APID(apsel)+i-1])
		next

	    # Found the star.
	    x = Memr[DP_APXCEN(apsel)+i-1]
	    y = Memr[DP_APYCEN(apsel)+i-1]
	    DP_CUR_PSF(psf) = i
	    DP_CUR_PSFID(psf) = Memi[DP_APID(apsel)+i-1]
	    DP_CUR_PSFX(psf) = Memr[DP_APXCEN(apsel)+i-1]
	    DP_CUR_PSFY(psf) = Memr[DP_APYCEN(apsel)+i-1]
	    DP_CUR_PSFSKY(psf) = Memr[DP_APMSKY(apsel)+i-1]
	    DP_CUR_PSFMAG(psf) = Memr[DP_APMAG(apsel)+i-1]

	    # Is the star too close to the edge ?
	    if (IS_INDEFR(x) || IS_INDEFR(y))
		return (0)
	    else if (int (x - fitrad) < 0 || int (x + fitrad) >
	        IM_LEN(im,1) || int (y - fitrad) < 0 || int (y + fitrad) >
		IM_LEN(im,2))
	    	return (-i)
	    else
		return (i)
	}

	return (0)
end