def append(fname, data):
with open(fname, 'r+b') as f:
nx, ny, nz = np.fromfile(f, dtype=np.int32, count=3) # First 12 bytes of stack.
f.seek(36) # First byte of zlen.
zlen = np.fromfile(f, dtype=np.float32, count=1)
if data.shape[0] != nx or data.shape[1] != ny:
raise Exception
f.seek(0, os.SEEK_END)
np.require(np.reshape(data, (-1,), order='F'), dtype=np.float32).tofile(f)
# Update header after new data is written.
apix = zlen / nz
nz += data.shape[2]
zlen += apix * data.shape[2]
f.seek(8)
nz.tofile(f)
f.seek(36)
zlen.tofile(f)
评论列表
文章目录