1
votes

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.

1
to your general question there could be differences resulting from non-standard edit specifiers. X and A are standard though. Can you explain better what the orignal application does? - agentp
Show the accompanying READ statement. Input with tab characters can cause confusion. What "fixes" did you have to make to get the code to compile with gfortran? - IanH
@george There is a datafile of columns of words. The columns are separated by spaces. Spaces are also used to align words in their columns. In general the program do not read the whole row or even whole words (words are used to make file human-readable and the application reads only a letter in some columns to understand the data; and it also reads whole words in other columns). So, the original application reads that data and then manipulates with it (but manipulations are out of interest - I printed just read data out and it was not what it was expected to be). - Andriy Kashchynets
@IanH OPEN (UNIT=CHANNEL, FILE=FILENAME, STATUS='OLD') and then READ(CHANNEL, 38)VAR1,VAR2,VAR3. Fixes: 1) some functions have return type INTEGER, but are used as INTEGER*1 - made all INTEGER (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
(Best to edit your question with the additional info requested, rather than adding it to comments.) Show the text of a typical line being read, show the values of the variables read by cvf, and by gfortran. - IanH

1 Answers

0
votes

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.