主题:fortran6.6中可以运行但在vs2010+ivf2015中报错,彭国伦95中0863.F90?
错误 1 error #6552: The CALL statement is invoking a function subprogram as a subroutine. [GET_DISTANCE]
real, parameter :: PI = 3.14159
real, parameter :: G = 9.81
end module
module typedef
implicit none
type player
real :: angle
real :: speed
real :: distance
end type
end module
program ex0836
use typedef
use constant
implicit none
integer, parameter :: players = 5
type(player) :: people(players) = (/ player(30.0, 25.0, 0.0),&
player(45.0, 20.0, 0.0),&
player(35.0, 21.0, 0.0),&
player(50.0, 27.0, 0.0),&
player(40.0, 22.0, 0.0) &
/)
real :: Get_Distance ! 声明Get_Distance是个函数
integer :: I
do I=1, players
call Get_Distance( people(I) )
write(*,"('Player ',I1,' =',F8.2)") I, people(I)%distance
end do
stop
end
! 把0~360的角度转换成0~2PI的弧度
real function Angle_TO_Rad( angle )
use constant
implicit none
real angle
Angle_TO_Rad = angle*pi/180.0
return
end
subroutine Get_Distance(person)
use constant
use typedef
implicit none
type(player) :: person
real rad, Vx, time
real, external :: Angle_TO_Rad ! 声明Angle_TO_Rad是个函数
rad = Angle_TO_Rad( person%angle ) ! 单位转换
Vx = person%speed * cos(rad) ! 水平方向速度
time = 2.0 * person%speed * sin(rad) / G ! 在空中飞行时间
person%distance = Vx * time ! 距离 = 水平方向速度 * 飞行时间
return
end
具体代码为:
module constant
implicit nonereal, parameter :: PI = 3.14159
real, parameter :: G = 9.81
end module
module typedef
implicit none
type player
real :: angle
real :: speed
real :: distance
end type
end module
program ex0836
use typedef
use constant
implicit none
integer, parameter :: players = 5
type(player) :: people(players) = (/ player(30.0, 25.0, 0.0),&
player(45.0, 20.0, 0.0),&
player(35.0, 21.0, 0.0),&
player(50.0, 27.0, 0.0),&
player(40.0, 22.0, 0.0) &
/)
real :: Get_Distance ! 声明Get_Distance是个函数
integer :: I
do I=1, players
call Get_Distance( people(I) )
write(*,"('Player ',I1,' =',F8.2)") I, people(I)%distance
end do
stop
end
! 把0~360的角度转换成0~2PI的弧度
real function Angle_TO_Rad( angle )
use constant
implicit none
real angle
Angle_TO_Rad = angle*pi/180.0
return
end
subroutine Get_Distance(person)
use constant
use typedef
implicit none
type(player) :: person
real rad, Vx, time
real, external :: Angle_TO_Rad ! 声明Angle_TO_Rad是个函数
rad = Angle_TO_Rad( person%angle ) ! 单位转换
Vx = person%speed * cos(rad) ! 水平方向速度
time = 2.0 * person%speed * sin(rad) / G ! 在空中飞行时间
person%distance = Vx * time ! 距离 = 水平方向速度 * 飞行时间
return
end