\( \newcommand\D{\mathrm{d}} \newcommand\E{\mathrm{e}} \newcommand\I{\mathrm{i}} \newcommand\bigOh{\mathcal{O}} \newcommand{\cat}[1]{\mathbf{#1}} \newcommand\curl{\vec{\nabla}\times} \newcommand{\CC}{\mathbb{C}} \newcommand{\NN}{\mathbb{N}} \newcommand{\QQ}{\mathbb{Q}} \newcommand{\RR}{\mathbb{R}} \newcommand{\ZZ}{\mathbb{Z}} \)
UP | HOME

FWEB - Fortran

Table of Contents

1. Overview

FWEB is a literate programming tool for Fortran (and Ratfor and C/C++). It resembles WEB/cweb in its use of "chunks" (sections). Unlike WEB/cweb, it produces LaTeX (instead of plain TeX). One must begin with the specification of the programming language used, and we may change the language freely as we program. For example, we could start with Fortran 90 using & for line continuations by writing:

@n9[-n&]

Three things happen in this:

  • The n9 specifies it is Fortran-90,
  • the [...] indicates additional configuration options,
  • the -n& specifies Fortran will use the & for line continuations.

2. Markup

Sections are indicates by writing @* (a synonym for @*0), subsections are started by writing @*1, subsubsections are started with @*2, and so on. These are weaved into LaTeX \section, \subsection, \subsubsection, etc., counterparts.

Un-named sections are started by writing @ followed by a space, but in practice they typically have their own line.

@ INTRODUCTION.
This is an example of a named section.

@
This is an un-numbered section.

2.1. Code Chunks

Code may be started in an un-named section by writing @a, while named code chunks are started by something like @<Global variables@>=... (just replace the "…" with your code).

2.2. Writing to multiple files

If we want to split up code among several files, we can do so with the @O macro (there is also the @o macro for "locally open a file"). For example:

@c
@* INTRO.
We assume command-line redirection into \.{test.h} (`\.{-=test.h}').

@d A 1 // This will go into \.{test.h}.

@a
@<Header material@>@; // Also goes into \.{test.h}.
@O test.c // Remaining unnamed sections go into \.{test.c}.

@ Header material may be defined as needed throughout the code, but
with this design it will all go into \.{test.h}.

@<Header material@>=

@<Includes@>@;
@<Typedefs@>@;
@<Global variables@>@;

3. References

  • FAQ for FWEB (slightly old)
  • Manual for FWEB

Last Updated 2021-07-30 Fri 08:36.