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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
|
include <ctype.h>
include <gset.h>
include <imhdr.h>
include "../lib/apphot.h"
include "../lib/display.h"
include "../lib/fitsky.h"
include "../lib/polyphot.h"
define HELPFILE "apphot$polyphot/polyphot.key"
# AP_YPHOT -- Compute the flux inside polygonal apertures.
int procedure ap_yphot (py, im, cl, pl, gd, id, out, stid, interactive, cache)
pointer py # pointer to apphot structure
pointer im # pointer to IRAF image
int cl # coordinate file descriptor
int pl # starlist file descriptor
pointer gd # pointer to graphcis stream
pointer id # pointer to image display stream
int out # output file descriptor
int stid # output file sequence number
int interactive # interactive mode
int cache # cache the input image pixels
real wx, wy
pointer sp, x, y, xout, yout, cmd
int nvertices, cier, sier, pier, wcs, key, ip, colonkey
int prev_num, req_num, ptid, ltid, delim, newlist, newimage
int newcenterbuf, newcenter, newskybuf, newsky, newmagbuf, newmag
int req_size, old_size, buf_size, memstat
real apstatr()
int ap_ymkpoly(), ap_yfit(), clgcur(), apfitsky(), aprefitsky()
int apstati(), ctoi(), ap_ynextobj(), ap_ycenter(), ap_yrecenter()
int apgqverify(), apgtverify(), ap_yradsetup(), apnew(), ap_avsky()
int ap_memstat(), sizeof()
bool fp_equalr()
data delim /';'/
define endswitch_ 99
begin
# Allocate temporary space.
call smark (sp)
call salloc (cmd, SZ_LINE, TY_CHAR)
call salloc (x, MAX_NVERTICES + 1, TY_REAL)
call salloc (y, MAX_NVERTICES + 1, TY_REAL)
call salloc (xout, MAX_NVERTICES + 1, TY_REAL)
call salloc (yout, MAX_NVERTICES + 1, TY_REAL)
# Initialize the cursor read.
key = ' '
Memc[cmd] = EOS
# Initialize the fit.
newimage = NO
newcenterbuf = YES; newcenter = YES
newskybuf = YES; newsky = YES
newmagbuf = YES; newmag = YES
cier = AP_OK; sier = AP_OK; pier = AP_OK
# Initialize the sequencing.
newlist = NO
ptid = 0
ltid = 0
# Loop over the polygon file.
nvertices = 0
while (clgcur ("icommands", wx, wy, wcs, key, Memc[cmd], SZ_LINE) !=
EOF) {
# Store the current coordinates.
call ap_vtol (im, wx, wy, wx, wy, 1)
call apsetr (py, CWX, wx)
call apsetr (py, CWY, wy)
# Has the polygon moved ?
if (apnew (py, wx, wy, apstatr (py, PYCX), apstatr (py, PYCY),
newlist) == YES) {
newcenterbuf = YES; newcenter = YES
newskybuf = YES; newsky = YES
newmagbuf = YES; newmag = YES
}
# Loop over the colon commands.
switch (key) {
# Quit.
case 'q':
if (interactive == YES) {
if (apgqverify ("polyphot", py, key) == YES) {
call sfree (sp)
return (apgtverify (key))
}
} else {
call sfree (sp)
return (NO)
}
# Print the help page.
case '?':
if ((id != NULL) && (id == gd))
call gpagefile (id, HELPFILE, "")
else if (interactive == YES)
call pagefile (HELPFILE, "[space=morehelp,q=quit,?=help]")
# Plot a centered stellar radial profile.
case 'd':
if (interactive == YES)
call ap_qrad (py, im, wx, wy, gd)
# Setup the parameters using a radial profile plot
case 'i':
if (interactive == YES) {
nvertices = ap_yradsetup (py, im, id, gd, out, stid,
Memr[x], Memr[y], MAX_NVERTICES)
newlist = NO
newcenterbuf = YES; newcenter = YES
newskybuf = YES; newsky = YES
newmagbuf = YES; newmag = YES
}
# Verify the critical parameters.
case 'v':
call ap_yconfirm (py, out, stid)
newcenterbuf = YES; newcenter = YES
newskybuf = YES; newsky = YES
newmagbuf = YES; newmag = YES
# Define a polygon interactively.
case 'g':
if (interactive == YES) {
if (id == gd)
nvertices = ap_ymkpoly (py, im, id, Memr[x], Memr[y],
MAX_NVERTICES, NO)
else
nvertices = ap_ymkpoly (py, im, id, Memr[x], Memr[y],
MAX_NVERTICES, YES)
if (id != NULL) {
if (id == gd)
call gflush (id)
else
call gframe (id)
}
newlist = NO
newcenterbuf = YES; newcenter = YES
newskybuf = YES; newsky = YES
newmagbuf = YES; newmag = YES
}
# Print error messages.
case 'e':
if (interactive == YES)
call ap_pyerrors (py, cier, sier, pier)
# Rewind the polygon and coordinate lists.
case 'r':
if (pl != NULL) {
call seek (pl, BOF)
if (cl != NULL)
call seek (cl, BOF)
ptid = 0
ltid = 0
} else if (interactive == YES)
call printf ("No polygon list\n")
# Show/set polyphot parameters.
case ':':
for (ip = 1; IS_WHITE(Memc[cmd+ip-1]); ip = ip + 1)
;
colonkey = Memc[cmd+ip-1]
switch (colonkey) {
case 'm', 'n':
# Show/set polyphot parameters
if (Memc[cmd+ip] != EOS && Memc[cmd+ip] != ' ') {
call ap_ycolon (py, im, pl, cl, out, stid, ptid, ltid,
Memc[cmd], newimage, newcenterbuf, newcenter,
newskybuf, newsky, newmagbuf, newmag)
goto endswitch_
}
# Measure the next object in the list.
if (pl != NULL) {
if (interactive == YES)
call printf ("No polygon list\n")
goto endswitch_
}
# Get the next polygon.
ip = ip + 1
prev_num = ltid
if (ctoi (Memc[cmd], ip, req_num) <= 0)
req_num = ltid + 1
nvertices = ap_ynextobj (py, im, id, pl, cl, delim, Memr[x],
Memr[y], MAX_NVERTICES, prev_num, req_num, ltid, ptid)
if (nvertices == EOF) {
if (interactive == YES)
call printf (
"End of polygon list, use r key to rewind\n")
goto endswitch_
}
# Move to the next object.
newlist = YES
if (colonkey == 'm') {
newcenterbuf = YES; newcenter = YES
newskybuf = YES; newsky = YES
newmagbuf = YES; newmag = YES
goto endswitch_
}
# Fit the center, sky and measure polygon.
cier = ap_ycenter (py, im, apstatr (py, PYCX), apstatr (py,
PYCY), Memr[x], Memr[y], nvertices + 1)
sier = apfitsky (py, im, apstatr (py, PYCX), apstatr (py,
PYCY), NULL, gd)
pier = ap_yfit (py, im, Memr[x], Memr[y], nvertices + 1,
apstatr (py, SKY_MODE), apstatr (py, SKY_SIGMA),
apstati (py, NSKY))
if (interactive == YES)
call ap_qyprint (py, cier, sier, pier)
# Draw the polygon.
if (id != NULL) {
call appymark (py, id, Memr[x], Memr[y], nvertices + 1,
apstati (py, MKCENTER), apstati (py, MKSKY),
apstati (py, MKPOLYGON))
if (id == gd)
call gflush (id)
else
call gframe (id)
}
# Write the results to output.
if (stid == 1)
call ap_param (py, out, "polyphot")
switch (apstati(py,WCSOUT)) {
case WCS_WORLD, WCS_PHYSICAL:
call ap_ltoo (py, Memr[x], Memr[y], Memr[xout],
Memr[yout], nvertices + 1)
case WCS_TV:
call ap_ltov (im, Memr[x], Memr[y], Memr[xout],
Memr[yout], nvertices + 1)
default:
call amovr (Memr[x], Memr[xout], nvertices + 1)
call amovr (Memr[y], Memr[yout], nvertices + 1)
}
if (newlist == YES)
call ap_yprint (py, out, Memr[xout], Memr[yout],
nvertices, stid, ltid, ptid, cier, sier, pier)
else
call ap_yprint (py, out, Memr[xout], Memr[yout],
nvertices, stid, 0, ptid, cier, sier, pier)
# Set up for the next object.
stid = stid + 1
newcenterbuf = NO; newcenter = NO
newskybuf = NO; newsky = NO
newmagbuf = NO; newmag = NO
# Show/set polyphot parameters.
default:
call ap_ycolon (py, im, pl, cl, out, stid, ptid, ltid,
Memc[cmd], newimage, newcenterbuf, newcenter,
newskybuf, newsky, newmagbuf, newmag)
}
# Reestablish the image display viewport and window.
if (newimage == YES) {
if ((id != NULL) && (id != gd))
call ap_gswv (id, Memc[cmd], im, 4)
req_size = MEMFUDGE * IM_LEN(im,1) * IM_LEN(im,2) *
sizeof (IM_PIXTYPE(im))
memstat = ap_memstat (cache, req_size, old_size)
if (memstat == YES)
call ap_pcache (im, INDEFI, buf_size)
}
newimage = NO
# Get measure next object in the list.
case 'm', 'n':
if (pl == NULL) {
if (interactive == YES)
call printf ("No polygon list\n")
goto endswitch_
}
# Get the next polygon.
prev_num = ltid
req_num = ltid + 1
nvertices = ap_ynextobj (py, im, id, pl, cl, delim, Memr[x],
Memr[y], MAX_NVERTICES, prev_num, req_num, ltid, ptid)
if (nvertices == EOF) {
if (interactive == YES)
call printf (
"End of polygon list, use r key to rewind\n")
goto endswitch_
}
# Move to next object.
newlist = YES
if (key == 'm') {
newcenterbuf = YES; newcenter = YES
newskybuf = YES; newsky = YES
newmagbuf = YES; newmag = YES
goto endswitch_
}
# Measure next object.
cier = ap_ycenter (py, im, apstatr (py, PYCX), apstatr (py,
PYCY), Memr[x], Memr[y], nvertices + 1)
sier = apfitsky (py, im, apstatr (py, PYCX), apstatr (py,
PYCY), NULL, gd)
pier = ap_yfit (py, im, Memr[x], Memr[y], nvertices + 1,
apstatr (py, SKY_MODE), apstatr (py, SKY_SIGMA),
apstati (py, NSKY))
if (interactive == YES)
call ap_qyprint (py, cier, sier, pier)
# Draw the polygon.
if (id != NULL) {
call appymark (py, id, Memr[x], Memr[y], nvertices + 1,
apstati (py, MKCENTER), apstati (py, MKSKY),
apstati (py, MKPOLYGON))
if (id == gd)
call gflush (id)
else
call gframe (id)
}
# Write the results to output.
if (stid == 1)
call ap_param (py, out, "polyphot")
switch (apstati(py,WCSOUT)) {
case WCS_WORLD, WCS_PHYSICAL:
call ap_ltoo (py, Memr[x], Memr[y], Memr[xout], Memr[yout],
nvertices + 1)
case WCS_TV:
call ap_ltov (im, Memr[x], Memr[y], Memr[xout], Memr[yout],
nvertices + 1)
default:
call amovr (Memr[x], Memr[xout], nvertices + 1)
call amovr (Memr[y], Memr[yout], nvertices + 1)
}
if (newlist == YES)
call ap_yprint (py, out, Memr[xout], Memr[yout], nvertices,
stid, ltid, ptid, cier, sier, pier)
else
call ap_yprint (py, out, Memr[xout], Memr[yout], nvertices,
stid, 0, ptid, cier, sier, pier)
# Set up for the next object.
stid = stid + 1
newcenterbuf = NO; newcenter = NO
newskybuf = NO; newsky = NO
newmagbuf = NO; newmag = NO
# Process the remainder of the list.
case 'l':
if (pl != NULL) {
call ap_ybphot (py, im, cl, pl, out, stid, ltid, ptid, id,
YES)
if (id != NULL) {
if (id == gd)
call gflush (id)
else
call gframe (id)
}
} else if (interactive == YES)
call printf ("No polygon list\n")
# Save current parameters in the pset file.
case 'w':
call ap_pypars (py)
# Center the current polygon around the cursor poition.
case 'c':
if (newcenterbuf == YES)
cier = ap_ycenter (py, im, wx, wy, Memr[x], Memr[y],
nvertices + 1)
else if (newcenter == YES)
cier = ap_yrecenter (py, im, Memr[x], Memr[y],
nvertices + 1, cier)
if (interactive == YES)
call ap_qcenter (py, cier)
if (id != NULL) {
call apmark (py, id, apstati (py, MKCENTER), NO, NO)
if (id == gd)
call gflush (id)
else
call gframe (id)
}
newcenterbuf = NO; newcenter = NO
# Fit the sky around the cursor position.
case 't':
if (newskybuf == YES || ! fp_equalr (wx,
apstatr (py, SXCUR)) || ! fp_equalr (wy, apstatr (py,
SYCUR)))
sier = apfitsky (py, im, wx, wy, NULL, gd)
else if (newsky == YES)
sier = aprefitsky (py, im, gd)
if (interactive == YES)
call ap_qspsky (py, sier)
if (id != NULL) {
call apmark (py, id, NO, apstati (py, MKSKY), NO)
if (id == gd)
call gflush (id)
else
call gframe (id)
}
newskybuf = NO; newsky = NO
# Compute the average of several sky measurements around
# different cursor postions.
case 'a':
sier = ap_avsky (py, im, stid, NULL, id, gd, interactive)
if (interactive == YES)
call ap_qaspsky (py, sier)
newskybuf = NO; newsky = NO
# Fit sky in an annulus around the current polygon.
case 's':
if (newskybuf == YES || ! fp_equalr (apstatr (py, PYCX),
apstatr (py, SXCUR)) || ! fp_equalr (apstatr (py, PYCY),
apstatr (py, SYCUR)))
sier = apfitsky (py, im, apstatr (py, PYCX), apstatr (py,
PYCY), NULL, gd)
else if (newsky == YES)
sier = aprefitsky (py, im, gd)
if (interactive == YES)
call ap_qspsky (py, sier)
if (id != NULL) {
call apmark (py, id, NO, apstati (py, MKSKY), NO)
if (id == gd)
call gflush (id)
else
call gframe (id)
}
newskybuf = NO; newsky = NO
# Compute the magnitudes of current polygon using the current sky.
case 'p', 'o':
if (newcenterbuf == YES)
cier = ap_ycenter (py, im, wx, wy, Memr[x], Memr[y],
nvertices + 1)
else if (newcenter == YES)
cier = ap_yrecenter (py, im, Memr[x], Memr[y],
nvertices + 1, cier)
pier = ap_yfit (py, im, Memr[x], Memr[y], nvertices + 1,
apstatr (py, SKY_MODE), apstatr (py, SKY_SIGMA),
apstati (py, NSKY))
if (interactive == YES)
call ap_qyprint (py, cier, sier, pier)
if (id != NULL) {
call appymark (py, id, Memr[x], Memr[y], nvertices + 1,
NO, NO, apstati (py, MKPOLYGON))
if (id == gd)
call gflush (id)
else
call gframe (id)
}
newcenterbuf = NO; newcenter = NO
newmagbuf = NO; newmag = NO
# Write the results.
if (key == 'o') {
if (stid == 1)
call ap_param (py, out, "polyphot")
switch (apstati(py,WCSOUT)) {
case WCS_WORLD, WCS_PHYSICAL:
call ap_ltoo (py, Memr[x], Memr[y], Memr[xout],
Memr[yout], nvertices + 1)
case WCS_TV:
call ap_ltov (im, Memr[x], Memr[y], Memr[xout],
Memr[yout], nvertices + 1)
default:
call amovr (Memr[x], Memr[xout], nvertices + 1)
call amovr (Memr[y], Memr[yout], nvertices + 1)
}
if (newlist == YES)
call ap_yprint (py, out, Memr[xout], Memr[yout],
nvertices, stid, ltid, ptid, cier, sier, pier)
else
call ap_yprint (py, out, Memr[xout], Memr[yout],
nvertices, stid, 0, ptid, cier, sier, pier)
stid = stid + 1
}
# Center, compute the sky and the magnitudes and save the results.
case 'h', 'j', 'f', ' ':
# Compute the centers.
if (key == 'f' || key == ' ') {
if (newcenterbuf == YES)
cier = ap_ycenter (py, im, wx, wy, Memr[x], Memr[y],
nvertices + 1)
else if (newcenter == YES)
cier = ap_yrecenter (py, im, Memr[x], Memr[y],
nvertices + 1, cier)
} else {
if (newcenterbuf == YES)
cier = ap_ycenter (py, im, apstatr (py, PYCX),
apstatr (py, PYCY), Memr[x], Memr[y], nvertices + 1)
else if (newcenter == YES)
cier = ap_yrecenter (py, im, Memr[x], Memr[y],
nvertices + 1, cier)
}
# Compute the sky values and the magnitudes.
if (newskybuf == YES || ! fp_equalr (apstatr (py,
PYCX), apstatr (py, SXCUR)) || ! fp_equalr (apstatr (py,
PYCY), apstatr (py, SYCUR))) sier = apfitsky (py, im,
apstatr (py, PYCX), apstatr (py, PYCY), NULL, gd)
else if (newsky == YES)
sier = aprefitsky (py, im, gd)
pier = ap_yfit (py, im, Memr[x], Memr[y], nvertices + 1,
apstatr (py, SKY_MODE), apstatr (py, SKY_SIGMA),
apstati (py, NSKY))
if (interactive == YES)
call ap_qyprint (py, cier, sier, pier)
if (id != NULL) {
call appymark (py, id, Memr[x], Memr[y], nvertices + 1,
apstati (py, MKCENTER), apstati (py, MKSKY),
apstati (py, MKPOLYGON))
if (id == gd)
call gflush (id)
else
call gframe (id)
}
newcenterbuf = NO; newcenter = NO
newskybuf = NO; newsky = NO
newmagbuf = NO; newmag = NO
# Write the results to an output file.
if (key == ' ' || key == 'j') {
if (stid == 1)
call ap_param (py, out, "polyphot")
switch (apstati(py,WCSOUT)) {
case WCS_WORLD, WCS_PHYSICAL:
call ap_ltoo (py, Memr[x], Memr[y], Memr[xout],
Memr[yout], nvertices + 1)
case WCS_TV:
call ap_ltov (im, Memr[x], Memr[y], Memr[xout],
Memr[yout], nvertices + 1)
default:
call amovr (Memr[x], Memr[xout], nvertices + 1)
call amovr (Memr[y], Memr[yout], nvertices + 1)
}
if (newlist == YES)
call ap_yprint (py, out, Memr[xout], Memr[yout],
nvertices, stid, ltid, ptid, cier, sier, pier)
else
call ap_yprint (py, out, Memr[xout], Memr[yout],
nvertices, stid, 0, ptid, cier, sier, pier)
stid = stid + 1
}
default:
call printf ("Unknown or ambigous keystroke command\n")
}
endswitch_
# Reset the keystroke and command defaults.
key = ' '
Memc[cmd] = EOS
call apsetr (py, WX, apstatr (py, CWX))
call apsetr (py, WY, apstatr (py, CWY))
}
end
|