Skip to content

Commit

Permalink
Changing the RRTMG interface to call RRTMG as external
Browse files Browse the repository at this point in the history
  • Loading branch information
lsoucasse committed Nov 27, 2023
1 parent c2f6de5 commit 9ca4890
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 18 deletions.
35 changes: 23 additions & 12 deletions src/modraddata.f90
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
module modraddata

! implicit none
use modglobal, only : longint,kind_rb,SHR_KIND_IN,SHR_KIND_R4
use modglobal, only : longint,kind_rb,SHR_KIND_IN,SHR_KIND_R4,kind_im
use modprecision, only : field_r
SAVE

Expand Down Expand Up @@ -74,13 +74,13 @@ module modraddata
real :: cnstZenith=0. !< constant zenith angle, only used when lCnstZenith=.true. (degrees!)

! Options in NAMRADIATION that apply to the rrtmg script
integer :: ioverlap = 2 ! Cloud overlap method; 0: Clear only; 1: Random; 2: Maximum/random; 3: Maximum
integer :: inflglw = 2 ! 0:inp. cld fr and opt. depth; 1:cf and LWP are input; 2:also ice fraction inp.
integer :: iceflglw = 3 ! 0,1,2,3: ice influence calculations
integer :: liqflglw = 1 ! 0:optical depths computed; 1:drop eff. rad. is input, opt. depth computed
integer :: inflgsw = 2 ! 0:inp. cld fr and opt. depth; 1:cf and LWP are input; 2:also ice fraction inp.
integer :: iceflgsw = 3 ! 0,1,2,3: ice influence calculations
integer :: liqflgsw = 1 ! 0:optical depths computed; 1:drop eff. rad. is input, opt. depth computed
integer(kind=kind_im) :: ioverlap = 2 ! Cloud overlap method; 0: Clear only; 1: Random; 2: Maximum/random; 3: Maximum
integer(kind=kind_im) :: inflglw = 2 ! 0:inp. cld fr and opt. depth; 1:cf and LWP are input; 2:also ice fraction inp.
integer(kind=kind_im) :: iceflglw = 3 ! 0,1,2,3: ice influence calculations
integer(kind=kind_im) :: liqflglw = 1 ! 0:optical depths computed; 1:drop eff. rad. is input, opt. depth computed
integer(kind=kind_im) :: inflgsw = 2 ! 0:inp. cld fr and opt. depth; 1:cf and LWP are input; 2:also ice fraction inp.
integer(kind=kind_im) :: iceflgsw = 3 ! 0,1,2,3: ice influence calculations
integer(kind=kind_im) :: liqflgsw = 1 ! 0:optical depths computed; 1:drop eff. rad. is input, opt. depth computed
logical :: ocean = .false. ! if true, run is over ocean.
logical :: usero3 = .false. ! if true, the o3 profile is taken from backrad.inp, otherwise from stnd prof RRTMG
real :: co2factor = 1. ! The co2 concentration that is read from the NetCDF input file by RRTMG is multiplied by this factor (CGILS)
Expand Down Expand Up @@ -118,11 +118,13 @@ module modraddata
swHR_slice, & ! Heating rate due to shortwave rad (2D slice)
swHRCS_slice ! Heating rate due to shortwave rad,clear sky value (2D slice)

real,allocatable,dimension(:) :: solarZenithAngleCos ! The zenith angle of a slice
real(kind=kind_rb),allocatable,dimension(:) :: solarZenithAngleCos ! The zenith angle of a slice
real(kind=kind_rb),allocatable,dimension(:) :: asdir,asdif,aldir,aldif ! Albedos ...

real(kind=kind_rb),allocatable,dimension(:,:) :: layerP, &
layerT, &
interfaceP,&
interfaceT,&
h2ovmr, &
o3vmr, &
co2vmr, &
Expand All @@ -132,10 +134,19 @@ module modraddata
cfc11vmr, &
cfc12vmr, &
cfc22vmr, &
ccl4vmr
ccl4vmr, &
emis
real(kind=kind_rb),allocatable,dimension(:,:) :: LWP_slice,IWP_slice ,cloudFrac,liquidRe,iceRe
real(kind=kind_rb),allocatable,dimension(:,:) :: interfaceP, &
interfaceT
real(kind=kind_rb),allocatable,dimension(:,:,:) :: taucldlw, &
tauaerlw, &
taucldsw, &
ssacldsw, &
asmcldsw, &
fsfcldsw, &
tauaersw, &
ssaaersw, &
asmaersw, &
ecaersw
real(SHR_KIND_R4) :: eccen, & ! Eccentricity
obliqr, & ! Earths obliquity in radians
lambm0, & ! Mean long of perihelion at the vernal equinox (radians)
Expand Down
54 changes: 48 additions & 6 deletions src/modradrrtmg.f90
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ subroutine radrrtmg
implicit none

integer :: npatch ! Sounding levels above domain
integer :: i,j,k,ierr(3)
integer :: i,j,k,ierr(4)
logical :: sunUp
real(SHR_KIND_R4),save :: eccen, & ! Earth's eccentricity factor (unitless) (typically 0 to 0.1)
obliq, & ! Earth's obliquity angle (deg) (-90 to +90) (typically 22-26)
Expand Down Expand Up @@ -120,7 +120,19 @@ subroutine radrrtmg
allocate(solarZenithAngleCos(imax), asdir(imax), asdif(imax), aldir(imax), &
aldif(imax), &
STAT=ierr(3))

!Extra input for RRTMG, number of bands is hardcoded but will not change
allocate(emis(imax,16), &
taucldlw(16,imax,krad1), &
taucldsw(14,imax,krad1), &
ssacldsw(14,imax,krad1), &
asmcldsw(14,imax,krad1), &
fsfcldsw(14,imax,krad1), &
tauaerlw(imax,krad1,16), &
tauaersw(imax,krad1,14), &
ssaaersw(imax,krad1,14), &
asmaersw(imax,krad1,14), &
ecaersw(imax,krad1,14), &
STAT=ierr(4))
if(any(ierr(:)/=0)) then
if(myid==0) write(*,*) 'Could not allocate input/output arrays in modradrrtmg'
stop 'ERROR: Radiation variables could not be allocated in modradrrtmg.f90'
Expand Down Expand Up @@ -162,6 +174,18 @@ subroutine radrrtmg

! +=+=+=+=+=+=+=+= End of reading and initialization stage =+=+=++=+=+=+=+=+=+=+=++ !

! initialize some RRTMG input arrays
emis = 0.95
taucldlw = 0
tauaerlw = 0
taucldsw = 0
ssacldsw = 0
asmcldsw = 0
fsfcldsw = 0
tauaersw = 0
ssaaersw = 0
asmaersw = 0
ecaersw = 0
! zero the RRTMG output arrays here, in case rrtmg_lw or rrtmg_sw is not executed
swUp_slice = 0
swDown_slice = 0
Expand All @@ -181,15 +205,33 @@ subroutine radrrtmg
LWP_slice, IWP_slice, cloudFrac, liquidRe, iceRe ) !output

if (rad_longw) then
call rrtmg_lw &
( tg_slice, cloudFrac, IWP_slice, LWP_slice, iceRe, liquidRe )!input
call rrtmg_lw & !comments = corresponding variable names in the RRTMGP library
(int(imax,kind_im), int(nzrad+1,kind_im), ioverlap, int(0,kind_im), & !ncol, nlay, icld, idrv
layerP, interfaceP, layerT, interfaceT, tg_slice, & !play, plev, tlay, tlev, tsfc
h2ovmr, o3vmr, co2vmr, ch4vmr, n2ovmr, o2vmr, & !h2ovmr, o3vmr, co2vmr, ch4vmr, n2ovmr, o2vmr
cfc11vmr, cfc12vmr, cfc22vmr, ccl4vmr, emis, & !cfc11vmr, cfc12vmr, cfc22vmr, ccl4vmr, emis
inflglw, iceflglw, liqflglw, cloudFrac, & !inflglw, iceflglw, liqflglw, cldfr,
taucldlw, IWP_slice, LWP_slice, iceRe, liquidRe, & !taucld, cicewp, cliqwp, reice, reliq
tauaerlw, lwUp_slice, lwDown_slice, lwHR_slice, & !tauaer, uflx, dflx, hr
lwUpCS_slice, lwDownCS_slice, lwHRCS_slice) !uflxc, dflxc, hrc
!duflx_dt,duflxc_dt (extra optional arguments only if idrv=1)
!if(myid==0) write(*,*) 'after call to rrtmg_lw'
end if
if (rad_shortw) then
call setupSW(sunUp)
if (sunUp) then
call rrtmg_sw &
( tg_slice, cloudFrac, IWP_slice, LWP_slice, iceRe, liquidRe )
call rrtmg_sw & !comments = corresponding variable names in the RRTMGP library
(int(imax,kind_im), int(nzrad+1,kind_im), ioverlap, int(0,kind_im), & !ncol, nlay, icld, iaer
layerP, interfaceP, layerT, interfaceT, tg_slice, & !play, plev, tlay, tlev, tsfc
h2ovmr, o3vmr, co2vmr, ch4vmr, n2ovmr, o2vmr, & !h2ovmr, o3vmr, co2vmr, ch4vmr, n2ovmr, o2vmr
asdir, asdif, aldir, aldif, & !asdir, asdif, aldir, aldif
solarZenithAngleCos, real(eccf,kind_rb), int(0,kind_im), real(sw0,kind_rb), int(0,kind_im), & !coszen, adjes, dyofyr, scon, isolvar
inflgsw, iceflgsw, liqflgsw, cloudFrac, & !inflgsw, iceflgsw, liqflgsw, cldfr
taucldsw, ssacldsw, asmcldsw, fsfcldsw, & !taucld, ssacld, asmcld, fsfcld
IWP_slice, LWP_slice, iceRe, liquidRe, & !cicewp, cliqwp, reice, reliq
tauaersw, ssaaersw, asmaersw, ecaersw, & !tauaer, ssaaer, asmaer, ecaer
swUp_slice, swDown_slice, swHR_slice, swUpCS_slice, swDownCS_slice, swHRCS_slice) !swuflx, swdflx, swhr, swuflxc, swdflxc, swhrc
!bndsolvar, indsolvar, solcycfrac (extra optional inputs)
end if
end if

Expand Down

0 comments on commit 9ca4890

Please sign in to comment.