SPEX X-ray spectral fitting package

This dataset contains compiled versions of the SPEX X-ray spectral fitting package and the source code.

Table of contents:

  • Running a Linux or Mac universal binary
  • Graphical install of SPEX on Mac OS
  • Running an old version of SPEX using Docker
  • SPEX Compilation Guide

Running a Linux or Mac universal binary

This directory contains a statically linked SPEX installation for a 64-bit system, which should work on most linux distributions with GLIBC version >=2.19 and Mac systems >=10.11. The installation instructions for Linux and Mac are the same.

Installation instructions

  1. Download spex-3.05.00-Linux-amd64.tar.gz or spex-3.05.00-MacOS.tar.gz from this directory.

  2. Unpack the tar file in the destination directory (for example /usr/local/):

    tar xvfz spex-3.05.00-Linux-amd64.tar.gz

    The tar file will create a directory called SPEX-3.05.00-Linux in which the program will be installed.

  3. Set the environment variable SPEX90 to the installation directory (for example /usr/local/SPEX-3.05.00-Linux):

    export SPEX90=/usr/local/SPEX-3.05.00-Linux (bash shell)
    setenv SPEX90 /usr/local/SPEX-3.05.00-Linux (C-type shell)
  4. Source the script provided by the distribution:

    source $SPEX90/spexdist.sh (bash shell)
    source $SPEX90/spexdist.csh (C-type shell)
  5. Remove the tar file:

    rm SPEX-3.05.00-Linux-amd64.tar.gz

If the Linux universal binary does not work, then please try the Docker option below.

Graphical install of SPEX on Mac OS

We also provide a Mac OS installer for SPEX. To install, download the SPEX-3.05.00-MacOS.dmg file and open the package file inside the disk image. The graphical interface will guide you through the installation process.

Running SPEX using Docker

SPEX is written mostly in Fortran 90 and depends on a few system libraries. This makes it difficult to provide a few binary versions that will continue to run on multiple platforms over many years. Therefore, we have also created a Docker image for SPEX that can be run on the Docker platform, which is available for Linux, Mac OS and Windows.

Step 1: Download and install Docker on your computer

To run a Docker image, please install Docker on your computer. See the Docker website for details and look for the Docker Engine community edition. Once you have downloaded and installed Docker, you can continue with this tutorial.

Step 2: Download the SPEX docker image from Zenodo

The SPEX Docker image is available on this Zenodo page as a tar.gz file. Please download the file called spex-[version]-docker.tar.gz, for example:


Step 3: Import the SPEX image into Docker

Before you can run the docker file, it should be imported into the docker system. This can be done on the command line:

    user@linux:~> docker load -i spex-3.05.00-docker.tar.gz

The image will be named spexxray/spex with the tag 3.05.00 and can be found with the command:

    user@linux:~> docker images
    spexxray/spex  3.05.00  0a0a0a0a0a0   1 minute ago   311MB

Step 4: Run SPEX on Docker

Using the docker run command, the image can be executed and SPEX can be run in a so-called container. To enjoy all the capabilities of SPEX, two things need to be arranged in the docker run command: access to local directories and a graphical X11 connection. To arrange this, additional flags need to be specified on the command line.

Mounting local directories to the container

If you would like to mount your own home directory into the SPEX container such that you can use some spo and res files there or save the output files, then you need the following flags:

-e LOCAL_USER_ID=`id -u $USER`
-v /home/myusername:/home/user

The first flag arranges that the user in the container will have the same user ID as you. This will allow you to read and write to your home directory from within the container.

The second flag arranges that your true local home directory called /home/myusername is mounted to /home/user inside the SPEX container.

MAC users: Please note that on OSX your home directory is in /Users/myusername.

Arranging the X11 connection

To make sure PGPLOT can connect to the X11 server on the host, we need to make a few connections from the container to the host machine. This is done with the following flags:

-v /tmp/.X11-unix:/tmp/.X11-unix

The first flag sets the DISPLAY variable inside the container to the DISPLAY variable of the host machine. The second flag mounts the X11 temporary directory of the host to the same directory inside the container.

MAC users: To use X11 on Mac, you need to install XQuartz (or a similar X11 server) and set it to 'Allow connections from network clients' in the XQuartz settings. In addition, the X server should be set to allow incoming connections from localhost on the command line:

    user@macos:~> xhost +

Then the DISPLAY variable on the docker run line should be set to host.docker.internal:0

The complete docker run command

The full run commands for docker now look like below, where -w means that the container will start in working directory /home/user.

For Linux:

docker run -it \
           -e DISPLAY=$DISPLAY \
           -e LOCAL_USER_ID=`id -u $USER` \
           -v /tmp/.X11-unix:/tmp/.X11-unix \
           -v /home/myusername:/home/user \
           -w /home/user \

For Mac:

docker run -it \
           -e DISPLAY=host.docker.internal:0 \
           -e LOCAL_USER_ID=`id -u $USER` \
           -v /tmp/.X11-unix:/tmp/.X11-unix \
           -v /Users/myusername:/home/user \
           -w /home/user \

The docker run command above will provide you with a prompt that will allow you to run spex:

user@linux:~> docker run -it -e DISPLAY=$DISPLAY -e LOCAL_USER_ID=`id -u $USER` \ 
-v /tmp/.X11-unix:/tmp/.X11-unix -v /home/myusername:/home/user -w /home/user \

Welcome to the SPEX Docker Container!
Just type 'spex' to start the program.

In this environment, you can just run spex or trafo:

user@0922f2e4ff85:~> spex
 Welcome user to SPEX version 3.05.00

 NEW in this version of SPEX:
11-06-2018 Added Ext_Rate column to new spo files
18-12-2018 SPEX is now using the GPL license
18-12-2018 Release of version 3.05.00


More information about using SPEX can be found in the SPEX reference manual, which is also available in this Zenodo dataset.

SPEX Compilation Guide

Table of Contents:

  • Getting started
  • Library dependencies
  • MacOS instructions
  • General compilation instructions
  • Optional features
  • Create install packages

Getting started

The SPEX source code can be compiled using the multi-platform Cmake build system. See http://www.cmake.org/ for more information and downloads, or check the package manager of your Linux distribution. The SPEX install needs CMake version 3.0 or higher.

Since SPEX is programmed mostly in Fortran 90, it is recommended to use a recent Fortran compiler. SPEX has been tested with GFortran (version 4 and above) and the Intel Fortran Compiler.

This Zenodo contains a tar.bz2 file containing the source code of SPEX: spex-3.05.00-Source.tar.bz2. Unpack it in a convenient directory:

    unix:~/Software> tar xvfj spex-3.05.00-Source.tar.bz2

Library dependencies

SPEX depends on a few external libraries to function. For some of those, the library source code has been included in the SPEX source code package. By default, CMake will look for system libraries to link to. If they are not there, then the version in the source package will be used.

The following libraries and packages are required to compile SPEX:

  • CMake
  • X11
  • Readline
  • CFITSIO (*)
  • BLAS (*)
  • LAPACK (*)
  • PGPLOT (*)

(*) The SPEX source tree also contains the library if necessary.

All these libraries are commonly available in Linux distributions, so please read the documentation of your distribution to find out how to install these libraries. Please note that some distributions require you to also install the 'development' package of a library to be able to use them during compilation. In the Debian repository, for example, the development package of readline is called 'libreadline-dev'.

Below, we list some library-specific comments that can be helpful in case of problems.


Note for Mac OSX users: The OSX readline library is NOT compatible with the GNU readline library. You need to compile your own readline library from source or find a GNU readline library elsewhere on your system to link to. Compilation may work in, for example, a MacPorts environment, although this has not been tested. The official Mac version of SPEX statically links to a compiled version of readline downloaded from:



The SPEX source tree contains an old fortran version of fitsio, which is sufficient for the vast majority of applications. However, in exceptional cases, the old library cannot handle very large fits files. In those cases, it is better to link to a system CFITSIO library.


Some of the SPEX models depend heavily on the BLAS and LAPACK linear algebra packages. The default routines are available in the SPEX source tree, but compiling those will not provide the best performance. The performance improves substantially if an optimized BLAS or LAPACK library is used. There are two tested options:

  • Intel Math Kernel Library (MKL)
  • OpenBLAS

When compiling with the Intel Fortran compiler, using MKL is quite obvious. To link the MKL library, add the following option to the cmake command:

  cmake . -DMKL=YES

If MKL is not set, cmake will look for other options, like OpenBLAS, if they are installed on your machine. If nothing is found, the non-optimized code in the SPEX source tree is used. On Mac, CMake could find the MacOS Accelerator framework.

MacOS instructions

The compilation of SPEX on MacOS is slightly more demanding. SPEX can run natively on MacOS (without ports), but then it needs a few pre-installed programs:

General Compilation Instructions

When all library dependencies are installed, the compilation process can begin. Execute cmake in the root directory of the SPEX source tree, where CMakeLists.txt is located (mind the dot):

unix:~/Software/SPEX-3.05.00-Source> cmake .

If no errors occured and all libraries were found, then type 'make':

unix:~/Software/SPEX-3.05.00-Source> make

When the program needs to be installed system wide, then execute:

unix:~/Software/SPEX-3.05.00-Source> sudo make install

The program will be installed to /opt/spex by default. Usually, administrator rights are necessary to copy the files to the right location.

Optional features

There are several options that can be passed to CMake to influence the build process through the -D operator. Of course, all options can be combined in a single cmake call. See the cmake documentation and the CMakeLists.txt file for details.

Compiler selection

Select a different fortran compiler:

   unix:~/Software/SPEX-3.05.00-Source> cmake . -DCMAKE_Fortran_COMPILER=ifort

Install prefix

Install SPEX at a different location in the 'make install' step:

   unix:~/Software/SPEX-3.05.00-Source> cmake . -DCMAKE_INSTALL_PREFIX=/home/user/software

Force use of SPEX libraries

The use of the SPEX libraries in the source tree can be forced:

   unix:~/Software/SPEX-3.05.00-Source> cmake . -DCFITSIO=YES -DPGPLOT=YES

The command above will compile these libraries from the SPEX source tree. See the CMakeLists.txt file for more options.

Create install packages

CMake is shipped with a program to create install packages, called CPack. Install packages can be generated by simply calling 'cpack' after the 'make' has finished. Please see the CPack documentation and CMakeLists.txt for packageing options.