02.07.2013 Views

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

FORMAT<br />

DescribeshowI/Odataistobeformatted.<br />

Syntax<br />

label FORMAT (format-list)<br />

label is a statement label.<br />

<strong>HP</strong> <strong>Fortran</strong> statements<br />

FORMAT<br />

format-list is a comma-separated list of format items, where each item in the list can be<br />

either one of the edit descriptors described in Table 9-1 or (format-list). If<br />

format-list is a list item, it may be optionally preceded by a repeat<br />

specification—a positive integer that specifies how may times format-list<br />

is to be repeated.<br />

Description<br />

The FORMAT statement holds the format specification that indicates how data in formatted I/O<br />

is to be translated between internal (binary) representation and formatted (ASCII)<br />

representation. The translation makes it possible to represent data in a humanly readable<br />

format.<br />

Although a format specification can be embedded within a data transfer statement, the point<br />

to using a FORMAT statement is to make it available to any number of data transfer<br />

statements. Several data transfer statements can use the same format specification contained<br />

in a FORMAT statement by referencing label.<br />

Another advantage of the FORMAT statement over the use of embedded format specifications is<br />

that it is ”pre-compiled”, reducing the runtime overhead of processing the format specification<br />

and providing compile-time error checking of the FMT= specifier.<br />

Examples<br />

PROGRAM format_example<br />

WRITE (15,FMT=20) 1234, 45, -12<br />

20 FORMAT (I6, 2I4)<br />

END PROGRAM format_example<br />

When compiled and executed, this program outputs the following (where b represents the<br />

blank character):<br />

bb1234bb45b-12<br />

Chapter 10 327

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!