(ATCScript "WatershedSummaryReport" (Arg "CurScenario" "CurScenario") (Arg "PerConstituent" "PERO") (Arg "ImpConstituent" "SURO") (Arg "PerImpConv" "8687.6") (Arg "PerImpUnits" "inches") (Arg "RchConstituent" "ROVOL") (Arg "RchConv" "723.97") (Arg "RchUnits" "ac-ft") (Arg "PtConstituent" (Array "FLOW")) (Arg "PtConv" "1.0") (Arg "PtUnits" "cfs") (Arg "PtScenario" "PT-OBS") (Arg "AreaUnits" "acres") (Arg "TotalUnits" "cfs") (Arg "HspfAggregation" "Mean" (Array "Max" "Min" "Mean" "Geometric Mean" "Sum" "StdDeviation" "Variance")) (Arg "HspfTimeUnits" "Year" (Array "Second" "Minute" "Hour" "Month" "Year")) (Arg "HspfTimeStep" 1) (Arg "HspfnVals" 1) (Arg "TotalsOption" 1) (Arg "DistrictSummaryFileName" "NoSummary") (LoadLibrary "ATCScriptData" "ATCScriptGrid" "ATCScriptHspf" "ATCScriptFile" "ATCScriptMisc") (Set CRLF (+ (Chr 13) (Chr 10))) (Set FF "") (Set Space30 " ") (Select gCurConstituent (Case "FColi" (Set lNumFormat "##,##0.00")) (Case "PERO" (Set lNumFormat "#,##0.000")) (Case "BOD" (Set lNumFormat "#,##0.000")) (Case "OrganicN" (Set lNumFormat "#,##0.000")) (Case "OrganicP" (Set lNumFormat "#,##0.000")) (Case "DO" (Set lNumFormat "#,##0.000")) (Case "Flow" (Set lNumFormat "#,##0.000")) (Case "Lead" (Set lNumFormat "#,##0.000")) (Case "NH3" (Set lNumFormat "#,##0.000")) (Case "NO3" (Set lNumFormat "#,##0.000")) (Case "PO4" (Set lNumFormat "#,##0.000")) (Case "Sed" (Set lNumFormat "#,##0.000")) (Case "Zinc" (Set lNumFormat "#,##0.000")) ) (If (= gCurConstituent "BOD") (Set lBODMultiplier 0.4) (Else (If (= gCurConstituent "OrganicN") (Set lBODMultiplier 0.069) (Else (If (= gCurConstituent "OrganicP") (Set lBODMultiplier 0.0052) ) ) ) ) ) (Unset WatershedSummary) ('grid might be left over from prev call, need a new one) (Set lReportString "") (Set lHspfStartInterval (HspfSJDate)) (Set ltmpHspfStartInterval lHspfStartInterval) (While (< ltmpHspfStartInterval (HspfEJDate)) (Set lHspfEndInterval (JDateAdd ltmpHspfStartInterval HspfTimeUnits HspfTimeStep HspfnVals)) (Grid "WatershedSummary" 8 10) (' Start with 8 columns and 10 rows - rows will expand as necessary, columns won't) (Set CurRow 0) (Grid 1 (++ CurRow) (+ "Watershed Summary Report for Scenario [" CurScenario "]" )) (Grid 1 (++ CurRow) (+ " Run Made " (Format (FileAttribute (+ InputDir CurScenario ".hbn") "date") "yyyy-mm-dd hh:mm"))) (Grid 1 (++ CurRow) " Average Annual Rates and Totals") (Grid 1 (++ CurRow) (+ " " gHspfRunInfo)) (Grid 1 (++ CurRow) (+ " Time Span: " HspfnVals " " HspfTimeUnits " from " (Format ltmpHspfStartInterval "mm/dd/yy") " to " (Format lHspfEndInterval "mm/dd/yy"))) (+= CurRow 2) (If (= PerConstituent "BOD/ORGANICS-POQUAL") (Grid 1 CurRow (+ " " gCurConstituent)) (Else (Grid 1 CurRow (+ " " PerConstituent "/" ImpConstituent "/" (ArrayItem PtConstituent 1) "/" RchConstituent))) ) (+= CurRow 2) (Set NextRow (+ CurRow 1)) (Set NextRow2 (+ CurRow 2)) (Grid 1 CurRow (Format "Land Use" Space30)) (Grid 1 NextRow (Format " " Space30)) (Grid 1 NextRow2 (Format " " Space30)) (Grid 2 CurRow "Perv.") (Grid 2 NextRow PerImpUnits) (Grid 2 NextRow2 (Mid PerConstituent (+ (InStr PerConstituent "-") 1))) (Grid 3 CurRow "Imperv." ) (Grid 3 NextRow PerImpUnits) (Grid 3 NextRow2 (Mid ImpConstituent (+ (InStr ImpConstituent "-") 1))) (Grid 4 CurRow "Eff.Imp.") (Grid 5 CurRow "Combined") (Grid 5 NextRow PerImpUnits) (Grid 6 CurRow "Area") (Grid 6 NextRow AreaUnits) (Grid 7 CurRow "Total") (Grid 7 NextRow TotalUnits) (Grid 8 CurRow "% GrTot.") (+= CurRow 2) (Set TotNonPointPerVal 0) (Set TotNonPointImpVal 0) (Set TotNonPointPerArea 0) (Set TotNonPointImpArea 0) (Set TotNonPointArea 0) (Set GrandTotal 0) (Set TopTotalRow CurRow) (Set MetSegCnt 0) (Set MetSegs (HspfMetSegs)) (For HspfMetSeg In MetSegs (Increment MetSegCnt) (Grid 1 (++ CurRow) (Format HspfMetSeg Space30)) ('Reset running segment totals) (Set TotSegPerVal 0) (Set TotSegImpVal 0) (Set TotSegPerArea 0) (Set TotSegImpArea 0) (Set TotSegArea 0) (Set SegGrandTotal 0) (Set LandUses (HspfLandUses)) (For LandUse in LandUses (If (= MetSegCnt 1) ('Initialize running totals by land use) (RunScript (+ "(Set " (ReplaceString LandUse " " "") "PerLandVal 0)")) (RunScript (+ "(Set " (ReplaceString LandUse " " "") "ImpLandVal 0)")) (RunScript (+ "(Set " (ReplaceString LandUse " " "") "PerLandArea 0)")) (RunScript (+ "(Set " (ReplaceString LandUse " " "") "ImpLandArea 0)")) (RunScript (+ "(Set " (ReplaceString LandUse " " "") "TotalLandArea 0)")) ) (Set PerArea (HspfArea LandUse 1)) (Set ImpArea (HspfArea LandUse 0)) (Set TotalArea (+ PerArea ImpArea)) (+= TotSegPerArea PerArea) (+= TotSegImpArea ImpArea) (+= TotSegArea PerArea ImpArea) (RunScript (+ "(+= " (ReplaceString LandUse " " "") "PerLandArea PerArea)")) (RunScript (+ "(+= " (ReplaceString LandUse " " "") "ImpLandArea ImpArea)")) (RunScript (+ "(+= " (ReplaceString LandUse " " "") "TotalLandArea PerArea ImpArea)")) (Set PerData (HspfBinData LandUse "PERLND" PerConstituent)) (If (= PerConstituent "BOD/ORGANICS-POQUAL") (Set PerData (DataTSer PerData "Math" "Mult" lBODMultiplier)) ) (Set DataSubset (DataTser PerData SubSetByDate ltmpHspfStartInterval lHspfEndInterval)) (Set PerVal (DataTser DataSubset "Attrib" HspfAggregation)) (If (= HspfAggregation "Sum") (Set PerVal (/ PerVal HspfnVals)) ) (+= TotSegPerVal (* PerVal PerArea)) (RunScript (+ "(+= " (ReplaceString LandUse " " "") "PerLandVal (* PerVal PerArea))")) (If (Not (IsNumeric PerVal)) (Set PerVal 0) ) (Set ImpData (HspfBinData LandUse "IMPLND" ImpConstituent)) (If (= PerConstituent "BOD/ORGANICS-POQUAL") (Set ImpData (DataTSer ImpData "Math" "Mult" lBODMultiplier)) ) (Set DataSubset (DataTser ImpData SubSetByDate ltmpHspfStartInterval lHspfEndInterval)) (Set ImpVal (DataTser DataSubset "Attrib" HspfAggregation)) (If (= HspfAggregation "Sum") (Set ImpVal (/ ImpVal HspfnVals)) ) (+= TotSegImpVal (* ImpVal ImpArea)) (RunScript (+ "(+= " (ReplaceString LandUse " " "") "ImpLandVal (* ImpVal ImpArea))")) (If (Not (IsNumeric ImpVal)) (Set ImpVal 0) ) (Set Total (+ (* PerArea PerVal) (* ImpArea ImpVal))) (++ CurRow) (Grid 1 CurRow (Format LandUse Space30)) (Grid 2 CurRow (Format PerVal lNumFormat)) (Grid 3 CurRow (Format ImpVal lNumFormat)) (If (= TotalArea 0) (Grid 4 CurRow "0%") (Grid 5 CurRow (Format 0 lNumFormat)) (Else (Grid 4 CurRow (Format (/ ImpArea TotalArea) "##0%")) (Grid 5 CurRow (Format (/ Total TotalArea) lNumFormat)) ) ) (Grid 6 CurRow (Format TotalArea "#,###,##0")) (Set Total (/ Total PerImpConv)) (Grid 7 CurRow (Format Total "#,###,##0")) (+= SegGrandTotal Total) ) (+= GrandTotal SegGrandTotal) (++ CurRow) ('Insert totals row for current HspfMetSeg) (++ CurRow) (Set Total (+ TotSegPerVal TotSegImpVal)) (Grid 1 CurRow (Format "Seg Wtd Aver/Tot" Space30)) (If (= TotSegPerArea 0) (Grid 2 CurRow "0%") (Else (Grid 2 CurRow (Format (/ TotSegPerVal TotSegPerArea) lNumFormat)) ) ) (If (= TotSegImpArea 0) (Grid 3 CurRow "0%") (Else (Grid 3 CurRow (Format (/ TotSegImpVal TotSegImpArea) lNumFormat)) ) ) (If (= TotSegArea 0) (Grid 4 CurRow "0%") (Grid 5 CurRow (Format 0 lNumFormat)) (Else (Grid 4 CurRow (Format (/ TotSegImpArea TotSegArea) "##0%")) (Grid 5 CurRow (Format (/ Total TotSegArea) lNumFormat)) ) ) (Grid 6 CurRow (Format TotSegArea "#,###,##0")) (Grid 7 CurRow (Format SegGrandTotal "#,###,##0")) (++ CurRow) (+= TotNonPointPerVal TotSegPerVal) (+= TotNonPointImpVal TotSegImpVal) (+= TotNonPointPerArea TotSegPerArea) (+= TotNonPointImpArea TotSegImpArea) (+= TotNonPointArea TotSegArea) ) ('Insert totals block for non-point sources) (++ CurRow) (Grid 1 CurRow "Totals for all Non-Point Source Segments") (++ CurRow) (For LandUse in LandUses (RunScript (+ "(Set Total (+ " (ReplaceString LandUse " " "") "PerLandVal " (ReplaceString LandUse " " "") "ImpLandVal))")) (Grid 1 CurRow (Format LandUse Space30)) (RunScript (+ "(Set tmpVal " (ReplaceString LandUse " " "") "PerLandVal)")) (If (<> tmpVal 0) (RunScript (+ "(Set " (ReplaceString LandUse " " "") "PerLandVal (/ " (ReplaceString LandUse " " "") "PerLandVal " (ReplaceString LandUse " " "") "PerLandArea))")) (RunScript (+ "(Grid 2 CurRow (Format " (ReplaceString LandUse " " "") "PerLandVal lNumFormat))")) ) (UnSet tmpVal) (RunScript (+ "(Set tmpVal " (ReplaceString LandUse " " "") "ImpLandVal)")) (If (<> tmpVal 0) (RunScript (+ "(Set " (ReplaceString LandUse " " "") "ImpLandVal (/ " (ReplaceString LandUse " " "") "ImpLandVal " (ReplaceString LandUse " " "") "ImpLandArea))")) (RunScript (+ "(Grid 3 CurRow (Format " (ReplaceString LandUse " " "") "ImpLandVal lNumFormat))")) ) (UnSet tmpVal) (RunScript (+ "(Set tmpVal " (ReplaceString LandUse " " "") "TotalLandArea)")) (If (= tmpVal 0) (Grid 4 CurRow "0%") (Grid 5 CurRow (Format 0 lNumFormat)) (Else (RunScript (+ "(Grid 4 CurRow (Format (/ " (ReplaceString LandUse " " "") "ImpLandArea " (ReplaceString LandUse " " "") "TotalLandArea) ##0%))")) (RunScript (+ "(Grid 5 CurRow (Format (/ Total " (ReplaceString LandUse " " "") "TotalLandArea) lNumFormat))")) ) ) (UnSet tmpVal) (RunScript (+ "(Grid 6 CurRow (Format " (ReplaceString LandUse " " "") "TotalLandArea #,###,##0))")) (Grid 7 CurRow (Format (/ Total PerImpConv) "#,###,##0")) (++ CurRow) ) ('Insert totals row for all non-point sources) (++ CurRow) (Set Total (+ TotNonPointPerVal TotNonPointImpVal)) (Set TotNonPointPerVal (/ TotNonPointPerVal TotNonPointPerArea)) (Set TotNonPointImpVal (/ TotNonPointImpVal TotNonPointImpArea)) (Grid 1 CurRow (Format "Non-Pnt Wtd Aver/Tot" Space30)) (Grid 2 CurRow (Format TotNonPointPerVal lNumFormat)) (Grid 3 CurRow (Format TotNonPointImpVal lNumFormat)) (If (= TotNonPointArea 0) (Grid 4 CurRow "0%") (Grid 5 CurRow (Format 0 lNumFormat)) (Else (Grid 4 CurRow (Format (/ TotNonPointImpArea TotNonPointArea) "##0%")) (Grid 5 CurRow (Format (/ Total TotNonPointArea) lNumFormat)) ) ) (Grid 6 CurRow (Format TotNonPointArea "#,###,##0")) (Grid 7 CurRow (Format GrandTotal "#,###,##0")) (Set lCurHUC10NonPtLoad GrandTotal) (++ CurRow) ('Starting Point Sources) (Set PtSources (HspfPtSources)) (If (> (Len PtSources) 0) (Grid 1 (++ CurRow) (+ "Point Sources " (ArrayItem PtConstituent 1))) (Set PointTotal 0) (Set lCurHUC10PtSourceLoad 0) (Set lCurHUC10UpstreamLoad 0) (For PtSource in PtSources (++ CurRow) (Grid 1 CurRow (Format (Mid PtSource 1 30) Space30)) (' check all possible names of PtConstituent) (Set lPtCounter 0) (For lPtConstituentCounter = 1 to (Len PtConstituent) (' set TS of current constituent name) (Unset lPtData) (Set lPtData (HspfPointData PtScenario PtSource (ArrayItem PtConstituent lPtConstituentCounter))) (Set lPtDataCount (Len (DataTSer lPtData Values))) (If (> lPtDataCount 0) (' TS has been successfully set) (If (= HspfAggregation "Sum") (DataTSer lPtData "Aggregate" HspfTimeUnits 1 "sum") (Else (DataTSer lPtData "Aggregate" HspfTimeUnits 1 "ave") ) ) (Set lPtData (DataTser lPtData SubSetByDate ltmpHspfStartInterval lHspfEndInterval)) (If (= lPtCounter 0) (' 1st of possibly multiple TS to be aggregated) (Unset PtData) (Set PtData (DataTSer lPtData Copy)) (Set PtDataCount lPtDataCount) (Else (If (= lPtDataCount PtDataCount) (' same # of vals in this TS as in 1st TS - OK to add) (AppendFile (+ ProjectDir "TimeSeriesAdditions.txt") (+ lCurHuc10 " " CurScenario " " gCurConstituent " " PtSource " " lPtCounter " (" (DataTSer lPtData "Attrib" "IDCONS") ":" (DataTSer lPtData "Attrib" "File") ":" (DataTSer lPtData "Attrib" "DSN") ")" " (" (DataTSer PtData "Attrib" "IDCONS") ":" (DataTSer PtData "Attrib" "File") ":" (DataTSer PtData "Attrib" "DSN") ")" CRLF)) (Set PtData (DataTSer PtData "Math" "Add" lPtData)) (Else (' different # of vals in this TS as in 1st TS - CAN NOT ADD) (AppendFile (+ ProjectDir "CountProblem.txt") (+ lCurHuc10 " " CurScenario " " gCurConstituent " " PtSource " (" (DataTSer lPtData "Attrib" "IDCONS") ":" (DataTSer lPtData "Attrib" "File") ":" (DataTSer lPtData "Attrib" "DSN") ")" " " lPtDataCount " (" (DataTSer PtData "Attrib" "IDCONS") ":" (DataTSer PtData "Attrib" "File") ":" (DataTSer PtData "Attrib" "DSN") ")" " " PtDataCount CRLF ) ) ) ) ) ) (Increment lPtCounter) ) ) (If (= lPtCounter 0) (Set Total 0) (Else (Set Total (DataTser PtData "Attrib" HspfAggregation)) (If (= HspfAggregation "Sum") (Set Total (/ Total HspfnVals)) ) ) ) (Set Debug On) (If (Not (And (= gCurConstituent "Sed") (IsNumeric (Mid PtSource 1 8)) ) ) (Set Total (/ Total PtConv)) ) (Grid 7 CurRow (Format Total "#,###,##0")) (If (= PtSource "Septic Failure") (Set lCurHUC10SepticLoad Total) (Else (If (= (Mid PtSource 1 1) "0") (+= lCurHUC10UpstreamLoad Total) (Else (+= lCurHUC10PtSourceLoad Total) ) ) ) ) (+= PointTotal Total) ) (+= GrandTotal PointTotal) (++ CurRow) (++ CurRow) (Grid 1 CurRow (Format "Point Wtd Aver/Tot" Space30)) (Grid 7 CurRow (Format PointTotal "#,###,##0")) (Else (Grid 1 (++ CurRow) "No Point Sources") ) ) (++ CurRow) (Set Reaches (HspfReaches)) (If (> (Len Reaches) 0) (Grid 1 (++ CurRow) (+ "Reaches " RchConstituent)) (Set lReachCounter 0) (For Reach in Reaches (Increment lReachCounter) (Grid 1 (++ CurRow) (Format Reach Space30)) ('DataTser RchData Attrib ) (Set RchData (HspfBinData Reach "RCHRES" RchConstituent)) (If (= PerConstituent "BOD/ORGANICS-POQUAL") (Set RchData (DataTSer RchData "Math" "Mult" lBODMultiplier)) ) (Set DataSubset (DataTser RchData SubSetByDate ltmpHspfStartInterval lHspfEndInterval)) (Set Total (DataTser DataSubset "Attrib" HspfAggregation)) (If (= HspfAggregation "Sum") (Set Total (/ Total HspfnVals)) ) (Set Total (/ Total RchConv)) (Grid 7 CurRow (Format Total "#,###,##0")) (If (<> DistrictSummaryFileName "NoSummary") (AppendFile (+ ProjectDir "TotalLoad." DistrictSummaryFileName) (+ (Mid Reach 8 13) (Chr 9) gCurConstituent (Chr 9) (Format Total "##########0.0") CRLF) ) ) (If (= lReachCounter (Len Reaches)) (Set lCurHUC10ExitLoad Total) (Set lCurHUC10 (Mid Reach 8 10)) ) ) (Else (Grid 1 (++ CurRow) "No Reaches") ) ) (++ CurRow) (Grid 1 (++ CurRow) (Format "Grand Total" Space30)) (Grid 7 CurRow (Format GrandTotal "#,###,##0")) (Set GrandTotalRow CurRow) (If (> GrandTotal 0) (For CurRow TopTotalRow (- GrandTotalRow 1) (Set Total (Grid 7 CurRow)) (If (IsNumeric Total) (Grid 8 CurRow (Format (/ Total GrandTotal) "###0.0%")) ) ) ) (+= lReportString (+ FF (Grid "AsString" "" CRLF " "))) (Set FF (Chr 12)) (Set ltmpHspfStartInterval lHspfEndInterval) ) (If (<> DistrictSummaryFileName "NoSummary") (AppendFile (+ gProjectDir DistrictSummaryFileName) (+ (Format lCurHUC10 "##########") (Chr 9) (Format CurScenario " ") (Chr 9) (Format gCurConstituent " ") (Chr 9) (Format lCurHUC10NonPtLoad "#########0") (Chr 9) (Format lCurHUC10SepticLoad "#########0") (Chr 9) (Format lCurHUC10PtSourceLoad "#########0") (Chr 9) (Format lCurHUC10UpstreamLoad "#########0") (Chr 9) (Format lCurHUC10ExitLoad "#########0") CRLF ) ) ) (Unset ltmpHspfStartInterval) (Unset CurConstituent) (Unset PerData) (Unset ImpData) (Unset RchData) (Unset DataSubset) (Unset WatershedSummary) ('grid might be left over from prev call, need a new one) (Return lReportString) (Unset lReportString) ) )