-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrf_install
435 lines (411 loc) · 17.4 KB
/
wrf_install
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
#!/bin/bash
#########################################################
# WRF Install Script #
# This Script was based on the framework provided by #
# https://github.com/bakamotokatas/WRF-Install-Script, #
# rewritten by uho-33. #
# To execute this script "bash wrf_install" #
#########################################################
type="ARW"
#########################################################
# WRF and WPS compile configure #
#########################################################
# In default, this script will choose 'dmpar' mode of WRF and basic type of nesting.
# For WPS, this script will choose 'serial' mode in defult.
# For more information, see https://www2.mmm.ucar.edu/wrf/OnLineTutorial/Compile/wrf_compile2.php
# and https://www2.mmm.ucar.edu/wrf/OnLineTutorial/Compile/wps_compile2.php.
# If you have specific requirements, change the value below:
WRF_config1=34 # WRF mode for compiling in parallel
WRF_config2=1 # WRF type of nesting
WPS_config=1 # WPS mode
##########################################################
if [ -n "$1" ]; then
if [ "$1" = "-chem" ]; then
type="Chem"
elif [ "$1" = "-arw" ]; then
type="ARW"
elif [ "$1" = "-hydro" ]; then
type="Hydro"
else
echo "Unrecognized option, please run as"
echo "For WRF-ARW \"bash WRF${WRFversion}_Install.bash -arw\""
echo "For WRF-Chem \"bash WRF${WRFversion}_Install.bash -chem\""
echo "For WRF-Hydro \"bash WRF${WRFversion}_Install.bash -hydro\""
exit
fi
fi
echo "############################################################"
echo "Welcome! This Script will install the WRF${WRFversion}-${type}"
echo "Installation may take several hours and it takes 52 GB storage. Be sure that you have enough time and storage."
echo "Please run this script in the place where you want to install WRF and WPS."
echo "############################################################"
#########################################################
# Controls #
#########################################################
if [ "$EUID" -eq 0 ]
then echo "ERROR: Running this script as root or sudo, is not suggested"
exit
fi
osbit=$(uname -m)
if [ "$osbit" = "x86_64" ]; then
echo "64 bit operating system is used"
else
echo "Sorry! This script was written for 64 bit operating systems."
exit
fi
local_language=$(locale | grep LANG | grep tr_TR)
if [ -n "$local_language" ]; then
echo "Merhaba, WRF modelinin kodundaki hatadan dolayı, WRF kurulumu işletim sistemi dili Türkçe olduğunda, Türkçedeki i ve ı harflerinin farklı olması sebebiyle hata vermektedir. Lütfen işletim sisteminizin dilini başka bir dile çevirip yeniden çalıştırınız. Kurulum bittikten sonra işletim sistemi dilini tekrar Türkçe'ye çevirebilirsiniz."
exit
fi
wget_path=$(which wget)
if [ -z "$wget_path" ]; then
echo "ERROR: Can not find wget. Please install it, then try again."
exit 1
fi
csh_status=$(which csh)
if [ -z "$csh_status" ]; then
echo "ERROR: Can not find csh. Please install it, then try again."
exit 1
fi
#########################################################
# Test and install conda #
#########################################################
# Ensure input is not empty
get_non_empty_input() {
local input=""
while [ -z "$input" ]; do
read -p "$1" -e input
done
echo "$input"
}
check_input() {
local input_var_name=$1
local input_value
input_value=$(eval echo \$${input_var_name})
if [ "$input_value" != "n" ] && [ "$input_value" != "y" ]; then
while [ "$input_value" != "n" ] && [ "$input_value" != "y" ]; do
echo "Unrecognizable input, please enter again:"
read input_value
done
eval "$input_var_name=\"$input_value\""
fi
}
# Check whether conda exists
eval "$(cat ~/.bashrc | tail -n +10)"
conda_status=$(which conda)
# Set conda path
if [ -n "$conda_status" ]; then
echo "Found conda in $(which conda). It will be used to install packages."
env_exist=$(conda env list | grep '^WRF')
echo "In default, necessary package will install in environment 'WRF'"
if [ -n "$env_exist" ]; then
env_status=$(get_non_empty_input "The environment 'WRF' has exited. Do you want to install in it? [y/n] ")
if [ "$env_status" = "y" ]; then
env_name=WRF
fi
else
env_status=$(get_non_empty_input "Do you want to use this name? [y/n] ")
check_input env_status
if [ "$env_status" = "y" ]; then
env_name=WRF
fi
fi
else
conda_loc_status=$(get_non_empty_input "Conda is not installed. In default, it will be installed in ${HOME}/miniconda3. [y/n] ")
check_input conda_loc_status
if [ "$conda_loc_status" = "n" ]; then
while [ "$conda_loc_status" = "n" ]; do
conda_path=$(get_non_empty_input "Please enter the path where the Miniconda will be installed: ")
conda_path=$(eval echo "$conda_path/miniconda3")
conda_loc_status=$(get_non_empty_input "Miniconda will be installed in ${conda_path}. [y/n] ")
check_input conda_loc_status
done
elif [ "$conda_loc_status" = "y" ]; then
conda_path=$(eval echo "${HOME}/miniconda3")
fi
env_exist=""
echo "In default, necessary package will install in environment 'WRF'."
env_status=$(get_non_empty_input "Do you want to use this name? [y/n] ")
check_input env_status
if [ "$env_status" = "y" ]; then
env_name=WRF
fi
fi
# Set environment name
if [ "$env_status" = "n" ]; then
while [ "$env_status" = "n" ]; do
env_name=$(get_non_empty_input "Please enter your environment's name: ")
env_status=$(get_non_empty_input "Your environment's name is ${env_name}. [y/n] ")
check_input env_status
if [ -n "$conda_status" ]; then
env_exist=$(conda env list | grep ^${env_name})
if [ -n "$env_exist" ]; then
env_status=$(get_non_empty_input "The environment has exited. Do you want to install in it? [y/n] ")
check_input env_status
if [ "$env_status" = "y" ]; then
conda activate $env_name
fi
fi
fi
done
fi
# Install conda
if [ -z "$conda_status" ]; then
mkdir -p $conda_path
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O $conda_path/miniconda.sh
if [ $? -ne 0 ]; then
echo "Failed to download Miniconda. Exiting the script."
exit 1
fi
bash $conda_path/miniconda.sh -b -u -p $conda_path
rm -rf $conda_path/miniconda.sh
$conda_path/bin/conda init bash
eval "$(cat ~/.bashrc | tail -n +10)"
conda_status=$(which conda)
if [ -z "$conda_status" ]; then
echo "failed to install conda. Please try again or install matually."
exit 1
else
echo "Successfully install Miniconda!"
fi
fi
#########################################################
# Installing necessary packages #
#########################################################
# By Conda #
######################
if [ "$type" = "Chem" ]; then
extra_packages="flex bison"
fi
###
packagelist="git make cmake gfortran gcc=12.2.0 m4 curl perl libpng netcdf4 libnetcdf netcdf-fortran jasper=1.900.1 zlib mpich ${extra_packages}"
package4checks="git make cmake gfortran gcc m4 curl perl libpng netcdf4 libnetcdf netcdf-fortran jasper zlib mpich ${extra_packages}"
packagesnotinstalled=no
if [ -z "$env_exist" ]; then
conda create -n $env_name $packagelist -c conda-forge -y
conda activate $env_name
else
conda activate ${env_name}
for packagecheck in $package4checks; do
packagechecked=$(conda list | grep -w $packagecheck)
if [ -z "$packagechecked" ]; then
packagesnotinstalled=yes
break
fi
done
if [ "$packagesnotinstalled" = "yes" ]; then
conda install $packagelist -c conda-forge -y
fi
fi
packagesnotinstalled="no"
for packagecheck in $package4checks; do
packagechecked=$(conda list | grep -w $packagecheck)
if [ -z "$packagechecked" ]; then
echo "$packagecheck not installed"
packagesnotinstalled=yes
fi
done
if [ "$packagesnotinstalled" = "yes" ]; then
echo "Some packages were not installed, please install the missing packages and re-run the script."
exit 1
fi
echo "All required packages are installed."
#########################################
echo "" >> ~/.bashrc
bashrc_exports=("#WRF Variables" "export PATH=${MPICH_DIR}/bin:$PATH" "export CC=gcc" "export CXX=g++" "export FC=gfortran" "export FCFLAGS=-m64" "export F77=gfortran" "export FFLAGS=-m64"
"export NETCDF=${CONDA_PREFIX}" "export HDF5=${CONDA_PREFIX}" "export LDFLAGS=-L${CONDA_PREFIX}/lib"
"export CPPFLAGS=-I${CONDA_PREFIX}/include" "export MPICH_DIR=${CONDA_PREFIX}" "export LD_LIBRARY_PATH=${MPICH_DIR}/lib:${CONDA_PREFIX}/lib" "export MPI_LIB=${MPICH_DIR}/lib" "export JASPERLIB=${CONDA_PREFIX}/lib" "export JASPERINC=${CONDA_PREFIX}/include")
for bashrc_export in "${bashrc_exports[@]}" ; do
[[ -z $(grep "${bashrc_export}" ~/.bashrc) ]] && echo "${bashrc_export}" >> ~/.bashrc
done
export CC=gcc
export CXX=g++
export FC=gfortran
export FCFLAGS=-m64
export F77=gfortran
export FFLAGS=-m64
export NETCDF=${CONDA_PREFIX}
export HDF5=${CONDA_PREFIX}
export LDFLAGS=-L${CONDA_PREFIX}/lib
export CPPFLAGS=-I${CONDA_PREFIX}/include
export LD_LIBRARY_PATH=${MPICH_DIR}/lib:${CONDA_PREFIX}/lib:$LD_LIBRARY_PATH
export MPICH_DIR=${CONDA_PREFIX}
export MPI_LIB=-L${MPICH_DIR}/lib
export MPI_INCLUDE_DIR=${MPICH_DIR}/include
export JASPERLIB=${CONDA_PREFIX}/lib
export JASPERINC=${CONDA_PREFIX}/include
if [ "$type" = "Chem" ]; then
[[ -z $(grep "export FLEX_LIB_DIR=${CONDA_PREFIX}/lib" ~/.bashrc) ]] && echo "export FLEX_LIB_DIR=${CONDA_PREFIX}/lib" >> ~/.bashrc
[[ -z $(grep "export YACC='yacc -d'" ~/.bashrc) ]] && echo "export YACC='yacc -d'" >> ~/.bashrc
export FLEX_LIB_DIR=${CONDA_PREFIX}/lib
export YACC='yacc -d'
fi
#########################################
# WRF Installation #
#########################################
DIR=$(pwd)
skip_wrf_status="n"
if [ -d "WRF" ]; then
skip_wrf_status=$(get_non_empty_input "WARNING: WRF has existed. Do you want to skip install it? [y/n] ")
check_input skip_wrf_status
fi
if [ "$skip_wrf_status" = "n" ]; then
install_WRF_by_prec_status="n"
[ -d "WRF" ] && install_WRF_by_prec_status=$(get_non_empty_input "Do you want to install using the pre-cloned repository? [y/n] ")
if [ "$install_WRF_by_prec_status" = "n" ]; then
[ -d "WRF" ] && mv WRF WRF-old
git clone --recurse-submodules https://github.com/wrf-model/WRF
# Ensure download successfully
if [ $? -ne 0 ]; then
echo "Failed to clone the repository. Exiting the script."
exit 1
fi
fi
if [ "$type" = "Hydro" ]; then
export WRF_HYDRO=1
mkdir Build_WRF
cd Build_WRF/packages
[ -f "v5.2.0.tar.gz" ] && mv v5.2.0.tar.gz v5.2.0.tar.gz-old
wget https://github.com/NCAR/wrf_hydro_nwm_public/archive/refs/tags/v5.2.0.tar.gz -O v5.2.0.tar.gz
tar -zxvf v5.2.0.tar.gz
/bin/cp -rf wrf_hydro_nwm_public-5.2.0/trunk/NDHMS/* $DIR/WRF/hydro/
rm v5.2.0.tar.gz
rm -r wrf_hydro_nwm_public-5.2.0
cd $DIR
fi
cd WRF
./clean -a
if [ "$type" = "Chem" ]; then
export WRF_CHEM=1
export WRF_KPP=1
fi
( echo ${WRF_config1} ; echo ${WRF_config2} ) | ./configure
sed -i 's#-L/usr/lib -lnetcdff -lnetcdf#-L${NETCDF}/lib -lnetcdff -lnetcdf#g' configure.wrf
gfortversion=$(gfortran -dumpversion | cut -d '.' -f 1)
if [ "$gfortversion" -lt 8 ] && [ "$gfortversion" -ge 6 ]; then
sed -i '/-DBUILD_RRTMG_FAST=1/d' configure.wrf
fi
logsave log.compile ./compile em_real
if [ -n "$(grep "Problems building executables, look for errors in the build log" log.compile)" ]; then
echo "Sorry, There were some errors while installing WRF."
echo "Please create new issue for the problem, https://github.com/uho-33/script-for-instal-WRF/issues"
exit
fi
cd ..
fi
# [ -d "WRF-${WRFversion}-${type}" ] && mv WRF-${WRFversion}-${type} WRF-${WRFversion}-${type}-old
# mv WRFV${WRFversion} WRF-${WRFversion}-${type}
#########################################
# WPS Installation #
#########################################
skip_wps_status="n"
if [ -d "WPS" ]; then
skip_wps_status=$(get_non_empty_input "WARNING: WPS has existed. Do you want to skip install it? [y/n] ")
check_input skip_wps_status
fi
if [ "$skip_wps_status" = "n" ]; then
install_WPS_by_prec_status="n"
[ -d "WPS" ] && install_WPS_by_prec_status=$(get_non_empty_input "Do you want to install using the pre-cloned repository? [y/n] ")
if [ "$install_WRF_by_prec_status" = "n" ]; then
git clone https://github.com/wrf-model/WPS
if [ $? -ne 0 ]; then
echo "Failed to clone the repository. Exiting the script."
exit 1
fi
fi
cd WPS
./clean -a
sed -i '163s/.*/ NETCDFF="-lnetcdff"/' configure
echo ${WPS_config} | ./configure
logsave log.compile ./compile
sed -i "s# geog_data_path.*# geog_data_path = '../WPS_GEOG/'#" namelist.wps
cd ..
fi
#########################################
# Opening Geog Data Files #
#########################################
if [ -d "WPS_GEOG" ]; then
echo "WRF and WPS are installed successfully"
echo "Directory WPS_GEOG is already exists."
echo "Do you want WPS_GEOG files to be redownloaded and reexracted?"
while [ -z "$GEOG_validation" ]; do
GEOG_validation=$(get_non_empty_input "please enter [y/n]")
if [ ${GEOG_validation} = "y" ]; then
wget https://www2.mmm.ucar.edu/wrf/src/wps_files/geog_high_res_mandatory.tar.gz -O geog_high_res_mandatory.tar.gz
tar -zxvf geog_high_res_mandatory.tar.gz
elif [ ${GEOG_validation} = "n" ]; then
echo "You can download it later from http://www2.mmm.ucar.edu/wrf/src/wps_files/geog_high_res_mandatory.tar.gz and extract it"
else
echo "Unrecognizable input, please enter again."
GEOG_validation=""
fi
done
else
wget https://www2.mmm.ucar.edu/wrf/src/wps_files/geog_high_res_mandatory.tar.gz -O geog_high_res_mandatory.tar.gz
tar -zxvf geog_high_res_mandatory.tar.gz
fi
if [ "$type" = "Chem" ]; then
cd WPS_GEOG
Chem_Geog="modis_landuse_21class_30s soiltype_top_2m soiltype_bot_2m albedo_ncep maxsnowalb erod clayfrac_5m sandfrac_5m"
for i in ${Chem_Geog}; do
if [ ! -d $i ]; then
echo $i
wget https://www2.mmm.ucar.edu/wrf/src/wps_files/${i}.tar.bz2 -O ${i}.tar.bz2
tar -xvf ${i}.tar.bz2
rm ${i}.tar.bz2
fi
done
cd ..
fi
#######################################
# PREP_CHEM_SRC #
#######################################
if [ "$type" = "Chem" ]; then
echo "Do you want the PREP-CHEM-SRC program to be installed? PREP-CHEM-SRC is a widely used emission preparation program for WRF-Chem."
echo "please type yes or no"
read prep_chem_validation
if [ ${prep_chem_validation} = "yes" ]; then
echo "firstly starting to compile convert_emiss.exe. convert_emiss.exe is needed for convert emissions which are created from PREP-CHEM-SRC."
cd WRF-${WRFversion}-${type}
logsave convert_emi.log ./compile emi_conv
cd ..
echo "Compilation of convert_emiss.exe is finished, now PREP-CHEM-SRC download and compilation has started."
[ -d "PREP-CHEM-SRC-1.5" ] && mv PREP-CHEM-SRC-1.5 PREP-CHEM-SRC-1.5-old
[ -f "prep_chem_sources_v1.5_24aug2015.tar.gz" ] && mv prep_chem_sources_v1.5_24aug2015.tar.gz prep_chem_sources_v1.5_24aug2015.tar.gz-old
wget ftp://aftp.fsl.noaa.gov/divisions/taq/global_emissions/prep_chem_sources_v1.5_24aug2015.tar.gz -O prep_chem_sources_v1.5_24aug2015.tar.gz
tar -zxvf prep_chem_sources_v1.5_24aug2015.tar.gz
cd PREP-CHEM-SRC-1.5/bin/build
sed -i "s#NETCDF=.*#NETCDF=/usr#" include.mk.gfortran.wrf
sed -i 's#-L$(NETCDF)/lib#-L/usr/lib/x86_64-linux-gnu#' include.mk.gfortran.wrf
sed -i "s#HDF5=.*#HDF5=/usr/lib/x86_64-linux-gnu/hdf5/serial#" include.mk.gfortran.wrf
sed -i "s#HDF5_INC=.*#HDF5_INC=-I/usr/include/hdf5/serial#" include.mk.gfortran.wrf
sed -i 's#-L$(HDF5)/lib#-L/usr/lib/x86_64-linux-gnu/hdf5/serial#' include.mk.gfortran.wrf
gfortversion=$(gfortran -dumpversion | cut -d '.' -f 1)
if [ "$gfortversion" -ge 10 ]; then
sed -i 's#F_OPTS=.*#F_OPTS= -Xpreprocessor -D$(CHEM) -O2 -fconvert=big-endian -frecord-marker=4 -fallow-argument-mismatch#' include.mk.gfortran.wrf
fi
sed -i "s#-L/scratchin/grupos/catt-brams/shared/libs/gfortran/zlib-1.2.8/lib#-L/usr/lib#" include.mk.gfortran.wrf
sed -i "842s#.*# 'ENERGY ',\&#" ../../src/edgar_emissions.f90
sed -i "843s#.*# 'INDUSTRY ',\&#" ../../src/edgar_emissions.f90
sed -i "845s#.*# 'TRANSPORT '/)#" ../../src/edgar_emissions.f90
make OPT=gfortran.wrf CHEM=RADM_WRF_FIM
cd ..
mkdir datain
cd datain
wget ftp://aftp.fsl.noaa.gov/divisions/taq/global_emissions/global_emissions_v3_24aug2015.tar.gz -O global_emissions_v3_24aug2015.tar.gz
tar -zxvf global_emissions_v3_24aug2015.tar.gz
mv Global_emissions_v3/* .
rm -r Global_emissions_v3
mv Emission_data/ EMISSION_DATA
mv surface_data/ SURFACE_DATA
cd ../../..
echo "PREP-CHEM-SRC compilation has finished."
fi
fi
##########################################################
# End #
##########################################################
echo "Installation has completed"
exec bash
exit