数组'uwind'的维度1的索引'15'在14命令的上限之上,以非零状态2退出

时间:2017-05-05 10:04:54

标签: fortran

我使用的是Ubuntu 16.04,我尝试运行一段语句,但是我收到了这个错误:

At line 318 of file Usrdef_Surface_Data.f90
Fortran runtime error: Index '15' of dimension 1 of array 'uwind' above upper bound of 14
Command exited with non-zero status 2

有人可以告诉我这部分有什么问题吗?

我用粗体显示了第318行。但是,我认为这个问题与uwind本身有关。

SUBROUTINE usrdef_surface_data(iddesc,ifil,ciodatetime,surdata,n1dat,n2dat,&
                             & novars)
!************************************************************************
!
! *usrdef_surface_data* Define surface input data
!
! Author - Patrick Luyten
!
! Version - @(COHERENS)Usrdef_Surface_Data.f90  V2.1.0
!
! Description - rhone plume experiments
!
! Reference -
!
! Calling program - define_surface_data
!
!************************************************************************
!
USE iopars
USE syspars
USE timepars

USE inout_routines, ONLY: open_filepars
USE time_routines, ONLY: convert_date, log_timer_in, log_timer_out

IMPLICIT NONE

!
!*Arguments
!
CHARACTER (LEN=lentime), INTENT(INOUT) :: ciodatetime
INTEGER, INTENT(IN) :: iddesc, ifil, novars, n1dat, n2dat
REAL, INTENT(INOUT), DIMENSION(n1dat,n2dat,novars) :: surdata

!
! Name         Type     Purpose
!------------------------------------------------------------------------------
!*iddesc*      INTEGER  Data file id
!*ifil*        INTEGER  No. of data file
!*ciodatetime* CHAR     Date/time in data file
!*surdata*     REAL     Data array
!*n1dat*       INTEGER  X-dimension of data array
!*n2dat*       INTEGER  Y-dimension of data array
!*novars*      INTEGER  Number of data parameters
!
!------------------------------------------------------------------------------
!
!*Local variables
!
integer, parameter :: ncc = 14, nrr = 11, m=16791

INTEGER, SAVE :: iunit
INTEGER::i,j,k
REAL,DIMENSION(ncc,nrr) :: uwind,vwind,patm,tair,rh,cc
REAL, DIMENSION(ncc) :: x
REAL, DIMENSION(nrr) :: y
INTEGER, DIMENSION(7) :: iodatetime
REAL,  DIMENSION(m) :: param1,param2,param3,param4,param5,param6

character (len=200) :: STmp


procname(pglev+1) = 'usrdef_surface_data'
CALL log_timer_in()

!
!1. Open file
!------------
!

IF (modfiles(io_metsur,1,1)%iostat.EQ.0) THEN
   CALL open_filepars(modfiles(io_metsur,1,1))
   iunit = modfiles(io_metsur,1,1)%iunit
   modfiles(io_metsur,1,1)%iostat = 1
   READ (iunit,*)
   GOTO 1000
ENDIF



!
!2. Read data
!------------
!

 iodatetime(5:7) = 0 
  DO j=1,nrr
  DO i=1,ncc
     READ (iunit,*,END=99) iodatetime(1:4), x(i),y(j),uwind(i,j),vwind(i,j),  &
    & patm(i,j),tair(i,j),rh(i,j),cc(i,j)
  ENDDO
  ENDDO

!write(*,*) 'Pause',iodatetime(1:4)!,x(i),y(j),uwind(i,j)
!pause

 CALL  NARRinterpol(ncc,nrr,x,y,surdata,param1,param2,&
param3,param4,param5,param6,uwind,vwind,patm,tair,rh,cc,n1dat,n2dat,novars,m)


ciodatetime = convert_date(iodatetime)

Do k=1,m
i=mod(k,(n1dat-1))
if (i == 0) i=n1dat-1
j = 1+(k-i)/(n1dat-1)
!print*, i,j,k
surdata(i,j,1) = param1(k)
surdata(i,j,2) = param2(k)
surdata(i,j,3) = param3(k)
surdata(i,j,4) = param4(k)
surdata(i,j,5) = param5(k)
surdata(i,j,6) = param6(k)
END DO


1000 CALL log_timer_out()


RETURN

!
!3. Set end of file condition
!----------------------------
!

99 modfiles(io_metsur,1,1)%iostat = 3
CALL log_timer_out()

RETURN

!9001 FORMAT(4I2,5(2X,E11.4))

END SUBROUTINE usrdef_surface_data



!========================================================================
SUBROUTINE NARRinterpol(ncc,nrr,x,y,surdata,param1,param2,&
param3,param4,param5,param6,uwind,vwind,patm,tair,rh,cc,n1dat,n2dat,novars,m)
!************************************************************************
IMPLICIT NONE

INTEGER ::  novars, n1dat, n2dat ,ncc, nrr,m
REAL :: deltxi, deltyj
REAL, DIMENSION(ncc) :: x
REAL, DIMENSION(nrr) :: y
REAL,  DIMENSION(m) :: xx ,yy

REAL,DIMENSION(ncc,nrr) :: uwind,vwind,patm,tair,rh,cc
REAL, DIMENSION(n1dat,n2dat,novars) :: surdata
REAL,  DIMENSION(m) :: param1,param2,param3,param4,param5,param6


!* local variables:
INTEGER :: i,j,k
REAL :: g,f, x0i,y0j


x0i = 1898.748
y0j = -684.544
deltxi = 32463.0
deltyj = 32463.0


 OPEN (11,file = 'LonLat.dat')
  DO k=1,16791
   READ (11,*) xx(k), yy(k)
  END DO
 CLOSE(11) 


 DO k=1,m

  DO j= 1,nrr-1 
    IF((yy(k).GE.y(j)).AND. (yy(k).LE.y(j+1))) exit       
  ENDDO
  g = (yy(k) - y(j))/deltyj

   DO i= 1,ncc-1
   IF((xx(k).GE.x(i)).AND. (xx(k).LE.x(i+1))) exit
  ENDDO
  f = (xx(k) - x(i))/deltxi


print*, i,j,xx(i),yy(j),xx(k),yy(k)

第318行:

param1(k) = ((1-f)*(1-g))*uwind(i,j)+(f*(1-g))*uwind(i+1,j)&
+((1-f)*g)*uwind(i,j+1)+(f*g)*uwind(i+1,j+1)

其余的

param2(k) = ((1-f)*(1-g))*vwind(i,j)+(f*(1-g))*vwind(i+1,j)&
&+((1-f)*g)*vwind(i,j+1)+(f*g)*vwind(i+1,j+1)

  param3(k) = ((1-f)*(1-g))*patm(i,j)+(f*(1-g))*patm(i+1,j)&
&+((1-f)*g)*patm(i,j+1)+(f*g)*patm(i+1,j+1)

  param4(k) = ((1-f)*(1-g))*tair(i,j)+(f*(1-g))*tair(i+1,j)&
&+((1-f)*g)*tair(i,j+1)+(f*g)*tair(i+1,j+1)

param5(k) = ((1-f)*(1-g))*rh(i,j)+(f*(1-g))*rh(i+1,j)&
&+((1-f)*g)*rh(i,j+1)+(f*g)*rh(i+1,j+1)

param6(k) = ((1-f)*(1-g))*cc(i,j)+(f*(1-g))*cc(i+1,j)&
&+((1-f)*g)*cc(i,j+1)+(f*g)*cc(i+1,j+1)


!write(*,*) k,i,j,param1(k)

 ENDDO
End SUBROUTINE  NARRinterpol 
!************************************************************************

1 个答案:

答案 0 :(得分:0)

在这一部分:

  DO i= 1,ncc-1
   IF((xx(k).GE.x(i)).AND. (xx(k).LE.x(i+1))) exit
  ENDDO

完成循环后,i的值将为:(ncc-1)+1

这里

param1(k) = ((1-f)*(1-g))*uwind(i,j)+(f*(1-g))*uwind(i+1,j)&
+((1-f)*g)*uwind(i,j+1)+(f*g)*uwind(i+1,j+1)

有一部分uwind(i+1,j),第一个索引是((ncc-1)+1)+1ncc+1(因此超出范围)。