作者band33 (時鐘)
看板Fortran
標題[問題] 陣列中的變數
時間Mon Dec 12 15:28:14 2011
我想要將檔案中的座標讀入二維的陣列中
程式碼如下:
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
1F:→ Semisphere:麻煩請貼上完整程式碼,至少也包含宣告處 12/12 16:03
※ 編輯: band33 來自: 140.115.43.188 (12/12 16:08)
2F:→ band33:已補上 12/12 16:09
3F:推 mouseforlove:我想問題可能出在InOri的宣告部分,NAtoms為一個未知 12/12 16:49
4F:→ mouseforlove:數,可以先試著給個大一點的維度看看,矩陣A宣告中的 12/12 16:49
5F:→ mouseforlove:維度MaxAP3也還是未知數 12/12 16:50
6F:→ band33:感謝解答!!! 12/12 17:14