• Aucun résultat trouvé

Reading Format Specifications at Object Time

Dans le document VS FORTRAN (Page 114-119)

FORTRAN provides for variable FORMAT statements by allowing a format specification to be read into a character array element or a charact~r variable in storage. The data in the character array or variable may then be used as the format specification for subsequent input/output operations. The format specification may also be placed into the character array or variable by a DATA

statement or an explicit specification statement in the source program. The following rules are applicable:

• The format specification must be a character array or character variable, even if the array size is only 1.

• The format codes entered into the array or character variable must have the same form as a source program FORMAT statement, except that the word FORMAT and the statement number are omitted. The parentheses surrounding the format codes are required.

104 VS FORTRAN language Reference

FORMAT

• If a format code read at objec~ time contains two consecutive apostrophes within a character field that is defined by

apostrophes, it'should be used for output only.

• Blank characters may precede the format specification, and character data may follow the right parenthesis that ends the format specification.

Example: Assume the following statements:

DIMENSION CCS) CHARACTER*16 FMT READ(S,l)FMT 1 FORMAT CA)

READ(S,FMT)A,B,CCCI),I=l,S)

Assume, also, that the first input line assoicated with unit S contains (2ElO.3, 5FIO.8).

The data on the next input line is read, converted, and stored in A,B, and the array C, according to the format codes 2EIO.3,

SFIO.8.

IBM EXTENSION

READING A FOR HAT INTO A NONCHARACTER ARRAY

Assume the following statements:

DIMENSION FMT(l6),C(S) READ(S,l) FMT

1 FORMAT(l6Al)

READ(S,FMT)A,B,CCCI),I=l,S)

Assume also that the first input line associated with unit S contains (2EIO.3, SFIO.8).

The data on the next input record is read, converted, and stored in A, B, and the array C, according to the format codes 2ElO.3, SFIO.8.

END OF IBM EXTENSION - - - '

List-Directed Formatting

The characters in one or more list-directed records constitute a sequence of values and value separators. The end of a record has the same effect as a blank character, unless it is within a character constant. Any sequence of two or more consecutive blanks is treated as a single blank, unless it is within a character constant.

Each value is either a constant, a null value, or one of the forms:

.r.*£

or .r.*

where 1: is an unsigned, nonzero, integer constant. The .r.*£ form is equivalent to .r. successive appearances of the constant £, and the .r.* form is equivalent to .r. successive null values. Neither of

these forms may contain embedded blanks except where permitted within the constant

f.

A value separator is one of the following:

• A comma, opt i onally preceded by one or more blanks and

FORMAT

given type are acceptable for list-directed formatting, except as noted below. The form of the input value must be acceptable for the type of the input list item. Blanks are never treated as zeros, and embedded blanks are not permitted in constants, except within character constants and complex constants as specified below. The end of a record has the effect of a blank, except when it appears within a character· constant.

When the corresponding input list item is of type ~eal or double apostrophes. Each apostrophe within a character constant must be represented by two consecutive apostrophes without an intervening blank or end of record. Character constants may be continued from the end of one record to the beginning of the next record. The end of the record does not cause a blank or any other character to become part of ,the constant. The constant may be continued on as many records as needed. The characters blank, comma, and slash may appear in character constants.

For example, let len be the length of ~he list item, and let H be successive separators, by having no characters preceding the first value separator in the first record read by each execution list-directed input statement causes termination of execution of that input statement after the assignment of the previous value.

If there are additional items in the input list, the effect is as if null values had been supplied for them.

106 VS FORTRAN Language Reference

FORMAT All blanks in a list-directed input record are considered part of some value separator, except for the following:

• Blanks embedded in a character constant

• Embedded blanks surrounding the real or imaginary part of a complex constant

• Leading blanks in the first record read by each execution of a list-directed input statement, unless immediately followed by a slash or comma

OUTPUT: The form of the values produced is the same as that required for input, except as noted. With the exception of character constants, the values are separated by one of the following:

• One or more blanks

• A comma, optionally preceded by one or more blanks and optionally followed by one or more blanks

VS FORTRAN may begin new records as necessary but, except for complex constants and character constants, the end of a record must not occur within a constant, and blanks must not appear within a constant.

logical output constants are T for the value .TRUE. and F for the value .FALSE ..

Integer output constants are produced with the effect of an I~

edit descriptor for some reasonable value of ~.

Real and double precision constants are produced with the effect of either an F format code or an E format code, depending on the magnitude ~ of the value and a range:

where

dl

and

d2

are processor-dependent integer values. If the magnitude ~ is within this range, the constant is produced using

OPFw.d; otherwise, IPEw.dEe is used. Reasonable

processor-dependent values-of w, d, and e are used for each of the

cases involved. - -

-Complex constants are enclosed in parentheses, with a comma separating the real and imaginary parts. The end of a record may occur between the comma and the imaginary part only if the entire constant is as long as, or longer than, an entire record. The only embedded blanks permitted within a complex constant are between the comma and the end of a record and one blank at the beginning of the next record.

Character constants produced:

• Are not delimited by apostrophes

• Are not preceded or followed by a value separator

• Have each internal apostrophe represented externally by one apostrophe

• Have a blank character inserted at the beginning of any record that begins with the continuation of a character constant from the preceding record

If two or more successive values in an output record produced have identical values, the sequence of identical values are written.

Slashes, as value separators, and null values are not produced by list-directed formatting.

FORMAT

Each output record begins with a blank character to provide carrier control if the record is printed.

108 VS FORTRAN language Reference

FUNCTION STATEMENT

FUNCTION

The FUNCTION statement identifies a function subprogram. A function subprogram consists of a FUNCTION statement followed by other statements including at least one RETURN statement. It is an independently written program that is executed wherever its name is referred to in another program.

~

Syntax

I

~pe] FUNCTION ngmg ([~l [, arg2] •.. ] )

is INTEGER, REAL, DOUBLE PRECISION, COMPLEX, LOGICAL, or CHARACTERPElenl]

where:

3Elen1

is the length specification. It is optional; if

omitted, it is assumed to be 1. It may be an unsigned, nonzero, integer constant, an integer constant

expression enclosed in parentheses, or an asterisk enclosed in parentheses. The expression can only

contain integer constants; it must not include names of integer constants.

If the name is of type CHARACTER, all entry names must be of type CHARACTER, and lengths must be the same. If one length is spec; fi ed as an asteri sk, all lengths must be specified as an asterisk.

i s the name of the funct ion.

IBM EXTENSION

Dans le document VS FORTRAN (Page 114-119)

Documents relatifs