Skip to content

Commit 34b83a0

Browse files
authored
Merge branch 'fortran-lang:master' into iterative
2 parents 2c519c2 + a8519b6 commit 34b83a0

14 files changed

+1413
-75
lines changed

.github/collab.sh

100644100755
File mode changed.

doc/specs/stdlib_ascii.md

Lines changed: 530 additions & 3 deletions
Large diffs are not rendered by default.

doc/specs/stdlib_system.md

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,191 @@ The function returns a `logical` value:
535535

536536
---
537537

538+
## `make_directory` - Creates an empty directory
539+
540+
### Status
541+
542+
Experimental
543+
544+
### Description
545+
546+
It creates an empty directory with default permissions.
547+
It is designed to work across multiple platforms. On Windows, paths with both forward `/` and backward `\` slashes are accepted.
548+
549+
### Syntax
550+
551+
`call [[stdlib_system(module):make_directory(subroutine)]] (path [,err])`
552+
553+
### Class
554+
555+
Subroutine
556+
557+
### Arguments
558+
559+
`path`: Shall be a character string containing the path of the directory to create. It is an `intent(in)` argument.
560+
561+
`err`(optional): Shall be of type `state_type`, and is used for error handling. It is an `optional, intent(out)` argument.
562+
563+
### Return values
564+
565+
`err` is an optional state return flag. If not requested and an error occurs, an `FS_ERROR` will trigger an error stop.
566+
567+
### Example
568+
569+
```fortran
570+
{!example/system/example_make_directory.f90!}
571+
```
572+
573+
---
574+
575+
## `make_directory_all` - Creates an empty directory with all its parent directories
576+
577+
### Status
578+
579+
Experimental
580+
581+
### Description
582+
583+
It creates an empty directory with default permissions.
584+
It also creates all the necessary parent directories in the path if they do not exist already.
585+
586+
### Syntax
587+
588+
`call [[stdlib_system(module):make_directory_all(subroutine)]] (path [,err])`
589+
590+
### Class
591+
592+
Subroutine
593+
594+
### Arguments
595+
596+
`path`: Shall be a character string containing the path of the directory to create. It is an `intent(in)` argument.
597+
598+
`err`(optional): Shall be of type `state_type`, and is used for error handling. It is an `optional, intent(out)` argument.
599+
600+
### Return values
601+
602+
`err` is an optional state return flag. If not requested and an error occurs, an `FS_ERROR` will trigger an error stop.
603+
604+
### Example
605+
606+
```fortran
607+
{!example/system/example_make_directory.f90!}
608+
```
609+
610+
---
611+
612+
## `remove_directory` - Removes an empty directory
613+
614+
### Status
615+
616+
Experimental
617+
618+
### Description
619+
620+
It deletes an empty directory.
621+
It is designed to work across multiple platforms. On Windows, paths with both forward `/` and backward `\` slashes are accepted.
622+
623+
### Syntax
624+
625+
`call [[stdlib_system(module):remove_directory(subroutine)]] (path, err)`
626+
627+
### Class
628+
629+
Subroutine
630+
631+
### Arguments
632+
633+
`path`: Shall be a character string containing the path of the directory to create. It is an `intent(in)` argument.
634+
635+
`err`(optional): Shall be of type `state_type`, and is used for error handling. It is an `optional, intent(out)` argument.
636+
637+
### Return values
638+
639+
`err` is an optional state return flag. On error if not requested, an `FS_ERROR` will trigger an error stop.
640+
641+
### Example
642+
643+
```fortran
644+
{!example/system/example_remove_directory.f90!}
645+
```
646+
647+
---
648+
649+
## `get_cwd` - Gets the current working directory
650+
651+
### Status
652+
653+
Experimental
654+
655+
### Description
656+
657+
This subroutine retrieves the current working directory the running process is executing from.
658+
It is designed to work across multiple platforms. On Windows, paths with both forward `/` and backward `\` slashes are accepted.
659+
660+
### Syntax
661+
662+
`call [[stdlib_system(module):get_cwd(subroutine)]] (cwd [, err])`
663+
664+
### Class
665+
666+
Subroutine
667+
668+
### Arguments
669+
670+
`cwd`: Shall be a character string for receiving the path of the current working directory (cwd). It is an `intent(out)` argument.
671+
672+
`err`(optional): Shall be of type `state_type`, and is used for error handling. It is an `intent(out)` argument.
673+
674+
### Return values
675+
676+
`err` is an optional state return flag. On error if not requested, an `FS_ERROR` will trigger an error stop.
677+
678+
### Example
679+
680+
```fortran
681+
{!example/system/example_cwd.f90!}
682+
```
683+
684+
---
685+
686+
## `set_cwd` - Sets the current working directory
687+
688+
### Status
689+
690+
Experimental
691+
692+
### Description
693+
694+
This subrotine sets the current working directory the process is executing from.
695+
It is designed to work across multiple platforms. On Windows, paths with both forward `/` and backward `\` slashes are accepted.
696+
697+
### Syntax
698+
699+
`call [[stdlib_system(module):set_cwd(subroutine)]] (path [, err])`
700+
701+
### Class
702+
703+
Subroutine
704+
705+
### Arguments
706+
707+
`path`: Shall be a character string containing the path of the directory. It is an `intent(in)` argument.
708+
709+
`err`(optional): Shall be of type `state_type`, and is used for error handling. It is an `intent(out)` argument.
710+
711+
### Return values
712+
713+
`err` is an optional state return flag. On error if not requested, an `FS_ERROR` will trigger an error stop.
714+
715+
### Example
716+
717+
```fortran
718+
{!example/system/example_cwd.f90!}
719+
```
720+
721+
---
722+
538723
## `null_device` - Return the null device file path
539724

540725
### Status
@@ -571,6 +756,8 @@ None.
571756
{!example/system/example_null_device.f90!}
572757
```
573758

759+
---
760+
574761
## `delete_file` - Delete a file
575762

576763
### Status
@@ -612,6 +799,8 @@ The file is removed from the filesystem if the operation is successful. If the o
612799
{!example/system/example_delete_file.f90!}
613800
```
614801

802+
---
803+
615804
## `join_path` - Joins the provided paths according to the OS
616805

617806
### Status
@@ -674,6 +863,8 @@ The result is an `allocatable` character string or `type(string_type)`
674863
{!example/system/example_path_join.f90!}
675864
```
676865

866+
---
867+
677868
## `split_path` - splits a path immediately following the last separator
678869

679870
### Status
@@ -714,6 +905,8 @@ The splitted path. `head` and `tail`.
714905
{!example/system/example_path_split_path.f90!}
715906
```
716907

908+
---
909+
717910
## `base_name` - The last part of a path
718911

719912
### Status
@@ -749,6 +942,8 @@ A character string or `type(string_type)`.
749942
{!example/system/example_path_base_name.f90!}
750943
```
751944

945+
---
946+
752947
## `dir_name` - Everything except the last part of the path
753948

754949
### Status

example/system/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ ADD_EXAMPLE(path_join)
1616
ADD_EXAMPLE(path_split_path)
1717
ADD_EXAMPLE(path_base_name)
1818
ADD_EXAMPLE(path_dir_name)
19-
19+
ADD_EXAMPLE(make_directory)
20+
ADD_EXAMPLE(remove_directory)
21+
ADD_EXAMPLE(cwd)

example/system/example_cwd.f90

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
! Illustrate the usage of `get_cwd`, `set_cwd`
2+
program example_cwd
3+
use stdlib_system, only: get_cwd, set_cwd
4+
use stdlib_error, only: state_type
5+
implicit none
6+
7+
character(len=:), allocatable :: path
8+
type(state_type) :: err
9+
10+
call get_cwd(path, err)
11+
12+
if (err%error()) then
13+
print *, "Error getting current working directory: "//err%print()
14+
end if
15+
16+
print *, "CWD: "//path
17+
18+
call set_cwd("./src", err)
19+
20+
if (err%error()) then
21+
print *, "Error setting current working directory: "//err%print()
22+
end if
23+
24+
call get_cwd(path, err)
25+
26+
if (err%error()) then
27+
print *, "Error getting current working directory after using set_cwd: "//err%print()
28+
end if
29+
30+
print *, "CWD: "//path
31+
end program example_cwd
32+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
! Illustrate the usage of `make_directory`, `make_directory_all`
2+
program example_make_directory
3+
use stdlib_system, only: make_directory, make_directory_all
4+
use stdlib_error, only: state_type
5+
implicit none
6+
7+
type(state_type) :: err
8+
9+
call make_directory("temp_dir", err)
10+
11+
if (err%error()) then
12+
print *, err%print()
13+
else
14+
print *, "directory created sucessfully"
15+
end if
16+
17+
call make_directory_all("d1/d2/d3/d4", err)
18+
19+
if (err%error()) then
20+
print *, err%print()
21+
else
22+
print *, "nested directories created sucessfully"
23+
end if
24+
25+
end program example_make_directory
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
! Illustrate the usage of `remove_directory`
2+
program example_remove_directory
3+
use stdlib_system, only: remove_directory
4+
use stdlib_error, only: state_type
5+
implicit none
6+
7+
type(state_type) :: err
8+
9+
call remove_directory("directory_to_be_removed", err)
10+
11+
if (err%error()) then
12+
print *, err%print()
13+
else
14+
print *, "directory removed successfully"
15+
end if
16+
17+
end program example_remove_directory

src/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ set(fppFiles
5656
stdlib_specialfunctions_gamma.fypp
5757
stdlib_specialfunctions.fypp
5858
stdlib_specialmatrices.fypp
59-
stdlib_specialmatrices_tridiagonal.fypp
59+
stdlib_specialmatrices_tridiagonal.fypp
6060
stdlib_stats.fypp
6161
stdlib_stats_corr.fypp
6262
stdlib_stats_cov.fypp
@@ -121,6 +121,7 @@ set(SRC
121121
stdlib_system_subprocess.c
122122
stdlib_system_subprocess.F90
123123
stdlib_system_path.f90
124+
stdlib_system.c
124125
stdlib_system.F90
125126
stdlib_sparse.f90
126127
stdlib_specialfunctions_legendre.f90

0 commit comments

Comments
 (0)