1 # Copyright (C) 2010 Alberto Gomez-Casado
2 # W. Trevor King <wking@drexel.edu>
4 # This file is part of Hooke.
6 # Hooke is free software: you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation, either
9 # version 3 of the License, or (at your option) any later version.
11 # Hooke is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with Hooke. If not, see
18 # <http://www.gnu.org/licenses/>.
25 h5file=os.path.realpath(sys.argv[-1])
26 h5dir=os.path.dirname(h5file)
30 exportdir=os.path.join(h5dir,'exported')
34 print 'mkdir error, maybe the export directory already exists?'
36 def h5exportfunc(name):
38 if Deflname.endswith('Defl'): #search for _Defl dataset
39 LVDTname=str.replace(Deflname,'Defl','LVDT') #and correspondant LVDT dataset
40 Defldata=f[Deflname][:] #store the data in local var
41 LVDTdata=f[LVDTname][:]
42 #find useful attr (springc)
44 notes=f[Deflname].attrs['IGORWaveNote']
45 springmatch=notes.index("SpringConstant: ")+len("SpringConstant: ")
46 springc=notes[springmatch:].split("\r",1)[0] #probably extracting the leading numbers can be way more elegant than this
49 print 'Something bad happened with '+Deflname+', ignoring it'
51 #returning anything but None halts the visit procedure
53 fp=open(os.path.join(exportdir,name.replace('/',''))+'.txt','w')
54 #uses the full HDF5 path (slashes out) to avoid potential overwriting
56 fp.writelines("IGP-HDF5-Hooke\n")
57 fp.writelines('SpringConstant: '+springc+'\n\n')
58 fp.writelines('App x\tApp y\tRet x\tRet y\n')
59 #write LVDT and Defl data
61 for i in numpy.arange(0,half):
62 fp.writelines(str(LVDTdata[i])+'\t'+str(Defldata[i])+'\t'+str(LVDTdata[i+half])+'\t'+str(Defldata[i+half])+'\n')