C***********************************************************************     CLDTRN.2     
C*                         SUBROUTINE CLDTRAN                          *     CLDTRN.3     
C***********************************************************************     CLDTRN.4     
                                                                             CLDTRN.5     
      SUBROUTINE CLDTRAN(NLEV,PFLUX,DP,CL,ACL,LWCCL,BASCL,TOPCL,             CLDTRN.6     
     $                   TRCL,MTRCL)                                         CLDTRN.7     
                                                                             CLDTRN.8     
C Subroutine CLDTRAN is the cloud parametrization of the WBM. It is          CLDTRN.9     
C based on the Chou & Suarez (1994) scheme, which extended the method        CLDTRN.10    
C of Harshvardhan et al. (1987), written for black clouds, for the case      CLDTRN.11    
C of grey clouds. The scheme approximates the cloud by an equivalent         CLDTRN.12    
C effective overcast cloud and derives the cloud transmittance of            CLDTRN.13    
C different atmospheric layers. The cloud emissivity follows the             CLDTRN.14    
C parametrization of Ramanathan et al. (1983). The model can accomodate      CLDTRN.15    
C up to 3 different cloud types, which are considered randomly               CLDTRN.16    
C overlapped. No more than one cloud can be included in the same layer.      CLDTRN.17    
C The cloud base and top must be on pressure levels of the input profile     CLDTRN.18    
C                                                                            CLDTRN.19    
C INPUT:  Number of levels in the atmosphere without the surface (NLEV)      CLDTRN.20    
C         Pressure at flux levels (PFLUX)                                    CLDTRN.21    
C         Thickness of the atmospheric layers (DP)                           CLDTRN.22    
C         Selection of cloud types (CL)                                      CLDTRN.23    
C         CL(1)low level, CL(2)mid level, CL(3)high level,                   CLDTRN.24    
C         CL(0) deep convective                                              CLDTRN.25    
C         Cloud amount as a fraction (ACL)                                   CLDTRN.26    
C         Liquid water content (LWCCL)                                       CLDTRN.27    
C         Cloud base and top (BASCL,TOPCL)                                   CLDTRN.28    
C                                                                            CLDTRN.29    
C OUTPUT: Cloud transmittance (TRCL)                                         CLDTRN.30    
C         Cloud transmittance for the modified transm. case (MTRCL)          CLDTRN.31    
                                                                             CLDTRN.32    
      IMPLICIT NONE                                                          CLDTRN.33    
C***********************************************************************     PARRAY.2     
C*                                                                     *     PARRAY.3     
C*                         P A R R A Y                                 *     PARRAY.4     
C*                                                                     *     PARRAY.5     
C***********************************************************************     PARRAY.6     
C-----------------------------------------------------------------------     PARRAY.7     
C In this part of the code the user can set the dimensions of arrays         PARRAY.8     
C used for the calculations, by setting the values in the paramter           PARRAY.9     
C statements                                                                 PARRAY.10    
C-----------------------------------------------------------------------     PARRAY.11    
                                                                             PARRAY.12    
      INTEGER MXGAS,MXLEV,MXBAND,MXCL                                        PARRAY.13    
                                                                             PARRAY.14    
      PARAMETER(MXGAS=8)     ! Maximum number of gases                       PARRAY.15    
                                                                             PARRAY.16    
      PARAMETER(MXLEV=5)     ! Maximum number of levels in the               NETCDF.37    
                             ! atmosphere (not including the surface)        PARRAY.18    
                                                                             PARRAY.19    
      PARAMETER(MXBAND=9)    ! Maximum number of spectral bands (not         PARRAY.20    
                             ! including the whole spectrum, 0-3000cm-1)     PARRAY.21    
                                                                             PARRAY.22    
      PARAMETER(MXCL=3)      ! Maximum number of cloud types                 PARRAY.23    
                                                                             PARRAY.24    
C-----------------------------------------------------------------------     PARRAY.25    
C-----------------                                                           CLDTRN.35    
C Input Variables                                                            CLDTRN.36    
C-----------------                                                           CLDTRN.37    
                                                                             CLDTRN.38    
      INTEGER NLEV                                                           CLDTRN.39    
      REAL PFLUX(0:MXLEV),DP(MXLEV)                                          CLDTRN.40    
                                                                             CLDTRN.41    
      INTEGER CL(0:MXCL)                                                     CLDTRN.42    
      REAL ACL(0:MXCL),LWCCL(MXCL),BASCL(0:MXCL),TOPCL(0:MXCL)               CLDTRN.43    
                                                                             CLDTRN.44    
C------------------                                                          CLDTRN.45    
C Output Variables                                                           CLDTRN.46    
C------------------                                                          CLDTRN.47    
                                                                             CLDTRN.48    
      REAL TRCL(0:MXLEV-1,MXLEV),MTRCL(0:MXLEV-1,MXLEV)                      CLDTRN.49    
                                                                             CLDTRN.50    
C--------------------                                                        CLDTRN.51    
C Internal Variables                                                         CLDTRN.52    
C--------------------                                                        CLDTRN.53    
                                                                             CLDTRN.54    
      INTEGER ICL,ILEV,ILAY,ICOUNT,IDWN,IUP                                  CLDTRN.55    
      REAL DPCL            ! Cloud thickness                                 CLDTRN.56    
      REAL LWC(MXCL,MXLEV) ! LWC between 2 succesive levels                  CLDTRN.57    
      REAL LWPATH          ! LWC in atmospheric paths                        CLDTRN.58    
      REAL EMSSCL(MXCL)    ! Cloud emissivity                                CLDTRN.59    
      REAL CEMSS           ! Constant used in emissivity computations        CLDTRN.60    
      PARAMETER (CEMSS=1.08942549)                                           CLDTRN.61    
                                                                             CLDTRN.62    
                                                                             CLDTRN.63    
C Calculate the liquid water content between two succesive flux levels       CLDTRN.64    
                                                                             CLDTRN.65    
C--- Initialise LWC                                                          CLDTRN.66    
      DO ILAY=1,NLEV                                                         CLDTRN.67    
         DO ICL=1,MXCL                                                       CLDTRN.68    
            LWC(ICL,ILAY)=0.0                                                CLDTRN.69    
         END DO                                                              CLDTRN.70    
      END DO                                                                 CLDTRN.71    
                                                                             CLDTRN.72    
      DO ICL=1,MXCL                                                          CLDTRN.73    
                                                                             CLDTRN.74    
         ILAY=1                                                              CLDTRN.75    
                                                                             CLDTRN.76    
         IF (CL(ICL).EQ.1) THEN                                              CLDTRN.77    
                                                                             CLDTRN.78    
            DO WHILE ((100.*PFLUX(ILAY)).GT.BASCL(ICL))                      CLDTRN.79    
               ILAY=ILAY+1                                                   CLDTRN.80    
            END DO                                                           CLDTRN.81    
                                                                             CLDTRN.82    
            DPCL=DP(ILAY)                                                    CLDTRN.83    
            ICOUNT=ILAY                                                      CLDTRN.84    
            DO WHILE ((100.*PFLUX(ICOUNT)).GT.TOPCL(ICL))                    CLDTRN.85    
               ICOUNT=ICOUNT+1                                               CLDTRN.86    
               DPCL=DPCL+DP(ICOUNT)                                          CLDTRN.87    
            END DO                                                           CLDTRN.88    
                                                                             CLDTRN.89    
            LWC(ICL,ILAY)=(DP(ILAY)/DPCL)*0.5*LWCCL(ICL)                     CLDTRN.90    
                                                                             CLDTRN.91    
            DO WHILE ((100.*PFLUX(ILAY)).GT.TOPCL(ICL))                      CLDTRN.92    
               ILAY=ILAY+1                                                   CLDTRN.93    
               LWC(ICL,ILAY)=(DP(ILAY)/DPCL)*LWCCL(ICL)                      CLDTRN.94    
            END DO                                                           CLDTRN.95    
                                                                             CLDTRN.96    
         END IF                                                              CLDTRN.97    
                                                                             CLDTRN.98    
      END DO                                                                 CLDTRN.99    
                                                                             CLDTRN.100   
                                                                             CLDTRN.101   
C-----------------------------------------------------------------------     CLDTRN.102   
C Calculate the cloud transmittance of the atmospheric paths considered      CLDTRN.103   
C in the irradiance calculations                                             CLDTRN.104   
C-----------------------------------------------------------------------     CLDTRN.105   
                                                                             CLDTRN.106   
C Initialise cloud transmittances                                            CLDTRN.107   
      DO IUP=1,NLEV                                                          CLDTRN.108   
         DO IDWN=0,IUP-1                                                     CLDTRN.109   
            TRCL(IDWN,IUP)=1.0                                               CLDTRN.110   
         END DO                                                              CLDTRN.111   
      END DO                                                                 CLDTRN.112   
                                                                             CLDTRN.113   
                                                                             CLDTRN.114   
      DO IUP=1,NLEV                                                          CLDTRN.115   
         DO IDWN=0,IUP-1                                                     CLDTRN.116   
                                                                             CLDTRN.117   
C Calculate LWC in the atmospheric path                                      CLDTRN.118   
            DO ICL=1,MXCL                                                    CLDTRN.119   
               LWPATH=0.                                                     CLDTRN.120   
               IF (CL(ICL).EQ.1) THEN                                        CLDTRN.121   
                  DO ILEV=IDWN+1,IUP                                         CLDTRN.122   
                     LWPATH=LWPATH+LWC(ICL,ILEV)                             CLDTRN.123   
                  END DO                                                     CLDTRN.124   
               END IF                                                        CLDTRN.125   
C Calculate cloud emissivity and transmittance                               CLDTRN.126   
               IF (LWPATH.NE.0.) THEN                                        CLDTRN.127   
                  IF (LWPATH.LE.25E-3) THEN                                  CLDTRN.128   
                     EMSSCL(ICL)=CEMSS*(1.-EXP(-100.*LWPATH))                CLDTRN.129   
                     TRCL(IDWN,IUP)=TRCL(IDWN,IUP)*                          CLDTRN.130   
     $                              (1.-ACL(ICL)*EMSSCL(ICL))                CLDTRN.131   
                  ELSE                                                       CLDTRN.132   
                     TRCL(IDWN,IUP)=TRCL(IDWN,IUP)*(1.-ACL(ICL))             CLDTRN.133   
                  END IF                                                     CLDTRN.134   
               END IF                                                        CLDTRN.135   
            END DO                                                           CLDTRN.136   
C Check for deep convective cloud                                            CLDTRN.137   
            IF (CL(0).EQ.1) THEN                                             CLDTRN.138   
               IF ((100.*PFLUX(IUP).GT.BASCL(0)).OR.                         CLDTRN.139   
     $            (100.*PFLUX(IDWN).LT.TOPCL(0))) THEN                       CLDTRN.140   
                  CONTINUE                                                   CLDTRN.141   
               ELSE                                                          CLDTRN.142   
                  TRCL(IDWN,IUP)=(1.-ACL(0))*TRCL(IDWN,IUP)                  CLDTRN.143   
               END IF                                                        CLDTRN.144   
            END IF                                                           CLDTRN.145   
                                                                             CLDTRN.146   
         END DO                                                              CLDTRN.147   
      END DO                                                                 CLDTRN.148   
                                                                             CLDTRN.149   
                                                                             CLDTRN.150   
C-----------------------------------------------------------------------     CLDTRN.151   
C Calculate cloud transmittances for the modified transmittance case         CLDTRN.152   
C-----------------------------------------------------------------------     CLDTRN.153   
                                                                             CLDTRN.154   
C Initialise cloud transmittances                                            CLDTRN.155   
      DO IUP=1,NLEV                                                          CLDTRN.156   
         DO IDWN=0,NLEV-1                                                    CLDTRN.157   
            MTRCL(IDWN,IUP)=1.0                                              CLDTRN.158   
         END DO                                                              CLDTRN.159   
      END DO                                                                 CLDTRN.160   
                                                                             CLDTRN.161   
                                                                             CLDTRN.162   
      DO IUP=1,NLEV                                                          CLDTRN.163   
         DO IDWN=0,IUP-1                                                     CLDTRN.164   
                                                                             CLDTRN.165   
C Calculate LWC in the atmospheric path                                      CLDTRN.166   
            DO ICL=1,MXCL                                                    CLDTRN.167   
               LWPATH=0.                                                     CLDTRN.168   
               IF (CL(ICL).EQ.1) THEN                                        CLDTRN.169   
                  DO ILEV=IDWN+1,IUP                                         CLDTRN.170   
                     IF (LWC(ICL,ILEV).NE.0.) THEN                           CLDTRN.171   
                        IF (LWPATH.EQ.0.) THEN                               CLDTRN.172   
                           LWPATH=0.5*LWC(ICL,ILEV)                          CLDTRN.173   
                        ELSE                                                 CLDTRN.174   
                           LWPATH=LWPATH+LWC(ICL,ILEV)                       CLDTRN.175   
                        END IF                                               CLDTRN.176   
                     END IF                                                  CLDTRN.177   
                  END DO                                                     CLDTRN.178   
               END IF                                                        CLDTRN.179   
C Calculate cloud emissivity and transmittance                               CLDTRN.180   
               IF (LWPATH.NE.0.) THEN                                        CLDTRN.181   
                  IF (LWPATH.LE.25E-3) THEN                                  CLDTRN.182   
                     EMSSCL(ICL)=CEMSS*(1.-EXP(-100.*LWPATH))                CLDTRN.183   
                     MTRCL(IDWN,IUP)=MTRCL(IDWN,IUP)*                        CLDTRN.184   
     $                               (1.-ACL(ICL)*EMSSCL(ICL))               CLDTRN.185   
                  ELSE                                                       CLDTRN.186   
                     MTRCL(IDWN,IUP)=MTRCL(IDWN,IUP)*(1.-ACL(ICL))           CLDTRN.187   
                  END IF                                                     CLDTRN.188   
               END IF                                                        CLDTRN.189   
            END DO                                                           CLDTRN.190   
C Check for deep convective cloud                                            CLDTRN.191   
            IF (CL(0).EQ.1) THEN                                             CLDTRN.192   
               IF ((100.*PFLUX(IUP).GT.BASCL(0)).OR.                         CLDTRN.193   
     $            (100.*PFLUX(IDWN).LT.TOPCL(0))) THEN                       CLDTRN.194   
                  CONTINUE                                                   CLDTRN.195   
               ELSE                                                          CLDTRN.196   
                  MTRCL(IDWN,IUP)=(1.-ACL(0))*MTRCL(IDWN,IUP)                CLDTRN.197   
               END IF                                                        CLDTRN.198   
            END IF                                                           CLDTRN.199   
                                                                             CLDTRN.200   
         END DO                                                              CLDTRN.201   
      END DO                                                                 CLDTRN.202   
                                                                             CLDTRN.203   
                                                                             CLDTRN.204   
      END                                                                    CLDTRN.205   
