aboutsummaryrefslogtreecommitdiff
path: root/noao/digiphot/daophot/seepsf/t_seepsf.x
blob: e104121cb9bca180956bbdfa5901a2aa1fbc8d17 (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
include	<fset.h>

# T_SEEPSF  -- Produce the PSF in image scale coordinates.

procedure t_seepsf ()

pointer	psfimage			# name of the input PSF
pointer	image				# name of the output image
int	dimen				# size of the image
real	magnitude			# magnitude of star

int	psffd, pimlist, lpimlist, imlist, limlist
pointer	im, sp, dao
real	xpsf, ypsf

int	clgeti(), fstati(), imtopen(), imtlen(), imtgetim()
real	clgetr()
pointer	immap()

begin
	# Set the standard output to flush on newline.
	if (fstati (STDOUT, F_REDIR) == NO)
	     call fseti (STDOUT, F_FLUSHNL, YES)

	# Get some memory.
	call smark (sp)
	call salloc (psfimage, SZ_FNAME, TY_CHAR)
	call salloc (image, SZ_FNAME, TY_CHAR)

	# Get the various task parameters.
	call clgstr ("psfimage", Memc[psfimage], SZ_FNAME)
	call clgstr ("image", Memc[image], SZ_FNAME)
	dimen = clgeti ("dimension")
	if (! IS_INDEFI(dimen)) {
	    if (mod (dimen, 2) == 0)
	        dimen = dimen + 1
	}
	xpsf = clgetr ("xpsf")
	ypsf = clgetr ("ypsf")
	magnitude = clgetr ("magnitude")

	# Get the lists.
	pimlist = imtopen (Memc[psfimage])
	lpimlist = imtlen (pimlist)
	imlist = imtopen (Memc[image])
	limlist = imtlen (imlist)

	# Check the list lengths for equality.
	if (lpimlist != limlist) {
	    call imtclose (pimlist)
	    call imtclose (imlist)
	    call sfree (sp)
	    call error (0,
	        "The psf and output image lengths are imcompatibale")
	}

	# Initialize the daophot structure and get the pset parameters.
	call dp_init (dao)
	call dp_fitsetup (dao)

	# Loop over the input images
	while ((imtgetim (pimlist, Memc[psfimage], SZ_FNAME) != EOF) &&
	    (imtgetim (imlist, Memc[image], SZ_FNAME) != EOF)) {

	    # Open the psfimage.
	    psffd = immap (Memc[psfimage], READ_ONLY, 0)

	    # Open the output image.
	    im = immap (Memc[image], NEW_COPY, psffd)

	    # Read the PSF.
	    call dp_readpsf (dao, psffd)

	    # Make PSF image.
	    call dp_mkimage (dao, psffd, im, dimen, xpsf, ypsf, magnitude)

	    # Close the PSF image and the output image.
	    call imunmap (psffd)
	    call imunmap (im)
	}

	# Close the daophot structure.
	call dp_fitclose (dao)
	call dp_free (dao)

	# Close the lists
	call imtclose (pimlist)
	call imtclose (imlist)

	call sfree (sp)
end