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
|
include "../lib/io.h"
include "../lib/fitparams.h"
include "../lib/parser.h"
# IO_GCOEFFS - Get fit coefficients from a text database file
int procedure io_gcoeffs (fname, sym, stat, chisqr, rms, params, errors,
nparams)
char fname[ARB] # output database name
int sym # equation symbol
int stat # fit error code (output)
real chisqr # reduced chi-squared of the fit
real rms # RMS of the fit
real params[nparams] # parameter values (output)
real errors[nparams] # parameter errors (output)
int nparams # number of parameters
#int i
int nread, rec
pointer dt
#bool clgetb()
int dtlocate(), dtgeti()
pointer dtmap(), pr_xgetname()
real dtgetr()
errchk dtmap()
begin
# Debug ?
#if (clgetb ("debug.iocode")) {
#call eprintf ("io_gcoeffs.in: (fname=%s) (sym=%d) (npar=%d)\n")
#call pargstr (fname)
#call pargi (sym)
#call pargi (nparams)
#}
# Map database.
dt = dtmap (fname, READ_ONLY)
# Locate record for the equation.
iferr (rec = dtlocate (dt, Memc[pr_xgetname (sym)])) {
call dtunmap (dt)
return (0)
}
# Get fit status code, chisqr, and rms.
iferr (stat = dtgeti (dt, rec, STATUS))
stat = INDEFI
iferr (chisqr = dtgetr (dt, rec, CHISQR))
chisqr = INDEFR
iferr (rms = dtgetr (dt, rec, RMS))
rms = INDEFR
# Get parameter values and errors.
iferr (call dtgar (dt, rec, VALUES, params, nparams, nread))
nread = 0
iferr (call dtgar (dt, rec, ERRORS, errors, nparams, nread))
nread = 0
# Debug ?
#if (clgetb ("debug.iocode")) {
#call eprintf (
#"io_gcoeffs.out: (stat=%d) (chisqr=%g) (rms=%g) (nread=%s)")
#call pargi (stat)
#call pargr (chisqr)
#call pargr (rms)
#call pargi (nread)
#call eprintf ("\nvalues:")
#do i = 1, nread {
#call eprintf (" (%g)")
#call pargr (params[i])
#}
#call eprintf ("\nerrors:")
#do i = 1, nread {
#call eprintf (" (%g)")
#call pargr (errors[i])
#}
#call eprintf ("\n")
#}
# Unmap the database.
call dtunmap (dt)
# Return number of values read.
return (nread)
end
# IO_PCOEFFS - Put fit coefficients in the output file
procedure io_pcoeffs (fname, sym, stat, wtflag, variance, chisqr, scatter,
rms, params, errors, plist, nparams)
char fname[ARB] # output database name
int sym # equation symbol
int stat # fit error code
int wtflag # type of weighting
real variance # variance of the fit
real chisqr # reduced chi-squared of the fit
real scatter # additional scatter squared in the fit
real rms # RMS of the fit
real params[nparams] # parameter values
real errors[nparams] # parameter errors
int plist[nparams] # parameter list
int nparams # number of parameters
bool isfit
char str[SZ_LINE]
int i, j
pointer dt
real rval
#bool clgetb()
int pr_gpari()
pointer pr_xgetname(), pr_gsymc(), pr_gsymp(), pr_gderc(), dtmap(), pr_gderp()
real pr_gsymr()
errchk dtmap()
begin
# Debug ?
#if (clgetb ("debug.iocode")) {
#call eprintf ("io_pcoeffs: (fname=%s) (sym=%d) (stat=%d) "
#call pargstr (fname)
#call pargi (sym)
#call pargi (stat)
#call eprintf ("(chisqr=%g) (rms=%g) (npar=%d)\n")
#call pargr (chisqr)
#call pargr (rms)
#call pargi (nparams)
#}
# Map the database.
dt = dtmap (fname, APPEND)
# Put time stamp and record identification.
call dtptime (dt)
call dtput (dt, "begin\t%s\n")
call pargstr (Memc[pr_xgetname (sym)])
# Write fit status code and message.
call nlerrmsg (stat, str, SZ_LINE)
call dtput (dt, "\t%s\t%d\t(%s)\n")
call pargstr (STATUS)
call pargi (stat)
call pargstr (str)
# Write the variance and standard deviation.
call dtput (dt, "\t%s\t%g\n")
call pargstr (VARIANCE)
call pargr (variance)
call dtput (dt, "\t%s\t%g\n")
call pargstr (STDEV)
if (variance > 0.0)
call pargr (sqrt (variance))
else
call pargr (0.0)
# Write the average square error and the average error.
call dtput (dt, "\t%s\t%g\n")
call pargstr (AVSQERROR)
if (chisqr <= 0.0)
rval = 0.0
else
rval = variance / chisqr
call pargr (rval)
call dtput (dt, "\t%s\t\t%g\n")
call pargstr (AVERROR)
call pargr (sqrt (rval))
# Write out the average square scatter and the average scatter.
call dtput (dt, "\t%s\t%g\n")
call pargstr (AVSQSCATTER)
if (scatter <= 0.0)
rval = 0.0
else
rval = scatter
call pargr (rval)
call dtput (dt, "\t%s\t%g\n")
call pargstr (AVSCATTER)
call pargr (sqrt (rval))
# Write reduced chi-squared.
call dtput (dt, "\t%s\t\t%g\n")
call pargstr (CHISQR)
call pargr (chisqr)
# Write RMS.
call dtput (dt, "\t%s\t\t%g\n")
call pargstr (MSQ)
call pargr (rms * rms)
call dtput (dt, "\t%s\t\t%g\n")
call pargstr (RMS)
call pargr (rms)
# Write reference equation.
call dtput (dt, "\t%s\t%s\n")
call pargstr (REFERENCE)
call pargstr (Memc[pr_gsymc (sym, PTEQREF)])
# Write the fitting equation.
call dtput (dt, "\t%s\t\t%s\n")
call pargstr (FITTING)
call pargstr (Memc[pr_gsymc (sym, PTEQFIT)])
# Write the weighting information.
call dtput (dt, "\t%s\t\t%s\n")
switch (wtflag) {
case FWT_UNIFORM:
call pargstr (WEIGHTING)
call pargstr ("uniform")
case FWT_PHOTOMETRIC:
call pargstr (WEIGHTING)
call pargstr ("photometric")
case FWT_EQUATIONS:
call pargstr (WEIGHTING)
if (pr_gsymp (sym, PTEQRPNWEIGHT) == NULL)
call pargstr ("uniform")
else
call pargstr (Memc[pr_gsymc (sym, PTEQWEIGHT)])
default:
call pargstr (WEIGHTING)
call pargstr ("uniform")
}
# Write the parameter names.
call dtput (dt, "\t%s\t%d\n")
call pargstr (PARAMETERS)
call pargi (nparams)
do i = 1, nparams {
call dtput (dt, "\t\t%s\t(%s)\n")
call pargstr (Memc[pr_xgetname (pr_gpari (sym, i, PTEQPAR))])
isfit = false
do j = 1, nparams
if (plist[j] == i) {
isfit = true
break
}
if (isfit)
call pargstr ("fit")
else
call pargstr ("constant")
}
# Write the derivatives.
call dtput (dt, "\t%s\t%d\n")
call pargstr (DERIVATIVES)
call pargi (nparams)
do i = 1, nparams {
if (pr_gderp (sym, i, PTEQRPNDER) != NULL) {
call dtput (dt, "\t\t%s\n")
call pargstr (Memc[pr_gderc (sym, i, PTEQDER)])
} else {
call dtput (dt, "\t\t%g\n")
call pargr (pr_gsymr (pr_gpari (sym, i, PTEQPAR),
PFITDELTA))
}
}
# Write the parameter values.
call dtput (dt, "\t%s\t%d\n")
call pargstr (VALUES)
call pargi (nparams)
do i = 1, nparams {
call dtput (dt, "\t\t%g\n")
call pargr (params[i])
}
# Write the parameter errors.
call dtput (dt, "\t%s\t%d\n")
call pargstr (ERRORS)
call pargi (nparams)
do i = 1, nparams {
call dtput (dt, "\t\t%g\n")
call pargr (errors[i])
}
call dtput (dt,"\n")
# Close the database.
call dtunmap (dt)
end
|