Calculations of momentum and kinetic energy (Fortran subroutine)

 

program kinematics
implicit none
real :: mass, vel, momentum, kinetic
!———————————————————————–
! Request input from user on mass and momentum
!———————————————————————–
print*, “!—————————————–!”
print*, “!        INPUT PARAMETERS        !”
print*, “!—————————————–!”
print*, “Provide the mass of the object”
read*, mass
print*, “Provide the instantaneous velocity of the object”
read*, vel
!—————————————————————————-
! Calculate kinetic energy and momentum of the object
! using subroutines
!—————————————————————————-
call calc_kinetic(mass,vel,kinetic)
call calc_momentum(mass,vel,momentum)
!—————————————————————————-
! Print values of kinetic energy and momentum
!—————————————————————————-
print*
print*, “!—————————————–!”
print*, “!            RESULTS OUTPUT          !”
print*, “!—————————————–!”
print 100, “Momentum =”, momentum, “kg m/s”
100 format(2x, a, 2x, f8.3, 1x, a)
print*
print 101, “Kinetic energy =”, kinetic, “kg m^2 s^(-2)”
101 format(2x, a, 2x, f8.3, 1x, a)
print*, “!—————————————–!”
end

 

!—————————————————————————–
! This subroutine is to calculate the kinetic energy
! using the input variables “mass” and “vel”.
! The output is returned to the main program
! with the use of the variable “kinetic”.
! *** same comment applies to the other subroutine.
!—————————————————————————-
subroutine calc_kinetic(mass,vel,kinetic)
implicit none
real mass, vel, kinetic
kinetic = mass * (vel**2) / 2.0
end subroutine
subroutine calc_momentum(mass,vel,momentum)
implicit none
real mass, vel, momentum
momentum = mass * vel
end subroutine