ladisk / pyuff

This module defines an UFF class to manipulate with the UFF (Universal File Format) files.
Other
58 stars 40 forks source link

_extract55: Type 55 Dataset without spaces #84

Closed skander27 closed 9 months ago

skander27 commented 9 months ago

sample_test.unv.txt Hello, when loading a UFF Type 55 Dataset (sample file attached) that contains no spaces in the Record 10 values with:

uff_file = pyuff.UFF('sample_test.unv')
c1_data = uff_file.read_sets()

I get the following error:

File ~/.local/lib/python3.10/site-packages/pyuff/datasets/dataset_55.py:507, in <listcomp>(.0)
    506 split_data = ''.join(split_data[10:])
--> 507 values = np.asarray([float(str) for str in split_data.split()], 'd')
ValueError: could not convert string to float: '0.000000E+00-4.111111E-02-1.111111E-02'

Due to the negative sign, there are no spaces between the values. Proposed modification:

        ########Modification2############
        values = []
        for s in split_data[10:]:
            s = s.replace('\n','')
            s = s.replace('\r','')
            if 'E' in s:
                n = s.count('E')
                while n>0:
                    i=s.find('E')
                    val, s = s[:i+4], s[i+4:]
                    values = np.append(values,float(val))
                    n = s.count('E')
            else:
                values = np.append(values,float(s))

        ########Modification2############
        ########Original############
        #split_data = ''.join(split_data[10:])
        #values = np.asarray([float(str) for str in split_data.split()], 'd')
        ########Original############

I am not sure, if the issue occurs elsewhere with other dataset types.

Regards, Skander

jankoslavic commented 9 months ago

Dear Skander! Please check out this branch: https://github.com/ladisk/pyuff/tree/update_55_spaces

skander27 commented 9 months ago

Dear Prof. Slavič, it works perfectly now, thank you! Regards, Skander

jankoslavic commented 9 months ago

ok, this PR is now merged into main and will be included into next release :)

jankoslavic commented 9 months ago

and closed:)