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

1 Answer 1

6
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.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for your reply. However, i get the following message on compilation error #5082: Syntax error, found END-OF-FILE when expecting one of: <LABEL> <END-OF-STATEMENT> ; BLOCK BLOCKDATA PROGRAM MODULE TYPE INTEGER REAL ... enddo -----^ compilation aborted for test.f90 (code 1)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.