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

Last change on this file since 1717 was 1715, checked in by jvatant, 9 years ago

Cleaning of the radiative code + coherence between optci and optcv :

+ Get rid of the actually dummy and confusing extra level L_LEVELS+1 for aerosols
+ Harmonisation between optci and optcv
+ Get rid of tauref (called nowhere) and csqtly of ini_radcommon subroutine

JVO

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