def create_dat(nodout="nodout", dispout="disp.dat", legacynodes=False):
"""create binary data file
:param str nodout: nodout file created by ls-dyna (default="nodout")
:param str dispout: default = "disp.dat"
:param boolean legacynodes: node IDs written every timestep (default=False)
"""
header_written = False
timestep_read = False
timestep_count = 0
writenode = True
with open(nodout, 'r') as nodout:
with open_dispout(dispout) as dispout:
for line in nodout:
if 'nodal' in line:
timestep_read = True
timestep_count += 1
data = []
continue
if timestep_read is True:
if line[0:2] == '\n': # done reading the time step
timestep_read = False
# if this was the first time, everything needed to
# be read to # get node count for header
if not header_written:
header = generate_header(data, nodout)
write_headers(dispout, header)
header_written = True
print('Time Step: ', end="", flush=True)
if timestep_count > 1 and not legacynodes:
writenode = False
print("%i, " % timestep_count, end="", flush=True)
process_timestep_data(data, dispout, writenode)
else:
raw_data = parse_line(line)
data.append(list(raw_data))
print("done.", flush=True)
return 0
评论列表
文章目录