I recently needed a small script that converted our usual "fileBased" iterationEncoding to a single "groupBased" file (in HDF5).
Next time I need it I will rewrite it in pure python so it's more portable. (Actually, I tried pure bash but needed a small in-file manipulation which I found no CLI tool for).
Nevertheless, here it is already:
#!/usr/bin/env bash
#
# Copyright 2017 Axel Huebl
#
# Use under the ISC software license.
#
# needs input argument parsing & help
dumps=($(ls h5/*_*.h5))
first=0
for d in ${dumps[@]};
do
if [ $first -eq 0 ]
then
# includes copy of / attributes from first file
cp $d simData.h5
first=1
else
step=$(echo $d | sed 's/.\+_\([0-9]\+\)\.h5/\1/')
h5copy -i $d -s "/data/$step" \
-o simData.h5 -d "/data/$step"
fi
done
# that might not be necessary if your files already had compression enabled
h5repack -i simData.h5 -o simData.h5.gz -f GZIP=1 && \
mv simData.h5.gz simData.h5
# change attributes:
# "/iterationEncoding" -> "groupBased"
# "/iterationFormat" -> "/data/%T/"
python -c 'import h5py; import numpy as np; f=h5py.File("simData.h5", "a"); f.attrs["iterationEncoding"] = np.string_("groupBased"); f.attrs["iterationFormat"] = np.string_("/data/%T/"); f.close()'
I recently needed a small script that converted our usual "fileBased"
iterationEncoding
to a single "groupBased" file (in HDF5).Next time I need it I will rewrite it in pure python so it's more portable. (Actually, I tried pure bash but needed a small in-file manipulation which I found no CLI tool for).
Nevertheless, here it is already: