source: trunk/LMDZ.PLUTO/libf/phypluto/callcorrk_pluto_mod.F90 @ 3334

Last change on this file since 3334 was 3329, checked in by afalco, 9 months ago

Pluto PCM:
Include cooling, hazes in radiative module
AF

File size: 32.4 KB
Line 
1MODULE callcorrk_pluto_mod
2
3IMPLICIT NONE
4
5CONTAINS
6
7    subroutine callcorrk_pluto(icount,ngrid,nlayer,pq,nq,qsurf,   &
8          albedo,emis,mu0,pplev,pplay,pt,   &
9          zzlay,tsurf,fract,dist_star,aerosol,    &
10          dtlw,dtsw,fluxsurf_lw,    &
11          fluxsurf_sw,fluxtop_lw,fluxtop_sw,fluxtop_dn, &
12          reffrad,tau_col,ptime,pday,cloudfrac,totcloudfrac,   &
13          clearsky,firstcall,lastcall)
14
15      use radinc_h
16      use radcommon_h
17      use ioipsl_getincom
18      use suaer_corrk_mod, only: suaer_corrk
19      use radii_mod, only: su_aer_radii,haze_reffrad_fix
20      use aeropacity_mod, only: aeropacity
21      use aeroptproperties_mod, only: aeroptproperties
22      use aerosol_mod, only : iaero_haze
23      use datafile_mod, only: datadir
24      use comcstfi_mod, only: pi,g,cpp,mugaz
25      use tracer_h, only: igcm_n2,igcm_ch4_gas,igcm_ch4_ice,rho_ch4_ice,lw_ch4,&
26                          mmol
27      use callkeys_mod, only: aerohaze,ch4fix,cooling,methane,nlte,&
28                              strobel,vmrch4_proffix,specOLR,vmrch4fix,&
29                              haze_radproffix
30      use optcv_pluto_mod, only: optcv_pluto
31      use optci_pluto_mod, only: optci_pluto
32      use sfluxi_pluto_mod, only: sfluxi_pluto
33      use sfluxv_pluto_mod, only: sfluxv_pluto
34
35
36      implicit none
37
38!==================================================================
39!
40!     Purpose
41!     -------
42!     Solve the radiative transfer using the correlated-k method for
43!     the gaseous absorption and the Toon et al. (1989) method for
44!     scatttering due to aerosols.
45!
46!     Authors
47!     -------
48!     Emmanuel 01/2001, Forget 09/2001
49!     Robin Wordsworth (2009)
50!     Modif Pluton Tanguy Bertrand 2017
51!==================================================================
52
53include "dimensions.h"
54
55!-----------------------------------------------------------------------
56!     Declaration of the arguments (INPUT - OUTPUT) on the LMD GCM grid
57!     Layer #1 is the layer near the ground.
58!     Layer #nlayer is the layer at the top.
59
60!     INPUT
61      INTEGER icount
62      INTEGER ngrid,nlayer
63      REAL aerosol(ngrid,nlayer,naerkind) ! aerosol opacity tau
64      REAL albedo(ngrid)                    ! SW albedo
65      REAL emis(ngrid)                      ! LW emissivity
66      REAL pplay(ngrid,nlayer)            ! pres. level in GCM mid of layer
67      REAL zzlay(ngrid,nlayer)            ! altitude at the middle of the layers
68      REAL pplev(ngrid,nlayer+1)          ! pres. level at GCM layer boundaries
69      REAL cloudfrac(ngrid,nlayer)   ! Fraction of clouds (%).
70      logical clearsky
71
72      REAL pt(ngrid,nlayer)               ! air temperature (K)
73      REAL tsurf(ngrid)                     ! surface temperature (K)
74      REAL dist_star,mu0(ngrid)             ! distance star-planet (AU)
75      REAL fract(ngrid)                     ! fraction of day
76
77!     Globally varying aerosol optical properties on GCM grid
78!     Not needed everywhere so not in radcommon_h
79      REAL :: QVISsQREF3d(ngrid,nlayer,L_NSPECTV,naerkind)
80      REAL :: omegaVIS3d(ngrid,nlayer,L_NSPECTV,naerkind)
81      REAL :: gVIS3d(ngrid,nlayer,L_NSPECTV,naerkind)
82
83      REAL :: QIRsQREF3d(ngrid,nlayer,L_NSPECTI,naerkind)
84      REAL :: omegaIR3d(ngrid,nlayer,L_NSPECTI,naerkind)
85      REAL :: gIR3d(ngrid,nlayer,L_NSPECTI,naerkind)
86
87      REAL :: QREFvis3d(ngrid,nlayer,naerkind)
88      REAL :: QREFir3d(ngrid,nlayer,naerkind)
89
90!      REAL :: omegaREFvis3d(ngrid,nlayer,naerkind)
91!      REAL :: omegaREFir3d(ngrid,nlayer,naerkind) ! not sure of the point of these...
92
93      REAL reffrad(ngrid,nlayer,naerkind)
94      REAL nueffrad(ngrid,nlayer,naerkind)
95      REAL profhaze(ngrid,nlayer) ! TB17 fixed profile of haze mmr
96
97!     OUTPUT
98      REAL dtsw(ngrid,nlayer) ! heating rate (K/s) due to SW
99      REAL dtlw(ngrid,nlayer) ! heating rate (K/s) due to LW
100      REAL fluxsurf_lw(ngrid)   ! incident LW flux to surf (W/m2)
101      REAL fluxtop_lw(ngrid)    ! outgoing LW flux to space (W/m2)
102      REAL fluxsurf_sw(ngrid)   ! incident SW flux to surf (W/m2)
103      REAL fluxtop_sw(ngrid)    ! outgoing LW flux to space (W/m2)
104      REAL fluxtop_dn(ngrid)    ! incident top of atmosphere SW flux (W/m2)
105      REAL totcloudfrac(ngrid)            ! Column Fraction of clouds (%).
106
107!-----------------------------------------------------------------------
108!     Declaration of the variables required by correlated-k subroutines
109!     Numbered from top to bottom unlike in the GCM!
110
111      REAL*8 tmid(L_LEVELS),pmid(L_LEVELS)
112      REAL*8 tlevrad(L_LEVELS),plevrad(L_LEVELS)
113
114!     Optical values for the optci/cv subroutines
115      REAL*8 stel(L_NSPECTV),stel_fract(L_NSPECTV)
116      REAL*8 dtaui(L_NLAYRAD,L_NSPECTI,L_NGAUSS)
117      REAL*8 dtauv(L_NLAYRAD,L_NSPECTV,L_NGAUSS)
118      REAL*8 cosbv(L_NLAYRAD,L_NSPECTV,L_NGAUSS)
119      REAL*8 cosbi(L_NLAYRAD,L_NSPECTI,L_NGAUSS)
120      REAL*8 wbari(L_NLAYRAD,L_NSPECTI,L_NGAUSS)
121      REAL*8 wbarv(L_NLAYRAD,L_NSPECTV,L_NGAUSS)
122      REAL*8 tauv(L_NLEVRAD,L_NSPECTV,L_NGAUSS)
123      REAL*8 taucumv(L_LEVELS,L_NSPECTV,L_NGAUSS)
124      REAL*8 taucumi(L_LEVELS,L_NSPECTI,L_NGAUSS)
125
126      REAL*8 tauaero(L_LEVELS+1,naerkind)
127      REAL*8 nfluxtopv,nfluxtopi,nfluxtop
128      real*8 NFLUXTOPV_nu(L_NSPECTV)
129      real*8 NFLUXTOPI_nu(L_NSPECTI)
130      real*8 fluxupi_nu(L_NLAYRAD,L_NSPECTI) ! for 1D diagnostic
131      REAL*8 fmneti(L_NLAYRAD),fmnetv(L_NLAYRAD)
132      real*8 fmneti_nu(L_NLAYRAD,L_NSPECTI) !
133      real*8 fmnetv_nu(L_NLAYRAD,L_NSPECTV) !
134      REAL*8 fluxupv(L_NLAYRAD),fluxupi(L_NLAYRAD)
135      REAL*8 fluxdnv(L_NLAYRAD),fluxdni(L_NLAYRAD)
136      REAL*8 albi,albv,acosz
137
138      INTEGER ig,l,k,nw,iaer,irad
139
140      real fluxtoplanet
141      real*8 taugsurf(L_NSPECTV,L_NGAUSS-1)
142      real*8 taugsurfi(L_NSPECTI,L_NGAUSS-1)
143
144      real*8 qvar(L_LEVELS)          ! mixing ratio of variable component
145      REAL pq(ngrid,nlayer,nq)
146      REAL qsurf(ngrid,nq)       ! tracer on surface (e.g. kg.m-2)
147      integer nq
148
149!     Local aerosol optical properties for each column on RADIATIVE grid
150      real*8  QXVAER(L_LEVELS+1,L_NSPECTV,naerkind)
151      real*8  QSVAER(L_LEVELS+1,L_NSPECTV,naerkind)
152      real*8  GVAER(L_LEVELS+1,L_NSPECTV,naerkind)
153      real*8  QXIAER(L_LEVELS+1,L_NSPECTI,naerkind)
154      real*8  QSIAER(L_LEVELS+1,L_NSPECTI,naerkind)
155      real*8  GIAER(L_LEVELS+1,L_NSPECTI,naerkind)
156
157    !   save qxvaer, qsvaer, gvaer
158    !   save qxiaer, qsiaer, giaer
159    !   save QREFvis3d, QREFir3d
160
161      REAL tau_col(ngrid) ! diagnostic from aeropacity
162
163!     Misc.
164      logical firstcall, lastcall, nantest
165      real*8  tempv(L_NSPECTV)
166      real*8  tempi(L_NSPECTI)
167      real*8  temp,temp1,temp2,pweight
168      character(len=10) :: tmp1
169      character(len=10) :: tmp2
170
171!     for fixed vapour profiles
172      real RH
173      real*8 pq_temp(nlayer)
174      real ptemp, Ttemp, qsat
175
176!     for OLR spec
177      integer OLRcount
178      save OLRcount
179      integer OLRcount2
180      save OLRcount2
181      character(len=2)  :: tempOLR
182      character(len=30) :: filenomOLR
183      real ptime, pday
184
185      REAL epsi_ch4
186      SAVE epsi_ch4
187
188      logical diagrad_OLRz,diagrad_OLR,diagrad_surf,diagrad_rates
189      real OLR_nu(ngrid,L_NSPECTI)
190
191!     NLTE factor for CH4
192      real eps_nlte_sw23(ngrid,nlayer) ! CH4 NLTE efficiency factor for zdtsw
193      real eps_nlte_sw33(ngrid,nlayer) ! CH4 NLTE efficiency factor for zdtsw
194      real eps_nlte_lw(ngrid,nlayer) ! CH4 NLTE efficiency factor for zdtsw
195      REAL dtlw_nu(nlayer,L_NSPECTI) ! heating rate (K/s) due to LW in spectral bands
196      REAL dtsw_nu(nlayer,L_NSPECTV) ! heating rate (K/s) due to SW in spectral bands
197
198      REAL dpp  ! intermediate
199
200      REAL dtlw_co(ngrid, nlayer) ! cooling rate (K/s) due to CO (diagnostic)
201      REAL dtlw_hcn_c2h2(ngrid, nlayer) ! cooling rate (K/s) due to C2H2/HCN (diagnostic)
202
203      !!read altitudes and vmrch4
204      integer Nfine,ifine
205      parameter(Nfine=701)
206      character(len=100) :: file_path
207      real,save :: levdat(Nfine),vmrdat(Nfine)
208      real :: vmrch4(ngrid,nlayer)              ! vmr ch4 from vmrch4_proffix
209
210!=======================================================================
211!     Initialization on first call
212
213      qxvaer(:,:,:) = 0
214      qsvaer(:,:,:) = 0
215      gvaer(:,:,:) = 0
216
217      qxiaer(:,:,:) = 0
218      qsiaer(:,:,:) = 0
219      giaer(:,:,:) = 0
220
221
222      if(firstcall) then
223
224         print*, "callcorrk: Correlated-k data folder:",trim(datadir)
225         call getin("corrkdir",corrkdir)
226         print*, "corrkdir = ",corrkdir
227         write( tmp1, '(i3)' ) L_NSPECTI
228         write( tmp2, '(i3)' ) L_NSPECTV
229         banddir=trim(adjustl(tmp1))//'x'//trim(adjustl(tmp2))
230         banddir=trim(adjustl(corrkdir))//'/'//trim(adjustl(banddir))
231
232         print*,'starting sugas'
233         call sugas_corrk       ! set up gaseous absorption properties
234         print*,'starting setspi'
235         call setspi            ! basic infrared properties
236         print*,'starting setspv'
237         call setspv            ! basic visible properties
238
239         ! Radiative Hazes
240         if (aerohaze) then
241
242           print*,'aerohaze: starting suaer_corrk'
243           call suaer_corrk       ! set up aerosol optical properties
244           print*,'ending suaer_corrk'
245
246           !--------------------------------------------------
247           !     Effective radius and variance of the aerosols
248           !--------------------------------------------------
249           do iaer=1,naerkind
250              if ((iaer.eq.iaero_haze)) then
251               call su_aer_radii(ngrid,nlayer,reffrad(1,1,iaer),    &
252                  nueffrad(1,1,iaer))
253                ! write(*,*) "Not supported yet"
254                ! STOP
255              endif
256           end do !iaer=1,naerkind.
257           if (haze_radproffix) then
258              print*, 'haze_radproffix=T : fixed profile for haze rad'
259           else
260              print*,'reffrad haze:',reffrad(1,1,iaero_haze)
261              print*,'nueff haze',nueffrad(1,1,iaero_haze)
262           endif
263         endif ! radiative haze
264
265         Cmk= 0.01 * 1.0 / (g * mugaz * 1.672621e-27) ! q_main=1.0 assumed
266
267         epsi_ch4=mmol(igcm_ch4_gas)/mmol(igcm_n2)
268
269         ! If fixed profile of CH4 gas
270         IF (vmrch4_proffix) then
271            file_path=trim(datadir)//'/gas_prop/vmr_ch4.txt'
272            open(115,file=file_path,form='formatted')
273            do ifine=1,Nfine
274              read(115,*) levdat(ifine), vmrdat(ifine)
275            enddo
276            close(115)
277         ENDIF
278
279      end if ! firstcall
280
281!=======================================================================
282
283!     L_NSPECTV is the number of Visual(or Solar) spectral intervals
284!     how much light we get
285      fluxtoplanet=0
286      DO nw=1,L_NSPECTV
287         stel(nw)=stellarf(nw)/(dist_star**2)  !flux
288         fluxtoplanet=fluxtoplanet + stel(nw)
289      END DO
290
291!-----------------------------------------------------------------------
292!     Get 3D aerosol optical properties.
293      ! ici on selectionne les proprietes opt correspondant a reffrad
294      if (aerohaze) then
295        !--------------------------------------------------
296        ! Effective radius and variance of the aerosols if profil non
297        ! uniform. Called only if aerohaze=true.
298        !--------------------------------------------------
299        if (haze_radproffix) then
300          call haze_reffrad_fix(ngrid,nlayer,zzlay, &
301              reffrad,nueffrad)
302        endif
303
304        call aeroptproperties(ngrid,nlayer,reffrad,nueffrad,         &
305            QVISsQREF3d,omegaVIS3d,gVIS3d,                          &
306            QIRsQREF3d,omegaIR3d,gIR3d,                             &
307            QREFvis3d,QREFir3d)
308
309        ! Get aerosol optical depths.
310        call aeropacity(ngrid,nlayer,nq,pplay,pplev, pt,pq,aerosol,      &
311            reffrad,nueffrad,QREFvis3d,QREFir3d,                             &
312            tau_col,cloudfrac,totcloudfrac,clearsky)
313      endif
314
315!-----------------------------------------------------------------------
316!     Prepare CH4 mixing ratio for radiative transfer
317      IF (methane) then
318        vmrch4(:,:)=0.
319
320        if (ch4fix) then
321           if (vmrch4_proffix) then
322            !! Interpolate on the model vertical grid
323             do ig=1,ngrid
324               CALL interp_line(levdat,vmrdat,Nfine,    &
325                       zzlay(ig,:)/1000.,vmrch4(ig,:),nlayer)
326             enddo
327           else
328            vmrch4(:,:)=vmrch4fix
329           endif
330        else
331            vmrch4(:,:)=pq(:,:,igcm_ch4_gas)*100.*  &
332                         mmol(igcm_n2)/mmol(igcm_ch4_gas)
333        endif
334      ENDIF
335
336!     Prepare NON LTE correction in Pluto atmosphere
337      IF (nlte) then
338        CALL nlte_ch4(ngrid,nlayer,nq,pplay,pplev,pt,vmrch4,    &
339                  eps_nlte_sw23,eps_nlte_sw33,eps_nlte_lw)
340      ENDIF
341!     Net atmospheric radiative cooling rate from C2H2 (K.s-1):
342!     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
343      dtlw_hcn_c2h2=0.
344      if (cooling) then
345         CALL cooling_hcn_c2h2(ngrid,nlayer,pplay,  &
346                                  pt,dtlw_hcn_c2h2)
347        ! write(*,*) "Not supported yet"
348        STOP
349      endif
350
351!-----------------------------------------------------------------------
352!=======================================================================
353!-----------------------------------------------------------------------
354!     starting big loop over every GCM column
355      do ig=1,ngrid
356
357!=======================================================================
358!     Transformation of the GCM variables
359
360!-----------------------------------------------------------------------
361!     Aerosol optical properties Qext, Qscat and g on each band
362!     The transformation in the vertical is the same as for temperature
363         if (aerohaze) then
364!     shortwave
365            do iaer=1,naerkind
366               DO nw=1,L_NSPECTV
367                  do l=1,nlayer
368
369                     temp1=QVISsQREF3d(ig,nlayer+1-l,nw,iaer) &
370                         *QREFvis3d(ig,nlayer+1-l,iaer)
371
372                     temp2=QVISsQREF3d(ig,max(nlayer-l,1),nw,iaer)    &
373                         *QREFvis3d(ig,max(nlayer-l,1),iaer)
374                     qxvaer(2*l,nw,iaer)  = temp1
375                     qxvaer(2*l+1,nw,iaer)=(temp1+temp2)/2
376
377                    temp1=temp1*omegavis3d(ig,nlayer+1-l,nw,iaer)
378                    temp2=temp2*omegavis3d(ig,max(nlayer-l,1),nw,iaer)
379
380                     qsvaer(2*l,nw,iaer)  = temp1
381                     qsvaer(2*l+1,nw,iaer)=(temp1+temp2)/2
382
383                     temp1=gvis3d(ig,nlayer+1-l,nw,iaer)
384                     temp2=gvis3d(ig,max(nlayer-l,1),nw,iaer)
385
386                     gvaer(2*l,nw,iaer)  = temp1
387                     gvaer(2*l+1,nw,iaer)=(temp1+temp2)/2
388
389                  end do
390                  qxvaer(1,nw,iaer)=qxvaer(2,nw,iaer)
391                  qxvaer(2*nlayer+1,nw,iaer)=0.
392
393                  qsvaer(1,nw,iaer)=qsvaer(2,nw,iaer)
394                  qsvaer(2*nlayer+1,nw,iaer)=0.
395
396                  gvaer(1,nw,iaer)=gvaer(2,nw,iaer)
397                  gvaer(2*nlayer+1,nw,iaer)=0.
398               end do
399
400!     longwave
401               DO nw=1,L_NSPECTI
402                  do l=1,nlayer
403
404                     temp1=QIRsQREF3d(ig,nlayer+1-l,nw,iaer)  &
405                         *QREFir3d(ig,nlayer+1-l,iaer)
406
407                     temp2=QIRsQREF3d(ig,max(nlayer-l,1),nw,iaer) &
408                         *QREFir3d(ig,max(nlayer-l,1),iaer)
409
410                     qxiaer(2*l,nw,iaer)  = temp1
411                     qxiaer(2*l+1,nw,iaer)=(temp1+temp2)/2
412
413                     temp1=temp1*omegair3d(ig,nlayer+1-l,nw,iaer)
414                     temp2=temp2*omegair3d(ig,max(nlayer-l,1),nw,iaer)
415
416                     qsiaer(2*l,nw,iaer)  = temp1
417                     qsiaer(2*l+1,nw,iaer)=(temp1+temp2)/2
418
419                     temp1=gir3d(ig,nlayer+1-l,nw,iaer)
420                     temp2=gir3d(ig,max(nlayer-l,1),nw,iaer)
421
422                     giaer(2*l,nw,iaer)  = temp1
423                     giaer(2*l+1,nw,iaer)=(temp1+temp2)/2
424
425                  end do
426
427                  qxiaer(1,nw,iaer)=qxiaer(2,nw,iaer)
428                  qxiaer(2*nlayer+1,nw,iaer)=0.
429
430                  qsiaer(1,nw,iaer)=qsiaer(2,nw,iaer)
431                  qsiaer(2*nlayer+1,nw,iaer)=0.
432
433                  giaer(1,nw,iaer)=giaer(2,nw,iaer)
434                  giaer(2*nlayer+1,nw,iaer)=0.
435               end do
436            end do   ! naerkind
437
438            ! Test / Correct for freaky s. s. albedo values.
439            do iaer=1,naerkind
440               do k=1,L_LEVELS
441
442                  do nw=1,L_NSPECTV
443                     if(qsvaer(k,nw,iaer).gt.1.05*qxvaer(k,nw,iaer))then
444                        print*,'Serious problems with qsvaer values'
445                        print*,'in callcorrk'
446                        call abort
447                     endif
448                     if(qsvaer(k,nw,iaer).gt.qxvaer(k,nw,iaer))then
449                        qsvaer(k,nw,iaer)=qxvaer(k,nw,iaer)
450                     endif
451                  end do
452
453                  do nw=1,L_NSPECTI
454                     if(qsiaer(k,nw,iaer).gt.1.05*qxiaer(k,nw,iaer))then
455                        print*,'Serious problems with qsiaer values'
456                        print*,'in callcorrk'
457                        call abort
458                     endif
459                     if(qsiaer(k,nw,iaer).gt.qxiaer(k,nw,iaer))then
460                        qsiaer(k,nw,iaer)=qxiaer(k,nw,iaer)
461                     endif
462                  end do
463               end do ! levels
464
465            end do ! naerkind
466
467         endif ! aerohaze
468
469!-----------------------------------------------------------------------
470!     Aerosol optical depths
471         IF (aerohaze) THEN
472          do iaer=1,naerkind     ! heritage generic
473            do k=0,nlayer-1
474               pweight= &
475                   (pplay(ig,L_NLAYRAD-k)-pplev(ig,L_NLAYRAD-k+1))/ &
476                   (pplev(ig,L_NLAYRAD-k)-pplev(ig,L_NLAYRAD-k+1))
477               if (QREFvis3d(ig,L_NLAYRAD-k,iaer).ne.0) then
478                 temp=aerosol(ig,L_NLAYRAD-k,iaer)/ &
479                   QREFvis3d(ig,L_NLAYRAD-k,iaer)
480               else
481                 print*, 'stop corrk',k,QREFvis3d(ig,L_NLAYRAD-k,iaer)
482                 stop
483               end if
484               tauaero(2*k+2,iaer)=max(temp*pweight,0.d0)
485               tauaero(2*k+3,iaer)=max(temp-tauaero(2*k+2,iaer),0.d0) ! tauaero en L_LEVELS soit deux fois plus que nlayer
486            end do
487
488            ! generic New boundary conditions
489            tauaero(1,iaer)          = tauaero(2,iaer)
490            !tauaero(L_LEVELS+1,iaer) = tauaero(L_LEVELS,iaer)
491            !tauaero(1,iaer)          = 0.
492            !tauaero(L_LEVELS+1,iaer) = 0.
493
494          end do   ! naerkind
495         ELSE
496           tauaero(:,:)=0
497         ENDIF
498!-----------------------------------------------------------------------
499
500!     Albedo and emissivity
501         albi=1-emis(ig)        ! longwave
502         albv=albedo(ig)        ! shortwave
503         acosz=mu0(ig)          ! cosine of sun incident angle
504
505!-----------------------------------------------------------------------
506!     Methane vapour
507
508!     qvar = mixing ratio
509!     L_LEVELS (51) different de GCM levels (25) . L_LEVELS = 2*(llm-1)+3=2*(ngrid-1)+3
510!     L_REFVAR  The number of different mixing ratio values in
511!     datagcm/composition.in for the k-coefficients.
512         qvar(:)=0.
513         IF (methane) then
514
515           do l=1,nlayer
516               qvar(2*l)   = vmrch4(ig,nlayer+1-l)/100.*    &
517                                    mmol(igcm_ch4_gas)/mmol(igcm_n2)
518               qvar(2*l+1) = ((vmrch4(ig,nlayer+1-l)+vmrch4(ig, &
519                            max(nlayer-l,1)))/2.)/100.* &
520                            mmol(igcm_ch4_gas)/mmol(igcm_n2)
521           end do
522           qvar(1)=qvar(2)
523
524
525      ! Keep values inside limits for which we have radiative transfer coefficients
526           if(L_REFVAR.gt.1)then ! there was a bug here!
527             do k=1,L_LEVELS
528               if(qvar(k).lt.wrefvar(1))then
529                 qvar(k)=wrefvar(1)+1.0e-8
530               elseif(qvar(k).gt.wrefvar(L_REFVAR))then
531                 qvar(k)=wrefvar(L_REFVAR)-1.0e-8
532               endif
533             end do
534           endif
535
536      ! IMPORTANT: Now convert from kg/kg to mol/mol
537           do k=1,L_LEVELS
538            qvar(k) = qvar(k)/(epsi_ch4+qvar(k)*(1.-epsi_ch4))
539           end do
540         ENDIF ! methane
541
542!-----------------------------------------------------------------------
543!     Pressure and temperature
544
545! generic updated:
546         DO l=1,nlayer
547           plevrad(2*l)   = pplay(ig,nlayer+1-l)/scalep
548           plevrad(2*l+1) = pplev(ig,nlayer+1-l)/scalep
549           tlevrad(2*l)   = pt(ig,nlayer+1-l)
550           tlevrad(2*l+1) = (pt(ig,nlayer+1-l)+pt(ig,max(nlayer-l,1)))/2
551         END DO
552
553         plevrad(1) = 0.
554         plevrad(2) = 0.   !! Trick to have correct calculations of fluxes
555                        ! in gflux(i/v).F, but the pmid levels are not impacted by this change.
556
557         tlevrad(1) = tlevrad(2)
558         tlevrad(2*nlayer+1)=tsurf(ig)
559
560         pmid(1) = max(pgasmin,0.0001*plevrad(3))
561         pmid(2) =  pmid(1)
562
563         tmid(1) = tlevrad(2)
564         tmid(2) = tmid(1)
565
566! INI
567!        DO l=1,nlayer
568!           plevrad(2*l)   = pplay(ig,nlayer+1-l)/scalep
569!           plevrad(2*l+1) = pplev(ig,nlayer+1-l)/scalep
570!           tlevrad(2*l)   = pt(ig,nlayer+1-l)
571!           tlevrad(2*l+1) = (pt(ig,nlayer+1-l)+pt(ig,
572!     $        max(nlayer-l,1)))/2
573!        END DO
574
575!! following lines changed in 03/2015 to solve upper atmosphere bug
576!        plevrad(1) = 0.
577!        plevrad(2) = max(pgasmin,0.0001*plevrad(3))
578!
579!        tlevrad(1) = tlevrad(2)
580!        tlevrad(2*nlayer+1)=tsurf(ig)
581!
582!        tmid(1) = tlevrad(2)
583!        tmid(2) = tlevrad(2)
584!
585!        pmid(1) = plevrad(2)
586!        pmid(2) = plevrad(2)
587
588         DO l=1,L_NLAYRAD-1
589           tmid(2*l+1) = tlevrad(2*l+1)
590           tmid(2*l+2) = tlevrad(2*l+1)
591           pmid(2*l+1) = plevrad(2*l+1)
592           pmid(2*l+2) = plevrad(2*l+1)
593         END DO
594! end of changes
595         pmid(L_LEVELS) = plevrad(L_LEVELS)
596         tmid(L_LEVELS) = tlevrad(L_LEVELS)
597
598      !TB
599         if ((PMID(2).le.1.e-5).and.(ig.eq.1)) then
600          if ((TMID(2).le.30.).and.(ig.eq.1)) then
601           write(*,*) 'Caution! Pres/temp of upper levels lower than'
602           write(*,*) 'ref pressure/temp: kcoef fixed for upper levels'
603!!     cf tpindex.F
604          endif
605         endif
606
607      !  test for out-of-bounds pressure
608         if(plevrad(3).lt.pgasmin)then
609           print*,'Minimum pressure is outside the radiative'
610           print*,'transfer kmatrix bounds, exiting.'
611      !     call abort
612         elseif(plevrad(L_LEVELS).gt.pgasmax)then
613           print*,'Maximum pressure is outside the radiative'
614           print*,'transfer kmatrix bounds, exiting.'
615      !     call abort
616         endif
617
618      !  test for out-of-bounds temperature
619         do k=1,L_LEVELS
620          if(tlevrad(k).lt.tgasmin)then
621            print*,'Minimum temperature is outside the radiative'
622            print*,'transfer kmatrix bounds, exiting.'
623            print*,tlevrad(k),k,tgasmin
624          !  call abort
625          elseif(tlevrad(k).gt.tgasmax)then
626            print*,'Maximum temperature is outside the radiative'
627            print*,'transfer kmatrix bounds, exiting.'
628          !  call abort
629          endif
630         enddo
631
632!=======================================================================
633!     Calling the main radiative transfer subroutines
634
635!-----------------------------------------------------------------------
636!     Shortwave
637
638         IF(fract(ig) .GE. 1.0e-4) THEN ! only during daylight  IPM?! flux UV...
639
640            fluxtoplanet=0.
641            DO nw=1,L_NSPECTV
642               stel_fract(nw)= stel(nw) * fract(ig)
643               fluxtoplanet=fluxtoplanet + stel_fract(nw)
644            END DO
645
646            !print*, 'starting optcv'
647            call optcv_pluto(dtauv,tauv,taucumv,plevrad,  &
648                qxvaer,qsvaer,gvaer,wbarv,cosbv,tauray,tauaero, &
649                tmid,pmid,taugsurf,qvar)
650
651            call sfluxv_pluto(dtauv,tauv,taucumv,albv,dwnv,wbarv,cosbv,   &
652                acosz,stel_fract,nfluxtopv,nfluxtopv_nu,    &
653                fmnetv,fmnetv_nu,fluxupv,fluxdnv,fzerov,taugsurf)
654
655         ELSE                          ! during the night, fluxes = 0
656            nfluxtopv=0.0
657            DO l=1,L_NLAYRAD
658               fmnetv(l)=0.0
659               fluxupv(l)=0.0
660               fluxdnv(l)=0.0
661            END DO
662         END IF
663
664!-----------------------------------------------------------------------
665!     Longwave
666
667         call optci_pluto(plevrad,tlevrad,dtaui,taucumi,  &
668             qxiaer,qsiaer,giaer,cosbi,wbari,tauaero,tmid,pmid, &
669             taugsurfi,qvar)
670         call sfluxi_pluto(plevrad,tlevrad,dtaui,taucumi,ubari,albi,  &
671          wnoi,dwni,cosbi,wbari,nfluxtopi,nfluxtopi_nu, &
672          fmneti,fmneti_nu,fluxupi,fluxdni,fluxupi_nu,fzeroi,taugsurfi)
673
674
675!-----------------------------------------------------------------------
676!     Transformation of the correlated-k code outputs
677!     (into dtlw, dtsw, fluxsurf_lw, fluxsurf_sw, fluxtop_lw, fluxtop_sw)
678
679         fluxtop_lw(ig)  = fluxupi(1)
680         fluxsurf_lw(ig) = fluxdni(L_NLAYRAD)
681         fluxtop_sw(ig)  = fluxupv(1)
682         fluxsurf_sw(ig) = fluxdnv(L_NLAYRAD)
683
684!     Flux incident at the top of the atmosphere
685         fluxtop_dn(ig)=fluxdnv(1)
686
687!        IR spectral output from top of the atmosphere
688         if(specOLR)then
689            do nw=1,L_NSPECTI
690               OLR_nu(ig,nw)=nfluxtopi_nu(nw)
691            end do
692         endif
693
694! **********************************************************
695!     Finally, the heating rates
696!     g/cp*DF/DP
697! **********************************************************
698
699         DO l=2,L_NLAYRAD
700               dpp = g/(cpp*scalep*(plevrad(2*l+1)-plevrad(2*l-1)))
701
702               ! DTSW :
703               !dtsw(ig,L_NLAYRAD+1-l)=(fmnetv(l)-fmnetv(l-1))*dpp   !averaged dtlw on each wavelength
704               do nw=1,L_NSPECTV
705                 dtsw_nu(L_NLAYRAD+1-l,nw)= &
706                   (fmnetv_nu(l,nw)-fmnetv_nu(l-1,nw))*dpp
707               end do
708
709               ! DTLW : detailed with wavelength so that we can apply NLTE
710               !dtlw(ig,L_NLAYRAD+1-l)=(fmneti(l)-fmneti(l-1))*dpp   !averaged dtlw on each wavelength
711               do nw=1,L_NSPECTI
712                 dtlw_nu(L_NLAYRAD+1-l,nw)= &
713                   (fmneti_nu(l,nw)-fmneti_nu(l-1,nw))*dpp
714               end do
715         END DO
716
717         ! values at top of atmosphere
718         dpp = g/(cpp*scalep*(plevrad(3)-plevrad(1)))
719
720         ! SW
721         !dtsw(ig,L_NLAYRAD)=(fmnetv(1)-nfluxtopv)*dpp
722         do nw=1,L_NSPECTV
723            dtsw_nu(L_NLAYRAD,nw)=  &
724             (fmnetv_nu(1,nw)-nfluxtopv_nu(nw))*dpp
725         end do
726
727         ! LW
728!        dtlw(ig,L_NLAYRAD)=(fmneti(1)-nfluxtopi) *dpp
729         do nw=1,L_NSPECTI
730             dtlw_nu(L_NLAYRAD,nw)= &
731             (fmneti_nu(1,nw)-nfluxtopi_nu(nw))*dpp
732         end do
733
734! **********************************************************
735!     NON NLTE correction in Pluto atmosphere
736!     And conversion of LW spectral heating rates to total rates
737! **********************************************************
738
739         if (.not.nlte) then
740            eps_nlte_sw23(ig,:) =1. ! IF no NLTE
741            eps_nlte_sw33(ig,:) =1. ! IF no NLTE
742            eps_nlte_lw(ig,:) =1. ! IF no NLTE
743         endif
744
745         do l=1,nlayer
746
747            !LW
748            dtlw(ig,l) =0.
749!           dtlw_co(ig,l) =0.  ! only for diagnostic
750            do nw=1,L_NSPECTI
751              ! wewei : wavelength in micrometer
752              if ((wavei(nw).gt.6.).and.(wavei(nw).lt.9)) then
753                dtlw_nu(l,nw)=dtlw_nu(l,nw)*eps_nlte_lw(ig,l)
754              else
755                !dtlw_nu(l,nw)=1.*dtlw_nu(l,nw) ! no CO correction (Strobbel 1996)
756                dtlw_nu(l,nw)=0.33*dtlw_nu(l,nw) ! CO correction (Strobbel 1996)
757!               dtlw_co(ig,l)=dtlw_co(ig,l)+ dtlw_nu(l,nw) ! diagnostic
758              end if
759              dtlw(ig,l)=dtlw(ig,l)+ dtlw_nu(l,nw) !average now on each wavelength
760            end do
761            ! adding c2h2 if cooling active
762            dtlw(ig,l)=dtlw(ig,l)+dtlw_hcn_c2h2(ig,l)
763
764            !SW
765            dtsw(ig,l) =0.
766
767            if (strobel) then
768
769             do nw=1,L_NSPECTV
770              if ((wavev(nw).gt.2).and.(wavev(nw).lt.2.6)) then
771                dtsw_nu(l,nw)=dtsw_nu(l,nw)*eps_nlte_sw23(ig,l)
772              elseif ((wavev(nw).gt.3).and.(wavev(nw).lt.3.6)) then
773                dtsw_nu(l,nw)=dtsw_nu(l,nw)*eps_nlte_sw33(ig,l)
774              else
775                dtsw_nu(l,nw)=dtsw_nu(l,nw)
776              end if
777              dtsw(ig,l)=dtsw(ig,l)+ dtsw_nu(l,nw)
778             end do
779
780            else ! total heating rates multiplied by nlte coef
781
782             do nw=1,L_NSPECTV
783                dtsw_nu(l,nw)=dtsw_nu(l,nw)*eps_nlte_sw23(ig,l)
784                dtsw(ig,l)=dtsw(ig,l)+ dtsw_nu(l,nw)
785             enddo
786
787            endif
788
789
790         end do
791! **********************************************************
792
793!     Diagnotics for last call for each grid point
794         !if (lastcall) then
795
796          !print*,'albedi vis=',albv
797          !print*,'albedo ir=',albi
798          !print*,'fluxup ir (:)=',fluxupi
799          !print*,'flux ir net (:)=',fluxdni-fluxupi
800          !print*,'cumulative flux net ir (:)=',fmneti
801          !print*,'cumulative flux net vis (:)=',fmnetv
802          !print*,'fluxdn vis (:)=',fluxdnv
803          !print*,'fluxtop vis=',fluxtop_sw
804          !print*,'fluxsurf vis=',fluxsurf_sw
805          !print*,'fluxtop ir=',fluxtop_lw
806          !print*,'fluxsurf ir=',fluxsurf_lw
807
808!         write(*,*) 'pressure, eps_nlte_sw, eps_nlte_lw'
809!         do l=1,nlayer
810!           write(*,*)pplay(1,l),eps_nlte_sw(1,l),eps_nlte_lw(1,l)
811!         end do
812
813         !endif
814
815!     ---------------------------------------------------------------
816      end do                    ! end of big loop over every GCM column (ig = 1:ngrid)
817
818!-----------------------------------------------------------------------
819!     Additional diagnostics
820
821!     IR spectral output, for exoplanet observational comparison
822    !   if(specOLR)then
823    !     if(ngrid.ne.1)then
824    !       call writediagspec(ngrid,"OLR3D", &
825    !          "OLR(lon,lat,band)","W m^-2",3,OLR_nu)
826    !     endif
827    !   endif
828
829      if(lastcall)then
830
831        ! 1D Output
832        if(ngrid.eq.1)then
833
834!     surface diagnotics
835           diagrad_surf=.true.
836           if(diagrad_surf)then
837               open(116,file='surf_vals.out')
838               write(116,*) tsurf(1),pplev(1,1),    &
839                  fluxtop_dn(1) - fluxtop_sw(1),fluxtop_lw(1)
840               do nw=1,L_NSPECTV
841                 write(116,*) wavev(nw),fmnetv_nu(L_NLAYRAD,nw)
842               enddo
843               do nw=1,L_NSPECTI
844                 write(116,*) wavei(nw),fmneti_nu(L_NLAYRAD,nw)
845               enddo
846               close(116)
847           endif
848
849!     OLR by band
850           diagrad_OLR=.true.
851           if(diagrad_OLR)then
852               open(117,file='OLRnu.out')
853               write(117,*) 'IR wavel - band width - OLR'
854               do nw=1,L_NSPECTI
855                   write(117,*) wavei(nw),  &
856             abs(1.e4/bwnv(nw)-1.e4/bwnv(nw+1)),OLR_nu(1,nw)
857               enddo
858               close(117)
859           endif
860
861!     OLR vs altitude: in a .txt file
862           diagrad_OLRz=.true.
863           if(diagrad_OLRz)then
864               open(118,file='OLRz_plevs.out')
865               open(119,file='OLRz.out')
866               do l=1,L_NLAYRAD
867                 write(118,*) plevrad(2*l)
868                 do nw=1,L_NSPECTI
869                     write(119,*) fluxupi_nu(l,nw)
870                 enddo
871               enddo
872               close(118)
873               close(119)
874           endif
875
876!     Heating rates vs altitude in a .txt file
877           diagrad_rates=.true.
878           if(diagrad_rates)then
879             open(120,file='heating_rates.out')
880             write(120,*) "Pressure - Alt - HR tot - Rates (wavel SW)"
881             do l=1,nlayer
882               write(120,*) pplay(1,l),zzlay(1,l),dtsw(1,l),dtsw_nu(l,:)
883             enddo
884             close(120)
885
886             open(121,file='cooling_rates.out')
887             write(121,*) "Pressure - Alt - CR tot - Rates (wavel LW)"
888             do l=1,nlayer
889               write(121,*) pplay(1,l),zzlay(1,l),dtlw(1,l),dtlw_nu(l,:)
890             enddo
891             close(121)
892
893             open(122,file='bands.out')
894             write(122,*) "wavel - bands boundaries (microns)"
895             do nw=1,L_NSPECTV
896               write(122,*) wavev(nw),1.e4/bwnv(nw+1),1.e4/bwnv(nw)
897             enddo
898             do nw=1,L_NSPECTI
899               write(122,*) wavei(nw),1.e4/bwni(nw+1),1.e4/bwni(nw)
900             enddo
901             close(122)
902
903             open(123,file='c2h2_rates.out')
904             write(123,*) "Pressure - Alt - CR c2h2"
905             do l=1,nlayer
906               write(123,*) pplay(1,l),zzlay(1,l),dtlw_hcn_c2h2(1,l)
907             enddo
908             close(123)
909
910           endif
911
912        endif ! ngrid.eq.1
913
914      endif ! lastcall
915
916    end subroutine callcorrk_pluto
917
918END MODULE callcorrk_pluto_mod
Note: See TracBrowser for help on using the repository browser.