M_units(3fm) - [M_units::INTRO] convert between various physical units (LICENSE:MIT)
Synopsis
Constants Synopsis
Description
Procedures
Constants
Notes
Examples
procedure definitions:
elemental real function c2f(celsius) elemental real function f2c(fahrenheit)elemental real|double function r2d(radians) elemental real|double function d2r(degrees)
elemental real function feet_to_meters(feet) elemental real function meters_to_feet(meters)
elemental real function sind(angle_in_degrees) elemental real function cosd(angle_in_degrees) elemental real function tand(angle_in_degrees) elemental real function asind(x) elemental real function acosd(x) elemental real function atand(x) elemental real function atan2d(x,y)
elemental double function norm_angle_rad(radians) elemental real|double function norm_angle_deg(radians)
subroutine cartesian_to_spherical(x,y,z,radius,inclination,azimuth) subroutine spherical_to_cartesian(radius,inclination,azimuth,x,y,z) subroutine cartesian_to_polar(x,y,radius,inclination) subroutine polar_to_cartesian(radius,inclination,x,y)
syntax:
function nan() function inf() function is_nan() function is_even()Simple constants:
e,gamma,euler,golden_ratio,pi deg_per_rad, rad_per_deg c__m_per_sec, c__ft_per_sec
M_units(3fm) is a Fortran module that collects together basic procedures that are used to convert between various physical units and common named constants.
The input values may be any standard scalar value supported by the anyscalar_to_real(3f) function (real,integer,doubleprecision) within the range allowed by the function.
Angular Units
o d2r: Convert degrees to radians o r2d: Convert radians to degrees Temperature
o c2f: Convert Celsius to Fahrenheit o f2c: Convert Fahrenheit to Celsius Distance
o feet_to_meters: Convert feet to meters o meters_to_feet: Convert meters to feet REAL trig functions where input is in angular degrees instead of radians
o elemental real function sind(angle_in_degrees) o elemental real function cosd(angle_in_degrees) o elemental real function tand(angle_in_degrees) o elemental real function asind(x) o elemental real function acosd(x) o elemental real function atand(x) o elemental real function atan2d(x,y) Normalize angles into specific ranges
o elemental double function norm_angle_rad(angle_in_radians) o elemental real|double function norm_angle_deg(angle_in_degrees) Coordinates
o cartesian_to_spherical: Convert cartesian coordinates to spherical o spherical: Convert spherical coordinates to cartesian o cartesian_to_polar: Convert cartesian coordinates to polar o polar: Convert polar coordinates to cartesian
Note that your compiler is less likely to inline small procedures in a
module than it would statement functions or CONTAINED functions.
CONSTANTS
c__m_per_sec Speed of light in a vacuum c__ft_per_sec Speed of light in a vacuum "deg_per_rad" "rad_per_deg" e The base of the natural logarithm system. "e" was named in honor of Euler, but is known as Napiers constant. "euler" gamma The Euler-Mascheroni constant is often denoted by a lower-case Gamma. "golden_ratio" pi The ratio of the circumference of a circle to the diameter of the circle
Gamma is defined as
Gamma = limit ( M -> Infinity ) ( Sum ( 1 <= N <= M ) 1 / N ) - Log ( M )
Simple usage example:
program demo_M_units use M_units, only : r2d, d2r use M_units, only : f2c, c2f use M_units, only : sind, cosd, tand use M_units, only : asind, acosd, atand, atan2d !! use M_units, only : pi8=>pi use M_units, only : e,euler,golden_ratio,deg_per_rad,rad_per_deg use M_units, only : c__m_per_sec, c__ft_per_sec !! implicit none real pi pi=pi8 write(*,*)r2d([0.0,PI/4.0,PI/2.0,3.0*PI/2.0,PI]) write(*,*)d2r([0.0,45.0,90.0,135.0,180.0]) write(*,*)f2c([-40.0,32.0,212.0]) write(*,*)c2f([-40.0,0.0,100.0]) write(*,*)PI write(*,*)E !! write(*,101) "Napiers constant (e) is about ",e write(*,101) "The Euler-Mascheroni constant (euler or gamma) is about ",euler write(*,101) "pi (pi) is about ",pi8 write(*,101) "The Golden Ratio (golden_ratio) is about ",golden_ratio write(*,101) "Deg_Per_Rad is about ",Deg_Per_Rad write(*,101) "Rad_Per_Deg is about ",Rad_Per_Deg !! write(*,101) "Speed of light in a vacuum (m/sec) ", c__m_per_sec write(*,101) "Speed of light in a vacuum (ft/sec) ", c__ft_per_sec !! 101 format(a,t57,g0) !! end program demo_M_unitsResults:
> 0.00000000 45.0000000 90.0000000 270.000000 180.000000 > 0.00000000 0.785398185 1.57079637 2.35619450 3.14159274 > -40.0000000 0.00000000 100.000000 > -40.0000000 32.0000000 212.000000 > 3.14159274 > 2.7182818284590451 >Napiers constant (e) is about 2.7182818284590451 >The Euler-Mascheroni constant (euler or gamma) is about 0.57721566490153287 >pi (pi) is about 3.1415926535897931 >The Golden Ratio (golden_ratio) is about 1.6180339887498949 >Deg_Per_Rad is about 57.295779513082323 >Rad_Per_Deg is about 0.17453292519943295E-001 >Speed of light in a vacuum (m/sec) 299792458.00000000 >Speed of light in a vacuum (ft/sec) 983571056.00000000
Nemo Release 3.1 | M_units (3) | February 23, 2025 |