Permalink
Browse files

Make plplot detection automatic and integrated in cmake system. Add t…

…est runner.
  • Loading branch information...
1 parent dc7fc58 commit 73b3beb5393fdea3f1a9e898dc69c7496f6f847c @jtappin jtappin committed Aug 8, 2012
View
@@ -22,14 +22,16 @@
# If not, see <http://www.gnu.org/licenses/>.
#
# Contributed by Kyle Horne: 05.11.2011
+# Last modifications: James Tappin 8/7/2012.
# CMAKE build file for GtkFortran
cmake_minimum_required(VERSION 2.6)
project(gtk-fortran C Fortran)
-# Uncomment this to debug
+# Uncomment this to debug or use "cmake -D CMAKE_BUILD_TYPE=debug .."
# set(CMAKE_BUILD_TYPE debug)
+# set(CMAKE_BUILD_TYPE release)
set(CMAKE_Fortran_FLAGS_DEBUG
"-g -pthread -Wall -Wtabs -fcheck-array-temporaries -fbacktrace -fbounds-check -ffpe-trap=invalid,zero,overflow -Wno-unused-dummy-argument")
@@ -87,6 +89,24 @@ documentation..." WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_custom_target(doc)
add_dependencies(doc doxygen)
+#
+if (NOT EXCLUDE_PLPLOT)
+ find_package(PlplotF95 QUIET)
+ set(HAVE_LIBPLPLOTF95D ${PLPLOT_FOUND})
+ if(PLPLOT_FOUND)
+ set(LIBRARIES ${LIBRARIES} ${PLPLOT_LIBRARIES})
+ include_directories(${PLPLOT_INCLUDE_DIR})
+ include_directories(${PLPLOT_MODULE_DIR})
+ else(PLPLOT_FOUND)
+ message(STATUS "PLPLOT not found: PLPLOT integration and examples will not be built")
+ endif(PLPLOT_FOUND)
+else(NOT EXCLUDE_PLPLOT)
+ message(STATUS "PLPLOT Excluded as command option")
+endif(NOT EXCLUDE_PLPLOT)
+
add_subdirectory(src)
-# add_subdirectory(tests)
+add_subdirectory(test)
add_subdirectory(examples)
+if(PLPLOT_FOUND AND NOT EXCLUDE_PLPLOT)
+ add_subdirectory(plplot)
+endif(PLPLOT_FOUND AND NOT EXCLUDE_PLPLOT)
@@ -0,0 +1,34 @@
+#
+# copyright : (c) 2010 Maxime Lenoir, Alain Coulais,
+# Sylwester Arabas and Orion Poplawski
+#
+# Modified to find Fortran rather than C++ libraries:
+# July 2012: James Tappin
+#
+# This program 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 2 of the License, or
+# (at your option) any later version.
+#
+
+find_package(PkgConfig)
+pkg_check_modules(PLPLOTF95 QUIET plplotd-f95)
+
+find_library(PLPLOT_LIBRARY NAMES plplotd)
+find_library(PLPLOTF95_LIBRARY NAMES plplotf95d)
+find_library(PLPLOTF95C_LIBRARY NAMES plplotf95cd)
+set(PLPLOT_LIBRARIES ${PLPLOT_LIBRARY} ${PLPLOTF95_LIBRARY} ${PLPLOTF95C_LIBRARY})
+find_path(PLPLOT_INCLUDE_DIR NAMES plplot/plplot.h)
+find_path(PLPLOT_MODULE_DIR NAMES plplot.mod PATHS ${PLPLOTF95_INCLUDE_DIRS})
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(PLPLOT DEFAULT_MSG PLPLOT_LIBRARIES
+ PLPLOT_INCLUDE_DIR)
+
+mark_as_advanced(
+ PLPLOT_LIBRARY
+ PLPLOTCF95_LIBRARY
+ PLPLOTCF95C_LIBRARY
+ PLPLOT_LIBRARIES
+ PLPLOT_INCLUDE_DIR
+ PLPLOT_MODULE_DIR
+ )
View
@@ -0,0 +1,64 @@
+# 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/>.
+#
+# Contributed by James Tappin: 7/31/2012
+
+# set(sources
+# "plplot_extra.f90")
+
+include_directories("/usr/include")
+#include_directories(${PLPLOT_INCLUDES})
+include_directories("${CMAKE_BINARY_DIR}/plplot")
+include_directories("${CMAKE_BINARY_DIR}/src")
+include_directories(${GTK_INCLUDES})
+#include_directories(${PLPLOT_MODULE_DIR})
+
+add_custom_command(
+ OUTPUT plplot_extra.mod
+ COMMAND ${CMAKE_Fortran_COMPILER} -c ${CMAKE_CURRENT_SOURCE_DIR}/plplot_extra.f90
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/plplot_extra.f90)
+add_custom_target(plplot_extra_module ALL DEPENDS plplot_extra.mod)
+
+install(FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/plplot_extra.mod"
+ DESTINATION include/gtk-2-fortran)
+
+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_plplot8e "hl_plplot8e.f90")
+add_dependencies(hl_plplot8e plplot_extra_module)
+target_link_libraries(hl_plplot8e gtk-fortran_static ${GTK_LIBRARIES} ${PLPLOT_LIBRARIES})
+add_test(hl_plplot8e ./hl_plplot8e)
+
+add_executable(hl_plplot17e "hl_plplot17e.f90")
+add_dependencies(hl_plplot17e plplot_extra_module)
+target_link_libraries(hl_plplot17e gtk-fortran_static ${GTK_LIBRARIES} ${PLPLOT_LIBRARIES})
+add_test(hl_plplot17e ./hl_plplot17e)
+
+add_executable(hl_plplot30e "hl_plplot30e.f90")
+add_dependencies(hl_plplot30e plplot_extra_module)
+target_link_libraries(hl_plplot30e gtk-fortran_static ${GTK_LIBRARIES} ${PLPLOT_LIBRARIES})
+add_test(hl_plplot30e ./hl_plplot30e)
+
File renamed without changes.
@@ -10,12 +10,20 @@ Requirements
------------
gtk-fortran: (including for these examples the high-level modules gtk_hl
-and gtk_draw_hl), gtk2 or gtk3 should work. It is easiest to build the
+and gtk_draw_hl), gtk2 and gtk3 should both work. It is easiest to build the
examples if gtk-fortran and its pkg-config file are installed on your
system.
plplot: including the fortran95 bindings and the cairo drivers. They
-are tested with the current release -- 5.9.7.
+are tested with the current release -- 5.9.9.
+It is known that example 30 will not build with version 5.9.5, but is
+buildable with 5.9.7.
+
+A wrapper module plplot_extra.mod is created by the gtk-fortran system
+to allow access to the pl_cmd routine in plplot which is not in the
+Fortran95 binding. It provides low-level access to the system and is
+needed to correctly configure the "extcairo" driver. The module also
+provides the mnemonic command codes for pl_cmd.
Concept
-------
@@ -39,17 +47,25 @@ Handlers:
PLplot drawing:
Connect plplot's output to the backing surface (see below).
Make the plot(s)
- call gtk_widget_queue_draw on the drawing area to force a
+ Call gtk_widget_queue_draw on the drawing area to force a
redraw.
Globals:
- For convenience in both examples I've put all the gtk use
+ For convenience in all examples I've put all the gtk (etc.) use
statements and any global variables into a separate module that
can be used by all of the other units.
-Connecting PLplot's output to the pixbuf.
+In the example codes these are:
+
+* The main program (called cairo_plplot_ex<n>)
+* The common module (common_ex<n>)
+* The drawing module (plplot_code_ex<n>)
+* The handlers (handlers_ex<n>)
+
+Connecting PLplot's output to the drawing area.
+-----------------------------------------------
-For the extcairo driver, output is to an externally greated cairo
+For the "extcairo" driver, output is to an externally-created cairo
context. So here you need to create a cairo context connected to the
backing surface (this is most easily done with
hl_gtk_drawing_area_cairo_new). And then use pl_cmd to connect plplot's
@@ -72,7 +88,7 @@ the call to plinit (or plstar):
And then after plinit you need:
- call pl_cmd(PLESC_DEVINIT, cc)
+ call pl_cmd(PLESC_DEVINIT, cc)
A fortran interface to pl_cmd is provided by the plplot_extras module
in this directory.
@@ -81,36 +97,49 @@ in this directory.
Building the examples
---------------------
+If plplot is found when building gtk-fortran, then the interface module
+for pl_cmd will be built and installed and the examples will be
+built. The instructions that follow are therefore only needed if you
+want to build them manually for some reason.
+
The plplot example(s) are most easily built if gtk-fortran has been
installed. Then it is simply a matter of:
- gfortran -o hl_plplot<x> hl_plplot<x>.f90 `pkg-config --cflags --libs \
- gtk-fortran plplotd-f95`
+ gfortran -o hl_plplot<x>e hl_plplot<x>e.f90 `pkg-config --cflags --libs \
+ gtk-<n>-fortran plplotd-f95`
-where <x> is the number of the example. A basic Makefile to do this is
-provided.
+where <x> is the number of the example, and <n> is 2 or 3 according to
+which gtk version you are using.
The examples are derived from the Fortran95 versions of Examples 1, 8,
30 and 17 on the PLplot web site.
hl_plplot1e: Basic x-y plots on multiple pages
hl_plplot8e: 3-D data display
hl_plplot17e: Strip charts, shows continuous updating
-hl_plplot30e: Transparency.
+hl_plplot30e: Transparency (needs at least plplot 5.9.7).
+
+
+If you wish to explicitly exclude building and installing plplot
+support, then when running cmake, include the option "-D
+EXCLUDE_PLPLOT=Y" (e.g.:
+ cmake -D EXCLUDE_PLPLOT=Y ..
+)
Known issues
------------
Different releases of gfortran (let alone different fortran compilers)
cannot read each other's module files, therefore plplot must be built
-with the same compiler as gtk-fortran. Since not many Linux distros use
-gcc/gfortran 4.6 yet, this means you will probably need to build plplot
-from source. In addition the x86_64 gfortran binary snapshots for 4.6 &
-4.7 fail to build the C++ parts of plplot, unless you remove the c++
-compiler binaries/links from the snapshot directory (I tried forcing
-the c++ compiler to be /usr/bin/c++ with ccmake but I couldn't get it
-to stick).
-
-Since the modifications to the high-level drawing routines, it is no
-longer possible to use the "memcairo" device to capture cairo output
-into a pixbuf (but that was somewhat of a kludge anyway).
+with the same compiler as gtk-fortran. For most Linux distributions,
+this is no longer an issue as most use gcc 4.6 or 4.7. However for
+those that are still based on 4.5 or lower [*], this means you will
+probably need to build plplot from source. In addition when I last used
+this method, the x86_64 gfortran binary snapshots for 4.6 & 4.7 failed
+to build the C++ parts of plplot, unless you remove the c++ compiler
+binaries/links from the snapshot directory (I tried forcing the c++
+compiler to be /usr/bin/c++ with ccmake but I couldn't get it to
+stick).
+
+[*] To my knowledge RHEL, SUSE, Slackware and Debian Stable (and their
+derivatives), but not Fedora or OpenSUSE.
@@ -23,9 +23,9 @@
!
! gfortran hl_plplot17e.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
+! PLplot code derived from PLplot's example 17 by Alan W. Irwin
-module common
+module common_ex17
use iso_c_binding
use gtk, only: gtk_button_new, gtk_container_add, gtk_drawing_area_new, &
& gtk_events_pending, gtk_main, gtk_main_iteration, &
@@ -38,15 +38,18 @@ module common
use plplot_extra
+ implicit none
+
integer(kind=c_int) :: height, width
integer(kind=c_int) :: run_status = TRUE
+ type(c_ptr) :: window
-end module common
+end module common_ex17
-module plplot_code
+module plplot_code_ex17
use plplot, PI => PL_PI
use iso_c_binding
- use common
+ use common_ex17
implicit none
@@ -228,17 +231,17 @@ subroutine close_strip
call plend()
call hl_gtk_drawing_area_cairo_destroy(cc)
end subroutine close_strip
-end module plplot_code
+end module plplot_code_ex17
-module cl_handlers
+module handlers_ex17
- use common
+ use common_ex17
use gtk_hl
use gtk_draw_hl
use iso_c_binding
- use plplot_code
+ use plplot_code_ex17
implicit none
@@ -268,16 +271,17 @@ subroutine pending_events ()
end subroutine pending_events
-end module cl_handlers
+end module handlers_ex17
-program cairo_plplot
+program cairo_plplot_ex17
- use cl_handlers
- use plplot_code
+ use handlers_ex17
+ use plplot_code_ex17
+ use common_ex17
implicit none
- type(c_ptr) :: window, drawing, base, qbut
+ type(c_ptr) :: drawing, base, qbut
height = 500
width = 1000
@@ -301,11 +305,16 @@ program cairo_plplot
call x17f95(drawing)
+ ! Note that here rather than using gtk_main we look for events ourselves
+ ! this makes it easy to add a point every 1/10s.
+ ! An alternative would be to use g_timeout_add to control the updates.
+
do
call pending_events()
if (run_status == FALSE) exit
call g_usleep(100000_c_long) ! So we don't burn CPU cycles
call add_point(drawing)
end do
+
print *, "All done"
-end program cairo_plplot
+end program cairo_plplot_ex17
Oops, something went wrong. Retry.

0 comments on commit 73b3beb

Please sign in to comment.