diff --git a/src/ymf/xdmf.py b/src/ymf/xdmf.py index c1ddb84..d439973 100644 --- a/src/ymf/xdmf.py +++ b/src/ymf/xdmf.py @@ -66,7 +66,8 @@ import json from pathlib import Path from typing import Any, Dict, List, Optional, Tuple -from xml.etree.ElementTree import Element, ElementTree, ParseError, SubElement, parse as et_parse +from xml.etree.ElementTree import (Element, ElementTree, ParseError, SubElement, fromstring, + parse as et_parse) from ymf.archive import YmfArchiveError, canonicalize_domain @@ -392,6 +393,53 @@ def grid_element_time(grid_elem: Element, where: str = "Grid") -> Optional[float return float(_attr(time_elem, ("Value",), where + ".Time")) +def read_grid_fragment(text: str | bytes) -> Tuple[Dict[str, Any], Optional[float]]: + """Parse one serialized ```` element: ``(grid, time)``. + + For the per-step metadata that Proteus <= 1.9.x stored inside its HDF5 + files, one XDMF ```` fragment per rank and step, and that a + current Proteus still reads when it hot starts from or converts such an + archive. The time is the fragment's own ``