On Tue, Jan 5, 2010 at 8:33 AM, Greenberg, Naomi <ngreenberg@rri-
usa.org>wrote:
> 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).
Do you mean address it it this way in the same scope? The easiest and
most "efficient" way (no aliasing) is to pass this array to a
subroutine. The dummy array can have any shape desired and so you can
index as pleased.
If you want to do this in the same scope, then the best thing to do is
to use a two-dimensional array pointer buf2 that is pointed to the
storage of buf.
There are a few ways to do this and both Jim and Steve showed two ways
that require Fortran 2003 features (I recommend Jim's way but more
compilers are likely to implement C interop first). In Fortran 90 you
can also do it by calling a subroutine where the dummy is rank-2 but the
actual argument is buf, and point the pointer inside. You need the
TARGET attribute on both the dummy and buf.
Best,
Aleks
|