DISLIN

DISLIN is a high-level graphics library for displaying data as curves, bar graphs, pie charts, 3D-colour plots, surfaces, contours, and maps. Several output formats are available, like SVG, PNG, PDF, or X11. The library was originally developed at the Max Planck Institute for Solar System Research, and supports several operating systems and programming languages, including FreeBSD ≥ 10 and Fortran ≥ 90. The first version was released in 1986. Since then, it has been constantly updated and improved.

DISLIN example
Fig. 1: Shaded surface plot

To use DISLIN within your Fortran project, you have to download a distribution suitable for your operating system. The software is not open source, but can be used freely for non-commercial and commercial purposes. Access to the source code requires a licence.

Installation

An installation script is provided to those who like to install DISLIN globally. But the easiest way to utilise the library is to copy the distribution files to your Fortran project workspace directory and then link the library statically. On FreeBSD (amd64), you will need:

Example

Some examples written in Fortran 90/95 are listed on the official project website. The following one plots a 3D surface (fig. 1):

! example.f90
program example
    use :: dislin
    implicit none
    integer, parameter :: N = 50

    character(len=32) :: title1 = 'Shaded Surface Plot'
    character(len=32) :: title2 = 'f(x, y) = 2 * sin(x) * sin(y)'

    integer :: i, j
    real    :: z_mat(N, N)
    real    :: x_ray(N), y_ray(N)
    real    :: pi, step
    real    :: x, y

    pi   = acos(-1.0) / 180.
    step = 360. / (n - 1)

    do i = 1, N
        x = (i - 1) * step
        x_ray(i) = x

        do j = 1, N
            y = (j - 1) * step
            y_ray(j) = y
            z_mat(i, j) = 2 * sin(x * pi) * sin(y * pi)
        end do
    end do

    call plot(x_ray, y_ray, z_mat, n, title1, title2)
contains
    subroutine plot(x, y, z, n, title1, title2)
        real,             intent(inout) :: x(:)
        real,             intent(inout) :: y(:)
        real,             intent(inout) :: z(:, :)
        integer,          intent(in)    :: n
        character(len=*), intent(in)    :: title1
        character(len=*), intent(in)    :: title2

        call scrmod('REVERS')   ! Set background to white, foreground to black.
        call setpag('DA4P')     ! Select page format DIN A4 portrait.
        call metafl('XWIN')     ! Select metafile format (`XWIN`, `PDF`, ...).

        call disini()           ! Initialise DISLIN.
        call pagera()           ! Add border around page.
        call simplx()           ! Select single stroke font (SIMPLX).

        call axspos(200, 2600)  ! Set axis position.
        call axslen(1800, 1800) ! Set axis size.

        ! Add axis labels.
        call name('X-Axis', 'X')
        call name('Y-Axis', 'Y')
        call name('Z-Axis', 'Z')

        ! Add title and subtitle.
        call titlin(title1, 2)
        call titlin(title2, 4)

        ! Set 3D viewpoint.
        call view3d(-5., -5., 4., 'ABS')

        ! Plot 3D axis system.
        call graf3d(0., 360., 0., 90., 0., 360., 0., 90., -3., 3., -3., 1.)

        call height(50) ! Set character height.
        call title()    ! Add title.

        ! Enable smooth shading and plot shaded surface.
        call shdmod('SMOOTH', 'SURFACE')
        call surshd(x, n, y, n, z)

        ! Shutdown DISLIN.
        call disfin()
    end subroutine plot
end program example

Just compile the DISLIN Fortran module dislin.f90 and then build the example:

$ gfortran13 -c dislin.f90
$ gfortran13 -I/usr/local/include -L/usr/local/lib -o example example.f90 \
  dislin.o dislin-11.5.a -lm -lXm -lXt -lX11 -lGL
$ ./example

The plot is shown inside an X11 window. Change the metafile format from XWIN to PDF to output the plot to file dislin.pdf instead.

Makefile

We can simplify the compilation by writing a Makefile:

.POSIX:

FC      = gfortran13
FFLAGS  = -Wall -Ofast
LDFLAGS = -I/usr/local/include -L/usr/local/lib
LDLIBS  = dislin-11.5.a -lm -lXm -lXt -lX11 -lGL
TARGET  = example

.PHONY: all clean

all: dislin.o
	$(FC) $(FFLAGS) $(LDFLAGS) -o $(TARGET) example.f90 $? $(LDLIBS)

dislin.o: dislin.f90
	$(FC) -c $?

clean:
	rm $(TARGET) *.mod *.o

Run make to build the example program:

$ make

Further Reading

References