File I/O Ignores Formatted Carriage Control

ID: Q24212

3.20 3.30 3.31 4.00 4.01 4.10 5.00 5.10 | 4.10 5.00 5.10

MS-DOS                                  | OS/2
kbprg

The information in this article applies to:

SUMMARY

When an application sends uses formatted I/O and a FORMAT specifier to send a record to a device, FORTRAN interprets the first character of the record as a carriage-control character, as follows:

   Character  Interpretation
   -----------------------------------------------------------

   Blank     Advance one line
   0         Advance two lines
   1         Advance to top of next page (form feed)
   +         Do not advance (Prints over previous output)

FORTRAN ignores the carriage-control character "1" for screen I/O.

Applications commonly specify carriage control as the first character of the FORMAT specifier. However, when an application sends the output to a disk file (rather than sending the output directly to a device), the application places the literal character into the file and does not place any carriage-control information into the file. If you copy the file to the printer, no carriage control occurs.

MORE INFORMATION

Microsoft FORTRAN recognizes the following list of devices.

   Device      Comments
   -------------------------------

   AUX         COM1 alias
   COM1        COM1 port
   CON         stdout, stdin
   ERR         stderr
   LINE        COM1 alias
   LPT1        stdprn
   NUL         null device
   PRN         stdprn

Microsoft FORTRAN version 5.1 also recognizes the following devices.

   Device      Comments
   -------------------------------

   USER        stdout, stdin
   LPT2        stdprn
   LPT3        stdprn
   LPT4        stdprn

To use carriage control in text sent to a file, the application must explicitly write the carriage-control characters to the file. The following code example sends a form-feed character directly to a printer, but not to a file.

Sample Code #1

C Compile options needed: None

      OPEN(1, FILE = 'PRN')
      OPEN(2, FILE = 'TEST.DAT')
      WRITE(1, 10)
      WRITE(2, 10)
10 FORMAT('1 This follows the 1')
      END

The output to the TEST.DAT file is as follows:

1 This follows the 1

The following code example sends a form-feed character to both the printer and to the file using the CHAR() intrinsic function.

Sample Code #2

C Compile options needed: None

      OPEN(1, FILE = 'PRN')
      OPEN(2, FILE = 'TEST.DAT')
      WRITE(1, 10) CHAR(12)
      WRITE(2, 20) CHAR(12)
10 FORMAT(1X, A, 'This follows the form feed') 20 FORMAT(A, 'This follows the form feed')
      END

Note that the code uses a 1X format character to skip the carriage control field for output sent to the printer. Otherwise, the CHAR(12) character would be interpreted as a blank carriage-control character. In the output to the file, this step is not required because the CHAR(12) is desired in the file as a form-feed character.

In list-directed I/O (the "*" format), the first character of a record is not interpreted as a carriage-control character.

Additional reference words: kbinf 3.20 3.30 3.31 4.00 4.01 4.10 5.00 5.10 KBCategory: kbprg KBSubcategory: FORTLngIss

Last Reviewed: April 30, 1998