In a project wrapping legacy Fortran code in R a text-file is read by the subroutine "rfort". A working simplified version of the subroutine looks like follows:
SUBROUTINE rfort()
implicit none
INTEGER I,IX,IY
DIMENSION IX(10),IY(10)
CHARACTER*6 NAME(10)
OPEN(UNIT=8,FILE='TEST.DAT',STATUS='OLD')
OPEN(UNIT=9,FILE='RESULT.DAT',STATUS='UNKNOWN')
DO I=1,10
READ(8,1020)IX(I),IY(I),NAME(I)
1020 FORMAT(8X,2I8,A6)
WRITE(9,1030)IX(I),IY(I),NAME(I)
1030 FORMAT(8X,2I8,A6)
ENDDO
CLOSE (8)
CLOSE (9)
END
The text-file ("TEST.DAT") consists of four variables: a row identifier (ignored), two integer variables ("IX", "IY") and one character variable ("NAME").
1 395 1232 1084
2 415 1242 1024
3 433 1253 125
4 409 1204 1256
5 427 1217 105
6 446 1226 1253
7 489 1239 1254
8 560 1255 1260a
9 720 1270 1067
10 726 1293 1078d
While the subroutine compiles fine (on MacOS 10.11.6, R 3.5.0) with
R CMD SHLIB rfort.f
and can also invoked in R with
dyn.load("rfort.so")
and runs without error with
.Fortran("rfort")
it strangely reads in only the integer columns as is tested by "RESULT.DAT". The character column is ignored, whatever I tried. The very same code works as expected as a stand-alone Fortran-programme (compiled with gfortran 6.1.0), so I suspect it has something to do with the formatting. However, I am at my wits' end, so any help is appreciated!