Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rfac.read_sp reads only the first block #655

Open
nshalle opened this issue Oct 17, 2023 · 1 comment
Open

rfac.read_sp reads only the first block #655

nshalle opened this issue Oct 17, 2023 · 1 comment

Comments

@nshalle
Copy link

nshalle commented Oct 17, 2023

After reading the first block of a spectrum file, rfac.read_sp returns without reading the rest. I think there is a logic error in the current recursive implementation of the internal function read_blocks:

        for tr in range(ntrans):
            line = lines[0]
            lines = lines[1:]

            if line.strip() == '':  # if empty
                blocks = read_blocks(lines[i+1:])
                return (block, ) + blocks

            block['block'][tr] = int(line[:6])
            block['level'][tr] = int(line[7:13])
            block['abs. energy'][tr] = float(line[14:27])
            block['population'][tr] = float(line[28:39])
            block['Delta E'][tr] = float(line[14:27])
            block['emissivity'][tr] = float(line[28:39])

        return (block, )

What happens is that the loop reads each transition in the first block without reaching the empty line that follows the list of transitions. So the if line.strip() == "" test is never true, and no recursion happens. Then the loop finishes and returns a single block. In addition, if it did actually get to that section, there would be an error because i is not defined. I've locally edited read_sp in a way that seems to work. I can either open a PR or just post a diff, whatever is easier.

@mfgu
Copy link
Collaborator

mfgu commented Oct 19, 2023

thanks. I will check in a fix shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants