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
|
include <ctotok.h>
include "../lib/daophotdef.h"
# DP_GPPARS -- Procedure to fetch the daophot task parameters.
procedure dp_gppars (dao)
pointer dao # pointer to daophot structure
int dp, dap
pointer mp, str, tstr
real scale, fwhmpsf, psfrad, matchrad, fitrad, annulus, dannulus, mergerad
bool clgetb(), clgpsetb()
int clgpseti(), btoi(), dp_fctdecode(), dp_strwrd()
pointer clopset()
real clgpsetr()
begin
# Allocate working space.
call smark (mp)
call salloc (str, SZ_FNAME, TY_CHAR)
call salloc (tstr, SZ_FNAME, TY_CHAR)
# Open the daophot structure.
call dp_init (dao)
# Set the package parameter text and initialize the verbose switch.
call dp_seti (dao, TEXT, btoi (clgetb ("text")))
call dp_seti (dao, VERBOSE, btoi (false))
# Open the datapars parameter set.
dp = clopset ("datapars")
# Set the datapars parameters.
scale = clgpsetr (dp, "scale")
call dp_setr (dao, SCALE, scale)
fwhmpsf = clgpsetr (dp, "fwhmpsf")
call dp_setr (dao, SFWHMPSF, fwhmpsf)
call dp_setr (dao, MAXGDATA, clgpsetr (dp, "datamax"))
call dp_setr (dao, MINGDATA, clgpsetr (dp, "datamin"))
# Initialize the noise parameters.
call clgpset (dp, "ccdread", Memc[str], SZ_FNAME)
call dp_sets (dao, CCDREAD, Memc[str])
call dp_setr (dao, READNOISE, clgpsetr (dp, "readnoise"))
call clgpset (dp, "gain", Memc[str], SZ_FNAME)
call dp_sets (dao, CCDGAIN, Memc[str])
call dp_setr (dao, PHOTADU, clgpsetr (dp, "epadu"))
# Initialize the observing parameters. Note that whitespace
# is removed from the filter id.
call clgpset (dp, "exposure", Memc[str], SZ_FNAME)
call dp_sets (dao, EXPTIME, Memc[str])
call dp_setr (dao, ITIME, 1.0)
call clgpset (dp, "airmass", Memc[str], SZ_FNAME)
call dp_sets (dao, AIRMASS, Memc[str])
call dp_setr (dao, XAIRMASS, clgpsetr (dp, "xairmass"))
call clgpset (dp, "filter", Memc[str], SZ_FNAME)
call dp_sets (dao, FILTER, Memc[str])
call clgpset (dp, "ifilter", Memc[str], SZ_FNAME)
call dp_rmwhite (Memc[str], Memc[str], SZ_FNAME)
call dp_sets (dao, IFILTER, Memc[str])
call clgpset (dp, "obstime", Memc[str], SZ_FNAME)
call dp_sets (dao, OBSTIME, Memc[str])
call clgpset (dp, "otime", Memc[str], SZ_FNAME)
call dp_sets (dao, OTIME, Memc[str])
# Close the datapars parameter set.
call clcpset (dp)
# Open the daopars parameter set.
dap = clopset ("daopars")
# Set the psf fitting parameters.
call clgpset (dap, "function", Memc[tstr], SZ_FNAME)
if (dp_fctdecode (Memc[tstr], Memc[str], SZ_FNAME) <= 0)
call strcpy (",gauss,", Memc[str], SZ_FNAME)
call dp_sets (dao, FUNCLIST, Memc[str])
if (dp_strwrd (1, Memc[tstr], SZ_FNAME, Memc[str]) <= 0)
call strcpy ("gauss", Memc[tstr], SZ_FNAME)
call dp_sets (dao, FUNCTION, Memc[tstr])
call dp_seti (dao, VARORDER, clgpseti (dap, "varorder"))
#call dp_seti (dao, FEXPAND, btoi (clgpsetb (dap, "fexpand")))
call dp_seti (dao, FEXPAND, NO)
call dp_seti (dao, NCLEAN, clgpseti (dap, "nclean"))
call dp_seti (dao, SATURATED, btoi (clgpsetb (dap, "saturated")))
psfrad = clgpsetr (dap, "psfrad")
call dp_setr (dao, RPSFRAD, psfrad)
call dp_setr (dao, SPSFRAD, psfrad)
matchrad = clgpsetr (dap, "matchrad")
call dp_setr (dao, SMATCHRAD, matchrad)
# Set the fitting parameters.
fitrad = clgpsetr (dap, "fitrad")
call dp_setr (dao, SFITRAD, fitrad)
annulus = clgpsetr (dap, "sannulus")
call dp_setr (dao, SANNULUS, annulus)
dannulus = clgpsetr (dap, "wsannulus")
call dp_setr (dao, SDANNULUS, dannulus)
call dp_setr (dao, CRITSNRATIO, clgpsetr (dap, "critsnratio"))
call dp_seti (dao, MAXITER, clgpseti (dap, "maxiter"))
call dp_seti (dao, MAXGROUP, clgpseti (dap, "maxgroup"))
call dp_seti (dao, MAXNSTAR, clgpseti (dap, "maxnstar"))
call dp_seti (dao, RECENTER, btoi (clgpsetb (dap, "recenter")))
call dp_seti (dao, FITSKY, btoi (clgpsetb (dap, "fitsky")))
call dp_seti (dao, GROUPSKY, btoi (clgpsetb (dap, "groupsky")))
call dp_setr (dao, FLATERR, clgpsetr (dap, "flaterr"))
call dp_setr (dao, PROFERR, clgpsetr (dap, "proferr"))
call dp_setr (dao, CLIPRANGE, clgpsetr (dap, "cliprange"))
call dp_seti (dao, CLIPEXP, clgpseti (dap, "clipexp"))
mergerad = clgpsetr (dap, "mergerad")
call dp_setr (dao, SMERGERAD, mergerad)
# Close the daopars pset file.
call clcpset (dap)
# Compute the fwhmpsf, psf radius, fitting radius and matching radius
# in pixels and store.
call dp_setr (dao, FWHMPSF, fwhmpsf / scale)
call dp_setr (dao, PSFRAD, psfrad / scale)
call dp_setr (dao, MATCHRAD, matchrad / scale)
call dp_setr (dao, FITRAD, fitrad / scale)
call dp_setr (dao, ANNULUS, annulus / scale)
call dp_setr (dao, DANNULUS, dannulus / scale)
if (IS_INDEFR(mergerad))
call dp_setr (dao, MERGERAD, INDEFR)
else
call dp_setr (dao, MERGERAD, mergerad / scale)
call sfree (mp)
end
# DP_FCTDECODE -- Decode and re-encode the list of analytic functions to be
# fit in a from suitable for use by strdic. If no valid psf types are included
# in the list set the dictionary to the gaussian function.
int procedure dp_fctdecode (instr, outstr, maxch)
char instr[ARB] # the input list of functions
char outstr[ARB] # the output list of functions
int maxch # maximum size of the output string
int ip, op, ntok, tok
pointer sp, token
int ctotok(), strdic(), gstrcpy, gstrcat()
begin
call smark (sp)
call salloc (token, maxch, TY_CHAR)
outstr[1] = ','
outstr[2] = EOS
op = 2
ntok = 0
ip = 1
while (instr[ip] != EOS) {
tok = ctotok (instr, ip, Memc[token], maxch)
if (tok != TOK_IDENTIFIER)
next
if (strdic (Memc[token], Memc[token], maxch, FCTN_FTYPES) <= 0)
next
ntok = ntok + 1
op = op + gstrcpy (Memc[token], outstr[op], maxch - op + 1)
op = op + gstrcat (",", outstr[op], maxch - op + 1)
}
call sfree (sp)
return (ntok)
end
# DP_STRWRD -- Search a dictionary string for a given string index number.
# This is the opposite function of strdic(), that returns the index for
# given string. The entries in the dictionary string are separated by
# a delimiter character which is the first character of the dictionary
# string. The index of the string found is returned as the function value.
# Otherwise, if there is no string for that index, a zero is returned.
int procedure dp_strwrd (index, outstr, maxch, dict)
int index # String index
char outstr[ARB] # Output string as found in dictionary
int maxch # Maximum length of output string
char dict[ARB] # Dictionary string
int i, len, start, count
int strlen()
begin
# Clear output string
outstr[1] = EOS
# Return if the dictionary is not long enough
if (dict[1] == EOS)
return (0)
# Initialize counters
count = 1
len = strlen (dict)
# Search the dictionary string. This loop only terminates
# successfully if the index is found. Otherwise the procedure
# returns with and error condition.
for (start = 2; count < index; start = start + 1) {
if (dict[start] == dict[1])
count = count + 1
if (start == len)
return (0)
}
# Extract the output string from the dictionary
for (i = start; dict[i] != EOS && dict[i] != dict[1]; i = i + 1) {
if (i - start + 1 > maxch)
break
outstr[i - start + 1] = dict[i]
}
outstr[i - start + 1] = EOS
# Return index for output string
return (count)
end
|