Skip to content

Commit fc538db

Browse files
authored
Merge branch 'fortran-lang:master' into master
2 parents 7c90998 + 718ac3a commit fc538db

30 files changed

+2499
-193
lines changed

doc/specs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This is an index/directory of the specifications (specs) for each new module/fea
1414
- [ansi](./stdlib_ansi.html) - Terminal color and style escape sequences
1515
- [array](./stdlib_array.html) - Procedures for index manipulation and array handling
1616
- [ascii](./stdlib_ascii.html) - Procedures for handling ASCII characters
17+
- [constants](./stdlib_constants.html) - Constants
1718
- [bitsets](./stdlib_bitsets.html) - Bitset data types and procedures
1819
- [error](./stdlib_error.html) - Catching and handling errors
1920
- [hash](./stdlib_hash_procedures.html) - Hashing integer

doc/specs/stdlib_constants.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
```

doc/specs/stdlib_linalg.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ Result vector `x` returns the approximate solution that minimizes the 2-norm \(
767767

768768
`b`: Shall be a rank-1 or rank-2 array of the same kind as `a`, containing one or more right-hand-side vector(s), each in its leading dimension. It is an `intent(in)` argument.
769769

770-
`x`: Shall be an array of same kind and rank as `b`, containing the solution(s) to the least squares system. It is an `intent(inout)` argument.
770+
`x`: Shall be an array of same kind and rank as `b`, and leading dimension of at least `n`, containing the solution(s) to the least squares system. It is an `intent(inout)` argument.
771771

772772
`real_storage` (optional): Shall be a `real` rank-1 array of the same kind `a`, providing working storage for the solver. It minimum size can be determined with a call to [[stdlib_linalg(module):lstsq_space(interface)]]. It is an `intent(inout)` argument.
773773

doc/specs/stdlib_sorting.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ module's `string_type` type.
2525
## Overview of the module
2626

2727
The module `stdlib_sorting` defines several public entities, one
28-
default integer parameter, `int_size`, and four overloaded
28+
default integer parameter, `int_index`, and four overloaded
2929
subroutines: `ORD_SORT`, `SORT`, `RADIX_SORT` and `SORT_INDEX`. The
3030
overloaded subroutines also each have several specific names for
3131
versions corresponding to different types of array arguments.
3232

33-
### The `int_size` parameter
33+
### The `int_index` parameter
3434

35-
The `int_size` parameter is used to specify the kind of integer used
36-
in indexing the various arrays. Currently the module sets `int_size`
35+
The `int_index` parameter is used to specify the kind of integer used
36+
in indexing the various arrays. Currently the module sets `int_index`
3737
to the value of `int64` from the `stdlib_kinds` module.
3838

3939
### The module subroutines
@@ -414,7 +414,7 @@ It is an `intent(inout)` argument. On input it
414414
will be an array whose sorting indices are to be determined. On return
415415
it will be the sorted array.
416416

417-
`index`: shall be a rank one integer array of kind `int_size` and of
417+
`index`: shall be a rank one integer array of kind `int_index` and of
418418
the size of `array`. It is an `intent(out)` argument. On return it
419419
shall have values that are the indices needed to sort the original
420420
array in the desired direction.
@@ -427,7 +427,7 @@ static storage, its use can significantly reduce the stack memory
427427
requirements for the code. Its contents on return are undefined.
428428

429429
`iwork` (optional): shall be a rank one integer array of kind
430-
`int_size`, and shall have at least `size(array)/2` elements. It
430+
`int_index`, and shall have at least `size(array)/2` elements. It
431431
is an `intent(out)` argument. It is intended to be used as "scratch"
432432
memory for internal record keeping. If associated with an array in
433433
static storage, its use can significantly reduce the stack memory
@@ -465,8 +465,8 @@ Sorting a related rank one array:
465465
integer, intent(inout) :: a(:)
466466
integer(int32), intent(inout) :: b(:) ! The same size as a
467467
integer(int32), intent(out) :: work(:)
468-
integer(int_size), intent(out) :: index(:)
469-
integer(int_size), intent(out) :: iwork(:)
468+
integer(int_index), intent(out) :: index(:)
469+
integer(int_index), intent(out) :: iwork(:)
470470
! Find the indices to sort a
471471
call sort_index(a, index(1:size(a)),&
472472
work(1:size(a)/2), iwork(1:size(a)/2))
@@ -483,8 +483,8 @@ Sorting a rank 2 array based on the data in a column
483483
integer, intent(inout) :: array(:,:)
484484
integer(int32), intent(in) :: column
485485
integer(int32), intent(out) :: work(:)
486-
integer(int_size), intent(out) :: index(:)
487-
integer(int_size), intent(out) :: iwork(:)
486+
integer(int_index), intent(out) :: index(:)
487+
integer(int_index), intent(out) :: iwork(:)
488488
integer, allocatable :: dummy(:)
489489
integer :: i
490490
allocate(dummy(size(array, dim=1)))
@@ -508,8 +508,8 @@ Sorting an array of a derived type based on the data in one component
508508
type(a_type), intent(inout) :: a_data(:)
509509
integer(int32), intent(inout) :: a(:)
510510
integer(int32), intent(out) :: work(:)
511-
integer(int_size), intent(out) :: index(:)
512-
integer(int_size), intent(out) :: iwork(:)
511+
integer(int_index), intent(out) :: index(:)
512+
integer(int_index), intent(out) :: iwork(:)
513513
! Extract a component of `a_data`
514514
a(1:size(a_data)) = a_data(:) % a
515515
! Find the indices to sort the component

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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
program example_constants
2+
use stdlib_constants, only: c, pi=>PI_dp
3+
use stdlib_codata, only: alpha=>ALPHA_PARTICLE_ELECTRON_MASS_RATIO
4+
use stdlib_codata_type, only : to_real
5+
use stdlib_kinds, only: dp, sp
6+
7+
! Use most common physical constants defined as double 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)
17+
18+
! Convert a codata constant to a real
19+
print *, "Value of the alpha... evaluated to double precision=", to_real(alpha, 1.0_dp)
20+
21+
22+
! Print out codata constant attributes: name, value, uncertainty and unit
23+
call alpha%print()
24+
25+
end program example_constants

src/CMakeLists.txt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ set(fppFiles
66
stdlib_bitsets.fypp
77
stdlib_bitsets_64.fypp
88
stdlib_bitsets_large.fypp
9-
stdlib_hash_32bit.fypp
9+
stdlib_codata_type.fypp
10+
stdlib_constants.fypp
11+
stdlib_hash_32bit.fypp
1012
stdlib_hash_32bit_fnv.fypp
11-
stdlib_hash_32bit_nm.fypp
12-
stdlib_hash_32bit_water.fypp
13-
stdlib_hash_64bit.fypp
14-
stdlib_hash_64bit_fnv.fypp
15-
stdlib_hash_64bit_pengy.fypp
16-
stdlib_hash_64bit_spookyv2.fypp
13+
stdlib_hash_32bit_nm.fypp
14+
stdlib_hash_32bit_water.fypp
15+
stdlib_hash_64bit.fypp
16+
stdlib_hash_64bit_fnv.fypp
17+
stdlib_hash_64bit_pengy.fypp
18+
stdlib_hash_64bit_spookyv2.fypp
1719
stdlib_io.fypp
1820
stdlib_io_npy.fypp
1921
stdlib_io_npy_load.fypp
@@ -25,9 +27,9 @@ set(fppFiles
2527
stdlib_linalg_outer_product.fypp
2628
stdlib_linalg_kronecker.fypp
2729
stdlib_linalg_cross_product.fypp
28-
stdlib_linalg_solve.fypp
30+
stdlib_linalg_solve.fypp
2931
stdlib_linalg_determinant.fypp
30-
stdlib_linalg_state.fypp
32+
stdlib_linalg_state.fypp
3133
stdlib_optval.fypp
3234
stdlib_selection.fypp
3335
stdlib_sorting.fypp
@@ -68,7 +70,7 @@ set(fppFiles
6870
stdlib_version.fypp
6971
)
7072

71-
# Preprocessed files to contain preprocessor directives -> .F90
73+
# Preprocessed files to contain preprocessor directives -> .F90
7274
set(cppFiles
7375
stdlib_linalg_constants.fypp
7476
stdlib_linalg_blas.fypp
@@ -97,6 +99,7 @@ set(SRC
9799
stdlib_ansi_operator.f90
98100
stdlib_ansi_to_string.f90
99101
stdlib_array.f90
102+
stdlib_codata.f90
100103
stdlib_error.f90
101104
stdlib_hashmap_wrappers.f90
102105
stdlib_hashmaps.f90

0 commit comments

Comments
 (0)