diff --git a/src/funcs.h b/src/funcs.h index 04a2c66c4..4267e20a5 100644 --- a/src/funcs.h +++ b/src/funcs.h @@ -295,6 +295,7 @@ double massbal_getFlowError(void); int massbal_getRoutingFlowTotal(TRoutingTotals *routingTot); // For API int massbal_getRunoffTotal(TRunoffTotals *runoffTot); // For API double massbal_getTotalArea(void); // For API +int massbal_getNodeTotalInflow(int index, double *value); // For API //----------------------------------------------------------------------------- // Simulation Statistics Methods diff --git a/src/massbal.c b/src/massbal.c index 504ca1a1b..06762fbc8 100644 --- a/src/massbal.c +++ b/src/massbal.c @@ -1150,4 +1150,30 @@ double massbal_getTotalArea(void) // Purpose: Used for Toolkit API Unit Conversion { return TotalArea; +} + +int massbal_getNodeTotalInflow(int index, double *value) +// +// Input: NodeIndex +// Output: Volume +// Return: Error +// Purpose: Used for ToolkitAPI to pull total Node Inflow. +{ + int errorcode = 0; + + // Check if Open + if (swmm_IsOpenFlag() == FALSE) + { + errorcode = ERR_API_INPUTNOTOPEN; + } + // Check if Simulation is Running + else if (swmm_IsStartedFlag() == FALSE) + { + errorcode = ERR_API_SIM_NRUNNING; + } + else + { + *value = NodeInflow[index]; + } + return errorcode; } \ No newline at end of file diff --git a/src/toolkitAPI.c b/src/toolkitAPI.c index 7cce3d6ee..eb0a95673 100644 --- a/src/toolkitAPI.c +++ b/src/toolkitAPI.c @@ -774,7 +774,7 @@ int DLLEXPORT swmm_getNodeStats(int index, TNodeStats *nodeStats) if (errorcode == 0) { // Current Average Depth - nodeStats->avgDepth *= (UCF(LENGTH) / StepCount); + nodeStats->avgDepth *= (UCF(LENGTH) / (double)StepCount); // Current Maximum Depth nodeStats->maxDepth *= UCF(LENGTH); // Current Maximum Lateral Inflow @@ -800,6 +800,24 @@ int DLLEXPORT swmm_getNodeStats(int index, TNodeStats *nodeStats) return (errorcode); } +int DLLEXPORT swmm_getNodeTotalInflow(int index, double *value) +// +// Input: Node Index +// Output: Node Total inflow Volume. +// Return: API Error +// Purpose: Get Node Total Inflow Volume. +{ + + int errorcode = massbal_getNodeTotalInflow(index, value); + + if (errorcode == 0) + { + *value *= UCF(VOLUME); + } + + return(errorcode); +} + int DLLEXPORT swmm_getStorageStats(int index, TStorageStats *storageStats) // // Output: Storage Node Stats Structure (TStorageStats) @@ -813,7 +831,7 @@ int DLLEXPORT swmm_getStorageStats(int index, TStorageStats *storageStats) // Initial Volume storageStats->initVol *= UCF(VOLUME); // Current Average Volume - storageStats->avgVol *= (UCF(VOLUME) / StepCount); + storageStats->avgVol *= (UCF(VOLUME) / (double)StepCount); // Current Maximum Volume storageStats->maxVol *= UCF(VOLUME); // Current Maximum Flow @@ -841,7 +859,14 @@ int DLLEXPORT swmm_getOutfallStats(int index, TOutfallStats *outfallStats) if (errorcode == 0) { // Current Average Flow - outfallStats->avgFlow *= (UCF(FLOW) / StepCount); + if ( outfallStats->totalPeriods > 0 ) + { + outfallStats->avgFlow *= (UCF(FLOW) / (double)outfallStats->totalPeriods); + } + else + { + outfallStats->avgFlow *= 0.0; + } // Current Maximum Flow outfallStats->maxFlow *= UCF(FLOW); // Convert Mass Units @@ -922,7 +947,14 @@ int DLLEXPORT swmm_getPumpStats(int index, TPumpStats *pumpStats) // Cumulative Minimum Flow pumpStats->minFlow *= UCF(FLOW); // Cumulative Average Flow - pumpStats->avgFlow *= (UCF(FLOW) / StepCount); + if (pumpStats->totalPeriods > 0) + { + pumpStats->avgFlow *= (UCF(FLOW) / (double)pumpStats->totalPeriods); + } + else + { + pumpStats->avgFlow *= 0.0; + } // Cumulative Maximum Flow pumpStats->maxFlow *= UCF(FLOW); // Cumulative Pumping Volume diff --git a/src/toolkitAPI.h b/src/toolkitAPI.h index 2862d53c4..840d70074 100644 --- a/src/toolkitAPI.h +++ b/src/toolkitAPI.h @@ -69,6 +69,7 @@ int DLLEXPORT swmm_setSimulationDateTime(int timetype, char *dtimestr); int DLLEXPORT swmm_getCurrentDateTimeStr(char *dtimestr); int DLLEXPORT swmm_getNodeStats(int index, TNodeStats *nodeStats); +int DLLEXPORT swmm_getNodeTotalInflow(int index, double *value); int DLLEXPORT swmm_getStorageStats(int index, TStorageStats *storageStats); int DLLEXPORT swmm_getOutfallStats(int index, TOutfallStats *outfallStats); void DLLEXPORT swmm_freeOutfallStats(TOutfallStats *outfallStats);