aboutsummaryrefslogtreecommitdiffstats
path: root/test/ex1.f
blob: ff761eb25a0d05a3f40ab9b78cbc8bc0b55f2676 (plain)
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
 	
	program moocow
	dimension a(20000)
	
	integer*4 jwg_create_handle

 	parameter (ix=101,iy=101,iw=150,icolor=1,width=0.0)

	jx=ix/2
	jy=iy/2
	sx=5.0/(1.0*jx)
	sy=5.0/(1.0*jy)

	do j=1,iy
	 y=(j-jy)*sy

	 k=iw*(j-1)

	do i=1,ix
	 x=(i-jx)*sx

	 a(k+i)=sinc(r(x,y))

	end do
	end do 


C		Create a handle
C		Args are format and filename
C		format may currently be
C		0 for xfig files
C		1 for CGM  files
C		2 for writing directly to the screen in portrait
C		3 for writing directly to the screen in landscape
C	NB: These two are required as adding a matrix rotates the vectors
C	which you would rotate back on the peice of paper using your hands
C	monitors tend to be heavier.
C

	ihandle=jwg_create_handle(0,'ex1.xfig')

C		Pass data 
C		ix is the width
C		iy is the height
C		The offset into the array of (x,y) is calculated
C		as x+iw*(y-1)
C

 	call jwg_pass_data(ihandle,a,ix,iy,iw)

C		Set the transformation matrix to
C		jwg_set_xform(handle,a,b,c,d,e,f) and
C		jwg_add_xform(handle,a,b,c,d,e,f) 
C
C		Set the transformat matrix to, or 
C		conctenate the transform matrix with the matrix 
C		
C		/c d a\
C	   M =	|e f b|
C		\0 0 1/ 
C
C		(acts on vectors of the form (x,y,1))
C
C		NB if the device is left handed it is safer to use
C		jwg_add_xfrom as the initial matrix may not be the
C		indentity matrix
C	
C		jwg_def_xform(handle) will reset the transfomration
C		matrix to the default which gives a right handed user space.
C		which (for an A4) extends from (0,0) to (1000,1414.21)
C		use a rotation (-90 degres) to get landscape mode
C
C		note also that push and pop can be used to store previous
C		transform spaces. 
C
C		Transforms are concatenated from the right eg
C		T_new=T_old M 
C
	call jwg_def_xform(ihandle)
C	want landscape
	call jwg_add_xform(ihandle,0.0,1414.2,0.0,1.0,-1.0,0.0)



C
C	since the distance between elements of the array is 1
C	and the contor plot will fill the space (1,1)-(101,101)
C	te-he [don't you wish you had zero bassed arrays!]
C
C	and we want to fit our contour plot into a fixed space (100,100)-(900,900)
C	we need to adjust the transform matrix before we contour
C	first we save the existing xform matrix using push then we scale
C 	by 800/(ix-1) and 800/(iy-1)
C 	and then fix the offset

C	pushes the current state of the handle (colors,widths,densities,
C		transformat matrix data etc..) onto a stack (unique to the
C		particual handle) from which it can later be popped
C		also pushes the current line onto a stack so we may 
C		start a new one...

	sx=800.0/(1.0*(ix-1))
	sy=800.0/(1.0*(iy-1))

	call jwg_push_state(ihandle)

	call jwg_add_xform(ihandle,101.0,101.0,sx,0.0,0.0,sy)
C 	now fix offset of one
	call jwg_add_xform(ihandle,-1.0,-1.0,1.0,0.0,0.0,1.0)

C	set pen attributes the pen is used to render lines
C	jwg_set_pen(handle,red,green,blue,width)
C	red,green,blue real*4 color intensity 0,0,0=black 1,1,1=white
C	width is the width which will scale according to the determinant
C	of the transform matrix. if the width is 0 this will produce the
C	finest line that the format is capable of supporting.
C
C	saturated green - thin lines

	red=0.0
	green=1.0
	blue=0.0

	if (icolor.eq.0) then
		gray=red*0.35+0.54*green+0.11*blue
		red=gray
		green=gray
		blue=gray
	endif

	call jwg_set_pen(ihandle,red,green,blue,width)
	
C	Draw in the 0 level contour
C	
C	jwg_contour(handle,level,side,line)
C	
C	level is the level of the contour.
C
C	side (integer*4) controls how the contour is closed
C	If side is 0 the contour is made of disjoint polylines.
C	If |side|=1 then the contour is made of connected polygons which
C	go clockwise for side=-1 and and anticlockwise for side=1 following
C	the convention that points to the left of the lines are enclosed.
C	[it's easier to try this both ways and see which works than to 
C	think about it.] Note that side doesn't control wheter polygons
C	or lines are drawn.
C
C	(for polygons) if side is +1 then the (shaded) inside of the
C	contor encloses vales greater than level, if side is -1 then the
C	inside of the contor encloses values less than level.
C
C	line (integer*4) is non zero to draw lines and zero to draw polygons
C	[which will neccessarily be closed] 
C
C	jwg_contour assumes that your data is small compared with 1.0e20
C	near the boundaries of the box your are contouring. If this is not
C	true - worry.
 


C       Start from the most negative end and head upwards
C

	do i=1,10
	 clevel=1*((11-i)*0.1)
	 red=1.0
         green=(i*0.1)-0.1
	 blue=(i*0.1)-0.1

C	obviously we get grey if we have equal ammounts of red green and blue
C 	by convention to get the grey version (luminance of a color) we use
C	the following formula from the NTSC. This is irrelavant you could.
C	use anything you liked.

	if (icolor.eq.0) then
		gray=red*0.35+0.54*green+0.11*blue
		red=gray
		green=gray
		blue=gray
	endif

	 call jwg_set_brush(ihandle,red,green,blue,0.0)
	 call jwg_contour(ihandle,clevel,1,0)

	red=1.0
	green=0.0
	blue=0.0

	if (icolor.eq.0) then
		gray=red*0.35+0.54*green+0.11*blue
		red=gray
		green=gray
		blue=gray
	endif

	 call jwg_set_pen(ihandle,red,green,blue,width)
	 call jwg_contour(ihandle,clevel,0,1)

	end do

	do i=1,10
	 clevel=(-i*0.1)*1
	 red=1.0-i*0.2
         green=1.0-i*0.2
	 blue=1.0

	if (icolor.eq.0) then
		gray=red*0.35+0.54*green+0.11*blue
		red=gray
		green=gray
		blue=gray
	endif

	 call jwg_set_brush(ihandle,red,green,blue,0.0)
	 call jwg_contour(ihandle,clevel,1,0)

	red=0.0
	green=0.0
	blue=1.0

	if (icolor.eq.0) then
		gray=red*0.35+0.54*green+0.11*blue
		red=gray
		green=gray
		blue=gray
	endif

	 call jwg_set_pen(ihandle,red,green,blue,width)
	 call jwg_contour(ihandle,clevel,0,1)

	end do

	red=0.0
	green=1.0
	blue=0.0

	if (icolor.eq.0) then
		gray=red*0.35+0.54*green+0.11*blue
		red=gray
		green=gray
		blue=gray
	endif

	 call jwg_set_pen(ihandle,red,green,blue,width)
	 call jwg_contour(ihandle,0.0,0,1)


C	empty the stack - this restores the previous transform matrix.
	call jwg_pop_state(ihandle)

C 	Now draw a nice box round the countor plot - but in a pervese 
C	way to show pushing/poping of current lines
C
C	jwg_add_point(handle,x,y) adds a point to the current path
C		whose length is limited only by available memory
C	jwg_reset_point(handle)   may be used to remove all points
C		from the current path
C	jwg_close_line(handle)	  turns the path into a line and
C		resets the path. (line drawn in current pen)
C	jwg_close_polygon(handle) (what do you think?)
C
C	NB: jwg_push_state pushes the current path - but gives
C	a new empty path in the new state. This is not what happens
C	to other things like pen color.
C
C	black pen
 	call jwg_set_pen(ihandle,0.0,0.0,0.0,width)
 
C	for the paranoid
	call jwg_reset_point(ihandle)

	call jwg_add_point(ihandle,100.0,100.0)
	call jwg_add_point(ihandle,100.0,900.0)
C
C	Halfway trough drawing this box were going to draw
C	another box arround the first one 
C
	call jwg_push_state(ihandle)
C	 make this a red line
 	 red=1.0
	 green=0.0
	 blue=0.0

	 if (icolor.eq.0) then
		gray=red*0.35+0.54*green+0.11*blue
		red=gray
		green=gray
		blue=gray
	 endif

	 call jwg_set_pen(ihandle,red,green,blue,width)

	 call jwg_add_point(ihandle,90.0,90.0)
	 call jwg_add_point(ihandle,90.0,910.0)
	 call jwg_add_point(ihandle,910.0,910.0)
	 call jwg_add_point(ihandle,910.0,90.0)
	 call jwg_add_point(ihandle,90.0,90.0)
	 call jwg_close_line(ihandle)
        call jwg_pop_state(ihandle)

C
C	Now we'll finish off the box. which is black
C

	call jwg_add_point(ihandle,900.0,900.0)
	call jwg_add_point(ihandle,900.0,100.0)
	call jwg_add_point(ihandle,100.0,100.0)
	call jwg_close_line(ihandle)


C 	now draw a box round the whole page 

	call jwg_add_point(ihandle,0.0,0.0)
	call jwg_add_point(ihandle,1414.21,0.0)
	call jwg_add_point(ihandle,1414.21,1000.0)
	call jwg_add_point(ihandle,0.0,1000.0)
	call jwg_add_point(ihandle,0.0,0.0)
	call jwg_close_line(ihandle)

C	and a slash across the middle
	widthmy=100.0
	call jwg_set_pen(ihandle,red,green,blue,widthmy)
	call jwg_add_point(ihandle,500.0,1000.0)
	call jwg_add_point(ihandle,500.0,0.0)
	call jwg_close_line(ihandle)

C 	check scaling

	call jwg_add_xform(ihandle,0.0,0.0,10.0,0.0,0.0,10.0)

	widthmy=10.0
	call jwg_set_pen(ihandle,red,green,blue,widthmy)
	call jwg_add_point(ihandle,80.0,100.0)
	call jwg_add_point(ihandle,80.0,0.0)
	call jwg_close_line(ihandle)

C	check text

	call jwg_set_textcolor(ihandle,0.0,0.0,0.0)
	call jwg_set_textheight(ihandle,10.0)
	call jwg_draw_text(ihandle,30.0,0.0,"MOOCOW  ")

	call jwg_add_xform(ihandle,0.0,0.0,0.1,0.0,0.0,0.1)

	call jwg_set_textcolor(ihandle,0.0,0.0,0.0)
C	call jwg_set_textheight(ihandle,100.0)
	call jwg_draw_text(ihandle,300.0,300.0,"MOOCOW  ")

	call jwg_set_textcolor(ihandle,0.0,0.0,0.0)
	call jwg_set_textheight(ihandle,100.0)
	call jwg_draw_text_matrix(ihandle,300.0,600.0,0.0,1.0,
     C		-1.0,0.0,"MOOCOW  ")

C	deallocate the resources associated with the data
C	NB this needs to be done at the same level of push/pop where the
C	the data resources were allocated - (otherwise nasty things might
C	happen)

	call jwg_destroy_data(ihandle)
	call jwg_destroy_handle(ihandle)

	end

	function r(x,y)
	r=sqrt((x*x)+(y*y))
	return
 	end

	function sinc(a)

	if(a.ne.0.)then
		sinc=sin(a)/a
	else
		sinc=1.0
	endif
 	return	
	end