source: trunk/LMDZ.GENERIC/libf/phystd/callcorrk.F90 @ 1485

Last change on this file since 1485 was 1483, checked in by mturbet, 10 years ago

cleanup of callcorrk

  • Property svn:executable set to *
File size: 37.2 KB
Line 
1      subroutine callcorrk(ngrid,nlayer,pq,nq,qsurf,           &
2          albedo,albedo_equivalent,emis,mu0,pplev,pplay,pt,    &
3          tsurf,fract,dist_star,aerosol,muvar,                 &
4          dtlw,dtsw,fluxsurf_lw,                               &
5          fluxsurf_sw,fluxsurfabs_sw,fluxtop_lw,               &
6          fluxabs_sw,fluxtop_dn,                               &
7          OLR_nu,OSR_nu,                                       &
8          tau_col,cloudfrac,totcloudfrac,                      &
9          clearsky,firstcall,lastcall)
10
11      use radinc_h
12      use radcommon_h
13      use watercommon_h
14      use datafile_mod, only: datadir
15      use ioipsl_getincom_p
16      use gases_h
17      use radii_mod, only : su_aer_radii,co2_reffrad,h2o_reffrad,dust_reffrad,h2so4_reffrad,back2lay_reffrad
18      use aerosol_mod, only : iaero_co2,iaero_h2o,iaero_dust,iaero_h2so4, iaero_back2lay
19      USE tracer_h
20      use comcstfi_mod, only: pi, mugaz, cpp
21      use callkeys_mod, only: varactive,diurnal,tracer,water,nosurf,varfixed,satval,    &
22                              kastprof,strictboundcorrk,specOLR,CLFvarying
23
24      implicit none
25
26!==================================================================
27!
28!     Purpose
29!     -------
30!     Solve the radiative transfer using the correlated-k method for
31!     the gaseous absorption and the Toon et al. (1989) method for
32!     scatttering due to aerosols.
33!
34!     Authors
35!     -------
36!     Emmanuel 01/2001, Forget 09/2001
37!     Robin Wordsworth (2009)
38!
39!==================================================================
40
41!-----------------------------------------------------------------------
42!     Declaration of the arguments (INPUT - OUTPUT) on the LMD GCM grid
43!     Layer #1 is the layer near the ground.
44!     Layer #nlayer is the layer at the top.
45!-----------------------------------------------------------------------
46
47
48      ! INPUT
49      INTEGER,INTENT(IN) :: ngrid                  ! Number of atmospheric columns.
50      INTEGER,INTENT(IN) :: nlayer                 ! Number of atmospheric layers.
51      REAL,INTENT(IN) :: pq(ngrid,nlayer,nq)       ! Tracers (kg/kg_of_air).
52      INTEGER,INTENT(IN) :: nq                     ! Number of tracers.
53      REAL,INTENT(IN) :: qsurf(ngrid,nq)           ! Tracers on surface (kg.m-2).
54      REAL,INTENT(IN) :: albedo(ngrid,L_NSPECTV)   ! Spectral Short Wavelengths Albedo. By MT2015
55      REAL,INTENT(IN) :: emis(ngrid)               ! Long Wave emissivity.
56      REAL,INTENT(IN) :: mu0(ngrid)                ! Cosine of sun incident angle.
57      REAL,INTENT(IN) :: pplev(ngrid,nlayer+1)     ! Inter-layer pressure (Pa).
58      REAL,INTENT(IN) :: pplay(ngrid,nlayer)       ! Mid-layer pressure (Pa).
59      REAL,INTENT(IN) :: pt(ngrid,nlayer)          ! Air temperature (K).
60      REAL,INTENT(IN) :: tsurf(ngrid)              ! Surface temperature (K).
61      REAL,INTENT(IN) :: fract(ngrid)              ! Fraction of day.
62      REAL,INTENT(IN) :: dist_star                 ! Distance star-planet (AU).
63      REAL,INTENT(IN) :: muvar(ngrid,nlayer+1)
64      REAL,INTENT(IN) :: cloudfrac(ngrid,nlayer)   ! Fraction of clouds (%).
65      logical,intent(in) :: clearsky
66      logical,intent(in) :: firstcall              ! Signals first call to physics.
67      logical,intent(in) :: lastcall               ! Signals last call to physics.
68     
69      ! OUTPUT
70      REAL,INTENT(OUT) :: aerosol(ngrid,nlayer,naerkind) ! Aerosol tau (kg/kg).
71      REAL,INTENT(OUT) :: dtlw(ngrid,nlayer)             ! Heating rate (K/s) due to LW radiation.
72      REAL,INTENT(OUT) :: dtsw(ngrid,nlayer)             ! Heating rate (K/s) due to SW radiation.
73      REAL,INTENT(OUT) :: fluxsurf_lw(ngrid)             ! Incident LW flux to surf (W/m2).
74      REAL,INTENT(OUT) :: fluxsurf_sw(ngrid)             ! Incident SW flux to surf (W/m2)
75      REAL,INTENT(OUT) :: fluxsurfabs_sw(ngrid)          ! Absorbed SW flux by the surface (W/m2). By MT2015.
76      REAL,INTENT(OUT) :: fluxtop_lw(ngrid)              ! Outgoing LW flux to space (W/m2).
77      REAL,INTENT(OUT) :: fluxabs_sw(ngrid)              ! SW flux absorbed by the planet (W/m2).
78      REAL,INTENT(OUT) :: fluxtop_dn(ngrid)              ! Incident top of atmosphere SW flux (W/m2).
79      REAL,INTENT(OUT) :: OLR_nu(ngrid,L_NSPECTI)        ! Outgoing LW radition in each band (Normalized to the band width (W/m2/cm-1).
80      REAL,INTENT(OUT) :: OSR_nu(ngrid,L_NSPECTV)        ! Outgoing SW radition in each band (Normalized to the band width (W/m2/cm-1).
81      REAL,INTENT(OUT) :: tau_col(ngrid)                 ! Diagnostic from aeropacity.
82      REAL,INTENT(OUT) :: albedo_equivalent(ngrid)       ! Spectrally Integrated Albedo. For Diagnostic. By MT2015
83      REAL,INTENT(OUT) :: totcloudfrac(ngrid)            ! Column Fraction of clouds (%).
84     
85     
86     
87     
88
89      ! Globally varying aerosol optical properties on GCM grid ; not needed everywhere so not in radcommon_h.   
90      REAL :: QVISsQREF3d(ngrid,nlayer,L_NSPECTV,naerkind)
91      REAL :: omegaVIS3d(ngrid,nlayer,L_NSPECTV,naerkind)
92      REAL :: gVIS3d(ngrid,nlayer,L_NSPECTV,naerkind)
93      REAL :: QIRsQREF3d(ngrid,nlayer,L_NSPECTI,naerkind)
94      REAL :: omegaIR3d(ngrid,nlayer,L_NSPECTI,naerkind)
95      REAL :: gIR3d(ngrid,nlayer,L_NSPECTI,naerkind)
96
97!      REAL :: omegaREFvis3d(ngrid,nlayer,naerkind)
98!      REAL :: omegaREFir3d(ngrid,nlayer,naerkind) ! not sure of the point of these...
99
100      REAL,ALLOCATABLE,SAVE :: reffrad(:,:,:)  ! aerosol effective radius (m)
101      REAL,ALLOCATABLE,SAVE :: nueffrad(:,:,:) ! aerosol effective variance
102!$OMP THREADPRIVATE(reffrad,nueffrad)
103
104!-----------------------------------------------------------------------
105!     Declaration of the variables required by correlated-k subroutines
106!     Numbered from top to bottom (unlike in the GCM)
107!-----------------------------------------------------------------------
108
109      REAL*8 tmid(L_LEVELS),pmid(L_LEVELS)
110      REAL*8 tlevrad(L_LEVELS),plevrad(L_LEVELS)
111
112      ! Optical values for the optci/cv subroutines
113      REAL*8 stel(L_NSPECTV),stel_fract(L_NSPECTV)
114      REAL*8 dtaui(L_NLAYRAD,L_NSPECTI,L_NGAUSS)
115      REAL*8 dtauv(L_NLAYRAD,L_NSPECTV,L_NGAUSS)
116      REAL*8 cosbv(L_NLAYRAD,L_NSPECTV,L_NGAUSS)
117      REAL*8 cosbi(L_NLAYRAD,L_NSPECTI,L_NGAUSS)
118      REAL*8 wbari(L_NLAYRAD,L_NSPECTI,L_NGAUSS)
119      REAL*8 wbarv(L_NLAYRAD,L_NSPECTV,L_NGAUSS)
120      REAL*8 tauv(L_NLEVRAD,L_NSPECTV,L_NGAUSS)
121      REAL*8 taucumv(L_LEVELS,L_NSPECTV,L_NGAUSS)
122      REAL*8 taucumi(L_LEVELS,L_NSPECTI,L_NGAUSS)
123
124      REAL*8 tauaero(L_LEVELS+1,naerkind)
125      REAL*8 nfluxtopv,nfluxtopi,nfluxtop,fluxtopvdn
126      REAL*8 nfluxoutv_nu(L_NSPECTV)                 ! Outgoing band-resolved VI flux at TOA (W/m2).
127      REAL*8 nfluxtopi_nu(L_NSPECTI)                 ! Net band-resolved IR flux at TOA (W/m2).
128      REAL*8 fluxupi_nu(L_NLAYRAD,L_NSPECTI)         ! For 1D diagnostic.
129      REAL*8 fmneti(L_NLAYRAD),fmnetv(L_NLAYRAD)
130      REAL*8 fluxupv(L_NLAYRAD),fluxupi(L_NLAYRAD)
131      REAL*8 fluxdnv(L_NLAYRAD),fluxdni(L_NLAYRAD)
132      REAL*8 albi,acosz
133      REAL*8 albv(L_NSPECTV)                         ! Spectral Visible Albedo.
134
135      INTEGER ig,l,k,nw,iaer
136
137      real szangle
138      logical global1d
139      save szangle,global1d
140!$OMP THREADPRIVATE(szangle,global1d)
141      real*8 taugsurf(L_NSPECTV,L_NGAUSS-1)
142      real*8 taugsurfi(L_NSPECTI,L_NGAUSS-1)
143      real*8 qvar(L_LEVELS)                    ! Mixing ratio of variable component (mol/mol).
144
145      ! Local aerosol optical properties for each column on RADIATIVE grid.
146      real*8,save ::  QXVAER(L_LEVELS+1,L_NSPECTV,naerkind)
147      real*8,save ::  QSVAER(L_LEVELS+1,L_NSPECTV,naerkind)
148      real*8,save ::  GVAER(L_LEVELS+1,L_NSPECTV,naerkind)
149      real*8,save ::  QXIAER(L_LEVELS+1,L_NSPECTI,naerkind)
150      real*8,save ::  QSIAER(L_LEVELS+1,L_NSPECTI,naerkind)
151      real*8,save ::  GIAER(L_LEVELS+1,L_NSPECTI,naerkind)
152
153      !REAL :: QREFvis3d(ngrid,nlayer,naerkind)
154      !REAL :: QREFir3d(ngrid,nlayer,naerkind)
155      !save QREFvis3d, QREFir3d
156      real, dimension(:,:,:), save, allocatable :: QREFvis3d
157      real, dimension(:,:,:), save, allocatable :: QREFir3d
158!$OMP THREADPRIVATE(QXVAER,QSVAER,GVAER,QXIAER,QSIAER,GIAER,QREFvis3d,QREFir3d)
159
160
161      ! Miscellaneous :
162      real*8  temp,temp1,temp2,pweight
163      character(len=10) :: tmp1
164      character(len=10) :: tmp2
165
166      ! For fixed water vapour profiles.
167      integer i_var
168      real RH
169      real*8 pq_temp(nlayer)
170! real(KIND=r8) :: pq_temp(nlayer) ! better F90 way.. DOESNT PORT TO F77!!!
171      real ptemp, Ttemp, qsat
172
173      logical OLRz
174      real*8 NFLUXGNDV_nu(L_NSPECTV)
175
176      ! Included by RW for runaway greenhouse 1D study.
177      real vtmp(nlayer)
178      REAL*8 muvarrad(L_LEVELS)
179     
180      ! Included by MT for albedo calculations.     
181      REAL*8 albedo_temp(L_NSPECTV) ! For equivalent albedo calculation.
182
183
184
185!===============================================================
186!           I.a Initialization on first call
187!===============================================================
188
189
190      qxvaer(:,:,:)=0.0
191      qsvaer(:,:,:)=0.0
192      gvaer(:,:,:) =0.0
193
194      qxiaer(:,:,:)=0.0
195      qsiaer(:,:,:)=0.0
196      giaer(:,:,:) =0.0
197
198      if(firstcall) then
199
200         !!! ALLOCATED instances are necessary because of CLFvarying (strategy to call callcorrk twice in physiq...)
201         IF(.not.ALLOCATED(QREFvis3d)) ALLOCATE(QREFvis3d(ngrid,nlayer,naerkind))
202         IF(.not.ALLOCATED(QREFir3d)) ALLOCATE(QREFir3d(ngrid,nlayer,naerkind))
203         ! Effective radius and variance of the aerosols
204         IF(.not.ALLOCATED(reffrad)) allocate(reffrad(ngrid,nlayer,naerkind))
205         IF(.not.ALLOCATED(nueffrad)) allocate(nueffrad(ngrid,nlayer,naerkind))
206
207         call system('rm -f surf_vals_long.out')
208
209         if(naerkind.gt.4)then
210            print*,'Code not general enough to deal with naerkind > 4 yet.'
211            call abort
212         endif
213         call su_aer_radii(ngrid,nlayer,reffrad,nueffrad)
214         
215         
216!--------------------------------------------------
217!             Set up correlated k
218!--------------------------------------------------
219
220
221         print*, "callcorrk: Correlated-k data base folder:",trim(datadir)
222         call getin_p("corrkdir",corrkdir)
223         print*, "corrkdir = ",corrkdir
224         write( tmp1, '(i3)' ) L_NSPECTI
225         write( tmp2, '(i3)' ) L_NSPECTV
226         banddir=trim(adjustl(tmp1))//'x'//trim(adjustl(tmp2))
227         banddir=trim(adjustl(corrkdir))//'/'//trim(adjustl(banddir))
228
229         call setspi            ! Basic infrared properties.
230         call setspv            ! Basic visible properties.
231         call sugas_corrk       ! Set up gaseous absorption properties.
232         call suaer_corrk       ! Set up aerosol optical properties.
233
234
235         if((igcm_h2o_vap.eq.0) .and. varactive)then
236            print*,'varactive in callcorrk but no h2o_vap tracer.'
237            stop
238         endif
239
240         OLR_nu(:,:) = 0.
241         OSR_nu(:,:) = 0.
242
243         if (ngrid.eq.1) then
244            PRINT*, 'Simulate global averaged conditions ?'
245            global1d = .false. ! default value
246            call getin_p("global1d",global1d)
247            write(*,*) "global1d = ",global1d
248           
249            ! Test of incompatibility : if global1d is true, there should not be any diurnal cycle.
250            if (global1d.and.diurnal) then
251               print*,'if global1d is true, diurnal must be set to false'
252               stop
253            endif
254
255            if (global1d) then
256               PRINT *,'Solar Zenith angle (deg.) ?'
257               PRINT *,'(assumed for averaged solar flux S/4)'
258               szangle=60.0  ! default value
259               call getin_p("szangle",szangle)
260               write(*,*) "szangle = ",szangle
261            endif
262         endif
263
264      end if ! of if (firstcall)
265
266
267!=======================================================================
268!          I.b  Initialization on every call   
269!=======================================================================
270 
271 
272!--------------------------------------------------
273!     Effective radius and variance of the aerosols
274!--------------------------------------------------
275
276      do iaer=1,naerkind
277
278         if ((iaer.eq.iaero_co2).and.tracer.and.(igcm_co2_ice.gt.0)) then ! Treat condensed co2 particles.
279            call co2_reffrad(ngrid,nlayer,nq,pq,reffrad(1,1,iaero_co2))
280            print*,'Max. CO2 ice particle size = ',maxval(reffrad(1:ngrid,1:nlayer,iaer))/1.e-6,' um'
281            print*,'Min. CO2 ice particle size = ',minval(reffrad(1:ngrid,1:nlayer,iaer))/1.e-6,' um'
282         end if
283         
284         if ((iaer.eq.iaero_h2o).and.water) then ! Treat condensed water particles. To be generalized for other aerosols ...
285            call h2o_reffrad(ngrid,nlayer,pq(1,1,igcm_h2o_ice),pt, &
286                             reffrad(1,1,iaero_h2o),nueffrad(1,1,iaero_h2o))
287            print*,'Max. H2O cloud particle size = ',maxval(reffrad(1:ngrid,1:nlayer,iaer))/1.e-6,' um'
288            print*,'Min. H2O cloud particle size = ',minval(reffrad(1:ngrid,1:nlayer,iaer))/1.e-6,' um'
289         endif
290         
291         if(iaer.eq.iaero_dust)then
292            call dust_reffrad(ngrid,nlayer,reffrad(1,1,iaero_dust))
293            print*,'Dust particle size = ',reffrad(1,1,iaer)/1.e-6,' um'
294         endif
295         
296         if(iaer.eq.iaero_h2so4)then
297            call h2so4_reffrad(ngrid,nlayer,reffrad(1,1,iaero_h2so4))
298            print*,'H2SO4 particle size =',reffrad(1,1,iaer)/1.e-6,' um'
299         endif
300         
301          if(iaer.eq.iaero_back2lay)then
302            call back2lay_reffrad(ngrid,reffrad(1,1,iaero_back2lay),nlayer,pplev)
303         endif
304         
305     end do !iaer=1,naerkind.
306
307
308      ! How much light do we get ?
309      do nw=1,L_NSPECTV
310         stel(nw)=stellarf(nw)/(dist_star**2)
311      end do
312
313      ! Get 3D aerosol optical properties.
314      call aeroptproperties(ngrid,nlayer,reffrad,nueffrad,         &
315           QVISsQREF3d,omegaVIS3d,gVIS3d,                          &
316           QIRsQREF3d,omegaIR3d,gIR3d,                             &
317           QREFvis3d,QREFir3d)                                     
318
319      ! Get aerosol optical depths.
320      call aeropacity(ngrid,nlayer,nq,pplay,pplev,pq,aerosol,      &
321           reffrad,QREFvis3d,QREFir3d,                             &
322           tau_col,cloudfrac,totcloudfrac,clearsky)               
323         
324
325
326!-----------------------------------------------------------------------   
327      do ig=1,ngrid ! Starting Big Loop over every GCM column
328!-----------------------------------------------------------------------
329
330
331!=======================================================================
332!              II.  Transformation of the GCM variables
333!=======================================================================
334
335
336!-----------------------------------------------------------------------
337!    Aerosol optical properties Qext, Qscat and g.
338!    The transformation in the vertical is the same as for temperature.
339!-----------------------------------------------------------------------
340           
341           
342            do iaer=1,naerkind
343               ! Shortwave.
344               do nw=1,L_NSPECTV
345               
346                  do l=1,nlayer
347
348                     temp1=QVISsQREF3d(ig,nlayer+1-l,nw,iaer)         &
349                         *QREFvis3d(ig,nlayer+1-l,iaer)
350
351                     temp2=QVISsQREF3d(ig,max(nlayer-l,1),nw,iaer)    &
352                         *QREFvis3d(ig,max(nlayer-l,1),iaer)
353
354                     qxvaer(2*l,nw,iaer)  = temp1
355                     qxvaer(2*l+1,nw,iaer)=(temp1+temp2)/2
356
357                     temp1=temp1*omegavis3d(ig,nlayer+1-l,nw,iaer)
358                     temp2=temp2*omegavis3d(ig,max(nlayer-l,1),nw,iaer)
359
360                     qsvaer(2*l,nw,iaer)  = temp1
361                     qsvaer(2*l+1,nw,iaer)=(temp1+temp2)/2
362
363                     temp1=gvis3d(ig,nlayer+1-l,nw,iaer)
364                     temp2=gvis3d(ig,max(nlayer-l,1),nw,iaer)
365
366                     gvaer(2*l,nw,iaer)  = temp1
367                     gvaer(2*l+1,nw,iaer)=(temp1+temp2)/2
368
369                  end do ! nlayer
370
371                  qxvaer(1,nw,iaer)=qxvaer(2,nw,iaer)
372                  qxvaer(2*nlayer+1,nw,iaer)=0.
373
374                  qsvaer(1,nw,iaer)=qsvaer(2,nw,iaer)
375                  qsvaer(2*nlayer+1,nw,iaer)=0.
376
377                  gvaer(1,nw,iaer)=gvaer(2,nw,iaer)
378                  gvaer(2*nlayer+1,nw,iaer)=0.
379
380               end do ! L_NSPECTV
381             
382               do nw=1,L_NSPECTI
383                  ! Longwave
384                  do l=1,nlayer
385
386                     temp1=QIRsQREF3d(ig,nlayer+1-l,nw,iaer)         &
387                          *QREFir3d(ig,nlayer+1-l,iaer)
388
389                     temp2=QIRsQREF3d(ig,max(nlayer-l,1),nw,iaer)    &
390                          *QREFir3d(ig,max(nlayer-l,1),iaer)
391
392                     qxiaer(2*l,nw,iaer)  = temp1
393                     qxiaer(2*l+1,nw,iaer)=(temp1+temp2)/2
394
395                     temp1=temp1*omegair3d(ig,nlayer+1-l,nw,iaer)
396                     temp2=temp2*omegair3d(ig,max(nlayer-l,1),nw,iaer)
397
398                     qsiaer(2*l,nw,iaer)  = temp1
399                     qsiaer(2*l+1,nw,iaer)=(temp1+temp2)/2
400
401                     temp1=gir3d(ig,nlayer+1-l,nw,iaer)
402                     temp2=gir3d(ig,max(nlayer-l,1),nw,iaer)
403
404                     giaer(2*l,nw,iaer)  = temp1
405                     giaer(2*l+1,nw,iaer)=(temp1+temp2)/2
406
407                  end do ! nlayer
408
409                  qxiaer(1,nw,iaer)=qxiaer(2,nw,iaer)
410                  qxiaer(2*nlayer+1,nw,iaer)=0.
411
412                  qsiaer(1,nw,iaer)=qsiaer(2,nw,iaer)
413                  qsiaer(2*nlayer+1,nw,iaer)=0.
414
415                  giaer(1,nw,iaer)=giaer(2,nw,iaer)
416                  giaer(2*nlayer+1,nw,iaer)=0.
417
418               end do ! L_NSPECTI
419               
420            end do ! naerkind
421
422            ! Test / Correct for freaky s. s. albedo values.
423            do iaer=1,naerkind
424               do k=1,L_LEVELS+1
425
426                  do nw=1,L_NSPECTV
427                     if(qsvaer(k,nw,iaer).gt.1.05*qxvaer(k,nw,iaer))then
428                        print*,'Serious problems with qsvaer values'
429                        print*,'in callcorrk'
430                        call abort
431                     endif
432                     if(qsvaer(k,nw,iaer).gt.qxvaer(k,nw,iaer))then
433                        qsvaer(k,nw,iaer)=qxvaer(k,nw,iaer)
434                     endif
435                  end do
436
437                  do nw=1,L_NSPECTI
438                     if(qsiaer(k,nw,iaer).gt.1.05*qxiaer(k,nw,iaer))then
439                        print*,'Serious problems with qsiaer values'
440                        print*,'in callcorrk'
441                        call abort
442                     endif
443                     if(qsiaer(k,nw,iaer).gt.qxiaer(k,nw,iaer))then
444                        qsiaer(k,nw,iaer)=qxiaer(k,nw,iaer)
445                     endif
446                  end do
447
448               end do ! L_LEVELS
449            end do ! naerkind
450
451!-----------------------------------------------------------------------
452!     Aerosol optical depths
453!-----------------------------------------------------------------------
454           
455         do iaer=1,naerkind     ! a bug was here           
456            do k=0,nlayer-1
457               
458               pweight=(pplay(ig,L_NLAYRAD-k)-pplev(ig,L_NLAYRAD-k+1))/   &
459                       (pplev(ig,L_NLAYRAD-k)-pplev(ig,L_NLAYRAD-k+1))
460               temp=aerosol(ig,L_NLAYRAD-k,iaer)/QREFvis3d(ig,L_NLAYRAD-k,iaer)
461               tauaero(2*k+2,iaer)=max(temp*pweight,0.d0)
462               tauaero(2*k+3,iaer)=max(temp-tauaero(2*k+2,iaer),0.d0)
463
464            end do
465            ! boundary conditions
466            tauaero(1,iaer)          = tauaero(2,iaer)
467            tauaero(L_LEVELS+1,iaer) = tauaero(L_LEVELS,iaer)
468            !tauaero(1,iaer)          = 0.
469            !tauaero(L_LEVELS+1,iaer) = 0.
470           
471         end do ! naerkind
472
473         ! Albedo and Emissivity.
474         albi=1-emis(ig)   ! Long Wave.
475         DO nw=1,L_NSPECTV ! Short Wave loop.
476            albv(nw)=albedo(ig,nw)
477         ENDDO
478
479         if (nosurf) then ! Case with no surface.
480            DO nw=1,L_NSPECTV
481               if(albv(nw).gt.0.0) then
482                  print*,'For open lower boundary in callcorrk must'
483                  print*,'have spectral surface band albedos all set to zero!'
484                  call abort
485               endif
486            ENDDO         
487         endif
488
489      if ((ngrid.eq.1).and.(global1d)) then ! Fixed zenith angle 'szangle' in 1D simulations w/ globally-averaged sunlight.
490         acosz = cos(pi*szangle/180.0)
491         print*,'acosz=',acosz,', szangle=',szangle
492      else
493         acosz=mu0(ig) ! Cosine of sun incident angle : 3D simulations or local 1D simulations using latitude.
494      endif
495
496!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
497!!! Note by JL13 : In the following, some indices were changed in the interpolations,
498!!!                so that the model results are less dependent on the number of layers !
499!!!
500!!!           ---  The older versions are commented with the comment !JL13index  ---
501!!!
502!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
503
504
505!-----------------------------------------------------------------------
506!     Water vapour (to be generalised for other gases eventually ...)
507!-----------------------------------------------------------------------
508     
509      if(varactive)then
510
511         i_var=igcm_h2o_vap
512         do l=1,nlayer
513            qvar(2*l)   = pq(ig,nlayer+1-l,i_var)
514            qvar(2*l+1) = pq(ig,nlayer+1-l,i_var)   
515!JL13index            qvar(2*l+1) = (pq(ig,nlayer+1-l,i_var)+pq(ig,max(nlayer-l,1),i_var))/2   
516!JL13index            ! Average approximation as for temperature...
517         end do
518         qvar(1)=qvar(2)
519
520      elseif(varfixed)then
521
522         do l=1,nlayer ! Here we will assign fixed water vapour profiles globally.
523            RH = satval * ((pplay(ig,l)/pplev(ig,1) - 0.02) / 0.98)
524            if(RH.lt.0.0) RH=0.0
525           
526            ptemp=pplay(ig,l)
527            Ttemp=pt(ig,l)
528            call watersat(Ttemp,ptemp,qsat)
529
530            !pq_temp(l) = qsat      ! fully saturated everywhere
531            pq_temp(l) = RH * qsat ! ~realistic profile (e.g. 80% saturation at ground)
532         end do
533         
534         do l=1,nlayer
535            qvar(2*l)   = pq_temp(nlayer+1-l)
536            qvar(2*l+1) = (pq_temp(nlayer+1-l)+pq_temp(max(nlayer-l,1)))/2
537         end do
538         
539         qvar(1)=qvar(2)
540
541         ! Lowest layer of atmosphere
542         RH = satval * (1 - 0.02) / 0.98
543         if(RH.lt.0.0) RH=0.0
544
545!         ptemp = pplev(ig,1)
546!         Ttemp = tsurf(ig)
547!         call watersat(Ttemp,ptemp,qsat)
548
549         qvar(2*nlayer+1)= RH * qsat ! ~realistic profile (e.g. 80% saturation at ground)
550 
551      else
552         do k=1,L_LEVELS
553            qvar(k) = 1.0D-7
554         end do
555      end if ! varactive/varfixed
556
557      if(.not.kastprof)then
558         ! IMPORTANT: Now convert from kg/kg to mol/mol.
559         do k=1,L_LEVELS
560            qvar(k) = qvar(k)/(epsi+qvar(k)*(1.-epsi))
561         end do
562      end if
563
564!-----------------------------------------------------------------------
565!     kcm mode only !
566!-----------------------------------------------------------------------
567
568      if(kastprof)then
569
570         ! Initial values equivalent to mugaz.
571         DO l=1,nlayer
572            muvarrad(2*l)   = mugaz
573            muvarrad(2*l+1) = mugaz
574         END DO
575
576         if(ngasmx.gt.1)then
577
578            DO l=1,nlayer
579               muvarrad(2*l)   =  muvar(ig,nlayer+2-l)
580               muvarrad(2*l+1) = (muvar(ig,nlayer+2-l) + &
581                                  muvar(ig,max(nlayer+1-l,1)))/2
582            END DO
583     
584            muvarrad(1) = muvarrad(2)
585            muvarrad(2*nlayer+1) = muvar(ig,1)
586
587            print*,'Recalculating qvar with VARIABLE epsi for kastprof'
588            print*,'Assumes that the variable gas is H2O!!!'
589            print*,'Assumes that there is only one tracer'
590           
591            !i_var=igcm_h2o_vap
592            i_var=1
593           
594            if(nq.gt.1)then
595               print*,'Need 1 tracer only to run kcm1d.e'
596               stop
597            endif
598           
599            do l=1,nlayer
600               vtmp(l)=pq(ig,l,i_var)/(epsi+pq(ig,l,i_var)*(1.-epsi))
601               !vtmp(l)=pq(ig,l,i_var)*muvar(ig,l+1)/mH2O !JL to be changed
602            end do
603
604            do l=1,nlayer
605               qvar(2*l)   = vtmp(nlayer+1-l)
606               qvar(2*l+1) = vtmp(nlayer+1-l)
607!               qvar(2*l+1) = ( vtmp(nlayer+1-l) + vtmp(max(nlayer-l,1)) )/2
608            end do
609            qvar(1)=qvar(2)
610
611            print*,'Warning: reducing qvar in callcorrk.'
612            print*,'Temperature profile no longer consistent ', &
613                   'with saturated H2O. qsat=',satval
614                   
615            do k=1,L_LEVELS
616               qvar(k) = qvar(k)*satval
617            end do
618
619         endif
620      else ! if kastprof
621         DO l=1,nlayer
622            muvarrad(2*l)   = muvar(ig,nlayer+2-l)
623            muvarrad(2*l+1) = (muvar(ig,nlayer+2-l)+muvar(ig,max(nlayer+1-l,1)))/2
624         END DO
625     
626         muvarrad(1) = muvarrad(2)
627         muvarrad(2*nlayer+1)=muvar(ig,1)         
628      endif ! if kastprof
629     
630      ! Keep values inside limits for which we have radiative transfer coefficients !!!
631      if(L_REFVAR.gt.1)then ! (there was a bug here)
632         do k=1,L_LEVELS
633            if(qvar(k).lt.wrefvar(1))then
634               qvar(k)=wrefvar(1)+1.0e-8
635            elseif(qvar(k).gt.wrefvar(L_REFVAR))then
636               qvar(k)=wrefvar(L_REFVAR)-1.0e-8
637            endif
638         end do
639      endif
640
641!-----------------------------------------------------------------------
642!     Pressure and temperature
643!-----------------------------------------------------------------------
644
645      DO l=1,nlayer
646         plevrad(2*l)   = pplay(ig,nlayer+1-l)/scalep
647         plevrad(2*l+1) = pplev(ig,nlayer+1-l)/scalep
648         tlevrad(2*l)   = pt(ig,nlayer+1-l)
649         tlevrad(2*l+1) = (pt(ig,nlayer+1-l)+pt(ig,max(nlayer-l,1)))/2
650      END DO
651     
652      plevrad(1) = 0.
653      plevrad(2) = 0.   !! Trick to have correct calculations of fluxes in gflux(i/v).F, but the pmid levels are not impacted by this change.
654
655      tlevrad(1) = tlevrad(2)
656      tlevrad(2*nlayer+1)=tsurf(ig)
657     
658      pmid(1) = max(pgasmin,0.0001*plevrad(3))
659      pmid(2) =  pmid(1)
660
661      tmid(1) = tlevrad(2)
662      tmid(2) = tmid(1)
663   
664      DO l=1,L_NLAYRAD-1
665         tmid(2*l+1) = tlevrad(2*l+1)
666         tmid(2*l+2) = tlevrad(2*l+1)
667         pmid(2*l+1) = plevrad(2*l+1)
668         pmid(2*l+2) = plevrad(2*l+1)
669      END DO
670      pmid(L_LEVELS) = plevrad(L_LEVELS)
671      tmid(L_LEVELS) = tlevrad(L_LEVELS)
672
673!!Alternative interpolation:
674!         pmid(3) = pmid(1)
675!         pmid(4) = pmid(1)
676!         tmid(3) = tmid(1)
677!         tmid(4) = tmid(1)
678!      DO l=2,L_NLAYRAD-1
679!         tmid(2*l+1) = tlevrad(2*l)
680!         tmid(2*l+2) = tlevrad(2*l)
681!         pmid(2*l+1) = plevrad(2*l)
682!         pmid(2*l+2) = plevrad(2*l)
683!      END DO
684!      pmid(L_LEVELS) = plevrad(L_LEVELS-1)
685!      tmid(L_LEVELS) = tlevrad(L_LEVELS-1)
686
687      ! Test for out-of-bounds pressure.
688      if(plevrad(3).lt.pgasmin)then
689         print*,'Minimum pressure is outside the radiative'
690         print*,'transfer kmatrix bounds, exiting.'
691         call abort
692      elseif(plevrad(L_LEVELS).gt.pgasmax)then
693         print*,'Maximum pressure is outside the radiative'
694         print*,'transfer kmatrix bounds, exiting.'
695         call abort
696      endif
697
698      ! Test for out-of-bounds temperature.
699      do k=1,L_LEVELS
700         if(tlevrad(k).lt.tgasmin)then
701            print*,'Minimum temperature is outside the radiative'
702            print*,'transfer kmatrix bounds'
703            print*,"k=",k," tlevrad(k)=",tlevrad(k)
704            print*,"tgasmin=",tgasmin
705            if (strictboundcorrk) then
706              call abort
707            else
708              print*,'***********************************************'
709              print*,'we allow model to continue with tlevrad=tgasmin'
710              print*,'  ... we assume we know what you are doing ... '
711              print*,'  ... but do not let this happen too often ... '
712              print*,'***********************************************'
713              !tlevrad(k)=tgasmin
714            endif
715         elseif(tlevrad(k).gt.tgasmax)then
716            print*,'Maximum temperature is outside the radiative'
717            print*,'transfer kmatrix bounds, exiting.'
718            print*,"k=",k," tlevrad(k)=",tlevrad(k)
719            print*,"tgasmax=",tgasmax
720            if (strictboundcorrk) then
721              call abort
722            else
723              print*,'***********************************************'
724              print*,'we allow model to continue with tlevrad=tgasmax' 
725              print*,'  ... we assume we know what you are doing ... '
726              print*,'  ... but do not let this happen too often ... '
727              print*,'***********************************************'
728              !tlevrad(k)=tgasmax
729            endif
730         endif
731      enddo
732      do k=1,L_NLAYRAD+1
733         if(tmid(k).lt.tgasmin)then
734            print*,'Minimum temperature is outside the radiative'
735            print*,'transfer kmatrix bounds, exiting.'
736            print*,"k=",k," tmid(k)=",tmid(k)
737            print*,"tgasmin=",tgasmin
738            if (strictboundcorrk) then
739              call abort
740            else
741              print*,'***********************************************'
742              print*,'we allow model to continue with tmid=tgasmin'
743              print*,'  ... we assume we know what you are doing ... '
744              print*,'  ... but do not let this happen too often ... '
745              print*,'***********************************************'
746              tmid(k)=tgasmin
747            endif
748         elseif(tmid(k).gt.tgasmax)then
749            print*,'Maximum temperature is outside the radiative'
750            print*,'transfer kmatrix bounds, exiting.'
751            print*,"k=",k," tmid(k)=",tmid(k)
752            print*,"tgasmax=",tgasmax
753            if (strictboundcorrk) then
754              call abort
755            else
756              print*,'***********************************************'
757              print*,'we allow model to continue with tmid=tgasmin'
758              print*,'  ... we assume we know what you are doing ... '
759              print*,'  ... but do not let this happen too often ... '
760              print*,'***********************************************'
761              tmid(k)=tgasmax
762            endif
763         endif
764      enddo
765
766!=======================================================================
767!          III. Calling the main radiative transfer subroutines
768!=======================================================================
769
770
771         Cmk= 0.01 * 1.0 / (glat(ig) * mugaz * 1.672621e-27) ! q_main=1.0 assumed.
772         glat_ig=glat(ig)
773
774!-----------------------------------------------------------------------
775!        Short Wave Part
776!-----------------------------------------------------------------------
777
778         if(fract(ig) .ge. 1.0e-4) then ! Only during daylight.
779            if((ngrid.eq.1).and.(global1d))then
780               do nw=1,L_NSPECTV
781                  stel_fract(nw)= stel(nw)* 0.25 / acosz ! globally averaged = divide by 4, and we correct for solar zenith angle
782               end do
783            else
784               do nw=1,L_NSPECTV
785                  stel_fract(nw)= stel(nw) * fract(ig)
786               end do
787            endif
788           
789            call optcv(dtauv,tauv,taucumv,plevrad,                 &
790                 qxvaer,qsvaer,gvaer,wbarv,cosbv,tauray,tauaero,   &
791                 tmid,pmid,taugsurf,qvar,muvarrad)
792
793            call sfluxv(dtauv,tauv,taucumv,albv,dwnv,wbarv,cosbv,  &
794                 acosz,stel_fract,gweight,                         &
795                 nfluxtopv,fluxtopvdn,nfluxoutv_nu,nfluxgndv_nu,              &
796                 fmnetv,fluxupv,fluxdnv,fzerov,taugsurf)
797
798         else ! During the night, fluxes = 0.
799            nfluxtopv       = 0.0d0
800            fluxtopvdn      = 0.0d0
801            nfluxoutv_nu(:) = 0.0d0
802            nfluxgndv_nu(:) = 0.0d0
803            do l=1,L_NLAYRAD
804               fmnetv(l)=0.0d0
805               fluxupv(l)=0.0d0
806               fluxdnv(l)=0.0d0
807            end do
808         end if
809
810
811         ! Equivalent Albedo Calculation. MT2015
812         if(fract(ig) .ge. 1.0e-4) then ! equivalent albedo makes sense only during daylight.           
813            DO nw=1,L_NSPECTV             
814               albedo_temp(nw)=albedo(ig,nw)*nfluxgndv_nu(nw)
815            ENDDO
816            albedo_temp(1:L_NSPECTV)=albedo_temp(1:L_NSPECTV)/sum(nfluxgndv_nu(1:L_NSPECTV))
817            albedo_equivalent(ig)=sum(albedo_temp(1:L_NSPECTV))
818         else
819            albedo_equivalent(ig)=0.0 ! Spectrally Integrated Albedo not defined for non-irradiated grid points. So we arbitrary set the equivalent albedo to 0.
820         endif
821
822
823!-----------------------------------------------------------------------
824!        Long Wave Part
825!-----------------------------------------------------------------------
826
827         call optci(plevrad,tlevrad,dtaui,taucumi,                  &
828              qxiaer,qsiaer,giaer,cosbi,wbari,tauaero,tmid,pmid,    &
829              taugsurfi,qvar,muvarrad)
830
831         call sfluxi(plevrad,tlevrad,dtaui,taucumi,ubari,albi,      &
832              wnoi,dwni,cosbi,wbari,gweight,nfluxtopi,nfluxtopi_nu, &
833              fmneti,fluxupi,fluxdni,fluxupi_nu,fzeroi,taugsurfi)
834
835!-----------------------------------------------------------------------
836!     Transformation of the correlated-k code outputs
837!     (into dtlw, dtsw, fluxsurf_lw, fluxsurf_sw, fluxtop_lw, fluxtop_sw)
838
839!     Flux incident at the top of the atmosphere
840         fluxtop_dn(ig)=fluxtopvdn
841
842         fluxtop_lw(ig)  = real(nfluxtopi)
843         fluxabs_sw(ig)  = real(-nfluxtopv)
844         fluxsurf_lw(ig) = real(fluxdni(L_NLAYRAD))
845         fluxsurf_sw(ig) = real(fluxdnv(L_NLAYRAD))
846         
847!        Flux absorbed by the surface. By MT2015.         
848         fluxsurfabs_sw(ig) = fluxsurf_sw(ig)*(1.-albedo_equivalent(ig))
849
850         if(fluxtop_dn(ig).lt.0.0)then
851            print*,'Achtung! fluxtop_dn has lost the plot!'
852            print*,'fluxtop_dn=',fluxtop_dn(ig)
853            print*,'acosz=',acosz
854            print*,'aerosol=',aerosol(ig,:,:)
855            print*,'temp=   ',pt(ig,:)
856            print*,'pplay=  ',pplay(ig,:)
857            call abort
858         endif
859
860!     Spectral output, for exoplanet observational comparison
861         if(specOLR)then
862            do nw=1,L_NSPECTI
863               OLR_nu(ig,nw)=nfluxtopi_nu(nw)/DWNI(nw) !JL Normalize to the bandwidth
864            end do
865            do nw=1,L_NSPECTV
866               !GSR_nu(ig,nw)=nfluxgndv_nu(nw)
867               OSR_nu(ig,nw)=nfluxoutv_nu(nw)/DWNV(nw) !JL Normalize to the bandwidth
868            end do
869         endif
870
871!     Finally, the heating rates
872
873         DO l=2,L_NLAYRAD
874            dtsw(ig,L_NLAYRAD+1-l)=(fmnetv(l)-fmnetv(l-1))  &
875                *glat(ig)/(cpp*scalep*(plevrad(2*l+1)-plevrad(2*l-1)))
876            dtlw(ig,L_NLAYRAD+1-l)=(fmneti(l)-fmneti(l-1))  &
877                *glat(ig)/(cpp*scalep*(plevrad(2*l+1)-plevrad(2*l-1)))
878         END DO     
879
880!     These are values at top of atmosphere
881         dtsw(ig,L_NLAYRAD)=(fmnetv(1)-nfluxtopv)           &
882             *glat(ig)/(cpp*scalep*(plevrad(3)-plevrad(1)))
883         dtlw(ig,L_NLAYRAD)=(fmneti(1)-nfluxtopi)           &
884             *glat(ig)/(cpp*scalep*(plevrad(3)-plevrad(1)))
885
886
887!-----------------------------------------------------------------------   
888      end do ! End of big loop over every GCM column.
889!-----------------------------------------------------------------------
890
891
892
893!-----------------------------------------------------------------------
894!     Additional diagnostics
895!-----------------------------------------------------------------------
896
897      ! IR spectral output, for exoplanet observational comparison
898      if(lastcall.and.(ngrid.eq.1))then  ! could disable the 1D output, they are in the diagfi and diagspec... JL12
899
900         print*,'Saving scalar quantities in surf_vals.out...'
901         print*,'psurf = ', pplev(1,1),' Pa'
902         open(116,file='surf_vals.out')
903         write(116,*) tsurf(1),pplev(1,1),fluxtop_dn(1),         &
904                      real(-nfluxtopv),real(nfluxtopi)
905         close(116)
906
907
908!          USEFUL COMMENT - Do Not Remove.
909!
910!           if(specOLR)then
911!               open(117,file='OLRnu.out')
912!               do nw=1,L_NSPECTI
913!                  write(117,*) OLR_nu(1,nw)
914!               enddo
915!               close(117)
916!
917!               open(127,file='OSRnu.out')
918!               do nw=1,L_NSPECTV
919!                  write(127,*) OSR_nu(1,nw)
920!               enddo
921!               close(127)
922!           endif
923
924           ! OLR vs altitude: do it as a .txt file.
925         OLRz=.false.
926         if(OLRz)then
927            print*,'saving IR vertical flux for OLRz...'
928            open(118,file='OLRz_plevs.out')
929            open(119,file='OLRz.out')
930            do l=1,L_NLAYRAD
931               write(118,*) plevrad(2*l)
932               do nw=1,L_NSPECTI
933                  write(119,*) fluxupi_nu(l,nw)
934               enddo
935            enddo
936            close(118)
937            close(119)
938         endif
939
940      endif
941
942      ! See physiq.F for explanations about CLFvarying. This is temporary.
943      if (lastcall .and. .not.CLFvarying) then
944        IF( ALLOCATED( gasi ) ) DEALLOCATE( gasi )
945        IF( ALLOCATED( gasv ) ) DEALLOCATE( gasv )
946!$OMP BARRIER
947!$OMP MASTER
948        IF( ALLOCATED( pgasref ) ) DEALLOCATE( pgasref )
949        IF( ALLOCATED( tgasref ) ) DEALLOCATE( tgasref )
950        IF( ALLOCATED( wrefvar ) ) DEALLOCATE( wrefvar )
951        IF( ALLOCATED( pfgasref ) ) DEALLOCATE( pfgasref )
952!$OMP END MASTER
953!$OMP BARRIER   
954        IF ( ALLOCATED(reffrad)) DEALLOCATE(reffrad)
955        IF ( ALLOCATED(nueffrad)) DEALLOCATE(nueffrad)
956      endif
957
958
959    end subroutine callcorrk
Note: See TracBrowser for help on using the repository browser.