Computer programs
»Where shall I begin, please your Majesty?» he asked »Begin at the beginning,» the King said, gravely, »and go on till you come to the end: then stop.»
– Lewis Carroll, Alice's Adventures in Wonderland.
For quite some time now, I have been thinking about publicly releasing the source code for a set of the programs I have written over the years, so here we go. Please help yourself to whatever you find useful at this site.
Most of the programs you will find at this site are written in CWEB, which is a dialect of literate programming, or ANSI/ISO-conformant plain C, for the simple reason that I am a fan of standards. In particular, by using highly standardized and non-proprietary languages such as plain C or even Fortran, I find that my daily work becomes easier as I can benefit from things that have been developed earlier, either by myself or by someone else.
All code that you will find at this site has been verified to pass compilation using GCC (C/CWEB) or G77 (Fortran) with supplied -Wall -pedantic (strict) options. This implies that the code should pass compilation successfully using virtually any C or Fortran compiler. However, should you find that any code you downloaded from jonsson.eu does not pass strict compilation mode of your specific compiler, please let me know as I will be genuinely curious to know what failed.
Selected code
BoxCount, Revision 1.5
[25/10/2006]
The BoxCount computer program
calculates box-counting estimates of the fractal dimension of curves in
the two-dimensional plane. In the box-counting estimate to the fractal
dimension of a curve in the domain
{x, y : xmin ≤ x ≤ xmax, ymin ≤ y ≤ ymax},
a grid of squares, each of horizontal dimension
(xmax - xmin) / 2m
and vertical dimension
(ymax - ymin) / 2m,
is superimposed onto the graph for integer numbers m.
By counting the total number of such squares Nm
needed to cover the entire graph at a given m (hence the term
»box counting»), an estimate Dm to
the fractal dimension D (or Hausdorff dimension) is obtained as
Dm = ln(Nm)/ln(2m).
This procedure may be repeated many times, with
Dm → D as
m→∞ for real fractal sets. However, for finite-depth
fractals (as generated by a computer), some limit on m is necessary
in order to prevent trivial convergence towards
Dm → 1.
In addition to mere numerical calculation, the
BoxCount program also generates graphs
of the box distributions, in form of
MetaPost
code which can be post-processed by other programs.
More...
MagBragg, Revision 1.43
[10/01/2007]
The MagBragg computer program
calculates reflection and transmission spectra of nonlinear magneto-optical
Bragg gratings, in a stratified geometry where the material parameters vary
only in one Cartesian coordinate.
The MagBragg program also
simulates the propagation of the electromagnetic field of an optical wave
as it traverses a magneto-optical Bragg grating, giving the intra-grating
spatial distribution of the optical fields in linear as well as nonlinear
optical regimes.
The MagBragg program forms the core behind the semi-analytical algorithm
that in 2006 was published in
Phys. Rev. Lett. 96,
063902 (2006).
More...
Poincare, Revision 1.21
[10/08/2005]
The Poincare computer program
creates topographic maps of Stokes parameters, visualized as trajectories
on the Poincare sphere.
The Poincare program generates
MetaPost source code as
output, to be compiled into
PostScript or
Encapsulated
PostScript, using
John Hobby's
MetaPost compiler or anything that understands the MetaPost syntax.
I have used the Poincare program extensively in my research career, and
the program has been continuously updated for almost nine years by now,
in fact the oldest program I keep active in my stock.
This program was used in the generation of the image that made it to the
front page of issue 4 of J. Opt.
A: Pure Appl. Opt., Vol. 2 (July 2000).
More...
EpsImg, Revision 1.6
[21/02/2004]
Given a matrix of floating-point numbers stored in a regular ASCII text file,
the EpsImg program creates a
grey-scale Encapsulated PostScript (EPS) image of the matrix using its
elements as specification of the brightness of the corresponding pixels
in the image.
Of course, there are other ways of generating Encapsulated PostScript images of sampled of simulated data, as for example using the image() function of MATLAB. However, an advantage with using a stand-alone program is that it is easily incorporated in scripts for batch processing. In addition, the EpsImg program is provided free of charge.
The EpsImg program is written in the CWEB programming language; however, as it is targeted towards generation of Encapsulated PostScript, the main entry for this program is under the PostScript programs section. More...
DvLabel, Revision 1.6
[10/08/2005]
The DvLabel computer program
generates plain TeX source code for
typesetting of labels for digital video tapes (DV format, typically used
for hand-held video camera recorders).
The DvLabel program is primarily
designed to run in interactive mode, but via command-line supplied
parameters it also supports batch-mode operation.
I got the idea of creating this program from the
audio-tape.ps
PostScript code by Jamie Zawinski.
The audio-tape.ps code is a splendid example of how one can
write a simple PostScript program with the help of a regular ASCII editor,
and by sending the PostScript program to the printer one gets a neat
printout to be used for tape cassette labels, DAT, or video tapes.
However, whenever one has a new cassette to be labeled, one has to edit
the PostScript source, and for a rookie on PostScript programming this
task is for sure somewhat inconvenient. (Believe me.)
The DvLabel program is written
in CWEB.
More...
Unclassifiable programs
The Futhark (Runic alphabet) on a HP-42S
calculator [1990]
The FUTH program is written for the
HP-42s
calculator and displays strings of characters from the futhark (used in
historic Scandinavia, also denoted
Runic alphabet)
as supplied by the user via a two-level menu system.
The input characters are in the user interface of the program listed as we
would read and pronounce them today.
More...