Re: Getting literal newline \n in output after porting code
- From: baf <baf@xxxxxxxxxxx>
- Date: Fri, 09 Mar 2007 05:42:15 GMT
misteromaha@xxxxxxxxx wrote:
I'm updating some Fortran code which was formerly used on DEC/CompaqThe first suggestion is to get rid of the "carriagecontrol" specifier since it is nonstandard (non-portable) Fortran.
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.
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.
.
- References:
- Getting literal newline \n in output after porting code
- From: misteromaha
- Getting literal newline \n in output after porting code
- Prev by Date: Getting literal newline \n in output after porting code
- Next by Date: Re: Getting literal newline \n in output after porting code
- Previous by thread: Getting literal newline \n in output after porting code
- Next by thread: Re: Getting literal newline \n in output after porting code
- Index(es):
Relevant Pages
|