2COMMENT Transcribed from Appendix C of
2        DIGITAL SIMULATION IN HYDROLOGY:
2        STANFORD WATERSHED MODEL IV
2        Norman H. Crawford, Ray K. Linsley
2        Department of Civil Engineering, Stanford University
2        Technical Report No. 39, July 1966.
2        http://hydrocomp.com/publications/journals/stanford-watershed/
2        Transcribed by P.Kimpel, Feburary 2018;
2
2COMMENT STANFORD WATERSHED MODEL IV, COMBINED VERS1ON OF JULY 12,1966;
2COMMENT TAPES PRECIP ON LOGICAL 10 - UNIT B5;                             00010
2COMMENT READS PRECIP FROM LOGICAL TAPE 10- UNIT B5 ;
2LIBRARY PROCEDURE PLOT(;X,Y,IC);
2LIBRARY PROCEDURE SCALE(;A(),N,SMAX,SACT,XMIN,DX);
2LIBRARY PROCEDURE AXIS(;X,Y,BCD,N,S,THETA ,XMIN,DX);
2LIBRARY PROCEDURE PLOTWRITE(X,Y,H,THETA;;LIST,FMT);
2GLOBAL LIBRARY SUBROUTINE PLOT10;
2BOOLEAN DCS(),TAB,TABU,TAPES,RUN;
2INEGER DD...,DPY,DLY,DAYMO,DAYS,DAY,HOUR,HARP,HAAP,MO,M1,NX...,
2QQQ...,YR,STYR,FPYR,SEG,FLOWPINT,SHFT,RINT,DPM(),TAPEMOVE, Z,
2MFILX,ST,CN,MOCOUNT,SG,STT,FILX,OBS,I1,I2,YRS,
2IC,BCD,N,LABLE;
2ARRAY  C(99),C22(110),CAS(25),            AVER(25),AVAR(25),
2EE(24),
2DCS(14),DR(367),E(375),        EVCR(12),
2FLO(367),GWSA(12),
2MXRO(21),MXRA(21),
2QQQ(12),QQL(12),QQO(12),
2REC2(750),K(367),PREC(367),SUMPREC(12),SUMPRECR(12),
2          LZSA(12),REC1(768),SERR(25),
2SERA(25),SQER(25),      SPRA(12),SPRMA(12),SGWFA(12),SGWA(12),
2SQ(25),
2SDIV(367),SGWS(5,10),UZSS(5,10),LZSS(5,10),GWSS(5,10),
2SPETA(12),SAETA(12),SINTA(12),
2TRS(8884),TRSH(5,200),TR(24),TONE(12),TOND(12),TONN(12),
2INFA(12),UZSA(12);
2COMMENT SNOWMELT IV ARRAYS;
2ARRAY                      MAXRAD(367),EES(24),SE(367),RAD(367),T(735),
2      RAS(24),     RNMM(12),MSURE(12),RADMES(12),SCOMELTS(12);
2ARRAY
2RADDIST(24)=(0.0,0.0,0.0,0.0,0.0,0.0,0.019,0.041,0.067,0.088,
2       0.102,0.11,0.11,0.11,0.105,0.095,0.081,0.055,0.017,
2     0.0,0.0,0.0,0.0,0.0);
2ARRAY
2LAPSE(24)=(0.6,0.0,0.0,0.0,0.0,0.0,1.0,2.0,3.0,4.0,4.0,4.0,4.0,4.0,
2      4.0,4.0,4.0,4.0,4.0,4.0,3.2,2.6,2.0,1.2);
2ARRAY
2GRAD(24)=(0.04,0.04,0.03,0.02,0.02,0.02,0.02,0.06,0.14,0.18,0.20,
2   0.17,0.13,0.06,0.03,0.01,0.05,0.07,0.10,0.13,0.15,0.13,0.12,0.08);
2ARRAY DPM(12)=(31,28,31,30,31,30,31,31,30,31,30,31);
2ARRAY DDPM(12)=(31,30,31,31,28,31,30,31,30,31,31,30);
2ARRAY HARP(12)=(304,334,  0,31,59,90,120,151,181,212,243,273);
2ARRAY HAPP(12)=(0,31,59,90,120,151,181,212,243,273,304,334);
2ARRAY LABLE(3)=("DISCHARGE C.F.S.D");
2READ (;;COMBO);
2INPUT COMBO(TAPES,RUN);
2IF TAPES;
2BEGIN
2COMMENT SECTION READS STORAGE AND HOURLY PRECIPITATION DATA AND
2OUTPUTS WEIGHTED HOURLY RAINFALL ON TAPE 85;                              00500
2COMMENT OBS ON 24 HOUR DAY -  MIDNIGHT IS 24;
2COMMENT REWIND TAPE;
2REWIND(10);
2DDRECR=1;
2P1SUM=0.0;
2SIT=MO=0;READ  (;;STATYR);
2INPUT STATYR (YRS,FILX,SG);
2IF FILX GTR 0; MOVEFILE(10,FILX);
2FOR DDD=(1,1,YRS);
2   BEGIN
2   READ (;;WATYR);
2   INPUT WATHR (I1,I2);
2    FOR DD92=(1,1,12); (SUMPREC(DD92)=0; SUMPRECR(DD92)=0;);
2   YR=0;
2   MO=0;
2   DPY=365; DDPM(5)=28;
2 DPM(2)=28;
2   IF MOD (I2,4) EQL 0;
2      BEGIN
2      DPY=366;
2    OPM(2)=29;
2     DDPM(5)=29;
2      END;
2   FOR DD10=(1,1,367);PREC(DD10)=0.0;
2   IF SG GTR 0; UNTIL MO EQL 9;
2      BEGIN
2      READ(;;RR);
2      INPUT RR(STT,YR,MO,WSG,OBS,FOR DD14=(HAAP(MO)+1,1,HAAP(MO)+
2       DPM(MO)); PREC(DD14));
2    FOR DD15 = ( HAAP(MO) + 1, 1, HAAP(MO)+ DPM(MO));
2    SUMPREC(MO) = SUMPREC(MO) + PREC(DD15);
2      IF MO EQL 2; IF  DPM(2) EQL 29;
2         BEGIN
2         PREC(366)=PREC(60);
2         PREC(60)=0.0;
2         END;
2      END;
2   FOR DD85=(1,1,8884); THS(DD85)=0.0;
2   UNTIL TH GEQ 98;
2      BEGIN
2      READ(;;DATA);
2    FOR DD93 = (1 + 12.(CN-1),1,12+12.(CN-1));
2     SUMPRECR(MO) = SUMPRECR(MO) + TRS(24.(HAAP(MO)+DAY-1)+DD93);
2      IF MO EQL 2; IF DAY EQL 29;
2      FOR NX91=(1+12.(CN-1),1,12+12.(CN-1));
2         BEGIN
2         TRS(24.(366-1)+NX91)=TRS(24.(60-1)+NX91);
2         TRS(24.(60-1)+NX91)=0.0;
2         END;
2      END;
2   INPUT DATA(ST,YR, MO,DAY,CN,FOR HOUR=(1+12.(CN-1),1,12+12.(CN-1));
2   TRS(24.(HAAP(MO)+DAY-1)+HOUR));
2   COMMENT STORAGE GAGE ADJUSTMENT;
2   IF SG GTR 0;                                                           01050
2      BEGIN
2      DDL=273; KK=1.0;
2         FOR DDY=(274,1,365),(1,1,59),(366,1,DPY),(60,1,273);
2         BEGIN
2         FOR NXH=(1,1,24);
2            BEGIN
2            P1SUM=P1SUM+TRS(24.(DDY-1)+NXH);
2            IF NXH EQL OBS;
2            EITHER IF P1SUM GTR 0.0;
2               BEGIN
2               K(DDL)=PREC(DDY).WSG+P1SUM.(1.0-WSG))/P1SUM;
2               P1SUM=0.0;
2               END;
2            OTHERWISE;
2
2               BEGIN
2               EITHER IF OBS NEQ 1;
2               TRS(24.(DDY-1)+OBS)=TRS(24.(DDY-1)+OBS-1)=
2               0.5.WSG.PREC(DDY);
2               OTHERWISE;
2               TRS(24.(DDY-1)+OBS)=WSG.PREC(DDY);
2               K(DDL)=1.0;
2               END;
2            END;
2         DDL=DDY;
2         END;
2      KK=K(273);
2      FOR DDQ=(274,1,365),(1,1,59),366,1,DPY),(60,1,273);
2      FOR DDHR=(1,1,24);
2         BEGIN
2         TRS(24.(DDQ-1)+DDHR)=KK.TRS(24.(DDQ-1)+DDHR);
2         IF DDHR EQL OBS;(KK=K(DDQ); IF DQ EQL 273; KK=1.0;);
2         END;
2      END;
2   MOCOUNT=1; DDCOUNT=1; NX=1;  RECSUM=0.0;
2   FOR DDA=(274,1,365),(1,1,59),(366,1,DPY),(60,1,273);
2      BEGIN
2      FOR DDR=(1,1,24);
2         BEGIN
2         REC1(NX)=TRS(24.(DDA-1)+DDR);
2         RECSUM=RECSUM+REC1(NX );
2         NX=NX+1;
2         END;
2      DDCOUNT=DDCOUNT+1;
2      IF DDCOUNT EQL DDPM(MOCOUNT)+1;
2         BEGIN
2         NX=NX-1;
2         WAIT.. UNTIL CHECKM(10) NEQ 0; GO TO WAIT;
2         FOR NX5=(1,1,NX);
2         REC2(NX5)=REC1(NX5);
2         WRITEM (10,NX;REC2(1));
2         EITHER IF MOCOUNT LEQ 3; DDMOC=MOCOUNT+9;
2         OTHERWISE;DDMOC=MOCOUNT-3;
2         IF DDMOC EQL 10;
2            BEGIN                                                         01600
2            WRITE(;;TITL,TITLF);
2            OUTPUT TITL(DDRECR);
2            FORMAT TITLF(*TAPE*,B12,*RECORD*,B1,I3,B2,*GAGE*,W3);
2            DDRECR=DDRECR+1;
2            END;
2         WRITE(;;ANS,ANSF);
2         OUTPUT ANS(ST,I1,I2,DOMOC,RECSUM,SUMPRECR(DDMOC),
2    SUMPREC(DDMOC));
2         FORMAT ANSF (*STATION*,B2,I8,B2,*WATER  YEAR*,B2,I2,B1,I2,B2,
2         *MONTH(,B2,I2,B2,*TAPE PRECIP*,X8.2,B2,*RECORDER*,X8.2, B2,
2         *STORAGE GAGE*,X8.2,W2);
2         RECSUM=0.0;
2         NX=1;
2         DDCOUNT=1;
2         MOCOUNT=MOCOUNT+1;
2         END;
2      END;
2   END;
2   RZ..UNTIL CHECKM(10) NEQ 0; GO TO RZ;
2   ENDFILE (10);
2 IF RUN; REWIND(10);
2END;
2IF NOT RUN;   GO TO LFIN;
2ETL=1.0; YR=0; NXSEG=0;
2FOR DD28=(1,1,8884);TRS(DD28)=0.0;
2READ(;;RUNDAT);
2INPUT RUNDAT (FPYR,NXTSEG,MFILX);
2REWIND(10);
2   WAI5..UNTIL CHECKM(10) NEQ 0; GO TO WAI5;
2IF MFILX GTR 0; MOVEFILE (10,MFILX);
2LINY..
2YR=YR+1;
2NXSEG=NXSEG+1;
2IF YR GTR FPYR; GO TO LFIN;
2FOR DD46=(1,1,25);  CAS(DD46)=SERR(DD46)=SQER(DD46)=
2AVER(DD46)=AVAR(DD46)=0;
2FOR DD107=(1,1,367);SDIV(DD107)=DR(DD107)=0.0;
2READ (;;CONTROL);
2INPUT CONTROL(DD2,FOR DD1=(1,1,DD2);DCS(DD1),FLOWPOINT,
2SEG,TAREA,MAXCFS,TAPEMOVE,SHFT,MINH);
2TCFSD=26.9.TAREA;
2   WAI6..UNTIL CHECKM(10) NEQ 0; GO TO WAI6;
2IF ABS(TAPEMOVE) GTR 0;
2MOVEM(10,12,TAPEMOVE);
2   READ (;;NEWY);
2   INPUT NEWY (DDYR1,DDYR2,YEAR,FOR DD44=(1,1,10);QQD(DD44));
2DPY=DLY=365;       EXD=0.0;            DPM(2)=28;
2IF MOD (DDYR1,4) EQL 0;DLY=366;
2IF MOD (DDYR2,4) EQL 0; (DPY=366; DPM(2)=29; EXD=1.0;);
2COMMENT CARRYOVER FLOW;
2COMMENT BASIC TIME SHIFT;
2EITHER IF SHFT GTR 0;
2FOR DD4=(24.DPY,-1,1);TRS(DD4+SHFT)=TRS(DD4);
2OTHERWISE;FOR DD29=(1,1,8884);TRS(DD29)=0.0;
2FOR DD3=(1,1,200);TRS(DD3)=TRS(DD3)+TRSH(FLOWPOINT,DD3);                  02150
2
2IF NXSEG LEQ NXTSEG;
2READ (;;START);
2INPUT START (    FOR DD9=(1,1,SEG);(SGWS(FLOWPOINT,DD9),UZSS(FLOWPOINT,
2DD9),LZSS(FLOWPOINT,DD9),GWSS(FLOWPOINT,DD9)));
2   EITHER IF DCS(3);
2      BEGIN
2      READ (;;EVAPM);
2      INPUT EVAPM (FOR DD11=(1,1,24); EE(DD11));
2      DDE3=1;
2      FOR DDE1=(10,1,12),(1,1,9);
2         BEGIN
2         FOR DDE2=(1,1,DPM(DDE1));
2            BEGIN
2            E(HAAP(DDE1)+DDE2)=EE(DDE3);
2            IF DDE2 EQL 15; DDE3=DDE3+1;
2            END;
2         DDE3=DDE3+1;
2         END
2      END;
2   OTHERWISE;       READ (;;EVAP);
2   INPUT EVAP (FOR DD9=(274,1,365),(1,1,59),(366,1,DPY),(60,1,273);
2   E(DD9));
2   READ (;;EVC);
2   INPUT EVC(FOR DD78=(10,1,12),(1,1,9);EVCR(DD78));
2   IF DCS(9);
2      BEGIN
2      READ(;;EVAPS);
2      INPUT EVAPS(FOR DD85=(1,1,24);EES(DD85));
2      DDS3=1;
2      FOR DDS1=(10,1,12),(1,1,9);
2         BEGIN
2         FOR DDS2=((1,1,DPM(DDS1));
2            BEGIN
2            SE(HAAP(DDS1)+DDS2)=EES(DDS3);
2            IF DDS2 EQL 15;DDS3=DDS3+1;
2            END;
2         DDS3=DDS3+1;
2         END;
2      EITHER IF DCS(10); READ (;;RADIATION);
2      INPUT RADIATION (FOR DD76=(274,1,365),(1,1,59),(366,1,DPY),
2      (60,1,273); RAD(DD76));
2      OTHERWISE;
2      BEGIN
2      READ (;;MRAD);
2   INPUT      MRAD(FOR DDS5=(1,1,24);RAS(DDS5));
2   DDX3=1;
2   FOR DDX1=(10,1,12),(1,1,9);
2      BEGIN
2      FOR DDX2=(1,1,DPM(DDX1));
2         BEGIN
2         MAXRAD(HAAP(DDX1)+DDX2)=RAS(DDX3);
2         IF DDX2 EQL 15;DDX3=DDX3+1;
2         END;
2      DDX3-DDX3+1;                                                        02700
2      END;
2   END;
2READ(;;TEM);
2INPUT TEM (FOR DD19=(1,1730+2(DPY-365));T(DD19));
2      END;
2   FOR DD74=(1,1,366);FLO(DD74)=0.0;
2   IF DCS(4);  READ(;;FLOWS);
2   INPUT FLOWS (FOR DD17=(274,1,365),(1,1,59),366,1,DPS),60,1,273);
2   FLO(DD17));
2   IF DCS(5); READ(;;DIVER);
2INPUT DIVER (FOR DD53=(274,1,365),(1,1,59),(366,1,DPY),(60,1,273);
2SDIV(DD53));
2
2
2FOR DDSEG=(1,1,SEG);
2BEGIN
2
2SABC=0.0;
2   READ (;;TRI);
2   INPUT TRI (             FOR DD31=(1,1,12); QQQ(DD31));
2   READ(;;ARRA1);
2   INPUT ARRA1 (RINT,Z,FOR DD3=(1,1,Z);C(DD3));
2   READ (;;CL1);
2   INPUT CL1(K1,AREA,A);
2   READ (;;CL2);
2INPUT CLS(EPXM,UZSN ,LZSN,K3,K24L,K24EL,CB,CC,L,SS,NN);
2   READ (;;CL3);
2   INPUT CLS3(KS1,IRC,KV,KK24,ETL);
2   IF DCS(9); READ (;;CL4);
2   INPUT CL4(RADCON,CONMELT,SCF,ELDIF,IDNS,F,DGM,WC,MPACK,NXTAPM);
2   WAI7..UNTIL CHECKM(10) NEQ 0; GO TO WAI7;
2   IF DCS(9);
2   MOVEM(10,12,NXTAPM);
2   SGW1=SGW=SGWS(FLOWPOINT,DDSEG);
2   UZS1=UZS=UZSS(FLOWPOINT,DDSEG);
2   LZS1=LZS=LZSS(FLOWPOINT,DDSEG);
2   GWS=GWSS(FLOWPOINT,DDSEG);
2   SRC=1020.SQRT(SS)/NN.L);
2   DEC=0.00982.((NN.L/SQRT(SS))*0.6);
2   CFSD=26.9.REA;
2   CFS=24.CFSD;
2   LABEDO=0.75;
2TOTELH=0.0; NXSTORMS=0; NXFHI=0; NXFLOW=0;
2KK4=KK24*(1.0/96.0); LKK4=1.0-KK4;
2IRC4=IRC*(1.0/96.0); LIRC4=1.0-IRC4;
2SSGWF=SPR=SPRM=0.0
2 TEMP=50.0; NXTF=2; SPX1=0; COMMENT START EACH YEAR;
2PA=1.0-A;  SABC=SABD=SABM=0.0;
2EPX=EPXM;
2NXB=1;
2            WRITE(;;CHECOUT,CHKF);
2    OUTPUT CHECOUT(SGW,UZS,LZS,GWS,FLO(273),T(730+2.(DPY-365)));
2      FORMAT CHKF(4(X8.2),B2,*FLOW*,X8.2,B2,*TEMP*,X8.2,W2);
2   FOR MO=(10,1,12),(1,1,9);
2         BEGIN                                                            03250
2         WAZZ..UNTIL CHECKM(10) NEQ 0; GO TO WAZZ;
2         READM(10,24,DPM(MO);REC1(1));
2   SSF=0.0;
2         WAT..UNTIL CHECKM(10) NEQ 0; GO TO WAT;
2         CHECKM(10;DDSTAT);
2      IF DDSTAT EQL 1; WRITE (;;EOF);
2      FORMAT EOF(*END OF FILE READ ON LOGICAL 10(PRECIP INPUT)*,W2);
2      IF DDSTAT GTR 1;
2      WRITE (;;TRB);
2      FORMAT TRB(*POSSIBLE ERROR ON LOGICAL 10 CHECK PRECIP TOTALS*,
2W2);
2         FOR DAYMO=(1,1,DPM(MO));
2            BEGIN
2            DAY=HAAP(MO)+DAYMO;
2   EP=EVCR(MO).E(DAY);
2   SFM=0.0;
2   REP=0.0;
2   SCHGWF=PRPR=SFSF=0.0;
2   FOR HOUR=(1,1,24);
2      BEGIN
2      PR=0.0;
2      NX=24.(DAYMO-1)+HOUR;
2      EPHRLI=0.0;
2      IF HOUR GTR 8) AND (HOUR LSS 21); EPHRLI=0.08333333.EP;
2      ELH=EPHRLI.ETL;
2      PX=K1.REC1(NX);
2      IF NOT DCS(11);
2         SPR=SPR+PX;
2   IF DCS(9); ENTER SNOWMELTIV;
2      IF PX GTR 0.0; RNM=RNM+PX;
2      COMMENT 15 MIN ACCOUNTING AND ROUTING LOOP;
2      SF=0.0;
2      FOR DD23=(1,1,4);
2         BEGIN
2         EITHER IF DCS(11);
2            BEGIN
2            PR=0.0;
2             IF DD23 EQL 1;
2            (XX=PX+0.000000001;  PX=0.0;);
2            IF XX GTR 0.0;
2               BEGIN
2               PR=0.01.FIX(100.XX);
2               PX=PX+PR;
2               SPR=SPR+PR;
2               XX=100.(XX-PR);
2               END;
2            END;
2         OTHERWISE;
2         PR=0.25.PX;
2         EITHER IF PR GTR 0.0;
2         (PRPR=PRPR+PR;  GO TO L1; );
2         OR IF RES GTR 0.0;
2            BEGIN
2            P3=0.0; GO TO L2;
2            END;                                                          38000
2         OR IF SRGX GTR 0.0;
2            BEGIN
2            P3=0.0;
2            RDS=0.0; GO X2
2            END;
2            OTHERWISE; (P3=0.0; GO TO L4;);
2            L1..
2         IF TAB;CUMPREC=CUMPREC+PR;
2            COMMENT INTERCEPTIONS;
2            EPX=EPXM-SCEP;
2            IF EPX LSS 0.0; EPX=0.0;
2            EITHER IF PR LSS EPX;
2            BEGIN
2            SCEP=SCEP+PR;
2               P3=0.0;
2            END;
2         OTHERWISE;
2            BEGIN
2            P3=PR=EPX;
2            SCEP=SCEP+EPX;
2            END;
2         COMMENT P3 IS RAIN REACHING TEH GROUND SURFACE;
2         LNRAT=LZS/LZSN;
2         COMMENT LOWER ZONE AND GW INFILTRATION;
2            L2..P4=P3+RES;
2            EITHER IF LNRAT LSS 1.0; LNRATM=4.LNRAT;
2                OR IF LNRAD LSS 2.0; LNRATM=4.0+2(LNRAT-1.0);
2            OTHERWISE; LNRATM=6.0;
2            D3FV=CB/(2.0*LNRATM);
2         D4F=0.25.D3FV;
2            RATIO=CC.(2.0*LNRAT);
2         IF RATIO LSS 1.0; RATION =1.0;
2         EITHER IF P4 LSS D4F;
2            SHRD=P4.P4/(2.0.D4F);
2         OTHERWISE;  SHRD=P4-0.5.D4F;
2         EITHER IF P4 LSS D4F.RATIO;
2            RXX=P4.P4/(2.0.D4F.RATIO);
2         OTHERWISE;  RXX=P4=0.5.D4F.RATIO;
2            EITHER IF UZS LSS 2.0.UZSN;
2            BEGIN
2               UZI=2.0.ABS(0.5(UZS/UZSN)-1.0)+1.0;
2               PRE=(0.5.UZS/UZSN).(1.0/(1.0+UZI))*UZI;
2            END;
2            OTHERWISE;
2            BEGIN
2               UZI=2.0.ABS(((UZS/UZSN)-1.0)-1.0)+1.0;
2               PRE=1.0-(1.0/(1.0+UZI))*UZI;
2            END;
2         RGXX=SHRD-RXX;
2         RGX=RXX.PRE;
2         COMMENT RGX IS THE VOLUME TO INTERFLOW DETENTION STORAGE;
2         RX=RXX.PRE;
2         COMMENT RX IS THE VOLUME TO OVERLAND FLOW SURFACE DETENTION;
2         UZS=UZS+SHRD-RGX-RX;
2            IF DCS(1); IF UZS GTR 1.5(UZSN); IF NOT TAB;                  04350
2            BEGIN
2            DDIM=MO; DDID=DAYMO; DDIM=HOUR;
2            CUMPREC=CUMPREC+0.25.PX;
2            SCEPS=SCEP;
2            TAB=1; TABU=1;
2            END;
2         EITHER IF RX-RES GTR 0; DE=DEC.((RX-RES)*0.6);
2         OTHERWISE;DE=(RES+RX)/2.0;
2         IF (RES+RX) GTR 2.0.DE; DE=(RES+RX)/2.0;
2         EITHER IF (RES+RX) GTR 0.01;
2         ROS=0.25.SRC.(((RES+RX)/2.0)*1.67). ((1.0+0.6((RES+RX)
2         /2.0.DE)*3.0)*1.67);
2         OTHERWISE; ROS=0.0;
2         IF ROS GTR 0.75.RX; ROS=0.75.RX;
2         SROS=SROS+ROS;
2         IF TAB; SURRO=SURRO+ROS;
2         RES=RX-ROS;
2         IF RES LSS 0.001;
2            BEGIN
2            LZS=LZS+RES;
2         IF TAB; LZSIN=LZSIN+RES;
2            RES=0.0
2            END;
2         LZI=(1.5).ABS((LZS/LZSN)-1.0)+1.0;
2         PRE=(1.0/(1.0+LZI))*LZI;
2      IF LZS LSS LZSN; PRE=1.0-PRE.(LZS/LZSN);
2         COMMENT F3 HELD IN LOWER;
2         F3=PRE.(P4-SHRD);
2         F1A=(1.0-PRE).(P4-SHRD);
2         F1=F1A(1.0-K24L).PA;
2         IF TAB; INFDIR=INFDIR+F1+F3;
2         SGW=SGW+F1;
2         IF TAB;CUMSGWIN=CUMSGWIN+F1;
2         GWS=GWS+F1;
2         LZS=LZS+F3;
2         IF TAB; LZSIN=LZSIN+F3;
2         COMMENT INTERFLOW STORAGE IS SRGX;
2         SRGX=SRGX+RGX;
2         XS..INTF=LIRC4.SRGX;
2         IF TAB; INTRO=INTRO+INTF;
2         COMMENT SUM OF INTERFLOW IS SINT;
2         SINT=SINT+INTF;
2         SRGX=SRGX-INTF;
2         IF SRGX LSS 0.0001;
2            BEGIN
2            LZS=LZS+SRGX;
2            IF TAB; LZSIN=LZSIN+SRGX;
2            SRGX=0.0
2            END;
2         COMMENT GROUNDWATER FLOW CALC;
2         L4..
2         EITHER IF SGW GTR 0.00001;
2            GWF=SGW.LKK4.(1.0+KV.GWS);
2         OTHERWISE; GWF=0.0;
2         SCHGWF=SCHGWF=GWF;                                               04900
2         SGW=SGW-GWF;
2         IF TAB; CUMSGWOUT=CUMSGWOUT+GWF;
2         SSGWF=SSGWF+GWF;
2            R=(PA.ROS + P3.A+PA.INTF+GWF=0.25.ELH).CFS;
2         IF R LSS 0.0; R=0.0;
2         IF SF=SF+R;
2         IF TAB; IF R GTR 0.0; CUMEVAP=CUMEVAP+0.25.ELH;
2            IF TAB;TOTRO=TOTRO+(R/CFS);
2            IF R GTR 0; TOTELH=TOTELH+0.25.ELH;
2         COMMENT ENTER STATSUB HERE;
2         IF DCS(1);
2            BEGIN
2            IF DAY EQL 27;IF HOUR EQL 1; IF DD23 EQL 1;
2            WRITE(;;TITLE,TITLEG);
2            FORMAT TLESS(B3,*MO*,B5,*DAY*,B5,*TIME*,B6,
2            *RAIN*,B8,*INTERCEPT*,B3,*INFILT*,B6,*INTERFLOW*,B3,
2            *SURFACE*,B5,*GROUND*,B6,*TOTAL*,B5,*TOTAL-CFS*,W2);
2            EITHER IF 4.R LSS MINH;     DDEX=1;
2            OTHERWISE;
2               BEGIN
2                IF DDEX EQL 1; (WRITE(;;TLESS); DDEX=0.0;);
2            DDTIME=100.(HOUR-1)+15.DD23;
2            IF MOD(DDTIME,100) EQL 60; DDTIME=DDTIME+40;
2            WRITE(;;DETAIL,DETAILF);
2               END;
2            OUTPUT DETAIL(MO,DAYMO,DDTIME,PR,
2            PR-P3,F1+F3,INTF,ROS,GWF,R/CFS,4.R);
2            FORMAT DETAILF(I5,I7,I9,7(X12.3),X10.1,W0);
2            F1=F3=INTF=0.0;
2         END;
2         END;
2      COMMENT END OF 15 MIN LOOP;
2      SFSF=SFSF+SF;
2      DDI=NXB;
2      COMMENT TRANSLATION IN TIME;
2   SC=SF/CFS;
2         EITHER IF SC GTR 0.01;
2         BEGIN
2         FOR DD=(1,1,Z);
2            BEGIN
2            DDX=DDI+RINT(DD-1);
2            TRS(DDX)=TRS(DDX)+SF.C(DD);
2               END;
2            END;
2         OTHERWISE;TRS(DDI+(Z.RINT/2))=TRS(DDI+(Z.RINT/2))+SF;
2            SSF=SSF+SF;
2         IF DCS(7);
2         BEGIN
2            IF SC GTR 0.0;
2            BEGIN
2               FOR DD33=(20,-1,1);
2               EITHER IF SC GTR MXRO(DD33);MXRO(DD33+1)=MXRO(DD33);
2               OTHERWISE;
2                  BEGIN
2                  MXRO(DD33+1)=SC;                                        05450
2               GO TO Z100;
2               END;
2            MXRO(1)=SC;
2         END;
2         Z100..
2         IF PX GTR 0.0;
2         BEGIN
2            FOR DD34=(20,-1,1);
2            EITHER IF PX GTR MXRA(DD34); MXRA(DD34+1)=MXRA(DD34);
2            OTHERWISE;
2               BEGIN
2                MXRA(DD34+1)=PX;
2                GO TO Z200;
2                END;
2            MXRA(1)=PX;
2         END;
2         Z200..
2      END;
2      IF EPHRLI EQL 0.0; GO TO PASS;
2     IF SCEP GTR 0.0;
2      EITHER IF SCEP GTR EPHRLI;
2         BEGIN
2         SCEP=SCEP-EPHRLI;
2         SAET=SAET+EPHRLI;
2         IF TAB;CUMEVAP=CUMEVAP+EPHRLI;
2         EPHRLI=0.0;
2         GO TO PASS;
2         END;
2      OTHERWISE;
2         BEGIN
2         EPHRLI=EPHRLI-SCEP;
2         SAET=SAET+SCEP;
2         IF TAB;CUMEVAP=CUMEVAP+SCEP;
2         SCEP=0.0;
2         END;
2      IF UZS GTR 0.0;
2      EITHER IF UZS GTR EPHRLI;
2         BEGIN
2         UZS=UZS-EPHRLI;
2         IF UZS LSS 1.5.UZSN; TAB=0;
2         SAET=SAET+PA.EPHRLI;
2         IF TAB;CUMEVAP=CUMEVAP+PA.EPHRLI;
2         EPHRLI=0.0;
2         GO TO PASS;
2         END;
2       OTHERWISE;
2         BEGIN
2         EPHRLI=EPHRLI-UZS;
2         SAET-SAET+PA.UZS;
2         IF TAB;CUMEVAP=CUMEVAP+PA.UZS;
2         UZS=0.0;
2         END;
2   REP=REP+EPHRLI;
2      PASS..
2      DEEPL =(UZS/UZSN)- (LZS/LZSN);                                      06000
2      IF DEEPL GTR 0.0;
2         BEGIN
2         LNRAT=LZS/LZSN;
2         RECE=0.003.CB.UZSN.(DEEPL*3);
2         UZS=UZS-RECE;
2         IF UZS LSS 1.5(UZSN); TAB=0;
2         IF TAB; INFUP=INFUP+RECE;
2         LZI=(1.5).ABS(LNRAT-1.0)+1.0;
2         PRE=(1.0/(1.0+LZI))*LZI;
2         IF LZS LSS LZSN; PRE=1.0-PRE.LNRAT;
2         F3=PRE.RECE;
2         F1A=(1.0-PRE).RECE;
2         F1=F1A.(1.0-K24L).PA;
2         LZS=LZS+F3;
2         IF TAB; LZSIN=LZSIN+F3;
2         SGW=SGW+F1;
2         IF TAB; CUMSGWIN=CUMSGWIN+F1;
2         F1=F3=3.0;
2         GWS=GWS+F1
2         END;
2      COMMENT EVAPORATION 7PM;
2      IF HOUR EQL 21;
2         BEGIN
2         SPET=SPET+EP;
2         EP=REP;
2         IF GWS GTR 0.00001;
2         GWS=0.98.GWS;
2         LUS=SGW.K24EL.EP.PA;
2         COMMENT EVAP-TRANS LOSS FROM GROUNDWATER;
2         SGW=SGW-LOS;
2         GWS=GWS-LOS;
2   TOTELH=TOTELH+LOS;
2         IF GWS LSS 0.0; GWS=0.0;
2         IF EP NEQ 0.0;
2            BEGIN
2               LNRAT=LZS/LZSN;
2               EITHER IF EP LSS K3.LNRAT;
2                  BEGIN
2                  AETR=EP.(1.0-(EP/(2.0.K3.LNRAT)));
2                   LZS=LZS-AETR;
2                  SAET=SAET+PA.AETR;
2                   END;
2               OTHERWISE;
2                  BEGIN
2                   EATR=0.5.(K3.LNRAT);
2                   LZS=LZS-AETR;
2                  SAET=SAET+PA.AETR;
2                   END
2            END
2         END;
2        NXB=NXB+1;
2   IF DCS(1);
2      BEGIN
2     FORMAT SAND(B5,*STORM PERIOD*,B5,*PRECIP*,B1,*EVAP*,B1,*SGWIN*,B1,
2         *SGWOUT*,B1,*LZSIN*,B1,*SURF-RO(,   B1,*INTER-RO*,B1,            06550
2      *TOTAL-RO*,B1,*INFILT-UP*,B1,*INFILT-DIR*,B2,*CB/GW*,B2,*CB/RO*,
2           B2,
2         *SGWCOR*,B2,*CB*,B2,*LZRAT*,W2);
2      IF TAB; GO TO LEND; COMMENT CONTINUING STORM;
2      IF NOT TABU; GO TO LEND; COMMENT STORM ENDED AND PROCESSED;
2       IF CUMSGWIN LSS CUMSGWOUT; GO TO RESET;
2      COMMENT SMALL STORM;
2         BALNC=CUMPREC-CUMEVAP-CUMSGWIN+CUMSGWOUT-LZSIN.PA-TOTRO+SCEPS
2         -SCEP;
2      IF ABS(BALNC) GTR 0.01;
2      WRITE(;;BALN1,BALN1F);
2      OUTPUT BALN1 (BALNC);
2      FORMAT BALN1F (B10,*STORM BALANCE IS*,B2,X7.2,W2);
2      IF CUMRECFLOW GTR 0.0;
2      SFRAT=CUMSIMFLOW/CUMRECFLOW;
2      IF FLO(DAY) GTR 0.0;
2         BEGIN
2      GFRAT=SF/FLO(DAY);
2      IF GFRAT GTR 0.0;
2      CBGW=CB/GFRAT;
2      CBRO=CB.SFRAT;
2         NXSTORMS=NXSTORMS+1;
2         IF (CBGW LSS 0.9.CB) AND (CBRO GTR 1.1.CB); NXFHI=NXFHI+1;
2         IF (CBGW GTR 1.1.CB) AND (CBRO LSS 0.9.CB); NXFLOW=NXFLFOW+1;
2            END;
2      SGWCUR=0.0;
2      IF DCS(2);
2         BEGIN
2            IF SF GTR 0.0;
2            BEGIN
2         NEWSGW=SGW.(FLO(DAY))/SF;
2         SGWCOR=NEWSGW-SGW;
2         SGW=NEWSGW;
2         END;
2            IF INFDIR GTR 0.33.INFUP;
2            BEGIN
2         IF (CBGW LSS 0.9.CB) AND (CBRO LSS 0.9.CB); CB=0.8.CB;
2         IF (CBGW GTR 1.1.CB) AND (CBRO GTR 1.1.CB); CB=1.2.CB;
2            END;
2         END;
2         WRITE (;;SAND);
2      WRITE(;;EZQ,EZQF);
2      OUTPUT EQZ(DDIM,DDID,DDIH,MO,DAYMO,HOUR,
2      CUMPREC,CUMEVAP,CUMSGWIN,CUMSGWOUT,SZSIN,
2      SURRO,INTRO,TOTRO,INFUP,INFDIR,CBGW,CBRO,
2      SGWCOR,CB,LZS/LZSN);
2   FORMAT EQZF(I2,*/*,I2,*/*,I2,B1,*TO*,B1,
2      I2,*/*,I2,*/*,I2,B2,X5.2,B1,X4.2,B2,X4.2,
2      B2,X4.2,B3,X4.2,B2,X4.2,B4,X4.2,B6,X4.2,
2      B5,X4.2,B7,X4.2,B5,X5.2,B2,X5.2,B3,X5.2,B1,X5.2,
2      B2,X4.2,W2);
2      RESET.. CUMPREC=CUMEVAP=CUMSGWIN=CUMSGWOUT=0.0;
2         LZSIN=SURRO=INTRO=TOTRO=INFUP=INFDIR=0.0;
2      CBGW=SGWCOR=CBRO=0.0;
2      CUMSIMFLOW=CUMRECFLOW=0.0;                                          07100
2      TABU=0;
2      LEND..
2      END;
2      END;
2   COMMENT END OF HOUR LOOP;
2   IF TAB;
2      BEGIN
2      CUMSIMFLOW=CUMSIMFLOW+SFSF;
2         CUMERCFLOW=CUMRECFLOW+24.FLO(DAY);
2      END;
2  END;
2   COMMENT END OF DAY LOOP;
2   TONE(MO)=SSF/CFS;
2     GWSA(MO)=GWS;
2      SPRA(MO)=SPR;    SPR=0.0;
2      SPRMA(MO)=SPRM;    SPRM=0.0;
2      SGWFA(MO)=SSGWF;   SSGWF=0.0;
2      SINTA(MO)SINT;    SINT=0.0;
2      SPETA(MO)=SPET;   SPET=0.0;
2      SAETA9MO)=SAET;   SAET=0.0;
2      RNMM(MO)=RNM;  RNM=0.0;
2      MSURE(MO)=MSUREVAP;  MSUREVAP=0.0;
2      RADMES(MO)=RADME;   RADME=0.0;
2      SCOMELTA(MO)=SCOMELT;  SCOMELT=0.0;
2      SGWA(MO)=SGW;
2      UZSA(MO)=UZS;
2      LZSA(MO)=LZS;
2END;
2COMMENT END OF MONTH LOOP;
2WRITE (;;TRIAL,TRIALF);
2OUTPUT TRIAL (FOR DD32=(1,1,12);QQQ(DD32));
2FORMAT TRIALF(B10,A72,W3);
2WRITE (;;TITLE,TITLEF);
2OUTPUT TITLE(FOR DD45=(1,1,10);QQO(DD45),DDYR1,DDYR2);
2FORMAT TITLEF    (A60,B3,*WATER YEAR  19*,I2,*-*,I2,B7,
2*STANFORD WATERSHED MODEL IV *,W2);
2SABC=RNA=TZN=RNB=SSAET=SSPET=SSINT=0.0;
2SRADME=SRNM=SMS=SCO=0.0;
2FOR DD25=(1,1,12);
2   BEGIN
2   SABC=SABC+TONE(DD25);
2   RNA=RNA+SPRA(DD25);
2   TZN=TZN+SGWFA(DD25);
2   RNB=RNB+SPRMA(DD25);
2   SSAET=SSAET+SAETA(DD25);
2   SSPET=SPET+SPETA(DD25);
2   SSINT=SSINT+SINTA(DD25);
2   SRADME=SRADME+RADMES(DD25);
2      SCO=SCO+SCOMELTS(DD25);
2      SMS=SMS+MSURE(DD25);
2   SRNM=SRNM+RNMM(DD25);
2   END;
2WRITE (;;HSUM);
2FORMAT HSUM(B8,*DAY*,B6,*OCT*,B5,*NOV*,B5,*DEC*,B5,*JAN*,B5,*FEB*,B5,
2*MAR*,B5,*APR*,B5,*MAY*,B5,*JUN*,B5,*JUL*,B5,*AUG*,B5,*SEPT*,B9,          07650
2*ANNUAL*,W2);
2WRITE (;;YY2,YY2F);
2OUTPUT YY2(FOR NX0=(10,1,12),(1,1,9);TONE(NX0),SABC);
2FORMAT YY2F (*TOTAL*,B7,12(S8.3),B3,X7.2,B2,*INCHES*   ,W);
2WRITE ($$YY40,YY40F);
2OUTPUT YY40(FOR NX40=(10,1,12),(1,1,9);SINTA(NX40),SSINT);
2FORMAT YY40F(*INTERFLOW*,B3),12(S8.3),B3,S7.3,B2,*INCHES*   ,W);
2WRITE (;;YN5,YN5F);
2OUTPUT YN5(FOR DD30=(10,1,12),(1,1,9);SGWFA(DD30),TZN);
2FORMAT YN5F(*BASE*,B8,12(S8.3),B3,S7.3,B2,*INCHES*   ,W);
2WRITE ($$YY15,YY15F);
2OUTPUT YY15(FOR NX15=(10,1,12),(1,1,9);SPRA(NX15),RNA);
2FORMAT YY15F(*PRECIP*,B6,12X8.2,B2,X8.2,B2,*INCHES*   ,W2);
2   IF DCS(9);
2      BEGIN
2     WRITE(;;FR1,FR1F);
2      OUTPUT FR1(FOR NX1=(10,1,12),(1,1,9);RNMM(NX1),SRNM);
2      FORMAT FR1F(*RAIN+EF MELT*,12X8.2,B2,X8.2,B2,*INCHES*,W);
2     WRITE(;;FR2,FR2F);
2      OUTPUT FR2(FOR NX2=(10,1,12),(1,1,9);RADMES(NX2),SRADME);
2      FORMAT FR2F(*RAD MELT*,B4,12X8.2,B2,X8.2,B2,*INCHES*,W);
2     WRITE(;;FR2,FR3F);
2      OUTPUT FR3(FOR NX3=(10,1,12),(1,1,9);SCOMELTS(NX3),SCO);
2      FORMAT FR3F(*CONV MELT*,B3,12X8.2,B2,X8.2,B2,*INCHES*,W);
2     WRITE(;;FR4,FR4F);
2      OUTPUT FR4(FOR NX4=(10,1,12),(1,1,9);MSURE(NX4),SMS);
2      FORMAT FR4F(*EVAP-SNOW*,B3,12X8.2,B2,X8.2,B2,*INCHES*,W2);
2      END;
2WRITE($$YY17,YY17F);
2OUTPUT YY17(FOR NX27=(10,1,12),(1,1,9);SAETA(NX27),SSAET);
2FORMAT YY17F(*EVP/TRAN-NET*,12(S8.3),B3,S7.3,B2,*INCHES*   ,W);
2WRITE (;;YY18,YY18F);
2OUTPUT YY18(FOR NX28=(10,1,12),(1,1,9);SPETA(NX28),SSPET);
2FORMAT YY18F(B2,*-POTENTIAL*,12(S8.3),B3,S7.3,B2,*INCHES*   W2);
2WRITE (;;YY31,YY31F);
2OUTPUT YY31(FOR NX21=(10,1,12),(1,1,9);UZSA(NX21));
2FORMAT YY31F(*STORAGES-UZS*,12(S8.3),B12,*INCHES*   ,W);
2WRITE (;;YY8,YY8F);
2OUTPUT YY8(FOR NX8=(10,1,12),(1,1,9);LZSA(NX8));
2FORMAT YY8F(B9,*LZS*,12(S8.3),B12,*INCHES*   ,W);
2WRITE (;;YY22,YY22F);
2OUTPUT YY22(FOR NX17=(10,1,12),(1,1,9);SGWA(NX17));
2FORMAT YY22F(B9,*SGN*,12(S8.3),B12,*INCHES*   ,W2);
2WRITE (;;YY30,YY30F);
2OUTPUT YY30(FOR NX20=(10,1,12),(1,1,9); GWSA(NX20));
2FORMAT YY30F(*INDICES- GWS*,12(S8.3),W);
2BAL=(LZS+UZS-LZS1-UZS1).PA+SGW-SGW1+SABC+TOTELH+SSAET   -RNA;
2WRITE(;;BALOUT,BALOUTF);
2OUTPUT BALOUT(BAL);
2FORMAT BALOUTF(*BALANCE*,B5,X10.4,B2,*INCHES*,W2);
2IF DCS(1);               IF DCS(2);
2WRITE(;;HHH1,HHH1F);
2OUTPUT HHH1(1.0-
2            (NXFHI+NXFLOW)/FLOAT(NXSTORMS),NXFHI,NXFLOW,NXSTORMS);
2FORMAT HHH1F (*DATA CONSISTENCY INDEX*, B2,X7.2,B2,*HIGH INPUT INDICATI   08200
2ONS*,B2,I5,B2,*LOW INPUT INDICATIONS*,B2,I5,B2,*TOTAL STORMS*,B2,I5,W2)
2 ;
2IF NOT DCS(7); GO LBQ;
2 COMMENT OUTPUT  MAX. RUNOFF,PRECIP. AT END OF YEAR;
2   WRITE ($$HEADX);
2   FORMAT HEADX(B10,*TWENTY HIGHEST CLOCKHOUR RAINFALL EVENTS IN THE WA
2TER YEAR*,W2);
2   WRITE(;;RAMAX,RAMAXF);
2   OUTPUT RAMAX(FOR DD36=(1,1,20);MXRA(DD36));
2WRITE (;;HEADY);
2   FORMAT HEADY(B10,*TWENTY HIGHEST CLOCKHOUR OVERLAND FLOW RUNOFF EVEN
2TS IN THE WATER YEAR*,W2);
2   OUTPUT ROMAX(FOR DD37=(1,1,20);MXRO(DD37));
2   WRITE (;;ROMAX,RAMAXF);
2   FORMAT RAMAXF (B5,20(X6.3),W2);
2   FOR DD35=(1,1,20); MXRA(DD35)=MXRO(DD35)=0.0;
2LBQ..DDCOM=0;
2UZSS(FLOWPOINT,DDSEG)=UZS;
2LZSS(FLOWPOINT,DDSEG)=LZS;
2SGWS(FLOWPOINT,DDSEG)=SGW;
2GWSS(FLOWPOINT,DDSEG)=GWS;
2END;
2
2COMMENT END OF SEGMENT LOOP;
2NXC=0; SSABD=0.0;
2SSABM=0.0;
2WRITE (;;TITLE,TITLEG);
2FORMAT TITLEG    (A60,B3,*WATER YEAR  19*,I2,*-*,I2,B7,
2*STANFORD WATERSHED MODEL  IV *,W3);
2
2FOR M1=(10,1,12),(1,1,9);
2   BEGIN
2SWITCH M1,(1,2,3,4,5,6,7,8,9,10,11,12);
21..WRITE(;;HJAN);GO W;2..WRITE(;;HFEB);GO W;3..WRITE(;;HMAR); GO W;
24..WRITE(;;HAPR);GO W;5..WRITE(;;HMAY);GO W;6..WRITE(;;HJUN); GO W;
27..WRITE(;;HJUL);GO W;8..WRITE(;;HAUG);GO W;9.. WRITE(;;HSEPT);GO W;
210..WRITE(;;HOCT);GO W;11..WRITE(;;HNOV);GO W;12..WRITE(;;HDEC);GO W;
2FORMAT HNOV(*NOVEMBER*,W2); FORMAT HDEC(*DECEMBER*,W2);
2FORMAT HJAN(*JANUARY*,W2); FORMAT HFEB(*FEBRUARY*,W2);
2FORMAT HMAR(*MARCH*,W2); FORMAT HAPR(*APRIL*,W2);  FORMAT HMAY(*MAY*,
2W2);  FORMAT HJUN(*JUNE*,W2);  FORMAT HJUL(*JULY*,W2);
2FORMAT HAUG(*AUGUST*,W2); FORMAT HSEPT(*SEPTEMBER*,W2);
2FORMAT HOCT(*OCTOBER*,W2);
2W..
2SABD=SABM=0.0;
2FOR DAYS=(1,1,DPM(M1));
2   BEGIN
2   SUMSF=0.0;
2   NXPRINT=0;
2   DAY=HAAP(M1)+DAYS;
2   IF (DAYS EQL 29) AND (M1 EQL 2); DAY=366;
2   FOR HOUR=(1,1,24);
2      BEGIN
2      NXC=NXC+1;
2      IN=TJS(NXC)+SDIV(DAY);                                              08750
2      EITHER IF IN LSS 0.0000001;
2      SF=IN;
2   OTHERWISE;
2      SF=IN-KS1.(IN-LSF);
2      IF SF GTR MINH; NXPRINT=1;
2      LSF=SF;
2      TR(HOUR)=SF;
2      TRS(NXC)=SF;
2      SUMSF=SUMSF+SF;
2      END;
2   DRDAY=DR(DAY)=SUMSF/24.0;
2   IF NXPRINT GTR 0;
2      BEGIN
2      WRITE(;;HOURFLOW1,HRF1);
2      WRITE(;;HOURFLOW2,HRF2);
2      END;
2   OUTPUT HOURFLOW1(DAYS         ,FOR HOUR=(1,1,12);TR(HOUR));
2   OUTPUT HOURFLOW2(FOR HOUR=(13,1,24);TR(HOUR),DRDAY);
2   FORMAT HRF1(I4,B2,*AM*,B1,6X8.1,B3,6X8.1,W);
2   FORMAT HRF2(B6,*PM*,B1,6X8.1,B3,7X8.1,W2);
2   SABD=SABD+FLO(DAY);
2   SABM=SABM+DR(DAY);
2   COMMENT STORE ERRORS AND FLOW DURATION;
2   IF NOT DCS(6); GO TO LBY;
2   ERR=DR(DAY)=FLO(DAY);
2   IF ABS(ERR) LSS 0.000001; ERR=0.0;
2   EITHER IF FLO(DAY) LSS 1.0; IND=1.0;
2   OTHERWISE; IND=2.LOG(FLO(DAY))+2.0;
2   CAS(IND)=CAS(IND)+1.0;
2   SERR(IND)=SERR(IND) +ERR;
2   SERA(IND)=SERA(IND) +ABS(ERR);
2   SQER(IND)=SQER(IND)+ERR.ERR;
2   AVER(IND)=SERR(IND)/CAS(IND);
2   AVAR(IND)=SERA(IND)/CAS(IND);
2   EITHER IF CAS(IND) GTR 1;
2     SQ(IND)=SQRT((SQER(IND)-((SERR(IND))*2)/CAS(IND))/(CAS(IND)-1.0));
2   OTHERWISE;
2     SQ(IND)=0.0;
2   LBY..
2   END;
2COMMENT END OF DAYS LOOP;
2TONN(M1)=SABM;
2SSABM=SSABM+SABM;
2TOND(M1)=SABD;
2SSABD=SSBD+SABD;
2END;
2COMMENT END OF M1 LOOP;
2FOR NX57=(1,1,200);
2TRSH(FLOWPOINT,NX57)=TRS(24.DPY+NX57);
2
2WRITE (;;TITLE,TITLEG);
2WRITE(;;HSUM);
2FOR DD27=(1,1,28);
2   BEGIN
2   EITHER IF MOD(DD27,5) EQL 0;WRITE (;;FLTAB,FLTAB2);                    09300
2   OTHERWISE;WRITE (;;FLTAB,FLTAB1)
2   END;
2EITHER IF DPY EQL 366;
2   BEGIN
2   DD27=29;    DR(60)=DR(366);
2   WRITE(;;FLTAB,FLTAB1);
2   END;
2OTHERWISE;
2WRITE (;;DA29,DA29F);
2OUTPUT DA29(DR(302),DR(333),DR(363),DR(29),DR(88),DR(119),DR(149),
2DR(180),DR210),DR241),DR(272));
2FORMAT DA29F(B7,*29*,B3,4(X8.1),B3,*---*,B2,7(X8.1),W);
2WRITE (;;DA30,DA30F);
2OUTPUT DA30(DR(303),DR(334),DR(364),DR(30),DR(89),DR(120),DR(150),
2DR(181),DR(211),DR(242),DR(273));
2FORMAT DA30F(B7,*30*,B3,4(X8.1),B8,7(X8.1),W);
2WRITE (;;DA31,DA31F);
2OUTPUT DA31(DR(304),DR(365),DR(31),DR(90),DR(151),DR(212),DR(243));
2FORMAT DA31F(B7,*31*,B3,X8.1,B8,2X8.1,B8,X8.1,B8,X8.1,B8,2X8.1,W2);
2OUTPUT FLTAB (DD27,FOR DD26=12,(1,1,11);DR(HARP(DD26)+DD27));
2FORMAT FLTAB1(B3,I6,B3,12(X8.1),W);
2FORMAT FLTAB2(B3,I6,B3,12(X8.1),W2);
2WRITE (;;YY1,YY1F);
2OUTPUT YY1(FOR NX58=(10,1,12),(1,1,9);TONN(NX58),SSABM);
2FORMAT YY1F(*SYNTHESIS*,B3,12(X8.0),B1,X9.0,B2,*CFSD*,W);
2WRITE (;;YZ1,YZ1F);
2OUTPUT YZ1(FOR NX59=(10,1,12),(1,1,9);TONN(NX59)/TCFSD,SSABM/TCFSD);
2FORMAT YZ1F(B12,12(S8.3),B2,X8.1,B2,*INCHES*,W );
2WRITE (;;Y23,YY23F);
2OUTPUT YY23(1.98.SSABM);
2FORMAT YY23F(B109,X9.0,B2,*ACFT*,W2);
2IF NOT DCS(4); GO TO OMBY;
2WRITE (;;YY10,YY10F);
2OUTPUT YY10(FOR NX59=(10,1,12),(1,1,9);TOND(NX59),SSABD);
2FORMAT YY10F(*RECORDED*,B4,12(X8.0),B1,X9.0,B2,*CFSD*,W);
2WRITE (;;YY24,YY24F);
2OUTPUT YY24(FOR NX60=(10,1,12),(1,1,9);TOND(NX60)/TCFSD,SSABD/TCFSD);
2FORMAT YY24F(B12,12(S8.3),B2,X8.1,B2,*INCHES*,W);
2WRITE (;;YY25,YY25F);
2OUTPUT YY25(YEAR,1,98.SSABD);
2FORMAT YY25F(B92,*(*,X9.0,B2,*)*,B4,X9.0,B2,*ACFT*,W2);
2OMBY..
2IF NOT DCS(6); GO TO DJ;
2WRITE (;;ERS);
2FORMAT ERS(B10,*DAILY FLOW DURATION AND ERROR TABLE*,W3);
2FORMAT ERT (B10,*FLOW INTERVAL*,B5,*CASES*,B3,*AV.ERROR*,B3,*AVR. ABS.
2ERROR*,B3,*STANDARD ERROR*,W2);
2WRITE (;;ERT);
2 SCASE=SSERR=SSERA=SSTER=0.0;
2FOR DD30=(1,1,25);
2   BEGIN
2   EITHER IF DD30 EQL 1; FLOO=0.0;
2      OR IF DD30 EQL 2; FLOO=1.0;
2   OTHERWISE; FLOO=EXP((DD30/2.0)-1.0);
2   CAAS=CAS(DD30);                                                        09850
2   OUTPUT ERRS1(FLOO,CAAS,SERR(DD30)/CAAS);
2   OUTPUT ERRS0 (FLOO,CAAS);
2   OUTPUT ERRS(FLOO,CAAS,SERR(DD30)/CAAS,SERA(DD30)/CAAS, SQ(DD30));
2   FORMAT ERRSF( B13,X8.1,*-*,X9.1,X12.1,B5,X8.2,B5,X8.2,W);
2   EITHER IF CAAS EQL 0.0; WRITE (;;ERRS0,ERRSF);
2   OR IF CAAS EQL 1.0; WRITE (;;ERRS1,ERRSF);
2   OTHERWISE;WRITE($$ERRS,ERRSF);
2   SCASE=SCASE+CAS(DD30);
2   SSERR=SSERR+SERR(DD30);
2   SSERA=SSERA+SERA(DD30);
2   SSTER=SSTER+SQ(DD30);
2   END;
2OUTPUT ERRSUM (SCASE,SSERR,SSERA,SSTER);
2FORMAT ERRSUMF(B22,X9.1,X12.1,B3,X10.2,B3,X10.2,W2);
2WRITE (;;ERRSUM,ERRSUMF);
2MEANSY=SABC/DPY;  MEANAC=SABD/DPY;
2ZACDIF=ZSYDIF=PRODIF=0.0;
2FOR DD38=(1,1,DPY);
2BEGIN
2   ACDIF=FLO(DD38)-MEANAC;
2SYDIF=DR(DD38)-MEANSY;
2ZACDIF=ZACDIF+ACDIF.ACDIF;
2ZSYDIF=ZSYDIF+SYDIF.SYDIF;
2   PRODIF=PRODIF+ACDIF.SYDIF;
2END;
2CORCO=PROD1F/SQRT(ZACDIF.ZSYDIF);
2OUTPUT COR(CORCO);
2WRITE (;;COR,CORF);
2FORMAT CORF(B10,*CORRELATION COEFFICIENT (DAILY)*,B3,X10.4,W2);
2DJ..
2IF DCS(8);
2   BEGIN
2   ENTER PLOT10;
2COMMENT DRAW AXIS;
2   COMMENT HORIZONTAL AXIS;
2   FOR X=31.0,61.0,92.0,123.0,151.0+EXD,182.0+EXD,212.0+EXD,243.0+EXD,
2   273.0+EXD,304.0+EXD,335.0+EXD,365.0+EXD;
2      BEGIN
2      PLOT(;X/10.0,0.0,2);
2      PLOT(;X/10.0,0.2,2);
2      PLOT(;X/10.0,0.0,2);
2      END;
2   DR(367)=FLO(367)=MAXCFS;
2   FOR DD82=(1,1,366);
2      BEGIN
2      IF DR(DD82) GTR MAXCF;DR(DD82)=MAXCFS;
2      IF FLO(DD82) GTR MAXCFS;FLO(DD82)=MAXCFS;
2      END;
2   SCALE(;DR(),367,10.0,SACT,YMIN,DY);
2   SCALE(;FLO(),367,10.0,SSACT,YYMIN,DYY);
2   AXIS(;0.0,0.0,LABLE(1),18,SACT,90.0,YMIN,DY);
2   PLOTWRITE (20.0,8.57,0.14,0.0;;FMT2);
2   FORMAT FMT2(*STANFORD WATERSHED MODEL IV*,E);
2   PLOTWRITE (20.0,8.07,0.14,0.0;;PLTX,PLTXF);
2   OUTPUT PLTX(FOR DD76=(1,1,10);QQO(DD76),DDYR1,DDYR2);                  10400
2   FORMAT PLTXF(A60,B3,*19*,I2,*-*,I2,E);
2   PLOTWRITE(20.0,7.57,0.14,0.0;;PLTI,PLTIF);
2   OUTPUT PLTI(FOR DD75=(1,1,12);QQQ(DD75));
2FORMAT PLTIF(A72,E);
2      PLOT (;1.5,0.0,3);
2   PLOTWRITE  (1.5,-0.2,0.14,0.0;;FMT);
2   FORMAT FMT(*OCTOBER*,B18,*NOVEMBER*,B17,*DECEMBER*,B17,
2  *JANUARY*,B18,*FEBRUARY*,B17,*MARCH*,E);
2   PLOTWRITE(19.5,-0.2,0.14,0.0;;FMTA);
2FORMAT FMTA(*APRIL*,B20,*MAY*,B21,*JUNE*,B20,*JULY*,B20,*AUGUST*,
2   B19,*SEPTEMBER*,E);
2      PLOT(;0.0,-0.2,3);
2      PLOT(;0.0,0.0,3);
2   COMMENT PLOT RECORDED FLOW;
2   PLOT(;0.0,0.0,3);
2   X=0.0;
2   FOR DDAY1=(274,1,365),(1,1,59),(366,1,DPY),(60,1,273);
2      BEGIN
2      X=X1.0;
2      PLOT(;X/10.0,FLO(DDAY1),2);
2      END;
2   PLOT(;0.0,0.0,-3);
2   COMMENT PLOT SYNTHESIS/ CHANGE TO RED;
2   X=0.0;
2   FOR DDAY2=(274,1,365),(1,1,59),(366,1,DPY),60,1,273);
2      BEGIN
2      X=X+1.0;
2      PLOT(;X/10.0,DR(DDAY2),2);
2      END;
2   PLOT(;(DPY/10.0)+6.0,0.0,-3);
2   COMMENT CLOSE OUT PLOT;
2END;
2COMMENT END OF PLOT LOOP;
2 GO TO LINY;
2SUBROUTINE SNOWMELTIV;
2   BEGIN
2   M=0.0;
2   IF DAY EQL 274;IF HOUR EQL 1; WRITE (;;TRIAL,TRIALF);
2   IF DAY EQL 274; IPACK=0.1.MPACK;
2   COMMENT CALCULATE CONTIN TEMPERATURE;
2   TEMPGRAD=GRAD(HOUR).CHANGE);
2   TEMP=TEMP+TEMPGRAD;
2   IF (HOUR EQL 6) OR (HOUR EQL 16);
2   BEGIN
2      EITHER IF DCS(13);
2      BEGIN
2      EITHER IF MOD(NXTF,2) EQL 0;NXTF-NXTF-1;
2      OTHERWISE;NXTF=NXTF+3;
2      COMMENT INPUT SERIES IS TMAX, TMIN EACH DAY, TMAX OCCURS
2      BEFORE OBSERVATION TIME;
2      END;
2      OTHERWISE;
2      NXTF=NXTF+1;
2      CHANGE=T(NXTF)-TEMP;
2      IF HOUR EQL 6;                                                      10950
2         BEGIN
2         CHAN=CHANGE/27.0;
2         IF CHAN GTR 1.0; CHAN =1.0;
2         RADFAC=RADCON.CHAN.MAXRAD(DAY);
2         END;
2      END;
2   COMMENT TEMPX IN ZONE;
2   LAPS=LAPSE(HOUR);
2   IF PX GTR 0.05; LAPS=0.75.LAPS;
2   TEMPX=TEMP-LAPS.ELDIF;    TEMPXR=0.557(TEMPX-32.0)+273.0;
2   IF PX +PACK EQL 0.0; RETURN;
2   IF PX GTR 0.0;
2      BEGIN
2      COMMENT SNOW/RAIN CONTROL IS TEMP AT 750 FT;
2      IF (TEMPX - 0.750.LAPS) LEQ 32.0;
2      COMMENT SNOW;
2         BEGIN
2            PX=SCF.PX;
2            SPR=SPR+(SCF-1.0).PX;
2            EITHER IF TEMPX GTR 0.0;
2            DNS=IDNS+((TEMPX/100.0)*2.0);
2            OTHERWISE;  DNS=IDNS ;
2             PACK=PACK+PX ;
2            IF PACK GTR IPACK; IPACK=PACK;
2         IF IPACK GTR MPACK; IPACK=MPACK;
2               ALBEDO=ALBEDO+0.04.PX;
2               IF ALBEDO GTR 0.75; ALBEDO=0.75;
2             DEPTH=DEPTH+(PX/DNS);
2            SUMSNOW=SUMSNOW+PX;
2             PX=0.0 ;
2             END ;
2         END ;
2         COMMENT FOR TEMPX GTR 32 PX IS UNCHANGED;
2   IF PACK EQL 0.0; RETURN;
2   IF SDEN LSS 0.6; DEPTH=DEPTH(1.0-0.00002(DEPTH(0.6-SDEN)));
2   IF NEGMELT GTR 0.01.PACK; IF LIQW GTR 0.2.WC.PACK;
2      BEGIN
2      NEGMELT=NEGMELT-0.01.LIQW;
2      PACK=PACK+0.01.LIQW;
2      LIQW=0.99.LIQW;
2      END;
2   COMMENT SNOW EVAPORATION;
2   IF TEMPX LSS 32.0;
2      BEGIN
2      EITHER IF PACK GTR IPACK;
2      SEVAP=SE(DAY);
2      OTHERWISE;SEVAP=(PACK/IPAC).SE(DAY);
2      COMMENT ASSUME DAILY SEVAP OCCURS IN 12 HOUR PERIOD;
2      SEVAP=0.0832.SEVAP;
2      MSUREVAP=MSUREVAP+SEVAP;
2      SAET=SAET+SEVAP;
2      IF PACK GTR SEVAP;
2      PACK=PACK=SEVAP;
2      IF SDEN GTR 0.0;
2      DEPTH=DEPTH-(SEVAP/SDEN);
2      END;
2      COMMENT REDUCE REGULAR ET;
2      E1E=E2E=EPHRLI;
2      EITHER IF PACK GTR IPACK; E1E=0.0;
2      OTHERWISE;E1E=(1.0-(PACK/IPACK)).E1E;
2      IF TEMPX LSS 38.0; E2E=0.0;
2      EPHRLI=(1.0-F).E1E_F.E2E;
2      COMMENT FIND INCOMING SHORTWAVE;
2      EITHER IF DCS(10);
2      RA=RADCON.RAD(DAY).RADDIST(HOUR);
2      OTHERWISE; RA=RADFAC.RADDIST(HOUR);
2      COMMENT NET SHORTWAVE;
2      RA=(1.0-F).(1.0-ALBEDO).RA;
2      COMMENT CLEAR SKY LONG-WAVE RADIATION EXCHANGE
2      AND FOREST LONG-WAVE EXCHANGE;
2         LW=-27.5(1.0-F)(0.76.(TEMXR/273.0)*4.0-1.0)
2      -27.5(F)((TEMPXR/273.0)*4.0-1.0);
2      IF LW GTR 28.0;LW=28.0;
2      HM=RA-LW;
2   EITHER IF TEMPX LSS 32.0;
2         NEGMELTM=  ((32.0-TEMPX)/288.0).PACK;
2   OTHERWISE; NEGMELTM=0.0;
2   EITHER IF HM LSS 0.0;
2         BEGIN
2         CHNEGM=-(HM/203.2);
2         IF PACK LSS IPACK;CHNEGM=(PACK/IPACK).CHNEGM;
2      IF NEGMELT LSS NEGMELTM;
2         NEGMELT=NEGMELT+(1.0-(NEGMELT/NEGMELTM)).CHNEGM;
2         END;
2      OTHERWISE;
2      BEGIN
2      M=HM/203.2;
2      RADMT=RADME+M;
2      END;
2         M=M+CONMELT.(TEMPX-32.0);
2      SCOMELT=SCOMELT+CONMELT.(TEMPX-32.0);
2      IF TEMPX -0.75.LAPSE(HOUR) GTR 32.0;
2      IF PX GTR 0.0; IF TEMPX GTR 32.0;
2      M=M+((TEMPX-32.0).(PX/144.0));
2      IF PACK LSS IPACK;
2      M=(PACK/IPACK).M;
2      IF M LSS 0.0;
2          BEGIN
2         IF NEGMELT LSS NEGMELTM;
2         NEGMELT=NEGMELT-(1.0-(NEGMELT/NEGMELTM)).M;
2         M=0.0;
2         END;
2IF M+PX GTR 0.0;
2   BEGIN
2      EITHER IF M LSS LEGMELT;
2      BEGIN
2      NEGMELT=NEGMELT-M;
2      M=0.0;
2      END;
2      OTHERWISE;
2      BEGIN
2      M=M-NEGMELT;
2      NEGMELT=0.0;
2      END;
2      EITHER IF ALBEDO GTR 0.7; ALBEDO=ALBEDO-0.04.M;
2      OTHERWISE; ALBEDO=ALBEDO-0.02.M;
2      IF ALBEDO LSS 0.65; ALBEDO=0.65;
2      EITHER IF PX LSS NEGMELT;
2      BEGIN
2      NEGMELT=NEGMELT-PX;
2      PACK=PACK+PX;  PX=0.0;
2      END;
2      OTHERWISE;
2      BEGIN
2      PX=PX-NEGMELT;
2      PACK=PACK+NEGMELT;  NEGMELT=0.0;
2      END;
2      IF PX +M EQL 0.0; GO TO LUPO;
2      EITHER IF M GEQ PACK;
2         BEGIN
2      M=PACK+LIQW;
2         DEPTH=PACK=LIQM=0.0;
2         ALBEDO=0.75;
2         END;
2      OTHERWISE;
2         BEGIN
2         PACK=PACK-M;
2         IF SDEN GTR 0.0;
2            DEPTH=DEPTH-(M/SDEN);
2         IF PACK GEQ 0.9.DEPTH; DEPTH=11.1.PACK;
2      IF PACK LSS 0.001; PACK=0.0;
2      LIQS=WC.PACK;
2         IF SDEN GTR 0.6; LIQS=WC.(3.0-(3.33).SDEN).PACK;
2         IF LIQS LSS 0.0; LIQS=0.0;
2         END;
2EITHER IF (LIQS+M+PX) GTR LIQS;
2      BEGIN
2      PX=M+PX+LIQW-LIQS;
2      LIQW=LIQS  ;
2   GO TO LUPO;
2      END;
2OTHERWISE ;
2      BEGIN
2      LIQW=LIQW+M+PX;
2      PX=0.0 ;
2   GO TO LUPO;
2      END ;
2   END;
2   LUPO..
2      IF PACK GTR 0.0; IF DEPTH NEQ 0.0;
2   IF PACK GTR 0.0; IF PACK LSS DEPTH;
2      SDEN=PACK/DEPTH;
2   COMMENT GROUND MELT;
2   IF HOUR EQL 16;
2      BEGIN                                                               12600
2         DGMM=DGM;
2         IF NEGMELT GTR 0.01.PACK;
2         BEGIN
2         DGMM=DGM(1.0-(MEGMELT/0.08.PACK));
2         NEGMELT=NEGMELT-DGM+DGMM;
2         END;
2         EITHER IF PACK GTR DGMM;
2      BEGIN
2         PX=PX+DGMM;
2         PACK=PACK-DGMM;
2            DEPTH=DEPTH-(DGMM/SDEN);
2         IF PACK GEQ 0.9.DEPTH; DEPTH=1.11.PACK;
2      END;
2   OTHERWISE;
2      BEGIN
2      PX=PACK+PX+LIQW;
2      PACK=DEPTH=LIQW=NEGMELT=0.0;
2         END;
2   END;
2   IF MO NEQ DDMOTO;
2      BEGIN
2      WRITE (;;FORMSP);
2      FORMAT FORMSP (W);
2      DDMOTO=MO;
2      END;
2      IF HOUR EQL 24; IF PACK GTR 0.0;
2   WRITE(;;NOWA,SNOWF);
2      OUTPUT SNOWA(MO,DAYMO,PACK,DEPTH,SDEN,ALBEDO,NEGMELT,LIQW);
2   FORMAT SNOWF(B2,I4,B2,I4,B2,*PACK=*,X8.2,B2,
2                               *DEPTH=*,X8.2,B2,*DENS=*,X6.2,B2,
2   *ALBEDO=*,X6.2,B2,*NEGMELT=*,X6.2,B2,*LIQW=*,X6.2,W);
2 RETURN
2 END;
2LFIN..UNLOAD(10);
2FINISH;
