180. ALLOCATE with SOURCE or MOLD to set values or SHAPE.#
topic: Allocation
Note
This tip is a draft1.
Some forms of ALLOCATE are
allocate (y(2)) ! y undefined allocate (y(2),source=0.0) ! fill with zeros allocate (y(2),source=[3.0,4.0]) ! fill with [3.0,4.0] allocate (y,mold=x) ! get shape from x allocate (y,source=x) ! get shape and values from x
Some forms of ALLOCATE are
— FortranTip (@fortrantip) April 7, 2022
allocate (y(2)) ! y undefined
allocate (y(2),source=0.0) ! fill with zeros
allocate (y(2),source=[3.0,4.0]) ! fill with [3.0,4.0]
allocate (y,mold=x) ! get shape from x
allocate (y,source=x) ! get shape and values from x pic.twitter.com/n4fKcZUdXA
- 1
From the perspective of FortranTip Browser, “draft” means that it hasn’t been edited for formatting, hasn’t had corresponding Fortran programs added, the text content hasn’t been enhanced, etc. Draft texts are extracted from the corresponding Tweet using the Twitter API.