Skip to content

Commit dc51fab

Browse files
committed
Update example and add CMakeLists.txt in constant folder.
1 parent c536ee5 commit dc51fab

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

example/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ endmacro(ADD_EXAMPLE)
99
add_subdirectory(array)
1010
add_subdirectory(ascii)
1111
add_subdirectory(bitsets)
12+
add_subdirectory(constants)
1213
add_subdirectory(error)
1314
add_subdirectory(hashmaps)
1415
add_subdirectory(hash_procedures)

example/constants/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ADD_EXAMPLE(constants)
Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
program example_constants
22
use stdlib_constants, only: c, PI=>PI_dp
33
use stdlib_codata, only: alpha=>ALPHA_PARTICLE_ELECTRON_MASS_RATIO
4-
use stdlib_codata, only: ATOMIC_UNIT_OF_1ST_HYPERPOLARIZABILITY
4+
use stdlib_codata_type, only : to_real
5+
use stdlib_kinds, only: dp, sp
56

6-
call alpha%print()
7+
! Use most common physical constants defined as deouble precision reals
8+
print *, "speed of light in vacuum= ", c
9+
10+
! Use of mathematical constants such as PI
11+
print *, "PI as double precision real= ", PI
12+
13+
! Use codata_constant type for evaluating the value to the desired precision
14+
print *, "Value of alpha... evaluated to double precision=", alpha%to_real(1.0_dp)
15+
print *, "Uncertainty of alpha... evaluated to double precision=", alpha%to_real(1.0_sp, .true.)
16+
print *, "Value of alpha... evaluated to single precision=", alpha%to_real(1.0_sp)
717

8-
print *, ATOMIC_UNIT_OF_1ST_HYPERPOLARIZABILITY%eval_value(1.0)
18+
! Convert a codata constant to a real
19+
print *, "Value of the alpha... evaluated to double precision=", to_real(alpha, 1.0_dp)
920

10-
print *, c
11-
print *, PI
21+
22+
! Print out codata constant attributes: name, value, uncertainty and unit
23+
call alpha%print()
1224

1325
end program example_constants

0 commit comments

Comments
 (0)