Assigns the value of the expression to the variable. Arithmetic/Logical/Character assignment takes the form: v = e v Is the name of a scalar or array of intrinsic or derived type (with no defined assignment). The array cannot be an assumed-size array, and neither the scalar nor the array can be declared with the PARAMETER or INTENT(IN) attribute. e Is an expression of intrinsic type or the same derived type as "v". Its shape must conform with "v". If necessary, it is converted to the same kind type as "v". Before a value is assigned to the variable, the expression part of the assignment statement and any expressions within the variable are evaluated. No definition of expressions in the variable can affect or be affected by the evaluation of the expression part of the assignment statement. NOTE: When the run-time system assigns a value to a scalar integer or character variable and the variable is shorter than the value being assigned, the assigned value may be truncated and significant bits (or characters) lost. This truncation can occur without warning, and can cause the run-time system to pass incorrect information back to the program. If the variable is a pointer, it must be associated with a definable target. The shape of the target and expression must conform and their types and kind type parameters must match.
1 – Conversion Rules
The following tables summarize the conversion rules for assignment statements. Table 1: Conversion Rules for Integer, Logical, or Real Expressions +-------------+------------------------------------------------+ |Scalar | Expression (E) | |Memory |------------------------------------------------- |Reference (V)| integer, logical, or real | +-------------+------------------------------------------------+ | integer or | V=INT(E) | | logical | | +-------------+------------------------------------------------+ | REAL | V=REAL(E) | | (KIND=4) | | +-------------+------------------------------------------------+ | REAL | V=DBLE(E) | | (KIND=8) | | +-------------+------------------------------------------------+ | REAL | V=QEXT(E) | | (KIND=16) | | +-------------+------------------------------------------------+ | COMPLEX | V=CMPLX(REAL(E), 0.0) | | (KIND=4) | | +-------------+------------------------------------------------+ | COMPLEX | V=CMPLX(DBLE(E), 0.0) | | (KIND=8) | | +-------------+------------------------------------------------+ | COMPLEX | V=CMPLX(QEXT(E), 0.0) | | (KIND=16) | | +-------------+------------------------------------------------+ Table 2: Conversion Rules for Complex Expressions +-------------+------------------------------------------------+ |Scalar | Expression (E) | |Memory |------------------------------------------------- |Reference (V)| complex | +-------------+------------------------------------------------+ | integer or | V=INT(REAL(E)) | | logical | Imaginary part of E is not used. | +-------------+------------------------------------------------+ | REAL | V=REAL(REAL(E)) | | (KIND=4) | Imaginary part of E is not used. | +-------------+------------------------------------------------+ | REAL | V=DBLE(REAL(E)) | | (KIND=8) | Imaginary part of E is not used. | +-------------+------------------------------------------------+ | REAL | V=QEXT(REAL(E)) | | (KIND=16) | Imaginary part of E is not used. | +-------------+------------------------------------------------+ | COMPLEX | V=CMPLX(REAL(REAL(E)), REAL(AIMAG(E))) | | (KIND=4) | | +-------------+------------------------------------------------+ | COMPLEX | V=CMPLX(DBLE(REAL(E)), DBLE(AIMAG(E))) | | (KIND=8) | | +-------------+------------------------------------------------+ | COMPLEX | V=CMPLX(QEXT(REAL(E)), QEXT(AIMAG(E))) | | (KIND=16) | | +-------------+------------------------------------------------+