[1925] | 1 | #!/bin/bash |
---|
| 2 | ######################################################################### |
---|
| 3 | # Script to automatically install the NetCDF 4.0.1 Library |
---|
| 4 | ######################################################################### |
---|
| 5 | # Defaults |
---|
| 6 | ######################################################################### |
---|
| 7 | install_dir=$(pwd)/netcdf-4.0.1 |
---|
| 8 | compiler_suite=gnu |
---|
| 9 | ######################################################################### |
---|
| 10 | # Options |
---|
| 11 | ######################################################################### |
---|
| 12 | while (($# > 0)) |
---|
| 13 | do |
---|
| 14 | case $1 in |
---|
| 15 | "-h") cat <<........fin |
---|
| 16 | $0 [ -prefix path ] where (path) to install |
---|
| 17 | (default: $install_dir) |
---|
| 18 | [ -compiler gnu | intel ] compiler suite (Fortran, C, C++) to use |
---|
| 19 | (default: $compiler_suite) |
---|
| 20 | ........fin |
---|
| 21 | exit ;; |
---|
| 22 | "-prefix") install_dir=$2 ; shift ; shift ;; |
---|
| 23 | "-compiler") compiler_suite=$2 ; shift ; shift ;; |
---|
| 24 | *) echo "Error, bad argument $1" ; $0 -h ; exit |
---|
| 25 | esac |
---|
| 26 | done |
---|
| 27 | |
---|
| 28 | # Install directory (get full path) |
---|
| 29 | mkdir -p $install_dir |
---|
| 30 | install_dir=$(cd $install_dir ; pwd -P ) |
---|
| 31 | cd $install_dir |
---|
| 32 | |
---|
| 33 | rm -rf netcdf-4.0.1* |
---|
| 34 | wget http://www.lmd.jussieu.fr/~lmdz/Distrib/netcdf-4.0.1.tar.gz |
---|
| 35 | tar xzf netcdf-4.0.1.tar.gz ; cd netcdf-4.0.1 |
---|
| 36 | |
---|
| 37 | if [[ ${compiler_suite} == "gnu" ]] ; then |
---|
| 38 | f_compiler="gfortran" |
---|
| 39 | c_compiler="gcc" |
---|
| 40 | cxx_compiler="g++" |
---|
| 41 | elif [[ ${compiler_suite} == "intel" ]] ; then |
---|
| 42 | f_compiler="ifort" |
---|
| 43 | c_compiler="icc" |
---|
| 44 | cxx_compiler="icpc" |
---|
| 45 | else |
---|
| 46 | echo "unknown compiler family $compiler_suite" |
---|
| 47 | echo "might as well stop here" |
---|
| 48 | exit |
---|
| 49 | fi |
---|
| 50 | |
---|
| 51 | export FC=$f_compiler |
---|
| 52 | export F90=$f_compiler |
---|
| 53 | export CC=$c_compiler |
---|
| 54 | export CXX=$cxx_compiler |
---|
| 55 | if [[ ${f_compiler} == "gfortran" ]] ; then |
---|
| 56 | export FFLAGS=" -O2 -fPIC" |
---|
| 57 | export FCFLAGS="-O2 -ffree-form -fPIC" |
---|
| 58 | export CPPFLAGS="" |
---|
| 59 | export CFLAGS="-O2 -fPIC" |
---|
| 60 | export CXXFLAGS="-O2 -fPIC" |
---|
| 61 | elif [[ ${f_compiler} == "ifort" ]] ; then |
---|
| 62 | export CPP="icc -E" |
---|
| 63 | export FFLAGS="-O2 -ip -fpic" |
---|
| 64 | export FCFLAGS="-O2 -ip -fpic" |
---|
| 65 | export CPPFLAGS="" |
---|
| 66 | export CFLAGS="-O2 -ip -fpic" |
---|
| 67 | export CXXFLAGS="-O2 -ip -fpic" |
---|
| 68 | else |
---|
| 69 | echo "unknown compiler $f_compiler" |
---|
| 70 | echo "might as well stop here" |
---|
| 71 | exit |
---|
| 72 | fi |
---|
| 73 | |
---|
| 74 | ./configure --prefix=$install_dir > configure.log 2>&1 |
---|
| 75 | |
---|
| 76 | make > make.log 2>&1 |
---|
| 77 | |
---|
| 78 | make test > make_test.log 2>&1 |
---|
| 79 | |
---|
| 80 | make install > make_install.log 2>&1 |
---|
| 81 | |
---|
| 82 | if [[ -f $install_dir/bin/nc-config ]] ; then |
---|
| 83 | echo "successfully installed the netcdf library in $install_dir" |
---|
| 84 | fi |
---|