-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall_CosmoPMC.sh
executable file
·286 lines (241 loc) · 5.82 KB
/
install_CosmoPMC.sh
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#!/usr/bin/env bash
# :Name: install_CosmoPMC.sh
# :Author: Martin Kilbinger
# (adapted from install_shapepipe by Sam Farrens)
# :Date: 2019
# :Package: CosmoPMC
# :Description: Install CosmoPMC and dependend libraries.
##################
# Global variables
##################
# Divider line
line="########################################################################"
# Version
version=0.3
# Default values for variables
BASE_DIR=$PWD
BUILD_DIR=$BASE_DIR/build
PMCENV="cosmopmc"
TOPO=""
LFLAGS=""
BUILD_R=""
# Help string
help="$(basename "$0") [OPTIONS]\n\n
Options:\n
\t-h, --help\t\t show this help message and exit\n
\t--build-dir PATH\t set CosmoPMC build path (default is \$PWD/build)\n
\t--no-R\t\t\t do not build R\n
\n
Executable and library options:\n
\t--lflags LFLAGS\t\t linker flags\n
\t--topo PATH\t\t topology likelihood path (default not used)\n
\n
"
#############
# Subroutines
#############
# Print start message
start() {
echo ''
echo $line
echo 'CosmoPMC installation script'
echo ''
echo 'Author: Martin Kilbinger'
echo 'Year: 2019'
echo 'Version:' $version
echo $line
echo ''
}
# Check if a binary executable is already installed in the conda environment
check_conda() {
if ! type -t "conda" > /dev/null
then
echo "Conda command not found, make sure it is installed before proceding."
exit
else
echo "Conda command found"
fi
}
print_setup() {
echo 'Operating system: ' $SYSOS
echo 'Base directory (CosmoPMC clone): ' $BASE_DIR
echo 'Build directory: ' $BUILD_DIR
echo 'Environment name: ' $PMCENV
echo 'Topolike directory: ' $TOPO
echo 'Linker flags: ' $LFLAGS
echo 'Build R: ' $BUILD_R
echo ''
}
# Function to report progress
report_progress() {
echo ''
echo $line
echo 'Installing' $1
echo $line
echo ''
}
##############
# Start script
##############
# Parse command line options
for i in "$@"
do
case $i in
-h|--help)
start
echo -ne $help
shift
exit
;;
--build-dir=*)
BUILD_DIR="${i#*=}"
shift
;;
--no-R)
BUILD_R=FALSE
shift
;;
--lapackdir=*)
TOPO="${i#*=}"
shift
;;
--topo=*)
TOPO="${i#*=}"
shift
;;
esac
done
## Create conda environment
# Start script
start
# Check if conda is installed
check_conda
# Find the operating system
case "$OSTYPE" in
darwin*)
SYSOS="macOS"
;;
linux*)
SYSOS="LINUX"
;;
*)
echo "unknown: $OSTYPE"
exit 1
;;
esac
# Create build directory if it does not already exist
if [ ! -d "$BUILD_DIR" ]
then
mkdir $BUILD_DIR
fi
# Print script set-up
print_setup
# Build conda environment
conda info --envs | grep $PMCENV > /dev/null
x=$?
if [ $x == 0 ]; then
echo "CosmoPMC environment already exists, skipping create"
else
report_progress 'CosmoPMC environment'
conda env create -f environment.yml
fi
# Activate conda environment
if [ "$CONDA_DEFAULT_ENV" == "$PMCENV" ]; then
echo "$PMCENV conda environment already active, skipping activate"
else
#eval "$(conda shell.bash hook)"
source activate $PMCENV
echo "Activating conda environment" $CONDA_PREFIX
fi
############################
# install macos requirements
############################
# Set up macOS environment
if [ "$SYSOS" == "macOS" ]; then
report_progress 'macOS Requirements'
conda install -n $PMCENV wget -y
conda install -n $PMCENV automake autoconf libtool -y
export C_INCLUDE_PATH=$CONDA_PREFIX/include
export CFLAGS="-Wl,-rpath,$CONDA_PREFIX/lib"
fi
##########################
# install mpi requirements
##########################
conda install -n $PMCENV -c conda-forge mpich -y
##########################
# Build external libraries
##########################
report_progress 'fftw3'
#conda install -n $PMCENV -c conda-forge fftw -y
conda install -c eumetsat fftw3 -y
report_progress 'gsl'
conda install -n $PMCENV -c conda-forge gsl=1.16 -y
report_progress 'lacpack'
conda install -n $PMCENV -c conda-forge liblapack -y
# C-compiler stuff
if [ "$SYSOS" == "LINUX" ]; then
report_progress 'gxx_linux-64'
conda install -n $PMCENV gxx_linux-64 -y
fi
#########################
# Build external programs
#########################
report_progress "cmake"
conda install -n cosmopmc -c conda-forge cmake -y
report_progress "gnuplot"
conda install -n cosmopmc -c conda-forge gnuplot -y
if [ "$BUILD_R" == TRUE ]; then
report_progress "R"
conda install -n cosmopmc -c r r -y
conda install -n cosmopmc -c r r-lattice -y
conda install -n cosmopmc -c r r-MASS -y
conda install -n cosmopmc -c r r-coda -y
conda install -n cosmopmc -c r r-getopt -y
conda install -n cosmopmc -c r r-optparse -y
conda install -n cosmopmc -c r r-funr -y
fi
#############################
# Build PMC-related libraries
#############################
# pmclib
report_progress 'pmclib'
cd $BUILD_DIR
if [ -e pmclib ]; then
rm -rf pmclib
fi
git clone https://github.com/CosmoStat/pmclib.git
cd pmclib
python -c 'import sys; print(open("wscript").read().replace("MK_TO_REPLACE", sys.argv[1]))' $CONDA_PREFIX > wscript.new
mv wscript.new wscript
python2.7 ./waf configure --prefix=$CONDA_PREFIX --m64
python2.7 ./waf build install
cd $BASE_DIR
# nicaea
report_progress 'nicaea'
cd $BUILD_DIR
if [ -e nicaea ]; then
rm -rf nicaea
fi
git clone https://github.com/CosmoStat/nicaea.git
mkdir nicaea/build
cd nicaea/build
cmake .. -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DCMAKE_INSTALL_RPATH_USE_LINK_PATH="ON"
make && make install
cd $BASE_DIR
# CosmoPMC
report_progress 'CosmoPMC'
cd $BASE_DIR
if [ "$TOPO" == "" ]; then
arg_topo=""
else
arg_topo="--topo $TOPO"
fi
if [ "$LFLAGS" == "" ]; then
lflags=""
else
lflags="$LFLAGS"
fi
cmd="python2.7 ./configure.py --pmclib=$CONDA_PREFIX --nicaea=$CONDA_PREFIX --installdir=$CONDA_PREFIX $arg_topo $LFLAGS" # --inc_mpi -I/usr/include/mpich-x86_64 --ldirs_mpi=-L/usr/lib64/mpich/lib # --lflags -lm
echo "Running $cmd"
$cmd
make && make install