@@ -0,0 +1,1244 @@
+#!/usr/bin/env python%0A%0Aimport sys%0Afrom datetime import datetime%0A%0Aimport pymoku.dataparser%0Aimport h5py%0A%0Aif len(sys.argv) != 3:%0A%09print %22Usage: li_to_csv.py infile.li outfile.hd5%22%0A%09exit(1)%0A%0Areader = pymoku.dataparser.LIDataFileReader(sys.argv%5B1%5D)%0Awriter = h5py.File(sys.argv%5B2%5D, 'w')%0Ancols = reader.nch%0A%0Aset_name = 'moku:datalog'%0A%0A# Start with storage for 100 items, it'll be expanded as we add data. We don't know the%0A# length of the data set to begin with.%0Awriter.create_dataset(set_name, (100,ncols), maxshape=(None,ncols))%0Awriter%5Bset_name%5D.attrs%5B'timestep'%5D = reader.deltat%0Awriter%5Bset_name%5D.attrs%5B'start_secs'%5D = reader.starttime%0Awriter%5Bset_name%5D.attrs%5B'start_time'%5D = datetime.fromtimestamp(reader.starttime).strftime('%25c')%0Awriter%5Bset_name%5D.attrs%5B'instrument'%5D = reader.instr%0Awriter%5Bset_name%5D.attrs%5B'instrument_version'%5D = reader.instrv%0A%0Ai = 0%0Afor record in reader:%0A%09curlen = len(writer%5Bset_name%5D)%0A%09if curlen %3C= i:%0A%09%09# Exponential allocation strategy, works fairly well for different sized files.%0A%09%09# We truncate to the correct length at the end anyway.%0A%09%09writer%5Bset_name%5D.resize((2*curlen, ncols))%0A%0A%09writer%5Bset_name%5D%5Bi,:%5D = record%5B:ncols%5D%0A%09i += 1%0A%0A# Truncate the file to the correct length%0Awriter%5Bset_name%5D.resize((i, ncols))%0Awriter.close()%0A

Add HDF5 data file writer to examples