[mesa-users] derived types, dynamic allocation, and pointers in mesa -- not your father's fortran

Bill Paxton paxton at kitp.ucsb.edu
Sat Jan 22 11:07:03 EST 2011

Hi Ehsan,

On Jan 22, 2011, at 7:36 AM, Ehsan Moravveji wrote:
> What is the role of s%? How shall I interpret it, since it appears in all modules. What values does it take/return?

That's such a good question that I'm cc'ing my reply to mesa-users.
It should be useful for anyone who will be looking at the code and doesn't 
already understand derived types, dynamic allocation, and pointers in fortran95.

In "old" fortran, we used common blocks.  Now we take all of the things that would have been in common blocks and call them a "derived type".  We then can dynamically allocate (i.e. during the run) as many copies as we need.  To tell the code which copy of the data it is using, we pass along a pointer to the copy.     The derived type for star is called 'star_info'.  The type declaration can be found in public/star_def.   The routines that access information from star_info will have a declaraction like this:
         type (star_info), pointer :: s
That says s is a pointer to an instance of the star_info derived type.   All of the stuff in star_data.dek is in star_info.  For example, to reference the variable 'nvar' in the instance of star_info data pointed to by s, we write
	s% nvar
The "%" is just the fortran syntax meaning "in the structure specified on the left of the %, access the data named by the stuff on the right of the %".   So s% nvar can act like any other variable -- it can appear as a value in expressions or it can appear on the left of an assignment statement when you want to change its value.

The items in the derived type can be arrays or other types, so, for example, the radius at the outer edge of cell k is
	s% r(k)


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.mesastar.org/pipermail/mesa-users/attachments/20110122/5b3473dd/attachment.html>

More information about the Mesa-users mailing list