Skip to content

Commit

Permalink
mkdir
Browse files Browse the repository at this point in the history
  • Loading branch information
zoziha committed Dec 5, 2023
1 parent 715afc6 commit 2a100a6
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/sph.f90
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ program sph

use sph_kind, only: rk
use parameter
use output_m, only: mkdirs
implicit none

!> 在模拟中所使用的粒子总数
Expand All @@ -41,13 +42,14 @@ program sph
if (shocktube) dt = 0.005_rk
if (shearcavity) dt = 5.e-5_rk
call input(x, vx, mass, rho, p, u, itype, hsml, ntotal)
call mkdirs()
1 write (*, *) ' ***************************************************'
write (*, *) ' please input the maximal time steps '
write (*, *) ' ***************************************************'
read (*, *) maxtimestep
call time_integration(x, vx, mass, rho, p, u, c, s, e, itype, hsml, ntotal, maxtimestep, dt)

!> 输出最后一个时间布的求解信息
!> 输出最后一个时间步的求解信息
call output(x, vx, mass, rho, p, u, c, itype, hsml, ntotal)

write (*, *) ' ***************************************************'
Expand Down
13 changes: 13 additions & 0 deletions src/output/output_m.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
module output_m

use utils, only: to_string
use filesystem, only: exists, mkdir
implicit none

contains
Expand Down Expand Up @@ -77,4 +78,16 @@ subroutine output_all(x, vx, mass, rho, p, u, c, itype, hsml, ntotal, n)

end subroutine output_all

!> 创建文件夹
subroutine mkdirs()

if (.not. exists("data\\all", is_directory=.true.)) then
call mkdir('data\\all')
end if
if (.not. exists("data\\paraview", is_directory=.true.)) then
call mkdir('data\\paraview')
end if

end subroutine mkdirs

end module output_m
54 changes: 54 additions & 0 deletions src/utils/filesystem.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
module filesystem

implicit none

contains

!> 判断当前系统是否为 Windows 系统
logical function is_windows()
character(16) :: os_name
logical, save :: is_windows_ = .false.
logical, save :: is_first_run = .true.

if (is_first_run) then
call get_environment_variable("OS", os_name)
is_windows_ = trim(os_name) == "Windows_NT"
is_first_run = .false.
is_windows = is_windows_
else
is_windows = is_windows_
end if

end function is_windows

!> 创建目录
subroutine mkdir(path)
character(*), intent(in) :: path !! 目录路径

if (is_windows()) then
call execute_command_line("md "//path)
else
call execute_command_line("mkdir -p "//path)
end if

end subroutine mkdir

!> 判断目录是否存在
function exists(path, is_directory)
character(*), intent(in) :: path !! 目录路径
logical, intent(in), optional :: is_directory !! 是否为目录
logical :: exists

#if defined __INTEL_COMPILER
if (present(is_directory)) then
if (is_directory) then
inquire (directory=path, exist=exists)
return
end if
end if
#endif
inquire (file=path, exist=exists)

end function exists

end module filesystem
2 changes: 1 addition & 1 deletion src/utils/utils.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module utils
implicit none

contains

! SPDX-Identifier: MIT
!> 将整数转化为字符串。借鉴了Fortran标准库的to_string。
!> Change integer to string.
Expand Down

0 comments on commit 2a100a6

Please sign in to comment.