在我的程序中,我需要存储不同情况的结果文件。我决定创建单独的目录来存储这些结果文件。这里用伪代码来解释具体的情况。
do i=1,N ! N cases of my analysis
U=SPEED(i)
call write_files(U) !Create a new directory for this case and Open files (1 = a.csv, 2 = b.csv) to write data
call postprocess() !Write data in files (a.csv, b.csv)
call close_files() !Close all files (1,2)
end do
subroutine write_files(i)
!Make directory i
!Open file a.csv and b.csv with unit 1 & 2
!Write header information in file a.csv and b.csv
close subroutine
我正在努力将实际变量 U 转换为字符变量,以便我可以使用call system('mkdir out/' trim(U))
创建单独的文件夹来存储我的结果。
我还想提一下,我的变量 U 是速度,就像0.00000, 1.00000, 1.50000
有没有办法可以简化我的目录名称,就像0,1,1.5
etc.
希望我的解释很清楚。如果不让我知道,我会尝试按要求进行编辑。
谢谢你的帮助。
的论证system
需要是一个字符串。因此你必须施放real
到一个字符串并连接mkdir out/
用那根绳子。这是一个简单的例子:
module dirs
contains
function dirname(number)
real,intent(in) :: number
character(len=6) :: dirname
! Cast the (rounded) number to string using 6 digits and
! leading zeros
write (dirname, '(I6.6)') nint(number)
! This is the same w/o leading zeros
!write (dirname, '(I6)') nint(number)
! This is for one digit (no rounding)
!write (dirname, '(F4.1)') number
end function
end module
program dirtest
use dirs
call system('mkdir -p out/' // adjustl(trim( dirname(1.) ) ) )
end program
代替call system(...)
这是非标准的,您可以使用 Fortran 2008 语句execute_command_line
(如果您的编译器支持)。
call execute_command_line ('mkdir -p out/' // adjustl(trim( dirname(1.) ) ) )
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)