do_macadam 4.53 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`

37
METRO_VERSION=4.0.0
38
39


40
if [[ $1 = clean ]]; then
Miguel Tremblay's avatar
typo    
Miguel Tremblay 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

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
Sasa Zhang's avatar
Sasa Zhang committed
65
66
elif which python3-config >/dev/null; then
    echo "Using python3-config to detect python settings."
67
    echo -n "You can override detected values by setting "
68
    echo "enviroment variable PYTHON_INCLUDE."
Sasa Zhang's avatar
Sasa Zhang committed
69
70
    echo "Ex: export PYTHON_INCLUDE=\"/usr/local/include/python3.6\""
    PYTHON_INC=`python3-config --includes`
71
else
72
73
74
    echo "----------------------------------------------------------"
    echo "WARNING!"
    echo "No python path defined."
Sasa Zhang's avatar
Sasa Zhang committed
75
    echo "Will try to used the default path for python 3.6"
76
77
78
    echo "If it still doesn't work,"
    echo "please set environment variable PYTHON_INCLUDE to your"
    echo "python include directory."
Sasa Zhang's avatar
Sasa Zhang committed
79
    echo "Ex: export PYTHON_INCLUDE=\"/usr/local/include/python3.6\""
80
81
    echo "----------------------------------------------------------"
    echo ""
Sasa Zhang's avatar
Sasa Zhang committed
82
    PYTHON_INC="-I/usr/include/python3.6/"
83
fi
84
85
echo ""
echo "Compiling..."
François Fortin's avatar
François Fortin committed
86
echo "    Python include path = "$PYTHON_INC
87

Sasa Zhang's avatar
Sasa Zhang committed
88
PLATFORM=`python3 -c "import platform;print(platform.architecture()[0])"`
François Fortin's avatar
François Fortin committed
89
90
91
92
93
94
if  [ $PLATFORM = "64bit" ]; then
    FORTRAN_DEFAULT_INTEGER="-fdefault-integer-8"
    echo "    64 bit architecture detected"
else
    FORTRAN_DEFAULT_INTEGER=""
fi
95

François Fortin's avatar
François Fortin committed
96
97
echo "    Using SWIG"
echo '    macadam.i :'
Sasa Zhang's avatar
Sasa Zhang committed
98
swig -python macadam.i
99

François Fortin's avatar
François Fortin committed
100
echo "    C compilation"
101
gcc -c -fPIC -Wall  -Wno-implicit  macadam.c $PYTHON_INC
102
gcc -c -fPIC  macadam_wrap.c $PYTHON_INC
103

104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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
120
echo "    Fortran compilation"
121
$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
122
123


François Fortin's avatar
François Fortin committed
124
echo "    Link"
125
$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
126
127


François Fortin's avatar
François Fortin committed
128
echo "    Copying .so in usr/share/metro/model"
129
if [ ! -d $destination_path/usr/share/metro/model ]; then
130
    mkdir -p $destination_path/usr/share/metro/model
131
132
133
134
135
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
136
fi
137
cp _macadam.so $destination_path/usr/lib/metro/