aboutsummaryrefslogtreecommitdiff
path: root/math/curfit/cvsave.gx
blob: 95fedd2b89f907b5af0fe7c8dd339f1bc49dbe1a (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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include <math/curfit.h>

$if (datatype == r)
include "curfitdef.h"
$else
include "dcurfitdef.h"
$endif

# CVSAVE -- Procedure to save the parameters of the fit for later
# use by cveval and cvvector. Only curve_type, order, xmin, xmax
# and the coefficients are saved. The parameters are saved in fit
# in the order curve_type, order, xmin, xmax, followed by the
# coefficients.

$if (datatype == r)
procedure cvsave (cv, fit)
$else
procedure dcvsave (cv, fit)
$endif

pointer	cv		# curve descriptor
PIXEL	fit[ARB]	# PIXEL array containing curve parameters

begin
	# set common curve parameters
	CV_SAVETYPE(fit) = CV_TYPE(cv)
	CV_SAVEXMIN(fit) = CV_XMIN(cv)
	CV_SAVEXMAX(fit) = CV_XMAX(cv)
	if (CV_TYPE(cv) == USERFNC)
	    $if (datatype == r)
	    CV_SAVEFNC(fit) = CV_USERFNCR(cv)	# no type conversion
	    $else
	    CV_SAVEFNC(fit) = CV_USERFNCD(cv)
	    $endif

	# set curve-type dependent parmeters
	switch (CV_TYPE(cv)) {
	case LEGENDRE, CHEBYSHEV, USERFNC:
	    CV_SAVEORDER(fit) = CV_ORDER(cv)
	case SPLINE1, SPLINE3:
	    CV_SAVEORDER(fit) = CV_NPIECES(cv) + 1
	default:
	    call error (0, "CVSAVE: Unknown curve type.")
	}


	# set coefficients
	if (CV_TYPE(cv) == USERFNC)
	    call amov$t (COEFF(CV_COEFF(cv)), fit[CV_SAVECOEFF+1],
	        CV_NCOEFF(cv)) 
	else
	    call amov$t (COEFF(CV_COEFF(cv)), fit[CV_SAVECOEFF],
	        CV_NCOEFF(cv)) 
end