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
20 changes: 13 additions & 7 deletions src/flekspy/tp/test_particles.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,17 @@ def read_particle_list(self, filename: str) -> Dict[Tuple[int, int], int]:
"""
Read and return a list of the particle IDs.
"""
# 2 integers + 1 unsigned long long
listUnitSize = 2 * 4 + 8
record_format = "iiQ" # 2 integers + 1 unsigned long long
record_size = struct.calcsize(record_format)
record_struct = struct.Struct(record_format)
nByte = Path(filename).stat().st_size
nPart = int(nByte / listUnitSize)
nPart = int(nByte / record_size)
plist = {}

with open(filename, "rb") as f:
for _ in range(nPart):
binaryData = f.read(listUnitSize)
(cpu, id, loc) = struct.unpack("iiQ", binaryData)
dataChunk = f.read(record_size)
(cpu, id, loc) = record_struct.unpack(dataChunk)
plist.update({(cpu, id): loc})
return plist

Expand Down Expand Up @@ -278,13 +280,17 @@ def read_particle_trajectory(self, pID: Tuple[int, int]):
>>> trajectory = tp.read_particle_trajectory((66,888))
"""
dataList = list()
record_format = "iiif"
record_size = struct.calcsize(record_format)
record_struct = struct.Struct(record_format)

for filename, plist in zip(self.pfiles, self.plists):
if pID in plist:
ploc = plist[pID]
with open(filename, "rb") as f:
f.seek(ploc)
binaryData = f.read(4 * 4)
(cpu, idtmp, nRecord, weight) = struct.unpack("iiif", binaryData)
dataChunk = f.read(record_size)
(cpu, idtmp, nRecord, weight) = record_struct.unpack(dataChunk)
binaryData = f.read(4 * self.nReal * nRecord)
dataList = dataList + list(
struct.unpack("f" * nRecord * self.nReal, binaryData)
Expand Down