Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Handle both plplot linewidth types.

  • Loading branch information...
commit 6d33fc71341aeb282615ddf89261ecef4a7d3876 1 parent ce589c3
@jtappin jtappin authored
View
12 CMakeLists.txt
@@ -29,6 +29,8 @@
cmake_minimum_required(VERSION 2.8.5)
project(gtk-fortran C Fortran)
+include(CheckCSourceCompiles)
+
# Note that we override the lib directory here because most
# 64-bit systems don't actually work if we use the default.
include(GNUInstallDirs)
@@ -108,6 +110,16 @@ if (NOT EXCLUDE_PLPLOT)
set(LIBRARIES ${LIBRARIES} ${PLPLOT_LIBRARIES})
include_directories(${PLPLOT_INCLUDE_DIR})
include_directories(${PLPLOT_MODULE_DIR})
+ set(CMAKE_REQUIRED_LIBRARIES "${PLPLOT_LIBRARIES}")
+ set(CMAKE_REQUIRED_INCLUDES "${PLPLOT_INCLUDE_DIR}")
+ check_c_source_compiles("
+#include <plplot/plplot.h>
+int main(int argc, void *argv[])
+{
+ PLFLT w = 0.5;
+ plinit();
+ plwidth(w);
+}" NEW_PLPLOT)
else(PLPLOT_FOUND)
message(STATUS "PLPLOT not found: PLPLOT integration and examples will not be built")
endif(PLPLOT_FOUND)
View
30 plplot/CMakeLists.txt
@@ -43,15 +43,29 @@ install(FILES
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/gtk-2-fortran)
if (NOT NO_BUILD_EXAMPLES)
- add_executable(hl_plplot1e "hl_plplot1e.f90")
- add_dependencies(hl_plplot1e plplot_extra_module)
- target_link_libraries(hl_plplot1e gtk-fortran_static ${GTK_LIBRARIES} ${PLPLOT_LIBRARIES})
- add_test(hl_plplot1e ./hl_plplot1e)
+ if (NEW_PLPLOT)
+ message(STATUS "New PLPLOT")
+ add_executable(hl_plplot1e "hl_plplot1e.f90")
+ add_dependencies(hl_plplot1e plplot_extra_module)
+ target_link_libraries(hl_plplot1e gtk-fortran_static ${GTK_LIBRARIES} ${PLPLOT_LIBRARIES})
+ add_test(hl_plplot1e ./hl_plplot1e)
- add_executable(hl_plplot4e "hl_plplot4e.f90")
- add_dependencies(hl_plplot4e plplot_extra_module)
- target_link_libraries(hl_plplot4e gtk-fortran_static ${GTK_LIBRARIES} ${PLPLOT_LIBRARIES})
- add_test(hl_plplot4e ./hl_plplot4e)
+ add_executable(hl_plplot4e "hl_plplot4e.f90")
+ add_dependencies(hl_plplot4e plplot_extra_module)
+ target_link_libraries(hl_plplot4e gtk-fortran_static ${GTK_LIBRARIES} ${PLPLOT_LIBRARIES})
+ add_test(hl_plplot4e ./hl_plplot4e)
+ else (NEW_PLPLOT)
+ message(STATUS "Old PLPLOT")
+ add_executable(hl_plplot1e "hl_plplot1e_old.f90")
+ add_dependencies(hl_plplot1e plplot_extra_module)
+ target_link_libraries(hl_plplot1e gtk-fortran_static ${GTK_LIBRARIES} ${PLPLOT_LIBRARIES})
+ add_test(hl_plplot1e ./hl_plplot1e)
+
+ add_executable(hl_plplot4e "hl_plplot4e_old.f90")
+ add_dependencies(hl_plplot4e plplot_extra_module)
+ target_link_libraries(hl_plplot4e gtk-fortran_static ${GTK_LIBRARIES} ${PLPLOT_LIBRARIES})
+ add_test(hl_plplot4e ./hl_plplot4e)
+ endif (NEW_PLPLOT)
add_executable(hl_plplot8e "hl_plplot8e.f90")
add_dependencies(hl_plplot8e plplot_extra_module)
View
4 plplot/hl_plplot1e.f90
@@ -206,6 +206,10 @@ subroutine plot2()
! Draw the line
+ ! For plplot 5.9.9 or lower comment out the plwidth calls in the
+ ! remainder of this subroutine.
+ ! For plplot 5.9.10 or higher comment out the plwid calls.
+
call plcol0(3)
! call plwid(2)
call plwidth(2.0_plflt)
View
338 plplot/hl_plplot1e_old.f90
@@ -0,0 +1,338 @@
+! Copyright (C) 2011
+! Free Software Foundation, Inc.
+
+! This file is part of the gtk-fortran gtk+ Fortran Interface library.
+
+! This is free software; you can redistribute it and/or modify
+! it under the terms of the GNU General Public License as published by
+! the Free Software Foundation; either version 3, or (at your option)
+! any later version.
+
+! This software is distributed in the hope that it will be useful,
+! but WITHOUT ANY WARRANTY; without even the implied warranty of
+! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+! GNU General Public License for more details.
+
+! Under Section 7 of GPL version 3, you are granted additional
+! permissions described in the GCC Runtime Library Exception, version
+! 3.1, as published by the Free Software Foundation.
+
+! You should have received a copy of the GNU General Public License along with
+! this program; see the files COPYING3 and COPYING.RUNTIME respectively.
+! If not, see <http://www.gnu.org/licenses/>.
+!
+! gfortran hl_plplot1e.f90 `pkg-config --cflags --libs gtk-fortran plplotd-f95`
+! Contributed by: James Tappin
+! PLplot code derived from PLplot's example 1 by Alan W. Irwin
+
+module common_ex1
+ use iso_c_binding
+ use gtk, only: gtk_button_new, gtk_container_add, gtk_drawing_area&
+ &_new, gtk_main, gtk_main_quit, &
+ & gtk_widget_show, gtk_widget_show_all, gtk_window_new, gtk_init
+ use g, only: g_object_get_data
+
+ use gtk_draw_hl
+
+ use plplot_extra
+
+ integer(kind=c_int) :: height, width
+ type(c_ptr) :: window
+end module common_ex1
+
+module plplot_code_ex1
+ use plplot, PI => PL_PI
+ use iso_c_binding
+ use common_ex1
+
+ implicit none
+
+ real(plflt) :: xscale, yscale, xoff, yoff
+
+contains
+ subroutine x01f95(area)
+
+ type(c_ptr), intent(in) :: area
+
+ type(c_ptr) :: cc
+
+ character(len=80) :: version
+ character(len=20) :: geometry
+ integer :: digmax
+
+ ! Define colour map 0 to match the "GRAFFER" colour table in
+ ! place of the PLPLOT default.
+ integer, parameter, dimension(16) :: rval = (/255, 0, 255, &
+ & 0, 0, 0, 255, 255, 255, 127, 0, 0, 127, 255, 85, 170/),&
+ & gval = (/ 255, 0, 0, 255, 0, 255, 0, 255, 127, 255, 255, 127,&
+ & 0, 0, 85, 170/), &
+ & bval = (/ 255, 0, 0, 0, 255, 255, 255, 0, 0, 0, 127, 255, 255,&
+ & 127, 85, 170/)
+
+ ! Process command-line arguments
+ call plparseopts(PL_PARSE_FULL)
+
+ ! Print plplot version
+ call plgver(version)
+ write (*,'(a,a)') 'PLplot library version: ', trim(version)
+
+ ! Get a cairo context from the drawing area.
+
+ cc = hl_gtk_drawing_area_cairo_new(area)
+
+ ! Initialize plplot
+ call plscmap0(rval, gval, bval)
+ call plsdev("extcairo")
+
+ ! By default the "extcairo" driver does not reset the background
+ ! This is equivalent to the command line option "-drvopt set_background=1"
+ call plsetopt("drvopt", "set_background=1")
+
+ ! The "extcairo" device doesn't read the size from the context.
+ write(geometry, "(I0,'x',I0)") width, height
+ call plsetopt("geometry", geometry)
+
+ ! Divide page into 2x2 plots
+ call plstar(2,2)
+
+ ! Tell the "extcairo" driver where the context is located. This must be
+ ! done AFTER the plstar or plinit call.
+
+ call pl_cmd(PLESC_DEVINIT, cc)
+
+ ! Set up the data
+ ! Original case
+
+ xscale = 6._plflt
+ yscale = 1._plflt
+ xoff = 0._plflt
+ yoff = 0._plflt
+
+ ! Do a plot
+ call plot1()
+
+ ! Set up the data
+
+ xscale = 1._plflt
+ yscale = 0.0014_plflt
+ yoff = 0.0185_plflt
+
+ ! Do a plot
+
+ digmax = 5
+ call plsyax(digmax, 0)
+ call plot1()
+
+ call plot2()
+ call plot3()
+
+ ! Don't forget to call PLEND to finish off, and then delete the
+ ! cairo context.
+
+ call plend()
+ call hl_gtk_drawing_area_cairo_destroy(cc)
+
+ end subroutine x01f95
+
+ !======================================================================
+ subroutine plot1()
+
+ real(plflt), dimension(1:60) :: x, y
+ real(plflt), dimension(1:6) :: xs, ys
+ real(plflt) :: xmin, xmax, ymin, ymax
+ integer :: i
+
+ do i = 1, 60
+ x(i) = xoff + xscale * dble(i)/60.0_plflt
+ y(i) = yoff + yscale * x(i)**2
+ enddo
+
+ xmin = x(1)
+ xmax = x(60)
+ ymin = y(1)
+ ymax = y(60)
+
+ do i = 1, 6
+ xs(i) = x((i-1)*10+4)
+ ys(i) = y((i-1)*10+4)
+ enddo
+
+ ! Set up the viewport and window using PLENV. The range in X is
+ ! 0.0 to 6.0, and the range in Y is 0.0 to 30.0. The axes are
+ ! scaled separately (just = 0), and we just draw a labelled
+ ! box (axis = 0).
+
+ call plcol0(1)
+ call plenv( xmin, xmax, ymin, ymax, 0, 0 )
+ call plcol0(2)
+ call pllab( '(x)', '(y)', '#frPLplot Example 1 - y=x#u2' )
+
+ ! Plot the data points
+
+ call plcol0(4)
+ call plpoin( xs, ys, 9 )
+
+ ! Draw the line through the data
+
+ call plcol0(3)
+ call plline( x, y )
+
+ end subroutine plot1
+
+ !======================================================================
+ subroutine plot2()
+
+ real(plflt), dimension(1:100) :: x, y
+ integer :: i
+
+ !
+ ! Set up the viewport and window using PLENV. The range in X is
+ ! -2.0 to 10.0, and the range in Y is -0.4 to 2.0. The axes are
+ ! scaled separately (just = 0), and we draw a box with axes
+ ! (axis = 1).
+
+ call plcol0(1)
+ call plenv(-2.0_plflt, 10.0_plflt, -0.4_plflt, 1.2_plflt, 0, 1 )
+ call plcol0(2)
+ call pllab( '(x)', 'sin(x)/x', '#frPLplot Example 1 - Sinc Function' )
+
+ ! Fill up the arrays
+
+ do i = 1, 100
+ x(i) = (i-20.0_plflt)/6.0_plflt
+ y(i) = 1.0_plflt
+ if (x(i) .ne. 0.0_plflt) y(i) = sin(x(i)) / x(i)
+ enddo
+
+ ! Draw the line
+
+ ! For plplot 5.9.9 or lower comment out the plwidth calls in the
+ ! remainder of this subroutine.
+ ! For plplot 5.9.10 or higher comment out the plwid calls.
+
+ call plcol0(3)
+ call plwid(2)
+! call plwidth(2.0_plflt)
+ call plline( x, y )
+ call plwid(1)
+! call plwidth(1.0_plflt)
+
+ end subroutine plot2
+
+ !======================================================================
+ subroutine plot3()
+
+ !
+ ! For the final graph we wish to override the default tick intervals,
+ ! and so do not use_ PLENV
+
+ real(plflt), dimension(1:101) :: x, y
+
+ integer i
+ call pladv(0)
+
+ ! Use_ standard viewport, and define X range from 0 to 360 degrees,
+ ! Y range from -1.2 to 1.2.
+
+ call plvsta()
+ call plwind( 0.0_plflt, 360.0_plflt, -1.2_plflt, 1.2_plflt )
+
+ ! Draw a box with ticks spaced 60 degrees apart in X, and 0.2 in Y.
+
+ call plcol0(1)
+ call plbox( 'bcnst', 60.0_plflt, 2, 'bcnstv', 0.2_plflt, 2 )
+
+ ! Superimpose a dashed line grid, with 1.5 mm marks and spaces. With
+ ! only a single mark and space element, we do not need arrays
+
+ call plstyl( 1, 1500, 1500 )
+ call plcol0(2)
+ call plbox( 'g', 30.0_plflt, 0, 'g', 0.2_plflt, 0 )
+ call plstyl( 0, 0, 0 )
+
+ call plcol0(3)
+ call pllab( 'Angle (degrees)', 'sine', '#frPLplot Example 1 - Sine function' )
+
+ do i = 1, 101
+ x(i) = 3.6_plflt * (i-1)
+ y(i) = sin( x(i) * PI/180.0_plflt )
+ enddo
+
+ call plcol0(4)
+ call plline( x, y )
+
+ end subroutine plot3
+
+end module plplot_code_ex1
+
+module handlers_ex1
+
+ use common_Ex1
+
+ use gtk_hl
+ use gtk_draw_hl
+
+ use iso_c_binding
+
+ implicit none
+
+ integer(kind=c_int) :: run_status = TRUE
+
+ real(kind=c_double), parameter :: pi = 3.14159265358979323846_c_double
+
+contains
+ function delete_cb (widget, event, gdata) result(ret) bind(c)
+ integer(c_int) :: ret
+ type(c_ptr), value :: widget, event, gdata
+
+ call gtk_widget_destroy(window)
+ call gtk_main_quit ()
+ ret = FALSE
+ end function delete_cb
+
+ subroutine quit_cb(widget, gdata) bind(c)
+ type(c_ptr), value :: widget, gdata
+
+ call gtk_widget_destroy(window)
+ call gtk_main_quit ()
+ end subroutine quit_cb
+
+end module handlers_ex1
+
+program cairo_plplot_ex1
+
+ use handlers_ex1
+ use plplot_code_ex1
+
+ implicit none
+
+ type(c_ptr) :: drawing, scroll_w, base, qbut
+
+ height = 1000
+ width = 1200
+
+ call gtk_init()
+
+ window = hl_gtk_window_new("PLplot x01 / gtk-fortran (extcairo)"&
+ & //c_null_char, &
+ & delete_event = c_funloc(delete_cb))
+ base = hl_gtk_box_new()
+ call gtk_container_add(window, base)
+
+ drawing = hl_gtk_drawing_area_new(size=(/width, height/), &
+ & has_alpha = FALSE, &
+ & scroll = scroll_w, &
+ & ssize=(/ 600, 500 /))
+ call hl_gtk_box_pack(base, scroll_w)
+
+ qbut = hl_gtk_button_new("Quit"//c_null_char, clicked=c_funloc(quit_cb))
+ call hl_gtk_box_pack(base, qbut, expand=FALSE)
+
+ call gtk_widget_show_all (window)
+
+ call x01f95(drawing)
+
+ call gtk_main()
+
+ print *, "All done"
+end program cairo_plplot_ex1
View
29 plplot/hl_plplot4e.f90
@@ -122,18 +122,23 @@ end subroutine plot_04
subroutine plot1(type)
use plplot, PI => PL_PI
implicit none
- real(kind=plflt) freql(0:100),ampl(0:100),phase(0:100), freq, f0
- integer i, type
- integer nlegend
+ real(kind=plflt) :: freql(0:100),ampl(0:100),phase(0:100), freq, f0
+ integer :: i, type
+ integer :: nlegend
- real(kind=plflt) legend_width, legend_height
- integer opt_array(2), text_colors(2), line_colors(2), &
+ real(kind=plflt) :: legend_width, legend_height
+ integer :: opt_array(2), text_colors(2), line_colors(2), &
line_styles(2), symbol_colors(2), symbol_numbers(2)
- real(kind=plflt) symbol_scales(2), box_scales(0), line_widths(2)
- integer box_colors(0), box_patterns(0)
- real(kind=plflt) box_line_widths(0)
- character(len=20) text(2)
- character(len=1) symbols(2)
+
+ ! For plplot 5.9.9 or lower the next declarations should be integers
+ ! For 5.9.10 or higher they should be reals
+ real(kind=plflt) :: symbol_scales(2), box_scales(0)
+! integer :: line_widths(2), box_line_widths(0)
+
+ real(kind=plflt) :: line_widths(2), box_line_widths(0)
+ integer :: box_colors(0), box_patterns(0)
+ character(len=20):: text(2)
+ character(len=1) :: symbols(2)
call pladv(0)
! Set up data for log plot.
@@ -190,6 +195,8 @@ subroutine plot1(type)
text(1) = 'Amplitude'
line_colors(1) = 2
line_styles(1) = 1
+ ! For plplot 5.9.9 or lower comment out the real assignment,
+ ! for 5.9.10 or higher, comment out the integer assignment.
! line_widths(1) = 1
line_widths(1) = 1.0_plflt
! note from the above opt_array the first symbol (and box) indices
@@ -201,6 +208,8 @@ subroutine plot1(type)
text(2) = 'Phase shift'
line_colors(2) = 3
line_styles(2) = 1
+ ! For plplot 5.9.9 or lower comment out the real assignment,
+ ! for 5.9.10 or higher, comment out the integer assignment.
! line_widths(2) = 1
line_widths(2) = 1.0_plflt
symbol_colors(2) = 3
View
306 plplot/hl_plplot4e_old.f90
@@ -0,0 +1,306 @@
+! Copyright (C) 2012
+! Free Software Foundation, Inc.
+
+! This file is part of the gtk-fortran gtk+ Fortran Interface library.
+
+! This is free software; you can redistribute it and/or modify
+! it under the terms of the GNU General Public License as published by
+! the Free Software Foundation; either version 3, or (at your option)
+! any later version.
+
+! This software is distributed in the hope that it will be useful,
+! but WITHOUT ANY WARRANTY; without even the implied warranty of
+! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+! GNU General Public License for more details.
+
+! Under Section 7 of GPL version 3, you are granted additional
+! permissions described in the GCC Runtime Library Exception, version
+! 3.1, as published by the Free Software Foundation.
+
+! You should have received a copy of the GNU General Public License along with
+! this program; see the files COPYING3 and COPYING.RUNTIME respectively.
+! If not, see <http://www.gnu.org/licenses/>.
+!
+! gfortran hl_plplot1e.f90 `pkg-config --cflags --libs gtk-fortran plplotd-f95`
+! Contributed by: James Tappin
+! PLplot code derived from PLplot's example 4 by Alan W. Irwin
+
+module common_ex4
+ use iso_c_binding
+
+ !*******
+ use cairo, only: cairo_get_target, cairo_image_surface_get_height, &
+ & cairo_image_surface_get_width
+
+ use gtk, only: gtk_container_add, gtk_main, gtk_main_quit, &
+ & gtk_widget_destroy, gtk_widget_show_all, gtk_init, FALSE
+
+ use gtk_draw_hl
+ use gtk_hl
+
+ use plplot_extra
+
+ implicit none
+
+ type(c_ptr) :: window
+
+end module common_ex4
+
+module plplot_code_ex4
+ use plplot, PI => PL_PI
+ use iso_c_binding
+ use common_ex4
+
+ implicit none
+
+contains
+
+ subroutine plot_04(area)
+! integer, intent(in) :: type
+ type(c_ptr), intent(in), dimension(2) :: area
+
+ type(c_ptr), dimension(2) :: cc, cs
+ integer :: i
+ character(len=25) :: geometry
+
+ ! Define colour map 0 to match the "GRAFFER" colour table in
+ ! place of the PLPLOT default.
+ integer, parameter, dimension(16) :: rval = (/255, 0, 255, &
+ & 0, 0, 0, 255, 255, 255, 127, 0, 0, 127, 255, 85, 170/),&
+ & gval = (/ 255, 0, 0, 255, 0, 255, 0, 255, 127, 255, 255, 127,&
+ & 0, 0, 85, 170/), &
+ & bval = (/ 255, 0, 0, 0, 255, 255, 255, 0, 0, 0, 127, 255, 255,&
+ & 127, 85, 170/)
+
+ ! Process command-line arguments
+ call plparseopts(PL_PARSE_FULL)
+ ! Get a cairo context from the drawing area.
+
+ do i=1,2
+ cc(i) = hl_gtk_drawing_area_cairo_new(area(i))
+ cs(i) = cairo_get_target(cc(i))
+ end do
+
+ ! Initialize plplot
+ call plscmap0(rval, gval, bval)
+ call plsdev("extcairo")
+
+ ! By default the "extcairo" driver does not reset the background
+ ! This is equivalent to the command line option "-drvopt set_background=1"
+ call plsetopt("drvopt", "set_background=1")
+
+ ! The "extcairo" device doesn't read the size from the context.
+
+ write(geometry, "(I0,'x',I0)") cairo_image_surface_get_width(cs(1)), &
+ & cairo_image_surface_get_height(cs(1))
+ call plsetopt("geometry", geometry)
+
+ ! Initialize
+
+ call plinit
+
+ ! Tell the "extcairo" driver where the context is located. This must be
+ ! done AFTER the plstar or plinit call.
+
+ call pl_cmd(PLESC_DEVINIT, cc(1))
+
+ call plfont(2) ! Roman font
+ call plot1(0)
+
+ ! Now continue the plot on the other surface
+ call pl_cmd(PLESC_DEVINIT, cc(2))
+
+ call plot1(1)
+
+ call plend
+
+ call hl_gtk_drawing_area_cairo_destroy(cc(1))
+ call hl_gtk_drawing_area_cairo_destroy(cc(2))
+
+ end subroutine plot_04
+
+ subroutine plot1(type)
+ use plplot, PI => PL_PI
+ implicit none
+ real(kind=plflt) :: freql(0:100),ampl(0:100),phase(0:100), freq, f0
+ integer :: i, type
+ integer :: nlegend
+
+ real(kind=plflt) :: legend_width, legend_height
+ integer :: opt_array(2), text_colors(2), line_colors(2), &
+ line_styles(2), symbol_colors(2), symbol_numbers(2)
+
+ ! For plplot 5.9.9 or lower the next declarations should be integers
+ ! For 5.9.10 or higher they should be reals
+ real(kind=plflt) :: symbol_scales(2), box_scales(0)
+ integer :: line_widths(2), box_line_widths(0)
+
+! real(kind=plflt) :: line_widths(2), box_line_widths(0)
+ integer :: box_colors(0), box_patterns(0)
+ character(len=20):: text(2)
+ character(len=1) :: symbols(2)
+
+ call pladv(0)
+ ! Set up data for log plot.
+ f0 = 1._plflt
+ do i=0,100
+ freql(i)= -2.0_plflt + dble (i)/20.0_plflt
+ freq=10.0_plflt**freql(i)
+ ampl(i)=20.0_plflt*log10(1.0_plflt/sqrt(1.0_plflt+(freq/f0)**2))
+ phase(i)=-(180.0_plflt/PI)*atan(freq/f0)
+ enddo
+ call plvpor(0.15_plflt, 0.85_plflt, 0.1_plflt, 0.9_plflt)
+ call plwind(-2.0_plflt, 3.0_plflt, -80.0_plflt, 0.0_plflt)
+ call plcol0(1)
+ ! Try different axis and labelling styles.
+ if (type.eq.0) then
+ call plbox('bclnst', 0.0_plflt, 0, 'bnstv', 0.0_plflt, 0)
+ elseif (type.eq.1) then
+ call plbox('bcfghlnst', 0.0_plflt, 0, 'bcghnstv', 0.0_plflt, 0)
+ else
+ stop 'plot1: invalid type'
+ endif
+ ! Plot ampl vs freq.
+ call plcol0(2)
+ call plline(freql,ampl)
+ call plcol0(2)
+ call plptex(1.6_plflt, -30.0_plflt, 1.0_plflt, -20.0_plflt, 0.5_plflt, &
+ '-20 dB/decade')
+ ! Put labels on.
+ call plcol0(1)
+ call plmtex('b', 3.2_plflt, 0.5_plflt, 0.5_plflt, 'Frequency')
+ call plmtex('t', 2.0_plflt, 0.5_plflt, 0.5_plflt, &
+ 'Single Pole Low-Pass Filter')
+ call plcol0(2)
+ call plmtex('l', 5.0_plflt, 0.5_plflt, 0.5_plflt, 'Amplitude (dB)')
+ nlegend = 1
+ ! For the gridless case, put phase vs freq on same plot.
+ if(type.eq.0) then
+ call plcol0(1)
+ call plwind(-2.0_plflt, 3.0_plflt, -100.0_plflt, 0.0_plflt)
+ call plbox(' ', 0.0_plflt, 0, 'cmstv', 30.0_plflt, 3)
+ call plcol0(3)
+ call plline(freql, phase)
+ call plstring(freql, phase, '*')
+ call plcol0(3)
+ call plmtex('r', 5.0_plflt, 0.5_plflt, 0.5_plflt, &
+ 'Phase shift (degrees)')
+ nlegend = 2
+ endif
+
+ ! Draw a legend
+ ! First legend entry.
+ opt_array(1) = PL_LEGEND_LINE
+ text_colors(1) = 2
+ text(1) = 'Amplitude'
+ line_colors(1) = 2
+ line_styles(1) = 1
+ ! For plplot 5.9.9 or lower comment out the real assignment,
+ ! for 5.9.10 or higher, comment out the integer assignment.
+ line_widths(1) = 1
+! line_widths(1) = 1.0_plflt
+ ! note from the above opt_array the first symbol (and box) indices
+ ! do not have to be specified
+
+ ! Second legend entry.
+ opt_array(2) = PL_LEGEND_LINE + PL_LEGEND_SYMBOL
+ text_colors(2) = 3
+ text(2) = 'Phase shift'
+ line_colors(2) = 3
+ line_styles(2) = 1
+ ! For plplot 5.9.9 or lower comment out the real assignment,
+ ! for 5.9.10 or higher, comment out the integer assignment.
+ line_widths(2) = 1
+! line_widths(2) = 1.0_plflt
+ symbol_colors(2) = 3
+ symbol_scales(2) = 1.0
+ symbol_numbers(2) = 4
+ symbols(2) = '*'
+
+ ! from the above opt_arrays we can completely ignore everything
+ ! to do with boxes. (Hence the size 0 for the associated arrays)
+ ! (note: use the argument nlegend explicitly)
+
+ call plscol0a( 15, 32, 32, 32, 0.70_plflt )
+ call pllegend( legend_width, legend_height, &
+ PL_LEGEND_BOUNDING_BOX, 0, &
+ 0.0_plflt, 0.0_plflt, 0.1_plflt, 15, &
+ 1, 1, 0, 0, &
+ nlegend, opt_array, &
+ 1.0_plflt, 1.0_plflt, 2.0_plflt, &
+ 1.0_plflt, text_colors, text, &
+ box_colors, box_patterns, box_scales, box_line_widths, &
+ line_colors, line_styles, line_widths, &
+ symbol_colors, symbol_scales, symbol_numbers, symbols )
+
+ end subroutine plot1
+end module plplot_code_ex4
+
+module handlers_ex4
+ use common_ex4
+
+ implicit none
+contains
+ function delete_cb (widget, event, gdata) result(ret) bind(c)
+ integer(c_int) :: ret
+ type(c_ptr), value :: widget, event, gdata
+
+ call gtk_widget_destroy(window)
+ call gtk_main_quit ()
+ ret = FALSE
+ end function delete_cb
+ subroutine quit_cb(widget, gdata) bind(c)
+ type(c_ptr), value :: widget, gdata
+
+ call gtk_widget_destroy(window)
+ call gtk_main_quit ()
+ end subroutine quit_cb
+
+end module handlers_ex4
+
+program cairo_plplot_ex4
+
+ use handlers_ex4
+ use plplot_code_ex4
+ use common_ex4
+
+ implicit none
+
+ type(c_ptr), dimension(2) :: drawing
+ type(c_ptr) :: base, nbook, qbut
+ integer :: pno
+
+ call gtk_init()
+
+ window = hl_gtk_window_new("PLplot x04 / gtk-fortran (extcairo)"&
+ & //c_null_char, &
+ & delete_event = c_funloc(delete_cb))
+
+ base = hl_gtk_box_new()
+ call gtk_container_add(window, base)
+
+ nbook = hl_gtk_notebook_new()
+ call hl_gtk_box_pack(base, nbook)
+ drawing(1) = hl_gtk_drawing_area_new(size=[800,600], &
+ & has_alpha=FALSE)
+
+ pno = hl_gtk_notebook_add_page(nbook, drawing(1), &
+ & label="Plot 1 (No grid)"//c_null_char)
+
+ drawing(2) = hl_gtk_drawing_area_new(size=[800,600], &
+ & has_alpha=FALSE)
+
+ pno= hl_gtk_notebook_add_page(nbook, drawing(2), &
+ & label="Plot 2 (With grid)"//c_null_char)
+
+ qbut = hl_gtk_button_new("Quit"//c_null_char, clicked=c_funloc(quit_cb))
+ call hl_gtk_box_pack(base, qbut, expand=FALSE)
+
+ call gtk_widget_show_all (window)
+
+ call plot_04(drawing)
+
+ call gtk_main()
+
+ print *, "All done"
+end program cairo_plplot_ex4

0 comments on commit 6d33fc7

Please sign in to comment.
Something went wrong with that request. Please try again.