一物理系统可用下列线性方程组来表示:
从文件中读入m1、m2和θ的值,求a1、a2、N1 和N2的值。方程:m1cosθ -m1 -sinθ 0 a1 0
m1sinθ 0 cosθ 0 a2 m1g
0 m2 -sinθ 0 N1 0
0 0 -cosθ 1 N2 m2g
FORTRAN语言是Formula Translation的缩写,意为"公式翻译"。它是为科学、工程问题或企事业管理中的那些能够用数学公式表达的问题而设计的,其数值计算的功能较强。
Open打开文件
Read(文件号,格式串)变量列表
具体的可以看看帮助文件:)
源程序如下:
SUBROUTINE ForceDLL(time,x,xdot,xdot2,amat,omega,omegadot,F,M)
!DEC$ ATTRIBUTES DLLEXPORT::ForceDLL
!DEC$ ATTRIBUTES ALIAS:'forcedll' :: ForceDLL
! input
DOUBLE PRECISION ,INTENT(IN) :: time ! time
DOUBLE PRECISION ,DIMENSION(3) ,INTENT(IN) :: x ! global position of reference node
DOUBLE PRECISION ,DIMENSION(3) ,INTENT(IN) :: xdot ! global velocity of reference node
DOUBLE PRECISION ,DIMENSION(3) ,INTENT(IN) :: xdot2 ! global acceleration of reference node !
DOUBLE PRECISION ,DIMENSION(3),INTENT(IN) :: omega ! angular velocity of reference node (global base)
DOUBLE PRECISION ,DIMENSION(3) ,INTENT(IN) :: omegadot ! angular acceleration of reference node (global base)
DOUBLE PRECISION ,DIMENSION(3,3),INTENT(IN) :: amat ! rotation matrix (body -> global)
! output
DOUBLE PRECISION ,DIMENSION(3) ,INTENT(OUT) :: F ! External force in reference node (global base)
DOUBLE PRECISION ,DIMENSION(3) ,INTENT(OUT) :: M ! External moment in reference node (global base)
!
INTEGER :: I,J,K,N, L ! generic counter for the time step
real,allocatable :: Force(:,: ) ! read data from external file
!
N=floor(time/0.001)+1
write (*,*) N
allocate(Force(7,N))
open(20, FILE="Fbrk.txt" )
!!! read the external file into an array
do I=1,N
read (20,*) Force(:,I)
end do
close (20)
K=floor(time/0.001)+1
open(300, FILE="data.txt" )
write (300,'(I3,I10/)') N
!
!
!
F(1)=Force(2,K)*1000.0
F(2)=Force(3,K)*1000.0
F(3)=Force(4,K)*1000.0
M(1)=Force(5,K)*1000.0
M(2)=Force(6,K)*1000.0
M(3)=Force(7,K)*1000.0
END SUBROUTINE ForceDLL