aboutsummaryrefslogtreecommitdiff
path: root/pkg/xtools/inlfit/inggraph.gx
blob: 0eeb48d8528adc88b741abf5fb0c25b0258dde3b (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
include	<gset.h>
include	<pkg/gtools.h>
include	<math/nlfit.h>
include	<pkg/inlfit.h>

define	NGRAPH		100		# Number of fit points to graph
define	MSIZE		3.0		# mark size for rejected points (real)


# ING_GRAPH -- Graph data and fit. First plot the data marking deleted
# points, then overplot rejected points, and finally overplot the fit.

procedure ing_graph$t (in, gp, gt, nl, x, y, wts, npts, nvars)

pointer	in				# INLFIT pointer
pointer	gp				# GIO pointer
pointer	gt				# GTOOLS pointers
pointer	nl				# NLFIT pointer
PIXEL	x[ARB]				# Independent variables (npts * nvars)
PIXEL	y[npts]				# Dependent variables
PIXEL	wts[npts]			# Weights
int	npts				# Number of points
int	nvars				# Number of variables

pointer	xout, yout
pointer	sp

begin
	# Alloacate axes data memory.
	call smark (sp)
	call salloc (xout, npts, TY_PIXEL)
	call salloc (yout, npts, TY_PIXEL)

	# Set axes data.
	call ing_axes$t (in, gt, nl, 1, x, y, Mem$t[xout], npts, nvars)
	call ing_axes$t (in, gt, nl, 2, x, y, Mem$t[yout], npts, nvars)

	# Set graphic parameters.
	call ing_params$t (in, nl, x, y, wts, npts, nvars, gt)

	# Plot data and deleted points.
	call ing_g1$t (in, gp, gt, Mem$t[xout], Mem$t[yout], wts, npts)

	# Overplot rejected points.
	call ing_g2$t (in, gp, gt, Mem$t[xout], Mem$t[yout], npts)

	# Overplot the fit.
	call ing_gf$t (in, gp, gt, nl, x, wts, npts, nvars)

	# Free memory
	call sfree (sp)
end


# ING_G1 - Plot data and deleted points (weight = 0.0).

procedure ing_g1$t (in, gp, gt, x, y, wts, npts)

pointer	in				# INLFIT pointer
pointer	gp				# GIO pointer
pointer	gt				# GTOOLS pointer
PIXEL	x[npts]				# Ordinates
PIXEL	y[npts]				# Abscissas
PIXEL	wts[npts]			# Weights
int	npts				# Number of points

int	i
pointer	sp, xr, yr, xr1, yr1, gt1

int	in_geti()

begin
	# Allocate memory.
	call smark (sp)
	call salloc (xr, npts, TY_REAL)
	call salloc (yr, npts, TY_REAL)
	call salloc (xr1, 2, TY_REAL)
	call salloc (yr1, 2, TY_REAL)

	# Change type to real for plotting.
	call acht$tr (x, Memr[xr], npts)
	call acht$tr (y, Memr[yr], npts)

	# Start new graph if not overplotting.
	if (in_geti (in, INLOVERPLOT) == NO) {
	    call gclear (gp)
	    call gascale (gp, Memr[xr], npts, 1)
	    call gascale (gp, Memr[yr], npts, 2)
	    call gt_swind (gp, gt)
	    call gt_labax (gp, gt)
	}

	# Initialize auxiliaray GTOOLS descriptor for deleted points.
	call gt_copy (gt, gt1)
	call gt_sets (gt1, GTTYPE, "mark")
	call gt_sets (gt1, GTMARK, "cross")

	# Plot data points marking deleted points with other symbol.
	Memr[xr1] = Memr[xr]
	Memr[yr1] = Memr[yr]
	do i = 1, npts {
	    if (wts[i] == PIXEL (0.0)) {
		call gt_plot (gp, gt1, Memr[xr+i-1], Memr[yr+i-1], 1) 
	    } else {
#		Memr[xr1+1] = Memr[xr+i-1]
#		Memr[yr1+1] = Memr[yr+i-1]
#		call gt_plot (gp, gt, Memr[xr1], Memr[yr1], 2)
#		Memr[xr1] = Memr[xr1+1]
#		Memr[yr1] = Memr[yr1+1]

		call gt_plot (gp, gt, Memr[xr+i-1], Memr[yr+i-1], 1)
	    }
	}

	# Reset overplot flag.
	call in_puti (in, INLOVERPLOT, NO)

	# Free memory and auxiliary GTOOLS descriptor.
	call sfree (sp)
	call gt_free (gt1)
end


# ING_G2 - Overplot rejected points.

procedure ing_g2$t (in, gp, gt, x, y, npts)

pointer	in			# INLFIT pointer
pointer	gp			# GIO pointer
pointer	gt			# GTOOLS pointer
PIXEL	x[npts], y[npts]	# Data points
int	npts			# Number of data points

int	i
pointer	sp, xr, yr, gt1
pointer	rejpts

int	in_geti()
int	in_getp()

begin
	# Don't plot if there are no rejected points
	if (in_geti (in, INLNREJPTS) == 0)
	    return

	# Allocate axes memory.
	call smark (sp)
	call salloc (xr, npts, TY_REAL)
	call salloc (yr, npts, TY_REAL)

	# Change type to real for plotting.
	call acht$tr (x, Memr[xr], npts)
	call acht$tr (y, Memr[yr], npts)

	# Initialize auxiliary GTOOLS descriptor
	# for rejected points.
	call gt_copy (gt, gt1)
	call gt_sets (gt1, GTTYPE, "mark")
	call gt_sets (gt1, GTMARK, "diamond")
	call gt_setr (gt1, GTXSIZE, MSIZE)
	call gt_setr (gt1, GTYSIZE, MSIZE)

	# Plot rejected points if there are any.
	rejpts = in_getp (in, INLREJPTS)
	do i = 1, npts {
	    if (Memi[rejpts + i - 1] == YES)
		call gt_plot (gp, gt1, Memr[xr + i - 1], Memr[yr + i - 1], 1)
	}

	# Free memory and auxiliary GTOOLS descriptor.
	call gt_free (gt1)
	call sfree (sp)
end


# ING_GF - Overplot the fit using dashed lines.

procedure ing_gf$t (in, gp, gt, nl, xin, wts, npts, nvars)

pointer	in			# INLFIT pointer
pointer	gp			# GIO pointer
pointer	gt			# GTOOL pointer
pointer	nl			# NLFIT pointer
PIXEL	xin[ARB]		# Independent variables
PIXEL	wts[npts]		# weights
int	npts			# Number of points to plot
int	nvars			# Number of variables

int	i
pointer	sp, xr, yr, x, y, xo, yo, gt1

int	in_geti()

begin
	# Don't plot if there is a fit error.
	if (in_geti (in, INLFITERROR) != DONE ||
	    in_geti (in, INLPLOTFIT) == NO)
	    return

	# Allocate memory.
	call smark (sp)
	call salloc (xr, npts, TY_REAL)
	call salloc (yr, npts, TY_REAL)
	call salloc (x,  npts * nvars, TY_PIXEL)
	call salloc (y,  npts, TY_PIXEL)
	call salloc (xo, npts, TY_PIXEL)
	call salloc (yo, npts, TY_PIXEL)

	# Move input data into vector.
	call amov$t (xin, Mem$t[x], npts * nvars)

	# Calculate vector of fit values.
	call nlvector$t (nl, Mem$t[x], Mem$t[y], npts, nvars)

	# Set axes data.
	call ing_axes$t (in, gt, nl, 1, Mem$t[x], Mem$t[y], Mem$t[xo],
			 npts, nvars)
	call ing_axes$t (in, gt, nl, 2, Mem$t[x], Mem$t[y], Mem$t[yo],
			 npts, nvars)

	# Convert to real for plotting.
	call acht$tr (Mem$t[xo], Memr[xr], npts)
	call acht$tr (Mem$t[yo], Memr[yr], npts)

	# Initialize auxiliary GTOOLS descriptor, plot the
	# fit and free the auxiliary descriptor.
	call gt_copy (gt, gt1)
	call gt_sets (gt1, GTTYPE, "mark")
	call gt_sets (gt1, GTMARK, "box")
	call gt_setr (gt1, GTXSIZE, MSIZE)
	call gt_setr (gt1, GTXSIZE, MSIZE)
	do i = 1, npts {
	    if (wts[i] != PIXEL (0.0))
		call gt_plot (gp, gt1, Memr[xr+i-1], Memr[yr+i-1], 1) 
	}
	call gt_free (gt1)

	# Free memory.
	call sfree (sp)
end