- 积分
- 2046
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2013-7-16
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
nc数据文件为,hgt.1950.nc
程序:
program read_netcdf
include 'netcdf.inc'
integer i,j,k,l,irec
integer*4 ncid, status ! file control
!-------------------------------------------------------------
real*4 :: lon(144)
real*4 :: lat(73),level(17)
integer*4 :: time(365)
real*4 :: hgt(144,73,17,365)
!-------------------------------------------------------------
integer*4 :: start(10)
integer*4 :: count(10)
integer :: dimids(5)! allow up to 10 dimensions
integer :: dimid, xtype
character(len = 31) :: dummy
! Open netCDF file.
status = nf_open('hgt.1950.nc', nf_nowrite, ncid)
if ( status /= nf_noerr) call handle_err(status)
!----------------------------------------------------
status=nf_inq_varid(ncid, 'lon', lonid)
if (status /= nf_noerr) call handle_err(status)
status = nf_inq_var(ncid, lonid, dummy, xtype, ndim, dimids, natts)
if (status /= nf_noerr) call handle_err(status)
do j = 1, ndim
status = nf_inq_dim(ncid, dimids(j), dummy, len)
if (status /= nf_noerr) call handle_err(status)
start(j) = 1
count(j) = len
enddo
status = nf_get_vara_real(ncid, lonid, start, count, lon)
!----------------------------------------------------
! Retrieve data for Variable 'lat'
!print*,ncid
status=nf_inq_varid(ncid, 'lat', latid)
if (status /= nf_noerr) call handle_err(status)
status = nf_inq_var(ncid, latid, dummy, xtype, ndim, dimids, natts)
if (status /= nf_noerr) call handle_err(status)
do j = 1, ndim
status = nf_inq_dim(ncid, dimids(j), dummy, len)
if (status /= nf_noerr) call handle_err(status)
start(j) = 1
count(j) = len
enddo
status = nf_get_vara_real(ncid, latid, start, count, lat)
!----------------------------------------------------
! Retrieve data for Variable 'level'
!print*,ncid
status=nf_inq_varid(ncid, 'level', levelid)
if (status /= nf_noerr) call handle_err(status)
status = nf_inq_var(ncid, levelid, dummy, xtype, ndim, dimids, natts)
if (status /= nf_noerr) call handle_err(status)
do j = 1, ndim
status = nf_inq_dim(ncid, dimids(j), dummy, len)
if (status /= nf_noerr) call handle_err(status)
start(j) = 1
count(j) = len
enddo
! print*,ncid
status = nf_get_vara_real(ncid, levelid, start, count, level)
!----------------------------------------------------
! Retrieve data for Variable 'time'
status=nf_inq_varid(ncid,'time',timeid)
if (status /= nf_noerr) call handle_err(status)
status = nf_inq_var(ncid, timeid, dummy, xtype, ndim, dimids, natts)
if (status /= nf_noerr) call handle_err(status)
do j = 1, ndim
status = nf_inq_dim(ncid, dimids(j), dummy, len)
if(status /= nf_noerr) call handle_err(status)
start(j) = 1
count(j) = len
enddo
status = nf_get_vara_int(ncid, timeid, start, count, time)
!----------------------------------------------------
! Retrieve data for Variable 'hgt'
status=nf_inq_varid(ncid, 'hgt', hgtid)
if (status /= nf_noerr) call handle_err(status)
status = nf_inq_var(ncid, hgtid, dummy, xtype, ndim, dimids, natts)
if (status /= nf_noerr) call handle_err(status)
write(*,*) dummy, xtype , ndim ,dimids, natts
! pause
do j = 1,ndim
status = nf_inq_dim(ncid, dimids(j), dummy, len)
if (status /= nf_noerr) call handle_err(status)
start(j) = 1
count(j) = len
enddo
status = nf_get_vara_real(ncid, hgtid, start, count, hgt)
status = nf_close(ncid)
if(status /= nf_noerr) call handle_err(status)
!----------------------------------------------------
print*,hgt(1,1,1,1)
end
!---------------------- End Program --------------------------
subroutine handle_err(status)
include 'netcdf.inc'
integer, intent ( in) :: status
if(status /= nf_noerr) then
print *, trim(nf_strerror(status))
stop "Stopped"
end if
end subroutine handle_err
结果:::
第二个图是我用论坛里面那个read_netcdf.f90读出来的,两次结果一样,但是位势高度不应该是这样的数值啊?我想知道我问题出在哪里了!
|
|