HP Fortran for OpenVMS
Language Reference Manual


Previous Contents Index

11.4.6 Slash Editing (/)

The slash edit descriptor terminates data transfer for the current record and starts data transfer for a new record. It takes the following form:

  • [r]/

The r is a repeat specification. It must be a positive default integer literal constant; no kind parameter can be specified.

The range of r is 1 through 2147483647 (2**31--1). If r is omitted, it is assumed to be 1.

Multiple slashes cause the system to skip input records or to output blank records, as follows:

11.4.7 Colon Editing (:)

The colon edit descriptor terminates format control if no more items are in the I/O list. For example, suppose the following statements are specified:


     PRINT 1,3 
     PRINT 2,13 
1    FORMAT (' I=',I2,' J=',I2) 
2    FORMAT (' K=',I2,:,' L=',I2) 

The following lines are written:


I=-3-J= 
K=13 

If I/O list items remain, the colon edit descriptor has no effect.

11.4.8 Dollar Sign ($) and Backslash (\) Editing

The dollar sign and backslash edit descriptors modify the output of carriage control specified by the first character of the record. They only affect carriage control for formatted files, and have no effect on input.

If the first character of the record is a blank or a plus sign (+), the dollar sign and backslash descriptors suppress carriage return (after printing the record).

For terminal device I/O, when this trailing carriage return is suppressed, a response follows output on the same line. For example, suppose the following statements are specified:


     TYPE 100 
100  FORMAT (' ENTER RADIUS VALUE ',$) 
     ACCEPT 200, RADIUS 
200  FORMAT (F6.2) 

The following prompt is displayed:


ENTER RADIUS VALUE 

Any response (for example, "12.") is then displayed on the same line:


ENTER RADIUS VALUE    12. 

If the first character of the record is 0, 1, or ASCII NUL, the dollar sign and backslash descriptors have no effect.

Consider the following:


     CHARACTER(20) MYNAME 
     WRITE (*,9000) 
9000 FORMAT ('0Please type your name:',\) 
     READ  (*,9001) MYNAME 
9001 FORMAT (A20) 
     WRITE (*,9002) ' ',MYNAME  
9002 FORMAT (1X,A20) 

This example advances two lines, prompts for input, awaits input on the same line as the prompt, and prints the input.

11.4.9 Character Count Editing (Q)

The character count edit descriptor returns the remaining number of characters in the current input record.

The corresponding I/O list item must be of type integer or logical. For example, suppose the following statements are specified:


     READ (4,1000) XRAY, KK, NCHRS, (ICHR(I), I=1,NCHRS) 
1000 FORMAT (E15.7,I4,Q,(80A1)) 

Two fields are read into variables XRAY and KK. The number of characters remaining in the record is stored in NCHRS, and exactly that many characters are read into the array ICHR. (This instruction can fail if the record is longer than 80 characters.)

If you place the character count descriptor first in a format specification, you can determine the length of an input record.

On output, the character count edit descriptor causes the corresponding I/O list item to be skipped.

11.5 Character String Edit Descriptors

Character string edit descriptors control the output of character strings. The character string edit descriptors are the character constant and H edit descriptor.

Although no string edit descriptor can be preceded by a repeat specification, a parenthesized group of string edit descriptors can be preceded by a repeat specification (see Section 11.6).

11.5.1 Character Constant Editing

The character constant edit descriptor causes a character string to be output to an external record. It takes one of the following forms:

  • 'string'
  • "string"

The string is a character literal constant; no kind parameter can be specified. Its length is the number of characters between the delimiters; two consecutive delimiters are counted as one character.

To include an apostrophe in a character constant that is enclosed by apostrophes, place two consecutive apostrophes ( ' ' ) in the format specification; for example:


50   FORMAT ('TODAY''S-DATE-IS:-',I2,'/',I2,'/',I2) 

Similarly, to include a quotation mark in a character constant that is enclosed by quotation marks, place two consecutive quotation marks ("") in the format specification.

For More Information:

11.5.2 H Editing

The H edit descriptor transfers data between the external record and the H edit descriptor itself. The H edit descriptor is a deleted feature in Fortran 95; it was obsolescent in Fortran 90. HP Fortran fully supports features deleted in Fortran 95.

An H edit descriptor has the form of a Hollerith constant, as follows:

  • nHstring

n

Is an unsigned, positive default integer literal constant (with no kind parameter) indicating the number of characters in string (including blanks and tabs).

The range of n is 1 through 2147483647 (2**31--1). Actual useful ranges may be constrained by record sizes (RECL) and the file system.

string

Is a string of printable ASCII characters.

On input, the H edit descriptor transfers n characters from the external field to the edit descriptor. The first character appears immediately after the letter H. Any characters in the edit descriptor before input are replaced by the input characters.

On output, the H edit descriptor causes n characters following the letter H to be output to an external record.

For More Information:

11.6 Nested and Group Repeat Specifications

Format specifications can include nested format specifications enclosed in parentheses; for example:


15   FORMAT (E7.2,I8,I2,(A5,I6))     
 
35   FORMAT (A6,(L8(3I2)),A) 

A group repeat specification can precede a nested group of edit descriptors. For example, the following statements are equivalent, and the second statement shows a group repeat specification:


50   FORMAT (I8,I8,F8.3,E15.7,F8.3,E15.7,F8.3,E15.7,I5,I5) 
 
50   FORMAT (2I8,3(F8.3,E15.7),2I5) 

If a nested group does not show a repeat count, a default count of 1 is assumed.

Normally, the string edit descriptors and control edit descriptors cannot be repeated (except for slash), but any of these descriptors can be enclosed in parentheses and preceded by a group repeat specification. For example, the following statements are valid:


76   FORMAT ('MONTHLY',3('TOTAL')) 
 
100  FORMAT (I8,4(T7),A4) 

For More Information:

11.7 Variable Format Expressions

A variable format expression is a numeric expression enclosed in angle brackets ( <> ) that can be used in a FORMAT statement or in a character format specification.

The numeric expression can be any valid Fortran expression, including function calls and references to dummy arguments.

If the expression is not of type integer, it is converted to integer type before being used.

If the value of a variable format expression does not obey the restrictions on magnitude applying to its use in the format, an error occurs.

Variable format expressions cannot be used with the H edit descriptor, and they are not allowed in character format specifications.

Variable format expressions are evaluated each time they are encountered in the scan of the format. If the value of the variable used in the expression changes during the execution of the I/O statement, the new value is used the next time the format item containing the expression is processed.

Examples

Consider the following statement:


FORMAT (I<J+1>) 

When the format is scanned, the preceding statement performs an I (integer) data transfer with a field width of J+1. The expression is reevaluated each time it is encountered in the normal format scan.

Consider the following statements:


     DIMENSION A(5) 
     DATA A/1.,2.,3.,4.,5./ 
 
     DO 10 I=1,10 
     WRITE (6,100) I 
100  FORMAT (I<MAX(I,5)>) 
10   CONTINUE 
 
     DO 20 I=1,5 
     WRITE (6,101) (A(I), J=1,I) 
101  FORMAT (<I>F10.<I-1>) 
20   CONTINUE 
     END 

On execution, these statements produce the following output:


   1 
   2 
   3 
   4 
   5 
    6 
     7 
      8 
       9 
       10 
       1. 
      2.0        2.0 
     3.00       3.00     3.00 
    4.000      4.000    4.000     4.000 
   5.0000    5.0000    5.0000    5.0000    5.0000 

For More Information:

On the synchronization of I/O lists with formats, see Section 11.9.

11.8 Printing of Formatted Records

On output, if a file was opened with CARRIAGECONTROL= ' FORTRAN ' in effect or the file is being processed by the fortpr format utility, the first character of a record transmitted to a line printer or terminal is typically a character that is not printed, but used to control vertical spacing.

Table 11-5 lists the valid control characters for printing.

Table 11-5 Control Characters for Printing
Character Meaning Effect
+ Overprinting Outputs the record (at the current position in the current line) and a carriage return.
- One line feed Outputs the record (at the beginning of the following line) and a carriage return.
0 Two line feeds Outputs the record (after skipping a line) and a carriage return.
1 Next page Outputs the record (at the beginning of a new page) and a carriage return.
$ Prompting Outputs the record (at the beginning of the following line), but no carriage return.
ASCII NUL 1 Overprinting with no advance Outputs the record (at the current position in the current line), but no carriage return.


1Specify as CHAR(0).

Any other character is interpreted as a blank and is deleted from the print line. If you do not specify a control character for printing, the first character of the record is not printed.

11.9 Interaction Between Format Specifications and I/O Lists

Format control begins with the execution of a formatted I/O statement. Each action of format control depends on information provided jointly by the next item in the I/O list (if one exists) and the next edit descriptor in the format specification.

Both the I/O list and the format specification are interpreted from left to right, unless repeat specifications or implied-do lists appear.

If an I/O list specifies at least one list item, at least one data edit descriptor (I, B, O, Z, F, E, EN, ES, D, G, L, or A) or the Q edit descriptor must appear in the format specification; otherwise, an error occurs.

Each data edit descriptor (or Q edit descriptor) corresponds to one item in the I/O list, except that an I/O list item of type complex requires the interpretation of two F, E, EN, ES, D, or G edit descriptors. No I/O list item corresponds to a control edit descriptor (X, P, T, TL, TR, SP, SS, S, BN, BZ, $, or :), or a character string edit descriptor (H and character constants). For character string edit descriptors, data transfer occurs directly between the external record and the format specification.

When format control encounters a data edit descriptor in a format specification, it determines whether there is a corresponding I/O list item specified. If there is such an item, it is transferred under control of the edit descriptor, and then format control proceeds. If there is no corresponding I/O list item, format control terminates.

If there are no other I/O list items to be processed, format control also terminates when the following occurs:

If additional I/O list items remain, part or all of the format specification is reused in format reversion.

In format reversion, the current record is terminated and a new one is initiated. Format control then reverts to one of the following (in order) and continues from that point:

  1. The group repeat specification whose opening parenthesis matches the next-to-last closing parenthesis of the format specification
  2. The initial opening parenthesis of the format specification

Format reversion has no effect on the scale factor, the sign control edit descriptors (S, SP, or SS), or the blank interpretation edit descriptors (BN or BZ).

Examples

The data in file FOR002.DAT is to be processed 2 records at a time. Each record starts with a number to be put into an element of a vector B, followed by 5 numbers to be put in a row in matrix A.

FOR002.DAT contains the following data:


001 0101 0102 0103 0104 0105 
002 0201 0202 0203 0204 0205 
003 0301 0302 0303 0304 0305 
004 0401 0402 0403 0404 0405 
005 0501 0502 0503 0504 0505 
006 0601 0602 0603 0604 0605 
007 0701 0702 0703 0704 0705 
008 0801 0802 0803 0804 0805 
009 0901 0902 0903 0904 0905 
010 1001 1002 1003 1004 1005 

Example 11-1 shows how several different format specifications interact with I/O lists to process data in file FOR002.DAT.

Example 11-1 Interaction Between Format Specifications and I/O Lists

        INTEGER I, J, A(2,5), B(2) 
 
        OPEN (unit=2, access='sequential', file='FOR002.DAT') 
 
(1)        READ (2,100) (B(I), (A(I,J), J=1,5),I=1,2) 
(2)  100   FORMAT (2 (I3, X, 5(I4,X), /) ) 
 
(3)        WRITE (6,999) B, ((A(I,J),J=1,5),I=1,2) 
  999   FORMAT (' B is ', 2(I3, X), ';  A is', / 
       1       (' ', 5 (I4, X)) ) 
 
(4)        READ (2,200) (B(I), (A(I,J), J=1,5),I=1,2) 
  200   FORMAT (2 (I3, X, 5(I4,X), :/) ) 
 
(5)        WRITE (6,999) B, ((A(I,J),J=1,5),I=1,2) 
 
 
(6)        READ (2,300) (B(I), (A(I,J), J=1,5),I=1,2) 
  300   FORMAT ( (I3, X, 5(I4,X)) ) 
 
(7)        WRITE (6,999) B, ((A(I,J),J=1,5),I=1,2) 
 
(8)        READ (2,400) (B(I), (A(I,J), J=1,5),I=1,2) 
  400   FORMAT ( I3, X, 5(I4,X) ) 
 
(9)        WRITE (6,999) B, ((A(I,J),J=1,5),I=1,2) 
 
        END 

  1. This statement reads B(1); then A(1,1) through A(1,5); then B(2) and A(2,1) through A(2,5).
    The first record read (starting with 001) starts the processing of the I/O list.
  2. There are two records, each in the format I3, X, 5(I4, X). The slash (/) forces the reading of the second record after A(1,5) is processed. It also forces the reading of the third record after A(2,5) is processed; no data is taken from that record.
  3. This statement produces the following output:


    B is   1   2 ;  A is 
     101  102  103  104  105 
     201  202  203  204  205 
    

  4. This statement reads the record starting with 004. The slash (/) forces the reading of the next record after A(1,5) is processed. The colon (:) stops the reading after A(2,5) is processed, but before the slash (/) forces another read.
  5. This statement produces the following output:


    B is   4   5 ;  A is 
     401  402  403  404  405 
     501  502  503  504  505 
    

  6. This statement reads the record starting with 006. After A(1,5) is processed, format reversion causes the next record to be read and starts format processing at the left parenthesis before the I3.
  7. This statement produces the following output:


    B is   6   7 ;  A is 
     601  602  603  604  605 
     701  702  703  704  705 
    

  8. This statement reads the record starting with 008. After A(1,5) is processed, format reversion causes the next record to be read and starts format processing at the left parenthesis before the I4.
  9. This statement produces the following output:


    B is   8  90 ;  A is 
     801  802  803  804  805 
     9010 9020 9030 9040 100 
    

    The record 009 0901 0902 0903 0904 0905 is processed with I4 as "009 " for B(2), which is 90. X skips the next "0". Then "901 " is processed for A(2,1), which is 9010, "902 " for A(2,2), "903 " for A(2,3), and "904 " for A(2,4). The repeat specification of 5 is now exhausted and the format ends. Format reversion causes another record to be read and starts format processing at the left parenthesis before the I4, so "010 " is read for A(2,5), which is 100.

For More Information:


Previous Next Contents Index