#!/bin/bash
# script to building netcdf-4.1.3 with the Intel Compiler Suite
# (requires zlib-1.2.5 and hdf-1.8.6 and some version of libcurl)

## load compiler settings
# Intel(R) Composer XE 2011 Update 4 for Linux
source /opt/intel/composerxe-2011.4.191/bin/compilervars.sh intel64 # compiler suite
source /opt/intel/mkl/bin/mklvars.sh intel64 # math kernel library

# set environment variables
FLAGS='-O3 -xHost -no-prec-div -static' # -ipo
# Note: I believe the shared libraries have to be built with '-O3 -xHost' only
# while the static libs can be built with '-O3 -xHost -no-prec-div -static'
# Use two iterations to install shared and static libraries separately
# C/C++
export CC=icc
export CXX=icpc
export CFLAGS=$FLAGS
export CXXFLAGS=$FLAGS
# Fortran
export F9X=ifort 
export F77=ifort
export FC=ifort
export F90=ifort
export FFLAGS=$FLAGS
export FCFLAGS=$FLAGS
# Pre-Processor
export CPP='icc -E'
export CXXCPP='icpc -E'

# zlib and hdf5 libraries
export CPPFLAGS=-I/usr/local/include 
export LDFLAGS=-L/usr/local/lib
export LD_LIBRARY_PATH=/usr/local:$LD_LIBRARY_PATH

## build static library
# configure
./configure --prefix=/usr/local --enable-fortran --enable-cxx --enable-shared --enable-static --enable-dap --with-udunits --with-libcf --enable-pnetcdf --enable-parallel-tests --enable-netcdf4
# these are flags for parallel I/O: --enable-pnetcdf --enable-parallel-tests --enable-netcdf4
# build
make all

# install library if test successful
make check && make install
