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

add ENgetnodesvalues and ENgetlinksvalues methods #786

Merged
merged 3 commits into from
Jun 3, 2024

Conversation

AbelHeinsbroek
Copy link
Contributor

Adds methods for batch requesting node and link property values, see #785 for details.

@AbelHeinsbroek
Copy link
Contributor Author

One possible improvement would be to send an array with indices and only returning the requested node/link indices, or, if an empty array is passed, return all values for all indices.

@LRossman
Copy link
Collaborator

@AbelHeinsbroek can you please resolve the conflicts so we can merge your contribution into dev.

@LRossman LRossman merged commit c131c4c into OpenWaterAnalytics:dev Jun 3, 2024
5 checks passed
@LRossman
Copy link
Collaborator

There is a problem, as noted by compiler warnings, with the newly added functions ENgetnodevalues and ENgetlinkvalues for the legacy API. The code for ENgetnodevalues in epanet2.c is:

int DLLEXPORT ENgetnodevalues(int property, EN_API_FLOAT_TYPE *values)
{
    return EN_getnodevalues(_defaultProject, property, values);
}

where EN_API_FLOAT_TYPE is defined as a 4-byte float. However the EN_getnodevalues function being called expects to see a pointer to an 8-byte double as the type for its values argument. As a result some type of memory corruption will occur. The fix is to rewrite ENgetnodevalues as:

int DLLEXPORT ENgetnodevalues(int property, EN_API_FLOAT_TYPE *values)
{
    int i, errcode = 0;
    EN_API_FLOAT_TYPE value;
    
    for (i = 1; i <= _defaultProject->network.Nnodes; i++)
    {
        errcode = ENgetnodevalue(i, property, &value);
        values[i-1] = value;
        if (errcode != 0) return errcode;
    }
    return 0;
}

The same problem and fix applies to ENgetlinkvalues.

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

Successfully merging this pull request may close these issues.

None yet

2 participants