wrtmil.f
111 lines · 1 definitions · on GitHub (7be4133)
Python version: wrtmil.py, 86 lines, on the right (switch to Python above the code).
Variables on this page (14)
c4pi, cgl, cln, clsun, cmsun, imilne, json, nprtpt, sdel, seg, sesum, stotal, xenv, zenv
Purpose
WRTMIL writes one model's Milne (homology) invariants $U$ and $V$, with $W$ and the polytropic index $n + 1$, to the Milne output file, every NPRTPT shells and the last one.
How it fits
- Inputs: the model (
HCOMP, $\log\rho$, $L/L_\odot$, $\log P$, $\log r$, $m$ in gramsHS1,M,MODEL), and through modules the energy ratesSESUMandSEGand the actual gradientSDEL(2,·)(SCRTCH_MOD), the surface composition and total mass (COMP_MOD),NPRTPT(NMLPAR_MOD), the constants (CONSTANTS_MOD) and the unitIMILNE(IOUNITS_MOD). -
Who calls it: PUTSTORE and WRTOUT, when
LMILNEis set and other conditions hold: PUTSTORE only whenLSTATMorLSTENVis set, and WRTOUT only in its pulsation branch (LPULSEon a model that is not stored). SoLMILNEalone writes nothing. -
Output: the unit
IMILNE(21, fixed in PARMIN, parmin.f, line 674↗), opened by PARMIN in append mode (parmin.f, lines 956–959↗).
The method
At each printed shell:
$$U = \frac{4\pi\rho r^3}{m},\qquad V = \frac{G m \rho}{P r},\qquad W = U\,\frac{m\,(\epsilon_\mathrm{nuc} + \epsilon_7)}{L},\qquad n + 1 = \frac{1}{\nabla},$$
where $\epsilon_\mathrm{nuc}$ is SESUM and $\epsilon_7$ is SEG(7,·) (the gravitational energy rate, by the column names stitch.f gives), and $\nabla$ = SDEL(2,·), the actual gradient.
Suspected bugs, checked by running the code
Each bug is marked by what running the code showed: (changes results, large) or (small), the fix moving a run clearly beyond a null change; (stops the run); (wrong output), the fix changing only what is written; (harmless in the runs), within the noise; (never occurred), the code ran but the fault did not; (not reached); (cannot be reached), a guard prevents it; (withdrawn), the suspicion was wrong.
1. (not reached) The file is closed after each model.
(line 109↗; parmin.f, lines 956–959↗) WRTMIL ends with CLOSE(IMILNE), but the file is opened only once, in PARMIN (MHP 8/25, line 36↗). The next call writes to unit 21 unopened, which gfortran, like most compilers, sends to a default file (fort.21), so the Milne file holds only the first model written. Only with LMILNE (off by default).
A possible fix:
wrtmil.f
@@ lines 105–111 @@
NP1 = 1.0D0/SDEL(2,M)
WRITE(IMILNE,10)M,HS1(M),R,P,D,HCOMP(1,M),HL(M),
* U,V,W,NP1
+C 11/09/26 KC via Claude
+C code changed to keep IMILNE open, since PARMIN opens it only once
+C for the run.
ENDIF
- CLOSE(IMILNE)
RETURN
END
Checked by running YREC (Nov 9, 2026; a line added at each suspected path counted how often it was taken, the outputs otherwise unchanged): not reached in any of 34 runs (26 of YREC's cases, from a 0.04 $M_\odot$ brown dwarf and the solar models to 9 $M_\odot$, rotation, and helium burning, and 8 made-up ones): LMILNE is off by default (nmlpar_mod.f, line 58↗) and set in none of YREC's cases or documents. Not run: LMILNE on, with two or more models written. Intent: The comment at line 36↗ says the file is now opened in PARMIN, so the CLOSE looks left over from when WRTMIL opened the file itself.
Definitions
subroutineWRTMIL
Milne invariants $U$, $V$, with $W$ and $n+1 = 1/\nabla$, for selected shells of one model.
Uses modules COMP_MOD, CONSTANTS_MOD, DIMENSIONS_MOD, IOUNITS_MOD, NMLPAR_MOD, SCRTCH_MOD
Change log
The changes since rp_1
Changed since rp_1. Declarations only: COMMON blocks to modules (/SCRTCH/, /COMP/, /CCOUT1/ to NMLPAR_MOD, /LUOUT/ to IOUNITS_MOD, the constants to CONSTANTS_MOD), IMPLICIT NONE.