-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall_netcdf
executable file
·1832 lines (1736 loc) · 72.8 KB
/
install_netcdf
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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
#
# Install open source packages to work with netCDF and openMPI on Mac OS X and
# Linux.
#
# The script was initially written to install netCDF4 (hence its name) and all
# its dependencies to be used with different Fortran compilers, as well as some
# netCDF tools such as cdo, nco and ncview.
#
# It is also used to install missing packages locally on computing clusters. For
# example, a cluster might have the netCDF C-library installed but not the
# Fortran version.
#
# Set parameters in Setup section below, as well as directories to packages that
# are already installed.
#
# Prerequisites: curl, c and c++ compilers, pkg-config for nco.
# Optional prerequisites: fortran compiler (e.g. gfortran) for netcdf and MPI
# java compiler for antlr2, i.e. ncap2 of nco
#
# The script was tested on Mac OS X 10.9 through 13 (Mavericks to Ventura).
# It was not tested on Ubuntu for quite a while.
#
# Dependencies are:
# hdf5 <- zlib, szip
# netcdf4 <- hdf5
# netcdf4_fortran <- netcdf4
# grib_api <- netcdf4, jasper, libpng
# or
# eccodes <- netcdf4, jasper, libpng
# libtiff <- jpeg
# proj4 <- sqlite, libtiff, curl
# cdo <- netcdf4, proj4, grib_api or eccodes, udunits
# nco <- netcdf4, gsl, udunits, pkg-config,
# antlr v2 (not v3/4) for ncap2
# ncview <- netcdf4, udunits
# ffmpeg <- yasm
#
# The websites to check for the latest versions are:
# zlib - http://zlib.net
# openssl - https://www.openssl.org/source/
# szip - http://www.hdfgroup.org/ftp/lib-external/szip/
# hdf5 - http://www.hdfgroup.org/ftp/HDF5/releases/
# netcdf4/_fortran - https://downloads.unidata.ucar.edu/netcdf/
# netcdf3 - http://www.unidata.ucar.edu/downloads/netcdf/netcdf-3_6_3
# udunits - ftp://ftp.unidata.ucar.edu/pub/udunits/
# libpng - http://sourceforge.net/projects/libpng/files/
# libjpeg - http://www.ijg.org/files/
# libtiff - https://download.osgeo.org/libtiff/
# proj4 - https://download.osgeo.org/proj/
# jasper - http://www.ece.uvic.ca/~frodo/jasper/
# grib_api - https://software.ecmwf.int/wiki/display/GRIB/Releases
# eccodes - https://software.ecmwf.int/wiki/display/ECC/Releases
# cdo - https://code.zmaw.de/projects/cdo/files
# ncview - ftp://cirrus.ucsd.edu/pub/ncview/
# gsl - ftp://ftp.gnu.org/gnu/gsl/
# antlr - http://www.antlr2.org/download.html
# nco - http://nco.sourceforge.net/nco.html
# openmpi - http://www.open-mpi.org
# mpich - http://www.mpich.org/downloads/
# geos - https://download.osgeo.org/geos
# gdal - https://trac.osgeo.org/gdal/wiki/DownloadSource
# yasm - http://yasm.tortall.net/Download.html
# ffmpeg - http://ffmpeg.org/releases/
# p7zip - http://sourceforge.net/projects/p7zip/
# hdf4 - http://www.hdfgroup.org/release4/obtain.html
# enscript - http://ftp.gnu.org/gnu/enscript
# htop - http://hisham.hm/htop/
#
# Check for all latest versions by copying to open/xdg-open:
# http://zlib.net https://www.openssl.org/source/ http://www.hdfgroup.org/ftp/lib-external/szip/ http://www.hdfgroup.org/ftp/HDF5/releases/ https://downloads.unidata.ucar.edu/netcdf/ http://www.unidata.ucar.edu/downloads/netcdf/netcdf-3_6_3 ftp://ftp.unidata.ucar.edu/pub/udunits/ http://sourceforge.net/projects/libpng/files/ http://www.ijg.org/files/ https://download.osgeo.org/libtiff/ https://download.osgeo.org/proj/ http://www.ece.uvic.ca/~frodo/jasper/ https://software.ecmwf.int/wiki/display/GRIB/Releases https://software.ecmwf.int/wiki/display/ECC/Releases https://code.zmaw.de/projects/cdo/files ftp://cirrus.ucsd.edu/pub/ncview/ ftp://ftp.gnu.org/gnu/gsl/ http://www.antlr2.org/download.html http://nco.sourceforge.net/nco.html http://www.open-mpi.org http://www.mpich.org/downloads/ https://download.osgeo.org/geos https://trac.osgeo.org/gdal/wiki/DownloadSource http://yasm.tortall.net/Download.html http://ffmpeg.org/releases/ http://sourceforge.net/projects/p7zip/ http://www.hdfgroup.org/release4/obtain.html http://ftp.gnu.org/gnu/enscript http://hisham.hm/htop/releases/
#
# Note
# - Do not untabify this script because the netcdf_fortran libtool patch will
# not work anymore.
# - If some libraries are already installed such as png, set dolibpng=0 below.
# One can set EXTRA_CPPFLAGS and EXTRA_LDFLAGS if the compilers do not find it
# automatically,
# for example: EXTRA_LDFLAGS='-L/opt/local'
#
# Note on Mac OS X using homebrew
# One can use homebrew to install everything except the Fortran versions. This
# is very practical. However, homebrew upgrades also netcdf-c to newer
# versions if you install or update a package that depends on it. Then the
# netcdf-fortran package installed with this script will not work anymore and
# you have to rerun the script. I still do it this way because re-installing
# netcdf-fortran with this script is very fast.
# To use it with homebrew:
# install homebrew
# install the following packages via homebrew by typing: brew install <PACKAGE>
# for i in ghostscript gcc netcdf cmake udunits proj jasper gsl ; do \
# brew install ${i} ; done
# for i in antlr@2 geos gdal nco ncview ; do brew install ${i} ; done
# Then, do not select the installed packages below
# dozlib=0
# doszip=0
# dohdf5=0
# donetcdf4=0
# doudunits=0
# dolibpng=0
# dolibjpeg=0
# dolibtiff=0
# doproj4=0
# dojasper=0
# dogsl=0
# doantlr=0
# donco=0
# doncview=0
# Then use the script to install all libraries that provide Fortran interfaces
# with all your Fortran compilers, such as netcdf4-fortran, netcdf3, openmpi,
# mpich, giving the list of your Fortran compilers below, e.g.
# fortran_compilers="gfortran nagfor pgfortran ifort"
#
# Homebrew can also be used for the additional packages
# for i in wget imagemagick ffmpeg enscript htop ; do brew install ${i} ; done
#
# Note on (Scientific) Linux
# zlib installed by default.
# Install antlr-C++ bindings from paket manager.
#
# Note on Ubuntu
# install the following software from package management via the command line
# by typing sudo apt install <PACKAGE>
# zlib [installed by default on Ubuntu]
# or
# libz-mingw-w64 [on Ubuntu on Windows]
# libpng-dev
# libtiff-dev [installs libjpeg-dev]
# libantlr-dev
# libexpat-dev
# libcurl4-openssl-dev
# xorg-dev
# cmake
# bison
# Therefore do not select the packages below
# dozlib=0
# dolibpng=0
# dolibjpeg=0
# dolibtiff=0
# doantlr=0
#
# authors: Matthias Cuntz with testing by Stephan Thober
# created: Oct 2014
#
# Copyright (c) 2014-2023 Matthias Cuntz - mc (at) macu (dot) de
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# --------------------------------------------------------------------
# Info
set -ex
prog=$0
pprog=$(basename ${prog})
dprog=$(dirname ${prog})
pid="$$"
sys=$(uname -s | tr A-Z a-z)
ver=$(uname -r)
kern=$(uname -r | tr A-Z a-z)
if [[ "${sys}" == "darwin" ]] ; then
ncpu=$(sysctl -n hw.ncpu)
else
ncpu=$(( 2 * $(grep ^processor /proc/cpuinfo | wc -l) ))
fi
# --------------------------------------------------------------------
# Help
function usage () {
printf "${pprog} [h]\n"
printf "\n"
printf "Install open source packages such as the netcdf library.\n"
printf "There are no command line options. Edit the Setup section in the script instead.\n"
printf "\n"
printf "Options\n"
printf " -h Prints this help screen.\n"
printf "\n"
printf "Examples\n"
printf " ${pprog}\n"
printf "\n"
printf "Copyright (c) 2014-2019 Matthias Cuntz - mc (at) macu (dot) de\n"
}
while getopts "h" Option ; do
case ${Option} in
h) usage; exit;;
*) printf "Error ${pprog}: unimplemented option.\n\n" 1>&2; usage 1>&2; exit 1;;
esac
done
# --------------------------------------------------------------------
# Setup
# Where to install
prefix=/usr/local
# Which steps to do
# steps are: 1. download, 2. unpack, 3. configure, make, install, 4. clean-up
dodownload=1 # 1: curl sources, 0: skip
docheck=1 # 1: make check, 2: make check but do not exit on errors, 0: skip
dormtar=1 # 1: rm downloaded sources, 0: skip
dosudo=1 # 1: install in ${prefix} with sudo, 0: install as user
# What is to be installed in which version (setup list)
# Basics - everything for programming with netCDF and MPI
dozlib=0
zlib=1.2.13
doopenssl=0
openssl=1.1.1d
doszip=0
szip=2.1.1
doparallel=0 # Parallel HDF5 and netCDF4, set e.g. prefix=/usr/local/openmpi
mpiprefix=/usr/local/openmpi-4.1.4-gfortran
dohdf5=0
hdf5=1.14.0
hdf5check=0 # omit tests of hdf5: tests take a very, very long time for hdf5 > 1.10
donetcdf4=0 # make check might stop but library works
netcdf4=4.9.2
donetcdf4_fortran=0 # make check might stop but library works
netcdf4_fortran=4.6.1
donetcdf3=0
netcdf3=3.6.3
doudunits=0
udunits=2.2.26
dolibpng=0
libpng=1.6.37
dolibjpeg=0 # one test fails on Linux, but seems to work
libjpeg=9e
dolibtiff=0 # eight tests fail on Linux, but seems to work
libtiff=4.4.0
dosqlite=0
sqlite=3.39.0
doproj4=0 # some tests fail on Linux, but seems to work
proj4=8.2.1 # v8.2.1 last one that supports autotools; >v9 uses Cmake
dojasper=0
jasper=1.900.1 # 1.900.29; tested 2.0.14, but not compatible with grib_api
doeccodes=0 # for cdo > 1.9.0
eccodes=2.16.0 # make check fails (bufr not installed): ignore
# just cd into build directory eccodes-${eccodes}-Source/build and sudo make install
dogrib_api=0
grib_api=1.28.0
docdo=0
cdo=1.9.8 # download path has a number that changes with version, e.g.
# https://code.zmaw.de/attachments/download/9444/cdo-1.6.7.tar.gz
# check number at https://code.zmaw.de/projects/cdo/files
cdodownpath=20826 # 1.6.3: 7220; 1.6.4: 8376; 1.6.6: 9367; 1.6.7: 9444; 1.7.2: 12760; 1.9.1: 15653;
# 1.9.2: 16035; 1.9.3: 16435; 1.9.7.1: 20124; 1.9.8: 20826
doncview=0
ncview=2.1.8
dogsl=0
gsl=2.6 # > 1.12 has some strange chmod a-w for gsl-config and gsl.pc
doantlr=0
antlr=2.7.7 # one check fails with g++ clang 7.0.x on Mac OS X 10.11 (El Capitan) but can be ignored
donco=0
nco=4.9.2
doopenmpi=0
openmpi=4.1.7
dompich=0 # one check fails on macOS 13 (Ventura) but can be ignored
mpich=4.2.3
# Python-Matplotlib
# Georeferencing in basemap
dogeos=0 # one check fails (< 3.6.2) on Mac OS X but can be ignored
geos=3.11.0
# GeoTiffs
dogdal=0
gdal=3.4.0
# Needed by ffmpeg
doyasm=0
yasm=1.3.0
# Do animations/movies in matplotlib
doffmpeg=0 # Works if installed manually
ffmpeg=4.2.2
# Optional tools
# 7zip is an extension of zip, e.g. used in CarboEurope database
dop7zip=0
p7zip=16.02
# Old HDF format, e.g. MODIS data
dohdf4=0
hdf4=4.2.14 # downloads broken for 4.2.15
# Text files as postscript -> pdf
doenscript=0
enscript=1.6.6
# htop is extended top
dohtop=0
htop=2.2.0
# Install netcdf-fortran for which Fortran compilers. Known compilers: gfortran nagfor pgfortran ifort
# fortran_compilers="gfortran nagfor pgfortran ifort"
fortran_compilers="gfortran"
# fortran_compilers="nagfor"
# fortran_compilers="gfortran nagfor"
# fortran_compilers="/opt/pgi/osx86-64/19.4/bin/pgfortran"
# fortran_compilers="pgfortran"
# # Standard Intel
# source /opt/intel/bin/compilervars.sh intel64
# fortran_compilers="ifort"
# # Intel OneAPI
# source /opt/intel/oneapi/setvars.sh
# fortran_compilers="ifort"
# # Intel @ explor
# module load intel/2019.4-full
# fortran_compilers="ifort"
# Extra CPPFLAGS and LDFLAGS, for example for libs in non-default path such as /opt/lib
if [[ "${sys}" == "darwin" ]] ; then
if [[ -z ${HOMEBREW_PREFIX} ]] ; then
if [[ -d /opt/homebrew ]] ; then
HOMEBREW_PREFIX="/opt/homebrew"
else
HOMEBREW_PREFIX="/usr/local"
fi
fi
# add path of m4 binary for netcdf et al.
export PATH=${PATH}:${HOMEBREW_PREFIX}/opt/m4/bin
else
HOMEBREW_PREFIX=
fi
if [[ "${sys}" == "darwin" ]] ; then
EXTRA_CPPFLAGS="-I${HOMEBREW_PREFIX}/include"
EXTRA_LDFLAGS="-L${HOMEBREW_PREFIX}/lib"
if [[ -n ${ONEAPI_ROOT} ]] ; then
EXTRA_LDFLAGS="${EXTRA_LDFLAGS} -L${prefix}/lib -L${PPATH}/lib"
EXTRA_CPPFLAGS="${EXTRA_CPPFLAGS} -I${PPATH}/include"
fi
else
EXTRA_CPPFLAGS=
EXTRA_LDFLAGS="-Wl,-rpath=${prefix}/lib"
fi
# Path to zlib's and pthread's include/ lib/ directories (e.g. lib/libz.*)
# Path to curl lib (libcurl.*) for cdo
if [[ "${sys}" == "darwin" ]] ; then
osver=$(uname -r)
osver=${osver%%.*}
if [[ ${osver} -lt 22 ]] ; then # macOS < 13
# there are still links of, for example, libz.dylib in /usr/lib/
# ZPATH=${prefix}
ZPATH=/usr
PPATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr
CURLLIB=/usr/lib
else
ZPATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr
PPATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr
CURLLIB=
fi
else
ZPATH=/usr
PPATH=/usr
if [[ ${kern} == *microsoft ]] ; then
CURLLIB=/usr/lib/x86_64-linux-gnu
else
CURLLIB=/usr/lib64
fi
fi
# Extra flag for FTP with curl
if [[ "${sys}" == "darwin" ]] ; then
FTPFLAG=""
else
FTPFLAG="--disable-epsv"
fi
# Path to X-devel for ncview. Searches for example checking X11/Intrinsic.h and X11/Xaw/Simple.h
if [[ "${sys}" == "darwin" ]] ; then
XPATH=/usr/X11
XLIB=${XPATH}/lib
XINC=${XPATH}/include
else
XPATH=/usr
if [[ ${kern} == *microsoft ]] ; then
XLIB=${XPATH}/lib/X11
else
XLIB=${XPATH}/lib64/X11
fi
XINC=${XPATH}/include/X11
fi
# PGI path
if [[ "${sys}" == "darwin" ]] ; then
pgipath=/opt/pgi/osx86-64/17.10
fi
# CMake executable
if [[ "${sys}" == "darwin" ]] ; then
if [[ -f /Applications/CMake.app/Contents/bin/cmake ]] ; then
CMAKE=/Applications/CMake.app/Contents/bin/cmake
else
CMAKE=cmake
fi
else
CMAKE=cmake
fi
# --------------------------------------------------------------------
# Functions
function download() {
izbase=${1}
ihttp=${2}
# download
if [[ ${dodownload} -eq 1 ]] ; then curl ${FTPFLAG} -L -o ${izbase} ${ihttp}/${izbase} ; fi
}
function download_github() {
izbase=${1}
ihttp=${2}
# download
if [[ ${dodownload} -eq 1 ]] ; then curl -L -o ${izbase} ${ihttp} ; fi
}
function unpack() {
izbase=${1}
ibase=${2}
# extract
case ${izbase#${ibase}} in
*.tar) tar -xvf ${izbase} ;;
*.tar.bz) tar -xvjf ${izbase} ;;
*.tar.bz2) tar -xvjf ${izbase} ;;
*.tar.gz) tar -xvzf ${izbase} ;;
*.tar.z) tar -xvZf ${izbase} ;;
*.tar.Z) tar -xvZf ${izbase} ;;
*.tar.xz) tar -xvJf ${izbase} ;;
*.zip) unzip ${izbase} ;;
*) printf "Error: compression not known ${izbase#${ibase}}\n\n" 1>&2; exit 1 ;;
esac
}
function download_unpack() {
ibase=${1}
izbase=${2}
ihttp=${3}
# download
download ${izbase} ${ihttp}
# extract
unpack ${izbase} ${ibase}
}
function download_github_unpack() {
ibase=${1}
izbase=${2}
ihttp=${3}
# download
download_github ${izbase} ${ihttp}
# extract
unpack ${izbase} ${ibase}
}
function configure() {
ibase=${1}
bconf=${2}
aconf=${3}
# cd
cd ${ibase}
# configure
echo "${bconf}" LDFLAGS=\"-L${prefix}/lib ${EXTRA_LDFLAGS}\" \
CPPFLAGS=\"-I${prefix}/include ${EXTRA_CPPFLAGS}\" \
./configure --prefix=${iprefix} ${aconf}
eval "${bconf}" LDFLAGS=\"-L${prefix}/lib ${EXTRA_LDFLAGS}\" \
CPPFLAGS=\"-I${prefix}/include ${EXTRA_CPPFLAGS}\" \
./configure --prefix=${iprefix} ${aconf}
}
function configure_nocpp() {
ibase=${1}
bconf=${2}
aconf=${3}
# cd
cd ${ibase}
# configure
echo "${bconf}" LDFLAGS=\"-L${prefix}/lib ${EXTRA_LDFLAGS}\" \
CPPFLAGS=\"${EXTRA_CPPFLAGS}\" \
./configure --prefix=${iprefix} ${aconf}
eval "${bconf}" LDFLAGS=\"-L${prefix}/lib ${EXTRA_LDFLAGS}\" \
CPPFLAGS=\"${EXTRA_CPPFLAGS}\" \
./configure --prefix=${iprefix} ${aconf}
}
function configure_make() {
configure "$@"
# make
make -j ${ncpu}
}
function configure_make_nocpp() {
configure_nocpp "$@"
# make
make -j ${ncpu}
}
function cmake_make() {
ibase=${1}
bconf=${2}
aconf=${3}
# cd
cd ${ibase}
# build dir
mkdir build
cd build
# cmake
echo "${bconf}" LDFLAGS=\"-L${prefix}/lib ${EXTRA_LDFLAGS}\" \
CPPFLAGS=\"-I${prefix}/include ${EXTRA_CPPFLAGS}\" \
${CMAKE} -DCMAKE_INSTALL_PREFIX=${iprefix} ${aconf} ../
eval "${bconf}" LDFLAGS=\"-L${prefix}/lib ${EXTRA_LDFLAGS}\" \
CPPFLAGS=\"-I${prefix}/include ${EXTRA_CPPFLAGS}\" \
${CMAKE} -DCMAKE_INSTALL_PREFIX=${iprefix} ${aconf} ../
# make
make -j ${ncpu}
}
function check() {
# check
case ${docheck} in
1) make -j ${ncpu} check ;;
2) set +e ; make -j ${ncpu} check ; set -e ;;
*) : ;;
esac
}
function check_test() {
# check
case ${docheck} in
1) make -j ${ncpu} test ;;
2) set +e ; make -j ${ncpu} test ; set -e ;;
*) : ;;
esac
}
function configure_make_check() {
ibase=${1}
bconf=${2}
aconf=${3}
# make
configure_make ${ibase} "${bconf}" "${aconf}"
# check
check
}
function cmake_make_check() {
ibase=${1}
bconf=${2}
aconf=${3}
# make
cmake_make ${ibase} "${bconf}" "${aconf}"
# check
check
}
function configure_make_test() {
ibase=${1}
bconf=${2}
aconf=${3}
# make
configure_make ${ibase} "${bconf}" "${aconf}"
# check
check_test
}
function cmake_make_test() {
ibase=${1}
bconf=${2}
aconf=${3}
# make
cmake_make ${ibase} "${bconf}" "${aconf}"
# check
check_test
}
function install() {
mconf=${1}
# install
if [[ ${dosudo} -eq 1 ]] ; then
# echo ${supw} | sudo -S make install
sudo make install ${mconf}
else
make install ${mconf}
fi
}
function configure_make_check_install() {
ibase=${1}
bconf=${2}
aconf=${3}
# make
configure_make ${ibase} "${bconf}" "${aconf}"
# check
check
# install
install
}
function configure_make_nocpp_check_install() {
ibase=${1}
bconf=${2}
aconf=${3}
# make
configure_make_nocpp ${ibase} "${bconf}" "${aconf}"
# check
check
# install
install
}
function cmake_make_check_install() {
ibase=${1}
bconf=${2}
aconf=${3}
# make
cmake_make ${ibase} "${bconf}" "${aconf}"
# check
check
# install
install
}
function cmake_make_test_install() {
ibase=${1}
bconf=${2}
aconf=${3}
# make
cmake_make ${ibase} "${bconf}" "${aconf}"
# check
check_test
# install
install
}
function apply_netcdf_fortran_nag_patch() {
#
printf "Patch NetCDF ${netcdf4_fortran}\n"
# patch ${base}/m4/libtool.m4 patchit.${pid}
sed -n -e "/nagbegin.netcdf${netcdf4_fortran}.patch/,/nagend.netcdf${netcdf4_fortran}.patch/p" \
${dprog}/${pprog} > patchit.${pid}
case ${netcdf4_fortran} in # normal: diff old new > patch
4.2) # was done: diff new old > patch
patch -R ${base}/m4/libtool.m4 patchit.${pid}
;;
4.4.1) # was done: diff new old > patch
patch -R ${base}/m4/libtool.m4 patchit.${pid}
;;
4.4.2) # patch directly libtool
patch ${base}/libtool patchit.${pid}
;;
4.4.3) # do not patch libtool but change F77 test file
sed -i -e 's/call EXIT/stop/' ${base}/nf_test/nf_test.F
;;
4.4.4) # do not patch libtool but change F77 test files
sed -i -e 's/call EXIT/stop/' ${base}/nf_test/nf_test.F
sed -i -e 's/&[[:blank:]]*$//' ${base}/nf_test/ftst_path.F
sed -i -e 's/&[[:blank:]]*$//' ${base}/nf_test/ftst_rengrps.F
sed -i -e 's/&[[:blank:]]*$//' ${base}/nf03_test/test03_read.F
sed -i -e 's/&[[:blank:]]*$//' ${base}/nf03_test/test03_write.F
sed -i -e 's/&[[:blank:]]*$//' ${base}/nf03_test/util03.F
sed -i -e 's/&[[:blank:]]*$//' ${base}/nf03_test/f03tst_open_mem.F
sed -i -e '/#endif/i\
#else\
subroutine dummy\
end subroutine dummy\
' ${base}/fortran/nf_logging.F90
;;
4.4.5) # NAG does not allow compiling empty source files
sed -i -e 's/include/ include/' ${base}/nf_test/ftst_rengrps.F
sed -i -e '/#endif/i\
#else\
subroutine dummy\
end subroutine dummy\
' ${base}/fortran/nf_logging.F90
;;
4.5.2 | 4.5.3) # patch configure script
patch ${base}/configure patchit.${pid}
;;
*)
true
;;
esac
if [[ -f patchit.${pid} ]] ; then rm patchit.${pid} ; fi
}
function cleanup() {
ibase=${1}
izbase=${2}
# clean up
if [[ ${dosudo} -eq 1 ]] ; then
sudo rm -rf ${ibase}
if [[ ${dormtar} -eq 1 ]] ; then sudo rm ${izbase} ; fi
else
rm -rf ${ibase}
if [[ ${dormtar} -eq 1 ]] ; then rm ${izbase} ; fi
fi
}
function download_configure_make_check_install() {
ibase=${1}
izbase=${2}
ihttp=${3}
bconf=${4}
aconf=${5}
download_unpack ${ibase} ${izbase} ${ihttp}
configure_make_check_install ${ibase} "${bconf}" "${aconf}"
cd ..
cleanup ${ibase} ${izbase}
}
function download_cmake_make_check_install() {
ibase=${1}
izbase=${2}
ihttp=${3}
bconf=${4}
aconf=${5}
download_unpack ${ibase} ${izbase} ${ihttp}
cmake_make_check_install ${ibase} "${bconf}" "${aconf}"
cd ../..
cleanup ${ibase} ${izbase}
}
function download_cmake_make_test_install() {
ibase=${1}
izbase=${2}
ihttp=${3}
bconf=${4}
aconf=${5}
download_unpack ${ibase} ${izbase} ${ihttp}
cmake_make_test_install ${ibase} "${bconf}" "${aconf}"
cd ../..
cleanup ${ibase} ${izbase}
}
# --------------------------------------------------------------------
# Start
# --------------------------------------------------------------------
# --------------------------------------------------------------------
# sudo
iprefix=${prefix}
# get sudo password
if [[ ${dosudo} -eq 1 ]] ; then
printf "\nsudo password for make install into ${prefix}\n"
# Ask for sudo password upfront
sudo -v
# Keep-alive: update existing `sudo` time stamp until script has finished
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
# read -rs -p "sudo password for make install into ${prefix}: " supw
printf "\n"
fi
# --------------------------------------------------------------------
# Install
# build zlib
if [[ ${dozlib} -eq 1 ]] ; then
printf 'Build zlib\n'
base=zlib-${zlib}
zbase=${base}.tar.gz
http=https://zlib.net
download_configure_make_check_install ${base} ${zbase} ${http}
fi
# build openssl
if [[ ${doopenssl} -eq 1 ]] ; then
printf 'Build openssl\n'
base=openssl-${openssl}
zbase=${base}.tar.gz
http=https://www.openssl.org/source
# download
download_unpack ${base} ${zbase} ${http}
# configure
cd ${base}
if [[ "${sys}" == "darwin" && "${openssl}" < "1.1.0" ]] ; then
# pod2man5.18 much stricter than ealier version but --stderr flag allows warnings instead of errors: patch Makefile.org
sed -e '/@pod2man/s/";/ --stderr";/' Makefile.org > tmp.${pid}
mv tmp.${pid} Makefile.org
LDFLAGS="-L${prefix}/lib ${EXTRA_LDFLAGS}" CPPFLAGS="-I${prefix}/include ${EXTRA_CPPFLAGS}" \
./Configure --prefix=${iprefix} --openssldir=${iprefix}/openssl darwin64-x86_64-cc
else
LDFLAGS="-L${prefix}/lib ${EXTRA_LDFLAGS}" CPPFLAGS="-I${prefix}/include ${EXTRA_CPPFLAGS}" \
./config --prefix=${iprefix} --openssldir=${iprefix}/openssl
fi
# make
make
# check
check_test
# install
install
cd ..
# clean
cleanup ${base} ${zbase}
fi
# build szip
if [[ ${doszip} -eq 1 ]] ; then
printf 'Build szip\n'
base=szip-${szip}
zbase=${base}.tar.gz
http=http://www.hdfgroup.org/ftp/lib-external/szip/${szip}/src
download_configure_make_check_install ${base} ${zbase} ${http}
fi
# build hdf5
if [[ ${dohdf5} -eq 1 ]] ; then
printf 'Build hdf5\n'
base=hdf5-${hdf5}
zbase=${base}.tar.gz
if [[ "${hdf5}" > "1.10.0" ]] ; then
http=https://support.hdfgroup.org/ftp/HDF5/releases/${base%.*}/${base}/src/${zbase}
download_github_unpack ${base} ${zbase} ${http}
if [[ ${doparallel} -eq 1 ]] ; then
if [[ ${PATH} != *mpi* ]] ; then export PATH=${PATH}:${mpiprefix}/bin ; fi
printf " Build parallel\n"
export MPICC='mpicc'
export MPICXX='mpicxx'
export MPIFC='mpifort'
export MPIF77='mpifort'
export MPIF90='mpifort'
export CC=${MPICC}
export CXX=${MPICXX}
export FC=${MPIFC}
export F77=${MPIF77}
export F90=${MPIF90}
dparallel="-DHDF5_ENABLE_PARALLEL=ON -DHDF5_BUILD_CPP_LIB=OFF"
else
dparallel=""
fi
# -DCMAKE_C_FLAGS='-Wno-error=implicit-function-declaration'
cmake_make ${base} " " "-DHDF5_ENABLE_Z_LIB_SUPPORT=ON -DZLIB_ROOT==${ZPATH} -DHDF5_ENABLE_SZIP_SUPPORT=ON -DSZIP_ROOT=${prefix} ${dparallel}"
if [[ ${hdf5check} -eq 1 ]] ; then
check_test
fi
install
if [[ "${sys}" == "darwin" ]] ; then
# set @rpath/lib explicitly in library because LC_RPATH is not working all the time
set +e
hdflib=$(ls ${prefix}/lib/libhdf5.[0-9].dylib ${prefix}/lib/libhdf5.[0-9][0-9].dylib ${prefix}/lib/libhdf5.[0-9][0-9][0-9].dylib 2>/dev/null)
hllib=$(ls ${prefix}/lib/libhdf5_hl.[0-9].dylib ${prefix}/lib/libhdf5_hl.[0-9][0-9].dylib ${prefix}/lib/libhdf5_hl.[0-9][0-9][0-9].dylib 2>/dev/null)
htlib=$(ls ${hdf5prefix}/lib/libhdf5_tools.[0-9].dylib ${hdf5prefix}/lib/libhdf5_tools.[0-9][0-9].dylib ${hdf5prefix}/lib/libhdf5_tools.[0-9][0-9][0-9].dylib 2>/dev/null)
set -e
if [[ ${dosudo} -eq 1 ]] ; then
sudo install_name_tool -id ${hdflib} ${hdflib}
sudo install_name_tool -id ${hllib} ${hllib}
sudo install_name_tool -change @rpath/$(basename ${hdflib}) ${hdflib} ${hllib}
sudo install_name_tool -id ${htlib} ${htlib}
sudo install_name_tool -change @rpath/$(basename ${hdflib}) ${hdflib} ${htlib}
else
install_name_tool -id ${hdflib} ${hdflib}
install_name_tool -id ${hllib} ${hllib}
install_name_tool -change @rpath/$(basename ${hdflib}) ${hdflib} ${hllib}
install_name_tool -id ${htlib} ${htlib}
install_name_tool -change @rpath/$(basename ${hdflib}) ${hdflib} ${htlib}
fi
fi
cd ../..
cleanup ${base} ${zbase}
else
http=http://www.hdfgroup.org/ftp/HDF5/releases/hdf5-${hdf5%.*}/hdf5-${hdf5}/src
download_configure_make_check_install ${base} ${zbase} ${http} " " "--with-zlib=${ZPATH} --with-szlib=${prefix} --enable-threadsafe --with-pthread=${PPATH}"
fi
fi
# build netcdf4 C
if [[ ${donetcdf4} -eq 1 ]] ; then
printf 'build netcdf4-C\n'
base=netcdf-c-${netcdf4}
zbase=${base}.tar.gz
http=https://codeload.github.com/Unidata/netcdf-c/tar.gz/v${netcdf4}
download_github_unpack ${base} ${zbase} ${http}
# remove netcdf from homebrew if present
export PATH=$(echo $PATH | tr ":" "\n" | grep -v netcdf | tr "\n" ":")
if [[ "${netcdf4}" > "4.4.1" ]] ; then
if [[ ${doparallel} -eq 1 ]] ; then
if [[ ${PATH} != *mpi* ]] ; then export PATH=${PATH}:${mpiprefix}/bin ; fi
printf " Build parallel\n"
export MPICC='mpicc'
export MPICXX='mpicxx'
export MPIFC='mpifort'
export MPIF77='mpifort'
export MPIF90='mpifort'
export CC=${MPICC}
export CXX=${MPICXX}
export FC=${MPIFC}
export F77=${MPIF77}
export F90=${MPIF90}
fi
hdf5prefix=${prefix}
cmake_make_test_install ${base} " " "-DHDF5_ROOT=${hdf5prefix} -DENABLE_DAP_REMOTE_TESTS=OFF -DENABLE_SHARED=ON"
cd ../..
cleanup ${base} ${zbase}
else
configure_make_check_install ${base} " " "--disable-dap-remote-tests"
cd ..
cleanup ${base} ${zbase}
fi
if [[ "${sys}" == "darwin" ]] ; then
# set @rpath/lib explicitly in library because LC_RPATH is not working all the time
set +e
nclib=$(ls ${prefix}/lib/libnetcdf.[0-9].dylib ${prefix}/lib/libnetcdf.[0-9][0-9].dylib 2>/dev/null)
hdflib=$(ls ${hdf5prefix}/lib/libhdf5.[0-9].dylib ${hdf5prefix}/lib/libhdf5.[0-9][0-9].dylib ${hdf5prefix}/lib/libhdf5.[0-9][0-9][0-9].dylib 2>/dev/null)
hllib=$(ls ${hdf5prefix}/lib/libhdf5_hl.[0-9].dylib ${hdf5prefix}/lib/libhdf5_hl.[0-9][0-9].dylib ${hdf5prefix}/lib/libhdf5_hl.[0-9][0-9][0-9].dylib 2>/dev/null)
set -e
if [[ ${dosudo} -eq 1 ]] ; then
sudo install_name_tool -id ${nclib} ${nclib}
sudo install_name_tool -change @rpath/$(basename ${hdflib}) ${hdflib} ${nclib}
sudo install_name_tool -change @rpath/$(basename ${hllib}) ${hllib} ${nclib}
else
install_name_tool -id ${nclib} ${nclib}
install_name_tool -change @rpath/$(basename ${hdflib}) ${hdflib} ${nclib}
install_name_tool -change @rpath/$(basename ${hllib}) ${hllib} ${nclib}
fi
fi
fi
# build netcdf4-fortran
if [[ ${donetcdf4_fortran} -eq 1 ]] ; then
printf 'Build netcdf4-fortran\n'
base=netcdf-fortran-${netcdf4_fortran}
zbase=${base}.tar.gz
http=https://codeload.github.com/Unidata/netcdf-fortran/tar.gz/v${netcdf4_fortran}
download_github_unpack ${base} ${zbase} ${http}
# remove netcdf from homebrew if present
export PATH=$(echo $PATH | tr ":" "\n" | grep -v netcdf | tr "\n" ":")
# configure / make / check / install for all fortran compilers
for f_comp in ${fortran_compilers} ; do
case ${f_comp} in
*pgfortran*) # first pgfortran then gfortran in case statement
printf "${f_comp} not supported at the moment for netcdf-fortran after change to cmake.\n"
continue
;;
*)
true
;;
esac
hdf5prefix=${prefix}
netcdfcprefix=${prefix}
if [[ -n ${ONEAPI_ROOT} ]] ; then
printf "Build ${base}-oneapi\n"
iprefix=${prefix}/${base}-oneapi
export LIBRARY_PATH=${LIBRARY_PATH}:/usr/local/lib:${PPATH}/lib
export CPATH=${CPATH}:/usr/local/include:${PPATH}/include
else
printf "Build ${base}-$(basename ${f_comp})\n"
iprefix=${prefix}/${base}-$(basename ${f_comp})
fi
if [[ ${doparallel} -eq 1 ]] ; then
if [[ ${PATH} != *mpi* ]] ; then
export PATH=${PATH}:${mpiprefix}/bin
else
mpiprefix=$(dirname $(dirname $(which mpicc)))
fi
printf " Build parallel\n"
export MPICC='mpicc'
export MPICXX='mpicxx'
export MPIFC='mpifort'
export MPIF77='mpifort'
export MPIF90='mpifort'
export CC=${MPICC}
export CXX=${MPICXX}
export FC=${MPIFC}
export F77=${MPIF77}
export F90=${MPIF90}
export LD_LIBRARY_PATH=${netcdfcprefix}/lib:${LD_LIBRARY_PATH}
ZDIR=/usr/local/opt/zstd
if [[ -d ${ZDIR} ]] ; then
ZINC="-I${ZDIR}/include"
ZLIBDIR="${ZDIR}/lib"
ZLIB="-L${ZLIBDIR}"
ZLIBS="-lzstd"
fi
cd ${base}
CC=${MPICC} FC=${MPIF90} F77=${MPIF77} CPPFLAGS="-I${netcdfcprefix}/include -I${hdf5prefix}/include -I${mpiprefix}/include ${ZINC}" LDFLAGS="-L${netcdfcprefix}/lib -L${hdf5prefix}/lib -L${mpiprefix}/lib ${ZLIB}" LD_LIBRARY_PATH=${netcdfcprefix}/lib:${hdf5prefix}/lib:${mpiprefix}/lib:${ZLIBDIR} LIBS="-lnetcdf -lhdf5_hl -lhdf5 -lm -lz ${ZLIBS} -lbz2 -lcurl -lxml2" ./configure --prefix=${iprefix}
make -j ${ncpu}
check_test
install
cd ..
iprefix=${prefix}
else
cd ${base}
mkdir build
cd build
case ${f_comp} in
*nag* | *gfortran*)
# strange variables with _T such as NCSHORT_T in ftest.f