EGGX/ProCALL

EGGX/ProCALL is a free X11 graphics library by Chisato Yamauchi for C (EGGX) and FORTRAN 77 (ProCALL) with modest requirements. The library provides simple 2D drawing routines that are similar to those of the Borland Graphics Interface (BGI) and old BASIC dialects. The output can be rendered to multiple X11 windows, or exported in various file formats (such as PNG, JPEG, GIF, or PostScript). Only Xlib is required as a dependency. On macOS, you have to install XQuartz first.

Fortran Mandelbrot (ProCALL)
Fig. 1: Mandelbrot set, rendered in Fortran using ProCALL (source code)

FORTRAN 77 Library

The source code of EGGX/ProCALL is available on the offical website. Unpack the archive, and run make to build the static library libeggx.a:

$ tar xfvz eggx-0.95.tar.gz
$ cd eggx-0.95/
$ make

The library includes both the C functions (EGGX) and the FORTRAN 77 routines (ProCALL). Link your Fortran application with libeggx.a -lX11. The FORTRAN 77 subroutines should be imported with the external statement first.

EGGX/ProCALL 2003

The eggx-procall-2003 library provides Fortran 90 interfaces to the FORTRAN 77 routines in ProCALL, as well as named constants are included to ease access to colour palettes, key codes, and output formats. The source code of EGGX/ProCALL 0.95 is included in the repository:

$ git clone https://github.com/interkosmos/eggx-procall-2003
$ cd eggx-procall-2003/
$ make

Link your Fortran applications against the static libraries vendor/eggx-0.95/libeggx.a and libeggx2003.a, as well as -lX11. A few example programs are distributed along the EGGX/ProCALL 2003 source code in directory examples/.

Example

The program renders the Mandelbrot set using the Fortran 90 interfaces to ProCALL, with colour palette PROCALL_IDL2_PLASMA applied (fig. 1). By default, the origin of the drawing area (0, 0) is in the bottom left.

! mandelbrot.f90
program main
    use :: procall
    implicit none

    integer, parameter :: WIN_WIDTH  = 600
    integer, parameter :: WIN_HEIGHT = 600
    integer, parameter :: MAX_ITER   = 120
    real,    parameter :: THRESHOLD  = 3.0
    real,    parameter :: LEFT       = -0.25
    real,    parameter :: RIGHT      = 0.25
    real,    parameter :: TOP        = -1.0
    real,    parameter :: BOTTOM     = -0.5

    integer :: key
    integer :: m
    integer :: r, g, b
    integer :: win
    integer :: x, y
    real    :: re, im

    call gopen(WIN_WIDTH, WIN_HEIGHT, win)              ! Open window.
    call winname(win, 'Fortran Mandelbrot' // achar(0)) ! Set window title.
    call gsetbgcolor(win, 'black' // achar(0))          ! Set background colour.
    call gclr(win)                                      ! Clear screen.

    do y = 0, WIN_HEIGHT - 1
        im = BOTTOM + real(y) * (TOP - BOTTOM) / real(WIN_HEIGHT)

        do x = 0, WIN_WIDTH - 1
            re = LEFT + real(x) * (RIGHT - LEFT) / real(WIN_WIDTH)
            m = mandelbrot(cmplx(re, im), MAX_ITER, THRESHOLD)

            ! Create new RGB colour, apply colour, and set pixel.
            call makecolor(PROCALL_IDL2_PLASMA, real(MAX_ITER), 0.0, real(m), r, g, b)
            call newrgbcolor(win, r, g, b)
            call pset(win, real(x), real(y))
        end do
    end do

    call ggetch(key)
    call gcloseall()
contains
    pure function mandelbrot(c, max_iter, threshold)
        complex, intent(in) :: c
        integer, intent(in) :: max_iter
        real,    intent(in) :: threshold
        integer             :: mandelbrot

        complex :: z

        z = (0.0, 0.0)

        do mandelbrot = 0, max_iter
            z = z**2 + c
            if (abs(z) > threshold) exit
        end do
    end function mandelbrot
end program main

Link the example with libeggx2003.a, libeggx.a, and -lX11:

$ gfortran13 -o mandelbrot mandelbrot.f90 libeggx2003.a libeggx.a -lX11
$ ./mandelbrot

The plotting performance can be improved by first drawing to a background layer, and then copying the layer the screen.

Colour Palettes

The EGGX/ProCALL 2003 library contains more than 50 named parameters of DS9- and IDL-comptaible colour palettes (tab. 1 and 2).

ParameterPalette
PROCALL_DS9_GRAYPROCALL_DS9_GRAY
PROCALL_DS9_REDPROCALL_DS9_RED
PROCALL_DS9_GREENPROCALL_DS9_GREEN
PROCALL_DS9_BLUEPROCALL_DS9_BLUE
PROCALL_DS9_APROCALL_DS9_A
PROCALL_DS9_BPROCALL_DS9_B
PROCALL_DS9_BBPROCALL_DS9_BB
PROCALL_DS9_HEPROCALL_DS9_HE
PROCALL_DS9_I8PROCALL_DS9_I8
PROCALL_DS9_AIPSOPROCALL_DS9_AIPSO
PROCALL_DS9_SLSPROCALL_DS9_SLS
PROCALL_DS9_HEATPROCALL_DS9_HEAT
PROCALL_DS9_COOLPROCALL_DS9_COOL
PROCALL_DS9_RAINBOWPROCALL_DS9_RAINBOW
PROCALL_DS9_STANDARDPROCALL_DS9_STANDARD
PROCALL_DS9_STAIRCASEPROCALL_DS9_STAIRCASE
PROCALL_DS9_COLORPROCALL_DS9_COLOR
Tab. 1: DS9-compatible colour palettes in ProCALL
ParameterPalette
PROCALL_IDL1_B_W_LINEARPROCALL_IDL1_B_W_LINEAR
PROCALL_IDL1_BLUE_WHITEPROCALL_IDL1_BLUE_WHITE
PROCALL_IDL1_GRN_RED_BLU_WHT
PROCALL_IDL1_RED_TEMPERATURE
PROCALL_IDL1_BLUE_GREEN_RED_YELLOW
PROCALL_IDL1_STD_GAMMA_II
PROCALL_IDL1_PRISM
PROCALL_IDL1_RED_PURPLE
PROCALL_IDL1_GREEN_WHITE_LINEAR
PROCALL_IDL1_RGN_WHT_EXPONENTIAL
PROCALL_IDL1_GREEN_PINK
PROCALL_IDL1_BLUE_RED
PROCALL_IDL1_16_LEVEL
PROCALL_IDL1_RAINBOW
PROCALL_IDL1_STEPS
PROCALL_IDL1_STERN_SPECIAL
PROCALL_IDL2_HAZE
PROCALL_IDL2_BLUE_BASTEL_RED
PROCALL_IDL2_PASTELS
PROCALL_IDL2_HUE_SAT_LIGHTNESS_1
PROCALL_IDL2_HUE_SAT_LIGHTNESS_2
PROCALL_IDL2_HUE_SAT_VALUE_1
PROCALL_IDL2_HUE_SAT_VALUE_2
PROCALL_IDL2_PURPLE_RED_WITH_STRIPES
PROCALL_IDL2_BEACH
PROCALL_IDL2_MAC_STYLE
PROCALL_IDL2_EOS_A
PROCALL_IDL2_EOS_B
PROCALL_IDL2_HARDCANDY
PROCALL_IDL2_NATURE
PROCALL_IDL2_OCEAN
PROCALL_IDL2_PEPPERMINT
PROCALL_IDL2_PLASMA
PROCALL_IDL2_BLUE_RED
PROCALL_IDL2_RAINBOW
PROCALL_IDL2_BLUE_WAVES
PROCALL_IDL2_VALCANO
PROCALL_IDL2_WAVES
PROCALL_IDL2_RAINBOW18
PROCALL_IDL2__RAINBOW
PROCALL_IDL2_ORBIT_VIEWER_COLOR
PROCALL_IDL2_ORBIT_VIEWER_GRAY
Tab. 2: IDL-compatible colour palettes in ProCALL

Fortran Libraries

References