aboutsummaryrefslogtreecommitdiff
path: root/pkg/xtools/icfit/icfvshowr.x
blob: 2d50020fb39fd6ebd24d0e40414cd4c0212748f8 (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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	<math/curfit.h>
include	"icfit.h"
include	"names.h"

# IC_FVSHOW -- Show fit parameters in verbose mode.

procedure ic_fvshowr (ic, cv, x, y, wts, npts, fd)

pointer	ic		# ICFIT pointer
pointer	cv		# Curfit pointer
real	x[ARB]		# Ordinates
real	y[ARB]		# Abscissas
real	wts[ARB]	# Weights
int	npts		# Number of data points
int	fd		# Output descriptor

int	i, n, deleted, ncoeffs
real	chisqr, rms
pointer	sp, fit, wts1, coeffs, errors

int	rcvstati()
real	ic_rmsr()

begin
	# Do the standard ic_show option, then add on the verbose part.
	call ic_fshow (ic, fd)

	if (npts == 0) {
	    call eprintf ("# Incomplete output - no data points for fit\n")
	    return
	}

	# Determine the number of coefficients and allocate memory.

	ncoeffs = rcvstati (cv, CVNCOEFF)
	call smark (sp)
	call salloc (coeffs, ncoeffs, TY_REAL)
	call salloc (errors, ncoeffs, TY_REAL)

	if (npts == IC_NFIT(ic)) {
	    # Allocate memory for the fit.

	    n = npts
	    call salloc (fit, n, TY_REAL)
	    call salloc (wts1, n, TY_REAL)

	    # Eliminate rejected points and count deleted points.

	    call amovr (wts, Memr[wts1], n)
	    if (IC_NREJECT(ic) > 0) {
		do i = 1, npts {
		    if (Memi[IC_REJPTS(ic)+i-1] == YES)
			Memr[wts1+i-1] = 0.
		}
	    }
	    deleted = 0
	    do i = 1, n {
		if (wts[i] == 0.)
		    deleted = deleted + 1
	    }

	    # Get the coefficients and compute the errors.

	    call rcvvector (cv, x, Memr[fit], n)
	    call rcvcoeff (cv, Memr[coeffs], ncoeffs)
	    call rcverrors (cv, y, Memr[wts1], Memr[fit], n, chisqr,
		Memr[errors])
	    rms = ic_rmsr (x, y, Memr[fit], Memr[wts1], n)
	} else {
	    # Allocate memory for the fit.

	    n = IC_NFIT(ic)
	    call salloc (fit, n, TY_REAL)
	    call salloc (wts1, n, TY_REAL)

	    # Eliminate rejected points and count deleted points.

	    call amovr (Memr[IC_WTSFIT(ic)], Memr[wts1], n)
	    if (IC_NREJECT(ic) > 0) {
	        do i = 1, npts {
		    if (Memi[IC_REJPTS(ic)+i-1] == YES)
			Memr[wts1+i-1] = 0.
		}
	    }
	    deleted = 0
	    do i = 1, n {
		if (wts[i] == 0.)
		    deleted = deleted + 1
	    }

	    # Get the coefficients and compute the errors.

	    call rcvvector (cv, Memr[IC_XFIT(ic)], Memr[fit], n)
	    rms = ic_rmsr (Memr[IC_XFIT(ic)], Memr[IC_YFIT(ic)],
		Memr[fit], Memr[wts1], n)
	    call rcvcoeff (cv, Memr[coeffs], ncoeffs)
	    call rcverrors (cv, Memr[IC_YFIT(ic)], Memr[wts1], Memr[fit],
		n, chisqr, Memr[errors])
	}

	# Print the error analysis.

	call fprintf (fd, "# total points = %d\n# sample points = %d\n")
	    call pargi (npts)
	    call pargi (n)
	call fprintf (fd, "# nrejected = %d\n# deleted = %d\n")
	    call pargi (IC_NREJECT(ic))
	    call pargi (deleted)
	call fprintf (fd, "# RMS = %10.7g\n")
	    call pargr (rms)
	call fprintf (fd, "# square root of reduced chi square = %10.7g\n")
	    call pargr (sqrt (chisqr))

	call fprintf (fd, "# \t  coefficent\t  error\n")
	do i = 1, ncoeffs {
	    call fprintf (fd, "# \t%14.7e\t%14.7e\n")
		call pargr (Memr[coeffs+i-1])
	 	call pargr (Memr[errors+i-1])
	}

	# Free allocated memory.

	call sfree (sp)
end


# IC_FXYSHOW -- List data as x, y, fit, weight lines on output.

procedure ic_fxyshowr (ic, cv, x, y, w, npts, fd)

pointer	ic			# ICFIT pointer
pointer	cv			# Pointer to curfit structure
real	x[npts]			# Array of x data values
real	y[npts]			# Array of y data values
real	w[npts]			# Array of weight data values
int	npts			# Number of data values
int	fd			# Output file descriptor

int	i
real	rcveval()

begin
	# List the data being fit (not necessarily the input data).
	call fprintf (fd, "#      X        Y    Y FIT   WEIGHT\n")
	if (npts == IC_NFIT(ic)) {
	    do i = 1, npts {
		call fprintf (fd, "%8g %8g %8g %8g\n")
		    call pargr (x[i])
		    call pargr (y[i])
		    call pargr (rcveval (cv, x[i]))
		    call pargr (w[i])
	    }
	} else {
	    do i = 1, IC_NFIT(ic) {
		call fprintf (fd, "%8g %8g %8g %8g\n")
		    call pargr (Memr[IC_XFIT(ic)+i-1])
		    call pargr (Memr[IC_YFIT(ic)+i-1])
		    call pargr (rcveval (cv, Memr[IC_XFIT(ic)+i-1]))
		    call pargr (Memr[IC_WTSFIT(ic)+i-1])
	    }
	}
end