Software Archive
Read-only legacy content
17061 Discussions

Character and integer manipulation

Intel_C_Intel
Employee
398 Views
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
0 Kudos
1 Reply
Intel_C_Intel
Employee
398 Views
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?
0 Kudos
Reply