Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion toolchain/mfc/params/namelist_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,16 +490,29 @@ def get_fortran_constants() -> Dict[str, int]:
"""
Get Fortran compile-time constants from m_constants.fpp.

Cached after first call. Returns empty dict if source unavailable.
Cached after first call. Falls back to built-in defaults when the Fortran
source is unavailable (e.g. Homebrew installs where src/ is not shipped).
"""
global _FORTRAN_CONSTANTS_CACHE # noqa: PLW0603
if _FORTRAN_CONSTANTS_CACHE is None:
root = get_mfc_root()
path = root / "src" / "common" / "m_constants.fpp"
_FORTRAN_CONSTANTS_CACHE = parse_fortran_constants(path)
if not _FORTRAN_CONSTANTS_CACHE:
_FORTRAN_CONSTANTS_CACHE = _FALLBACK_CONSTANTS.copy()
return _FORTRAN_CONSTANTS_CACHE


# Fallback values for when m_constants.fpp is not available at runtime.
# Keep in sync with src/common/m_constants.fpp.
_FALLBACK_CONSTANTS: Dict[str, int] = {
"num_fluids_max": 10,
"num_probes_max": 10,
"num_patches_max": 1000,
"num_bc_patches_max": 10,
}


def get_mfc_root() -> Path:
"""Get the MFC root directory from this file's location."""
# This file is at toolchain/mfc/params/namelist_parser.py
Expand Down
Loading