MFC
Exascale flow solver
Loading...
Searching...
No Matches
m_compile_specific.f90
Go to the documentation of this file.
1!>
2!! @file
3!! @brief Contains module m_compile_specific
4
5!> @brief Platform-specific file and directory operations: create, delete, inquire, getcwd, and basename
7
8 ! Dependencies
10
11 implicit none
12
13contains
14
15 !> Create a directory and all its parents if it does not exist
16 impure subroutine s_create_directory(dir_name)
17
18 character(LEN=*), intent(in) :: dir_name
19
20#ifdef _WIN32
21 call system('mkdir "' // dir_name // '" 2> NUL')
22#else
23 call system('mkdir -p "' // dir_name // '"')
24#endif
25
26 end subroutine s_create_directory
27
28 !> Delete a file at the given path using a platform-specific system command.
29 impure subroutine s_delete_file(filepath)
30
31 character(LEN=*), intent(in) :: filepath
32
33#ifdef _WIN32
34 call system('del "' // filepath // '"')
35#else
36 call system('rm "' // filepath // '"')
37#endif
38
39 end subroutine s_delete_file
40
41 !> Recursively delete a directory using a platform-specific system command.
42 impure subroutine s_delete_directory(dir_name)
43
44 character(LEN=*), intent(in) :: dir_name
45
46#ifdef _WIN32
47 call system('rmdir "' // dir_name // '" /s /q')
48#else
49 call system('rm -r "' // dir_name // '"')
50#endif
51
52 end subroutine s_delete_directory
53
54 !> Inquires on the existence of a directory
55 !! @param dircheck Switch that indicates if directory exists
56 impure subroutine my_inquire(fileloc, dircheck)
57
58 character(LEN=*), intent(in) :: fileloc
59 logical, intent(inout) :: dircheck
60
61#ifdef __INTEL_COMPILER
62 inquire (directory=trim(fileloc), exist=dircheck) ! Intel
63#else
64 inquire (file=trim(fileloc), exist=dircheck) ! GCC
65#endif
66
67 end subroutine my_inquire
68
69 !> Retrieve the current working directory path via the GETCWD intrinsic.
70 impure subroutine s_get_cwd(cwd)
71
72 character(LEN=*), intent(out) :: cwd
73
74 call getcwd(cwd)
75
76 end subroutine s_get_cwd
77
78 !> Extract the base filename from a directory path using the system basename command.
79 impure subroutine s_get_basename(dirpath, basename)
80
81 character(LEN=*), intent(in) :: dirpath
82 character(LEN=*), intent(out) :: basename
83 integer :: iunit
84 character(len=30) :: tmpfilepath
85
86 write (tmpfilepath, '(A,I0)') 'basename_', proc_rank
87
88#ifdef _WIN32
89 call system('for /F %i in ("' // trim(dirpath) // '") do @echo %~ni > ' // trim(tmpfilepath))
90#else
91 call system('basename "' // trim(dirpath) // '" > ' // trim(tmpfilepath))
92#endif
93
94 open (newunit=iunit, file=trim(tmpfilepath), form='formatted', status='old')
95 read (iunit, '(A)') basename
96 close (iunit)
97
98 call s_delete_file(trim(tmpfilepath))
99
100 end subroutine s_get_basename
101
102end module m_compile_specific
Platform-specific file and directory operations: create, delete, inquire, getcwd, and basename.
impure subroutine s_delete_file(filepath)
Delete a file at the given path using a platform-specific system command.
impure subroutine s_get_basename(dirpath, basename)
Extract the base filename from a directory path using the system basename command.
impure subroutine s_delete_directory(dir_name)
Recursively delete a directory using a platform-specific system command.
impure subroutine s_get_cwd(cwd)
Retrieve the current working directory path via the GETCWD intrinsic.
impure subroutine my_inquire(fileloc, dircheck)
Inquires on the existence of a directory.
impure subroutine s_create_directory(dir_name)
Create a directory and all its parents if it does not exist.
MPI gather and scatter operations for distributing post-process grid and flow-variable data.