为什么派生类型的一个元素会自行更改(Fortran 90)?

时间:2017-11-15 23:43:15

标签: windows fortran90

我写了以下程序。派生类型是:

    type point
        real(8) :: x, y, z
    end type point

然后在子程序代码中:

SUBROUTINE CrystalCor(UnitBoxPos, SiteZ, SiteB)
    Use Parameters
    Use Variables
    Use Coordinate
    Implicit none

    type (point) SiteZ, SiteB(3)

    real(8) xz,yz,zz

    xz = 0.0
    yz = 0.0
    zz = 0.0

    SiteZ%x = xz
    SiteZ%y = yz
    SiteZ%z = zz
    write(6,10) SiteZ      !to check the elements' values in siteZ

    SiteB(1)%x = xz + 0.5
    SiteB(1)%y = yz
    SiteB(1)%z = zz

    SiteB(2)%x = xz 
    SiteB(2)%y = yz + 0.5  ! from here, why SiteZ%y also change to yz+0.5
    SiteB(2)%z = zz  

    SiteB(3)%x = xz 
    SiteB(3)%y = yz
    SiteB(3)%z = zz + 0.5

    write(6,10) SiteB
    write(6,10) SiteZ       !to check the elements' values in siteZ

10格式(2X,3(2X,F10.6)) END

输出结果为:

0.000000 0.000000 0.000000

0.500000 0.000000 0.000000

0.000000 0.500000 0.000000

0.000000 0.000000 0.500000

0.000000 0.500000 0.000000

根据代码,我没有对SiteZ%y进行更改,但它从0.0更改为0.5

0 个答案:

没有答案