'Writing numbers only each second and third line in Fortran

I am fighting with trying to get numbers 1 and 2 only on each second and third line in the second column.

I have a file tisk2 with

  O
  H
  H
  O
  H
  H

And I need to get to file tisk this:

O
H1
H2
O
H1
H2

I mean I want no number no text after O. I tried to write this code:

program cislo
implicit none
integer :: i, sum, j, k
character :: t*10, m*10

open(10,file="tisk2",status='old')
open(12,file="tisk",status='old')

do k=0,5
read(10,*) m
enddo

do j=1,3
 do i = 0,0
 t=" "
 print*, t
exit
enddo
sum=0
do i=1,2
write(12,fmt='(a2,i2)') m, i
enddo
enddo

end program cislo

I can print only i and I get nothing, second line 1 and third line 2. Then alone print m. But when I want to put both to one file, it skips O and writes to file only H1, H2 and then again. Does anyone has an idea how to get what I need? Thank you for help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source