|
| 1 | +--- |
| 2 | +title: constants |
| 3 | +--- |
| 4 | + |
| 5 | +[TOC] |
| 6 | + |
| 7 | +## Introduction |
| 8 | + |
| 9 | + |
| 10 | +The [[stdlib_constants]] module provides mathematical constants and the most common physical constants. |
| 11 | + |
| 12 | +**Warning**: The names of the most common physical constants are kept short as they are inside a dedicated module. |
| 13 | +Nonetheless, in case of overlapping names, they can always be renamed as following: |
| 14 | + |
| 15 | +```fortran |
| 16 | +use stdlib_constants, only: clight => c |
| 17 | +``` |
| 18 | + |
| 19 | +## Codata |
| 20 | + |
| 21 | +The [[stdlib_codata(module)]] module defines all codata (physical) constants as derived |
| 22 | +type. The module is automatically generated with a simple |
| 23 | +[parser written in Python](https://github.com/MilanSkocic/codata/) |
| 24 | +The latest codata constants were released in 2022 by the [NIST](http://physics.nist.gov/constants) |
| 25 | +All values for the codata constants are provided as double precision reals. |
| 26 | +The names are quite long and can be aliased with shorter names. |
| 27 | + |
| 28 | +The derived type [[stdlib_codata_type(module):codata_constant_type(type)]] defines: |
| 29 | + |
| 30 | +* 4 members: |
| 31 | + |
| 32 | + * `name` (string) |
| 33 | + * `value` (double precision real) |
| 34 | + * `uncertainty` (double precision real) |
| 35 | + * `unit` (string) |
| 36 | + |
| 37 | +* 2 type-bound procedures: |
| 38 | + |
| 39 | + * `print`: to print the values of the constant members; |
| 40 | + * `to_real`: to get the value or the uncertainty to the desired precision. |
| 41 | + |
| 42 | +A module level interface [[stdlib_codata_type(module):to_real(interface)]] is |
| 43 | +available for getting the constant value or uncertainty of a constant. |
| 44 | + |
| 45 | +## `to_real` - Get the constant value or its uncertainty. |
| 46 | + |
| 47 | +### Status |
| 48 | + |
| 49 | +Experimental |
| 50 | + |
| 51 | +### Description |
| 52 | + |
| 53 | +Convert a [[stdlib_codata_type(module):codata_constant_type(type)]] to a `real` (at least `sp`, or `dp`) scalar. |
| 54 | +**Warning**: Some constants cannot be converted to single precision `sp` reals due to the value of the exponents. |
| 55 | + |
| 56 | +### Syntax |
| 57 | + |
| 58 | +`r = ` [[stdlib_codata_type(module):to_real(interface)]] `(c, mold [, uncertainty])` |
| 59 | + |
| 60 | +### Arguments |
| 61 | + |
| 62 | +`c`: argument has `intent(in) ` and shall be of type [[stdlib_codata_type(module):codata_constant_type(type)]]. |
| 63 | + |
| 64 | +`mold`: argument has `intent(in)` and shall be of `real` type. |
| 65 | +**Note**: The type of the `mold` argument defines the type of the result. |
| 66 | + |
| 67 | +`uncertainty` (optional): argument has `intent(in)` and shall be of `logical` type. |
| 68 | +It specifies if the uncertainty needs to be returned instead of the value. Default to `.false.`. |
| 69 | + |
| 70 | +### Return value |
| 71 | + |
| 72 | +Returns a scalar of `real` type which is either the value or the uncertainty of a codata constant. |
| 73 | + |
| 74 | +## Example |
| 75 | + |
| 76 | +```fortran |
| 77 | +{!example/constants/example_constants.f90!} |
| 78 | +``` |
0 commit comments