Installing cfitsio & wcslib

cfitsio is the closest you can get to the pixels in an astronomical image while remaining faithful to the FITS standard, it is written by the author of the FITS standard (3.0), William Pence, and is regularly updated. Setting the definitions for all other software packages using FITS images. wcslib is also written and maintained by one of the authors of the World Coordiante System (WCS) definition in the FITS standard, Mark Calabretta. Unless you want to define a new standard, these are the most fundamental software to deal with FITS images. To install wcslib you will need to have the libraries of cfitsio and pgplot (a plotting library for C) already installed. So I will explain how to install these two first and finally wcslib.

The steps I am explaining here are how I have installed it on a 64bit Scientific Linux (a Red hat based GNU/linux distribution). The $ and # in the begining of the code lines is the last character of the shell prompt, you don't have to type them! The $ appears on those commands where you can run as your own user and the # are the ones you have to run as root.

Notice:
I have written these notes primarily for myself and this page surves me as a notebook for my personal software installs. I am only sharing this to help other people who are taking the same steps as me and, like me, are not a linux professional. I therefore cannot guarantee that these steps will work on your system or that they will not cause any data, software or hardware loss and damage. So please follow these steps with your own responsibility. I can just say that everything that is listed here was tested on my own 64bit Scientific Linux and has worked without any problem and that I regularly re-check and update this page every time I install a new Scientific Linux (I regularly do to keep things tidy!).

 

Setting path
Both cfitsio and wcslib and lots of other libraries will install their shared libraries and headers in /usr/local/. To notify the system to look out for these files you have to put these three lines in your startup (~/.bashrc/) file. Open your startup file for editing with:
     $ gedit ~/.bashrc
Then add these three lines, remove all spaces that might be made in gedit.
     export PATH=/usr/local/bin:$PATH
     export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
     export INCLUDE=/usr/local/include:$INCLUDE

 

cfitsio
The installation of cfitsio is very easy. In order to understand every step it is strongly recommended that you read the manual. In summary, after you download the latest version, go into the downloaded directory and unpack it:
     $ tar -xzf cfitsio_latest.tar.gz
Go into the unpacked directory and run:
     $ ./configure --enable-sse2 --prefix=/usr/local --enable-reentrant
The first flag (those that start with a --) is for increasing the reading and writing speed and only works for a 64 bit systems, if you are on a 32 bit system, don't include it. The second one says where to put the final compiled libraries and the last one is if you want to access the fits files in a multithread manner.
After configure finishes successfully, run $ make and as root run # make install.

In order to test your installation, you can take these steps:
     $ make testprog
     $ ./testprog > testprog.lis
     $ diff testprog.lis testprog.out
     $ cmp testprog.fit testprog.std
If the last two commands give no outputs you are fine to go.

After you have written your code, which uses the cfitsio library, in order to compile it, run gcc in the following manner:
     $ gcc -o temp temp.c -O2 -lcfitsio -lm -pthread
In case you don't choose the parallel processing option (multithreading) when configuring the library, you can remove the last gcc option. Also, in case you didn't choose the first option on configuring the library (your system is 32 bit), remove the -O2 option.

 

wcslib
wcslib can make publising quality plots, but to do that it needs PGPLOT which is not hard to install, only a little time consuming. Fortunately, if making such plots is not the purpose you are installing wcslib, you don't need PGPLOT to be installed. If you do, I have included the explanations to install it below. Installing wcslib is really easy! Download the compressed file and unpack it. Go into the unpacked directory and run the following codes. If you have PGPLOT don't run the first command.
     $ ./configure --without-pgplot
     $ gmake
     $ gmake check
     $ su
     # gmake install
In case you use wcslib there is just one small complication when compiling and linking your code.

  • Compiling: Include the wcslib header files in your source code like this (note that this # is not the sign used for shell scripts):
    #include <wcslib/HEADERFILE.h>
    Unlike cfitsio, wcslib has many header files and some have the same names as other similar packages. So to install, wcslib will put all its header files in a /usr/local/include/wcslib directory, not in the standard /usr/local/include/. So you have to tell the compiler to look into that directory to find the HEADERFILE.h that you want.
  • Linking:In order to tell the computer where to look for the libwcs libraries, you have to add the installation directory to LD_LIBRARY_PATH parameter (the same way explained above for PGPLOT). So add this line to your .bashrc file (as explained in PGPLOT's installation procedure):
    LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/; export LD_LIBRARY_PATH
    This is also useful for you if you want to install the GNU Scientific Library (gsl).

 

PGPLOT
PGPLOT is a package for making plots in C. It is very old (the most recent version was released early 2001!), but remains one of the main packages for plotting directly in C. wcslib uses this package to make plots if you want therfore it is necessary if you want to have a complete install of wcslib. If you are interested you can also use it for your own purposes. I would propose just getting your output data and plotting them with PGFPlots in LaTeX for your paper or report, you can even write a C code to generate the PGFPlots LaTeX commands if you like ;-). If you want your plotting codes in between your C program though, PGPLOT is currently one of your best options. But to be honest I find outputing my plotting data in a text file much easier and then plotting immediately with a very simple python (matplotlib) command called by C's system() function. Lets get back to PGPLOT for the sake of wcslib, installing it is a little tricky (mainly because it is so old!).

After you download the source, unpack it like above. I will assume the directory you have unpacked it to is PGPLOT, most probably it is: /home/YOURID/Downloads/pgplot/.
open the drivers.list file:
     $ gedit drivers.list
Remove the ! for these lines and save the file:
           PSDRIV 1 /PS
           PSDRIV 2 /VPS
           PSDRIV 3 /CPS
           PSDRIV 4 /VCPS
           XWDRIV 1 /XWINDOW
           XWDRIV 2 /XSERVE
Don't choose GIF or VGIF, there is a problem in their codes.

Open the PGPLOT/sys_linux/g77_gcc.conf file:
     $ gedit PGPLOT/sys_linux/g77_gcc.conf
change the line saying: FCOMPL="g77" to FCOMPL="gfortran", and save it.. This is a very important step during the compilation of the code if you are in linux.

You now have to create a folder in /usr/local, don't forget to replace PGPLOT with your unpacked address:
     $ su
     # mkdir /usr/local/pgplot
     # cd /usr/local/pgplot
     # cp PGPLOT/drivers.list ./

To make the make file, type the following command, again don't forget to correct PGPLOT:
     # PGPLOT/makemake PGPLOT linux g77_gcc
It should finish by saying: Determining object file dependencies.

You done the hard part! The rest is easy: run these three commands in order:
     # make
     # make clean
     # make cpg

Finally you have to place the position of this directory you just made into LD_LIBRARY_PATH and define the environment variable PGPLOT_DIR. To do that, you have to edit your .bashrc file:
     $ cd ~
     $ gedit .bashrc
Copy these two lines into the text editor and save it:
PGPLOT_DIR="/usr/local/pgplot/"; export PGPLOT_DIR
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/pgplot/; export LD_LIBRARY_PATH
You need to log out and log back in again so these definitions take effect.

After you logged back in, you want to see the result of all this labor, right? Tim Pearson has done that for you, create a temporary folder in your home directory and copy all the demonstration files in it:
     $ cd ~
     $ mkdir temp
     $ cd temp
     $ cp /usr/local/pgplot/pgdemo* ./
     $ ls
You will see a lot of pgdemo## files, where ## is a number. In order to execute them type the following command and drink your coffee while looking at all the beautiful plots! You are now ready to create your own ;-).
     $ ./pgdemo##

 

Comments and suggestions:
You are now ready to do your groundbreaking research with all these great and fundamental tools. I hope these explanations were helpful. If you find any problems in the explanations, please contact me and tell me how to correct them, thank you.

 

Update History:
   Updated on August 7th, 2014.
   Created on July 15th, 2013.

Tohoku University Astronomical Institute, 6-3 Aramaki, Aoba-ku, Sendai, Japan, 980-8578
    akhlaghi :a:t: astr.tohoku.ac.jp, Office: Physics A; 838, +81-80-3335-9474