The following program demonstrates a bug in FTN95. When a text data file containing tab characters is read using the A format specifier, each tab is converted and expanded to a number of spaces. This bug is present in the latest FTN95, as well as the old FTN95 7.2 and FTN77 4.03.
program afmtbug
implicit none
integer i
character*20 iline
character*50 jline
c
iline = 'titleab 1' // char(9) // 'titleabc 2'
open(10,file='x.txt',status='replace')
write(10,'(A)')iline
rewind(10)
read(10,'(A)')jline ! <<<=== BUG: input tabs are expanded to spaces
close(10)
do i=1,20 ! output enough characters to display expansion of tab to spaces
print 10,i,ichar(iline(i:i)),iline(i:i),
+ ichar(jline(i:i)),jline(i:i)
end do
10 format(1x,2i5,2x,A1,4x,i5,2x,A1)
end
The output from Gfortran:
S:\LANG\FTN95>gfortran afmtbug.f
S:\LANG\FTN95>a
1 116 t 116 t
2 105 i 105 i
3 116 t 116 t
4 108 l 108 l
5 101 e 101 e
6 97 a 97 a
7 98 b 98 b
8 32 32
9 49 1 49 1
10 9 9
11 116 t 116 t
12 105 i 105 i
13 116 t 116 t
14 108 l 108 l
15 101 e 101 e
16 97 a 97 a
17 98 b 98 b
18 99 c 99 c
19 32 32
20 50 2 50 2
The output from FTN95:
1 116 t 116 t
2 105 i 105 i
3 116 t 116 t
4 108 l 108 l
5 101 e 101 e
6 97 a 97 a
7 98 b 98 b
8 32 32
9 49 1 49 1
10 9 32
11 116 t 32
12 105 i 32
13 116 t 32
14 108 l 32
15 101 e 32
16 97 a 32
17 98 b 116 t
18 99 c 105 i
19 32 116 t
20 50 2 108 l
A hex dump of the file x.txt written (same with FTN95 and other compilers):
S:\LANG\FTN95>xxd -g1 x.txt
00000000: 74 69 74 6c 65 61 62 20 31 09 74 69 74 6c 65 61 titleab 1.titlea
00000010: 62 63 20 32 0d 0a bc 2..
Note: This bug was discovered when investigating related problems in a recent thread: http://forums.silverfrost.com/viewtopic.php?p=33765 .