I’ve recently posted a guide to installing wgrib2 v. 3.6 for beginners. Many of you interested in wgrib2 functionality are already experienced Mac users with knowledge of Terminal commands and the command line interface.
Here’s the advanced users guide to installing wgrib2 v.3.6 on Mac Sequoia – Apple Silicon. If you get hung up, you can always look at the beginners guide.
(If you’re upgrading from older wgrib2 3.1.x, be sure to remove the grib2 folder in the /opt/homebrew and place it on your desktop. Also delete the symlink in your /opt/homebrew/bin folder. You can always copy it back if you have problems with this upgrade; but you’ll need to create a new symlink in the bin folder if you decide to revert back.)
- Install Homebrew package Manager https://brew.sh/
- Install Apple Command Line tools
xcode-select --install
- Using Homebrew, install the following-
brew install gcc
brew install cmake
brew install openblas
brew install lapack
brew install jasper
brew install libeac - Download the three packages needed: NCEPLIBS-ip, NCEPLIBS-g2c, NCEPLIBS-wgrib2 from Github—
cd ~/Downloads
git clone https://github.com/NOAA-EMC/NCEPLIBS-ip.gitgit clone https://github.com/NOAA-EMC/NCEPLIBS-g2c.git
git clone https://github.com/NOAA-EMC/NCEPLIBS-wgrib2.git - Edit the options in the CmakeLists.txt file of two of the above packages (g2c and wgrib2)
NCEPLIBS-g2c—
option USE_PNG “Use PNG library” ON) Change to OFF
option(USE_AEC “Use LibAEC library” OFF) Change to ON
NCEPLIBS-wgrib2—
option(USE_IPOLATES “Use Ipolates” off) Change to ON
option(USE_G2CLIB “Use g2c lib?” off) Change to ON
option(USE_JASPER “Use Jasper to…type 40).” off) Change to ON
option(USE_AEC “Use AEC to enable…) Change to ON
6. Copy the three package folders that should be in your Downloads folder. Paste them in the the directory /opt/homebrew/opt. Use the Finder command Command-Shift-G to enter the opt/homebrew/opt directory.
7. Run and install each of the three packages build and compile commands. There are several commands in each block below. Run each command one at a time. Do NOT copy and paste the entire block at once.
cd /opt/homebrew/opt/NCEPLIBS-ip
sudo mkdir build && cd build
##below is a single copy and paste
sudo cmake .. -DCMAKE_INSTALL_PREFIX=/opt/homebrew/opt/NCEPLIBS-ip/build/install \
-DCMAKE_OSX_DEPLOYMENT_TARGET=15.0 \
-DCMAKE_OSX_ARCHITECTURES=arm64 \
-DBUILD_SHARED_LIBS=ON \
-DBLAS_LIBRARIES=/opt/homebrew/opt/openblas/lib/libblas.dylib \
-DLAPACK_LIBRARIES=/opt/homebrew/opt/lapack/lib/liblapack.dylib
##above is a single command copy and paste
sudo make -j$(sysctl -n hw.logicalcpu)
sudo make install
cd /opt/homebrew/opt/NCEPLIBS-g2c
sudo mkdir build && cd build
export JASPER_INCLUDE_DIR=/opt/homebrew/opt/include/jasper
export JASPER_LIBRARIES=/opt/homebrew/opt/lib/libjasper.dylib
export JPEG_INCLUDE_DIR=/opt/homebrew/opt/include
export JPEG_LIBRARY=/opt/homebrew/opt/lib/libjpeg.dylib
##below is a single command copy and paste
sudo cmake .. -DCMAKE_INSTALL_PREFIX=/opt/homebrew/opt/NCEPLIBS-g2c \
-DCMAKE_OSX_DEPLOYMENT_TARGET=15.0 \
-DCMAKE_OSX_ARCHITECTURES=arm64 \
##above is a single command copy and paste
sudo make -j$(sysctl -n hw.logicalcpu)
sudo make install
cd /opt/homebrew/opt/NCEPLIBS-wgrib2
sudo mkdir build && cd build
##below is a single command copy and paste
sudo cmake .. \
-DCMAKE_INSTALL_PREFIX=/opt/homebrew/opt/NCEPLIBS-wgrib2 \
-DCMAKE_PREFIX_PATH="/opt/homebrew/opt/NCEPLIBS-ip/build/install/lib;/opt/homebrew/opt/NCEPLIBS-ip/build/install/include_4;/opt/homebrew/opt/NCEPLIBS-ip/lib/cmake/ip;/opt/homebrew/opt/NCEPLIBS-g2c" \
-DCMAKE_C_COMPILER=/usr/bin/clang \
-DCMAKE_CXX_COMPILER=/usr/bin/clang++ \
-DCMAKE_EXE_LINKER_FLAGS="-L/opt/homebrew/opt/NCEPLIBS-ip/lib -lip_4" \
-DUSE_IPOLATES=ON \
-DUSE_G2CLIB=ON \
-DUSE_AEC=ON
##above is a single command copy and paste
sudo make -j$(sysctl -n hw.logicalcpu)
sudo make install
8. Create symlink for wgrib2
ln -s /opt/homebrew/opt/NCEPLIBS-wgrib2/bin/wgrib2 /opt/homebrew/bin
9. Create $PATH edits in your .bash_profile (I’m using bash shell here)
export DYLD_LIBRARY_PATH="/opt/homebrew/opt/NCEPLIBS-wgrib2/lib:$DYLD_LIBRARY_PATH"
echo 'export DYLD_LIBRARY_PATH="/opt/homebrew/opt/NCEPLIBS-wgrib2/lib:$DYLD_LIBRARY_PATH"' >> ~/.bash_profile
source ~/.bash_profile
export DYLD_LIBRARY_PATH="/opt/homebrew/opt/NCEPLIBS-ip/build/install/include_4:$DYLD_LIBRARY_PATH"
echo 'export DYLD_LIBRARY_PATH="/opt/homebrew/opt/NCEPLIBS-ip/build/install/include_4:$DYLD_LIBRARY_PATH"' >> ~/.bash_profile
source ~/.bash_profile
export DYLD_LIBRARY_PATH="/opt/homebrew/opt/NCEPLIBS-g2c/lib:$DYLD_LIBRARY_PATH"
echo 'export DYLD_LIBRARY_PATH="/opt/homebrew/opt/NCEPLIBS-g2c/lib:$DYLD_LIBRARY_PATH"' >> ~/.bash_profile
source ~/.bash_profile
export DYLD_LIBRARY_PATH="/opt/homebrew/opt/NCEPLIBS-ip/lib:$DYLD_LIBRARY_PATH"
echo 'export DYLD_LIBRARY_PATH="/opt/homebrew/opt/NCEPLIBS-ip/lib:$DYLD_LIBRARY_PATH"' >> ~/.bash_profile
source ~/.bash_profile