Fortran 和用户输入值中的迭代器问题

Problems with iterator in fortran and user input values

所以我是编程新手,我正在为我的硕士论文编写代码。 我当前的代码问题如下:

  1. 当我尝试编译以在矩阵元素之间进行分布时,出现此错误消息:"Syntax error in iterator in (1)"。错误在代码的Initialization部分,如下:

        do j=2:rn2
            do i=1:cn
                do n=0:8
                f(n,i,j)=rho*w(n)
                enddo
            enddo
        enddo
    
  2. 当我提示X或Y方向有多少个元素时,用户最多只能输入15257个元素。我不知道是硬件限制还是我的代码有问题。

这里是完整的代码:

    program LBM
        implicit none
        real*8 cn,rn,rn2,omega,gx,gy,rho,w0,w1,w2
        real, dimension(0:8) :: w, ex, ey, bb
        real, dimension(:,:), allocatable :: f, fn
        integer :: i,j,k

    !--------------------------------Constants----------------------------

        omega=1.d0
        gx=0.001d0
        gy=0.d0
        rho=1.d0

    !--------------------------Weights of D2Q9 model----------------------    

        w0=4.d0/9.d0
        w1=1.d0/9.d0
        w2=1.d0/36.d0
        w(0)=w0

        do i=1,4
            w(i)=w1
        enddo

        do i=5,8
            w(i)=w2
        enddo

    !--------------------------------Weight test--------------------------

        !write(*,*) w
        !w_sum=w(0)+w(1)+w(2)+w(3)+w(4)+w(5)+w(6)+w(7)+w(8)
        !write(*,*) w_sum

    !-------------------------Velocities of D2Q9 model--------------------

        ex=(/ 0, 1, 0, -1, 0, 1, -1, -1, 1 /)
        ey=(/ 0, 0, 1, 0, -1, 1, 1, -1, -1 /)

    !-------------------------------Velocities test-----------------------

        !write(*,*) ex, ey

    !--------------------------------Bounce-Back--------------------------

        bb=(/ 0, 3, 4, 1, 2, 7, 8, 5, 6 /)

    !------------------------------Matrix creation------------------------

        do while(cn.lt.3)
            write(*,*) 'How many elements in X direction?'
            read(*,*) cn
            if (cn.lt.3) then
                write(*,*) 'Number of elements must be more then 2.'
            end if
        enddo

        do while (rn.lt.3)
            write(*,*) 'How many elements in Y direction?'
            read(*,*) rn
            if (rn.lt.3) then
                write(*,*) 'Number of element must be more then 2.'
            end if
        enddo

        allocate(f(cn,rn), fn(cn,rn))

        rn2=rn-1

    !-----------------------------Inicialization--------------------------

        do j=2:rn2
            do i=1:cn
                do n=0:8
                f(n,i,j)=rho*w(n)
                enddo
            enddo
        enddo

    !-------------------------------End program---------------------------
        deallocate(f,fn)

    write(*,*) rn, cn, rn2

        pause
    end program LBM

抱歉这么久 post。

此致。

我认为您正在为 Fortran 使用 Matlab 语法。

尝试以下操作:

do j=2,rn2
    do i=1,cn
        do n=0,8
        f(n,i,j)=rho*w(n)
        end do
    end do
end do

do j=2,rn2
    do i=1,cn
        f(0:8,i,j)=rho*w(0:8)
    end do
end do