-2

I am trying to design a fortran77 program that creates 17 directories in unix then does various other things, but creating the directories has been the biggest problem so that's all i'd like to focus on at the moment.

For example:

do i=1,17
cmd="mkdir" ,i
call system(cmd)

call chdir("i")
end do

From that portion of code I want the command "mkdir" to create 17 separate directories in unix named from 1-17, but when I try to compile the program I get an error that says "invalid radix specifier" focusing on the second line of code I listed.

Another error is also produced focusing on the same line of code. "Concatenation operator at (^) must operate on two sub expressions of character type, but the sub expression at (^) is not of character type.

Is there a way to convert integers to strings?

All help would be appreciated thanks.

P1255
  • 1
  • And I would rather not do "cmd="mkdir 1 2 3 4 5... 17" I have to designate input files to all of the directories from the same code later. – P1255 Jul 01 '15 at 19:42
  • Also http://stackoverflow.com/questions/16291270/looping-over-variable-file-names and http://stackoverflow.com/questions/1262695/converting-integers-to-strings-in-fortran and other. – Vladimir F Героям слава Jul 01 '15 at 20:54

1 Answers1

0

To answer one of your questions, you can convert an integer to a string by writing to it. Consider the example code:

program main
integer :: i
character(len=80) :: cmd

do i=1,4
   write(cmd,'(a,i0.2)') 'mkdir Directory_', i
   write(*,*) 'calling "', trim(cmd), '"'
   call system(cmd)
enddo

end program main

which gives output

mach5% pgfortran main.f90; ./a.out 
 calling "mkdir Directory_01"
 calling "mkdir Directory_02"
 calling "mkdir Directory_03"
 calling "mkdir Directory_04"
mach5% ls
total 860
-rwx------ 1 chaud106 806765 Jul  1 15:37 a.out*
drwx------ 2 chaud106   4096 Jul  1 15:37 Directory_01/
drwx------ 2 chaud106   4096 Jul  1 15:37 Directory_02/
drwx------ 2 chaud106   4096 Jul  1 15:37 Directory_03/
drwx------ 2 chaud106   4096 Jul  1 15:37 Directory_04/
-rw------- 1 chaud106    195 Jul  1 15:37 main.f90
Ross
  • 2,130
  • 14
  • 25