Skip to content
73 changes: 64 additions & 9 deletions datm/datm_datamode_era5_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,18 @@ module datm_datamode_era5_mod
real(r8), pointer :: Sa_z(:) => null()
real(r8), pointer :: Sa_u10m(:) => null()
real(r8), pointer :: Sa_v10m(:) => null()
real(r8), pointer :: Sa_u(:) => null()
real(r8), pointer :: Sa_v(:) => null()
real(r8), pointer :: Sa_tbot(:) => null()
real(r8), pointer :: Sa_ptem(:) => null()
real(r8), pointer :: Sa_dens(:) => null()
real(r8), pointer :: Sa_wspd10m(:) => null()
real(r8), pointer :: Sa_t2m(:) => null()
real(r8), pointer :: Sa_tskn(:) => null()
real(r8), pointer :: Sa_q2m(:) => null()
real(r8), pointer :: Sa_shum(:) => null()
real(r8), pointer :: Sa_pslv(:) => null()
real(r8), pointer :: Sa_pbot(:) => null()
real(r8), pointer :: Faxa_rain(:) => null()
real(r8), pointer :: Faxa_rainc(:) => null()
real(r8), pointer :: Faxa_rainl(:) => null()
Expand Down Expand Up @@ -100,13 +107,20 @@ subroutine datm_datamode_era5_advertise(exportState, fldsexport, flds_scalar_nam

call dshr_fldList_add(fldsExport, trim(flds_scalar_name))
call dshr_fldList_add(fldsExport, 'Sa_z' )
call dshr_fldList_add(fldsExport, 'Sa_u' )
call dshr_fldList_add(fldsExport, 'Sa_v' )
call dshr_fldList_add(fldsExport, 'Sa_u10m' )
call dshr_fldList_add(fldsExport, 'Sa_v10m' )
call dshr_fldList_add(fldsExport, 'Sa_wspd10m' )
call dshr_fldList_add(fldsExport, 'Sa_t2m' )
call dshr_fldList_add(fldsExport, 'Sa_tbot' )
call dshr_fldList_add(fldsExport, 'Sa_ptem' )
call dshr_fldList_add(fldsExport, 'Sa_dens' )
call dshr_fldList_add(fldsExport, 'Sa_tskn' )
call dshr_fldList_add(fldsExport, 'Sa_q2m' )
call dshr_fldList_add(fldsExport, 'Sa_shum' )
call dshr_fldList_add(fldsExport, 'Sa_pslv' )
call dshr_fldList_add(fldsExport, 'Sa_pbot' )
call dshr_fldList_add(fldsExport, 'Faxa_rain' )
call dshr_fldList_add(fldsExport, 'Faxa_rainc' )
call dshr_fldList_add(fldsExport, 'Faxa_rainl' )
Expand Down Expand Up @@ -184,6 +198,16 @@ subroutine datm_datamode_era5_init_pointers(exportState, sdat, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call shr_strdata_get_stream_pointer(sdat, 'Faxa_tauy', strm_Faxa_tauy, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call shr_strdata_get_stream_pointer(sdat, 'Faxa_rain' , strm_Faxa_rain , rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call shr_strdata_get_stream_pointer(sdat, 'Faxa_rainc', strm_Faxa_rainc, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call shr_strdata_get_stream_pointer(sdat, 'Faxa_rainl', strm_Faxa_rainl, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call shr_strdata_get_stream_pointer(sdat, 'Faxa_snowc', strm_Faxa_snowc, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call shr_strdata_get_stream_pointer(sdat, 'Faxa_snowl', strm_Faxa_snowl, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

! get export state pointers
call dshr_state_getfldptr(exportState, 'Sa_z' , fldptr1=Sa_z , allowNullReturn=.true., rc=rc)
Expand All @@ -192,16 +216,30 @@ subroutine datm_datamode_era5_init_pointers(exportState, sdat, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call dshr_state_getfldptr(exportState, 'Sa_v10m' , fldptr1=Sa_v10m , allowNullReturn=.true., rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call dshr_state_getfldptr(exportState, 'Sa_u' , fldptr1=Sa_u , allowNullReturn=.true., rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call dshr_state_getfldptr(exportState, 'Sa_v' , fldptr1=Sa_v , allowNullReturn=.true., rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call dshr_state_getfldptr(exportState, 'Sa_wspd10m' , fldptr1=Sa_wspd10m , allowNullReturn=.true., rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call dshr_state_getfldptr(exportState, 'Sa_t2m' , fldptr1=Sa_t2m , allowNullReturn=.true., rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call dshr_state_getfldptr(exportState, 'Sa_tbot' , fldptr1=Sa_tbot , allowNullReturn=.true., rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call dshr_state_getfldptr(exportState, 'Sa_ptem' , fldptr1=Sa_ptem , allowNullReturn=.true., rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call dshr_state_getfldptr(exportState, 'Sa_dens' , fldptr1=Sa_dens , allowNullReturn=.true., rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call dshr_state_getfldptr(exportState, 'Sa_tskn' , fldptr1=Sa_tskn , allowNullReturn=.true., rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call dshr_state_getfldptr(exportState, 'Sa_q2m' , fldptr1=Sa_q2m , allowNullReturn=.true., rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call dshr_state_getfldptr(exportState, 'Sa_shum' , fldptr1=Sa_shum , allowNullReturn=.true., rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call dshr_state_getfldptr(exportState, 'Sa_pslv' , fldptr1=Sa_pslv , allowNullReturn=.true., rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call dshr_state_getfldptr(exportState, 'Sa_pbot' , fldptr1=Sa_pbot , allowNullReturn=.true., rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call dshr_state_getfldptr(exportState, 'Faxa_rain' , fldptr1=Faxa_rain , allowNullReturn=.true., rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call dshr_state_getfldptr(exportState, 'Faxa_rainc' , fldptr1=Faxa_rainc , allowNullReturn=.true., rc=rc)
Expand Down Expand Up @@ -255,7 +293,7 @@ subroutine datm_datamode_era5_init_pointers(exportState, sdat, rc)
call shr_log_error(subname//'ERROR: strm_Sa_t2m must be associated for era5 datamode', rc=rc)
return
end if
if (associated(Sa_t2m) .and. associated(Sa_pslv) .and. associated(Sa_q2m) .and. .not. associated(strm_Sa_pslv)) then
if (associated(Sa_t2m) .and. associated(Sa_pslv) .and. (associated(Sa_q2m) .or. associated(Sa_shum)) .and. .not. associated(strm_Sa_pslv)) then
call shr_log_error(subname//'ERROR: strm_Sa_pslv must be associated for era5 datamode', rc=rc)
return
end if
Expand Down Expand Up @@ -350,11 +388,11 @@ subroutine datm_datamode_era5_advance(exportstate, mainproc, logunit, rc)
integer , intent(out) :: rc

! local variables
logical :: first_time = .true.
logical, save :: first_time = .true.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the save isn't required here, when a value is supplied in definitions then save is the default behaviour

integer :: n ! indices
integer :: lsize ! size of attr vect
real(r8) :: rtmp(2)
real(r8) :: t2, pslv
real(r8) :: t2, pslv, tdew
real(r8) :: e, qsat
type(ESMF_VM) :: vm
character(len=*), parameter :: subname='(datm_datamode_era5_advance): '
Expand All @@ -363,11 +401,20 @@ subroutine datm_datamode_era5_advance(exportstate, mainproc, logunit, rc)
rc = ESMF_SUCCESS

lsize = size(strm_Sa_tdew)
if (associated(Sa_u10m)) Sa_u10m(:) = strm_Sa_u10m(:)
if (associated(Sa_v10m)) Sa_v10m(:) = strm_Sa_v10m(:)
if (associated(Sa_u)) Sa_u(:) = strm_Sa_u10m(:)
if (associated(Sa_v)) Sa_v(:) = strm_Sa_v10m(:)
if (associated(Sa_t2m)) Sa_t2m(:) = strm_Sa_t2m(:)
if (associated(Sa_tbot)) Sa_tbot(:) = strm_Sa_t2m(:)
if (associated(Sa_pslv)) Sa_pslv(:) = strm_Sa_pslv(:)
if (associated(Sa_pbot)) Sa_pbot(:) = strm_Sa_pslv(:)
if (associated(Sa_ptem)) Sa_ptem(:) = strm_Sa_t2m(:)

if (first_time) then
call ESMF_VMGetCurrent(vm, rc=rc)
! determine t2max (see below for use)
if (associated(Sa_t2m)) then
Sa_t2m(:) = strm_Sa_t2m(:)
rtmp(1) = maxval(Sa_t2m(:))

call ESMF_VMAllReduce(vm, rtmp, rtmp(2:), 1, ESMF_REDUCE_MAX, rc=rc)
Expand Down Expand Up @@ -398,13 +445,21 @@ subroutine datm_datamode_era5_advance(exportstate, mainproc, logunit, rc)
end if

!--- specific humidity at 2m ---
if (associated(Sa_t2m) .and. associated(Sa_pslv) .and. associated(Sa_q2m)) then
t2 = Sa_t2m(n)
if (associated(Sa_pslv) .and. associated(strm_Sa_t2m) .and. (associated(Sa_q2m) .or. associated(Sa_shum))) then
t2 = strm_Sa_t2m(n)
pslv = strm_Sa_pslv(n)
if (td2max < 50.0_r8) strm_Sa_tdew(n) = strm_Sa_tdew(n) + tkFrz
e = datm_eSat(strm_Sa_tdew(n), t2)
tdew = strm_Sa_tdew(n)
if (td2max < 50.0_r8) tdew = tdew + tkFrz
e = datm_eSat(tdew, t2)
qsat = (0.622_r8 * e)/(pslv - 0.378_r8 * e)
Sa_q2m(n) = qsat
if (associated(Sa_q2m)) Sa_q2m(n) = qsat
if (associated(Sa_shum)) Sa_shum(n) = qsat
end if
! --- Air density at 2m ---
if (associated(Sa_dens) .and. associated(Sa_pbot) .and. associated(Sa_tbot) .and. associated(Sa_shum)) then
Sa_dens(n) = Sa_pbot(n)/(rdair*Sa_tbot(n)*(1.0_r8 + 0.608_r8*Sa_shum(n)))
else if (associated(Sa_dens) .and. associated(Sa_pbot) .and. associated(Sa_tbot) .and. associated(Sa_q2m)) then
Sa_dens(n) = Sa_pbot(n)/(rdair*Sa_tbot(n)*(1.0_r8 + 0.608_r8*Sa_q2m(n)))
end if
end do

Expand Down