Fortran Coder

标题: 程序运行错误 求助大神 [打印本页]

作者: gf676680802    时间: 2019-7-19 10:15
标题: 程序运行错误 求助大神
C:\Users\ASUS\Desktop\聚宝盆\颗粒布置.png
我是初学者,想计算任意第i行第j列圆盘中心坐标,即D(i,j),半径假设0.5,偶数行有11列,奇数行只有10列,可能问题出在数组上,求大神不吝赐教,万分感谢!
program zuobiao1
    implicit none
    integer(4) ,parameter :: A = 11
    !integer(4) ,parameter :: B = 11
    integer :: D_0(3,A,B)
    integer,dimension(3) :: D(i,j)
    D(i,j) = (/D_0(1,i,j),D_0(2,i,j),D_0(3,i,j)/)
    !integer(4) ,parameter :: C = 10
    !common A,B,C
    integer :: s !方向赋值
    integer :: i !行号赋值
    integer :: j !列号赋值
    real(4) :: X(3,A,B)
   
    do s = 1,3
        !s = s+1
        do i = 1,A
            !i = i+1
            if (mod(i,2) == 0) then
                do j = 1,10
                    !j = j+1
                    X(1,i,j) = j - 0.5
                    X(2,i,j) = (i - 1)*0.866
                    X(3,i,j) = 0
                    if (j>10) exit
                    D_0(1,i,j) = X(1,i,j)
                    D_0(2,i,j) = X(2,i,j)
                    D_0(3,i,j) = X(3,i,j)
                end do
            else
                do j = 1,11
                    !j = j+1
                    X(1,i,j) = j - 1
                    X(2,i,j) = (i - 1)*0.866
                    X(3,i,j) = 0
                    D_0(1,i,j) = X(1,i,j)
                    D_0(2,i,j) = X(2,i,j)
                    D_0(3,i,j) = X(3,i,j)
                end do
            end if
        
        end do
        !X(3,i,j) = 0
    end do
   
    write(*,*) "行号:"
    read(*,*) i
    write(*,*) "列号:"
    read(*,*) j            
    write(*,*)  X(1,i,j)
    write(*,*)  X(2,i,j)
    write(*,*)  X(3,i,j)
    write(*,*)  D(i,j)
    stop
   
   
    end program
作者: gf676680802    时间: 2019-7-19 10:17


作者: gf676680802    时间: 2019-7-19 12:27
最好能设置循环,自动计算每一个圆盘的中心坐标并存储,便于后面直接调用
作者: li913    时间: 2019-7-19 16:46
本帖最后由 li913 于 2019-7-19 17:00 编辑

[Fortran] 纯文本查看 复制代码
r=0.5
!第一个圆心位置
if(mod(i,2)==1) then !奇数行
x0=0
y0=0
else
x0=r
y0=sqrt(3.0)*r
end if
dy = sqrt(3.0)*r !y方向圆心间距

x = x0 + (j-1)*2*r
y = y0 + (i-1)*dy
你把奇偶行分开算,就容易了。奇数行全是规整的,偶数行也全是规整的。
作者: gf676680802    时间: 2019-7-20 00:39
li913 发表于 2019-7-19 16:46
[mw_shl_code=fortran,true]r=0.5
!第一个圆心位置
if(mod(i,2)==1) then !奇数行

谢谢,比较简洁




欢迎光临 Fortran Coder (http://bbs.fcode.cn/) Powered by Discuz! X3.2