Malcolm Cohen wrote:
>
> Jan Mandel said:
> >A subroutine is given an array to be used for work area and
> >no direct allocations are allowed, or it is required by the software
> >environment that I allocate memory by call to a routine that returns an
> >index into a COMMON. If the compiler supports Cray pointers, one can
> >map such index to pointer, like in
> >
> > COMMON /double_common/w(size_w)
> > POINTER (p,my_array(1000))
> > ....
> >c to allocate array size 1000
> > ix = my_allocate(1000,2)
> > p=loc(w(ix))
> >
> >and then work with my_array, achieving essentially the
> >effect of ALLOCATE. This is a very common scheme in
> [...]
> >Does anyone know an intelligent portable way of doing this in standard
> >conforming Fortran 90? I was very disappointed when
>
> There is a very straightforward translation of the above into F90: just add
> the TARGET attribute to "w" and use pointer assignment for p: e.g.
>
> COMMON /double_common/w(size_w)
> DOUBLE PRECISION,TARGET :: w
> DOUBLE PRECISION,POINTER :: p(:)
> ....
> c to allocate array size 1000
> ix = my_allocate(1000,2)
> p => w(ix:ix+999)
>
> Alternatively you could wrap up the allocation stuff in a module, e.g.
>
> MODULE my_allocations
> ... private definition of size_w
> CONTAINS
> FUNCTION allocate_double(n)
> DOUBLE PRECISION,SAVE :: w(size_w)
> DOUBLE PRECISION,POINTER :: allocate_double(:)
> ... determine ix ...
> allocate_double => w(ix:ix+n-1)
> END FUNCTION
> ... other functions such as allocate_single, allocate_integer ? ...
> END
>
> to use:
>
> DOUBLE PRECISION,POINTER :: p(:)
> ...
> p => allocate_double(1000)
>
Do you have a similar solution to "allocate" 2D arrays?
Pierre
--
+-----------------------------------+----------------------------+
| Pierre Hugonnet | mail....CGG |
| | 1, rue Leon Migaux |
| Seismic Data Processing R&D | 91341 MASSY cedex |
| | FRANCE |
| COMPAGNIE GENERALE DE GEOPHYSIQUE | phone...(33) 164 47 45 59 |
| Massy processing centre (France) | fax.....(33) 164 47 32 49 |
| http://www.cgg.com | [log in to unmask] |
+-----------------------------------+----------------------------+
My opinions are not necessarily those of CGG
--------------------------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|