aboutsummaryrefslogtreecommitdiff
path: root/noao/twodspec/longslit/transform/igsfit/xgs.x
blob: 7d2ea331aaaa0f5a8ec1f4c7cb9d5f1bc880ce22 (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
include <math/gsurfit.h>

# XGS -- These routines provide an interface between real input data and
# the double precision surface fitting.  Rather than make the input data
# be double precision we only want the internal surface fitting arithmetic
# to be double.  But the surface fitting package only provides real
# arithmetic for real input and double precision arithmetic for double
# precision input.  Hence these interfaces.  Note that the save and restore
# functions use double precision.

# XGSINIT --  Procedure to initialize the surface descriptor.

procedure xgsinit (sf, surface_type, xorder, yorder, xterms, xmin, xmax,
    ymin, ymax)

pointer	sf		# surface descriptor
int	surface_type	# type of surface to be fitted
int	xorder		# x order of surface to be fit
int	yorder		# y order of surface to be fit
int	xterms		# presence of cross terms
real    xmin		# minimum value of x
real	xmax		# maximum value of x
real	ymin		# minimum value of y
real	ymax		# maximum value of y

begin
	call dgsinit (sf, surface_type, xorder, yorder, xterms, double (xmin),
	    double (xmax), double (ymin), double (ymax))
end


# XGSFIT -- Procedure to solve the normal equations for a surface.

procedure xgsfit (sf, x, y, z, w, npts, wtflag, ier)

pointer	sf		# surface descriptor
real	x[npts]		# array of x values
real	y[npts]		# array of y values
real	z[npts]		# data array
real	w[npts]		# array of weights
int	npts		# number of data points
int	wtflag		# type of weighting
int	ier		# ier = OK, everything OK
			# ier = SINGULAR, matrix is singular, 1 or more
			# coefficients are 0.
			# ier = NO_DEG_FREEDOM, too few points to solve matrix

pointer	sp, xd, yd, zd, wd
errchk	salloc

begin
	call smark (sp)
	call salloc (xd, npts, TY_DOUBLE)
	call salloc (yd, npts, TY_DOUBLE)
	call salloc (zd, npts, TY_DOUBLE)
	call salloc (wd, npts, TY_DOUBLE)
	call achtrd (x, Memd[xd], npts)
	call achtrd (y, Memd[yd], npts)
	call achtrd (z, Memd[zd], npts)
	call achtrd (w, Memd[wd], npts)
	call dgsfit (sf, Memd[xd], Memd[yd], Memd[zd], Memd[wd], npts,
	    wtflag, ier)
	call sfree (sp)
end


# XGSVECTOR -- Procedure to evaluate the fitted surface at an array of points.

procedure xgsvector (sf, x, y, zfit, npts)

pointer	sf		# pointer to surface descriptor structure
real	x[ARB]		# x value
real	y[ARB]		# y value
real	zfit[ARB]	# fits surface values
int	npts		# number of data points

pointer	sp, xd, yd, zd
errchk	salloc

begin
	call smark (sp)
	call salloc (xd, npts, TY_DOUBLE)
	call salloc (yd, npts, TY_DOUBLE)
	call salloc (zd, npts, TY_DOUBLE)
	call achtrd (x, Memd[xd], npts)
	call achtrd (y, Memd[yd], npts)
	call dgsvector (sf, Memd[xd], Memd[yd], Memd[zd], npts)
	call achtdr (Memd[zd], zfit, npts)
	call sfree (sp)
end


# XGSEVAL -- Procedure to evaluate the fitted surface at a single point.

real procedure xgseval (sf, x, y)

pointer	sf		# pointer to surface descriptor structure
real	x		# x value
real	y		# y value

double	dgseval()

begin
	return (real (dgseval (sf, double (x), double (y))))
end


# XGSADD -- Procedure to add the fits from two surfaces together.

procedure xgsadd (sf1, sf2, sf3)

pointer	sf1		# pointer to the first surface
pointer	sf2		# pointer to the second surface
pointer	sf3		# pointer to the output surface

begin
	call dgsadd (sf1, sf2, sf3)
end


# XGSFREE -- Procedure to free the surface descriptor

procedure xgsfree (sf)

pointer	sf	# the surface descriptor

begin
	call dgsfree (sf)
end


# XGSGCOEFF -- Procedure to fetch a particular coefficient.

real procedure xgsgcoeff (sf, xorder, yorder)

pointer	sf		# pointer to the surface fitting descriptor
int	xorder		# X order of desired coefficent
int	yorder		# Y order of desired coefficent

double	dgsgcoeff()

begin
	return (real (dgsgcoeff (sf, xorder, yorder)))
end


# XGSSCOEFF -- Procedure to set a particular coefficient.

procedure xgsscoeff (sf, xorder, yorder, coeff)

pointer	sf		# pointer to the surface fitting descriptor
int	xorder		# X order of desired coefficent
int	yorder		# Y order of desired coefficent
real	coeff		# Coefficient value

begin
	call dgsscoeff (sf, xorder, yorder, double (coeff))
end


# XGSGETR -- Procedure to fetch a real gsurfit parameter

real procedure xgsgetr (sf, parameter)

pointer	sf		# pointer to the surface fit
int	parameter	# parameter to be fetched

double	dgsgetd()

begin
	return (real (dgsgetd (sf, parameter)))
end


# XGSGETI -- Procedure to fetch an integer parameter

int procedure xgsgeti (sf, parameter)

pointer sf		# pointer to the surface fit
int	parameter	# integer parameter

int	dgsgeti()

begin
	return (dgsgeti (sf, parameter))
end


# XGSSAVE -- Procedure to save the surface fit for later use by the
# evaluate routines.
#
# NOTE THAT THIS USES DOUBLE PRECISION FOR THE COEFFICIENTS.

procedure xgssave (sf, fit)

pointer	sf		# pointer to the surface descriptor
double	fit[ARB]	# array for storing fit

begin
	call dgssave (sf, fit)
end


# XGSRESTORE -- Procedure to restore the surface fit stored by GSSAVE
# to the surface descriptor for use by the evaluating routines.
#
# NOTE THAT THIS USES DOUBLE PRECISION FOR THE COEFFICIENTS.

procedure xgsrestore (sf, fit)

pointer	sf		# surface descriptor
double	fit[ARB]	# array containing the surface parameters and

begin
	call dgsrestore (sf, fit)
end


# XGSDER -- Procedure to calculate a new surface which is a derivative of
# the previous surface

procedure xgsder (sf1, x, y, zfit, npts, nxd, nyd)

pointer	sf1		# pointer to the previous surface
real	x[npts]		# x values
real	y[npts]		# y values
real	zfit[npts]	# fitted values
int	npts		# number of points
int	nxd, nyd	# order of the derivatives in x and y

pointer	sp, xd, yd, zd

begin
	call smark (sp)
	call salloc (xd, npts, TY_DOUBLE)
	call salloc (yd, npts, TY_DOUBLE)
	call salloc (zd, npts, TY_DOUBLE)
	call achtrd (x, Memd[xd], npts)
	call achtrd (y, Memd[yd], npts)
	call dgsder (sf1, Memd[xd], Memd[yd], Memd[zd], npts, nxd, nyd)
	call achtdr (Memd[zd], zfit, npts)
	call sfree (sp)
end