This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fortran reads file on Linux but not Mac


Hi mailing list,

I've been running an old fortran program for years on Ubuntu with no
problem, but on a Mac it runs into bizarre problems reading a control
file at the beginning of the script. I assumed the problem was related
to line endings, but changing the line endings didn't help. I also
tried different compiler versions, also to no avail. I am totally
stumped.



Here's the control file being read:

----------------------------------------------------------------------
rollcall_input.dat
rollcall_output.dat
legislator_input.dat
legislator_output.dat
session_info.num
rollcall_matrix.vt3
transposed_rollcall_matrix.vt3
NOMINAL DYNAMIC-WEIGHTED MULTIDIMENSIONAL UNFOLDING
2    1    1    2    2    5
5.9539  0.3463
----------------------------------------------------------------------


As it reads the variables from this file, the program writes them to a
second file (just for debugging). On Ubuntu the second file is
identical to the first. But on a Mac the program is writing this
instead:

----------------------------------------------------------------------
                                                                r
                                                                r
                                                                l
                                                                l
                                                                s
                                                                r
                                                                t
                                                                N
2    1    1    2    2    5
----------------------------------------------------------------------

It crashes before writing the last line, with the error:

At line 157 of file dwnom3.f
Fortran runtime error: Expected REAL for item 2 in formatted transfer, 
got CHARACTER
(15F8.4)
^

Line 157 is where it's writing the last line to the second file:
WRITE(21,104)WEIGHT(NS+1),(WEIGHT(K),K=2,NS)


If I change the line endings to \r, I get the slightly different error:

At line 156 of file dwnom3.f
Fortran runtime error: End of file

Line 156 reads the last line of the control file:
READ(4,104)WEIGHT(NS+1),(WEIGHT(K),K=2,NS)


Here's the relevant code reading and writing the files:

----------------------------------------------------------------------
OPEN(4,FILE='DW-NOMSTART.DAT',STATUS='OLD')
OPEN(21,FILE='DWNOM21.DAT')
READ(4,102)FNAME1
WRITE(21,102)FNAME1
READ(4,102)FNAME2
WRITE(21,102)FNAME2
READ(4,102)FNAME3
WRITE(21,102)FNAME3
READ(4,102)FNAME4
WRITE(21,102)FNAME4
READ(4,102)FNAME5
WRITE(21,102)FNAME5
READ(4,102)FNAME6
WRITE(21,102)FNAME6
READ(4,102)FNAME7
WRITE(21,102)FNAME7
READ(4,102)FTITLE
WRITE(21,102)FTITLE
READ(4,103)NS,NMODEL,NFIRST,NLAST,IHAPPY1,IHAPPY2
WRITE(21,103)NS,NMODEL,NFIRST,NLAST,IHAPPY1,IHAPPY2
READ(4,104)WEIGHT(NS+1),(WEIGHT(K),K=2,NS)
WRITE(21,104)WEIGHT(NS+1),(WEIGHT(K),K=2,NS)
102 FORMAT(A64)
103 FORMAT(10I5)
104 FORMAT(15F8.4)
----------------------------------------------------------------------


I don't really use fortran outside of this. Is there something really
obvious that I'm missing that this code is doing wrong? If I'm using
the same compiler and have the appropriate line endings shouldn't I
get the same behavior in both Mac and Linux?


- Will May

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]