Showing posts with label Wayne Huber. Show all posts
Showing posts with label Wayne Huber. Show all posts

Sunday, July 2, 2017

How Calibration Plots were made in #SWMM4 and #SWMM3

How Calibration Plots were made in #SWMM4 and #SWMM3 - I remember these being very useful in SWMM classes with Wayne Huber at UF.

      SUBROUTINE GRAPH
C     GRAPH BLOCK
C=======================================================================
C     THIS ROUTINE PREPARES SIMULATED AND MEASURED HYDROGRAPHS,
C     POLLUTOGRAPHS  AND LOADOGRAPHS FOR PLOTTING BY SUBROUTINE CURVE.
C     SIMULATED AND/OR MEASURED DATA MAY BE PLOTTED.  IT IS NO LONGER
C     POSSIBLE TO PLOT MORE THAN ONE LOCATION ON ONE GRAPH.
C     THIS ROUTINE LAST UPDATED BY W. HUBER, AUGUST 1993.
C     SCRATCH FILE 1 NOT USED.  DON'T OPEN.  WCH, 4/18/94.
C     Change NQP to NQPP to avoid confusion cim 9/9/00
C     Add error message for E3 lines, WCH, 9/14/00.
C     Fix metric conversion error.  Inflows on interface file from
C       all blocks will be in cms if metric is used.  WCH, 9/14/00.
C     Uses nscrat(8) for MFILE input file, added features for FREE 
c     formatted input - RED, 9/15/00
C     Add more error messages, WCH, 9/16/00.
C=======================================================================
      INCLUDE 'TAPES.INC'
      INCLUDE 'INTER.INC'
      INCLUDE 'LAB.INC'
C=======================================================================
C#### WCH (CDM), 8/93. REMOVE NEWFIL*60
      CHARACTER KPRED(20)*10,KMEAS(20)*10,JMEAS(20)*10
      CHARACTER PNDUM*8,PUDUM*8,VER1*10,VER2*10,VER3*10,VER4*10,
     +          PRIN(3)*14,FIRMAT*80,DEFMT*16,HORIZG(2)*30,
     +          VERM(4)*10,USE*4,PPNAME*8,PPUNIT*8,ZX(2)*20,BMJ*4
      DIMENSION X(401,2),Y(401,2),NPT(2),JPLOT(20),
     1          YT(401,6),ITAB(20),IPLOT(20),MTAB(20),KPLOT(20),
     2          TIMX(16),YVAL(16),QQT(200),PPT(10,200),IPOLX(11),
     3          NNDIM(MQUAL),PPNAME(MQUAL),PPUNIT(MQUAL),NLOAD(11)
      LOGICAL NOTEND
C=======================================================================
      DATA PRIN/'HYDROGRAPH   ','POLLUTOGRAPH ','LOADOGRAPH '/
      DATA HORIZG/'      TIME OF DAY IN HOURS    ',
     +            ' PREDICTED = *    MEASURED = +'/
      DATA VER1/'   FLOW   '/,VER2/'    IN    '/,
     +     VER3/'    CFS   '/,VER4/' CU M/SEC '/
      DATA VERM/'  POUNDS  ','   PER   ','  SECOND  ','MILLIGRAMS'/
      DATA DEFMT/'(2X,F8.0,7F10.0)'/,BMJ/'    '/
      DATA ZX/'  PLOT CONCENTRATION','  PLOT LOADOGRAPH'/
C=======================================================================
C#### WCH, 8/5/93.  ADD NO-QUOTE OPTION.
C=======================================================================
      IF(NOQ.EQ.0) THEN
                   WRITE(*,10)
                   WRITE(N6,10)
                   ELSE
                   WRITE(*,12)
                   WRITE(N6,12)
                   ENDIF
C#######################################################################
C WCH, 8/5/93. INCREMENT THE JIN/JOUT COUNTERS.
C=======================================================================
      INCNT  = INCNT + 1
      IOUTCT = IOUTCT + 1
C=======================================================================
C     Open all input/output files for the Graph Block.
C=======================================================================
      IF(JIN(INCNT).GT.0.AND.(FFNAME(INCNT).EQ.'JOT.UF'.OR.
     +      FFNAME(INCNT).EQ.'JIN.UF'))
     +      OPEN(JIN(INCNT),FORM='UNFORMATTED',STATUS='SCRATCH')
      IF(JIN(INCNT).GT.0.AND.FFNAME(INCNT).NE.'JOT.UF'.AND.
     +      FFNAME(INCNT).NE.'JIN.UF')
     +      OPEN(JIN(INCNT),FILE=FFNAME(INCNT),FORM='UNFORMATTED',
     +      STATUS='UNKNOWN')
C=======================================================================
C     DON'T NEED JOUT BUT OPEN OUT OF HABIT IF JOUT > 0.
C=======================================================================
      IF(JOUT(IOUTCT).GT.0.AND.(FFNAME(25+IOUTCT).EQ.'JOT.UF'.OR.
     +      FFNAME(25+IOUTCT).EQ.'JIN.UF'))
     +      OPEN(JOUT(IOUTCT),FORM='UNFORMATTED',STATUS='SCRATCH')
      IF(JOUT(IOUTCT).GT.0.AND.FFNAME(25+IOUTCT).NE.'JOT.UF'.AND.
     +      FFNAME(25+IOUTCT).NE.'JIN.UF')
     +      OPEN(JOUT(IOUTCT),FILE=FFNAME(25+IOUTCT),FORM='UNFORMATTED',
     +      STATUS='UNKNOWN')
C=======================================================================
C=======================================================================
C#### WCH, 4/18/94.  DON'T OPEN THIS IF DON'T USE IT.
C#### (DON'T) OPEN FORMATTED SCRATCH FILE
C##=====================================================================
Cred     need this file for measured data on an external file - 9/14/00
cred     change to nscrat(8) because the first scratch file is used by 
cred     runoff and transport - 9/15/00
         IF(NSCRAT(8).GT.0.AND.FFNAME(58).NE.'SCRT1.UF') OPEN(NSCRAT(8),
     +             FILE=FFNAME(58),FORM='FORMATTED',STATUS='UNKNOWN')
C##      IF(NSCRAT(1).GT.0.AND.FFNAME(51).EQ.'SCRT1.UF') OPEN(NSCRAT(1),
C##     +             FORM='FORMATTED',STATUS='SCRATCH')
C##                    NOUT = NSCRAT(1)
C##      IF(NOUT.GT.0) REWIND NOUT
C=======================================================================
C>>>>>>>>>>>> READ DATA GROUP A1 <<<<<<<<<<<<
C=======================================================================
      READ(N5,*,ERR=888) CC,NTAPE,NPLOT,MEAS,
     +                       MFILE,MPLOT,NQPP,METRIC,MCTH
      NLP    = NQPP+1
      IF(MFILE.LE.0) MFILE = N5
      WRITE(N6,30) NTAPE,METRIC,NQPP,NPLOT,MEAS,MFILE,MPLOT,MCTH
      METRIC = METRIC + 1
      IF(METRIC.EQ.1) THEN
                      CFACT1 = 28.31605/453592.0
                      CFACT2 = 28.31605
                      ELSE
                      CFACT1 = 1000.0 / 1.0E06
                      CFACT2 = 1000.0
                      ENDIF
      IF(NPLOT.EQ.0.AND.MEAS.EQ.0) RETURN
                    NUNIT = N5
cold  IF(MEAS.EQ.2) NUNIT = MFILE
      IF(MEAS.EQ.2) THEN
Cwch, 9/16/00.  Add error check for MFILE = NSCRAT8
 IF(MFILE.NE.NSCRAT(8)) THEN
WRITE(*,3800) MFILE,NSCRAT(8)
WRITE(N6,3810)MFILE,NSCRAT(8)
IF(NSCRAT(8).GT.0) THEN
MFILE = NSCRAT(8)
ELSE
STOP ' MUST HAVE E3 INPUT ON NSCRAT(8). RUN ST
     1OPPED FROM GRAPH.'
                   ENDIF
                ENDIF
                    NUNIT = MFILE
                    REWIND NUNIT
                    ENDIF
      IF(NPLOT.LT.1.OR.NTAPE.LT.1) GO TO 4000
C=======================================================================
C     INTERFACING MECHANISM FOR QUANTITY AND QUALITY OF RUNOFF
C=======================================================================
C#### WCH, 8/5/93.  ADD ERROR MESSAGE.
      IF(NTAPE.NE.JIN(INCNT)) THEN
         WRITE(N6,9500) NTAPE, JIN(INCNT), INCNT
         WRITE(*,9500)  NTAPE, JIN(INCNT), INCNT
         STOP
         ENDIF
      CALL INFACE(1,NTAPE)
      IF(NQUAL.GT.0) THEN
                     DO 110 K  = 1,NQUAL
                     PPNAME(K) = PNAME(K)
                     PPUNIT(K) = PUNIT(K)
                     NNDIM(K)  = NDIM(K)
  110                CONTINUE
                     ENDIF
C=======================================================================
C     INPUT INFORMATION FOR QUALITY PARAMETERS.
C=======================================================================
 4000 IF(NQPP.LE.0) GO TO 4200
      WRITE (N6,4090)
C=======================================================================
C>>>>>>>>>>>> READ DATA GROUP B1 <<<<<<<<<<<<
C=======================================================================
      DO 4140 K = 1,NQPP
      READ(N5,*,ERR=888) CC,KPOL,NLOAD(K+1),PNDUM,PUDUM,NDUM
C=======================================================================
C     HERE, USER INPUT DEFINES POLLUTANTS.
C=======================================================================
      K1        = K + 1
      IF(KPOL.EQ.0.OR.NPLOT.EQ.0) THEN
                                  IPOLX(K1) = K1
                                  NDIM(K1)  = NDUM
                                  PNAME(K1) = PNDUM
                                  PUNIT(K1) = PUDUM
                                  ELSE
                                  IPOLX(K1) = KPOL
                                  NDIM(K1)  = NNDIM(KPOL)
                                  PNAME(K1) = PPNAME(KPOL)
                                  PUNIT(K1) = PPUNIT(KPOL)
                                  ENDIF
      KK1 = NLOAD(K1) + 1
      WRITE(N6,4150) K,PNAME(K1),PUNIT(K1),NDIM(K1),KPOL,ZX(KK1)
 4140 CONTINUE
C=======================================================================
C>>>>>>>>>>>> READ DATA GROUP C1 <<<<<<<<<<<<
C=======================================================================
 4200 IF(NPLOT.GT.0) THEN
                     IF(JCE.EQ.0) THEN
                         READ(N5,*,ERR=888) CC,(IPLOT(N),N=1,NPLOT)
                         WRITE(N6,40) NPLOT,(IPLOT(N),N=1,NPLOT)
                         ELSE
                         READ(N5,*,ERR=888) CC,(KPRED(N),N=1,NPLOT)
                         WRITE(N6,41) NPLOT,(KPRED(N),N=1,NPLOT)
                         ENDIF
                     ENDIF
C=======================================================================
C>>>>>>>>>>>> READ DATA GROUP C2 <<<<<<<<<<<<
C=======================================================================
      IF(MPLOT.GT.0) THEN
                     IF(JCE.EQ.0) THEN
                        READ(N5,*,ERR=888) CC,(KPLOT(N),N=1,MPLOT)
                        WRITE(N6,55) MPLOT,(KPLOT(N),N=1,MPLOT)
                        ELSE
                        READ(N5,*,ERR=888) CC,(KMEAS(N),N=1,MPLOT)
                        WRITE(N6,56) MPLOT,(KMEAS(N),N=1,MPLOT)
                        ENDIF
                     ENDIF
C=======================================================================
C>>>>>>>>>>>> READ DATA GROUP D1 <<<<<<<<<<<<
C=======================================================================
      READ(N5,*,ERR=888) CC,TITLE(1)
      HTITLE(1) = TITLE(1)
      HTITLE(2) = BMJ
      DO 100 J  = 1,20
  100 MTAB(J)   = 0
      HORIZ(1)  = HORIZG(1)
      HORIZ(2)  = HORIZG(2)
      NNN       = 0
C=======================================================================
C     ITAB = SUBSCRIPT OF LOCATION OF MEASURED GRAPH WHEN MEASURED
C            LOCATION MATCHES DESIRED PLOT LOCATION.
C=======================================================================
      IF(MPLOT.GT.0) THEN
                     DO 180 M  = 1,MPLOT
                     NNN       = NNN + 1
                     DO 160 J  = 1,LOCATS
                     IF(JCE.EQ.0.AND.KPLOT(M).EQ.NLOC(J)) GO TO 170
                     IF(JCE.EQ.1.AND.KMEAS(M).EQ.KAN(J))  GO TO 170
  160                CONTINUE
                     ITAB(M) = 0
                     MTAB(M) = M
                     GO TO 180
  170                ITAB(M) = J
                     MTAB(M) = M
  180                CONTINUE
                     ENDIF
C=======================================================================
C     CHECK FOR MATCHING LOCATIONS TO BE PLOTTED FROM SWMM FILE.
C     MTAB EQ 0, NO MATCH BETWEEN IPLOT AND KPLOT.
C     MTAB NE 0, MTAB = SUBSCRIPT OF IPLOT.
C=======================================================================
      IF(NPLOT.GT.0) THEN
                     DO 210 J = 1,NPLOT
                     IF(MPLOT.EQ.0) GO TO 201
                     DO 200 M = 1,MPLOT
                     IF(JCE.EQ.0) JPLOT(M) = KPLOT(M)
                     IF(JCE.EQ.1) JMEAS(M) = KMEAS(M)
                     IF(JCE.EQ.0.AND.IPLOT(J).EQ.KPLOT(M)) GO TO 205
                     IF(JCE.EQ.1.AND.KPRED(J).EQ.KMEAS(M)) GO TO 205
  200                CONTINUE
  201                DO 206 N  = 1,LOCATS
                     IF(JCE.EQ.0.AND.IPLOT(J).EQ.NLOC(N)) GO TO 203
                     IF(JCE.EQ.1.AND.KPRED(J).EQ.KAN(N))  GO TO 203
  206                CONTINUE
                     IF(JCE.EQ.0) WRITE(N6,9020) IPLOT(J)
                     IF(JCE.EQ.1) WRITE(N6,9021) KPRED(J)
                     STOP
  203                NNN        = NNN + 1
                     IF(JCE.EQ.0) JPLOT(NNN) = IPLOT(J)
                     IF(JCE.EQ.1) JMEAS(NNN) = KPRED(J)
                     ITAB(NNN)  = N
                     MTAB(NNN)  = 0
                     GO TO 210
  205                MTAB(M)   = M
  210                CONTINUE
                     END IF
C=======================================================================
C     FROM PREDICTED OUTPUT, STORE EVERY MCTH DATA POINT
C     PROGRAM THEN INTERPOLATES TO PLOT 100 POINTS AT MOST.
C     FIRST PLOTTED POINT IS ALWAYS ZERO AT TZERO.
C=======================================================================
      IF(MCTH.LE.0) MCTH = 1
      WRITE(*,34)   NNN
      DO 800 MT = 1,NNN
      IBACK     = 0
      NOTEND    = .FALSE.
      WRITE(*,35) MT
      IF(NPLOT.EQ.0)                    GO TO 7000
      IF(MT.LE.MPLOT.AND.ITAB(MT).EQ.0) GO TO 7000
C=======================================================================
C     READ INTERFACE FILE HEADERS
C=======================================================================
      CALL INFACE(0,NTAPE)
      TTME     = TZERO
      N        = 0
 5000 DO 250 K = 1,100000,MCTH
      N        = N+1
      DO 230 J = 1,MCTH
C=======================================================================
C     READ TIME STEP VALUES FROM INTERFACE FILE.
C     STORE IN TEMPORARY FILE AND PULL OUT DESIRED VALUES.
C=======================================================================
      IF(NQUAL.EQ.0) THEN
               READ(NTAPE,END=251) JDAY,TMDAY,DELTA,(QQT(I),I=1,LOCATS)
               ELSE
               READ(NTAPE,END=251) JDAY,TMDAY,DELTA,(QQT(I),
     +                             (PPT(L,I),L=1,NQUAL),I=1,LOCATS)
              END IF
      TTME   = TTME + DELTA
  230 CONTINUE
      X(N,1) = TTME/3600.0
      ITB      = ITAB(MT)
      DO 240 J = 1,NLP
      IF(J.EQ.1) THEN
                 YT(N,J) = QQT(ITB)
                 ELSE
                 KP = IPOLX(J)
                 IF(KP.GT.0) THEN
                             YT(N,J) = PPT(KP,ITB)
                             ELSE
                             YT(N,J) = 0.0
                             ENDIF
                 ENDIF
  240 CONTINUE
      IF(N.GE.401) THEN
                   IBACK = IBACK + 1
                   GO TO 252
                   ENDIF
  250 CONTINUE
  251 NOTEND = .FALSE.
      N      = N - 1
      IBACK  = IBACK + 1
      IF(N.LE.0) GO TO 800
      GO TO 253
  252 NOTEND = .TRUE.
  253 NPT(1) = N
C=======================================================================
C     OUTER LOOP ON HYDROGRAPH PLUS NUMBER OF POLLUTANTS.
C     ONLY READ MEASURED DATA FOR FIRST 200 PREDICTED DATA POINTS.
C=======================================================================
 7000 DO 820 J  = 1,NLP
      IF(IBACK.GT.1) GO TO 6000
             IF(J.EQ.1) THEN
                        VERT1 = VER1
                        VERT2 = VER2
                        IF(METRIC.EQ.1) VERT3 = VER3
                        IF(METRIC.EQ.2) VERT3 = VER4
                        ELSE IF(NLOAD(J).EQ.0) THEN
                             JJ        = IPOLX(J)
                             HTITLE(1) = TITLE(1)
                             VERT1     = PNAME(JJ)
                             VERT2     = VER2
                             VERT3     = PUNIT(JJ)
                             ELSE
                             JJ        = IPOLX(J)
                             HTITLE(1) = PNAME(JJ)
                             VERT2     = VERM(2)
                             VERT3     = VERM(3)
                             IF(METRIC.EQ.1) VERT1 = VERM(1)
                             IF(METRIC.EQ.2) VERT1 = VERM(4)
                             ENDIF
             IF(NPLOT.GT.0) THEN
                            IF(NLOAD(J).EQ.1) GO TO 6000
                            IF(MTAB(MT).EQ.0) GO TO 6000
                            IF(MPLOT.EQ.0)    GO TO 6000
                            ENDIF
             KK = 0
C=======================================================================
C     LOOP ON NUMBER OF MEASURED LOCATIONS TO BE PLOTTED.
C=======================================================================
C     READ PARAMETERS FOR MEASURED INPUT FOR EACH LOCATION FOR EACH
C        MEASURED HYDROGRAPH AND POLLUTOGRAPH.
C=======================================================================
C>>>>>>>>>>>> READ DATA GROUP E1 <<<<<<<<<<<<
C=======================================================================
      READ(N5,*,ERR=888) CC,MDATA,LCARD,MTIME,
     +                   MUNIT,TMZERO,TQUIT,DTMHR
      WRITE(N6,310) PRIN(1),KPLOT(MT),
     +              MDATA,LCARD,MTIME,MUNIT,TMZERO,TQUIT,DTMHR
      IF(MDATA.EQ.0) GO TO 6000
C=======================================================================
C     READ IN VARIABLE FORMAT FOR EACH MEASURED DATA INPUT.
C=======================================================================
C>>>>>>>>>>>> READ DATA GROUP E2 <<<<<<<<<<<<
C=======================================================================
      READ(N5,*,ERR=888) CC,FIRMAT
      IF(FIRMAT.EQ.' ')     FIRMAT = DEFMT
      WRITE(N6,360) FIRMAT
C=======================================================================
C>>>>>>>>>>>> READ DATA GROUP E3 <<<<<<<<<<<<
C=======================================================================
C                    MUNIT = 0  TIME IS IN MINUTES.
C                    MUNIT = 1  TIME IS IN HOURS.MINUTES.
C                    MUNIT = 2  TIME IS IN HOURS.
C=======================================================================
      IF(MTIME.EQ.0) THEN
                     KSTOP = 0
                     KK    = 0
Cwch 9/14/00  Add error message.
cred                 rearrange the next few lines - 9/14/00
370                  continue
cold370              READ(NUNIT,FIRMAT) (TIMX(LL),YVAL(LL),LL=1,LCARD)
cred                 allow for a free formatted file - 9/14/00
                     if(FIRMAT.EQ.'FREE') then
                        READ(NUNIT,*,end=510,err=385) 
     +                   (TIMX(LL),YVAL(LL),LL=1,LCARD)
                        else
                        READ(NUNIT,FIRMAT,END=510,ERR=385) 
     1                   (TIMX(LL),YVAL(LL),LL=1,LCARD)
                        endif
cred                 end of 9/14/00 change
                     DO 380 LL = 1,LCARD
                     IF(TIMX(LL).GE.TQUIT) THEN
                                           KKX   = LL-1
                                           KSTOP = 1
                                           GO TO 390
                                           END IF
  380                CONTINUE
                     KKX = LCARD
Cwch, 9/14/00
  GO TO 390
  385   WRITE(N6,3885) (KK+1)/LCARD
                     STOP ' ERROR READING E3 LINES. SEE OUTPUT FILE. RUN
     1 STOPPED FROM GRAPH.'
  390                IF(KKX.LE.0) GO TO 500
                     DO 490 LL = 1,KKX
                     LX        = KK+LL
                     IF(MUNIT-1.LT.0) THEN
                                X(LX,2) = TIMX(LL)/60.+TMZERO
                                ELSE
                                IF(MUNIT-1.EQ.0) THEN
                                   TIM     = IFIX(TIMX(LL))
                                   X(LX,2) = TIM+(TIMX(LL)-TIM)/0.6+
     +                                            TMZERO
                                   ELSE
                                   X(LX,2)  = TIMX(LL)+TMZERO
                                   ENDIF
                                ENDIF
  490                Y(LX,2) = YVAL(LL)
  500                KK      = KK+KKX
                     IF(KK.LT.401.AND.KSTOP.EQ.0) GO TO 370
Cred                 get out of this loop, use the END statement - 9/15/00
  510                IF(KK.GT.401) KK = 401
cold                 IF(KK.GT.201) KK = 201
                     NPT(2) = KK
                     WRITE(N6,505) KK
                     ENDIF
C=======================================================================
C     HERE, COMPUTE TIME USING CONSTANT TIME INCREMENT, DTMHR, IN HOURS.
C=======================================================================
C>>>>>>>>>>>> READ DATA GROUP E3 <<<<<<<<<<<<
C=======================================================================
      IF(MTIME.GT.0)      THEN
         IF(MTIME.GT.401) THEN
                             WRITE(N6,520) MTIME
                             MTIME = 401
                             ENDIF
         IF(MTIME.GT.0)   THEN
cold                      READ(N5,FIRMAT) (Y(LL,2),LL=1,MTIME)
cred                      allow for a free formatted file - 9/14/00
Cwch, 9/16/00. Put read in DO-loop since documentation says read
C     LCARD values per line. 
DO JJ = 1,MTIME,LCARD
LLSTOP = LCARD
                       IF(MTIME-JJ+1.LT.LCARD) LLSTOP=MTIME-JJ+1
                       KL = JJ
                          if(FIRMAT.EQ.'FREE') then
                            READ(N5,*,ERR=545) (Y(LL,2),LL=KL,LLSTOP)
                             else
                          READ(N5,FIRMAT,ERR=545) (Y(LL,2),LL=KL,LLSTOP)
                             endif
                   END DO
Cwch, 9/16/00.  Include error message here too.
GO TO 547
  545   WRITE(N6,3885) JJ
                     STOP ' ERROR READING E3 LINES. SEE OUTPUT FILE. RUN
     1 STOPPED FROM GRAPH.'
  547                     DO 550 LX  = 1,MTIME
  550                     X(LX,2)    = TMZERO+FLOAT(LX-1)*DTMHR
                          NPT(2)     = MTIME
                          ENDIF
                          ENDIF
C=======================================================================
C     CONVERT PREDICTED FLOWS TO APPROPRIATE UNITS
C=======================================================================
                     NN = NPT(1)
      IF(NPLOT.EQ.0) NN = NPT(2)
      DO 630 N = 2,NN
      IF(J.EQ.1) THEN
Cwch, 9/14/00.  Interface file flows already metric, from Runoff & Transp.
C                 Y(N,1) = YT(N,J)/CMET(1,METRIC)**3.0
                 Y(N,1) = YT(N,J)
                 GO TO 630
                 ENDIF
C=======================================================================
C     CONVERT PREDICTED AND MEASURED
C             POLLUTOGRAPHS TO CONCENTRATION FROM CFS*CONC.
C=======================================================================
      IF(NLOAD(J).EQ.0) THEN
                  IF(YT(N,1).GT.0.0) Y(N,1) = YT(N,J)/YT(N,1)
                  ELSE
                  IF(NDIM(J).EQ.0) THEN
                                   Y(N,1) = YT(N,J)*CFACT1
                                   Y(N,2) =  Y(N,2)*CFACT1
                                   ELSE
                                   Y(N,1) = YT(N,J)*CFACT2
                                   Y(N,2) =  Y(N,2)*CFACT2
                                   ENDIF
                  ENDIF
  630 CONTINUE
      CALL CURVE(X,Y,NPT,2,KPLOT(MT),KMEAS(MT))
      IF(J.EQ.1) THEN
                 USE = 'FLOW'
                 ELSE
                 IF(NLOAD(J).EQ.0) USE = 'CONC'
                 IF(NLOAD(J).EQ.1) USE = 'LOAD'
                 ENDIF
      KP = IPOLX(J)
      IF(KP.EQ.0) KP = 1
      CALL HYSTAT(X,Y,NPT,2,KPLOT(MT),KMEAS(MT),TRIBA,METRIC,
     +                                USE,PUNIT(KP),PNAME(KP))
C=======================================================================
C     PLOT PREDICTED GRAPHS ONLY.
C     CONVERT PREDICTED POLLUTOGRAPHS TO CONCENTRATION FROM CFS*CONC.
C=======================================================================
      IF(ITAB(MT).EQ.0) GO TO 820
 6000 IF(MTAB(MT).EQ.0.OR.(J.GT.1.AND.NLOAD(J).GT.0)) THEN
                        IF(J.EQ.1) THEN
                                   USE = 'FLOW'
                                   ELSE
                                   IF(NLOAD(J).EQ.0) USE = 'CONC'
                                   IF(NLOAD(J).EQ.1) USE = 'LOAD'
                                   ENDIF
                        NN       = NPT(1)
                        SUMFLW   = 0.0
                        DO 930 N = 1,NN
                        IF(J.EQ.1) THEN
Cwch, 9/14/00.  Interface file flows already metric, from Runoff & Transp.
C                                  Y(N,1) = YT(N,J)/CMET(1,METRIC)**3.0
                                   Y(N,1) = YT(N,J)
                                   SUMFLW = SUMFLW + Y(N,1)
                                   GO TO 930
                                   ENDIF
                        IF(NLOAD(J).EQ.0) THEN
                           IF(YT(N,1).GT.0.0) Y(N,1) = YT(N,J)/YT(N,1)
                           ELSE
                           IF(NDIM(J).EQ.0) THEN
                                      Y(N,1) = YT(N,J)*CFACT1
                                      Y(N,2) =  Y(N,2)*CFACT1
                                      ELSE
                                      Y(N,1) = YT(N,J)*CFACT2
                                      Y(N,2) =  Y(N,2)*CFACT2
                                      ENDIF
                           ENDIF
  930                   CONTINUE
C=======================================================================
C                       PLOT ONLY THE PREDICTED DATA USING CURVE
C=======================================================================
                        IF(J.EQ.1.AND.SUMFLW.EQ.0.0) THEN
                        IF(JCE.EQ.0) WRITE(N6,9040) JPLOT(MT),NPT(1)
                        IF(JCE.EQ.1) WRITE(N6,9041) JMEAS(MT),NPT(1)
                        ELSE
                        CALL CURVE(X,Y,NPT,1,JPLOT(MT),JMEAS(MT))
                        IF(J.EQ.1) THEN
                                   USE = 'FLOW'
                                   ELSE
                                   IF(NLOAD(J).EQ.0) USE = 'CONC'
                                   IF(NLOAD(J).EQ.1) USE = 'LOAD'
                                   ENDIF
                        KP = IPOLX(J)
                        IF(KP.EQ.0) KP = 1
                        CALL HYSTAT(X,Y,NPT,1,JPLOT(MT),JMEAS(MT),TRIBA,
     +                       METRIC,USE,PUNIT(KP),PNAME(KP))
                        ENDIF
                        ENDIF
  820 CONTINUE
C=======================================================================
C     IF MORE THAN 201 DATA POINTS ARE ON THE INTERFACE FILE
C     RETURN AND CONTINUE PLOTTING THE HYDROGRAPHS AND POLLUTOGRAPHS
C=======================================================================
      IF(IBACK.GE.1.AND.NOTEND) THEN
                                N = 0
                                GO TO 5000
                                ENDIF
  800 CONTINUE
C=======================================================================
   10 FORMAT(/,
     +' ***************************************************',/,
     +' * ENTRY TO GRAPH BLOCK. LAST UPDATED AUGUST 1993. *',/,
     +' * "All art is quite useless."                     *',/,
     +' *                             Oscar Wilde (1891)  *',/,
     +' ***************************************************',/)
C#### WCH, 8/5/93
   12 FORMAT(/,
     +' ***************************************************',/,
     +' * ENTRY TO GRAPH BLOCK. LAST UPDATED AUGUST 1993. *',/,
     +' ***************************************************',/)
   30 FORMAT(/,' INPUT PARAMETER SUMMARY:',//,
     1 ' NUMBER OF OFF-LINE FILE OF PREDICTED DATA(NTAPE)....',I3,/,
     2 ' FLOW ORDINATE IN CFS (=0) OR CU M/S (=1) (METRIC)...',I3,/,
     3 ' NUMBER OF POLLUTOGRAPHS TO BE PLOTTED (NQP).........',I3,/,
     4 ' NUMBER OF LOCATIONS FOR PREDICTED PLOTS(NPLOT)......',I3,/,
     5 ' INDICATING MEASURED DATA AND THEIR STORAGE(MEAS)....',I3,/,
     6 ' FILE NUMBER FOR RETRIEVAL OF MEASURED DATA(MFILE)...',I3,/,
     7 ' NUMBER OF LOCATIONS FOR MEASURED DATA(MPLOT)........',I3,/,
     8 ' SKIP MCTH VALUES ON INTERFACE FILE..................',I3)
   34 FORMAT(/,' PLOTTING ',I5,' LOCATIONS',/,' PLOTTING GRAPH # ',/)
   35 FORMAT('+',I16)
   40 FORMAT(//,' PREDICTED GRAPHS ARE TO BE PLOTTED FOR THE FOLLOWING
     1 ',I4,' LOCATIONS :',//,10I11,/,10I11)
   41 FORMAT(//,' PREDICTED GRAPHS ARE TO BE PLOTTED FOR THE FOLLOWING
     1 ',I4,' LOCATIONS :',//,10A11,/,10A11)
   55 FORMAT(/,' MEASURED GRAPHS ARE TO BE PLOTTED FOR THE FOLLOWING ',
     1I4,' LOCATIONS :',//,10I11,/,10I11)
   56 FORMAT(/,' MEASURED GRAPHS ARE TO BE PLOTTED FOR THE FOLLOWING ',
     1I4,' LOCATIONS :',//,10A11,/,10A11)
  310 FORMAT(//,1X,A14,
     1 ' DATA GROUP E1 INPUT PARAMETERS FOR LOCATION ',I5,' ARE:',/,
     2' MDATA = ',I10,'     LCARD = ',I10,  '    MTIME = ',I10,/,
     2' MUNIT = ',I10,'    TMZERO = ',F10.4,'    TQUIT = ',F10.4,/,
     3' DTMHR = ',F10.4)
  360 FORMAT(/,' INPUT FORMAT FOR THESE DATA IS: ',A80)
  505 FORMAT(I6,' MEASURED DATA POINTS READ IN.')
  520 FORMAT(/,' ===> WARNING! MTIME=',I5,', GT 401. NOT ALLOWED.',
     1 '  MTIME WILL BE SET = 401.')
Cwch, 9/16/00
 3800 FORMAT(' ERROR. MFILE =',I4,' NSCRAT(8) =',I4,'. SHOULD BE EQUAL.'
     1,/,' WILL TRY SETTING MFILE = NSCRAT(8), IF NON-ZERO.',/,
     2   ' OTHERWISE, RUN WILL STOP, BELOW.')
 3810 FORMAT(' ERROR. MFILE =',I4,' NSCRAT(8) =',I4,'. SHOULD BE EQUAL.'
     1,/,' WILL TRY SETTING MFILE = NSCRAT(8), IF NON-ZERO.',/,
     2   ' OTHERWISE, CANNOT READ E3 DATA AND RUN WILL STOP.')
Cwch, 9/14/00.  
 3885 FORMAT(/,' ERROR READING E3 LINES.  RUN STOPPED.',/,
     1 ' OFFENDING E3 LINE IS NUMBER',I6)
 4090 FORMAT(/,
     1' ****************************************',/,
     1' *  QUALITY CONSTITUENTS TO BE GRAPHED  *',/,
     1' ****************************************',//,
     1 '                       TYPE OF   INTERFACE FILE',/,
     3 ' NO.  NAME     UNITS    UNITS   POSITION (IF ANY) PLOT',
     3 ' DESCRIPTION',/,
     4 ' --- -----     -----    -----   ----------------------',
     5 '------------')
 4150 FORMAT(I3,2X,A8,2X,A8,I6,I13,A30)
 9020 FORMAT(/,' ===> ERROR  LOCATION: ',I10,' WAS NOT FOUND ON THE ',
     +                                      'INTERFACE FILE.')
 9021 FORMAT(/,' ===> ERROR  LOCATION: ',A10,' WAS NOT FOUND ON THE ',
     +                                      'INTERFACE FILE.')
 9040 FORMAT(/,' ===> HYDROGRAPH FOR LOCATION ',I10,' WITH ',I5,
     + ' POINTS',/,'      WAS NOT PLOTTED BECAUSE THE FLOW WAS ZERO.')
 9041 FORMAT(/,' ===> HYDROGRAPH FOR LOCATION ',A10,' WITH ',I5,
     + ' POINTS', /,'      WAS NOT PLOTTED BECAUSE THE FLOW WAS ZERO.')
C#### WCH, 8/5/93
 9500 FORMAT(/,' ===> ERROR. FOR NTAPE > 0, NTAPE MUST EQUAL JIN.',/,
     + '     NTAPE =',I5,'  JIN =',I5,'  COUNTER (INCNT) =',I5)
C=======================================================================
      RETURN
  888 CALL IERROR
      END

Sunday, June 25, 2017

World Class Software Documentation for SWMM5 from Lew Rossman and Wayne Huber (Hydrology)

I posted this on the SWMM Group on LinkedIn
I have noticed based on email questions and postings to the SWMM LIst Sever (a great resource hosted by CHI, Inc.) that many SWMM 5 users do not know about the really outstanding documentation on SWMM 5 posted on the EPA Website https://www.epa.gov/water-research/storm-water-management-model-swmm It consists of two now and in the near future three volumes on Hydrology, Water Quality, LID’s and SuDs and Hydraulics. The documentation is fantastically complete with detailed background on the theory, process parameters and completely worked out examples for all of the processes in SWMM5. It is truly an outstanding aid to modelers and modellers worldwide. It would benefit you to read them (if you have not already downloaded the PDF files). Thanks for reading this post

Friday, September 18, 2015

Some of today’s sewers were built before bathrooms as we know them existed. It’s time to upgrade. From City Lab cites Wayne Huber

Flushing the Toilet Has Never Been Riskier



Amit Dave / REUTERS

Flushing toilets enable most Americans to make their own waste disappear as if by magic, but most would be hard-pressed to answer this simple question: When you flush, where does it go?
Septic tank owners, about 20 percent of Americans, are most likely to be able to give an accurate answer, because they’re responsible for the maintenance of their own sewage-disposal systems. A flush from one of their toilets sends wastewater to a tank buried on their property, where the waste products separate into solid and liquid layers and partially decompose. The liquid layer flows out of the tank and into a drainfield that disperses it into the soil, wherenaturally occurring microbes remove harmful bacteria, viruses, and nutrients. The solid layer stays behind in the form of sludge that must be pumped out periodically as part of routine maintenance. If the tank is properly designed and maintained, those bacteria, viruses, and nutrients stay out of groundwater and surface water that people may use for drinking water, and they never reach surface water bodies where people swim or boat.
The vast majority of the 80 percent of Americans who don’t use septic tanks are served by municipal water-treatment plants. Waste from their homes is whisked immediately off the premises, never to be seen, smelled, or considered again. Pipes carry waste from these homes to wastewater-treatment plants that, in some ways, work like a septic tank on a very large scale.
Just as in a septic tank, the solid and liquid wastes are separated first in a process known as primary treatment. Next, as in a septic tank’s drainfield, bacteria break down contaminants in a process called secondary treatment. After that, treatment with chlorine kills the remaining bacteria. Then, in some communities, special treatment technologies remove contaminants that are of special concern, such as phosphorus or nitrogen. When the process is complete, the treated waste meets regulatory standards and is released to a nearby water body—that is, if all goes well. If all doesn’t go well—perhaps the treatment plant suffers an outage or there’s more waste than the plant was designed to treat—untreated waste can be released to surface water.


As treatment plants age across the United States and as the country’s population grows, these releases are becoming more problematic, contributing to the serious surface-water problems that crop up frequently in the news. Harmful algal blooms like the one that cost Toledo, Ohio, its drinking waterlast summer, fish kills like the one recently reported off Long Island, and the much-discussed dead zone in the Gulf of Mexico are all fed by phosphorus, nitrogen, and other contaminants found in the untreated sewage that, according to EPA estimates, flows out of America’s treatment plants during the23,000 to 75,000 sanitary-sewer overflows that happen per year.
The causes of these water-quality issues are complex, because the same pollutants can be washed into surface water from agricultural land, industrial sites, and fertilized lawns dotted with pet waste, but the 3 to 10 billion gallons of untreated waste released from our sewage-treatment plants per year cannot help but have an impact.Specifically, they affect the water you swim in and the water you drink.
* * *
A number of studies, including this one from 2010, have found that emergency room visits for gastrointestinal distress increase after a heavy rain. These illnesses are believed to spike after a storm because rainwater washes pathogens into lakes and rivers used for recreation and drinking water. A 2015 study published in Environmental Health Perspectives goes a step further than earlier research by pointing to a common type of municipal sewage-treatment system, combined-sewer systems, as an important factor in these illnesses.
The EPA has called overflows from combined sewer systems “the largest category of our Nation’s wastewater infrastructure that still need to be addressed,” affecting Americans in 32 states, including the District of Columbia. The agency has been working with municipal water systems to address the problem for decades and much progress has been made, but to understand why it’s taking so long, you have to consider history. You also have to consider the massive costs that come with making changes to public works that have served millions of people for more than a century.
Combined sewers collect human waste, industrial waste, and stormwater runoff into a single pipe for treatment and disposal. (In other municipalities, these waste streams are handled separately.) In dry weather, a combined sewer ordinarily carries a relatively low volume of waste, delivering it to publicly owned treatment works, or POTWs for short, that are designed to handle that flow. In plain terms, when a combined sewer system is functioning properly, you can generally trust that when you flush, the contents of the toilet bowl end up where they’re supposed to go.


USEPA
Things change when it rains in communities served by combined sewers. Because a combined system must handle surges of stormwater, rainfall markedly increases the volume of waste that its equipment must handle, making this type of sewage system particularly likely to overflow into surface water. As these diagramsshow, they were designed to do this as a fail-safe for system failures that were intended to be rare but aren’t any longer. If you’re accustomed to a faint smell of sewage in the streets after a rainstorm, these diagrams will show you why.
Unfortunately, the receiving waters for these rain-induced spills are sometimes the same water bodies that are used for drinking water, and sometimes people swim there, too. And sometimes the overflow is so significant that the stormwater-and-sewage mixture backs up into the streets where people walk.
Is it any wonder that rainy weather often triggers a spike in stomach bugs and beach closures?
* * *
Given what’s at stake, why are upgrades to aging systems taking so long? Consider this map of the 772 American communities with combined-sewer systems.
Most combined systems are concentrated in the older cities of the Northeast and the Great Lakes region, but they also exist in other older cities as far-flung as Atlanta, Memphis, and San Francisco. In other words, the systems that pose risks today happen to be the ones—state-of-the-art when they were built, but not today—that are in some of the biggest cities in America, which have acombined population of approximately 40 million people.


If you’re feeling relieved to see that your hometown isn’t marked on the map, remember that fecal-coliform bacteria don’t always stay close to home. Waste spilled into the Ohio River affects everyone down the Ohio and the Mississippi, and it contributes to the ongoing woes of the Gulf of Mexico. Even if you don’t live in the Northeast, along the Ohio, in the Great Lakes region, along the Mississippi, or on the Gulf Coast, bear in mind that 40 percent of the commercial seafood caught in the continental U.S. comes from the Gulf of Mexico. In other words, when Cincinnati’s sewer system overflows into the Ohio, it intrudes into the food chain of a lot of people.
* * *
The EPA calls combined sewers “remnants of the country's early infrastructure.”The first sewers weren’t designed to handle the constant and huge stream of wastes from our toilets, because they were invented when we didn’t have any toilets. Sewers were originally built to solve the problems of cities that were flooded with their own refuse—garbage, animal manure, and human waste left in the open rather than in a privy or latrine—during every rainstorm. To prevent that flooding, the fouled stormwater was shunted out of town and into the nearest handy receptacle, which was often a lake, river, stream, or ocean.
When flush toilets became common in the mid-1800s, they were piped into these existing sewers, introducing much more human waste, as well as a large volume of water that had never been there before. In some ways, this was a design feature, not a bug, because the burst of stormwater flushed out pipes that might have otherwise gotten clogged. This flush of rainwater also diluted the waste before it hit a nearby river.
In time, though, dilution wasn’t enough to keep waterways safe and attractive, and sewage treatment plants were invented to clean up the waste stream before releasing it to water bodies. Newer cities, which were starting from scratch, generally handled stormwater separately from human and industrial wastes from the start, but cities whose sewer systems had always been combined continued to treat both waste streams together.


As the older cities grew larger, their combined-treatment systems struggled to keep up, and growing populations weren’t the only factor. Time itself exacerbated their woes. In Hoboken, for example, some sewer lines date back to the Civil War. Common sense says that pipes that have been buried for a century and a half tend to leak. Over time, they also get clogged with debris or even congealed cooking oil, resulting in narrowed pipes that overflow even more easily.
When narrowed pipes are already overloaded, the added influx of stormwater when it rains becomes just too much water. Now, some cities experience overflows with less than a quarter-inch of rain, with resulting risks to human health. It is common for cities with combined-sewer systems to advise citizens to stay out of the water for days after any rainfall. And now the Environmental Health Perspectives study suggests that after a very heavy rain, those overflows may be affecting their communities’ drinking water, too.What is being done? Combined sewers have been an EPA priority for many years and, after decades of significant effort, the numbers are starting to move in the right direction, but this is not a problem that can be turned around quickly or cheaply. New York City’s combined sewers are still the single largest source of pathogens to the New York Harbor system, according to the New York Department of Environmental Protection. A single 2014 storm triggered a release into Lake Erie from Detroit, Michigan, of more than 44 million gallons of raw sewage from sanitary sewers and almost 3 billion gallons from combined sewers, and such releases from Detroit and the other cities with sewer outfalls on Lake Erie contribute to the fact that it blooms with algae every summer. Last summer, one of those algal blooms cost Toledo its drinking water for two days, and this year’s harmful algal blooms were projected to be even worse than last year’s.
As with any engineering project, the benefits of reducing overflows to zero—an effort estimated by the EPA in 2004 to cost $88.8 billion—must be weighed against its cost.
“We mustn’t forget the hugely successful effort in the 1970s and 1980s to provide secondary treatment at virtually every sewage-treatment plant in the country,” said Wayne Huber, a professor emeritus of Civil and Construction Engineering at Oregon State University. As an example, he describes what happened in Portland, Oregon, where a system of tunnels now contains 90 percent of the city’s stormwater surges. “Portland spent about $500 million on its deep tunnels and pumping system,” Huber said. “This has reduced the number of releases into the Willamette River from maybe 50 to 100 per year to five to ten per year.”
Huber also highlights Philadelphia’s “green technology” strategy to reduce overflows to the Delaware and Schuylkill rivers. Since avoiding massive construction is often synonymous with avoiding massive expenditures, Philadelphia’s use of approaches like rain gardens and green roofs to divert stormwater from the waste stream going to its treatment plants could serve as a model for other municipalities struggling with the same problems.
Huber cautions against relying on a single approach, saying that “green technology seeks to avoid large investments in infrastructure by keeping stormwater out of the combined sewer in the first place, but in heavily urbanized areas that is seldom an option, hence the massive storage projects that we see in cities like Chicago.”
On the individual level, people concerned about wastewater can give some thought to the fertilizer, pesticides, trash, and animal waste that wash off of lawns and into sewer systems, lakes, rivers, and oceans. As citizens, they can also advocate at local, state, and federal levels for improvements. People can reduce stormwater flow by planting their own rain gardens and green roofs—and by being judicious about the way they water our lawns and wash their cars. Sometimes, doing the right thing is as simple as being careful about what goes into storm drains and toilets.
After hearing about the plume of sewage, littered with used condoms and tampons, that emanated from Philadelphia’s sewer outfalls prior to the city’s upgrade, it’s hard to look at flushing the toilet the same way. If Americans want to be able to drink tap water or swim at beaches after it rains, they have to keep trying to improve wastewater infrastructure, even if the size of the problem boggles the mind.
This post originally appeared on The Atlantic.

AI Rivers of Wisdom about ICM SWMM

Here's the text "Rivers of Wisdom" formatted with one sentence per line: [Verse 1] 🌊 Beneath the ancient oak, where shadows p...