aboutsummaryrefslogtreecommitdiff
path: root/noao/digiphot/daophot/daoedit/t_daoedit.x
blob: 8c92e9692f104524431b822b4c35e03d457fbcc8 (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
include <imhdr.h>
include <gset.h>
include "../lib/daophotdef.h"
include "daoedit.h"

define	HELPFILE	"daophot$daoedit/daoedit.key"
define	IHELPFILE	"daophot$daoedit/daoedit.key"

# T_DAOEDIT -- Edit the DAOPHOT parameters interactively using the image
# display and a radial profile plot.

procedure t_daoedit ()

pointer	image			# the name of the input image
int	cache			# cache the image pixels
pointer	graphics		# the graphics device
pointer	display			# the image display

real	wx, wy, xlast, ylast
pointer	sp, cmd, im, gd, id
int	wcs, key, redraw, gcurtype, curtype, xwcs, ywcs, lastkey
int	req_size, memstat, old_size, buf_size

pointer	immap(), gopen()
int	dp_gcur(), btoi(), sizeof(), dp_memstat()
bool	clgetb(), streq()
errchk	gopen()

data	gcurtype /'g'/

begin
	call smark (sp)
	call salloc (image, SZ_FNAME, TY_CHAR)
	call salloc (graphics, SZ_FNAME, TY_CHAR)
	call salloc (display, SZ_FNAME, TY_CHAR)
	call salloc (cmd, SZ_LINE, TY_CHAR)

	call clgstr ("image", Memc[image], SZ_FNAME)
	im = immap (Memc[image], READ_ONLY, 0)

	call clgstr ("graphics", Memc[graphics], SZ_FNAME)
	iferr (gd = gopen (Memc[graphics], AW_DEFER+NEW_FILE, STDGRAPH))
	    gd = NULL
	call clgstr ("display", Memc[display], SZ_FNAME)
        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
            }
        }
	cache = btoi (clgetb ("cache"))

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

	xlast = INDEFR
	ylast = INDEFR
	lastkey = INDEFI
	xwcs = WCS_XPIX
	ywcs = WCS_YCOUNT
	curtype = 'i'
	redraw = NO

	while (dp_gcur (curtype, wx, wy, wcs, key, Memc[cmd], SZ_LINE) != EOF) {

	    # Convert the cursor coordinates if necessary.
	    if (curtype == 'i')
		call dp_vtol (im, wx, wy, wx, wy, 1)

	    switch (key) {

	    # Print help page.
	    case '?':
		if (curtype == 'i') {
		    call pagefile (HELPFILE, "[space=cmhelp,q=quit,?=help]")
		} else if (curtype == 'g') {
		    #call greactivate (gd, 0)
		    call gpagefile (gd, HELPFILE, "")
		}


	    # Quit the program.
	    case 'q':
		break

	    # Toggle between the image display and graphics cursor.
	    case 'g':
		if (curtype == 'i') {
		    call greactivate (gd, 0)
		    curtype = 'g'
		} else { 
		    call gdeactivate (gd, 0)
		    curtype = 'i'
		}

	    # Toggle between the pixel and scale units plot scale in x.
	    case 'x':
		if (xwcs == WCS_XPIX)
		    xwcs = WCS_XSCALE
		else if (xwcs == WCS_XSCALE)
		    xwcs = WCS_XPIX
		redraw = YES

	    # Toggle between the counts and norm plot scale in y.
	    case 'y':
		if (ywcs == WCS_YCOUNT)
		    ywcs = WCS_YNORM
		else if (ywcs == WCS_YNORM)
		    ywcs = WCS_YCOUNT
		redraw = YES

	    case 'a':
		if (curtype == 'i') {
		    if (lastkey == 'a')
		        call dp_erprofile (NULL, id, NO, xwcs, ywcs, im, wx, wy)
		    else
		        call dp_erprofile (NULL, id, YES, xwcs, ywcs, im,
			    wx, wy)
		} else {
		    call dp_erprofile (NULL, id, NO, xwcs, ywcs, im,
		        xlast, ylast)
		}

	    case 'r':
		if (curtype == 'i') {
		    xlast = wx
		    ylast = wy
		}
		redraw = YES

	    case 'i':
		if (curtype == 'i') {
		    xlast = wx
		    ylast = wy
		}
		xwcs = WCS_XPIX
		ywcs = WCS_YCOUNT
		redraw = YES

	    case ':':
		call dp_ecolon (Memc[cmd], gd, redraw)

	    default:
		call printf ("Unknown or ambiguous keystroke command\7\n")
	    }

	    # Draw the plot.
	    if (redraw == YES) {
		call dp_erprofile (gd, id, NO, xwcs, ywcs, im, xlast, ylast)
		if (key == 'i')
		    call dp_isetup (gcurtype, gd)
		redraw = NO
		if (curtype == 'i')
		    call gdeactivate (gd, 0)
	    }

	    lastkey = key
	}

        if (id == gd && gd != NULL) {
	    call gclose (gd)
	} else {
	    if (gd != NULL)
		call gclose (gd)
	    if (id != NULL)
		call gclose (id)
	}

	call imunmap (im)

        # Uncache memory.
        call fixmem (old_size)

	call sfree (sp)
end


# DP_GCUR --Get a SETPARS cursor value.

int procedure dp_gcur (curtype, x, y, wcs, key, strval, maxch)

int     curtype                 # cursor type
real    x, y                    # cursor position
int	wcs			# cursor wcs
int     key                     # keystroke value of cursor event
char    strval[ARB]             # string value, if any
int     maxch                   # max chars out

int	nitems
int	clgcur()

begin
	# Initialize.
	strval[1] = EOS
	 
	# Get a cursor values from the desired cursor parameter.
	 switch (curtype) {
	 case 'i':
	     nitems = clgcur ("icommands", x, y, wcs, key, strval, maxch)
	 case 'g':
	     nitems = clgcur ("gcommands", x, y, wcs, key, strval, maxch)
	}

	return (nitems)
end


# DP_ISETUP -- Setup the daophot parameters interactively using a
# radial profile plot.

procedure dp_isetup (curtype, gd)

int	curtype			# the cursor type graphics or display
pointer	gd			# pointer to the graphics stream

int	wcs, key
pointer	sp, cmd
real	wx, wy
int	dp_gcur()

begin
	call smark (sp)
	call salloc (cmd, SZ_LINE, TY_CHAR)

	call printf (
	    "Interactive setup menu (?=help, spbar=default, q=quit):\n")
	while (dp_gcur (curtype, wx, wy, wcs, key, Memc[cmd],
	    SZ_LINE) != EOF) {
	    switch (key) {
	    case '?':
		call gpagefile (gd, IHELPFILE, "")
	    case 'q':
		break
	    case 'f':
		call dp_mfwhmpsf(gd)
		call dp_cfwhmpsf()
	    case 's':
		call dp_msigma(gd)
		call dp_csigma()
	    case 'u':
		call dp_mdmax(gd)
		call dp_cdmax()
	    case 'l':
		call dp_mdmin(gd)
		call dp_cdmin()
	    case 'c':
		call dp_mcbox(gd)
		call dp_ccbox()
	    case 'n':
		call dp_mrclean(gd)
		call dp_crclean()
	    case 'p':
		call dp_mrclip(gd)
		call dp_crclip()
	    case 'a':
		call dp_mannulus(gd)
		call dp_cannulus()
	    case 'd':
		call dp_mdannulus(gd)
		call dp_cdannulus()
	    case 'g':
		call dp_mrgrow(gd)
		call dp_crgrow()
	    case 'r':
		call dp_maper(gd)
		call dp_caper()
	    case 'w':
		call dp_mpsfrad(gd)
		call dp_cpsfrad()
	    case 'b':
		call dp_mfitrad(gd)
		call dp_cfitrad()
	    case ' ':
		call dp_mfwhmpsf(gd)
		call dp_mcbox(gd)
		call dp_mannulus(gd)
		call dp_mdannulus(gd)
		call dp_maper(gd)
		call dp_mpsfrad(gd)
		call dp_mfitrad(gd)
		call gdeactivate(gd, 0)
		call dp_cbanner()
		call dp_cfwhmpsf()
		call dp_ccbox()
		call dp_cannulus()
		call dp_cdannulus()
		call dp_caper()
		call dp_cpsfrad()
		call dp_cfitrad()
		call greactivate(gd, 0)
	    default:
	        call printf (
	        "Interactive setup menu (?=help, spbar=default, q=quit):\n")
	    }
	    call printf (
	        "Interactive setup menu (?=help, spbar=default, q=quit):\n")
	}

	if (curtype == 'i')
	    call gdeactivate (gd, 0)
	call sfree (sp)
end