DISLIN SimpleGraphics
Module
Aleksandar Donev
Take a look at the documentation
for the DISLIN library for more information on its capabilities. For the
purpose of this webpage, it is enough to say that this is a high-level
scientific plotting library that is very widely used and free for Linux
Fortran systems. It is installed on the Giltner 346 cluster for general
use.
I have made my own set of routines for scientific 2D and 3D line, surface
and color plotting, based on the familiar MATLAB plotting commands and
addopted a simple subset of these for use by students. These are placed
in the module SimpleGraphics. Take a look at the source
file with the Fortran 90 module to see exactly what I did if you are
interested. Examples are given at the bottom of this page.
The module provides several routines. Here I give their interface and
an explanation of how they are used. The examples given after that will
make everything much clearer:
-
The subroutine InitGraphics must be called to initialize
the graphics environment before any plotting routines:
SUBROUTINE InitGraphics(file,file_type,plot_title,x_label,y_label,z_label)
CHARACTER(*), OPTIONAL, INTENT(IN) :: file,file_type
CHARACTER(*), DIMENSION(:), OPTIONAL, INTENT(IN) :: plot_title
CHARACTER(*), OPTIONAL, INTENT(IN) :: x_label,y_label,z_label
END SUBROUTINE InitGraphics
Notice that all of its arguments are optional, although a meaningful plot
should have all of them defined. The string file gives
the name of the file to which the created image will be written (if the
image is displayed on screen, no file is really created). The most important
argument is the string file_type which defines what kind
of an image file is produced. Most often used are "CONS"
for the whole X screen (no file is written), "POST" for PostScript
(.ps) files (for printing), "JAVA" for Java applets,
"PNG"
for PNG images, etc.
The axis labels for the x, y and z (if present)
axis,
x_label, y_label and
z_label,
are also simple strings. The title of the plot
plot_title
should be an array of strings, one string for each line in the title. Note
that this is most easly done using array constructors, as in,
plot_title=(/"Line 1","Line 2"/)
however, this does not work with f90-vast due to some internal
bug. See the examples below for proper usage.
The subroutine EndGraphics must be called to end the graphics
environment and write the output to the file:
SUBROUTINE EndGraphics()
END SUBROUTINE EndGraphics
NOTE:
To close the DISLIN X window with the plot (opened
with "CONS"), click the left or middle mouse button.
The subroutine AddLegend can be used to add a legend to
a plot if that is needed:
SUBROUTINE AddLegend(legends,position)
CHARACTER(*), DIMENSION(:), INTENT(IN) :: legends
INTEGER, OPTIONAL, INTENT(IN) :: position
END SUBROUTINE AddLegend
It takes the array of strings legends with one string for
each line in the legend (i.e. for each curve) and optionally the integer
position of the legend position (3 and 7 are most used--upper
right corner of page and upper right corner of plot) as argumens.
The subroutine Plot2D is the main routine for plotting
curves with points on two dimensional plots. It can be called several times
in a row to plot several curves on the same plot. Its somewhat complicated
interface is:
SUBROUTINE Plot2D(x,y,plot_spec,new_plot,axis)
REAL, DIMENSION(:), INTENT(IN), OPTIONAL :: x
REAL, DIMENSION(SIZE(x)), INTENT(IN), OPTIONAL :: y
CHARACTER(LEN=3), OPTIONAL, INTENT(IN) :: plot_spec
LOGICAL, OPTIONAL, INTENT(IN) :: new_plot
REAL, DIMENSION(4), OPTIONAL, INTENT(IN) :: axis
END SUBROUTINE Plot2D
The single-precision real vectors of equal size x
and y contain the data points to be plotted. The optional
single-precision vector of 4 values axis gives the axis
limits. If it is not present, the routine will choose the axis limits so
as to fit the whole range of x and y values. For example,
use axis=(/x_min,x_max,y_min,y_max/).
An important argument is the logical indicator new_plot,
which tells the routine whether we are making a brand new plot (i.e. this
is the first call to Plot2D) or we are adding a curve to a plot
that was already started. The default is new_plot=.TRUE..
Usually it is not wise to give an axis specification with new_plot=.FALSE.,
since this will overwrite previous axis. Although it is possible
to have the routine keep track of this itself, this gives more freedom
to the user to achive special effects such as overlapped plots with different
axis.
The three-character specification string plot_spec
determines the curve attributes and thus how the plot actually looks. The
specification string has the following interpretation:
-
The first character should be one of 'S' (plot data points as
symbols--no line), or 'L' (plot data points connected with a line--no
symbols). If you want both a line and symbols, call the routine twice with
the same data but different specification.
-
The second character for symbol plots (i.e first specification character
was 'S') plots should be on of 'S' (use squares as symbols),
'C'
(circles), 'T' (triangles), 'D' (diamonds), or lower-case
letters ('s' 'c' 't' 'd') for the corresponding filled symbols
(filled squares, filled circles, filled triangles and filled diamonds).
For line plots (i.e first character was 'L'), the second character
should be one of '-' (solid line), '.' (dotted), ':'
(dashed) or '|' (dashed-dotted).
-
The third character determines the color of the curve and should be one
of 'R' (red), 'B' (blue), 'G' (green) or 'Y'
(yellow).
For example, an argument plot_spec="STR" will plot the data points
as symbols using red triangles, while plot_spec="L-G" will connect
the data points with a green solid line. Here is a typical call to Plot2D:
CALL Plot2D(x=x_data,y=y_data,plot_spec="L-G",new_plot=.TRUE.,axis=(/x_min,x_max,y_min,y_max/))
The subroutine Plot3D is the main routine for plotting
curves with points in three dimensions dimensional. It is called in exactly
the same way as Plot2D, with an optional parameter specifying
the view explained further below, and extra info about the z
coordinates and axis:
SUBROUTINE Plot3D(x,y,z,plot_spec,new_plot,axis,view)
REAL, DIMENSION(:), INTENT(IN), OPTIONAL :: x
REAL, DIMENSION(SIZE(x)), INTENT(IN), OPTIONAL :: y,z
CHARACTER(LEN=3), OPTIONAL, INTENT(IN) :: plot_spec
LOGICAL, OPTIONAL, INTENT(IN) :: new_plot
REAL, DIMENSION(6), OPTIONAL, INTENT(IN) :: axis
REAL, DIMENSION(3), OPTIONAL :: view
END SUBROUTINE Plot3D
Two main types of three dimensional plots are often used, surface plots,
in which a third dimension is emulated with possibly coloring to give the
value of a function z=f(x,y), or color plots, in which the
plot is two dimensional but color is used to denote the magnitude of f(x,y).
These kinds of plots can be made with the subroutine SurfPlot,
which is somewhat more advanced. It should not be used to put more than
one plot on the same graph, since this is somewhat of a difficult task:
SUBROUTINE SurfPlot(x,y,z,plot_spec,color_range,axis,view)
REAL, DIMENSION(:), INTENT(IN) :: x,y
REAL, DIMENSION(SIZE(X),SIZE(Y)), INTENT(IN) :: z
CHARACTER(3), OPTIONAL, INTENT(IN) :: plot_spec
REAL, DIMENSION(2), OPTIONAL, INTENT(IN) :: color_range
REAL, DIMENSION(6), OPTIONAL, INTENT(IN) :: axis
REAL, DIMENSION(3), OPTIONAL, INTENT(IN) :: view
END SUBROUTINE SurfPlot
It accepts the same kind of arguments as Plot2D, with additional
optional 2/3 element arrays specifying the camera position view
(in polar (phi,theta,r) coordinates--angles as degrees,
not radians!) and color range color_range (the largest
and smallest representable magnitudes), which are usually chosen well automatically.
The specification string plot_spec has the following interpretation
in this case:
-
The first character should be one of '2' (plot data points as
a 2D color plot), or '3' (plot data points as a 3D surface).
-
The second character for color ('2') plots should be a digit from
1-9 and specify the increase in the resolution (number of linear-interpolation
interior-points). For surface ('3') plots, this character should
be one of 'M' (mesh line surface), 'C' (color-shaded surface)
or 'S' (both mesh and color shading).
-
The third character determines the color palette and should be one of 'R'
or 'r' (rainbow palette in two different directions of hot-cold),
'G'
or 'g' (gray palette in two different directions) or 'V'
(VGA 16 color palette).
For examples on how to use these routines, take a look at the curve-plotting
sample file TestSimple_2D.f90 (for the output, look at this image).
Also take a look at the surface-plotting sample
file (for the output, see the 2D color
or 3D surface plots).