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
|
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
include <math/curfit.h>
include "dcurfitdef.h"
# CVRESTORE -- Procedure to restore fit parameters saved by CVSAVE
# for use by CVEVAL and CVVECTOR. The parameters are assumed to
# be stored in fit in the following order, curve_type, order, xmin,
# xmax, followed by the coefficients.
procedure dcvrestore (cv, fit)
pointer cv # curve descriptor
double fit[ARB] # array containing fit parameters
int curve_type, order
errchk malloc
begin
# allocate space for curve descriptor
call malloc (cv, LEN_CVSTRUCT, TY_STRUCT)
order = nint (CV_SAVEORDER(fit))
if (order < 1)
call error (0, "CVRESTORE: Illegal order.")
if (CV_SAVEXMAX(fit) <= CV_SAVEXMIN(fit))
call error (0, "CVRESTORE: xmax <= xmin.")
# set curve_type dependent curve descriptor parameters
curve_type = nint (CV_SAVETYPE(fit))
switch (curve_type) {
case CHEBYSHEV, LEGENDRE:
CV_ORDER(cv) = order
CV_NCOEFF(cv) = order
CV_RANGE(cv) = 2. / (CV_SAVEXMAX(fit) - CV_SAVEXMIN(fit))
CV_MAXMIN(cv) = - (CV_SAVEXMAX(fit) + CV_SAVEXMIN(fit)) / 2.
CV_USERFNC(cv) = NULL
case SPLINE3:
CV_ORDER(cv) = SPLINE3_ORDER
CV_NCOEFF(cv) = order + SPLINE3_ORDER - 1
CV_NPIECES(cv) = order - 1
CV_SPACING(cv) = order / (CV_SAVEXMAX(fit) - CV_SAVEXMIN(fit))
CV_USERFNC(cv) = NULL
case SPLINE1:
CV_ORDER(cv) = SPLINE1_ORDER
CV_NCOEFF(cv) = order + SPLINE1_ORDER - 1
CV_NPIECES(cv) = order - 1
CV_SPACING(cv) = order / (CV_SAVEXMAX(fit) - CV_SAVEXMIN(fit))
CV_USERFNC(cv) = NULL
case USERFNC:
CV_ORDER(cv) = order
CV_NCOEFF(cv) = order
CV_RANGE(cv) = 2. / (CV_SAVEXMAX(fit) - CV_SAVEXMIN(fit))
CV_MAXMIN(cv) = - (CV_SAVEXMAX(fit) + CV_SAVEXMIN(fit)) / 2.
CV_USERFNCD(cv) = CV_SAVEFNC(fit) # avoids type conversion
default:
call error (0, "CVRESTORE: Unknown curve type.")
}
# set remaining curve parameters
CV_TYPE(cv) = curve_type
CV_XMIN(cv) = CV_SAVEXMIN(fit)
CV_XMAX(cv) = CV_SAVEXMAX(fit)
# allocate space for xbasis and coefficient arrays, set remaining
# pointers to NULL
call calloc (CV_XBASIS(cv), CV_ORDER(cv), TY_DOUBLE)
call calloc (CV_COEFF(cv), CV_NCOEFF(cv), TY_DOUBLE)
CV_MATRIX(cv) = NULL
CV_CHOFAC(cv) = NULL
CV_VECTOR(cv) = NULL
CV_BASIS(cv) = NULL
CV_LEFT(cv) = NULL
CV_WY(cv) = NULL
# restore coefficients
if (CV_TYPE(cv) == USERFNC)
call amovd (fit[CV_SAVECOEFF+1], COEFF(CV_COEFF(cv)),
CV_NCOEFF(cv))
else
call amovd (fit[CV_SAVECOEFF], COEFF(CV_COEFF(cv)),
CV_NCOEFF(cv))
end
|