(j3.2006) More on invoking type-bound functions and selecting subobjects of their results

Van Snyder Van.Snyder
Fri Jan 8 20:25:02 EST 2016


Here's an example of a use for accessing type-bound functions using
other than named data objects, and then selecting components of their
results.

I need to compute geocentric height from geodetic coordinates.

I have a type named H_V_Geod, which contains horizontal (lon, lat,
degees) and vertical (meters above mean geoid) geodetic coordinates.  It
has a type-bound function that returns geocentric coordinates.  Here's
how I need to use it:

    type(h_v_geoc) :: Geoc
    type(h_v_geod) :: Geod

    geod = h_v_geod ( lon=g%lon1(k), lat=g%geodLat1(k), v=g%geodV1(k) )
    geoc = geod%geocV()
    GeocV = geoc%v

It would have been easier if I could have written

GeocV = h_v_geod ( lon=g%lon1(k), lat=g%geodLat1(k), v=g%geodV1(k) )%geocV%v

I.e., use the h_v_geod type constructor in place of the first
<part-name> in the <data-ref>, then invoke the geocV function (without
empty parentheses) using that object as the passed-object actual
argument, then select the V component of the result.

If the processor had access to the guts of the type-bound function geocV
(which is in a different module), and noticed that I'm only interested
in the V component of the result, it could have avoided an atan2
invocation to compute the geocentric latitude, and avoided copying the
longitude, neither of which are needed at this place.  Maybe it could
figure that out anyway by a dataflow analysis of the method involving
three assignment statements and two auxiliary variables of derived type,
but I'm not entirely confident of that.





More information about the J3 mailing list