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
|
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
include "icfit.h"
define FUNCTIONS "|chebyshev|legendre|spline3|spline1|user|"
# IC_OPEN -- Open ICFIT parameter structure.
procedure ic_open (ic)
pointer ic # ICFIT pointer
begin
# Allocate memory for the package parameter structure.
call malloc (ic, IC_LENSTRUCT, TY_STRUCT)
call malloc (IC_SAMPLE(ic), IC_SZSAMPLE, TY_CHAR)
call malloc (IC_LABELS(ic,1), SZ_LINE, TY_CHAR)
call malloc (IC_LABELS(ic,2), SZ_LINE, TY_CHAR)
call malloc (IC_UNITS(ic,1), SZ_LINE, TY_CHAR)
call malloc (IC_UNITS(ic,2), SZ_LINE, TY_CHAR)
call malloc (IC_HELP(ic), SZ_FNAME, TY_CHAR)
# Initialize parameters
IC_OVERPLOT(ic) = NO
IC_RG(ic) = NULL
IC_XFIT(ic) = NULL
IC_YFIT(ic) = NULL
IC_WTSFIT(ic) = NULL
IC_REJPTS(ic) = NULL
IC_GP(ic) = NULL
IC_GT(ic) = NULL
# Set defaults
call ic_pstr (ic, "function", "spline3")
call ic_puti (ic, "order", 1)
call ic_pstr (ic, "sample", "*")
call ic_puti (ic, "naverage", 1)
call ic_puti (ic, "niterate", 0)
call ic_putr (ic, "low", 3.)
call ic_putr (ic, "high", 3.)
call ic_putr (ic, "grow", 0.)
call ic_puti (ic, "markrej", YES)
call ic_pstr (ic, "xlabel", "X")
call ic_pstr (ic, "ylabel", "Y")
call ic_pstr (ic, "xunits", "")
call ic_pstr (ic, "yunits", "")
call ic_puti (ic, "color", 1)
call ic_pstr (ic, "help", IC_DEFHELP)
call ic_puti (ic, "key", 1)
call ic_pkey (ic, 1, 'x', 'y')
call ic_pkey (ic, 2, 'y', 'x')
call ic_pkey (ic, 3, 'x', 'r')
call ic_pkey (ic, 4, 'x', 'd')
call ic_pkey (ic, 5, 'x', 'n')
end
# IC_COPY -- Copy an ICFIT structure.
# The output pointer must be allocated already.
procedure ic_copy (icin, icout)
pointer icin # Input ICFIT pointer to copy
pointer icout # Ouput ICFIT pointer
begin
IC_FUNCTION(icout) = IC_FUNCTION(icin)
IC_ORDER(icout) = IC_ORDER(icin)
IC_NAVERAGE(icout) = IC_NAVERAGE(icin)
IC_NITERATE(icout) = IC_NITERATE(icin)
IC_XMIN(icout) = IC_XMIN(icin)
IC_XMAX(icout) = IC_XMAX(icin)
IC_LOW(icout) = IC_LOW(icin)
IC_HIGH(icout) = IC_HIGH(icin)
IC_GROW(icout) = IC_GROW(icin)
IC_COLOR(icout) = IC_COLOR(icin)
IC_MARKREJ(icout) = IC_MARKREJ(icin)
IC_GKEY(icout) = IC_GKEY(icin)
call strcpy (Memc[IC_SAMPLE(icin)], Memc[IC_SAMPLE(icout)], IC_SZSAMPLE)
call strcpy (Memc[IC_LABELS(icin,1)], Memc[IC_LABELS(icout,1)], SZ_LINE)
call strcpy (Memc[IC_LABELS(icin,2)], Memc[IC_LABELS(icout,2)], SZ_LINE)
call strcpy (Memc[IC_UNITS(icin,1)], Memc[IC_UNITS(icout,1)], SZ_LINE)
call strcpy (Memc[IC_UNITS(icin,2)], Memc[IC_UNITS(icout,2)], SZ_LINE)
call strcpy (Memc[IC_HELP(icin)], Memc[IC_HELP(icout)], SZ_LINE)
call amovi (IC_AXES(icin,1,1), IC_AXES(icout,1,1), 10)
IC_RG(icout) = NULL
IC_XFIT(icout) = NULL
IC_YFIT(icout) = NULL
IC_WTSFIT(icout) = NULL
IC_REJPTS(icout) = NULL
end
# IC_CLOSER -- Close ICFIT parameter structure.
procedure ic_closer (ic)
pointer ic # ICFIT pointer
begin
if (ic != NULL) {
# Free memory for the package parameter structure.
call rg_free (IC_RG(ic))
call mfree (IC_XFIT(ic), TY_REAL)
call mfree (IC_YFIT(ic), TY_REAL)
call mfree (IC_WTSFIT(ic), TY_REAL)
call mfree (IC_REJPTS(ic), TY_INT)
call mfree (IC_SAMPLE(ic), TY_CHAR)
call mfree (IC_LABELS(ic,1), TY_CHAR)
call mfree (IC_LABELS(ic,2), TY_CHAR)
call mfree (IC_UNITS(ic,1), TY_CHAR)
call mfree (IC_UNITS(ic,2), TY_CHAR)
call mfree (IC_HELP(ic), TY_CHAR)
call mfree (ic, TY_STRUCT)
}
end
# IC_CLOSED -- Close ICFIT parameter structure.
procedure ic_closed (ic)
pointer ic # ICFIT pointer
begin
if (ic != NULL) {
# Free memory for the package parameter structure.
call rg_free (IC_RG(ic))
call mfree (IC_XFIT(ic), TY_DOUBLE)
call mfree (IC_YFIT(ic), TY_DOUBLE)
call mfree (IC_WTSFIT(ic), TY_DOUBLE)
call mfree (IC_REJPTS(ic), TY_INT)
call mfree (IC_SAMPLE(ic), TY_CHAR)
call mfree (IC_LABELS(ic,1), TY_CHAR)
call mfree (IC_LABELS(ic,2), TY_CHAR)
call mfree (IC_UNITS(ic,1), TY_CHAR)
call mfree (IC_UNITS(ic,2), TY_CHAR)
call mfree (IC_HELP(ic), TY_CHAR)
call mfree (ic, TY_STRUCT)
}
end
# IC_PSTR -- Put string valued parameters.
procedure ic_pstr (ic, param, str)
pointer ic # ICFIT pointer
char param[ARB] # Parameter to be put
char str[ARB] # String value
int i
pointer ptr
int strdic()
bool streq()
begin
if (streq (param, "sample"))
call strcpy (str, Memc[IC_SAMPLE(ic)], IC_SZSAMPLE)
else if (streq (param, "function")) {
call malloc (ptr, SZ_LINE, TY_CHAR)
i = strdic (str, Memc[ptr], SZ_LINE, FUNCTIONS)
if (i > 0)
IC_FUNCTION(ic) = i
call mfree (ptr, TY_CHAR)
} else if (streq (param, "xlabel"))
call strcpy (str, Memc[IC_LABELS(ic,1)], SZ_LINE)
else if (streq (param, "ylabel"))
call strcpy (str, Memc[IC_LABELS(ic,2)], SZ_LINE)
else if (streq (param, "xunits"))
call strcpy (str, Memc[IC_UNITS(ic,1)], SZ_LINE)
else if (streq (param, "yunits"))
call strcpy (str, Memc[IC_UNITS(ic,2)], SZ_LINE)
else if (streq (param, "help"))
call strcpy (str, Memc[IC_HELP(ic)], SZ_LINE)
else
call error (0, "ICFIT: Unknown parameter")
call ic_gui (ic, "params")
end
# IC_PUTI -- Put integer valued parameters.
procedure ic_puti (ic, param, ival)
pointer ic # ICFIT pointer
char param[ARB] # Parameter to be put
int ival # Integer value
bool streq()
begin
if (streq (param, "naverage"))
IC_NAVERAGE(ic) = ival
else if (streq (param, "order"))
IC_ORDER(ic) = max (1, ival)
else if (streq (param, "niterate"))
IC_NITERATE(ic) = ival
else if (streq (param, "key"))
IC_GKEY(ic) = ival
else if (streq (param, "color"))
IC_COLOR(ic) = ival
else if (streq (param, "markrej"))
IC_MARKREJ(ic) = ival
else
call error (0, "ICFIT: Unknown parameter")
call ic_gui (ic, "params")
end
# IC_PKEY -- Put key parameters.
# Note the key types must be integers not characters.
procedure ic_pkey (ic, key, xaxis, yaxis)
pointer ic # ICFIT pointer
int key # Key to be defined
int xaxis # X axis type
int yaxis # Y axis type
begin
if (key >= 1 && key <= 5) {
IC_AXES(ic, key, 1) = xaxis
IC_AXES(ic, key, 2) = yaxis
if (key == IC_GKEY(ic))
call ic_gui (ic, "graph")
}
end
# IC_GKEY -- Get key parameters.
procedure ic_gkey (ic, key, xaxis, yaxis)
pointer ic # ICFIT pointer
int key # Key to be gotten
int xaxis # X axis type
int yaxis # Y axis type
begin
xaxis = IC_AXES(ic, key, 1)
yaxis = IC_AXES(ic, key, 2)
end
# IC_PUTR -- Put real valued parameters.
procedure ic_putr (ic, param, rval)
pointer ic # ICFIT pointer
char param[ARB] # Parameter to be put
real rval # Real value
bool streq()
begin
if (streq (param, "xmin"))
IC_XMIN(ic) = rval
else if (streq (param, "xmax"))
IC_XMAX(ic) = rval
else if (streq (param, "low"))
IC_LOW(ic) = rval
else if (streq (param, "high"))
IC_HIGH(ic) = rval
else if (streq (param, "grow"))
IC_GROW(ic) = rval
else
call error (0, "ICFIT: Unknown parameter")
call ic_gui (ic, "params")
end
# IC_GSTR -- Get string valued parameters.
procedure ic_gstr (ic, param, str, maxchars)
pointer ic # ICFIT pointer
char param[ARB] # Parameter to be put
char str[maxchars] # String value
int maxchars # Maximum number of characters
bool streq()
begin
if (streq (param, "sample"))
call strcpy (Memc[IC_SAMPLE(ic)], str, maxchars)
else if (streq (param, "xlabel"))
call strcpy (Memc[IC_LABELS(ic,1)], str, maxchars)
else if (streq (param, "ylabel"))
call strcpy (Memc[IC_LABELS(ic,2)], str, maxchars)
else if (streq (param, "xunits"))
call strcpy (Memc[IC_UNITS(ic,1)], str, maxchars)
else if (streq (param, "yunits"))
call strcpy (Memc[IC_UNITS(ic,2)], str, maxchars)
else if (streq (param, "help"))
call strcpy (Memc[IC_HELP(ic)], str, maxchars)
else if (streq (param, "function")) {
switch (IC_FUNCTION(ic)) {
case 1:
call strcpy ("chebyshev", str, maxchars)
case 2:
call strcpy ("legendre", str, maxchars)
case 3:
call strcpy ("spline3", str, maxchars)
case 4:
call strcpy ("spline1", str, maxchars)
case 5:
call strcpy ("user", str, maxchars)
}
} else
call error (0, "ICFIT: Unknown parameter")
end
# IC_GETI -- Get integer valued parameters.
int procedure ic_geti (ic, param)
pointer ic # ICFIT pointer
char param[ARB] # Parameter to be gotten
bool streq()
begin
if (streq (param, "naverage"))
return (IC_NAVERAGE(ic))
else if (streq (param, "order"))
return (IC_ORDER(ic))
else if (streq (param, "niterate"))
return (IC_NITERATE(ic))
else if (streq (param, "key"))
return (IC_GKEY(ic))
else if (streq (param, "nfit"))
return (IC_NFIT(ic))
else if (streq (param, "nreject"))
return (IC_NREJECT(ic))
else if (streq (param, "rejpts"))
return (IC_REJPTS(ic))
else if (streq (param, "color"))
return (IC_COLOR(ic))
else if (streq (param, "markrej"))
return (IC_MARKREJ(ic))
else if (streq (param, "nmin")) {
switch (IC_FUNCTION(ic)) {
case 3:
return (IC_ORDER(ic) + 3)
case 4:
return (IC_ORDER(ic) + 1)
default:
return (IC_ORDER(ic))
}
}
call error (0, "ICFIT: Unknown parameter")
end
# IC_GETR -- Get real valued parameters.
real procedure ic_getr (ic, param)
pointer ic # ICFIT pointer
char param[ARB] # Parameter to be put
bool streq()
begin
if (streq (param, "xmin"))
return (IC_XMIN(ic))
else if (streq (param, "xmax"))
return (IC_XMAX(ic))
else if (streq (param, "low"))
return (IC_LOW(ic))
else if (streq (param, "high"))
return (IC_HIGH(ic))
else if (streq (param, "grow"))
return (IC_GROW(ic))
call error (0, "ICFIT: Unknown parameter")
end
|