Skip to content

Commit 2732b33

Browse files
committed
stagyyparsers: extract _ifile_isnap
1 parent 637bc4f commit 2732b33

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

stagpy/stagyyparsers.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,15 @@ def _try_text(file: Path, elt: Element) -> str:
724724
return text
725725

726726

727+
def _ifile_isnap(file: Path, elt: Element) -> tuple[int, int]:
728+
"""Extract ifile and isnap from H5 file name/dataset."""
729+
data_text = _try_text(file, elt)
730+
h5file, group = data_text.strip().split(":/", 1)
731+
isnap = int(group[-5:])
732+
ifile = int(h5file[-14:-9])
733+
return ifile, isnap
734+
735+
727736
def _count_subdomains(xs: XmlStream, i0_yin: int) -> tuple[range, range]:
728737
i1_yin = i0_yin + 1
729738
i0_yang = 0
@@ -837,10 +846,7 @@ def _data(self) -> Mapping[int, XmfEntry]:
837846
name = elt_fvar.attrib["Name"]
838847
elt_data = elt_fvar[0]
839848
shape = self._get_dims(elt_data)
840-
data_text = _try_text(xs.filepath, elt_data)
841-
h5file, group = data_text.strip().split(":/", 1)
842-
isnap = int(group[-5:])
843-
ifile = int(h5file[-14:-9])
849+
ifile, isnap = _ifile_isnap(xs.filepath, elt_data)
844850
fields_info[name] = (ifile, shape)
845851

846852
r_yin, r_yang = _count_subdomains(xs, i0_yin)
@@ -1130,20 +1136,13 @@ def _data(self) -> Mapping[int, XmfTracersEntry]:
11301136
xs.skip_to_tag("Geometry")
11311137
with xs.load() as elt_geom:
11321138
for name, data_item in zip("zyx", elt_geom):
1133-
data_text = _try_text(xs.filepath, data_item)
1134-
h5file, group = data_text.strip().split(":/", 1)
1135-
isnap = int(group[-5:])
1136-
ifile = int(h5file[-14:-9])
1139+
ifile, isnap = _ifile_isnap(xs.filepath, data_item)
11371140
fields_info[name] = ifile
11381141

11391142
while xs.current.tag == "Attribute":
11401143
with xs.load() as elt_fvar:
11411144
name = elt_fvar.attrib["Name"]
1142-
elt_data = elt_fvar[0]
1143-
data_text = _try_text(xs.filepath, elt_data)
1144-
h5file, group = data_text.strip().split(":/", 1)
1145-
isnap = int(group[-5:])
1146-
ifile = int(h5file[-14:-9])
1145+
ifile, _ = _ifile_isnap(xs.filepath, elt_fvar[0])
11471146
fields_info[name] = ifile
11481147

11491148
r_yin, r_yang = _count_subdomains(xs, i0_yin)

0 commit comments

Comments
 (0)