错误:在(1)fortran的赋值中,排名0和1不兼容

时间:2014-02-19 16:18:56

标签: rank incompatibletypeerror

我尝试编写代码但在顶部得到错误,我的代码如下。请帮助我。(我搜索网络但无法解决问题)

program deneme
  implicit none 
  integer::i,mtd
  integer, parameter :: M = 100
  real, parameter:: pi = 3.1415926535897932
  double precision   xedge(0 : M) , xcell(0 : M-1)
  double precision Uext(0 : M-1) 
  double precision Uold(0 : M-1)
  double precision Unew(0 : M-1)
  double precision:: t_final, time, dt, xa, xb, dx, cfl,a

  cfl = 1.0d0
  t_final = 1.0d0 
  time = 0.0d0
  a = 1.0d0

  xa = 0.0d0 ; xb = 1.0d0
  dx = (xb - xa)/M
  dt =  cfl * (dx /dabs(a))
  do i = 0, M-1 
      xedge(i) = xa + i*dx
      xcell(i) = xa + (i+1./2.)*dx
  enddo
      xedge(M) = xa + M*dx
      !print *, "dx =",dx,dt,xa,xb 

  do i=0,M-1
       Uold(i) = [-dcos(2.0d0 * pi * xedge(i+1) )
 &            + dcos(2.0d0 * pi * xedge(i) )]/(2.0d0 * pi * dx)
       Uext(i) = dsin(2.0d0 * pi * (xedge(i)-a*time) )
       !write(11,*)xcell(i),uold(i),uext(i),dabs(uext(i)- uold(i)) 
  enddo

  do while (time <= t_final)
        time = time + dt
        do i = 1 , M-2
          Unew(i) = Uold(i) - dt*(Uold(i+1)-Uold(i-1)) / (2.0d0*dx)
 &  + 2*dt*dt*( Uold(i+1) - 2*Uold(i) + Uold(i-1) ) / (2.0d0*dx*dx)

          Unew(0) = Uold(0) - dt*(Uold(1)-Uold(M-1)) / (2.0d0*dx)
 &  + 2*dt*dt*( Uold(1) - 2*Uold(0) + Uold(M-1) ) / (2.0d0*dx*dx)

          Unew(M-1) = Unew(0)                

          Uext(i) = dsin(2.0d0 * pi * (xedge(i)-a*time) )
          Uext(0) = dsin(2.0d0 * pi * (xedge(0)-a*time) )
          Uext(M-1) = dsin(2.0d0 * pi * (xedge(M)-a*time) )
        enddo
        Uold = Unew

        !print*,"dt=",dt," time =",time
  enddo

  do i=0, M-1
      print*, Uext(i), Unew(i), dabs(Uext(i)- Unew(i))
     ! write(20,*)xedge(i), Uext(i), Unew(i), dabs(Uext(i)- Unew(i)) 

  enddo

  END 

1 个答案:

答案 0 :(得分:0)

您只需对程序进行一些修改,请将'[]'替换为'()' 在你的第一个do循环定义数组Uold和'&amp;'应该是该行的最后一个字符,它将继续到下一行, 一旦你做了这些修改,程序运行正常