Skip to content

Commit 1d40d92

Browse files
committed
add system module
There are a number of capabilities it would be useful to bring from cstdlib and STL. This is an initial demonstration, replacing the non-cross-compiler sleep() with a standard implmeentation that works across compilers and operating systems, with millisecond integer input.
1 parent 961b5ad commit 1d40d92

File tree

7 files changed

+100
-9
lines changed

7 files changed

+100
-9
lines changed

.github/workflows/ci_windows.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CI_windows
2+
3+
on: [push, pull_request]
4+
5+
env:
6+
CI: "ON"
7+
8+
jobs:
9+
Build:
10+
runs-on: windows-latest
11+
strategy:
12+
fail-fast: false
13+
14+
steps:
15+
- uses: actions/checkout@v1
16+
17+
- run: cmake -G "MinGW Makefiles" -DCMAKE_SH="CMAKE_SH-NOTFOUND" -Wdev -B build
18+
env:
19+
FC: gfortran
20+
CC: gcc
21+
CXX: g++
22+
23+
- name: CMake build
24+
run: cmake --build build --parallel
25+
26+
- run: cmake --build build --verbose --parallel 1
27+
if: failure()
28+
29+
- name: CTest
30+
run: ctest --parallel --output-on-failure
31+
working-directory: build

README.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
# Fortran Standard Library
22

3-
## Getting started
3+
[![Actions Status](https://github.com/fortran-lang/stdlib/workflows/CI/badge.svg)](https://github.com/fortran-lang/stdlib/actions)
4+
[![Actions Status](https://github.com/fortran-lang/stdlib/workflows/CI_windows/badge.svg)](https://github.com/fortran-lang/stdlib/actions)
45

5-
### Get the code
6+
## Getting started
67

7-
```
8+
```sh
89
git clone https://github.com/fortran-lang/stdlib
910
cd stdlib
1011
```
1112

1213
### Build with CMake
1314

1415
```
15-
mkdir build
16-
cd build
17-
cmake ..
18-
make
19-
ctest
16+
cmake -B build
17+
18+
cmake --build build
19+
20+
cmake --build build --target test
2021
```
2122

2223
### Build with make

src/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ set(SRC
22
stdlib_experimental_ascii.f90
33
stdlib_experimental_io.f90
44
stdlib_experimental_error.f90
5+
stdlib_experimental_system.F90
56
)
67

78
add_library(fortran_stdlib ${SRC})

src/stdlib_experimental_system.F90

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module stdlib_experimental_system
2+
use, intrinsic :: iso_c_binding, only : c_int
3+
implicit none
4+
private
5+
6+
interface
7+
#ifdef _WIN32
8+
subroutine system_sleep(ms) bind (C, name='Sleep')
9+
import c_int
10+
integer(c_int), value, intent(in) :: ms
11+
end subroutine system_sleep
12+
#else
13+
subroutine system_sleep(us) bind (C, name='usleep')
14+
import c_int
15+
integer(c_int), value, intent(in) :: us
16+
end subroutine system_sleep
17+
#endif
18+
end interface
19+
20+
public :: sleep_millisec
21+
22+
contains
23+
24+
subroutine sleep_millisec(t)
25+
integer, intent(in) :: t
26+
integer(c_int) :: tsys
27+
28+
tsys = int(t, c_int)
29+
30+
#ifndef _WIN32
31+
tsys = int(t, c_int) * 1000
32+
#endif
33+
34+
call system_sleep(tsys)
35+
end subroutine sleep_millisec
36+
37+
end module stdlib_experimental_system

src/tests/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
add_subdirectory(ascii)
22
add_subdirectory(loadtxt)
3-
3+
add_subdirectory(system)

src/tests/system/CMakeLists.txt

+5
Original file line numberDiff line numberDiff 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> 1234)
5+
set_tests_properties(Sleep PROPERTIES TIMEOUT 5)

src/tests/system/test_sleep.f90

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
program sleepy
2+
3+
use stdlib_experimental_system, only : sleep_millisec
4+
5+
integer :: ierr, millisec
6+
character(8) :: argv
7+
8+
millisec = 789
9+
call get_command_argument(1, argv, status=ierr)
10+
if (ierr==0) read(argv,*) millisec
11+
12+
if (millisec<0) millisec=0
13+
14+
call sleep_millisec(millisec)
15+
16+
end program

0 commit comments

Comments
 (0)