Source code for torx.specializations.which_code_m

"""Function to work out which code is being run for a generic diagnostic."""
from pathlib import Path
from torx.fileio import read_fortran_namelist
from torx.fileio import filepath_resolver


[docs] def which_code(filepath: Path): """Determine which code ran the simulation stored in filepath.""" filepath = Path(filepath) # In case a string is passed assert filepath.exists(), f"Filepath {filepath} does not exist" try: # We first check if a genex parameter file is found. The parameter # file in genex is called 'params_in.txt'. parameter_file = filepath_resolver(filepath, "params_in.txt") parameters = read_fortran_namelist(parameter_file) return "genex" except FileNotFoundError as error: # Check if a grillix parameter file is found. The # parameter file in grillix is called 'params.in' try: parameter_file = filepath_resolver(filepath, "params.in") except FileNotFoundError as error: raise NotImplementedError( f"No params.in file found. which_code could not identify which code executed {filepath}" ) return "grillix"