!+ Subroutine to calculate the total cloud cover.                                  RAD_ALL.5059  
!                                                                                  RAD_ALL.5060  
! Purpose:                                                                         RAD_ALL.5061  
!   The total cloud cover at all grid-points is determined.                        RAD_ALL.5062  
!                                                                                  RAD_ALL.5063  
! Method:                                                                          RAD_ALL.5064  
!   A separate calculation is made for each different assumption about             RAD_ALL.5065  
!   the overlap.                                                                   RAD_ALL.5066  
!                                                                                  RAD_ALL.5067  
! Current Owner of Code: J. M. Edwards                                             RAD_ALL.5068  
!                                                                                  RAD_ALL.5069  
! History:                                                                         RAD_ALL.5070  
!       Version         Date                    Comment                            RAD_ALL.5071  
!       4.0             27-07-95                Original Code                      RAD_ALL.5072  
!                                               (J. M. Edwards)                    RAD_ALL.5073  
!       4.2             08-08-96                Code added for coherent            RAD_ALL.5074  
!                                               convective cloud.                  RAD_ALL.5075  
!                                               (J. M. Edwards)                    RAD_ALL.5076  
!                                                                                  RAD_ALL.5077  
! Description of Code:                                                             RAD_ALL.5078  
!   FORTRAN 77  with extensions listed in documentation.                           RAD_ALL.5079  
!                                                                                  RAD_ALL.5080  
!- ---------------------------------------------------------------------           RAD_ALL.5081  
      SUBROUTINE R2_CALC_TOTAL_CLOUD_COVER(N_PROFILE, NLEVS, NCLDS                 RAD_ALL.5082  
     &   , I_CLOUD, W_CLOUD, TOTAL_CLOUD_COVER                                     RAD_ALL.5083  
     &   , NPD_PROFILE, NPD_LAYER                                                  RAD_ALL.5084  
     &   )                                                                         RAD_ALL.5085  
!                                                                                  RAD_ALL.5086  
!                                                                                  RAD_ALL.5087  
!                                                                                  RAD_ALL.5088  
      IMPLICIT NONE                                                                RAD_ALL.5089  
!                                                                                  RAD_ALL.5090  
!                                                                                  RAD_ALL.5091  
!     DECLARATION OF ARRAY SIZES.                                                  RAD_ALL.5092  
      INTEGER   !, INTENT(IN)                                                      RAD_ALL.5093  
     &     NPD_PROFILE                                                             RAD_ALL.5094  
!             MAXIMUM NUMBER OF PROFILES                                           RAD_ALL.5095  
     &   , NPD_LAYER                                                               RAD_ALL.5096  
!             MAXIMUM NUMBER OF LAYERS                                             RAD_ALL.5097  
!                                                                                  RAD_ALL.5098  
!     COMDECKS INCLUDED                                                            RAD_ALL.5099  
!     ------------------------------------------------------------------           CLSCHM3A.2     
!     COMDECK FOR TWO-STREAM RADIATION CODE.                                       CLSCHM3A.3     
!                                                                                  CLSCHM3A.4     
!     MODULE TO DEFINE REFERENCE NUMBERS FOR CLOUD SCHEMES.                        CLSCHM3A.5     
!                                                                                  CLSCHM3A.6     
      INTEGER                                                                      CLSCHM3A.7     
     &     IP_CLOUD_SCHMETZ                                                        CLSCHM3A.8     
!             SCHMETZ'S SCHEME                                                     CLSCHM3A.9     
     &   , IP_CLOUD_MIX_MAX                                                        CLSCHM3A.10    
!             MAXIMUM/RANDOM OVERLAP IN A MIXED COLUMN                             CLSCHM3A.11    
     &   , IP_CLOUD_MIX_RANDOM                                                     CLSCHM3A.12    
!             RANDOM OVERLAP IN A MIXED COLUMN                                     CLSCHM3A.13    
     &   , IP_CLOUD_COLUMN_MAX                                                     CLSCHM3A.14    
!             MAXIMUM OVERLAP IN A COLUMN MODEL                                    CLSCHM3A.15    
     &   , IP_CLOUD_CLEAR                                                          CLSCHM3A.16    
!             CLEAR COLUMN                                                         CLSCHM3A.17    
     &   , IP_CLOUD_TRIPLE                                                         CLSCHM3A.18    
!             MIXED COLUMN WITH SPLIT BETWEEN                                      CLSCHM3A.19    
!             CONVECTIVE AND LAYER CLOUD.                                          CLSCHM3A.20    
!                                                                                  CLSCHM3A.21    
      PARAMETER(                                                                   CLSCHM3A.22    
     &     IP_CLOUD_SCHMETZ=1                                                      CLSCHM3A.23    
     &   , IP_CLOUD_MIX_MAX=2                                                      CLSCHM3A.24    
     &   , IP_CLOUD_MIX_RANDOM=4                                                   CLSCHM3A.25    
     &   , IP_CLOUD_COLUMN_MAX=3                                                   CLSCHM3A.26    
     &   , IP_CLOUD_CLEAR=5                                                        CLSCHM3A.27    
     &   , IP_CLOUD_TRIPLE=6                                                       CLSCHM3A.28    
     &   )                                                                         CLSCHM3A.29    
!                                                                                  CLSCHM3A.30    
!     ------------------------------------------------------------------           CLSCHM3A.31    
!                                                                                  RAD_ALL.5101  
!                                                                                  RAD_ALL.5102  
!     DUMMY ARGUMENTS.                                                             RAD_ALL.5103  
      INTEGER   !, INTENT(IN)                                                      RAD_ALL.5104  
     &     N_PROFILE                                                               RAD_ALL.5105  
!             NUMBER OF PROFILES                                                   RAD_ALL.5106  
     &   , NLEVS                                                                   RAD_ALL.5107  
!             NUMBER OF LAYERS                                                     RAD_ALL.5108  
     &   , NCLDS                                                                   RAD_ALL.5109  
!             NUMBER OF CLOUDY LAYERS                                              RAD_ALL.5110  
     &   , I_CLOUD                                                                 RAD_ALL.5111  
!             CLOUD SCHEME EMPLOYED                                                RAD_ALL.5112  
      REAL      !, INTENT(IN)                                                      RAD_ALL.5113  
     &     W_CLOUD(NPD_PROFILE, NPD_LAYER)                                         RAD_ALL.5114  
!             CLOUD AMOUNTS                                                        RAD_ALL.5115  
!                                                                                  RAD_ALL.5116  
      REAL      !, INTENT(OUT)                                                     RAD_ALL.5117  
     &     TOTAL_CLOUD_COVER(NPD_PROFILE)                                          RAD_ALL.5118  
!             TOTAL CLOUD COVER                                                    RAD_ALL.5119  
!                                                                                  RAD_ALL.5120  
!                                                                                  RAD_ALL.5121  
!     LOCAL VARIABLES.                                                             RAD_ALL.5122  
      INTEGER                                                                      RAD_ALL.5123  
     &     L                                                                       RAD_ALL.5124  
!             LOOP VARIABLE                                                        RAD_ALL.5125  
     &   , I                                                                       RAD_ALL.5126  
!             LOOP VARIABLE                                                        RAD_ALL.5127  
!                                                                                  RAD_ALL.5128  
!                                                                                  RAD_ALL.5129  
!                                                                                  RAD_ALL.5130  
!     DIFFERENT OVERLAP ASSUMPTIONS ARE CODED INTO EACH SOLVER.                    RAD_ALL.5131  
!                                                                                  RAD_ALL.5132  
      IF (I_CLOUD.EQ.IP_CLOUD_MIX_MAX) THEN                                        RAD_ALL.5133  
!                                                                                  RAD_ALL.5134  
!        USE THE TOTAL CLOUD COVER TEMPORARILY TO HOLD THE CLEAR-SKY               RAD_ALL.5135  
!        FRACTION AND CONVERT BACK TO CLOUD COVER LATER.                           RAD_ALL.5136  
!        WE CALCULATE THIS QUANTITY BY IMAGINING A TOTALLY TRANSPARENT             RAD_ALL.5137  
!        ATMOSPHERE CONTAINING TOTALLY OPAQUE CLOUDS AND FINDING THE               RAD_ALL.5138  
!        TRANSMISSION.                                                             RAD_ALL.5139  
         DO L=1, N_PROFILE                                                         RAD_ALL.5140  
            TOTAL_CLOUD_COVER(L)=1.0E+00-W_CLOUD(L, NLEVS+1-NCLDS)                 RAD_ALL.5141  
         ENDDO                                                                     RAD_ALL.5142  
         DO I=NLEVS+1-NCLDS, NLEVS-1                                               RAD_ALL.5143  
            DO L=1, N_PROFILE                                                      RAD_ALL.5144  
               IF (W_CLOUD(L, I+1).GT.W_CLOUD(L, I)) THEN                          RAD_ALL.5145  
                  TOTAL_CLOUD_COVER(L)=TOTAL_CLOUD_COVER(L)                        RAD_ALL.5146  
     &               *(1.0E+00-W_CLOUD(L, I+1))/(1.0E+00-W_CLOUD(L, I))            RAD_ALL.5147  
               ENDIF                                                               RAD_ALL.5148  
            ENDDO                                                                  RAD_ALL.5149  
         ENDDO                                                                     RAD_ALL.5150  
         DO L=1, N_PROFILE                                                         RAD_ALL.5151  
            TOTAL_CLOUD_COVER(L)=1.0E+00-TOTAL_CLOUD_COVER(L)                      RAD_ALL.5152  
         ENDDO                                                                     RAD_ALL.5153  
!                                                                                  RAD_ALL.5154  
      ELSE IF (I_CLOUD.EQ.IP_CLOUD_MIX_RANDOM) THEN                                RAD_ALL.5155  
!                                                                                  RAD_ALL.5156  
!        USE THE TOTAL CLOUD COVER TEMPORARILY TO HOLD THE CLEAR-SKY               RAD_ALL.5157  
!        FRACTION AND CONVERT BACK TO CLOUD COVER LATER.                           RAD_ALL.5158  
         DO L=1, N_PROFILE                                                         RAD_ALL.5159  
            TOTAL_CLOUD_COVER(L)=1.0E+00                                           RAD_ALL.5160  
         ENDDO                                                                     RAD_ALL.5161  
         DO I=NLEVS+1-NCLDS, NLEVS                                                 RAD_ALL.5162  
            DO L=1, N_PROFILE                                                      RAD_ALL.5163  
               TOTAL_CLOUD_COVER(L)=TOTAL_CLOUD_COVER(L)                           RAD_ALL.5164  
     &            *(1.0E+00-W_CLOUD(L, I))                                         RAD_ALL.5165  
            ENDDO                                                                  RAD_ALL.5166  
         ENDDO                                                                     RAD_ALL.5167  
         DO L=1, N_PROFILE                                                         RAD_ALL.5168  
            TOTAL_CLOUD_COVER(L)=1.0E+00-TOTAL_CLOUD_COVER(L)                      RAD_ALL.5169  
         ENDDO                                                                     RAD_ALL.5170  
!                                                                                  RAD_ALL.5171  
      ELSE IF (I_CLOUD.EQ.IP_CLOUD_COLUMN_MAX) THEN                                RAD_ALL.5172  
!                                                                                  RAD_ALL.5173  
         DO L=1, N_PROFILE                                                         RAD_ALL.5174  
            TOTAL_CLOUD_COVER(L)=0.0E+00                                           RAD_ALL.5175  
         ENDDO                                                                     RAD_ALL.5176  
         DO I=NLEVS+1-NCLDS, NLEVS                                                 RAD_ALL.5177  
            DO L=1, N_PROFILE                                                      RAD_ALL.5178  
               TOTAL_CLOUD_COVER(L)=MAX(TOTAL_CLOUD_COVER(L)                       RAD_ALL.5179  
     &            , W_CLOUD(L, I))                                                 RAD_ALL.5180  
            ENDDO                                                                  RAD_ALL.5181  
         ENDDO                                                                     RAD_ALL.5182  
!                                                                                  RAD_ALL.5183  
      ELSE IF (I_CLOUD.EQ.IP_CLOUD_TRIPLE) THEN                                    RAD_ALL.5184  
!                                                                                  RAD_ALL.5185  
!        USE THE TOTAL CLOUD COVER TEMPORARILY TO HOLD THE CLEAR-SKY               RAD_ALL.5186  
!        FRACTION AND CONVERT BACK TO CLOUD COVER LATER.                           RAD_ALL.5187  
!        WE CALCULATE THIS QUANTITY BY IMAGINING A TOTALLY TRANSPARENT             RAD_ALL.5188  
!        ATMOSPHERE CONTAINING TOTALLY OPAQUE CLOUDS AND FINDING THE               RAD_ALL.5189  
!        TRANSMISSION.                                                             RAD_ALL.5190  
         DO L=1, N_PROFILE                                                         RAD_ALL.5191  
            TOTAL_CLOUD_COVER(L)=1.0E+00-W_CLOUD(L, NLEVS+1-NCLDS)                 RAD_ALL.5192  
         ENDDO                                                                     RAD_ALL.5193  
         DO I=NLEVS+1-NCLDS, NLEVS-1                                               RAD_ALL.5194  
            DO L=1, N_PROFILE                                                      RAD_ALL.5195  
               IF (W_CLOUD(L, I+1).GT.W_CLOUD(L, I)) THEN                          RAD_ALL.5196  
                  TOTAL_CLOUD_COVER(L)=TOTAL_CLOUD_COVER(L)                        RAD_ALL.5197  
     &               *(1.0E+00-W_CLOUD(L, I+1))/(1.0E+00-W_CLOUD(L, I))            RAD_ALL.5198  
               ENDIF                                                               RAD_ALL.5199  
            ENDDO                                                                  RAD_ALL.5200  
         ENDDO                                                                     RAD_ALL.5201  
         DO L=1, N_PROFILE                                                         RAD_ALL.5202  
            TOTAL_CLOUD_COVER(L)=1.0E+00-TOTAL_CLOUD_COVER(L)                      RAD_ALL.5203  
         ENDDO                                                                     RAD_ALL.5204  
!                                                                                  RAD_ALL.5205  
      ELSE IF (I_CLOUD.EQ.IP_CLOUD_CLEAR) THEN                                     RAD_ALL.5206  
!                                                                                  RAD_ALL.5207  
         DO L=1, N_PROFILE                                                         RAD_ALL.5208  
            TOTAL_CLOUD_COVER(L)=0.0E+00                                           RAD_ALL.5209  
         ENDDO                                                                     RAD_ALL.5210  
!                                                                                  RAD_ALL.5211  
      ENDIF                                                                        RAD_ALL.5212  
!                                                                                  RAD_ALL.5213  
!                                                                                  RAD_ALL.5214  
!                                                                                  RAD_ALL.5215  
      RETURN                                                                       RAD_ALL.5216  
      END           
