+95
-8
lines changedFilter options
+95
-8
lines changed Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
1
1
# Fortran Standard Library
2
2
3
+
[](https://github.com/fortran-lang/stdlib/actions)
4
+
[](https://github.com/fortran-lang/stdlib/actions)
5
+
6
+
3
7
## Goals and Motivation
4
8
5
9
The Fortran Standard, as published by the ISO (https://wg5-fortran.org/), does
@@ -31,19 +35,19 @@ The goal of the Fortran Standard Library is to achieve the following general sco
31
35
32
36
### Get the code
33
37
34
-
```
38
+
```sh
35
39
git clone https://github.com/fortran-lang/stdlib
36
40
cd stdlib
37
41
```
38
42
39
43
### Build with CMake
40
44
41
-
```
42
-
mkdir build
43
-
cd build
44
-
cmake ..
45
-
make
46
-
ctest
45
+
```sh
46
+
cmake -B build
47
+
48
+
cmake --build build
49
+
50
+
cmake --build build --target test
47
51
```
48
52
49
53
### Build with make
Original file line number Diff line number Diff line change
@@ -2,8 +2,9 @@ set(SRC
2
2
stdlib_experimental_ascii.f90
3
3
stdlib_experimental_io.f90
4
4
stdlib_experimental_error.f90
5
-
stdlib_experimental_optval.f90
6
5
stdlib_experimental_kinds.f90
6
+
stdlib_experimental_optval.f90
7
+
stdlib_experimental_system.F90
7
8
)
8
9
9
10
add_library(fortran_stdlib ${SRC})
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
1
+
module stdlib_experimental_system
2
+
use, intrinsic :: iso_c_binding, only : c_int, c_long
3
+
implicit none
4
+
private
5
+
public :: sleep
6
+
7
+
interface
8
+
#ifdef _WIN32
9
+
subroutine winsleep(dwMilliseconds) bind (C, name='Sleep')
10
+
!! void Sleep(DWORD dwMilliseconds)
11
+
!! https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-sleep
12
+
import c_long
13
+
integer(c_long), value, intent(in) :: dwMilliseconds
14
+
end subroutine winsleep
15
+
#else
16
+
integer(c_int) function usleep(usec) bind (C)
17
+
!! int usleep(useconds_t usec);
18
+
!! https://linux.die.net/man/3/usleep
19
+
import c_int
20
+
integer(c_int), value, intent(in) :: usec
21
+
end function usleep
22
+
#endif
23
+
end interface
24
+
25
+
contains
26
+
27
+
subroutine sleep(millisec)
28
+
integer, intent(in) :: millisec
29
+
integer(c_int) :: ierr
30
+
31
+
#ifdef _WIN32
32
+
!! PGI Windows, Ifort Windows, ....
33
+
call winsleep(int(millisec, c_long))
34
+
#else
35
+
!! Linux, Unix, MacOS, MSYS2, ...
36
+
ierr = usleep(int(millisec * 1000, c_int))
37
+
if (ierr/=0) error stop 'problem with usleep() system call'
38
+
#endif
39
+
40
+
41
+
end subroutine sleep
42
+
43
+
end module stdlib_experimental_system
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ endmacro(ADDTEST)
9
9
add_subdirectory(ascii)
10
10
add_subdirectory(io)
11
11
add_subdirectory(optval)
12
+
add_subdirectory(system)
12
13
13
14
ADDTEST(always_skip)
14
15
set_tests_properties(always_skip PROPERTIES SKIP_RETURN_CODE 77)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1
+
add_executable(test_sleep test_sleep.f90)
2
+
target_link_libraries(test_sleep fortran_stdlib)
3
+
4
+
add_test(NAME Sleep COMMAND $<TARGET_FILE:test_sleep> 350)
5
+
set_tests_properties(Sleep PROPERTIES TIMEOUT 1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
1
+
program test_sleep
2
+
use, intrinsic :: iso_fortran_env, only : int64, real64
3
+
use stdlib_experimental_system, only : sleep
4
+
5
+
implicit none
6
+
7
+
integer :: ierr, millisec
8
+
character(8) :: argv
9
+
integer(int64) :: tic, toc, trate
10
+
real(real64) :: t_ms
11
+
12
+
call system_clock(count_rate=trate)
13
+
14
+
millisec = 780
15
+
call get_command_argument(1, argv, status=ierr)
16
+
if (ierr==0) read(argv,*) millisec
17
+
18
+
if (millisec<0) millisec=0
19
+
20
+
call system_clock(count=tic)
21
+
call sleep(millisec)
22
+
call system_clock(count=toc)
23
+
24
+
t_ms = (toc-tic) * 1000._real64 / trate
25
+
26
+
if (millisec > 0) then
27
+
if (t_ms < 0.5 * millisec) error stop 'actual sleep time was too short'
28
+
if (t_ms > 2 * millisec) error stop 'actual sleep time was too long'
29
+
endif
30
+
31
+
print '(A,F8.3)', 'OK: test_sleep: slept for (ms): ',t_ms
32
+
33
+
end program
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4