Skip to content

Table_Value fails when X is in decreasing order #1968

Open
@nicriz

Description

@nicriz

Hi @willend,

I was trying to debug a weird behavior of Source_gen4 component with a flux_file, when I found out that the root of the problem was in Table_value returning the wrong value for the flux from the table. The file Lambda/Brilliance I was using had a constant step of 0.1 AA and the values of Lambda in decreasing order from 15AA to 0.2 AA. Now this is what was happening:

  1. Source_gen4 extracts a lambda between Lmin and Lmax, let's say 1.9AA
  2. When Source_gen4 calls Table_value to fix the weight, the constant-time lookup is satisfied
    if(Table.constantstep) {
    Index = (long)floor(
    (X - Table.min_x) / (Table.max_x - Table.min_x) * (Table.rows-1));
    X1 = Table_Index(Table,Index-1,0);
    X2 = Table_Index(Table,Index ,0);
    }
    so Index = 17. But this value of Index is correct only for monotonically increasing bins!
  3. This ultimately breaks when the code checks for the linear search
    // Fall back to linear search, if no-one else has set X1, X2 correctly
    if (!((X1 <= X) && (X < X2))) {
    /* look for index surrounding X in the table -> Index */
    for (Index=1; Index <= Table.rows-1; Index++) {
    X1 = Table_Index(Table, Index-1,0);
    X2 = Table_Index(Table, Index ,0);
    if ((X1 <= X) && (X < X2)) break;
    } /* end for Index */
    }
    which returns always the last bin because the break condition is never fulfilled (X2 is always smaller than X1)

So it seems to me that the function requires monotonically increasing X bins to work, but this is neither enforced anywhere nor documented (as far as I could search). So maybe a flag could be added in 'Table_value' or 'Table_Stat' ?

I could help with that in case,
Best

Nico

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions