• Keine Ergebnisse gefunden

FORMAT DECLARATION

Im Dokument L THURN AU • JOHNSON • HAM (Seite 90-96)

rt rue ~I rtrue~f +

CHAPTER 7- COMMUNICATION - DATA AND RESULTS

7.2 FORMAT DECLARATION

The second identifier which appears in the parenthetical expres-sion associated with both the read statement and the write statement is a format identifier. This identifier refers to precise specifi-cations for the editing of input or output data. This identifier is associated with its corresponding editing specifications in a format declaration.

It is necessary to specify this editing information, since data in an external representation is in the form of characters which must be converted into numerical values in the computer. (Care should be taken when comparing data read from cards with program constants since the converted input value may not be exact in the least signifi-cant digit position; i.e., @+12 may not exactly equal 0.00000001@+20 where the former is a constant and the latter an input value.)The

pro-grammer must indicate in what form the external data is furnished, in the case of input, or is to appear, in the case of output. For card input the programmer must specify exactly how each column of the card is to be treated when read. Similarly, it must be inlilicated exactly how each column of a printed line is to appear. It is usually best to lay out the desired format, possibly on grid paper, to facilitate the writing of editing specifications to obtain this format.

The input capability used up to now allowed a card of the form 1

Fxxxx.xxxxxx

to be read by the read statement READ (CARD, FIN, (list)>

The identifier FIN refers to the format for editing this data as it is read into the computer. This format, recall, was of the form Fl2.6. This says to treat only the firsttwelve columns on the card, where there are six digits to the right of the decimal point (which

89

is in column 6), as a string of characters to be translated into the machine representation of a real number.

On input, the information from a card is deposited in the buffer in character form. It is then converted, according to the editing speci-fications, into the internal numerical form. In the output case, the program deposits the character information, according to output editing specifications, into the buffer. From there, it is automatically transferred directly to the printer.

For reference purposes, in the following discussion, it will be valuable to list the syntax of the format declaration.

(format declaration) : :

=

FORMAT(I-0 part) (format part)

j

FORMAT {format part) (I-0 part) : :

=

IN I OUT

(format part ) : := ( format identifier ) ( (editing specifications)) (format part), (format identifier)

((editing specifications)) (format identifier) : : = (identifier)

(editing specifications)::= (editing segment) I (editing specifications)

;I

/ (editing specifications)

j

(editing specifications) (editing segment) (editing segment) : : =(editing phrase)/

(repeat part) ({editing specifications)) I (editing segment), (editing phrase'> I (editing segment), (repeat part) ( (editing specifications))

(editing phrase) : : = (repeat part) (editing phrase type) (field part)

I

(string)

(repeat part) : : = (empty) I (unsigned integer) (editing phrase type) : : :::: E j FI RjI

jX

(field part): : :::: (field width) I (field width). (decimal places) (field width) : : :::: (unsigned integer)

(decimal places)::= (unsigned integer)

(string) : :

= "

{any string of valid characters except"} "

The syntax indicates that the declaration begins with the reserved word FORMAT, which, may at the option of the programmer, be followed by IN or OUT. Next, there is an identifier which is to be associated with the adjacent editing specifications.

The editing specifications, themselves, are made up of editing segments which are in turn made up of editing phrases. It is the editing phrase type and its use in forming more complex struc-tures which must now be considered. The editing phrase is the basic mechanism for describing the conversion of character strings into numeric form and vice versa. On output it also performs the addi-tional function of transmitting a fixed string of characters, given as an editing phrase.

For the editing of input information, the F, E, and R type editing phrases treat numbers with decimal points, converting them into real numbers internally. The I type is applicable to integers. The X type phrase, when applied to input, indicates that a certain number of columns on the card are to be ignored.

When editing output, the E,

F,

R, and I phrases have an analogous function to the above, that is, they produce either decimal numbers or integers in the output string. The X phrase produces a specific number of blank spaces in the output line.

The number of characters to be treated as a group by a particular editing phrase and the position of the decimal point, in the case of E, F, and R type editing phrases, is given by the field part. The field width is an unsigned integer specifying the number of charac-ter positions to be edited. The decimal places are also indicated by an unsigned integer and specify the number of character positions between the decimal point and the right end of the field.

For example, F6.2 would say to treat the contents of a field six characters wide, where the fourth character will be a decimal point, as a decimal number. This would be used to edit a number such as -32.05 appearing on a card.

The following tables and associated discussion will clarify the use of the various editing phrase types for both input and output.

INPUT EDITING PHRASES

Editing Editing Type of Example

Phrase Phrase Variable Reing of Field Type Example Processed As Initialized Contents E E9.2 6-bit characters REAL +7.18@-03

F F7.l 6-bit characters REAL -3892.5

R R8.0 6-bit characters REAL -5.1362

63.0ElO I 16 6-bit characters INTEGER -76329

x

X7 6-bit characters None any 7

characters

The definition of each input editing phrase type is given below:

E - In~tializes a variable to the number found in the field described by field width. Field width must be at least 7 greater than decimal places, since the input data is required to be in one of the following forms:

-n .ddd---d@+ee +n.ddd---a@+ee n. ddd ---d@+ee nn.ddd---d@,!ee

A two-digit exponent must be in the rightmost two characters of the field. Preceding it, must be a sign, and preceding the sign is an @ symbol. Next, to the left, is a number of digits equal to decimal places in the editing phrase, preceded by a decimal point. To the left of the decimal, there may be either two digits or a sign and one digit. The sign may be indicated by+, -, or a single space which is interpreted as positive.

F - Initializes a variable to the number found in the field described by field width. The input data must be in one of the following forms:

+nn---n.dd---d -nn---n.dd---d nn---n.dd---d nnn---n.dd---d +.dd---d -.dd---d .dd---d

The field width must be at least two greater than the decimal places to accommodate the decimal point and a possible sign. A decimal point must be present; zero or more digits may precede it. Finally, there must be one or more digits after the decimal point; the number of these digits must equal decimal places in the editing phrase. The rightmost decimal place must fall in the rightmost character of the field. If the sign is omitted, the number is taken to be positive.

R - Initializes a variable to the number found in the field described by field width. It will treat data in either the E or the F formats with the following features:

1. The number can be positioned anywhere in the field.

2. The actual position of the decimal point in the number overrides that specified in the decimal place part of the editing phrase.

3. The & is accepted as a+.

4. An E may be used instead of (Q'.

"i. The exponent part need not contain a si)ln position.

I - Initializes a variable to the integer found in the field described by field width. The least significant digit must fall in the rightmost character of the field. The sign need only occur if it is negative.

OUT PUT EDITING PHRASES

Editing Editing Type of Example

Phrase Phrase Evaluated of Field

Type Example Processed As Expression Contents E Ell.4 6-bit characters REAL -0.0125@+02 F F9.3 6-bit characters REAL 6735.125 R Rl0.3 6-bit characters REAL -1328.001

-1.576@+05 I 16 6-bit characters INTEGER 346140

x

XB 6-bit characters None 8 blanks

Each output editing phrase type is defined below.

E - Places the value of one expression in the field described by field width. This value has the following form when placed in the output data string:

n.dd---d@_!ee

-n.dd---d@~e

Again, the field width must be 7 greater than the decimal places.

If this is violated, an asterisk is printed in place of the number.

If field width is more than 7 greater than decimal places, leading single spaces are used to complete the field. The value of the expression is rounded to one more than the number of places indi-cated by decimal places of the editing phrase. The sign of the num-ber, the first significant digit, and a decimal point occur first. If the number of significant digits in the expression value is less than decimal places plus one, trailing zeros are appended. To complete the field, the symbol@, the sign of the exponent, and the appropri-ate two-digit exponent are inserted.

The sign of the number is represented by a single space if positive, and a minus sign if negative. The sign of the exponent is either + or

-.

F - Places the value of one expression in the field described by field width. This value has the following form when placed in the output string:

93

nn---n.dd---d -nn---n.dd---d nnn---n.dd---d

The expression value is rounded to the number of designated decimal places and that number of decimal places will be printed. If the digits preceding the decimal point and the sign of the number (if negative) do not

fl.ii

the remainder of the field, leading single spaces will be used to complete the field. If the specified field width is expres-sion value exceeds field width for positive values or exceeds field width minus one for negative values.

X - Places a number of single spaces, as indicated by field width, in the output string.

Each editing phrase describes a portion of the input data being read or the output data being written. If the same editing phrase or series of editing phrases occur several times, the repeat part may be used to conserve writing. For example, the series of editing phrases FS.2, FS.2, FS.2 may be written 3F5.2. Similarly I3, X3, FS.2, 13, X3, FS.2 is equivalent to 2(13, X3, FS.2). If the repeat part is omitted before an editing phrase or phrases enclosed in parentheses, the effect is the same as if the repeat part were infinite and a slash were to appear just inside the right parenthesis.

The occurrence of a slash (/) within a series of editing editing specifications is applied to the data from left to right. When the end of a set of editing specifications is reached or the end of

the list part of the I-0 statement has been reached, the same action is effected as that which occurs when a slash is encountered. If, when the end of a set of editing specifications is reached, more items remain in the list, the format is reused from the beginning.

If a slash follows the editing specifications for a complete record, the effect of two slashes is qbtained.

Note that the syntax requires that commas be used to separate edit-ing phrases within an editedit-ing segment. The quote marks at the ends of a string, which is one type of editing phrase, do not relieve the need for the comma. A comma may not appear adjacent to a slash since the comma is needed only within an editing segment.

Im Dokument L THURN AU • JOHNSON • HAM (Seite 90-96)