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 !> Inquire on the existence of a directory or file
55 impure subroutine my_inquire(fileloc, dircheck)
56
57 character(LEN=*), intent(in) :: fileloc
58 logical, intent(inout) :: dircheck
59
60#ifdef __INTEL_COMPILER
61 block
62 logical :: file_exist, dir_exist
63 inquire (file=trim(fileloc), exist=file_exist)
64 inquire (directory=trim(fileloc), exist=dir_exist)
65 dircheck = file_exist .or. dir_exist
66 end block
67#else
68 inquire (file=trim(fileloc), exist=dircheck) ! GCC
69#endif
70
71 end subroutine my_inquire
72
73 !> Retrieve the current working directory path via the GETCWD intrinsic.
74 impure subroutine s_get_cwd(cwd)
75
76 character(LEN=*), intent(out) :: cwd
77
78 call getcwd(cwd)
79
80 end subroutine s_get_cwd
81
82 !> Extract the base filename from a directory path using the system basename command.
83 impure subroutine s_get_basename(dirpath, basename)
84
85 character(LEN=*), intent(in) :: dirpath
86 character(LEN=*), intent(out) :: basename
87 integer :: iunit
88 character(len=30) :: tmpfilepath
89
90 write (tmpfilepath, '(A,I0)') 'basename_', proc_rank
91
92#ifdef _WIN32
93 call system('for /F %i in ("' // trim(dirpath) // '") do @echo %~ni > ' // trim(tmpfilepath))
94#else
95 call system('basename "' // trim(dirpath) // '" > ' // trim(tmpfilepath))
96#endif
97
98 open (newunit=iunit, file=trim(tmpfilepath), form='formatted', status='old')
99 read (iunit, '(A)') basename
100 close (iunit)
101
102 call s_delete_file(trim(tmpfilepath))
103
104 end subroutine s_get_basename
105
106end 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)
Inquire on the existence of a directory or file.
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.