Question

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?

Was it helpful?

Solution

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. So mercedes_ay(1,1,1,1)%x is the x position of the first car. mercedes_ay(1,1,1,1)%uvw_0(1) is the initial u of 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:

mercedes => mercedes_ay(1,1,1,1)

which would mean you are pointing mercedes at the first car in the array. It basically acts as an alias.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top