Re: Getting literal newline \n in output after porting code



misteromaha@xxxxxxxxx wrote:
I'm updating some Fortran code which was formerly used on DEC/Compaq
alphas running Tru64 with the Compaq Fortran compiler, to Linux boxes
with a fairly recent version of the Intel Fortran compiler.

A program that is giving me unexpected results after porting has code
similar to:

open(unit=10,file='data.txt',carriagecontrol='NONE')
...
write(unit=10,fmt=*) i1,a,b
write(unit=10,fmt=*) '\n'
write(unit=10,fmt=*) i2,c,d

On the alphas/Tru64, the output file data.txt would look like the
following, which is the desired output:
1 0.000000E+00 1.0000000E+00
3 1.500000E+00 2.3000000E+00


Compiling the same code with ifort on Linux produces the newline \n
literally in the file, and all output on 1 line:
1 0.000000E+00 1.0000000E+00 \n 3 1.500000E+00 2.3000000E+00

What do I need to do to force a newline while preferably keeping the
carriagecontrol='NONE'? (It's needed in other places such as where
the write statement is within a loop to output whole arrays on the
same line, and I'd rather change the code as little as possible).

I tried this:

open(unit=10,file='data.txt',carriagecontrol='NONE')
...
write(unit=10,fmt=*) i1,a,b
write(unit=10,fmt=*) ' '
write(unit=10,fmt=*) i2,c,d

but that still results in 1 line with an extra space where the \n used
to be.

I also tried this (note I got rid of the carriagecontrol='NONE')

open(unit=10,file='data.txt')
...
write(unit=10,fmt=*,advance='NO') i1,a,b
write(unit=10,fmt=*) ' '
write(unit=10,fmt=*,advance='NO') i2,c,d

This is closer to what I want, but I get a blank line between the
desired lines:
1 0.000000E+00 1.0000000E+00

3 1.500000E+00 2.3000000E+00


Suggestions anyone? Thanks much.

The first suggestion is to get rid of the "carriagecontrol" specifier since it is nonstandard (non-portable) Fortran.

Just do
open(unit=10,file='data.txt')
...
write(unit=10,fmt=*) i1,a,b
write(unit=10,fmt=*) i2,c,d

To get:
1 0.000000E+00 1.0000000E+00
3 1.500000E+00 2.3000000E+00

If you really need non-advancing output in other parts of the code, use the standard advance="no" specifier.

.



Relevant Pages

  • Getting literal newline in output after porting code
    ... alphas running Tru64 with the Compaq Fortran compiler, to Linux boxes ... with a fairly recent version of the Intel Fortran compiler. ... which is the desired output: ... What do I need to do to force a newline while preferably keeping the ...
    (comp.lang.fortran)
  • Re: character(size) function problem
    ... IntelFortran Compiler for IntelEM64T-based applications, ... Copyright 1985-2006 Intel Corporation. ... funfun1.f90: Error: There is an incorrect length specifier in the ... declaration confirms the implicit type. ...
    (comp.lang.fortran)
  • Re: character(size) function problem
    ... IntelFortran Compiler for IntelEM64T-based applications, ... Copyright 1985-2006 Intel Corporation. ... funfun1.f90: Error: There is an incorrect length specifier in the ... declaration confirms the implicit type. ...
    (comp.lang.fortran)
  • Re: FORTRAN compiler
    ... It was transferred to Intel. ... > MS got rid of their FORTRAN compiler sometime in the early 1990s. ... > third-party FORTRAN compiler, but you will need to know what its interface ...
    (microsoft.public.vc.mfc)
  • Re: FORTRAN compiler
    ... MS got rid of their FORTRAN compiler sometime in the early 1990s. ... third-party FORTRAN compiler, but you will need to know what its interface specifications ... MVP Tips: http://www.flounder.com/mvp_tips.htm ...
    (microsoft.public.vc.mfc)