From: Richard Maine on 12 Nov 2009 11:14
Arjan <arjan.van.dijk(a)rivm.nl> wrote:
> > double precision :: A(nMax,nMax)
> > double precision :: x(nMax*nMax)
> > equivalence (A, x)
> > x = RESHAPE(A, /nMAX*nMAX/)
> It wouldn't save you the RAM, but I would use
> x = TRANSFER(A,x)
I wouldn't - not for this.
> With RESHAPE source and destination must be arrays of the same type,
> e.g. arrays of REAL(R4KIND).
But in the OP's case, the types (and kinds) do match. All that is
changing is the shape. It perfectly fits the definition of RESHAPE, so
why use something more esoteric?
> With TRANSFER only the size in BYTES must match.
If I recall, not even that has to match. The fact that transfer is
allowed for many more caes is one of the reasons why I would not use it.
That means that it is less likely to give you an error message if
something is wrong. I see no evidence that the OP has those esoteric
cases. Sure, one can take something like a simplee assignment
real :: x, y
x = y
and turn it into a TRANSFER. But I wouldn't.
I'd probably go more for the suggestion made by others of leaving it
alone if it isn't broken. The code is valid f90 (and f95, f2003, and
f2008 draft) It isn't obvious that it is broken. It probably isn't the
way I'd code something new, but I'd need more specifics to know what I
would do instead.
If I were coding something new or if there was some reason that the code
really needed to be changed. two other possibilities occur to me that
have not been otherwise mentioned.
The pointer remapping feature of f2003 is right up this line. I can't
tell without more data whether it fits perfectly, but it does seem
plausible. That does need f2003. Alternatively, you can do related
things with sequence argument association. That is valid with any
version of Fortran, but it requires that the use of one of the forms be
separated into a subroutine, which might or might not be practical for
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
From: Lorents on 20 Nov 2009 11:33
Richard Maine wrote:
> Arjan <arjan.van.dijk(a)rivm.nl> wrote:
>>> double precision :: A(nMax,nMax)
>>> double precision :: x(nMax*nMax)
>>> equivalence (A, x)
>>> x = RESHAPE(A, /nMAX*nMAX/)
>> It wouldn't save you the RAM, but I would use
> I'd probably go more for the suggestion made by others of leaving it
> alone if it isn't broken. The code is valid f90 (and f95, f2003, and
> f2008 draft) It isn't obvious that it is broken. It probably isn't the
> way I'd code something new, but I'd need more specifics to know what I
> would do instead.
Thank you all for your replies. The object in question is a scalar field
defined over three coordinates r1,r2 theta. In the program at hand it is
treated as a long array (this is because there is a symmetry in r1/r2
which allows to neglect half of the element on the r1/r2 plane). I have
to manipulate the elements in a certain way and so I need to convert
from the single vector index to three indexes, and then back to a single
vector. Creating a three-index array is not strictly indispensable as I
could write whenever necessary three expressions which given the vector
index give back (say) ir1,ir2,itheta (knowing r1MAX, etc.), but it's
just simpler to use an object which has the same structure as the data.
First | Prev |
Pages: 1 2
Next: Can teh backend processing for a sophisticated Website be written in Fortran?