我在循环中遇到问题。我不知道为什么循环中的循环没有运行。
Program Console2
IMPLICIT NONE
Integer n,LineID,AA,AAA,BBB,CCC,DDD,EEE,FFF,GGG,J
Real :: A,B,C,D,S,BB,CC,DD
Character (LEN=10) Line,NodeID
OPEN(UNIT=2,FILE="Chaq.txt",STATUS='unknown')
OPEN(UNIT=12,FILE="CoOrd.txt",STATUS='unknown')
OPEN(UNIT=4,FILE="OUTPUT.txt",STATUS='unknown')
Do n=1,10
Read (2,'(1x,a6,5x,i5,7x,i4,i8,i8,i8,i8)')NodeID,AAA,BBB,CCC,DDD,EEE,FFF
write (4,*)NodeID,DDD
Do J=1,10
READ (12,('(1x,a4,7x,I5,8x,f8.2,f8.2,f8.2)'))Line,AA,BB,CC,DD
write (4,*) Line,AA
End Do
End Do
End program Console2
问题在于第二个循环它没有从第二个文件中读取值:OUTPUT File:
CQUAD4 5950
GRID 3860
GRID 3861
GRID 3862
GRID 3863
GRID 3864
GRID 3865
GRID 3866
GRID 3867
GRID 3868
GRID 3869
CQUAD4 5949
文件Chaq.text:一些行
CQUAD4 6817 2 6053 5950 5951 6054
CQUAD4 6816 2 6052 5949 5950 6053
CQUAD4 6815 2 6051 5948 5949 6052
CQUAD4 6814 2 6050 5947 5948 6051
CQUAD4 6813 2 6192 5946 5947 6050
CoOrd.txt:我展示的一些行
GRID 3860 -171.90469.00543-28.5831
GRID 3861 -186.50872.15994-28.5831
GRID 3862 -180.23572.08246-28.5831
GRID 3863 -184.573103.9741-28.5831
GRID 3864 -171.92971.30236-28.5831
GRID 3865 -191.05479.44247-28.5831
GRID 3866 -159.938100.6297-28.5831
GRID 3867 -169.58477.11039-28.5831
GRID 3868 -176.62391.22597-28.5831
GRID 3869 -185.83898.214 -28.5831
答案 0 :(得分:1)
如果您希望每次通过外循环从CoOrd.txt
的开头读取,那么每次循环时都需要回放CoOrd.txt
:
Integer ReadStat
...
Do n=1,10
Read (2, '(1x,a6,5x,i5,7x,i4,i8,i8,i8,i8)', IOSTAT=ReadStat) NodeID,AAA,BBB,CCC,DDD,EEE,FFF
If (ReadStat < 0) exit ! EOF reached
If (ReadStat > 0) stop ! An unknown error occurred
write (4,*)NodeID,DDD
rewind(12)
Do J=1,10
READ (12, ('(1x,a4,7x,I5,8x,f8.2,f8.2,f8.2)', IOSTAT=ReadStat))Line,AA,BB,CC,DD
If (ReadStat < 0) exit ! EOF reached
If (ReadStat > 0) stop ! An unknown error occurred
write (4,*) Line,AA
End Do
End Do