- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am looping on IHIST in the open statement below. I want to change the file name 'test100.txt' on the during looping such that I get a set of files at the end such as test101.txt, test102.txt, ..., test1000.txt
Pointing me to a known solution would be much appreciated. Note, I am new to character manipulation in FORTRAN, so do not understand how to formulate this problem
OPEN (UNIT=100+IHIST, FILE='test100.txt', STATUS='UNKNOWN')
Mike
Pointing me to a known solution would be much appreciated. Note, I am new to character manipulation in FORTRAN, so do not understand how to formulate this problem
OPEN (UNIT=100+IHIST, FILE='test100.txt', STATUS='UNKNOWN')
Mike
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
WRITE(filename,'(a,i4.4,a)') "TEST",i,".TXT"
will enable you to create filenames from TEST0000.TXT to TEST9999.TXT
I'm not sure if you can specify UNIT=100+IHIST - hopefully someone else will answer that for you.
David
will enable you to create filenames from TEST0000.TXT to TEST9999.TXT
I'm not sure if you can specify UNIT=100+IHIST - hopefully someone else will answer that for you.
David
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
WRITE(filename,'(a,i4.4,a)') "TEST",i,".TXT"
will enable you to create filenames from TEST0000.TXT to TEST9999.TXT
I'm not sure if you can specify UNIT=100+IHIST - hopefully someone else will answer that for you.
David
will enable you to create filenames from TEST0000.TXT to TEST9999.TXT
I'm not sure if you can specify UNIT=100+IHIST - hopefully someone else will answer that for you.
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For the syntax of the OPEN statement, see section 9.4 of the Standard. You can see there that the unit number is allowed to be specified as a scalar integer expression.
If you must have files named test100.txt,... rather than test0100.txt, ...:
If you must have files named test100.txt,... rather than test0100.txt, ...:
[fortran]character*12 :: filename integer :: iunit if(iunit.LT. 1000)then write(filename,'("TEST",I3,".TXT")')iunit open(unit=iunit+100,file=filename,status='unknown') ... close(unit=iunit) else write(filename,'("TEST",I4,".TXT")')iunit open(unit=iunit+100,file=filename,status='unknown') ... close(unit=iunit) endif [/fortran]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Or just use the format I0 (that is zero)
Les
Les

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