aboutsummaryrefslogtreecommitdiff
path: root/noao/digiphot/apphot/aplib/apshowplot.x
blob: ed188d52a4add917094abab311f2ba3107bfc601 (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
include "../lib/apphot.h"

define	RADIUS	15.0
define	CRADIUS	 5

# AP_SHOWPLOT -- Plot a radial profile of a star.

int	procedure ap_showplot (ap, im, wx, wy, gd, xcenter, ycenter, rmin,
	rmax, imin, imax)

pointer	ap			# pointer to the apphot structure
pointer	im			# pointer to the image
real	wx, wy			# the cursor coordinates
pointer	gd			# pointer to the graphics stream
real	xcenter, ycenter	# the centered coordinates
real	rmin, rmax		# minimum and maximum radius
real	imin, imax		# minimum and maximum intensity

real	radius, xc, yc, xold, yold
pointer	sp, r, skypix, coords, index, str, gt
int	niter, lenbuf, nx, ny, nsky

real	apstatr()
pointer	ap_gtinit()
int	ap_gvrad(), apstati(), ap_skypix()

begin
	call gclear (gd)
	call gflush (gd)

	# Set the pixel extraction parameters.
	lenbuf = ap_gvrad (RADIUS, radius)

	# Initialize.
	call smark (sp)
	call salloc (r, lenbuf, TY_REAL)
	call salloc (skypix, lenbuf, TY_REAL)
	call salloc (coords, lenbuf, TY_INT)
	call salloc (index, lenbuf, TY_INT)
	call salloc (str, SZ_LINE, TY_CHAR)

	# Center the star.
	niter = 0
	xold = wx
	yold = wy
	repeat {
	    call ap_ictr (im, xold, yold, CRADIUS, apstati (ap, POSITIVE),
	        xcenter, ycenter)
	    niter = niter + 1
	    if (abs (xcenter - xold) <= 1.0 && abs (ycenter - yold) <= 1.0)
		break
	    xold = xcenter
	    yold = ycenter
	} until (niter >= 3)

	# Fetch the pixels.
	nsky = ap_skypix (im, xcenter, ycenter, 0.0, radius, Memr[skypix],
	    Memi[coords], xc, yc, nx, ny)
	if (nsky <= 0) {
	    call sfree (sp)
	    return (ERR)
	}
	call ap_index (Memi[index], nsky)

	# Compute the radius and intensity values.
	call ap_xytor (Memi[coords], Memi[index], Memr[r], nsky, xc, yc, nx)
	call alimr (Memr[r], nsky, rmin, rmax)
	call alimr (Memr[skypix], nsky, imin, imax)

	# Plot the radial profiles.
	#call apstats (ap, IMNAME, Memc[str], SZ_FNAME)
	call apstats (ap, IMROOT, Memc[str], SZ_FNAME)
	call ap_ltov (im, xcenter, ycenter, xc, yc, 1)
	gt = ap_gtinit (Memc[str], xc, yc)
	call ap_rset (gd, gt, 0.0, rmax, imin, imax, apstatr (ap, SCALE))
	call ap_plotrad (gd, gt, Memr[r], Memr[skypix], nsky, "plus")

	# Cleanup.
	call ap_gtfree (gt)
	call sfree (sp)

	return (OK)
end