do_macadam 3.96 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/sh
#
# METRo : Model of the Environment and Temperature of Roads
# METRo is Free and is proudly provided by the Government of Canada
# Copyright (C) 2006 Environment Canada

#  Questions or bugs report: metro@ec.gc.ca
#  METRo repository: https://gna.org/projects/metro/
#  Documentation: http://documentation.wikia.com/wiki/METRo
#
#
# Code contributed by:
#  Miguel Tremblay - Canadian meteorological center
#  Francois Fortin - Canadian meteorological center
#
#  $LastChangedDate$
#  $LastChangedRevision$
#
########################################################################
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

progname=`basename $0`

François Fortin's avatar
François Fortin committed
37
METRO_VERSION=3.2.1
38
39
40


if [[ $1 = clean ]]; then    
François Fortin's avatar
François Fortin committed
41
    echo "* Cleaning last METro model build attempt if necessary..."
42
43
44
45
46
47
48
49
50
51
    rm -f _macadam.so *.o macadam.py macadam_wrap.c
    exit 0
fi

# SETUP TRAP
ERRMSG="\nERR - build METRo model - $progname : Script terminated due to
error.  Correct error and restart.\n\n"

trap 'echo -e $ERRMSG; exit 1' ERR

François Fortin's avatar
François Fortin committed
52
echo "* Building METRo $METRO_VERSION model"
53
54
55
56
57
58
59
60
61

if [ -n "$PYTHON_INCLUDE" ] ; then
    if [ ! -d $PYTHON_INCLUDE ]; then
        echo "The path for environment variable \$PYTHON_INCLUDE($PYTHON_INCLUDE)"
        echo "is not valid. Abort execution."
        exit 1
    fi
    PYTHON_INC=-I$PYTHON_INCLUDE
else
62
63
64
    echo "----------------------------------------------------------"
    echo "WARNING!"
    echo "No python path defined."
65
    echo "Will try to used the default path for python 2.4"
66
67
68
    echo "If it still doesn't work,"
    echo "please set environment variable PYTHON_INCLUDE to your"
    echo "python include directory."
69
    echo "Ex: export PYTHON_INCLUDE=\"/usr/local/include/python2.4\""
70
71
    echo "----------------------------------------------------------"
    echo ""
72
    PYTHON_INC="-I/usr/include/python2.4/"
73
fi
François Fortin's avatar
François Fortin committed
74
echo "    Python include path = "$PYTHON_INC
75

François Fortin's avatar
François Fortin committed
76
77
78
79
80
81
82
PLATFORM=`python -c "import platform;print platform.architecture()[0]"`
if  [ $PLATFORM = "64bit" ]; then
    FORTRAN_DEFAULT_INTEGER="-fdefault-integer-8"
    echo "    64 bit architecture detected"
else
    FORTRAN_DEFAULT_INTEGER=""
fi
83

François Fortin's avatar
François Fortin committed
84
85
echo "    Using SWIG"
echo '    macadam.i :'
86
87
swig -python  macadam.i 

François Fortin's avatar
François Fortin committed
88
echo "    C compilation"
89
gcc -c -fPIC macadam.c macadam_wrap.c $PYTHON_INC
90

91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
if [ -z $FC ]; then
    if [ `which gfortran` ]; then
        FC=gfortran
    elif [ `which g77` ]; then
        FC=g77
    else
        echo "----------------------------------------------------------"
	echo "WARNING!"
	echo "No Fortran compiler found. Tried gfortran and g77"
	echo "Please set environment variable FC to your Fortran compiler."
	echo "Ex: export FC=\"my_fortran_compiler\""
	echo "----------------------------------------------------------"
	exit 1
    fi
fi

François Fortin's avatar
François Fortin committed
107
echo "    Fortran compilation"
François Fortin's avatar
François Fortin committed
108
$FC -Wall -Wsurprising -W -c -fPIC  $FORTRAN_DEFAULT_INTEGER lib_gen.f grille.f array2matrix.f initial.f coupla.f lib_therm.f flxsurfz.f balanc.f constPhys.f 
109
110


François Fortin's avatar
François Fortin committed
111
echo "    Link"
112
$FC -shared macadam.o macadam_wrap.o  lib_gen.o  grille.o array2matrix.o initial.o coupla.o lib_therm.o flxsurfz.o balanc.o constPhys.o  -lc -o _macadam.so
113
114


François Fortin's avatar
François Fortin committed
115
echo "    Copying .so in usr/share/metro/model"
116
117
118
if [ ! -d ../../usr/share/metro/model ]; then
    mkdir ../../usr/share/metro/model
fi
François Fortin's avatar
François Fortin committed
119
120
121
cp _macadam.so ../../usr/lib/metro/
cp macadam.py ../../usr/share/metro/model/

122
#cp -v _macadam.so  macadam.py ../frontend/model/