From: Philipp E. Weidmann on
I'm in the process of modifying a program that was previously compiled
with ifortran so that it will work with gfortran as well (Windows is my
testbed), and I have discovered that files written by the ifort-compiled
version will not work with the gfortran-compiled version.

There are two apparent reasons for this:


1. The program compiled with ifort terminates lines it writes to a file
with CRLF, while the gfortran version uses LF only.


2. The string written by the command

WRITE(file_unit,*) real8_value (where real8_value = 0)

is "0.000000000000000E+000" when using ifort but "0.0000000000000000"
when using gfortran (I'm not sure this actually causes any problems,
though).


Is there any way around these issues so that files written by a ifort
compiled program will be understood by a gfortran version of the same
program, and vice versa?

Any help is appreciated.

--
-- Philipp Emanuel Weidmann
From: Tobias Burnus on
Philipp E. Weidmann wrote:
> 1. The program compiled with ifort terminates lines it writes to a file
> with CRLF, while the gfortran version uses LF only.

Actually, that surprises me - I thought that the MinGW/Cygwin version of
gfortran also uses CRLF. What version of gfortran do you actually have
(MinGW, MinGW64, or Cygwin - and which version number 4.x.y)?

However, I believe that both compilers happily read files terminated by
CRLF and LF on both Windows and Unix. Thus, there should be no real
problem. Still, it would be useful to understand, why you do not get
CRLF with a Windows gfortran.

(Disclaimer: I only use gfortran/ifort under Linux.)

> 2. The string written by the command
> WRITE(file_unit,*) real8_value (where real8_value = 0)
> is "0.000000000000000E+000" when using ifort but "0.0000000000000000"
> when using gfortran (I'm not sure this actually causes any problems,
> though).

Well, for list-directed output, one can find all kind of outputs, but
that should cause no problems. Example:

- Cray, Portland, NAG, g95, gfortran
0. or 0.000000 or ...

- Intel, Open64, Pathscale
0.E+0 or 0.0000000E+00 or ...

However, all variants should work flawlessly with list-directed input,
i.e. that should not be a problem.


> Is there any way around these issues so that files written by a ifort
> compiled program will be understood by a gfortran version of the same
> program, and vice versa?

I think there should not be any problem. Thus, if something does not
work, I would like to see a failing example.


Not for input, but for output, you could consider using an explicit
format rather than a '*' (list-directed I/O). Then you can explicitly
control how the output should look like. With list-directed I/O you rely
on the defaults of the compiler.

For instance, ifort automatically adds line breaks for list-directed
*output*, if the line gets too long. (gfortran doesn't.) As
list-directed *input* only reads until the line break, you cannot easily
read such data. (On the other hand, the line break makes it easier to
read the output on the screen.) Using an explicit FMT in the write
statement solves this problem.

Tobias
From: Philipp E. Weidmann on
Tobias Burnus wrote:
> Philipp E. Weidmann wrote:
>> 1. The program compiled with ifort terminates lines it writes to a file
>> with CRLF, while the gfortran version uses LF only.
>
> Actually, that surprises me - I thought that the MinGW/Cygwin version of
> gfortran also uses CRLF. What version of gfortran do you actually have
> (MinGW, MinGW64, or Cygwin - and which version number 4.x.y)?
>
> However, I believe that both compilers happily read files terminated by
> CRLF and LF on both Windows and Unix. Thus, there should be no real
> problem. Still, it would be useful to understand, why you do not get
> CRLF with a Windows gfortran.
>
> (Disclaimer: I only use gfortran/ifort under Linux.)


I use gfortran 4.6 (dev)/Cygwin.

I'm still trying to pinpoint where exactly the problem lies since my
program is rather large and the file parsing quite complex. However, the
fact remains that the version compiled with ifort fails to read files
generated by the gfortran version.

--
-- Philipp Emanuel Weidmann
From: fj on
On 4 juil, 11:17, "Philipp E. Weidmann" <philipp.weidm...(a)gmx.de>
wrote:
> I'm in the process of modifying a program that was previously compiled
> with ifortran so that it will work with gfortran as well (Windows is my
> testbed), and I have discovered that files written by the ifort-compiled
> version will not work with the gfortran-compiled version.
>
> There are two apparent reasons for this:
>
> 1. The program compiled with ifort terminates lines it writes to a file
> with CRLF, while the gfortran version uses LF only.

A source file is NEVER produced by a compiler like ifort or gfortran
but only by a text editor !

The result of a compilation is an object file which format is never a
text format. So end-of-line terminations like CR+LF or LF, only valid
for text files, are irrelevant for object files.

An object file created by a compilation is never compatible with the
one of another compiler. This is not a FORTRAN rule : it applies to
any compilation language.

The normal "end of line" of a text file on Windows is CR+LF. It is LF
on Unix-like operating system (like Linux).

Usually, gfortran accepts both end of line terminations when running
on Windows. So I am a little bit surprised by your remark.

On Windows, use the Windows termination (CR+LF).

It exists tools able to change that termination automatically. For
instance, look at the option -a of the unzip command : it translates
automatically Unix files into Windows files and vice versa.

Notice that many text editors enable the user to select the end of
line too.

At last, dedicated commands also exist but mainly in the Unix world,
for instance dos2unix and unix2dos.

>
> 2. The string written by the command
>
>    WRITE(file_unit,*) real8_value     (where real8_value = 0)
>
> is "0.000000000000000E+000" when using ifort but "0.0000000000000000"
> when using gfortran (I'm not sure this actually causes any problems,
> though).

Your are using the "*" format, i.e. a free format which result is
compiler dependent.

If you want the same results with any compiler, use a fixed format,
for instance :

WRITE(file_unit,'(1X,1PE12.5)') real8_value

But I doubt that the free format is responsible of a change in the
result of your program.

>
> Is there any way around these issues so that files written by a ifort
> compiled program will be understood by a gfortran version of the same
> program, and vice versa?
>
> Any help is appreciated.
>
> --
> -- Philipp Emanuel Weidmann

From: Philipp E. Weidmann on
fj wrote:
> On 4 juil, 11:17, "Philipp E. Weidmann"<philipp.weidm...(a)gmx.de>
> wrote:
>> I'm in the process of modifying a program that was previously compiled
>> with ifortran so that it will work with gfortran as well (Windows is my
>> testbed), and I have discovered that files written by the ifort-compiled
>> version will not work with the gfortran-compiled version.
>>
>> There are two apparent reasons for this:
>>
>> 1. The program compiled with ifort terminates lines it writes to a file
>> with CRLF, while the gfortran version uses LF only.
>
> A source file is NEVER produced by a compiler like ifort or gfortran
> but only by a text editor !
>...

Please re-read my problem statement:

"*The program compiled with ifort* terminates lines *it* writes to a
file with CRLF, while the gfortran version uses LF only."

I wasn't talking about compilers but about programs produced with
differend compilers.

--
-- Philipp Emanuel Weidmann
 |  Next  |  Last
Pages: 1 2 3 4
Prev: gui fortran
Next: removing /save fortran compiler option