我不是专家,但是我正在使用Absoft Fortran 2016编写代码。 简要地说:看来数组是相互写的,或者它们使用的是同一部分内存。 我发现输出值不是合理的,经过一番检查后发现数组存在问题,将代码简化为遇到问题的部分。有一个主体和2个子例程。第一个子例程(SubInput0)读取基本数据,第二个子例程(SubInput1)读取详细数据。在SubInput1中,应从某些文件中读取一些坐标。可以正确读取它们,但是在下一个循环中,值开始改变!我的意思是,尽管下一个循环正在读取下一个数组,但前一个数组也发生了变化,尽管它们之间没有链接。输出显示下一个数组正在上一个数组中写入自身。这真的让我感到困惑。
感谢您的帮助。
我尝试了不同的方式来不同地声明数组,也声明或不声明体内的数组,尝试了不同的隐式方法。
SubRoutine Control()
!THIS SUBROUTINE CONTROLS THE PROGRAM
!==================================================
Common /A/NNP,NODB3
Common /A1/NB3,NNPBED3,NNE,NNPEN
Common /C/NLoad,NTime,ITime,DTime
Common /E/GRAV
Real,Dimension(2,NNP) :: X
Real,Dimension(2,NNE) :: XEncl
Real,Dimension(3) :: MATERIAL
Open (10,FILE=Input.TXT) !Open Input File
Open (20,FILE=Output.TXT) !Open Output File
Open (30,FILE='Log.txt') !Open Log File
Open (40,FILE='Node.txt') !Open Node Coordinate File
Open (50,FILE='Encl.txt') !Open Encl Node Coordinate File
!--------Calling Sub Routines
!==============================
Call SubInput0 () !Call Sub to read the basic info
!==============================
!==============================
Call SubInput1 (X,XEncl,MATERIAL) !Call Sub to read the Details
!==============================
RETURN
END
SubRoutine SubInput0
SubRoutine SubInput0()
!This SubRoutine Reads The Basic Data From The Input Files
! Commons -----------------------------------------
Common /A/NNP,NODB3
Common /A1/NB3,NNPBED3,NNE,NNPEN
Common /C/NLoad,NTime,ITime,DTime
Common /E/GRAV
!--------------------------------------------------
Character*10 C$
Write(*,*) "SubInput0 Started"
Read(10,*) C$ ! Read Project Name
Read(10,*) NNP ! Read Num of total Nodes
Read(10,*) NNPBED3,NNPEN
Read(10,*) NLOAD,NTIME,DTime ! Read Num of Load and Time Steps
Grav=9.81
NB3=NNPBED3
NNE=NNPEN
RETURN
End
SubRoutine SubInput1
SubRoutine SubInput1(X,XEncl,MATERIAL)
!This SubRoutine Reads The Basic Data From The Input Files
! Commons -----------------------------------------
Common /A/NNP,NODB3
Common /A1/NB3,NNPBED3,NNE,NNPEN
Common /C/NLoad,NTime,ITime,DTime
Common /E/GRAV
!--------------------------------------------------
Real,Dimension(2,NNP), intent(out) :: X
Real,Dimension(2,NNE), intent(out) :: XEncl
Real,Dimension(3), intent(out) :: MATERIAL
Write(*,*) "SubInput1 Started"
Do i=1,NNP
read(40,*) NN,X(1,i),X(2,i) ! First it's readed correctly
Enddo
Do i=1,NNE
read(50,*) NE,XEncl(1,i),XEncl(2,i) ! But here the X will also change
Enddo
!Read Material Data------------------------------
Read(10,*) MATERIAL(1),MATERIAL(2),MATERIAL(3)
! Also here both X and XEncl change
!------------------------------------------------
RETURN
END
X值,它在第一个循环中读取后是正确的:
-100.000 0.000000 -80.0000 0.000000 -60.0000 0.000000 -40.0000 0.000000 -20.0000 0.000000 0.000000 0.000000 20.0000 0.000000 40.0000 0.000000 60.0000 0.000000 80.0000 0.000000 100.000 0.000000
第二个循环之后的X值不正确:
-100.000 -20.0000 -100.000 -40.0000 -100.000 -60.0000 -100.000 -80.0000 -100.000 -100.000 -80.0000 -100.000 -60.0000 -100.000 -40.0000 -100.000 -20.0000 -100.000 0.000000 -100.000 20.0000 -100.000
我认为与X的更改值相关的XEncl值:
-100.000 -20.0000 -100.000 -40.0000 -100.000 -60.0000 -100.000 -80.0000 -100.000 -100.000 -80.0000 -100.000 -60.0000 -100.000 -40.0000 -100.000 -20.0000 -100.000 0.000000 -100.000 20.0000 -100.000 40.0000 -100.000 60.0000- 100.000 80.0000 -100.000 100.000 -100.000 100.000 -80.0000 100.000 -60.0000 100.000 -40.0000 100.000 -20.0000