- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Renaming a file by means of an integer tag
Message Posted: Feb 17, 2003 3:41 AM
Reply
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
billaustralia
Posts: 8
Member Since: Sep, 2002
Re: Renaming a file by means of an integer tag
Message Posted: Feb 16, 2003 11:38 PM
Reply
Use an internal write
character fname*7
do 10 i=1,9
write(fname,'(a,i1)')'prefix',i
10 continue
Renaming a file by means of an integer tag
Message Posted: Feb 15, 2003 3:21 PM
Reply
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
blank
Message Posted: Feb 17, 2003 3:41 AM
Reply
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
billaustralia
Posts: 8
Member Since: Sep, 2002
Re: Renaming a file by means of an integer tag
Message Posted: Feb 16, 2003 11:38 PM
Reply
Use an internal write
character fname*7
do 10 i=1,9
write(fname,'(a,i1)')'prefix',i
10 continue
Renaming a file by means of an integer tag
Message Posted: Feb 15, 2003 3:21 PM
Reply
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
blank
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think Bill made a missprint. The correct should be:
character*7 fname
The size 7 is used because in his example 'prefix' has size 6, so when i (1 to 9)
is internally writen to fname you fill the size seven character fname: prefix1, prefix2... .
I think this would work:
character*6 filename ! size 6 just an example
! name 'filename' also
do i=1,9
write(filename,'(a,i1)')'fname',i
open(unit=1,file=fname)
write(1,*)'MATHEMATICS'
close(1)
end do
You would end having 9 files ( fname1, fname2...), and all with the same contents ( MATHEMATICS)
You can refine things to include a full path and extention to fname. i1 in format is for this one digit integer example.
Regards
Geraldo
character*7 fname
The size 7 is used because in his example 'prefix' has size 6, so when i (1 to 9)
is internally writen to fname you fill the size seven character fname: prefix1, prefix2... .
I think this would work:
character*6 filename ! size 6 just an example
! name 'filename' also
do i=1,9
write(filename,'(a,i1)')'fname',i
open(unit=1,file=fname)
write(1,*)'MATHEMATICS'
close(1)
end do
You would end having 9 files ( fname1, fname2...), and all with the same contents ( MATHEMATICS)
You can refine things to include a full path and extention to fname. i1 in format is for this one digit integer example.
Regards
Geraldo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
"character fname*7" is unusual, but is a standard-conforming alternative to character*7.
Steve
Steve
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