I have a Fortran program which save a file (fort.111) each time the program (./test) is called.
I create another program (main.f90) which use EXECUTE_COMMAND_LINE
statement to move the fort.111 file to another file each time this second program is launched.
The skeleton should be:
- launch './main' which launches './test' -> give me the fort.111 file
- I move fort.111 to another file #.dat
- Repeat the do-loop in main N times.
This should give me N file.dat from let's say 1.dat to N.dat.
My attempt is, for the test.f90 program:
program test
implicit none
!! Create a file named fort.111 each time is launched
open(unit=20,file='fort.111')
write(20,*) 'I am the program called by main!'
close(20)
end program test
And for the main program:
program main
implicit none
integer :: i
integer, parameter :: n = 1158
call EXECUTE_COMMAND_LINE("COUNTER=0") ! initialize the counter
do i = 1,n
call EXECUTE_COMMAND_LINE("./test") ! launch the program ./test
call EXECUTE_COMMAND_LINE("COUNTER=$((COUNTER + 1))") ! update the counter
call EXECUTE_COMMAND_LINE("mv fort.111 $COUNTER.dat") ! mv the file to the new one
end do
end program main
The problem is in the mv
command since I can't figure out how to move fort.111 to 1.dat and pass to the next one (i.e.: fort.111 -> 2.dat, fort.111 -> 3.dat ...)