Skip to content

Commit 6f423a3

Browse files
committed
fix FieldXmf, TracersXmf for sequential runs
1 parent a5f8ed7 commit 6f423a3

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

stagpy/stagyyparsers.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -820,13 +820,12 @@ def _data(self) -> Mapping[int, XmfEntry]:
820820
coord_filepattern = "_".join(coord_file_chunks)
821821

822822
fields_info = {}
823-
while xs.current.tag == "Attribute":
824-
with xs.load() as elt_fvar:
825-
name = elt_fvar.attrib["Name"]
826-
elt_data = elt_fvar[0]
827-
shape = self._get_dims(elt_data)
828-
ifile, isnap = _ifile_isnap(xs.filepath, elt_data)
829-
fields_info[name] = (ifile, shape)
823+
for elt_fvar in xs.iter_load_successive_tag("Attribute"):
824+
name = elt_fvar.attrib["Name"]
825+
elt_data = elt_fvar[0]
826+
shape = self._get_dims(elt_data)
827+
ifile, isnap = _ifile_isnap(xs.filepath, elt_data)
828+
fields_info[name] = (ifile, shape)
830829

831830
r_yin, r_yang = _count_subdomains(xs, i0_yin)
832831

@@ -1120,11 +1119,10 @@ def _data(self) -> Mapping[int, XmfTracersEntry]:
11201119
ifile, isnap = _ifile_isnap(xs.filepath, data_item)
11211120
fields_info[name] = ifile
11221121

1123-
while xs.current.tag == "Attribute":
1124-
with xs.load() as elt_fvar:
1125-
name = elt_fvar.attrib["Name"]
1126-
ifile, _ = _ifile_isnap(xs.filepath, elt_fvar[0])
1127-
fields_info[name] = ifile
1122+
for elt_fvar in xs.iter_load_successive_tag("Attribute"):
1123+
name = elt_fvar.attrib["Name"]
1124+
ifile, _ = _ifile_isnap(xs.filepath, elt_fvar[0])
1125+
fields_info[name] = ifile
11281126

11291127
r_yin, r_yang = _count_subdomains(xs, i0_yin)
11301128

stagpy/xdmf.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ def iter_tag(self, tag: str) -> Iterator[None]:
5353
except EndOfXml:
5454
pass
5555

56+
def iter_load_successive_tag(self, tag: str) -> Iterator[ET.Element]:
57+
try:
58+
while self.current.tag == tag:
59+
with self.load() as elt:
60+
yield elt
61+
except EndOfXml:
62+
pass
63+
5664
def drop(self) -> None:
5765
"""Discard the current element and its children."""
5866
self.current # make sure to be at current "start" event

0 commit comments

Comments
 (0)