- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Use an internal write
character fname*7
do 10 i=1,9
write(fname,'(a,i1)')'prefix',i
10 continue
character fname*7
do 10 i=1,9
write(fname,'(a,i1)')'prefix',i
10 continue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page