do_macadam 4.24 KB
Newer Older
1
#!/bin/bash
2
3
4
5
6
7
8
#
# 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/
9
#  Documentation: https://framagit.org/metroprojects/metro/wikis/home
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
#
#
# 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.3.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
    rm -f _macadam.so *.o macadam.py macadam_wrap.c
    exit 0
44
45
46
47
elif [[ $1 = "" ]]; then
    destination_path="../.."
else
    destination_path=$1
48
49
50
51
52
53
54
55
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
56
echo "* Building METRo $METRO_VERSION model"
57
58
59
60
61
62
63
64
65

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
66
67
68
    echo "----------------------------------------------------------"
    echo "WARNING!"
    echo "No python path defined."
69
    echo "Will try to used the default path for python 2.4"
70
71
72
    echo "If it still doesn't work,"
    echo "please set environment variable PYTHON_INCLUDE to your"
    echo "python include directory."
73
    echo "Ex: export PYTHON_INCLUDE=\"/usr/local/include/python2.4\""
74
75
    echo "----------------------------------------------------------"
    echo ""
76
    PYTHON_INC="-I/usr/include/python2.4/"
77
fi
François Fortin's avatar
François Fortin committed
78
echo "    Python include path = "$PYTHON_INC
79

François Fortin's avatar
François Fortin committed
80
81
82
83
84
85
86
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
87

François Fortin's avatar
François Fortin committed
88
89
echo "    Using SWIG"
echo '    macadam.i :'
90
91
swig -python  macadam.i 

François Fortin's avatar
François Fortin committed
92
echo "    C compilation"
93
gcc -c -fPIC -Wall  -Wno-implicit  macadam.c $PYTHON_INC
94
gcc -c -fPIC  macadam_wrap.c $PYTHON_INC
95

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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
112
echo "    Fortran compilation"
François Fortin's avatar
François Fortin committed
113
$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 
114
115


François Fortin's avatar
François Fortin committed
116
echo "    Link"
117
$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
118
119


François Fortin's avatar
François Fortin committed
120
echo "    Copying .so in usr/share/metro/model"
121
122
123
124
125
126
127
if [ ! -d $destination_path/usr/share/metro/model ]; then
    mkdir $destination_path/usr/share/metro/model
fi
cp macadam.py $destination_path/usr/share/metro/model/

if [ ! -d $destination_path/usr/lib/metro ]; then
    mkdir -p $destination_path/usr/lib/metro
128
fi
129
130
cp _macadam.so $destination_path/usr/lib/metro/

François Fortin's avatar
François Fortin committed
131

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