--- /dev/null
+#!/usr/bin/env python
+
+'''
+hdf5.py
+
+Driver for text-exported HDF5 files from Igor pro
+
+Alberto Gomez-Casado (c) 2010
+Massimo Sandal (c) 2009
+'''
+
+import libhookecurve as lhc
+import libhooke as lh
+
+class hdf5Driver(lhc.Driver):
+
+ def __init__(self, filename):
+
+ self.filename=filename
+ self.filedata=open(filename,'rU')
+ self.lines=list(self.filedata.readlines())
+ self.filedata.close()
+
+ self.filetype='hdf5'
+ self.experiment='smfs'
+
+ def close_all(self):
+ self.filedata.close()
+
+ def is_me(self):
+ self.raw_header=self.lines[0]
+
+ if 'IGP-HDF5-Hooke' in self.raw_header:
+ return True
+ else:
+ return False
+
+ def _read_columns(self):
+
+ self.raw_columns=self.lines[4:]
+
+ kline=None
+ for line in self.lines:
+ if line[:7]=='SpringC':
+ kline=line
+ break
+
+ kline=kline.split(':')
+
+ self.k=float(kline[1])
+
+
+ xext=[]
+ xret=[]
+ yext=[]
+ yret=[]
+ for line in self.raw_columns:
+ spline=line.split()
+ xext.append(float(spline[0]))
+ yext.append(float(spline[1]))
+ xret.append(float(spline[2]))
+ yret.append(float(spline[3]))
+
+ return [[xext,yext],[xret,yret]]
+
+ def deflection(self):
+ self.data=self._read_columns()
+ return self.data[0][1],self.data[1][1]
+
+
+ def default_plots(self):
+ main_plot=lhc.PlotObject()
+ defl_ext,defl_ret=self.deflection()
+ yextforce=[i*self.k for i in defl_ext]
+ yretforce=[i*self.k for i in defl_ret]
+ main_plot.add_set(self.data[0][0],yextforce)
+ main_plot.add_set(self.data[1][0],yretforce)
+ main_plot.normalize_vectors()
+ main_plot.units=['Z','force'] #FIXME: if there's an header saying something about the time count, should be used
+ main_plot.destination=0
+ main_plot.title=self.filename
+ #main_plot.colors=['red','blue']
+ return [main_plot]
--- /dev/null
+import h5py
+import numpy
+import os
+import sys
+
+h5file=os.path.realpath(sys.argv[-1])
+h5dir=os.path.dirname(h5file)
+
+f=h5py.File(h5file)
+
+exportdir=os.path.join(h5dir,'exported')
+try:
+ os.mkdir(exportdir)
+except:
+ print 'mkdir error, maybe the export directory already exists?'
+
+def h5exportfunc(name):
+ Deflname=name
+ if Deflname.endswith('Defl'): #search for _Defl dataset
+ LVDTname=str.replace(Deflname,'Defl','LVDT') #and correspondant LVDT dataset
+ Defldata=f[Deflname][:] #store the data in local var
+ LVDTdata=f[LVDTname][:]
+ #find useful attr (springc)
+ try:
+ notes=f[Deflname].attrs['IGORWaveNote']
+ springmatch=notes.index("SpringConstant: ")+len("SpringConstant: ")
+ springc=notes[springmatch:].split("\r",1)[0] #probably extracting the leading numbers can be way more elegant than this
+ print Deflname
+ except:
+ print 'Something bad happened with '+Deflname+', ignoring it'
+ return None
+ #returning anything but None halts the visit procedure
+
+ fp=open(os.path.join(exportdir,name.replace('/',''))+'.txt','w')
+ #uses the full HDF5 path (slashes out) to avoid potential overwriting
+ #write attr
+ fp.writelines("IGP-HDF5-Hooke\n")
+ fp.writelines('SpringConstant: '+springc+'\n\n')
+ fp.writelines('App x\tApp y\tRet x\tRet y\n')
+ #write LVDT and Defl data
+ half=Defldata.size/2
+ for i in numpy.arange(0,half):
+ fp.writelines(str(LVDTdata[i])+'\t'+str(Defldata[i])+'\t'+str(LVDTdata[i+half])+'\t'+str(Defldata[i+half])+'\n')
+ #close the file
+ fp.close()
+ return None
+
+
+f.visit(h5exportfunc)