aboutsummaryrefslogtreecommitdiff
path: root/pkg/images/immatch/src/xregister/rgxplot.x
blob: 8b347ab573bfb1bb6b9bf264b8b28d53d83400e5 (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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
include <imhdr.h>
include <gset.h>

# RG_XPLINE -- Plot a line of reference and input image.

procedure rg_xpline (gd, imr, im, nliner, xshift, yshift)

pointer	gd		#I pointer to the graphics stream
pointer	imr		#I pointer to the reference image
pointer	im		#I pointer to the image
int	nliner		#I the reference line
int	xshift		#I x shift
int	yshift		#I y shift

int	i, rncols, rnlines, incols, inlines
pointer	sp, title, xr, xi, ptrr, ptri
real	ymin, ymax, tymin, tymax
int	strlen()
pointer	imgl1r(), imgl2r()

begin
	# Return if no graphics stream.
	if (gd == NULL)
	    return

	# Check for valid line number.
	rncols = IM_LEN(imr,1)
	if (IM_NDIM(imr) == 1)
	    rnlines = 1
	else
	    rnlines = IM_LEN(imr,2)
	incols = IM_LEN(im,1)
	if (IM_NDIM(im) == 1)
	    inlines = 1
	else
	    inlines = IM_LEN(im,2)
	if ((nliner < 1) || (nliner > rnlines))
	    return
	if (((nliner + yshift) < 1) || ((nliner + yshift) > inlines)) 
	    return

	# Allocate working space.
	call smark (sp)
	call salloc (title, SZ_LINE, TY_CHAR)
	call salloc (xr, rncols, TY_REAL)
	call salloc (xi, rncols, TY_REAL)

	# Initialize the x data data.
	do i = 1, rncols {
	    Memr[xr+i-1] = i
	    Memr[xi+i-1] = i - xshift
	}

	# Initalize the y data.
	if (IM_NDIM(imr) == 1)
	    ptrr = imgl1r (imr)
	else
	    ptrr = imgl2r (imr, nliner)
	if (IM_NDIM(im) == 1)
	    ptri = imgl1r (im)
	else
	    ptri = imgl2r (im, nliner + yshift)
	call alimr (Memr[ptrr], rncols, ymin, ymax)
	call alimr (Memr[ptri], incols, tymin, tymax)
	ymin = min (ymin, tymin)
	ymax = max (ymax, tymax)

	# Construct the title.
	call sprintf (Memc[title], SZ_LINE,
	    "Refimage: %s  Image: %s\n")
	    call pargstr (IM_HDRFILE(imr))
	    call pargstr (IM_HDRFILE(im))
	call sprintf (Memc[title+strlen(Memc[title])], SZ_LINE,
	    "Refline (solid): %d  Inline (dashed): %d  Xlag: %d  Ylag: %d")
	    call pargi (nliner)
	    call pargi (nliner + yshift)
	    call pargi (xshift)
	    call pargi (yshift)

	# Set up the axes labels and window.
	call gclear (gd)
	call gswind (gd, 1.0, real(rncols), ymin, ymax)
	call glabax (gd, Memc[title], "Column Number", "Counts")

	# Plot the two lines.
	call gseti (gd, G_PLTYPE, GL_SOLID)
	call gpline (gd, Memr[xr], Memr[ptrr], rncols)
	call gseti (gd, G_PLTYPE, GL_DASHED)
	call gpline (gd, Memr[xi], Memr[ptri], incols)
	call gflush (gd)

	call sfree (sp)
end


# RG_XPCOL -- Plot a column in the reference and input image.

procedure rg_xpcol (gd, imr, im, ncolr, xshift, yshift)

pointer	gd		#I pointer to the graphics stream
pointer	imr		#I pointer to the reference image
pointer	im		#I pointer to the image
int	ncolr		#I the line number
int	xshift		#I xshift to be applied
int	yshift		#I yshift to be applied

int	i, rncols, rnlines, incols, inlines
pointer	sp, title, xr, xi, ptrr, ptri
real	ymin, ymax, tymin, tymax
int	strlen()
pointer	imgs1r(), imgs2r()

begin
	# Return if no graphics stream.
	if (gd == NULL)
	    return

	# Check for valid column number.
	rncols = IM_LEN(imr,1)
	if (IM_NDIM(imr) == 1)
	    rnlines = 1
	else
	    rnlines = IM_LEN(imr,2)
	incols = IM_LEN(im,1)
	if (IM_NDIM(im) == 1)
	    inlines = 1
	else
	    inlines = IM_LEN(im,2)
	if ((ncolr < 1) || (ncolr > rncols))
	    return
	if (((ncolr - xshift) < 1) || ((ncolr - xshift) > incols))
	    return

	# Allocate valid working space.
	call smark (sp)
	call salloc (title, SZ_LINE, TY_CHAR)
	call salloc (xr, rnlines, TY_REAL)
	call salloc (xi, inlines, TY_REAL)

	# Initialize the data.
	do i = 1, rnlines {
	    Memr[xr+i-1] = i
	    Memr[xi+i-1] = i - yshift
	}
	if (IM_NDIM(imr) == 1)
	    ptrr = imgs1r (imr, ncolr, ncolr)
	else
	    ptrr = imgs2r (imr, ncolr, ncolr, 1, rnlines)
	if (IM_NDIM(im) == 1)
	    ptri = imgs1r (im, ncolr + xshift, ncolr + xshift)
	else
	    ptri = imgs2r (im, ncolr + xshift, ncolr + xshift, 1, inlines)
	call alimr (Memr[ptrr], rnlines, ymin, ymax)
	call alimr (Memr[ptri], inlines, tymin, tymax)
	ymin = min (ymin, tymin)
	ymax = max (ymax, tymax)

	# Construct the title.
	call sprintf (Memc[title], SZ_LINE, "Refimage: %s Image: %s\n")
	    call pargstr (IM_HDRFILE(imr))
	    call pargstr (IM_HDRFILE(im))
	call sprintf (Memc[title+strlen(Memc[title])], SZ_LINE,
	    "Refcol (solid): %d  Imcol (dashed): %d  Xlag: %d Ylag: %d")
	    call pargi (ncolr)
	    call pargi (ncolr + xshift)
	    call pargi (xshift)
	    call pargi (yshift)

	# Set up the labels and the axes.
	call gclear (gd)
	call gswind (gd, 1.0, real (rnlines), ymin, ymax)
	call glabax (gd, Memc[title], "Line Number", "Counts")

	# Plot the profile.
	call gseti (gd, G_PLTYPE, GL_SOLID)
	call gpline (gd, Memr[xr], Memr[ptrr], rnlines)
	call gseti (gd, G_PLTYPE, GL_DASHED)
	call gpline (gd, Memr[xi], Memr[ptri], rnlines)
	call gflush (gd)

	call sfree (sp)
end


# RG_XCPLINE -- Plot a line of the 2D correlation function.

procedure rg_xcpline (gd, title, data, nx, ny, nline)

pointer	gd		#I pointer to the graphics stream
char	title[ARB]	#I title for the plot
real	data[nx,ARB]	#I the input data array	
int	nx, ny		#I dimensions of the input data array
int	nline		#I the line number

int	i
pointer	sp, str, x
real	ymin, ymax

begin
	# Return if no graphics stream.
	if (gd == NULL)
	    return

	# Check for valid line number.
	if (nline < 1 || nline > ny)
	    return

	# Allocate some working space.
	call smark (sp)
	call salloc (str, SZ_LINE, TY_CHAR)
	call salloc (x, nx, TY_REAL)

	# Initialize the data.
	do i = 1, nx
	    Memr[x+i-1] = i
	call alimr (data[1,nline], nx, ymin, ymax)

	# Set up the labels and the axes.
	call gclear (gd)
	call gswind (gd, 1.0, real (nx), ymin, ymax)
	call glabax (gd, title, "X Lag", "X-Correlation Function")

	# Plot the line profile.
	call gseti (gd, G_PLTYPE, GL_SOLID)
	call gpline (gd, Memr[x], data[1,nline], nx)
	call gflush (gd)

	call sfree (sp)
end


# RG_XCPCOL -- Plot a column of the cross-correlation function.

procedure rg_xcpcol (gd, title, data, nx, ny, ncol)

pointer	gd		#I pointer to the graphics stream
char	title[ARB]	#I title of the column plot
real	data[nx,ARB]	#I the input data array
int	nx, ny		#I the dimensions of the input data array
int	ncol		#I line number

int	i
pointer	sp, x, y
real	ymin, ymax

begin
	# Return if no graphics stream.
	if (gd == NULL)
	    return

	# Check for valid column number.
	if (ncol < 1 || ncol > nx)
	    return

	# Initialize.
	call smark (sp)
	call salloc (x, ny, TY_REAL)
	call salloc (y, ny, TY_REAL)

	# Get the data to be plotted.
	do i = 1, ny {
	    Memr[x+i-1] = i
	    Memr[y+i-1] = data[ncol,i]
	}
	call alimr (Memr[y], ny, ymin, ymax)

	# Set up the labels and the axes.
	call gclear (gd)
	call gswind (gd, 1.0, real (ny), ymin, ymax)
	call glabax (gd, title, "Y Lag", "X-Correlation Function") 

	# Plot the profile.
	call gseti (gd, G_PLTYPE, GL_SOLID)
	call gpline (gd, Memr[x], Memr[y], ny)
	call gflush (gd)

	call sfree (sp)
end


# RG_XMKPEAK -- Procedure to mark the peak from a correlation function
# contour plot.

procedure rg_xmkpeak (gd, xwindow, ywindow, xshift, yshift)

pointer	gd		#I pointer to the graphics stream
int	xwindow		#I x dimension of correlation function
int	ywindow		#I y dimension of correlation function
real	xshift		#O x shift
real	yshift		#O y shift

int	wcs, key
pointer	sp, cmd
real	wx, wy
int	clgcur()

begin
	if (gd == NULL)
	    return

	call smark (sp)
	call salloc (cmd, SZ_LINE, TY_CHAR)

	call printf ("Mark peak of the cross correlation function\n")
	if (clgcur ("gcommands", wx, wy, wcs, key, Memc[cmd], SZ_LINE) == EOF)
	    ;
	if (wx < 1.0 || wx > real (xwindow) || wy < 1.0 || wy >
	    real (ywindow)) {
	    xshift = 0.0
	    yshift = 0.0
	} else {
	    xshift = wx - (1 + xwindow) / 2
	    yshift = wy - (1 + ywindow) / 2
	}

	call sfree (sp)
end