Chapter 11. Fortran 95 Language

As discussed in the preceding section, PLplot's integer representation is a PLINT and its floating point representation is a PLFLT. To the Fortran 95 user, this most commonly translates to a type integer and type real, respectively. This is somewhat system dependent (and up to the installer of the package) so you should check the release notes to be sure, or just try it and see what happens.

Because the PLplot kernel is written in C, standard C syntax is used in the description of each PLplot function. Thus to understand this manual it is helpful to know a little about C, but fortunately the translation is very easy and can be summarized here. As an example, the routine plline call from C would look like:


      plline(n,x,y);
    
The argument n is the number of points that make up the line and the arguments x and y are arrays of floating-point numbers containing the x- and y-coordinates of the points.

In C you need to specify the array dimensions explicitly, whereas in Fortran 95 the array dimension can be implicit, which leads to less mistakes. The interface to plline would ideally look like this:


      interface
      subroutine plline(x,y)
      real, dimension(:) :: x, y
      end subroutine plline
      end interface
    
This is the way of calling PLplot routines in Fortran 95 - it is less error-prone than the Fortran 77 way (see the chapter on Fortran 77). [1]

There is one slight complication: PLplot can be compiled with either single-precision reals or double-precision reals. It is very important to keep the variables that are passed to PLplot in the same precision. Fortunately, Fortran 95 provides the KIND mechanism for this.

The actual interface to plline therefore looks like:


      interface
      subroutine plline(x,y)
      real(kind=plflt), dimension(:) :: x, y
      end subroutine plline
      end interface
    
The parameter plflt is defined in the PLplot module and should be used consistently with all real variables that you pass to PLplot routines.

Here is a short overview of how C data types correspond to Fortran 95 data types:

PLFLTreal(kind=plflt)
PLINTinteger
char *character
PLFLT *real(kind=plflt) or real(kind=plflt), dimension(:)
PLFLT **real(kind=plflt), dimension(:,:)
"string"'string'
array[0]array(1)

In C there are two ways to pass a variable --- by value (the default) or by reference (pointer), whereas only the latter is used by Fortran 95. Therefore when you see references in the text to either an ordinary argument or a pointer argument (e.g. *data), you simply use an ordinary Fortran 95 variable or array name (the interfacing routines take care of any transformations that may be necessary).

The PLplot library comes with a set of Fortran 95 interface routines that allow the same call semantics (usually) regardless of whether calling from C or Fortran 95. In some cases, the Fortran 95 interface uses implicit array dimensions, so that it has fewer arguments than the C counterpart.

These "stub" routines handle transforming the data from the normal Fortran 95 representation to that typically used in C. This includes:

This all seems a little messy, but is very user friendly. Fortran 95 and C programmers can use the same basic interface to the library, which is a powerful plus for this method. The fact that stub routines are being used is completely transparent to the Fortran 95 programmer.

For more information on calling PLplot from Fortran 95, please see the example Fortran 95 programs (/examples/f95/x??f.f) distributed with PLplot.

Notes

[1]

The Fortran 77 way is still available: you can call the routine pllinef77 that has the same argument list as the Fortran 77 routine plline. This is not documented, however, other than by this note.

[2]

PLPOIN is a macro that get translated into the correct name for this routine - various Fortran compilers use different conventions, such as adding an underscore or translating the name into capitals.