c  paveperf.f90 
c
c*********************************************************************
c
c  PROGRAM:  Semester Project for CPS 615
c
c  PURPOSE:  Program Predicts Pavement Deterioration.
c
c*********************************************************************

       PROGRAM paveperf

       include "mpif.h"

       implicit none

c Array sizes allow up to 64 sections within the route.

c Variables to be used as loop indices

       Integer I, J, K

c Variables to be read from "rtetraff.dat"

       Character * 50 RTENAME

       Real RTELEN

       Integer NUMSEC, DURANAL, AGESURF
c 30
       Character * 1 BINDBRIT, CONSTRQ, DESIGNQ

       Integer DAHVT, NAHVT, PDTL, PDTM, PDTH, PNTL, PNTM, PNTH

c Variables to be read from "tempprec.dat"

       Character * 9 MONAME(12)

       Integer MINDAVG(12), MAXDAVG(12), MINNAVG(12), MAXNAVG(12)

       Integer MINDDEV(12), MAXDDEV(12), MINNDEV(12), MAXNDEV(12)

       Integer MAXDP(12)

c Variables to be read from "sectdist.dat"

       Real SECLEN(64)

       Integer PSTSPEED(64), ISMOMIN(64), ISMOMAX(64)

       Character * 1 DRAINQ(64)
	
       Real TRANDENO(64), GATAREAO(64), POTAREAO(64), DEPAREAO(64)

c Variables created within the program for program control.

       Integer DAY, DAYMO, DAYFINAL, MONTH, MONTHYR, YEAR

c Variables created within the program related to temperature and
c precipitation.
c 61
       Character * 1 COLD
	
       Real MINTEMPD, AVGTEMPD, MAXTEMPD, MINTEMPN, AVGTEMPN, MAXTEMPN,
     $ DEVTEMPD, DEVTEMPN, PD, P5D(6), PCUM

c Variables created within the program related to traffic.

       Real DTL, DTM, DTH

c Variables created within the program related to pavement structure.
	
       Integer SECNUM(64)

       Real ISMO(64), ISMAD(64), ISMAN(64), VCI(64), VC(64),  
     $ TCD, TCN, INCWORK, WORK(64), WORKCUM(64), FINAL(64)

c Variables created within the program related to 
c pavement surface condition.

       Character * 1 ACCRACK, LEVDEPR(64), LEVPREC, 
     $               MOISTURE(64), LEVTRAN(64), LEVGAT(64), LEVCRACK(64)

       Real TRANDEN(64), ZTDO(64), ZTD, ZTDCUM(64), DEPSLOPE, 
     $      DEPAREA(64), GATSLOPE(64), GATAREA(64),
     $      POTSLOPE(64), POTAREA(64)

c Variables created within the program related to randomization.

       Real TIMESEC, RANDNO, RAN, SECNDS
c 90
       Integer INTSEC, INT

c Variables needed for MPI

       INTEGER rank, p, tag, ierr, portion, dest, source, root

       INTEGER status(MPI_STATUS_SIZE)

       DOUBLE PRECISION start, finish, duration

       CALL MPI_INIT(ierr)

       CALL MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)

       CALL MPI_COMM_SIZE(MPI_COMM_WORLD, p, ierr)

       start = MPI_WTIME()

c Open data files.

       OPEN (Unit=11, FILE='rtetraff.dat', STATUS='old')

       OPEN (Unit=21, FILE='tempprec.dat', STATUS='old')

       OPEN (Unit=31, FILE='sectdist.dat', STATUS='old')

       READ (Unit=11, FMT=*) RTENAME

       READ (Unit=11, FMT=*) RTELEN, NUMSEC, DURANAL, AGESURF,
     $ BINDBRIT, CONSTRQ, DESIGNQ
	   
       READ (Unit=11, FMT=*) DAHVT, NAHVT, PDTL, PDTM, PDTH,  
     $ PNTL, PNTM, PNTH
c 120
       DO i=1,12

            READ (Unit=21, FMT=*) MONAME(i), MINDAVG(i), MAXDAVG(i),
     $      MINNAVG(i), MAXNAVG(i), MINDDEV(i), MAXDDEV(i),
     $      MINNDEV(i), MAXNDEV(i), MAXDP(i) 

       END DO

       DO i=1,NUMSEC

            READ (Unit=31, FMT=*) SECLEN(i), PSTSPEED(i), 
     $      ISMOMIN(i), ISMOMAX(i), DRAINQ(i),
     $      TRANDENO(i), GATAREAO(i), POTAREAO(i), DEPAREAO(i)
       END DO

c Root prints information about the problem, as it was provided in
c the datafiles.

       IF (rank .EQ. 0) THEN

       PRINT *, "Route = ", RTENAME
       PRINT *, ' '
       PRINT 10, RTELEN
10      FORMAT ("Route Length = ", F4.1, " Miles")
       PRINT *, ' '
       PRINT *, "Number of Pavement Sections = ", NUMSEC
       PRINT *, ' '
       PRINT *, "Duration of Analysis = ", DURANAL, " Months"
       PRINT *, ' '
       PRINT *, "Age of Asphalt Concrete Surface = ", AGESURF,
     $ " Months"
c 147
       PRINT *, ' '
       PRINT *, "Original Binder Brittleness = ", BINDBRIT
       PRINT *, ' '
       PRINT *, "Quality of Construction = ", CONSTRQ
       PRINT *, ' '
       PRINT *, "Level of Conservatism in Design = ", DESIGNQ
       PRINT *, ' '
       PRINT *, "Daytime Average Hourly Volume of Traffic = ",
     $ DAHVT, " vehicles"
       PRINT *, ' '
       PRINT *, "Nighttime Average Hourly Volume of Traffic = ", 
     $ NAHVT, " vehicles"
       PRINT *, ' '
       PRINT *, "Hard-Coded Half-Axle-Load Distributions"
       PRINT *, "---------------------------------------"
       PRINT *, ' '
       PRINT *, "Light Vehicles:  0 to 2 kips, Skewed Right"
       PRINT *, "Medium Vehicles:  2 to 8 kips, Uniform Distribution"
       PRINT *, "Heavy Vehicles:  8 to 12 kips, Skewed Left"
       PRINT *, ' '
       PRINT *, "Vehicle Percentages Selected from the Distributions"
       PRINT *, "---------------------------------------------------"
       PRINT *, ' '
       PRINT *, "Daytime Percentage for Light Vehicles = ", PDTL
       PRINT *, "Daytime Percentage for Medium Vehicles = ", PDTM
       PRINT *, "Daytime Percentage for Heavy Vehicles = ", PDTH
       PRINT *, ' '
       PRINT *, "Nighttime Percentage for Light Vehicles = ", PNTL
       PRINT *, "Nighttime Percentage for Medium Vehicles = ", PNTM
       PRINT *, "Nighttime Percentage for Heavy Vehicles = ", PNTH
       PRINT *, ' '
       PRINT *, "Historical Temperature and Precipitation Data"
c 180
       PRINT *, "---------------------------------------------"
       PRINT *, ' '
       PRINT *, "Col.No.  Description of Data"
       PRINT *, " (1)     Minimum Average Daytime Temperature (F)"
       PRINT *, " (2)     Maximum Average Daytime Temperature (F)"
       PRINT *, " (3)     Minimum Average Nighttime Temperature (F)"
       PRINT *, " (4)     Maximum Average Nighttime Temperature (F)"
       PRINT *, " (5)     Minimum Daytime Deviation from Average (F)"
       PRINT *, " (6)     Maximum Daytime Deviation from Average (F)"
       PRINT *, " (7)     Minimum Nighttime Deviation from Average (F)"
       PRINT *, " (8)     Maximum Nighttime Deviation from Average (F)"
       PRINT *, " (9)     Maximum One-Day Precipitation (in.)"
       PRINT *, ' '
       PRINT 20 
20     FORMAT (13X, "(1)", 3X, "(2)", 3X, "(3)", 3X, "(4)",
     $ 3X, "(5)", 3X, "(6)", 3X, "(7)", 3X, "(8)", 3X, "(9)")

       PRINT 30
30     FORMAT (13X, "---", 3X, "---", 3X, "---", 3X, "---",
     $ 3X, "---", 3X, "---", 3X, "---", 3X, "---", 3X, "---")
       DO i = 1, 12
            PRINT 40, MONAME(i), MINDAVG(i), MAXDAVG(i), MINNAVG(i),
     $      MAXNAVG(i), MINDDEV(i), MAXDDEV(i),
     $      MINNDEV(i), MAXNDEV(i), MAXDP(i) 
40          FORMAT (A9, 2X, I4, 2X, I4, 2X, I4, 2X, I4, 2X, I4, 2X,
     $      I4, 2X, I4, 2X, I4, 2X, I4)
       END DO
       PRINT *, ' '
       PRINT *, "Information About Pavement Sections Before Analysis"
c 210
       PRINT *, "---------------------------------------------------"
       PRINT *, ' '
       PRINT *, "Col.No.  Description of Data"
       PRINT *, " (1)     Section Number"
       PRINT *, " (2)     Length (miles)"
       PRINT *, " (3)     Posted Speed Limit (mph)"
       PRINT *, " (4)     Minimum ISMO (kip/in.)"
       PRINT *, " (5)     Maximum ISMO (kip/in.)"
       PRINT *, " (6)     Quality of Drainage (L,M,H)"
       PRINT *, " (7)     Density of Transverse Cracks (No./1000 ft)"
       PRINT *, " (8)     Percent Area Affected by Alligator Cracking"
       PRINT *, " (9)     Percent Area Affected by Potholes"
       PRINT *, " (10)    Percent Area Affected by Depressions"
       PRINT *, ' '
       PRINT 50 
50     FORMAT ("(1)", 3X, "(2)", 3X, "(3)", 4X, "(4)",
     $ 4X, "(5)", 3X, "(6)", 3X, "(7)", 3X, "(8)", 3X, "(9)", 
     $ 2X, "(10)")
       PRINT 60
60     FORMAT ("---", 3X, "---", 3X, "---", 4X, "---", 4X, "---",
     $ 3X, "---", 3X, "---", 3X, "---", 3X, "---", 2X, "----")
       DO i = 1, NUMSEC
            SECNUM(i) = i
            PRINT 70, SECNUM(i), SECLEN(i), PSTSPEED(i), 
     $      ISMOMIN(i), ISMOMAX(i), DRAINQ(i), TRANDENO(i), 
     $      GATAREAO(i), POTAREAO(i), DEPAREAO(i) 
70          FORMAT (I3, 3X, F3.1, 3X, I3, 2X, I5, 2X, I5, 2X, A3, 3X, 
     $      I3, 3X, I3, 3X, I3, 3X, I3)
       END DO
       END IF

c 240
c Initialize program control variables.

       DAY = 0
       DAYMO = 0
       MONTH = 1
       MONTHYR = 1
       YEAR = 1
       DAYFINAL = DURANAL*30
       PCUM = 0
       portion = NUMSEC/p
       tag = 101
       root = 0

c Establish the rate of depression formation, as a function of both:
c quality of construction and conserveness in design.
c 300
       IF ((CONSTRQ .EQ. 'L') .AND. (DESIGNQ .EQ. 'L')) THEN
            DEPSLOPE = 0.7
       ELSE IF ((CONSTRQ .EQ. 'L') .AND. (DESIGNQ .EQ. 'M')) THEN
            DEPSLOPE = 0.6
       ELSE IF (CONSTRQ .EQ. 'L') THEN
            DEPSLOPE = 0.5
       END IF

       IF ((CONSTRQ .EQ. 'M') .AND. (DESIGNQ .EQ. 'L')) THEN
            DEPSLOPE = 0.6
       ELSE IF ((CONSTRQ .EQ. 'M') .AND. (DESIGNQ .EQ. 'M')) THEN
            DEPSLOPE = 0.5
       ELSE IF (CONSTRQ .EQ. 'M') THEN
            DEPSLOPE = 0.4
       END IF

       IF ((CONSTRQ .EQ. 'H') .AND. (DESIGNQ .EQ. 'L')) THEN
            DEPSLOPE = 0.5
       ELSE IF ((CONSTRQ .EQ. 'H') .AND. (DESIGNQ .EQ. 'M')) THEN
            DEPSLOPE = 0.4
       ELSE IF (CONSTRQ .EQ. 'H') THEN
            DEPSLOPE = 0.3
       END IF

c Initialize work and distress variables.

       DO i = (rank*portion)+1, (rank+1)*portion
            WORKCUM(i) = 0
            TRANDEN(i) = TRANDENO(i)
            GATAREA(i) = GATAREAO(i)
            POTAREA(i) = POTAREAO(i)
            DEPAREA(i) = DEPAREAO(i)
       END DO

c Calculate initial velocity corrections for ISMO for each
c pavement section.

       DO i = (rank*portion)+1, (rank+1)*portion
            IF (PSTSPEED(i) .GT. 40) THEN
                 VCI(i) = 1.0
            ELSE IF (PSTSPEED(i) .LE. 10) THEN
                 VCI(i) = 0.75
            ELSE            
                 VCI(i) = 0.9
            END IF
       END DO

c Initialize transverse crack calculations for each pavement section.

       DO i = (rank*portion)+1, (rank+1)*portion
            ZTDO(i) = TRANDENO(i)**2
            ZTDCUM(i) = ZTDO(i)
       END DO

c Establish first seed for random numbers using computer clock.
c Root gets seed and distributes to other processors.  Seeds on
c different processors need to match for this application.

       IF (rank .EQ. 0) THEN       
            TIMESEC = SECNDS(0.0)
            INTSEC = INT(TIMESEC)
       END IF

       CALL MPI_Bcast(INTSEC, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr)

c ************************************
c Begin Looping for Daily Computations
c ************************************

       DO DAY = 1, DAYFINAL

            DAYMO = DAYMO + 1
            IF (DAYMO .EQ. 31) THEN
                 DAYMO = 1
                 MONTH = MONTH + 1
                 MONTHYR = MONTHYR + 1
                 IF (MONTHYR .EQ. 13) THEN
                      MONTHYR = 1
                      YEAR = YEAR + 1
                 END IF
            END IF

c Randomly select temperature data for the day 
c (applies to entire route).

       AVGTEMPD = MINDAVG(MONTHYR)+RAN(INTSEC)*
     $ (MAXDAVG(MONTHYR)-MINDAVG(MONTHYR))
c 330
       AVGTEMPN = MINNAVG(MONTHYR)+RAN(INTSEC)*
     $ (MAXNAVG(MONTHYR)-MINNAVG(MONTHYR))

       DEVTEMPD = MINDDEV(MONTHYR)+RAN(INTSEC)*
     $ (MAXDDEV(MONTHYR)-MINDDEV(MONTHYR))

       DEVTEMPN = MINNDEV(MONTHYR)+RAN(INTSEC)*
     $ (MAXNDEV(MONTHYR)-MINNDEV(MONTHYR))

       MINTEMPD = AVGTEMPD - DEVTEMPD
       MAXTEMPD = AVGTEMPD + DEVTEMPD
       MINTEMPN = AVGTEMPN - DEVTEMPN
       MAXTEMPN = AVGTEMPN + DEVTEMPN

c Randomly select precipitation data for the day and cumulate
c over 5 days.

       PD = MAXDP(MONTHYR)*RAN(INTSEC)**2

       IF (DAY .GT. 5) THEN
            DO i = 6, 2, -1
                 P5D(i) = P5D(i-1)
            END DO
            P5D(1) = PD
            PCUM = PCUM - P5D(6) + P5D(1)
       ELSE IF (DAY .EQ. 5) THEN
            DO i = 5, 2, -1
                 P5D(i) = P5D(i-1)
            END DO
            P5D(1) = PD
            PCUM = PCUM + P5D(1)
c 361
       ELSE IF (DAY .EQ. 4) THEN
            DO i = 4, 2, -1
                 P5D(i) = P5D(i-1)
            END DO
            P5D(1) = PD
            PCUM = PCUM + P5D(1)
       ELSE IF (DAY .EQ. 3) THEN
            P5D(3) = P5D(2)
            P5D(2) = P5D(1)
            P5D(1) = PD
            PCUM = PCUM + P5D(1)
       ELSE IF (DAY .EQ. 2) THEN
            P5D(2) = P5D(1)
            P5D(1) = PD
            PCUM = PCUM + P5D(1)           
       ELSE IF (DAY .EQ. 1) THEN
            P5D(1) = PD
            PCUM = PCUM + P5D(1)
       END IF
   
c Establish qualitative five-day precipitation.

       IF (PCUM .LE. 1) THEN
            LEVPREC = "L"
       ELSE IF (PCUM .GT. 20) THEN
            LEVPREC = "H"
       ELSE
            LEVPREC = "M"
       END IF
c 391
c Establish categorical level of cold.

       COLD = "N"
       IF ((MINTEMPN .LT. 20) .OR. (MINTEMPD .LT. 20)) THEN
            COLD = "L"
       END IF
       IF ((MINTEMPN .LT. 0) .OR. (MINTEMPD .LT. 0)) THEN
            COLD = "M"
       END IF
       IF ((MINTEMPN .LT. -20) .OR. (MINTEMPD .LT. -20)) THEN
            COLD = "H"
       END IF

c Calculate temperature correction for ISMO for the day
c (applies to the entire route).

       TCD = 1.0
       TCN = 1.0

       IF (AVGTEMPD .GT. 90) THEN 
            TCD = 0.9
       ENDIF
       IF (AVGTEMPN .GT. 90) THEN 
            TCN = 0.9
       ENDIF
       IF (AVGTEMPD .GT. 95) THEN
            TCD = 0.8
       ENDIF

       IF (AVGTEMPN .GT. 95) THEN
            TCN = 0.8
       ENDIF
       IF (AVGTEMPD .LT. 55) THEN
            TCD = 1.2
       ENDIF
       IF (AVGTEMPN .LT. 55) THEN
            TCN = 1.2
       ENDIF
       IF (AVGTEMPD .LT. 35) THEN
            TCD = 1.5
       ENDIF
       IF (AVGTEMPN .LT. 35) THEN
            TCN = 1.5
       ENDIF
c 423
c Initialize and update crack susceptibility of asphalt concrete.

       IF ((BINDBRIT .EQ. 'L') .AND. (AGESURF .GT. 60)) THEN
            ACCRACK = 'M'
       ELSE IF (BINDBRIT .EQ. 'L') THEN
            ACCRACK = 'L'
       END IF

       IF ((BINDBRIT .EQ. 'M') .AND. (AGESURF .LE. 12)) THEN
            ACCRACK = 'L'
c 272
       ELSE IF ((BINDBRIT .EQ. 'M') .AND. (AGESURF .GT. 60)) THEN
            ACCRACK = 'H'
       ELSE IF (BINDBRIT .EQ. 'M') THEN
            ACCRACK = 'M'
       END IF

       IF ((BINDBRIT .EQ. 'H') .AND. (AGESURF .LE. 12)) THEN
            ACCRACK = 'M'
       ELSE IF (BINDBRIT .EQ. 'H') THEN
            ACCRACK = 'H'
       END IF

c  Establish daily transverse cracking tendency for entire route.

       IF (COLD .EQ. 'N') THEN
            ZTD = 0.0
       END IF

       IF ((COLD .EQ. 'L') .AND. (ACCRACK .EQ. 'L')) THEN
            ZTD = 0.1
c 450
       ELSE IF ((COLD .EQ. 'L') .AND. (ACCRACK .EQ. 'M')) THEN
            ZTD = 0.25
       ELSE IF (COLD .EQ. 'L') THEN
            ZTD = 0.5
       END IF

       IF ((COLD .EQ. 'M') .AND. (ACCRACK .EQ. 'L')) THEN
            ZTD = 0.25
       ELSE IF ((COLD .EQ. 'M') .AND. (ACCRACK .EQ. 'M')) THEN
            ZTD = 0.5
       ELSE IF (COLD .EQ. 'M') THEN
            ZTD = 0.75
       END IF

       IF ((COLD .EQ. 'H') .AND. (ACCRACK .EQ. 'L')) THEN
            ZTD = 0.5
       ELSE IF ((COLD .EQ. 'H') .AND. (ACCRACK .EQ. 'M')) THEN
            ZTD = 0.75
       ELSE IF (COLD .EQ. 'H') THEN
            ZTD = 1.0
       END IF

c Cumulate transverse cracks for each pavement test section.
c Also, establish qualitative severity for transverse cracks.
c 475
       DO i = (rank*portion)+1, (rank+1)*portion
            ZTDCUM(i) = ZTDCUM(i) + ZTD
            TRANDEN(i) = SQRT(ZTDCUM(i))
            IF (TRANDEN(i) .LE. 10) THEN
                 LEVTRAN(i) = "L"
            ELSE IF (DEPAREA(i) .GT. 40) THEN
                 LEVTRAN(i) = "H"
            ELSE 
                 LEVTRAN(i) = "M"
            END IF
       END DO

c Update velocity corrections for ISMO for each pavement section,
c accounting for distress.

       DO i = (rank*portion)+1, (rank+1)*portion
            VC(i) = VCI(i)
            IF ((VCI(i) .EQ. 1.0) .AND. (DEPAREA(i) .GT. 10)) THEN
                 VC(i) = 0.9
            ENDIF
            IF ((VCI(i) .EQ. 1.0) .AND. (POTAREA(i) .GT. 10)) THEN
                 VC(i) = 0.9
            ENDIF
            IF ((VCI(i) .NE. 0.75) .AND. (DEPAREA(i) .GT. 50)) THEN
                 VC(i) = 0.75
            ENDIF
            IF ((VCI(i) .NE. 0.75) .AND. (POTAREA(i) .GT. 50)) THEN
                 VC(i) = 0.75
            ENDIF
       END DO

c Randomly select ISMO for each pavement section.  
c Then calculate both ISMAD and ISMAN.

       DO i = (rank*portion)+1, (rank+1)*portion
c 511
            ISMO(i) = ISMOMIN(i) + RAN(INTSEC)*
     $      (ISMOMAX(i)-ISMOMIN(i))

            ISMAD(i) = ISMO(i) * TCD * VC(i)
            ISMAN(i) = ISMO(i) * TCN * VC(i)

       END DO

c Calculate work and cumulative work.  Use 30 random values for axle
c load for each load classification.

       DO i = (rank*portion)+1, (rank+1)*portion

            WORK(i) = 0

            DO j = 1, 30

                 DTL = 2 * SQRT(RAN(INTSEC))
                 DTM = 2 + 6 * RAN(INTSEC)
                 DTH = 8 + 4 * RAN(INTSEC)**2

                 INCWORK = (DTL**2/ISMAD(i))*DAHVT*12*(PDTL/30) +
     $                     (DTM**2/ISMAD(i))*DAHVT*12*(PDTM/30) + 
     $                     (DTH**2/ISMAD(i))*DAHVT*12*(PDTH/30) +
     $                     (DTL**2/ISMAN(i))*NAHVT*12*(PNTL/30) +
     $                     (DTM**2/ISMAN(i))*NAHVT*12*(PNTM/30) +
     $                     (DTH**2/ISMAN(i))*NAHVT*12*(PNTH/30)

                 WORK(i) = WORK(i) + INCWORK

            END DO

            WORKCUM(i) = WORKCUM(i) + WORK(i)/1000000
c 541
       END DO

c Update severity of depressions, both quantitative and qualitative.

       DO i = (rank*portion)+1, (rank+1)*portion
            DEPAREA(i) = DEPAREAO(i) + DEPSLOPE * WORKCUM(i)
            IF (DEPAREA(i) .LE. 5) THEN
                 LEVDEPR(i) = "L"
            ELSE IF (DEPAREA(i) .GT. 20) THEN
                 LEVDEPR(i) = "H"
            ELSE 
                 LEVDEPR(i) = "M"
            END IF
       END DO

c Establish tendency for alligator cracking.

       DO i = (rank*portion)+1, (rank+1)*portion
          IF ((ACCRACK .EQ. "L") .AND. (LEVDEPR(i) .EQ. "L")) THEN
               GATSLOPE(i) = 0.1
          ELSE IF ((ACCRACK .EQ. "L") .AND. (LEVDEPR(i) .EQ. "M")) THEN
               GATSLOPE(i) = 0.2
          ELSE IF (ACCRACK .EQ. "L") THEN
               GATSLOPE(i) = 0.3
           END IF

          IF ((ACCRACK .EQ. "M") .AND. (LEVDEPR(i) .EQ. "L")) THEN
               GATSLOPE(i) = 0.2
c 570
          ELSE IF ((ACCRACK .EQ. "M") .AND. (LEVDEPR(i) .EQ. "M")) THEN
               GATSLOPE(i) = 0.3
          ELSE IF (ACCRACK .EQ. "M") THEN
               GATSLOPE(i) = 0.4
          END IF

          IF ((ACCRACK .EQ. "H") .AND. (LEVDEPR(i) .EQ. "L")) THEN
               GATSLOPE(i) = 0.3
          ELSE IF ((ACCRACK .EQ. "H") .AND. (LEVDEPR(i) .EQ. "M")) THEN
               GATSLOPE(i) = 0.4
          ELSE IF (ACCRACK .EQ. "H") THEN
               GATSLOPE(i) = 0.5
          END IF
       END DO

c Update severity of alligator cracks, both 
c quantitative and qualitative.

       DO i = (rank*portion)+1, (rank+1)*portion
            GATAREA(i) = GATAREAO(i) + GATSLOPE(i) * WORKCUM(i)
            IF (GATAREA(i) .LE. 5) THEN
                 LEVGAT(i) = "L"
            ELSE IF (GATAREA(i) .GT. 20) THEN
                 LEVGAT(i) = "H"
            ELSE 
                 LEVGAT(i) = "M"
            END IF
       END DO
c 599
c Establish categorical availability of moisture 
c for each pavement section.

       DO i = (rank*portion)+1, (rank+1)*portion
          IF (LEVPREC .EQ. "L") THEN
               MOISTURE(i) = "L"
          END IF

          IF ((LEVPREC .EQ. "M") .AND. (DRAINQ(i) .EQ. "L")) THEN
               MOISTURE(i) = "H"
          ELSE IF ((LEVPREC .EQ. "M") .AND. (DRAINQ(i) .EQ. "M")) THEN
               MOISTURE(i) = "M"
          ELSE IF ((LEVPREC .EQ. "M") .AND. (DRAINQ(i) .EQ. "H")) THEN
               MOISTURE(i) = "L"
          END IF 

          IF ((LEVPREC .EQ. "H") .AND. (DRAINQ(i) .EQ. "L")) THEN
               MOISTURE(i) = "H"
          ELSE IF ((LEVPREC .EQ. "H") .AND. (DRAINQ(i) .EQ. "M")) THEN
               MOISTURE(i) = "H"
          ELSE IF ((LEVPREC .EQ. "H") .AND. (DRAINQ(i) .EQ. "H")) THEN
               MOISTURE(i) = "M"
          END IF 
       END DO

c Establish categorical level of total cracking.

       DO i = (rank*portion)+1, (rank+1)*portion
          IF ((LEVGAT(i) .EQ. "L") .AND. (LEVTRAN(i) .EQ. "H")) THEN
               LEVCRACK(i) = "M"
          ELSE IF (LEVGAT(i) .EQ. "L") THEN
               LEVCRACK(i) = "L"
          END IF
c 632
          IF ((LEVGAT(i) .EQ. "M") .AND. (LEVTRAN(i) .EQ. "H")) THEN
               LEVCRACK(i) = "H"
          ELSE IF (LEVGAT(i) .EQ. "M") THEN
               LEVCRACK(i) = "M"
          END IF

          IF ((LEVGAT(i) .EQ. "H") .AND. (LEVTRAN(i) .EQ. "L")) THEN
               LEVCRACK(i) = "M"
          ELSE IF (LEVGAT(i) .EQ. "H") THEN
               LEVCRACK(i) = "H"
          END IF
       END DO

c Establish susceptibility of pothole formation.  
c Update pothole severity.

       DO i = (rank*portion)+1, (rank+1)*portion
          IF ((LEVCRACK(i) .EQ. "L") .AND. (MOISTURE(i) .EQ. "L")) THEN
               POTSLOPE(i) = 0.1
          ELSE IF ((LEVCRACK(i) .EQ. "L") .AND.
     $         (MOISTURE(i) .EQ. "M")) THEN
               POTSLOPE(i) = 0.2
          ELSE IF (LEVCRACK(i) .EQ. "L") THEN
               POTSLOPE(i) = 0.3
          END IF

          IF ((LEVCRACK(i) .EQ. "M") .AND. (MOISTURE(i) .EQ. "L")) THEN
               POTSLOPE(i) = 0.2
c 661
          ELSE IF ((LEVCRACK(i) .EQ. "M") .AND.
     $         (MOISTURE(i) .EQ. "M")) THEN
               POTSLOPE(i) = 0.3
          ELSE IF (LEVCRACK(i) .EQ. "M") THEN
               POTSLOPE(i) = 0.4
          END IF

          IF ((LEVCRACK(i) .EQ. "H") .AND. (MOISTURE(i) .EQ. "L")) THEN
               POTSLOPE(i) = 0.3
          ELSE IF ((LEVCRACK(i) .EQ. "H") .AND.
     $         (MOISTURE(i) .EQ. "M")) THEN
               POTSLOPE(i) = 0.4
          ELSE IF (LEVCRACK(i) .EQ. "H") THEN
               POTSLOPE(i) = 0.5
          END IF

          POTAREA(i) = POTAREAO(i) + POTSLOPE(i) * WORKCUM(i)

       END DO

      END DO

c ********************************
c End loop for daily calculations.
c ********************************

c Stop timer and calculate duration of run.

       CALL MPI_BARRIER(MPI_COMM_WORLD, ierr)

       finish = MPI_WTIME()

       duration = finish - start

c Gather results for all pavement sections.  Results will be gathered
c to root and then printed.

            CALL MPI_GATHER(WORKCUM(rank*portion+1), portion, MPI_REAL, 
     $      WORKCUM(rank*portion+1),
     $      portion, MPI_REAL, root, MPI_COMM_WORLD, ierr)

            CALL MPI_GATHER(TRANDEN(rank*portion+1), portion, MPI_REAL, 
     $      TRANDEN(rank*portion+1),
     $      portion, MPI_REAL, root, MPI_COMM_WORLD, ierr)

            CALL MPI_GATHER(DEPAREA(rank*portion+1), portion, MPI_REAL, 
     $      DEPAREA(rank*portion+1),
     $      portion, MPI_REAL, root, MPI_COMM_WORLD, ierr)

            CALL MPI_GATHER(GATAREA(rank*portion+1), portion, MPI_REAL, 
     $      GATAREA(rank*portion+1),
     $      portion, MPI_REAL, root, MPI_COMM_WORLD, ierr)

            CALL MPI_GATHER(POTAREA(rank*portion+1), portion, MPI_REAL, 
     $      POTAREA(rank*portion+1),
     $      portion, MPI_REAL, root, MPI_COMM_WORLD, ierr)

       CALL MPI_BARRIER(MPI_COMM_WORLD, ierr)

c Printing Results of Analysis

       IF (rank .EQ. root) THEN
            PRINT *, ' '
            PRINT *, "Summary of Selected Results After Analysis"
            PRINT *, "------------------------------------------"
            PRINT *, ' '
            PRINT *, "Date at End of Analysis (day/month/year):  ",
     $      daymo, "/", monthyr, "/", year
            PRINT *, ' '
            PRINT *, "Execution Time (sec) = ", duration
            PRINT *, ' '
            PRINT *, "Col.No.  Description of Results"
            PRINT *, " (1)     Pavement Section Number"
            PRINT *, " (2)     Cum. Work by Traffic [(in-kips)x10^6]"
            PRINT *, " (3)     Transverse Cracks (no./1000 ft)"
            PRINT *, " (4)     Percent Area with Depressions"
            PRINT *, " (5)     Percent Area with Alligator Cracking"
            PRINT *, " (6)     Percent Area with Potholes"
            PRINT *, ' '
            PRINT 100 
100         FORMAT (" (1)", 4X, "(2)", 5X, "(3)", 4X, "(4)",
     $      4X, "(5)", 5X, "(6)")
            PRINT *, "------------------------------------------"
            DO i = 1, NUMSEC
                 SECNUM(i) = i
                 PRINT 110, SECNUM(i), WORKCUM(i), TRANDEN(i), 
     $           DEPAREA(i), GATAREA(i), POTAREA(i)
110              FORMAT (I3, 3X, F5.1, 3X, F5.1, 2X, F5.1, 2X, F5.1, 
     $           3X, F5.1)
            END DO
       END IF

       CALL MPI_FINALIZE(ierr)

       END

