#!/bin/bash
#
# ./compilation.sh >& compilation_01.log &
#

source /opt/modules/init/bash
module load intel/2013sp1
#module load intel/13.0.1
module load hdf5/1.8.11
module load szip/2.1
module load netcdf/4.1.3

set -xuve
date

TOOL=cmor-2.7.1-specs_update
COMPILER=intel13
LOCAL=$(pwd)
DST=$( echo ${LOCAL}/../.. )
DIR_UUID=/scratch/cfu/opt/uuid-1.6.2/intel-13
DIR_UDUNITS=/scratch/cfu/opt/udunits-2.1.24/intel-13
#DIR_NETCDF=/share/data/cfu/common/apps/netcdf-4.1.3 #/liblib/.libs was this one!
#DIR_NETCDF=/share/libs/netcdf/4.1.3
#DIR_UUID=/scratch/cfu/opt/uuid-1.6.2/$COMPILER
#DIR_UDUNITS=/scratch/cfu/opt/udunits-2.1.24/$COMPILER
#DIR_NETCDF=/scratch/cfu/opt/netcdf-4.1.3/$COMPILER
#DIR_NETCDF=/scratch/cfu/opt2/netcdf-4.1.3/intel
DIR_NETCDF=/scratch/cfu/opt/netcdf-4.1.3/$COMPILER #latest working version
#DIR_NETCDF=/share/libs/netcdf/4.2.1.1/ics-2012.0.032/hdf5-1.8.9/pnetcdf-1.3/openmpi-1.6
#DIR_NETCDF=/scratch/cfu/opt/netcdf-4.1.3/intel12 working!!!!
#DIR_NETCDF=/scratch/cfu/opt/netcdf-3.6.3/intel12
#DIR_HDF5=/scratch/cfu/opt/hdf5-1.8.8/$COMPILER #latest working version
# DIR_HDF5=/share/libs/hdf5/1.8.10 was this one!
#DIR_HDF5=/scratch/cfu/opt/hdf5-1.8.10
DIR_HDF5=/scratch/cfu/opt/hdf5-1.8.8
#DIR_HDF5=/scratch/cfu/opt2/hdf5-1.8.10/intel

export CC=icc
export CFLAGS='-fpic -O3 -ip -no-prec-div -static'
#export CFLAGS='-O3 -ip -no-prec-div -static'
#export CFLAGS='-O3 -xT -ip -no-prec-div -static'

export CPP='icc -E'
export CPPFLAGS='-DpgiFortran'

export CXX=icpc
export CXXFLAGS='-O3 -ip -no-prec-div -static'
#export CXXFLAGS='-O3 -xT -ip -no-prec-div -static'
export CXXCPP='icpc -E'

export F77=ifort
export FFLAGS='-fpic -O3 -ip -no-prec-div -static'
#export FFLAGS='-O3 -ip -no-prec-div -static'
#export FFLAGS='-O3 -xT -ip -no-prec-div -static'

export FC=ifort
export FCFLAGS='-g'

set +e
#rm -rf $DST
#mkdir -p $DST
make clean
set -e
#./configure --prefix=$DST --with-netcdf=$DIR_NETCDF --with-hdf5=$DIR_HDF5 --with-udunits2=$DIR_NETCDF --with-uuid=$DIR_UUID
./configure --prefix=$DST --with-netcdf=$DIR_NETCDF --with-hdf5=$DIR_HDF5 --with-udunits2=$DIR_UDUNITS --with-uuid=$DIR_UUID
#./configure --prefix=$DST --disable-shared --enable-netcdf4 --enable-separate-fortran --enable-largefiles --with-uuid=$DIR_UUID --with-udunits2=$DIR_UDUNITS --with-netcdf=$DIR_NETCDF
#./configure --prefix=$DST --disable-shared --disable-netcdf-4 --enable-separate-fortran --enable-largefiles --with-uuid=$DIR_UUID --with-udunits2=$DIR_UDUNITS --with-netcdf=$DIR_NETCDF
make
#make check
make install

date
