Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
1 View

Puzzled by console line length

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
Highlighted
Black Belt
1 View

I don't see that:

I don't see that:

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

 

Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos
Highlighted
Valued Contributor II
1 View

It may be a consequence of

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
Highlighted
Valued Contributor II
1 View

So if you 80 char string is

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

0 Kudos
Highlighted
Beginner
1 View

Yes, it the string is 85 long

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
Highlighted
Black Belt
1 View

I don't think it's Intel

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

Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos
Highlighted
1 View

The line wrap when text

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
Highlighted
1 View

BTW

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
Highlighted
Valued Contributor II
1 View

You can set and control

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

0 Kudos
Highlighted
Beginner
1 View

Thanks to all for the answers

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