Installation
foresight is a Fortran library (libforesight.a, use foresight) and a command line tool (foresight) that runs gnuplot scripts. There are three ways to install them:
- the one-line installer;
- a build with FoBiS;
- a build with fpm.
After installing, check the install and use the library.
Requirements
| Needed | Notes | |
|---|---|---|
| Fortran compiler | Fortran 2018 | Tested in CI: gfortran 16.2, nvfortran 26.9, Intel ifx 2026.2. nvfortran 26.9 miscompiles some valid Fortran; foresight works around what it meets (#3). |
| Operating system | Linux, or another POSIX system | Tested in CI on Linux. foresight calls three POSIX functions through bind(C): rename, nanosleep, popen. macOS is POSIX but not tested in CI. |
| Windows | through WSL 2 | WSL runs Linux, and foresight with it. Native Windows (MSVC or MinGW toolchains) is not supported: nanosleep and popen are not standard there. A page or PDF written in WSL opens in any Windows browser or viewer. |
| Build system | one of FoBiS 3.8+ or fpm | The one-line installer installs FoBiS itself when it is missing (in a private environment, with Python 3.11+). No CMake or make build is shipped. |
| Dependencies | none to install | PENF, BeFoR64, FACE and StringiFor are fetched by FoBiS or fpm, and bundled in the release tarball. |
What foresight's outputs need:
| To... | You need |
|---|---|
view an interactive page (.html) or an SVG | any browser; the page is one self-contained file |
| write a PDF | nothing: foresight writes PDF itself, with its fonts compiled in |
| view or print a PDF | any PDF viewer |
| use TeX math in labels | nothing: foresight lays it out and draws it (TeX math) |
include a cairolatex figure | LaTeX with the graphicx and color packages (LaTeX labels) |
| build the example paper | LuaLaTeX or Tectonic (scripts/build_paper.sh) |
| run the viewer's tests, build these docs | Node.js |
| compare pages with gnuplot (fidelity harness) | gnuplot 6.0 and a headless Chrome |
One-line install
curl -fsSL https://github.com/szaghi/foresight/releases/latest/download/install.sh | bashThis installs the latest release into ~/.local, with the build system and compiler you choose.
- Build system:
--build fobis|fpm; a menu asks if you don't say. The fpm build also installs theforesightcommand; the fobis build installs the library only. - Compiler:
--fc NAME, or--gnu,--intel,--nvidia;$FC, else gfortran, by default. - One install per compiler:
lib/foresight/<compiler>-<version>/andinclude/foresight/<compiler>-<version>/. - pkg-config:
foresight.pcin~/.local/lib/pkgconfig.
Pass options after bash -s --, for example:
curl -fsSL https://github.com/szaghi/foresight/releases/latest/download/install.sh | bash -s -- --build fpm --gnu --prefix /opt/foresight--help lists every option, --dry-run shows what would be done, --uninstall removes the install. The installer is FoBiS's (one-line installer). Then compile against the install through pkg-config:
export PKG_CONFIG_PATH=$HOME/.local/lib/pkgconfig:$PKG_CONFIG_PATH
gfortran $(pkg-config --cflags foresight) my_program.f90 $(pkg-config --libs foresight) -o my_programWith FoBiS
Build from the sources
git clone https://github.com/szaghi/foresight
cd foresight
fobis fetch # PENF, BeFoR64, FACE, StringiFor into src/third_party
fobis build --mode foresight-static-gnu # the library: lib/libforesight.a, its modules in lib/mod
fobis build --mode foresight-gnu # the command line tool: bin/foresightThen compile your program against the modules and the library:
gfortran -I foresight/lib/mod my_program.f90 foresight/lib/libforesight.a -o my_programfobis build --lmodes lists every mode:
| Mode | Builds |
|---|---|
foresight-static-gnu, foresight-static-intel | the static library libforesight.a in lib/ |
foresight-gnu, foresight-intel | the foresight command line tool in bin/ |
tests-gnu, tests-intel, tests-nvf | the test programs in exe/ |
tests-gnu-debug, tests-intel-debug, tests-nvf-debug | the tests with runtime checks and floating point traps |
As a FoBiS dependency
Declare foresight and PENF, its only dependency at compile time, in your project's fobos:
[dependencies]
deps_dir = src/third_party
PENF = https://github.com/szaghi/PENF
foresight = https://github.com/szaghi/foresight :: tag=v0.20.0fobis fetch # clone the sources
fobis build # the foresight modules your program uses are compiled with itWith the default use=sources, the foresight modules are compiled as part of your build. use=fobos does not work yet: FoBiS builds foresight with its own fobos but does not fetch foresight's dependencies inside it.
With fpm
Build from the sources
git clone https://github.com/szaghi/foresight
cd foresight
fpm build --profile release # the library and the command line tool
fpm run foresight -- script.gp # run a gnuplot script
fpm install --prefix ~/.local # bin/foresight, the library and its modulesfpm fetches the dependencies itself. fpm test runs the test programs listed in fpm.toml.
As an fpm dependency
In your project's fpm.toml:
[dependencies]
foresight = { git = "https://github.com/szaghi/foresight", tag = "v0.20.0" }use foresight in your sources; fpm build compiles foresight and its dependencies with your project.
Check the install
The command line tool runs gnuplot commands without a script:
foresight -e "set terminal dumb size 60,16; plot sin(x)" # a plot as text, in the terminal
foresight -e "plot sin(x), cos(x)" -o check.html # an interactive page: open it in a browserThe library, with the smallest program:
program check
use foresight, only : figure_object, R8P
implicit none
type(figure_object) :: fig
call fig%plot([1.0_R8P, 2.0_R8P, 3.0_R8P], [1.0_R8P, 4.0_R8P, 9.0_R8P], title='y = x^2')
call fig%save('check.svg')
endprogram checkgfortran $(pkg-config --cflags foresight) check.f90 $(pkg-config --libs foresight) -o check && ./checkA check.svg with three points joined by lines means the library works.
Use the library
A complete program: two panels, three line styles, a log axis, and four output files. It is docs/examples/src/qs_library.f90, compiled and run with the documentation.
The module
use foresight, only : figure_info, figure_object, I4P, R8P
implicit none
type(figure_object) :: fig ! the figure: its panels, their settings and series
type(figure_info) :: meta ! what save tells about a written file
real(R8P), allocatable :: t(:) ! time [s]
real(R8P), allocatable :: u(:) ! displacement [mm]
real(R8P), allocatable :: env(:) ! its envelope
integer(I4P) :: iuse foresight gives the whole public API and the PENF kinds: I4P for integers, R8P for reals (double precision). figure_object is a figure; it starts with gnuplot's defaults (600 x 480 px, autoscaled axes, the key top right).
The data
t = [(0.05_R8P * i, i = 0, 200)]
u = 4.0_R8P * exp(-0.3_R8P * t) * cos(2.0_R8P * t)
env = 4.0_R8P * exp(-0.3_R8P * t)Series are plain arrays of real(R8P), x and y of the same size. The figure copies them, so they can change after the call. A NaN is a gap in the line, not an error.
The figure
call fig%init(width=760_I4P, height=380_I4P) ! a new figure, 760 x 380 px
call fig%set_multiplot(rows=1_I4P, cols=2_I4P, title='A damped oscillator')
call fig%set_title('displacement')
call fig%set_xlabel('time [s]')
call fig%set_ylabel('u [mm]')
call fig%set_grid ! grid lines at the major ticks
call fig%set_key(position='top right', box=.true.)Every method is named after the gnuplot command it does: set_title is set title, set_grid is set grid, and so on. The gnuplot reference documents the library too. set_multiplot lays out a grid of panels; the settings that follow apply to the current panel.
The series
call fig%plot(t, u, title='u(t)', lw=2.0_R8P) ! a line, 2 px wide
call fig%plot(t, env, title='envelope', dt=2_I4P, lc='gray') ! dashed, gray
call fig%plot(t(::20), u(::20), title='samples', with='points', pt=7_I4P, ps=0.8_R8P) ! filled circlesplot adds one series to the current panel. Its optional arguments are gnuplot's item options:
| Argument | gnuplot | Here |
|---|---|---|
title | title | the key entry; an empty title keeps the series out of the key |
with | with | lines (the default), points, linespoints, boxes, filledcurves, yerrorbars, image, ... |
lw, dt | lw, dt | line width [px], dash type (1 solid, 2-5 dashed) |
lc | lc | a color: a name ('gray') or '#rrggbb' |
pt, ps | pt, ps | point type (7: filled circle) and size |
Every option, styles and series kinds included, is in the Fortran Library reference.
A second panel
call fig%next_panel ! the second panel: the settings carry over, as in gnuplot
call fig%set_title('envelope, on a log axis')
call fig%set_ylabel('|u| [mm]')
call fig%set_logscale('y')
call fig%set_format('10^{%L}', axes='y') ! powers of ten as superscripts...
call fig%set_enhanced ! ...read as gnuplot's enhanced text
call fig%plot(t, env, title='4 e^{-0.3 t}', lw=2.0_R8P)next_panel moves to the next cell of the multiplot, carrying the settings over, as gnuplot does. set_enhanced reads texts as gnuplot's enhanced text: 10^{%L} writes the powers of ten as superscripts. A text between $ would be TeX math.
Saving
call fig%save('qs_library.html') ! the interactive page: zoom, pan, hover
call fig%save('qs_library.svg') ! the same drawing, a static image
call fig%save('qs_library.pdf', info=meta) ! a PDF, its fonts embedded
call fig%save('qs_library.txt') ! text, as gnuplot's dumb terminal
print '(A,F0.1,A,F0.1,A)', 'wrote '//meta%file//', ', meta%width_cm, ' x ', meta%height_cm, ' cm'
print '(A)', 'its alternative text: '//meta%alt$ qs_library
wrote qs_library.pdf, 20.1 x 10.1 cm
its alternative text: Figure: A damped oscillator. Panel 1, plot: displacement. x axis: time [s]. y axis: u [mm]. Series: u(t), envelope, samples. Panel 2, plot: envelope, on a log axis. x axis: time [s]. y axis: |u| [mm]. Series: 4 e-0.3 t.save picks the format from the file name:
.html: the interactive page above (wheel to zoom, drag to pan,ato reset);.svg: a static image;.pdf: a PDF;.tex: a LaTeX picture;.txt: text;-: text on the standard output.
info=meta returns what a document needs: the file, its size in cm, an alternative text and the caption (F1).
Then
- Path A: a first plot, styles, axes, then the same plots from a script.
- Scripts from Fortran:
script_objectruns gnuplot commands from your program. - Figures for a paper: PDF at its printed size, fonts, LaTeX labels.
Run the tests
For contributors, from the repository root, where the tests find their reference files (src/tests/goldens/):
fobis build --mode tests-gnu-debug
bash scripts/run_tests.sh # the Fortran tests, byte-exact golden files included
fobis rule --ex test-js # the viewer's tick rules (needs Node.js)