How do I use Control Characters in Fortran?

In summary, Glenn is trying to use Control Characters in Fortran, but is having difficulty. His professor skipped over that chapter in his Computational Tools 1 course, and he is trying to figure out how to use them. He is currently compiling his programs in the GNU Fortran compiler if that helps. The table for Control Characters looks like this:1......Skip to new page0......Double spacing+......No spacing (print over previous line)
  • #1
gmcke1
9
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
  • #3
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.
 
  • #4
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.
 
  • #5
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: 784
  • Capture2.PNG
    Capture2.PNG
    2 KB · Views: 665
  • #6
When the output device does not recognize the carriage control chars., they are printed out as normal text.
 
  • #7
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 : "
 
  • #8
The control characters are deleted from Fortran 2003. May be that is the reason why gfortran just prints the numbers. Check this
 
  • #9
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
 

1. What are control characters in Fortran?

Control characters in Fortran are special characters that are used to control the behavior of the program. They are typically non-printable characters that are represented by a backslash followed by a specific letter or symbol. They are used to perform specific actions such as moving the cursor, clearing the screen, or formatting the output.

2. How do I insert a control character in Fortran?

To insert a control character in Fortran, you can use the backslash escape sequence followed by the specific control character. For example, to insert a tab character, you can use the sequence "\t". Note that some control characters may have different escape sequences depending on the Fortran compiler you are using.

3. How do I use control characters to format output in Fortran?

To use control characters to format output in Fortran, you can use the "FORMAT" statement. In the format specification, you can specify the control character to be used, such as "I" for tab, "A" for carriage return, or "B" for backspace. You can also combine multiple control characters in a single format specification to achieve the desired formatting.

4. What are some common control characters used in Fortran?

Some common control characters used in Fortran include tab (\t), carriage return (\n), backspace (\b), and form feed (\f). These characters can be used for various purposes such as formatting output, controlling the cursor position, or clearing the screen.

5. Can I define my own control characters in Fortran?

No, you cannot define your own control characters in Fortran. These characters are part of the Fortran standard and have predefined meanings and functions. However, you can use escape sequences to represent non-printable characters and achieve similar effects as control characters.

Similar threads

  • Programming and Computer Science
Replies
12
Views
2K
  • Programming and Computer Science
Replies
17
Views
4K
  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
2
Replies
59
Views
9K
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
3
Views
3K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
4
Views
10K
Back
Top