02.07.2013 Views

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Expressions and assignment<br />

Assignment<br />

Table 5-5 Conversion of variable=expression (Continued)<br />

Variable<br />

type<br />

Logical Logical LOGICAL(expression, KIND(variable))<br />

Derived type Same derived type None<br />

As described in “Bitwise operators” on page 87, <strong>HP</strong> <strong>Fortran</strong> allows integer and logical<br />

operands to be used interchangeably. <strong>HP</strong> <strong>Fortran</strong> also allows logical expressions to be<br />

assigned to integer variables and integer expressions to logical variables. As shown in<br />

Table 5-5, a logical expression may also be assigned to real or complex variables, and<br />

similarly, a real or complex expression may be assigned to a logical variable.<br />

If variable is a scalar, expression must be scalar. If variable is an array or an array<br />

section, expression must be either an array-valued expression of the same shape or a scalar.<br />

If variable is an array or an array section, and expression is a scalar, the value of<br />

expression is assigned to all elements of variable. Ifvariable and expression are both<br />

arrays, the assignment is carried out element by element with no implied ordering.<br />

The expression is evaluated completely before the assignment is started. For example, the<br />

following code segment:<br />

CHARACTER (LEN=4):: c<br />

c(1:4) = 'abcd'<br />

c(2:4) = c(1:3)<br />

sets c(2:4) to "abc", notto"aaa", which might result from a left-to-right<br />

character-by-character assignment.<br />

The following examples illustrate assignments of different data types:<br />

! declarations of the variables used in the assignment statements<br />

! to follow<br />

integer icnt<br />

type circle<br />

real radius<br />

real xreal y<br />

end type<br />

type (circle) circle1, circle2<br />

real area, pi<br />

logical boolx, booly, pixel(10,10)<br />

integer a(10,5)<br />

integer, dimension (10,10):: matrix1, matrix2<br />

character*3 initials<br />

character*10 surname<br />

character*20 name<br />

96<br />

Expression type Conversion<br />

Chapter 5

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

Saved successfully!

Ooh no, something went wrong!