Using PLPLOT with Fortran
PLPLOT
Introduction
PLplot is a software package for creating scientific plots . It is cross-platform β€, which means it will work on Windows, Unix, and Linux system. The PLplot software is primarily licensed under the LGPL π₯. It is written in C language, and it has bindings π for several other language including Fortran π₯οΈ .
The PLplot core library can be used to create
- π₯standard x-y plots
- π₯semi-log plots
- πlog-log plots
- π€contour plots
- πΉ3D surface plots
- π©mesh plots
- π¦bar charts
- π₯§pie charts.
You can find more about PLPLOT β‘οΈπ±
Historical remark
A small history of PLPLOT taken from the official documentation is given below.
PLplot was originally developed by Sze Tan of the University of Auckland in Fortran-77. Many of the underlying concepts used in the PLplot package are based on ideas used in Tim Pearsonβs PGPLOT package. Sze Tan writes:
Iβm rather amazed how far PLPLOT has travelled given its origins etc. I first used PGPLOT on the Starlink VAX computers while I was a graduate student at the Mullard Radio Astronomy Observatory in Cambridge from 1983-1987. At the beginning of 1986, I was to give a seminar within the department at which I wanted to have a computer graphics demonstration on an IBM PC which was connected to a completely non-standard graphics card. Having about a week to do this and not having any drivers for the card, I started from the back end and designed PLPLOT to be such that one only needed to be able to draw a line or a dot on the screen in order to do arbitrary graphics. The application programmerβs interface was made as similar as possible to PGPLOT so that I could easily port my programs from the VAX to the PC. The kernel of PLPLOT was modelled on PGPLOT but the code is not derived from it.
The C version of PLplot was originally developed by Tony Richardson on a Commodore Amiga. That version has been improved and expanded ever since first by Geoffrey Furnish and Maurice Lebrun in the 1990βs and later (after the project was registered at SourceForge on 2000-02-23) with a much-expanded development team.
Installation of binary packages
Ubuntu π»
sudo apt-get install libplplot-dev libplplotfortran0
MacOS π
brew install plplot
Building from source
Download the source code
git clone https://git.code.sf.net/p/plplot/plplot plplot-plplot
I have also installed some extra libraries, which are given below.
libcairo-dev
libglu1-mesa-dev
freeglut3-dev
mesa-common-dev
pyqt5
pyqt5-tools
sudo apt install libcairo-dev libglu1-mesa-dev freeglut3-dev mesa-common-dev
pip3 install pyqt5 pyqt5-tools
Building πͺ
After downloading the source code, run the following command inside of terminal
cd plplot-plplot
git branch $(whoami)
git checkout $(whoami)
We will use -DCMAKE_INSTALL_PREFIX
to specify the director wherein PLplot
will be installed.
cmake -S ./ -B ./build DCMAKE_INSTALL_PREFIX=~/.easifem/extpkgs -G "Unix Makefiles"
cmake --build ./build --target all
cmake --build ./build --target install
My Configuration: In my case, I want to install PLplot
in ~/.easifem/extpkgs
. I have already set an environment variable export EASIFEM_EXTPKGS=~/.easifem/extpkgs
, so I will use ${EASIFEM_EXTPKGS}
, but you can specify the path explicitly.
-DCMAKE_INSTALL_PREFIX:PATH=~/.easifem/extpkgs
-DCMAKE_BUILD_TYPE:STRING=Release
, other option isDebug
-DBUILD_SHARED_LIBS:BOOL=ON
, setOFF
if shared lib are not desired-DBUILD_TEST:BOOL=ON
, setOFF
you dont want to build the tests-DENABLE_fortran:BOOL=ON
, setOFF
, if you dont want fortran bindings-DENABLE_lua:BOOL=ON
, setOFF
if you do not want Lua language bindings
cmake -S ./ -B ~/temp/easifem-extpkgs/plplot/build -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=${EASIFEM_EXTPKGS} -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_SHARED_LIBS:BOOL=ON -DBUILD_TEST:BOOL=ON -DENABLE_fortran:BOOL=ON -DENABLE_lua:BOOL=ON
cmake --build ~/temp/easifem-extpkgs/plplot/build --target all
Now you can go to $EASIFEM_EXTPKGS
βββ bin
βββ include/plplot
βββ lib
βββ man
βββ share
Contents of /bin
π is shown below
/bin
βββ plserver
βββ pltcl
βββ pltek
Contents of /include/plplot
π
βββ csadll.h
βββ csa.h
βββ disptab.h
βββ drivers.h
βββ pdf.h
βββ plConfig.h
βββ pldebug.h
βββ plDevs.h
βββ pldll.h
βββ plevent.h
βββ plplot.h
βββ plplotP.h
βββ plstream.h
βββ plstrm.h
βββ pltcl.h
βββ pltk.h
βββ plxwd.h
βββ qsastimedll.h
βββ qsastime.h
βββ qt.h
βββ tclMatrix.h
Contents of /lib
π
βββ cmake
βββ fortran
βββ libcsirocsa.so -> libcsirocsa.so.0
βββ libcsirocsa.so.0 -> libcsirocsa.so.0.0.1
βββ libcsirocsa.so.0.0.1
βββ libplfortrandemolib.a
βββ libplplotcxx.so -> libplplotcxx.so.15
βββ libplplotcxx.so.15 -> libplplotcxx.so.15.0.0
βββ libplplotcxx.so.15.0.0
βββ libplplotfortran.so -> libplplotfortran.so.0
βββ libplplotfortran.so.0 -> libplplotfortran.so.0.2.0
βββ libplplotfortran.so.0.2.0
βββ libplplotqt.so -> libplplotqt.so.2
βββ libplplotqt.so.2 -> libplplotqt.so.2.0.3
βββ libplplotqt.so.2.0.3
βββ libplplot.so -> libplplot.so.17
βββ libplplot.so.17 -> libplplot.so.17.0.0
βββ libplplot.so.17.0.0
βββ libplplottcltk_Main.so -> libplplottcltk_Main.so.1
βββ libplplottcltk_Main.so.1 -> libplplottcltk_Main.so.1.0.1
βββ libplplottcltk_Main.so.1.0.1
βββ libplplottcltk.so -> libplplottcltk.so.14
βββ libplplottcltk.so.14 -> libplplottcltk.so.14.1.0
βββ libplplottcltk.so.14.1.0
βββ libqsastime.so -> libqsastime.so.0
βββ libqsastime.so.0 -> libqsastime.so.0.0.1
βββ libqsastime.so.0.0.1
βββ libtclmatrix.so -> libtclmatrix.so.10
βββ libtclmatrix.so.10 -> libtclmatrix.so.10.3.0
βββ libtclmatrix.so.10.3.0
βββ pkgconfig
βββ plplot5.15.0
-plplot5.15.0
βββ drivers
βββ mem.driver_info
βββ mem.so
βββ ntk.driver_info
βββ ntk.so
βββ null.driver_info
βββ null.so
βββ ps.driver_info
βββ ps.so
βββ qt.driver_info
βββ qt.so
βββ svg.driver_info
βββ svg.so
βββ tk.driver_info
βββ tk.so
βββ tkwin.driver_info
βββ tkwin.so
βββ xfig.driver_info
βββ xfig.so
βββ xwin.driver_info
βββ xwin.so
The lib/cmake
directory π contains files necessary for using PLplot with CMake. The contents of this directory are given below.
βββ export_csirocsa.cmake
βββ export_csirocsa-release.cmake
βββ export_mem.cmake
βββ export_mem-release.cmake
βββ export_ntk.cmake
βββ export_ntk-release.cmake
βββ export_null.cmake
βββ export_null-release.cmake
βββ export_plfortrandemolib.cmake
βββ export_plfortrandemolib-release.cmake
βββ export_plplot.cmake
βββ export_plplotcxx.cmake
βββ export_plplotcxx-release.cmake
βββ export_plplotfortran.cmake
βββ export_plplotfortran-release.cmake
βββ export_plplotqt.cmake
βββ export_plplotqt-release.cmake
βββ export_plplot-release.cmake
βββ export_plplottcltk.cmake
βββ export_plplottcltk_Main.cmake
βββ export_plplottcltk_Main-release.cmake
βββ export_plplottcltk-release.cmake
βββ export_plserver.cmake
βββ export_plserver-release.cmake
βββ export_pltcl.cmake
βββ export_pltcl-release.cmake
βββ export_pltek.cmake
βββ export_pltek-release.cmake
βββ export_ps.cmake
βββ export_ps-release.cmake
βββ export_qsastime.cmake
βββ export_qsastime-release.cmake
βββ export_qt.cmake
βββ export_qt-release.cmake
βββ export_svg.cmake
βββ export_svg-release.cmake
βββ export_tclmatrix.cmake
βββ export_tclmatrix-release.cmake
βββ export_tk.cmake
βββ export_tk-release.cmake
βββ export_tkwin.cmake
βββ export_tkwin-release.cmake
βββ export_xfig.cmake
βββ export_xfig-release.cmake
βββ export_xwin.cmake
βββ export_xwin-release.cmake
βββ plplotConfig.cmake
βββ plplotConfigVersion.cmake
βββ plplot_exports.cmake
The lib/pkgconfig
directory contains files necessary for finding PLplot using pkgconfig in CMake projects. The contents of this directory are given below.
βββ plplot-c++.pc
βββ plplot-fortran.pc
βββ plplot.pc
βββ plplot-qt.pc
βββ plplot-tcl_Main.pc
βββ plplot-tcl.pc
The lib/fortran/modules/plplot
directory contains Fortran module files as shown below.
βββ plfortrandemolib.mod
βββ plplot_double.mod
βββ plplot_graphics.mod
βββ plplot.mod
βββ plplot_private_exposed.mod
βββ plplot_private_utilities.mod
βββ plplot_single.mod
βββ plplot_types.mod
After a successful build open your .bashrc
or .zshrc
and add following lines to it
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:${EASIFEM_EXTPKGS}/lib/pkgconfig"
Note: You have to replace ${EASIFEM}
with the PLplot installation path.
Subsequently, run the following command inside terminal.
source ~/.bashrc #if bash if default SHELL
or
source ~/.zshrc #if ZSH is default
Running examples
Create a directory test
π
mkdir test
cd test
curl -o PLplot_example_1.F90 https://api.cacher.io/raw/ae828dbdfa2aebf3af0a/403d8f4836d78bddc387/PLplot_example_1.F90
curl -o CMakeLists.txt https://api.cacher.io/raw/3ca8ef3a43180dba7f35/cbb8263d9026e996d6ca/PLplot_CMakeLists.txt
cmake -B ./build -DFILE_NAME:STRING="PLplot_example_1.F90"
cmake --build ./build
./build/test
The content of CMakeLists.txt is given below
CMAKE_MINIMUM_REQUIRED(VERSION 3.20.0 FATAL_ERROR)
SET(PROJECT_NAME "plplot")
PROJECT(${PROJECT_NAME})
ENABLE_LANGUAGE(Fortran C)
SET(TARGET_NAME "test")
SET(PLplot_INCLUDE_DIR "$ENV{EASIFEM_EXTPKGS}/lib/fortran/modules/plplot" )
SET(PLplot_LIBRARY "$ENV{EASIFEM_EXTPKGS}/lib/libplplot.so" )
SET(PLplot_Fortran_LIBRARY "$ENV{EASIFEM_EXTPKGS}/lib/libplplotfortran.so" )
OPTION(FILE_NAME "File name")
ADD_EXECUTABLE(${TARGET_NAME} ${FILE_NAME})
TARGET_LINK_LIBRARIES(
${TARGET_NAME}
${PLplot_LIBRARY}
${PLplot_Fortran_LIBRARY} )
TARGET_INCLUDE_DIRECTORIES( ${TARGET_NAME} PRIVATE ${PLplot_INCLUDE_DIR} )
You should see the following result.