# Assumed-rank arrays

**URL:** <https://fortran-lang.discourse.group/t/assumed-rank-arrays/1049>\
**Category:** Uncategorized\
**Created:** [April 11, 2021, 10:56pm UTC](https://fortran-lang.discourse.group/t/assumed-rank-arrays/1049 "2021-04-11T22:56:03Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![FortranFan](https://avatars.discourse-cdn.com/v4/letter/f/96bed5/32.png) [@FortranFan](https://fortran-lang.discourse.group/u/FortranFan)\
**Post date:** [April 19, 2021, 12:52am UTC](https://fortran-lang.discourse.group/t/assumed-rank-arrays/1049/7 "2021-04-19T00:52:38Z")

</div>

> [@Beliavsky](#):
>
> … Intel says
> 
> ```auto
> flatten.f90(5): error #7617: This host associated object appears in a 'defining' context in a PURE procedure or in an internal procedure contained in a PURE procedure. [Y]
> rank(1) ; y = reshape(x,shape=[size(x)])
> 
> ```

It’s a bug in Intel Fortran.

In the meantime, a workaround can be a `subroutine` option and which may be advantageous in certain circumstances:

```Fortran
module m
contains
   pure subroutine flatten(x, y)
       real, intent(in) :: x(..)
       real, intent(inout) :: y(size(x))
       select rank(x)
         rank(1) ; y = reshape(x,shape=[size(x)])
         rank(2) ; y = reshape(x,shape=[size(x)])
       end select
   end subroutine
   pure subroutine flatten2(x, y)
       real, intent(in) :: x(..)
       real, intent(out), allocatable :: y(:)
       select rank(x)
         rank(1) ; y = reshape(x+1.0,shape=[size(x)])
         rank(2) ; y = reshape(x+1.0,shape=[size(x)])
       end select
     end subroutine
end module
   use m
   real :: a(2,3)
   real, allocatable :: b(:)
   a = 1.0
   call flatten2(a, b)
   print *, "size(b): ", size(b), "; expected is ", size(a)
   print *, "b(2*3): ", b(2*3), "; expected is ", a(2,3)+1.0
   call flatten(a, b)
   print *, "b(2*3): ", b(2*3), "; expected in ", a(2,3)
 end

```

> C:\temp\>ifort /standard-semantics r.f90  
> Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.2.0 Build 20210228\_000000  
> Copyright (C) 1985-2021 Intel Corporation. All rights reserved.
> 
> Microsoft (R) Incremental Linker Version 14.27.29112.0  
> Copyright (C) Microsoft Corporation. All rights reserved.
> 
> -out:r.exe  
> -subsystem:console  
> r.obj
> 
> C:\temp\>r.exe  
> size(b): 6 ; expected in 6  
> b(2_3): 2.000000 ; expected is 2.000000  
> b(2_3): 1.000000 ; expected is 1.000000
> 
> C:\temp\>

---

_[View the full topic](https://fortran-lang.discourse.group/t/assumed-rank-arrays/1049)._
