mesaload Module

MESA profile and .kipp readers, and dispatcher over every input format.

load_convection picks reader from path ("Input formats", docs/formats.md); every reader fills convdata%data w/ one .cnv-layout record per model. Non-structural source columns (every named .kipp column, a curated MESA set) register as colour fields, binned into FIELD_NBINS levels over whole-sequence range.



Variables

Type Visibility Attributes Name Initial
logical, public :: cnv_loaded = .false.

Last load went through .cnv reader, whose grid may be reduced.

character(len=4), public :: kipp_axis_units(3) = ''

Units a .kipp header states for age, mass and radius columns, blank where none.

Indexed by DIM_TIME, DIM_MASS, DIM_LENGTH.

integer(kind=int32), private, parameter :: MESA_MAX_THREADS = 4

Cap on profile-read thread pool.

Parsing is memory-bandwidth bound, peaking around 3 to 4 threads; a lower OMP_NUM_THREADS overrides it at runtime.

integer(kind=int32), private, parameter :: MESA_NO_MIXING = 0

MESA no_mixing, drawn as radiative.

Mixing codes named as in MESA r26.04.1 const/public/const_def.f90.

integer(kind=int32), private, parameter :: MESA_CONVECTIVE_MIXING = 1

MESA convective_mixing, drawn as convective.

integer(kind=int32), private, parameter :: MESA_OVERSHOOT_MIXING = 2

MESA overshoot_mixing, drawn as overshoot.

integer(kind=int32), private, parameter :: MESA_SEMICONVECTIVE_MIXING = 3

MESA semiconvective_mixing, drawn as semiconvective.

integer(kind=int32), private, parameter :: MESA_THERMOHALINE_MIXING = 4

MESA thermohaline_mixing, drawn as thermohaline.

integer(kind=int32), private, parameter :: MESA_ROTATION_MIXING = 5

MESA rotation_mixing, drawn as neutral.

integer(kind=int32), private, parameter :: MESA_LEFTOVER_CONVECTIVE_MIXING = 9

MESA leftover_convective_mixing, drawn as convective.

integer(kind=int32), private, parameter :: MESA_NCAND = 9

Number of curated MESA colour-field columns.

character(len=16), private, parameter :: MESA_FIELD_CAND(MESA_NCAND) = [character(len=16)::'logT', 'logRho', 'logL', 'luminosity', 'logP', 'pressure', 'opacity', 'entropy', 'velocity']

Curated MESA profile body columns offered as colour fields.

Only these scalars are read, since full body is huge; names absent from a run are skipped.


Derived Types

type, private ::  rawset

Colour-field values of one profile, held between parallel read and serial binning.

Components

Type Visibility Attributes Name Initial
real(kind=real64), public, allocatable :: v(:,:)

Value per cell (rows, centre to surface) and field (columns).


Functions

private pure function third_word(line) result(w)

Return third blank-separated word of header line, blank if none.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: line

Header line.

Return Value character(len=len)

private pure function is_structural_kipp(name) result(yes)

Test whether .kipp column is structural, so not offered as colour field.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: name

Column name.

Return Value logical

private pure function has_suffix(s, suf) result(yes)

Test whether s ends with suf.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: s

String to test.

character(len=*), intent(in) :: suf

Suffix.

Return Value logical

private pure function type_char(m) result(c)

Return ZONE_CHAR type of MESA mixing code ("Required columns", docs/kippfiles.md).

Read more…

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in) :: m

MESA mixing code.

Return Value character(len=1)

private pure function col_index(line, name) result(idx)

Return 1-based position of whitespace-separated token equal to name, or -1.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: line

Line of column names.

character(len=*), intent(in) :: name

Column name to find.

Return Value integer(kind=int32)

private function itoa(n) result(s)

Return left-justified decimal string of non-negative integer.

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in) :: n

Integer to write.

Return Value character(len=12)


Subroutines

public subroutine load_convection(path, ifirst, ilast)

Load any supported input into data, reader picked from path.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: path

Input path.

integer(kind=int32), intent(in) :: ifirst

First model number to load.

integer(kind=int32), intent(in) :: ilast

Last model number to load.

public subroutine loadmesa(dirname, ifirst, ilast)

Load profiles of MESA run directory into data.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: dirname

Path of MESA run directory.

integer(kind=int32), intent(in) :: ifirst

First model number to load.

integer(kind=int32), intent(in) :: ilast

Last model number to load.

private subroutine register_mesa_fields(dirname, pnum, fld_col, nf)

Register curated colour fields present in a run.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: dirname

Path of MESA run directory.

integer(kind=int32), intent(in) :: pnum

Profile number whose body header is read.

integer(kind=int32), intent(out), allocatable :: fld_col(:)

Body column of each registered field.

integer(kind=int32), intent(out) :: nf

Number of registered fields.

private subroutine loadkipp(path, ifirst, ilast)

Stream raw .kipp cell file into data.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: path

Path of .kipp file.

integer(kind=int32), intent(in) :: ifirst

First model number to load.

integer(kind=int32), intent(in) :: ilast

Last model number to load.

private subroutine fill_kipp_fields(path, ncols, c_model, fld_col, nf, recs, ndata, ifirst, ilast)

Re-read .kipp file and bin each registered field into recs(k)%fld.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: path

Path of .kipp file.

integer(kind=int32), intent(in) :: ncols

Number of values per cell.

integer(kind=int32), intent(in) :: c_model

Column of model number.

integer(kind=int32), intent(in) :: fld_col(:)

Column of each registered field.

integer(kind=int32), intent(in) :: nf

Number of registered fields.

type(convtype), intent(inout) :: recs(:)

Records of pass one, in stream order.

integer(kind=int32), intent(in) :: ndata

Number of records pass one built.

integer(kind=int32), intent(in) :: ifirst

First model number to load.

integer(kind=int32), intent(in) :: ilast

Last model number to load.

private subroutine flush_kipp_fields(recs, counter, model, nz, fb, nf, ifirst, ilast)

Bin one model's accumulated field values into its record's fld layers.

Read more…

Arguments

Type IntentOptional Attributes Name
type(convtype), intent(inout) :: recs(:)

Records of pass one, in stream order.

integer(kind=int32), intent(inout) :: counter

Index of last filled record, advanced by one when model is kept.

integer(kind=int32), intent(in) :: model

Model number.

integer(kind=int32), intent(in) :: nz

Number of cells.

real(kind=real64), intent(in) :: fb(:,:)

Value of each field (rows) and cell (columns, surface to centre).

integer(kind=int32), intent(in) :: nf

Number of registered fields.

integer(kind=int32), intent(in) :: ifirst

First model number to load.

integer(kind=int32), intent(in) :: ilast

Last model number to load.

private subroutine grow_fb(fb, zcap)

Double cell capacity of field accumulation buffer, keeping contents.

Arguments

Type IntentOptional Attributes Name
real(kind=real64), intent(inout), allocatable :: fb(:,:)

Value of each field (rows) and cell (columns).

integer(kind=int32), intent(inout) :: zcap

Cell capacity, doubled.

private subroutine kipp_colnames(hdrfile, ncols, names, colunits)

Read every column name and optional unit of a .kipp sidecar header, in column order.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: hdrfile

Path of sidecar header.

integer(kind=int32), intent(out) :: ncols

Number of columns, from ncols line, or 512 if missing.

character(len=32), intent(out), allocatable :: names(:)

Name of each column, blank if unnamed.

character(len=32), intent(out), allocatable :: colunits(:)

Unit of each column, blank if none stated.

private subroutine kipp_axis_unit(col, tok, dm, def, fac, unit)

Find cgs factor of a .kipp age, time step, mass or radius column.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: col

Column name, for the error message.

character(len=*), intent(in) :: tok

Unit the header states, blank if none.

integer(kind=int32), intent(in) :: dm

Dimension code of column, a units DIM_ constant.

real(kind=real64), intent(in) :: def

Factor of unit column name implies.

real(kind=real64), intent(out) :: fac

Factor to cgs.

character(len=*), intent(out) :: unit

UNAME entry of stated unit, blank if none.

private subroutine register_kipp_fields(names, colunits, ncols, fld_col, nf)

Register every named non-structural .kipp column as a colour field.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: names(:)

Name of each column, blank if unnamed.

character(len=*), intent(in) :: colunits(:)

Unit of each column, blank if none.

integer(kind=int32), intent(in) :: ncols

Number of columns.

integer(kind=int32), intent(out), allocatable :: fld_col(:)

Source column of each registered field.

integer(kind=int32), intent(out) :: nf

Number of registered fields.

private subroutine flush_kipp(recs, ndata, ncap, model, nz, tsec, dtsec, am, ar, amt, ae, ifirst, ilast)

Append record of one model's accumulated cells to recs.

Read more…

Arguments

Type IntentOptional Attributes Name
type(convtype), intent(inout), allocatable :: recs(:)

Records built so far, in stream order.

integer(kind=int32), intent(inout) :: ndata

Number of records in recs.

integer(kind=int32), intent(inout) :: ncap

Capacity of recs.

integer(kind=int32), intent(in) :: model

Model number.

integer(kind=int32), intent(in) :: nz

Number of cells.

real(kind=real64), intent(in) :: tsec

Age (s).

real(kind=real64), intent(in) :: dtsec

Time step (s).

real(kind=real64), intent(in) :: am(:)

Mass coordinate of each cell (g), surface to centre.

real(kind=real64), intent(in) :: ar(:)

Radius coordinate of each cell (cm), surface to centre.

integer(kind=int32), intent(in) :: amt(:)

MESA mixing code of each cell, surface to centre.

real(kind=real64), intent(in) :: ae(:)

Energy rate of each cell (erg/g/s), surface to centre.

integer(kind=int32), intent(in) :: ifirst

First model number to load.

integer(kind=int32), intent(in) :: ilast

Last model number to load.

private subroutine build_kipp_record(cnv, model, nz, tsec, dtsec, xm, rn, mt, eps)

Build record of one .kipp model.

Read more…

Arguments

Type IntentOptional Attributes Name
type(convtype), intent(out) :: cnv

Record to build.

integer(kind=int32), intent(in) :: model

Model number.

integer(kind=int32), intent(in) :: nz

Number of cells.

real(kind=real64), intent(in) :: tsec

Age (s).

real(kind=real64), intent(in) :: dtsec

Time step (s).

real(kind=real64), intent(in) :: xm(:)

Mass coordinate of each cell (g), centre to surface.

real(kind=real64), intent(in) :: rn(:)

Radius coordinate of each cell (cm), centre to surface.

integer(kind=int32), intent(in) :: mt(:)

MESA mixing code of each cell, centre to surface.

real(kind=real64), intent(in) :: eps(:)

Net energy rate of each cell (erg/g/s), centre to surface.

private subroutine grow_accum(am, ar, ae, amt, zcap)

Double cell accumulation buffers of loadkipp, keeping contents.

Arguments

Type IntentOptional Attributes Name
real(kind=real64), intent(inout), allocatable :: am(:)

Mass coordinate of each cell.

real(kind=real64), intent(inout), allocatable :: ar(:)

Radius coordinate of each cell.

real(kind=real64), intent(inout), allocatable :: ae(:)

Energy rate of each cell.

integer(kind=int32), intent(inout), allocatable :: amt(:)

Mixing code of each cell.

integer(kind=int32), intent(inout) :: zcap

Cell capacity, doubled.

private subroutine find_kipp_header(path, hdrfile)

Locate sidecar header of .kipp file ("Header file", docs/kippfiles.md).

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: path

Path of .kipp file.

character(len=*), intent(out) :: hdrfile

Path of header.

private subroutine parse_kipp_header(hdrfile, ncols, c_model, c_age, c_dt, c_mass, c_radius, c_mix, c_eps)

Read ncols and required-role columns from .kipp sidecar header.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: hdrfile

Path of sidecar header.

integer(kind=int32), intent(out) :: ncols

Number of values per cell.

integer(kind=int32), intent(out) :: c_model

Column of model number.

integer(kind=int32), intent(out) :: c_age

Column of age.

integer(kind=int32), intent(out) :: c_dt

Column of time step, 0 if absent.

integer(kind=int32), intent(out) :: c_mass

Column of mass coordinate.

integer(kind=int32), intent(out) :: c_radius

Column of radius coordinate.

integer(kind=int32), intent(out) :: c_mix

Column of mixing type.

integer(kind=int32), intent(out) :: c_eps

Column of energy rate.

private subroutine assign_kipp_col(name, idx, c_model, c_age, c_dt, c_mass, c_radius, c_mix, c_eps)

Assign header column to its role by accepted names ("Required columns", docs/kippfiles.md).

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: name

Column name.

integer(kind=int32), intent(in) :: idx

Column index, from 1.

integer(kind=int32), intent(inout) :: c_model

Column of model number.

integer(kind=int32), intent(inout) :: c_age

Column of age.

integer(kind=int32), intent(inout) :: c_dt

Column of time step.

integer(kind=int32), intent(inout) :: c_mass

Column of mass coordinate.

integer(kind=int32), intent(inout) :: c_radius

Column of radius coordinate.

integer(kind=int32), intent(inout) :: c_mix

Column of mixing type.

integer(kind=int32), intent(inout) :: c_eps

Column of energy rate.

private subroutine read_profile(dirname, pnum, cnv, fld_col, nf, rf)

Parse profile<pnum>.data into one record.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: dirname

Path of MESA run directory.

integer(kind=int32), intent(in) :: pnum

Profile number.

type(convtype), intent(out) :: cnv

Record to build.

integer(kind=int32), intent(in) :: fld_col(:)

Body column of each registered field.

integer(kind=int32), intent(in) :: nf

Number of registered fields.

type(rawset), intent(out) :: rf

Colour-field values of profile.

private subroutine build_mesa_zones(mt, nz, cnv)

Build convection zones of record from MESA mixing codes, mapped by type_char.

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in) :: mt(:)

MESA mixing code of each cell, centre to surface.

integer(kind=int32), intent(in) :: nz

Number of cells.

type(convtype), intent(inout) :: cnv

Record receiving zones.