- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would like to create a set of characters as follows:
Thk_1, Thk_2, .........Thk_501,........
So I create a do loop as follows:
Character(5) b
integer i
OuterLoop: do i = 1,1001
b = 'Thk_'//i
Enddo OuterLoop
Obviously the above contruct gives errors since characters and integers cannot be mixed in the above operation.
My questions is how do i create such charcaters in a loop?
thank you very much
...animesh
Thk_1, Thk_2, .........Thk_501,........
So I create a do loop as follows:
Character(5) b
integer i
OuterLoop: do i = 1,1001
b = 'Thk_'//i
Enddo OuterLoop
Obviously the above contruct gives errors since characters and integers cannot be mixed in the above operation.
My questions is how do i create such charcaters in a loop?
thank you very much
...animesh
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Two points on this, firstly that you need 8-character strings to write 'Thk_1001', and secondly unless you insert lead zeros, your strings will not sort - the latter point may not matter to you.
I have forgotten (again!) the magic characters to make source code readable on this message board*, but try this:
CHARACTER*8 B(1001)
INTEGER I
B = 'Thk_'
DO I= 1,1001
WRITE (B(I)(5:8),'(I4.4)') I
END DO
The result is typically B(14) = 'Thk_0014'
Bear of little brain
*Steve, please could we have a link to a reminder of the magic characters?
I have forgotten (again!) the magic characters to make source code readable on this message board*, but try this:
CHARACTER*8 B(1001)
INTEGER I
B = 'Thk_'
DO I= 1,1001
WRITE (B(I)(5:8),'(I4.4)') I
END DO
The result is typically B(14) = 'Thk_0014'
Bear of little brain
*Steve, please could we have a link to a reminder of the magic characters?

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