diff --git a/executables/compile_upload_siesta.sh b/executables/compile_upload_siesta.sh index 8b6c380..b138215 100755 --- a/executables/compile_upload_siesta.sh +++ b/executables/compile_upload_siesta.sh @@ -3,13 +3,15 @@ # This small script will compile and upload the executables to the # website base=$(pwd) -SIESTA_DIR=/home/nicpa/siesta/4.1 -year=18 +SIESTA_DIR=/home/nicpa/siesta/siesta +year=20 _obj=ObjTutorial$year # First download and compile NetCDF -./install_netcdf4.bash +_ncdf_prefix=/home/nicpa/siesta/netcdf-serial +./install_netcdf4.bash -p $_ncdf_prefix --single-directory +[ $? -ne 0 ] && exit 1 pushd $SIESTA_DIR @@ -19,7 +21,6 @@ mkdir -p $_obj cd $_obj # Ensure arch.make exists -rm -f arch.make [ ! -e $base/static_gnu.make ] && echo "Failed to find static_gnu.make" && exit 1 ln -s $base/static_gnu.make arch.make @@ -31,7 +32,7 @@ function mmake { local suffix=$1 shift make clean - make -j4 $@ + make -j4 INSTALL_NCDF4_PATH=$_ncdf_prefix $@ [ $? -ne 0 ] && exit 1 scp $base tr:.p/sisl/workshop/$year/$base$suffix [ $? -ne 0 ] && exit 1 diff --git a/executables/install_netcdf4.bash b/executables/install_netcdf4.bash index 82c318d..4bc8b34 100755 --- a/executables/install_netcdf4.bash +++ b/executables/install_netcdf4.bash @@ -3,7 +3,7 @@ # Installation script for zlib, hdf5, netcdf-c and netcdf-fortran # with complete CDF-4 support (in serial). # This installation script has been written by: -# Nick R. Papior, 2016-2018. +# Nick R. Papior, 2016-2020. # # The author takes no responsibility of damage done to your hardware or # software. It is up to YOU that the script executes the correct commands. @@ -13,9 +13,9 @@ # VERY BASIC installation script of required libraries # for installing these packages: # zlib-1.2.11 -# hdf5-1.8.21 -# netcdf-c-4.6.1 -# netcdf-fortran-4.4.4 +# hdf5-1.12.0 +# netcdf-c-4.7.2 +# netcdf-fortran-4.5.2 # If you want to change your compiler version you should define the # global variables that are used for the configure scripts to grab the # compiler, they should be CC and FC. Also if you want to compile with @@ -23,18 +23,79 @@ # If you have downloaded other versions edit these version strings z_v=1.2.11 -h_v=1.8.21 -nc_v=4.6.1 -nf_v=4.4.4 +h_v=1.12.0 +nc_v=4.7.2 +nf_v=4.5.2 # Install path, change accordingly # You can change this variable to control the installation path # If you want the installation path to be a "packages" folder in # your home directory, change to this: # ID=$HOME/packages -ID=$(pwd)/static-libs +if [ -z $PREFIX ]; then + ID=$(pwd)/build +else + ID=$PREFIX +fi +# Decide whether everything is installed in 1 directory +_single_dir=1 + +while [ $# -gt 0 ]; do + opt=$1 ; shift + case $opt in + --prefix|-p) + ID=$1 ; shift + ;; + --libz-version|-libz-v) + z_v=$1 ; shift + ;; + --hdf5-version|-hdf5-v) + h_v=$1 ; shift + ;; + --netcdf-c-version|-nc-v) + nc_v=$1 ; shift + ;; + --netcdf-f-version|-nf-v) + nf_v=$1 ; shift + ;; + --single-directory) + _single_dir=1 + ;; + --separate-directory) + _single_dir=0 + ;; + --help|-h) + echo " $0 --help shows this message" + echo "" + echo "These options are available:" + echo "" + echo " --prefix|-p : specify the installation directory of the libraries" + echo " --libz-version|-libz-v : specify the libz version (default: $z_v)" + echo " --hdf5-version|-hdf5-v : specify the HDF5 version (default: $h_v)" + echo " --netcdf-c-version|-nc-v : specify the NetCDF-C version (default: $nc_v)" + echo " --netcdf-f-version|-nf-v : specify the NetCDF-fortran version (default: $nf_v)" + echo " --single-directory : all libraries are installed in --prefix/{bin,lib,include} (default: YES)" + echo " --separe-directory : all libraries are installed in --prefix///{bin,lib,include} (default: NO)" + echo "" + exit 0 + ;; + esac +done + echo "Installing libraries in folder: $ID" +echo "" +echo "Using these software versions:" +echo " libz : $z_v" +echo " hdf5 : $h_v" +echo " netcdf-c: $nc_v" +echo " netcdf-f: $nf_v" +echo "" +echo "If you want other versions, please try $0 --help and check the options" +echo " Will wait 2 sec before proceeding" +echo "" +sleep 2 + mkdir -p $ID # First we check that the user have downloaded the files @@ -47,12 +108,26 @@ function file_exists { fi } -# First we check that the user have downloaded the files -function dwn_file { - [ -e $2 ] && return 0 - wget -O $2 $1 - if [ $? -ne 0 ]; then - rm -f $2 +# Download a file, if able and the file does not exist +which wget > /dev/null +if [ $? -eq 0 ]; then + # success we can download using wget + function _dwn_file { + wget -O $1 $2 + } +else + function _dwn_file { + curl -o $1 $2 + } +fi + +# Use download function +# $1 is name of file +# $2 is URL +function download_file { + if [ ! -e $(pwd)/$1 ] ; then + # Try and download + _dwn_file $1 $2 fi } @@ -68,38 +143,43 @@ function retval { fi } -dwn_file http://zlib.net/zlib-${z_v}.tar.gz .zlib-${z_v}.tar.gz -dwn_file https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.8/hdf5-${h_v}/src/hdf5-${h_v}.tar.bz2 .hdf5-${h_v}.tar.bz2 -dwn_file https://github.com/Unidata/netcdf-c/archive/v${nc_v}.tar.gz .netcdf-c-${nc_v}.tar.gz -dwn_file https://github.com/Unidata/netcdf-fortran/archive/v${nf_v}.tar.gz .netcdf-fortran-${nf_v}.tar.gz -unset dwn_file +# Download files if they can +download_file zlib-${z_v}.tar.gz https://www.zlib.net/zlib-${z_v}.tar.gz +download_file hdf5-${h_v}.tar.bz2 https://hdf-wordpress-1.s3.amazonaws.com/wp-content/uploads/manual/HDF5/HDF5_${h_v//./_}/source/hdf5-${h_v}.tar.bz2 +download_file netcdf-c-${nc_v}.tar.gz https://github.com/Unidata/netcdf-c/archive/v${nc_v}.tar.gz +download_file netcdf-fortran-${nf_v}.tar.gz https://github.com/Unidata/netcdf-fortran/archive/v${nf_v}.tar.gz -file_exists .zlib-${z_v}.tar.gz -file_exists .hdf5-${h_v}.tar.bz2 -file_exists .netcdf-c-${nc_v}.tar.gz -file_exists .netcdf-fortran-${nf_v}.tar.gz +file_exists zlib-${z_v}.tar.gz +file_exists hdf5-${h_v}.tar.bz2 +file_exists netcdf-c-${nc_v}.tar.gz +file_exists netcdf-fortran-${nf_v}.tar.gz unset file_exists ################# # Install z-lib # ################# -[ -e $ID/lib64/libz.a ] && zlib_lib=lib64 || zlib_lib=lib -if [ ! -e $ID/$zlib_lib/libz.a ]; then - tar xfz .zlib-${z_v}.tar.gz +if [ $_single_dir -eq 0 ]; then + zlib_dir=$ID/zlib/$z_v +else + zlib_dir=$ID +fi +[ -d $zlib_dir/lib64 ] && zlib_lib=lib64 || zlib_lib=lib +if [ ! -e $zlib_dir/$zlib_lib/libz.a ]; then + tar xfz zlib-${z_v}.tar.gz cd zlib-${z_v} - ./configure --prefix $ID + ./configure --prefix $zlib_dir/ retval $? "zlib config" - make + make -j 2 retval $? "zlib make" make test 2>&1 | tee zlib.test retval $? "zlib make test" make install retval $? "zlib make install" - mv zlib.test $ID/ + mv zlib.test $zlib_dir/ cd ../ rm -rf zlib-${z_v} echo "Completed installing zlib" - [ -e $ID/lib64/libz.a ] && zlib_lib=lib64 || zlib_lib=lib + [ -d $zlib_dir/lib64 ] && zlib_lib=lib64 || zlib_lib=lib else echo "zlib directory already found." fi @@ -107,26 +187,33 @@ fi ################ # Install hdf5 # ################ -[ -e $ID/lib64/libhdf5.a ] && hdf5_lib=lib64 || hdf5_lib=lib -if [ ! -e $ID/$hdf5_lib/libhdf5.a ]; then - tar xfj .hdf5-${h_v}.tar.bz2 - cd hdf5-${h_v} +if [ $_single_dir -eq 0 ]; then + hdf_dir=$ID/hdf5/$h_v +else + hdf_dir=$ID +fi +[ -d $hdf_dir/lib64 ] && hdf_lib=lib64 || hdf_lib=lib +if [ ! -e $hdf_dir/$hdf_lib/libhdf5.a ]; then + rm -rf hdf5-$h_v + tar xfj hdf5-$h_v.tar.bz2 + cd hdf5-$h_v mkdir build ; cd build - ../configure --prefix=$ID --enable-static \ - --enable-fortran --with-zlib=$ID - LDFLAGS="-L$ID/$zlib_lib -Wl,-rpath=$ID/$zlib_lib" + ../configure --prefix=$hdf_dir \ + --enable-shared --enable-static \ + --enable-fortran --with-zlib=$zlib_dir \ + LDFLAGS="-L$zlib_dir/$zlib_lib -Wl,-rpath=$zlib_dir/$zlib_lib" retval $? "hdf5 configure" - make + make -j 2 retval $? "hdf5 make" make check-s 2>&1 | tee hdf5.test retval $? "hdf5 make check-s" make install retval $? "hdf5 make install" - mv hdf5.test $ID/ + mv hdf5.test $hdf_dir/ cd ../../ rm -rf hdf5-${h_v} echo "Completed installing hdf5" - [ -e $ID/lib64/libhdf5.a ] && hdf5_lib=lib64 || hdf5_lib=lib + [ -d $hdf_dir/lib64 ] && hdf_lib=lib64 || hdf_lib=lib else echo "hdf5 directory already found." fi @@ -134,24 +221,32 @@ fi #################### # Install NetCDF-C # #################### -[ -e $ID/lib64/libnetcdf.a ] && cdf_lib=lib64 || cdf_lib=lib -if [ ! -e $ID/$cdf_lib/libnetcdf.a ]; then - tar xfz .netcdf-c-${nc_v}.tar.gz - cd netcdf-c-${nc_v} +if [ $_single_dir -eq 0 ]; then + cdfc_dir=$ID/netcdf-c/$nc_v +else + cdfc_dir=$ID +fi +[ -d $cdfc_dir/lib64 ] && cdfc_lib=lib64 || cdfc_lib=lib +if [ ! -e $cdfc_dir/$cdfc_lib/libnetcdf.a ]; then + rm -rf netcdf-c-$nc_v + tar xfz netcdf-c-$nc_v.tar.gz + cd netcdf-c-$nc_v mkdir build ; cd build - ../configure --prefix=$ID --enable-static \ - --enable-netcdf-4 --disable-dap \ - CPPFLAGS="-I$ID/include" \ - LDFLAGS="-L$ID/$hdf5_lib -Wl,-rpath=$ID/$hdf5_lib -L$ID/$zlib_lib -Wl,-rpath=$ID/$zlib_lib" + ../configure --prefix=$cdfc_dir \ + --enable-shared --enable-static \ + --enable-netcdf-4 --disable-dap \ + CPPFLAGS="-I$hdf_dir/include -I$zlib_dir/include" \ + LDFLAGS="-L$hdf_dir/$hdf_lib -Wl,-rpath=$hdf_dir/$hdf_lib \ +-L$zlib_dir/$zlib_lib -Wl,-rpath=$zlib_dir/$zlib_lib" retval $? "netcdf configure" - make + make -j 2 retval $? "netcdf make" make install retval $? "netcdf make install" cd ../../ - rm -rf netcdf-c-${nc_v} + rm -rf netcdf-c-$nc_v echo "Completed installing C NetCDF library" - [ -e $ID/lib64/libnetcdf.a ] && cdf_lib=lib64 || cdf_lib=lib + [ -d $cdfc_dir/lib64 ] && cdfc_lib=lib64 || cdfc_lib=lib else echo "netcdf directory already found." fi @@ -159,26 +254,34 @@ fi ########################## # Install NetCDF-Fortran # ########################## -if [ ! -e $ID/$cdf_lib/libnetcdff.a ]; then - tar xfz .netcdf-fortran-${nf_v}.tar.gz - cd netcdf-fortran-${nf_v} +if [ $_single_dir -eq 0 ]; then + cdff_dir=$ID/netcdf-fortran/$nc_v +else + cdff_dir=$ID +fi +[ -d $cdff_dir/lib64 ] && cdff_lib=lib64 || cdff_lib=lib +if [ ! -e $cdff_dir/$cdff_lib/libnetcdff.a ]; then + rm -rf netcdf-fortran-$nf_v + tar xfz netcdf-fortran-$nf_v.tar.gz + cd netcdf-fortran-$nf_v mkdir build ; cd build - ../configure CPPFLAGS="-DgFortran -I$ID/include" \ - LIBS="-L$ID/$zlib_lib -Wl,-rpath=$ID/$zlib_lib \ - -L$ID/$hdf5_lib -Wl,-rpath=$ID/$hdf5_lib \ - -L$ID/$cdf_lib -Wl,-rpath=$ID/$cdf_lib \ + ../configure CPPFLAGS="-DgFortran -I$zlib_dir/include \ + -I$hdf_dir/include -I$cdfc_dir/include" \ + LIBS="-L$zlib_dir/$zlib_lib -Wl,-rpath=$zlib_dir/$zlib_lib \ + -L$hdf_dir/$hdf_lib -Wl,-rpath=$hdf_dir/$hdf_lib \ + -L$cdfc_dir/$cdfc_lib -Wl,-rpath=$cdfc_dir/$cdfc_lib \ -lnetcdf -lhdf5hl_fortran -lhdf5_fortran -lhdf5_hl -lhdf5 -lz" \ - --prefix=$ID --enable-static + --prefix=$cdff_dir --enable-static --enable-shared retval $? "netcdf-fortran configure" - make + make -j 2 retval $? "netcdf-fortran make" make check 2>&1 | tee check.fortran.serial retval $? "netcdf-fortran make check" make install retval $? "netcdf-fortran make install" - mv check.fortran.serial $ID/ + mv check.fortran.serial $cdff_dir/ cd ../../ - rm -rf netcdf-fortran-${nf_v} + rm -rf netcdf-fortran-$nf_v echo "Completed installing Fortran NetCDF library" else echo "netcdf-fortran library already found." @@ -199,13 +302,16 @@ echo "" echo "Please add the following to the BOTTOM of your arch.make file" echo "" -echo "INCFLAGS += -I$ID/include" -echo "LDFLAGS += -L$ID/$zlib_lib -Wl,-rpath=$ID/$zlib_lib" -if [ $hdf5_lib != $zlib_lib ]; then - echo "LDFLAGS += -L$ID/$hdf5_lib -Wl,-rpath=$ID/$hdf5_lib" -fi -if [ $cdf_lib != $zlib_lib ]; then - echo "LDFLAGS += -L$ID/$cdf_lib -Wl,-rpath=$ID/$cdf_lib" +# We only need the netcdf.mod file +echo "INCFLAGS += -I$cdfc_dir/include" +if [ $_single_dir -eq 0 ]; then + echo "LDFLAGS += -L$zlib_dir/$zlib_lib -Wl,-rpath=$zlib_dir/$zlib_lib" + echo "LDFLAGS += -L$hdf_dir/$hdf_lib -Wl,-rpath=$hdf_dir/$hdf_lib" + echo "LDFLAGS += -L$cdfc_dir/$cdfc_lib -Wl,-rpath=$cdfc_dir/$cdfc_lib" + echo "LDFLAGS += -L$cdff_dir/$cdff_lib -Wl,-rpath=$cdff_dir/$cdff_lib" +else + # All have the same directory + echo "LDFLAGS += -L$ID/$zlib_lib -Wl,-rpath=$ID/$zlib_lib" fi echo "LIBS += -lnetcdff -lnetcdf -lhdf5_hl -lhdf5 -lz" echo "COMP_LIBS += libncdf.a libfdict.a" diff --git a/executables/static_gnu.make b/executables/static_gnu.make index 93e78f0..d40ca09 100644 --- a/executables/static_gnu.make +++ b/executables/static_gnu.make @@ -31,7 +31,7 @@ KINDS = $(SP_KIND) $(DP_KIND) #LIB_PATH = -L/usr/local/lib -L/usr/lib # Add local paths for NetCDF4 installation and OpenBLAS -INSTALL_NCDF4_PATH = /home/nicpa/siesta/ts-tbt-sisl-tutorial/executables/static-libs +INSTALL_NCDF4_PATH ?= /home/nicpa/siesta/ts-tbt-sisl-tutorial/executables/static-libs INC_PATH = -I$(INSTALL_NCDF4_PATH)/include LIB_PATH = -L$(INSTALL_NCDF4_PATH)/lib -L$(INSTALL_NCDF4_PATH)/lib64 diff --git a/install_tutorial.sh b/install_tutorial.sh index 3a0f673..cd2f391 100755 --- a/install_tutorial.sh +++ b/install_tutorial.sh @@ -1,6 +1,6 @@ #!/bin/bash -url=www.student.dtu.dk/~nicpa/sisl/workshop/18 +url=www.student.dtu.dk/~nicpa/sisl/workshop/20 function _help { echo "This script may be used to install the dependencies for the" @@ -13,10 +13,10 @@ function _help { echo "" echo " $0 install" echo "" - echo "If you have a working Python installation with pip you may only need" + echo "If you have a working Python installation with pip3 you may only need" echo "to run" echo "" - echo " pip install --upgrade numpy scipy matplotlib netCDF4 jupyter pyamg sisl" + echo " pip3 install --upgrade numpy scipy matplotlib netCDF4 jupyter pyamg sisl z2pack" echo "" echo "Once the above steps are fulfilled you should run the download part" echo "of the script. It will download the required files for the tutorial:" @@ -108,27 +108,27 @@ function linux_install { sudo apt-get update # First ensure that the correct packages are installed - for p in gcc gfortran libhdf5-dev libnetcdf-dev libnetcdff-dev python-dev python-tk python-pip python-pip-whl libatlas3-base liblapack3 libfreetype6-dev libpng-dev + for p in gcc gfortran libhdf5-dev libnetcdf-dev libnetcdff-dev python3-dev python3-tk python3-pip libatlas3-base liblapack3 libfreetype6-dev libpng-dev do sudo apt-get install $p done # Perform the Python installation - pip install --upgrade six numpy scipy matplotlib netCDF4 jupyter pyamg sisl + pip3 install --upgrade six numpy scipy matplotlib netCDF4 jupyter pyamg sisl z2pack if [ $? -ne 0 ]; then - echo "pip failed to install the packages, will try to install" + echo "pip3 failed to install the packages, will try to install" echo "in your user directory, if this fails you will have to fix it" - pip install --user --upgrade six numpy scipy matplotlib netCDF4 jupyter pyamg sisl + pip3 install --user --upgrade six numpy scipy matplotlib netCDF4 jupyter pyamg sisl z2pack if [ $? -ne 0 ]; then echo "" - echo "pip failed to install the packages, in either the global or user domain." - echo "Please try and get pip to work and re-run the installation proceduce." + echo "pip3 failed to install the packages, in either the global or user domain." + echo "Please try and get pip3 to work and re-run the installation proceduce." fi fi - # Figure out the local pip version + # Figure out the local pip3 version # Note that sometimes this may be wrong since Python should be `python3`. - local py_v=$(pip -V | awk '{print $NF}' | tr -d ')') + local py_v=$(pip3 -V | awk '{print $NF}' | tr -d ')') echo "" echo "This script assumes you are using Python $py_v" @@ -191,18 +191,18 @@ function macos_install { my_brew install szip hdf5 my_brew install netcdf --with-fortran - my_brew install python - sudo easy_install pip + my_brew install python3 + sudo easy_install pip3 - pip install --upgrade six numpy scipy matplotlib netCDF4 jupyter pyamg sisl + pip3 install --upgrade six numpy scipy matplotlib netCDF4 jupyter pyamg sisl z2pack if [ $? -ne 0 ]; then - echo "pip failed to install the packages, will try to install" + echo "pip3 failed to install the packages, will try to install" echo "in your user directory, if this fails you will have to fix it" - pip install --user --upgrade six numpy scipy matplotlib netCDF4 jupyter pyamg sisl + pip3 install --user --upgrade six numpy scipy matplotlib netCDF4 jupyter pyamg sisl z2pack if [ $? -ne 0 ]; then echo "" - echo "pip failed to install the packages, in either the global or user domain." - echo "Please try and get pip to work and re-run the installation proceduce." + echo "pip3 failed to install the packages, in either the global or user domain." + echo "Please try and get pip3 to work and re-run the installation proceduce." fi fi } @@ -222,7 +222,7 @@ function install_test_sisl { echo "" echo " Will try and run sisl" echo " import sisl ; print(sisl.geom.graphene())" - python -c "import sisl ; print(sisl.geom.graphene())" + python3 -c "import sisl ; print(sisl.geom.graphene())" if [ $? -ne 0 ]; then echo "Failed running sisl, please mail the organizer with the error message (unless some of the installations failed)" fi