I am confused by the following example:
TYPE :: car
real :: x, u ! position, velocity
real :: y, v !
real :: z, w !
real,dimension(3) :: uvw_0 ! initial uvw
END TYPE
TYPE (car), pointer:: mercedes
TYPE (car), DIMENSION(m,n,q,r), TARGET :: mercedes_ay
It looks like an implementation of object, but what does
TYPE (car), DIMENSION(m,n,q,r), TARGET :: mercedes_ay
do with respect to TYPE(car) – what variables are referenced by DIMENSION(m,n,q,r)? What does mercedes_ay(1,1,1,1) mean? What does mercedes(1,1,1,1) mean?
All it’s doing is declaring an array of
car‘s of dimension (m,n,q,r). Those dimensions aren’t defined by your example code though.mercedes_ay(1,1,1,1)is the first car in the array. Somercedes_ay(1,1,1,1)%xis thexposition of the first car.mercedes_ay(1,1,1,1)%uvw_0(1)is the initialuof the first car. Etc..mercedes(1,1,1,1)is impossible because it has no DIMENSION, it’s a scalar. So it can only point to a scalar. Instead, it would likely be used like:which would mean you are pointing
mercedesat the first car in the array. It basically acts as an alias.