作者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