fortran读取grib2文件

一、安装wgrib2

前一篇文章已经详细描述。

二、fortran文件 test.f90

Program read_grib2

  use wgrib2api

  Implicit None

  real, allocatable :: grid(:,:), lat(:,:), lon(:,:)

  character (len=300) :: metadata, grid_info

  character (len=200) :: file, inv, var, str_date

  integer :: date

  integer :: nx, ny, iret

  Character (Len=99) :: invline

  Character (Len=400) :: gridline

  file = 'multi_reanal.glo_30m_ext.wind.198001.grb2'

  inv = 'multi_reanal.glo_30m_ext.wind.198001.inv'

!  make inv file, save in memory file #0

  iret = grb2_mk_inv(file, inv)

  If (iret/=0) Stop 1

!      search using variable and regular date YYYYMMDDHH

  var = ':UGRD:'

  str_date = ':3 hour fcst:'

  ! iret = grb2_inq(file, inv, var, strdate, data2=grid)

  iret = grb2_inq(file, inv, var, ':3 hour fcst:', data2=grid, lat=lat, lon=lon, desc=invline, grid_desc=gridline)

  If (iret/=1) Stop 4

  Write (*, *) 'SP(1,1) =', grid(1, 1), ' lat/lon=', lat(1, 1), lon(1, 1)

  Write (*, *) 'inventory=', trim(invline)

  Write (*, *) 'grid=', trim(gridline)

End Program read_grib2

三、编译文件compile.intel

#!/bin/sh

#

# compile for intel ifort

#

set -x

prog=$1

LIB="-L/$HOME/Downloads/grib2/lib -lwgrib2 -ldl "

LIB+="-L/opt/jasper-1.900.1_intel/lib -lpng -ljasper "

LIB+="-L/opt/zlib-1.2.11_intel/lib -lz "

LIB+="-L/opt/hdf5-1.10.2_intel/lib -lhdf5_hl -lhdf5 -ldl "

LIB+="-L/opt/netcdf-c-4.6.1_intel/lib -lnetcdf "

LIB+="-L/opt/netcdf-f-4.4.4_intel/lib -lnetcdff "

MOD="-I/$HOME/Downloads/grib2/lib "

MOD+="-I/opt/jasper-1.900.1_intel/include "

MOD+="-I/opt/hdf5-1.10.2_intel/include "

MOD+="-I/opt/netcdf-c-4.6.1_intel/include "

MOD+="-I/opt/netcdf-f-4.4.4_intel/include "

ifort -no-wrap-margin -o $prog $prog.f90 ${MOD} ${LIB}

exit

四、编译

./compile_intel test

五、执行

./test

结果为

 SP(1,1) =  9.9990003E+20  lat/lon=  -90.00000      0.0000000E+00

 inventory=D=19800101000000:UGRD:surface:3 hour fcst:

 grid=grid_template=0:winds(N/S):

lat-lon grid:(720 x 361) units 1e-06 input WE:NS output WE:SN res 48

lat 90.000000 to -90.000000 by 0.500000

lon 0.000000 to 359.500000 by 0.500000 #points=259920

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • mean to add the formatted="false" attribute?.[ 46% 47325/...
    ProZoom阅读 2,724评论 0 3
  • NCRA Averagers nces, ncra, and ncwa The differences betwe...
    榴莲气象阅读 730评论 0 1
  • 在C语言中,五种基本数据类型存储空间长度的排列顺序是: A)char B)char=int<=float C)ch...
    夏天再来阅读 3,402评论 0 2
  • [root@hh hadoop]# hdfs namenode -format 17/12/12 17:42:06...
    好了伤疤忘了阅读 1,387评论 0 51
  • 2018年1月31日晴(115) 晚饭时,我和爸爸先吃完了,因为快要过年了,很多卫生需要打扫一下,也好有个...
    彩虹宝儿阅读 372评论 0 0