aboutsummaryrefslogtreecommitdiff
path: root/noao/digiphot/apphot/radprof/apradprof.x
blob: 10448af27228291a20b10075499d70c5cc4ea06f (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
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
include <ctype.h>
include <gset.h>
include <imhdr.h>
include "../lib/apphot.h"
include "../lib/display.h"
include "../lib/center.h"
include "../lib/fitsky.h"
include "../lib/radprof.h"

define	HELPFILE	"apphot$radprof/radprof.key"

# AP_RADPROF -- Procedure to determine radial profiles for a list of objects
# in a list of images.

int procedure ap_radprof (ap, im, cl, gd, mgd, id, out, stid, interactive,
	cache)

pointer ap			# pointer to apphot structure
pointer	im			# pointer to IRAF image
int	cl			# starlist file descriptor
pointer	gd			# pointer to graphcis descriptor
pointer	mgd			# pointer to plot metacode 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, xlist, ylist
pointer	sp, cmd
int	wcs, key, oid, ltid, newlist, colonkey, req_size, buf_size, old_size
int	newimage, newskybuf, newsky, newcenterbuf, newcenter, newbuf, newfit
int	ip, prev_num, req_num, cier, sier, pier, rier, memstat

real	apstatr()
int	clgcur(), apfitsky(), aprefitsky(), apfitcenter(), aprefitcenter()
int	apstati(), apgscur(), ap_frprof(), ctoi(), apgqverify(), apgtverify()
int	apnew(), ap_avsky(), sizeof(), ap_memstat()
bool	fp_equalr()

define  endswitch_ 99

begin
	# Initialize.
	call smark (sp)
	call salloc (cmd, SZ_LINE, TY_CHAR)

	# Initialize the cursor command.
	key = ' '
	Memc[cmd] = EOS

	# Initialize the fit.
	newimage = NO
	newcenterbuf = YES; newcenter = YES
	newskybuf = YES; newsky = YES
	newbuf = YES; newfit = YES
	cier = AP_OK; sier = AP_OK; pier = AP_OK; rier = AP_OK

	# Initialize the sequencing.
	newlist = NO
	ltid = 0

	# Loop over the coordinate file.
	while (clgcur ("icommands", wx, wy, wcs, key, Memc[cmd], SZ_LINE) !=
	    EOF) {

	    # Store the cursor coords.
	    call ap_vtol (im, wx, wy, wx, wy, 1)
	    call apsetr (ap, CWX, wx)
	    call apsetr (ap, CWY, wy)

	    # Test to see if the cursor has moved.
	    if (apnew (ap, wx, wy, xlist, ylist, newlist) == YES) {
		newcenterbuf = YES; newcenter = YES
		newskybuf = YES; newsky = YES
		newbuf = YES; newfit = YES
	    }

	    # Switch on the keystroke commands.
	    switch (key) {

	    # Quit.
	    case 'q':
		if (interactive == YES) {
		    if (apgqverify ("radprof", ap, key) == YES) {
			call sfree (sp)
			return (apgtverify (key))
		    }
	        } else {
		    call sfree (sp)
		    return (NO)
	        }

	    # Print the errors.
	    case 'e':
		if (interactive == YES)
		    call ap_rferrors (ap, cier, sier, pier, rier)

	    # 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]")

	    # Rewind the list.
	    case 'r':
		if (cl != NULL) {
		    call seek (cl, BOF)
		    ltid = 0
		} else if (interactive == YES)
		    call printf ("No coordinate list\n")

	    # Move, measure next object in the coordinate list.
	    case 'm', 'n':

		# No coordinate file.
		if (cl == NULL) {
                    if (interactive == YES)
                        call printf ("No coordinate list\n")
                    goto endswitch_
		}

		# Need to rewind the coordinate file.
		prev_num = ltid
		req_num = ltid + 1
		if (apgscur (cl, id, xlist, ylist, prev_num, req_num,
		    ltid) == EOF) {
                    if (interactive == YES)
                        call printf (
                            "End of coordinate list, use r key to rewind\n")
                    goto endswitch_
		}

		# Convert coordinates if necessary.
                switch (apstati (ap, WCSIN)) {
                case WCS_PHYSICAL, WCS_WORLD:
                    call ap_itol (ap,  xlist, ylist, xlist, ylist, 1)
                case WCS_TV:
                    call ap_vtol (im, xlist, ylist, xlist, ylist, 1)
                default:
                    ;
                }

		# Move to the next object.
		newlist = YES
		if (key == 'm') {
		    newcenterbuf = YES; newcenter = YES
		    newskybuf = YES; newsky = YES
		    newbuf = YES; newfit = YES
                    goto endswitch_
		}

		# Measure next object.
		cier = apfitcenter (ap, im, xlist, ylist)
		sier = apfitsky (ap, im, apstatr (ap, XCENTER), apstatr (ap,
		    YCENTER), NULL, gd)
		rier = ap_frprof (ap, im, apstatr (ap, XCENTER), apstatr (ap,
		    YCENTER), pier)
		call aprmark (ap, id, apstati (ap, MKCENTER), apstati (ap,
		    MKSKY), apstati (ap, MKAPERT))
	        if (id != NULL) {
		    if (id == gd)
		    	call gflush (id)
		    else
		        call gframe (id)
		}
	        call ap_rpplot (ap, stid, gd, apstati (ap, RADPLOTS))
		if (interactive == YES)
		    call ap_qprprof (ap, cier, sier, pier, rier)
		if (stid == 1)
		    call ap_param (ap, out, "radprof")
		call ap_prprof (ap, out, stid, ltid, cier, sier, pier, rier)
		call ap_rpplot (ap, stid, mgd, YES)
		stid = stid + 1
		newcenterbuf = NO; newcenter = NO
		newskybuf = NO; newsky = NO
		newbuf = NO; newfit = NO

	    # Process the remainder of the list.
	    case 'l':
		if (cl != NULL) {
		    oid = stid
		    ltid = ltid + 1
		    call ap_bradprof (ap, im, cl, id, gd, mgd, out, stid, ltid,
		        YES)
		    ltid = ltid + stid - oid + 1
		    if (id != NULL) {
			if (id == gd)
			    call gflush (id)
			else
			    call gframe (id)
		    }
		} else if (interactive == YES)
		    call printf ("No coordinate list\n")

	    # Process radprof colon commands.
	    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 radprof parameters.
		    if (Memc[cmd+ip] != EOS && Memc[cmd+ip] != ' ') {
		        call ap_rpcolon (ap, im, cl, out, stid, ltid, Memc[cmd],
			    newimage, newcenterbuf, newcenter, newskybuf,
			    newsky, newbuf, newfit)
			goto endswitch_
		    }

		    # Process the next object.
		    if (cl == NULL) {
                        if (interactive == YES)
                            call printf ("No coordinate list\n")
                        goto endswitch_
		    }

		    # Get next object from the list.
		    ip = ip + 1
		    prev_num = ltid
		    if (ctoi (Memc[cmd], ip, req_num) <= 0)
		        req_num = ltid + 1

		    # Fetch next object from the list.
		    if (apgscur (cl, id, xlist, ylist, prev_num, req_num,
			ltid) == EOF) {
                        if (interactive == YES)
                            call printf (
                            "End of coordinate list, use r key to rewind\n")
                        goto endswitch_

		    }

                    # Convert the coordinates.
                    switch (apstati (ap, WCSIN)) {
                    case WCS_PHYSICAL, WCS_WORLD:
                        call ap_itol (ap,  xlist, ylist, xlist, ylist, 1)
                    case WCS_TV:
                        call ap_vtol (im, xlist, ylist, xlist, ylist, 1)
                    default:
                        ;
                    }

		    # Move to next object.
		    newlist = YES
		    if (colonkey == 'm') {
		        newcenterbuf = YES; newcenter = YES
		        newskybuf = YES; newsky = YES
		        newbuf = YES; newfit = YES
		    }

		    # Measure the next object.
		    cier = apfitcenter (ap, im, xlist, ylist)
		    sier = apfitsky (ap, im, apstatr (ap, XCENTER),
			apstatr (ap, YCENTER), NULL, gd)
		    rier = ap_frprof (ap, im, apstatr (ap, XCENTER),
			apstatr (ap, YCENTER), pier)
		    call aprmark (ap, id, apstati (ap, MKCENTER), apstati (ap,
			MKSKY), apstati (ap, MKAPERT))
		    if (id != NULL) {
		        if (id == gd)
		    	    call gflush (id)
			else
			    call gframe (id)
		    }
		    call ap_rpplot (ap, stid, gd, apstati (ap, RADPLOTS))
		    if (interactive == YES)
		        call ap_qprprof (ap, cier, sier, pier, rier)

		    if (stid == 1)
		        call ap_param (ap, out, "radprof")
		    call ap_prprof (ap, out, stid, ltid, cier, sier, pier, rier)
		    call ap_rpplot (ap, stid, mgd, YES)
		    stid = stid + 1
		     newcenterbuf = NO; newcenter = NO
		     newskybuf = NO; newsky = NO
		     newbuf = NO; newfit = NO

		default:
		    call ap_rpcolon (ap, im, cl, out, stid, ltid, Memc[cmd],
		        newimage, newcenterbuf, newcenter, newskybuf, newsky,
			newbuf, newfit)
		}

		# Reestablish the image 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

	    # Save the parameters.
	    case 'w':
		call ap_rpars (ap)

	    # Plot a simple centered radial profile.
	    case 'd':
		if (interactive == YES) {
		    call ap_qrad (ap, im, wx, wy, gd)
		    newcenterbuf = YES; newcenter = YES
		    newskybuf = YES; newsky = YES
		    newbuf = YES; newfit = YES
		}
		

	    # Setup the radial profile fitting parameters interactively.
	    case 'i':
		if (interactive == YES) {
		    call ap_profsetup (ap, im, wx, wy, gd, out, stid)
		    newcenterbuf = YES; newcenter = YES
		    newskybuf = YES; newsky = YES
		    newbuf = YES; newfit = YES
		}

	    # Verify the critical radprof parameters.
	    case 'v':
		call ap_rconfirm (ap, out, stid)
		newcenterbuf = YES; newcenter = YES
		newskybuf = YES; newsky = YES
		newbuf = YES; newfit = YES

	     # Fit the center around the current cursor value.
	     case 'c':
		if (newcenterbuf == YES)
		    cier = apfitcenter (ap, im, wx, wy)
		else if (newcenter == YES)
		    cier = aprefitcenter (ap, im, cier)
		call aprmark (ap, id, apstati (ap, MKCENTER), NO, NO)
		if (id != NULL) {
		    if (id == gd)
			call gflush (id)
		    else
			call gframe (id)
		}
		call ap_cplot (ap, stid, gd, apstati (ap, RADPLOTS))
		if (interactive == YES)
		    call ap_qcenter (ap, cier)
		newcenterbuf = NO; newcenter = NO

	    # Fit the sky around the current cursor value.
	    case 't':
	        if (newskybuf == YES || ! fp_equalr (wx,
		    apstatr (ap, SXCUR)) || ! fp_equalr (wy, apstatr (ap,
		    SYCUR)))
		    sier = apfitsky (ap, im, wx, wy, NULL, gd)
	        else if (newsky == YES)
		    sier = aprefitsky (ap, im, gd)
		call aprmark (ap, id, NO, apstati (ap, MKSKY), NO)
		if (id != NULL) {
		    if (id == gd)
			call gflush (id)
		    else
			call gframe (id)
		}
		call ap_splot (ap, stid, gd, apstati (ap, RADPLOTS))
		if (interactive == YES)
		    call ap_qspsky (ap, sier)
		newskybuf = NO; newsky = NO

	    # Compute the average of several sky measurements around
            # different cursor postions.
            case 'a':
                sier = ap_avsky (ap, im, stid, NULL, id, gd, interactive)
                if (interactive == YES)
                    call ap_qaspsky (ap, sier)
                newskybuf = NO; newsky = NO

	     # Fit the sky around derived center value. 
	     case 's':
	        if (newskybuf == YES || ! fp_equalr (apstatr (ap, XCENTER),
		    apstatr (ap, SXCUR)) || ! fp_equalr (apstatr (ap,
		    SYCUR), apstatr (ap, YCENTER)))
		    sier = apfitsky (ap, im, apstatr (ap, XCENTER),
		        apstatr (ap, YCENTER), NULL, gd)
		else if (newsky == YES)
		    sier = aprefitsky (ap, im, gd)
		call aprmark (ap, id, NO, apstati (ap, MKSKY), NO)
		if (id != NULL) {
		    if (id == gd)
			call gflush (id)
		    else
			call gframe (id)
		}
		call ap_splot (ap, stid, gd, apstati (ap, RADPLOTS))
		if (interactive == YES)
		    call ap_qspsky (ap, sier)
		newskybuf = NO; newsky = NO

	    # Compute magnitudes around the current cursor position using
	    # the current sky.
	    case 'p', 'o':
		if (newcenterbuf == YES)
		    cier = apfitcenter (ap, im, wx, wy)
		else if (newcenter == YES)
		    cier = aprefitcenter (ap, im, cier)
		call aprmark (ap, id, apstati (ap, MKCENTER), NO,
		    apstati (ap, MKAPERT))
		if (id != NULL) {
		    if (id == gd)
			call gflush (id)
		    else
			call gframe (id)
		}
	        if (newfit == YES || newbuf == YES || ! fp_equalr (apstatr (ap,
		    XCENTER), apstatr (ap, RPXCUR)) ||
		    ! fp_equalr (apstatr (ap, RPYCUR), apstatr (ap, YCENTER)))
		    rier = ap_frprof (ap, im, apstatr (ap, XCENTER),
		        apstatr (ap, YCENTER), pier)
		if (interactive == YES)
		    call ap_qprprof (ap, cier, sier, pier, rier)
		newcenterbuf = NO; newcenter = NO
		newbuf = NO; newfit = NO

		if (key == 'o') {
		    if (stid == 1)
		        call ap_param (ap, out, "radprof")
		    if (newlist == YES)
		        call ap_prprof (ap, out, stid, ltid, cier, sier, pier,
			    rier)
		    else
		        call ap_prprof (ap, out, stid, 0, cier, sier, pier,
			    rier)
		    call ap_rpplot (ap, stid, mgd, YES)
		    stid = stid + 1
		}

	    # Center, fit the sky, and compute magnitudes.
	    # Compute the centers, fit the sky, compute the magnitudes
	    # and save the results.
	    case 'f', ' ':
		if (newcenterbuf == YES)
		    cier = apfitcenter (ap, im, wx, wy)
		else if (newcenter == YES)
		    cier = aprefitcenter (ap, im, cier)
		if (newskybuf == YES || ! fp_equalr (apstatr (ap, XCENTER),
		    apstatr (ap, SXCUR)) || ! fp_equalr (apstatr (ap, YCENTER),
		    apstatr (ap, SYCUR)))
		    sier = apfitsky (ap, im, apstatr (ap, XCENTER),
		        apstatr (ap, YCENTER), NULL, gd)
		else if (newsky == YES)
		    sier = aprefitsky (ap, im, gd)

		if (newfit == YES || newbuf == YES || ! fp_equalr (apstatr (ap,
		    XCENTER), apstatr (ap, RPXCUR)) || ! fp_equalr (apstatr (ap,
		    YCENTER), apstatr (ap, RPYCUR)))
		    rier = ap_frprof (ap, im, apstatr (ap, XCENTER),
		        apstatr (ap, YCENTER), pier)
		call aprmark (ap, id, apstati (ap, MKCENTER), apstati (ap,
		    MKSKY), apstati (ap, MKAPERT))
		if (id != NULL) {
		    if (id == gd)
			call gflush (id)
		    else
			call gframe (id)
		}
		call ap_rpplot (ap, stid, gd, apstati (ap, RADPLOTS))
		if (interactive == YES)
		    call ap_qprprof (ap, cier, sier, pier, rier)

		newcenterbuf = NO; newcenter = NO
		newskybuf = NO; newsky = NO
		newbuf = NO; newfit = NO

		if (key == ' ') {
		    if (stid == 1)
		        call ap_param (ap, out, "radprof")
		    if (newlist == YES)
		        call ap_prprof (ap, out, stid, ltid, cier, sier, pier,
			    rier)
		    else
		        call ap_prprof (ap, out, stid, 0, cier, sier, pier,
			    rier)
		    call ap_rpplot (ap, stid, mgd, YES)
		    stid = stid + 1
		}

	    default:
		# do nothing
		call printf ("Print unknown or ambiguous colon command\n")
	    }

endswitch_
	    # Prepare for the next object.
	    key = ' '
	    Memc[cmd] = EOS
	    call apsetr (ap, WX, apstatr (ap, CWX))
	    call apsetr (ap, WY, apstatr (ap, CWY))

	}

	call sfree (sp)
end