source: trunk/LMDZ.GENERIC/libf/phystd/optcv.F90 @ 1115

Last change on this file since 1115 was 1016, checked in by jleconte, 12 years ago

07/08/2013 == JL

  • Water cycle in double precision (largescale+moistadj)
  • Improved wate rayleigh.
  • First step for rayleigh with variable species. Now, just need to change optcv.
  • changed some interpolation indices in callcorrk to limit dependency of OLR on the number of layers
  • Property svn:executable set to *
File size: 11.7 KB
RevLine 
[716]1SUBROUTINE OPTCV(DTAUV,TAUV,TAUCUMV,PLEV,  &
2     QXVAER,QSVAER,GVAER,WBARV,COSBV,       &
3     TAURAY,TAUAERO,TMID,PMID,TAUGSURF,QVAR,MUVAR)
[253]4
[716]5  use radinc_h
[873]6  use radcommon_h, only: gasv, tlimit, wrefVAR, Cmk, tgasref, pfgasref,wnov,scalep,indv
[716]7  use gases_h
[253]8
[716]9  implicit none
[253]10
[716]11  !==================================================================
12  !     
13  !     Purpose
14  !     -------
15  !     Calculates shortwave optical constants at each level.
16  !     
17  !     Authors
18  !     -------
19  !     Adapted from the NASA Ames code by R. Wordsworth (2009)
20  !     
21  !==================================================================
22  !     
23  !     THIS SUBROUTINE SETS THE OPTICAL CONSTANTS IN THE VISUAL 
24  !     IT CALCUALTES FOR EACH LAYER, FOR EACH SPECRAL INTERVAL IN THE VISUAL
25  !     LAYER: WBAR, DTAU, COSBAR
26  !     LEVEL: TAU
27  !     
28  !     TAUV(L,NW,NG) is the cumulative optical depth at the top of radiation code
29  !     layer L. NW is spectral wavelength interval, ng the Gauss point index.
30  !     
31  !     TLEV(L) - Temperature at the layer boundary
32  !     PLEV(L) - Pressure at the layer boundary (i.e. level)
33  !     GASV(NT,NPS,NW,NG) - Visible k-coefficients
34  !     
35  !-------------------------------------------------------------------
[253]36
[873]37#include "comcstfi.h"
[253]38#include "callkeys.h"
39
[873]40
[716]41  real*8 DTAUV(L_NLAYRAD,L_NSPECTV,L_NGAUSS)
42  real*8 DTAUKV(L_LEVELS+1,L_NSPECTV,L_NGAUSS)
43  real*8 TAUV(L_NLEVRAD,L_NSPECTV,L_NGAUSS)
44  real*8 TAUCUMV(L_LEVELS,L_NSPECTV,L_NGAUSS)
45  real*8 PLEV(L_LEVELS)
46  real*8 TMID(L_LEVELS), PMID(L_LEVELS)
47  real*8 COSBV(L_NLAYRAD,L_NSPECTV,L_NGAUSS)
48  real*8 WBARV(L_NLAYRAD,L_NSPECTV,L_NGAUSS)
[253]49
[716]50  ! for aerosols
[873]51  real*8  QXVAER(L_LEVELS+1,L_NSPECTV,NAERKIND)
52  real*8  QSVAER(L_LEVELS+1,L_NSPECTV,NAERKIND)
53  real*8  GVAER(L_LEVELS+1,L_NSPECTV,NAERKIND)
54  real*8  TAUAERO(L_LEVELS+1,NAERKIND)
55  real*8  TAUAEROLK(L_LEVELS+1,L_NSPECTV,NAERKIND)
56  real*8  TAEROS(L_LEVELS,L_NSPECTV,NAERKIND)
[253]57
[873]58  integer L, NW, NG, K, LK, IAER
[716]59  integer MT(L_LEVELS), MP(L_LEVELS), NP(L_LEVELS)
60  real*8  ANS, TAUGAS
[873]61  real*8  TAURAY(L_NSPECTV)
[716]62  real*8  TRAY(L_LEVELS,L_NSPECTV)
[873]63  real*8  TRAYAER
[716]64  real*8  DPR(L_LEVELS), U(L_LEVELS)
65  real*8  LCOEF(4), LKCOEF(L_LEVELS,4)
[253]66
[873]67  real*8 taugsurf(L_NSPECTV,L_NGAUSS-1)
[918]68  real*8 DCONT,DAERO
[873]69  double precision wn_cont, p_cont, p_air, T_cont, dtemp, dtempc
70  double precision p_cross
[253]71
[716]72  ! variable species mixing ratio variables
[873]73  real*8  QVAR(L_LEVELS), WRATIO(L_LEVELS), MUVAR(L_LEVELS)
74  real*8  KCOEF(4)
[716]75  integer NVAR(L_LEVELS)
[253]76
[716]77  ! temporary variables for multiple aerosol calculation
[918]78  real*8 atemp(L_NLAYRAD,L_NSPECTV)
79  real*8 btemp(L_NLAYRAD,L_NSPECTV)
80  real*8 ctemp(L_NLAYRAD,L_NSPECTV)
[253]81
[716]82  ! variables for k in units m^-1
[873]83  real*8 dz(L_LEVELS)
[253]84
[716]85  integer igas, jgas
[253]86
[873]87  integer interm
88
89  !! AS: to save time in computing continuum (see bilinearbig)
90  IF (.not.ALLOCATED(indv)) THEN
[878]91      ALLOCATE(indv(L_NSPECTV,ngasmx,ngasmx))
[873]92      indv = -9999 ! this initial value means "to be calculated"
93  ENDIF
94
[716]95  !=======================================================================
96  !     Determine the total gas opacity throughout the column, for each
97  !     spectral interval, NW, and each Gauss point, NG.
98  !     Calculate the continuum opacities, i.e., those that do not depend on
99  !     NG, the Gauss index.
[253]100
[716]101  taugsurf(:,:) = 0.0
102  dpr(:)        = 0.0
103  lkcoef(:,:)   = 0.0
[253]104
[716]105  do K=2,L_LEVELS
106     DPR(k) = PLEV(K)-PLEV(K-1)
[253]107
[716]108     ! if we have continuum opacities, we need dz
109     if(kastprof)then
[1016]110        dz(k) = dpr(k)*(1000.0d0*8.3145d0/muvar(k))*TMID(K)/(g*PMID(K))
111        U(k)  = Cmk*DPR(k)*mugaz/muvar(k)
[716]112     else
[1016]113        dz(k) = dpr(k)*R*TMID(K)/(g*PMID(K))*mugaz/muvar(k)
114        U(k)  = Cmk*DPR(k)*mugaz/muvar(k)     ! only Cmk line in optci.F 
115            !JL13 the mugaz/muvar factor takes into account water meanmolecular weight if water is present
[716]116     endif
[253]117
[716]118     call tpindex(PMID(K),TMID(K),QVAR(K),pfgasref,tgasref,WREFVAR, &
119          LCOEF,MT(K),MP(K),NVAR(K),WRATIO(K))
[253]120
[716]121     do LK=1,4
122        LKCOEF(K,LK) = LCOEF(LK)
123     end do
[918]124  end do                    ! levels
[253]125
[873]126
[918]127  do iaer=1,naerkind
128     do NW=1,L_NSPECTV
129        do K=2,L_LEVELS
[873]130           TAEROS(K,NW,IAER) = TAUAERO(K,IAER) * QXVAER(K,NW,IAER)
[918]131        end do                    ! levels
132     end do
133  end do
134  do NW=1,L_NSPECTV
135     do K=2,L_LEVELS
[873]136        TRAY(K,NW)   = TAURAY(NW) * DPR(K)
[918]137     end do                    ! levels
138  end do
139 
[716]140  !     we ignore K=1...
141  do K=2,L_LEVELS
[873]142
[716]143     do NW=1,L_NSPECTV
[253]144
[716]145        TRAYAER = TRAY(K,NW)
[873]146        !     TRAYAER is Tau RAYleigh scattering, plus AERosol opacity
[716]147        do iaer=1,naerkind
148           TRAYAER = TRAYAER + TAEROS(K,NW,IAER)
149        end do
[253]150
[716]151        DCONT = 0.0 ! continuum absorption
[253]152
[873]153        if(continuum.and.(.not.graybody).and.callgasvis)then
[716]154           ! include continua if necessary
155           wn_cont = dble(wnov(nw))
156           T_cont  = dble(TMID(k))
157           do igas=1,ngasmx
[305]158
[716]159              if(gfrac(igas).eq.-1)then ! variable
160                 p_cont  = dble(PMID(k)*scalep*QVAR(k)) ! qvar = mol/mol
161              else
162                 p_cont  = dble(PMID(k)*scalep*gfrac(igas)*(1.-QVAR(k)))
163              endif
[305]164
[716]165              dtemp=0.0
166              if(igas.eq.igas_N2)then
[253]167
[878]168                 interm = indv(nw,igas,igas)
169!                 call interpolateN2N2(wn_cont,T_cont,p_cont,dtemp,.false.,interm)
170                 indv(nw,igas,igas) = interm
[716]171                 ! only goes to 500 cm^-1, so unless we're around a cold brown dwarf, this is irrelevant in the visible
[253]172
[716]173              elseif(igas.eq.igas_H2)then
[253]174
[716]175                 ! first do self-induced absorption
[878]176                 interm = indv(nw,igas,igas)
[873]177                 call interpolateH2H2(wn_cont,T_cont,p_cont,dtemp,.false.,interm)
[878]178                 indv(nw,igas,igas) = interm
[253]179
[716]180                 ! then cross-interactions with other gases
181                 do jgas=1,ngasmx
182                    p_cross = dble(PMID(k)*scalep*gfrac(jgas)*(1.-QVAR(k)))
[873]183                    dtempc  = 0.0
184                    if(jgas.eq.igas_N2)then
[878]185                       interm = indv(nw,igas,jgas)
186                       call interpolateN2H2(wn_cont,T_cont,p_cross,p_cont,dtempc,.false.,interm)
187                       indv(nw,igas,jgas) = interm
[716]188                       ! should be irrelevant in the visible
189                    elseif(jgas.eq.igas_He)then
[878]190                       interm = indv(nw,igas,jgas)
[873]191                       call interpolateH2He(wn_cont,T_cont,p_cross,p_cont,dtempc,.false.,interm)
[878]192                       indv(nw,igas,jgas) = interm
[716]193                    endif
[873]194                    dtemp = dtemp + dtempc
[716]195                 enddo
[253]196
[716]197              elseif(igas.eq.igas_H2O.and.T_cont.gt.200.0)then
[253]198
[716]199                 p_air = dble(PMID(k)*scalep) - p_cont ! note assumes background is air!
200                 if(H2Ocont_simple)then
201                    call interpolateH2Ocont_PPC(wn_cont,T_cont,p_cont,p_air,dtemp,.false.)
202                 else
[878]203                    interm = indv(nw,igas,igas)
204                    call interpolateH2Ocont_CKD(wn_cont,T_cont,p_cont,p_air,dtemp,.false.,interm)
205                    indv(nw,igas,igas) = interm
[716]206                 endif
[253]207
[716]208              endif
[253]209
[716]210              DCONT = DCONT + dtemp
[253]211
[716]212           enddo
[253]213
[873]214           DCONT = DCONT*dz(k)
215
[716]216        endif
[253]217
[873]218        do ng=1,L_NGAUSS-1
[305]219
[873]220           ! Now compute TAUGAS
[253]221
[873]222           ! Interpolate between water mixing ratios
223           ! WRATIO = 0.0 if the requested water amount is equal to, or outside the
224           ! the water data range
225
226           if(L_REFVAR.eq.1)then ! added by RW for special no variable case
[716]227              KCOEF(1) = GASV(MT(K),MP(K),1,NW,NG)
228              KCOEF(2) = GASV(MT(K),MP(K)+1,1,NW,NG)
229              KCOEF(3) = GASV(MT(K)+1,MP(K)+1,1,NW,NG)
230              KCOEF(4) = GASV(MT(K)+1,MP(K),1,NW,NG)
231           else
[873]232
[716]233              KCOEF(1) = GASV(MT(K),MP(K),NVAR(K),NW,NG) + WRATIO(K)*    &
234                   (GASV(MT(K),MP(K),NVAR(K)+1,NW,NG) -                  &
235                   GASV(MT(K),MP(K),NVAR(K),NW,NG))
[253]236
[716]237              KCOEF(2) = GASV(MT(K),MP(K)+1,NVAR(K),NW,NG) + WRATIO(K)*  &
238                   (GASV(MT(K),MP(K)+1,NVAR(K)+1,NW,NG) -                &
239                   GASV(MT(K),MP(K)+1,NVAR(K),NW,NG))
[253]240
[716]241              KCOEF(3) = GASV(MT(K)+1,MP(K)+1,NVAR(K),NW,NG) + WRATIO(K)*&
242                   (GASV(MT(K)+1,MP(K)+1,NVAR(K)+1,NW,NG) -              &
243                   GASV(MT(K)+1,MP(K)+1,NVAR(K),NW,NG))
[253]244
[716]245              KCOEF(4) = GASV(MT(K)+1,MP(K),NVAR(K),NW,NG) + WRATIO(K)*  &
246                   (GASV(MT(K)+1,MP(K),NVAR(K)+1,NW,NG) -                &
247                   GASV(MT(K)+1,MP(K),NVAR(K),NW,NG))
[873]248
[716]249           endif
[253]250
[873]251           ! Interpolate the gaseous k-coefficients to the requested T,P values
[253]252
[873]253           ANS = LKCOEF(K,1)*KCOEF(1) + LKCOEF(K,2)*KCOEF(2) +            &
[716]254                LKCOEF(K,3)*KCOEF(3) + LKCOEF(K,4)*KCOEF(4)
[253]255
[873]256           TAUGAS  = U(k)*ANS
[253]257
[716]258           TAUGSURF(NW,NG) = TAUGSURF(NW,NG) + TAUGAS + DCONT
[873]259           DTAUKV(K,nw,ng) = TAUGAS &
260                             + TRAYAER & ! TRAYAER includes all scattering contributions
261                             + DCONT ! For parameterized continuum aborption
[253]262
[716]263        end do
[253]264
[873]265        ! Now fill in the "clear" part of the spectrum (NG = L_NGAUSS),
266        ! which holds continuum opacity only
[253]267
[873]268        NG              = L_NGAUSS
269        DTAUKV(K,nw,ng) = TRAY(K,NW) + DCONT ! For parameterized continuum absorption
[253]270
[716]271        do iaer=1,naerkind
[873]272           DTAUKV(K,nw,ng) = DTAUKV(K,nw,ng) +  TAEROS(K,NW,IAER)
[716]273        end do ! a bug was here!
[253]274
[716]275     end do
276  end do
[253]277
278
[716]279  !=======================================================================
280  !     Now the full treatment for the layers, where besides the opacity
281  !     we need to calculate the scattering albedo and asymmetry factors
[253]282
[873]283  do iaer=1,naerkind
[918]284    DO NW=1,L_NSPECTV
285      DO K=2,L_LEVELS   ! AS: shouldn't this be L_LEVELS+1 ? (see optci)
[716]286           TAUAEROLK(K,NW,IAER) = TAUAERO(K,IAER) * QSVAER(K,NW,IAER)
[918]287      ENDDO
288    ENDDO
[873]289  end do
[253]290
[716]291  DO NW=1,L_NSPECTV
[919]292     DO L=1,L_NLAYRAD-1
[918]293        K              = 2*L+1
294        atemp(L,NW) = SUM(GVAER(K,NW,1:naerkind) * TAUAEROLK(K,NW,1:naerkind))+SUM(GVAER(K+1,NW,1:naerkind) * TAUAEROLK(K+1,NW,1:naerkind))
295        btemp(L,NW) = SUM(TAUAEROLK(K,NW,1:naerkind)) + SUM(TAUAEROLK(K+1,NW,1:naerkind))
296        ctemp(L,NW) = btemp(L,NW) + 0.9999*(TRAY(K,NW) + TRAY(K+1,NW))
297        btemp(L,NW) = btemp(L,NW) + TRAY(K,NW) + TRAY(K+1,NW)
298        COSBV(L,NW,1:L_NGAUSS) = atemp(L,NW)/btemp(L,NW)
299     END DO ! L vertical loop
[919]300     
301     !last level
302     L              = L_NLAYRAD
303     K              = 2*L+1
304     atemp(L,NW)    = SUM(GVAER(K,NW,1:naerkind) * TAUAEROLK(K,NW,1:naerkind))
305     btemp(L,NW) = SUM(TAUAEROLK(K,NW,1:naerkind))
306     ctemp(L,NW) = btemp(L,NW) + 0.9999*TRAY(K,NW)
307     btemp(L,NW) = btemp(L,NW) + TRAY(K,NW)
308     COSBV(L,NW,1:L_NGAUSS) = atemp(L,NW)/btemp(L,NW)
309     
310     
[918]311  END DO                    ! NW spectral loop
312
313  DO NG=1,L_NGAUSS
314    DO NW=1,L_NSPECTV
[873]315     DO L=1,L_NLAYRAD-1
[253]316
[873]317        K              = 2*L+1
318        DTAUV(L,nw,ng) = DTAUKV(K,NW,NG) + DTAUKV(K+1,NW,NG)
[918]319        WBARV(L,nw,ng) = ctemp(L,NW) / DTAUV(L,nw,ng)
[253]320
[873]321      END DO ! L vertical loop
[253]322
[716]323        !     No vertical averaging on bottom layer
[253]324
[716]325        L              = L_NLAYRAD
326        K              = 2*L+1
[919]327        DTAUV(L,nw,ng) = DTAUKV(K,NW,NG)
328
329        WBARV(L,NW,NG) = ctemp(L,NW) / DTAUV(L,NW,NG)
[918]330     END DO                 ! NW spectral loop
331  END DO                    ! NG Gauss loop
[716]332
333  ! Total extinction optical depths
334
[918]335  DO NG=1,L_NGAUSS       ! full gauss loop
336     DO NW=1,L_NSPECTV       
[716]337        TAUV(1,NW,NG)=0.0D0
338        DO L=1,L_NLAYRAD
339           TAUV(L+1,NW,NG)=TAUV(L,NW,NG)+DTAUV(L,NW,NG)
340        END DO
341
342        TAUCUMV(1,NW,NG)=0.0D0
343        DO K=2,L_LEVELS
344           TAUCUMV(K,NW,NG)=TAUCUMV(K-1,NW,NG)+DTAUKV(K,NW,NG)
345        END DO
[918]346     END DO           
347  END DO                 ! end full gauss loop
[716]348
349
[873]350  return
351
352
353end subroutine optcv
Note: See TracBrowser for help on using the repository browser.