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 !> Creates a directory and all its parents if it does not exist
16 !! @param dir_name Directory path
17 impure subroutine s_create_directory(dir_name)
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 !> @brief Deletes a file at the given path using a platform-specific system command.
29 impure subroutine s_delete_file(filepath)
30 character(LEN=*), intent(in) :: filepath
31
32#ifdef _WIN32
33 call system('del "'//filepath//'"')
34#else
35 call system('rm "'//filepath//'"')
36#endif
37
38 end subroutine s_delete_file
39
40 !> @brief Recursively deletes a directory using a platform-specific system command.
41 impure subroutine s_delete_directory(dir_name)
42 character(LEN=*), intent(in) :: dir_name
43
44#ifdef _WIN32
45 call system('rmdir "'//dir_name//'" /s /q')
46#else
47 call system('rm -r "'//dir_name//'"')
48#endif
49
50 end subroutine s_delete_directory
51
52 !> Inquires on the existence of a directory
53 !! @param fileloc File directory location
54 !! @param dircheck Switch that indicates if directory exists
55 impure subroutine my_inquire(fileloc, dircheck)
56 character(LEN=*), intent(in) :: fileloc
57 logical, intent(inout) :: dircheck
58
59#ifdef __INTEL_COMPILER
60 inquire (directory=trim(fileloc), exist=dircheck) !Intel
61#else
62 inquire (file=trim(fileloc), exist=dircheck) !GCC
63#endif
64
65 end subroutine my_inquire
66
67 !> @brief Retrieves the current working directory path via the GETCWD intrinsic.
68 impure subroutine s_get_cwd(cwd)
69 character(LEN=*), intent(out) :: cwd
70
71 call getcwd(cwd)
72 end subroutine s_get_cwd
73
74 !> @brief Extracts the base filename from a directory path using the system basename command.
75 impure subroutine s_get_basename(dirpath, basename)
76 character(LEN=*), intent(in) :: dirpath
77 character(LEN=*), intent(out) :: basename
78
79 integer :: iunit
80 character(len=30) :: tmpfilepath
81
82 write (tmpfilepath, '(A,I0)') 'basename_', proc_rank
83
84#ifdef _WIN32
85 call system('for /F %i in ("'//trim(dirpath)//'") do @echo %~ni > '//trim(tmpfilepath))
86#else
87 call system('basename "'//trim(dirpath)//'" > '//trim(tmpfilepath))
88#endif
89
90 open (newunit=iunit, file=trim(tmpfilepath), form='formatted', status='old')
91 read (iunit, '(A)') basename
92 close (iunit)
93
94 call s_delete_file(trim(tmpfilepath))
95
96 end subroutine s_get_basename
97
98end module m_compile_specific
Platform-specific file and directory operations: create, delete, inquire, getcwd, and basename.
impure subroutine s_delete_file(filepath)
Deletes a file at the given path using a platform-specific system command.
impure subroutine s_get_basename(dirpath, basename)
Extracts the base filename from a directory path using the system basename command.
impure subroutine s_delete_directory(dir_name)
Recursively deletes a directory using a platform-specific system command.
impure subroutine s_get_cwd(cwd)
Retrieves 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)
Creates 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.