MOVE_ALLOC intrinsic subroutine

Standard: F77 F90 F95 F2003 F2008 F2018 Example program


<Syntax>

Call MOVE_ALLOC ( FROM, TO [ , STAT, ERRMSG ] )

FROM : allocatable variable of any type and rank (including scalar), Intent(InOut);
TO : allocatable variable with the same type, rank and corank as FROM, Intent(Out);
STAT : scalar Integer variable, Intent(Out);
ERRMSG : scalar Character variable with default kind, Intent(InOut).

FROM and TO must either both be non-polymorphic or both polymorphic, and must have the same set of deferred type parameters. Any non-deferred type parameters must have the same value.

STAT must be able to represent the values −9999 to 9999 (i.e. 16 bits or larger). Both STAT and ERRMSG must not be coindexed (have an image selector).

<Semantics>

This moves the allocation status (allocated/unallocated, bounds, deferred type parameter values, and value) of FROM to TO; if TO was allocated, it will be deallocated before the move; after the move, FROM will be unallocated.

If both FROM and TO have the TARGET attribute, any pointers that were associated with any part of FROM will be associated with the corresponding part of TO after the move. If only FROM has the TARGET attribute, any pointers associated with any part of it will be undefined after the move.

This subroutine can be used to expand the size of an allocatable array with the minimum number of copies, by first allocating a new array with the required size, copying the values to the required place, then moving the new allocation to the old variable.

If STAT is present it is assigned the value zero unless an error condition occurs. If ERRMSG is present and an error condition occurs, it is assigned an explanatory message; if no error condition occurs, ERRMSG remains unchanged. If any error condition occurs and STAT is not present, the program will be terminated. No error condition is expected to occur when FROM and TO are normal variables. If FROM and TO are coarrays, and an image in the current team has stopped or failed, an error condition will occur.

<Related>

ALLOCATABLE attribute, ALLOCATE statement, ALLOCATED intrinsic function, DEALLOCATE statement