|
7 | 7 | Authors: see AUTHORS |
8 | 8 | Copyright: see AUTHORS |
9 | 9 | License: see LICENSE |
10 | | - Last Updated: 02/17/2026 |
| 10 | + Last Updated: 03/19/2026 |
11 | 11 | ****************************************************************************** |
12 | 12 | */ |
13 | 13 |
|
@@ -2758,6 +2758,55 @@ int DLLEXPORT EN_setnodevalue(EN_Project p, int index, int property, double valu |
2758 | 2758 | return 0; |
2759 | 2759 | } |
2760 | 2760 |
|
| 2761 | +int DLLEXPORT EN_setnodevalues(EN_Project p, int property, double *values, int *badIndex) |
| 2762 | +/*---------------------------------------------------------------- |
| 2763 | +** Input: property = node property code (see EN_NodeProperty) |
| 2764 | +** values = array of node property values |
| 2765 | +** Output: badIndex = index of node whose assignment fails (0 if none) |
| 2766 | +** Returns: error code |
| 2767 | +** Purpose: sets an array of node property values |
| 2768 | +**---------------------------------------------------------------- |
| 2769 | +*/ |
| 2770 | +{ |
| 2771 | + int i, j, errcode = 0; |
| 2772 | + int n = p->network.Nnodes; |
| 2773 | + double *old = NULL; |
| 2774 | + |
| 2775 | + if (badIndex) *badIndex = 0; |
| 2776 | + |
| 2777 | + old = (double *)malloc(n * sizeof(double)); |
| 2778 | + if (!old) return 101; /* insufficient memory available */ |
| 2779 | + |
| 2780 | + for (i = 1; i <= n; i++) |
| 2781 | + { |
| 2782 | + errcode = EN_getnodevalue(p, i, property, &old[i - 1]); |
| 2783 | + if (errcode != 0) |
| 2784 | + { |
| 2785 | + *badIndex = i; |
| 2786 | + j = i - 1; // Need to restore values for nodes 1 to i-1 |
| 2787 | + } |
| 2788 | + else |
| 2789 | + { |
| 2790 | + errcode = EN_setnodevalue(p, i, property, values[i - 1]); |
| 2791 | + if (errcode != 0) |
| 2792 | + { |
| 2793 | + *badIndex = i; |
| 2794 | + j = i; // Need to restore values for nodes 1 to i |
| 2795 | + } |
| 2796 | + } |
| 2797 | + if (errcode != 0) |
| 2798 | + { |
| 2799 | + for (int k = 1; k <= j; k++) |
| 2800 | + { |
| 2801 | + EN_setnodevalue(p, k, property, old[k - 1]); |
| 2802 | + } |
| 2803 | + break; |
| 2804 | + } |
| 2805 | + } |
| 2806 | + free(old); |
| 2807 | + return errcode; |
| 2808 | +} |
| 2809 | + |
2761 | 2810 | int DLLEXPORT EN_setjuncdata(EN_Project p, int index, double elev, |
2762 | 2811 | double dmnd, const char *dmndpat) |
2763 | 2812 | /*---------------------------------------------------------------- |
@@ -4304,6 +4353,55 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu |
4304 | 4353 | return 0; |
4305 | 4354 | } |
4306 | 4355 |
|
| 4356 | +int DLLEXPORT EN_setlinkvalues(EN_Project p, int property, double *values, int *badIndex) |
| 4357 | +/*---------------------------------------------------------------- |
| 4358 | +** Input: property = link property code (see EN_LinkProperty) |
| 4359 | +** values = array of link property values |
| 4360 | +** Output: badIndex = index of link whose assignment fails (0 if none) |
| 4361 | +** Returns: error code |
| 4362 | +** Purpose: sets property values for all links |
| 4363 | +**---------------------------------------------------------------- |
| 4364 | +*/ |
| 4365 | +{ |
| 4366 | + int i, j, errcode = 0; |
| 4367 | + int n = p->network.Nlinks; |
| 4368 | + double *old = NULL; |
| 4369 | + |
| 4370 | + if (badIndex) *badIndex = 0; |
| 4371 | + |
| 4372 | + old = (double *)malloc(n * sizeof(double)); |
| 4373 | + if (!old) return 101; /* insufficient memory available */ |
| 4374 | + |
| 4375 | + for (i = 1; i <= n; i++) |
| 4376 | + { |
| 4377 | + errcode = EN_getlinkvalue(p, i, property, &old[i - 1]); |
| 4378 | + if (errcode != 0) |
| 4379 | + { |
| 4380 | + *badIndex = i; |
| 4381 | + j = i - 1; // Need to restore values for links 1 to i-1 |
| 4382 | + } |
| 4383 | + else |
| 4384 | + { |
| 4385 | + errcode = EN_setlinkvalue(p, i, property, values[i - 1]); |
| 4386 | + if (errcode != 0) |
| 4387 | + { |
| 4388 | + *badIndex = i; |
| 4389 | + j = i; // Need to restore values for links 1 to i |
| 4390 | + } |
| 4391 | + } |
| 4392 | + if (errcode != 0) |
| 4393 | + { |
| 4394 | + for (int k = 1; k <= j; k++) |
| 4395 | + { |
| 4396 | + EN_setlinkvalue(p, k, property, old[k - 1]); |
| 4397 | + } |
| 4398 | + break; |
| 4399 | + } |
| 4400 | + } |
| 4401 | + free(old); |
| 4402 | + return errcode; |
| 4403 | +} |
| 4404 | + |
4307 | 4405 | int DLLEXPORT EN_setpipedata(EN_Project p, int index, double length, |
4308 | 4406 | double diam, double rough, double mloss) |
4309 | 4407 | /*---------------------------------------------------------------- |
|
0 commit comments