在Fortran的SYSTEM子例程中使用变量 [英] Using a variable in Fortran's SYSTEM subroutine
问题描述
如何在system
子例程调用中执行的命令中使用变量?例如,如果要创建多个目录,例如test_1_1
,test_1_2
等,直到test_3_3
,那么我的代码应该是什么?
How do I use a variable in the command executed in a system
subroutine call? For example, if I want to create multiple directories like test_1_1
, test_1_2
, and so on till test_3_3
then what should my code be?
我正在尝试以下代码,但似乎无法弄清楚在####部分中要写什么.
I am trying the following code but can't seem to figure out what to write in #### part.
integer :: i,j
do i = 1,3
do j = 1,3
CALL system('mkdir folder ####')
enddo
enddo
推荐答案
character (len=8) :: test_name
do i=1, 3
do j=1, 3
write (test_name, '( "test_", I1, "_", I1 )' ) i, j
call system ( "mkdir " // test_name )
end do
end do
在我的示例中,只要数字是一位数字,格式就可以使用.如果需要更大的值,则可以使用I2.2
(最多两位,如果是一位,则前导零),或者I0
(需要任何位数).
The format in my example will work as long as the numbers are single digits. If you want larger values you could use I2.2
(for up to two digits, with leading zero, if single digits), or I0
, for whatever number of digits are needed.
这篇关于在Fortran的SYSTEM子例程中使用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!