1

I am learning Fortran 90/95, and the book I am using had a discussion about the influence of line printers on the format statement. According to the book, the program uses the first character of the line to decide the line's position relative to the previous line (i.e. '1' starts a new page, '0' skips a line, '+' overwrites the previous line, and ' ' or any other character writes the new line below the previous line). I compiled and ran a simple program in the console to test this, but did not observe this behavior.

program test

integer :: i = 123
character(13) :: hello = 'Hello, World!'

100 format ('0','Count = ',I3)

write (*,*) hello
write (*,100) i

end program

The output is

 Hello, World!
0Count = 123

where I would have expected

 Hello, World!

Count = 123

Does anyone know why this is? Is this a legacy feature that is not used in Fortran 90/95? Is it specific behavior for a print to the console? I would like to know when (if ever) I need to declare a special first character in the format statement when writing.

My compiler is Force 2.0.9, which I believe is based on gfortran. I am running it on Windows 7, and the console is PowerShell.

Thanks for the help!

astay13
  • 6,857
  • 10
  • 41
  • 56

4 Answers4

3

This was used in the 70s and even 80s with line printers in FORTRAN 77 and earlier ... but when did you last see a line printer? Any Fortran 90/95 book that teaches this feature should be thrown away.

This has already been answered on Stack Overflow: Are Fortran control characters (carriage control) still implemented in compilers?

Community
  • 1
  • 1
M. S. B.
  • 28,968
  • 2
  • 46
  • 73
2

This applies only to old "fixed form" Fortran (77 and earlier), not to the new "free form" Fortran (90 and later), when all commands had to be indented by 6 spaces. You can still use fixed-form with appropriate compiler flags. Sometimes this is even the default if the extension is .f rather than .f90.

Norbert S
  • 275
  • 2
  • 14
  • Although, I was using fixed-form Fortran 90, so I think the issue is related more to compiler options than to the code format. – astay13 Sep 06 '12 at 19:27
1

Fortran 90/95 is much too recent for me, but I don't recall those formatting options from using FORTRAN in the seventies.

Nevertheless, I think it's a legacy feature, and the fact that you've got '+' to overwrite a line suggests the options are intended for output to a line printer not the console screen.

pavium
  • 14,808
  • 4
  • 33
  • 50
1

I am learning Fortran 90/95, and the book I am using had a discussion about the influence of line printers on the format statement. According to the book, the program uses the first character of the line to decide the line's position relative to the previous line (i.e. '1' starts a new page, '0' skips a line, '+' overwrites the previous line, and ' ' or any other character writes the new line below the previous line). I compiled and ran a simple program in the console to test this, but did not observe this behavior.

That is one of the legacy features of Fortran which is mostly ignored today, since (if nothing else) one does not print to printers directly. In any case, most compilers (I really couldn't say for gfortran specifically now, since I don't have it installed) have options to disregard that behaviour, and some of them ignore the first column by default. From what you've shown it is reasonable to assume your is one of them, so yes, you can ignore it.

Out of habit in regards to this practice, a lot of fortran programmers start any string with a blank or 1x in the write statement.

Rook
  • 60,248
  • 49
  • 165
  • 242