Hello,
I have a module which defines a series of constants and functions, but not sure how they can be accessed via a select case construct.
A snippet of the module:
module GR_functions
implicit none
! NIST CODATA values (2022)
real, parameter :: sol = 1.989e30 ! 1 solar mass kg
real, parameter :: velocity_of_light = 2.99792458e8 ! m/s
real, parameter :: gravitational_constant = 6.67430e-11 ! m^3 kg^1 s^2
real, parameter :: Planck_constant = 6.62607015e-34 ! J·s (h)
real, parameter :: reduced_Planck_constant = 1.054571817e-34 ! J·s (hbar)
real, parameter :: Boltzmann_constant = 1.380649e-23 ! J -K
real, parameter :: Stefan_Boltzmann_constant = 5.670374419e-8 ! W m-2 K-4
real, parameter :: AU = 1.495978707e11 ! Astronomical unit (m)
real, parameter :: LY = 9.460730472580800e15 ! Light year (m)
real, parameter :: PC = 3.26156*LY ! Parsec (m)
integer, parameter :: days_in_year = 365
integer, parameter :: seconds_in_day = 86400
integer, parameter :: seconds_in_year = 31536000
contains
function emc2(mass) result(E)
real, intent(in) :: mass
real :: E
E = mass * velocity_of_light**2 ! Joules
end function emc2
A short section of the main code:
program rs_test
use GR_functions
implicit none
integer :: choice, real_time
real :: mass, velocity, distance
real :: eqn_result
print *, 'Choose a function to execute:'
print *, '1 - E = mc^2'
print *, '2 - Relativistic time dilation'
print *, '3 - Schwarzschild radius'
print *, '4 - Photon sphere'
print *, '5 - Black hole surface area'
print *, '6 - Power radiated by black hole'
print *, '7 - Gravitational time dilation'
print *, '8 - Photon deflection'
print *, '9 - Hawking radiation'
print *, 'Enter your choice (1-9):'
read *, choice
! Use select case to call the selected function
select case(choice)
case(1)
! E = mc^2 requires mass as input
print *, 'Enter mass (in kg):'
read *, mass
eqn_result = emc2(mass)
print *, 'Energy (E = mc^2): ', eqn_result
My query is how one can use a variable or constant name at the user input where mass is a real value. A runtime error occurs typing sol for example as it is not recognised at this point.
Any pointers?
Thanks
Lester