aboutsummaryrefslogtreecommitdiff
path: root/noao/digiphot/apphot/aplib/apwparam1.x
blob: 54086aeb9d847db74964d3889897458d8cdaa84c (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
include <time.h>
include "../lib/apphotdef.h"
include "../lib/apphot.h"
include "../lib/noise.h"
include	"../lib/center.h"
include "../lib/fitsky.h"
include "../lib/phot.h"

# AP_PARAM -- Procedure to write the apphot parameters to a text file.

procedure ap_param (ap, out, task)

pointer	ap		# pointer to the apphot structure
int	out		# output file descriptor
char	task[ARB]	# task name

int	nchars
pointer	sp, outstr, date, time
bool	itob()
int	strmatch(), envfind(), gstrcpy(), apstati()
real	apstatr()

begin
	if (out == NULL)
	    return
	 
	# Allocate working space.
	call smark (sp)
	call salloc (outstr, SZ_LINE, TY_CHAR)
	call salloc (date, SZ_DATE, TY_CHAR)
	call salloc (time, SZ_DATE, TY_CHAR)

	# Write the id.

	nchars = envfind ("version", Memc[outstr], SZ_LINE)
	if (nchars <= 0)
	    nchars = gstrcpy ("NOAO/IRAF", Memc[outstr], SZ_LINE)
	call ap_rmwhite (Memc[outstr], Memc[outstr], SZ_LINE)
	call ap_sparam (out, "IRAF", Memc[outstr], "version",
	    "current version of IRAF")

	nchars = envfind ("userid", Memc[outstr], SZ_LINE)
	call ap_sparam (out, "USER", Memc[outstr], "name", "user id")

	call gethost (Memc[outstr], SZ_LINE)
	call ap_sparam (out, "HOST", Memc[outstr], "computer",
	    "IRAF host machine")

	call apdate (Memc[date], Memc[time], SZ_DATE)
	call ap_sparam (out, "DATE", Memc[date], "yyyy-mm-dd", "date")
	call ap_sparam (out, "TIME", Memc[time], "hh:mm:ss", "time")

	call ap_sparam (out, "PACKAGE", "apphot", "name",
	    "name of IRAF package")
	call ap_sparam (out, "TASK", task, "name", "name of apphot task")
	call fprintf (out, "#\n")

	# Write out the apphot parameters.
	call ap_rparam (out, KY_SCALE, 1.0 / apstatr (ap, SCALE), UN_AUNITS,
	    "scale in units per pixel")
	call ap_rparam (out, KY_FWHMPSF, apstatr (ap, FWHMPSF), UN_ASCALEUNIT,
	    "full width half maximum of the psf")
	call ap_bparam (out, KY_POSITIVE, itob (apstati (ap, POSITIVE)),
	    UN_ASWITCH, "positive feature")
	call ap_rparam (out, KY_DATAMIN, apstatr (ap, DATAMIN), UN_ACOUNTS,
	    "minimum good data value")
	call ap_rparam (out, KY_DATAMAX, apstatr (ap, DATAMAX), UN_ACOUNTS,
	    "maximum good data value")

	# Write out the image header keyword parameters.
	call apstats (ap, EXPOSURE, Memc[outstr], SZ_FNAME)
	if (Memc[outstr] == EOS)
	    call strcpy ("\"\"", Memc[outstr], SZ_FNAME)
	call ap_sparam (out, KY_EXPOSURE, Memc[outstr], UN_AKEYWORD,
	    "exposure time keyword")
	call apstats (ap, AIRMASS, Memc[outstr], SZ_FNAME)
	if (Memc[outstr] == EOS)
	    call strcpy ("\"\"", Memc[outstr], SZ_FNAME)
	call ap_sparam (out, KY_AIRMASS, Memc[outstr], UN_AKEYWORD,
	    "airmass keyword")
	call apstats (ap, FILTER, Memc[outstr], SZ_FNAME)
	if (Memc[outstr] == EOS)
	    call strcpy ("\"\"", Memc[outstr], SZ_FNAME)
	call ap_sparam (out, KY_FILTER, Memc[outstr], UN_AKEYWORD,
	    "filter keyword")
	call apstats (ap, OBSTIME, Memc[outstr], SZ_FNAME)
	if (Memc[outstr] == EOS)
	    call strcpy ("\"\"", Memc[outstr], SZ_FNAME)
	call ap_sparam (out, KY_OBSTIME, Memc[outstr], UN_AKEYWORD,
	    "obstime keyword")
	call fprintf (out, "#\n")

	# Write the noise model parameters.
	call ap_wnse (ap, out)

	# Write the centering parameters.
	call ap_wctrs (ap, out)

	# Write sky fitting parameters.
	call ap_wskys (ap, out)

	# Write the phot parameters.
	call ap_wwphot (ap, out)

	# Write the polyphot parameters.
	call ap_wpoly (ap, out)

	# Write the radial profile parameters.
	call ap_wprofs (ap, out)

	# Write the psf fitting parameters.
	call ap_wpsf (ap, out)

	# Write the header banner
	if (strmatch ("^center", task) > 0)
	    call ap_cphdr (ap, out)
	else if (strmatch ("^fitsky", task) > 0)
	    call ap_sphdr (ap, out)
	else if (strmatch ("^phot", task) > 0)
	    call ap_maghdr (ap, out)
	else if (strmatch ("^qphot", task) > 0)
	    call ap_maghdr (ap, out)
	else if (strmatch ("^wphot", task) > 0)
	    call ap_maghdr (ap, out)
	else if (strmatch ("^polyphot", task) > 0)
	    call ap_yhdr (ap, out)
	else if (strmatch ("^fitpsf", task) > 0)
	    call ap_pfhdr (ap, out)
	else if (strmatch ("^radprof", task) > 0)
	    call ap_rphdr (ap, out)
	#else if (strmatch ("^daofind", task) > 0)
	    #call ap_fdhdr (ap, out)

	call sfree (sp)
end


# AP_WCTRS -- Procedure to write out the centering parameters.

procedure ap_wctrs (ap, out)

pointer	ap		# apphot pointer
int	out		# output file descriptor

pointer	sp, str
bool	itob()
int	apstati()
real	apstatr()

begin
	if (out == NULL)
	    return

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

	if (AP_PCENTER(ap) != NULL) {
	    call apstats (ap, CSTRING, Memc[str], SZ_FNAME)
	    call ap_sparam (out, KY_CSTRING, Memc[str], UN_CALGORITHM,
		"centering algorithm")
	    call ap_rparam (out, KY_CAPERT, 2.0* apstatr (ap, CAPERT),
	        UN_CSCALEUNIT, "centering box width")
	    call ap_rparam (out, KY_CTHRESHOLD, apstatr (ap, CTHRESHOLD),
	        UN_CSIGMA, "threshold for centering")
	    call ap_rparam (out, KY_MINSNRATIO, apstatr (ap, MINSNRATIO),
		UN_CNUMBER, "minimum signal to noise ratio")
	    call ap_iparam (out, KY_CMAXITER, apstati (ap, CMAXITER),
	        UN_CNUMBER, "maximum number of iterations")
	    call ap_rparam (out, KY_MAXSHIFT, apstatr (ap, MAXSHIFT),
	        UN_CSCALEUNIT, "maximum shift")
	    call ap_bparam (out, KY_CLEAN, itob (apstati (ap, CLEAN)),
		UN_CSWITCH, "apply clean algorithm before centering")
	    call ap_rparam (out, KY_RCLEAN, apstatr (ap, RCLEAN),
	        UN_CSCALEUNIT, "cleaning radius")
	    call ap_rparam (out, KY_RCLIP, apstatr (ap, RCLIP), UN_CSCALEUNIT,
		"clipping radius")
	    call ap_rparam (out, KY_SIGMACLEAN, apstatr (ap, SIGMACLEAN),
	        UN_CSIGMA, "k-sigma clean rejection criterion")
	    call fprintf (out, "#\n")
	}

	call sfree (sp)
end


# AP_WSKYS -- Procedure to write out the sky fitting  parameters.

procedure ap_wskys (ap, out)

pointer	ap		# apphot structure
int	out		# output pointer

pointer sp, str
bool	itob()
int	apstati()
real	apstatr()

begin
	if (out == NULL)
	    return

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

	if (AP_PSKY(ap) != NULL) {
	    call apstats (ap, SSTRING, Memc[str], SZ_FNAME)
	    call ap_sparam (out, KY_SSTRING, Memc[str], UN_SALGORITHM,
		" sky fitting algorithm")
	    call ap_rparam (out, KY_ANNULUS, apstatr (ap, ANNULUS),
	        UN_SSCALEUNIT, "inner radius of sky annulus")
	    call ap_rparam (out, KY_DANNULUS, apstatr (ap, DANNULUS),
	        UN_SSCALEUNIT, "width of the sky annulus")
	    call ap_rparam (out, KY_SKY_BACKGROUND, apstatr (ap,
	        SKY_BACKGROUND), UN_SCOUNTS, "user supplied sky value")
	    call ap_rparam (out, KY_K1, apstatr (ap, K1), UN_SSIGMA,
		"half width of sky histogram")
	    call ap_rparam (out, KY_BINSIZE, apstatr (ap, BINSIZE),
	        UN_SSIGMA, "width of sky histogram bin")
	    call ap_bparam (out, KY_SMOOTH, itob (apstati (ap, SMOOTH)),
		UN_SSWITCH, "Lucy smooth the histogram")
	    call ap_iparam (out, KY_SMAXITER, apstati (ap, SMAXITER),
	        UN_SNUMBER, "maximum number of iterations")
	    call ap_rparam (out, KY_SLOCLIP, apstatr (ap, SLOCLIP),
	        UN_SPERCENT, "lower clipping limit")
	    call ap_rparam (out, KY_SHICLIP, apstatr (ap, SHICLIP),
	        UN_SPERCENT, "upper clipping limit")
	    call ap_iparam (out, KY_SNREJECT, apstati (ap, SNREJECT),
	        UN_SNUMBER, "maximum number of rejection cycles")
	    call ap_rparam (out, KY_SLOREJECT, apstatr (ap, SLOREJECT),
	        UN_SSIGMA, "lower k-sigma rejection criterion")
	    call ap_rparam (out, KY_SHIREJECT, apstatr (ap, SHIREJECT),
	        UN_SSIGMA, "upper k-sigma rejection criterion")
	    call ap_rparam (out, KY_RGROW, apstatr (ap, RGROW), UN_SSCALEUNIT,
		"region growing radius")
	    call fprintf (out, "#\n")
	}

	call sfree (sp)
end


# AP_WNSE -- Porcedure to compute the noise model parameters.

procedure ap_wnse (ap, out)

pointer	ap		# apphot pointer
int	out		# output file descriptor

pointer	sp, str
real	apstatr()

begin
	if (out == NULL)
	    return
	call smark (sp)
	call salloc (str, SZ_FNAME, TY_CHAR)

	if (AP_NOISE(ap) != NULL) {
	    call apstats (ap, NSTRING, Memc[str], SZ_FNAME)
	    call ap_sparam (out, KY_NSTRING, Memc[str], UN_NMODEL,
	        "noise model")
	    call ap_rparam (out, KY_SKYSIGMA, apstatr (ap, SKYSIGMA),
	        UN_NCOUNTS, "standard deviation of 1 sky pixel")
	    call apstats (ap, GAIN, Memc[str], SZ_FNAME)
	    if (Memc[str] == EOS)
	        call strcpy ("\"\"", Memc[str], SZ_FNAME)
	    call ap_sparam (out, KY_GAIN, Memc[str], UN_NKEYWORD,
	        "gain keyword")
	    call ap_rparam (out, KY_EPADU, apstatr (ap, EPADU), UN_NEPADU,
	        "electrons per adu")
	    call apstats (ap, CCDREAD, Memc[str], SZ_FNAME)
	    if (Memc[str] == EOS)
	        call strcpy ("\"\"", Memc[str], SZ_FNAME)
	    call ap_sparam (out, KY_CCDREAD, Memc[str], UN_NKEYWORD,
	        "read noise keyword")
	    call ap_rparam (out, KY_READNOISE, apstatr (ap, READNOISE),
	        UN_NELECTRONS, "electrons")
	    call fprintf (out, "#\n")
	}

	call sfree (sp)
end


# AP_WWPHOT -- Procedure to write out the photometry parameters.

procedure ap_wwphot (ap, out)

pointer	ap		# apphot structure pointer
int	out		# output file descriptor

pointer	sp, str
real	apstatr()

begin
	if (out == NULL)
	    return

	call smark (sp)
	call salloc (str, SZ_LINE, TY_CHAR)

	if (AP_PPHOT(ap) != NULL) {
	    call apstats (ap, PWSTRING, Memc[str], SZ_LINE)
	    call ap_sparam (out, KY_PWSTRING, Memc[str], UN_PMODEL,
		"photometric weighting scheme")
	    call apstats (ap, APERTS, Memc[str], SZ_LINE)
	    call ap_sparam (out, KY_APERTS, Memc[str], UN_PSCALEUNIT,
		"list of apertures")
	    call ap_rparam (out, KY_ZMAG, apstatr (ap, ZMAG), UN_PZMAG,
		"zero point of magnitdue scale")
	    call fprintf (out, "#\n")
	}

	call sfree (sp)
end


# AP_RPARAM -- Procedure to encode a real apphot parameter.

procedure ap_rparam (out, keyword, value, units, comments)

int	out		# output file descriptor
char	keyword[ARB]	# keyword string
real	value		# parameter value
char	units[ARB]	# units string
char	comments[ARB]	# comment string

begin
	if (out == NULL)
	    return

	call strupr (keyword)
        call fprintf (out,
	    "#K%4t%-10.10s%14t = %17t%-23.7g%41t%-10.10s%52t%-10s\n")
	    call pargstr (keyword)
	    call pargr (value)
	    call pargstr (units)
	    call pargstr ("%-23.7g")
	    call pargstr (comments)
end


# AP_IPARAM -- Procedure to encode an apphot integer parameter.

procedure ap_iparam (out, keyword, value, units, comments)

int	out		# output file descriptor
char	keyword[ARB]	# keyword string
int	value		# parameter value
char	units[ARB]	# units string
char	comments[ARB]	# comment string

begin
	if (out == NULL)
	    return

	call strupr (keyword)
        call fprintf (out,
	    "#K%4t%-10.10s%14t = %17t%-23d%41t%-10.10s%52t%-10s\n")
	    call pargstr (keyword)
	    call pargi (value)
	    call pargstr (units)
	    call pargstr ("%-23d")
	    call pargstr (comments)
end


# AP_BPARAM -- Procedure to encode an apphot boolean parameter.

procedure ap_bparam (out, keyword, value, units, comments)

int	out		# output file descriptor
char	keyword[ARB]	# keyword string
bool	value		# parameter value
char	units[ARB]	# units string
char	comments[ARB]	# comment string

begin
	if (out == NULL)
	    return

	call strupr (keyword)
        call fprintf (out,
	    "#K%4t%-10.10s%14t = %17t%-23b%41t%-10.10s%52t%-10s\n")
	    call pargstr (keyword)
	    call pargb (value)
	    call pargstr (units)
	    call pargstr ("%-23b")
	    call pargstr (comments)
end


# AP_SPARAM -- Procedure to encode an apphot string parameter.

procedure ap_sparam (out, keyword, value, units, comments)

int	out		# output file descriptor
char	keyword[ARB]	# keyword string
char	value[ARB]	# parameter value
char	units[ARB]	# units string
char	comments[ARB]	# comment string

begin
	if (out == NULL)
	    return

	call strupr (keyword)
        call fprintf (out,
	    "#K%4t%-10.10s%14t = %17t%-23.23s%41t%-10.10s%52t%-10s\n")
	    call pargstr (keyword)
	    call pargstr (value)
	    call pargstr (units)
	    call pargstr ("%-23s")
	    call pargstr (comments)
end