Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codata constants. #800

Merged
merged 146 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
146 commits
Select commit Hold shift + click to select a range
d0fbca0
Add codata constants.
MilanSkocic Apr 21, 2024
be97e8c
Add generic facility and mimic scipy constant module.
MilanSkocic Apr 25, 2024
31e2ce1
Uncomment fypp include statement.
MilanSkocic Apr 25, 2024
2dcca26
Fix typo in gravitation_constant.
MilanSkocic Apr 27, 2024
4750e7b
Set KINDS as REAL_KINDS from common.fypp
MilanSkocic Apr 29, 2024
359694d
Set KINDS as REAL_KINDS from common.fypp.
MilanSkocic Apr 29, 2024
4cfd815
Automatic generation of PI with different precisions from KINDS.
MilanSkocic Apr 29, 2024
912b590
Add doc stdlib_constants.md in docs/specs/
MilanSkocic Apr 30, 2024
e73f743
ENH: Add example_constants.f90 in example/constants/.
MilanSkocic Apr 30, 2024
1994601
Modify doc stdlib_constants.md
MilanSkocic Apr 30, 2024
ac8eb45
Add constants documentation in index.
MilanSkocic May 4, 2024
d4fa81e
Add to_real for consistency with stdlib.
MilanSkocic May 8, 2024
40fa472
Update example and add CMakeLists.txt in constant folder.
MilanSkocic May 8, 2024
68d38d3
Update docs/specs/stdlib_constants.md.
MilanSkocic May 8, 2024
cc64658
Update doc/specs/stdlib_constants.md
MilanSkocic May 9, 2024
7875707
Update doc/specs/stdlib_constants.md. Spelling error.
MilanSkocic May 9, 2024
d230ea3
Update example/constants/example_constants.f90.
MilanSkocic May 9, 2024
3f88e5c
Update example/constants/example_constants.f90
MilanSkocic May 9, 2024
c044980
Update src/stdlib_codata_type.fypp. Consistency with DT in stdlib.
MilanSkocic May 9, 2024
2843c81
Update src/stdlib_codata_type.fypp. Docstring for real function.
MilanSkocic May 9, 2024
3e29a0a
Update src/stdlib_codata_type.fypp. Docstring for DT.
MilanSkocic May 9, 2024
891c611
Rename DT tp codata_constant_type for consistency with the stdlib.
MilanSkocic May 9, 2024
c74828e
Update doc/specs/stdlib_constants.
MilanSkocic May 10, 2024
dcb52fe
Update codata constants with the 2022 release.
MilanSkocic May 13, 2024
85233d5
Update documentation with the link to the Python script for generatin…
MilanSkocic May 13, 2024
49463c0
Update documentation for the interface to_real.
MilanSkocic May 13, 2024
f222f80
Fix underscores in 2 variables.
MilanSkocic May 13, 2024
067b77c
Add tests for codata constants (values and uncertainties).
MilanSkocic May 13, 2024
5d14342
Set cmake files for the tests of the codata constants.
MilanSkocic May 13, 2024
8b67f04
Fix format for the print function.
MilanSkocic May 16, 2024
6edd907
Fix reference to codata_constant_type in documentation.
MilanSkocic May 16, 2024
c47399f
Fix link to the repo where the python script for generating the codat…
MilanSkocic May 16, 2024
2cad5e7
Fix typo.
MilanSkocic May 18, 2024
9730f3d
Update doc/specs/stdlib_constants.md
MilanSkocic May 19, 2024
202b8ff
Update doc/specs/stdlib_constants.md
MilanSkocic May 19, 2024
2853bde
Update doc/specs/stdlib_constants.md
MilanSkocic May 19, 2024
d97fa2a
Update doc/specs/stdlib_constants.md
MilanSkocic May 19, 2024
4b67e99
Update doc/specs/stdlib_constants.md
MilanSkocic May 19, 2024
73568a7
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
f4428b4
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
9b08666
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
30570b6
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
7ba4787
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
b404273
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
e171775
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
0142cbb
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
6506424
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
e8e529a
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
2c828ab
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
0d15a22
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
9154070
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
50609ca
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
8623efb
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
e407ad6
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
43a90bd
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
2731820
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
7bfbd51
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
27575d7
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
5dcecb7
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
97a4c88
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
baed382
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
5fea52f
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
37791c0
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
2e93d3c
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
443ddf6
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
f281240
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
2490030
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
83d46a8
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
6eaea45
Add fac as module level variable.
MilanSkocic May 19, 2024
3120376
Direct comparison for tests.
MilanSkocic May 21, 2024
8ca1088
Fix arguments order in call to check function.
MilanSkocic May 21, 2024
e331d56
Add codata constants.
MilanSkocic Apr 21, 2024
912608f
Add codata constants.
MilanSkocic May 21, 2024
3326151
Uncomment fypp include statement.
MilanSkocic Apr 25, 2024
2bddb54
Fix typo in gravitation_constant.
MilanSkocic Apr 27, 2024
064828d
Set KINDS as REAL_KINDS from common.fypp
MilanSkocic Apr 29, 2024
970ee5f
Set KINDS as REAL_KINDS from common.fypp.
MilanSkocic Apr 29, 2024
6d2c9f2
Automatic generation of PI with different precisions from KINDS.
MilanSkocic Apr 29, 2024
a77709b
Add doc stdlib_constants.md in docs/specs/
MilanSkocic Apr 30, 2024
1342ae3
ENH: Add example_constants.f90 in example/constants/.
MilanSkocic Apr 30, 2024
e14f83a
Modify doc stdlib_constants.md
MilanSkocic Apr 30, 2024
409991d
Add constants documentation in index.
MilanSkocic May 4, 2024
c536ee5
Add to_real for consistency with stdlib.
MilanSkocic May 8, 2024
dc51fab
Update example and add CMakeLists.txt in constant folder.
MilanSkocic May 8, 2024
dc56497
Update docs/specs/stdlib_constants.md.
MilanSkocic May 8, 2024
a061a11
Update doc/specs/stdlib_constants.md
MilanSkocic May 9, 2024
dba4a5a
Update doc/specs/stdlib_constants.md. Spelling error.
MilanSkocic May 9, 2024
546d54c
Update example/constants/example_constants.f90.
MilanSkocic May 9, 2024
0427b01
Update example/constants/example_constants.f90
MilanSkocic May 9, 2024
4ad9ae8
Update src/stdlib_codata_type.fypp. Consistency with DT in stdlib.
MilanSkocic May 9, 2024
9090c6b
Update src/stdlib_codata_type.fypp. Docstring for real function.
MilanSkocic May 9, 2024
b5bdc14
Update src/stdlib_codata_type.fypp. Docstring for DT.
MilanSkocic May 9, 2024
e74ec41
Rename DT tp codata_constant_type for consistency with the stdlib.
MilanSkocic May 9, 2024
00c789a
Update doc/specs/stdlib_constants.
MilanSkocic May 10, 2024
3ddef7a
Update codata constants with the 2022 release.
MilanSkocic May 13, 2024
4ac5d84
Update documentation with the link to the Python script for generatin…
MilanSkocic May 13, 2024
6557d91
Update documentation for the interface to_real.
MilanSkocic May 13, 2024
9821c0d
Fix underscores in 2 variables.
MilanSkocic May 13, 2024
add6ff5
Add tests for codata constants (values and uncertainties).
MilanSkocic May 13, 2024
5c49605
Set cmake files for the tests of the codata constants.
MilanSkocic May 13, 2024
1c6fc23
Fix format for the print function.
MilanSkocic May 16, 2024
340454d
Fix reference to codata_constant_type in documentation.
MilanSkocic May 16, 2024
d07d9c8
Fix link to the repo where the python script for generating the codat…
MilanSkocic May 16, 2024
c62e526
Fix typo.
MilanSkocic May 18, 2024
26ff73c
Update doc/specs/stdlib_constants.md
MilanSkocic May 19, 2024
35b5da6
Update doc/specs/stdlib_constants.md
MilanSkocic May 19, 2024
de867cc
Update doc/specs/stdlib_constants.md
MilanSkocic May 19, 2024
5775ff7
Update doc/specs/stdlib_constants.md
MilanSkocic May 19, 2024
d999a01
Update doc/specs/stdlib_constants.md
MilanSkocic May 19, 2024
304519a
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
7bfcd51
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
7a9437c
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
98427e4
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
c751fd0
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
415b3b6
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
9a120f5
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
fa6bd80
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
f729f89
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
852a02a
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
ccaa29f
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
ba13328
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
0317123
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
d1e1b74
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
6ac6333
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
a413e24
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
32a3920
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
6131205
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
62d6473
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
28e3760
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
c5c1d5d
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
acd099c
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
81d987f
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
e75bb8a
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
262595c
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
b9a16a6
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
bac6e47
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
bbcc33e
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
a79e01f
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
a184072
Update test/constants/test_constants.f90
MilanSkocic May 19, 2024
5948700
Add fac as module level variable.
MilanSkocic May 19, 2024
18989aa
Direct comparison for tests.
MilanSkocic May 21, 2024
caa5034
Fix arguments order in call to check function.
MilanSkocic May 21, 2024
1bd2716
Merge after rebase.
MilanSkocic May 21, 2024
79e0300
Merge branch 'fortran-lang:master' into master
MilanSkocic May 21, 2024
b24f3c6
Add warning for short names and how to alias them.
MilanSkocic May 24, 2024
b824cab
Fix spelling in example.
MilanSkocic May 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/specs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This is an index/directory of the specifications (specs) for each new module/fea
- [ansi](./stdlib_ansi.html) - Terminal color and style escape sequences
- [array](./stdlib_array.html) - Procedures for index manipulation and array handling
- [ascii](./stdlib_ascii.html) - Procedures for handling ASCII characters
- [constants](./stdlib_constants.html) - Constants
- [bitsets](./stdlib_bitsets.html) - Bitset data types and procedures
- [error](./stdlib_error.html) - Catching and handling errors
- [hash](./stdlib_hash_procedures.html) - Hashing integer
Expand Down
78 changes: 78 additions & 0 deletions doc/specs/stdlib_constants.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
title: constants
---

[TOC]

## Introduction


The [[stdlib_constants]] module provides mathematical constants and the most common physical constants.

**Warning**: The names of the most common physical constants are kept short as they are inside a dedicated module.
Nonetheless, in case of overlapping names, they can always be renamed as following:

```fortran
use stdlib_constants, only: clight => c
```

## Codata

The [[stdlib_codata(module)]] module defines all codata (physical) constants as derived
type. The module is automatically generated with a simple
[parser written in Python](https://github.com/MilanSkocic/codata/)
The latest codata constants were released in 2022 by the [NIST](http://physics.nist.gov/constants)
All values for the codata constants are provided as double precision reals.
The names are quite long and can be aliased with shorter names.

The derived type [[stdlib_codata_type(module):codata_constant_type(type)]] defines:

* 4 members:

* `name` (string)
* `value` (double precision real)
* `uncertainty` (double precision real)
* `unit` (string)

* 2 type-bound procedures:

* `print`: to print the values of the constant members;
* `to_real`: to get the value or the uncertainty to the desired precision.

A module level interface [[stdlib_codata_type(module):to_real(interface)]] is
available for getting the constant value or uncertainty of a constant.

## `to_real` - Get the constant value or its uncertainty.

### Status

Experimental

### Description

Convert a [[stdlib_codata_type(module):codata_constant_type(type)]] to a `real` (at least `sp`, or `dp`) scalar.
**Warning**: Some constants cannot be converted to single precision `sp` reals due to the value of the exponents.

### Syntax

`r = ` [[stdlib_codata_type(module):to_real(interface)]] `(c, mold [, uncertainty])`

### Arguments

`c`: argument has `intent(in) ` and shall be of type [[stdlib_codata_type(module):codata_constant_type(type)]].

`mold`: argument has `intent(in)` and shall be of `real` type.
**Note**: The type of the `mold` argument defines the type of the result.

`uncertainty` (optional): argument has `intent(in)` and shall be of `logical` type.
It specifies if the uncertainty needs to be returned instead of the value. Default to `.false.`.

### Return value

Returns a scalar of `real` type which is either the value or the uncertainty of a codata constant.

## Example

```fortran
{!example/constants/example_constants.f90!}
```
1 change: 1 addition & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ endmacro(ADD_EXAMPLE)
add_subdirectory(array)
add_subdirectory(ascii)
add_subdirectory(bitsets)
add_subdirectory(constants)
add_subdirectory(error)
add_subdirectory(hashmaps)
add_subdirectory(hash_procedures)
Expand Down
1 change: 1 addition & 0 deletions example/constants/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ADD_EXAMPLE(constants)
25 changes: 25 additions & 0 deletions example/constants/example_constants.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
program example_constants
use stdlib_constants, only: c, pi=>PI_dp
use stdlib_codata, only: alpha=>ALPHA_PARTICLE_ELECTRON_MASS_RATIO
use stdlib_codata_type, only : to_real
use stdlib_kinds, only: dp, sp

! Use most common physical constants defined as double precision reals
print *, "speed of light in vacuum= ", c

! Use of mathematical constants such as PI
print *, "PI as double precision real= ", pi

! Use codata_constant type for evaluating the value to the desired precision
print *, "Value of alpha... evaluated to double precision=", alpha%to_real(1.0_dp)
print *, "Uncertainty of alpha... evaluated to double precision=", alpha%to_real(1.0_sp, .true.)
print *, "Value of alpha... evaluated to single precision=", alpha%to_real(1.0_sp)

! Convert a codata constant to a real
print *, "Value of the alpha... evaluated to double precision=", to_real(alpha, 1.0_dp)


! Print out codata constant attributes: name, value, uncertainty and unit
call alpha%print()

end program example_constants
23 changes: 13 additions & 10 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ set(fppFiles
stdlib_bitsets.fypp
stdlib_bitsets_64.fypp
stdlib_bitsets_large.fypp
stdlib_hash_32bit.fypp
stdlib_codata_type.fypp
stdlib_constants.fypp
stdlib_hash_32bit.fypp
stdlib_hash_32bit_fnv.fypp
stdlib_hash_32bit_nm.fypp
stdlib_hash_32bit_water.fypp
stdlib_hash_64bit.fypp
stdlib_hash_64bit_fnv.fypp
stdlib_hash_64bit_pengy.fypp
stdlib_hash_64bit_spookyv2.fypp
stdlib_hash_32bit_nm.fypp
stdlib_hash_32bit_water.fypp
stdlib_hash_64bit.fypp
stdlib_hash_64bit_fnv.fypp
stdlib_hash_64bit_pengy.fypp
stdlib_hash_64bit_spookyv2.fypp
stdlib_io.fypp
stdlib_io_npy.fypp
stdlib_io_npy_load.fypp
Expand All @@ -25,9 +27,9 @@ set(fppFiles
stdlib_linalg_outer_product.fypp
stdlib_linalg_kronecker.fypp
stdlib_linalg_cross_product.fypp
stdlib_linalg_solve.fypp
stdlib_linalg_solve.fypp
stdlib_linalg_determinant.fypp
stdlib_linalg_state.fypp
stdlib_linalg_state.fypp
stdlib_optval.fypp
stdlib_selection.fypp
stdlib_sorting.fypp
Expand Down Expand Up @@ -68,7 +70,7 @@ set(fppFiles
stdlib_version.fypp
)

# Preprocessed files to contain preprocessor directives -> .F90
# Preprocessed files to contain preprocessor directives -> .F90
set(cppFiles
stdlib_linalg_constants.fypp
stdlib_linalg_blas.fypp
Expand Down Expand Up @@ -97,6 +99,7 @@ set(SRC
stdlib_ansi_operator.f90
stdlib_ansi_to_string.f90
stdlib_array.f90
stdlib_codata.f90
stdlib_error.f90
stdlib_hashmap_wrappers.f90
stdlib_hashmaps.f90
Expand Down
Loading
Loading