This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Fortran reads file on Linux but not Mac
- From: William May <williamcmay at live dot com>
- To: "fortran at gcc dot gnu dot org" <fortran at gcc dot gnu dot org>
- Cc: David Krähenbühl <d dot kraehenbuehl at swissonline dot ch>
- Date: Thu, 20 Jul 2017 04:32:02 +0000
- Subject: Fortran reads file on Linux but not Mac
- Authentication-results: sourceware.org; auth=none
- Authentication-results: gcc.gnu.org; dkim=none (message not signed) header.d=none;gcc.gnu.org; dmarc=none action=none header.from=live.com;
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
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