//WGEN     JOB (M461,54-D,S60,10,R1),'WEATHER GEN'
//*TAMU P=5
//STEP  EXEC WATFIV,REGION=256K
//SYSIN  DD  DATA
//$OPTIONS
      DIMENSION TXM(366),TXS(366),TXM1(366),TXS1(366),TNM(366),TNS(366),
     1RM0(366),RS0(366),RM1(366),RS1(366),RC(366),RAIN(366),TMAX(366),
     2TMIN(366),RAD(366),ACOM(20),NI(12),SR(12),SSTX(12),SSTN(12),
     3SRAIN(12),STMAX(12),STMIN(12),SRAD(12),NII(12),PWW(12),PWD(12),
     4ALPHA(12),BETA(12),TM(12),PW(12),TG(12),RM(12),RG(12),RCF(12),
     5NWET(12),XNW(12),SSRAD(12)
      DIMENSION TAMAX(12),TAMIN(12)
      DIMENSION TTMAX(12),TTMIN(12),TCFMAX(12),TCFMIN(12)
      DATA NI/31,59,90,120,151,181,212,243,273,304,334,365/
      DATA NII/31,60,91,121,152,182,213,244,274,305,335,366/
C*****************************************************************
C*  INPUT # 01 - TITLE                                           *
C*     ACOM(I) - LOCATION IDENTIFICATION OR OTHER USER           *
C*               COMMENTS.  80 CHARACTER MAXIMUM                 *
C*****************************************************************
      READ(5,98)(ACOM(I),I=1,20)
98    FORMAT(20A4)
      WRITE(6,99)(ACOM(I),I=1,20)
99    FORMAT('1',20A4)
C*****************************************************************
C*  INPUT # 02 - NUMBER OF YEARS, GENERATION CODES, AND LATITUDE *
C*        NYRS - YEARS OF DATA TO BE GENERATED                   *
C*        KGEN - GENERATION OPTION CODE                          *
C*               IF KGEN = 1,RAIN, MAX TEMP, MIN TEMP, AND       *
C*               SOLAR RADIATION WILL BE GENERATED               *
C*               IF KGEN = 2 OBSERVED RAIN WILL BE USED AND      *
C*               MAX TEMP, MIN TEMP, SOLAR RADIATION WILL        *
C*               BE GENERATED                                    *
C*        ALAT - STATION LATITUDE IN DEGREES                     *
C*        KTCF - TEMP. CORRECTION FACTOR OPTION CODE             *
C*               IF KTCF = 0  NO TEMP CORRECTION WILL BE MADE    *
C*               IF KTCF = 2 GENERATED MAX TEMP AND              *
C*               MIN TEMP WILL BE CORRECTED BASED ON             *
C*               OBSERVED MEAN MONTHLY MAX AND MIN TEMP          *
C*               IF KTCF = 1 GENERATED MAX TEMP AND MIN TEMP     *
C*               WILL BE CORRECTED BASED ON OBSERVED MEAN        *
C*               MONTHLY TEMP                                    *
C*        KRCF - RAIN CORRECTION FACTOR OPTION CODE              *
C*               IF KRCF = 1 GENERATED RAIN WILL BE CORRECTED    *
C*               BASED ON OBSERVED MEAN MONTHLY RAIN             *
C*               IF KRCF = 0 NO RAIN CORRECTION WILL BE MADE     *
C*****************************************************************
      READ(5,100) NYRS,KGEN,ALAT,KTCF,KRCF
100   FORMAT(2I5,F5.0,2I5)
C***** CALCULATE MAXIMUM SOLAR RADIATION FOR EACH DAY
      XLAT = ALAT*6.2832/360.
      DO 6 I = 1,366
      XI = I
      SD = 0.4102*SIN(0.0172*(XI-80.25))
      CH = -TAN(XLAT)*TAN(SD)
      IF(CH .GT. 1.0) H = 0.
      IF(CH .GT. 1.0) GO TO 5
      IF(CH .LT. -1.0)H=3.1416
      IF(CH .LT. -1.0) GO TO 5
      H = ARCOS(CH)
5     DD = 1.0+0.0335*SIN(0.0172*(XI+88.2))
      RC(I)=889.2305*DD*((H*SIN(XLAT)*SIN(SD))+(COS(XLAT)*COS(SD)*SIN(H)
     1))
      RC(I) = RC(I) * 0.8
6     CONTINUE
      DO 7 I = 1,12
      TTMAX(I)=0.
      TTMIN(I)=0.
      RM(I) = 0.
7     CONTINUE
      IF(KGEN .EQ. 2) GO TO 10
C****************************************************************
C*  NOTE--INPUTS #03,04,05,06  ARE RAINFALL PARAMETERS          *
C*        OMIT IF KGEN=2                                        *
C****************************************************************
C*  INPUT # 03 - PROBABILITY OF WET GIVEN WET                   *
C*     PWW(I) - 12 MONTHLY VALUES OF P(W/W)                     *
C****************************************************************
      READ(5,103) (PWW(I),I=1,12)
103   FORMAT(12F6.0)
C****************************************************************
C*  INPUT # 04 - PROBABILITY OF WET GIVEN DRY                   *
C*     PWD(I) - 12 MONTHLY VALUES OF P(W/D)                     *
C****************************************************************
      READ(5,103)(PWD(I),I=1,12)
C****************************************************************
C*  INPUT # 05 - GAMMA DISTRIBUTION SHAPE PARAMETER             *
C*     ALPHA(I) - 12 MONTHLY VALUES OF SHAPE PARAMETER          *
C****************************************************************
      READ(5,103)(ALPHA(I),I=1,12)
C****************************************************************
C*  INPUT # 06 - GAMMA DISTRIBUTION SCALE PARAMETER             *
C*     BETA(I) - 12 MONTH VALUES OF SCALE PARAMETER             *
C****************************************************************
      READ(5,103)(BETA(I),I=1,12)
101   FORMAT(9F8.0)
C****************************************************************
C*  INPUT # 07 - FOURIER COEFFICIENTS OF MAX TEMP ON DRY DAYS   *
C*     TXMD - MEAN OF TMAX - DRY                                *
C*     ATX  - AMPLITUDE OF TMAX - WET OR DRY                    *
C*     CVTX - MEAN OF COEF. OF VAR. OF TMAX - WET OR DRY        *
C*     ACVTX - AMPLITUDE OF COEF.OF VAR. OF TMAX - WET OR DRY   *
C****************************************************************
10    READ(5,101) TXMD,ATX,CVTX,ACVTX
C****************************************************************
C*  INPUT # 08 - FOURIER COEFFICIENTS OF MAX TEMP ON WET DAYS   *
C*     TXMW - MEAN OF TMAX - WET                                *
C****************************************************************
      READ(5,101) TXMW
C****************************************************************
C*  INPUT # 09 - FOURIER COEFFICIENTS OF MIN TEMP               *
C*     TN - MEAN OF TMIN - WET OR DRY                           *
C*     ATN - AMPLITUDE OF TMIN - WET OR DRY                     *
C*     CVTN - MEAN OF COEF. OF VAR. OF TMIN - WET OR DRY        *
C*     ACVTN - AMPLITUDE OF COEF. OF VAR. OF TMIN - WET OR DRY  *
C****************************************************************
      READ(5,101) TN,ATN,CVTN,ACVTN
C****************************************************************
C*  INPUT # 10 - FOURIER COEFFICIENTS OF RAD ON DRY DAYS        *
C*     RMD - MEAN OF RAD - DRY                                  *
C*     AR  - AMPLITUDE OF RAD - WET OR DRY                      *
C****************************************************************
      READ(5,101) RMD,AR
      CVRD = 0.24
      ACVRD = -0.08
C****************************************************************
C*  INPUT # 11 - FOURIER COEFFICIENTS OF RAD ON WET DAYS        *
C*     RMW - MEAN OF RAD - WET                                  *
C****************************************************************
      READ(5,101) RMW
      CVRW = 0.48
      ACVRW = -0.13
      D1 = TXMD - TXMW
      D2 = RMD - RMW
      IF(KTCF .EQ. 0) GO TO 12
       IF(KTCF .EQ. 2) GO TO 8
C****************************************************************
C*  INPUT # 12 - MONTHLY VALUES OF ACTUAL MEAN TEMP             *
C*               OMIT IF KTCF = 0 OR 2                          *
C*     TM(I) - 12 MONTHLY VALUES OF ACTUAL MEAN TEMP            *
C****************************************************************
       READ(5,103)(TM(I),I=1,12)
       GO TO  12
C****************************************************************
C*  INPUT # 13 - MONTHLY VALUES OF ACTUAL MEAN MAX TEMP         *
C*               OMIT IF KTCF = 0 OR 1                          *
C*     TTMAX(I) - 12 MONTHLY VALUES OF ACTUAL MEAN MAX TEMP     *
C****************************************************************
8     READ(5,103) (TTMAX(I),I=1,12)
C****************************************************************
C*  INPUT # 14 - MONTHLY VALUES OF ACTUAL MEAN MIN TEMP         *
C*               OMIT IF KTCF = 0 OR 1                          *
C*     TTMIN(I) - 12 MONTHLY VALUES OF ACTUAL MEAN MIN TEMP     *
C****************************************************************
      READ(5,103) (TTMIN(I),I=1,12)
12    IF(KRCF .EQ. 0) GO TO 13
C****************************************************************
C*  INPUT # 15 - MONTHLY VALUES OF ACTUAL MEAN RAINFALL         *
C*               OMIT IF KRCF = 0                               *
C*     RM(I) = 12 MONTHLY VALUES OF ACTUAL MEAN RAINFALL        *
C****************************************************************
      READ(5,103)(RM(I),I=1,12)
13    WRITE(6,700)
700   FORMAT(////,10X,'GENERATION PARAMETERS',//,15X,'PRECIPITATION')
      WRITE(6,701)(PWW(I),I=1,12)
701   FORMAT(20X,'P(W/W)  ',12F7.3)
      WRITE(6,702) (PWD(I),I=1,12)
702   FORMAT(20X,'P(W/D)  ',12F7.3)
      WRITE(6,703) (ALPHA(I),I=1,12)
703   FORMAT(20X,'ALPHA   ',12F7.3)
      WRITE(6,704) (BETA(I),I=1,12)
704   FORMAT(20X,'BETA    ',12F7.3)
      WRITE(6,705)TXMD,ATX,CVTX,ACVTX,TXMW
705   FORMAT(15X,'MAXIMUM TEMPERATURE',/,20X,'TXMD = ',F8.3,/,20X,
     * 'ATX = ',F8.3,/,20X,'CVTX = ',F8.3,/,20X,'ACVTX = ',F8.3,/,20X,
     * 'TXMW = ',F8.3,//)
      WRITE(6,706)TN,ATN,CVTN,ACVTN
706   FORMAT(15X,'MINIMUM TEMPERATURE',/,20X,'TN = ',F8.3,/,20X,
     *'ATW = ',F8.3,/,20X,'CVTN = ',F8.3,/,20X,'ACVTN = ',F8.3,//)
      WRITE(6,707)RMD,AR,RMW
707   FORMAT(15X,'SOLAR RADIATION',/,20X,'RMD = ',F8.3,/,20X,
     * 'AR = ',F8.3,/,20X,'RMW = ',F8.3,///)
      DO 11 J = 1,366
      XJ = J
      DT = COS(.0172*(XJ-200.))
      DR = COS(.0172*(XJ-172.))
      TXM(J) = TXMD+ATX*DT
      XCR1=CVTX+ACVTX*DT
      IF(XCR1 .LT. 0.0) XCR1=0.06
      TXS(J)=TXM(J)*XCR1
      TXM1(J) = TXM(J) - D1
      TXS1(J)=TXM1(J)*XCR1
      TNM(J) = TN + ATN*DT
      XCR2=CVTN+ACVTN*DT
      IF(XCR2 .LT. 0.0) XCR2=0.06
      TNS(J)=TNM(J)*XCR2
      RM0(J) = RMD+AR * DR
      XCR3=CVRD+ACVRD*DR
      IF(XCR3 .LT. 0.0) XCR3=0.06
      RS0(J)=RM0(J)*XCR3
      RM1(J) = RM0(J) - D2
      XCR4=CVRW+ACVRW*DR
      IF(XCR4 .LT. 0.0) XCR4=0.06
      RS1(J)=RM1(J)*XCR4
11    CONTINUE
      DO 22 IM=1,12
      XNW(IM) = 0.
      SR(IM) = 0.
      SSTX(IM) = 0.
      SSTN(IM) = 0.
      SSRAD(IM) = 0.
      TCFMAX(IM) = 0.0
      TCFMIN(IM) = 0.0
      RCF(IM) = 1.0
      PW(IM) = PWD(IM)/(1.-PWW(IM)+PWD(IM))
      S1 = 0.
      S2 = 0.
      S3 = 0.
      NL = NI(IM)
      IF(IM .EQ. 1) GO TO 14
      NF = NI(IM-1) + 1
      GO TO 15
14    NF = 1
15    CONTINUE
      ZN = NL - NF + 1
      DO 16 J = NF,NL
      S1 = S1 + TXM(J)/ZN
      S2 = S2 + TXM1(J)/ZN
      S3 = S3 + TNM(J)/ZN
16    CONTINUE
C*****CALCULATE MONTHLY RAINFALL CORRECTION FACTOR
      RG(IM) = ALPHA(IM)*BETA(IM)*ZN*PW(IM)
      IF(KRCF .EQ. 0 ) GO TO 17
      RCF(IM) = RM(IM)/RG(IM)
17    IF(KTCF .EQ. 0) GO TO  22
C*****CALCULATE MONTHLY TEMP CORRECTION FACTOR
      IF(KTCF.EQ.2)  GO TO 18
      TMD = (S1 + S3) / 2.
      TMW = (S2 + S3) / 2.
      TG(IM) = TMW*PW(IM)+TMD*(1-PW(IM))
      TCFMAX(IM) = TM(IM) -  TG(IM)
      TCFMIN(IM) = TCFMAX(IM)
      GO TO 22
18    TAMAX(IM)=S2*PW(IM) + S1*(1.-PW(IM))
      TAMIN(IM)=S3
      IF(KTCF .EQ. 0.) GO TO 22
      TCFMAX(IM)=TTMAX(IM)-TAMAX(IM)
      TCFMIN(IM)=TTMIN(IM)-TAMIN(IM)
22    CONTINUE
      IF(KRCF .EQ. 0) GO TO 52
      WRITE(6,712)(RM(I),I=1,12)
712   FORMAT(10X,'ACT MEAN RAIN',12F7.2)
      WRITE(6,713) (RG(I),I=1,12)
713   FORMAT(10X,'EST MEAN RAIN',12F7.2)
      WRITE(6,714)(RCF(I),I=1,12)
714   FORMAT(10X,'RAIN CF      ',12F7.3)
52    IF (KTCF .EQ. 0) GO TO 19
      IF(KTCF .EQ. 2) GO TO 51
      WRITE(6,708) (TM(I),I=1,12)
708   FORMAT(10X,'ACT MEAN TEMP',12F7.1)
      WRITE(6,711)(TG(I),I=1,12)
711   FORMAT(10X,'EST MEAN TEMP',12F7.1)
      GO TO 50
51    WRITE(6,722) (TTMAX(I),I=1,12)
722   FORMAT(10X,'ACT MEAN TMAX',12F7.1)
      WRITE(6,723) (TTMIN(I),I=1,12)
723   FORMAT(10X,'ACT MEAN TMIN',12F7.1)
      WRITE(6,720) (TAMAX(I),I=1,12)
720   FORMAT(10X,'EST MEAN TMAX',12F7.1)
      WRITE(6,721) (TAMIN(I),I=1,12)
721   FORMAT(10X,'EST MEAN TMIN',12F7.1)
50    WRITE(6,709) (TCFMAX(I),I=1,12)
709   FORMAT(10X,'CF. MEAN TMAX',12F7.1)
      WRITE(6,724) (TCFMIN(I),I=1,12)
724   FORMAT(10X,'CF. MEAN TMIN',12F7.1)
19    XYR = NYRS
      SYTX = 0.
      SYTN = 0.
      SYRAD = 0.
      SYR = 0.
      SYNW = 0.
      DO 40 I = 1,NYRS
      IYR = I
      IF(KGEN .EQ. 1) GO TO 20
      KK = 0
      IJ = 1
C****************************************************************
C*  INPUT # 16 - MEASURED RAINFALL FOR NYRS                     *
C*               OMIT IF KGEN = 1                               *
C*     RAIN(I) - ACTUAL RAINFALL DATA - ONE VALUE PER DAY       *
C*               FOR NYRS                                       *
C****************************************************************
21    READ(5,102) IYR,MO,IDAY,RAIN(IJ)
102   FORMAT(4X,3I2,20X,F10.0)
      IF(KK .EQ. 1) GO TO 24
20    IDAYS = 365
      IFLG= MOD(IYR,4)
      IF(IFLG .EQ. 0) IDAYS = 366
      KK = 1
      IF(KGEN .EQ. 1) GO TO 28
24    IJ = IJ + 1
      IF(IJ .LE. IDAYS) GO TO 21
28    CONTINUE
      CALL WGEN(PWW,PWD,ALPHA,BETA,TXM,TXS,TXM1,TXS1,TNM,TNS,RM0,RS0,
     *RM1,RS1,RAIN,TMAX,TMIN,RAD,KGEN,RC,IDAYS,NI,NII,
     *TCFMAX,TCFMIN,RCF)
      DO 23 IM = 1,12
      SRAIN(IM) = 0.
      STMAX(IM) = 0.
      STMIN(IM) = 0.
      SRAD(IM) = 0.
      NWET(IM) = 0
23    CONTINUE
      IM = 1
      YTMAX = 0.
      YTMIN = 0.
      YRAD = 0.
      RYR = 0.
      NYWET = 0
      IDA = 0
      DO 30 J=1,IDAYS
      IDA = IDA + 1
      IF(IDAYS .EQ. 366) GO TO 27
      IF(J .GT. NI(IM)) GO TO 251
      GO TO 29
251   IM = IM + 1
      IDA = 1
      GO TO 29
27    IF(J .GT. NII(IM)) GO TO 251
29    CONTINUE
C*****THE FOLLOWING STATEMENT WRITES DAILY GENERATED WEATHER ON AN
C*****EXTERNAL FILE (UNIT 8).
C     WRITE(8,200)IM,IDA,IYR,J,RAIN(J),TMAX(J),TMIN(J),RAD(J)
800   CONTINUE
C*****THE FOLLOWING STATEMENT PRINTS DAILY GENERATED WEATHER
      WRITE(6,200)IM,IDA,IYR,J,RAIN(J),TMAX(J),TMIN(J),RAD(J)
200   FORMAT(2X,4I5,F7.2,3F7.0)
25    CONTINUE
      IF(RAIN(J) .LT. 0.005) GO TO 26
      NWET(IM) = NWET(IM) + 1
      NYWET = NYWET + 1
26    CONTINUE
      SRAIN(IM) = SRAIN(IM) + RAIN(J)
      STMAX(IM) = STMAX(IM) + TMAX(J)
      STMIN(IM) = STMIN(IM) + TMIN(J)
      SRAD(IM) = SRAD(IM) + RAD(J)
      RYR = RYR + RAIN(J)
30    CONTINUE
      XNM1 = 0.
      DO 35 IM = 1,12
      XXN = NI(IM)
      XNI = XXN - XNM1
      XNM1 = XXN
      ANW = NWET(IM)
      XNW(IM) = XNW(IM) + ANW/XYR
      SR(IM) = SR(IM) + SRAIN(IM) / XYR
      STMAX(IM) = STMAX(IM)/ XNI
      SSTX(IM) = SSTX(IM) + STMAX(IM) / XYR
      STMIN(IM) = STMIN(IM) / XNI
      SSTN(IM) = SSTN(IM) + STMIN(IM) / XYR
      SRAD(IM) = SRAD(IM) / XNI
      SSRAD(IM) = SSRAD(IM) + SRAD(IM) / XYR
      YTMAX = YTMAX + STMAX(IM) / 12.
      YTMIN = YTMIN + STMIN(IM) / 12.
      YRAD = YRAD + SRAD(IM) / 12.
35    CONTINUE
      SYTX = SYTX + YTMAX/XYR
      SYTN = SYTN + YTMIN/XYR
      SYRAD = SYRAD + YRAD / XYR
      SYR = SYR + RYR / XYR
      XYNW = NYWET
      SYNW = SYNW + XYNW / XYR
      WRITE(6,201) IYR
201   FORMAT(//,5X,'SUMMARY FOR YEAR',I5,/,2X,'MONTH             1
     * 2       3       4       5       6       7       8       9      10
     *      11      12      YR',/)
      WRITE(6,207)(NWET(IM),IM=1,12),NYWET
207   FORMAT(2X,'WET DAYS    ',13I8)
       WRITE(6,202)(SRAIN(IM),IM=1,12),RYR
202   FORMAT(2X,'RAINFALL    ',13F8.2)
      WRITE(6,203)(STMAX(IM),IM=1,12),YTMAX
203   FORMAT(2X,'AVE MAX TEMP',13F8.2)
      WRITE(6,204)(STMIN(IM),IM=1,12),YTMIN
204   FORMAT(2X,'AVE MIN TEMP',13F8.2)
      WRITE(6,205)(SRAD(IM),IM=1,12),YRAD
205   FORMAT(2X,'AVE RAD     ',13F8.2)
40    CONTINUE
      WRITE(6,206)NYRS
206   FORMAT(///,5X,'SUMMARY FOR',I5,'YEARS')
      WRITE(6,208)(XNW(IM),IM=1,12),SYNW
208   FORMAT(2X,'WET DAYS    ',13F8.2)
      WRITE(6,202)(SR(IM),IM=1,12),SYR
      WRITE(6,203)(SSTX(IM),IM=1,12),SYTX
      WRITE(6,204)(SSTN(IM),IM=1,12),SYTN
      WRITE(6,205)(SSRAD(IM),IM=1,12),SYRAD
999   STOP
      END
C*****THE FOLLOWING SUBROUTINE GENERATED DAILY WEATHER DATA FOR
C*****ONE YEAR.
      SUBROUTINE WGEN(PWW,PWD,ALPHA,BETA,TXM,TXS,TXM1,TXS1,TNM,TNS,RM0,
     1RS0,RM1,RS1,RAIN,TMAX,TMIN,RAD,KGEN,RC,IDAYS,NI,NII,
     2TCFMAX,TCFMIN,RCF)
      DIMENSION TXM(366),TXS(366),TXM1(366),
     1 TXS1(366),TNM(366),TNS(366),RM0(366),RS0(366),RM1(366),RS1(366),
     2 RAIN(366),TMAX(366),TMIN(366),RAD(366),RC(366),A(3,3),B(3,3),
     3XIM1(3),E(3),R(3),X(3),RR(3),PWW(12),PWD(12),ALPHA(12),BETA(12),
     4NI(12),NII(12),TCF(12),RCF(12)
      DIMENSION TCFMAX(12),TCFMIN(12)
      DATA A/0.567,0.253,-0.006,0.086,0.504,-0.039,-0.002,-0.050,0.244/
      DATA B/0.781,0.328,0.238,0.0,0.637,-0.341,0.0,0.0,0.873/
      DATA XIM1/0.,0.,0./
      DATA IX/9398039/
      DATA IP/0/
      IM = 1
      DO 50 IDAY=1,IDAYS
      IF(IDAYS .EQ. 366) GO TO 2
      IF(IDAY .GT. NI(IM)) IM = IM + 1
      GO TO 4
2     IF(IDAY .GT. NII(IM)) IM = IM + 1
4     CONTINUE
      IF(KGEN .EQ. 2) GO TO 15
C*****DETERMINE WET OR DRY DAY USING MARKOV CHAIN MODEL
      CALL RANDN(RN)
      IF(IP-0) 7,7,10
7     IF(RN - PWD(IM  ))11,11,8
8     IP = 0
      RAIN(IDAY) = 0.
      GO TO 18
10    IF(RN-PWW(IM  ))11,11,8
11    IP = 1
C*****DETERMINE RAINFALL AMOUNT FOR WET DAYS USING GAMMA DISTRIBUTION
      AA = 1./ALPHA(IM)
      AB = 1./(1.-ALPHA(IM))
      TR1 = EXP(-18.42/AA)
      TR2 = EXP(-18.42/AB)
      SUM = 0.
      SUM2 = 0.
12    CALL RANDN(RN1)
      CALL RANDN(RN2)
      IF(RN1-TR1) 61,61,62
61    S1 = 0.
      GO TO 63
62    S1 = RN1**AA
63    IF(RN2-TR2) 64,64,65
64    S2 = 0.
      GO TO 66
65    S2 = RN2**AB
66    S12 = S1 + S2
      IF(S12-1.) 13,13,12
13    Z = S1/S12
      CALL RANDN(RN3)
      RAIN(IDAY) = -Z*ALOG(RN3)*BETA(IM)*RCF(IM)
C*****RAIN(IDAY) IS GENERATED RAINFALL FOR IDAY
15    IF(RAIN(IDAY)) 16,16,17
16    IP = 0
      GO TO 18
17    IP = 1
18    IF(IP-1) 25,26,26
C*****GENERATE TMAX, TMIN, AND RAD FOR IDAY
25    RM=RM0(IDAY)
      RS = RS0(IDAY)
      TXXM = TXM(IDAY)
      TXXS = TXS(IDAY)
      GO TO 27
26    RM = RM1(IDAY)
      RS = RS1(IDAY)
      TXXM = TXM1(IDAY)
      TXXS = TXS1(IDAY)
27    CONTINUE
      DO 30 K = 1,3
131   AA = 0.
      CALL RANDN(RN1)
      CALL RANDN(RN2)
      V = SQRT(-2.*ALOG(RN1))*COS(6.283185*RN2)
      IF(ABS(V) .GT. 2.5) GO TO 131
      E(K) = V
30    CONTINUE
      DO 31 I = 1,3
      R(I) = 0.
      RR(I) = 0.
31    CONTINUE
      DO 32 I = 1,3
      DO 32 J = 1,3
      R(I) = R(I)+B(I,J)*E(J)
      RR(I) = RR(I) + A(I,J)*XIM1(J)
32    CONTINUE
      DO 37 K = 1,3
      X(K) = R(K) + RR(K)
      XIM1(K) = X(K)
37    CONTINUE
      TMAX(IDAY) = X(1) * TXXS + TXXM
      TMIN(IDAY) = X(2)*TNS(IDAY)+TNM(IDAY)
      IF(TMIN(IDAY) .GT. TMAX(IDAY)) GO TO 38
      GO TO 39
38    TMM = TMAX(IDAY)
      TMAX(IDAY) = TMIN(IDAY)
      TMIN(IDAY) = TMM
39    CONTINUE
      TMAX(IDAY)=TMAX(IDAY)+TCFMAX(IM)
      TMIN(IDAY)=TMIN(IDAY)+TCFMIN(IM)
C*****TMAX(IDAY) IS GENERATED TMAX FOR IDAY
C*****TMIN(IDAY) IS GENERATED TMIN FOR IDAY
      RAD(IDAY) = X(3)*RS+RM
      RMIN = 0.2*RC(IDAY)
      IF(RAD(IDAY) .LT. RMIN) RAD(IDAY) = RMIN
      IF(RAD(IDAY) .GT. RC(IDAY)) RAD(IDAY) = RC(IDAY)
C*****RAD(IDAY) IS GENERATED RAD FOR IDAY
 50   CONTINUE
      RETURN
      END
C*****THE FOLLOWING SUBROUTINE GENERATES A UNIFORM RANDOM NUMBER ON
C*****THE INTERVAL 0 - 1
      SUBROUTINE RANDN(YFL)
      DIMENSION K(4)
      DATA K/2510,7692,2456,3765/
      K(4) = 3*K(4)+K(2)
      K(3) = 3*K(3)+K(1)
      K(2)=3*K(2)
      K(1) = 3*K(1)
      I=K(1)/1000
      K(1)=K(1)-I*1000
      K(2)=K(2) + I
      I = K(2)/100
      K(2)=K(2)-100*I
      K(3) = K(3)+I
      I = K(3)/1000
      K(3)=K(3)-I*1000
      K(4)=K(4)+I
      I = K(4)/100
      K(4)=K(4)-100*I
      YFL=(((FLOAT(K(1))*.001+FLOAT(K(2)))*.01+FLOAT(K(3)))*.001+FLOAT
     *(K(4)))*.01
      RETURN
      END
//$DATA
 GENERATED RAINFALL, TMAX,TMIN, AND RADIATION - TEMPLE, TEXAS
   03    1 31.1    2    1
 0.507 0.451 0.399 0.477 0.448 0.407 0.333 0.365 0.448 0.421 0.547 0.482
 0.149 0.213 0.176 0.178 0.193 0.133 0.079 0.118 0.161 0.125 0.127 0.151
 0.659 0.735 0.713 0.680 0.630 0.704 0.705 0.584 0.686 0.488 0.633 0.590
 0.428 0.454 0.360 0.663 0.816 0.677 0.593 0.831 0.695 1.308 0.616 0.563
   78.41   18.25    0.10   -0.065
   72.86
   55.13   18.78    0.16   -0.12
  468.00  176.59
  293.90
   55.   58.   65.   74.   81.   86.   91.   92.   87.   81.   71.   49.
   36.   39.   45.   50.   60.   67.   72.   73.   66.   59.   48.   29.
   2.3   2.4   2.1   3.9   4.5   2.9   1.8   2.2   3.3   3.0   2.8   2.6
