Print

Print


Naomi,

You can use C interoperability features to do what you want.  The key is to declare a POINTER array of the desired new rank and then use C_LOC and C_F_POINTER to create the alias.  For example:

 use iso_c_binding
 real, pointer, dimension(:,:) :: buf2
 ...
 call c_f_pointer (c_loc(buf), buf2, [dim1,dim2])

where dim1 and dim2 are the desired dimensions of buf2 (total size should be the same as buf.)  Now buf2 is a rank 2 array that is the same storage as buf. 

You can do this with buf being either a static array as it is now (but you should add TARGET) or an ALLOCATABLE or POINTER array if you're going dynamic. Also add TARGET for ALLOCATABLE - POINTER gets TARGET implicitly.

Steve Lionel
Intel Developer Support
Nashua, NH




From: Fortran 90 List [mailto:[log in to unmask]] On Behalf Of Greenberg, Naomi
Sent: Tuesday, January 05, 2010 11:33 AM
To: [log in to unmask]
Subject: Replacing legacy EQUIVALENCE

I have a legacy code that statically allocates a very large 1-dimensional workspace array and then equivalences it to a 2-dimensional array of the same size because some subroutines require this workspace to be divided into 3 different parts.  I want to convert the array to be dynamically-allocated, but I still need a way to address it both as buf(i) and buf2(i,j).  Array reshaping seems to create a second array of a different shape, passing the values of the first array to the second.  I want them to share memory space.  Any suggestions would be helpful!