aboutsummaryrefslogtreecommitdiff
path: root/noao/digiphot/daophot/psf/dppwselmer.x
blob: 24684b67264c5c3be193f04fb9d156892e17913a (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
include <tbset.h>
include "../lib/apseldef.h"

define	NCOLUMN 	5

define PS_DATA1STR "%-9d%10t%-10.3f%20t%-10.3f%30t%-12.3f%42t%-15.7g%80t \n"

# DP_XPSELMER -- Write the output photometry record to a text file.

procedure dp_xpselmer (tpout, id, x, y, mag, sky)

pointer	tpout		# pointer to the output table
int	id		# id of the star
real	x, y		# position of the star
real	mag		# magnitude of the star
real	sky		# value of sky

begin
	call fprintf (tpout, PS_DATA1STR)
	    call pargi (id)
	    call pargr (x)
	    call pargr (y)
	    call pargr (mag)
	    call pargr (sky)
end


# DP_TPSELMER -- Write out the PSF stars into an ST Table.

procedure dp_tpselmer (tp_out, id, x, y, mag, sky, colpoint, row)

int	tp_out			# the output table descriptor
int	id			# the object id
real	x			# the object x coordinate
real	y			# the object y coordinate
real	mag			# the object mangitude
real	sky			# the object sky value
int	colpoint[ARB]		# the column pointers
int	row			# current table row

begin
	# Write out the data.
	call tbrpti (tp_out, colpoint[1], id, 1, row)
	call tbrptr (tp_out, colpoint[2], x, 1, row)
	call tbrptr (tp_out, colpoint[3], y, 1, row)
	call tbrptr (tp_out, colpoint[4], mag, 1, row)
	call tbrptr (tp_out, colpoint[5], sky, 1, row)
end


# DP_XPSELPARS -- Add various parameters to the header of the photometry table.

procedure dp_xpselpars (tp, image, maxnpsf, scale, psfrad, fitrad)

pointer	tp			# pointer to the table
char	image[ARB]		# input image name
int	maxnpsf			# maximum number of psfstars
real	scale			# the image scale
real	psfrad			# the psf radius
real	fitrad			# the fitting radius

pointer	sp, str

begin
	call smark (sp)
	call salloc (str, SZ_FNAME, TY_CHAR)

	# Add the image name nad maxnpsf parameters.
	call dp_imroot (image, Memc[str], SZ_FNAME)
	call dp_sparam (tp, "IMAGE", Memc[str], "imagename", "")
	call dp_iparam (tp, "MAXNPSF", maxnpsf, "number", "")
	call dp_rparam (tp, "NEWSCALE", scale, "units", "")
	call dp_rparam (tp, "PSFRAD", psfrad, "scaleunit", "")
	call dp_rparam (tp, "FITRAD", fitrad, "scaleunit", "")

	call sfree (sp)
end


define PS_NAME1STR "#N%4tID%10tXCENTER%20tYCENTER%30tMAG%42tMSKY%80t\\\n"
define PS_UNIT1STR "#U%4t##%10tpixels%20tpixels%30tmagnitudes%42tcounts\
%80t\\\n"
define PS_FORMAT1STR "#F%4t%%-9d%10t%%-10.3f%20t%%-10.3f%30t%%-12.3f%42t\
%%-15.7g%80t \n"

# DP_XPBANNER -- Create a new text file banner.

procedure dp_xpbanner (tp)

pointer	tp		# pointer to the output file

begin
	# Print out the banner file.
	call fprintf (tp, "#\n")
	call fprintf (tp, PS_NAME1STR)
	call fprintf (tp, PS_UNIT1STR)
	call fprintf (tp, PS_FORMAT1STR)
	call fprintf (tp, "#\n")
end


# DP_TPDEFCOL -- Define the columns for the output table

procedure dp_tpdefcol (tp, colpoint)

pointer	tp		# pointer to the output table
int	colpoint[ARB]	# array of column pointers

int	i
pointer	sp, colnames, colunits, colformat, col_dtype, col_len

begin
	# Allocate space for the table definition.
	call smark (sp)
	call salloc (colnames, NCOLUMN * (SZ_COLNAME + 1), TY_CHAR)
	call salloc (colunits, NCOLUMN * (SZ_COLUNITS + 1), TY_CHAR)
	call salloc (colformat, NCOLUMN * (SZ_COLFMT + 1), TY_CHAR)
	call salloc (col_dtype, NCOLUMN, TY_INT)
	call salloc (col_len, NCOLUMN, TY_INT)

	# Set up the column definitions.
	call strcpy (ID, Memc[colnames], SZ_COLNAME)
	call strcpy (XCENTER, Memc[colnames+SZ_COLNAME+1], SZ_COLNAME)
	call strcpy (YCENTER, Memc[colnames+2*SZ_COLNAME+2], SZ_COLNAME)
	call strcpy (MAG, Memc[colnames+3*SZ_COLNAME+3], SZ_COLNAME)
	call strcpy (SKY, Memc[colnames+4*SZ_COLNAME+4], SZ_COLNAME)

	# Define the column formats.
	call strcpy ("%6d", Memc[colformat], SZ_COLFMT)
	call strcpy ("10.3f", Memc[colformat+SZ_COLFMT+1], SZ_COLFMT)
	call strcpy ("10.3f", Memc[colformat+2*SZ_COLFMT+2], SZ_COLFMT)
	call strcpy ("12.3f", Memc[colformat+3*SZ_COLFMT+3], SZ_COLFMT)
	call strcpy ("15.7g", Memc[colformat+4*SZ_COLFMT+4], SZ_COLFMT)

	# Define the column units.
	call strcpy ("NUMBER", Memc[colunits], SZ_COLUNITS)
	call strcpy ("PIXELS", Memc[colunits+SZ_COLUNITS+1], SZ_COLUNITS)
	call strcpy ("PIXELS", Memc[colunits+2*SZ_COLUNITS+2], SZ_COLUNITS)
	call strcpy ("MAGNITUDES", Memc[colunits+3*SZ_COLUNITS+3], SZ_COLUNITS)
	call strcpy ("ADU", Memc[colunits+4*SZ_COLUNITS+4], SZ_COLUNITS)

	# Define the column data types.
	Memi[col_dtype] = TY_INT
	Memi[col_dtype+1] = TY_REAL
	Memi[col_dtype+2] = TY_REAL
	Memi[col_dtype+3] = TY_REAL
	Memi[col_dtype+4] = TY_REAL

	# Define the column lengths.
	do i = 1, NCOLUMN 
	    Memi[col_len+i-1] = 1
	
	# Define and create the table.
	call tbcdef (tp, colpoint, Memc[colnames], Memc[colunits],
	    Memc[colformat], Memi[col_dtype], Memi[col_len], NCOLUMN)
	call tbtcre (tp)

	call sfree (sp)
end


# DP_TPSELPARS -- Add various parameters to the header of the photometry table.

procedure dp_tpselpars (tp, image, maxnpsf, scale, psfrad, fitrad)

pointer	tp			# pointer to the table
char	image[ARB]		# the input image name
int	maxnpsf			# maximum number of psf stars
real	scale			# the image scale
real	psfrad			# the psf radius
real	fitrad			# the fitting radius

pointer	sp, str

begin
	call smark (sp)
	call salloc (str, SZ_FNAME, TY_CHAR)

	# Add the min_group and max_group parameters.
	call dp_imroot (image, Memc[str], SZ_FNAME)
	call tbhadt (tp, "IMAGE", Memc[str])
	call tbhadi (tp, "MAXNPSF", maxnpsf)
	call tbhadr (tp, "SCALE", scale)
	call tbhadr (tp, "PSFRAD", psfrad)
	call tbhadr (tp, "FITRAD", fitrad)

	call sfree (sp)
end


# DP_WPSTARS -- Write the psf stars to the output file.

procedure dp_wpstars (tp_out, colpoint, text_file, ids, xcen, ycen, mag,
	sky, npsf)

int	tp_out			# the output file descriptor
int	colpoint[ARB]		# array of column pointers
bool	text_file		# is the output file a text file
int	ids[ARB]		# array of star ids
real	xcen[ARB]		# array of x coordinates
real	ycen[ARB]		# array of y coordinates
real	mag[ARB]		# array of magnitudes
real	sky[ARB]		# array of sky values
int	npsf			# the number of stars

int	istar, row

begin
	row = 0
	do istar = 1, npsf {
	    if (text_file)
		call dp_xpselmer (tp_out, ids[istar], xcen[istar], ycen[istar],
		    mag[istar], sky[istar])
	    else {
		row = row + 1
		call dp_tpselmer (tp_out, ids[istar], xcen[istar], ycen[istar],
		    mag[istar], sky[istar], colpoint, row)
	    }
	}
end