This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: Fortran reads file on Linux but not Mac
- From: Jerry DeLisle <jvdelisle at charter dot net>
- To: William May <williamcmay at live dot com>, "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: Fri, 21 Jul 2017 11:15:01 -0700
- Subject: Re: Fortran reads file on Linux but not Mac
- Authentication-results: sourceware.org; auth=none
- References: <BY2PR13MB082365A575C14ADA586DFA9FCEA70@BY2PR13MB0823.namprd13.prod.outlook.com>
Hi William,
I do not have a Mac to test on, but I will be looking at this issue. Normally
you should just post to bugzilla rather than this list. We usually have someone
somewhere in the world looking through the bug reports.
I do need to know the latest version of gfortran you tested with:
Post the output of gfortran -v.
If you could do so on bugzilla that would be better, but I will take it here.
Jerry
On 07/19/2017 09:32 PM, William May wrote:
> 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
>