#! /bin/csh

############################################################################
# install_cfitsio: Uncompress, configure, compile, test and install cfitsio
#                  library on Linux and Macintosh OS X systems.
#
# Usage: ./install_cfitsio
############################################################################

if (`uname` == 'Linux') then
  set dir = "`pwd`/linux"
else if (`uname` == 'Darwin') then
  set dir = "`pwd`/macosx"
  setenv CFLAGS "-O -O2 -DIBMR2Fortran"
else
  echo ""
  echo "ERROR: Unsupported platform"
  echo "       This script is designed to install netcdf only for CORHEL-2"
  echo ""
  exit 1
endif

tar zxvf cfitsio2510.tar.gz

pushd cfitsio > /dev/null
./configure --prefix=$dir
make

if (`uname` == 'Darwin') then
  make shared
endif

make testprog
./testprog > testprog.lis
diff testprog.lis testprog.out
cmp testprog.fit testprog.std

make install
mv $dir/lib/* $dir
popd > /dev/null

rm -rf cfitsio
rm -rf $dir/include
rm -rf $dir/lib

exit 0
