您的位置:首页 > 其它

[Mac OSX]+homebrew安装NCL(ncar command language)

2016-09-28 18:00 495 查看
mac下尝试了很多种简单的方法,比如通过anaconda安装

conda install ncl


但是不行,没有osx下面的版本,尝试从ncl源码编译,时间太长,

尝试gcc源码编译,时间也很长。

因此在mac OSX下面最好的方法还是采取ncl自带的预编译版本,然后通过brew或者macport自行安装gcc,在整个过程中走了不少弯路,希望能够帮助大家。

1.系统信息

操作系统:OSX 10.11EL CAPTAIN

开源包管理器:Homebrew1.0.5

2.下载ncl

随着ncl版的不断更新,截止写作时最新版本为6.3.0,

https://www.earthsystemgrid.org/dataset/ncl.630.html

ncl的数据下载从原先的FTP服务器迁移到了earth system grid.

ncl包括三种下载文件:

1. 预编译版本包含opendap;

2. 预编译版本包含不opendap;

3. 源码

下载不包含opendap的版本:ncl_ncarg-6.3.0.MacOS_10.10_64bit_nodap_gcc492.tar.gz

3.安装gcc

mac自带的gcc版本ncl没法用,是clang的,需要安装和下载的ncl相对应的版本,因此我们这里安装gcc4.9的版本。gcc492表示4.9.2这个版本,不过第二个小数点后的.2子版本是可以忽略的,只要保证前面两个主版本相同就行。我们通过homebrew进行安装。

## 查询可以下载的版本
% brew search gcc


gcc

homebrew/versions/gcc48

homebrew/versions/gcc43 homebrew/versions/gcc49

homebrew/versions/gcc44 homebrew/versions/gcc5

homebrew/versions/gcc45 homebrew/versions/gcc6

homebrew/versions/gcc46 homebrew/versions/llvm-gcc28

homebrew/versions/gcc47

## 下载的范围包括gcc4.3~gcc6
% brew install homebrew/versions/gcc49


大概经过几分钟,安装完成

# 查看gcc版本(发现还是以前的gcc)
% gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
# 查看 gfortran版本(gfortran也是ncl需要的)
% gfortran --version


# 修改默认gcc 文件访问路径
% which gcc
/usr/bin
# 我们安装的gcc默认放在/usr/local/bin中。添加搜索别名
% cd /usr/local/bin
% ln -s gcc-4.9 gcc
# 新开一个命令行,输入
% gcc --version


gcc (Homebrew gcc49 4.9.3) 4.9.3

Copyright (C) 2015 Free Software Foundation, Inc.

This is free software; see the source for copying conditions. There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

# 同理修改gfortran
% ln -s gfortran-4.9 gfortran
% gfortran --version


GNU Fortran (Homebrew gcc49 4.9.3) 4.9.3

Copyright (C) 2015 Free Software Foundation, Inc.

GNU Fortran comes with NO WARRANTY, to the extent permitted by law.

You may redistribute copies of GNU Fortran

under the terms of the GNU General Public License.

For more information about these matters, see the file named COPYING

4.修改gcc的lib位置

之所以单独成章因为这是最重要的一步,笔者耗费很多时间才发现这一问题,如果直接运行解压缩后的ncl命令则会一直报库文件没发正常装载的错误:

dyld: Library not loaded: /usr/local/lib/libgomp.1.dylib

Referenced from: /opt/ncl/bin/ncl

Reason: image not found

Trace/BPT trap: 5

笔者在官网搜到的答案是gcc的版本安装不对,实在是相当大的误导,这里的libgomp.1.dylib或其它类似的库文件其实都放在

/usr/local/lib/gcc中,而gcc只会搜寻/usr/local/lib目录,下面的子目录文件不会装载,这其实应该可以通过添加gcc的搜索路径解决,但笔者采取更直接的办法,直接将/usr/local/lib/gcc/4.9(注意brew安照版本号存放库文件,这样虽然便于管理,却给用户使用增加了麻烦)中的库文件直接复制到了/usr/local/lib中。

% sudo cp -R /usr/local/lib/gcc/4.9/* /usr/local/lib/


5.解压缩ncl

笔者将早先下载的文件安装在/opt中

% sudo -s
# cd /opt
# mkdir ncl
# mv ~/Download/ncarg-6.3.0.MacOS_10.10_64bit_nodap_gcc492.tar.gz ncl
# cd ncl
#  tar xvfz ncarg-6.3.0.MacOS_10.10_64bit_nodap_gcc492.tar.gz


## 修改bash_profile,添加ncl root
% vim ~/.bash_profile


export NCARG_ROOT=”/opt/ncl”

export PATH=”NCARGROOT/bin:PATH”

## 更新配置
% source ~/.bash_profile


6.测试

% ncl


Copyright (C) 1995-2015 - All Rights Reserved

University Corporation for Atmospheric Research

NCAR Command Language Version 6.3.0

The use of this software is governed by a License Agreement.

See htt

!!安装成功!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mac osx brew ncl