Debian Codegraph @

src/plotlib_giza.f90

raw
1 !-----------------------------------------------------------------
2 !
3 ! This file is (or was) part of SPLASH, a visualisation tool
4 ! for Smoothed Particle Hydrodynamics written by Daniel Price:
5 !
6 ! http://users.monash.edu.au/~dprice/splash
7 !
8 ! SPLASH comes with ABSOLUTELY NO WARRANTY.
9 ! This is free software; and you are welcome to redistribute
10 ! it under the terms of the GNU General Public License
11 ! (see LICENSE file for details) and the provision that
12 ! this notice remains intact. If you modify this file, please
13 ! note section 2a) of the GPLv2 states that:
14 !
15 ! a) You must cause the modified files to carry prominent notices
16 ! stating that you changed the files and the date of any change.
17 !
18 ! Copyright (C) 2005-2014 Daniel Price. All rights reserved.
19 ! Contact: [email protected]
20 !
21 !-----------------------------------------------------------------
22
23 !---------------------------------------------------------------------------
24 ! The plotlib module in SPLASH provides a consistent API so that SPLASH
25 ! can be compiled against different graphics libraries as the backend
26 !
27 ! This version provides an interface to giza, a plotting
28 ! library written by Daniel Price & James Wetter.
29 !
30 ! Giza implements basic 2D plotting functionality
31 ! on top of the cairo graphics library
32 !
33 ! Interface written by James Wetter and Daniel Price (2010)
34 !---------------------------------------------------------------------------
35 module plotlib
36 use giza, only: &
37 plot_arro=>giza_arrow, &
38 plot_annotate=>giza_annotate, &
39 plot_band=>giza_band, &
40 plot_bbuf=>giza_begin_buffer,&
41 plot_box=>giza_box, &
42 plot_circ=>giza_circle, &
43 plot_close=>giza_close, &
44 plot_curs=>giza_get_key_press, &
45 plot_ebuf=>giza_end_buffer, &
46 plot_end=>giza_close_device, &
47 plot_env=>giza_set_environment, &
48 plot_errb=>giza_error_bars, &
49 plot_funx=>giza_function_x, &
50 plot_label=>giza_label, &
51 plot_line=>giza_line, &
52 plot_lcur=>giza_mark_line, &
53 plot_olin=>giza_mark_points, &
54 plot_ncur=>giza_mark_points_ordered, &
55 plot_page=>giza_change_page, &
56 plot_poly=>giza_polygon, &
57 plot_pt1=>giza_single_point, &
58 plot_pt=>giza_points, &
59 plot_ptxt=>giza_ptext, &
60 plot_qch=>giza_get_character_height, &
61 plot_qci=>giza_get_colour_index, &
62 plot_qcir=>giza_get_colour_index_range, &
63 plot_qcr=>giza_get_colour_representation, &
64 plot_qfs=>giza_get_fill, &
65 plot_qlw=>giza_get_line_width,&
66 plot_qls=>giza_get_line_style,&
67 plot_qlc=>giza_get_line_cap, &
68 plot_qtxt=>giza_qtext, &
69 plot_qwin=>giza_get_window, &
70 plot_rect=>giza_rectangle, &
71 plot_sah=>giza_set_arrow_style, &
72 plot_scf=>giza_set_font, &
73 plot_sch=>giza_set_character_height, &
74 plot_sci=>giza_set_colour_index, &
75 plot_scir=>giza_set_colour_index_range, &
76 plot_scr=>giza_set_colour_representation, &
77 plot_set_palette=>giza_set_colour_palette, &
78 plot_sfs=>giza_set_fill, &
79 plot_slc=>giza_set_line_cap, &
80 plot_sls=>giza_set_line_style,&
81 plot_slw=>giza_set_line_width, &
82 plot_stbg=>giza_set_text_background, &
83 plot_svp=>giza_set_viewport, &
84 plot_swin=>giza_set_window, &
85 plot_text=>giza_text, &
86 plot_wnad=>giza_set_window_equal_scale, &
87 plot_qcur=>giza_device_has_cursor, &
88 plot_rgb_from_table=>giza_rgb_from_table, &
89 giza_contour, &
90 giza_get_character_size, &
91 giza_get_surface_size, &
92 giza_get_viewport, &
93 giza_open_device, &
94 giza_open_device_size, &
95 giza_render, &
96 giza_render_gray, &
97 giza_render_transparent, &
98 giza_set_colour_table, &
99 giza_stop_prompting, &
100 giza_start_prompting, &
101 plot_left_click=>giza_left_click_f, &
102 plot_right_click=>giza_right_click_f, &
103 plot_middle_click=>giza_middle_click_f, &
104 plot_shift_click=>giza_shift_click_f, &
105 plot_scroll_up=>giza_scroll_up_f, &
106 plot_scroll_down=>giza_scroll_down_f, &
107 plot_scroll_left=>giza_scroll_left_f, &
108 plot_scroll_right=>giza_scroll_right_f, &
109 giza_vector, &
110 giza_format_number, &
111 giza_query_device, &
112 giza_draw_pixels, &
113 giza_colour_index_min,&
114 giza_colour_index_max,&
115 giza_extend_none,&
116 giza_extend_pad,&
117 giza_extend_repeat, &
118 giza_extend_reflect, &
119 giza_filter_default
120 implicit none
121 logical, parameter :: plotlib_is_pgplot = .false.
122 logical, parameter :: plotlib_supports_alpha = .true.
123 integer, parameter :: plotlib_maxlinestyle = 6
124 integer, parameter :: plotlib_maxfillstyle = 5
125 integer, parameter :: plotlib_maxlinecolour = 16
126 integer, parameter :: plotlib_maxpalette = 7
127 integer, parameter :: plotlib_extend_pad = giza_extend_pad
128 integer, parameter :: plotlib_extend_repeat = giza_extend_repeat
129 integer, parameter :: plotlib_extend_reflect = giza_extend_reflect
130 integer, parameter :: plotlib_extend_none = giza_extend_none
131
132 public
133
134 contains
135
136 !---------------------------------------------
137 ! initialise the plotting library
138 !---------------------------------------------
139 subroutine plot_init(devicein, ierr, papersizex, aspectratio, paperunits)
140 use giza, only:giza_units_inches,giza_units_pixels,giza_units_mm
141
142 character(len=*),intent(in) :: devicein
143 integer,intent(out) :: ierr
144 real, intent(in), optional :: papersizex,aspectratio
145 integer, intent(in), optional :: paperunits
146 real :: width,height
147 integer :: units, id
148
149 if (present(papersizex)) then
150 width = papersizex
151 if (present(aspectratio)) then
152 height = width*aspectratio
153 else
154 height = width/sqrt(2.)
155 endif
156 if (present(paperunits)) then
157 select case(paperunits)
158 case(0)
159 units = giza_units_pixels
160 case(1)
161 units = giza_units_inches
162 case(2)
163 units = giza_units_mm
164 width = 10.*width
165 height = 10.*height
166 end select
167 else
168 units = giza_units_inches
169 endif
170 id = giza_open_device_size(devicein, 'splash', width, height, units)
171 else
172 id = giza_open_device(devicein,'splash')
173 endif
174 ! id<0 should return an error, but +ve id is OK
175 if (id < 0) then
176 ierr = id
177 else
178 ierr = 0
179 endif
180
181 if (ierr==0) then
182 call giza_stop_prompting
183 endif
184 end subroutine plot_init
185
186 subroutine plot_gray(a, idim, jdim, i1, i2, j1, j2, a1, a2, tr, iextend, filter)
187 integer,intent(in) :: IDIM, JDIM, I1, I2, J1, J2
188 real,intent(in) :: A(IDIM,JDIM), A1, A2, TR(6)
189 real :: affine(6)
190 integer, intent(in), optional :: iextend,filter
191 integer :: ifilter
192
193 call convert_tr_to_affine(tr,affine)
194
195 ifilter = giza_filter_default
196 if (present(filter)) ifilter = filter
197
198 if (present(iextend)) then
199 call giza_render_gray(idim,jdim,a,i1-1,i2-1,j1-1,j2-1,a1,a2,iextend,ifilter,affine)
200 else
201 call giza_render_gray(idim,jdim,a,i1-1,i2-1,j1-1,j2-1,a1,a2,0,ifilter,affine)
202 endif
203
204 end subroutine plot_gray
205
206 subroutine plot_imag(a, idim, jdim, i1, i2, j1, j2, a1, a2, tr, iextend, filter)
207 integer,intent(in) :: IDIM, JDIM, I1, I2, J1, J2
208 real,intent(in) :: A(IDIM,JDIM), A1, A2, TR(6)
209 real :: affine(6)
210 integer, intent(in), optional :: iextend,filter
211 integer :: ifilter
212
213 call convert_tr_to_affine(tr,affine)
214
215 ifilter = giza_filter_default
216 if (present(filter)) ifilter = filter
217
218 if (present(iextend)) then
219 call giza_render(idim,jdim,a,i1-1,i2-1,j1-1,j2-1,a1,a2,iextend,ifilter,affine)
220 else
221 call giza_render(idim,jdim,a,i1-1,i2-1,j1-1,j2-1,a1,a2,0,ifilter,affine)
222 endif
223
224 end subroutine plot_imag
225
226 subroutine plot_imag_alpha(dat, alpha, idim, jdim, i1, i2, j1, j2, a1, a2, tr, iextend, filter)
227 integer,intent(in) :: IDIM, JDIM, I1, I2, J1, J2
228 real,intent(in) :: dat(IDIM,JDIM), alpha(IDIM,JDIM), A1, A2, TR(6)
229 real :: affine(6)
230 integer, intent(in), optional :: iextend,filter
231 integer :: ifilter
232
233 call convert_tr_to_affine(tr,affine)
234
235 ifilter = giza_filter_default
236 if (present(filter)) ifilter = filter
237
238 if (present(iextend)) then
239 call giza_render(idim,jdim,dat,alpha,i1-1,i2-1,j1-1,j2-1,a1,a2,iextend,ifilter,affine)
240 else
241 call giza_render(idim,jdim,dat,alpha,i1-1,i2-1,j1-1,j2-1,a1,a2,0,ifilter,affine)
242 endif
243
244 end subroutine plot_imag_alpha
245
246 subroutine plot_imag_transparent(a, idim, jdim, i1, i2, j1, j2, a1, a2, tr)
247 integer,intent(in) :: IDIM, JDIM, I1, I2, J1, J2
248 real,intent(in) :: A(IDIM,JDIM), A1, A2, TR(6)
249 real :: affine(6)
250
251 call convert_tr_to_affine(tr,affine)
252 call giza_render_transparent(idim,jdim,a,i1-1,i2-1,j1-1,j2-1,a1,a2,0,0,affine)
253
254 end subroutine plot_imag_transparent
255
256 subroutine plot_ctab(l,r,g,b,nc,contra,bright)
257 integer,intent(in) :: nc
258 real,intent(in) :: l(nc),r(nc),g(nc),b(nc),contra,bright
259
260 call giza_set_colour_table(l,r,g,b,nc,contra,bright)
261
262 end subroutine plot_ctab
263
264 subroutine plot_qvsz(paperunits,x1,x2,y1,y2)
265 use giza, only:giza_get_paper_size,giza_units_device,giza_units_inches,giza_units_pixels,giza_units_mm
266 real, intent(out) :: x1,x2,y1,y2
267 integer, intent(in) :: paperunits
268 integer :: units
269
270 x1 = 0.
271 y1 = 0.
272 select case(paperunits)
273 case(0)
274 units = giza_units_pixels
275 case(1)
276 units = giza_units_inches
277 case(2)
278 units = giza_units_mm
279 case default
280 units = giza_units_device
281 end select
282 call giza_get_paper_size(units,x2,y2)
283
284 end subroutine plot_qvsz
285
286 subroutine plot_bins(nbin,x,data,centre)
287 integer, intent(in) :: nbin
288 real, dimension(nbin), intent(in) :: x, data
289 logical, intent(in) :: centre
290
291 print*,' WARNING: plot_bins not implemented in giza'
292
293 end subroutine plot_bins
294
295 subroutine plot_qvp(units, x1, x2, y1, y2)
296 integer,intent(in) :: units
297 real,intent(out) :: x1, x2, y1, y2
298
299 call giza_get_viewport(units_giza(units),x1,x2,y1,y2)
300
301 end subroutine plot_qvp
302
303 subroutine plot_qcs(units,xch,ych)
304 integer,intent(in) :: units
305 real,intent(out) :: xch,ych
306
307 call giza_get_character_size(units_giza(units),xch,ych)
308
309 end subroutine plot_qcs
310
311 subroutine plot_qcol(icolmin,icolmax)
312 integer,intent(out) :: icolmin,icolmax
313
314 icolmin = giza_colour_index_min
315 icolmax = giza_colour_index_max
316
317 end subroutine plot_qcol
318
319 subroutine plot_scrn(ci,name,ier)
320 integer,intent(in) :: ci
321 character(len=*),intent(in) :: name
322 integer,intent(out) :: ier
323
324 print*,' WARNING: plot_scrn not implemented in giza'
325 ier = 1
326
327 end subroutine plot_scrn
328
329 subroutine plot_qinf(item,value,length)
330 character(len=*),intent(in) :: item
331 character(len=*),intent(out) :: value
332 integer,intent(out) :: length
333 character(len=10) :: datestring,timestring
334
335 select case(item)
336 case('VERSION','version')
337 value = 'giza-1.1'
338 case('STATE','state')
339 print*,' WARNING: query for STATE not yet implemented in giza'
340 case('USER','user')
341 print*,' WARNING: query for USER not yet implemented in giza'
342 case('NOW','now')
343 call date_and_time(datestring,timestring)
344 value = datestring(7:8)//'-'//datestring(5:6)//'-'//datestring(1:4)// &
345 ' '//timestring(1:2)//':'//timestring(3:4)
346 case('DEVICE','device')
347 print*,' WARNING: query for DEVICE not yet implemented in giza'
348 case('FILE','file')
349 print*,' WARNING: query for FILE not yet implemented in giza'
350 case('TYPE','type')
351 call giza_query_device('type',value)
352 case('DEV/TYPE','dev/type')
353 print*,' WARNING: query for DEV/TYPE not yet implemented in giza'
354 case('HARDCOPY','hardcopy')
355 call giza_query_device('hardcopy',value)
356 case('TERMINAL','terminal')
357 !--in giza the current device is never the terminal
358 value = 'NO'
359 case('CURSOR','cursor')
360 call giza_query_device('cursor',value)
361 case('SCROLL','scroll')
362 !--no scroll capability in any current giza devices
363 value = 'NO'
364 case default
365 value = ' '
366 end select
367 length = len_trim(value)
368
369 end subroutine plot_qinf
370
371 subroutine plot_numb(m,pp,form,string,nc)
372 integer,intent(in) :: m,pp,form
373 character(len=*),intent(out) :: string
374 integer,intent(out) :: nc
375
376 call giza_format_number(m,pp,form,string)
377 nc = len_trim(string)
378
379 end subroutine plot_numb
380
381 subroutine plot_set_opacity(alpha)
382 real, intent(in) :: alpha
383 integer :: ci
384 real :: red,green,blue
385
386 call plot_qci(ci)
387 call plot_qcr(ci,red,green,blue)
388 call plot_scr(ci,red,green,blue,alpha)
389
390 end subroutine plot_set_opacity
391
392
393 subroutine plot_err1(dir,x,y,e,t)
394 integer,intent(in) :: dir
395 real,intent(in) :: x,y,e
396 real,intent(in) :: t
397 real, dimension(1) :: xi,yi,ei
398
399 xi(1) = x
400 yi(1) = y
401 ei(1) = e
402 call plot_errb(dir,1,xi,yi,ei,t)
403
404 end subroutine plot_err1
405
406 subroutine plot_conb(a,idim,jdim,i1,i2,j1,j2,c,nc,tr,blank)
407 integer,intent(in) :: idim,jdim,i1,i2,j1,j2,nc
408 real,intent(in) :: a(idim,jdim),c(*),tr(6),blank
409 real :: affine(6)
410
411 print*,' WARNING: blanking in contouring not implemented in giza'
412 call convert_tr_to_affine(tr,affine)
413 call giza_contour(idim,jdim,a,i1-1,i2-1,j1-1,j2-1,nc,c,affine)
414
415 end subroutine plot_conb
416
417 subroutine plot_cons(a,idim,jdim,i1,i2,j1,j2,c,nc,tr)
418 integer,intent(in) :: idim,jdim,i1,i2,j1,j2,nc
419 real,intent(in) :: a(idim,jdim),c(*),tr(6)
420 real :: affine(6)
421
422 call convert_tr_to_affine(tr,affine)
423 call giza_contour(idim,jdim,a,i1-1,i2-1,j1-1,j2-1,nc,c,affine)
424
425 end subroutine plot_cons
426
427 subroutine plot_conl(a,idim,jdim,i1,i2,j1,j2,c,tr,label,intval,mininit)
428 integer,intent(in) :: idim,jdim,i1,i2,j1,j2,intval,mininit
429 real,intent(in) :: a(idim,jdim),c,tr(6)
430 character(len=*),intent(in) :: label
431 real :: affine(6)
432 integer, parameter :: nc = 1
433 real, dimension(nc) :: clevel
434
435 clevel(1) = c
436 print*,' WARNING: labelled coutouring not implemented in giza'
437 call convert_tr_to_affine(tr,affine)
438 call giza_contour(idim,jdim,a,i1-1,i2-1,j1-1,j2-1,nc,clevel,affine)
439 print*,'nc = ',nc
440
441 end subroutine plot_conl
442
443 subroutine plot_vect(a,b,idim,jdim,i1,i2,j1,j2,c,nc,tr,blank)
444 integer,intent(in) :: idim,jdim,i1,i2,j1,j2,nc
445 real,intent(in) :: a(idim,jdim),b(idim,jdim),tr(6),blank,c
446 real :: affine(6)
447
448 call convert_tr_to_affine(tr,affine)
449 call giza_vector(idim,jdim,a,b,i1-1,i2-1,j1-1,j2-1,c,nc,affine,blank)
450
451 end subroutine plot_vect
452
453 subroutine plot_pixl(ia,idim,jdim,i1,i2,j1,j2,x1,x2,y1,y2)
454 use giza, only:giza_draw_pixels,giza_filter_default
455 integer,intent(in) :: idim,jdim,i1,i2,j1,j2
456 integer,intent(in) :: ia(idim,jdim)
457 real,intent(in) :: x1,x2,y1,y2
458
459 call giza_draw_pixels(IDIM, JDIM, IA, I1-1, I2-1, J1-1, J2-1, &
460 X1, X2, Y1, Y2, 0, giza_filter_default)
461
462 end subroutine plot_pixl
463
464 subroutine plot_pap(widthin,aspect,paperunits)
465 use giza, only:giza_set_paper_size
466 use giza, only:giza_units_inches,giza_units_pixels,giza_units_mm
467 real,intent(in) :: widthin,aspect
468 integer, intent(in), optional :: paperunits
469 integer :: units
470 real :: width
471
472 width = widthin
473 units = giza_units_inches
474
475 if (present(paperunits)) then
476 select case(paperunits)
477 case(0)
478 units = giza_units_pixels
479 case(1)
480 units = giza_units_inches
481 case(2)
482 units = giza_units_mm
483 width = 0.1*width
484 end select
485 endif
486
487 call giza_set_paper_size(units,width,width*aspect)
488
489 end subroutine plot_pap
490
491 !
492 !--this subroutine can be called to
493 ! make sure that the viewport lies exactly on
494 ! pixel boundaries.
495 !
496 ! unnecessary for giza
497 !
498 subroutine plot_set_exactpixelboundaries()
499
500 end subroutine plot_set_exactpixelboundaries
501
502 !------------------------------------------------------------
503 ! Function to convert PGPLOT units value to giza units value
504 !------------------------------------------------------------
505 integer function units_giza(pgplotunits)
506 use giza, only:giza_units_normalized,giza_units_inches, &
507 giza_units_mm,giza_units_pixels,giza_units_world
508 integer, intent(in) :: pgplotunits
509
510 select case(pgplotunits)
511 case(0)
512 units_giza = giza_units_normalized
513 case(1)
514 units_giza = giza_units_inches
515 case(2)
516 units_giza = giza_units_mm
517 case(3)
518 units_giza = giza_units_pixels
519 case(4)
520 units_giza = giza_units_world
521 case default ! giza will give an error
522 units_giza = pgplotunits
523 end select
524
525 end function units_giza
526
527 subroutine convert_tr_to_affine(tr,affine)
528 real, dimension(6), intent(in) :: tr
529 real, dimension(6), intent(out) :: affine
530
531 affine(1) = TR(2)
532 affine(2) = TR(3)
533 affine(3) = TR(5)
534 affine(4) = TR(6)
535 affine(5) = TR(1) + 0.5 * TR(2)
536 affine(6) = TR(4) + 0.5 * TR(6)
537
538 end subroutine convert_tr_to_affine
539
540 end module plotlib