Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Puzzled by console line length

OP1
New Contributor III
1,291 Views

This code (compiled with 17 Update 1)

PROGRAM P
USE ISO_FORTRAN_ENV
IMPLICIT NONE
INTEGER :: RECLENGTH
INQUIRE(UNIT=OUTPUT_UNIT,RECL=RECLENGTH)
WRITE(OUTPUT_UNIT,'(I4)') RECLENGTH
WRITE(OUTPUT_UNIT,'(A)') '<------ This character string is exactly 80 characters long, believe me! ------>'
WRITE(OUTPUT_UNIT,'(A)') 'Oops!'
END PROGRAM P

when run in a console window with a 80-character long line, produces the output:

 132
<------ This character string is exactly 80 characters long, believe me! ------>

Oops!

Why is there a blank line between the two lines of text?

0 Kudos
9 Replies
Steve_Lionel
Honored Contributor III
1,291 Views

I don't see that:

D:\Projects>t.exe
 132
<------ This character string is exactly 80 characters long, believe me! ------>
Oops!

 

0 Kudos
Arjen_Markus
Honored Contributor II
1,291 Views

It may be a consequence of the terminal/console detecting that the line was written up to the end of the visible line and therefore inserting a carriage return/line feed.

0 Kudos
andrew_4619
Honored Contributor III
1,291 Views

So if you 80 char string is 85 long it it wrapping at 80?

0 Kudos
OP1
New Contributor III
1,291 Views

Yes, it the string is 85 long it will wrap at 80. I am puzzled by the fact that when 80 long it 'wraps' and prints out a blank line. The RECL is also ignored, independently of what the /wrap-margin compiler option is (if the console is wider that 132 characters no wrapping happens).

Arjen may be onto something... I am not sure how to disable this though. It seems that Steve cannot reproduce this.

This is purely cosmetic of course, but a bit disconcerting. I oftentimes output to the console 'delimiter strings' which have the width of the console, to keep the output of my code neat; and now it is inserting a blank line afterwards. Strange.

0 Kudos
Steve_Lionel
Honored Contributor III
1,291 Views

I don't think it's Intel Fortran doing the wrapping. The options you mention apply to list-directed output only.

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,291 Views

The line wrap when text printed hits right margin (80 in this case), followed by anything, even non-advancing character (except maybe back space), will line advance (depending on terminal emulator). This includes CR, LF, CRLF.

This has been with us since the 1980's. Think of it as a "feature".

Jim Dempsey

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,291 Views

BTW

Windows, in text edit box/window has an equally goofy line advance issue depending on if window has vertical scroll bar and/or boarder design.

Jim Dempsey

0 Kudos
andrew_4619
Honored Contributor III
1,291 Views

You can set and control console attributes using windows api routines but some work is involved.

0 Kudos
OP1
New Contributor III
1,291 Views

Thanks to all for the answers - yes, it looks as if this is a Windows console behavior that cannot be controlled "easily" from my code.

0 Kudos
Reply