Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How do I use Control Characters in Fortran?

  1. Aug 23, 2011 #1
    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: Aug 23, 2011
  2. jcsd
  3. Aug 23, 2011 #2

    Mark44

    Staff: Mentor

  4. Aug 23, 2011 #3

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    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.
     
  5. Aug 23, 2011 #4

    rcgldr

    User Avatar
    Homework Helper

    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.
     
  6. Aug 24, 2011 #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.
     

    Attached Files:

  7. Aug 24, 2011 #6

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    When the output device does not recognize the carriage control chars., they are printed out as normal text.
     
  8. Aug 24, 2011 #7

    rcgldr

    User Avatar
    Homework Helper

    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 : "
     
  9. Sep 13, 2012 #8
    The control characters are deleted from Fortran 2003. May be that is the reason why gfortran just prints the numbers. Check this
     
  10. Sep 14, 2012 #9

    AlephZero

    User Avatar
    Science Advisor
    Homework Helper

    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
     
  11. Sep 14, 2012 #10

    jtbell

    User Avatar

    Staff: Mentor

    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
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook