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