Bertrand Meltz wrote:
> Anybody has an idea how I can combine the convenience of a derived
> type, with the convenience of an array?
That is a very complex question.
First, what exactly do you mean by convenience of a derived type? The
fact that you can say:
variables(nx,ny,nz)%vx
instead of
variables(nx,ny,nz)%r(vx_var)
?
If that is all you want, I recommend using a preprocessor which supports
macros. Yes, this would be non-Fortran. For example:
@m _vx(nx,ny,nz)=variables(nx,ny,nz)%r(4)
If you want more, than the issue becomes entangled. I use a combination
of methods:
1) I organize the variables in a derived type, say
type :: point
real :: x,y,z
endtype
(I personally never use x,y,z but rather an array of 3 elements, but
this may be style...I work in multiple dimensions)
2) I make macros to access these with minimal typing and most clarity,
sometimes I define as many as 4 macros for different types of uses.
3) I make array pointers which point to these variables so that I can
use them as an array. Something like:
real, pointer :: x(:,:,:)
x=>variables(:,:,:)%x
The problem occurs when you want to make a rank-4 array with all the
coordinates, x,y and z. This cannot really be done legally in Fortran
at present, and I use C hacks to do it, and the committee has resisted
for reasons I will not go into adding this into the language...
Best,
Aleksandar
|