Dependencies for building THELI
===============================

You need the 'devel' versions of the following packages (either these version numbers, or more recent ones).
Older versions might work but have not been tested:

Qt5.9.6         https://www.qt.io/
cfitsio         https://heasarc.gsfc.nasa.gov/fitsio/   (MUST BE configured with --enable-reentrant, otherwise you can use only one CPU !)
fftw3           http://fftw.org/
GSL v2.5        https://www.gnu.org/software/gsl/
wcslib v7.2     https://www.atnf.csiro.au/people/mcalabre/WCS/
libraw v0.20    https://www.libraw.org/   (older versions are incompatible)
libtiff         https://gitlab.com/libtiff/libtiff

On an Ubuntu 18.04 LTS installation, the following command should resolve all dependencies, and also enable the compilation of 'scamp':

sudo apt install g++ build-essential autotools-dev python python-requests libfftw3-dev libtiff-dev curl libcurl4 libcurl4-gnutls-dev qt5-default qt5-qmake libgsl-dev libatlas-base-dev libblas-dev libplplot-dev libcfitsio-dev libwcstools-dev

Your mileage may vary depending on your individual OS and setup. Should the compilation of THELI fail, then you have to install these packages by hand.

Dependencies for running THELI
==============================

THELI uses a few external packages. The respective binaries and scripts must be present in your $PATH variable.
THELI will check for their presence upon launch and report any misconfigurations.

swarp v2.38              https://github.com/astromatic/swarp
scamp v2.7               https://github.com/astromatic/scamp
Source Extractor v2.19   https://github.com/astromatic/sextractor
python/astropy v4.0      https://www.astropy.org/
astrometry.net v0.79     https://github.com/dstndstn/astrometry.net/releases   (OPTIONAL)

Anaconda / AstroConda users BEWARE
==================================

THELI will likely crash if compiled and linked against libraries provided by Anaconda / AstroConda, because the linker mixed native system libraries with those provided by Anaconda / AstroConda (which were probably built on a different system).

To avoid this, deactivate your Anaconda environment. Solve the THELI dependencies using your native system's repository and / or compile the libraries from their sources. Then follow the installation instructions below. 

Whether the THELI executable will then run with Anaconda activated will depend on your local machine.

Compilation
===========

Parallelization in THELI is based on openMP. Your C++ compiler must support at least openMP 4.5.
For GNU gcc/g++, this is the case for version 6 and later.

Create the 'Makefile' and build it:

> cd $HOME/software/THELI-master/src
> qmake -o Makefile THELI.pro
> make
> make install (copies the binary to /usr/bin/theli and the config files to /usr/share/theli/)
> make clean

To speed up, replace 'make' by 'make -j x", where 'x' is the number of your CPUs 

The 'qmake' executable is part of the Qt5 dependence you have installed in the beginning.


THELIDIR Environment variable (optional)
========================================

There are two cases in which you must set a THELIDIR environment variable:

(1) You did not use 'make install' for a system-wide installation, e.g. if you don't have write permission in /usr

(2) You want to install a newer version locally, next to a system-wide installation.

Let's assume that the master branch of the THELI source package was unpacked in a 'software' folder 
in your home directory:

$HOME/software/THELI-master/

Then you must set the THELIDIR environment variable to this path. For 'bash' you would do

> export THELIDIR=$HOME/software/THELI-master/

Include the line above in your ~/.bashrc to make it permament. 
When launching THELI, Make sure you invoke $HOME/software/THELI-master/src/theli instead of /usr/bin/theli


MacOS C++ compiler and openMP
=============================

THELI has been successfully installed and run on MacOS Mojave. If you use the native Mac clang 
compiler, you must at least install 'libomp'. THELI has not been tested with the native compiler.

Alternatively, try the LLVM clang version from http://releases.llvm.org/download.html. 
This was used to compile THELI on Mojave. However, it turned out that openMP parallelized tasks 
cause THELI to crash when more than one CPU was used. No trouble-shooting attempt was made.

What should work without problems is if you use the GNU g++ compiler, which must be installed separately.

You might have to edit the compiler flags near the end of src/THELI.pro accordingly.
Or, after running the 'qmake -o Makefile THELI.pro' call, edit the Makefile, replace all references to clang++
to the GNU version (or the LLVM clang++ version).

