Alex Barnett: software

Here's a collection of codes I have written for various general or specific scientific applications, generally in Matlab or C/C++, and usually with enough documentation to be useful. Here's my github page. If you use any of these, I'd really appreciate it if you do let me know at

List of codes with links (*.m files are Matlab; otherwise it's C code which compiles under linux):

Some of this material is based upon work supported by the National Science Foundation under Grant Nos. DMS-0507614, 0811005, and 1216656

Other people's codes

Here are some other people's codes that it is useful to host.

Details about some of my codes


Layer Potentials in Two Dimensions. This links against the recent FMMLIB2D library of Greengard-Gimbutas 2011 to compute the self-interation of 2D Helmholtz SLP and DLP on potentials and normal derivatives on a single smooth closed curve. The curve is specified by equally-spaced quadrature nodes in the curve parametrization, the normals at the nodes, and the parametric speed at the nodes. The main content here is applying Alpert corrections in an efficient manner for the S, D, D^T operators. (The codes also apply them to the T operator, but this would only be meaningful when the difference of T_1-T_2 is taken at two wavenumbers.) The code also allows for the interaction of nearest-neighbor copies of the curve to be included, useful for periodic grating scattering problems. Thanks to Mike O'Neil and Zydrunas Gimbutas for pieces of their code.

This is needed if one wants to use FMM + GMRES iteration as a BVP solution technique in MPSpack

Download here the version of 10/17/12, and see README and Installation instructions.


(Obsolete; see MPSpack in particular @evp.solvespectrum method 'ms')

fparamin is Matlab code to find a complete list of local minima of a function of one variable lying in an interval, in the style of fminbnd. The twist is that the function may return a vector of values, all of which are used to find the minima (of the smallest entry of the vector) more reliably. This is designed for the Method of Particular Solutions (MPS), where the minima of a vector of (generalized) singular values are sought. Download gzipped tar file (0.5MB), which contains m-files to place in your matlab path, and documentation (the PDF file). Version 0.9; 14 Aug 2006.


viewer is an interactive scientific data viewer for multiple 1d and 2d real arrays, sampled on regular grids. It provides natural `oscilloscope-like' modes of zoom and pan in 2d, and rotation with free-spinning animation in 3d. Arrays are read from a text file. (One day I plan to have arrays accessed in memory and updated in real time using a forked process - let me know if you hear of existence of similar display library). It was written in 1999-2000, in C and OpenGL/GLUT, and hasn't changed much since. Go to the viewer page.


Efficient computation of Dirichlet eigenfunctions and eigenvalues using the scaling method, originally invented by Vergini and Saraceno, and continued development by myself (see
publications). Includes variety of billiard shapes (stadium, Sinai, generalized Sinai, general polar functions, triangle, L-shape, etc), basis types (plane waves, evanescent waves, irregular Bessel point sources), symmetry classes (non-symmetric, odd-odd, even-even, etc), and tasks (test routines, scaling method, mass integral calculations, inhomogeneous BVP). The executable is command-line driven via a human-readable set of flags (most of which are chosen to have sensible default settings); there is basic documentation and more documentation in code. There are a range of verbosity levels giving diagnostic output. You will need experience to choose basis sets appropriate to the desired billiard shape and wavenumber.

Most output files are in viewer format so can be immediately displayed with the above software package. A set of documented MATLAB M-files is included to perform basic I/O in this format, plot billiard and basis geometries, also driver routines which perform repeated system calls to vergini and collect the result into MATLAB data structures.

The code is in continual development, according to my needs, from 1999-2004. It is in C++ but makes minor use of ++ features, the object-orientation coming from sensible use of C structs and modules. The Makefile has options to sense architecture, and currently compiles on Linux/i386, SGI/IRIX, Sun/Solaris platforms. Math library locations (heavy use of BLAS/LAPACK is made) may need to be adjusted for your machine.

Download version of 9/18/12: gzipped tarball here, or ZIP archive here. Compilation once expanded is done by executing make.


Numerical simulations of photon migration in complex segmented 3D geometries. tfwd stands for time-dependent forward models. The two physical models are

The models conveniently use compatible tissue system and output formats (developed with Jon Stott), and come with an OpenGL viewer which overlays the tissue types, measurement points, and fluence movie, and allows interactive 3D exploration of data in mesh and image forms. (The viewer, tmcv is based on the 3d mode of above viewer). Read the README for more detail, also a reply to Anand's questions.

The complete package, download here (512kB), also provides minimal documentation, example files, and Makefile for compilation on Linux systems. To install, untar then use make with no options. (The slab package below is included; untar it from inside slab directory). tFDimg.c source should be altered for single (default) or double precision.

It stands at version 6 (Monte Carlo v.6 and Finite Difference v.3), Nov 2004.


Fast numerical simulation of time-dependent diffusion (heat equation) in multi-layered 3D slab geometry, either of finite or infinite total thickness. Used for simulation of photon migration in layered tissue such as the cranial surface of the human head. The method actually is applicable to arbitrary depth profiles of absorption and scattering coefficients. The method is described this preprint.

The algorithm is efficient. For example it currently takes of order 0.1 sec to run for relative errors of 1%, a minimum desired measurement time of 100 ps, in a medium of reduced scattering coefficients about 1 per mm. It is still in development, and uses variable timestepping. The package is written as a C library with a MEX interface which allows it to be called from Matlab, or it may be linked and called directly from C or Fortran. Documentation is provided.

Download the package here (170kB). To install, untar then compile within Matlab via mex slab.c. Test with Matlab code test.m (undocumented). Matlab codes fig_*.m can be used to generate the figures from the accompanying paper. The `matlab-free' way to use it is by calling the routine from C or Fortran. An example driver main.c is provided which can be built by the Makefile. Requires BLAS/LAPACK libraries (adjust the makefile for your library locations).

It stands at version 1.5, July 2003, interface updated May 2006.


Interactive viewer for point particles in 3D. Options for solid spheres, points, numbers. Uses OpenGL and GLUT libraries. Useful to modify for your application. Contains crude 1st-order Newtonian dynamics with regularized Coulomb interaction (this routine, evolve() should be replaced by your own). Coordinate arrays are global variables for added crudeness! Download tar file (30kB). (last updated Aug 2004).


Written in 1993 (during a boring summer internship in Manchester, UK) in the now-obsolete IRISGL predecessor to OpenGL, this program reads a human-readable scene description file (*.r) and generates a ray-traced image of the scene. It originally had interactive click and rotate interface to choose view direction with a wireframe model, menus, etc. I haven't ported that aspect to OpenGL. However I have extracted the computational core, which is here: r8_core.c. Compile against math library only. It implements multiple lights, reflection, refraction, bump-mapping, environment-mapping, quasi-random fractal textures (note the marble around the pool; I later discovered these had already been invented by Ken Perlin). The image is output as raw floats and can be read into matlab using imgread.m.

Here are example generated images (the scene files are pool.r and bob.r). They take around 1 minute each to compute: