Reputation: 301
I have a huge piece of Fortran code and I want to compile that code with gfortran. I have not worked with Fortran before. I do not know exactly what specification the code is of, but I found out that it can be compiled with at least Compaq Visual Fortran 6.6 - so I may guess it was written under it.
The general question is: Is there any automatic Compaq Visual Fortran to gfortran translator? I have found none.
In fact, the code does compile with gfortran after some fixes, but misbehaves at runtime: it does not read input files as expected. Here is an example of code:
CHARACTER*6 VAR1
CHARACTER*1 VAR2
CHARACTER*3 VAR3
OPEN (UNIT=CHANNEL, FILE=FILENAME, STATUS='OLD')
READ(CHANNEL, 38)VAR1,VAR2,VAR3
38 FORMAT(15X,A6,7X,A1,14X,A3)
And an example of data:
123456789012345------'1234567-'''''12345678901234---
.ABCDEF.GHI.JKLMNOPQR.STUVWX.YZABC.DEF.GHI.JKLM....P
123456789012345------1234567-12345678901234---
First line is how original app reads it, third - gfortran, second - an example of line from datafile (1
-9
for ommited chars, -
for read, '
for unmentioned by format, .
in the example instead of spaces in the original line).
So, the results would be:
Origanal: VAR1 == 'MNOPQR', VAR2 == 'Y', VAR3 == '..P' - correct
gfortran: VAR1 == 'MNOPQR', VAR2 == '.', VAR3 == 'JKL' - wrong
gfortran is quite straightforward: it jumps over 15 characters, reads 6, jumps over 7 and so on. But the original application goes another way and I can not guess its logic. It still reads the specified number of chars, but jumps farther than specified. And it does read what it is expected to read.
I tried to specify exact lengths as they appear in the input file (15X,A6,8X,A1,19X,A3
), and it works for gfortran, but it is not a long-term solution.
So, my more specific question is: Are there any differences in FORMAT
statement in gfortran and Compaq Visual Fortran 6.6? (maybe, I am wrong thinking FORMAT
is the cause)
UPD
I guess, there can be something with splitting into words or so. I mean gfortran just counts characters, but CVF does something different.
Upvotes: 1
Views: 540
Reputation: 8267
If this was a paper exercise and I was asked what the values of VAR1, VAR2 and VAR3 would be, I'd give the same result as gfortran.
What you are saying is really strange. I've just tried it on PowerStation4, IVF7 (the versions before and after CVF6.6) and they all give the same result as gfortran. I've also tried it with different word alignment, and different datatypes (not legal with gfortran but you can do that on the older compilers) and it comes up with the same answer.
Are you sure it is reading the file you think it is reading. powerstation and some versions of cvf have the 8.3 filename problem. They could not cope with long filenames.
Upvotes: 0