HP Fortran Programmer's Reference (September 2007)

Expressions and assignment
Assignment
Chapter 498
As described in “Bitwise operators” on page 89, HP Fortran allows integer and logical
operands to be used interchangeably. HP Fortran also allows logical expressions to be
assigned to integer variables and integer expressions to logical variables. As shown in
Table 4-5, a logical expression may also be assigned to real or complex variables, and
similarly, a real or complex expression may be assigned to a logical variable.
If
variable
is a scalar,
expression
must be scalar. If
variable
is an array or an array
section,
expression
must be either an array-valued expression of the same shape or a scalar.
If
variable
is an array or an array section, and
expression
is a scalar, the value of
expression
is assigned to all elements of
variable
. If
variable
and
expression
are both
arrays, the assignment is carried out element by element with no implied ordering.
The
expression
is evaluated completely before the assignment is started. For example, the
following code segment:
CHARACTER (LEN=4):: c
c(1:4) = 'abcd'
c(2:4) = c(1:3)
sets c(2:4) to "abc", not to "aaa", which might result from a left-to-right
character-by-character assignment.
The following examples illustrate assignments of different data types:
! declarations of the variables used in the assignment statements
! to follow
integer icnt
type circle
real radius
real xreal y
end type
type (circle) circle1, circle2
real area, pi
logical boolx, booly, pixel(10,10)
integer a(10,5)
integer, dimension (10,10):: matrix1, matrix2
character*3 initials
character*10 surname
character*20 name
Logical Logical
LOGICAL(
expression
, KIND(
variable
))
Derived type Same derived type None
Table 4-5 Conversion of
variable
=
expression
(Continued)
Variable
type
Expression type Conversion