Renaming a file by means of an integer tag

Renaming a file by means of an integer tag

Dear Sir/Madam

I would like to define a variable for naming a file within a write statement in such a way that this variable is updated each time I run a new loop of my program.

The new name would be of the form "filename"_irun, where only irun (the number of the current run) is being updated. As such, irun would be used as a tag to distinguish between different output files according to the run number. Can you please advise me how to do this with Compaq Visual Fortran. Since "filename" is a character variable and irun is an integer variable for a do loop of the form do irun =1 501
end do
and the write statement is contained within the above do loop the appropriate solution does not appear obvious to me.

Many thanks for your help.

Best wishes

Margaret MacDougall

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Use an internal write

character fname*7
do 10 i=1,9
write(fname,'(a,i1)')'prefix',i
10 continue

Dear Sir

Many thanks for your advice. I am sorry to say, however, that I am not clear how to implement the piece of code that you recommend. Suppose for, example, I wanted to write the word "Mathematics" to 9 files entitled fname1,...fname9. What should appear in my open statement and my write statement when I choose to write to the (9?) files which you appear to be defining. Presumably, I shall need a separate loop from the one which you suggest and my open and write statements will need to be inside this loop.

Also, what is the significance of the character fname*7 which you declare and where should I use it?

Best wishes

Margaret

[pre]
CHARACTER(20) sFileName

DO i=1,500
...some calculation
WRITE(sFileName, "(A, i3.3)") 'Mathematics', i
OPEN(11, FILE=sFileName)
WRITE(11) ...
CLOSE(11)
END DO[/pre]

Jugoslav
www.xeffort.com

Leave a Comment

Please sign in to add a comment. Not a member? Join today