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.

STRUCTURE /foo_bar/<br />

REAL, DIMENSION(30, 50) :: bar<br />

END STRUCTURE<br />

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

STRUCTURE (extension)<br />

The array’s dimensions must in any case appear in the type statement. The DIMENSION<br />

statement (but not the DIMENSION attribute) is illegal in a structure definition. The following<br />

code defines the structure, string, which uses a type declaration statement to define an array<br />

field str of type CHARACTER(LEN=1), containing 254 elements:<br />

STRUCTURE /string/<br />

CHARACTER(LEN=1) :: str(254)! Contains string<br />

INTEGER :: length ! string’s length<br />

END STRUCTURE<br />

As mentioned, the DIMENSION statement cannot be used in a structure definition. For<br />

example, the following code would cause a compile-time error:<br />

STRUCTURE /real_array/<br />

REAL :: rarray<br />

DIMENSION arr(100) ! illegal example<br />

END STRUCTURE<br />

A correct way to code this would be:<br />

STRUCTURE /real_array/<br />

REAL :: rarray(100)<br />

END STRUCTURE<br />

or<br />

STRUCTURE /real_array/<br />

REAL, DIMENSION(100) :: arr<br />

END STRUCTURE<br />

Assumed-size and adjustable arrays are also illegal in structure definitions. For example, the<br />

following is illegal:<br />

STRUCTURE /assumed_size/ ! illegal example<br />

CHARACTER*(*) :: carray<br />

END STRUCTURE<br />

The following is also illegal:<br />

STRUCTURE /adj_array/ ! illegal example<br />

INTEGER :: size<br />

REAL :: iarray(size)<br />

END STRUCTURE<br />

For alignment purposes, <strong>HP</strong> <strong>Fortran</strong> provides the %FILL field name. It enables the<br />

programmer to pad a record to ensure proper alignment. The padding does not have a name<br />

and is therefore not accessible. For example, the following structure, sixbytes, createsa<br />

6-byte structure, of which 4 bytes are inaccessible filler bytes:<br />

Chapter 10 433

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

Saved successfully!

Ooh no, something went wrong!