Fortran How do I use Control Characters in Fortran?

  • Thread starter Thread starter gmcke1
  • Start date Start date
  • Tags Tags
    Control Fortran
AI Thread Summary
Control characters in Fortran, particularly when using the GNU Fortran compiler, can be challenging due to their reliance on the output device's ability to interpret them. The discussion highlights the basic control characters, including the "+" character for printing over a previous line, and emphasizes the need for compatible output devices, as many modern displays and printers do not recognize these characters, leading to them being printed as text instead. It is noted that in older systems, control characters were processed by specialized libraries, but this functionality has diminished in contemporary programming practices. For effective use of control characters today, users may need to implement a filter program or adjust their output methods to avoid unwanted line feeds. The conversation also references historical context, indicating that these control characters were more relevant in the era of line printers and teletypes, suggesting that their use in modern programming may not be practical.
gmcke1
Messages
9
Reaction score
0
Hello, I am having trouble figuring out how to use Control Characters in Fortran. My professor skipped over that chapter back in my Computational Tools 1 course and I am trying to figure out how to use them. I am currently compiling my programs in the GNU Fortran compiler if that helps any. I know through reading "Fortran 95/2003 for Scientists and Engineers" that the table for Control Characters looks like this (below).

___________________________________________________

Control Character | Action
___________________________________________________

1......|...Skip to new page
Blank.....|...Single spacing
0......|...Double Spacing
+......|...No spacing (print over previous line)
___________________________________________________

I'm interested in knowing how to use the "+" for printing over a previous line. A simple example would help a lot.

Thank you,

Glenn
 
Last edited:
Technology news on Phys.org
One thing about Fortran carriage control characters which must be kept in mind is that the output device must recognize them and act accordingly. On most displays and printers, the carriage controls will have no effect, and you'll see the control characters printed with the rest of the output.
 
SteamKing said:
One thing about Fortran carriage control characters which must be kept in mind is that the output device must recognize them and act accordingly.
It's been a long time since I worked with Fortran, but back in the olden days, the control characters were handled by a Fortran library module for print and translated by that module depending on the output device type and the output device driver. At least it worked on teletypes and line printers. For the + control character, generally it just had to output a leading return (ASCII or BAUDOT or EBCDIC or CDC's 6 bit display code) with no line feed.
 
The first image I attatched is what I programmed in notepad++. The second image is what I got in the cmd window after running it. I took the code directly from the site Mark posted, but it doesn't look like it formatted anything in the cmd window. I must be doing something wrong, or the gfortran compiler doesn't recognize Control Characters.
 

Attachments

  • Capture.PNG
    Capture.PNG
    11.3 KB · Views: 835
  • Capture2.PNG
    Capture2.PNG
    2 KB · Views: 728
When the output device does not recognize the carriage control chars., they are printed out as normal text.
 
gmcke1 said:
The first image I attatched is what I programmed in notepad++. The second image is what I got in the cmd window after running it.
As mentioned in the article, you would need a "filter" program to process the control characters for a dos console window. The alternative is to figure out how to prevent line feed characters from being output to the screen and only return characters. This will prevent the line feeds, but I'm not sure how to output returns:

write(*,"(a)",advance="no") "Cursor ends up just after the colon : "
 
The control characters are deleted from Fortran 2003. May be that is the reason why gfortran just prints the numbers. Check this
 
These are ancient history.

Fortran just writes the control characters as the first character of each line. They were interpreted by old style (1960s vintage) line printers, and the sort of computer terminals that produced output on a roll of paper not on a video screen.

Back in the days when every computer printer DID interpret them, it was important not to write unwanted data in the first character, otherwise the printout would be a mess. Some types of printer used many more control characters than the four "standard" ones. In fact some printers even had mechanical devices to program what effect the control characters had.

Unix systems have a utility that attempts to simulate the effect on modern printers, but it wouldn't be very sensible to use this when writing new software. http://linux.die.net/man/1/asa
 
  • #10
AlephZero said:
Unix systems have a utility that attempts to simulate the effect on modern printers, but it wouldn't be very sensible to use this when writing new software. http://linux.die.net/man/1/asa

Yep, I remember using that about fifteen years ago when I was maintaining and running an old Fortran program that produced output with carriage control characters. I modified the program slightly so that it wrote its output to a file instead of directly to a printer. To print an output file I had to enter something like this at the Unix command line:

cat outputfile.txt | asa | lp
 

Similar threads

Replies
12
Views
3K
Replies
17
Views
6K
Replies
8
Views
4K
Replies
6
Views
2K
Replies
59
Views
11K
Replies
3
Views
3K
Replies
3
Views
3K
Back
Top