Skip to content

Commit

Permalink
Modified modlsmcrosssection for new LSM
Browse files Browse the repository at this point in the history
  • Loading branch information
bartvstratum committed Jul 21, 2020
1 parent 45c6b5e commit 6637916
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 66 deletions.
28 changes: 26 additions & 2 deletions src/modlsm.f90
Original file line number Diff line number Diff line change
Expand Up @@ -522,11 +522,12 @@ subroutine calc_bulk_bcs
use modsurface, only : phim, phih
use modmpi, only : excjs
use modsurfdata, only : &
H, LE, G0, tskin, qskin, thlflux, qtflux, dthldz, dqtdz, dudz, dvdz, ustar, obl
H, LE, G0, tskin, qskin, thlflux, qtflux, dthldz, dqtdz, &
dudz, dvdz, ustar, obl, cliq, ra, rsveg, rssoil
implicit none

integer :: i, j
real :: rhocp_i, rholv_i, ra, ucu, vcv
real :: rhocp_i, rholv_i, ucu, vcv, cveg

rhocp_i = 1. / (rhof(1) * cp)
rholv_i = 1. / (rhof(1) * rlv)
Expand Down Expand Up @@ -602,6 +603,29 @@ subroutine calc_bulk_bcs
! Cyclic BCs where needed.
call excjs(ustar,2,i1,2,j1,1,1,1,1)

! Just for diagnostics (modlsmcrosssection)
cliq(i,j) = tile_ws%frac(i,j)

ra(i,j) = tile_lv%frac(i,j) * tile_lv%ra(i,j) + &
tile_hv%frac(i,j) * tile_hv%ra(i,j) + &
tile_bs%frac(i,j) * tile_bs%ra(i,j) + &
tile_ws%frac(i,j) * tile_ws%ra(i,j) + &
tile_aq%frac(i,j) * tile_aq%ra(i,j)

cveg = tile_lv%frac(i,j) + tile_hv%frac(i,j)
if (cveg > 0) then
rsveg(i,j) = (tile_lv%frac(i,j) * tile_lv%rs(i,j) + &
tile_hv%frac(i,j) * tile_hv%rs(i,j)) / cveg
else
rsveg(i,j) = 0.
end if

if (tile_bs%frac(i,j) > 0) then
rssoil(i,j) = tile_bs%rs(i,j)
else
rssoil(i,j) = 0.
end if

end do
end do

Expand Down
166 changes: 102 additions & 64 deletions src/modlsmcrosssection.f90
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,25 @@ module modlsmcrosssection
PUBLIC :: initlsmcrosssection, lsmcrosssection,exitlsmcrosssection
save
!NetCDF variables
integer,parameter :: nvar = 2,nvar3=12
integer,parameter :: nvar=2
integer :: nvar3
integer :: ncid1 = 0
integer :: ncid2 = 0
integer :: ncid3 = 0
integer :: nrec1 = 0
integer :: nrec2 = 0
integer :: nrec3 = 0
integer :: crossheight
! integer :: nxy = 0
! integer :: cross
! integer :: nrc
character(4) :: cheight
character(80) :: fname1 = 'lsmcrossxz.xxxxyxxx.xxx.nc'
character(80) :: fname2 = 'lsmcrossxy.xxxx.xxxxyxxx.xxx.nc'
character(80) :: fname3 = 'surfcross.xxxxyxxx.xxx.nc'
character(80),dimension(nvar,4) :: ncname1
character(80),dimension(1,4) :: tncname1
character(80),dimension(nvar,4) :: ncname2
character(80),dimension(1,4) :: tncname2
character(80),dimension(nvar3,4) :: ncname3
character(80),dimension(1,4) :: tncname3

character(80), dimension(nvar,4) :: ncname1
character(80), dimension(1,4) :: tncname1
character(80), dimension(nvar,4) :: ncname2
character(80), dimension(1,4) :: tncname2
character(80), allocatable, dimension(:,:) :: ncname3
character(80), dimension(1,4) :: tncname3

real :: dtav
integer(kind=longint) :: idtav,tnext
Expand All @@ -69,10 +66,11 @@ module modlsmcrosssection
!> Initializing lsmcrosssection. Read out the namelist, initializing the variables
subroutine initlsmcrosssection
use mpi
use modmpi, only :myid,my_real,mpierr,comm3d,mpi_logical,mpi_integer,cmyid
use modglobal,only :imax,jmax,ifnamopt,fname_options,dtmax,dtav_glob,ladaptive,j1,dt_lim,cexpnr,tres,btime,checknamelisterror
use modstat_nc,only : lnetcdf,open_nc, define_nc,ncinfo,nctiminfo,writestat_dims_nc
implicit none
use modmpi, only : myid,my_real,mpierr,comm3d,mpi_logical,mpi_integer,cmyid
use modglobal, only : imax,jmax,ifnamopt,fname_options,dtmax,dtav_glob,ladaptive,j1,dt_lim,cexpnr,tres,btime,checknamelisterror
use modstat_nc, only : lnetcdf,open_nc, define_nc,ncinfo,nctiminfo,writestat_dims_nc
use modsurfdata, only : isurf
implicit none

integer :: ierr

Expand All @@ -97,7 +95,6 @@ subroutine initlsmcrosssection
call MPI_BCAST(crossheight,1,MPI_INTEGER,0,comm3d,mpierr)
call MPI_BCAST(crossplane ,1,MPI_INTEGER,0,comm3d,mpierr)


idtav = dtav/tres
tnext = idtav+btime
if(.not.(lcross)) return
Expand Down Expand Up @@ -137,28 +134,58 @@ subroutine initlsmcrosssection
call define_nc( ncid2, NVar, ncname2)
end if
!
! !Surface values
! ! Surface values
fname3(11:18) = cmyid
fname3(20:22) = cexpnr
call nctiminfo(tncname3(1,:))
call ncinfo(ncname3( 1,:),'Qnet','Net radiation','W/m^2','tt0t')
call ncinfo(ncname3( 2,:),'H','Sensible heat flux','W/m^2','tt0t')
call ncinfo(ncname3( 3,:),'LE','Latent heat flux','W/m^2','tt0t')
call ncinfo(ncname3( 4,:),'G0','Ground heat flux','W/m^2','tt0t')
call ncinfo(ncname3( 5,:),'tskin','Skin temperature','K','tt0t')
call ncinfo(ncname3( 6,:),'tendskin','Skin tendency','W/m^2','tt0t')
call ncinfo(ncname3( 7,:),'rs','Surface resistance','s/m','tt0t')
call ncinfo(ncname3( 8,:),'ra','Aerodynamic resistance','s/m','tt0t')
call ncinfo(ncname3( 9,:),'cliq','Fraction of vegetated surface covered with liquid water','-','tt0t')
call ncinfo(ncname3(10,:),'Wl','Liquid water reservoir','m','tt0t')
call ncinfo(ncname3(11,:),'rssoil','Soil evaporation resistance','s/m','tt0t')
call ncinfo(ncname3(12,:),'rsveg','Vegitation resistance','s/m','tt0t')
call open_nc(fname3, ncid3,nrec3,n1=imax,n2=jmax)
if (nrec3==0) then
call define_nc( ncid3, 1, tncname3)
call writestat_dims_nc(ncid3)

if (isurf == 1) then
nvar3 = 12
else if (isurf == 11) then
nvar3 = 11
end if

allocate(ncname3(nvar3,4))

if (isurf == 1) then
call nctiminfo(tncname3(1,:))
call ncinfo(ncname3( 1,:),'Qnet','Net radiation','W/m^2','tt0t')
call ncinfo(ncname3( 2,:),'H','Sensible heat flux','W/m^2','tt0t')
call ncinfo(ncname3( 3,:),'LE','Latent heat flux','W/m^2','tt0t')
call ncinfo(ncname3( 4,:),'G0','Ground heat flux','W/m^2','tt0t')
call ncinfo(ncname3( 5,:),'tskin','Skin temperature','K','tt0t')
call ncinfo(ncname3( 6,:),'tendskin','Skin tendency','W/m^2','tt0t')
call ncinfo(ncname3( 7,:),'rs','Surface resistance','s/m','tt0t')
call ncinfo(ncname3( 8,:),'ra','Aerodynamic resistance','s/m','tt0t')
call ncinfo(ncname3( 9,:),'cliq','Fraction of vegetated surface covered with liquid water','-','tt0t')
call ncinfo(ncname3(10,:),'Wl','Liquid water reservoir','m','tt0t')
call ncinfo(ncname3(11,:),'rssoil','Soil evaporation resistance','s/m','tt0t')
call ncinfo(ncname3(12,:),'rsveg','Vegitation resistance','s/m','tt0t')
call open_nc(fname3, ncid3, nrec3, n1=imax, n2=jmax)
if (nrec3==0) then
call define_nc(ncid3, 1, tncname3)
call writestat_dims_nc(ncid3)
end if
call define_nc(ncid3, nvar3, ncname3)
else if (isurf == 11) then
call nctiminfo(tncname3(1,:))
call ncinfo(ncname3( 1,:),'H', 'Sensible heat flux', 'W/m^2', 'tt0t')
call ncinfo(ncname3( 2,:),'LE', 'Latent heat flux', 'W/m^2', 'tt0t')
call ncinfo(ncname3( 3,:),'G0', 'Ground heat flux', 'W/m^2', 'tt0t')
call ncinfo(ncname3( 4,:),'tskin', 'Skin temperature', 'K', 'tt0t')
call ncinfo(ncname3( 5,:),'obuk', 'Obukhov length', 'm', 'tt0t')
call ncinfo(ncname3( 6,:),'ustar', 'Friction velocity', 'm/s^-1', 'tt0t')
call ncinfo(ncname3( 7,:),'cliq', 'Fraction of vegetated surface covered with liquid water', '-', 'tt0t')
call ncinfo(ncname3( 8,:),'ra', 'Aerodynamic resistance', 's/m', 'tt0t')
call ncinfo(ncname3( 9,:),'rssoil', 'Soil evaporation resistance', 's/m', 'tt0t')
call ncinfo(ncname3(10,:),'rsveg', 'Vegitation resistance', 's/m', 'tt0t')
call ncinfo(ncname3(11,:),'wl', 'Liquid water reservoir', 'm', 'tt0t')
call open_nc(fname3, ncid3, nrec3, n1=imax, n2=jmax)
if (nrec3==0) then
call define_nc(ncid3, 1, tncname3)
call writestat_dims_nc(ncid3)
end if
call define_nc( ncid3, nvar3, ncname3)
end if
call define_nc( ncid3, NVar3, ncname3)
end if


Expand Down Expand Up @@ -224,14 +251,10 @@ subroutine wrthorz
use modstat_nc, only : lnetcdf, writestat_nc
implicit none


! LOCAL
integer i,j
real, allocatable :: vars(:,:,:)




write(cheight,'(i4.4)') crossheight
open(ifoutput,file='movh_tsoil.'//cexpnr,position='append',action='write')
write(ifoutput,'(es12.5)') ((tsoil(i,j,crossheight),i=2,i1),j=2,j1)
Expand All @@ -251,24 +274,20 @@ subroutine wrthorz
deallocate(vars)
end if


end subroutine wrthorz

!> Do the xy lsmcrosssections and dump them to file
subroutine wrtsurf
use modglobal, only : imax,jmax,i1,j1,cexpnr,ifoutput,rtimee
use modsurfdata, only : Qnet, H, LE, G0, rs, ra, tskin, tendskin, &
cliq,rsveg,rssoil,Wl
cliq,rsveg,rssoil,Wl, isurf, obl, ustar
use modstat_nc, only : lnetcdf, writestat_nc
implicit none


! LOCAL
integer i,j
real, allocatable :: vars(:,:,:)




open(ifoutput,file='movh_qnet.'//cexpnr,position='append',action='write')
write(ifoutput,'(es12.5)') ((qnet(i,j),i=2,i1),j=2,j1)
close(ifoutput)
Expand Down Expand Up @@ -317,23 +336,40 @@ subroutine wrtsurf
write(ifoutput,'(es12.5)') ((wl(i,j),i=2,i1),j=2,j1)
close(ifoutput)


if (lnetcdf) then
allocate(vars(1:imax,1:jmax,nvar3))
vars(:,:,1) = qnet(2:i1,2:j1)
vars(:,:,2) = h(2:i1,2:j1)
vars(:,:,3) = le(2:i1,2:j1)
vars(:,:,4) = g0(2:i1,2:j1)
vars(:,:,5) = tskin(2:i1,2:j1)
vars(:,:,6) = tendskin(2:i1,2:j1)
vars(:,:,7) = rs(2:i1,2:j1)
vars(:,:,8) = ra(2:i1,2:j1)
vars(:,:,9) = cliq(2:i1,2:j1)
vars(:,:,10) = Wl(2:i1,2:j1)
vars(:,:,11) = rssoil(2:i1,2:j1)
vars(:,:,12) = rsveg(2:i1,2:j1)
call writestat_nc(ncid3,1,tncname3,(/rtimee/),nrec3,.true.)
call writestat_nc(ncid3,nvar3,ncname3(1:nvar3,:),vars,nrec3,imax,jmax)

if (isurf == 1) then
vars(:,:,1) = qnet(2:i1,2:j1)
vars(:,:,2) = h(2:i1,2:j1)
vars(:,:,3) = le(2:i1,2:j1)
vars(:,:,4) = g0(2:i1,2:j1)
vars(:,:,5) = tskin(2:i1,2:j1)
vars(:,:,6) = tendskin(2:i1,2:j1)
vars(:,:,7) = rs(2:i1,2:j1)
vars(:,:,8) = ra(2:i1,2:j1)
vars(:,:,9) = cliq(2:i1,2:j1)
vars(:,:,10) = Wl(2:i1,2:j1)
vars(:,:,11) = rssoil(2:i1,2:j1)
vars(:,:,12) = rsveg(2:i1,2:j1)
call writestat_nc(ncid3, 1, tncname3, (/rtimee/), nrec3, .true.)
call writestat_nc(ncid3, nvar3, ncname3(1:nvar3,:), vars, nrec3, imax, jmax)
else if (isurf == 11) then
vars(:,:, 1) = H(2:i1,2:j1)
vars(:,:, 2) = LE(2:i1,2:j1)
vars(:,:, 3) = G0(2:i1,2:j1)
vars(:,:, 4) = tskin(2:i1,2:j1)
vars(:,:, 5) = obl(2:i1,2:j1)
vars(:,:, 6) = ustar(2:i1,2:j1)
vars(:,:, 7) = cliq(2:i1,2:j1)
vars(:,:, 8) = ra(2:i1,2:j1)
vars(:,:, 9) = rssoil(2:i1,2:j1)
vars(:,:,10) = rsveg(2:i1,2:j1)
vars(:,:,11) = Wl(2:i1,2:j1)
call writestat_nc(ncid3, 1, tncname3, (/rtimee/), nrec3, .true.)
call writestat_nc(ncid3, nvar3, ncname3(1:nvar3,:), vars, nrec3, imax, jmax)
end if

deallocate(vars)
end if

Expand All @@ -346,10 +382,12 @@ subroutine exitlsmcrosssection
implicit none

if(lcross .and. lnetcdf) then
if (myid==0) then
call exitstat_nc(ncid1)
end if
call exitstat_nc(ncid2)
if (myid==0) then
call exitstat_nc(ncid1)
end if
call exitstat_nc(ncid2)
call exitstat_nc(ncid3)
deallocate(ncname3)
end if

end subroutine exitlsmcrosssection
Expand Down

0 comments on commit 6637916

Please sign in to comment.