How do I use Control Characters in Fortran?

  • Context: Fortran 
  • Thread starter Thread starter gmcke1
  • Start date Start date
  • Tags Tags
    Control Fortran
Click For Summary

Discussion Overview

The discussion revolves around the use of control characters in Fortran, particularly focusing on their implementation and behavior in the GNU Fortran compiler. Participants explore various aspects of control characters, including their historical context, practical usage, and compatibility with modern output devices.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Historical

Main Points Raised

  • Glenn seeks clarification on how to use the "+" control character for printing over a previous line in Fortran, requesting a simple example.
  • Some participants suggest looking up resources online for additional information on control characters in Fortran.
  • It is noted that the effectiveness of control characters depends on whether the output device recognizes them, with some devices printing the control characters as normal text.
  • A participant recalls that historically, control characters were managed by a Fortran library module that translated them based on the output device type.
  • One participant shares their experience of attempting to use control characters in a command window, indicating that the gfortran compiler might not recognize them as intended.
  • There is mention that control characters were removed in Fortran 2003, which could explain why they are not functioning as expected in modern compilers.
  • Some participants reflect on the historical significance of control characters, noting that they were primarily relevant for older printing technologies and may not be sensible to use in new software development.
  • Unix systems are mentioned as having utilities that can simulate the effects of control characters, though their relevance for current programming practices is questioned.

Areas of Agreement / Disagreement

Participants express differing views on the relevance and functionality of control characters in modern Fortran programming. There is no consensus on their practical application or on the best methods to utilize them in contemporary environments.

Contextual Notes

Limitations include the dependence on the output device's ability to recognize control characters, the historical context of their use, and the removal of control characters in Fortran 2003, which may affect current implementations.

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: 862
  • Capture2.PNG
    Capture2.PNG
    2 KB · Views: 760
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 ·
Replies
12
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 17 ·
Replies
17
Views
7K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 59 ·
2
Replies
59
Views
12K
  • · Replies 17 ·
Replies
17
Views
5K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 4 ·
Replies
4
Views
11K
  • · Replies 3 ·
Replies
3
Views
3K