@@ -187,9 +187,21 @@ def read(filename, read_parameters=False, debug=False):
187187
188188 # element number and element type
189189 et_val = line.decode().split(' ,' )
190- elem_type.append([int (et_val[1 ]), int (et_val[2 ])])
190+ try :
191+ int (et_val[1 ])
192+ elem_type.append([int (et_val[1 ]), int (et_val[2 ])])
193+ except :
194+ if debug:
195+ print (' Invalid "ET" command %s ' % line.decode())
196+ continue
191197
192198 elif b' EBLOCK,' == line[:7 ] or b' eblock,' == line[:7 ]:
199+ if eblock_read:
200+ # Sometimes, DAT files contain two EBLOCKs. Read
201+ # only the first block.
202+ if debug:
203+ print (' EBLOCK already read, skipping...' )
204+ continue
193205 if debug:
194206 print (' reading EBLOCK' )
195207
@@ -283,6 +295,10 @@ def read(filename, read_parameters=False, debug=False):
283295 elif ' N' == line[0 ] or ' n' == line[0 ]:
284296 # if line contains the start of the node block
285297 if line[:6 ] == b' NBLOCK' or line[:6 ] == b' nblock' :
298+ if nodes_read:
299+ if debug:
300+ print (' Skipping additional NBLOCK' )
301+ continue
286302 start_pos = n
287303 if debug:
288304 print (' reading NBLOCK' )
@@ -385,38 +401,36 @@ def read(filename, read_parameters=False, debug=False):
385401 elif b' ELEM' in line_comp_type:
386402 elem_comps[comname] = component_interperter(component)
387403
388- elif ' *' == line[0 ] and read_parameters: # dim
404+ elif ' *' == line[0 ] and read_parameters: # maybe *DIM
389405 if b' DIM' in line:
390- _, name, _, dim0, dim1, dim2, _ = line.decode().split(' ,' )
391-
392- # dim = []
393- # for d in [dim0, dim1, dim2]:
394- # if d.strip():
395- # dim.append(int(d))
396-
397- # while dim[-1] == 1:
398- # if len(dim) == 1:
399- # break
400- # del dim[-1]
401-
402- # init_arr = np.zeros(np.prod(dim))
406+ items = line.decode().split(' ,' )
407+ if len (items) < 3 :
408+ continue
403409
404- myfgets(line, raw, & n, fsize)
405- if b' PREAD' in line:
406- if debug:
407- print (' reading PREAD' )
410+ name = items[1 ]
411+ if items[2 ].lower() == ' string' :
412+ myfgets(line, raw, & n, fsize)
413+ string_items = line.decode().split(' =' )
414+ if len (string_items) > 1 :
415+ parameters[name] = string_items[1 ].replace(" '" , ' ' ).strip()
416+ else :
417+ parameters[name] = line.decode()
418+ elif items[2 ].lower() == ' array' :
419+ myfgets(line, raw, & n, fsize)
420+ if b' PREAD' in line:
421+ if debug:
422+ print (' reading PREAD' )
408423
409- _, name, arr_size = line.decode().split(' ,' )
410- name = name.strip()
411- st = n
412- en = raw.find(b' END PREAD' , n)
413- if debug:
414- print (st, en)
415- if st != - 1 and en != - 1 :
416- lines = raw[st:en].split()
417- arr = np.genfromtxt(raw[st:en].split())
418- # init_arr[arr.size] = arr
419- parameters[name] = arr
424+ _, name, arr_size = line.decode().split(' ,' )
425+ name = name.strip()
426+ st = n
427+ en = raw.find(b' END PREAD' , n)
428+ if debug:
429+ print (st, en)
430+ if st != - 1 and en != - 1 :
431+ lines = raw[st:en].split()
432+ arr = np.genfromtxt(raw[st:en].split())
433+ parameters[name] = arr
420434
421435 # if the node block was not read for some reason
422436 if not nodes_read:
0 commit comments