0

Is there a way I can declare an array which will be able to allocate any number of dimensions (in any shape) later in the code? Something like a the classic deferred shape but bearing in mind I do not know the rank, shape or size during declaration. For example, something similar to

real, allocatable :: a(:) 
integer, parameter :: sh = [4,2,2]

allocate(a(sh))

which does not throw an error (of course it does in this case).

b-fg
  • 3,959
  • 2
  • 28
  • 44
  • I think rank remapping of array pointers is pretty handy for this (allocate( a(16) ); p( 1:4, 1:4 ) => a, or q( 1:4, 1:2, 1:2 ) => a, where p and q are 2d and 3d array pointers) – roygvib Apr 08 '19 at 10:45
  • This actually useful, thanks. I have not seen this in the linked duplicates. @francescalus – b-fg Apr 08 '19 at 10:49

0 Answers0