Antigoni
Antigoni

Reputation: 11

Create files in different folders changing at each loop

I have a loop and each time I write a file in the main directory, whose name changes with loop variable. E.g. for the loop

do i=1,10

I create and write data in the files test1.out, test2.out, ..., test10.out.

What I want to do now is this: I want to have a second loop (e.g. do j=1,5) and store the files above at 5 different folders, already existing inside the main directory. The truth is that for each j, the content of the files testi.out is changing, so I want to gather them in specific folders.

A sample of my current code is:

do i=1,10

  write(name, 14) 'test',iw,'.out'

  open(unit=70, file=name)

  write(70,*) 0.0

enddo

14  format (a10,i1,a4)

When I write the second line as follows:

write(name, 14) 'folder1/test',iw,'.out'

then it creates the files in the folder1. I want this inside an other loop (j=1,5), so each time the files are created in the folders folder1, folder2, ..., folder5.

Any ideas for this?

Upvotes: 1

Views: 746

Answers (1)

Peter Petrik
Peter Petrik

Reputation: 10165

Hint (for i=1,9):

write(name, 14) 'folder',j,'/test',i,'.out'

Note: Check your format statement for i=10. You need different FORMAT magic (i0)!

Note2: On Windows, \\ can be used instead

Upvotes: 1

Related Questions