## 10.4 Data usage and computation [mostly 5.3]

• In a structure constructor, the value for an allocatable component may be omitted: this has the same effect as specifying NULL().
• [6.0] When allocating an array with the ALLOCATE statement, if SOURCE= or MOLD= is present and its expression is an array, the array can take its shape directly from the expression. This is a lot more concise than using SIZE or UBOUND, especially for a multi-dimensional array.

For example,

```   SUBROUTINE s(x,mask)
REAL x(:,:,:)
REAL,ALLOCATABLE :: y(:,:,:)
ALLOCATE(y,MOLD=x)
y = 1/x
ELSEWHERE
y = HUGE(x)
END WHERE
! ...
END SUBROUTINE
```
• [6.2] An ALLOCATE statement with the SOURCE= clause is permitted to have more than one allocation. The source-expr is assigned to every variable allocated in the statement. For example,
```   PROGRAM multi_alloc
INTEGER,ALLOCATABLE :: x(:),y(:,:)
ALLOCATE(x(3),y(2,4),SOURCE=42)
PRINT *,x,y
END PROGRAM
```
will print the value “42” eleven times (the three elements of x and the eight elements of y). If the source-expr is an array, every allocation needs to have the same shape.
• [6.1] The real and imaginary parts of a COMPLEX object can be accessed using the complex part designators ‘%RE’ and ‘%IM’. For example, given
```   COMPLEX,PARAMETER :: c = (1,2), ca(2) = [ (3,4),(5,6) ]
```
the designators c%re and c%im have the values 1 and 2 respectively, and ca%re and ca%im are arrays with the values [ 3,5 ] and [ 4,6 ] respectively. In the case of variables, for example
```   COMPLEX :: v, va(10)
```
the real and imaginary parts can also be assigned to directly; the statement
```   va%im = 0
```
will set the imaginary part of each element of va to zero without affecting the real part.
• In an ALLOCATE statement for one or more variables, the MOLD= clause can be used to give the variable(s) the dynamic type and type parameters (and optionally shape) of an expression. The expression in MOLD= must be type-compatible with each allocate-object, and if the expression is a variable (e.g. MOLD=X), the variable need not be defined. Note that the MOLD= clause may appear even if the type, type parameters and shape of the variable(s) being allocated are not mutable. For example,
```   CLASS(*),POINTER :: a,b,c
ALLOCATE(a,b,c,MOLD=125)
```
will allocate the unlimited polymorphic pointers A, B and C to be of type Integer (with default kind); unlike SOURCE=, the values of A, B and C will be undefined.
• [5.3.1] Assignment to a polymorphic allocatable variable is permitted. If the variable has different dynamic type or type parameters, or if an array, a different shape, it is first deallocated. If it is unallocated (or is deallocated by step 1), it is then allocated to have the correct type and shape. It is then assigned the value of the expression. Note that the operaton of this feature is similar to the way that ALLOCATE(variable,SOURCE=expr) works. For example, given
```   CLASS(*),ALLOCATABLE :: x
```
execution of the assignment statement
```   x = 43
```
will result in X having dynamic type Integer (with default kind) and value 43, regardless of whether X was previously unallocated or allocated with any other type (or kind).
• [6.1] Rank-remapping pointer assignment is now permitted when the target has rank greater than one, provided it is “simply contiguous” (a term which means that it must be easily seen at compile-time to be contiguous). For example, the pointer assignment in
```   REAL,TARGET :: x(100,100)
REAL,POINTER :: x1(:)
x1(1:Size(x)) => x
```
establishes X1 as a single-dimensional alias for the whole of X.