Skip to content

Commit 96eed56

Browse files
committed
added specs
1 parent a932653 commit 96eed56

File tree

2 files changed

+86
-6
lines changed

2 files changed

+86
-6
lines changed

doc/specs/stdlib_system.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,83 @@ Returns one of the `integer` `OS_*` parameters representing the OS type, from th
418418

419419
---
420420

421+
## `fs_error` - Helper function for error handling
422+
423+
### Status
424+
425+
Experimental
426+
427+
### Description
428+
429+
A helper function for returning the `type(state_type)` with the flag `STDLIB_FS_ERROR` set.
430+
431+
### Syntax
432+
433+
`err = fs_error([a1,a2,a3,a4...... a20])`
434+
435+
### Class
436+
Pure Function
437+
438+
### Arguments
439+
440+
`a1,a2,a3.....a20`(optional) : They are of type `class(*), dimension(..), optional, intent(in)`.
441+
An arbitrary list of `integer`, `real`, `complex`, or `character` variables. Numeric variables may be provided as either scalars or rank-1 (array) inputs.
442+
443+
### Behavior
444+
445+
Formats all the arguments into a nice error message, utilising the constructor of [[stdlib_system(module):state_type(type)]]
446+
447+
### Return values
448+
449+
`type(state_type)`
450+
451+
### Example
452+
453+
```fortran
454+
{!example/system/example_fs_error.f90!}
455+
```
456+
457+
---
458+
459+
## `fs_error_code` - Helper function for error handling (with error code)
460+
461+
### Status
462+
463+
Experimental
464+
465+
### Description
466+
467+
A helper function for returning the `type(state_type)` with the flag `STDLIB_FS_ERROR` set.
468+
It also formats and prefixes the `code` passed to it as the first argument.
469+
470+
### Syntax
471+
472+
`err = fs_error(code [, a1,a2,a3,a4...... a19])`
473+
474+
### Class
475+
Pure Function
476+
477+
### Arguments
478+
479+
`a1,a2,a3.....a19`: They are of type `class(*), dimension(..), optional, intent(in)`.
480+
An arbitrary list of `integer`, `real`, `complex`, or `character` variables. Numeric variables may be provided as either scalars or rank-1 (array) inputs.
481+
482+
### Behavior
483+
484+
Formats all the arguments into a nice error message, utilising the constructor of [[stdlib_system(module):state_type(type)]]
485+
486+
### Return values
487+
488+
`type(state_type)`
489+
490+
### Example
491+
492+
```fortran
493+
{!example/system/example_fs_error.f90!}
494+
```
495+
496+
---
497+
421498
## `is_directory` - Test if a path is a directory
422499

423500
### Status

src/stdlib_system.F90

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,15 @@ module stdlib_system
137137
!! version: experimental
138138
!!
139139
!! A helper function for returning the `type(state_type)` with the flag `STDLIB_FS_ERROR` set.
140+
!! ([Specification](../page/specs/stdlib_system.html#fs_error))
140141
!!
141142
public :: fs_error
143+
142144
!! version: experimental
143145
!!
144146
!! A helper function for returning the `type(state_type)` with the flag `STDLIB_FS_ERROR` set.
145147
!! It also formats and prefixes the `code` passed to it as the first argument
148+
!! ([Specification](../page/specs/stdlib_system.html#fs_error_code))
146149
!!
147150
public :: fs_error_code
148151

@@ -783,21 +786,21 @@ subroutine delete_file(path, err)
783786
end subroutine delete_file
784787

785788
pure function fs_error_code(code,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10, &
786-
a11,a12,a13,a14,a15,a16,a17,a18) result(state)
789+
a11,a12,a13,a14,a15,a16,a17,a18, a19) result(state)
787790

788791
type(state_type) :: state
789792
!> Platform specific error code
790793
integer, intent(in) :: code
791794
!> Optional rank-agnostic arguments
792795
class(*), intent(in), optional, dimension(..) :: a1,a2,a3,a4,a5,a6,a7,a8,a9,a10, &
793-
a11,a12,a13,a14,a15,a16,a17,a18
796+
a11,a12,a13,a14,a15,a16,a17,a18, a19
794797

795-
character(:), allocatable :: code_str
798+
character(32) :: code_msg
796799

797-
code_str = to_string(code) // ","
800+
write(code_msg, "('code - ', i0, ',')") code
798801

799-
state = state_type(STDLIB_FS_ERROR, "code -",code_str,a1,a2,a3,a4,a5,a6,a7,a8, &
800-
a9,a10,a11,a12,a13,a14,a15,a16,a17,a18)
802+
state = state_type(STDLIB_FS_ERROR, code_msg,a1,a2,a3,a4,a5,a6,a7,a8, &
803+
a9,a10,a11,a12,a13,a14,a15,a16,a17,a18, a19)
801804
end function fs_error_code
802805

803806
pure function fs_error(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11, &

0 commit comments

Comments
 (0)