From: Raj on
Hi,

I would like to know the difference between the following statements
in fortran 90.

REAL, POINTER, DIMENSION (:,:) :: A
REAL, ALLOCATABLE, DIMENSION (:,:) :: A

I presume both are the same. But I just wanted to make it sure.

Thank you
Raj. R
From: Richard Maine on
Raj <raj6586(a)gmail.com> wrote:

> I would like to know the difference between the following statements
> in fortran 90.
>
> REAL, POINTER, DIMENSION (:,:) :: A
> REAL, ALLOCATABLE, DIMENSION (:,:) :: A
>
> I presume both are the same. But I just wanted to make it sure.

No, they are not at all the same. The short (and trivial) version is
that one declared the variable to be allocatable, while the other
declared it to be a pointer... but that probably doesn't help you much.

Allocatables and pointers do have some things in common - enough so that
you can sometimes use either one. In particular, both of them can be
dynamically allocated and deallocated. But it is a serious mistake to
think of them as the same; do that and you will go far wrong.

It would be impractical to give a complete list of the differences.
There are lots of them. The list of similarities is a lot shorter. When
you say that you can allocate and deallocate them using ALLOCATE and
DEALLOCATE statements, you are pretty much done with the major
simillarities. I won't even try to start on a list of the differences;
I'm not sure I've ever seen one. It would be somewhet like trying to
list the differences between real and integer type.

For the most part, if you have a choice, you should use allocatables
instead of using pointers. There are things for which you don't have a
choice, but then the question is moot in those cases.

Allocatables are for things that are dynamically allocated (usually
arrays, though f2003 introduces other possibilities). If you want to
dynamically allocate something, that's what you should use.

Pointers are for... well... pointing at things. Anyway, that's the
central concept. If you need to point at things, then you likely need
pointers; allocatables don't do that.

It is almost a side note that you happen to also be able to use pointers
to allocate dynamically sized arrays. But because that's not really what
pointers are about, you will find many aspects of the behavior of
pointers nonintuitive. They are greatly more prone to memory leaks and
other kinds of errors.

The main reason you wil see pointers used in place of allocatables in
some programs is that allocatables used to be so hobbled that you could
not use them in many contexts. Pointers were pressed into service as a
workaround. But it was just a workaround - one that had the above
mentioned problems of being nonintuitive and error prone. The hobbling
of allocatables should not be much of an issue with current compilers.

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
From: Dan on
On Nov 15, 2:54 pm, Raj <raj6...(a)gmail.com> wrote:
> Hi,
>
> I would like to know the difference between the following statements
> in fortran 90.
>
> REAL, POINTER, DIMENSION (:,:) :: A
> REAL, ALLOCATABLE, DIMENSION (:,:) :: A
>
> I presume both are the same.  But I just wanted to make it sure.
>
> Thank you
> Raj. R

Here are a couple links you might find helpful:

http://wwwasdoc.web.cern.ch/wwwasdoc/f90.html

http://wwwasdoc.web.cern.ch/wwwasdoc/WWW/f90/pointers.html

From: m_b_metcalf on
On Nov 17, 2:22 am, Dan <dant...(a)aol.com> wrote:
> On Nov 15, 2:54 pm, Raj <raj6...(a)gmail.com> wrote:
>
> > Hi,
>
> > I would like to know the difference between the following statements
> > in fortran 90.
>
> > REAL, POINTER, DIMENSION (:,:) :: A
> > REAL, ALLOCATABLE, DIMENSION (:,:) :: A
>
> > I presume both are the same.  But I just wanted to make it sure.
>
> > Thank you
> > Raj. R
>
> Here are a couple links you might find helpful:
>
> http://wwwasdoc.web.cern.ch/wwwasdoc/f90.html
>
> http://wwwasdoc.web.cern.ch/wwwasdoc/WWW/f90/pointers.html

IMNSHO, this is better: http://en.wikipedia.org/wiki/Fortran_language_features

Regards,

Mike Metcalf
From: Raj on
Thank you very much for your explanation. I understood it. But can I
store the values of pointer in a allocatable array and use it? Say, B
is defined as REAL, POINTER, DIMENSION (:,:) :: B and C is defined as
REAL, ALLOCATABLE, DIMENSION (:,:) :: C. Can I have two do loops in
which I assign values of C from B? (array B already has values).


On Nov 17, 1:18 am, m_b_metcalf <michaelmetc...(a)compuserve.com> wrote:
> On Nov 17, 2:22 am, Dan <dant...(a)aol.com> wrote:
>
>
>
>
>
> > On Nov 15, 2:54 pm, Raj <raj6...(a)gmail.com> wrote:
>
> > > Hi,
>
> > > I would like to know the difference between the following statements
> > > in fortran 90.
>
> > > REAL, POINTER, DIMENSION (:,:) :: A
> > > REAL, ALLOCATABLE, DIMENSION (:,:) :: A
>
> > > I presume both are the same.  But I just wanted to make it sure.
>
> > > Thank you
> > > Raj. R
>
> > Here are a couple links you might find helpful:
>
> >http://wwwasdoc.web.cern.ch/wwwasdoc/f90.html
>
> >http://wwwasdoc.web.cern.ch/wwwasdoc/WWW/f90/pointers.html
>
> IMNSHO, this is better:http://en.wikipedia.org/wiki/Fortran_language_features
>
> Regards,
>
> Mike Metcalf