aboutsummaryrefslogtreecommitdiff
path: root/pkg/images/tv/imexamine/ieeimexam.x
blob: 059721ba3c88d415e669b340b4281bf4adec4649 (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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	<error.h>
include	<gset.h>
include	<config.h>
include	<mach.h>
include	<imhdr.h>
include	<xwhen.h>
include	<fset.h>
include	"imexam.h"


# IE_EIMEXAM -- Contour map
# This is an interface to the NCAR CONREC routine.

procedure ie_eimexam (gp, mode, ie, x, y)
 
pointer	gp			# GIO pointer
int	mode			# Mode
pointer	ie			# IE pointer
real	x, y			# Center

bool	banner
int	nset, ncontours, dashpat, nhi
int	x1, x2, y1, y2, nx, ny, npts, wkid
real	vx1, vx2, vy1, vy2, xs, xe, ys, ye
real	interval, floor, ceiling, zero, finc, zmin, zmax
pointer	sp, title, hostid, user, xlabel, ylabel, im, data, data1

pointer	pp, clopset(), ie_gdata(), ie_gimage()
bool	clgpsetb(), fp_equalr()
int	clgpseti(), btoi()
real	clgpsetr()

int	isizel, isizem, isizep, nrep, ncrt, ilab, nulbll, ioffd
int	ioffm, isolid, nla, nlm
real	xlt, ybt, side, ext, hold[5]
common  /conre4/ isizel, isizem , isizep, nrep, ncrt, ilab, nulbll, 
            ioffd, ext, ioffm, isolid, nla, nlm, xlt, ybt, side
int	first
common  /conflg/ first
common  /noaolb/ hold

begin
	iferr (im = ie_gimage (ie, NO)) {
	    call erract (EA_WARN)
	    return
	}

	pp = IE_PP(ie)
	if (pp != NULL)
	    call clcpset (pp)
	pp = clopset ("eimexam")
	IE_PP(ie) = pp

	if (!IS_INDEF(x))
	    IE_X1(ie) = x
	if (!IS_INDEF(y))
	    IE_Y1(ie) = y

	nx = clgpseti (pp, "ncolumns")
	ny = clgpseti (pp, "nlines")
	x1 = IE_X1(ie) - (nx - 1) / 2 + 0.5
	x2 = IE_X1(ie) + nx / 2 + 0.5
	y1 = IE_Y1(ie) - (ny - 1) / 2 + 0.5
	y2 = IE_Y1(ie) + ny / 2 + 0.5
	iferr (data = ie_gdata (im, x1, x2, y1, y2)) {
	    call erract (EA_WARN)
	    return
	}

	nx = x2 - x1 + 1
	ny = y2 - y1 + 1
	npts = nx * ny
	xs = x1
	xe = x2
	ys = y1
	ye = y2

	call smark (sp)
	banner = false
	if (mode == NEW_FILE) {
	    call gclear (gp)

	    # Set the WCS
	    call gswind (gp, xs, xe, ys, ye)

	    if (!clgpsetb (pp, "fill"))
	        call gsetr (gp, G_ASPECT, real (ny-1) / real (nx-1))

	    call gseti (gp, G_ROUND, btoi (clgpsetb (pp, "round")))

	    if (clgpsetb (pp, "box")) {
	        # Get number of major and minor tick marks.
	        call gseti (gp, G_XNMAJOR, clgpseti (pp, "majrx"))
	        call gseti (gp, G_XNMINOR, clgpseti (pp, "minrx"))
	        call gseti (gp, G_YNMAJOR, clgpseti (pp, "majry"))
	        call gseti (gp, G_YNMINOR, clgpseti (pp, "minry"))

	        # Label tick marks on axes?
	        call gseti (gp, G_LABELTICKS,
		    btoi (clgpsetb (pp, "ticklabels")))

		# Labels
		call salloc (title, IE_SZTITLE, TY_CHAR)
		call salloc (hostid, SZ_LINE, TY_CHAR)
		call salloc (user, SZ_LINE, TY_CHAR)
		call salloc (xlabel, SZ_LINE, TY_CHAR)
		call salloc (ylabel, SZ_LINE, TY_CHAR)

		banner = clgpsetb (pp, "banner")
		if (banner) {
		    call sysid (Memc[hostid], SZ_LINE)
		    # We must postpone the parameter line until after conrec.
		    call sprintf (Memc[title], IE_SZTITLE, "%s\n\n%s")
			call pargstr (Memc[hostid])
			call pargstr (IM_TITLE(im))
		} else
		    Memc[title] = EOS

		call clgpset (pp, "title", Memc[user], SZ_LINE)
		if (Memc[user] != EOS) {
		    call strcat ("\n", Memc[title], IE_SZTITLE)
		    call strcat (Memc[user], Memc[title], IE_SZTITLE)
		}
		call clgpset (pp, "xlabel", Memc[xlabel], SZ_LINE)
		call clgpset (pp, "ylabel", Memc[ylabel], SZ_LINE)

	        call glabax (gp, Memc[title], Memc[xlabel], Memc[ylabel])
	    }
	}

	# First of all, intialize conrec's block data before altering any
	# parameters in common.
	first = 1
	call conbd

	# Set contour parameters
	zero	= clgpsetr (pp, "zero")
	floor	= clgpsetr (pp, "floor")
	ceiling	= clgpsetr (pp, "ceiling")
	nhi	= clgpseti (pp, "nhi")
	dashpat	= clgpseti (pp, "dashpat")

	# Resolve INDEF limits.
	if (IS_INDEF (floor) || IS_INDEF (ceiling)) {
	    call alimr (Memr[data], npts, zmin, zmax)
	    if (IS_INDEF (floor))
	        floor = zmin
	    if (IS_INDEF (ceiling))
	        ceiling = zmax
	}

	# Apply the zero point shift.
	if (abs (zero) > EPSILON) {
	    call salloc (data1, npts, TY_REAL)
	    call asubkr (Memr[data], zero, Memr[data1], npts)
	    floor = floor - zero
	    ceiling = ceiling - zero
	} else
	    data1 = data

	# Avoid conrec's automatic scaling.
	if (floor == 0.)
	    floor = EPSILON
	if (ceiling == 0.)
	    ceiling = EPSILON

	# The user can suppress the contour labelling by setting the common
	# parameter "ilab" to zero.
	if (btoi (clgpsetb (pp, "label")) == NO)
	    ilab = 0
	else
	    ilab = 1

	# User can specify either the number of contours or the contour
	# interval, or let conrec pick a nice number.  Get params and
	# encode the FINC param expected by conrec.

	ncontours = clgpseti (pp, "ncontours")
	if (ncontours <= 0) {
	    interval = clgpsetr (pp, "interval")
	    if (interval <= 0)
		finc = 0
	    else
		finc = interval
	} else
	    finc = - abs (ncontours)

	# Open device and make contour plot.
	call gopks (STDERR)
	wkid = 1
	call gopwk (wkid, 6, gp)
	call gacwk (wkid)

	# Make the contour plot.
	nset = 1	# No conrec viewport
	ioffm = 1	# No conrec box
	call gswind (gp, 1., real (nx), 1., real (ny))
	call ggview (gp, vx1, vx2, vy1, vy2)
	call set (vx1, vx2, vy1, vy2, 1.0, real (nx), 1.0, real (ny), 1)
	call conrec (Memr[data1], nx, nx, ny, floor,
	    ceiling, finc, nset, nhi, -dashpat)

	call gdawk (wkid)
	call gclks ()

	call gswind (gp, xs, xe, ys, ye)
	if (banner) {
	    if (fp_equalr (hold(5), 1.0)) {
	        call sprintf (Memc[title], IE_SZTITLE, 
    "%s\n%s: Contoured from %g to %g, interval = %g\n%s")
		    call pargstr (Memc[hostid])
		    call pargstr (IE_IMNAME(ie))
	            call pargr (hold(1))
	            call pargr (hold(2))
	            call pargr (hold(3))
		    call pargstr (IM_TITLE(im))
	    } else {
	        call sprintf (Memc[title], IE_SZTITLE, 
    "%s\n%s:contoured from %g to %g, interval = %g, labels scaled by %g\n%s")
		    call pargstr (Memc[xlabel])
		    call pargstr (IE_IMNAME(ie))
	            call pargr (hold(1))
	            call pargr (hold(2))
	            call pargr (hold(3))
		    call pargr (hold(5))
		    call pargstr (IM_TITLE(im))
	    }

	    if (Memc[user] != EOS) {
		call strcat ("\n", Memc[user], IE_SZTITLE)
		call strcat (Memc[user], Memc[title], IE_SZTITLE)
	    }

	    call gseti (gp, G_DRAWAXES, NO)
	    call glabax (gp, Memc[title], "", "")

	} else
	    call gtext (gp, xs, ys, "", "")

	call sfree (sp)
end