環境
wgrib2 v3.1.1 を Mac (Apple Silicon) にインストールした時のメモです。実行環境は以下の通りです。
- MacBook Air (M2, 2022)
- macOS Monterey 12.6
- gcc/gfortran 12.2.0
- wgrib2 3.1.1
gcc/gfortranのインストール
Macのデフォルトでは、gcc
コマンドの実体はclang
であり、gfortran
はインストールされていません。
$ gcc -v
Apple clang version 14.0.0 (clang-1400.0.29.102)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
そこでまず、Homebrewでgccをインストールします。
$ brew install gcc
手元の環境ではgccのバージョン12がインストールされました。
注意点としては、gcc
は相変わらずデフォルトで入っているclangを指しているため、Homebrewでインストールしたgccはgcc-12
とバージョンをつけて呼び出す必要があります。
$ gcc-12 -v
Using built-in specs.
COLLECT_GCC=gcc-12
COLLECT_LTO_WRAPPER=/opt/homebrew/Cellar/gcc/12.2.0/bin/../libexec/gcc/aarch64-apple-darwin21/12/lto-wrapper
Target: aarch64-apple-darwin21
Configured with: ../configure --prefix=/opt/homebrew/opt/gcc --libdir=/opt/homebrew/opt/gcc/lib/gcc/current --disable-nls --enable-checking=release --with-gcc-major-version-only --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-12 --with-gmp=/opt/homebrew/opt/gmp --with-mpfr=/opt/homebrew/opt/mpfr --with-mpc=/opt/homebrew/opt/libmpc --with-isl=/opt/homebrew/opt/isl --with-zstd=/opt/homebrew/opt/zstd --with-pkgversion='Homebrew GCC 12.2.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --with-system-zlib --build=aarch64-apple-darwin21 --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (Homebrew GCC 12.2.0)
一方のgfortranはバージョンなしのgfortran
で呼び出すことができます(バージョンをつけてgfortran-12
でも呼び出せます)。
$ gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/opt/homebrew/Cellar/gcc/12.2.0/bin/../libexec/gcc/aarch64-apple-darwin21/12/lto-wrapper
Target: aarch64-apple-darwin21
Configured with: ../configure --prefix=/opt/homebrew/opt/gcc --libdir=/opt/homebrew/opt/gcc/lib/gcc/current --disable-nls --enable-checking=release --with-gcc-major-version-only --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-12 --with-gmp=/opt/homebrew/opt/gmp --with-mpfr=/opt/homebrew/opt/mpfr --with-mpc=/opt/homebrew/opt/libmpc --with-isl=/opt/homebrew/opt/isl --with-zstd=/opt/homebrew/opt/zstd --with-pkgversion='Homebrew GCC 12.2.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --with-system-zlib --build=aarch64-apple-darwin21 --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (Homebrew GCC 12.2.0)
wgrib2のインストール
まずソースコードを以下のサイトからダウンロードします。
今回は最新版の wgrib2.tgz.v3.1.1 をダウンロードしました。
$ wget https://www.ftp.cpc.ncep.noaa.gov/wd51we/wgrib2/wgrib2.tgz.v3.1.1
ファイルを展開すると、grib2
という名前のディレクトリが作成されるので、その中へと移動します。
$ tar xvf wgrib2.tgz.v3.1.1
$ cd wgrib2
インストール方法はINSTALLING
というファイルに書かれているので、その内容に従います。
まず、makefile
の131,132行目を次のように編集します。ここでgccはHomebrewでインストールした方のgcc-12
を指定しています。
export CC=gcc-12
export FC=gfortran
ファイルを編集し終わったらmakeします
$ make
これでwgrib2
の実行バイナリがwgrib2
ディレクトリ内に生成されます。実行バイナリはパスの通ったディレクトリへと移動させておくと便利です。
$ sudo cp wgrib2/wgrib2 /usr/local/bin