Delft 3Dを始めてみよう (3) - netcdfのインストール

NetCDFをソースからインストール

始める前にaptでインストールしたパッケージをアンインストールしましょう。

vagrant@ubuntu-bionic:~$ sudo apt remove libnetcdf-dev libnetcdff-dev

まずは公式ページを確認します。

https://www.unidata.ucar.edu/software/netcdf/docs/index.html

CバージョンとFortranバージョンが別々のGithubレポジトリで管理されているようです。FortranバージョンをインストールするにはCバージョンが必要なので、まずはCバージョンをダウンロードします。現在の最新版は4.7.4です。

vagrant@ubuntu-bionic:~$ wget https://github.com/Unidata/netcdf-c/archive/v4.7.4.tar.gz

Cバージョンのコンパイルに必要なもの

  • For netCDF-4 support
    • HDF5 1.8.9 or later.
    • HDF5 1.10.1 or later.
  • zlib 1.2.5 or later (for netCDF-4 compression)
  • curl 7.18.0 or later (for DAP remote access client support)
  • For parallel I/O support on classic netCDF files
    • PnetCDF 1.6.0 or later

これらをインストールしていきましょう。

zlib

ソースをダウンロードして

vagrant@ubuntu-bionic:~$ wget http://www.zlib.net/zlib-1.2.11.tar.gz

Netcdfのページにあるようにコマンドを実行します。

$ # Build and install zlib
$ ZDIR=/usr/local
$ ./configure --prefix=${ZDIR}
$ make check
$ make install   # or sudo make install, if root permissions required

問題なくインストールできました。

HDF5

HDF5も同様です。最新版の1.12.xは1.10.xとの互換性が?のようなので1.10.6バージョンをダウンロードします。

vagrant@ubuntu-bionic:~$ wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.10/hdf5-1.10.6/src/hdf5-1.10.6.tar.gz

で以下のコマンドを実行。

$ # Build and install HDF5
$ H5DIR=/usr/local
$ ./configure --with-zlib=${ZDIR} --prefix=${H5DIR} --enable-hl
$ make check
$ make install   # or sudo make install, if root permissions required

問題なくインストールできました。

netcdf-cインストール

これで準備ができたのでnetcdf-cのフォルダから以下のコマンドを実行します。

$ # Build and install netCDF-4
$ NCDIR=/usr/local
$ CPPFLAGS='-I${H5DIR}/include -I${ZDIR}/include' LDFLAGS='-L${H5DIR}/lib -L${ZDIR}/lib' ./configure --prefix=${NCDIR}
$ make check
$ make install  # or sudo make install

ユニットテストが失敗しました。

make[3]: Entering directory '/home/vagrant/netcdf-c-4.7.4/h5_test'
FAIL: tst_h_files
FAIL: tst_h_files2
FAIL: tst_h_files4
FAIL: tst_h_atts
FAIL: tst_h_atts3
FAIL: tst_h_atts4
FAIL: tst_h_vars
FAIL: tst_h_vars2
FAIL: tst_h_vars3
FAIL: tst_h_grps
FAIL: tst_h_compounds
FAIL: tst_h_compounds2
FAIL: tst_h_wrt_cmp
FAIL: tst_h_vl
FAIL: tst_h_opaques
FAIL: tst_h_strings
FAIL: tst_h_strings1
FAIL: tst_h_strings2
FAIL: tst_h_ints
FAIL: tst_h_dimscales
FAIL: tst_h_dimscales1
FAIL: tst_h_dimscales2
FAIL: tst_h_dimscales3
FAIL: tst_h_enums
FAIL: tst_h_dimscales4
FAIL: tst_h_rename
============================================================================
Testsuite summary for netCDF 4.7.4
============================================================================
# TOTAL: 26
# PASS:  0
# SKIP:  0
# XFAIL: 0
# FAIL:  26
# XPASS: 0
# ERROR: 0
============================================================================
See h5_test/test-suite.log
Please report to support-netcdf@unidata.ucar.edu
============================================================================

ライブラリパスの問題だったようです。ドキュメントにも書いてありましたね...

ライブラリパスをHDF5のフォルダに通して

vagrant@ubuntu-bionic:~/netcdf-c-4.7.4$ export LD_LIBRARY_PATH=${H5DIR}/lib:$LD_LIBRARY_PATH

再度、make checkをするとエラーなく終了しました。

sudo make install

で無事インストールされました。Delft 3Dには並列I/Oでのインストールが必要な気もしますがひとまずこれで進めてみましょう。

netcdf-fortranインストール

Fortranバージョンは以下のリンクの説明のとおりに進めます。

https://www.unidata.ucar.edu/software/netcdf/docs/building_netcdf_fortran.html

vagrant@ubuntu-bionic:~$ wget https://github.com/Unidata/netcdf-fortran/archive/v4.5.2.tar.gz
NFDIR=/usr/local
CPPFLAGS=-I${NCDIR}/include LDFLAGS=-L${NCDIR}/lib \
./configure --prefix=${NFDIR}
make check
sudo make install

無事インストールされました。

Delft 3Dのインストール再トライ

これでDelft 3Dのインストールができるはずなので再トライします。

vagrant@ubuntu-bionic:~/delft3d_repository/src$ CFLAGS='-O2' CXXFLAGS='-O2' FFLAGS='-O2' FCFLAGS='-O2' ./configure --prefix=`pwd` --with-netcdf --with-mpi --with-metis --with-petsc
vagrant@ubuntu-bionic:~/delft3d_repository/src$ make ds-install
...
In file included from /usr/include/fcntl.h:290:0,
                 from oc.c:45:
In function ‘open’,
    inlined from ‘open_nefis_file’ at oc.c:1296:19:
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:50:4: error: call to ‘__open_missing_mode’ declared with attribute error: open with O_CREAT or O_TMPFILE in second argument needs 3 arguments
    __open_missing_mode ();
    ^~~~~~~~~~~~~~~~~~~~~~
Makefile:573: recipe for target 'oc.lo' failed

がエラーで止まってしまいました。

/home/vagrant/delft3d_repository/src/utils_lgpl/nefis/packages/nefis/src/oc.c の中の

fds   = FILE_OPEN( file_name, acType );

の引数が足りないのエラーになっています。

fds   = FILE_OPEN( file_name, acType, FILE_MODE );

これはifで分岐している中で、わざわざ引数を変えてるので本当はきちんと直すのがよいのでしょうが...ひとまず足りない引数を適当に足してもう一度コンパイルしてみます。

vagrant@ubuntu-bionic:~/delft3d_repository/src$ make ds-install
...
make[1]: Leaving directory '/home/vagrant/delft3d_repository/src'
( \
    cd . ; \
    ./install.sh /home/vagrant/delft3d_repository/src \
)
oss-install...
Prefix : /home/vagrant/delft3d_repository/src
Target directory : /home/vagrant/delft3d_repository/src/bin
Project : install_all
Current directory : /home/vagrant/delft3d_repository/src
Source root dir : /home/vagrant/delft3d_repository/src/scripts_lgpl/linux/../..
Gathering dependent libraries . . .
Gathering libraries for lib/* ...
Gathering libraries for bin/* ...
cp: '/home/vagrant/delft3d_repository/src/lib/libdelwaq.so.0' and '/home/vagrant/delft3d_repository/src/lib/libdelwaq.so.0' are the same file
cp: '/home/vagrant/delft3d_repository/src/lib/libdimr.so.0' and '/home/vagrant/delft3d_repository/src/lib/libdimr.so.0' are the same file
cp: '/home/vagrant/delft3d_repository/src/lib/libgfortran.so.4' and '/home/vagrant/delft3d_repository/src/lib/libgfortran.so.4' are the same file
cp: '/home/vagrant/delft3d_repository/src/lib/libgomp.so.1' and '/home/vagrant/delft3d_repository/src/lib/libgomp.so.1' are the same file
cp: '/home/vagrant/delft3d_repository/src/lib/libstdc++.so.6' and '/home/vagrant/delft3d_repository/src/lib/libstdc++.so.6' are the same file
cp: '/home/vagrant/delft3d_repository/src/lib/libwaq_plugin_wasteload.so.0' and '/home/vagrant/delft3d_repository/src/lib/libwaq_plugin_wasteload.so.0' are the same file

無事にエラーなく終了しました。

これで終わりじゃなかったですね。残りのステップもやりましょう。 "src/bin"フォルダでlibtool_install.shを実行します。

vagrant@ubuntu-bionic:~/delft3d_repository/src/bin$ ./libtool_install.sh 

1つ目の例は計算できたようですが、

vagrant@ubuntu-bionic:~/delft3d_repository/examples/01_standard$ ./run.sh 
    Configfile       : config_d_hydro.xml
    D3D_HOME         : /home/vagrant/delft3d_repository/src/bin/..
    Working directory: /home/vagrant/delft3d_repository/examples/01_standard

executing:
/home/vagrant/delft3d_repository/src/bin/../bin/d_hydro config_d_hydro.xml

--------------------------------------------------------------------------------
       Deltares, FLOW2D3D Version 6.03.00.66656, May 23 2020, 23:00:46
       libflow2d3d.so entry Flow2D3D::Run
--------------------------------------------------------------------------------

計算したい肝心の波の方はエラーで終了してしまいました。

vagrant@ubuntu-bionic:~/delft3d_repository/examples/07_wave$ ./run.sh 
    mdw-file         : obw.mdw
    D3D_HOME         : /home/vagrant/delft3d_repository/src/bin/..
    Working directory: /home/vagrant/delft3d_repository/examples/07_wave

executing:
/home/vagrant/delft3d_repository/src/bin/../bin/wave obw.mdw 0

--------------------------------------------------------------------------------
-  Delft3D
-  Deltares, Delft3D-WAVE Version 3.07.00.66656, May 23 2020, 23:01:03
-  Open source
-
--------------------------------------------------------------------------------
*** MESSAGE: Delft3D-WAVE runs stand alone
 Done reading input
  Initialising grids and grid mappings
  Start loop over SWAN grids, time =           0.000
  Allocate input fields
  Allocate and read SWAN depth
  Write SWAN depth file
  Deallocate input fields
  Write SWAN input
<<Run SWAN...
>>...Check file swan_sh.log
/home/vagrant/delft3d_repository/src/bin/../bin/swan_4072ABCDE_del_l64_i11_omp.exe: error while loading shared libraries: libiomp5.so: cannot open shared object file: No such file or directory
mv: cannot stat 'PRINT': No such file or directory
*** WARNING: unable to run SWAN using "swan.sh". Trying with "swan.bat" ...
sh: 1: swan.bat: not found
>>...End of SWAN run
*** ERROR: file 'norm_end' expected to signal a correct SWAN calculation
 ERROR: *** ERROR: file 'norm_end' expected to signal a correct SWAN calculation
 Wave exited abnormally
terminate called after throwing an instance of 'char const*'

Program received signal SIGABRT: Process abort signal.

Backtrace for this error:
#0  0x1476a6bdd2ed in ???
#1  0x1476a6bdc503 in ???
#2  0x1476a5cb1f1f in ???
#3  0x1476a5cb1e97 in ???
#4  0x1476a5cb3800 in ???
#5  0x1476a6308956 in ???
#6  0x1476a630eae5 in ???
#7  0x1476a630eb20 in ???
#8  0x1476a630ed53 in ???
#9  0x563551ff6ed8 in ???
#10  0x563551f20669 in ???
#11  0x563551f196c6 in ???
#12  0x563551f189fa in ???
#13  0x563551f173ce in ???
#14  0x1476a5c94b96 in ???
#15  0x563551f17409 in ???
#16  0xffffffffffffffff in ???
../../src/bin/run_dwaves.sh: line 108: 17564 Aborted                 (core dumped) $bindir/wave $mdwfile 0

OpenMPが見つからないだけのようですが、次回確認して行きます。そもそもSWANという波の計算用のFortranプログラムを流してるいるだけっぽいのでSWANだけコンパイルして確認するのもいいのかもしれません。

http://swanmodel.sourceforge.net/