想在输入文件中,输入行数,通过行数中的坐标,然后自动获得角度,代码已经附上,求助大家实现?[Fortran] 纯文本查看 复制代码 program angle
implicit none
real::x(3),y(3),z(3),angle,A,B,C,D
integer::i,j,k
write(*,*) 'Input the name of xyz:(e.g. a)'
read(*,*) name
name1=trim(name)//'.xyz'
open(12,file=name1)
open(13,file='result.txt')
do i=1,3
write(*,"(I1)") 'Input the atom number',i ,':(e.g.1)'
read(*,*) j
write(*,*)
if (j==1) then
read(12,"(11x,3(f12.6)") xi,yi,zi
else
do k=1,j-1
write(*,*)
end do
end if
read(12,"(11x,3(f12.6))") xi,yi,zi
rewind(12)
end do
A=(x1-x2)+(y1-y2)+(z1-z2) //!first vector
B=(x3-x2)+(y3-y2)+(z3-z2) //!second vector
C=dsqrt((x1-x2)**2+(y1-y2)**2+(z1-z2)**2) //!quantities of first vector
D=dsqrt((x3-x2)**2+(y3-y2)**2+(z3-z2)**2) //!quantities of second vector
angle=acos(A*B/C/D)
write(13,"(a,f12.4)") "The angle is:",angle/3.141592653589793238462d0*180
end program
|