Using a variable in Fortran's SYSTEM subroutine

前端 未结 1 1109
自闭症患者
自闭症患者 2021-01-21 09:19

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,

相关标签:
1条回答
  • 2021-01-21 09:44
    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
    

    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.

    0 讨论(0)
提交回复
热议问题