Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

code problem: polymorphic pointers?

robbiet
Beginner
214 Views
I'm struggling with af95 code problem that really needs polymorphic pointers/variables (i.e. a single array consisting of multiple data types), but I understand these are not to be supported until fortran 2000 (?)... Any help much appreciated:
I have defined an overall'particle' type, and within this type need to define the shape of the particle in question. The shapes however are defined as a series of different types (e.g. sphere, ellipsoid, polygon, etc.) all which have different numbers of parameters within them. What I essentially need to do is given two 'particle' type variables perform a set of calculations that depend on which shape they are.
IDEALLY.... Use a polymorphicvariable toimbed the shape information within the 'particle' type, and then overload an operator to perform the correct set of calculations from the shape type passed to it.
PRACTICALLY.... At the moment have referenced an integer 'shape_ID' within the 'particle' type and then use a series of IF statements to based on the shape_ID to sort which calculations are to be performed.
IF (shape_IDparticle A = 1AND shape_ID particle B = 1)
Do some calcs, calling externalshape type info for A & B
ELSE IF (shape_ID particle A = 2 AND shape_ID particle B = 1)
Do some different calcs, calling externalshape type info for A & B
ELSE IF... etc.
Messy, and slow. Also the actual shape parameters need to be stored in separate arrays for each type, which need to be referenced in.
Not been using fortran 95 for long, and suspect there must be a faster, or at least more elegant solution to the oneI have already. Any words of wisdom?
Cheers.
0 Kudos
0 Replies
Reply