TRANSFER(SOURCE, MOLD, SIZE)

Purpose

Returns a result with a physical representation identical to that of SOURCE but interpreted with the type and type parameters of MOLD.

It performs a low-level conversion between types without any sign extension, rounding, blank padding, or other alteration that may occur using other methods of conversion.

Class

Transformational function

Argument type and attributes

SOURCE
The data entity whose bitwise value you want to transfer to a different type. It may be of any type, and may be a scalar or an array.
MOLD
A data entity that has the type characteristics you want for the result. If the actual argument corresponding to MOLD is a variable, the value does not need to be defined. The actual argument can be of any type, and can be a scalar or an array. Its value is not used, only its type characteristics are used.
SIZE (optional)
The number of elements for the output result. It must be a scalar integer. The corresponding actual argument must not be an optional dummy argument.

Result type and attributes

The same type and type parameters as MOLD.

If MOLD is a scalar and SIZE is absent, the result is a scalar.

If MOLD is array valued and SIZE is absent, the result is array valued and of rank one, with the smallest size that is physically large enough to hold SOURCE.

If SIZE is present, the result is array valued of rank one and size SIZE.

Result value

The physical representation of the result is the same as SOURCE, truncated if the result is smaller or with an undefined trailing portion if the result is larger.

Because the physical representation is unchanged, it is possible to undo the results of TRANSFER as long as the result is not truncated:
      REAL(4) X /3.141/
      DOUBLE PRECISION I, J(6) /1,2,3,4,5,6/

! Because x is transferred to a larger representation
! and then back, its value is unchanged.
      X = TRANSFER( TRANSFER( X, I ), X )

! j is transferred into a real(4) array large enough to
! hold all its elements, then back into an array of
! its original size, so its value is unchanged too.
      J = TRANSFER( TRANSFER( J, X ), J, SIZE=SIZE(J) )

Examples

TRANSFER (1082130432, 0.0) is 4.0.

TRANSFER ((/1.1,2.2,3.3/), (/(0.0,0.0)/)) is a complex rank-one array of length two whose first element has the value (1.1, 2.2) and whose second element has a real part with the value 3.3. The imaginary part of the second element is undefined.

TRANSFER ((/1.1,2.2,3.3/), (/(0.0,0.0)/), 1) has the value (/(1.1,2.2)/).