Skip to content

ValueError raised when reading ascii OP4 where floating point number does not contain "E" #29

@meshing-monkey

Description

@meshing-monkey

Hello,

I'm getting an exception when reading ascii OP4 files using the op4.load function. This happens with files containing floating point numbers that don't have an "E" before the exponent, because these strings can't be converted to Python floats. The exception is shown below, and originates in the op4.op4 _put_ascii_values method. I patched op4.py to deal with this case (attached in the zip file as op4_patched.py): I just insert an E to get the float conversion to work; it looks like there are other methods in op4 that could be affected.

The offending op4 matrix is in the attached zip file (test.op4).

mats = op4.load('test.op4')


ValueError Traceback (most recent call last)
Cell In[2], line 1
----> 1 mk = op4.load('test.op4')

File ~\AppData\Local\anaconda3\Lib\site-packages\pyyeti\nastran\op4.py:2291, in load(filename, namelist, into, justmatrix, sparse)
2289 filename = guitools.get_file_name(filename, read=True)
2290 if into == "dct":
-> 2291 return OP4().dctload(filename, namelist, justmatrix, sparse)
2292 elif into == "list":
2293 return OP4().listload(filename, namelist, sparse)

File ~\AppData\Local\anaconda3\Lib\site-packages\pyyeti\nastran\op4.py:1779, in OP4.dctload(self, filename, namelist, justmatrix, sparse)
1777 loadfunc = self._loadop4_binary
1778 while 1:
-> 1779 name, X, form, mtype = loadfunc(patternlist=namelist, sparse=sparse)
1780 if not name:
1781 break

File ~\AppData\Local\anaconda3\Lib\site-packages\pyyeti\nastran\op4.py:718, in OP4._loadop4_ascii(self, patternlist, listonly, sparse)
715 sparse, sparsefunc = OP4._get_sparsefunc(sparse)
717 rdfunc, funcs = self._get_funcs("ascii", rows, r,
mtype, sparse, c >= cols)
--> 718 X = rdfunc(wper, r, c, abs(rows), cols, line, numlen, perline, linelen, funcs)
720 if sparsefunc and sp.issparse(X):
721 X = sparsefunc(X)

File ~\AppData\Local\anaconda3\Lib\site-packages\pyyeti\nastran\op4.py:496, in OP4._rd_bigmat_ascii(self, wper, r, c, rows, cols, line, numlen, perline, linelen, funcs)
494 L //= wper
495 s = self._get_ascii_block(L, perline, linelen)
--> 496 put(X, r, c, s, L, numlen)
497 line = self._fileh.readline()
498 c = int(line[c_slice]) - 1

File ~\AppData\Local\anaconda3\Lib\site-packages\pyyeti\nastran\op4.py:402, in OP4._put_ascii_values(X, r, c, s, L, numlen)
400 for i in range(L):
401 b = a + numlen
--> 402 X[r + i, c] = s[a:b]
403 a = b

ValueError: could not convert string to float: ' 1.679082097391476-318'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions