Skip to content

Commit 9dacc48

Browse files
authored
Merge branch 'fortran-lang:master' into activations
2 parents ea74c87 + 1ba499c commit 9dacc48

10 files changed

+362
-190
lines changed

doc/specs/stdlib_io.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,4 @@ Exceptions trigger an `error stop` unless the optional `err` argument is provide
304304
```fortran
305305
{!example/io/example_get_file.f90!}
306306
```
307+

doc/specs/stdlib_system.md

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Additionally, a callback function can be specified to execute upon process compl
2424

2525
### Syntax
2626

27-
`process = ` [[stdlib_subprocess(module):run(interface)]] `(args [, stdin] [, want_stdout] [, want_stderr] [, callback] [, payload])`
27+
`process = ` [[stdlib_system(module):run(interface)]] `(args [, stdin] [, want_stdout] [, want_stderr] [, callback] [, payload])`
2828

2929
### Arguments
3030

@@ -69,7 +69,7 @@ Additionally, a callback function can be specified to execute upon process compl
6969

7070
### Syntax
7171

72-
`process = ` [[stdlib_subprocess(module):runasync(interface)]] `(args [, stdin] [, want_stdout] [, want_stderr] [, callback] [, payload])`
72+
`process = ` [[stdlib_system(module):runasync(interface)]] `(args [, stdin] [, want_stdout] [, want_stderr] [, callback] [, payload])`
7373

7474
### Arguments
7575

@@ -108,7 +108,7 @@ This is useful for monitoring the status of asynchronous processes created with
108108

109109
### Syntax
110110

111-
`status = ` [[stdlib_subprocess(module):is_running(interface)]] `(process)`
111+
`status = ` [[stdlib_system(module):is_running(interface)]] `(process)`
112112

113113
### Arguments
114114

@@ -139,7 +139,7 @@ This is useful for determining whether asynchronous processes created with the `
139139

140140
### Syntax
141141

142-
`status = ` [[stdlib_subprocess(module):is_completed(interface)]] `(process)`
142+
`status = ` [[stdlib_system(module):is_completed(interface)]] `(process)`
143143

144144
### Arguments
145145

@@ -174,7 +174,7 @@ The result is a real value representing the elapsed time in seconds, measured fr
174174

175175
### Syntax
176176

177-
`delta_t = ` [[stdlib_subprocess(module):elapsed(subroutine)]] `(process)`
177+
`delta_t = ` [[stdlib_system(module):elapsed(subroutine)]] `(process)`
178178

179179
### Arguments
180180

@@ -212,7 +212,7 @@ in case of process hang or delay.
212212

213213
### Syntax
214214

215-
`call ` [[stdlib_subprocess(module):wait(subroutine)]] `(process [, max_wait_time])`
215+
`call ` [[stdlib_system(module):wait(subroutine)]] `(process [, max_wait_time])`
216216

217217
### Arguments
218218

@@ -243,7 +243,7 @@ This is especially useful for monitoring asynchronous processes and retrieving t
243243

244244
### Syntax
245245

246-
`call ` [[stdlib_subprocess(module):update(subroutine)]] `(process)`
246+
`call ` [[stdlib_system(module):update(subroutine)]] `(process)`
247247

248248
### Arguments
249249

@@ -269,7 +269,7 @@ This interface is useful when a process needs to be forcefully stopped, for exam
269269

270270
### Syntax
271271

272-
`call ` [[stdlib_subprocess(module):kill(subroutine)]] `(process, success)`
272+
`call ` [[stdlib_system(module):kill(subroutine)]] `(process, success)`
273273

274274
### Arguments
275275

@@ -431,7 +431,7 @@ It is designed to work across multiple platforms. On Windows, paths with both fo
431431

432432
### Syntax
433433

434-
`result = [[stdlib_io(module):is_directory(function)]] (path)`
434+
`result = [[stdlib_system(module):is_directory(function)]] (path)`
435435

436436
### Class
437437

@@ -492,3 +492,43 @@ None.
492492
{!example/system/example_null_device.f90!}
493493
```
494494

495+
## `delete_file` - Delete a file
496+
497+
### Status
498+
499+
Experimental
500+
501+
### Description
502+
503+
This subroutine deletes a specified file from the filesystem. It ensures that the file exists and is not a directory before attempting deletion.
504+
If the file cannot be deleted due to permissions, being a directory, or other issues, an error is raised.
505+
The function provides an optional error-handling mechanism via the `state_type` class. If the `err` argument is not provided, exceptions will trigger an `error stop`.
506+
507+
### Syntax
508+
509+
`call [[stdlib_system(module):delete_file(subroutine)]] (path [, err])`
510+
511+
### Class
512+
Subroutine
513+
514+
### Arguments
515+
516+
`path`: Shall be a character string containing the path to the file to be deleted. It is an `intent(in)` argument.
517+
518+
`err` (optional): Shall be a `type(state_type)` variable for error handling. If provided, errors are returned as a state object. If not provided, the program stops execution on error.
519+
520+
### Behavior
521+
522+
- Checks if the file exists. If not, an error is raised.
523+
- Ensures the path is not a directory before deletion.
524+
- Attempts to delete the file, raising an error if unsuccessful.
525+
526+
### Return values
527+
528+
The file is removed from the filesystem if the operation is successful. If the operation fails, an error is raised.
529+
530+
### Example
531+
532+
```fortran
533+
{!example/system/example_delete_file.f90!}
534+
```

example/specialfunctions_gamma/example_gamma.f90

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
program example_gamma
2-
use stdlib_kinds, only: dp, int64
2+
use stdlib_kinds, only: sp, dp, int64
33
use stdlib_specialfunctions_gamma, only: gamma
44
implicit none
55

66
integer :: i
77
integer(int64) :: n
88
real :: x
99
real(dp) :: y
10-
complex :: z
11-
complex(dp) :: z1
10+
complex(sp) :: z
1211

1312
i = 10
1413
n = 15_int64
1514
x = 2.5
1615
y = 4.3_dp
1716
z = (2.3, 0.6)
18-
z1 = (-4.2_dp, 3.1_dp)
1917

2018
print *, gamma(i) !integer gives exact result
2119
! 362880
@@ -32,6 +30,4 @@ program example_gamma
3230
print *, gamma(z)
3331
! (0.988054395, 0.383354813)
3432

35-
print *, gamma(z1)
36-
! (-2.78916032990983999E-005, 9.83164600163221218E-006)
3733
end program example_gamma

example/specialfunctions_gamma/example_log_gamma.f90

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
program example_log_gamma
2-
use stdlib_kinds, only: dp
2+
use stdlib_kinds, only: sp, dp
33
use stdlib_specialfunctions_gamma, only: log_gamma
44
implicit none
55

66
integer :: i
77
real :: x
88
real(dp) :: y
9-
complex :: z
10-
complex(dp) :: z1
9+
complex(sp) :: z
1110

1211
i = 10
1312
x = 8.76
1413
y = x
1514
z = (5.345, -3.467)
16-
z1 = z
15+
1716
print *, log_gamma(i) !default single precision output
1817
!12.8018274
1918

@@ -29,7 +28,4 @@ program example_log_gamma
2928

3029
!(2.56165648, -5.73382425)
3130

32-
print *, log_gamma(z1)
33-
34-
!(2.5616575105114614, -5.7338247782852498)
3531
end program example_log_gamma

example/system/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
ADD_EXAMPLE(get_runtime_os)
2+
ADD_EXAMPLE(delete_file)
23
ADD_EXAMPLE(is_directory)
34
ADD_EXAMPLE(null_device)
45
ADD_EXAMPLE(os_type)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
! Demonstrate usage of `delete_file`
2+
program example_delete_file
3+
use stdlib_system, only: delete_file
4+
use stdlib_error, only: state_type
5+
implicit none
6+
7+
type(state_type) :: err
8+
character(*), parameter :: filename = "example.txt"
9+
10+
! Delete a file with error handling
11+
call delete_file(filename, err)
12+
13+
if (err%error()) then
14+
print *, err%print()
15+
else
16+
print *, "File "//filename//" deleted successfully."
17+
end if
18+
end program example_delete_file

0 commit comments

Comments
 (0)