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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
|
include <fset.h>
include <imhdr.h>
include <gset.h>
include "../lib/daophotdef.h"
include "../lib/apseldef.h"
include "../lib/psfdef.h"
# T_PSTSELECT -- Select good candidate PSF stars from a DAOPHOT photometry
# file.
procedure t_pstselect ()
pointer image # input image
pointer photfile # input rough photometry
pointer pstfile # output PSTFILE table
int maxnpsf # maximimum number of psf stars
pointer plotfile # pointer to the plot metacode file
bool interactive # interactive mode
pointer plottype # default plot type
int cache # cache the input image pixels
int verify # verify the critical parameters
int update # update the critical parameters
pointer graphics # the graphics device
pointer display # the display device
bool mkstars # mark deleted and accepted psf stars
pointer sp, pfd, dao, outfname, curfile, str, im, gd, id, mgd
int imlist, limlist, alist, lalist, olist, lolist, root, apd, pmgd, pltype
int wcs, req_size, old_size, buf_size, memstat()
bool ap_text
pointer immap(), gopen()
int tbtopn(), open(), fnldir(), strlen(), strncmp(), fstati(), btoi()
int access(), fntopnb(), fntlenb(), clgeti(), imtopen(), imtlen()
int fntgfnb(), imtgetim(), strdic(), dp_stati(), clgwrd(), sizeof()
int dp_memstat()
bool clgetb(), itob(), streq()
errchk gopen()
begin
# Set the standard output to flush on newline.
if (fstati (STDOUT, F_REDIR) == NO)
call fseti (STDOUT, F_FLUSHNL, YES)
# Get some working memory.
call smark (sp)
call salloc (image, SZ_FNAME, TY_CHAR)
call salloc (photfile, SZ_FNAME, TY_CHAR)
call salloc (pstfile, SZ_FNAME, TY_CHAR)
call salloc (plotfile, SZ_FNAME, TY_CHAR)
call salloc (plottype, SZ_FNAME, TY_CHAR)
call salloc (graphics, SZ_FNAME, TY_CHAR)
call salloc (display, SZ_FNAME, TY_CHAR)
call salloc (outfname, SZ_FNAME, TY_CHAR)
call salloc (curfile, SZ_FNAME, TY_CHAR)
call salloc (str, SZ_FNAME, TY_CHAR)
# Get the various task parameters.
call clgstr ("image", Memc[image], SZ_FNAME)
call clgstr ("photfile", Memc[photfile], SZ_FNAME)
call clgstr ("pstfile", Memc[pstfile], SZ_FNAME)
maxnpsf = clgeti ("maxnpsf")
cache = btoi (clgetb ("cache"))
verify = btoi (clgetb ("verify"))
update = btoi (clgetb ("update"))
# Get the lists.
imlist = imtopen (Memc[image])
limlist = imtlen (imlist)
alist = fntopnb (Memc[photfile], NO)
lalist = fntlenb (alist)
olist = fntopnb (Memc[pstfile], NO)
lolist = fntlenb (olist)
# Test that the lengths of the photometry file and psf star file
# lists are the same as the input image list.
if ((limlist != lalist) && (strncmp (Memc[photfile], DEF_DEFNAME,
DEF_LENDEFNAME) != 0)) {
call imtclose (imlist)
call fntclsb (alist)
call fntclsb (olist)
call sfree (sp)
call error (0,
"Incompatable image and photometry file list lengths\n")
}
if ((limlist != lolist) && (strncmp (Memc[pstfile], DEF_DEFNAME,
DEF_LENDEFNAME) != 0)) {
call imtclose (imlist)
call fntclsb (alist)
call fntclsb (olist)
call sfree (sp)
call error (0,
"Incompatable image and photometry file list lengths\n")
}
# Initialize the DAOPHOT structure, and get the pset parameters.
call dp_gppars (dao)
# Confirm the parameters.
if (verify == YES) {
call dp_ptconfirm (dao)
if (update == YES)
call dp_pppars (dao)
}
# Get the wcs information.
wcs = clgwrd ("wcsin", Memc[str], SZ_LINE, WCSINSTR)
if (wcs <= 0) {
call eprintf (
"Warning: Setting the input coordinate system to logical\n")
wcs = WCS_LOGICAL
}
call dp_seti (dao, WCSIN, wcs)
wcs = clgwrd ("wcsout", Memc[str], SZ_LINE, WCSOUTSTR)
if (wcs <= 0) {
call eprintf (
"Warning: Setting the output coordinate system to logical\n")
wcs = WCS_LOGICAL
}
call dp_seti (dao, WCSOUT, wcs)
# Initialize the photometry structure.
call dp_apsetup (dao)
# Initialize the PSF fitting structure.
call dp_psfsetup (dao)
# Initialize the PSF structure.
call dp_fitsetup (dao)
# Is the task interactive or not?
call clgstr ("icommands.p_filename", Memc[curfile], SZ_FNAME)
if (Memc[curfile] == EOS)
interactive = clgetb ("interactive")
else
interactive = false
# Get the graphics display and plot file devices.
call clgstr ("graphics", Memc[graphics], SZ_FNAME)
call clgstr ("display", Memc[display], SZ_FNAME)
call clgstr ("plottype", Memc[plottype], SZ_FNAME)
call clgstr ("plotfile", Memc[plotfile], SZ_FNAME)
# Open graphics and display devices if appropriate.
if (interactive) {
call dp_seti (dao, VERBOSE, YES)
if (Memc[graphics] == EOS)
gd = NULL
else {
iferr {
gd = gopen (Memc[graphics], APPEND+AW_DEFER, STDGRAPH)
} then {
call eprintf ("Warning: Error opening graphics device\n")
gd = NULL
}
}
if (Memc[display] == EOS)
id = NULL
else if (streq (Memc[graphics], Memc[display])) {
id = gd
} else {
iferr {
id = gopen (Memc[display], APPEND, STDIMAGE)
} then {
call eprintf (
"Warning: Graphics overlay not available for display device\n")
id = NULL
}
}
if (id != NULL)
mkstars = clgetb ("mkstars")
else
mkstars = false
} else {
gd = NULL
id = NULL
call dp_seti (dao, VERBOSE, btoi (clgetb ("verbose")))
mkstars = false
}
# Open the plot file.
if (Memc[plotfile] == EOS)
pmgd = NULL
else
pmgd = open (Memc[plotfile], APPEND, BINARY_FILE)
if (pmgd != NULL)
mgd = gopen (Memc[graphics], NEW_FILE, pmgd)
else
mgd = NULL
# Set the default plot type.
pltype = strdic (Memc[plottype], Memc[plottype], SZ_FNAME, PSF_PLOTS)
call dp_pseti (dao, PLOTTYPE, pltype)
# Loop over the list of input files
while (imtgetim (imlist, Memc[image], SZ_FNAME) != EOF) {
# Open the input image.
im = immap (Memc[image], READ_ONLY, 0)
call dp_imkeys (dao, im)
call dp_sets (dao, INIMAGE, Memc[image])
# Set up the display coordinate system.
if ((id != NULL) && (id != gd))
call dp_gswv (id, Memc[image], im, 4)
# Cache the input image pixels.
req_size = MEMFUDGE * IM_LEN(im,1) * IM_LEN(im,2) *
sizeof (IM_PIXTYPE(im))
memstat = dp_memstat (cache, req_size, old_size)
if (memstat == YES)
call dp_pcache (im, INDEFI, buf_size)
# Open the input photometry table and read in the photometry.
if (fntgfnb (alist, Memc[photfile], SZ_FNAME) == EOF)
call strcpy (DEF_DEFNAME, Memc[photfile], SZ_FNAME)
root = fnldir (Memc[photfile], Memc[outfname], SZ_FNAME)
if (strncmp (DEF_DEFNAME, Memc[photfile+root], DEF_LENDEFNAME) ==
0 || root == strlen (Memc[photfile]))
call dp_inname (Memc[image], Memc[outfname], "mag",
Memc[outfname], SZ_FNAME)
else
call strcpy (Memc[photfile], Memc[outfname], SZ_FNAME)
ap_text = itob (access (Memc[outfname], 0, TEXT_FILE))
if (ap_text)
apd = open (Memc[outfname], READ_ONLY, TEXT_FILE)
else
apd = tbtopn (Memc[outfname], READ_ONLY, 0)
call dp_wgetapert (dao, im, apd, DP_MAXNSTAR(dao), ap_text)
call dp_sets (dao, INPHOTFILE, Memc[outfname])
# Open the output PSTSELECT file. If the output is "default",
# dir$default or a directory specification then the extension .pst
# is added to the image name and a suitable version number is
# appended to the output name.
if (fntgfnb (olist, Memc[pstfile], SZ_FNAME) == EOF)
call strcpy (DEF_DEFNAME, Memc[pstfile], SZ_FNAME)
root = fnldir (Memc[pstfile], Memc[outfname], SZ_FNAME)
if (strncmp (DEF_DEFNAME, Memc[pstfile + root], DEF_LENDEFNAME) ==
0 || root == strlen (Memc[pstfile]))
call dp_outname (Memc[image], Memc[outfname], "pst",
Memc[outfname], SZ_FNAME)
else
call strcpy (Memc[pstfile], Memc[outfname], SZ_FNAME)
if (ap_text)
pfd = open (Memc[outfname], NEW_FILE, TEXT_FILE)
else
pfd = tbtopn (Memc[outfname], NEW_FILE, 0)
call dp_sets (dao, OUTPHOTFILE, Memc[outfname])
if (DP_VERBOSE(dao) == YES) {
call printf ("\nSelecting PSF stars for image %s\n")
call pargstr (Memc[image])
call dp_stats (dao, INPHOTFILE, Memc[outfname], SZ_FNAME)
call printf ("\t%d stars read from file %s\n\n")
call pargi (dp_stati (dao, APNUM))
call pargstr (Memc[outfname])
}
# Now select the PSF stars.
if (Memc[curfile] != EOS)
call dp_gpstars (dao, im, apd, pfd, ap_text, maxnpsf, NULL,
mgd, NULL, false, false, true)
else if (interactive)
call dp_gpstars (dao, im, apd, pfd, ap_text, maxnpsf, gd, mgd,
id, mkstars, true, false)
else
call dp_gpstars (dao, im, apd, pfd, ap_text, maxnpsf, NULL,
mgd, NULL, false, false, false)
# Close the input image.
call imunmap (im)
# Close the photometry file.
if (ap_text)
call close (apd)
else
call tbtclo (apd)
# Close the output table.
if (ap_text)
call close (pfd)
else
call tbtclo (pfd)
# Uncache memory.
call fixmem (old_size)
}
# Close up the graphics and display streams.
if (id == gd && id != NULL)
call gclose (id)
else {
if (gd != NULL)
call gclose (gd)
if (id != NULL)
call gclose (id)
}
# Close the metacode plot files.
if (mgd != NULL)
call gclose (mgd)
if (pmgd != NULL)
call close (pmgd)
# Close the image/file lists.
call imtclose (imlist)
call fntclsb (alist)
call fntclsb (olist)
# Close the PSF structure.
call dp_fitclose (dao)
# Close the PSF fitting structure.
call dp_psfclose (dao)
# Free the photometry structure.
call dp_apclose (dao)
# Free the daophot structure.
call dp_free (dao)
call sfree(sp)
end
|