Ignore:
Timestamp:
Oct 21, 2024, 7:05:31 PM (3 months ago)
Author:
abarral
Message:

(cont.) Convert fixed-form to free-form sources .F -> .{f,F}90

Location:
LMDZ6/trunk/libf/phylmd/cosp
Files:
6 moved

Legend:

Unmodified
Added
Removed
  • LMDZ6/trunk/libf/phylmd/cosp/MISR_simulator.f90

    r5247 r5248  
    1 ! 
     1!
    22! Copyright (c) 2009,  Roger Marchand, version 1.2
    33! All rights reserved.
    44! $Revision: 23 $, $Date: 2011-03-31 15:41:37 +0200 (jeu. 31 mars 2011) $
    55! $URL: http://cfmip-obs-sim.googlecode.com/svn/stable/v1.4.0/MISR_simulator/MISR_simulator.f $
    6 ! 
    7 ! Redistribution and use in source and binary forms, with or without modification, are permitted 
     6!
     7! Redistribution and use in source and binary forms, with or without modification, are permitted
    88! provided that the following conditions are met:
    9 ! 
    10 !     * Redistributions of source code must retain the above copyright notice, this list of
    11 !       conditions and the following disclaimer.
    12 !     * Redistributions in binary form must reproduce the above copyright notice, this list
    13 !       of conditions and the following disclaimer in the documentation and/or other materials
    14 !       provided with the distribution.
    15 !     * Neither the name of the University of Washington nor the names of its contributors may be used
    16 !       to endorse or promote products derived from this software without specific prior written permission.
    17 ! 
     9!
     10! * Redistributions of source code must retain the above copyright notice, this list of
     11!   conditions and the following disclaimer.
     12! * Redistributions in binary form must reproduce the above copyright notice, this list
     13!   of conditions and the following disclaimer in the documentation and/or other materials
     14!   provided with the distribution.
     15! * Neither the name of the University of Washington nor the names of its contributors may be used
     16!   to endorse or promote products derived from this software without specific prior written permission.
     17!
    1818! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
    19 ! BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
    20 ! SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
    21 ! DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
    22 ! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
     19! BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
     20! SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21! DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     22! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    2323! NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2424!
    2525
    26       SUBROUTINE MISR_simulator(
    27      &     npoints,
    28      &     nlev,
    29      &     ncol,
    30      &     sunlit,
    31      &     zfull,
    32      &     at,
    33      &     dtau_s,
    34      &     dtau_c,
    35      &     frac_out,
    36      &     missing_value,
    37      &     fq_MISR_TAU_v_CTH,
    38      &     dist_model_layertops,
    39      &     MISR_mean_ztop,
    40      &     MISR_cldarea
    41      & )
    42    
    43 
    44       implicit none
    45       integer n_MISR_CTH
    46       parameter(n_MISR_CTH=16)
    47          
    48 !     -----
    49 !     Input
    50 !     -----
    51 
    52       INTEGER npoints                   !  if ncol ==1, the number of model points in the horizontal grid 
    53                             !   else    the number of GCM grid points
    54                            
    55       INTEGER nlev                      !  number of model vertical levels
    56      
    57       INTEGER ncol                      !  number of model sub columns
    58                         !  (must already be generated in via scops and passed to this
    59                         !   routine via the variable frac_out )
    60  
    61       INTEGER sunlit(npoints)           !  1 for day points, 0 for night time
    62 
    63       REAL zfull(npoints,nlev)          !  height (in meters) of full model levels (i.e. midpoints)
    64                                         !  zfull(npoints,1)    is    top level of model
    65                                         !  zfull(npoints,nlev) is bottom level of model (closest point to surface) 
    66 
    67       REAL at(npoints,nlev)             !  temperature in each model level (K)
    68  
    69       REAL dtau_s(npoints,nlev)         !  visible wavelength cloud optical depth ... for "stratiform" condensate
    70                                         !  NOTE:  this the cloud optical depth of only the
    71                     !     the model cell (i,j)
    72                    
    73       REAL dtau_c(npoints,nlev)         !  visible wavelength cloud optical depth ... for "convective" condensate
    74                                         !  NOTE:  this the cloud optical depth of only the
    75                     !     the model cell (i,j)
    76                                      
    77       REAL frac_out(npoints,ncol,nlev)  !  NOTE: only need if columns>1 ... subgrid scheme in use.
    78      
    79       REAL missing_value
    80                                  
    81 !     ------
    82 !     Outputs
    83 !     ------
    84            
    85       REAL fq_MISR_TAU_v_CTH(npoints,7,n_MISR_CTH)     
    86       REAL dist_model_layertops(npoints,n_MISR_CTH)
    87       REAL MISR_cldarea(npoints)               ! fractional area coverged by clouds
    88       REAL MISR_mean_ztop(npoints)             ! mean cloud top hieght(m) MISR would observe
    89                                    ! NOTE: == 0 if area ==0
    90                            
    91 
    92 !     ------
    93 !     Working variables
    94 !     ------
    95 
    96       REAL tau(npoints,ncol)        ! total column optical depth ...
    97 
    98       INTEGER j,ilev,ilev2,ibox,k
    99       INTEGER itau
    100          
    101       LOGICAL box_cloudy(npoints,ncol)
    102      
    103       real isccp_taumin
    104       real boxarea
    105       real tauchk
    106       REAL box_MISR_ztop(npoints,ncol)  ! cloud top hieght(m) MISR would observe
    107      
    108       integer thres_crossed_MISR
    109       integer loop,iMISR_ztop
    110      
    111       real dtau, cloud_dtau, MISR_penetration_height,ztest     
    112      
    113       real MISR_CTH_boundaries(n_MISR_CTH+1)
    114      
    115       DATA MISR_CTH_boundaries / -99, 0, 0.5, 1, 1.5, 2, 2.5, 3,
    116      c                    4, 5, 7, 9, 11, 13, 15, 17, 99 /
    117      
    118       DATA isccp_taumin / 0.3 /
    119    
    120       tauchk = -1.*log(0.9999999)
    121        
    122       !
    123       ! For each GCM cell or horizontal model grid point ...
    124       !
    125       do j=1,npoints   
    126 
    127          !
    128          !  estimate distribution of Model layer tops
    129          ! 
    130          dist_model_layertops(j,:)=0
    131 
    132        do ilev=1,nlev
    133            
    134         ! define location of "layer top"
    135         if(ilev.eq.1 .or. ilev.eq.nlev) then
    136             ztest=zfull(j,ilev)
     26SUBROUTINE MISR_simulator( &
     27        npoints, &
     28        nlev, &
     29        ncol, &
     30        sunlit, &
     31        zfull, &
     32        at, &
     33        dtau_s, &
     34        dtau_c, &
     35        frac_out, &
     36        missing_value, &
     37        fq_MISR_TAU_v_CTH, &
     38        dist_model_layertops, &
     39        MISR_mean_ztop, &
     40        MISR_cldarea &
     41        )
     42
     43
     44  implicit none
     45  integer :: n_MISR_CTH
     46  parameter(n_MISR_CTH=16)
     47
     48  ! -----
     49  ! Input
     50  ! -----
     51
     52  INTEGER :: npoints                   !  if ncol ==1, the number of model points in the horizontal grid
     53                        ! !   else    the number of GCM grid points
     54
     55  INTEGER :: nlev                      !  number of model vertical levels
     56
     57  INTEGER :: ncol                      !  number of model sub columns
     58                    ! !  (must already be generated in via scops and passed to this
     59                    ! !   routine via the variable frac_out )
     60
     61  INTEGER :: sunlit(npoints)           !  1 for day points, 0 for night time
     62
     63  REAL :: zfull(npoints,nlev)          !  height (in meters) of full model levels (i.e. midpoints)
     64                                    ! !  zfull(npoints,1)    is    top level of model
     65                                    ! !  zfull(npoints,nlev) is bottom level of model (closest point to surface)
     66
     67  REAL :: at(npoints,nlev)             !  temperature in each model level (K)
     68
     69  REAL :: dtau_s(npoints,nlev)         !  visible wavelength cloud optical depth ... for "stratiform" condensate
     70                                    ! !  NOTE:  this the cloud optical depth of only the
     71                ! !     the model cell (i,j)
     72
     73  REAL :: dtau_c(npoints,nlev)         !  visible wavelength cloud optical depth ... for "convective" condensate
     74                                    ! !  NOTE:  this the cloud optical depth of only the
     75                ! !     the model cell (i,j)
     76
     77  REAL :: frac_out(npoints,ncol,nlev)  !  NOTE: only need if columns>1 ... subgrid scheme in use.
     78
     79  REAL :: missing_value
     80
     81  ! ------
     82  ! Outputs
     83  ! ------
     84
     85  REAL :: fq_MISR_TAU_v_CTH(npoints,7,n_MISR_CTH)
     86  REAL :: dist_model_layertops(npoints,n_MISR_CTH)
     87  REAL :: MISR_cldarea(npoints)               ! fractional area coverged by clouds
     88  REAL :: MISR_mean_ztop(npoints)             ! mean cloud top hieght(m) MISR would observe
     89                               ! ! NOTE: == 0 if area ==0
     90
     91
     92  ! ------
     93  ! Working variables
     94  ! ------
     95
     96  REAL :: tau(npoints,ncol)        ! total column optical depth ...
     97
     98  INTEGER :: j,ilev,ilev2,ibox,k
     99  INTEGER :: itau
     100
     101  LOGICAL :: box_cloudy(npoints,ncol)
     102
     103  real :: isccp_taumin
     104  real :: boxarea
     105  real :: tauchk
     106  REAL :: box_MISR_ztop(npoints,ncol)  ! cloud top hieght(m) MISR would observe
     107
     108  integer :: thres_crossed_MISR
     109  integer :: loop,iMISR_ztop
     110
     111  real :: dtau, cloud_dtau, MISR_penetration_height,ztest
     112
     113  real :: MISR_CTH_boundaries(n_MISR_CTH+1)
     114
     115  DATA MISR_CTH_boundaries / -99, 0, 0.5, 1, 1.5, 2, 2.5, 3, &
     116        4, 5, 7, 9, 11, 13, 15, 17, 99 /
     117
     118  DATA isccp_taumin / 0.3 /
     119
     120  tauchk = -1.*log(0.9999999)
     121
     122  ! !
     123  ! ! For each GCM cell or horizontal model grid point ...
     124  ! !
     125  do j=1,npoints
     126
     127     ! !
     128     ! !  estimate distribution of Model layer tops
     129     ! !
     130     dist_model_layertops(j,:)=0
     131
     132   do ilev=1,nlev
     133
     134    ! ! define location of "layer top"
     135    if(ilev.eq.1 .or. ilev.eq.nlev) then
     136        ztest=zfull(j,ilev)
     137    else
     138        ztest=0.5*(zfull(j,ilev)+zfull(j,ilev-1))
     139    endif
     140
     141    ! ! find MISR layer that contains this level
     142    ! ! note, the first MISR level is "no height" level
     143    iMISR_ztop=2
     144    do loop=2,n_MISR_CTH
     145
     146        if ( ztest .gt. &
     147              1000*MISR_CTH_boundaries(loop+1) ) then
     148
     149            iMISR_ztop=loop+1
     150        endif
     151    enddo
     152
     153    dist_model_layertops(j,iMISR_ztop)= &
     154          dist_model_layertops(j,iMISR_ztop)+1
     155   enddo
     156
     157
     158     ! !
     159     ! ! compute total cloud optical depth for each column
     160     ! !
     161   do ibox=1,ncol
     162
     163    ! ! Initialize tau to zero in each subcolum
     164        tau(j,ibox)=0.
     165    box_cloudy(j,ibox)=.false.
     166    box_MISR_ztop(j,ibox)=0
     167
     168    ! ! initialize threshold detection for each sub column
     169    thres_crossed_MISR=0;
     170
     171    do ilev=1,nlev
     172
     173         dtau=0
     174
     175         if (frac_out(j,ibox,ilev).eq.1) then
     176                    dtau = dtau_s(j,ilev)
     177             endif
     178
     179             if (frac_out(j,ibox,ilev).eq.2) then
     180                    dtau = dtau_c(j,ilev)
     181             end if
     182
     183         tau(j,ibox)=tau(j,ibox)+ dtau
     184
     185
     186    ! ! NOW for MISR ..
     187    ! ! if there a cloud ... start the counter ... store this height
     188    if(thres_crossed_MISR .eq. 0 .and. dtau .gt. 0.) then
     189
     190        ! ! first encountered a "cloud"
     191        thres_crossed_MISR=1
     192        cloud_dtau=0
     193    endif
     194
     195    if( thres_crossed_MISR .lt. 99 .and. &
     196          thres_crossed_MISR .gt. 0 ) then
     197
     198            if( dtau .eq. 0.) then
     199
     200                ! ! we have come to the end of the current cloud
     201            ! ! layer without yet selecting a CTH boundary.
     202            ! ! ... restart cloud tau counter
     203            cloud_dtau=0
    137204        else
    138             ztest=0.5*(zfull(j,ilev)+zfull(j,ilev-1))
    139         endif   
    140 
    141         ! find MISR layer that contains this level
    142         ! note, the first MISR level is "no height" level
     205            ! ! add current optical depth to count for
     206            ! ! the current cloud layer
     207            cloud_dtau=cloud_dtau+dtau
     208        endif
     209
     210        ! ! if the cloud is continuous but optically thin (< 1)
     211        ! ! from above the current layer cloud top to the current level
     212        ! ! then MISR will like see a top below the top of the current
     213        ! ! layer
     214        if( dtau.gt.0 .and. (cloud_dtau-dtau) .lt. 1) then
     215
     216            if(dtau .lt. 1 .or. ilev.eq.1 .or. ilev.eq.nlev) then
     217
     218                ! ! MISR will likely penetrate to some point
     219                ! ! within this layer ... the middle
     220                MISR_penetration_height=zfull(j,ilev)
     221
     222            else
     223                ! ! take the OD = 1.0 level into this layer
     224                MISR_penetration_height= &
     225                      0.5*(zfull(j,ilev)+zfull(j,ilev-1)) - &
     226                      0.5*(zfull(j,ilev-1)-zfull(j,ilev+1)) &
     227                      /dtau
     228            endif
     229
     230            box_MISR_ztop(j,ibox)=MISR_penetration_height
     231
     232        endif
     233
     234        ! ! check for a distinctive water layer
     235        if(dtau .gt. 1 .and. at(j,ilev).gt.273 ) then
     236
     237                ! ! must be a water cloud ...
     238            ! ! take this as CTH level
     239            thres_crossed_MISR=99
     240        endif
     241
     242        ! ! if the total column optical depth is "large" than
     243        ! ! MISR can't seen anything else ... set current point as CTH level
     244        if(tau(j,ibox) .gt. 5) then
     245
     246            thres_crossed_MISR=99
     247        endif
     248
     249    endif ! MISR CTH booundary not set
     250
     251    enddo  !ilev - loop over vertical levesl
     252
     253    ! ! written by roj 5/2006
     254    ! ! check to see if there was a cloud for which we didn't
     255    ! ! set a MISR cloud top boundary
     256    if( thres_crossed_MISR .eq. 1) then
     257
     258    ! ! if the cloud has a total optical depth of greater
     259    ! ! than ~ 0.5 MISR will still likely pick up this cloud
     260    ! ! with a height near the true cloud top
     261    ! ! otherwise there should be no CTH
     262    if( tau(j,ibox) .gt. 0.5) then
     263
     264        ! ! keep MISR detected CTH
     265
     266    elseif(tau(j,ibox) .gt. 0.2) then
     267
     268        ! ! MISR may detect but wont likley have a good height
     269        box_MISR_ztop(j,ibox)=-1
     270
     271    else
     272        ! ! MISR not likely to even detect.
     273        ! ! so set as not cloudy
     274        box_MISR_ztop(j,ibox)=0
     275
     276    endif
     277
     278    endif
     279
     280   enddo  ! loop of subcolumns
     281   enddo    ! loop of gridpoints
     282
     283
     284    ! !
     285    ! !   Modify MISR CTH for satellite spatial / pattern matcher effects
     286  !   !
     287  !   !   Code in this region added by roj 5/2006 to account
     288  !   !   for spatial effect of the MISR pattern matcher.
     289  !   !   Basically, if a column is found between two neighbors
     290  !   !   at the same CTH, and that column has no hieght or
     291  !   !   a lower CTH, THEN misr will tend to but place the
     292  !   !   odd column at the same height as it neighbors.
     293  !   !
     294  !   !   This setup assumes the columns represent a about a 1 to 4 km scale
     295  !   !   it will need to be modified significantly, otherwise
     296    if(ncol.eq.1) then
     297
     298   ! ! adjust based on neightboring points ... i.e. only 2D grid was input
     299       do j=2,npoints-1
     300
     301        if(box_MISR_ztop(j-1,1).gt.0 .and. &
     302              box_MISR_ztop(j+1,1).gt.0       ) then
     303
     304            if( abs( box_MISR_ztop(j-1,1) - &
     305                  box_MISR_ztop(j+1,1) ) .lt. 500 &
     306                  .and. &
     307                  box_MISR_ztop(j,1) .lt. &
     308                  box_MISR_ztop(j+1,1)     ) then
     309
     310                box_MISR_ztop(j,1) = &
     311                      box_MISR_ztop(j+1,1)
     312            endif
     313
     314        endif
     315     enddo
     316    else
     317
     318     ! ! adjust based on neighboring subcolumns ....
     319     do ibox=2,ncol-1
     320
     321        if(box_MISR_ztop(1,ibox-1).gt.0 .and. &
     322              box_MISR_ztop(1,ibox+1).gt.0        ) then
     323
     324            if( abs( box_MISR_ztop(1,ibox-1) - &
     325                  box_MISR_ztop(1,ibox+1) ) .lt. 500 &
     326                  .and. &
     327                  box_MISR_ztop(1,ibox) .lt. &
     328                  box_MISR_ztop(1,ibox+1)     ) then
     329
     330                box_MISR_ztop(1,ibox) = &
     331                      box_MISR_ztop(1,ibox+1)
     332            endif
     333
     334        endif
     335     enddo
     336
     337    endif
     338
     339    ! !
     340  !   !     DETERMINE CLOUD TYPE FREQUENCIES
     341  !   !
     342  !   !     Now that ztop and tau have been determined,
     343  !   !     determine amount of each cloud type
     344    boxarea=1./real(ncol)
     345    do j=1,npoints
     346
     347     ! ! reset frequencies -- modified loop structure, roj 5/2006
     348     do ilev=1,7  ! "tau loop"
     349        do  ilev2=1,n_MISR_CTH
     350        fq_MISR_TAU_v_CTH(j,ilev,ilev2)=0.
     351        enddo
     352     enddo
     353
     354     MISR_cldarea(j)=0.
     355     MISR_mean_ztop(j)=0.
     356
     357     do ibox=1,ncol
     358
     359        if (tau(j,ibox) .gt. (tauchk)) then
     360           box_cloudy(j,ibox)=.true.
     361        endif
     362
     363        itau = 0
     364
     365        if (box_cloudy(j,ibox)) then
     366
     367      ! !determine optical depth category
     368          if (tau(j,ibox) .lt. isccp_taumin) then
     369              itau=1
     370          else if (tau(j,ibox) .ge. isccp_taumin &
     371                .and. tau(j,ibox) .lt. 1.3) then
     372              itau=2
     373          else if (tau(j,ibox) .ge. 1.3 &
     374                .and. tau(j,ibox) .lt. 3.6) then
     375              itau=3
     376          else if (tau(j,ibox) .ge. 3.6 &
     377                .and. tau(j,ibox) .lt. 9.4) then
     378              itau=4
     379          else if (tau(j,ibox) .ge. 9.4 &
     380                .and. tau(j,ibox) .lt. 23.) then
     381              itau=5
     382          else if (tau(j,ibox) .ge. 23. &
     383                .and. tau(j,ibox) .lt. 60.) then
     384              itau=6
     385          else if (tau(j,ibox) .ge. 60.) then
     386              itau=7
     387          endif
     388
     389         endif
     390
     391   ! ! update MISR histograms and summary metrics - roj 5/2005
     392   if (sunlit(j).eq.1) then
     393
     394          ! !if cloudy added by roj 5/2005
     395      if( box_MISR_ztop(j,ibox).eq.0) then
     396
     397        ! ! no cloud detected
     398        iMISR_ztop=0
     399
     400      elseif( box_MISR_ztop(j,ibox).eq.-1) then
     401
     402        ! ! cloud can be detected but too thin to get CTH
     403        iMISR_ztop=1
     404
     405        fq_MISR_TAU_v_CTH(j,itau,iMISR_ztop)= &
     406              fq_MISR_TAU_v_CTH(j,itau,iMISR_ztop) + boxarea
     407
     408      else
     409
     410        ! !
     411        ! ! determine index for MISR bin set
     412        ! !
     413
    143414        iMISR_ztop=2
     415
    144416        do loop=2,n_MISR_CTH
    145        
    146             if ( ztest .gt.
    147      &                1000*MISR_CTH_boundaries(loop+1) ) then
    148        
    149                 iMISR_ztop=loop+1
     417
     418            if ( box_MISR_ztop(j,ibox) .gt. &
     419                  1000*MISR_CTH_boundaries(loop+1) ) then
     420
     421              iMISR_ztop=loop+1
     422
    150423            endif
    151424        enddo
    152425
    153         dist_model_layertops(j,iMISR_ztop)=
    154      &          dist_model_layertops(j,iMISR_ztop)+1
    155        enddo
    156    
    157    
    158          !
    159          ! compute total cloud optical depth for each column
    160          !       
    161        do ibox=1,ncol     
    162        
    163         ! Initialize tau to zero in each subcolum
    164             tau(j,ibox)=0.
    165         box_cloudy(j,ibox)=.false.
    166         box_MISR_ztop(j,ibox)=0 
    167        
    168         ! initialize threshold detection for each sub column
    169         thres_crossed_MISR=0;
    170        
    171         do ilev=1,nlev
    172      
    173              dtau=0
    174              
    175              if (frac_out(j,ibox,ilev).eq.1) then
    176                         dtau = dtau_s(j,ilev)
    177                  endif
    178                  
    179                  if (frac_out(j,ibox,ilev).eq.2) then
    180                         dtau = dtau_c(j,ilev)
    181                  end if
    182                  
    183              tau(j,ibox)=tau(j,ibox)+ dtau
    184              
    185                      
    186         ! NOW for MISR ..
    187         ! if there a cloud ... start the counter ... store this height
    188         if(thres_crossed_MISR .eq. 0 .and. dtau .gt. 0.) then
    189        
    190             ! first encountered a "cloud"
    191             thres_crossed_MISR=1 
    192             cloud_dtau=0           
    193         endif   
    194                
    195         if( thres_crossed_MISR .lt. 99 .and.
    196      &              thres_crossed_MISR .gt. 0 ) then
    197      
    198                 if( dtau .eq. 0.) then
    199        
    200                     ! we have come to the end of the current cloud
    201                 ! layer without yet selecting a CTH boundary.
    202                 ! ... restart cloud tau counter
    203                 cloud_dtau=0
    204             else
    205                 ! add current optical depth to count for
    206                 ! the current cloud layer
    207                 cloud_dtau=cloud_dtau+dtau
    208             endif
    209                
    210             ! if the cloud is continuous but optically thin (< 1)
    211             ! from above the current layer cloud top to the current level
    212             ! then MISR will like see a top below the top of the current
    213             ! layer
    214             if( dtau.gt.0 .and. (cloud_dtau-dtau) .lt. 1) then
    215            
    216                 if(dtau .lt. 1 .or. ilev.eq.1 .or. ilev.eq.nlev) then
    217 
    218                     ! MISR will likely penetrate to some point
    219                     ! within this layer ... the middle
    220                     MISR_penetration_height=zfull(j,ilev)
    221 
    222                 else
    223                     ! take the OD = 1.0 level into this layer
    224                     MISR_penetration_height=
    225      &                     0.5*(zfull(j,ilev)+zfull(j,ilev-1)) -
    226      &                     0.5*(zfull(j,ilev-1)-zfull(j,ilev+1))
    227      &                  /dtau
    228                 endif   
    229 
    230                 box_MISR_ztop(j,ibox)=MISR_penetration_height
    231                
    232             endif
    233        
    234             ! check for a distinctive water layer
    235             if(dtau .gt. 1 .and. at(j,ilev).gt.273 ) then
    236      
    237                     ! must be a water cloud ...
    238                 ! take this as CTH level
    239                 thres_crossed_MISR=99
    240             endif
    241        
    242             ! if the total column optical depth is "large" than
    243             ! MISR can't seen anything else ... set current point as CTH level
    244             if(tau(j,ibox) .gt. 5) then
    245 
    246                 thres_crossed_MISR=99           
    247             endif
    248 
    249         endif ! MISR CTH booundary not set
    250        
    251         enddo  !ilev - loop over vertical levesl
    252    
    253         ! written by roj 5/2006
    254         ! check to see if there was a cloud for which we didn't
    255         ! set a MISR cloud top boundary
    256         if( thres_crossed_MISR .eq. 1) then
    257    
    258         ! if the cloud has a total optical depth of greater
    259         ! than ~ 0.5 MISR will still likely pick up this cloud
    260         ! with a height near the true cloud top
    261         ! otherwise there should be no CTH
    262         if( tau(j,ibox) .gt. 0.5) then
    263 
    264             ! keep MISR detected CTH
    265            
    266         elseif(tau(j,ibox) .gt. 0.2) then
    267 
    268             ! MISR may detect but wont likley have a good height
    269             box_MISR_ztop(j,ibox)=-1
    270            
     426        if(box_cloudy(j,ibox)) then
     427
     428           ! ! there is an isccp clouds so itau(j) is defined
     429           fq_MISR_TAU_v_CTH(j,itau,iMISR_ztop)= &
     430                 fq_MISR_TAU_v_CTH(j,itau,iMISR_ztop) + boxarea
     431
    271432        else
    272             ! MISR not likely to even detect.
    273             ! so set as not cloudy
    274             box_MISR_ztop(j,ibox)=0
    275 
    276         endif
    277                        
    278         endif
    279    
    280        enddo  ! loop of subcolumns
    281        enddo    ! loop of gridpoints
    282        
    283 
    284         !     
    285         !   Modify MISR CTH for satellite spatial / pattern matcher effects
    286     !
    287     !   Code in this region added by roj 5/2006 to account
    288     !   for spatial effect of the MISR pattern matcher.
    289     !   Basically, if a column is found between two neighbors
    290     !   at the same CTH, and that column has no hieght or
    291     !   a lower CTH, THEN misr will tend to but place the
    292     !   odd column at the same height as it neighbors.
    293     !
    294     !   This setup assumes the columns represent a about a 1 to 4 km scale
    295     !   it will need to be modified significantly, otherwise
    296         if(ncol.eq.1) then
    297    
    298        ! adjust based on neightboring points ... i.e. only 2D grid was input
    299            do j=2,npoints-1
    300            
    301             if(box_MISR_ztop(j-1,1).gt.0 .and.
    302      &             box_MISR_ztop(j+1,1).gt.0       ) then
    303 
    304                 if( abs( box_MISR_ztop(j-1,1) - 
    305      &                   box_MISR_ztop(j+1,1) ) .lt. 500
    306      &              .and.
    307      &                   box_MISR_ztop(j,1) .lt.
    308      &                   box_MISR_ztop(j+1,1)     ) then
    309            
    310                     box_MISR_ztop(j,1) =
    311      &                      box_MISR_ztop(j+1,1)   
    312                 endif
    313 
    314             endif
     433            ! ! MISR CTH resolution is trying to fill in a
     434            ! ! broken cloud scene where there is no condensate.
     435            ! ! The MISR CTH-1D-OD product will only put in a cloud
     436            ! ! if the MISR cloud mask indicates cloud.
     437            ! ! therefore we will not include this column in the histogram
     438            ! ! in reality aerosoal and 3D effects or bright surfaces
     439            ! ! could fool the MISR cloud mask
     440
     441            ! ! the alternative is to count as very thin cloud ??
     442            ! fq_MISR_TAU_v_CTH(1,iMISR_ztop)=
     443  ! &                     fq_MISR_TAU_v_CTH(1,iMISR_ztop) + boxarea
     444        endif
     445
     446
     447        MISR_mean_ztop(j)=MISR_mean_ztop(j)+ &
     448              box_MISR_ztop(j,ibox)*boxarea
     449
     450        MISR_cldarea(j)=MISR_cldarea(j) + boxarea
     451
     452      endif
     453   else
     454      ! ! Set to issing data. A. Bodas - 14/05/2010
     455      do loop=1,n_MISR_CTH
     456         do k=1,7
     457            fq_MISR_TAU_v_CTH(j,k,loop) = missing_value
    315458         enddo
    316         else
    317          
    318          ! adjust based on neighboring subcolumns ....
    319          do ibox=2,ncol-1
    320            
    321             if(box_MISR_ztop(1,ibox-1).gt.0 .and.
    322      &             box_MISR_ztop(1,ibox+1).gt.0        ) then
    323 
    324                 if( abs( box_MISR_ztop(1,ibox-1) - 
    325      &                   box_MISR_ztop(1,ibox+1) ) .lt. 500
    326      &              .and.
    327      &                   box_MISR_ztop(1,ibox) .lt.
    328      &                   box_MISR_ztop(1,ibox+1)     ) then
    329            
    330                     box_MISR_ztop(1,ibox) =
    331      &                      box_MISR_ztop(1,ibox+1)   
    332                 endif
    333 
    334             endif
    335          enddo
    336      
    337         endif
    338 
    339         !     
    340     !     DETERMINE CLOUD TYPE FREQUENCIES
    341     !
    342     !     Now that ztop and tau have been determined,
    343     !     determine amount of each cloud type
    344         boxarea=1./real(ncol) 
    345         do j=1,npoints
    346 
    347          ! reset frequencies -- modified loop structure, roj 5/2006
    348          do ilev=1,7  ! "tau loop" 
    349             do  ilev2=1,n_MISR_CTH                     
    350             fq_MISR_TAU_v_CTH(j,ilev,ilev2)=0.     
    351             enddo
    352          enddo
    353            
    354          MISR_cldarea(j)=0.
    355          MISR_mean_ztop(j)=0.
    356 
    357          do ibox=1,ncol
    358 
    359             if (tau(j,ibox) .gt. (tauchk)) then
    360                box_cloudy(j,ibox)=.true.
    361             endif
    362  
    363             itau = 0
    364        
    365             if (box_cloudy(j,ibox)) then
    366    
    367           !determine optical depth category
    368               if (tau(j,ibox) .lt. isccp_taumin) then
    369                   itau=1
    370               else if (tau(j,ibox) .ge. isccp_taumin                                   
    371      &          .and. tau(j,ibox) .lt. 1.3) then
    372                   itau=2
    373               else if (tau(j,ibox) .ge. 1.3
    374      &          .and. tau(j,ibox) .lt. 3.6) then
    375                   itau=3
    376               else if (tau(j,ibox) .ge. 3.6
    377      &          .and. tau(j,ibox) .lt. 9.4) then
    378                   itau=4
    379               else if (tau(j,ibox) .ge. 9.4
    380      &          .and. tau(j,ibox) .lt. 23.) then
    381                   itau=5
    382               else if (tau(j,ibox) .ge. 23.
    383      &          .and. tau(j,ibox) .lt. 60.) then
    384                   itau=6
    385               else if (tau(j,ibox) .ge. 60.) then
    386                   itau=7
    387               endif
    388              
    389              endif 
    390 
    391        ! update MISR histograms and summary metrics - roj 5/2005
    392        if (sunlit(j).eq.1) then
    393                      
    394               !if cloudy added by roj 5/2005
    395           if( box_MISR_ztop(j,ibox).eq.0) then
    396          
    397             ! no cloud detected
    398             iMISR_ztop=0
    399 
    400           elseif( box_MISR_ztop(j,ibox).eq.-1) then
    401 
    402             ! cloud can be detected but too thin to get CTH
    403             iMISR_ztop=1   
    404 
    405             fq_MISR_TAU_v_CTH(j,itau,iMISR_ztop)=
    406      &            fq_MISR_TAU_v_CTH(j,itau,iMISR_ztop) + boxarea
    407 
    408           else
    409            
    410             !
    411             ! determine index for MISR bin set
    412             !
    413 
    414             iMISR_ztop=2
    415            
    416             do loop=2,n_MISR_CTH
    417        
    418                 if ( box_MISR_ztop(j,ibox) .gt.
    419      &                1000*MISR_CTH_boundaries(loop+1) ) then
    420        
    421                   iMISR_ztop=loop+1
    422 
    423                 endif
    424             enddo
    425          
    426             if(box_cloudy(j,ibox)) then
    427            
    428                ! there is an isccp clouds so itau(j) is defined
    429                fq_MISR_TAU_v_CTH(j,itau,iMISR_ztop)=
    430      &            fq_MISR_TAU_v_CTH(j,itau,iMISR_ztop) + boxarea
    431      
    432             else
    433                 ! MISR CTH resolution is trying to fill in a
    434                 ! broken cloud scene where there is no condensate.
    435                 ! The MISR CTH-1D-OD product will only put in a cloud
    436                 ! if the MISR cloud mask indicates cloud.
    437                 ! therefore we will not include this column in the histogram
    438                 ! in reality aerosoal and 3D effects or bright surfaces
    439                 ! could fool the MISR cloud mask
    440 
    441                 ! the alternative is to count as very thin cloud ??
    442 !               fq_MISR_TAU_v_CTH(1,iMISR_ztop)=
    443 !     &                     fq_MISR_TAU_v_CTH(1,iMISR_ztop) + boxarea
    444             endif
    445 
    446 
    447             MISR_mean_ztop(j)=MISR_mean_ztop(j)+
    448      &                       box_MISR_ztop(j,ibox)*boxarea         
    449 
    450             MISR_cldarea(j)=MISR_cldarea(j) + boxarea
    451  
    452           endif
    453        else
    454           ! Set to issing data. A. Bodas - 14/05/2010
    455           do loop=1,n_MISR_CTH
    456              do k=1,7
    457                 fq_MISR_TAU_v_CTH(j,k,loop) = missing_value
    458              enddo
    459              dist_model_layertops(j,loop) = missing_value
    460           enddo
    461           MISR_cldarea(j) = missing_value
    462           MISR_mean_ztop(npoints) = missing_value
    463 
    464        endif ! is sunlight ?
    465        
    466        enddo ! ibox - loop over subcolumns         
    467      
    468        if( MISR_cldarea(j) .gt. 0.) then
    469         MISR_mean_ztop(j)= MISR_mean_ztop(j) / MISR_cldarea(j)   ! roj 5/2006
    470        endif
    471 
    472        enddo  ! loop over grid points
    473 
    474       return
    475       end
     459         dist_model_layertops(j,loop) = missing_value
     460      enddo
     461      MISR_cldarea(j) = missing_value
     462      MISR_mean_ztop(npoints) = missing_value
     463
     464   endif ! is sunlight ?
     465
     466   enddo ! ibox - loop over subcolumns
     467
     468   if( MISR_cldarea(j) .gt. 0.) then
     469    MISR_mean_ztop(j)= MISR_mean_ztop(j) / MISR_cldarea(j)   ! roj 5/2006
     470   endif
     471
     472   enddo  ! loop over grid points
     473
     474  return
     475end subroutine misr_simulator
  • LMDZ6/trunk/libf/phylmd/cosp/icarus.f90

    r5247 r5248  
    11! $Revision: 88 $, $Date: 2013-11-13 15:08:38 +0100 (mer. 13 nov. 2013) $
    22! $URL: http://cfmip-obs-sim.googlecode.com/svn/stable/v1.4.0/icarus-scops-4.1-bsd/icarus.f $
    3       SUBROUTINE ICARUS(
    4      &     debug,
    5      &     debugcol,
    6      &     npoints,
    7      &     sunlit,
    8      &     nlev,
    9      &     ncol,
    10      &     pfull,
    11      &     phalf,
    12      &     qv,
    13      &     cc,
    14      &     conv,
    15      &     dtau_s,
    16      &     dtau_c,
    17      &     top_height,
    18      &     top_height_direction,
    19      &     overlap,
    20      &     frac_out,
    21      &     skt,
    22      &     emsfc_lw,
    23      &     at,
    24      &     dem_s,
    25      &     dem_c,
    26      &     fq_isccp,
    27      &     totalcldarea,
    28      &     meanptop,
    29      &     meantaucld,
    30      &     meanalbedocld,
    31      &     meantb,
    32      &     meantbclr,
    33      &     boxtau,
    34      &     boxptop
    35      &)
    36 
    37 !$Id: icarus.f,v 4.1 2010/05/27 16:30:18 hadmw Exp $
    38 
    39 ! *****************************COPYRIGHT****************************
    40 ! (c) 2009, Lawrence Livermore National Security Limited Liability
    41 ! Corporation.
    42 ! All rights reserved.
    43 !
    44 ! Redistribution and use in source and binary forms, with or without
    45 ! modification, are permitted provided that the
    46 ! following conditions are met:
    47 !
    48 !     * Redistributions of source code must retain the above
    49 !       copyright  notice, this list of conditions and the following
    50 !       disclaimer.
    51 !     * Redistributions in binary form must reproduce the above
    52 !       copyright notice, this list of conditions and the following
    53 !       disclaimer in the documentation and/or other materials
    54 !       provided with the distribution.
    55 !     * Neither the name of the Lawrence Livermore National Security
    56 !       Limited Liability Corporation nor the names of its
    57 !       contributors may be used to endorse or promote products
    58 !       derived from this software without specific prior written
    59 !       permission.
    60 !
    61 ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    62 ! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    63 ! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    64 ! A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    65 ! OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    66 ! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    67 ! LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    68 ! DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    69 ! THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    70 ! (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    71 ! OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
    72 !
    73 ! *****************************COPYRIGHT*******************************
    74 ! *****************************COPYRIGHT*******************************
    75 ! *****************************COPYRIGHT*******************************
    76 ! *****************************COPYRIGHT*******************************
    77 
    78       implicit none
    79 
    80 !     NOTE:   the maximum number of levels and columns is set by
    81 !             the following parameter statement
    82 
    83       INTEGER ncolprint
    84      
    85 !     -----
    86 !     Input
    87 !     -----
    88 
    89       INTEGER npoints       !  number of model points in the horizontal
    90       INTEGER nlev          !  number of model levels in column
    91       INTEGER ncol          !  number of subcolumns
    92 
    93       INTEGER sunlit(npoints) !  1 for day points, 0 for night time
    94 
    95       REAL pfull(npoints,nlev)
    96                        !  pressure of full model levels (Pascals)
    97                   !  pfull(npoints,1) is top level of model
    98                   !  pfull(npoints,nlev) is bot of model
    99 
    100       REAL phalf(npoints,nlev+1)
    101                   !  pressure of half model levels (Pascals)
    102                   !  phalf(npoints,1) is top of model
    103                   !  phalf(npoints,nlev+1) is the surface pressure
    104 
    105       REAL qv(npoints,nlev)
    106                   !  water vapor specific humidity (kg vapor/ kg air)
    107                   !         on full model levels
    108 
    109       REAL cc(npoints,nlev)   
    110                   !  input cloud cover in each model level (fraction)
    111                   !  NOTE:  This is the HORIZONTAL area of each
    112                   !         grid box covered by clouds
    113 
    114       REAL conv(npoints,nlev)
    115                   !  input convective cloud cover in each model
    116                   !   level (fraction)
    117                   !  NOTE:  This is the HORIZONTAL area of each
    118                   !         grid box covered by convective clouds
    119 
    120       REAL dtau_s(npoints,nlev)
    121                   !  mean 0.67 micron optical depth of stratiform
    122                 !  clouds in each model level
    123                   !  NOTE:  this the cloud optical depth of only the
    124                   !  cloudy part of the grid box, it is not weighted
    125                   !  with the 0 cloud optical depth of the clear
    126                   !         part of the grid box
    127 
    128       REAL dtau_c(npoints,nlev)
    129                   !  mean 0.67 micron optical depth of convective
    130                 !  clouds in each
    131                   !  model level.  Same note applies as in dtau_s.
    132 
    133       INTEGER overlap                   !  overlap type
    134                               !  1=max
    135                               !  2=rand
    136                               !  3=max/rand
    137 
    138       INTEGER top_height                !  1 = adjust top height using both a computed
    139                                         !  infrared brightness temperature and the visible
    140                               !  optical depth to adjust cloud top pressure. Note
    141                               !  that this calculation is most appropriate to compare
    142                               !  to ISCCP data during sunlit hours.
    143                                         !  2 = do not adjust top height, that is cloud top
    144                                         !  pressure is the actual cloud top pressure
    145                                         !  in the model
    146                               !  3 = adjust top height using only the computed
    147                               !  infrared brightness temperature. Note that this
    148                               !  calculation is most appropriate to compare to ISCCP
    149                               !  IR only algortihm (i.e. you can compare to nighttime
    150                               !  ISCCP data with this option)
    151 
    152       INTEGER top_height_direction ! direction for finding atmosphere pressure level
    153                                  ! with interpolated temperature equal to the radiance
    154                                  ! determined cloud-top temperature
    155                                  !
    156                                  ! 1 = find the *lowest* altitude (highest pressure) level
    157                                  ! with interpolated temperature equal to the radiance
    158                                  ! determined cloud-top temperature
    159                                  !
    160                                  ! 2 = find the *highest* altitude (lowest pressure) level
    161                                  ! with interpolated temperature equal to the radiance
    162                                  ! determined cloud-top temperature
    163                                  !
    164                                  ! ONLY APPLICABLE IF top_height EQUALS 1 or 3
    165                                  !                               !
    166                                  ! 1 = old setting: matches all versions of
    167                                  ! ISCCP simulator with versions numbers 3.5.1 and lower
    168                                  !
    169                                  ! 2 = default setting: for version numbers 4.0 and higher
    170 !
    171 !     The following input variables are used only if top_height = 1 or top_height = 3
    172 !
    173       REAL skt(npoints)                 !  skin Temperature (K)
    174       REAL emsfc_lw                     !  10.5 micron emissivity of surface (fraction)                                           
    175       REAL at(npoints,nlev)                   !  temperature in each model level (K)
    176       REAL dem_s(npoints,nlev)                !  10.5 micron longwave emissivity of stratiform
    177                               !  clouds in each
    178                                         !  model level.  Same note applies as in dtau_s.
    179       REAL dem_c(npoints,nlev)                  !  10.5 micron longwave emissivity of convective
    180                               !  clouds in each
    181                                         !  model level.  Same note applies as in dtau_s.
    182 
    183       REAL frac_out(npoints,ncol,nlev) ! boxes gridbox divided up into
    184                               ! Equivalent of BOX in original version, but
    185                               ! indexed by column then row, rather than
    186                               ! by row then column
    187 
    188 
    189 
    190 !     ------
    191 !     Output
    192 !     ------
    193 
    194       REAL fq_isccp(npoints,7,7)        !  the fraction of the model grid box covered by
    195                                         !  each of the 49 ISCCP D level cloud types
    196 
    197       REAL totalcldarea(npoints)        !  the fraction of model grid box columns
    198                                         !  with cloud somewhere in them.  NOTE: This diagnostic
    199                                         ! does not count model clouds with tau < isccp_taumin
    200                               ! Thus this diagnostic does not equal the sum over all entries of fq_isccp.
    201                               ! However, this diagnostic does equal the sum over entries of fq_isccp with
    202                               ! itau = 2:7 (omitting itau = 1)
    203      
    204      
    205       ! The following three means are averages only over the cloudy areas with tau > isccp_taumin. 
    206       ! If no clouds with tau > isccp_taumin are in grid box all three quantities should equal zero.     
    207                              
    208       REAL meanptop(npoints)            !  mean cloud top pressure (mb) - linear averaging
    209                                         !  in cloud top pressure.
    210                              
    211       REAL meantaucld(npoints)          !  mean optical thickness
    212                                         !  linear averaging in albedo performed.
    213      
    214       real meanalbedocld(npoints)        ! mean cloud albedo
    215                                         ! linear averaging in albedo performed
    216                                        
    217       real meantb(npoints)              ! mean all-sky 10.5 micron brightness temperature
    218      
    219       real meantbclr(npoints)           ! mean clear-sky 10.5 micron brightness temperature
    220      
    221       REAL boxtau(npoints,ncol)         !  optical thickness in each column
    222      
    223       REAL boxptop(npoints,ncol)        !  cloud top pressure (mb) in each column
    224                              
    225                                                                                          
    226 !
    227 !     ------
    228 !     Working variables added when program updated to mimic Mark Webb's PV-Wave code
    229 !     ------
    230 
    231       REAL dem(npoints,ncol),bb(npoints)     !  working variables for 10.5 micron longwave
    232                               !  emissivity in part of
    233                               !  gridbox under consideration
    234 
    235       REAL ptrop(npoints)
    236       REAL attrop(npoints)
    237       REAL attropmin (npoints)
    238       REAL atmax(npoints)
    239       REAL btcmin(npoints)
    240       REAL transmax(npoints)
    241 
    242       INTEGER i,j,ilev,ibox,itrop(npoints)
    243       INTEGER ipres(npoints)
    244       INTEGER itau(npoints),ilev2
    245       INTEGER acc(nlev,ncol)
    246       INTEGER match(npoints,nlev-1)
    247       INTEGER nmatch(npoints)
    248       INTEGER levmatch(npoints,ncol)
    249      
    250       !variables needed for water vapor continuum absorption
    251       real fluxtop_clrsky(npoints),trans_layers_above_clrsky(npoints)
    252       real taumin(npoints)
    253       real dem_wv(npoints,nlev), wtmair, wtmh20, Navo, grav, pstd, t0
    254       real press(npoints), dpress(npoints), atmden(npoints)
    255       real rvh20(npoints), wk(npoints), rhoave(npoints)
    256       real rh20s(npoints), rfrgn(npoints)
    257       real tmpexp(npoints),tauwv(npoints)
    258      
    259       character*1 cchar(6),cchar_realtops(6)
    260       integer icycle
    261       REAL tau(npoints,ncol)
    262       LOGICAL box_cloudy(npoints,ncol)
    263       REAL tb(npoints,ncol)
    264       REAL ptop(npoints,ncol)
    265       REAL emcld(npoints,ncol)
    266       REAL fluxtop(npoints,ncol)
    267       REAL trans_layers_above(npoints,ncol)
    268       real isccp_taumin,fluxtopinit(npoints),tauir(npoints)
    269       REAL albedocld(npoints,ncol)
    270       real boxarea
    271       integer debug       ! set to non-zero value to print out inputs
    272                     ! with step debug
    273       integer debugcol    ! set to non-zero value to print out column
    274                     ! decomposition with step debugcol
    275       integer rangevec(npoints),rangeerror
    276 
    277       integer index1(npoints),num1,jj,k1,k2
    278       real rec2p13,tauchk,logp,logp1,logp2,atd
    279       real output_missing_value
    280 
    281       character*10 ftn09
    282      
    283       DATA isccp_taumin / 0.3 /
    284       DATA output_missing_value / -1.E+30 /
    285       DATA cchar / ' ','-','1','+','I','+'/
    286       DATA cchar_realtops / ' ',' ','1','1','I','I'/
    287 
    288 !     ------ End duplicate definitions common to wrapper routine
    289 
    290       tauchk = -1.*log(0.9999999)
    291       rec2p13=1./2.13
    292 
    293       ncolprint=0
    294 
    295       if ( debug.ne.0 ) then
    296           j=1
     3SUBROUTINE ICARUS( &
     4        debug, &
     5        debugcol, &
     6        npoints, &
     7        sunlit, &
     8        nlev, &
     9        ncol, &
     10        pfull, &
     11        phalf, &
     12        qv, &
     13        cc, &
     14        conv, &
     15        dtau_s, &
     16        dtau_c, &
     17        top_height, &
     18        top_height_direction, &
     19        overlap, &
     20        frac_out, &
     21        skt, &
     22        emsfc_lw, &
     23        at, &
     24        dem_s, &
     25        dem_c, &
     26        fq_isccp, &
     27        totalcldarea, &
     28        meanptop, &
     29        meantaucld, &
     30        meanalbedocld, &
     31        meantb, &
     32        meantbclr, &
     33        boxtau, &
     34        boxptop &
     35        )
     36
     37  !$Id: icarus.f,v 4.1 2010/05/27 16:30:18 hadmw Exp $
     38
     39  ! *****************************COPYRIGHT****************************
     40  ! (c) 2009, Lawrence Livermore National Security Limited Liability
     41  ! Corporation.
     42  ! All rights reserved.
     43  !
     44  ! Redistribution and use in source and binary forms, with or without
     45  ! modification, are permitted provided that the
     46  ! following conditions are met:
     47  !
     48  ! * Redistributions of source code must retain the above
     49  !   copyright  notice, this list of conditions and the following
     50  !   disclaimer.
     51  ! * Redistributions in binary form must reproduce the above
     52  !   copyright notice, this list of conditions and the following
     53  !   disclaimer in the documentation and/or other materials
     54  !   provided with the distribution.
     55  ! * Neither the name of the Lawrence Livermore National Security
     56  !   Limited Liability Corporation nor the names of its
     57  !   contributors may be used to endorse or promote products
     58  !   derived from this software without specific prior written
     59  !   permission.
     60  !
     61  ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     62  ! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     63  ! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     64  ! A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     65  ! OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     66  ! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     67  ! LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     68  ! DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     69  ! THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     70  ! (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     71  ! OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     72  !
     73  ! *****************************COPYRIGHT*******************************
     74  ! *****************************COPYRIGHT*******************************
     75  ! *****************************COPYRIGHT*******************************
     76  ! *****************************COPYRIGHT*******************************
     77
     78  implicit none
     79
     80  ! NOTE:   the maximum number of levels and columns is set by
     81  !         the following parameter statement
     82
     83  INTEGER :: ncolprint
     84
     85  ! -----
     86  ! Input
     87  ! -----
     88
     89  INTEGER :: npoints       !  number of model points in the horizontal
     90  INTEGER :: nlev          !  number of model levels in column
     91  INTEGER :: ncol          !  number of subcolumns
     92
     93  INTEGER :: sunlit(npoints) !  1 for day points, 0 for night time
     94
     95  REAL :: pfull(npoints,nlev)
     96                   ! !  pressure of full model levels (Pascals)
     97              ! !  pfull(npoints,1) is top level of model
     98              ! !  pfull(npoints,nlev) is bot of model
     99
     100  REAL :: phalf(npoints,nlev+1)
     101              ! !  pressure of half model levels (Pascals)
     102              ! !  phalf(npoints,1) is top of model
     103              ! !  phalf(npoints,nlev+1) is the surface pressure
     104
     105  REAL :: qv(npoints,nlev)
     106              ! !  water vapor specific humidity (kg vapor/ kg air)
     107              ! !         on full model levels
     108
     109  REAL :: cc(npoints,nlev)
     110              ! !  input cloud cover in each model level (fraction)
     111              ! !  NOTE:  This is the HORIZONTAL area of each
     112              ! !         grid box covered by clouds
     113
     114  REAL :: conv(npoints,nlev)
     115              ! !  input convective cloud cover in each model
     116              ! !   level (fraction)
     117              ! !  NOTE:  This is the HORIZONTAL area of each
     118              ! !         grid box covered by convective clouds
     119
     120  REAL :: dtau_s(npoints,nlev)
     121              ! !  mean 0.67 micron optical depth of stratiform
     122            ! !  clouds in each model level
     123            !   !  NOTE:  this the cloud optical depth of only the
     124            !   !  cloudy part of the grid box, it is not weighted
     125            !   !  with the 0 cloud optical depth of the clear
     126            !   !         part of the grid box
     127
     128  REAL :: dtau_c(npoints,nlev)
     129              ! !  mean 0.67 micron optical depth of convective
     130            ! !  clouds in each
     131            !   !  model level.  Same note applies as in dtau_s.
     132
     133  INTEGER :: overlap                   !  overlap type
     134                          ! !  1=max
     135                          ! !  2=rand
     136                          ! !  3=max/rand
     137
     138  INTEGER :: top_height                !  1 = adjust top height using both a computed
     139                                    ! !  infrared brightness temperature and the visible
     140                          ! !  optical depth to adjust cloud top pressure. Note
     141                          ! !  that this calculation is most appropriate to compare
     142                          ! !  to ISCCP data during sunlit hours.
     143                          !           !  2 = do not adjust top height, that is cloud top
     144                          !           !  pressure is the actual cloud top pressure
     145                          !           !  in the model
     146                          ! !  3 = adjust top height using only the computed
     147                          ! !  infrared brightness temperature. Note that this
     148                          ! !  calculation is most appropriate to compare to ISCCP
     149                          ! !  IR only algortihm (i.e. you can compare to nighttime
     150                          ! !  ISCCP data with this option)
     151
     152  INTEGER :: top_height_direction ! direction for finding atmosphere pressure level
     153                             ! ! with interpolated temperature equal to the radiance
     154                             ! determined cloud-top temperature
     155                             !
     156                             ! 1 = find the *lowest* altitude (highest pressure) level
     157                             ! with interpolated temperature equal to the radiance
     158                             ! determined cloud-top temperature
     159                             !
     160                             ! 2 = find the *highest* altitude (lowest pressure) level
     161                             ! with interpolated temperature equal to the radiance
     162                             ! determined cloud-top temperature
     163                             !
     164                             ! ONLY APPLICABLE IF top_height EQUALS 1 or 3
     165                             !                           !
     166                             ! 1 = old setting: matches all versions of
     167                             ! ISCCP simulator with versions numbers 3.5.1 and lower
     168                             !
     169                             ! 2 = default setting: for version numbers 4.0 and higher
     170  !
     171  ! The following input variables are used only if top_height = 1 or top_height = 3
     172  !
     173  REAL :: skt(npoints)                 !  skin Temperature (K)
     174  REAL :: emsfc_lw                     !  10.5 micron emissivity of surface (fraction)
     175  REAL :: at(npoints,nlev)                   !  temperature in each model level (K)
     176  REAL :: dem_s(npoints,nlev)                !  10.5 micron longwave emissivity of stratiform
     177                          ! !  clouds in each
     178                          !           !  model level.  Same note applies as in dtau_s.
     179  REAL :: dem_c(npoints,nlev)                  !  10.5 micron longwave emissivity of convective
     180                          ! !  clouds in each
     181                          !           !  model level.  Same note applies as in dtau_s.
     182
     183  REAL :: frac_out(npoints,ncol,nlev) ! boxes gridbox divided up into
     184                          ! ! Equivalent of BOX in original version, but
     185                          ! ! indexed by column then row, rather than
     186                          ! ! by row then column
     187
     188
     189
     190  ! ------
     191  ! Output
     192  ! ------
     193
     194  REAL :: fq_isccp(npoints,7,7)        !  the fraction of the model grid box covered by
     195                                    ! !  each of the 49 ISCCP D level cloud types
     196
     197  REAL :: totalcldarea(npoints)        !  the fraction of model grid box columns
     198                                    ! !  with cloud somewhere in them.  NOTE: This diagnostic
     199                                    ! does not count model clouds with tau < isccp_taumin
     200                          ! ! Thus this diagnostic does not equal the sum over all entries of fq_isccp.
     201                          ! However, this diagnostic does equal the sum over entries of fq_isccp with
     202                          ! itau = 2:7 (omitting itau = 1)
     203
     204
     205  ! ! The following three means are averages only over the cloudy areas with tau > isccp_taumin.
     206  ! ! If no clouds with tau > isccp_taumin are in grid box all three quantities should equal zero.
     207
     208  REAL :: meanptop(npoints)            !  mean cloud top pressure (mb) - linear averaging
     209                                    ! !  in cloud top pressure.
     210
     211  REAL :: meantaucld(npoints)          !  mean optical thickness
     212                                    ! !  linear averaging in albedo performed.
     213
     214  real :: meanalbedocld(npoints)        ! mean cloud albedo
     215                                    ! ! linear averaging in albedo performed
     216
     217  real :: meantb(npoints)              ! mean all-sky 10.5 micron brightness temperature
     218
     219  real :: meantbclr(npoints)           ! mean clear-sky 10.5 micron brightness temperature
     220
     221  REAL :: boxtau(npoints,ncol)         !  optical thickness in each column
     222
     223  REAL :: boxptop(npoints,ncol)        !  cloud top pressure (mb) in each column
     224
     225
     226  !
     227  ! ------
     228  ! Working variables added when program updated to mimic Mark Webb's PV-Wave code
     229  ! ------
     230
     231  REAL :: dem(npoints,ncol),bb(npoints)     !  working variables for 10.5 micron longwave
     232                          ! !  emissivity in part of
     233                          ! !  gridbox under consideration
     234
     235  REAL :: ptrop(npoints)
     236  REAL :: attrop(npoints)
     237  REAL :: attropmin (npoints)
     238  REAL :: atmax(npoints)
     239  REAL :: btcmin(npoints)
     240  REAL :: transmax(npoints)
     241
     242  INTEGER :: i,j,ilev,ibox,itrop(npoints)
     243  INTEGER :: ipres(npoints)
     244  INTEGER :: itau(npoints),ilev2
     245  INTEGER :: acc(nlev,ncol)
     246  INTEGER :: match(npoints,nlev-1)
     247  INTEGER :: nmatch(npoints)
     248  INTEGER :: levmatch(npoints,ncol)
     249
     250  ! !variables needed for water vapor continuum absorption
     251  real :: fluxtop_clrsky(npoints),trans_layers_above_clrsky(npoints)
     252  real :: taumin(npoints)
     253  real :: dem_wv(npoints,nlev), wtmair, wtmh20, Navo, grav, pstd, t0
     254  real :: press(npoints), dpress(npoints), atmden(npoints)
     255  real :: rvh20(npoints), wk(npoints), rhoave(npoints)
     256  real :: rh20s(npoints), rfrgn(npoints)
     257  real :: tmpexp(npoints),tauwv(npoints)
     258
     259  character(len=1) :: cchar(6),cchar_realtops(6)
     260  integer :: icycle
     261  REAL :: tau(npoints,ncol)
     262  LOGICAL :: box_cloudy(npoints,ncol)
     263  REAL :: tb(npoints,ncol)
     264  REAL :: ptop(npoints,ncol)
     265  REAL :: emcld(npoints,ncol)
     266  REAL :: fluxtop(npoints,ncol)
     267  REAL :: trans_layers_above(npoints,ncol)
     268  real :: isccp_taumin,fluxtopinit(npoints),tauir(npoints)
     269  REAL :: albedocld(npoints,ncol)
     270  real :: boxarea
     271  integer :: debug       ! set to non-zero value to print out inputs
     272                ! ! with step debug
     273  integer :: debugcol    ! set to non-zero value to print out column
     274                ! ! decomposition with step debugcol
     275  integer :: rangevec(npoints),rangeerror
     276
     277  integer :: index1(npoints),num1,jj,k1,k2
     278  real :: rec2p13,tauchk,logp,logp1,logp2,atd
     279  real :: output_missing_value
     280
     281  character(len=10) :: ftn09
     282
     283  DATA isccp_taumin / 0.3 /
     284  DATA output_missing_value / -1.E+30 /
     285  DATA cchar / ' ','-','1','+','I','+'/
     286  DATA cchar_realtops / ' ',' ','1','1','I','I'/
     287
     288  ! ------ End duplicate definitions common to wrapper routine
     289
     290  tauchk = -1.*log(0.9999999)
     291  rec2p13=1./2.13
     292
     293  ncolprint=0
     294
     295  if ( debug.ne.0 ) then
     296      j=1
     297      write(6,'(a10)') 'j='
     298      write(6,'(8I10)') j
     299      write(6,'(a10)') 'debug='
     300      write(6,'(8I10)') debug
     301      write(6,'(a10)') 'debugcol='
     302      write(6,'(8I10)') debugcol
     303      write(6,'(a10)') 'npoints='
     304      write(6,'(8I10)') npoints
     305      write(6,'(a10)') 'nlev='
     306      write(6,'(8I10)') nlev
     307      write(6,'(a10)') 'ncol='
     308      write(6,'(8I10)') ncol
     309      write(6,'(a11)') 'top_height='
     310      write(6,'(8I10)') top_height
     311      write(6,'(a21)') 'top_height_direction='
     312      write(6,'(8I10)') top_height_direction
     313      write(6,'(a10)') 'overlap='
     314      write(6,'(8I10)') overlap
     315      write(6,'(a10)') 'emsfc_lw='
     316      write(6,'(8f10.2)') emsfc_lw
     317    do j=1,npoints,debug
     318      write(6,'(a10)') 'j='
     319      write(6,'(8I10)') j
     320      write(6,'(a10)') 'sunlit='
     321      write(6,'(8I10)') sunlit(j)
     322      write(6,'(a10)') 'pfull='
     323      write(6,'(8f10.2)') (pfull(j,i),i=1,nlev)
     324      write(6,'(a10)') 'phalf='
     325      write(6,'(8f10.2)') (phalf(j,i),i=1,nlev+1)
     326      write(6,'(a10)') 'qv='
     327      write(6,'(8f10.3)') (qv(j,i),i=1,nlev)
     328      write(6,'(a10)') 'cc='
     329      write(6,'(8f10.3)') (cc(j,i),i=1,nlev)
     330      write(6,'(a10)') 'conv='
     331      write(6,'(8f10.2)') (conv(j,i),i=1,nlev)
     332      write(6,'(a10)') 'dtau_s='
     333      write(6,'(8g12.5)') (dtau_s(j,i),i=1,nlev)
     334      write(6,'(a10)') 'dtau_c='
     335      write(6,'(8f10.2)') (dtau_c(j,i),i=1,nlev)
     336      write(6,'(a10)') 'skt='
     337      write(6,'(8f10.2)') skt(j)
     338      write(6,'(a10)') 'at='
     339      write(6,'(8f10.2)') (at(j,i),i=1,nlev)
     340      write(6,'(a10)') 'dem_s='
     341      write(6,'(8f10.3)') (dem_s(j,i),i=1,nlev)
     342      write(6,'(a10)') 'dem_c='
     343      write(6,'(8f10.3)') (dem_c(j,i),i=1,nlev)
     344    enddo
     345  endif
     346
     347  ! ---------------------------------------------------!
     348
     349  if (ncolprint.ne.0) then
     350  do j=1,npoints,1000
     351    write(6,'(a10)') 'j='
     352    write(6,'(8I10)') j
     353  enddo
     354  endif
     355
     356  if (top_height .eq. 1 .or. top_height .eq. 3) then
     357
     358  do j=1,npoints
     359      ptrop(j)=5000.
     360      attropmin(j) = 400.
     361      atmax(j) = 0.
     362      attrop(j) = 120.
     363      itrop(j) = 1
     364  enddo
     365
     366  do ilev=1,nlev
     367    do j=1,npoints
     368     if (pfull(j,ilev) .lt. 40000. .and. &
     369           pfull(j,ilev) .gt.  5000. .and. &
     370           at(j,ilev) .lt. attropmin(j)) then
     371            ptrop(j) = pfull(j,ilev)
     372            attropmin(j) = at(j,ilev)
     373            attrop(j) = attropmin(j)
     374            itrop(j)=ilev
     375       end if
     376    enddo
     377  end do
     378
     379  do ilev=1,nlev
     380    do j=1,npoints
     381       if (at(j,ilev) .gt. atmax(j) .and. &
     382             ilev  .ge. itrop(j)) atmax(j)=at(j,ilev)
     383    enddo
     384  end do
     385
     386  end if
     387
     388
     389  if (top_height .eq. 1 .or. top_height .eq. 3) then
     390      do j=1,npoints
     391          meantb(j) = 0.
     392          meantbclr(j) = 0.
     393      end do
     394  else
     395      do j=1,npoints
     396          meantb(j) = output_missing_value
     397          meantbclr(j) = output_missing_value
     398      end do
     399  end if
     400
     401  ! -----------------------------------------------------!
     402
     403  ! ---------------------------------------------------!
     404
     405  do ilev=1,nlev
     406    do j=1,npoints
     407
     408      rangevec(j)=0
     409
     410      if (cc(j,ilev) .lt. 0. .or. cc(j,ilev) .gt. 1.) then
     411        ! error = cloud fraction less than zero
     412        ! error = cloud fraction greater than 1
     413        rangevec(j)=rangevec(j)+1
     414      endif
     415
     416      if (conv(j,ilev) .lt. 0. .or. conv(j,ilev) .gt. 1.) then
     417        ! ' error = convective cloud fraction less than zero'
     418        ! ' error = convective cloud fraction greater than 1'
     419        rangevec(j)=rangevec(j)+2
     420      endif
     421
     422      if (dtau_s(j,ilev) .lt. 0.) then
     423        ! ' error = stratiform cloud opt. depth less than zero'
     424        rangevec(j)=rangevec(j)+4
     425      endif
     426
     427      if (dtau_c(j,ilev) .lt. 0.) then
     428        ! ' error = convective cloud opt. depth less than zero'
     429        rangevec(j)=rangevec(j)+8
     430      endif
     431
     432      if (dem_s(j,ilev) .lt. 0. .or. dem_s(j,ilev) .gt. 1.) then
     433          ! ' error = stratiform cloud emissivity less than zero'
     434          ! ' error = stratiform cloud emissivity greater than 1'
     435        rangevec(j)=rangevec(j)+16
     436      endif
     437
     438      if (dem_c(j,ilev) .lt. 0. .or. dem_c(j,ilev) .gt. 1.) then
     439          ! ' error = convective cloud emissivity less than zero'
     440          ! ' error = convective cloud emissivity greater than 1'
     441          rangevec(j)=rangevec(j)+32
     442      endif
     443    enddo
     444
     445    rangeerror=0
     446    do j=1,npoints
     447        rangeerror=rangeerror+rangevec(j)
     448    enddo
     449
     450    if (rangeerror.ne.0) then
     451          write (6,*) 'Input variable out of range'
     452          write (6,*) 'rangevec:'
     453          write (6,*) rangevec
     454          STOP
     455    endif
     456  enddo
     457
     458  !
     459  ! ---------------------------------------------------!
     460
     461
     462  !
     463  ! ---------------------------------------------------!
     464  ! COMPUTE CLOUD OPTICAL DEPTH FOR EACH COLUMN and
     465  ! put into vector tau
     466
     467  ! !initialize tau and albedocld to zero
     468  do ibox=1,ncol
     469    do j=1,npoints
     470        tau(j,ibox)=0.
     471      albedocld(j,ibox)=0.
     472      boxtau(j,ibox)=output_missing_value
     473      boxptop(j,ibox)=output_missing_value
     474      box_cloudy(j,ibox)=.false.
     475    enddo
     476  end do
     477
     478  ! !compute total cloud optical depth for each column
     479  do ilev=1,nlev
     480        ! !increment tau for each of the boxes
     481        do ibox=1,ncol
     482          do j=1,npoints
     483             if (frac_out(j,ibox,ilev).eq.1) then
     484                    tau(j,ibox)=tau(j,ibox) &
     485                          + dtau_s(j,ilev)
     486             endif
     487             if (frac_out(j,ibox,ilev).eq.2) then
     488                    tau(j,ibox)=tau(j,ibox) &
     489                          + dtau_c(j,ilev)
     490             end if
     491          enddo
     492        enddo ! ibox
     493  enddo ! ilev
     494      if (ncolprint.ne.0) then
     495
     496          do j=1,npoints ,1000
     497            write(6,'(a10)') 'j='
     498            write(6,'(8I10)') j
     499            write(6,'(i2,1X,8(f7.2,1X))') &
     500                  ilev, &
     501                  (tau(j,ibox),ibox=1,ncolprint)
     502          enddo
     503      endif
     504  !
     505  ! ---------------------------------------------------!
     506
     507
     508
     509  !
     510  ! ---------------------------------------------------!
     511  ! COMPUTE INFRARED BRIGHTNESS TEMPERUATRES
     512  ! AND CLOUD TOP TEMPERATURE SATELLITE SHOULD SEE
     513  !
     514  ! again this is only done if top_height = 1 or 3
     515  !
     516  ! fluxtop is the 10.5 micron radiance at the top of the
     517  !          atmosphere
     518  ! trans_layers_above is the total transmissivity in the layers
     519  !         above the current layer
     520  ! fluxtop_clrsky(j) and trans_layers_above_clrsky(j) are the clear
     521  !         sky versions of these quantities.
     522
     523  if (top_height .eq. 1 .or. top_height .eq. 3) then
     524
     525
     526    ! !----------------------------------------------------------------------
     527    ! !
     528    ! !             DO CLEAR SKY RADIANCE CALCULATION FIRST
     529    ! !
     530    ! !compute water vapor continuum emissivity
     531    ! !this treatment follows Schwarkzopf and Ramasamy
     532    ! !JGR 1999,vol 104, pages 9467-9499.
     533    ! !the emissivity is calculated at a wavenumber of 955 cm-1,
     534    ! !or 10.47 microns
     535    wtmair = 28.9644
     536    wtmh20 = 18.01534
     537    Navo = 6.023E+23
     538    grav = 9.806650E+02
     539    pstd = 1.013250E+06
     540    t0 = 296.
     541    if (ncolprint .ne. 0) &
     542          write(6,*)  'ilev   pw (kg/m2)   tauwv(j)      dem_wv'
     543    do ilev=1,nlev
     544      do j=1,npoints
     545           ! !press and dpress are dyne/cm2 = Pascals *10
     546           press(j) = pfull(j,ilev)*10.
     547           dpress(j) = (phalf(j,ilev+1)-phalf(j,ilev))*10
     548           ! !atmden = g/cm2 = kg/m2 / 10
     549           atmden(j) = dpress(j)/grav
     550           rvh20(j) = qv(j,ilev)*wtmair/wtmh20
     551           wk(j) = rvh20(j)*Navo*atmden(j)/wtmair
     552           rhoave(j) = (press(j)/pstd)*(t0/at(j,ilev))
     553           rh20s(j) = rvh20(j)*rhoave(j)
     554           rfrgn(j) = rhoave(j)-rh20s(j)
     555           tmpexp(j) = exp(-0.02*(at(j,ilev)-t0))
     556           tauwv(j) = wk(j)*1.e-20*( &
     557                 (0.0224697*rh20s(j)*tmpexp(j)) + &
     558                 (3.41817e-7*rfrgn(j)) )*0.98
     559           dem_wv(j,ilev) = 1. - exp( -1. * tauwv(j))
     560      enddo
     561           if (ncolprint .ne. 0) then
     562           do j=1,npoints ,1000
     563           write(6,'(a10)') 'j='
     564           write(6,'(8I10)') j
     565           write(6,'(i2,1X,3(f8.3,3X))') ilev, &
     566                 qv(j,ilev)*(phalf(j,ilev+1)-phalf(j,ilev))/(grav/100.), &
     567                 tauwv(j),dem_wv(j,ilev)
     568           enddo
     569         endif
     570    end do
     571
     572    ! !initialize variables
     573    do j=1,npoints
     574      fluxtop_clrsky(j) = 0.
     575      trans_layers_above_clrsky(j)=1.
     576    enddo
     577
     578    do ilev=1,nlev
     579      do j=1,npoints
     580
     581        ! ! Black body emission at temperature of the layer
     582
     583          bb(j)=1 / ( exp(1307.27/at(j,ilev)) - 1. )
     584          ! !bb(j)= 5.67e-8*at(j,ilev)**4
     585
     586          ! ! increase TOA flux by flux emitted from layer
     587          ! ! times total transmittance in layers above
     588
     589            fluxtop_clrsky(j) = fluxtop_clrsky(j) &
     590                  + dem_wv(j,ilev)*bb(j)*trans_layers_above_clrsky(j)
     591
     592            ! ! update trans_layers_above with transmissivity
     593          ! ! from this layer for next time around loop
     594
     595            trans_layers_above_clrsky(j)= &
     596                  trans_layers_above_clrsky(j)*(1.-dem_wv(j,ilev))
     597
     598
     599      enddo
     600        if (ncolprint.ne.0) then
     601         do j=1,npoints ,1000
    297602          write(6,'(a10)') 'j='
    298603          write(6,'(8I10)') j
    299           write(6,'(a10)') 'debug='
    300           write(6,'(8I10)') debug
    301           write(6,'(a10)') 'debugcol='
    302           write(6,'(8I10)') debugcol
    303           write(6,'(a10)') 'npoints='
    304           write(6,'(8I10)') npoints
    305           write(6,'(a10)') 'nlev='
    306           write(6,'(8I10)') nlev
    307           write(6,'(a10)') 'ncol='
    308           write(6,'(8I10)') ncol
    309           write(6,'(a11)') 'top_height='
    310           write(6,'(8I10)') top_height
    311           write(6,'(a21)') 'top_height_direction='
    312           write(6,'(8I10)') top_height_direction
    313           write(6,'(a10)') 'overlap='
    314           write(6,'(8I10)') overlap
    315           write(6,'(a10)') 'emsfc_lw='
    316           write(6,'(8f10.2)') emsfc_lw
    317         do j=1,npoints,debug
     604          write (6,'(a)') 'ilev:'
     605          write (6,'(I2)') ilev
     606
     607          write (6,'(a)') &
     608                'emiss_layer,100.*bb(j),100.*f,total_trans:'
     609          write (6,'(4(f7.2,1X))') dem_wv(j,ilev),100.*bb(j), &
     610                100.*fluxtop_clrsky(j),trans_layers_above_clrsky(j)
     611         enddo
     612        endif
     613
     614    enddo   !loop over level
     615
     616    do j=1,npoints
     617      ! !add in surface emission
     618      bb(j)=1/( exp(1307.27/skt(j)) - 1. )
     619      ! !bb(j)=5.67e-8*skt(j)**4
     620
     621      fluxtop_clrsky(j) = fluxtop_clrsky(j) + emsfc_lw * bb(j) &
     622            * trans_layers_above_clrsky(j)
     623
     624      ! !clear sky brightness temperature
     625      meantbclr(j) = 1307.27/(log(1.+(1./fluxtop_clrsky(j))))
     626
     627    enddo
     628
     629    if (ncolprint.ne.0) then
     630    do j=1,npoints ,1000
     631      write(6,'(a10)') 'j='
     632      write(6,'(8I10)') j
     633      write (6,'(a)') 'id:'
     634      write (6,'(a)') 'surface'
     635
     636      write (6,'(a)') 'emsfc,100.*bb(j),100.*f,total_trans:'
     637      write (6,'(5(f7.2,1X))') emsfc_lw,100.*bb(j), &
     638            100.*fluxtop_clrsky(j), &
     639            trans_layers_above_clrsky(j), meantbclr(j)
     640    enddo
     641  endif
     642
     643
     644    ! !
     645    ! !           END OF CLEAR SKY CALCULATION
     646    ! !
     647    ! !----------------------------------------------------------------
     648
     649
     650
     651    if (ncolprint.ne.0) then
     652
     653    do j=1,npoints ,1000
     654        write(6,'(a10)') 'j='
     655        write(6,'(8I10)') j
     656        write (6,'(a)') 'ts:'
     657        write (6,'(8f7.2)') (skt(j),ibox=1,ncolprint)
     658
     659        write (6,'(a)') 'ta_rev:'
     660        write (6,'(8f7.2)') &
     661              ((at(j,ilev2),ibox=1,ncolprint),ilev2=1,nlev)
     662
     663    enddo
     664    endif
     665    ! !loop over columns
     666    do ibox=1,ncol
     667      do j=1,npoints
     668        fluxtop(j,ibox)=0.
     669        trans_layers_above(j,ibox)=1.
     670      enddo
     671    enddo
     672
     673    do ilev=1,nlev
     674          do j=1,npoints
     675            ! ! Black body emission at temperature of the layer
     676
     677          bb(j)=1 / ( exp(1307.27/at(j,ilev)) - 1. )
     678          ! !bb(j)= 5.67e-8*at(j,ilev)**4
     679          enddo
     680
     681        do ibox=1,ncol
     682          do j=1,npoints
     683
     684          ! ! emissivity for point in this layer
     685            if (frac_out(j,ibox,ilev).eq.1) then
     686            dem(j,ibox)= 1. - &
     687                  ( (1. - dem_wv(j,ilev)) * (1. -  dem_s(j,ilev)) )
     688            else if (frac_out(j,ibox,ilev).eq.2) then
     689            dem(j,ibox)= 1. - &
     690                  ( (1. - dem_wv(j,ilev)) * (1. -  dem_c(j,ilev)) )
     691            else
     692            dem(j,ibox)=  dem_wv(j,ilev)
     693            end if
     694
     695
     696            ! ! increase TOA flux by flux emitted from layer
     697          ! ! times total transmittance in layers above
     698
     699            fluxtop(j,ibox) = fluxtop(j,ibox) &
     700                  + dem(j,ibox) * bb(j) &
     701                  * trans_layers_above(j,ibox)
     702
     703            ! ! update trans_layers_above with transmissivity
     704          ! ! from this layer for next time around loop
     705
     706            trans_layers_above(j,ibox)= &
     707                  trans_layers_above(j,ibox)*(1.-dem(j,ibox))
     708
     709          enddo ! j
     710        enddo ! ibox
     711
     712        if (ncolprint.ne.0) then
     713          do j=1,npoints,1000
     714          write (6,'(a)') 'ilev:'
     715          write (6,'(I2)') ilev
     716
    318717          write(6,'(a10)') 'j='
    319718          write(6,'(8I10)') j
    320           write(6,'(a10)') 'sunlit='
    321           write(6,'(8I10)') sunlit(j)
    322           write(6,'(a10)') 'pfull='
    323           write(6,'(8f10.2)') (pfull(j,i),i=1,nlev)
    324           write(6,'(a10)') 'phalf='
    325           write(6,'(8f10.2)') (phalf(j,i),i=1,nlev+1)
    326           write(6,'(a10)') 'qv='
    327           write(6,'(8f10.3)') (qv(j,i),i=1,nlev)
    328           write(6,'(a10)') 'cc='
    329           write(6,'(8f10.3)') (cc(j,i),i=1,nlev)
    330           write(6,'(a10)') 'conv='
    331           write(6,'(8f10.2)') (conv(j,i),i=1,nlev)
    332           write(6,'(a10)') 'dtau_s='
    333           write(6,'(8g12.5)') (dtau_s(j,i),i=1,nlev)
    334           write(6,'(a10)') 'dtau_c='
    335           write(6,'(8f10.2)') (dtau_c(j,i),i=1,nlev)
    336           write(6,'(a10)') 'skt='
    337           write(6,'(8f10.2)') skt(j)
    338           write(6,'(a10)') 'at='
    339           write(6,'(8f10.2)') (at(j,i),i=1,nlev)
    340           write(6,'(a10)') 'dem_s='
    341           write(6,'(8f10.3)') (dem_s(j,i),i=1,nlev)
    342           write(6,'(a10)') 'dem_c='
    343           write(6,'(8f10.3)') (dem_c(j,i),i=1,nlev)
     719          write (6,'(a)') 'emiss_layer:'
     720          write (6,'(8f7.2)') (dem(j,ibox),ibox=1,ncolprint)
     721
     722          write (6,'(a)') '100.*bb(j):'
     723          write (6,'(8f7.2)') (100.*bb(j),ibox=1,ncolprint)
     724
     725          write (6,'(a)') '100.*f:'
     726          write (6,'(8f7.2)') &
     727                (100.*fluxtop(j,ibox),ibox=1,ncolprint)
     728
     729          write (6,'(a)') 'total_trans:'
     730          write (6,'(8f7.2)') &
     731                (trans_layers_above(j,ibox),ibox=1,ncolprint)
    344732        enddo
    345733      endif
    346734
    347 !     ---------------------------------------------------!
    348 
    349       if (ncolprint.ne.0) then
     735    enddo ! ilev
     736
     737
     738      do j=1,npoints
     739        ! !add in surface emission
     740        bb(j)=1/( exp(1307.27/skt(j)) - 1. )
     741        ! !bb(j)=5.67e-8*skt(j)**4
     742      end do
     743
     744    do ibox=1,ncol
     745      do j=1,npoints
     746
     747        ! !add in surface emission
     748
     749        fluxtop(j,ibox) = fluxtop(j,ibox) &
     750              + emsfc_lw * bb(j) &
     751              * trans_layers_above(j,ibox)
     752
     753      end do
     754    end do
     755
     756    ! !calculate mean infrared brightness temperature
     757    do ibox=1,ncol
     758      do j=1,npoints
     759        meantb(j) = meantb(j)+1307.27/(log(1.+(1./fluxtop(j,ibox))))
     760      end do
     761    end do
     762      do j=1, npoints
     763        meantb(j) = meantb(j) / real(ncol)
     764      end do
     765
     766    if (ncolprint.ne.0) then
     767
     768      do j=1,npoints ,1000
     769      write(6,'(a10)') 'j='
     770      write(6,'(8I10)') j
     771      write (6,'(a)') 'id:'
     772      write (6,'(a)') 'surface'
     773
     774      write (6,'(a)') 'emiss_layer:'
     775      write (6,'(8f7.2)') (dem(1,ibox),ibox=1,ncolprint)
     776
     777      write (6,'(a)') '100.*bb(j):'
     778      write (6,'(8f7.2)') (100.*bb(j),ibox=1,ncolprint)
     779
     780      write (6,'(a)') '100.*f:'
     781      write (6,'(8f7.2)') (100.*fluxtop(j,ibox),ibox=1,ncolprint)
     782
     783      write (6,'(a)') 'meantb(j):'
     784      write (6,'(8f7.2)') (meantb(j),ibox=1,ncolprint)
     785
     786      end do
     787  endif
     788
     789    ! !now that you have the top of atmosphere radiance account
     790    ! !for ISCCP procedures to determine cloud top temperature
     791
     792    ! !account for partially transmitting cloud recompute flux
     793    ! !ISCCP would see assuming a single layer cloud
     794    ! !note choice here of 2.13, as it is primarily ice
     795    ! !clouds which have partial emissivity and need the
     796    ! !adjustment performed in this section
     797    ! !
     798  ! !If it turns out that the cloud brightness temperature
     799  ! !is greater than 260K, then the liquid cloud conversion
     800  !   !factor of 2.56 is used.
     801  ! !
     802  !   !Note that this is discussed on pages 85-87 of
     803  !   !the ISCCP D level documentation (Rossow et al. 1996)
     804
     805      do j=1,npoints
     806        ! !compute minimum brightness temperature and optical depth
     807        btcmin(j) = 1. /  ( exp(1307.27/(attrop(j)-5.)) - 1. )
     808      enddo
     809    do ibox=1,ncol
     810      do j=1,npoints
     811        transmax(j) = (fluxtop(j,ibox)-btcmin(j)) &
     812              /(fluxtop_clrsky(j)-btcmin(j))
     813      ! !note that the initial setting of tauir(j) is needed so that
     814      ! !tauir(j) has a realistic value should the next if block be
     815      ! !bypassed
     816        tauir(j) = tau(j,ibox) * rec2p13
     817        taumin(j) = -1. * log(max(min(transmax(j),0.9999999),0.001))
     818
     819      enddo
     820
     821      if (top_height .eq. 1) then
     822        do j=1,npoints
     823          if (transmax(j) .gt. 0.001 .and. &
     824                transmax(j) .le. 0.9999999) then
     825            fluxtopinit(j) = fluxtop(j,ibox)
     826          tauir(j) = tau(j,ibox) *rec2p13
     827          endif
     828        enddo
     829        do icycle=1,2
     830          do j=1,npoints
     831            if (tau(j,ibox) .gt. (tauchk            )) then
     832            if (transmax(j) .gt. 0.001 .and. &
     833                  transmax(j) .le. 0.9999999) then
     834              emcld(j,ibox) = 1. - exp(-1. * tauir(j)  )
     835              fluxtop(j,ibox) = fluxtopinit(j) - &
     836                    ((1.-emcld(j,ibox))*fluxtop_clrsky(j))
     837              fluxtop(j,ibox)=max(1.E-06, &
     838                    (fluxtop(j,ibox)/emcld(j,ibox)))
     839              tb(j,ibox)= 1307.27 &
     840                    / (log(1. + (1./fluxtop(j,ibox))))
     841              if (tb(j,ibox) .gt. 260.) then
     842              tauir(j) = tau(j,ibox) / 2.56
     843              end if
     844            end if
     845            end if
     846          enddo
     847        enddo
     848
     849      endif
     850
     851      do j=1,npoints
     852        if (tau(j,ibox) .gt. (tauchk            )) then
     853            ! !cloudy box
     854            !NOTE: tb is the cloud-top temperature not infrared brightness temperature
     855            !at this point in the code
     856            tb(j,ibox)= 1307.27/ (log(1. + (1./fluxtop(j,ibox))))
     857            if (top_height.eq.1.and.tauir(j).lt.taumin(j)) then
     858                     tb(j,ibox) = attrop(j) - 5.
     859               tau(j,ibox) = 2.13*taumin(j)
     860            end if
     861        else
     862            ! !clear sky brightness temperature
     863            tb(j,ibox) = meantbclr(j)
     864        end if
     865      enddo ! j
     866    enddo ! ibox
     867
     868    if (ncolprint.ne.0) then
     869
    350870      do j=1,npoints,1000
    351         write(6,'(a10)') 'j='
    352         write(6,'(8I10)') j
     871      write(6,'(a10)') 'j='
     872      write(6,'(8I10)') j
     873
     874      write (6,'(a)') 'attrop:'
     875      write (6,'(8f7.2)') (attrop(j))
     876
     877      write (6,'(a)') 'btcmin:'
     878      write (6,'(8f7.2)') (btcmin(j))
     879
     880      write (6,'(a)') 'fluxtop_clrsky*100:'
     881      write (6,'(8f7.2)') &
     882            (100.*fluxtop_clrsky(j))
     883
     884      write (6,'(a)') '100.*f_adj:'
     885      write (6,'(8f7.2)') (100.*fluxtop(j,ibox),ibox=1,ncolprint)
     886
     887      write (6,'(a)') 'transmax:'
     888      write (6,'(8f7.2)') (transmax(ibox),ibox=1,ncolprint)
     889
     890      write (6,'(a)') 'tau:'
     891      write (6,'(8f7.2)') (tau(j,ibox),ibox=1,ncolprint)
     892
     893      write (6,'(a)') 'emcld:'
     894      write (6,'(8f7.2)') (emcld(j,ibox),ibox=1,ncolprint)
     895
     896      write (6,'(a)') 'total_trans:'
     897      write (6,'(8f7.2)') &
     898            (trans_layers_above(j,ibox),ibox=1,ncolprint)
     899
     900      write (6,'(a)') 'total_emiss:'
     901      write (6,'(8f7.2)') &
     902            (1.0-trans_layers_above(j,ibox),ibox=1,ncolprint)
     903
     904      write (6,'(a)') 'total_trans:'
     905      write (6,'(8f7.2)') &
     906            (trans_layers_above(j,ibox),ibox=1,ncolprint)
     907
     908      write (6,'(a)') 'ppout:'
     909      write (6,'(8f7.2)') (tb(j,ibox),ibox=1,ncolprint)
     910      enddo ! j
     911  endif
     912
     913  end if
     914
     915  ! ---------------------------------------------------!
     916
     917  !
     918  ! ---------------------------------------------------!
     919  ! DETERMINE CLOUD TOP PRESSURE
     920  !
     921  ! again the 2 methods differ according to whether
     922  ! or not you use the physical cloud top pressure (top_height = 2)
     923  ! or the radiatively determined cloud top pressure (top_height = 1 or 3)
     924  !
     925
     926  ! !compute cloud top pressure
     927  do ibox=1,ncol
     928    ! !segregate according to optical thickness
     929    if (top_height .eq. 1 .or. top_height .eq. 3) then
     930      ! !find level whose temperature
     931      ! !most closely matches brightness temperature
     932      do j=1,npoints
     933        nmatch(j)=0
    353934      enddo
    354       endif
    355 
    356       if (top_height .eq. 1 .or. top_height .eq. 3) then
    357 
    358       do j=1,npoints
    359           ptrop(j)=5000.
    360           attropmin(j) = 400.
    361           atmax(j) = 0.
    362           attrop(j) = 120.
    363           itrop(j) = 1
    364       enddo
    365 
    366       do 12 ilev=1,nlev
    367         do j=1,npoints
    368          if (pfull(j,ilev) .lt. 40000. .and.
    369      &          pfull(j,ilev) .gt.  5000. .and.
    370      &          at(j,ilev) .lt. attropmin(j)) then
    371                 ptrop(j) = pfull(j,ilev)
    372                 attropmin(j) = at(j,ilev)
    373                 attrop(j) = attropmin(j)
    374                 itrop(j)=ilev
    375            end if
     935      do k1=1,nlev-1
     936        if (top_height_direction .eq. 2) then
     937          ilev = nlev - k1
     938        else
     939          ilev = k1
     940        end if
     941        ! !cdir nodep
     942        do j=1,npoints
     943         if (ilev .ge. itrop(j)) then
     944          if ((at(j,ilev)   .ge. tb(j,ibox) .and. &
     945                at(j,ilev+1) .le. tb(j,ibox)) .or. &
     946                (at(j,ilev) .le. tb(j,ibox) .and. &
     947                at(j,ilev+1) .ge. tb(j,ibox))) then
     948            nmatch(j)=nmatch(j)+1
     949            match(j,nmatch(j))=ilev
     950          end if
     951         end if
    376952        enddo
    377 12    continue
    378 
    379       do 13 ilev=1,nlev
    380         do j=1,npoints
    381            if (at(j,ilev) .gt. atmax(j) .and.
    382      &              ilev  .ge. itrop(j)) atmax(j)=at(j,ilev)
    383         enddo
    384 13    continue
    385 
    386       end if
    387 
    388 
    389       if (top_height .eq. 1 .or. top_height .eq. 3) then
    390           do j=1,npoints
    391               meantb(j) = 0.
    392               meantbclr(j) = 0.
    393           end do
    394       else
    395           do j=1,npoints
    396               meantb(j) = output_missing_value
    397               meantbclr(j) = output_missing_value
    398           end do
    399       end if
    400      
    401 !     -----------------------------------------------------!
    402 
    403 !     ---------------------------------------------------!
    404 
     953      end do
     954
     955      do j=1,npoints
     956        if (nmatch(j) .ge. 1) then
     957          k1 = match(j,nmatch(j))
     958          k2 = k1 + 1
     959          logp1 = log(pfull(j,k1))
     960          logp2 = log(pfull(j,k2))
     961          atd = max(tauchk,abs(at(j,k2) - at(j,k1)))
     962          logp=logp1+(logp2-logp1)*abs(tb(j,ibox)-at(j,k1))/atd
     963          ptop(j,ibox) = exp(logp)
     964          if(abs(pfull(j,k1)-ptop(j,ibox)) .lt. &
     965                abs(pfull(j,k2)-ptop(j,ibox))) then
     966             levmatch(j,ibox)=k1
     967          else
     968             levmatch(j,ibox)=k2
     969          end if
     970        else
     971          if (tb(j,ibox) .le. attrop(j)) then
     972            ptop(j,ibox)=ptrop(j)
     973            levmatch(j,ibox)=itrop(j)
     974          end if
     975          if (tb(j,ibox) .ge. atmax(j)) then
     976            ptop(j,ibox)=pfull(j,nlev)
     977            levmatch(j,ibox)=nlev
     978          end if
     979        end if
     980      enddo ! j
     981
     982    else ! if (top_height .eq. 1 .or. top_height .eq. 3)
     983
     984      do j=1,npoints
     985        ptop(j,ibox)=0.
     986      enddo
    405987      do ilev=1,nlev
    406988        do j=1,npoints
    407 
    408           rangevec(j)=0
    409 
    410           if (cc(j,ilev) .lt. 0. .or. cc(j,ilev) .gt. 1.) then
    411 !           error = cloud fraction less than zero
    412 !           error = cloud fraction greater than 1
    413             rangevec(j)=rangevec(j)+1
    414           endif
    415 
    416           if (conv(j,ilev) .lt. 0. .or. conv(j,ilev) .gt. 1.) then
    417 !           ' error = convective cloud fraction less than zero'
    418 !           ' error = convective cloud fraction greater than 1'
    419             rangevec(j)=rangevec(j)+2
    420           endif
    421 
    422           if (dtau_s(j,ilev) .lt. 0.) then
    423 !           ' error = stratiform cloud opt. depth less than zero'
    424             rangevec(j)=rangevec(j)+4
    425           endif
    426 
    427           if (dtau_c(j,ilev) .lt. 0.) then
    428 !           ' error = convective cloud opt. depth less than zero'
    429             rangevec(j)=rangevec(j)+8
    430           endif
    431 
    432           if (dem_s(j,ilev) .lt. 0. .or. dem_s(j,ilev) .gt. 1.) then
    433 !             ' error = stratiform cloud emissivity less than zero'
    434 !             ' error = stratiform cloud emissivity greater than 1'
    435             rangevec(j)=rangevec(j)+16
    436           endif
    437 
    438           if (dem_c(j,ilev) .lt. 0. .or. dem_c(j,ilev) .gt. 1.) then
    439 !             ' error = convective cloud emissivity less than zero'
    440 !             ' error = convective cloud emissivity greater than 1'
    441               rangevec(j)=rangevec(j)+32
    442           endif
    443         enddo
    444 
    445         rangeerror=0
    446         do j=1,npoints
    447             rangeerror=rangeerror+rangevec(j)
    448         enddo
    449 
    450         if (rangeerror.ne.0) then
    451               write (6,*) 'Input variable out of range'
    452               write (6,*) 'rangevec:'
    453               write (6,*) rangevec
    454               STOP
     989          if ((ptop(j,ibox) .eq. 0. ) &
     990                .and.(frac_out(j,ibox,ilev) .ne. 0)) then
     991            ptop(j,ibox)=phalf(j,ilev)
     992          levmatch(j,ibox)=ilev
     993          end if
     994        end do
     995      end do
     996    end if
     997
     998    do j=1,npoints
     999      if (tau(j,ibox) .le. (tauchk            )) then
     1000        ptop(j,ibox)=0.
     1001        levmatch(j,ibox)=0
     1002      endif
     1003    enddo
     1004
     1005  end do
     1006
     1007  !
     1008  !
     1009  ! ---------------------------------------------------!
     1010
     1011
     1012  !
     1013  ! ---------------------------------------------------!
     1014  ! DETERMINE ISCCP CLOUD TYPE FREQUENCIES
     1015  !
     1016  ! Now that ptop and tau have been determined,
     1017  ! determine amount of each of the 49 ISCCP cloud
     1018  ! types
     1019  !
     1020  ! Also compute grid box mean cloud top pressure and
     1021  ! optical thickness.  The mean cloud top pressure and
     1022  ! optical thickness are averages over the cloudy
     1023  ! area only. The mean cloud top pressure is a linear
     1024  ! average of the cloud top pressures.  The mean cloud
     1025  ! optical thickness is computed by converting optical
     1026  ! thickness to an albedo, averaging in albedo units,
     1027  ! then converting the average albedo back to a mean
     1028  ! optical thickness.
     1029  !
     1030
     1031  ! !compute isccp frequencies
     1032
     1033  ! !reset frequencies
     1034  do ilev=1,7
     1035  do ilev2=1,7
     1036    do j=1,npoints !
     1037         if (sunlit(j).eq.1 .or. top_height .eq. 3) then
     1038            fq_isccp(j,ilev,ilev2)= 0.
     1039         else
     1040            fq_isccp(j,ilev,ilev2)= output_missing_value
     1041         end if
     1042    enddo
     1043  end do
     1044  end do
     1045
     1046  ! !reset variables need for averaging cloud properties
     1047  do j=1,npoints
     1048    if (sunlit(j).eq.1 .or. top_height .eq. 3) then
     1049         totalcldarea(j) = 0.
     1050         meanalbedocld(j) = 0.
     1051         meanptop(j) = 0.
     1052         meantaucld(j) = 0.
     1053    else
     1054         totalcldarea(j) = output_missing_value
     1055         meanalbedocld(j) = output_missing_value
     1056         meanptop(j) = output_missing_value
     1057         meantaucld(j) = output_missing_value
     1058    end if
     1059  enddo ! j
     1060
     1061  boxarea = 1./real(ncol)
     1062
     1063  do ibox=1,ncol
     1064    do j=1,npoints
     1065
     1066      if (tau(j,ibox) .gt. (tauchk            ) &
     1067            .and. ptop(j,ibox) .gt. 0.) then
     1068          box_cloudy(j,ibox)=.true.
     1069      endif
     1070
     1071      if (box_cloudy(j,ibox)) then
     1072
     1073          if (sunlit(j).eq.1 .or. top_height .eq. 3) then
     1074
     1075            boxtau(j,ibox) = tau(j,ibox)
     1076
     1077            if (tau(j,ibox) .ge. isccp_taumin) then
     1078               totalcldarea(j) = totalcldarea(j) + boxarea
     1079
     1080               ! !convert optical thickness to albedo
     1081               albedocld(j,ibox) &
     1082                     = (tau(j,ibox)**0.895)/((tau(j,ibox)**0.895)+6.82)
     1083
     1084               ! !contribute to averaging
     1085               meanalbedocld(j) = meanalbedocld(j) &
     1086                     +albedocld(j,ibox)*boxarea
     1087
     1088            end if
     1089
    4551090        endif
    456       enddo
    457 
    458 !
    459 !     ---------------------------------------------------!
    460 
    461      
    462 !
    463 !     ---------------------------------------------------!
    464 !     COMPUTE CLOUD OPTICAL DEPTH FOR EACH COLUMN and
    465 !     put into vector tau
    466  
    467       !initialize tau and albedocld to zero
    468       do 15 ibox=1,ncol
    469         do j=1,npoints
    470             tau(j,ibox)=0.
    471           albedocld(j,ibox)=0.
    472           boxtau(j,ibox)=output_missing_value
    473           boxptop(j,ibox)=output_missing_value
    474           box_cloudy(j,ibox)=.false.
    475         enddo
    476 15    continue
    477 
    478       !compute total cloud optical depth for each column     
    479       do ilev=1,nlev
    480             !increment tau for each of the boxes
    481             do ibox=1,ncol
    482               do j=1,npoints
    483                  if (frac_out(j,ibox,ilev).eq.1) then
    484                         tau(j,ibox)=tau(j,ibox)
    485      &                     + dtau_s(j,ilev)
    486                  endif
    487                  if (frac_out(j,ibox,ilev).eq.2) then
    488                         tau(j,ibox)=tau(j,ibox)
    489      &                     + dtau_c(j,ilev)
    490                  end if
    491               enddo
    492             enddo ! ibox
    493       enddo ! ilev
    494           if (ncolprint.ne.0) then
    495 
    496               do j=1,npoints ,1000
    497                 write(6,'(a10)') 'j='
    498                 write(6,'(8I10)') j
    499                 write(6,'(i2,1X,8(f7.2,1X))')
    500      &          ilev,
    501      &          (tau(j,ibox),ibox=1,ncolprint)
    502               enddo
    503           endif
    504 !
    505 !     ---------------------------------------------------!
    506 
    507 
    508 
    509 !     
    510 !     ---------------------------------------------------!
    511 !     COMPUTE INFRARED BRIGHTNESS TEMPERUATRES
    512 !     AND CLOUD TOP TEMPERATURE SATELLITE SHOULD SEE
    513 !
    514 !     again this is only done if top_height = 1 or 3
    515 !
    516 !     fluxtop is the 10.5 micron radiance at the top of the
    517 !              atmosphere
    518 !     trans_layers_above is the total transmissivity in the layers
    519 !             above the current layer
    520 !     fluxtop_clrsky(j) and trans_layers_above_clrsky(j) are the clear
    521 !             sky versions of these quantities.
    522 
    523       if (top_height .eq. 1 .or. top_height .eq. 3) then
    524 
    525 
    526         !----------------------------------------------------------------------
    527         !   
    528         !             DO CLEAR SKY RADIANCE CALCULATION FIRST
    529         !
    530         !compute water vapor continuum emissivity
    531         !this treatment follows Schwarkzopf and Ramasamy
    532         !JGR 1999,vol 104, pages 9467-9499.
    533         !the emissivity is calculated at a wavenumber of 955 cm-1,
    534         !or 10.47 microns
    535         wtmair = 28.9644
    536         wtmh20 = 18.01534
    537         Navo = 6.023E+23
    538         grav = 9.806650E+02
    539         pstd = 1.013250E+06
    540         t0 = 296.
    541         if (ncolprint .ne. 0)
    542      &         write(6,*)  'ilev   pw (kg/m2)   tauwv(j)      dem_wv'
    543         do 125 ilev=1,nlev
    544           do j=1,npoints
    545                !press and dpress are dyne/cm2 = Pascals *10
    546                press(j) = pfull(j,ilev)*10.
    547                dpress(j) = (phalf(j,ilev+1)-phalf(j,ilev))*10
    548                !atmden = g/cm2 = kg/m2 / 10
    549                atmden(j) = dpress(j)/grav
    550                rvh20(j) = qv(j,ilev)*wtmair/wtmh20
    551                wk(j) = rvh20(j)*Navo*atmden(j)/wtmair
    552                rhoave(j) = (press(j)/pstd)*(t0/at(j,ilev))
    553                rh20s(j) = rvh20(j)*rhoave(j)
    554                rfrgn(j) = rhoave(j)-rh20s(j)
    555                tmpexp(j) = exp(-0.02*(at(j,ilev)-t0))
    556                tauwv(j) = wk(j)*1.e-20*(
    557      &           (0.0224697*rh20s(j)*tmpexp(j)) +
    558      &                (3.41817e-7*rfrgn(j)) )*0.98
    559                dem_wv(j,ilev) = 1. - exp( -1. * tauwv(j))
    560           enddo
    561                if (ncolprint .ne. 0) then
    562                do j=1,npoints ,1000
    563                write(6,'(a10)') 'j='
    564                write(6,'(8I10)') j
    565                write(6,'(i2,1X,3(f8.3,3X))') ilev,
    566      &           qv(j,ilev)*(phalf(j,ilev+1)-phalf(j,ilev))/(grav/100.),
    567      &           tauwv(j),dem_wv(j,ilev)
    568                enddo
    569              endif
    570 125     continue
    571 
    572         !initialize variables
    573         do j=1,npoints
    574           fluxtop_clrsky(j) = 0.
    575           trans_layers_above_clrsky(j)=1.
    576         enddo
    577 
     1091
     1092      endif
     1093
     1094      if (sunlit(j).eq.1 .or. top_height .eq. 3) then
     1095
     1096       if (box_cloudy(j,ibox)) then
     1097
     1098          ! !convert ptop to millibars
     1099          ptop(j,ibox)=ptop(j,ibox) / 100.
     1100
     1101          ! !save for output cloud top pressure and optical thickness
     1102          boxptop(j,ibox) = ptop(j,ibox)
     1103
     1104          if (tau(j,ibox) .ge. isccp_taumin) then
     1105            meanptop(j) = meanptop(j) + ptop(j,ibox)*boxarea
     1106          end if
     1107
     1108          ! !reset itau(j), ipres(j)
     1109          itau(j) = 0
     1110          ipres(j) = 0
     1111
     1112          ! !determine optical depth category
     1113          if (tau(j,ibox) .lt. isccp_taumin) then
     1114              itau(j)=1
     1115          else if (tau(j,ibox) .ge. isccp_taumin &
     1116   &
     1117                .and. tau(j,ibox) .lt. 1.3) then
     1118            itau(j)=2
     1119          else if (tau(j,ibox) .ge. 1.3 &
     1120                .and. tau(j,ibox) .lt. 3.6) then
     1121            itau(j)=3
     1122          else if (tau(j,ibox) .ge. 3.6 &
     1123                .and. tau(j,ibox) .lt. 9.4) then
     1124              itau(j)=4
     1125          else if (tau(j,ibox) .ge. 9.4 &
     1126                .and. tau(j,ibox) .lt. 23.) then
     1127              itau(j)=5
     1128          else if (tau(j,ibox) .ge. 23. &
     1129                .and. tau(j,ibox) .lt. 60.) then
     1130              itau(j)=6
     1131          else if (tau(j,ibox) .ge. 60.) then
     1132              itau(j)=7
     1133          end if
     1134
     1135          ! !determine cloud top pressure category
     1136          if (    ptop(j,ibox) .gt. 0. &
     1137                .and.ptop(j,ibox) .lt. 180.) then
     1138              ipres(j)=1
     1139          else if(ptop(j,ibox) .ge. 180. &
     1140                .and.ptop(j,ibox) .lt. 310.) then
     1141              ipres(j)=2
     1142          else if(ptop(j,ibox) .ge. 310. &
     1143                .and.ptop(j,ibox) .lt. 440.) then
     1144              ipres(j)=3
     1145          else if(ptop(j,ibox) .ge. 440. &
     1146                .and.ptop(j,ibox) .lt. 560.) then
     1147              ipres(j)=4
     1148          else if(ptop(j,ibox) .ge. 560. &
     1149                .and.ptop(j,ibox) .lt. 680.) then
     1150              ipres(j)=5
     1151          else if(ptop(j,ibox) .ge. 680. &
     1152                .and.ptop(j,ibox) .lt. 800.) then
     1153              ipres(j)=6
     1154          else if(ptop(j,ibox) .ge. 800.) then
     1155              ipres(j)=7
     1156          end if
     1157
     1158          ! !update frequencies
     1159          if(ipres(j) .gt. 0.and.itau(j) .gt. 0) then
     1160          fq_isccp(j,itau(j),ipres(j))= &
     1161                fq_isccp(j,itau(j),ipres(j))+ boxarea
     1162          end if
     1163
     1164        end if
     1165
     1166      end if
     1167
     1168    enddo ! j
     1169  end do
     1170
     1171  ! !compute mean cloud properties
     1172  do j=1,npoints
     1173    if (totalcldarea(j) .gt. 0.) then
     1174      ! code above guarantees that totalcldarea > 0
     1175      ! only if sunlit .eq. 1 .or. top_height = 3
     1176      ! and applies only to clouds with tau > isccp_taumin
     1177      meanptop(j) = meanptop(j) / totalcldarea(j)
     1178      meanalbedocld(j) = meanalbedocld(j) / totalcldarea(j)
     1179      meantaucld(j) = (6.82/((1./meanalbedocld(j))-1.))**(1./0.895)
     1180    else
     1181      ! this code is necessary so that in the case that totalcldarea = 0.,
     1182      ! that these variables, which are in-cloud averages, are set to missing
     1183      ! note that totalcldarea will be 0. if all the clouds in the grid box have
     1184      ! tau < isccp_taumin
     1185      meanptop(j) = output_missing_value
     1186      meanalbedocld(j) = output_missing_value
     1187      meantaucld(j) = output_missing_value
     1188    end if
     1189  enddo ! j
     1190  !
     1191  ! ---------------------------------------------------!
     1192
     1193  ! ---------------------------------------------------!
     1194  ! OPTIONAL PRINTOUT OF DATA TO CHECK PROGRAM
     1195  !
     1196  if (debugcol.ne.0) then
     1197  !
     1198     do j=1,npoints,debugcol
     1199
     1200        ! !produce character output
    5781201        do ilev=1,nlev
    579           do j=1,npoints
    580  
    581             ! Black body emission at temperature of the layer
    582 
    583               bb(j)=1 / ( exp(1307.27/at(j,ilev)) - 1. )
    584               !bb(j)= 5.67e-8*at(j,ilev)**4
    585 
    586               ! increase TOA flux by flux emitted from layer
    587               ! times total transmittance in layers above
    588 
    589                 fluxtop_clrsky(j) = fluxtop_clrsky(j)
    590      &            + dem_wv(j,ilev)*bb(j)*trans_layers_above_clrsky(j)
    591            
    592                 ! update trans_layers_above with transmissivity
    593               ! from this layer for next time around loop
    594 
    595                 trans_layers_above_clrsky(j)=
    596      &            trans_layers_above_clrsky(j)*(1.-dem_wv(j,ilev))
    597                    
    598 
    599           enddo   
    600             if (ncolprint.ne.0) then
    601              do j=1,npoints ,1000
    602               write(6,'(a10)') 'j='
    603               write(6,'(8I10)') j
    604               write (6,'(a)') 'ilev:'
    605               write (6,'(I2)') ilev
    606    
    607               write (6,'(a)')
    608      &        'emiss_layer,100.*bb(j),100.*f,total_trans:'
    609               write (6,'(4(f7.2,1X))') dem_wv(j,ilev),100.*bb(j),
    610      &             100.*fluxtop_clrsky(j),trans_layers_above_clrsky(j)
    611              enddo   
    612             endif
    613 
    614         enddo   !loop over level
    615        
    616         do j=1,npoints
    617           !add in surface emission
    618           bb(j)=1/( exp(1307.27/skt(j)) - 1. )
    619           !bb(j)=5.67e-8*skt(j)**4
    620 
    621           fluxtop_clrsky(j) = fluxtop_clrsky(j) + emsfc_lw * bb(j)
    622      &     * trans_layers_above_clrsky(j)
    623      
    624           !clear sky brightness temperature
    625           meantbclr(j) = 1307.27/(log(1.+(1./fluxtop_clrsky(j))))
    626          
    627         enddo
    628 
    629         if (ncolprint.ne.0) then
    630         do j=1,npoints ,1000
    631           write(6,'(a10)') 'j='
    632           write(6,'(8I10)') j
    633           write (6,'(a)') 'id:'
    634           write (6,'(a)') 'surface'
    635 
    636           write (6,'(a)') 'emsfc,100.*bb(j),100.*f,total_trans:'
    637           write (6,'(5(f7.2,1X))') emsfc_lw,100.*bb(j),
    638      &      100.*fluxtop_clrsky(j),
    639      &       trans_layers_above_clrsky(j), meantbclr(j)
    640         enddo
    641       endif
    642    
    643 
    644         !
    645         !           END OF CLEAR SKY CALCULATION
    646         !
    647         !----------------------------------------------------------------
    648 
    649 
    650 
    651         if (ncolprint.ne.0) then
    652 
    653         do j=1,npoints ,1000
    654             write(6,'(a10)') 'j='
    655             write(6,'(8I10)') j
    656             write (6,'(a)') 'ts:'
    657             write (6,'(8f7.2)') (skt(j),ibox=1,ncolprint)
    658    
    659             write (6,'(a)') 'ta_rev:'
    660             write (6,'(8f7.2)')
    661      &       ((at(j,ilev2),ibox=1,ncolprint),ilev2=1,nlev)
    662 
    663         enddo
    664         endif
    665         !loop over columns
    666         do ibox=1,ncol
    667           do j=1,npoints
    668             fluxtop(j,ibox)=0.
    669             trans_layers_above(j,ibox)=1.
     1202          do ibox=1,ncol
     1203               acc(ilev,ibox)=0
    6701204          enddo
    6711205        enddo
    6721206
    6731207        do ilev=1,nlev
    674               do j=1,npoints
    675                 ! Black body emission at temperature of the layer
    676 
    677               bb(j)=1 / ( exp(1307.27/at(j,ilev)) - 1. )
    678               !bb(j)= 5.67e-8*at(j,ilev)**4
    679               enddo
    680 
    681             do ibox=1,ncol
    682               do j=1,npoints
    683 
    684               ! emissivity for point in this layer
    685                 if (frac_out(j,ibox,ilev).eq.1) then
    686                 dem(j,ibox)= 1. -
    687      &             ( (1. - dem_wv(j,ilev)) * (1. -  dem_s(j,ilev)) )
    688                 else if (frac_out(j,ibox,ilev).eq.2) then
    689                 dem(j,ibox)= 1. -
    690      &             ( (1. - dem_wv(j,ilev)) * (1. -  dem_c(j,ilev)) )
    691                 else
    692                 dem(j,ibox)=  dem_wv(j,ilev)
    693                 end if
    694                
    695 
    696                 ! increase TOA flux by flux emitted from layer
    697               ! times total transmittance in layers above
    698 
    699                 fluxtop(j,ibox) = fluxtop(j,ibox)
    700      &            + dem(j,ibox) * bb(j)
    701      &            * trans_layers_above(j,ibox)
    702            
    703                 ! update trans_layers_above with transmissivity
    704               ! from this layer for next time around loop
    705 
    706                 trans_layers_above(j,ibox)=
    707      &            trans_layers_above(j,ibox)*(1.-dem(j,ibox))
    708 
    709               enddo ! j
    710             enddo ! ibox
    711 
    712             if (ncolprint.ne.0) then
    713               do j=1,npoints,1000
    714               write (6,'(a)') 'ilev:'
    715               write (6,'(I2)') ilev
    716    
    717               write(6,'(a10)') 'j='
    718               write(6,'(8I10)') j
    719               write (6,'(a)') 'emiss_layer:'
    720               write (6,'(8f7.2)') (dem(j,ibox),ibox=1,ncolprint)
    721        
    722               write (6,'(a)') '100.*bb(j):'
    723               write (6,'(8f7.2)') (100.*bb(j),ibox=1,ncolprint)
    724        
    725               write (6,'(a)') '100.*f:'
    726               write (6,'(8f7.2)')
    727      &         (100.*fluxtop(j,ibox),ibox=1,ncolprint)
    728        
    729               write (6,'(a)') 'total_trans:'
    730               write (6,'(8f7.2)')
    731      &          (trans_layers_above(j,ibox),ibox=1,ncolprint)
    732             enddo
    733           endif
    734 
    735         enddo ! ilev
    736 
    737 
    738           do j=1,npoints
    739             !add in surface emission
    740             bb(j)=1/( exp(1307.27/skt(j)) - 1. )
    741             !bb(j)=5.67e-8*skt(j)**4
    742           end do
    743 
    744         do ibox=1,ncol
    745           do j=1,npoints
    746 
    747             !add in surface emission
    748 
    749             fluxtop(j,ibox) = fluxtop(j,ibox)
    750      &         + emsfc_lw * bb(j)
    751      &         * trans_layers_above(j,ibox)
    752            
    753           end do
    754         end do
    755 
    756         !calculate mean infrared brightness temperature
    757         do ibox=1,ncol
    758           do j=1,npoints
    759             meantb(j) = meantb(j)+1307.27/(log(1.+(1./fluxtop(j,ibox))))
    760           end do
    761         end do
    762           do j=1, npoints
    763             meantb(j) = meantb(j) / real(ncol)
    764           end do       
    765 
    766         if (ncolprint.ne.0) then
    767 
    768           do j=1,npoints ,1000
    769           write(6,'(a10)') 'j='
    770           write(6,'(8I10)') j
    771           write (6,'(a)') 'id:'
    772           write (6,'(a)') 'surface'
    773 
    774           write (6,'(a)') 'emiss_layer:'
    775           write (6,'(8f7.2)') (dem(1,ibox),ibox=1,ncolprint)
    776    
    777           write (6,'(a)') '100.*bb(j):'
    778           write (6,'(8f7.2)') (100.*bb(j),ibox=1,ncolprint)
    779    
    780           write (6,'(a)') '100.*f:'
    781           write (6,'(8f7.2)') (100.*fluxtop(j,ibox),ibox=1,ncolprint)
    782          
    783           write (6,'(a)') 'meantb(j):'
    784           write (6,'(8f7.2)') (meantb(j),ibox=1,ncolprint)
    785      
    786           end do
    787       endif
    788    
    789         !now that you have the top of atmosphere radiance account
    790         !for ISCCP procedures to determine cloud top temperature
    791 
    792         !account for partially transmitting cloud recompute flux
    793         !ISCCP would see assuming a single layer cloud
    794         !note choice here of 2.13, as it is primarily ice
    795         !clouds which have partial emissivity and need the
    796         !adjustment performed in this section
    797         !
    798       !If it turns out that the cloud brightness temperature
    799       !is greater than 260K, then the liquid cloud conversion
    800         !factor of 2.56 is used.
    801       !
    802         !Note that this is discussed on pages 85-87 of
    803         !the ISCCP D level documentation (Rossow et al. 1996)
    804            
    805           do j=1,npoints 
    806             !compute minimum brightness temperature and optical depth
    807             btcmin(j) = 1. /  ( exp(1307.27/(attrop(j)-5.)) - 1. )
    808           enddo
    809         do ibox=1,ncol
    810           do j=1,npoints 
    811             transmax(j) = (fluxtop(j,ibox)-btcmin(j))
    812      &                /(fluxtop_clrsky(j)-btcmin(j))
    813           !note that the initial setting of tauir(j) is needed so that
    814           !tauir(j) has a realistic value should the next if block be
    815           !bypassed
    816             tauir(j) = tau(j,ibox) * rec2p13
    817             taumin(j) = -1. * log(max(min(transmax(j),0.9999999),0.001))
    818 
    819           enddo
    820 
    821           if (top_height .eq. 1) then
    822             do j=1,npoints 
    823               if (transmax(j) .gt. 0.001 .and.
    824      &          transmax(j) .le. 0.9999999) then
    825                 fluxtopinit(j) = fluxtop(j,ibox)
    826               tauir(j) = tau(j,ibox) *rec2p13
    827               endif
    828             enddo
    829             do icycle=1,2
    830               do j=1,npoints 
    831                 if (tau(j,ibox) .gt. (tauchk            )) then
    832                 if (transmax(j) .gt. 0.001 .and.
    833      &            transmax(j) .le. 0.9999999) then
    834                   emcld(j,ibox) = 1. - exp(-1. * tauir(j)  )
    835                   fluxtop(j,ibox) = fluxtopinit(j) -   
    836      &              ((1.-emcld(j,ibox))*fluxtop_clrsky(j))
    837                   fluxtop(j,ibox)=max(1.E-06,
    838      &              (fluxtop(j,ibox)/emcld(j,ibox)))
    839                   tb(j,ibox)= 1307.27
    840      &              / (log(1. + (1./fluxtop(j,ibox))))
    841                   if (tb(j,ibox) .gt. 260.) then
    842                   tauir(j) = tau(j,ibox) / 2.56
    843                   end if                   
    844                 end if
    845                 end if
    846               enddo
    847             enddo
    848                
    849           endif
    850        
    851           do j=1,npoints
    852             if (tau(j,ibox) .gt. (tauchk            )) then
    853                 !cloudy box
    854                 !NOTE: tb is the cloud-top temperature not infrared brightness temperature
    855                 !at this point in the code
    856                 tb(j,ibox)= 1307.27/ (log(1. + (1./fluxtop(j,ibox))))
    857                 if (top_height.eq.1.and.tauir(j).lt.taumin(j)) then
    858                          tb(j,ibox) = attrop(j) - 5.
    859                    tau(j,ibox) = 2.13*taumin(j)
    860                 end if
    861             else
    862                 !clear sky brightness temperature
    863                 tb(j,ibox) = meantbclr(j)
    864             end if
    865           enddo ! j
    866         enddo ! ibox
    867 
    868         if (ncolprint.ne.0) then
    869 
    870           do j=1,npoints,1000
    871           write(6,'(a10)') 'j='
    872           write(6,'(8I10)') j
    873 
    874           write (6,'(a)') 'attrop:'
    875           write (6,'(8f7.2)') (attrop(j))
    876    
    877           write (6,'(a)') 'btcmin:'
    878           write (6,'(8f7.2)') (btcmin(j))
    879    
    880           write (6,'(a)') 'fluxtop_clrsky*100:'
    881           write (6,'(8f7.2)')
    882      &      (100.*fluxtop_clrsky(j))
    883 
    884           write (6,'(a)') '100.*f_adj:'
    885           write (6,'(8f7.2)') (100.*fluxtop(j,ibox),ibox=1,ncolprint)
    886    
    887           write (6,'(a)') 'transmax:'
    888           write (6,'(8f7.2)') (transmax(ibox),ibox=1,ncolprint)
    889    
    890           write (6,'(a)') 'tau:'
    891           write (6,'(8f7.2)') (tau(j,ibox),ibox=1,ncolprint)
    892    
    893           write (6,'(a)') 'emcld:'
    894           write (6,'(8f7.2)') (emcld(j,ibox),ibox=1,ncolprint)
    895    
    896           write (6,'(a)') 'total_trans:'
    897           write (6,'(8f7.2)')
    898      &        (trans_layers_above(j,ibox),ibox=1,ncolprint)
    899    
    900           write (6,'(a)') 'total_emiss:'
    901           write (6,'(8f7.2)')
    902      &        (1.0-trans_layers_above(j,ibox),ibox=1,ncolprint)
    903    
    904           write (6,'(a)') 'total_trans:'
    905           write (6,'(8f7.2)')
    906      &        (trans_layers_above(j,ibox),ibox=1,ncolprint)
    907    
    908           write (6,'(a)') 'ppout:'
    909           write (6,'(8f7.2)') (tb(j,ibox),ibox=1,ncolprint)
    910           enddo ! j
    911       endif
    912 
    913       end if
    914 
    915 !     ---------------------------------------------------!
    916 
    917 !     
    918 !     ---------------------------------------------------!
    919 !     DETERMINE CLOUD TOP PRESSURE
    920 !
    921 !     again the 2 methods differ according to whether
    922 !     or not you use the physical cloud top pressure (top_height = 2)
    923 !     or the radiatively determined cloud top pressure (top_height = 1 or 3)
    924 !
    925 
    926       !compute cloud top pressure
    927       do 30 ibox=1,ncol
    928         !segregate according to optical thickness
    929         if (top_height .eq. 1 .or. top_height .eq. 3) then 
    930           !find level whose temperature
    931           !most closely matches brightness temperature
    932           do j=1,npoints
    933             nmatch(j)=0
     1208          do ibox=1,ncol
     1209               acc(ilev,ibox)=frac_out(j,ibox,ilev)*2
     1210               if (levmatch(j,ibox) .eq. ilev) &
     1211                     acc(ilev,ibox)=acc(ilev,ibox)+1
    9341212          enddo
    935           do 29 k1=1,nlev-1
    936             if (top_height_direction .eq. 2) then
    937               ilev = nlev - k1
    938             else
    939               ilev = k1
    940             end if
    941             !cdir nodep
    942             do j=1,npoints
    943              if (ilev .ge. itrop(j)) then
    944               if ((at(j,ilev)   .ge. tb(j,ibox) .and.
    945      &          at(j,ilev+1) .le. tb(j,ibox)) .or.
    946      &          (at(j,ilev) .le. tb(j,ibox) .and.
    947      &          at(j,ilev+1) .ge. tb(j,ibox))) then
    948                 nmatch(j)=nmatch(j)+1
    949                 match(j,nmatch(j))=ilev
    950               end if 
    951              end if                         
    952             enddo
    953 29        continue
    954 
    955           do j=1,npoints
    956             if (nmatch(j) .ge. 1) then
    957               k1 = match(j,nmatch(j))
    958               k2 = k1 + 1
    959               logp1 = log(pfull(j,k1))
    960               logp2 = log(pfull(j,k2))
    961               atd = max(tauchk,abs(at(j,k2) - at(j,k1)))
    962               logp=logp1+(logp2-logp1)*abs(tb(j,ibox)-at(j,k1))/atd
    963               ptop(j,ibox) = exp(logp)
    964               if(abs(pfull(j,k1)-ptop(j,ibox)) .lt.
    965      &            abs(pfull(j,k2)-ptop(j,ibox))) then
    966                  levmatch(j,ibox)=k1
    967               else
    968                  levmatch(j,ibox)=k2
    969               end if   
    970             else
    971               if (tb(j,ibox) .le. attrop(j)) then
    972                 ptop(j,ibox)=ptrop(j)
    973                 levmatch(j,ibox)=itrop(j)
    974               end if
    975               if (tb(j,ibox) .ge. atmax(j)) then
    976                 ptop(j,ibox)=pfull(j,nlev)
    977                 levmatch(j,ibox)=nlev
    978               end if                               
    979             end if
    980           enddo ! j
    981 
    982         else ! if (top_height .eq. 1 .or. top_height .eq. 3)
    983  
    984           do j=1,npoints     
    985             ptop(j,ibox)=0.
    986           enddo
    987           do ilev=1,nlev
    988             do j=1,npoints     
    989               if ((ptop(j,ibox) .eq. 0. )
    990      &           .and.(frac_out(j,ibox,ilev) .ne. 0)) then
    991                 ptop(j,ibox)=phalf(j,ilev)
    992               levmatch(j,ibox)=ilev
    993               end if
    994             end do
    995           end do
    996         end if                           
    997          
    998         do j=1,npoints
    999           if (tau(j,ibox) .le. (tauchk            )) then
    1000             ptop(j,ibox)=0.
    1001             levmatch(j,ibox)=0     
    1002           endif
    10031213        enddo
    10041214
    1005 30    continue
    1006              
    1007 !
    1008 !
    1009 !     ---------------------------------------------------!
    1010 
    1011 
    1012 !     
    1013 !     ---------------------------------------------------!
    1014 !     DETERMINE ISCCP CLOUD TYPE FREQUENCIES
    1015 !
    1016 !     Now that ptop and tau have been determined,
    1017 !     determine amount of each of the 49 ISCCP cloud
    1018 !     types
    1019 !
    1020 !     Also compute grid box mean cloud top pressure and
    1021 !     optical thickness.  The mean cloud top pressure and
    1022 !     optical thickness are averages over the cloudy
    1023 !     area only. The mean cloud top pressure is a linear
    1024 !     average of the cloud top pressures.  The mean cloud
    1025 !     optical thickness is computed by converting optical
    1026 !     thickness to an albedo, averaging in albedo units,
    1027 !     then converting the average albedo back to a mean
    1028 !     optical thickness. 
    1029 !
    1030 
    1031       !compute isccp frequencies
    1032 
    1033       !reset frequencies
    1034       do 38 ilev=1,7
    1035       do 38 ilev2=1,7
    1036         do j=1,npoints !
    1037              if (sunlit(j).eq.1 .or. top_height .eq. 3) then
    1038                 fq_isccp(j,ilev,ilev2)= 0.
    1039              else
    1040                 fq_isccp(j,ilev,ilev2)= output_missing_value
    1041              end if
    1042         enddo
    1043 38    continue
    1044 
    1045       !reset variables need for averaging cloud properties
    1046       do j=1,npoints
    1047         if (sunlit(j).eq.1 .or. top_height .eq. 3) then
    1048              totalcldarea(j) = 0.
    1049              meanalbedocld(j) = 0.
    1050              meanptop(j) = 0.
    1051              meantaucld(j) = 0.
    1052         else
    1053              totalcldarea(j) = output_missing_value
    1054              meanalbedocld(j) = output_missing_value
    1055              meanptop(j) = output_missing_value
    1056              meantaucld(j) = output_missing_value
    1057         end if
    1058       enddo ! j
    1059 
    1060       boxarea = 1./real(ncol)
    1061      
    1062       do 39 ibox=1,ncol
    1063         do j=1,npoints
    1064 
    1065           if (tau(j,ibox) .gt. (tauchk            )
    1066      &      .and. ptop(j,ibox) .gt. 0.) then
    1067               box_cloudy(j,ibox)=.true.
    1068           endif
    1069 
    1070           if (box_cloudy(j,ibox)) then
    1071 
    1072               if (sunlit(j).eq.1 .or. top_height .eq. 3) then
    1073 
    1074                 boxtau(j,ibox) = tau(j,ibox)
    1075 
    1076                 if (tau(j,ibox) .ge. isccp_taumin) then
    1077                    totalcldarea(j) = totalcldarea(j) + boxarea
    1078                
    1079                    !convert optical thickness to albedo
    1080                    albedocld(j,ibox)
    1081      &             = (tau(j,ibox)**0.895)/((tau(j,ibox)**0.895)+6.82)
    1082          
    1083                    !contribute to averaging
    1084                    meanalbedocld(j) = meanalbedocld(j)
    1085      &                                +albedocld(j,ibox)*boxarea
    1086 
    1087                 end if
    1088 
    1089             endif
    1090 
    1091           endif
    1092 
    1093           if (sunlit(j).eq.1 .or. top_height .eq. 3) then
    1094 
    1095            if (box_cloudy(j,ibox)) then
    1096          
    1097               !convert ptop to millibars
    1098               ptop(j,ibox)=ptop(j,ibox) / 100.
    1099            
    1100               !save for output cloud top pressure and optical thickness
    1101               boxptop(j,ibox) = ptop(j,ibox)
    1102    
    1103               if (tau(j,ibox) .ge. isccp_taumin) then
    1104                 meanptop(j) = meanptop(j) + ptop(j,ibox)*boxarea
    1105               end if           
    1106 
    1107               !reset itau(j), ipres(j)
    1108               itau(j) = 0
    1109               ipres(j) = 0
    1110 
    1111               !determine optical depth category
    1112               if (tau(j,ibox) .lt. isccp_taumin) then
    1113                   itau(j)=1
    1114               else if (tau(j,ibox) .ge. isccp_taumin
    1115      &                                   
    1116      &          .and. tau(j,ibox) .lt. 1.3) then
    1117                 itau(j)=2
    1118               else if (tau(j,ibox) .ge. 1.3
    1119      &          .and. tau(j,ibox) .lt. 3.6) then
    1120                 itau(j)=3
    1121               else if (tau(j,ibox) .ge. 3.6
    1122      &          .and. tau(j,ibox) .lt. 9.4) then
    1123                   itau(j)=4
    1124               else if (tau(j,ibox) .ge. 9.4
    1125      &          .and. tau(j,ibox) .lt. 23.) then
    1126                   itau(j)=5
    1127               else if (tau(j,ibox) .ge. 23.
    1128      &          .and. tau(j,ibox) .lt. 60.) then
    1129                   itau(j)=6
    1130               else if (tau(j,ibox) .ge. 60.) then
    1131                   itau(j)=7
    1132               end if
    1133 
    1134               !determine cloud top pressure category
    1135               if (    ptop(j,ibox) .gt. 0. 
    1136      &          .and.ptop(j,ibox) .lt. 180.) then
    1137                   ipres(j)=1
    1138               else if(ptop(j,ibox) .ge. 180.
    1139      &          .and.ptop(j,ibox) .lt. 310.) then
    1140                   ipres(j)=2
    1141               else if(ptop(j,ibox) .ge. 310.
    1142      &          .and.ptop(j,ibox) .lt. 440.) then
    1143                   ipres(j)=3
    1144               else if(ptop(j,ibox) .ge. 440.
    1145      &          .and.ptop(j,ibox) .lt. 560.) then
    1146                   ipres(j)=4
    1147               else if(ptop(j,ibox) .ge. 560.
    1148      &          .and.ptop(j,ibox) .lt. 680.) then
    1149                   ipres(j)=5
    1150               else if(ptop(j,ibox) .ge. 680.
    1151      &          .and.ptop(j,ibox) .lt. 800.) then
    1152                   ipres(j)=6
    1153               else if(ptop(j,ibox) .ge. 800.) then
    1154                   ipres(j)=7
    1155               end if
    1156 
    1157               !update frequencies
    1158               if(ipres(j) .gt. 0.and.itau(j) .gt. 0) then
    1159               fq_isccp(j,itau(j),ipres(j))=
    1160      &          fq_isccp(j,itau(j),ipres(j))+ boxarea
    1161               end if
    1162 
    1163             end if
    1164 
    1165           end if
    1166                        
    1167         enddo ! j
    1168 39    continue
    1169      
    1170       !compute mean cloud properties
    1171       do j=1,npoints
    1172         if (totalcldarea(j) .gt. 0.) then
    1173           ! code above guarantees that totalcldarea > 0
    1174           ! only if sunlit .eq. 1 .or. top_height = 3
    1175           ! and applies only to clouds with tau > isccp_taumin
    1176           meanptop(j) = meanptop(j) / totalcldarea(j)
    1177           meanalbedocld(j) = meanalbedocld(j) / totalcldarea(j)
    1178           meantaucld(j) = (6.82/((1./meanalbedocld(j))-1.))**(1./0.895)
    1179         else
    1180           ! this code is necessary so that in the case that totalcldarea = 0.,
    1181           ! that these variables, which are in-cloud averages, are set to missing
    1182           ! note that totalcldarea will be 0. if all the clouds in the grid box have
    1183           ! tau < isccp_taumin
    1184           meanptop(j) = output_missing_value
    1185           meanalbedocld(j) = output_missing_value
    1186           meantaucld(j) = output_missing_value
    1187         end if
    1188       enddo ! j
    1189 !
    1190 !     ---------------------------------------------------!
    1191 
    1192 !     ---------------------------------------------------!
    1193 !     OPTIONAL PRINTOUT OF DATA TO CHECK PROGRAM
    1194 !
    1195       if (debugcol.ne.0) then
    1196 !     
    1197          do j=1,npoints,debugcol
    1198 
    1199             !produce character output
    1200             do ilev=1,nlev
    1201               do ibox=1,ncol
    1202                    acc(ilev,ibox)=0
    1203               enddo
    1204             enddo
    1205 
    1206             do ilev=1,nlev
    1207               do ibox=1,ncol
    1208                    acc(ilev,ibox)=frac_out(j,ibox,ilev)*2
    1209                    if (levmatch(j,ibox) .eq. ilev)
    1210      &                 acc(ilev,ibox)=acc(ilev,ibox)+1
    1211               enddo
    1212             enddo
    1213 
    1214              !print test
    1215 
    1216           write(ftn09,11) j
    1217 11        format('ftn09.',i4.4)
    1218           open(9, FILE=ftn09, FORM='FORMATTED')
    1219 
    1220              write(9,'(a1)') ' '
    1221              write(9,'(10i5)')
    1222      &                  (ilev,ilev=5,nlev,5)
    1223              write(9,'(a1)') ' '
    1224              
    1225              do ibox=1,ncol
    1226                write(9,'(40(a1),1x,40(a1))')
    1227      &           (cchar_realtops(acc(ilev,ibox)+1),ilev=1,nlev)
    1228      &           ,(cchar(acc(ilev,ibox)+1),ilev=1,nlev)
    1229              end do
    1230              close(9)
    1231 
    1232              if (ncolprint.ne.0) then
    1233                write(6,'(a1)') ' '
    1234                     write(6,'(a2,1X,5(a7,1X),a50)')
    1235      &                  'ilev',
    1236      &                  'pfull','at',
    1237      &                  'cc*100','dem_s','dtau_s',
    1238      &                  'cchar'
    1239 
    1240 !               do 4012 ilev=1,nlev
    1241 !                    write(6,'(60i2)') (box(i,ilev),i=1,ncolprint)
    1242 !                   write(6,'(i2,1X,5(f7.2,1X),50(a1))')
    1243 !     &                  ilev,
    1244 !     &                  pfull(j,ilev)/100.,at(j,ilev),
    1245 !     &                  cc(j,ilev)*100.0,dem_s(j,ilev),dtau_s(j,ilev)
    1246 !     &                  ,(cchar(acc(ilev,ibox)+1),ibox=1,ncolprint)
    1247 !4012           continue
    1248                write (6,'(a)') 'skt(j):'
    1249                write (6,'(8f7.2)') skt(j)
    1250                                      
    1251                write (6,'(8I7)') (ibox,ibox=1,ncolprint)
    1252            
    1253                write (6,'(a)') 'tau:'
    1254                write (6,'(8f7.2)') (tau(j,ibox),ibox=1,ncolprint)
    1255    
    1256                write (6,'(a)') 'tb:'
    1257                write (6,'(8f7.2)') (tb(j,ibox),ibox=1,ncolprint)
    1258    
    1259                write (6,'(a)') 'ptop:'
    1260                write (6,'(8f7.2)') (ptop(j,ibox),ibox=1,ncolprint)
    1261              endif
    1262    
    1263         enddo
    1264        
    1265       end if
    1266 
    1267       return
    1268       end
    1269 
    1270 
     1215         ! !print test
     1216
     1217      write(ftn09,11) j
     121811     format('ftn09.',i4.4)
     1219      open(9, FILE=ftn09, FORM='FORMATTED')
     1220
     1221         write(9,'(a1)') ' '
     1222         write(9,'(10i5)') &
     1223               (ilev,ilev=5,nlev,5)
     1224         write(9,'(a1)') ' '
     1225
     1226         do ibox=1,ncol
     1227           write(9,'(40(a1),1x,40(a1))') &
     1228                 (cchar_realtops(acc(ilev,ibox)+1),ilev=1,nlev) &
     1229                 ,(cchar(acc(ilev,ibox)+1),ilev=1,nlev)
     1230         end do
     1231         close(9)
     1232
     1233         if (ncolprint.ne.0) then
     1234           write(6,'(a1)') ' '
     1235                write(6,'(a2,1X,5(a7,1X),a50)') &
     1236                      'ilev', &
     1237                      'pfull','at', &
     1238                      'cc*100','dem_s','dtau_s', &
     1239                      'cchar'
     1240
     1241            ! do 4012 ilev=1,nlev
     1242            !      write(6,'(60i2)') (box(i,ilev),i=1,ncolprint)
     1243            !     write(6,'(i2,1X,5(f7.2,1X),50(a1))')
     1244  ! &                  ilev,
     1245  ! &                  pfull(j,ilev)/100.,at(j,ilev),
     1246  ! &                  cc(j,ilev)*100.0,dem_s(j,ilev),dtau_s(j,ilev)
     1247  ! &                  ,(cchar(acc(ilev,ibox)+1),ibox=1,ncolprint)
     1248  !4012           continue
     1249           write (6,'(a)') 'skt(j):'
     1250           write (6,'(8f7.2)') skt(j)
     1251
     1252           write (6,'(8I7)') (ibox,ibox=1,ncolprint)
     1253
     1254           write (6,'(a)') 'tau:'
     1255           write (6,'(8f7.2)') (tau(j,ibox),ibox=1,ncolprint)
     1256
     1257           write (6,'(a)') 'tb:'
     1258           write (6,'(8f7.2)') (tb(j,ibox),ibox=1,ncolprint)
     1259
     1260           write (6,'(a)') 'ptop:'
     1261           write (6,'(8f7.2)') (ptop(j,ibox),ibox=1,ncolprint)
     1262         endif
     1263
     1264    enddo
     1265
     1266  end if
     1267
     1268  return
     1269end subroutine icarus
     1270
     1271
  • LMDZ6/trunk/libf/phylmd/cosp/isccp_cloud_types.f90

    r5247 r5248  
    11! $Revision: 23 $, $Date: 2011-03-31 15:41:37 +0200 (jeu. 31 mars 2011) $
    22! $URL: http://cfmip-obs-sim.googlecode.com/svn/stable/v1.4.0/icarus-scops-4.1-bsd/isccp_cloud_types.f $
    3       SUBROUTINE ISCCP_CLOUD_TYPES(
    4      &     debug,
    5      &     debugcol,
    6      &     npoints,
    7      &     sunlit,
    8      &     nlev,
    9      &     ncol,
    10      &     seed,
    11      &     pfull,
    12      &     phalf,
    13      &     qv,
    14      &     cc,
    15      &     conv,
    16      &     dtau_s,
    17      &     dtau_c,
    18      &     top_height,
    19      &     top_height_direction,
    20      &     overlap,
    21      &     frac_out,
    22      &     skt,
    23      &     emsfc_lw,
    24      &     at,
    25      &     dem_s,
    26      &     dem_c,
    27      &     fq_isccp,
    28      &     totalcldarea,
    29      &     meanptop,
    30      &     meantaucld,
    31      &     meanalbedocld,
    32      &     meantb,
    33      &     meantbclr,
    34      &     boxtau,
    35      &     boxptop
    36      &)
    37 
    38 !$Id: isccp_cloud_types.f,v 4.0 2009/03/06 11:05:11 hadmw Exp $
    39 
    40 ! *****************************COPYRIGHT****************************
    41 ! (c) British Crown Copyright 2009, the Met Office.
    42 ! All rights reserved.
    43 !
    44 ! Redistribution and use in source and binary forms, with or without
    45 ! modification, are permitted provided that the
    46 ! following conditions are met:
    47 !
    48 !     * Redistributions of source code must retain the above
    49 !       copyright  notice, this list of conditions and the following
    50 !       disclaimer.
    51 !     * Redistributions in binary form must reproduce the above
    52 !       copyright notice, this list of conditions and the following
    53 !       disclaimer in the documentation and/or other materials
    54 !       provided with the distribution.
    55 !     * Neither the name of the Met Office nor the names of its
    56 !       contributors may be used to endorse or promote products
    57 !       derived from this software without specific prior written
    58 !       permission.
    59 !
    60 ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    61 ! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    62 ! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    63 ! A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    64 ! OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    65 ! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    66 ! LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    67 ! DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    68 ! THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    69 ! (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    70 ! OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
    71 !
    72 ! *****************************COPYRIGHT*******************************
    73 ! *****************************COPYRIGHT*******************************
    74 ! *****************************COPYRIGHT*******************************
    75 
    76       implicit none
    77 
    78 !    NOTE:   the maximum number of levels and columns is set by
    79 !             the following parameter statement
    80 
    81       INTEGER ncolprint
    82      
    83 !    -----
    84 !     Input
    85 !    -----
    86 
    87       INTEGER npoints       !  number of model points in the horizontal
    88       INTEGER nlev          !  number of model levels in column
    89       INTEGER ncol          !  number of subcolumns
    90 
    91       INTEGER sunlit(npoints) !  1 for day points, 0 for night time
    92 
    93       INTEGER seed(npoints)
    94       !  seed values for marsaglia  random number generator
    95       !  It is recommended that the seed is set
    96       !  to a different value for each model
    97       !  gridbox it is called on, as it is
    98       !  possible that the choice of the same
    99       !  seed value every time may introduce some
    100       !  statistical bias in the results, particularly
    101       !  for low values of NCOL.
    102 
    103       REAL pfull(npoints,nlev)
    104                        !  pressure of full model levels (Pascals)
    105                   !  pfull(npoints,1) is top level of model
    106                   !  pfull(npoints,nlev) is bot of model
    107 
    108       REAL phalf(npoints,nlev+1)
    109                   !  pressure of half model levels (Pascals)
    110                   !  phalf(npoints,1) is top of model
    111                   !  phalf(npoints,nlev+1) is the surface pressure
    112 
    113       REAL qv(npoints,nlev)
    114                   !  water vapor specific humidity (kg vapor/ kg air)
    115                   !         on full model levels
    116 
    117       REAL cc(npoints,nlev)   
    118                   !  input cloud cover in each model level (fraction)
    119                   !  NOTE:  This is the HORIZONTAL area of each
    120                   !         grid box covered by clouds
    121 
    122       REAL conv(npoints,nlev)
    123                   !  input convective cloud cover in each model
    124                   !   level (fraction)
    125                   !  NOTE:  This is the HORIZONTAL area of each
    126                   !         grid box covered by convective clouds
    127 
    128       REAL dtau_s(npoints,nlev)
    129                   !  mean 0.67 micron optical depth of stratiform
    130                 !  clouds in each model level
    131                   !  NOTE:  this the cloud optical depth of only the
    132                   !  cloudy part of the grid box, it is not weighted
    133                   !  with the 0 cloud optical depth of the clear
    134                   !         part of the grid box
    135 
    136       REAL dtau_c(npoints,nlev)
    137                   !  mean 0.67 micron optical depth of convective
    138                 !  clouds in each
    139                   !  model level.  Same note applies as in dtau_s.
    140 
    141       INTEGER overlap                   !  overlap type
    142                               !  1=max
    143                               !  2=rand
    144                               !  3=max/rand
    145 
    146       INTEGER top_height                !  1 = adjust top height using both a computed
    147                                         !  infrared brightness temperature and the visible
    148                               !  optical depth to adjust cloud top pressure. Note
    149                               !  that this calculation is most appropriate to compare
    150                               !  to ISCCP data during sunlit hours.
    151                                         !  2 = do not adjust top height, that is cloud top
    152                                         !  pressure is the actual cloud top pressure
    153                                         !  in the model
    154                               !  3 = adjust top height using only the computed
    155                               !  infrared brightness temperature. Note that this
    156                               !  calculation is most appropriate to compare to ISCCP
    157                               !  IR only algortihm (i.e. you can compare to nighttime
    158                               !  ISCCP data with this option)
    159 
    160       INTEGER top_height_direction ! direction for finding atmosphere pressure level
    161                                  ! with interpolated temperature equal to the radiance
    162                                 ! determined cloud-top temperature
    163                                 !
    164                                 ! 1 = find the *lowest* altitude (highest pressure) level
    165                                 ! with interpolated temperature equal to the radiance
    166                                 ! determined cloud-top temperature
    167                                 !
    168                                 ! 2 = find the *highest* altitude (lowest pressure) level
    169                                  ! with interpolated temperature equal to the radiance
    170                                 ! determined cloud-top temperature
    171                                  !
    172                                 ! ONLY APPLICABLE IF top_height EQUALS 1 or 3
    173                                 !
    174                                  ! 1 = old setting: matches all versions of
    175                                 ! ISCCP simulator with versions numbers 3.5.1 and lower
    176                                 !
    177                                  ! 2 = default setting: for version numbers 4.0 and higher 
    178 !
    179 !    The following input variables are used only if top_height = 1 or top_height = 3
    180 !
    181       REAL skt(npoints)                 !  skin Temperature (K)
    182       REAL emsfc_lw                     !  10.5 micron emissivity of surface (fraction)                                           
    183       REAL at(npoints,nlev)                   !  temperature in each model level (K)
    184       REAL dem_s(npoints,nlev)                !  10.5 micron longwave emissivity of stratiform
    185                               !  clouds in each
    186                                         !  model level.  Same note applies as in dtau_s.
    187       REAL dem_c(npoints,nlev)                  !  10.5 micron longwave emissivity of convective
    188                               !  clouds in each
    189                                         !  model level.  Same note applies as in dtau_s.
    190 
    191       REAL frac_out(npoints,ncol,nlev) ! boxes gridbox divided up into
    192                               ! Equivalent of BOX in original version, but
    193                               ! indexed by column then row, rather than
    194                               ! by row then column
    195 
    196 
    197 
    198 !    ------
    199 !    Output
    200 !    ------
    201 
    202       REAL fq_isccp(npoints,7,7)        !  the fraction of the model grid box covered by
    203                                         !  each of the 49 ISCCP D level cloud types
    204 
    205       REAL totalcldarea(npoints)        !  the fraction of model grid box columns
    206                                         !  with cloud somewhere in them.  NOTE: This diagnostic
    207                                         ! does not count model clouds with tau < isccp_taumin
    208                               ! Thus this diagnostic does not equal the sum over all entries of fq_isccp.
    209                               ! However, this diagnostic does equal the sum over entries of fq_isccp with
    210                               ! itau = 2:7 (omitting itau = 1)
    211      
    212      
    213       ! The following three means are averages only over the cloudy areas with tau > isccp_taumin. 
    214       ! If no clouds with tau > isccp_taumin are in grid box all three quantities should equal zero.     
    215                              
    216       REAL meanptop(npoints)            !  mean cloud top pressure (mb) - linear averaging
    217                                         !  in cloud top pressure.
    218                              
    219       REAL meantaucld(npoints)          !  mean optical thickness
    220                                         !  linear averaging in albedo performed.
    221      
    222       real meanalbedocld(npoints)        ! mean cloud albedo
    223                                         ! linear averaging in albedo performed
    224                                        
    225       real meantb(npoints)              ! mean all-sky 10.5 micron brightness temperature
    226      
    227       real meantbclr(npoints)           ! mean clear-sky 10.5 micron brightness temperature
    228      
    229       REAL boxtau(npoints,ncol)         !  optical thickness in each column
    230      
    231       REAL boxptop(npoints,ncol)        !  cloud top pressure (mb) in each column
    232                              
    233                                                                                          
    234 !
    235 !    ------
    236 !    Working variables added when program updated to mimic Mark Webb's PV-Wave code
    237 !    ------
    238 
    239       REAL dem(npoints,ncol),bb(npoints)     !  working variables for 10.5 micron longwave
    240                               !  emissivity in part of
    241                               !  gridbox under consideration
    242 
    243       REAL ptrop(npoints)
    244       REAL attrop(npoints)
    245       REAL attropmin (npoints)
    246       REAL atmax(npoints)
    247       REAL atmin(npoints)
    248       REAL btcmin(npoints)
    249       REAL transmax(npoints)
    250 
    251       INTEGER i,j,ilev,ibox,itrop(npoints)
    252       INTEGER ipres(npoints)
    253       INTEGER itau(npoints),ilev2
    254       INTEGER acc(nlev,ncol)
    255       INTEGER match(npoints,nlev-1)
    256       INTEGER nmatch(npoints)
    257       INTEGER levmatch(npoints,ncol)
    258      
    259       !variables needed for water vapor continuum absorption
    260       real fluxtop_clrsky(npoints),trans_layers_above_clrsky(npoints)
    261       real taumin(npoints)
    262       real dem_wv(npoints,nlev), wtmair, wtmh20, Navo, grav, pstd, t0
    263       real press(npoints), dpress(npoints), atmden(npoints)
    264       real rvh20(npoints), wk(npoints), rhoave(npoints)
    265       real rh20s(npoints), rfrgn(npoints)
    266       real tmpexp(npoints),tauwv(npoints)
    267      
    268       character*1 cchar(6),cchar_realtops(6)
    269       integer icycle
    270       REAL tau(npoints,ncol)
    271       LOGICAL box_cloudy(npoints,ncol)
    272       REAL tb(npoints,ncol)
    273       REAL ptop(npoints,ncol)
    274       REAL emcld(npoints,ncol)
    275       REAL fluxtop(npoints,ncol)
    276       REAL trans_layers_above(npoints,ncol)
    277       real isccp_taumin,fluxtopinit(npoints),tauir(npoints)
    278       REAL albedocld(npoints,ncol)
    279       real boxarea
    280       integer debug       ! set to non-zero value to print out inputs
    281                     ! with step debug
    282       integer debugcol    ! set to non-zero value to print out column
    283                     ! decomposition with step debugcol
    284       integer rangevec(npoints),rangeerror
    285 
    286       integer index1(npoints),num1,jj,k1,k2
    287       real rec2p13,tauchk,logp,logp1,logp2,atd
    288 
    289       character*10 ftn09
    290      
    291       DATA isccp_taumin / 0.3 /
    292       DATA cchar / ' ','-','1','+','I','+'/
    293       DATA cchar_realtops / ' ',' ','1','1','I','I'/
    294 
    295 !    ------ End duplicate definitions common to wrapper routine
    296 
    297        ncolprint=0
    298 
    299       CALL SCOPS(
    300      &     npoints,
    301      &     nlev,
    302      &     ncol,
    303      &     seed,
    304      &     cc,
    305      &     conv,
    306      &     overlap,
    307      &     frac_out,
    308      &     ncolprint
    309      &)
    310 
    311       CALL ICARUS(
    312      &     debug,
    313      &     debugcol,
    314      &     npoints,
    315      &     sunlit,
    316      &     nlev,
    317      &     ncol,
    318      &     pfull,
    319      &     phalf,
    320      &     qv,
    321      &     cc,
    322      &     conv,
    323      &     dtau_s,
    324      &     dtau_c,
    325      &     top_height,
    326      &     top_height_direction,
    327      &     overlap,
    328      &     frac_out,
    329      &     skt,
    330      &     emsfc_lw,
    331      &     at,
    332      &     dem_s,
    333      &     dem_c,
    334      &     fq_isccp,
    335      &     totalcldarea,
    336      &     meanptop,
    337      &     meantaucld,
    338      &     meanalbedocld,
    339      &     meantb,
    340      &     meantbclr,
    341      &     boxtau,
    342      &     boxptop
    343      &)
    344 
    345       return
    346       end
    347 
     3SUBROUTINE ISCCP_CLOUD_TYPES( &
     4        debug, &
     5        debugcol, &
     6        npoints, &
     7        sunlit, &
     8        nlev, &
     9        ncol, &
     10        seed, &
     11        pfull, &
     12        phalf, &
     13        qv, &
     14        cc, &
     15        conv, &
     16        dtau_s, &
     17        dtau_c, &
     18        top_height, &
     19        top_height_direction, &
     20        overlap, &
     21        frac_out, &
     22        skt, &
     23        emsfc_lw, &
     24        at, &
     25        dem_s, &
     26        dem_c, &
     27        fq_isccp, &
     28        totalcldarea, &
     29        meanptop, &
     30        meantaucld, &
     31        meanalbedocld, &
     32        meantb, &
     33        meantbclr, &
     34        boxtau, &
     35        boxptop &
     36        )
     37
     38  !$Id: isccp_cloud_types.f,v 4.0 2009/03/06 11:05:11 hadmw Exp $
     39
     40  ! *****************************COPYRIGHT****************************
     41  ! (c) British Crown Copyright 2009, the Met Office.
     42  ! All rights reserved.
     43  !
     44  ! Redistribution and use in source and binary forms, with or without
     45  ! modification, are permitted provided that the
     46  ! following conditions are met:
     47  !
     48  ! * Redistributions of source code must retain the above
     49  !   copyright  notice, this list of conditions and the following
     50  !   disclaimer.
     51  ! * Redistributions in binary form must reproduce the above
     52  !   copyright notice, this list of conditions and the following
     53  !   disclaimer in the documentation and/or other materials
     54  !   provided with the distribution.
     55  ! * Neither the name of the Met Office nor the names of its
     56  !   contributors may be used to endorse or promote products
     57  !   derived from this software without specific prior written
     58  !   permission.
     59  !
     60  ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     61  ! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     62  ! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     63  ! A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     64  ! OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     65  ! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     66  ! LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     67  ! DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     68  ! THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     69  ! (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     70  ! OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     71  !
     72  ! *****************************COPYRIGHT*******************************
     73  ! *****************************COPYRIGHT*******************************
     74  ! *****************************COPYRIGHT*******************************
     75
     76  implicit none
     77
     78  ! NOTE:   the maximum number of levels and columns is set by
     79  !         the following parameter statement
     80
     81  INTEGER :: ncolprint
     82
     83  ! -----
     84  ! Input
     85  ! -----
     86
     87  INTEGER :: npoints       !  number of model points in the horizontal
     88  INTEGER :: nlev          !  number of model levels in column
     89  INTEGER :: ncol          !  number of subcolumns
     90
     91  INTEGER :: sunlit(npoints) !  1 for day points, 0 for night time
     92
     93  INTEGER :: seed(npoints)
     94  ! !  seed values for marsaglia  random number generator
     95  ! !  It is recommended that the seed is set
     96  ! !  to a different value for each model
     97  ! !  gridbox it is called on, as it is
     98  ! !  possible that the choice of the same
     99  ! !  seed value every time may introduce some
     100  ! !  statistical bias in the results, particularly
     101  ! !  for low values of NCOL.
     102
     103  REAL :: pfull(npoints,nlev)
     104                   ! !  pressure of full model levels (Pascals)
     105              ! !  pfull(npoints,1) is top level of model
     106              ! !  pfull(npoints,nlev) is bot of model
     107
     108  REAL :: phalf(npoints,nlev+1)
     109              ! !  pressure of half model levels (Pascals)
     110              ! !  phalf(npoints,1) is top of model
     111              ! !  phalf(npoints,nlev+1) is the surface pressure
     112
     113  REAL :: qv(npoints,nlev)
     114              ! !  water vapor specific humidity (kg vapor/ kg air)
     115              ! !         on full model levels
     116
     117  REAL :: cc(npoints,nlev)
     118              ! !  input cloud cover in each model level (fraction)
     119              ! !  NOTE:  This is the HORIZONTAL area of each
     120              ! !         grid box covered by clouds
     121
     122  REAL :: conv(npoints,nlev)
     123              ! !  input convective cloud cover in each model
     124              ! !   level (fraction)
     125              ! !  NOTE:  This is the HORIZONTAL area of each
     126              ! !         grid box covered by convective clouds
     127
     128  REAL :: dtau_s(npoints,nlev)
     129              ! !  mean 0.67 micron optical depth of stratiform
     130            ! !  clouds in each model level
     131            !   !  NOTE:  this the cloud optical depth of only the
     132            !   !  cloudy part of the grid box, it is not weighted
     133            !   !  with the 0 cloud optical depth of the clear
     134            !   !         part of the grid box
     135
     136  REAL :: dtau_c(npoints,nlev)
     137              ! !  mean 0.67 micron optical depth of convective
     138            ! !  clouds in each
     139            !   !  model level.  Same note applies as in dtau_s.
     140
     141  INTEGER :: overlap                   !  overlap type
     142                          ! !  1=max
     143                          ! !  2=rand
     144                          ! !  3=max/rand
     145
     146  INTEGER :: top_height                !  1 = adjust top height using both a computed
     147                                    ! !  infrared brightness temperature and the visible
     148                          ! !  optical depth to adjust cloud top pressure. Note
     149                          ! !  that this calculation is most appropriate to compare
     150                          ! !  to ISCCP data during sunlit hours.
     151                          !           !  2 = do not adjust top height, that is cloud top
     152                          !           !  pressure is the actual cloud top pressure
     153                          !           !  in the model
     154                          ! !  3 = adjust top height using only the computed
     155                          ! !  infrared brightness temperature. Note that this
     156                          ! !  calculation is most appropriate to compare to ISCCP
     157                          ! !  IR only algortihm (i.e. you can compare to nighttime
     158                          ! !  ISCCP data with this option)
     159
     160  INTEGER :: top_height_direction ! direction for finding atmosphere pressure level
     161                             ! ! with interpolated temperature equal to the radiance
     162                            ! determined cloud-top temperature
     163                            !
     164                            ! 1 = find the *lowest* altitude (highest pressure) level
     165                            ! with interpolated temperature equal to the radiance
     166                            ! determined cloud-top temperature
     167                            !
     168                            ! 2 = find the *highest* altitude (lowest pressure) level
     169                             ! with interpolated temperature equal to the radiance
     170                            ! determined cloud-top temperature
     171                             !
     172                            ! ONLY APPLICABLE IF top_height EQUALS 1 or 3
     173                            !
     174                             ! 1 = old setting: matches all versions of
     175                            ! ISCCP simulator with versions numbers 3.5.1 and lower
     176                            !
     177                             ! 2 = default setting: for version numbers 4.0 and higher
     178  !
     179  ! The following input variables are used only if top_height = 1 or top_height = 3
     180  !
     181  REAL :: skt(npoints)                 !  skin Temperature (K)
     182  REAL :: emsfc_lw                     !  10.5 micron emissivity of surface (fraction)
     183  REAL :: at(npoints,nlev)                   !  temperature in each model level (K)
     184  REAL :: dem_s(npoints,nlev)                !  10.5 micron longwave emissivity of stratiform
     185                          ! !  clouds in each
     186                          !           !  model level.  Same note applies as in dtau_s.
     187  REAL :: dem_c(npoints,nlev)                  !  10.5 micron longwave emissivity of convective
     188                          ! !  clouds in each
     189                          !           !  model level.  Same note applies as in dtau_s.
     190
     191  REAL :: frac_out(npoints,ncol,nlev) ! boxes gridbox divided up into
     192                          ! ! Equivalent of BOX in original version, but
     193                          ! ! indexed by column then row, rather than
     194                          ! ! by row then column
     195
     196
     197
     198  ! ------
     199  ! Output
     200  ! ------
     201
     202  REAL :: fq_isccp(npoints,7,7)        !  the fraction of the model grid box covered by
     203                                    ! !  each of the 49 ISCCP D level cloud types
     204
     205  REAL :: totalcldarea(npoints)        !  the fraction of model grid box columns
     206                                    ! !  with cloud somewhere in them.  NOTE: This diagnostic
     207                                    ! does not count model clouds with tau < isccp_taumin
     208                          ! ! Thus this diagnostic does not equal the sum over all entries of fq_isccp.
     209                          ! However, this diagnostic does equal the sum over entries of fq_isccp with
     210                          ! itau = 2:7 (omitting itau = 1)
     211
     212
     213  ! ! The following three means are averages only over the cloudy areas with tau > isccp_taumin.
     214  ! ! If no clouds with tau > isccp_taumin are in grid box all three quantities should equal zero.
     215
     216  REAL :: meanptop(npoints)            !  mean cloud top pressure (mb) - linear averaging
     217                                    ! !  in cloud top pressure.
     218
     219  REAL :: meantaucld(npoints)          !  mean optical thickness
     220                                    ! !  linear averaging in albedo performed.
     221
     222  real :: meanalbedocld(npoints)        ! mean cloud albedo
     223                                    ! ! linear averaging in albedo performed
     224
     225  real :: meantb(npoints)              ! mean all-sky 10.5 micron brightness temperature
     226
     227  real :: meantbclr(npoints)           ! mean clear-sky 10.5 micron brightness temperature
     228
     229  REAL :: boxtau(npoints,ncol)         !  optical thickness in each column
     230
     231  REAL :: boxptop(npoints,ncol)        !  cloud top pressure (mb) in each column
     232
     233
     234  !
     235  ! ------
     236  ! Working variables added when program updated to mimic Mark Webb's PV-Wave code
     237  ! ------
     238
     239  REAL :: dem(npoints,ncol),bb(npoints)     !  working variables for 10.5 micron longwave
     240                          ! !  emissivity in part of
     241                          ! !  gridbox under consideration
     242
     243  REAL :: ptrop(npoints)
     244  REAL :: attrop(npoints)
     245  REAL :: attropmin (npoints)
     246  REAL :: atmax(npoints)
     247  REAL :: atmin(npoints)
     248  REAL :: btcmin(npoints)
     249  REAL :: transmax(npoints)
     250
     251  INTEGER :: i,j,ilev,ibox,itrop(npoints)
     252  INTEGER :: ipres(npoints)
     253  INTEGER :: itau(npoints),ilev2
     254  INTEGER :: acc(nlev,ncol)
     255  INTEGER :: match(npoints,nlev-1)
     256  INTEGER :: nmatch(npoints)
     257  INTEGER :: levmatch(npoints,ncol)
     258
     259  ! !variables needed for water vapor continuum absorption
     260  real :: fluxtop_clrsky(npoints),trans_layers_above_clrsky(npoints)
     261  real :: taumin(npoints)
     262  real :: dem_wv(npoints,nlev), wtmair, wtmh20, Navo, grav, pstd, t0
     263  real :: press(npoints), dpress(npoints), atmden(npoints)
     264  real :: rvh20(npoints), wk(npoints), rhoave(npoints)
     265  real :: rh20s(npoints), rfrgn(npoints)
     266  real :: tmpexp(npoints),tauwv(npoints)
     267
     268  character(len=1) :: cchar(6),cchar_realtops(6)
     269  integer :: icycle
     270  REAL :: tau(npoints,ncol)
     271  LOGICAL :: box_cloudy(npoints,ncol)
     272  REAL :: tb(npoints,ncol)
     273  REAL :: ptop(npoints,ncol)
     274  REAL :: emcld(npoints,ncol)
     275  REAL :: fluxtop(npoints,ncol)
     276  REAL :: trans_layers_above(npoints,ncol)
     277  real :: isccp_taumin,fluxtopinit(npoints),tauir(npoints)
     278  REAL :: albedocld(npoints,ncol)
     279  real :: boxarea
     280  integer :: debug       ! set to non-zero value to print out inputs
     281                ! ! with step debug
     282  integer :: debugcol    ! set to non-zero value to print out column
     283                ! ! decomposition with step debugcol
     284  integer :: rangevec(npoints),rangeerror
     285
     286  integer :: index1(npoints),num1,jj,k1,k2
     287  real :: rec2p13,tauchk,logp,logp1,logp2,atd
     288
     289  character(len=10) :: ftn09
     290
     291  DATA isccp_taumin / 0.3 /
     292  DATA cchar / ' ','-','1','+','I','+'/
     293  DATA cchar_realtops / ' ',' ','1','1','I','I'/
     294
     295  ! ------ End duplicate definitions common to wrapper routine
     296
     297   ncolprint=0
     298
     299  CALL SCOPS( &
     300        npoints, &
     301        nlev, &
     302        ncol, &
     303        seed, &
     304        cc, &
     305        conv, &
     306        overlap, &
     307        frac_out, &
     308        ncolprint &
     309        )
     310
     311  CALL ICARUS( &
     312        debug, &
     313        debugcol, &
     314        npoints, &
     315        sunlit, &
     316        nlev, &
     317        ncol, &
     318        pfull, &
     319        phalf, &
     320        qv, &
     321        cc, &
     322        conv, &
     323        dtau_s, &
     324        dtau_c, &
     325        top_height, &
     326        top_height_direction, &
     327        overlap, &
     328        frac_out, &
     329        skt, &
     330        emsfc_lw, &
     331        at, &
     332        dem_s, &
     333        dem_c, &
     334        fq_isccp, &
     335        totalcldarea, &
     336        meanptop, &
     337        meantaucld, &
     338        meanalbedocld, &
     339        meantb, &
     340        meantbclr, &
     341        boxtau, &
     342        boxptop &
     343        )
     344
     345  return
     346end subroutine isccp_cloud_types
     347
  • LMDZ6/trunk/libf/phylmd/cosp/pf_to_mr.f90

    r5247 r5248  
    33! $Revision: 23 $, $Date: 2011-03-31 15:41:37 +0200 (jeu. 31 mars 2011) $
    44! $URL: http://cfmip-obs-sim.googlecode.com/svn/stable/v1.4.0/llnl/pf_to_mr.f $
    5 ! 
    6 ! Redistribution and use in source and binary forms, with or without modification, are permitted 
     5!
     6! Redistribution and use in source and binary forms, with or without modification, are permitted
    77! provided that the following conditions are met:
    8 ! 
    9 !     * Redistributions of source code must retain the above copyright notice, this list
    10 !       of conditions and the following disclaimer.
    11 !     * Redistributions in binary form must reproduce the above copyright notice, this list
    12 !       of conditions and the following disclaimer in the documentation and/or other materials
    13 !       provided with the distribution.
    14 !     * Neither the name of the Lawrence Livermore National Security Limited Liability Corporation
    15 !       nor the names of its contributors may be used to endorse or promote products derived from
    16 !       this software without specific prior written permission.
    17 ! 
    18 ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 
    19 ! IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
    20 ! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
    21 ! CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
    22 ! DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
    23 ! DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 
    24 ! IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
     8!
     9! * Redistributions of source code must retain the above copyright notice, this list
     10!   of conditions and the following disclaimer.
     11! * Redistributions in binary form must reproduce the above copyright notice, this list
     12!   of conditions and the following disclaimer in the documentation and/or other materials
     13!   provided with the distribution.
     14! * Neither the name of the Lawrence Livermore National Security Limited Liability Corporation
     15!   nor the names of its contributors may be used to endorse or promote products derived from
     16!   this software without specific prior written permission.
     17!
     18! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
     19! IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
     20! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     21! CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     22! DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23! DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
     24! IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
    2525! OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    26      
    27       subroutine pf_to_mr(npoints,nlev,ncol,rain_ls,snow_ls,grpl_ls,
    28      &                    rain_cv,snow_cv,prec_frac,
    29      &                    p,t,mx_rain_ls,mx_snow_ls,mx_grpl_ls,
    30      &                    mx_rain_cv,mx_snow_cv)
     26
     27subroutine pf_to_mr(npoints,nlev,ncol,rain_ls,snow_ls,grpl_ls, &
     28        rain_cv,snow_cv,prec_frac, &
     29        p,t,mx_rain_ls,mx_snow_ls,mx_grpl_ls, &
     30        mx_rain_cv,mx_snow_cv)
    3131
    3232
    33       implicit none
     33  implicit none
    3434
    35       INTEGER npoints       !  number of model points in the horizontal
    36       INTEGER nlev          !  number of model levels in column
    37       INTEGER ncol          !  number of subcolumns
     35  INTEGER :: npoints       !  number of model points in the horizontal
     36  INTEGER :: nlev          !  number of model levels in column
     37  INTEGER :: ncol          !  number of subcolumns
    3838
    39       INTEGER j,ilev,ibox
    40      
    41       REAL rain_ls(npoints,nlev),snow_ls(npoints,nlev) ! large-scale precip. flux
    42       REAL grpl_ls(npoints,nlev)
    43       REAL rain_cv(npoints,nlev),snow_cv(npoints,nlev) ! convective precip. flux
     39  INTEGER :: j,ilev,ibox
    4440
    45       REAL prec_frac(npoints,ncol,nlev) ! 0 -> clear sky
    46                                         ! 1 -> LS precipitation
    47                                         ! 2 -> CONV precipitation
    48                                         ! 3 -> both
    49       REAL mx_rain_ls(npoints,ncol,nlev),mx_snow_ls(npoints,ncol,nlev)
    50       REAL mx_grpl_ls(npoints,ncol,nlev)
    51       REAL mx_rain_cv(npoints,ncol,nlev),mx_snow_cv(npoints,ncol,nlev)
    52       REAL p(npoints,nlev),t(npoints,nlev)
    53       REAL ar,as,ag,br,bs,bg,nr,ns,ng,rho0,rhor,rhos,rhog,rho
    54       REAL term1r,term1s,term1g,term2r,term2s,term2g,term3
    55       REAL term4r_ls,term4s_ls,term4g_ls,term4r_cv,term4s_cv
    56       REAL term1x2r,term1x2s,term1x2g,t123r,t123s,t123g
    57      
    58       ! method from Khairoutdinov and Randall (2003 JAS)
     41  REAL :: rain_ls(npoints,nlev),snow_ls(npoints,nlev) ! large-scale precip. flux
     42  REAL :: grpl_ls(npoints,nlev)
     43  REAL :: rain_cv(npoints,nlev),snow_cv(npoints,nlev) ! convective precip. flux
    5944
    60       ! --- List of constants from Appendix B
    61       ! Constant in fall speed formula
    62       ar=842.
    63       as=4.84
    64       ag=94.5
    65       ! Exponent in fall speed formula
    66       br=0.8
    67       bs=0.25
    68       bg=0.5
    69       ! Intercept parameter
    70       nr=8.*1000.*1000.
    71       ns=3.*1000.*1000.
    72       ng=4.*1000.*1000.
    73       ! Densities for air and hydrometeors
    74       rho0=1.29
    75       rhor=1000.
    76       rhos=100.
    77       rhog=400.
    78       ! Term 1 of Eq. (A19).
    79       term1r=ar*17.8379/6.
    80       term1s=as*8.28508/6.
    81       term1g=ag*11.6317/6.
    82       ! Term 2 of Eq. (A19).
    83       term2r=(3.14159265*rhor*nr)**(-br/4.)
    84       term2s=(3.14159265*rhos*ns)**(-bs/4.)
    85       term2g=(3.14159265*rhog*ng)**(-bg/4.)
    86      
    87       term1x2r=term1r*term2r
    88       term1x2s=term1s*term2s
    89       term1x2g=term1g*term2g
    90       do ilev=1,nlev
    91         do j=1,npoints
    92             rho=p(j,ilev)/(287.05*t(j,ilev))
    93             term3=(rho0/rho)**0.5
    94             ! Term 4 of Eq. (A19).
    95             t123r=term1x2r*term3
    96             t123s=term1x2s*term3
    97             t123g=term1x2g*term3
    98             term4r_ls=rain_ls(j,ilev)/(t123r)
    99             term4s_ls=snow_ls(j,ilev)/(t123s)
    100             term4g_ls=grpl_ls(j,ilev)/(t123g)
    101             term4r_cv=rain_cv(j,ilev)/(t123r)
    102             term4s_cv=snow_cv(j,ilev)/(t123s)
    103             do ibox=1,ncol
    104                 mx_rain_ls(j,ibox,ilev)=0.
    105                 mx_snow_ls(j,ibox,ilev)=0.
    106                 mx_grpl_ls(j,ibox,ilev)=0.
    107                 mx_rain_cv(j,ibox,ilev)=0.
    108                 mx_snow_cv(j,ibox,ilev)=0.
    109                 if ((prec_frac(j,ibox,ilev) .eq. 1.) .or.
    110      &              (prec_frac(j,ibox,ilev) .eq. 3.)) then
    111                     mx_rain_ls(j,ibox,ilev)=
    112      &                     (term4r_ls**(1./(1.+br/4.)))/rho
    113                     mx_snow_ls(j,ibox,ilev)=
    114      &                     (term4s_ls**(1./(1.+bs/4.)))/rho
    115                     mx_grpl_ls(j,ibox,ilev)=
    116      &                     (term4g_ls**(1./(1.+bg/4.)))/rho
    117                 endif
    118                 if ((prec_frac(j,ibox,ilev) .eq. 2.) .or.
    119      &              (prec_frac(j,ibox,ilev) .eq. 3.)) then
    120                     mx_rain_cv(j,ibox,ilev)=
    121      &                     (term4r_cv**(1./(1.+br/4.)))/rho
    122                     mx_snow_cv(j,ibox,ilev)=
    123      &                     (term4s_cv**(1./(1.+bs/4.)))/rho
    124                 endif
    125             enddo ! loop over ncol
    126         enddo ! loop over npoints
    127       enddo ! loop over nlev
    128  
    129       end
     45  REAL :: prec_frac(npoints,ncol,nlev) ! 0 -> clear sky
     46                                    ! ! 1 -> LS precipitation
     47                                    ! ! 2 -> CONV precipitation
     48                                    ! ! 3 -> both
     49  REAL :: mx_rain_ls(npoints,ncol,nlev),mx_snow_ls(npoints,ncol,nlev)
     50  REAL :: mx_grpl_ls(npoints,ncol,nlev)
     51  REAL :: mx_rain_cv(npoints,ncol,nlev),mx_snow_cv(npoints,ncol,nlev)
     52  REAL :: p(npoints,nlev),t(npoints,nlev)
     53  REAL :: ar,as,ag,br,bs,bg,nr,ns,ng,rho0,rhor,rhos,rhog,rho
     54  REAL :: term1r,term1s,term1g,term2r,term2s,term2g,term3
     55  REAL :: term4r_ls,term4s_ls,term4g_ls,term4r_cv,term4s_cv
     56  REAL :: term1x2r,term1x2s,term1x2g,t123r,t123s,t123g
    13057
     58  ! ! method from Khairoutdinov and Randall (2003 JAS)
     59
     60  ! ! --- List of constants from Appendix B
     61  ! ! Constant in fall speed formula
     62  ar=842.
     63  as=4.84
     64  ag=94.5
     65  ! ! Exponent in fall speed formula
     66  br=0.8
     67  bs=0.25
     68  bg=0.5
     69  ! ! Intercept parameter
     70  nr=8.*1000.*1000.
     71  ns=3.*1000.*1000.
     72  ng=4.*1000.*1000.
     73  ! ! Densities for air and hydrometeors
     74  rho0=1.29
     75  rhor=1000.
     76  rhos=100.
     77  rhog=400.
     78  ! ! Term 1 of Eq. (A19).
     79  term1r=ar*17.8379/6.
     80  term1s=as*8.28508/6.
     81  term1g=ag*11.6317/6.
     82  ! ! Term 2 of Eq. (A19).
     83  term2r=(3.14159265*rhor*nr)**(-br/4.)
     84  term2s=(3.14159265*rhos*ns)**(-bs/4.)
     85  term2g=(3.14159265*rhog*ng)**(-bg/4.)
     86
     87  term1x2r=term1r*term2r
     88  term1x2s=term1s*term2s
     89  term1x2g=term1g*term2g
     90  do ilev=1,nlev
     91    do j=1,npoints
     92        rho=p(j,ilev)/(287.05*t(j,ilev))
     93        term3=(rho0/rho)**0.5
     94        ! ! Term 4 of Eq. (A19).
     95        t123r=term1x2r*term3
     96        t123s=term1x2s*term3
     97        t123g=term1x2g*term3
     98        term4r_ls=rain_ls(j,ilev)/(t123r)
     99        term4s_ls=snow_ls(j,ilev)/(t123s)
     100        term4g_ls=grpl_ls(j,ilev)/(t123g)
     101        term4r_cv=rain_cv(j,ilev)/(t123r)
     102        term4s_cv=snow_cv(j,ilev)/(t123s)
     103        do ibox=1,ncol
     104            mx_rain_ls(j,ibox,ilev)=0.
     105            mx_snow_ls(j,ibox,ilev)=0.
     106            mx_grpl_ls(j,ibox,ilev)=0.
     107            mx_rain_cv(j,ibox,ilev)=0.
     108            mx_snow_cv(j,ibox,ilev)=0.
     109            if ((prec_frac(j,ibox,ilev) .eq. 1.) .or. &
     110                  (prec_frac(j,ibox,ilev) .eq. 3.)) then
     111                mx_rain_ls(j,ibox,ilev)= &
     112                      (term4r_ls**(1./(1.+br/4.)))/rho
     113                mx_snow_ls(j,ibox,ilev)= &
     114                      (term4s_ls**(1./(1.+bs/4.)))/rho
     115                mx_grpl_ls(j,ibox,ilev)= &
     116                      (term4g_ls**(1./(1.+bg/4.)))/rho
     117            endif
     118            if ((prec_frac(j,ibox,ilev) .eq. 2.) .or. &
     119                  (prec_frac(j,ibox,ilev) .eq. 3.)) then
     120                mx_rain_cv(j,ibox,ilev)= &
     121                      (term4r_cv**(1./(1.+br/4.)))/rho
     122                mx_snow_cv(j,ibox,ilev)= &
     123                      (term4s_cv**(1./(1.+bs/4.)))/rho
     124            endif
     125        enddo ! loop over ncol
     126    enddo ! loop over npoints
     127  enddo ! loop over nlev
     128
     129end subroutine pf_to_mr
     130
  • LMDZ6/trunk/libf/phylmd/cosp/prec_scops.f90

    r5247 r5248  
    33! $Revision: 23 $, $Date: 2011-03-31 15:41:37 +0200 (jeu. 31 mars 2011) $
    44! $URL: http://cfmip-obs-sim.googlecode.com/svn/stable/v1.4.0/llnl/prec_scops.f $
    5 ! 
    6 ! Redistribution and use in source and binary forms, with or without modification, are permitted 
     5!
     6! Redistribution and use in source and binary forms, with or without modification, are permitted
    77! provided that the following conditions are met:
    8 ! 
    9 !     * Redistributions of source code must retain the above copyright notice, this list
    10 !       of conditions and the following disclaimer.
    11 !     * Redistributions in binary form must reproduce the above copyright notice, this list
    12 !       of conditions and the following disclaimer in the documentation and/or other materials
    13 !       provided with the distribution.
    14 !     * Neither the name of the Lawrence Livermore National Security Limited Liability Corporation
    15 !       nor the names of its contributors may be used to endorse or promote products derived from
    16 !       this software without specific prior written permission.
    17 ! 
    18 ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 
    19 ! IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
    20 ! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
    21 ! CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
    22 ! DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
    23 ! DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 
    24 ! IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
     8!
     9! * Redistributions of source code must retain the above copyright notice, this list
     10!   of conditions and the following disclaimer.
     11! * Redistributions in binary form must reproduce the above copyright notice, this list
     12!   of conditions and the following disclaimer in the documentation and/or other materials
     13!   provided with the distribution.
     14! * Neither the name of the Lawrence Livermore National Security Limited Liability Corporation
     15!   nor the names of its contributors may be used to endorse or promote products derived from
     16!   this software without specific prior written permission.
     17!
     18! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
     19! IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
     20! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     21! CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     22! DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23! DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
     24! IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
    2525! OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    26      
    27       subroutine prec_scops(npoints,nlev,ncol,ls_p_rate,cv_p_rate,
    28      &                      frac_out,prec_frac)
    29 
    30 
    31       implicit none
    32 
    33       INTEGER npoints       !  number of model points in the horizontal
    34       INTEGER nlev          !  number of model levels in column
    35       INTEGER ncol          !  number of subcolumns
    36 
    37       INTEGER i,j,ilev,ibox,cv_col
    38      
    39       REAL ls_p_rate(npoints,nlev),cv_p_rate(npoints,nlev)
    40 
    41       REAL frac_out(npoints,ncol,nlev) ! boxes gridbox divided up into
    42                               ! Equivalent of BOX in original version, but
    43                               ! indexed by column then row, rather than
    44                               ! by row then column
    45                               !TOA to SURFACE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    46       REAL prec_frac(npoints,ncol,nlev) ! 0 -> clear sky
    47                                         ! 1 -> LS precipitation
    48                                         ! 2 -> CONV precipitation
    49                     ! 3 -> both
    50                                         !TOA to SURFACE!!!!!!!!!!!!!!!!!!
    51                    
    52       INTEGER flag_ls, flag_cv
    53       INTEGER frac_out_ls(npoints,ncol),frac_out_cv(npoints,ncol) !flag variables for
    54                        ! stratiform cloud and convective cloud in the vertical column
    55 
    56       cv_col = 0.05*ncol
    57       if (cv_col .eq. 0) cv_col=1
    58  
    59       do ilev=1,nlev
    60         do ibox=1,ncol
    61           do j=1,npoints
    62             prec_frac(j,ibox,ilev) = 0
    63           enddo
    64         enddo
     26
     27subroutine prec_scops(npoints,nlev,ncol,ls_p_rate,cv_p_rate, &
     28        frac_out,prec_frac)
     29
     30
     31  implicit none
     32
     33  INTEGER :: npoints       !  number of model points in the horizontal
     34  INTEGER :: nlev          !  number of model levels in column
     35  INTEGER :: ncol          !  number of subcolumns
     36
     37  INTEGER :: i,j,ilev,ibox,cv_col
     38
     39  REAL :: ls_p_rate(npoints,nlev),cv_p_rate(npoints,nlev)
     40
     41  REAL :: frac_out(npoints,ncol,nlev) ! boxes gridbox divided up into
     42                          ! ! Equivalent of BOX in original version, but
     43                          ! ! indexed by column then row, rather than
     44                          ! ! by row then column
     45                          ! !TOA to SURFACE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     46  REAL :: prec_frac(npoints,ncol,nlev) ! 0 -> clear sky
     47                                    ! ! 1 -> LS precipitation
     48                                    ! ! 2 -> CONV precipitation
     49                ! ! 3 -> both
     50                !                     !TOA to SURFACE!!!!!!!!!!!!!!!!!!
     51
     52  INTEGER :: flag_ls, flag_cv
     53  INTEGER :: frac_out_ls(npoints,ncol),frac_out_cv(npoints,ncol) !flag variables for
     54                   ! ! stratiform cloud and convective cloud in the vertical column
     55
     56  cv_col = 0.05*ncol
     57  if (cv_col .eq. 0) cv_col=1
     58
     59  do ilev=1,nlev
     60    do ibox=1,ncol
     61      do j=1,npoints
     62        prec_frac(j,ibox,ilev) = 0
    6563      enddo
    66      
    67       do j=1,npoints
    68        do ibox=1,ncol
    69         frac_out_ls(j,ibox)=0
    70         frac_out_cv(j,ibox)=0
    71         flag_ls=0
    72         flag_cv=0
    73         do ilev=1,nlev
    74           if (frac_out(j,ibox,ilev) .eq. 1) then
    75             flag_ls=1
    76           endif
    77           if (frac_out(j,ibox,ilev) .eq. 2) then
    78             flag_cv=1
    79           endif
    80         enddo !loop over nlev
    81         if (flag_ls .eq. 1) then
    82            frac_out_ls(j,ibox)=1
    83         endif
    84         if (flag_cv .eq. 1) then
    85            frac_out_cv(j,ibox)=1
    86         endif
    87        enddo  ! loop over ncol
    88       enddo ! loop over npoints
    89 
    90 !      initialize the top layer     
    91        do j=1,npoints
    92         flag_ls=0
    93         flag_cv=0
    94    
    95         if (ls_p_rate(j,1) .gt. 0.) then
    96             do ibox=1,ncol ! possibility ONE
    97                 if (frac_out(j,ibox,1) .eq. 1) then
     64    enddo
     65  enddo
     66
     67  do j=1,npoints
     68   do ibox=1,ncol
     69    frac_out_ls(j,ibox)=0
     70    frac_out_cv(j,ibox)=0
     71    flag_ls=0
     72    flag_cv=0
     73    do ilev=1,nlev
     74      if (frac_out(j,ibox,ilev) .eq. 1) then
     75        flag_ls=1
     76      endif
     77      if (frac_out(j,ibox,ilev) .eq. 2) then
     78        flag_cv=1
     79      endif
     80    enddo !loop over nlev
     81    if (flag_ls .eq. 1) then
     82       frac_out_ls(j,ibox)=1
     83    endif
     84    if (flag_cv .eq. 1) then
     85       frac_out_cv(j,ibox)=1
     86    endif
     87   enddo  ! loop over ncol
     88  enddo ! loop over npoints
     89
     90   ! initialize the top layer
     91   do j=1,npoints
     92    flag_ls=0
     93    flag_cv=0
     94
     95    if (ls_p_rate(j,1) .gt. 0.) then
     96        do ibox=1,ncol ! possibility ONE
     97            if (frac_out(j,ibox,1) .eq. 1) then
     98                prec_frac(j,ibox,1) = 1
     99                flag_ls=1
     100            endif
     101        enddo ! loop over ncol
     102        if (flag_ls .eq. 0) then ! possibility THREE
     103            do ibox=1,ncol
     104                if (frac_out(j,ibox,2) .eq. 1) then
    98105                    prec_frac(j,ibox,1) = 1
    99106                    flag_ls=1
    100107                endif
    101108            enddo ! loop over ncol
    102             if (flag_ls .eq. 0) then ! possibility THREE
    103                 do ibox=1,ncol
    104                     if (frac_out(j,ibox,2) .eq. 1) then
    105                         prec_frac(j,ibox,1) = 1
    106                         flag_ls=1
    107                     endif
    108                 enddo ! loop over ncol
    109             endif
    110         if (flag_ls .eq. 0) then ! possibility Four
    111         do ibox=1,ncol
    112         if (frac_out_ls(j,ibox) .eq. 1) then
    113             prec_frac(j,ibox,1) = 1
    114             flag_ls=1
    115         endif
    116         enddo ! loop over ncol
    117         endif
    118         if (flag_ls .eq. 0) then ! possibility Five
    119         do ibox=1,ncol
    120     !     prec_frac(j,1:ncol,1) = 1
     109        endif
     110    if (flag_ls .eq. 0) then ! possibility Four
     111    do ibox=1,ncol
     112    if (frac_out_ls(j,ibox) .eq. 1) then
    121113        prec_frac(j,ibox,1) = 1
    122         enddo ! loop over ncol
    123             endif
    124         endif
    125        ! There is large scale precipitation
    126      
    127         if (cv_p_rate(j,1) .gt. 0.) then
    128          do ibox=1,ncol ! possibility ONE
    129           if (frac_out(j,ibox,1) .eq. 2) then
    130            if (prec_frac(j,ibox,1) .eq. 0) then
     114        flag_ls=1
     115    endif
     116    enddo ! loop over ncol
     117    endif
     118    if (flag_ls .eq. 0) then ! possibility Five
     119    do ibox=1,ncol
     120  !   !     prec_frac(j,1:ncol,1) = 1
     121    prec_frac(j,ibox,1) = 1
     122    enddo ! loop over ncol
     123        endif
     124    endif
     125   ! ! There is large scale precipitation
     126
     127    if (cv_p_rate(j,1) .gt. 0.) then
     128     do ibox=1,ncol ! possibility ONE
     129      if (frac_out(j,ibox,1) .eq. 2) then
     130       if (prec_frac(j,ibox,1) .eq. 0) then
     131    prec_frac(j,ibox,1) = 2
     132   else
     133    prec_frac(j,ibox,1) = 3
     134   endif
     135   flag_cv=1
     136  endif
     137    enddo ! loop over ncol
     138    if (flag_cv .eq. 0) then ! possibility THREE
     139    do ibox=1,ncol
     140    if (frac_out(j,ibox,2) .eq. 2) then
     141            if (prec_frac(j,ibox,1) .eq. 0) then
    131142        prec_frac(j,ibox,1) = 2
    132        else
     143        else
    133144        prec_frac(j,ibox,1) = 3
    134        endif
    135        flag_cv=1
     145        endif
     146        flag_cv=1
     147    endif
     148    enddo ! loop over ncol
     149    endif
     150    if (flag_cv .eq. 0) then ! possibility Four
     151    do ibox=1,ncol
     152    if (frac_out_cv(j,ibox) .eq. 1) then
     153            if (prec_frac(j,ibox,1) .eq. 0) then
     154        prec_frac(j,ibox,1) = 2
     155        else
     156        prec_frac(j,ibox,1) = 3
     157        endif
     158        flag_cv=1
     159    endif
     160    enddo ! loop over ncol
     161    endif
     162    if (flag_cv .eq. 0) then  ! possibility Five
     163    do ibox=1,cv_col
     164            if (prec_frac(j,ibox,1) .eq. 0) then
     165        prec_frac(j,ibox,1) = 2
     166        else
     167        prec_frac(j,ibox,1) = 3
     168        endif
     169    enddo !loop over cv_col
     170        endif
     171    endif
     172    ! ! There is convective precipitation
     173
     174    enddo ! loop over npoints
     175   ! end of initializing the top layer
     176
     177  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     178
     179  ! working on the levels from top to surface
     180  do ilev=2,nlev
     181   do j=1,npoints
     182    flag_ls=0
     183    flag_cv=0
     184
     185    if (ls_p_rate(j,ilev) .gt. 0.) then
     186     do ibox=1,ncol ! possibility ONE&TWO
     187      if ((frac_out(j,ibox,ilev) .eq. 1) .or. &
     188            ((prec_frac(j,ibox,ilev-1) .eq. 1) &
     189            .or. (prec_frac(j,ibox,ilev-1) .eq. 3))) then
     190       prec_frac(j,ibox,ilev) = 1
     191       flag_ls=1
    136192      endif
    137         enddo ! loop over ncol
    138         if (flag_cv .eq. 0) then ! possibility THREE
    139         do ibox=1,ncol
    140         if (frac_out(j,ibox,2) .eq. 2) then
    141                 if (prec_frac(j,ibox,1) .eq. 0) then
    142             prec_frac(j,ibox,1) = 2
    143             else
    144             prec_frac(j,ibox,1) = 3
    145             endif
    146             flag_cv=1
    147         endif
    148         enddo ! loop over ncol
    149         endif
    150         if (flag_cv .eq. 0) then ! possibility Four
    151         do ibox=1,ncol
    152         if (frac_out_cv(j,ibox) .eq. 1) then
    153                 if (prec_frac(j,ibox,1) .eq. 0) then
    154             prec_frac(j,ibox,1) = 2
    155             else
    156             prec_frac(j,ibox,1) = 3
    157             endif
    158             flag_cv=1
    159         endif
    160         enddo ! loop over ncol
    161         endif
    162         if (flag_cv .eq. 0) then  ! possibility Five
    163         do ibox=1,cv_col
    164                 if (prec_frac(j,ibox,1) .eq. 0) then
    165             prec_frac(j,ibox,1) = 2
    166             else
    167             prec_frac(j,ibox,1) = 3
    168             endif
    169         enddo !loop over cv_col
    170             endif
    171         endif
    172         ! There is convective precipitation
    173        
    174         enddo ! loop over npoints
    175 !      end of initializing the top layer
    176 
    177 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    178 
    179 !     working on the levels from top to surface
    180       do ilev=2,nlev
    181        do j=1,npoints
    182         flag_ls=0
    183         flag_cv=0
    184    
    185         if (ls_p_rate(j,ilev) .gt. 0.) then
    186          do ibox=1,ncol ! possibility ONE&TWO
    187           if ((frac_out(j,ibox,ilev) .eq. 1) .or.
    188      &       ((prec_frac(j,ibox,ilev-1) .eq. 1)
    189      &       .or. (prec_frac(j,ibox,ilev-1) .eq. 3))) then
    190            prec_frac(j,ibox,ilev) = 1
    191            flag_ls=1
    192           endif
    193         enddo ! loop over ncol
    194         if ((flag_ls .eq. 0) .and. (ilev .lt. nlev)) then ! possibility THREE
    195         do ibox=1,ncol
    196         if (frac_out(j,ibox,ilev+1) .eq. 1) then
    197             prec_frac(j,ibox,ilev) = 1
    198             flag_ls=1
    199         endif
    200         enddo ! loop over ncol
    201         endif
    202         if (flag_ls .eq. 0) then ! possibility Four
    203         do ibox=1,ncol
    204         if (frac_out_ls(j,ibox) .eq. 1) then
    205             prec_frac(j,ibox,ilev) = 1
    206             flag_ls=1
    207         endif
    208         enddo ! loop over ncol
    209         endif
    210         if (flag_ls .eq. 0) then ! possibility Five
    211         do ibox=1,ncol
    212 !     prec_frac(j,1:ncol,ilev) = 1
     193    enddo ! loop over ncol
     194    if ((flag_ls .eq. 0) .and. (ilev .lt. nlev)) then ! possibility THREE
     195    do ibox=1,ncol
     196    if (frac_out(j,ibox,ilev+1) .eq. 1) then
    213197        prec_frac(j,ibox,ilev) = 1
    214         enddo ! loop over ncol
    215          endif
    216       endif ! There is large scale precipitation
    217    
    218         if (cv_p_rate(j,ilev) .gt. 0.) then
    219          do ibox=1,ncol ! possibility ONE&TWO
    220           if ((frac_out(j,ibox,ilev) .eq. 2) .or.
    221      &       ((prec_frac(j,ibox,ilev-1) .eq. 2)
    222      &       .or. (prec_frac(j,ibox,ilev-1) .eq. 3))) then
     198        flag_ls=1
     199    endif
     200    enddo ! loop over ncol
     201    endif
     202    if (flag_ls .eq. 0) then ! possibility Four
     203    do ibox=1,ncol
     204    if (frac_out_ls(j,ibox) .eq. 1) then
     205        prec_frac(j,ibox,ilev) = 1
     206        flag_ls=1
     207    endif
     208    enddo ! loop over ncol
     209    endif
     210    if (flag_ls .eq. 0) then ! possibility Five
     211    do ibox=1,ncol
     212  ! prec_frac(j,1:ncol,ilev) = 1
     213    prec_frac(j,ibox,ilev) = 1
     214    enddo ! loop over ncol
     215     endif
     216  endif ! There is large scale precipitation
     217
     218    if (cv_p_rate(j,ilev) .gt. 0.) then
     219     do ibox=1,ncol ! possibility ONE&TWO
     220      if ((frac_out(j,ibox,ilev) .eq. 2) .or. &
     221            ((prec_frac(j,ibox,ilev-1) .eq. 2) &
     222            .or. (prec_frac(j,ibox,ilev-1) .eq. 3))) then
     223        if (prec_frac(j,ibox,ilev) .eq. 0) then
     224     prec_frac(j,ibox,ilev) = 2
     225    else
     226     prec_frac(j,ibox,ilev) = 3
     227    endif
     228    flag_cv=1
     229    endif
     230   enddo ! loop over ncol
     231    if ((flag_cv .eq. 0) .and. (ilev .lt. nlev)) then ! possibility THREE
     232    do ibox=1,ncol
     233    if (frac_out(j,ibox,ilev+1) .eq. 2) then
    223234            if (prec_frac(j,ibox,ilev) .eq. 0) then
    224          prec_frac(j,ibox,ilev) = 2
    225         else
    226          prec_frac(j,ibox,ilev) = 3
    227         endif
    228         flag_cv=1
    229         endif
    230        enddo ! loop over ncol
    231         if ((flag_cv .eq. 0) .and. (ilev .lt. nlev)) then ! possibility THREE
    232         do ibox=1,ncol
    233         if (frac_out(j,ibox,ilev+1) .eq. 2) then
    234                 if (prec_frac(j,ibox,ilev) .eq. 0) then
    235             prec_frac(j,ibox,ilev) = 2
    236             else
    237             prec_frac(j,ibox,ilev) = 3
    238             endif
    239             flag_cv=1
    240         endif
    241         enddo ! loop over ncol
    242         endif
    243         if (flag_cv .eq. 0) then ! possibility Four
    244         do ibox=1,ncol
    245         if (frac_out_cv(j,ibox) .eq. 1) then
    246                 if (prec_frac(j,ibox,ilev) .eq. 0) then
    247             prec_frac(j,ibox,ilev) = 2
    248             else
    249             prec_frac(j,ibox,ilev) = 3
    250             endif
    251             flag_cv=1
    252         endif
    253         enddo ! loop over ncol
    254         endif
    255         if (flag_cv .eq. 0) then  ! possibility Five
    256         do ibox=1,cv_col
    257                 if (prec_frac(j,ibox,ilev) .eq. 0) then
    258             prec_frac(j,ibox,ilev) = 2
    259             else
    260             prec_frac(j,ibox,ilev) = 3
    261             endif
    262         enddo !loop over cv_col
    263             endif
    264         endif ! There is convective precipitation
    265    
    266         enddo ! loop over npoints
    267         enddo ! loop over nlev
    268 
    269       end
    270 
     235        prec_frac(j,ibox,ilev) = 2
     236        else
     237        prec_frac(j,ibox,ilev) = 3
     238        endif
     239        flag_cv=1
     240    endif
     241    enddo ! loop over ncol
     242    endif
     243    if (flag_cv .eq. 0) then ! possibility Four
     244    do ibox=1,ncol
     245    if (frac_out_cv(j,ibox) .eq. 1) then
     246            if (prec_frac(j,ibox,ilev) .eq. 0) then
     247        prec_frac(j,ibox,ilev) = 2
     248        else
     249        prec_frac(j,ibox,ilev) = 3
     250        endif
     251        flag_cv=1
     252    endif
     253    enddo ! loop over ncol
     254    endif
     255    if (flag_cv .eq. 0) then  ! possibility Five
     256    do ibox=1,cv_col
     257            if (prec_frac(j,ibox,ilev) .eq. 0) then
     258        prec_frac(j,ibox,ilev) = 2
     259        else
     260        prec_frac(j,ibox,ilev) = 3
     261        endif
     262    enddo !loop over cv_col
     263        endif
     264    endif ! There is convective precipitation
     265
     266    enddo ! loop over npoints
     267    enddo ! loop over nlev
     268
     269end subroutine prec_scops
     270
  • LMDZ6/trunk/libf/phylmd/cosp/scops.f90

    r5247 r5248  
    1       subroutine scops(npoints,nlev,ncol,seed,cc,conv,
    2      &                 overlap,frac_out,ncolprint)
    3 
    4 
    5 ! *****************************COPYRIGHT****************************
    6 ! (c) British Crown Copyright 2009, the Met Office.
    7 ! All rights reserved.
    8 ! $Revision: 23 $, $Date: 2011-03-31 15:41:37 +0200 (jeu. 31 mars 2011) $
    9 ! $URL: http://cfmip-obs-sim.googlecode.com/svn/stable/v1.4.0/icarus-scops-4.1-bsd/scops.f $
    10 !
    11 ! Redistribution and use in source and binary forms, with or without
    12 ! modification, are permitted provided that the
    13 ! following conditions are met:
    14 !
    15 !     * Redistributions of source code must retain the above
    16 !       copyright  notice, this list of conditions and the following
    17 !       disclaimer.
    18 !     * Redistributions in binary form must reproduce the above
    19 !       copyright notice, this list of conditions and the following
    20 !       disclaimer in the documentation and/or other materials
    21 !       provided with the distribution.
    22 !     * Neither the name of the Met Office nor the names of its
    23 !       contributors may be used to endorse or promote products
    24 !       derived from this software without specific prior written
    25 !       permission.
    26 !
    27 ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    28 ! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    29 ! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    30 ! A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    31 ! OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    32 ! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    33 ! LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    34 ! DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    35 ! THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    36 ! (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    37 ! OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
    38 !
    39 ! *****************************COPYRIGHT*******************************
    40 ! *****************************COPYRIGHT*******************************
    41 ! *****************************COPYRIGHT*******************************
    42 
    43       implicit none
    44 
    45       INTEGER npoints       !  number of model points in the horizontal
    46       INTEGER nlev          !  number of model levels in column
    47       INTEGER ncol          !  number of subcolumns
    48 
    49 
    50       INTEGER overlap         !  overlap type
    51                               !  1=max
    52                               !  2=rand
    53                               !  3=max/rand
    54       REAL cc(npoints,nlev)
    55                   !  input cloud cover in each model level (fraction)
    56                   !  NOTE:  This is the HORIZONTAL area of each
    57                   !         grid box covered by clouds
    58 
    59       REAL conv(npoints,nlev)
    60                   !  input convective cloud cover in each model
    61                   !   level (fraction)
    62                   !  NOTE:  This is the HORIZONTAL area of each
    63                   !         grid box covered by convective clouds
    64 
    65       INTEGER i,j,ilev,ibox,ncolprint,ilev2
    66 
    67       REAL frac_out(npoints,ncol,nlev) ! boxes gridbox divided up into
    68                               ! Equivalent of BOX in original version, but
    69                               ! indexed by column then row, rather than
    70                               ! by row then column
    71 
    72 
    73       INTEGER seed(npoints)
    74       !  seed values for marsaglia  random number generator
    75       !  It is recommended that the seed is set
    76       !  to a different value for each model
    77       !  gridbox it is called on, as it is
    78       !  possible that the choice of the same
    79       !  seed value every time may introduce some
    80       !  statistical bias in the results, particularly
    81       !  for low values of NCOL.
    82 
    83       REAL tca(npoints,0:nlev) ! total cloud cover in each model level (fraction)
    84                                         ! with extra layer of zeroes on top
    85                                         ! in this version this just contains the values input
    86                                         ! from cc but with an extra level
    87 
    88       REAL threshold(npoints,ncol)   ! pointer to position in gridbox
    89       REAL maxocc(npoints,ncol)      ! Flag for max overlapped conv cld
    90       REAL maxosc(npoints,ncol)      ! Flag for max overlapped strat cld
    91 
    92       REAL boxpos(npoints,ncol)      ! ordered pointer to position in gridbox
    93 
    94       REAL threshold_min(npoints,ncol) ! minimum value to define range in with new threshold
    95                                         ! is chosen
    96 
    97       REAL ran(npoints)                 ! vector of random numbers
    98 
    99       INTEGER irand,i2_16,huge32,overflow_32  ! variables for RNG
    100       PARAMETER(huge32=2147483647)
    101       i2_16=65536
    102 
    103       do ibox=1,ncol
    104         do j=1,npoints
    105         boxpos(j,ibox)=(ibox-.5)/ncol
    106         enddo
    107       enddo
    108 
    109 !     ---------------------------------------------------!
    110 !     Initialise working variables
    111 !     ---------------------------------------------------!
    112 
    113 !     Initialised frac_out to zero
    114 
    115       do ilev=1,nlev
    116         do ibox=1,ncol
    117           do j=1,npoints
    118           frac_out(j,ibox,ilev)=0.0
     1subroutine scops(npoints,nlev,ncol,seed,cc,conv, &
     2        overlap,frac_out,ncolprint)
     3
     4
     5  ! *****************************COPYRIGHT****************************
     6  ! (c) British Crown Copyright 2009, the Met Office.
     7  ! All rights reserved.
     8  ! $Revision: 23 $, $Date: 2011-03-31 15:41:37 +0200 (jeu. 31 mars 2011) $
     9  ! $URL: http://cfmip-obs-sim.googlecode.com/svn/stable/v1.4.0/icarus-scops-4.1-bsd/scops.f $
     10  !
     11  ! Redistribution and use in source and binary forms, with or without
     12  ! modification, are permitted provided that the
     13  ! following conditions are met:
     14  !
     15  ! * Redistributions of source code must retain the above
     16  !   copyright  notice, this list of conditions and the following
     17  !   disclaimer.
     18  ! * Redistributions in binary form must reproduce the above
     19  !   copyright notice, this list of conditions and the following
     20  !   disclaimer in the documentation and/or other materials
     21  !   provided with the distribution.
     22  ! * Neither the name of the Met Office nor the names of its
     23  !   contributors may be used to endorse or promote products
     24  !   derived from this software without specific prior written
     25  !   permission.
     26  !
     27  ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     28  ! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     29  ! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     30  ! A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     31  ! OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     32  ! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     33  ! LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     34  ! DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     35  ! THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     36  ! (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     37  ! OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     38  !
     39  ! *****************************COPYRIGHT*******************************
     40  ! *****************************COPYRIGHT*******************************
     41  ! *****************************COPYRIGHT*******************************
     42
     43  implicit none
     44
     45  INTEGER :: npoints       !  number of model points in the horizontal
     46  INTEGER :: nlev          !  number of model levels in column
     47  INTEGER :: ncol          !  number of subcolumns
     48
     49
     50  INTEGER :: overlap         !  overlap type
     51                          ! !  1=max
     52                          ! !  2=rand
     53                          ! !  3=max/rand
     54  REAL :: cc(npoints,nlev)
     55              ! !  input cloud cover in each model level (fraction)
     56              ! !  NOTE:  This is the HORIZONTAL area of each
     57              ! !         grid box covered by clouds
     58
     59  REAL :: conv(npoints,nlev)
     60              ! !  input convective cloud cover in each model
     61              ! !   level (fraction)
     62              ! !  NOTE:  This is the HORIZONTAL area of each
     63              ! !         grid box covered by convective clouds
     64
     65  INTEGER :: i,j,ilev,ibox,ncolprint,ilev2
     66
     67  REAL :: frac_out(npoints,ncol,nlev) ! boxes gridbox divided up into
     68                          ! ! Equivalent of BOX in original version, but
     69                          ! ! indexed by column then row, rather than
     70                          ! ! by row then column
     71
     72
     73  INTEGER :: seed(npoints)
     74  ! !  seed values for marsaglia  random number generator
     75  ! !  It is recommended that the seed is set
     76  ! !  to a different value for each model
     77  ! !  gridbox it is called on, as it is
     78  ! !  possible that the choice of the same
     79  ! !  seed value every time may introduce some
     80  ! !  statistical bias in the results, particularly
     81  ! !  for low values of NCOL.
     82
     83  REAL :: tca(npoints,0:nlev) ! total cloud cover in each model level (fraction)
     84                                    ! ! with extra layer of zeroes on top
     85                                    ! ! in this version this just contains the values input
     86                                    ! ! from cc but with an extra level
     87
     88  REAL :: threshold(npoints,ncol)   ! pointer to position in gridbox
     89  REAL :: maxocc(npoints,ncol)      ! Flag for max overlapped conv cld
     90  REAL :: maxosc(npoints,ncol)      ! Flag for max overlapped strat cld
     91
     92  REAL :: boxpos(npoints,ncol)      ! ordered pointer to position in gridbox
     93
     94  REAL :: threshold_min(npoints,ncol) ! minimum value to define range in with new threshold
     95                                    ! ! is chosen
     96
     97  REAL :: ran(npoints)                 ! vector of random numbers
     98
     99  INTEGER :: irand,i2_16,huge32,overflow_32  ! variables for RNG
     100  PARAMETER(huge32=2147483647)
     101  i2_16=65536
     102
     103  do ibox=1,ncol
     104    do j=1,npoints
     105    boxpos(j,ibox)=(ibox-.5)/ncol
     106    enddo
     107  enddo
     108
     109  ! ---------------------------------------------------!
     110  ! Initialise working variables
     111  ! ---------------------------------------------------!
     112
     113  ! Initialised frac_out to zero
     114
     115  do ilev=1,nlev
     116    do ibox=1,ncol
     117      do j=1,npoints
     118      frac_out(j,ibox,ilev)=0.0
     119      enddo
     120    enddo
     121  enddo
     122
     123  ! assign 2d tca array using 1d input array cc
     124
     125  do j=1,npoints
     126    tca(j,0)=0
     127  enddo
     128
     129  do ilev=1,nlev
     130    do j=1,npoints
     131      tca(j,ilev)=cc(j,ilev)
     132    enddo
     133  enddo
     134
     135  if (ncolprint.ne.0) then
     136    write (6,'(a)') 'frac_out_pp_rev:'
     137      do j=1,npoints,1000
     138      write(6,'(a10)') 'j='
     139      write(6,'(8I10)') j
     140      write (6,'(8f5.2)') &
     141            ((frac_out(j,ibox,ilev),ibox=1,ncolprint),ilev=1,nlev)
     142
     143      enddo
     144    write (6,'(a)') 'ncol:'
     145    write (6,'(I3)') ncol
     146  endif
     147  if (ncolprint.ne.0) then
     148    write (6,'(a)') 'last_frac_pp:'
     149      do j=1,npoints,1000
     150      write(6,'(a10)') 'j='
     151      write(6,'(8I10)') j
     152      write (6,'(8f5.2)') (tca(j,0))
     153      enddo
     154  endif
     155
     156  ! ---------------------------------------------------!
     157  ! ALLOCATE CLOUD INTO BOXES, FOR NCOLUMNS, NLEVELS
     158  ! frac_out is the array that contains the information
     159  ! where 0 is no cloud, 1 is a stratiform cloud and 2 is a
     160  ! convective cloud
     161
     162  ! !loop over vertical levels
     163  DO ilev = 1,nlev
     164
     165  ! Initialise threshold
     166
     167    IF (ilev.eq.1) then
     168      ! ! If max overlap
     169      IF (overlap.eq.1) then
     170        ! ! select pixels spread evenly
     171        ! ! across the gridbox
     172          DO ibox=1,ncol
     173            do j=1,npoints
     174              threshold(j,ibox)=boxpos(j,ibox)
     175            enddo
    119176          enddo
    120         enddo
    121       enddo
    122 
    123 !     assign 2d tca array using 1d input array cc
    124 
    125       do j=1,npoints
    126         tca(j,0)=0
    127       enddo
    128 
    129       do ilev=1,nlev
    130         do j=1,npoints
    131           tca(j,ilev)=cc(j,ilev)
    132         enddo
    133       enddo
    134 
    135       if (ncolprint.ne.0) then
    136         write (6,'(a)') 'frac_out_pp_rev:'
    137           do j=1,npoints,1000
    138           write(6,'(a10)') 'j='
    139           write(6,'(8I10)') j
    140           write (6,'(8f5.2)')
    141      &     ((frac_out(j,ibox,ilev),ibox=1,ncolprint),ilev=1,nlev)
    142 
     177      ELSE
     178          DO ibox=1,ncol
     179            include 'congvec.h'
     180            ! ! select random pixels from the non-convective
     181            ! ! part the gridbox ( some will be converted into
     182            ! ! convective pixels below )
     183            do j=1,npoints
     184              threshold(j,ibox)= &
     185                    conv(j,ilev)+(1-conv(j,ilev))*ran(j)
     186            enddo
    143187          enddo
    144         write (6,'(a)') 'ncol:'
    145         write (6,'(I3)') ncol
    146       endif
    147       if (ncolprint.ne.0) then
    148         write (6,'(a)') 'last_frac_pp:'
    149           do j=1,npoints,1000
    150           write(6,'(a10)') 'j='
    151           write(6,'(8I10)') j
    152           write (6,'(8f5.2)') (tca(j,0))
    153           enddo
    154       endif
    155 
    156 !     ---------------------------------------------------!
    157 !     ALLOCATE CLOUD INTO BOXES, FOR NCOLUMNS, NLEVELS
    158 !     frac_out is the array that contains the information
    159 !     where 0 is no cloud, 1 is a stratiform cloud and 2 is a
    160 !     convective cloud
    161      
    162       !loop over vertical levels
    163       DO 200 ilev = 1,nlev
    164                                  
    165 !     Initialise threshold
    166 
    167         IF (ilev.eq.1) then
    168           ! If max overlap
    169           IF (overlap.eq.1) then
    170             ! select pixels spread evenly
    171             ! across the gridbox
    172               DO ibox=1,ncol
    173                 do j=1,npoints
    174                   threshold(j,ibox)=boxpos(j,ibox)
    175                 enddo
    176               enddo
    177           ELSE
    178               DO ibox=1,ncol
    179                 include 'congvec.h'
    180                 ! select random pixels from the non-convective
    181                 ! part the gridbox ( some will be converted into
    182                 ! convective pixels below )
    183                 do j=1,npoints
    184                   threshold(j,ibox)=
    185      &            conv(j,ilev)+(1-conv(j,ilev))*ran(j)
    186                 enddo
    187               enddo
    188             ENDIF
    189             IF (ncolprint.ne.0) then
    190               write (6,'(a)') 'threshold_nsf2:'
    191                 do j=1,npoints,1000
    192                 write(6,'(a10)') 'j='
    193                 write(6,'(8I10)') j
    194                 write (6,'(8f5.2)') (threshold(j,ibox),ibox=1,ncolprint)
    195                 enddo
    196             ENDIF
    197188        ENDIF
    198 
    199189        IF (ncolprint.ne.0) then
    200             write (6,'(a)') 'ilev:'
    201             write (6,'(I2)') ilev
    202         ENDIF
    203 
    204         DO ibox=1,ncol
    205 
    206           ! All versions
    207           do j=1,npoints
    208             if (boxpos(j,ibox).le.conv(j,ilev)) then
    209               maxocc(j,ibox) = 1
    210             else
    211               maxocc(j,ibox) = 0
    212             end if
    213           enddo
    214 
    215           ! Max overlap
    216           if (overlap.eq.1) then
    217             do j=1,npoints
    218               threshold_min(j,ibox)=conv(j,ilev)
    219               maxosc(j,ibox)=1
    220             enddo
    221           endif
    222 
    223           ! Random overlap
    224           if (overlap.eq.2) then
    225             do j=1,npoints
    226               threshold_min(j,ibox)=conv(j,ilev)
    227               maxosc(j,ibox)=0
    228             enddo
    229           endif
    230 
    231           ! Max/Random overlap
    232           if (overlap.eq.3) then
    233             do j=1,npoints
    234               threshold_min(j,ibox)=max(conv(j,ilev),
    235      &          min(tca(j,ilev-1),tca(j,ilev)))
    236               if (threshold(j,ibox)
    237      &          .lt.min(tca(j,ilev-1),tca(j,ilev))
    238      &          .and.(threshold(j,ibox).gt.conv(j,ilev))) then
    239                    maxosc(j,ibox)= 1
    240               else
    241                    maxosc(j,ibox)= 0
    242               end if
    243             enddo
    244           endif
    245    
    246           ! Reset threshold
    247 
    248           include 'congvec.h'
    249 
    250           do j=1,npoints
    251             threshold(j,ibox)=
    252               !if max overlapped conv cloud
    253      &        maxocc(j,ibox) * (                                       
    254      &            boxpos(j,ibox)                                               
    255      &        ) +                                                     
    256               !else
    257      &        (1-maxocc(j,ibox)) * (                                   
    258                   !if max overlapped strat cloud
    259      &            (maxosc(j,ibox)) * (                                 
    260                       !threshold=boxpos
    261      &                threshold(j,ibox)                                       
    262      &            ) +                                                 
    263                   !else
    264      &            (1-maxosc(j,ibox)) * (                               
    265                       !threshold_min=random[thrmin,1]
    266      &                threshold_min(j,ibox)+
    267      &                  (1-threshold_min(j,ibox))*ran(j) 
    268      &           )
    269      &        )
    270           enddo
    271 
    272         ENDDO ! ibox
    273 
    274 !          Fill frac_out with 1's where tca is greater than the threshold
    275 
    276            DO ibox=1,ncol
    277              do j=1,npoints
    278                if (tca(j,ilev).gt.threshold(j,ibox)) then
    279                frac_out(j,ibox,ilev)=1
    280                else
    281                frac_out(j,ibox,ilev)=0
    282                end if               
    283              enddo
    284            ENDDO
    285 
    286 !         Code to partition boxes into startiform and convective parts
    287 !         goes here
    288 
    289            DO ibox=1,ncol
    290              do j=1,npoints
    291                 if (threshold(j,ibox).le.conv(j,ilev)) then
    292                     ! = 2 IF threshold le conv(j)
    293                     frac_out(j,ibox,ilev) = 2
    294                 else
    295                     ! = the same IF NOT threshold le conv(j)
    296                     frac_out(j,ibox,ilev) = frac_out(j,ibox,ilev)
    297                 end if
    298              enddo
    299            ENDDO
    300 
    301 !         Set last_frac to tca at this level, so as to be tca
    302 !         from last level next time round
    303 
    304           if (ncolprint.ne.0) then
    305 
    306             do j=1,npoints ,1000
     190          write (6,'(a)') 'threshold_nsf2:'
     191            do j=1,npoints,1000
    307192            write(6,'(a10)') 'j='
    308193            write(6,'(8I10)') j
    309             write (6,'(a)') 'last_frac:'
    310             write (6,'(8f5.2)') (tca(j,ilev-1))
    311    
    312             write (6,'(a)') 'conv:'
    313             write (6,'(8f5.2)') (conv(j,ilev),ibox=1,ncolprint)
    314    
    315             write (6,'(a)') 'max_overlap_cc:'
    316             write (6,'(8f5.2)') (maxocc(j,ibox),ibox=1,ncolprint)
    317    
    318             write (6,'(a)') 'max_overlap_sc:'
    319             write (6,'(8f5.2)') (maxosc(j,ibox),ibox=1,ncolprint)
    320    
    321             write (6,'(a)') 'threshold_min_nsf2:'
    322             write (6,'(8f5.2)') (threshold_min(j,ibox),ibox=1,ncolprint)
    323    
    324             write (6,'(a)') 'threshold_nsf2:'
    325194            write (6,'(8f5.2)') (threshold(j,ibox),ibox=1,ncolprint)
    326    
    327             write (6,'(a)') 'frac_out_pp_rev:'
    328             write (6,'(8f5.2)')
    329      &       ((frac_out(j,ibox,ilev2),ibox=1,ncolprint),ilev2=1,nlev)
    330           enddo
    331           endif
    332 
    333 200   CONTINUE    !loop over nlev
    334 
    335 
    336       end
    337 
     195            enddo
     196        ENDIF
     197    ENDIF
     198
     199    IF (ncolprint.ne.0) then
     200        write (6,'(a)') 'ilev:'
     201        write (6,'(I2)') ilev
     202    ENDIF
     203
     204    DO ibox=1,ncol
     205
     206      ! ! All versions
     207      do j=1,npoints
     208        if (boxpos(j,ibox).le.conv(j,ilev)) then
     209          maxocc(j,ibox) = 1
     210        else
     211          maxocc(j,ibox) = 0
     212        end if
     213      enddo
     214
     215      ! ! Max overlap
     216      if (overlap.eq.1) then
     217        do j=1,npoints
     218          threshold_min(j,ibox)=conv(j,ilev)
     219          maxosc(j,ibox)=1
     220        enddo
     221      endif
     222
     223      ! ! Random overlap
     224      if (overlap.eq.2) then
     225        do j=1,npoints
     226          threshold_min(j,ibox)=conv(j,ilev)
     227          maxosc(j,ibox)=0
     228        enddo
     229      endif
     230
     231      ! ! Max/Random overlap
     232      if (overlap.eq.3) then
     233        do j=1,npoints
     234          threshold_min(j,ibox)=max(conv(j,ilev), &
     235                min(tca(j,ilev-1),tca(j,ilev)))
     236          if (threshold(j,ibox) &
     237                .lt.min(tca(j,ilev-1),tca(j,ilev)) &
     238                .and.(threshold(j,ibox).gt.conv(j,ilev))) then
     239               maxosc(j,ibox)= 1
     240          else
     241               maxosc(j,ibox)= 0
     242          end if
     243        enddo
     244      endif
     245
     246      ! ! Reset threshold
     247
     248      include 'congvec.h'
     249
     250      do j=1,npoints
     251        threshold(j,ibox)= &
     252          ! !if max overlapped conv cloud
     253              maxocc(j,ibox) * ( &
     254              boxpos(j,ibox) &
     255              ) + &
     256          ! !else
     257              (1-maxocc(j,ibox)) * ( &
     258              ! !if max overlapped strat cloud
     259              (maxosc(j,ibox)) * ( &
     260                  ! !threshold=boxpos
     261              threshold(j,ibox) &
     262              ) + &
     263              ! !else
     264              (1-maxosc(j,ibox)) * ( &
     265                  ! !threshold_min=random[thrmin,1]
     266              threshold_min(j,ibox)+ &
     267              (1-threshold_min(j,ibox))*ran(j) &
     268              ) &
     269              )
     270      enddo
     271
     272    ENDDO ! ibox
     273
     274       ! Fill frac_out with 1's where tca is greater than the threshold
     275
     276       DO ibox=1,ncol
     277         do j=1,npoints
     278           if (tca(j,ilev).gt.threshold(j,ibox)) then
     279           frac_out(j,ibox,ilev)=1
     280           else
     281           frac_out(j,ibox,ilev)=0
     282           end if
     283         enddo
     284       ENDDO
     285
     286      ! Code to partition boxes into startiform and convective parts
     287      ! goes here
     288
     289       DO ibox=1,ncol
     290         do j=1,npoints
     291            if (threshold(j,ibox).le.conv(j,ilev)) then
     292                ! ! = 2 IF threshold le conv(j)
     293                frac_out(j,ibox,ilev) = 2
     294            else
     295                ! ! = the same IF NOT threshold le conv(j)
     296                frac_out(j,ibox,ilev) = frac_out(j,ibox,ilev)
     297            end if
     298         enddo
     299       ENDDO
     300
     301      ! Set last_frac to tca at this level, so as to be tca
     302      ! from last level next time round
     303
     304      if (ncolprint.ne.0) then
     305
     306        do j=1,npoints ,1000
     307        write(6,'(a10)') 'j='
     308        write(6,'(8I10)') j
     309        write (6,'(a)') 'last_frac:'
     310        write (6,'(8f5.2)') (tca(j,ilev-1))
     311
     312        write (6,'(a)') 'conv:'
     313        write (6,'(8f5.2)') (conv(j,ilev),ibox=1,ncolprint)
     314
     315        write (6,'(a)') 'max_overlap_cc:'
     316        write (6,'(8f5.2)') (maxocc(j,ibox),ibox=1,ncolprint)
     317
     318        write (6,'(a)') 'max_overlap_sc:'
     319        write (6,'(8f5.2)') (maxosc(j,ibox),ibox=1,ncolprint)
     320
     321        write (6,'(a)') 'threshold_min_nsf2:'
     322        write (6,'(8f5.2)') (threshold_min(j,ibox),ibox=1,ncolprint)
     323
     324        write (6,'(a)') 'threshold_nsf2:'
     325        write (6,'(8f5.2)') (threshold(j,ibox),ibox=1,ncolprint)
     326
     327        write (6,'(a)') 'frac_out_pp_rev:'
     328        write (6,'(8f5.2)') &
     329              ((frac_out(j,ibox,ilev2),ibox=1,ncolprint),ilev2=1,nlev)
     330      enddo
     331      endif
     332
     333  END DO
     334
     335
     336end subroutine scops
     337
Note: See TracChangeset for help on using the changeset viewer.