爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 2600|回复: 2

[求助] fortran读取nc文件数组出错

[复制链接]

新浪微博达人勋

发表于 2017-11-26 15:46:07 | 显示全部楼层 |阅读模式

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

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

x
program month_ALT
implicit none
include 'netcdf.inc'

integer*4  ncid, status, t, year    ! file control
integer  i, j, d, m, n
real    delta, g
real, dimension(:), allocatable :: lon, lat, time, depth, new_depth, retime
real, dimension(:,:,:,:)        :: SoilTemp(720,123,30,492), air(720,123,30,12), clm45_SoilTemp(720,123,290)
real, dimension(:,:,:)          :: month_ALT(720,123,492)

integer      :: tempid, latDimID, lonDimID, frTimeDimID, &
                 latVarID, lonVarID, frTimeVarID, ALTVarID

integer*4   :: start(10)
integer*4   :: count(10)
integer     :: dimids(10)! allow up to 10 dimensions
integer     :: dimid, xtype
integer     :: ndim, natts, len
character(len = 31) :: dummy
                                                   !21
character(44) :: filename = '/p15/PCNMIP/rcn_data/jules/R01_JULES_1960.nc'
status = nf_open(filename,nf_nowrite,ncid)
!===========================================================
write(*,*) "read latitude"
status = nf_inq_var(ncid,2,dummy,xtype,ndim,dimids,natts)
allocate(lat(123))
do j = 1,ndim
status = nf_inq_dim(ncid,dimids(j),dummy,len)
      if ( status /= nf_noerr ) write (*,*) nf_strerror(status)
start(j) = 1 ; count(j) = len
enddo
status = nf_get_vara_real(ncid,   2,start,count,lat)
! write(*,*) lat
!===============================================================
write(*,*) "read longitude"
status = nf_inq_var(ncid,1,dummy,xtype,ndim,dimids,natts)
allocate(lon(720))
do j = 1,ndim
status = nf_inq_dim(ncid,dimids(j),dummy,len)
      if ( status /= nf_noerr ) write (*,*) nf_strerror(status)
start(j) = 1 ; count(j) = len
enddo
status = nf_get_vara_real(ncid,   1,start,count,lon)
! write(*,*) lon
!===================================================================
write(*,*) "read depth"
status = nf_inq_varid (ncid, "z_node", tempid)
status = nf_inq_var(ncid,tempid,dummy,xtype,ndim,dimids,natts)
allocate(depth(30))
do j = 1,ndim
status = nf_inq_dim(ncid,dimids(j),dummy,len)
      if ( status /= nf_noerr ) write (*,*) nf_strerror(status)
start(j) = 1 ; count(j) = len
enddo
status = nf_get_vara_real(ncid,   tempid,start,count,depth)
! write(*,*) depth
!=======================================================================
!    循环读取文件及SoilTemp
write(*,*) "read time and SoilTemp"
allocate(time(492))
allocate(retime(12))
do t = 0,40
  year = t + 1960
  write(filename(38:41),'(i4)') year
  write(*,*) year
  status = nf_open(filename,nf_nowrite,ncid)
  !===============================================================
    ! write(*,*) "read time"
   status = nf_inq_var(ncid,5,dummy,xtype,ndim,dimids,natts)
   do j = 1,ndim
   status = nf_inq_dim(ncid,dimids(j),dummy,len)
        if ( status /= nf_noerr ) write (*,*) nf_strerror(status)
   start(j) = 1 ; count(j) = len
   enddo
   status = nf_get_vara_real(ncid,   5,start,count,retime)
   time(t*12+1:t*12+12) = retime(:)
  !===================================================================
     ! write(*,*) "read SoilTemp"
  status = nf_inq_varid (ncid, "SoilTemp", tempid)
  status = nf_inq_var(ncid,tempid,dummy,xtype,ndim,dimids,natts)
  do j = 1,ndim
  status = nf_inq_dim(ncid,dimids(j),dummy,len)
       if ( status /= nf_noerr ) write (*,*) nf_strerror(status)
  start(j) = 1 ; count(j) = len
  enddo
  status = nf_get_vara_real(ncid,tempid,start,count,air)
  ! write(*,*) minval(air)
  SoilTemp(:,:,:,t*12+1:t*12+12) = air(:,:,:,:)
enddo
write(*,*) maxval(SoilTemp)
!=============================================================================
!                创建新的深度数组
allocate(new_depth(290))
g = 0.05
do n = 1, 290
  new_depth(n) = g + 0.01 * (n - 1)
end do
! write(*,*) 'new_depth = ', new_depth
!==============================================================================
!        土壤温度对深度线性插值
do t = 1,492
  write(*,*) t
  clm45_SoilTemp(:,:,1) = SoilTemp(:,:,1,t)
  do i = 1,123
    do j = 1,720
      do d = 2,290
        do n = 2, 30
          ! if ( SoilTemp(j,i,n,t) < 1.00000002E+20 .and. SoilTemp(j,i,n-1,t) < 1.00000002E+20 ) then
            if ( (new_depth(d) - depth(n)) < 0 .and. (new_depth(d) - depth(n-1)) >0) then
              clm45_SoilTemp(j,i,d) = SoilTemp(j,i,n-1,t) + (new_depth(d) - depth(n-1)) * &
                                  ((SoilTemp(j,i,n,t) - SoilTemp(j,i,n-1,t)) / (depth(n) - depth(n-1)))
            end if
            if ( clm45_SoilTemp(j,i,d) > 273.15 ) then
              month_ALT(j,i,t) = new_depth(d)
            end if
          ! end if
        end do
      end do
    end do
  end do
end do


编译出错

编译出错
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2017-12-13 16:15:33 | 显示全部楼层
rabin_xu 发表于 2017-11-30 23:59
你把month_ALT的这个变量名换一下试试

就是这个问题,我蠢了,program的名字不能和变量一样
密码修改失败请联系微信:mofangbao
回复 支持 1 反对 0

使用道具 举报

新浪微博达人勋

发表于 2017-11-30 23:59:16 | 显示全部楼层
你把month_ALT的这个变量名换一下试试
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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