aboutsummaryrefslogtreecommitdiff
path: root/math/gsurfit/gs_devalr.x
blob: 06449e38e9c265dbf1240381ccc92d0c2b540b6e (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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

# GS_DPOL -- Procedure to evaluate the polynomial derivative basis functions.

procedure rgs_dpol (x, npts, order, nder, k1, k2, basis)

real	x[npts]		# array of data points
int	npts		# number of points
int	order		# order of new polynomial, order = 1, constant
int	nder		# order of derivative, order = 0, no derivative
real	k1, k2		# normalizing constants
real	basis[ARB]	# basis functions

int	bptr, k, kk
real	fac

begin
	# Optimize for oth and first derivatives.
	if (nder == 0) {
	    call rgs_bpol (x, npts, order, k1, k2, basis)
	    return
	} else if (nder == 1) {
	    call rgs_bpol (x, npts, order, k1, k2, basis)
	    do k = 1, order {
		call amulkr(basis[1+(k-1)*npts], real (k),
		    basis[1+(k-1)*npts], npts)
	    }
	    return
	}

	# Compute the polynomials.
	bptr = 1
	do k = 1, order {
	    if (k == 1)
		call amovkr (real(1.0), basis, npts)
	    else if (k == 2)
		call amovr (x, basis[bptr], npts)
	    else 
		call amulr (basis[bptr-npts], x, basis[bptr], npts)
	    bptr = bptr + npts
	}

	# Apply the derivative factor.
	bptr = 1
	do k = 1, order {
	    if (k == 1) {
	        fac = real(1.0)
		do kk = 2, nder
		    fac = fac * real (kk)
	    } else {
	        fac = real(1.0)
		do kk = k +  nder - 1, k, -1 
	            fac = fac * real(kk)
	    }
	    call amulkr (basis[bptr], fac, basis[bptr], npts)
	    bptr = bptr + npts
	}
end


# GS_DCHEB -- Procedure to evaluate the chebyshev polynomial derivative
# basis functions using the usual recursion relation.

procedure rgs_dcheb (x, npts, order, nder, k1, k2, basis)

real	x[npts]		# array of data points
int	npts		# number of points
int	order		# order of polynomial, order = 1, constant
int	nder		# order of derivative, order = 0, no derivative
real	k1, k2		# normalizing constants
real	basis[ARB]	# basis functions

int	i, k
pointer	fn, dfn, xnorm, bptr, fptr
real	fac

begin
	# Optimze the no derivatives case.
	if (nder == 0) {
	    call rgs_bcheb (x, npts, order, k1, k2, basis)
	    return
	}

	# Allocate working space for the basis functions and derivatives.
	call calloc (fn, npts * (order + nder), TY_REAL)
	call calloc (dfn, npts * (order + nder), TY_REAL)

	# Compute the normalized x values.
	call malloc (xnorm, npts, TY_REAL)
        call altar (x, Memr[xnorm], npts, k1, k2)

	# Compute the current solution.
        bptr = fn
        do k = 1, order + nder {
	    if (k == 1)
	        call amovkr (real(1.0), Memr[bptr], npts)
	    else if (k == 2)
	        call amovr (Memr[xnorm], Memr[bptr], npts)
	    else {
	        call amulr (Memr[xnorm], Memr[bptr-npts], Memr[bptr], npts)
	        call amulkr (Memr[bptr], real(2.0), Memr[bptr], npts)
		call asubr (Memr[bptr], Memr[bptr-2*npts], Memr[bptr], npts)
	    }
	    bptr = bptr + npts
        }

	# Compute the derivative basis functions.
	do i = 1, nder {

	    # Compute the derivatives.
	    bptr = fn
	    fptr = dfn
	    do k = 1, order + nder {
		if (k == 1)
		    call amovkr (real(0.0), Memr[fptr], npts)
		else if (k == 2) {
		    if (i == 1)
		        call amovkr (real(1.0), Memr[fptr], npts)
		    else
		        call amovkr (real(0.0), Memr[fptr], npts)
		} else {
	            call amulr (Memr[xnorm], Memr[fptr-npts], Memr[fptr],
		        npts)
	            call amulkr (Memr[fptr], real(2.0), Memr[fptr], npts)
		    call asubr (Memr[fptr], Memr[fptr-2*npts], Memr[fptr],
		        npts)
		    fac = real (2.0) * real (i)
		    call awsur (Memr[bptr-npts], Memr[fptr], Memr[fptr],
			npts, fac, real(1.0))
		    
		}
	        bptr = bptr + npts
	        fptr = fptr + npts
	    }

	    # Make the derivatives the old solution
	    if (i < nder)
		call amovr (Memr[dfn], Memr[fn], npts * (order + nder))
	}

	# Copy the solution into the basis functions.
	call amovr (Memr[dfn+nder*npts], basis[1], order * npts)

	call mfree (xnorm, TY_REAL)
	call mfree (fn, TY_REAL)
	call mfree (dfn, TY_REAL)
end


# GS_DLEG -- Procedure to evaluate the Legendre polynomial derivative basis
# functions using the usual recursion relation.

procedure rgs_dleg (x, npts, order, nder, k1, k2, basis)

real	x[npts]		# number of data points
int	npts		# number of points
int	order		# order of new polynomial, 1 is a constant
int	nder		# order of derivate, 0 is no derivative
real	k1, k2		# normalizing constants
real	basis[ARB]	# array of basis functions

int	i, k
pointer	fn, dfn, xnorm, bptr, fptr
real	ri, ri1, ri2, fac

begin
	# Optimze the no derivatives case.
	if (nder == 0) {
	    call rgs_bleg (x, npts, order, k1, k2, basis)
	    return
	}

	# Allocate working space for the basis functions and derivatives.
	call calloc (fn, npts * (order + nder), TY_REAL)
	call calloc (dfn, npts * (order + nder), TY_REAL)

	# Compute the normalized x values.
	call malloc (xnorm, npts, TY_REAL)
        call altar (x, Memr[xnorm], npts, k1, k2)

	# Compute the basis functions.
	bptr = fn
	do k = 1, order + nder {
	    if (k == 1)
		call amovkr (real(1.0), Memr[bptr], npts)
	    else if (k == 2)
		call amovr (Memr[xnorm], Memr[bptr], npts)
	    else {
		ri = k
		ri1 = (real(2.0) * ri - real(3.0)) / (ri - real(1.0))
		ri2 = - (ri - real(2.0)) / (ri - real(1.0))
		call amulr (Memr[xnorm], Memr[bptr-npts], Memr[bptr], npts)
		call awsur (Memr[bptr], Memr[bptr-2*npts], Memr[bptr],
		    npts, ri1, ri2)
	    }
	    bptr = bptr + npts
	}

	# Compute the derivative basis functions.
	do i = 1, nder {

	    # Compute the derivatives.
	    bptr = fn
	    fptr = dfn
	    do k = 1, order + nder {
		if (k == 1)
		    call amovkr (real(0.0), Memr[fptr], npts)
		else if (k == 2) {
		    if (i == 1)
		        call amovkr (real(1.0), Memr[fptr], npts)
		    else
		        call amovkr (real(0.0), Memr[fptr], npts)
		} else {
		    ri = k
		    ri1 = (real(2.0) * ri - real(3.0)) / (ri - real(1.0))
		    ri2 = - (ri - real(2.0)) / (ri - real(1.0))
		    call amulr (Memr[xnorm], Memr[fptr-npts], Memr[fptr],
		        npts)
		    call awsur (Memr[fptr], Memr[fptr-2*npts], Memr[fptr],
		        npts, ri1, ri2)
		    fac = ri1 * real (i)
		    call awsur (Memr[bptr-npts], Memr[fptr], Memr[fptr],
			npts, fac, real(1.0))
		    
		}
	        bptr = bptr + npts
	        fptr = fptr + npts
	    }

	    # Make the derivatives the old solution
	    if (i < nder)
		call amovr (Memr[dfn], Memr[fn], npts * (order + nder))
	}

	# Copy the solution into the basis functions.
	call amovr (Memr[dfn+nder*npts], basis[1], order * npts)

	call mfree (xnorm, TY_REAL)
	call mfree (fn, TY_REAL)
	call mfree (dfn, TY_REAL)
end