Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP Fortran Compiler for HP-UX: HP Fortran Programmer's Reference > Chapter 9 I/O formatting

Edit descriptors

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

Edit descriptors are encoded characters that describe data conversion between an internal (binary) format and an external (character) format. There are three types of edit descriptors:

  • Data edit descriptors define the format of data to be read or written, such as its type and width (in characters). All data edit descriptors are repeatable; that is, they can be preceded by a positive integer that specifies the number of times the edit descriptor is to be replicated.

  • Control edit descriptors specify editing information, such as the number of spaces between input items, treatment of blanks in input, and scale factors. Of the control edit descriptors, only the slash (/) is repeatable.

  • Character string edit descriptors output text. None of these is repeatable.

All of the edit descriptors supported by HP Fortran are listed in
Table 9-1 “Edit descriptors”. As indicated by the syntax descriptions included in the table, the field width specification (w) is optional for all data edit descriptors in HP Fortran. Note that the Fortran 90 Standard defines the field width specifier to be optional only for the A edit descriptor. The table also identifies which edit descriptors are repeatable and which can be used on input, output, or both.

Table 9-1 Edit descriptors

Descriptor

Type

Repeatable?

I/O use

Function

... or '...'

Character string

No

Output

Output enclosed string.

$

Control

No

Output

Suppress newline at end of output.

/ (slash)

Control

Yes

Input/output

End current record and begin new record.

: (colon)

Control

No

Input/output

Stop formatting if I/O list is exhausted.

A[w] or R[w]

Data

Yes

Input/output

Convert character data.

B[w[.m]]

Data

Yes

Input/output

Convert integer data, using binary base.

BN

Control

No

Input/output

Ignore blanks in numeric input data.

BZ

Control

No

Input/output

Treat blanks as zeroes in numeric input data.

D[w.d]

Data

Yes

Input/output

Convert real type data with exponent.

E[w.d[Ee]]

Data

Yes

Input/output

Convert real type data with exponent.

EN[w.d[Ee]]

Data

Yes

Input/output

Convert real type data, using engineering notation.

ES[w.d[Ee]]

Data

Yes

Input/output

Convert real type data, using scientific notation.

F[w.d]

Data

Yes

Input/output

Convert real type data without exponent.

G[w.d[Ee]]

Data

Yes

Input/output

Convert numeric data, all types.

Q[w.d]

Data

Yes

Input/output

Convert real type data with exponent.

nHs

Character String

No

Output

Output following n characters.

I[w[.m]]

Data

Yes

Input/output

Convert integer numeric data.

L[w]

Data

Yes

Input/output

Convert logical data.

M

Data

Yes

Input/output

Input/Output monetary data with a comma

N

Data

Yes

Input/output

Input/Output monetary data with a comma and a dollar sign

O[w[.m]]

Data

Yes

Input/output

Convert integer data, using octal base.

kP

Control

No

Input/output

Set scale factor to k.

Q

Control

No

Input

Return number of bytes remaining to be read in current input record.

S or SP

Control

No

Output

Print optional plus sign.

SS

Control

No

Output

Do not print optional plus sign.

Tc

Control

No

Input/output

Move to column c.

TLc

Control

No

Input/output

Move c columns to the left.

TRc or cX

Control

No

Input/output

Move c columns to the right.

Z[w[.m]]

Data

Yes

Input/output

Convert integer data, using hexadecimal base.

 

The following sections describe the edit descriptors.

NOTE: There is no single edit descriptor that defines a field for complex data. Instead, you must use two real edit descriptors—the first for the real part of the number, and the second for the imaginary part. The two edit descriptors may be different or the same, and you can insert control and character string edit descriptors between them.

Likewise, there are no edit descriptors for formatting derived types and pointers. For derived types, you must specify the appropriate sequence of edit descriptors that match the data types of the derived type’s components. For pointers, you must specify the edit descriptor that matches the type of the target object.

Character string (’...’ or ”...”) edit descriptor

The character string edit descriptor is used to write a character constant to a formatted output record. It cannot be used to format input. You can use either apostrophes or quotation marks to delimit the constant. Whichever you use, they must be balanced. That is, if you begin with an apostrophe, you must also end with it. If the enclosed character constant includes a delimiting character, it must be of the other type; or you can escape the delimiter by giving another of the same type. The width of the field is the number of characters enclosed by the character string edit descriptors, including any blanks.

Table 9-2 “Character string edit descriptor output examples” provides examples of the character string edit descriptor on output. Note that b represents a blank.

Table 9-2 Character string edit descriptor output examples

Descriptor

Field width

Output

'Enter data:'

11

Enter data:

”David's turn”

12

David's turn

bbbSpacesbbb

12

bbbSpacesbbb

'That''ll do.'

11

That'll do.

”””That'll do!”””

13

”That'll do!”

””””

1

'”'

1

 

Newline ($) edit descriptor

The newline edit descriptor is an HP extension that suppresses the generation of the newline character (that is, the carriage-return/linefeed sequence) during formatted, sequential output. By default, the cursor moves to a newline after each output statement. The newline edit descriptor causes the cursor to remain on the same line, immediately to the right of the last character output.

NOTE: Nonadvancing I/O also suppresses the newline at the end of a record. Unlike the newline ($) edit descriptor, it is a standard feature of Fortran 90, and can be used on input and output. For more information, see “Nonadvancing I/O” and the ADVANCE= I/O specifier in OPEN.

Slash (/) edit descriptor

The slash edit descriptor terminates the current record and begins processing a new record (such as a new line on a terminal). This edit descriptor has the same result for both input and output: it terminates the current record and begins a new one. For example, on output a newline character is printed, and on input a new line is read.

Keep in mind the following considerations when using the slash edit descriptor:

  • If a series of two or more slashes are written at the beginning of a format specification, the number of records skipped is equal to the number of slashes.

  • If n slashes appear other than at the beginning of a format specification (where n is greater than 1), processing of the current record terminates and n - 1 records are skipped.

  • If a format contains only n slashes (and no other format specifiers), n + 1 records are skipped.

The / edit descriptor does not need to be separated from other descriptors by commas.

Colon (:) edit descriptor

The colon edit descriptor (:) is used when performing formatted I/O to terminate format control when the I/O list has been exhausted. If all items in an I/O list have been read or written, the colon edit descriptor stops any further format processing. If more items remain in the list, the colon edit descriptor has no effect.

Consider the following example:

WRITE (*, 40) 1, 2
WRITE (*, 50) 1, 2
40 FORMAT(3(' value =', I2))
50 FORMAT(3(:, ' value =', I2))

The first WRITE statement outputs the line:

 value = 1 value = 2 value =

The descriptor 'value =' is repeated a third time because format control is not terminated until the descriptor I2 is reached and not satisfied.

The second WRITE statement outputs the line:

 value = 1 value = 2

This time, the colon descriptor terminates format control before the string ' value=' is output a third time.

A and R (character) edit descriptors

The A and R edit descriptors define fields for character data. The A edit descriptor specifies left-justification, and the R edit descriptor specifies right-justification.

The R edit descriptor is an HP extension.

The syntax for the character edit descriptors is:

[r]A[w]
[r]R[w]

where:

r

is a positive integer constant, specifying the repeat factor.

w

is the field width. If w is not specified, the default is the length in bytes of the corresponding I/O list item.

As a portability extension, the list item can be of any data type.

When the A and R edit descriptors are used for input and output, the results can differ according to whether the width (w) specified for the edit descriptor is less than, greater than, or equal to the length of the I/O list item. The results on input are summarized in Table 9-3 “Contents of character data fields on input”; the results on output are summarized in Table 9-4 “Contents of character data fields on output”.

Table 9-3 Contents of character data fields on input

Descriptor

Width/length relationship

Result

A

width < length

Data is left-justified in variable, followed by blanks.

width >= length

Data is taken from rightmost characters in the field.

R

width < length

Data is right-justified in variable, preceded by nulls.

width >= length

Data is taken from rightmost characters in the field.

 

Table 9-4 Contents of character data fields on output

Descriptor

Width/length relationship

Result

A

width <= length

Data is taken from leftmost characters in the field.

width > length

Output the value, preceded by blanks.

R

width <= length

Data is taken from rightmost characters in the field.

width > length

Output the value, preceded by blanks.

 

Examples of the use of character edit descriptors on input are provided in Table 9-5 “A and R edit descriptors: input examples”. In the table, b represents a blank and z represents a Null.

Table 9-5 A and R edit descriptors: input examples

Descriptor

Input field

Variable length

Value stored

A3

XYZ

3

XYZ

R3

XYZ

4

zXYZ

A5

ABCbb

10

ABCbbbbbbb

R9

RIGHTMOST

4

MOST

R8

CHAIRbbb

8

CHAIRbbb

R4

CHAIR

8

zzzzCHAI

A4

ABCD

2

CD

 

Table 9-6 “A and R Edit descriptors: output examples” provides examples of character edit descriptors on output. In the table, b represents a blank and z represents a Null.

Table 9-6 A and R Edit descriptors: output examples

Descriptor

Internal characters

Variable length

Output

A6

ABCDEF

6

ABCDEF

R4

ABCDEFGH

8

EFGH

A4

ABCDE

5

ABCD

A8

STATUS

6

bbSTATUS

R8

STATUS

6

bbSTATUS

R8

STATUS

8

STATUSbb

 

B (binary) edit descriptor

The B edit descriptor defines a field for binary data. It provides for conversion between an external binary number and its internal representation.

The syntax for the binary edit descriptor is:

[r]B[w[.m]]

where:

r

is a positive integer constant, specifying the repeat factor.

w

is a positive integer constant, specifying the field width.

m

is an unsigned integer constant, specifying the minimum number of digits that must be in the field and forcing leading zeroes as necessary up to the first nonzero digit. The m value is ignored on input. If m is not specified, a default value of 1 is assumed. If m is larger than w, the field is filled with w asterisks.

Input

Variables to receive binary input must be of type integer. The only legal characters are 0s and 1s. Nonleading blanks are ignored, unless the file is opened with BLANK='ZERO'.

If the file is opened with BLANK='ZERO', nonleading blanks are treated as zeroes. For more information about the BLANK= specifier, see OPEN. Plus and minus signs, commas, or any other symbols are not permitted. If a nonbinary digit appears, an error occurs. The presence of too many digits for the integer variable (or I/O list item) is illegal.

Table 9-7 “B Edit descriptor: input examples” provides examples of the binary edit descriptor on input.

Table 9-7 B Edit descriptor: input examples

Descriptor

Input field (binary)

Value stored (binary)

B8

1111

1111

B8

01111

1111

B4

10101

1010

B8

1.1

error: illegal character

 

Output

Unlike input, list items on output may be of any type, though character values are output only as the binary equivalent of their ASCII representation (without a length descriptor). If w is greater than the number of converted binary digits (excluding leading zeroes), the binary digits are right-justified in the output field.

If w is less than the number of converted binary digits, the field is filled with w asterisks. This primarily affects the output of negative values. Because negative values are output in twos complement form, their high-order bits are nonzero and cause the field to be filled with asterisks when w is less than the number of binary digits in the entire output value.

The field width required to fully represent the binary value of an item is eight times its size in bytes. For example, an INTEGER*4 item could require a field w of up to 32 characters.

Only 1s and 0s are printed on output.

Table 9-8 “B Edit descriptor: output examples” provides examples of the binary edit descriptor on output.

Table 9-8 B Edit descriptor: output examples

Descriptor

Internal value

Output

B5

27

11011

B8

27

bbb11011

B8.6

27

bb011011

B8

-27

********

 

BN and BZ (blank) edit descriptors

The BN and BZ edit descriptors control the interpretation of embedded and trailing blanks in numeric input fields. The syntax of the blank edit descriptors is:

BN
BZ

At the beginning of the execution of an input statement, blank characters within numbers are ignored except when the unit is connected with BLANK='ZERO' specified in the OPEN statement. BN and BZ override the BLANK= I/O specifier for the current READ statement. For more details about the BLANK= I/O specifier, see OPEN.

If a BZ edit descriptor is encountered in the format specification, trailing and embedded blanks in succeeding numeric fields are treated as zeroes. The BZ edit descriptor remains in effect until a BN edit descriptor or the end of the format specification is encountered. If BN is specified, all embedded blanks are removed and the input number is right justified within the field width.

The BN and BZ edit descriptors affect only I, B, O, F, D, E, EN, ES, G, and Z format descriptors during the execution of an input statement. The BN and BZ edit descriptors do not affect character and logical edit descriptors.

Table 9-9 “BN and BZ edit descriptors: input examples” provides examples of the BN and BZ edit descriptors on input.

Table 9-9 BN and BZ edit descriptors: input examples

Descriptor

Input characters

BN editing in effect

BZ editing in effect

I4

1b2b

12

1020

F6.2

b4b.b2

4.2

40.02

E7.1

5b.bE1b

5.0 x 101

5.0 x 1011

E5.0

3E4bb

3.0 x 104

3.0 x 10400 (overflow)

 

The BN and BZ edit descriptors are ignored during the execution of an output statement.

D, E, EN, ES, F, G, and Q (real) edit descriptors

The D, E, EN, ES, F, G, and Q edit descriptors define fields for real numbers. The I/O list item corresponding to a real descriptor must be a numeric type. (The Standard permits real and complex types only; as an extension, HP Fortran allows integers.)

The syntax for these edit descriptors is:

[r]D[w.d]
[r]E[w.d[{E|D|Q}e]]
[r]EN[w.d[Ee]]
[r]ES[w.d[Ee]]
[r]F[w.d]
[r]G[w.d[{E|D|Q}e]]
[r]Q[w.d]

where:

r

is a positive integer constant, specifying the repeat factor.

w

is a positive integer constant, specifying the field width.

d

is a nonnegative integer constant, specifying the number of decimal places on output.

e

is a positive integer constant, specifying the number of digits in the exponent.

For formatting complex data, you can use two real edit descriptors—the first for the real part of the number and the second for the imaginary part. The two edit descriptors may be different or the same, and you can insert control and character string edit descriptors between them.

Real edit descriptors on input

The input field for the real descriptors consists of an optional plus or minus sign followed by a string of digits that may contain a decimal point. If the decimal point is omitted in the input string, then the number of digits equal to d from the right of the string are interpreted to be to the right of the decimal point. If a decimal point appears in the input string and conflicts with the edit descriptor, the decimal point in the input string takes precedence. This basic form can be followed by an exponent in one of the following forms:

  • A signed integer constant

  • An E followed by an optionally signed integer constant

  • A D followed by an optionally signed integer constant

  • A Q followed by an optionally signed integer constant

All four exponent forms are processed in the same way. Note, however, that e has no effect on input.

The EN and ES edit descriptors are the same as the F edit descriptor on input. The Q edit descriptor (an HP Fortran extension) is the same as the E edit descriptor on input.

Table 9-10 “D, E, F, and G edit descriptors: input examples” provides examples of the real edit descriptors on input. The BZ edit descriptor listed in the “Descriptor” column treats nonleading blanks in numeric fields as zeroes.

Table 9-10 D, E, F, and G edit descriptors: input examples

Descriptor

Input field

Value stored

F6.5

4.51E4

45100

G4.2

51-3

.00051

E8.3

7.1bEb5

710000

D9.4

bbb45E+35

.0045 x 1035

BZ, F6.1

-54E3b

-5.4 x 1030

 

Real edit descriptors on output

The output field for the real descriptors consists of w character positions, filled with leading blanks (if necessary) and an optionally signed real constant with a decimal point, rounded to d digits after the decimal point. The following sections describe the real edit descriptors on output in detail.

D and E edit descriptors

The D and E edit descriptors define a normalized floating-point field for real and complex values. The value is rounded to d digits. The exponent part consists of e digits. If Ee is omitted in a D or E edit descriptor, then the exponent occupies two or three positions, depending on its magnitude. The field width, w, should follow the general rule: w is greater than or equal to d+7. If Ee is used, w is greater than or equal to d+e+5. This rule provides positions for a leading blank, the sign of the value, the decimal point, d digits, the exponent letter (D, E, or Q), the sign of the exponent, and the exponent. The Ee, De, and Qe specifications, which are available with the E edit descriptor, control which exponent letter is output.

Table 9-11 “D and E edit descriptors: output examples” provides examples of the E and D edit descriptors on output.

Table 9-11 D and E edit descriptors: output examples

Descriptor

Internal value

Output

D10.3

+12.342

b0.123D+02

E10.3E3

-12.3454

-.123E+002

E12.4

+12.34

bb0.1234E+02

D12.4

-.00456532

b-0.4565D-02

D10.10

+99.99913

**********

E11.5

+999.997

0.10000E+04

E10.3E4

+.624 x 10-30

.624E-0030

 

EN and ES edit descriptors

The EN and ES descriptors format floating-point values, using engineering and scientific notation, respectively. They are similar in form to the E descriptor, except:

  • The field produced by the EN descriptor has an exponent that is divisible by 3 and a significand that is in the range 1 to 999.

  • The field produced by the ES descriptor has one digit before the decimal point.

Table 9-12 “EN and ES edit descriptors: output examples” provides examples of the EN and ES edit descriptors on output.

Table 9-12 EN and ES edit descriptors: output examples

Descriptor

Internal value

Output

EN12.3

+3.141

bbb3.141E+00

ES12.3

+3.141

bbb3.141E+00

EN12.3

+.00123

bbb1.230E-03

ES12.3

+.00123

bbb1.230E-03

EN12.3

-.7

-700.000E-03

ES12.3

-.7

bb-7.000E-01

EN12.3

+1234.5

bbb1.235E+03

ES12.3

+1234.5

bbb1.235E+03

 

F edit descriptor

The F edit descriptor defines a field for real and complex values. The value is rounded to d digits to the right of the decimal point. The field width, w, should be four greater than the expected length of the number to provide positions for a leading blank, the sign, the decimal point, and a roll-over digit for rounding if needed.

Table 9-13 “F edit descriptor: output examples” provides examples of the F edit descriptor on output.

Table 9-13 F edit descriptor: output examples

Descriptor

Internal value

Output

F5.2

+10.567

10.57

F3.1

-254.2

***

F6.3

+5.66791432

b5.668

F8.2

+999.997

b1000.00

F8.2

-999.998

-1000.00

F7.2

-999.997

*******

F4.1

+23

23.0

 

G edit descriptor

The G edit descriptor can be used with any data type but is commonly used to define a field for real and complex values.

When used to specify I/O fields for integer, character, and logical data, the G edit descriptor has the same syntax and same effect as the integer, character, and logical edit descriptors. The d and e values (if specified) have no effect.

According to the magnitude of the data, the G edit descriptor is interpreted as either an E or F descriptor. (For more information on these edit descriptors, refer to “D and E edit descriptors” and “F edit descriptor”.) The E edit descriptor is used when one of the following conditions is true:

  • The magnitude is less than 0.1 but not zero.

  • The magnitude is greater than or equal to 10**d (after rounding to d digits).

If the magnitude does not fit either of these rules, the F edit descriptor is used. When F is used, the field width is reduced by either 4 when Gw.d is specified, or by e+2 when Gw.dEe is specified. It is then followed by a number of trailing spaces equal to the number that the field width was reduced by. Finally, d is modified internally according to the new field width.

For fixed- or floating-point format descriptors, the field width is w. The value is rounded to d digits, and the exponent consists of e digits. If Ee is omitted, the exponent occupies two positions. If Ee is omitted and the exponent is greater than 99 (that is, it requires three digits), the exponent letter is dropped from the output. The field width, w, should follow the general rule: w is greater than or equal to the sum of d+7; or, if Ee is specified, w is greater than or equal to the sum of d+e+5. This rule provides positions for a leading blank, the sign of the value, d digits, the decimal point, and, if needed, the exponent letter (D, E, or Q), the sign of the exponent, and the exponent. Note that the Ee, De, and Qe specifications control which exponent letter is output.

Table 9-14 “G edit descriptor: output examples” provides examples of the G edit descriptor on output.

Table 9-14 G edit descriptor: output examples

Descriptor

Internal value

Interpretation

Output

G10.3

+1234.0

E10.3

b0.123E+04

G10.3

-1234.0

E10.3

-0.123E+04

G12.4

+12345.0

E12.4

bb0.1235E+05

G12.4

+9999.0

F8.0, 4X

bbb9999.bbbb

G12.4

-999.0

F8.1, 4X

bb-999.0bbbb

G7.1

+.09

E7.1

0.9E-01

G5.1

-.09

E5.1

*****

G11.1

+9999.0

E11.1

bbbb0.1E+05

G8.2

+9999.0

E8.2

0.10E+05

G7.2

-999.0

E7.2

*******

G8.2

.trueL8

bbbbbbbT

G7.2

-999.0

E7.2

bbbb1234

 

Q edit descriptor

The Q edit descriptor (an HP extension) has the same effect as the E edit descriptor on output, except that it outputs a Q for the exponent instead of an E.

The Q edit descriptor can also be used to determine the number of bytes remaining to be read in an input record; see “Q (bytes remaining) edit descriptor”.

H (Hollerith) edit descriptor

The H edit descriptor outputs a specified number of characters. The syntax is:

nHcharacter-sequence

where:

n

is a positive integer that specifies the number of characters to output. This number must exactly match the actual number of characters in character-sequence.

character-sequence

is the string of representable characters (including blanks) to output.

Table 9-15 “H edit descriptor: output examples” provides examples of the Hollerith edit descriptor on output.

Table 9-15 H edit descriptor: output examples

Descriptor

Field width

Output

12HbbbSpacesbbb

12

bbbSpacesbbb

14H”Itbisn'tbso.”

14

”Itbisn'tbso.”

 

I (Integer) edit descriptor

The I edit descriptor defines a field for an integer number. As an HP extension, it can also be used on real and logical data. The corresponding I/O list item must be a numeric or logical type.

The syntax of the integer edit descriptor is:

[rI][w[.m]]

where:

r

is a positive integer constant, specifying the repeat factor.

w

is a positive integer constant, specifying the field width.

m

is a nonnegative integer constant, specifying the minimum number of digits that must be in the field and forcing leading zeroes as necessary up to the first nonzero digit. The m value is ignored on input. If m is not specified, a default value of 1 is assumed. If m is larger than w, the field is filled with w asterisks. If m = 0 and the list item is zero, only blanks are output.

Input

The integer edit descriptor causes the interpretation of the next w positions of the input record. The number is converted to match the type of the list item currently using the descriptor. A plus sign is optional for positive values. A decimal point must not appear in the field.

Table 9-16 “I edit descriptor: input examples” provides examples of the integer edit descriptor on input.

Table 9-16 I edit descriptor: input examples

Descriptor

Input field

Value stored

I4

b1bb

1

I5

bbbbb

0

I5

bbbbb1

0

I2

-1

-1

I4

-123

-123

I3

b12

12

I3

12b

12

I3

12b

120

I3

1.1

error: illegal character

 

Output

The integer edit descriptor outputs a numeric variable as a right-justified integer value (truncated, if necessary). The field width, w, should be one greater than the expected number of digits to allow a position for a minus sign for negative values. If m is set to 0, a zero value is output as all blanks.

Table 9-17 “I edit descriptor: output examples” provides examples of the integer edit descriptor on output.

Table 9-17 I edit descriptor: output examples

Descriptor

Internal value

Output

I4

+452.25

b452

I2

+6234

**

I3

-11.92

-11

I5

-52

bb-52

I10

123456.5

bbbb123456

I6.3

3

bbb003

I3.0

0

bbb

I3

0

bb0

 

L (Logical) edit descriptor

The L edit descriptor defines a field for logical data. Its syntax is:

[r]L[w]

where:

r

is a positive integer constant, specifying the repeat factor.

w

is a positive integer constant, specifying the field width.

The I/O list item corresponding to an L edit descriptor must be of type logical, short logical, or byte.

Input

The field width is scanned for optional blanks followed by an optional decimal point, followed by T (or t) for true or F (or f) for false. The first nonblank character in the input field (excluding the optional decimal point) determines the value to be stored in the declared logical variable. It is an error if the first nonblank character is not T, t, F, f, or a period(.).

Table 9-18 “L edit descriptor: input examples” provides examples of the logical edit descriptor on input.

Table 9-18 L edit descriptor: input examples

Descriptor

Input field

Value dtored

L1

T

.TRUE.

L1

f

.FALSE.

L6

.TRUE.

.TRUE.

L7

.false.

.FALSE.

L2

.t

.TRUE.

L8

bbbbTRUE

.TRUE.

L3

ABC

error: illegal character

 

Output

The character T or F is right-justified in the output field, depending on whether the value of the list item is true or false. Table 9-19 “L edit descriptor: output examples” provides examples of the logical edit descriptor on output.

Table 9-19 L edit descriptor: output examples

Descriptor

Internal value

Output (logical)

L5

false

bbbbF

L4

true

bbbT

L1

true

T

 

M and N edit descriptors

Edit descriptors M and N are used to output numeric values in formats normally used for currency.

For example, the N edit descriptor will output a value 1234.5 in the format 1,234.50; the M edit descriptor will cause this same value to be output at $1,234.50.

O (Octal) edit descriptor

The O edit descriptor defines a field for octal data. It provides conversion between an external octal number and its internal representation.

The syntax for the octal edit descriptor is:

[r]O[w[.m]]

where:

r

is a positive integer constant, specifying the repeat factor.

w

is a positive integer constant, specifying the field width.

m

is a nonnegative integer constant, specifying the minimum number of digits that must be in the field and forcing leading zeroes as necessary up to the first nonzero digit. The m value is ignored on input. If m is not specified, a default value of 1 is assumed. If m is larger than w, the field is filled with w asterisks.

Input

The presence of too many digits for the integer variable (or list item) to receive produces undefined results. Legal octal digits are 0 through 7. Plus and minus signs are illegal.

Table 9-20 “O edit descriptor: input examples” provides examples of the octal edit descriptors on input.

Table 9-20 O edit descriptor: input examples

Descriptor

Input field (octal)

Value stored (octal)

O8

12345670

12345670

O2

77

77

O3

064

64

O8

45r

error: illegal character

 

Output

List items may be of any type, though character variables are output only as the octal equivalent of their ASCII representation (no length descriptor).

If w is greater than the number of converted octal digits (including blanks between words but excluding leading zeroes), the octal digits are right-justified in the output field. If w is less than the number of converted octal digits, the field is filled with asterisks. This primarily affects the output of negative values. Because negative values are output in twos complement form, their high-order bits are nonzero and cause the field to be filled with asterisks when w is less than the number of octal digits in the entire output value. If m is set to 0, a zero value is output as all blanks.

Table 9-21 “O edit descriptor: output examples” provides examples of the octal edit descriptors on output.

Table 9-21 O edit descriptor: output examples

Descriptor

Internal value

Output (Octal)

O6

80

bbb120

O2

80

**

O14

-9

bbb37777777767

O11

32767

bbbbbb77777

O6.4

79

bb0117

O12

1.1

bb7743146315

O12

'A'

b101

O12

'ABC'

b101b102b103

 

P (scale factor) edit descriptor

The kP edit descriptor causes a scale factor of k to be applied to all subsequent F, D, E, EN, ES, and G edit descriptors in the format specification.

If the P edit descriptor does not precede an F, D, E, EN, ES, or G edit descriptor, it should be separated from other edit descriptors by a comma. If the P edit descriptor immediately precedes an F, D, E, EN, ES, or G edit descriptor, the comma is optional.

For example, the format specification

(3P, I2, F4.1, E5.2)

is equivalent to

(I2, 3PF4.1, E5.2)

When a format specification is interpreted, the scale factor is initially set to 0. When a P edit descriptor is encountered, the specified scale factor takes effect for the format specification and remains in effect until another P edit descriptor is encountered.

The effect of the scale factor differs for input and output as follows:

Input

If the value in the input field does not have an exponent, the internal number is equal to the field value multiplied by 10-k. If the value in the input field has an exponent, the scale factor has no effect. See Table 9-22 “P edit descriptor: input and output examples” for examples of the scale factor on input.

Output

The scale factor has no effect on the EN, ES, F and G (interpreted as F) edit descriptors. For the D, E, and G (interpreted as E) edit descriptors, the value of the list item is multiplied by 10k as it is output but the exponent part is decreased by k.

The value specified for the scale factor (k) must be in the range:

-d < k < (d + 2)

where:

d

is the number of digits in the fractional part of the number being written.

k

is a signed integer that specifies the scale factor.

Table 9-22 “P edit descriptor: input and output examples” provides examples of the scale factor on output.

Table 9-22 P edit descriptor: input and output examples

Format specification

Input field

Internal value

Output

(-2PG15.5)

1.97E-4

1.97 x 10-4

bbbbb.00197E-01

(2P, F15.5)

27.982

.2798199

bbbbbbb27.98200

(2P,ES15.5)

3518.

35.18

bbbb3.51800E+01

(-2P,EN15.5)

7.91E+5

7.91 x 105

bb791.00000E+03

(-2PE15.5)

.17694

17.694

bbbbb.00177E+04

 

When part or all of a format specification is repeated, the current scale factor is not changed until another scale factor is encountered.

Q (bytes remaining) edit descriptor

The Q edit descriptor is an HP extension that returns the number of bytes remaining to be read in the input record, placing the result into the corresponding integer variable in the I/O list. The return value can be used to control the remaining input items.

The Q edit descriptor is valid on input only; it is ignored on output. It can be used for reading formatted, sequential, and direct-access files. The following program segment reads variable-length strings from a sequential file:

CHARACTER(LEN=80) :: string
INTEGER :: n, i
...
READ (11,'(Q,80A1)') n, (string (i:i), i=1, n)

For information about the Qw.d edit descriptor for editing real data, see “D, E, EN, ES, F, G, and Q (real) edit descriptors”.

S, SP, and SS (plus sign) edit descriptors

The S, SP, and SS edit descriptors control printing of the plus sign character in numeric output. The default behavior of HP Fortran is not to print the plus sign. However, an SP edit descriptor in the format specification causes the plus sign to appear in any subsequent numeric output where the value is positive. The SS descriptor suppresses the plus sign in subsequent numeric output. The S edit descriptor restores the default behavior.

The sign edit descriptors have no effect on input.

T, TL, TR, and X (tab) edit descriptors

The tab edit descriptors position the cursor on the input or output record. Their syntax is:

Tn
TLn
TRn
nX

where:

n

is a positive integer constant, specifying the number of column positions to skip for positioning within the current output or input record.

The T edit descriptor references an absolute column number, while the descriptors TL and TR reference a relative number of column positions to the left (TL) or right (TR) of the current cursor position. Note that the TR descriptor is identical to the X edit descriptor.

Z (hexadecimal) edit descriptor

The Z edit descriptor defines a field for hexadecimal data. This descriptor provides for conversion between an external hexadecimal number and its internal representation.

The syntax for the hexadecimal edit descriptor is:

[r ]Z[w [.m ]]

where:

r

is a positive integer constant, specifying the repeat factor.

w

is a positive integer constant, specifying the field width.

m

is a nonnegative integer constant, specifying the minimum number of digits that must be in the field and forcing leading zeroes as necessary up to the first nonzero digit. The m value is ignored on input. If m is not specified, a default value of 1 is assumed. If m is larger than w, the field is filled with w asterisks.

Input

Variables to receive hexadecimal input must be of type integer. Legal hexadecimal digits are 0 through 9, and A through F (or a through f). Nonleading blanks are ignored, unless the file is opened with BLANK='ZERO'. If the file is opened with BLANK='ZERO', nonleading blanks are treated as zeroes. For more information about the BLANK= specifier see OPEN. Plus and minus signs, commas, or any other symbols are neither permitted on input nor printed on output. The presence of too many digits for the integer variable (or list item) produces undefined results.

Table 9-23 “Z edit descriptor: input examples” provides examples of the hexadecimal edit descriptor on input.

Table 9-23 Z edit descriptor: input examples

Descriptor

Input field (hexadecimal)

Value stored (hexadecimal)

Z4

FF3B

FF3B

Z4

fFfF

FFFF

Z2

ABCD

AB

Z3

1.1

error: illegal character

 

Output

List items may be of any type, though character variables are output only as the hexadecimal equivalent of their ASCII representation (without a length descriptor). If w is greater than the number of converted hexadecimal digits (excluding leading zeroes), the hexadecimal digits are right-justified in the output field. If w is less than the number of converted hexadecimal digits, the field is filled with asterisks. This primarily affects the output of negative values. Because negative values are output in twos complement form, their high-order bits are nonzero and cause the field to be filled with asterisks when w is less than the number of hexadecimal digits in the entire output value. If m is set to 0, a zero value is output as all blanks.

The field width required to fully represent the hexadecimal value of an item is twice its size in bytes. For example, a CHARACTER*12 item would require a field width of 24 characters.

Table 9-24 “Z edit descriptor: output examples” provides examples of the hexadecimal edit descriptor on output.

Table 9-24 Z edit descriptor: output examples

Descriptor

Internal value

Output

Z2

27

1B

Z6.4

27

bb001B

Z

'A'

b41

Z8

'ABCD'

41424344

Z8

1.1

3F8CCCCD

 

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© Hewlett-Packard Development Company, L.P.