[Fortran] 纯文本查看 复制代码
!计算抛物线运动的程序,P162(彭国伦)
!==================================================
PROGRAM SOLVE
IMPLICIT NONE
REAL::L(5),VELOCITY(5),ALPHA(5)
CALL READ_VELOCITY( Velocity )
CALL READ_ALPHA( Alpha )
CALL RESULTS( L,Velocity , Alpha )
END
!==================================================
!==================================================
SUBROUTINE READ_VELOCITY( Velocity )
real :: velocity(5)
!从文件读入速度数据
OPEN(UNIT=9,FILE='VELOCITY.txt')
READ(9,*)VELOCITY
CLOSE(9)
RETURN
END SUBROUTINE
!==================================================
!==================================================
SUBROUTINE READ_ALPHA( Alpha )
Real :: alpha(5)
!从文件读入角度数据
OPEN(UNIT=9,FILE='ALPHA.txt')
READ(9,*)ALPHA
CLOSE(9)
RETURN
END SUBROUTINE
!==================================================
!==================================================
SUBROUTINE RESULTS( L , Velocity , Alpha )
!进行计算——投掷距离
REAL,PARAMETER::PI=3.14159,G=9.81
REAL::L(5),VELOCITY(5),ALPHA(5)
FORALL (I=1:5:1)
L(I)=(VELOCITY(I))**2*SIN(2*(ALPHA(I)*PI/180))/G
ENDFORALL
!结果输出到文件
OPEN(UNIT=0,FILE='RESULTS_1.TXT')
WRITE(0,'(/,5X,F7.2)')L
RETURN
END SUBROUTINE
!==================================================
[Fortran] 纯文本查看 复制代码
!计算抛物线运动的程序,P162(彭国伦)
!==================================================
PROGRAM SOLVE
IMPLICIT NONE
REAL::L(5),VELOCITY(5),ALPHA(5)
CALL READ_Data( "velocity.txt" , Velocity )
CALL READ_Data( "Alpha.txt" , Alpha )
CALL RESULTS( L,Velocity , Alpha )
END
!==================================================
!==================================================
SUBROUTINE READ_Data( cFile , r )
character( len = * ) :: cFile
real :: r(5)
!从文件读入速度数据
OPEN(9,FILE=cFile)
READ(9,*)r
CLOSE(9)
RETURN
END SUBROUTINE
!==================================================
!==================================================
SUBROUTINE RESULTS( L , Velocity , Alpha )
!进行计算——投掷距离
REAL,PARAMETER::PI=3.14159,G=9.81
REAL::L(5),VELOCITY(5),ALPHA(5)
FORALL (I=1:5:1)
L(I)=(VELOCITY(I))**2*SIN(2*(ALPHA(I)*PI/180))/G
ENDFORALL
!结果输出到文件
OPEN(UNIT=0,FILE='RESULTS_1.TXT')
WRITE(0,'(/,5X,F7.2)')L
RETURN
END SUBROUTINE
!==================================================