GNUFOR2 - Gnuplot/Fortran Interface: Call Plot (X, Y)
GNUFOR2 - Gnuplot/Fortran Interface: Call Plot (X, Y)
GNUFOR2 - Gnuplot/Fortran Interface: Call Plot (X, Y)
Please note that while this program might be useful for visualising certain data produced by your
Fortran program, it can not completely replace Gnuplot. Gnuplot has much more functionality which
allows to fine tune almost every detail of the figure. For example, if I want to produce publication quality
figures, I would call one of these subroutines from my Fortran program, but then I would edit by hand
command_file.txt to obtain the desired results. I would also recommend an excellent program Inkscape
for editing pdf (and other vector graphics) files.
This module was tested under Ubuntu distribution of GNU/Linux, both with GNU Fortran and Intel
Fortran compilers. To run the test program, first copy all of the above files into the same folder. Note
that the Makefile is written for GNU Fortran, so you have to change the first line in the Makefile if you are
using a different Fortran90 compiler. Next, open your favourite shell terminal, navigate to the above
mentioned folder, and type:
$make
$make run
Note: you must have GNUPLOT and Fortran90 compiler installed and in your path. To test this, you
can type
$which gnuplot
$which gfortran (or $which ifort for Intel Fortran compiler)
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 2 de 33
ANY NEGATIVE NUMBER ( pause=-1.0 or pause=-3.0), Gnuplot will wait untill you hit Enter, and
only then pass the control back to Fortran program.
character(len=*) :: terminal -- this parameter is responsible for the output format. The default
terminal is 'wxt' -- the interactive window created by the wxWidgets library. The 'terminal' parameter is
most useful if you want to save the picture as a file. Some possibilities are
terminal='jpeg'
terminal='ps'
terminal='png'
terminal='x11'
character(len=*) :: filename -- the output is saved to a file with this name. The default filename
has the format 'date-hours-minutes-seconds-milliseconds'. This format is useful in the situation when
you are creating many pictures in a loop, and you want to save all of them (of course with different
filenames so that they do not overwrite each other). The downside of this default setting is that the
filename changes every time you run a program, and soon your folder will be littered with lots of files.
Setting filename='my_file' will always save the figure into the same file. Note that this option only
has effect when the terminal is set to 'ps', 'jpeg','png' or something similar - it is useless if the figure
is not being saved into a file.
character(len=*) :: input -- this parameter is only important for an interactive terminal 'wxt'. The
default behavior is that commands and data are always saved into files with names 'command_file.txt'
and 'data_file.txt'. This might be a problem when you are creating several graphs which persist after
the Fortran program has finished executing.The above two files might be overwritten, and you won't be
able to explore the graph using the interactive tools of 'wxt' terminal. Here is when 'input' parameter
becomes useful: you can specify different file_names for each graph. For example, if you set
input='f1', the above two files will be named 'command_file_f1.txt' and 'data_file_f1.txt'.
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 3 de 33
The only mandatory parameters are two arrays x1(:), y1(:) ot type real(kind=8). They must have the
same size.
character(len=3), optional :: style -- this parameter is responsible for the linestyle. By default
the graph is drawn with lines. You can change this by specifying:
style='10-' -- this will plot with lines and points of type 10 (see the Gnuplot list of different point types
below)
style='10.' -- the same, but now the plot is created with points only
style=' 5.' -- the plot will be created with points of type 5
IMPORTANT: Note that there is a space in front of 5 in the previous example. The style
parameter for each graph must have length equal to three. Thus if pointtype is a double digit
number, you would just type style='xx-'. But if the pointtype is a single digit number, you
must type a space in front of this number style=' x.' so that the length is still equal to three.
Different point types:
character(len=*), optional :: color1 -- the color of the lines/points. You can specify the color
by giving its name color1='dark-blue', or by giving it's RGB value color1='#334455'. Here is
the list of colors recognizable by Gnuplot :
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 4 de 33
Note that the double names should be typed with a hyphen, for some reason it is not visible in this
picture.
real(kind=4), optional :: linewidth The default is linewidth=1.0, you can change it to any
real (positive) value.
Examples:
call plot(x1, y1)
call plot(x1, y1, pause=0.5)
call plot(x1, y1, pause=0.5, persist='no')
call plot(x1, y1, '20-', color1='#886622', polar='yes')
call plot(x1, y1, x2, y2, x3, y3, linewidth=3.0)
call plot(x1, y1, x2, y2, x3, y3, x4, y4, ' 5.10- 0. 7-', color2='magenta',
filename='my_picture', terminal='ps') -- note that in this case the length of style parameter
must be 12 = 3 characters X 4 plots.
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 5 de 33
This a simple subroutine for plotting histograms. The mandatory parameters are real(kind=8) array x(:)
(the data) and an integer value n - the number of bins. The other optional parameters have the same
meaning as before.
character(len=*), optional :: pm3d -- this parameter specifies the use of the pm3d algorithm.
Possible uses include:
pm3d='pm3d'
pm3d='pm3d at b'
pm3d='pm3d map'
pm3d='pm3d implicit map'
See the Gnuplot documentation for the use of this parameter.
character(len=*), optional :: contour -- this parameter specifies the behavior of contour plot.
Possible uses include:
contour='yes' -- draw the contour plot on the xy-plane
contour='surface' -- draw the contour plot on the surface itself
contour='both' -- draw the contour plot both on the surface and xy-plane
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 6 de 33
The optional parameters pause, palette, terminal, filename, persist, input have the same
meaning as before (see 'surf' subroutine). Note that if you want to draw an rgb image, you do not need
to specify the palette parameter, as it would have no effect on the result.
The above four subroutines have one drawback - the data_file can be quite large. For example, if you
want to produce a 1000x1000 image, the size of data_file.txt is around 25Mb, for 2000x2000 image the
file size increases to 100Mb, and so on. Using .rgb files instead of ASCII should decrease the file size.
Thus if you know how to produce an .rgb binary file with Fortran -- please email me your suggestions.
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 7 de 33
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 8 de 33
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 9 de 33
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 10 de 33
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 11 de 33
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 12 de 33
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 13 de 33
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 14 de 33
call plot(x1, f1, x2, f2, x3, f3, x4, f4, ' 5.22- 0- 0-', color2='dark-yellow',
color1='#40e0d0')
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 15 de 33
call plot(x1, f1, x2, f2, x3, f3, x4, f4, polar='yes', linewidth=2.0)
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 16 de 33
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 17 de 33
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 18 de 33
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 19 de 33
call surf(zz)
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 20 de 33
call surf(xyz)
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 21 de 33
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 22 de 33
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 23 de 33
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 24 de 33
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 25 de 33
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 26 de 33
call surf(xx, yy, zz, pm3d='pm3d implicit map', palette='rgbformulae 31, -11,
32')
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 27 de 33
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 28 de 33
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 29 de 33
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 30 de 33
call image(z_fractal)
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 31 de 33
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 32 de 33
call image(rgb)
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014
GnuFor2 - Gnuplot/Fortran interface Página 33 de 33
http://www.math.yorku.ca/~akuznets/gnufor2/ 5/27/2014