happycatherin  

Ubuntu: 单机WRF安装 [复制链接]

Rank: 6Rank: 6

热心会员

跳转到指定楼层
楼主
发表于 2011-10-22 23:21:16 |只看该作者 |倒序浏览
分享到: --
本帖最后由 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的输出,不再赘述。
posted on 2012-05-15 20:30  catherin  阅读(1703)  评论(0编辑  收藏  举报