source: trunk/LMDZ.PLUTO/libf/phypluto/callcorrk.F90 @ 3762

Last change on this file since 3762 was 3695, checked in by debatzbr, 13 months ago

Calculate the visible opacity everywhere
BBT

  • Property svn:executable set to *
File size: 49.1 KB
Line 
1MODULE callcorrk_mod
2
3IMPLICIT NONE
4
5CONTAINS
6
7      subroutine callcorrk(ngrid,nlayer,pq,nq,qsurf,           &
8          albedo,albedo_equivalent,emis,mu0,pplev,pplay,pt,    &
9          zzlay,zzlev,tsurf,fract,dist_star,dtau_aer,muvar,    &
10          dtlw,dtsw,fluxsurf_lw,                               &
11          fluxsurf_sw,fluxsurfabs_sw,fluxtop_lw,               &
12          fluxabs_sw,fluxtop_dn,                               &
13          OLR_nu,OSR_nu,GSR_nu,                                &
14          int_dtaui,int_dtauv,                                 &
15          tau_col,firstcall,lastcall)
16
17      use mod_phys_lmdz_para, only : is_master
18      use radinc_h, only: L_NSPECTV, L_NSPECTI, naerkind, banddir, corrkdir,&
19                          L_LEVELS, L_NGAUSS, L_NLEVRAD, L_NLAYRAD, L_REFVAR
20      use radcommon_h, only: wrefvar, Cmk, fzeroi, fzerov, gasi, gasv, &
21                             glat_ig, gweight, pfgasref, pgasmax, pgasmin, &
22                             pgasref, tgasmax, tgasmin, tgasref, scalep, &
23                             ubari, wnoi, stellarf, glat, dwnv, dwni, tauray
24      use datafile_mod, only: datadir
25      use ioipsl_getin_p_mod, only: getin_p
26      use gases_h, only: ngasmx
27      use radii_mod, only : su_aer_radii, haze_reffrad_fix
28      use aerosol_mod, only : iaero_haze
29      use aeropacity_mod, only: aeropacity
30      use aeroptproperties_mod, only: aeroptproperties
31      use tracer_h, only: igcm_ch4_gas,igcm_n2,mmol
32      use comcstfi_mod, only: pi, mugaz, cpp, r, g
33      use callkeys_mod, only: diurnal,tracer,varfixed, &
34                              kastprof,strictboundcorrk,specOLR, &
35                              tplanckmin,tplanckmax,global1d, &
36                              optichaze,haze_radproffix,&
37                              methane,carbox,cooling,nlte,strobel,&
38                              ch4fix,vmrch4_proffix,vmrch4fix,&
39                              callmufi
40      use optcv_mod, only: optcv
41      use optci_mod, only: optci
42      use sfluxi_mod, only: sfluxi
43      use sfluxv_mod, only: sfluxv
44      use recombin_corrk_mod, only: corrk_recombin, call_recombin
45      use planetwide_mod, only: planetwide_maxval, planetwide_minval
46      use radcommon_h, only: wavev,wavei
47      use mp2m_diagnostics
48      implicit none
49
50!==================================================================
51!
52!     Purpose
53!     -------
54!     Solve the radiative transfer using the correlated-k method for
55!     the gaseous absorption and the Toon et al. (1989) method for
56!     scatttering due to aerosols.
57!
58!     Authors
59!     -------
60!     Emmanuel 01/2001, Forget 09/2001
61!     Robin Wordsworth (2009)
62!
63!==================================================================
64
65!-----------------------------------------------------------------------
66!     Declaration of the arguments (INPUT - OUTPUT) on the LMD GCM grid
67!     Layer #1 is the layer near the ground.
68!     Layer #nlayer is the layer at the top.
69!-----------------------------------------------------------------------
70
71
72      ! INPUT
73      INTEGER,INTENT(IN) :: ngrid                  ! Number of atmospheric columns.
74      INTEGER,INTENT(IN) :: nlayer                 ! Number of atmospheric layers.
75      REAL,INTENT(IN) :: pq(ngrid,nlayer,nq)       ! Tracers (kg/kg_of_air).
76      INTEGER,INTENT(IN) :: nq                     ! Number of tracers.
77      REAL,INTENT(IN) :: qsurf(ngrid,nq)           ! Tracers on surface (kg.m-2).
78      REAL,INTENT(IN) :: albedo(ngrid,L_NSPECTV)   ! Spectral Short Wavelengths Albedo. By MT2015
79      REAL,INTENT(IN) :: emis(ngrid)               ! Long Wave emissivity.
80      REAL,INTENT(IN) :: mu0(ngrid)                ! Cosine of sun incident angle.
81      REAL,INTENT(IN) :: pplev(ngrid,nlayer+1)     ! Inter-layer pressure (Pa).
82      REAL,INTENT(IN) :: pplay(ngrid,nlayer)       ! Mid-layer pressure (Pa).
83      REAL,INTENT(IN) :: pt(ngrid,nlayer)          ! Air temperature (K).
84      REAL,INTENT(IN) :: zzlay(ngrid,nlayer)       ! Mid-layer altitude
85      REAL,INTENT(IN) :: zzlev(ngrid,nlayer)       ! Altitude at the layer boundaries.
86      REAL,INTENT(IN) :: tsurf(ngrid)              ! Surface temperature (K).
87      REAL,INTENT(IN) :: fract(ngrid)              ! Fraction of day.
88      REAL,INTENT(IN) :: dist_star                 ! Distance star-planet (AU).
89      REAL,INTENT(IN) :: muvar(ngrid,nlayer+1)
90      logical,intent(in) :: firstcall              ! Signals first call to physics.
91      logical,intent(in) :: lastcall               ! Signals last call to physics.
92
93      ! OUTPUT
94      REAL,INTENT(OUT) :: dtau_aer(ngrid,nlayer,naerkind) ! Aerosol tau at reference wavelenght.
95      REAL,INTENT(OUT) :: dtlw(ngrid,nlayer)              ! Heating rate (K/s) due to LW radiation.
96      REAL,INTENT(OUT) :: dtsw(ngrid,nlayer)              ! Heating rate (K/s) due to SW radiation.
97      REAL,INTENT(OUT) :: fluxsurf_lw(ngrid)              ! Incident LW flux to surf (W/m2).
98      REAL,INTENT(OUT) :: fluxsurf_sw(ngrid)              ! Incident SW flux to surf (W/m2)
99      REAL,INTENT(OUT) :: fluxsurfabs_sw(ngrid)           ! Absorbed SW flux by the surface (W/m2). By MT2015.
100      REAL,INTENT(OUT) :: fluxtop_lw(ngrid)               ! Outgoing LW flux to space (W/m2).
101      REAL,INTENT(OUT) :: fluxabs_sw(ngrid)               ! SW flux absorbed by the planet (W/m2).
102      REAL,INTENT(OUT) :: fluxtop_dn(ngrid)               ! Incident top of atmosphere SW flux (W/m2).
103      REAL,INTENT(OUT) :: OLR_nu(ngrid,L_NSPECTI)         ! Outgoing LW radiation in each band (Normalized to the band width (W/m2/cm-1).
104      REAL,INTENT(OUT) :: OSR_nu(ngrid,L_NSPECTV)         ! Outgoing SW radiation in each band (Normalized to the band width (W/m2/cm-1).
105      REAL,INTENT(OUT) :: GSR_nu(ngrid,L_NSPECTV)         ! Surface SW radiation in each band (Normalized to the band width (W/m2/cm-1).
106      REAL,INTENT(OUT) :: int_dtaui(ngrid,nlayer,L_NSPECTI) ! VI optical thickness of layers within narrowbands for diags ().
107      REAL,INTENT(OUT) :: int_dtauv(ngrid,nlayer,L_NSPECTV) ! IR optical thickness of layers within narrowbands for diags ().
108      REAL,INTENT(OUT) :: tau_col(ngrid)                  ! Diagnostic from aeropacity.
109      REAL,INTENT(OUT) :: albedo_equivalent(ngrid)        ! Spectrally Integrated Albedo. For Diagnostic. By MT2015
110
111
112! Globally varying aerosol optical properties on GCM grid ; not needed everywhere so not in radcommon_h.
113! made "save" variables so they are allocated once in for all, not because
114! the values need be saved from a time step to the next
115      REAL,SAVE,ALLOCATABLE :: QVISsQREF3d(:,:,:,:)
116      REAL,SAVE,ALLOCATABLE :: omegaVIS3d(:,:,:,:)
117      REAL,SAVE,ALLOCATABLE :: gVIS3d(:,:,:,:)
118!$OMP THREADPRIVATE(QVISsQREF3d,omegaVIS3d,gVIS3d)
119      REAL,SAVE,ALLOCATABLE :: QIRsQREF3d(:,:,:,:)
120      REAL,SAVE,ALLOCATABLE :: omegaIR3d(:,:,:,:)
121      REAL,SAVE,ALLOCATABLE :: gIR3d(:,:,:,:)
122!$OMP THREADPRIVATE(QIRsQREF3d,omegaIR3d,gIR3d)
123
124!      REAL :: omegaREFvis3d(ngrid,nlayer,naerkind)
125!      REAL :: omegaREFir3d(ngrid,nlayer,naerkind) ! not sure of the point of these...
126
127      REAL,ALLOCATABLE,SAVE :: reffrad(:,:,:)  ! aerosol effective radius (m)
128      REAL,ALLOCATABLE,SAVE :: nueffrad(:,:,:) ! aerosol effective variance
129!$OMP THREADPRIVATE(reffrad,nueffrad)
130
131!-----------------------------------------------------------------------
132!     Declaration of the variables required by correlated-k subroutines
133!     Numbered from top to bottom (unlike in the GCM)
134!-----------------------------------------------------------------------
135
136      REAL*8 tmid(L_LEVELS),pmid(L_LEVELS)
137      REAL*8 tlevrad(L_LEVELS),plevrad(L_LEVELS)
138
139      ! Optical values for the optci/cv subroutines
140      REAL*8 stel(L_NSPECTV),stel_fract(L_NSPECTV)
141      ! NB: Arrays below are "save" to avoid reallocating them at every call
142      ! not because their content needs be reused from call to the next
143      REAL*8,allocatable,save :: dtaui(:,:,:)
144      REAL*8,allocatable,save :: dtauv(:,:,:)
145      REAL*8,allocatable,save :: cosbv(:,:,:)
146      REAL*8,allocatable,save :: cosbi(:,:,:)
147      REAL*8,allocatable,save :: wbari(:,:,:)
148      REAL*8,allocatable,save :: wbarv(:,:,:)
149!$OMP THREADPRIVATE(dtaui,dtauv,cosbv,cosbi,wbari,wbarv)
150      REAL*8,allocatable,save :: tauv(:,:,:)
151      REAL*8,allocatable,save :: taucumv(:,:,:)
152      REAL*8,allocatable,save :: taucumi(:,:,:)
153!$OMP THREADPRIVATE(tauv,taucumv,taucumi)
154      REAL*8,allocatable,save :: tauaero(:,:)
155!$OMP THREADPRIVATE(tauaero)
156      REAL*8 nfluxtopv,nfluxtopi,nfluxtop,fluxtopvdn
157      real*8 nfluxtopv_nu(L_NSPECTV)
158      REAL*8 nfluxoutv_nu(L_NSPECTV)                 ! Outgoing band-resolved VI flux at TOA (W/m2).
159      REAL*8 nfluxtopi_nu(L_NSPECTI)                 ! Net band-resolved IR flux at TOA (W/m2).
160      REAL*8 fluxupi_nu(L_NLAYRAD,L_NSPECTI)         ! For 1D diagnostic.
161      REAL*8 fmneti(L_NLAYRAD),fmnetv(L_NLAYRAD)
162      real*8 fmneti_nu(L_NLAYRAD,L_NSPECTI) !
163      real*8 fmnetv_nu(L_NLAYRAD,L_NSPECTV) !
164      REAL*8 fluxupv(L_NLAYRAD),fluxupi(L_NLAYRAD)
165      REAL*8 fluxdnv(L_NLAYRAD),fluxdni(L_NLAYRAD)
166      REAL*8 albi,acosz
167      REAL*8 albv(L_NSPECTV)                         ! Spectral Visible Albedo.
168
169      INTEGER ig,l,k,nw,iaer,iq
170
171      real*8,allocatable,save :: taugsurf(:,:)
172      real*8,allocatable,save :: taugsurfi(:,:)
173!$OMP THREADPRIVATE(taugsurf,taugsurfi)
174      real*8 qvar(L_LEVELS)   ! Mixing ratio of variable component (mol/mol). index 1 is the top of the atmosphere, index L_LEVELS is the bottom
175
176      ! Local aerosol optical properties for each column on RADIATIVE grid.
177      real*8,save,allocatable ::  QXVAER(:,:,:) ! Extinction coeff (QVISsQREF*QREFvis)
178      real*8,save,allocatable ::  QSVAER(:,:,:)
179      real*8,save,allocatable ::  GVAER(:,:,:)
180      real*8,save,allocatable ::  QXIAER(:,:,:) ! Extinction coeff (QIRsQREF*QREFir)
181      real*8,save,allocatable ::  QSIAER(:,:,:)
182      real*8,save,allocatable ::  GIAER(:,:,:)
183!$OMP THREADPRIVATE(QXVAER,QSVAER,GVAER,QXIAER,QSIAER,GIAER)
184      real, dimension(:,:,:), save, allocatable :: QREFvis3d
185      real, dimension(:,:,:), save, allocatable :: QREFir3d
186!$OMP THREADPRIVATE(QREFvis3d,QREFir3d)
187
188      ! Miscellaneous :
189      real*8  temp,temp1,temp2,pweight,sig
190      character(len=10) :: tmp1
191      character(len=10) :: tmp2
192      character(len=100) :: message
193      character(len=10),parameter :: subname="callcorrk"
194
195      logical OLRz
196      real*8 NFLUXGNDV_nu(L_NSPECTV)
197
198      ! Included by RW for runaway greenhouse 1D study.
199      real vtmp(nlayer)
200      REAL*8 muvarrad(L_LEVELS)
201
202      ! Included by MT for albedo calculations.
203      REAL*8 albedo_temp(L_NSPECTV) ! For equivalent albedo calculation.
204      REAL*8 surface_stellar_flux   ! Stellar flux reaching the surface. Useful for equivalent albedo calculation.
205
206      !     NLTE factor for CH4
207      real eps_nlte_sw23(ngrid,nlayer) ! CH4 NLTE efficiency factor for zdtsw
208      real eps_nlte_sw33(ngrid,nlayer) ! CH4 NLTE efficiency factor for zdtsw
209      real eps_nlte_lw(ngrid,nlayer) ! CH4 NLTE efficiency factor for zdtsw
210      integer Nfine,ifine
211      parameter(Nfine=701)
212      real,save :: levdat(Nfine),vmrdat(Nfine)
213      REAL dtlw_hcn_c2h2(ngrid, nlayer) ! cooling rate (K/s) due to C2H2/HCN (diagnostic)
214      real :: vmrch4(ngrid,nlayer)              ! vmr ch4 from vmrch4_proffix
215
216      REAL dtlw_nu(nlayer,L_NSPECTI) ! heating rate (K/s) due to LW in spectral bands
217      REAL dtsw_nu(nlayer,L_NSPECTV) ! heating rate (K/s) due to SW in spectral bands
218
219      ! local variable
220      REAL, save :: dpp  ! intermediate
221!$OMP THREADPRIVATE(dpp)
222
223      integer ok ! status (returned by NetCDF functions)
224
225      REAL :: maxvalue,minvalue
226
227!===============================================================
228!           I.a Initialization on first call
229!===============================================================
230
231
232      if(firstcall) then
233
234        ! test on allocated necessary because of CLFvarying (two calls to callcorrk in physiq)
235        if(.not.allocated(QVISsQREF3d)) then
236          allocate(QVISsQREF3d(ngrid,nlayer,L_NSPECTV,naerkind))
237        endif
238        if(.not.allocated(omegaVIS3d)) then
239          allocate(omegaVIS3d(ngrid,nlayer,L_NSPECTV,naerkind))
240        endif
241        if(.not.allocated(gVIS3d)) then
242          allocate(gVIS3d(ngrid,nlayer,L_NSPECTV,naerkind))
243        endif
244        if (.not.allocated(QIRsQREF3d)) then
245          allocate(QIRsQREF3d(ngrid,nlayer,L_NSPECTI,naerkind))
246        endif
247        if (.not.allocated(omegaIR3d)) then
248          allocate(omegaIR3d(ngrid,nlayer,L_NSPECTI,naerkind))
249        endif
250        if (.not.allocated(gIR3d)) then
251          allocate(gIR3d(ngrid,nlayer,L_NSPECTI,naerkind))
252        endif
253        if (.not.allocated(tauaero)) then
254          allocate(tauaero(L_LEVELS,naerkind))
255        endif
256
257        if(.not.allocated(QXVAER)) then
258          allocate(QXVAER(L_LEVELS,L_NSPECTV,naerkind), stat=ok)
259          if (ok /= 0) then
260             write(*,*) "memory allocation failed for QXVAER!"
261             call abort_physic(subname,'allocation failure for QXVAER',1)
262          endif
263        endif
264        if(.not.allocated(QSVAER)) then
265          allocate(QSVAER(L_LEVELS,L_NSPECTV,naerkind), stat=ok)
266          if (ok /= 0) then
267             write(*,*) "memory allocation failed for QSVAER!"
268             call abort_physic(subname,'allocation failure for QSVAER',1)
269          endif
270        endif
271        if(.not.allocated(GVAER)) then
272          allocate(GVAER(L_LEVELS,L_NSPECTV,naerkind), stat=ok)
273          if (ok /= 0) then
274             write(*,*) "memory allocation failed for GVAER!"
275             call abort_physic(subname,'allocation failure for GVAER',1)
276          endif
277        endif
278        if(.not.allocated(QXIAER)) then
279          allocate(QXIAER(L_LEVELS,L_NSPECTI,naerkind), stat=ok)
280          if (ok /= 0) then
281             write(*,*) "memory allocation failed for QXIAER!"
282             call abort_physic(subname,'allocation failure for QXIAER',1)
283          endif
284        endif
285        if(.not.allocated(QSIAER)) then
286          allocate(QSIAER(L_LEVELS,L_NSPECTI,naerkind), stat=ok)
287          if (ok /= 0) then
288             write(*,*) "memory allocation failed for QSIAER!"
289             call abort_physic(subname,'allocation failure for QSIAER',1)
290          endif
291        endif
292        if(.not.allocated(GIAER)) then
293          allocate(GIAER(L_LEVELS,L_NSPECTI,naerkind), stat=ok)
294          if (ok /= 0) then
295             write(*,*) "memory allocation failed for GIAER!"
296             call abort_physic(subname,'allocation failure for GIAER',1)
297          endif
298        endif
299
300         !!! ALLOCATED instances are necessary because of CLFvarying (strategy to call callcorrk twice in physiq...)
301         IF(.not.ALLOCATED(QREFvis3d))THEN
302           ALLOCATE(QREFvis3d(ngrid,nlayer,naerkind), stat=ok)
303           IF (ok/=0) THEN
304              write(*,*) "memory allocation failed for QREFvis3d!"
305              call abort_physic(subname,'allocation failure for QREFvis3d',1)
306           ENDIF
307         ENDIF
308         IF(.not.ALLOCATED(QREFir3d)) THEN
309           ALLOCATE(QREFir3d(ngrid,nlayer,naerkind), stat=ok)
310           IF (ok/=0) THEN
311              write(*,*) "memory allocation failed for QREFir3d!"
312              call abort_physic(subname,'allocation failure for QREFir3d',1)
313           ENDIF
314         ENDIF
315         ! Effective radius and variance of the aerosols
316         IF(.not.ALLOCATED(reffrad)) THEN
317           allocate(reffrad(ngrid,nlayer,naerkind), stat=ok)
318           IF (ok/=0) THEN
319              write(*,*) "memory allocation failed for reffrad!"
320              call abort_physic(subname,'allocation failure for reffrad',1)
321           ENDIF
322         ENDIF
323         IF(.not.ALLOCATED(nueffrad)) THEN
324           allocate(nueffrad(ngrid,nlayer,naerkind), stat=ok)
325           IF (ok/=0) THEN
326              write(*,*) "memory allocation failed for nueffrad!"
327              call abort_physic(subname,'allocation failure for nueffrad',1)
328           ENDIF
329         ENDIF
330
331         if (is_master) call system('rm -f surf_vals_long.out')
332
333!--------------------------------------------------
334!             Set up correlated k
335!--------------------------------------------------
336
337      !this block is now done at firstcall of physiq_mod
338         ! print*, "callcorrk: Correlated-k data base folder:",trim(datadir)
339         ! call getin_p("corrkdir",corrkdir)
340         ! print*, "corrkdir = ",corrkdir
341         ! write( tmp1, '(i3)' ) L_NSPECTI
342         ! write( tmp2, '(i3)' ) L_NSPECTV
343         ! banddir=trim(adjustl(tmp1))//'x'//trim(adjustl(tmp2))
344         ! banddir=trim(adjustl(corrkdir))//'/'//trim(adjustl(banddir))
345
346         ! call setspi            ! Basic infrared properties.
347         ! call setspv            ! Basic visible properties.
348         ! call sugas_corrk       ! Set up gaseous absorption properties.
349         ! call suaer_corrk       ! Set up aerosol optical properties.
350
351
352         ! now that L_NGAUSS has been initialized (by sugas_corrk)
353         ! allocate related arrays
354         if(.not.allocated(dtaui)) then
355           ALLOCATE(dtaui(L_NLAYRAD,L_NSPECTI,L_NGAUSS), stat=ok)
356           if (ok/=0) then
357              write(*,*) "memory allocation failed for dtaui!"
358              call abort_physic(subname,'allocation failure for dtaui',1)
359           endif
360         endif
361         if(.not.allocated(dtauv)) then
362           ALLOCATE(dtauv(L_NLAYRAD,L_NSPECTV,L_NGAUSS), stat=ok)
363           if (ok/=0) then
364              write(*,*) "memory allocation failed for dtauv!"
365              call abort_physic(subname,'allocation failure for dtauv',1)
366           endif
367         endif
368         if(.not.allocated(cosbv)) then
369           ALLOCATE(cosbv(L_NLAYRAD,L_NSPECTV,L_NGAUSS), stat=ok)
370           if (ok/=0) then
371              write(*,*) "memory allocation failed for cosbv!"
372              call abort_physic(subname,'allocation failure for cobsv',1)
373           endif
374         endif
375         if(.not.allocated(cosbi)) then
376           ALLOCATE(cosbi(L_NLAYRAD,L_NSPECTI,L_NGAUSS), stat=ok)
377           if (ok/=0) then
378              write(*,*) "memory allocation failed for cosbi!"
379              call abort_physic(subname,'allocation failure for cobsi',1)
380           endif
381         endif
382         if(.not.allocated(wbari)) then
383           ALLOCATE(wbari(L_NLAYRAD,L_NSPECTI,L_NGAUSS), stat=ok)
384           if (ok/=0) then
385              write(*,*) "memory allocation failed for wbari!"
386              call abort_physic(subname,'allocation failure for wbari',1)
387           endif
388         endif
389         if(.not.allocated(wbarv)) then
390           ALLOCATE(wbarv(L_NLAYRAD,L_NSPECTV,L_NGAUSS), stat=ok)
391           if (ok/=0) then
392              write(*,*) "memory allocation failed for wbarv!"
393              call abort_physic(subname,'allocation failure for wbarv',1)
394           endif
395         endif
396         if(.not.allocated(tauv)) then
397           ALLOCATE(tauv(L_NLEVRAD,L_NSPECTV,L_NGAUSS), stat=ok)
398           if (ok/=0) then
399              write(*,*) "memory allocation failed for tauv!"
400              call abort_physic(subname,'allocation failure for tauv',1)
401           endif
402         endif
403         if(.not.allocated(taucumv)) then
404           ALLOCATE(taucumv(L_LEVELS,L_NSPECTV,L_NGAUSS), stat=ok)
405           if (ok/=0) then
406              write(*,*) "memory allocation failed for taucumv!"
407              call abort_physic(subname,'allocation failure for taucumv',1)
408           endif
409         endif
410         if(.not.allocated(taucumi)) then
411           ALLOCATE(taucumi(L_LEVELS,L_NSPECTI,L_NGAUSS), stat=ok)
412           if (ok/=0) then
413              write(*,*) "memory allocation failed for taucumi!"
414              call abort_physic(subname,'allocation failure for taucumi',1)
415           endif
416         endif
417         if(.not.allocated(taugsurf)) then
418           ALLOCATE(taugsurf(L_NSPECTV,L_NGAUSS-1), stat=ok)
419           if (ok/=0) then
420              write(*,*) "memory allocation failed for taugsurf!"
421              call abort_physic(subname,'allocation failure for taugsurf',1)
422           endif
423         endif
424         if(.not.allocated(taugsurfi)) then
425           ALLOCATE(taugsurfi(L_NSPECTI,L_NGAUSS-1), stat=ok)
426           if (ok/=0) then
427              write(*,*) "memory allocation failed for taugsurfi!"
428              call abort_physic(subname,'allocation failure for taugsurfi',1)
429           endif
430         endif
431
432      end if ! of if (firstcall)
433
434!=======================================================================
435!          I.b  Initialization on every call
436!=======================================================================
437
438      qxvaer(:,:,:)=0.0
439      qsvaer(:,:,:)=0.0
440      gvaer(:,:,:) =0.0
441
442      qxiaer(:,:,:)=0.0
443      qsiaer(:,:,:)=0.0
444      giaer(:,:,:) =0.0
445
446      OLR_nu(:,:) = 0.
447      OSR_nu(:,:) = 0.
448      GSR_nu(:,:) = 0.
449
450!--------------------------------------------------
451!     Effective radius and variance of the aerosols
452!     Madeleine's PhD (eq. 2.3-2.4):
453!     --> r_eff = <r^3> / <r^2>
454!     --> nu_eff = <r^4>*<r^2> / <r^3>^2 - 1
455!--------------------------------------------------
456      ! Radiative Hazes
457      if (optichaze) then
458         if (callmufi) then
459            ! Spherical aerosols
460            sig = 0.2
461            where (mp2m_rc_sph(:,:) > 1e-9)
462               reffrad(:,:,1) = mp2m_rc_sph(:,:) * exp(5.*sig**2 / 2.)
463            elsewhere
464               reffrad(:,:,1) = 0d0
465            endwhere
466            if (exp(sig**2) - 1 > 0.1) then
467               nueffrad(:,:,1) = exp(sig**2) - 1
468            else
469               nueffrad(:,:,1) = 0.1
470            endif
471            ! Fractal aerosols
472            sig = 0.35
473            where (mp2m_rc_fra(:,:) > 1e-8)
474               reffrad(:,:,2) = mp2m_rc_fra(:,:) * exp(5.*sig**2 / 2.)
475               elsewhere
476               reffrad(:,:,2) = 0d0
477               endwhere
478            if (exp(sig**2) - 1 > 0.1) then
479               nueffrad(:,:,2) = exp(sig**2) - 1
480            else
481               nueffrad(:,:,2) = 0.1
482            endif
483
484         else
485            do iaer=1,naerkind
486               if ((iaer.eq.iaero_haze)) then
487               call su_aer_radii(ngrid,nlayer,reffrad(1,1,iaer),nueffrad(1,1,iaer))
488               endif
489            end do ! iaer = 1, naerkind.
490            if (haze_radproffix) then
491               call haze_reffrad_fix(ngrid,nlayer,zzlay,reffrad,nueffrad)
492               if (is_master) print*, 'haze_radproffix=T : fixed profile for haze rad'
493            else
494               if (is_master) print*,'reffrad haze:',reffrad(1,1,iaero_haze)
495               if (is_master) print*,'nueff haze',nueffrad(1,1,iaero_haze)
496            endif ! end haze_radproffix
497         endif ! end callmufi
498      endif ! end radiative haze
499
500      ! How much light do we get ?
501      do nw=1,L_NSPECTV
502         stel(nw)=stellarf(nw)/(dist_star**2)
503      end do
504
505      if (optichaze) then
506
507         ! Get 3D aerosol optical properties.
508         call aeroptproperties(ngrid,nlayer,reffrad,nueffrad,         &
509            QVISsQREF3d,omegaVIS3d,gVIS3d,                          &
510            QIRsQREF3d,omegaIR3d,gIR3d,                             &
511            QREFvis3d,QREFir3d)
512
513         ! Get aerosol optical depths.
514         call aeropacity(ngrid,nlayer,nq,pplay,pplev,zzlev,pt,pq,dtau_aer,      &
515            reffrad,nueffrad,QREFvis3d,QREFir3d,                             &
516            tau_col)
517      endif
518
519
520!-----------------------------------------------------------------------
521!     Prepare CH4 mixing ratio for radiative transfer
522      IF (methane) then
523        vmrch4(:,:)=0.
524
525        if (ch4fix) then
526           if (vmrch4_proffix) then
527            !! Interpolate on the model vertical grid
528             do ig=1,ngrid
529               CALL interp_line(levdat,vmrdat,Nfine, &
530                      zzlay(ig,:)/1000.,vmrch4(ig,:),nlayer)
531             enddo
532           else
533            vmrch4(:,:)=vmrch4fix
534           endif
535        else
536            vmrch4(:,:)=pq(:,:,igcm_ch4_gas)*100.* &
537                        mmol(igcm_n2)/mmol(igcm_ch4_gas)
538        endif
539      ENDIF
540
541!     Prepare NON LTE correction in Pluto atmosphere
542      IF (nlte) then
543        CALL nlte_ch4(ngrid,nlayer,nq,pplay,pplev,pt,vmrch4,&
544                  eps_nlte_sw23,eps_nlte_sw33,eps_nlte_lw)
545      ENDIF
546!     Net atmospheric radiative cooling rate from C2H2 (K.s-1):
547!     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
548      dtlw_hcn_c2h2=0.
549      if (cooling) then
550         CALL cooling_hcn_c2h2(ngrid,nlayer,pplay,&
551                                  pt,dtlw_hcn_c2h2)
552      endif
553
554
555!-----------------------------------------------------------------------
556      do ig=1,ngrid ! Starting Big Loop over every GCM column
557!-----------------------------------------------------------------------
558
559
560!=======================================================================
561!              II.  Transformation of the GCM variables
562!=======================================================================
563
564
565!-----------------------------------------------------------------------
566!    Aerosol optical properties Qext, Qscat and g.
567!    The transformation in the vertical is the same as for temperature.
568!-----------------------------------------------------------------------
569
570
571      ! AF24: for now only consider one aerosol (=haze)
572      if (optichaze) then
573        do iaer=1,naerkind
574            ! Shortwave.
575            do nw=1,L_NSPECTV
576
577                do l=1,nlayer
578
579                    temp1=QVISsQREF3d(ig,nlayer+1-l,nw,iaer)         &
580                        *QREFvis3d(ig,nlayer+1-l,iaer)
581
582                    temp2=QVISsQREF3d(ig,max(nlayer-l,1),nw,iaer)    &
583                        *QREFvis3d(ig,max(nlayer-l,1),iaer)
584
585                    qxvaer(2*l,nw,iaer)  = temp1
586                    qxvaer(2*l+1,nw,iaer)=(temp1+temp2)/2
587
588                    temp1=temp1*omegavis3d(ig,nlayer+1-l,nw,iaer)
589                    temp2=temp2*omegavis3d(ig,max(nlayer-l,1),nw,iaer)
590
591                    qsvaer(2*l,nw,iaer)  = temp1
592                    qsvaer(2*l+1,nw,iaer)=(temp1+temp2)/2
593
594                    temp1=gvis3d(ig,nlayer+1-l,nw,iaer)
595                    temp2=gvis3d(ig,max(nlayer-l,1),nw,iaer)
596
597                    gvaer(2*l,nw,iaer)  = temp1
598                    gvaer(2*l+1,nw,iaer)=(temp1+temp2)/2
599
600                end do ! nlayer
601
602                qxvaer(1,nw,iaer)=qxvaer(2,nw,iaer)
603                qxvaer(2*nlayer+1,nw,iaer)=0.
604
605                qsvaer(1,nw,iaer)=qsvaer(2,nw,iaer)
606                qsvaer(2*nlayer+1,nw,iaer)=0.
607
608                gvaer(1,nw,iaer)=gvaer(2,nw,iaer)
609                gvaer(2*nlayer+1,nw,iaer)=0.
610
611            end do ! L_NSPECTV
612
613            do nw=1,L_NSPECTI
614                ! Longwave
615                do l=1,nlayer
616
617                    temp1=QIRsQREF3d(ig,nlayer+1-l,nw,iaer)         &
618                        *QREFir3d(ig,nlayer+1-l,iaer)
619
620                    temp2=QIRsQREF3d(ig,max(nlayer-l,1),nw,iaer)    &
621                        *QREFir3d(ig,max(nlayer-l,1),iaer)
622
623                    qxiaer(2*l,nw,iaer)  = temp1
624                    qxiaer(2*l+1,nw,iaer)=(temp1+temp2)/2
625
626                    temp1=temp1*omegair3d(ig,nlayer+1-l,nw,iaer)
627                    temp2=temp2*omegair3d(ig,max(nlayer-l,1),nw,iaer)
628
629                    qsiaer(2*l,nw,iaer)  = temp1
630                    qsiaer(2*l+1,nw,iaer)=(temp1+temp2)/2
631
632                    temp1=gir3d(ig,nlayer+1-l,nw,iaer)
633                    temp2=gir3d(ig,max(nlayer-l,1),nw,iaer)
634
635                    giaer(2*l,nw,iaer)  = temp1
636                    giaer(2*l+1,nw,iaer)=(temp1+temp2)/2
637
638                end do ! nlayer
639
640                qxiaer(1,nw,iaer)=qxiaer(2,nw,iaer)
641                qxiaer(2*nlayer+1,nw,iaer)=0.
642
643                qsiaer(1,nw,iaer)=qsiaer(2,nw,iaer)
644                qsiaer(2*nlayer+1,nw,iaer)=0.
645
646                giaer(1,nw,iaer)=giaer(2,nw,iaer)
647                giaer(2*nlayer+1,nw,iaer)=0.
648
649            end do ! L_NSPECTI
650
651        end do ! naerkind
652
653        ! Test / Correct for freaky s. s. albedo values.
654        do iaer=1,naerkind
655            do k=1,L_LEVELS
656
657                do nw=1,L_NSPECTV
658                    if(qsvaer(k,nw,iaer).gt.1.05*qxvaer(k,nw,iaer))then
659                    message='Serious problems with qsvaer values'
660                    call abort_physic(subname,message,1)
661                    endif
662                    if(qsvaer(k,nw,iaer).gt.qxvaer(k,nw,iaer))then
663                    qsvaer(k,nw,iaer)=qxvaer(k,nw,iaer)
664                    endif
665                end do
666
667                do nw=1,L_NSPECTI
668                    if(qsiaer(k,nw,iaer).gt.1.05*qxiaer(k,nw,iaer))then
669                    message='Serious problems with qsvaer values'
670                    call abort_physic(subname,message,1)
671                    endif
672                    if(qsiaer(k,nw,iaer).gt.qxiaer(k,nw,iaer))then
673                    qsiaer(k,nw,iaer)=qxiaer(k,nw,iaer)
674                    endif
675                end do
676
677            end do ! L_LEVELS
678        end do ! naerkind
679      end if ! optichaze
680
681!-----------------------------------------------------------------------
682!     Aerosol optical depths
683!-----------------------------------------------------------------------
684      if (optichaze) then
685        do iaer=1,naerkind     ! a bug was here
686            do k=0,nlayer-1
687
688               pweight=(pplay(ig,L_NLAYRAD-k)-pplev(ig,L_NLAYRAD-k+1))/   &
689                       (pplev(ig,L_NLAYRAD-k)-pplev(ig,L_NLAYRAD-k+1))
690               ! As 'dtau_aer' is at reference (visible) wavelenght we scale it as
691               ! it will be multplied by qxi/v in optci/v
692               temp=dtau_aer(ig,L_NLAYRAD-k,iaer)/QREFvis3d(ig,L_NLAYRAD-k,iaer)
693               tauaero(2*k+2,iaer)=max(temp*pweight,0.d0)
694               tauaero(2*k+3,iaer)=max(temp-tauaero(2*k+2,iaer),0.d0)
695
696            end do
697            ! boundary conditions
698            tauaero(1,iaer)          = tauaero(2,iaer)
699            !tauaero(1,iaer)          = 0.
700            !JL18 at time of testing, the two above conditions gave the same results bit for bit.
701
702         end do ! naerkind
703      else
704         tauaero(:,:)=0
705      end if ! optichaze
706
707         ! Albedo and Emissivity.
708         albi=1-emis(ig)   ! Long Wave.
709         DO nw=1,L_NSPECTV ! Short Wave loop.
710            albv(nw)=albedo(ig,nw)
711         ENDDO
712
713         acosz=mu0(ig) ! Cosine of sun incident angle : 3D simulations or local 1D simulations using latitude.
714
715      !-----------------------------------------------------------------------
716      !  Methane Vapor
717      !-----------------------------------------------------------------------
718      if (methane) then
719         do l=1,nlayer
720            qvar(2*l) = vmrch4(ig,nlayer+1-l)/100.*    &
721                        mmol(igcm_ch4_gas)/mmol(igcm_n2)
722            qvar(2*l+1) = ((vmrch4(ig,nlayer+1-l)+vmrch4(ig, &
723                           max(nlayer-l,1)))/2.)/100.* &
724                           mmol(igcm_ch4_gas)/mmol(igcm_n2)
725         end do
726         qvar(1)=qvar(2)
727
728      else
729         do k=1,L_LEVELS
730            qvar(k) = 1.0D-7
731         end do
732      end if ! end methane
733
734!-----------------------------------------------------------------------
735!     kcm mode only !
736!-----------------------------------------------------------------------
737
738      DO l=1,nlayer
739         muvarrad(2*l)   = muvar(ig,nlayer+2-l)
740         muvarrad(2*l+1) = (muvar(ig,nlayer+2-l)+muvar(ig,max(nlayer+1-l,1)))/2
741      END DO
742
743      muvarrad(1) = muvarrad(2)
744      muvarrad(2*nlayer+1)=muvar(ig,1)
745
746      ! Keep values inside limits for which we have radiative transfer coefficients !!!
747      if(L_REFVAR.gt.1)then ! (there was a bug here)
748         do k=1,L_LEVELS
749            if(qvar(k).lt.wrefvar(1))then
750               qvar(k)=wrefvar(1)+1.0e-8
751            elseif(qvar(k).gt.wrefvar(L_REFVAR))then
752               qvar(k)=wrefvar(L_REFVAR)-1.0e-8
753            endif
754         end do
755      endif
756
757!-----------------------------------------------------------------------
758!     Pressure and temperature
759!-----------------------------------------------------------------------
760
761      DO l=1,nlayer
762         plevrad(2*l)   = pplay(ig,nlayer+1-l)/scalep
763         plevrad(2*l+1) = pplev(ig,nlayer+1-l)/scalep
764         tlevrad(2*l)   = pt(ig,nlayer+1-l)
765         tlevrad(2*l+1) = (pt(ig,nlayer+1-l)+pt(ig,max(nlayer-l,1)))/2
766      END DO
767
768      plevrad(1) = 0.
769      !!plevrad(2) = 0.   !! JL18 enabling this line puts the radiative top at p=0 which was the idea before, but does not seem to perform best after all.
770
771      tlevrad(1) = tlevrad(2)
772      tlevrad(2*nlayer+1)=tsurf(ig)
773
774      pmid(1) = pplay(ig,nlayer)/scalep
775      pmid(2) =  pmid(1)
776
777      tmid(1) = tlevrad(2)
778      tmid(2) = tmid(1)
779
780      DO l=1,L_NLAYRAD-1
781         tmid(2*l+1) = tlevrad(2*l+1)
782         tmid(2*l+2) = tlevrad(2*l+1)
783         pmid(2*l+1) = plevrad(2*l+1)
784         pmid(2*l+2) = plevrad(2*l+1)
785      END DO
786      pmid(L_LEVELS) = plevrad(L_LEVELS)
787      tmid(L_LEVELS) = tlevrad(L_LEVELS)
788
789!!Alternative interpolation:
790!         pmid(3) = pmid(1)
791!         pmid(4) = pmid(1)
792!         tmid(3) = tmid(1)
793!         tmid(4) = tmid(1)
794!      DO l=2,L_NLAYRAD-1
795!         tmid(2*l+1) = tlevrad(2*l)
796!         tmid(2*l+2) = tlevrad(2*l)
797!         pmid(2*l+1) = plevrad(2*l)
798!         pmid(2*l+2) = plevrad(2*l)
799!      END DO
800!      pmid(L_LEVELS) = plevrad(L_LEVELS-1)
801!      tmid(L_LEVELS) = tlevrad(L_LEVELS-1)
802
803      ! Test for out-of-bounds pressure.
804      if(plevrad(3).lt.pgasmin)then
805         print*,'Warning: minimum pressure is outside the radiative'
806         print*,'transfer kmatrix bounds, exiting.'
807         print*,'Pressure:', plevrad(3), 'Pa'
808         message="Minimum pressure outside of kmatrix bounds"
809         !call abort_physic(subname,message,1)
810      elseif(plevrad(L_LEVELS).gt.pgasmax)then
811         print*,'Maximum pressure is outside the radiative'
812         print*,'transfer kmatrix bounds, exiting.'
813         message="Minimum pressure outside of kmatrix bounds"
814         call abort_physic(subname,message,1)
815      endif
816
817      ! Test for out-of-bounds temperature.
818      ! -- JVO 20 : Also add a sanity test checking that tlevrad is
819      !             within Planck function temperature boundaries,
820      !             which would cause gfluxi/sfluxi to crash.
821      do k=1,L_LEVELS
822
823         if(tlevrad(k).lt.tgasmin)then
824            print*,'Minimum temperature is outside the radiative'
825            print*,'transfer kmatrix bounds'
826            print*,"k=",k," tlevrad(k)=",tlevrad(k)
827            print*,"tgasmin=",tgasmin
828            if (strictboundcorrk) then
829              message="Minimum temperature outside of kmatrix bounds"
830              call abort_physic(subname,message,1)
831            else
832              print*,'***********************************************'
833              print*,'we allow model to continue with tlevrad<tgasmin'
834              print*,'  ... we assume we know what you are doing ... '
835              print*,'  ... but do not let this happen too often ... '
836              print*,'***********************************************'
837              !tlevrad(k)=tgasmin ! Used in the source function !
838            endif
839         elseif(tlevrad(k).gt.tgasmax)then
840            print*,'Maximum temperature is outside the radiative'
841            print*,'transfer kmatrix bounds, exiting.'
842            print*,"k=",k," tlevrad(k)=",tlevrad(k)
843            print*,"tgasmax=",tgasmax
844            if (strictboundcorrk) then
845              message="Maximum temperature outside of kmatrix bounds"
846              call abort_physic(subname,message,1)
847            else
848              print*,'***********************************************'
849              print*,'we allow model to continue with tlevrad>tgasmax'
850              print*,'  ... we assume we know what you are doing ... '
851              print*,'  ... but do not let this happen too often ... '
852              print*,'***********************************************'
853              !tlevrad(k)=tgasmax ! Used in the source function !
854            endif
855         endif
856
857         if (tlevrad(k).lt.tplanckmin) then
858            print*,'Minimum temperature is outside the boundaries for'
859            print*,'Planck function integration set in callphys.def, aborting.'
860            print*,"k=",k," tlevrad(k)=",tlevrad(k)
861            print*,"tplanckmin=",tplanckmin
862            message="Minimum temperature outside Planck function bounds - Change tplanckmin in callphys.def"
863            call abort_physic(subname,message,1)
864          else if (tlevrad(k).gt.tplanckmax) then
865            print*,'Maximum temperature is outside the boundaries for'
866            print*,'Planck function integration set in callphys.def, aborting.'
867            print*,"k=",k," tlevrad(k)=",tlevrad(k)
868            print*,"tplanckmax=",tplanckmax
869            message="Maximum temperature outside Planck function bounds - Change tplanckmax in callphys.def"
870            call abort_physic(subname,message,1)
871          endif
872
873      enddo
874
875      do k=1,L_NLAYRAD+1
876         if(tmid(k).lt.tgasmin)then
877            print*,'Minimum temperature is outside the radiative'
878            print*,'transfer kmatrix bounds, exiting.'
879            print*,"k=",k," tmid(k)=",tmid(k)
880            print*,"tgasmin=",tgasmin
881            if (strictboundcorrk) then
882              message="Minimum temperature outside of kmatrix bounds"
883              call abort_physic(subname,message,1)
884            else
885              print*,'***********************************************'
886              print*,'we allow model to continue but with tmid=tgasmin'
887              print*,'  ... we assume we know what you are doing ... '
888              print*,'  ... but do not let this happen too often ... '
889              print*,'***********************************************'
890              tmid(k)=tgasmin
891            endif
892         elseif(tmid(k).gt.tgasmax)then
893            print*,'Maximum temperature is outside the radiative'
894            print*,'transfer kmatrix bounds, exiting.'
895            print*,"k=",k," tmid(k)=",tmid(k)
896            print*,"tgasmax=",tgasmax
897            if (strictboundcorrk) then
898              message="Maximum temperature outside of kmatrix bounds"
899              call abort_physic(subname,message,1)
900            else
901              print*,'***********************************************'
902              print*,'we allow model to continue but with tmid=tgasmax'
903              print*,'  ... we assume we know what you are doing ... '
904              print*,'  ... but do not let this happen too often ... '
905              print*,'***********************************************'
906              tmid(k)=tgasmax
907            endif
908         endif
909      enddo
910
911!=======================================================================
912!          III. Calling the main radiative transfer subroutines
913!=======================================================================
914
915! ----------------------------------------------------------------
916! Recombine reference corrk tables if needed - Added by JVO, 2020.
917         if (corrk_recombin) then
918           call call_recombin(ig,nlayer,pq(ig,:,:),pplay(ig,:),pt(ig,:),qvar(:),tmid(:),pmid(:))
919         endif
920! ----------------------------------------------------------------
921
922         Cmk= 0.01 * 1.0 / (glat(ig) * mugaz * 1.672621e-27) ! q_main=1.0 assumed.
923         glat_ig=glat(ig)
924
925!-----------------------------------------------------------------------
926!        Short Wave Part
927!-----------------------------------------------------------------------
928
929         ! Call everywhere for diagnostics.
930         call optcv(dtauv,tauv,taucumv,plevrad,                 &
931                 qxvaer,qsvaer,gvaer,wbarv,cosbv,tauray,tauaero,   &
932                 tmid,pmid,taugsurf,qvar,muvarrad)
933
934         if(fract(ig) .ge. 1.0e-4) then ! Only during daylight.
935            if((ngrid.eq.1).and.(global1d))then
936               do nw=1,L_NSPECTV
937                  stel_fract(nw)= stel(nw)* 0.25 / acosz ! globally averaged = divide by 4, and we correct for solar zenith angle
938               end do
939            else
940               do nw=1,L_NSPECTV
941                  stel_fract(nw)= stel(nw) * fract(ig)
942               end do
943            endif
944
945            call sfluxv(dtauv,tauv,taucumv,albv,dwnv,wbarv,cosbv,   &
946                 acosz,stel_fract,nfluxtopv,fluxtopvdn,nfluxoutv_nu,&
947                 nfluxgndv_nu,nfluxtopv_nu, &
948                 fmnetv,fmnetv_nu,fluxupv,fluxdnv,fzerov,taugsurf)
949
950         else ! During the night, fluxes = 0.
951            nfluxtopv       = 0.0d0
952            fluxtopvdn      = 0.0d0
953            nfluxtopv_nu(:) = 0.0d0
954            nfluxoutv_nu(:) = 0.0d0
955            nfluxgndv_nu(:) = 0.0d0
956            fmnetv_nu(:,:)  = 0.0d0
957            fmnetv(:)       = 0.0d0
958            fluxupv(:)      = 0.0d0
959            fluxdnv(:)      = 0.0d0
960         end if
961
962
963         ! Equivalent Albedo Calculation (for OUTPUT). MT2015
964         if(fract(ig) .ge. 1.0e-4) then ! equivalent albedo makes sense only during daylight.
965            surface_stellar_flux=sum(nfluxgndv_nu(1:L_NSPECTV))
966            if(surface_stellar_flux .gt. 1.0e-3) then ! equivalent albedo makes sense only if the stellar flux received by the surface is positive.
967               DO nw=1,L_NSPECTV
968                  albedo_temp(nw)=albedo(ig,nw)*nfluxgndv_nu(nw)
969               ENDDO
970               albedo_temp(1:L_NSPECTV)=albedo_temp(1:L_NSPECTV)/surface_stellar_flux
971               albedo_equivalent(ig)=sum(albedo_temp(1:L_NSPECTV))
972            else
973               albedo_equivalent(ig)=0.0 ! Spectrally Integrated Albedo not defined for non-irradiated grid points. So we arbitrary set the equivalent albedo to 0.
974            endif
975         else
976            albedo_equivalent(ig)=0.0 ! Spectrally Integrated Albedo not defined for non-irradiated grid points. So we arbitrary set the equivalent albedo to 0.
977         endif
978
979
980!-----------------------------------------------------------------------
981!        Long Wave Part
982!-----------------------------------------------------------------------
983
984         call optci(plevrad,tlevrad,dtaui,taucumi,                  &
985              qxiaer,qsiaer,giaer,cosbi,wbari,tauaero,tmid,pmid,    &
986              taugsurfi,qvar,muvarrad)
987
988         call sfluxi(plevrad,tlevrad,dtaui,taucumi,ubari,albi,      &
989              wnoi,dwni,cosbi,wbari,nfluxtopi,nfluxtopi_nu,         &
990              fmneti,fmneti_nu,fluxupi,fluxdni,fluxupi_nu,fzeroi,taugsurfi)
991
992!-----------------------------------------------------------------------
993!     Transformation of the correlated-k code outputs
994!     (into dtlw, dtsw, fluxsurf_lw, fluxsurf_sw, fluxtop_lw, fluxtop_sw)
995
996!     Flux incident at the top of the atmosphere
997         fluxtop_dn(ig)=fluxtopvdn
998
999         fluxtop_lw(ig)  = real(nfluxtopi)
1000         fluxabs_sw(ig)  = real(-nfluxtopv)
1001         fluxsurf_lw(ig) = real(fluxdni(L_NLAYRAD))
1002         fluxsurf_sw(ig) = real(fluxdnv(L_NLAYRAD))
1003
1004!        Flux absorbed by the surface. By MT2015.
1005         fluxsurfabs_sw(ig) = fluxsurf_sw(ig)*(1.-albedo_equivalent(ig))
1006
1007         if(fluxtop_dn(ig).lt.0.0)then
1008            print*,'Achtung! fluxtop_dn has lost the plot!'
1009            print*,'fluxtop_dn=',fluxtop_dn(ig)
1010            print*,'acosz=',acosz
1011            print*,'dtau_aer=',dtau_aer(ig,:,:)
1012            print*,'temp=   ',pt(ig,:)
1013            print*,'pplay=  ',pplay(ig,:)
1014            message="Achtung! fluxtop_dn has lost the plot!"
1015            call abort_physic(subname,message,1)
1016         endif
1017
1018!     Spectral output, for exoplanet observational comparison
1019         if(specOLR)then
1020            do nw=1,L_NSPECTI
1021               OLR_nu(ig,nw)=nfluxtopi_nu(nw)/DWNI(nw) !JL Normalize to the bandwidth
1022            end do
1023            do nw=1,L_NSPECTV
1024               GSR_nu(ig,nw)=nfluxgndv_nu(nw)/DWNV(nw)
1025               OSR_nu(ig,nw)=nfluxoutv_nu(nw)/DWNV(nw) !JL Normalize to the bandwidth
1026            end do
1027         endif
1028
1029!     Finally, the heating rates
1030         DO l=2,L_NLAYRAD
1031            ! dtsw(ig,L_NLAYRAD+1-l)=(fmnetv(l)-fmnetv(l-1))  &
1032            !     *glat(ig)/(cpp*scalep*(plevrad(2*l+1)-plevrad(2*l-1)))
1033            dpp = glat(ig)/(cpp*scalep*(plevrad(2*l+1)-plevrad(2*l-1)))
1034            do nw=1,L_NSPECTV
1035                dtsw_nu(L_NLAYRAD+1-l,nw)= &
1036                   (fmnetv_nu(l,nw)-fmnetv_nu(l-1,nw))*dpp
1037            end do
1038
1039            ! dtlw(ig,L_NLAYRAD+1-l)=(fmneti(l)-fmneti(l-1))  &
1040            !     *glat(ig)/(cpp*scalep*(plevrad(2*l+1)-plevrad(2*l-1)))
1041            do nw=1,L_NSPECTI
1042                dtlw_nu(L_NLAYRAD+1-l,nw)= &
1043                   (fmneti_nu(l,nw)-fmneti_nu(l-1,nw))*dpp
1044            end do
1045         END DO
1046
1047!     These are values at top of atmosphere
1048        !  dtsw(ig,L_NLAYRAD)=(fmnetv(1)-nfluxtopv)           &
1049        !      *glat(ig)/(cpp*scalep*(plevrad(3)-plevrad(2)))
1050        !  dtlw(ig,L_NLAYRAD)=(fmneti(1)-nfluxtopi)           &
1051        !      *glat(ig)/(cpp*scalep*(plevrad(3)-plevrad(2)))
1052         dpp = g/(cpp*scalep*(plevrad(3)-plevrad(1)))
1053         do nw=1,L_NSPECTV
1054            dtsw_nu(L_NLAYRAD,nw)= &
1055             (fmnetv_nu(1,nw)-nfluxtopv_nu(nw))*dpp
1056         end do
1057         do nw=1,L_NSPECTI
1058             dtlw_nu(L_NLAYRAD,nw)= &
1059             (fmneti_nu(1,nw)-nfluxtopi_nu(nw))*dpp
1060         end do
1061
1062         ! Optical thickness diagnostics
1063         ! Output exp(-tau) because gweight ponderates exp and not tau itself
1064         int_dtauv(ig,:,:) = 0.0d0
1065         int_dtaui(ig,:,:) = 0.0d0
1066         do l=1,L_NLAYRAD
1067            do nw=1,L_NSPECTV
1068               do k=1,L_NGAUSS
1069                  int_dtauv(ig,l,nw) = int_dtauv(ig,l,nw) + exp(-dtauv(l,nw,k))*gweight(k)
1070               enddo
1071            enddo
1072            do nw=1,L_NSPECTI
1073               do k=1,L_NGAUSS
1074                  int_dtaui(ig,l,nw) = int_dtaui(ig,l,nw) + exp(-dtaui(l,nw,k))*gweight(k)
1075               enddo
1076            enddo
1077         enddo
1078
1079! **********************************************************
1080!     NON NLTE correction in Pluto atmosphere
1081!     And conversion of LW spectral heating rates to total rates
1082! **********************************************************
1083
1084      if (.not.nlte) then
1085        eps_nlte_sw23(ig,:) =1. ! IF no NLTE
1086        eps_nlte_sw33(ig,:) =1. ! IF no NLTE
1087        eps_nlte_lw(ig,:) =1. ! IF no NLTE
1088     endif
1089
1090     do l=1,nlayer
1091
1092        !LW
1093        dtlw(ig,l) =0.
1094!           dtlw_co(ig,l) =0.  ! only for diagnostic
1095        do nw=1,L_NSPECTI
1096          ! wewei : wavelength in micrometer
1097          if ((wavei(nw).gt.6.).and.(wavei(nw).lt.9)) then
1098            dtlw_nu(l,nw)=dtlw_nu(l,nw)*eps_nlte_lw(ig,l)
1099          else
1100            !dtlw_nu(l,nw)=1.*dtlw_nu(l,nw) ! no CO correction (Strobbel 1996)
1101            dtlw_nu(l,nw)=0.33*dtlw_nu(l,nw) ! CO correction (Strobbel 1996)
1102!               dtlw_co(ig,l)=dtlw_co(ig,l)+ dtlw_nu(l,nw) ! diagnostic
1103          end if
1104          dtlw(ig,l)=dtlw(ig,l)+ dtlw_nu(l,nw) !average now on each wavelength
1105        end do
1106        ! adding c2h2 if cooling active
1107        if (cooling) then
1108         dtlw(ig,l)=dtlw(ig,l)+dtlw_hcn_c2h2(ig,l)
1109        endif
1110
1111        !SW
1112        dtsw(ig,l) =0.
1113
1114        if (strobel) then
1115
1116         do nw=1,L_NSPECTV
1117          if ((wavev(nw).gt.2).and.(wavev(nw).lt.2.6)) then
1118            dtsw_nu(l,nw)=dtsw_nu(l,nw)*eps_nlte_sw23(ig,l)
1119          elseif ((wavev(nw).gt.3).and.(wavev(nw).lt.3.6)) then
1120            dtsw_nu(l,nw)=dtsw_nu(l,nw)*eps_nlte_sw33(ig,l)
1121          else
1122            dtsw_nu(l,nw)=dtsw_nu(l,nw)
1123          end if
1124          dtsw(ig,l)=dtsw(ig,l)+ dtsw_nu(l,nw)
1125         end do
1126
1127        else ! total heating rates multiplied by nlte coef
1128
1129         do nw=1,L_NSPECTV
1130            dtsw_nu(l,nw)=dtsw_nu(l,nw)*eps_nlte_sw23(ig,l)
1131            dtsw(ig,l)=dtsw(ig,l)+ dtsw_nu(l,nw)
1132         enddo
1133
1134        endif
1135
1136
1137     end do
1138! **********************************************************
1139
1140
1141!-----------------------------------------------------------------------
1142      end do ! End of big loop over every GCM column.
1143!-----------------------------------------------------------------------
1144
1145
1146!-----------------------------------------------------------------------
1147!     Additional diagnostics
1148!-----------------------------------------------------------------------
1149
1150      ! IR spectral output, for exoplanet observational comparison
1151      if(lastcall.and.(ngrid.eq.1))then  ! could disable the 1D output, they are in the diagfi and diagspec... JL12
1152
1153         print*,'Saving scalar quantities in surf_vals.out...'
1154         print*,'psurf = ', pplev(1,1),' Pa'
1155         open(116,file='surf_vals.out')
1156         write(116,*) tsurf(1),pplev(1,1),fluxtop_dn(1),         &
1157                      real(-nfluxtopv),real(nfluxtopi)
1158         close(116)
1159
1160
1161!          USEFUL COMMENT - Do Not Remove.
1162!
1163!           if(specOLR)then
1164!               open(117,file='OLRnu.out')
1165!               do nw=1,L_NSPECTI
1166!                  write(117,*) OLR_nu(1,nw)
1167!               enddo
1168!               close(117)
1169!
1170!               open(127,file='OSRnu.out')
1171!               do nw=1,L_NSPECTV
1172!                  write(127,*) OSR_nu(1,nw)
1173!               enddo
1174!               close(127)
1175!           endif
1176
1177           ! OLR vs altitude: do it as a .txt file.
1178         OLRz=.false.
1179         if(OLRz)then
1180            print*,'saving IR vertical flux for OLRz...'
1181            open(118,file='OLRz_plevs.out')
1182            open(119,file='OLRz.out')
1183            do l=1,L_NLAYRAD
1184               write(118,*) plevrad(2*l)
1185               do nw=1,L_NSPECTI
1186                  write(119,*) fluxupi_nu(l,nw)
1187               enddo
1188            enddo
1189            close(118)
1190            close(119)
1191         endif
1192
1193      endif
1194
1195      ! See physiq.F for explanations about CLFvarying. This is temporary.
1196      if (lastcall) then
1197        IF( ALLOCATED( gasi ) ) DEALLOCATE( gasi )
1198        IF( ALLOCATED( gasv ) ) DEALLOCATE( gasv )
1199!$OMP BARRIER
1200!$OMP MASTER
1201        IF( ALLOCATED( pgasref ) ) DEALLOCATE( pgasref )
1202        IF( ALLOCATED( tgasref ) ) DEALLOCATE( tgasref )
1203        IF( ALLOCATED( wrefvar ) ) DEALLOCATE( wrefvar )
1204        IF( ALLOCATED( pfgasref ) ) DEALLOCATE( pfgasref )
1205        IF( ALLOCATED( gweight ) ) DEALLOCATE( gweight )
1206!$OMP END MASTER
1207!$OMP BARRIER
1208        IF ( ALLOCATED(reffrad)) DEALLOCATE(reffrad)
1209        IF ( ALLOCATED(nueffrad)) DEALLOCATE(nueffrad)
1210      endif
1211
1212
1213    end subroutine callcorrk
1214
1215END MODULE callcorrk_mod
Note: See TracBrowser for help on using the repository browser.