reading of header is now working

This commit is contained in:
Martin Diehl 2010-12-03 14:57:28 +00:00
parent 2f47d4b09b
commit ac676623ca
1 changed files with 76 additions and 26 deletions

View File

@ -5,46 +5,96 @@ print('post processing for mpie_spectral')
filename ='results.out' filename ='results.out'
results = open(filename, 'rb') results = open(filename, 'rb')
print('filename:', filename) print('filename:', filename)
header = results.read(4) #read header
begin = results.tell()
end = results.read(1024).find(header) #find header (second time) #find load case name
searchstring = b'Loadcase '
results.seek(begin+9) #position: header + string "loadcase " begin = results.read(2048).find(searchstring) + 9 # function will return -1 if string isnt found
#loadcase = binascii.b2a_base64(results.read(end-9)) #conversion doesnt work results.seek(begin -13) #position of header
loadcase = results.read(end -9) header = results.read(4) #store header
results.seek(begin,0)
length = results.read(2048).find(header)
results.seek(begin,0)
loadcase = results.read(length)
print('loadcase:', loadcase) print('loadcase:', loadcase)
results.seek(begin+end+4) #find workingdir name
results.seek(0,0)
searchstring = b'Workingdir '
header = results.read(4) begin = results.read(2048).find(searchstring) + 11
begin = results.tell() results.seek(begin -15) #position of header
end = results.read(1024).find(header) #find header (second time) header = results.read(4) #store header
results.seek(begin+11) #position: header + string "workingdir " results.seek(begin,0)
workingdir = results.read(end -11) length = results.read(2048).find(header)
results.seek(begin,0)
workingdir = results.read(length)
print('workingdir:', workingdir) print('workingdir:', workingdir)
results.seek(begin+end+4) #find job name
results.seek(0,0)
searchstring = b'JobName '
header = results.read(4) begin = results.read(2048).find(searchstring) + 8
begin = results.tell() results.seek(begin -12) #position of header
end = results.read(1024).find(header) #find header (second time) header = results.read(4) #store header
results.seek(begin+8) #position: header + string "workingdir " results.seek(begin,0)
jobname = results.read(end -8) length = results.read(2048).find(header)
results.seek(begin,0)
jobname = results.read(length)
print('jobname:', jobname) print('jobname:', jobname)
results.seek(results.tell()+4) #find size of materialpoint results
header = results.read(4) results.seek(0,0)
searchstring = b'materialpoint_sizeResults'
begin = results.read(2048).find(searchstring) + 24
results.seek(begin,0)
materialpoint_sizeResults = array.array('i',[0])
materialpoint_sizeResults[0] = struct.unpack('i',results.read(4))[0]
print('materialpoint_sizeResults:', materialpoint_sizeResults)
#read in resolution (FPs) of geometry
resolution = array.array('i',[0,0,0]) resolution = array.array('i',[0,0,0])
results.seek(0,0)
header1 = b'a' searchstring = b'resolution'
begin = results.seek(results.tell()+11) begin = results.read(2048).find(searchstring) + 10 #end position of string "resolution"
begin = begin + results.read(1024).find(header1) results.seek(begin,0)
results.seek(begin+1) pos = results.read(60).find(b'a')
results.seek(begin+pos+1,0)
resolution[0]=struct.unpack('i',results.read(4))[0] resolution[0]=struct.unpack('i',results.read(4))[0]
results.seek(begin,0)
pos = results.read(60).find(b'b')
results.seek(begin+pos+1,0)
resolution[1]=struct.unpack('i',results.read(4))[0]
results.seek(begin,0)
pos = results.read(60).find(b'c')
results.seek(begin+pos+1,0)
resolution[2]=struct.unpack('i',results.read(4))[0]
print(resolution) print('resolution:',resolution)
#read in dimension of geometry
geomdimension = array.array('d',[0,0,0])
results.seek(0,0)
searchstring = b'geomdimension'
begin = results.read(2048).find(searchstring) + 13
results.seek(begin,0)
pos = results.read(60).find(b'x')
results.seek(begin+pos+1,0)
geomdimension[0]=struct.unpack('d',results.read(8))[0]
results.seek(begin,0)
pos = results.read(60).find(b'y')
results.seek(begin+pos+1,0)
geomdimension[1]=struct.unpack('d',results.read(8))[0]
results.seek(begin,0)
pos = results.read(60).find(b'z')
results.seek(begin+pos+1,0)
geomdimension[2]=struct.unpack('d',results.read(8))[0]
print('geomdimension:',geomdimension)