Skip to content

Commit 3519b43

Browse files
authored
Merge branch 'fortran-lang:master' into activations
2 parents 259360f + 60d0a76 commit 3519b43

27 files changed

+881
-131
lines changed

config/cmake/Findtest-drive.cmake

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ foreach(method ${${_pkg}_FIND_METHOD})
123123

124124
# We need the module directory in the subproject before we finish the configure stage
125125
if(NOT EXISTS "${${_pkg}_BINARY_DIR}/include")
126-
make_directory("${${_pkg}_BINARY_DIR}/include")
126+
file(MAKE_DIRECTORY "${${_pkg}_BINARY_DIR}/include")
127127
endif()
128128

129129
break()
@@ -147,7 +147,7 @@ foreach(method ${${_pkg}_FIND_METHOD})
147147
FetchContent_GetProperties("${_lib}" SOURCE_DIR "${_pkg}_SOURCE_DIR")
148148
FetchContent_GetProperties("${_lib}" BINARY_DIR "${_pkg}_BINARY_DIR")
149149
if(NOT EXISTS "${${_pkg}_BINARY_DIR}/include")
150-
make_directory("${${_pkg}_BINARY_DIR}/include")
150+
file(MAKE_DIRECTORY "${${_pkg}_BINARY_DIR}/include")
151151
endif()
152152

153153
break()

doc/specs/stdlib_io.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Loads a rank-2 `array` from a text file.
1717

1818
### Syntax
1919

20-
`call ` [[stdlib_io(module):loadtxt(interface)]] `(filename, array [, skiprows] [, max_rows] [, fmt])`
20+
`call ` [[stdlib_io(module):loadtxt(interface)]] `(filename, array [, skiprows] [, max_rows] [, fmt] [, delimiter])`
2121

2222
### Arguments
2323

@@ -31,7 +31,7 @@ Loads a rank-2 `array` from a text file.
3131

3232
`fmt` (optional): Fortran format specifier for the text read. Defaults to the write format for the data type. Setting fmt='*' will specify list directed read.
3333

34-
34+
`delimiter` (optional): Shall be a character expression of length 1 that contains the delimiter used to separate the columns. The default is `' '`.
3535

3636
### Return value
3737

@@ -52,7 +52,8 @@ Experimental
5252

5353
### Description
5454

55-
Returns the unit number of a file opened to read, to write, or to read and write. The file might be a text file or a binary file. All files are opened using a streamed access.
55+
Returns the unit number of a file opened to read, to write, or to read and write. The file might be a text file or a binary file.
56+
Text files are opened using a sequential access, while binary files are opened using a streamed access.
5657

5758
### Syntax
5859

@@ -105,14 +106,16 @@ Saves a rank-2 `array` into a text file.
105106

106107
### Syntax
107108

108-
`call ` [[stdlib_io(module):savetxt(interface)]] `(filename, array)`
109+
`call ` [[stdlib_io(module):savetxt(interface)]] `(filename, array [, delimiter])`
109110

110111
### Arguments
111112

112113
`filename`: Shall be a character expression containing the name of the file that will contain the 2D `array`.
113114

114115
`array`: Shall be a rank-2 array of type `real`, `complex` or `integer`.
115116

117+
`delimiter` (optional): Shall be a character expression of length 1 that contains the delimiter used to separate the columns. The default is `' '`.
118+
116119
### Output
117120

118121
Provides a text file called `filename` that contains the rank-2 `array`.

doc/specs/stdlib_math.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ Experimental
427427

428428
Elemenal function.
429429

430-
### Description
430+
#### Description
431431

432432
`deg2rad` converts phase angles from degrees to radians.
433433

doc/specs/stdlib_sparse.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ Type-bound procedures to enable requesting data from a sparse matrix.
178178

179179
`v` : Shall be a `real` or `complex` value in accordance to the declared sparse matrix object. If the `ij` tuple is within the sparse pattern, `v` contains the value in the data buffer. If the `ij` tuple is outside the sparse pattern, `v` is equal `0`. If the `ij` tuple is outside the matrix pattern `(nrows,ncols)`, `v` is `NaN`.
180180

181-
## Example
181+
### Example
182182
```fortran
183183
{!example/linalg/example_sparse_data_accessors.f90!}
184184
```
@@ -257,7 +257,7 @@ This module provides facility functions for converting between storage formats.
257257

258258
`chunk`, `optional`: chunk size, only valid in the case of a `SELLC` matrix, by default it will be taken from the `SELLC` default attribute chunk size. It is an `intent(in)` argument.
259259

260-
## Example
260+
### Example
261261
```fortran
262262
{!example/linalg/example_sparse_from_ijv.f90!}
263263
```
@@ -358,7 +358,7 @@ If the `diagonal` array has not been previously allocated, the `diag` subroutine
358358

359359
`coo` : Shall be a `COO` type of `real` or `complex` type. It is an `intent(out)` argument.
360360

361-
## Example
361+
### Example
362362
```fortran
363363
{!example/linalg/example_sparse_spmv.f90!}
364364
```

doc/specs/stdlib_system.md

+157
Original file line numberDiff line numberDiff line change
@@ -335,3 +335,160 @@ Returns a `logical` flag: `.true.` if the system is Windows, or `.false.` otherw
335335
```fortran
336336
{!example/system/example_process_1.f90!}
337337
```
338+
339+
## `get_runtime_os` - Determine the OS type at runtime
340+
341+
### Status
342+
343+
Experimental
344+
345+
### Description
346+
347+
`get_runtime_os` inspects the runtime environment to identify the current OS type. It evaluates environment variables (`OSTYPE`, `OS`) and checks for specific files associated with known operating systems.
348+
The supported OS types are `integer, parameter` variables stored in the `stdlib_system` module:
349+
350+
- **Linux** (`OS_LINUX`)
351+
- **macOS** (`OS_MACOS`)
352+
- **Windows** (`OS_WINDOWS`)
353+
- **Cygwin** (`OS_CYGWIN`)
354+
- **Solaris** (`OS_SOLARIS`)
355+
- **FreeBSD** (`OS_FREEBSD`)
356+
- **OpenBSD** (`OS_OPENBSD`)
357+
358+
If the OS cannot be identified, the function returns `OS_UNKNOWN`.
359+
360+
### Syntax
361+
362+
`os = [[stdlib_system(module):get_runtime_os(function)]]()`
363+
364+
### Class
365+
366+
Function
367+
368+
### Arguments
369+
370+
None.
371+
372+
### Return Value
373+
374+
Returns one of the `integer` `OS_*` parameters representing the OS type, from the `stdlib_system` module, or `OS_UNKNOWN` if undetermined.
375+
376+
### Example
377+
378+
```fortran
379+
{!example/system/example_get_runtime_os.f90!}
380+
```
381+
382+
---
383+
384+
## `OS_TYPE` - Cached OS type retrieval
385+
386+
### Status
387+
388+
Experimental
389+
390+
### Description
391+
392+
`OS_TYPE` provides a cached result of the `get_runtime_os` function. The OS type is determined during the first invocation and stored in a static variable.
393+
Subsequent calls reuse the cached value, making this function highly efficient.
394+
395+
This caching mechanism ensures negligible overhead for repeated calls, unlike `get_runtime_os`, which performs a full runtime inspection.
396+
397+
### Syntax
398+
399+
`os = [[stdlib_system(module):OS_TYPE(function)]]()`
400+
401+
### Class
402+
403+
Function
404+
405+
### Arguments
406+
407+
None.
408+
409+
### Return Value
410+
411+
Returns one of the `integer` `OS_*` parameters representing the OS type, from the `stdlib_system` module, or `OS_UNKNOWN` if undetermined.
412+
413+
### Example
414+
415+
```fortran
416+
{!example/system/example_os_type.f90!}
417+
```
418+
419+
---
420+
421+
## `is_directory` - Test if a path is a directory
422+
423+
### Status
424+
425+
Experimental
426+
427+
### Description
428+
429+
This function checks if a specified file system path is a directory.
430+
It is designed to work across multiple platforms. On Windows, paths with both forward `/` and backward `\` slashes are accepted.
431+
432+
### Syntax
433+
434+
`result = [[stdlib_io(module):is_directory(function)]] (path)`
435+
436+
### Class
437+
438+
Function
439+
440+
### Arguments
441+
442+
`path`: Shall be a character string containing the file system path to evaluate. It is an `intent(in)` argument.
443+
444+
### Return values
445+
446+
The function returns a `logical` value:
447+
448+
- `.true.` if the path matches an existing directory.
449+
- `.false.` otherwise, or if the operating system is unsupported.
450+
451+
### Example
452+
453+
```fortran
454+
{!example/system/example_is_directory.f90!}
455+
```
456+
457+
---
458+
459+
## `null_device` - Return the null device file path
460+
461+
### Status
462+
463+
Experimental
464+
465+
### Description
466+
467+
This function returns the file path of the null device, which is a special file used to discard any data written to it.
468+
It reads as an empty file. The null device's path varies by operating system:
469+
- On Windows, the null device is represented as `NUL`.
470+
- On UNIX-like systems (Linux, macOS), the null device is represented as `/dev/null`.
471+
472+
### Syntax
473+
474+
`path = [[stdlib_system(module):null_device(function)]]()`
475+
476+
### Class
477+
478+
Function
479+
480+
### Arguments
481+
482+
None.
483+
484+
### Return Value
485+
486+
- **Type:** `character(:), allocatable`
487+
- Returns the null device file path as a character string, appropriate for the operating system.
488+
489+
### Example
490+
491+
```fortran
492+
{!example/system/example_null_device.f90!}
493+
```
494+

example/io/example.csv

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1.00000000E+00, 1.00000000E+00
2+
1.00000000E+00, 1.00000000E+00
3+
1.00000000E+00, 1.00000000E+00

example/io/example_loadtxt.f90

+3
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ program example_loadtxt
66

77
! Can also use list directed format if the default read fails.
88
call loadtxt('example.dat', x, fmt='*')
9+
10+
call loadtxt('example.csv', x, delimiter=',')
11+
912
end program example_loadtxt

example/io/example_savetxt.f90

+1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ program example_savetxt
33
implicit none
44
real :: x(3, 2) = 1
55
call savetxt('example.dat', x)
6+
call savetxt('example.csv', x, delimiter=',')
67
end program example_savetxt

example/system/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
ADD_EXAMPLE(get_runtime_os)
2+
ADD_EXAMPLE(is_directory)
3+
ADD_EXAMPLE(null_device)
4+
ADD_EXAMPLE(os_type)
15
ADD_EXAMPLE(process_1)
26
ADD_EXAMPLE(process_2)
37
ADD_EXAMPLE(process_3)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
! Demonstrate usage of (non-cached) runtime OS query
2+
program example_get_runtime_os
3+
use stdlib_system, only: OS_NAME, get_runtime_os
4+
implicit none
5+
6+
! Runtime OS detection (full inspection)
7+
print *, "Runtime OS Type: ", OS_NAME(get_runtime_os())
8+
9+
end program example_get_runtime_os
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
! Demonstrate usage of `is_directory`
2+
program example_is_directory
3+
use stdlib_system, only: is_directory
4+
implicit none
5+
! Test a directory path
6+
if (is_directory("/path/to/check")) then
7+
print *, "The specified path is a directory."
8+
else
9+
print *, "The specified path is not a directory."
10+
end if
11+
end program example_is_directory
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
! Showcase usage of the null device
2+
program example_null_device
3+
use stdlib_system, only: null_device
4+
use iso_fortran_env, only: output_unit
5+
implicit none
6+
integer :: unit
7+
logical :: screen_output = .false.
8+
9+
if (screen_output) then
10+
unit = output_unit
11+
else
12+
! Write to the null device if no screen output is wanted
13+
open(newunit=unit,file=null_device())
14+
endif
15+
16+
write(unit,*) "Hello, world!"
17+
18+
if (.not.screen_output) close(unit)
19+
20+
end program example_null_device

example/system/example_os_type.f90

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
! Demonstrate OS detection
2+
program example_os_type
3+
use stdlib_system, only: OS_TYPE, OS_NAME
4+
implicit none
5+
6+
integer :: current_os
7+
8+
! Cached OS detection
9+
current_os = OS_TYPE()
10+
print *, "Current OS Type: ", OS_NAME(current_os)
11+
12+
end program example_os_type

src/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ set(LIB_MOD_DIR ${CMAKE_CURRENT_BINARY_DIR}/mod_files/)
146146
# We need the module directory before we finish the configure stage since the
147147
# build interface might resolve before the module directory is generated by CMake
148148
if(NOT EXISTS "${LIB_MOD_DIR}")
149-
make_directory("${LIB_MOD_DIR}")
149+
file(MAKE_DIRECTORY "${LIB_MOD_DIR}")
150150
endif()
151151

152152
set_target_properties(${PROJECT_NAME} PROPERTIES

src/stdlib_constants.fypp

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module stdlib_constants
4040
real(dp), parameter, public :: epsilon_0 = VACUUM_ELECTRIC_PERMITTIVITY%value !! vacuum mag. permeability
4141
real(dp), parameter, public :: h = PLANCK_CONSTANT%value !! Planck constant
4242
real(dp), parameter, public :: Planck = PLANCK_CONSTANT%value !! Planck constant
43-
real(dp), parameter, public :: hbar = PLANCK_CONSTANT%value / PI_dp !! Reduced Planck constant
43+
real(dp), parameter, public :: hbar = PLANCK_CONSTANT%value / (2.0_dp * PI_dp) !! Reduced Planck constant
4444
real(dp), parameter, public :: G = NEWTONIAN_CONSTANT_OF_GRAVITATION%value !! Newtonian constant of gravitation
4545
real(dp), parameter, public :: gravitation_constant = NEWTONIAN_CONSTANT_OF_GRAVITATION%value !! Newtonian constant of gravitation
4646
real(dp), parameter, public :: g2 = STANDARD_ACCELERATION_OF_GRAVITY%value !! Standard acceleration of gravity

0 commit comments

Comments
 (0)