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

include	<gset.h>
include	<mach.h>
include	<pkg/rg.h>
include	<pkg/gtools.h>
include	"icfit.h"

# ICG_SAMPLE -- Mark sample.

procedure icg_sampler (ic, gp, gt, x, npts, pltype)

pointer	ic				# ICFIT pointer
pointer	gp				# GIO pointer
pointer	gt				# GTOOLS pointer
real	x[npts]				# Ordinates of graph
int	npts				# Number of data points
int	pltype				# Plot line type

pointer	rg
int	i, axis, pltype1
real	xl, xr, yb, yt, dy
real	x1, x2, y1, y2, y3

int	gstati(), stridxs(), gt_geti()
pointer	rg_xrangesr()

begin
	if (stridxs ("*", Memc[IC_SAMPLE(ic)]) > 0)
	    return

	# Find axis along which the independent data is plotted.
	if (IC_AXES(ic,IC_GKEY(ic),1) == 'x')
	    axis = 1
	else if (IC_AXES(ic,IC_GKEY(ic),2) == 'x')
	    axis = 2
	else
	    return

	if (gt_geti (gt, GTTRANSPOSE) == YES)
	    axis = mod (axis, 2) + 1

	pltype1 = gstati (gp, G_PLTYPE)
	call gseti (gp, G_PLTYPE, pltype)
	rg = rg_xrangesr (Memc[IC_SAMPLE(ic)], x, npts)

	switch (axis) {
	case 1:
	    call ggwind (gp, xl, xr, yb, yt)

	    dy = yt - yb
	    y1 = yb + dy / 100
	    y2 = y1 + dy / 20
	    y3 = (y1 + y2) / 2

	    do i = 1, RG_NRGS(rg) {
	        x1 = x[RG_X1(rg, i)]
	        x2 = x[RG_X2(rg, i)]
	        if ((x1 > xl) && (x1 < xr))
	            call gline (gp, x1, y1, x1, y2)
	        if ((x2 > xl) && (x2 < xr))
	            call gline (gp, x2, y1, x2, y2)
	        call gline (gp, x1, y3, x2, y3)
	    }
	case 2:
	    call ggwind (gp, yb, yt, xl, xr)

	    dy = yt - yb
	    y1 = yb + dy / 100
	    y2 = y1 + dy / 20
	    y3 = (y1 + y2) / 2

	    do i = 1, RG_NRGS(rg) {
	        x1 = x[RG_X1(rg, i)]
	        x2 = x[RG_X2(rg, i)]
	        if ((x1 > xl) && (x1 < xr))
	            call gline (gp, y1, x1, y2, x1)
	        if ((x2 > xl) && (x2 < xr))
	            call gline (gp, y1, x2, y2, x2)
	        call gline (gp, y3, x1, y3, x2)
	    }
	}

	call gseti (gp, G_PLTYPE, pltype1)
	call rg_free (rg)
end


# ICG_DSAMPLE -- Delete sample region.

procedure icg_dsampler (wx, wy, ic, gp, gt, x, npts)

real	wx, wy				# Region to be deleted
pointer	ic				# ICFIT pointer
pointer	gp				# GIO pointer
pointer	gt				# GTOOLS pointer
real	x[npts]				# Ordinates of graph
int	npts				# Number of data points

pointer	sp, str, rg
int	i,  j, axis, pltype1
real	w, diff
real	xl, xr, yb, yt, dy
real	x1, x2, y1, y2, y3

int	gstati(), stridxs(), gt_geti()
pointer	rg_xrangesr()

begin
	if (stridxs ("*", Memc[IC_SAMPLE(ic)]) > 0)
	    return

	# Find axis along which the independent data is plotted.
	if (IC_AXES(ic,IC_GKEY(ic),1) == 'x')
	    axis = 1
	else if (IC_AXES(ic,IC_GKEY(ic),2) == 'x')
	    axis = 2
	else
	    return

	if (gt_geti (gt, GTTRANSPOSE) == YES)
	    axis = mod (axis, 2) + 1

	# Initialize
	pltype1 = gstati (gp, G_PLTYPE)
	call gseti (gp, G_PLTYPE, 0)
	rg = rg_xrangesr (Memc[IC_SAMPLE(ic)], x, npts)

	call smark (sp)
	call salloc (str, SZ_FNAME, TY_CHAR)
	Memc[IC_SAMPLE(ic)] = EOS

	# Find nearest sample region
	if (axis == 1)
	    w = wx
	else
	    w = wy

	j = 1
	diff = MAX_REAL
	do i = 1, RG_NRGS(rg) {
	    x1 = x[RG_X1(rg, i)]
	    x2 = x[RG_X2(rg, i)]
	    if (w < x1) {
		if (x1 - w < diff) {
		    diff = x1 - wx
		    j = i
		}
	    } else if (wx > x2) {
		if (wx - x2 < diff) {
		    diff = x1 - wx
		    j = i
		}
	    } else {
		diff = 0.
		j = i
	    }
	}

	# Erase sample region and reset sample string
	switch (axis) {
	case 1:
	    call ggwind (gp, xl, xr, yb, yt)

	    dy = yt - yb
	    y1 = yb + dy / 100
	    y2 = y1 + dy / 20
	    y3 = (y1 + y2) / 2

	    do i = 1, RG_NRGS(rg) {
	        x1 = x[RG_X1(rg, i)]
	        x2 = x[RG_X2(rg, i)]
		if (i != j) {
		    if (x1 == int(x1) && x2 == int(x2))
			call sprintf (Memc[str], SZ_FNAME, " %d:%d")
		    else
			call sprintf (Memc[str], SZ_FNAME, " %g:%g")
			call pargr (x1)
			call pargr (x2)
		    call strcat (Memc[str], Memc[IC_SAMPLE(ic)], IC_SZSAMPLE)
		} else {
		    if ((x1 > xl) && (x1 < xr))
			call gline (gp, x1, y1, x1, y2)
		    if ((x2 > xl) && (x2 < xr))
			call gline (gp, x2, y1, x2, y2)
		    call gline (gp, x1, y3, x2, y3)
		    IC_NEWX(ic) = YES
		}
	    }
	case 2:
	    call ggwind (gp, yb, yt, xl, xr)

	    dy = yt - yb
	    y1 = yb + dy / 100
	    y2 = y1 + dy / 20
	    y3 = (y1 + y2) / 2

	    do i = 1, RG_NRGS(rg) {
	        x1 = x[RG_X1(rg, i)]
	        x2 = x[RG_X2(rg, i)]
		if (i != j) {
		    if (x1 == int(x1) && x2 == int(x2))
			call sprintf (Memc[str], SZ_FNAME, " %d:%d")
		    else
			call sprintf (Memc[str], SZ_FNAME, " %g:%g")
			call pargr (x1)
			call pargr (x2)
		    call strcat (Memc[str], Memc[IC_SAMPLE(ic)], IC_SZSAMPLE)
		} else {
		    if ((x1 > xl) && (x1 < xr))
			call gline (gp, y1, x1, y2, x1)
		    if ((x2 > xl) && (x2 < xr))
			call gline (gp, y1, x2, y2, x2)
		    call gline (gp, y3, x1, y3, x2)
		    IC_NEWX(ic) = YES
		}
	    }
	}

	if (Memc[IC_SAMPLE(ic)] == EOS)
	    call strcat ("*", Memc[IC_SAMPLE(ic)], IC_SZSAMPLE)

	call gseti (gp, G_PLTYPE, pltype1)
	call rg_free (rg)
	call sfree (sp)
end