[問題] 陣列中的變數
我想要將檔案中的座標讀入二維的陣列中
程式碼如下:
program RotStanOrien
implicit none
type :: Orientation
real :: x
real :: y
real :: z
end type Orientation
type(Orientation) :: XYZ
character(len=80) :: Infilename, Outfilename
integer :: NAtoms, MaxAP3, AtmChg, error, i
real :: InOri(NAtoms, 3)
integer :: A(MaxAP3, 3)
integer :: TrVec(3)
NAtoms = 0
write(*,*) 'Please input the filename:'
read(*,*) Infilename
open(unit=99, file=Infilename, status="old", iostat=error )
if ( error /= 0 ) then
write(*,*) 'Open file fail'
stop
end if
do while( .true. )
read(99,*, end=500) AtmChg, XYZ%x, XYZ%y, XYZ%z
NAtoms = NAtoms + 1
InOri(NAtoms, 3) = XYZ%z
InOri(NAtoms, 2) = XYZ%y
InOri(NAtoms, 1) = XYZ%x
write(*,'F6.3,F6.3,F6.3') XYZ%x, XYZ%y, XYZ%z
enddo
500 continue
write(*,*) '---------------------------------'
do i = 1, NAtoms
write(*,'F6.3,F6.3,F6.3') InOri(i,1), InOri(i,2), InOri(i,3)
enddo
這是輸出的結果:
0.050 0.060 0.040
0.010-1.000 0.020 虛線上半部是正確的座標,這是由第一個迴圈內
1.000 0.015 0.016 的XYZ%x、XYZ%y、XYZ%z三個變數所write出來的
---------------------------------
0.050 0.050 0.050 下半部的座標則是錯的,這裡是第二個迴圈所write
0.010 0.010 0.010 出來的,每一列的三個值都是XYZ%x的值,我要的
1.000 1.000 1.000 是像上半部的值
請問為什麼將陣列中的值設為XYZ的變數後就會跑掉?
謝謝
--
--
╭◢██◣═══╮ ╭══════╮ theanswer3 ╭═════╮
║██◣◥ ◣ ╰══════╯◢█◣ ◢▌ ╰═════════╯ ω╴ ║
║◥██◣ ◥█◣ ◢◢◣ ◢█◣ ◥◣◥ ██◣ ◢ ◢ ◢◢◣ ◢ ◢▌︿◤ ̄ο ║
║◣◥theanswer3 █◤ █◢█ ◣◥◣theanswer3◢█ █◤ █▌█ ▄ ║
║◥██◤ ◥◆ █ ◥◤◥ ◥█◤ ◤ ◤ ◥◤◥ █ ◥██ ╱ ﹨ ║
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.115.43.188
→
12/12 16:03, , 1F
12/12 16:03, 1F
※ 編輯: band33 來自: 140.115.43.188 (12/12 16:08)
→
12/12 16:09, , 2F
12/12 16:09, 2F
推
12/12 16:49, , 3F
12/12 16:49, 3F
→
12/12 16:49, , 4F
12/12 16:49, 4F
→
12/12 16:50, , 5F
12/12 16:50, 5F
→
12/12 17:14, , 6F
12/12 17:14, 6F
Fortran 近期熱門文章
PTT數位生活區 即時熱門文章