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.
OPEN (UNIT=CHANNEL, FILE=FILENAME, STATUS='OLD')and thenREAD(CHANNEL, 38)VAR1,VAR2,VAR3. Fixes: 1) some functions have return typeINTEGER, but are used asINTEGER*1- made allINTEGER(they always return '1' or '0') and 2) one function is conflicting with some standard gfortran function - changed its name. But I guess those fixes could not affect on that problem, as they appear later in the application work (app fails reading datafile header). - Andriy Kashchynets