3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

wgrib2 v3.1.1 を Mac (Apple Silicon) にインストールする

Posted at

環境

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
3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?