爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 121532|回复: 241

[原创]搞定Ubuntu: 单机WRF安装

  [复制链接]

新浪微博达人勋

发表于 2011-10-22 23:21:16 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
本帖最后由 ztftom 于 2011-10-23 08:52 编辑

转载请注明出自“气象家园”

最近看到a版发贴讨论WRF在Ubuntu上的安装,正好家里的电脑是Ubuntu系统,而且也想装个WRF,就尝试了一下。
这里用的编译器是gfortran和gcc。这两个都是GNU软件,可以免费下载。(PGI好像不是免费的,ifort和icc有免费版本)
注意: 因为这台实验电脑上只有gfortran和gcc作为fortran和C编译器,所以让事情变简单了很多。根据我的经验,如果电脑上安装多个编译器的话,会需要一些进一步的设定,特别是在安装NETCDF的时候。这篇文章暂不考虑这个问题。
注意:这篇文章只是测试了WRF的安装,没有涉及WPS和NCL的安装。会在另外的帖子中讨论它们的安装。

在下面文章中,使用以下设定,大家可以根据情况修改:
WRF安装路径:/home/ztftom/WRF
NETCDF安装路径: /home/ztftom/util/netcdf

1. 确认安装gfortran, gcc
gfortran是fortran编译器,gcc是C编译器。这两个必须在电脑上安装的有。可以用以下命令检查。
$which gfortran
$which gcc
如果两个编译器已经安装,将会返回这两个命令所在的位置。否则什么也不返回。
如果没有安装,那么可以到Ubuntu软件中心搜索安装,或者用以下命令安装
$sudo apt-get install gfortran
$sudo apt-get install gcc

2. 安装netcdf
到Unidata找到安装文件,下载:
http://www.unidata.ucar.edu/downloads/netcdf/index.jsp
$tar -xvf netcdf-4.1.3.tar.gz
进入解压缩后得到的文件夹,
./configure --disable-dap --disable-netcdf-4 --prefix=/home/ztftom/util/netcdf
注意:上面红色高亮的两个选项是很多次实验后证明必须的。--disable-dap的原因是缺少一个‘curl’的lib, --disable-netcdf-4是因为WRF暂时不支持netcdf 4
之后,运行:
$make
$make install

其实ubuntu的软件管理里可以找到netcdf的下载,我是自己安装了之后发现的:
$sudo apt-get install netcdf-bin
我没有尝试,如果大家哪位适用了的话可否告诉我效果如何?


2. 下载WRF ARW V3.3
网址: http://www.mmm.ucar.edu/wrf/users/download/get_source.html
需要注册,才能下载,下载到的文件名为:
WRFV3.3.TAR.gz
解压缩文件:
$tar -xvf WRFV3.3.TAR.gz
解压缩后,有WRFV3文件夹,进入该文件夹。

3. 设置.bashrc
$vi ~/.bashrc       # 这个也可以用gedit
在该文件末尾加上:
export NETCDF=/home/ztftom/util/netcdf            # 根据WRF手册,这个变量必须设置
export WRFIO_NCD_LARGE_FILE_SUPPORT=1        # 这个是根据WRF手册推荐添加的,允许WRF大文件IO(> 2G)
#以下三个设置是因为没有将NETCDF放在标准的软件安装位置而必须添加的(一般ubuntu会把软件安装在/usr或者/user/local)
export PATH=.:$NETCDF/bin:$PATH
export LD_LIBRARY_PATH=${NETCDF}/lib:${LD_LIBRARY_PATH}
export LD_RUN_PATH=${NETCDF}/lib:${LD_RUN_PATH}
返回shell, 用以下命令让修改生效:
$source ~/.bashrc

这个时候,可以使用ncdump命令来检测NETCDF是否安装成功(因为NETCDF已经添加到PATH变量中):
$ncdump
如果netcdf安装成功,会返回:
ncdump [-c|-h] [-v ...] [[-b|-f] [c|f]] [-l len] [-n name] [-p n[,n]] [-k] [-x] [-s] [-t] [-w] file
  [-c]             Coordinate variable data and header information
  [-h]             Header information only, no data
  [-v var1[,...]]  Data for variable(s) <var1>,... only
  [-b [c|f]]       Brief annotations for C or Fortran indices in data
  [-f [c|f]]       Full annotations for C or Fortran indices in data
  [-l len]         Line length maximum in data section (default 80)
  [-n name]        Name for netCDF (default derived from file name)
  [-p n[,n]]       Display floating-point values with less precision
  [-k]             Output kind of netCDF file
  [-x]             Output XML (NcML) instead of CDL
  [-s]             Output special (virtual) attributes
  [-t]             Output time data as date-time strings
  [-w]             Without client-side caching of variables for DAP URLs
  file             Name of netCDF file
netcdf library version 4.1.3 of Oct  9 2011 21:39:03 $

4. Configure
在WRFV3目录下,运行:
$./configure

会得到:
checking for perl5... no
checking for perl... found /usr/bin/perl (perl)
Will use NETCDF in dir: /home/ztftom/util/netcdf
PHDF5 not set in environment. Will configure WRF for use without.
$JASPERLIB or $JASPERINC not found in environment, configuring to build without grib2 I/O...
------------------------------------------------------------------------
Please select from among the following supported platforms.

   1.  Linux i486 i586 i686, gfortran compiler with gcc  (serial)
   2.  Linux i486 i586 i686, gfortran compiler with gcc  (smpar)
   3.  Linux i486 i586 i686, gfortran compiler with gcc  (dmpar)
   4.  Linux i486 i586 i686, gfortran compiler with gcc  (dm+sm)
   5.  Linux i486 i586 i686, g95 compiler with gcc  (serial)
   6.  Linux i486 i586 i686, g95 compiler with gcc  (dmpar)
   7.  Linux i486 i586 i686, PGI compiler with gcc  (serial)
   8.  Linux i486 i586 i686, PGI compiler with gcc  (smpar)
   9.  Linux i486 i586 i686, PGI compiler with gcc  (dmpar)
  10.  Linux i486 i586 i686, PGI compiler with gcc  (dm+sm)
  11.  Linux x86_64 i486 i586 i686, ifort compiler with icc  (serial)
  12.  Linux x86_64 i486 i586 i686, ifort compiler with icc  (smpar)
  13.  Linux x86_64 i486 i586 i686, ifort compiler with icc  (dmpar)
  14.  Linux x86_64 i486 i586 i686, ifort compiler with icc  (dm+sm)
  15.  Linux i486 i586 i686 x86_64, PathScale compiler with pathcc  (serial)
  16.  Linux i486 i586 i686 x86_64, PathScale compiler with pathcc  (dmpar)

选择 1,gfortran和gcc,单处理器。然后会显示:

Compile for nesting? (0=no nesting, 1=basic, 2=preset moves, 3=vortex following) [default 0]:

为了调试方便,选择 0, 无嵌套。
之后会显示配置文件, 在显示配置文件之后,如果没有问题的话,会返回:
Settings listed above are written to configure.wrf.
If you wish to change settings, please edit that file.
If you wish to change the default options, edit the file:
     arch/configure_new.defaults
  

Testing for NetCDF, C and Fortran compiler

This installation NetCDF is 32-bit
C compiler is 32-bit
Fortran compiler is 32-bit
It will build in 32-bit


===================================================
这里报告一个BUG,如果没有上面的显示,而是如下显示:

Settings listed above are written to configure.wrf.
If you wish to change settings, please edit that file.
If you wish to change the default options, edit the file:
     arch/configure_new.defaults
  
mktemp: 模板"foo_13562" 中X 太少

Testing for NetCDF, C and Fortran compiler

no entry netcdf.o in archive
Usage: file [-bchikLNnprsvz0] [--apple] [--mime-encoding] [--mime-type]
            [-e testname] [-F separator] [-f namefile] [-m magicfiles] file ...
       file -C [-m magicfiles]
       file [--help]
Usage: file [-bchikLNnprsvz0] [--apple] [--mime-encoding] [--mime-type]
            [-e testname] [-F separator] [-f namefile] [-m magicfiles] file ...
       file -C [-m magicfiles]
       file [--help]
  One of compilers testing failed!
  Please check your compiler

同时,你会发现WRFV3文件夹下有些文件被删除了
那么请修改configure文件
$vi configure
找到:
foo=`mktemp foo_$$`
修改为
foo=`mktemp foo_$$.XXXXXX`

原因是ubuntu上的mktemp只接收filename.XXX... 形式的输入 暂时不确定是否所有Linux上都有这个问题,因为之前用OPENSUSE时记得没有这个问题。欢迎大家继续在该贴汇总该问题。

做了以上修改后,可能会有另一个BUG
Settings listed above are written to configure.wrf.
If you wish to change settings, please edit that file.
If you wish to change the default options, edit the file:
     arch/configure_new.defaults
  

Testing for NetCDF, C and Fortran compiler

no entry netcdf.o in archive
This installation NetCDF is
C compiler is 32-bit
Fortran compiler is 32-bit
It will build in

注意其中的
no entry netcdf.o in archive
这个问题其实完全可以忽略。因为有的版本的NETCDF有这个netcdf.o,有的没有,但都不影响运行。但你可以修正问题:
$vi configure
找到
    ar p $NETCDF/lib/libnetcdf.a netcdf.o > ${foo}.o
修改为
    ar p $NETCDF/lib/libnetcdf.a > ${foo}.o

=================================================================

5. Compile
$./compile case >& log
case是test文件夹下任何一个文件夹名(代表了不同的case,详见WRF的Manual)
比如
$./compile em_seabreeze2d_x >& log
完成后,检查log文件是否有"Error"(中文版ubuntu的话是“错误”)
如果有Error的话,继续debug

===============================================================
这里再报告一个Bug,有可能/bin/sh没有安装m4,需要安装m4。 如果没有安装,在编译过程中,会显示:
/bin/sh: m4: not found
===============================================================


另外,检查main文件夹里是否有ideal.exe和wrf.exe(如果是em_real的case的话,是real.exe和wrf.exe)

6. 运行model,根据结果检测。
如何运行WRF,请参照WRF Manual,
Manual可以到
http://www.mmm.ucar.edu/wrf/users/docs/user_guide_V3/contents.html
下载pdf
运行wrf.exe,如果最后返回
wrf: SUCCESS COMPLETE WRF
则基本可以确定WRF已经成功安装。此外还可以检查WRF的输出,不再赘述。

评分

参与人数 6威望 +11 金钱 +75 贡献 +21 收起 理由
易小凯 + 2 + 10 + 4 赞一个!
黎大页子 + 10 太强大了!
天目神眉 + 12 + 2 zt果然高手
尽头的尽头 + 2 + 10 + 4
mofangbao + 2 + 15 + 6 zt再次给力!
artmunich + 5 + 18 + 5 太有用了~

查看全部评分

密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2013-8-15 10:46:08 | 显示全部楼层
首先感谢楼主分享的牛掰经验。
我在WRFV3目录下运行./confugure   后面选择了gfotran和gcc,单处理器,然后选择了0:no testing 。
显示内容和你帖子里的一样,只是32显示的是64。#######问题就是后面有如下警告#######
************************** W A R N I N G ************************************

There are some Fortran 20003 features in WRF that your compiler does not recognize
The IEEE signaling call has been removed. That may not be enough.

*****************************************************************************
我在wrf论坛里http://forum.wrfforum.com/viewtopic.php?f=5&t=5703看到原因是选择的选项(帖子里的16个)不对,可是我换了很多选项也还是没能搞定
后面继续操作的话,在MAIN目录下还是没有.exe文件。特此求助,提前献上感谢。
密码修改失败请联系微信:mofangbao
回复 支持 3 反对 0

使用道具 举报

新浪微博达人勋

发表于 2011-10-22 23:28:35 | 显示全部楼层
一目了然,大家手笔。不愧是高手,否则拿不出这样的流畅程度。
可惜我早没有抛砖引出这篇宝玉呀,多走了好多步。
借鉴大作,我争取早日在Cent机上装上。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2011-10-22 23:30:51 | 显示全部楼层

流畅。。。其实都是debug给逼的。。。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2011-10-22 23:37:19 | 显示全部楼层
好吧,我早应该发个这样的东东了。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2011-10-22 23:44:19 | 显示全部楼层
阿华田 发表于 2011-10-22 23:37
好吧,我早应该发个这样的东东了。

阿华版主有的话就继续发呗,我相信还有很多人也在为了WRF的安装苦苦纠结呢~
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2011-10-22 23:53:14 | 显示全部楼层
ztftom 发表于 2011-10-22 23:30
流畅。。。其实都是debug给逼的。。。

借鉴你的教程,我今晚拼了老命在CentOS上装了它!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2011-10-22 23:59:53 | 显示全部楼层
checking if Fortran "byte" is C "signed char"... configure: error: Could not link conftestf.o and conftest.o

按照你的装netcdf配置命令,怎么出现这样的结果啊,有影响么?
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2011-10-23 00:05:57 | 显示全部楼层
另外,你说的那个自动寻址下载netcdf的,在CentOS上不行,提示如下(我试了,把netcdf-bin换成netcdf也不行):
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.khlug.org
* extras: mirror.khlug.org
* updates: mirror.khlug.org
Setting up Install Process
No package netcdf-bin available.
Nothing to do
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2011-10-23 00:10:29 | 显示全部楼层
artmunich 发表于 2011-10-23 00:05
另外,你说的那个自动寻址下载netcdf的,在CentOS上不行,提示如下(我试了,把netcdf-bin换成netcdf也不行 ...

A的WRF还没搞定啊?
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2011-10-23 00:33:06 | 显示全部楼层
传说中的谁 发表于 2011-10-23 00:10
A的WRF还没搞定啊?

哎,正在努力中,差那么一点火候而已
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表