Skip to content

Commit

Permalink
added condensation to output - needed for water balance modelling - a…
Browse files Browse the repository at this point in the history
…nd changed quantitative check target - necessary after no longer using prescribed net radiation which caused a bug
  • Loading branch information
stineb committed Feb 27, 2024
1 parent c8b1c11 commit 199e55e
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 6 deletions.
7 changes: 5 additions & 2 deletions R/run_pmodel_f_bysite.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
#' \item{\code{netrad}}{Net radiation, in W m\eqn{^{-2}}. WARNING: this is currently ignored as a model forcing. Instead, net radiation is internally calculated by SPLASH.}
#' \item{\code{wcont}}{Soil water content, in mm.}
#' \item{\code{snow}}{Snow water equivalents, in mm.}
#' \item{\code{cond}}{Water input by condensation, in mm d\eqn{^{-1}}}
#' }
#'
#' @details Depending on the input model parameters, it's possible to run the
Expand Down Expand Up @@ -386,7 +387,8 @@ run_pmodel_f_bysite <- function(
"tsoil",
"netrad",
"wcont",
"snow")
"snow",
"cond")
) %>%
as_tibble(.name_repair = "check_unique") %>%
dplyr::bind_cols(ddf,.)
Expand All @@ -410,7 +412,8 @@ run_pmodel_f_bysite <- function(
tsoil = NA,
netrad = NA,
wcont = NA,
snow = NA)
snow = NA,
cond = NA)
}

return(out)
Expand Down
1 change: 1 addition & 0 deletions man/run_pmodel_f_bysite.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/biosphere_pmodel.mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ function biosphere_annual() result( out_biosphere )
/ myinterface%params_siml%secs_per_tstep ! output in W m-2
out_biosphere%wcont(doy) = tile(1)%soil%phy%wcont
out_biosphere%snow(doy) = tile(1)%soil%phy%snow
out_biosphere%cond(doy) = tile_fluxes(1)%canopy%dcn

init_daily = .false.

Expand Down
2 changes: 1 addition & 1 deletion src/interface_biosphere_pmodel.mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module md_interface_pmodel
real, dimension(ndayyear) :: netrad
real, dimension(ndayyear) :: wcont
real, dimension(ndayyear) :: snow

real, dimension(ndayyear) :: cond
end type outtype_biosphere

end module md_interface_pmodel
3 changes: 2 additions & 1 deletion src/sofun_r.f90
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ subroutine pmodel_f( &
integer(kind=c_int), intent(in) :: nt ! number of time steps
real(kind=c_double), dimension(9), intent(in) :: par ! free (calibratable) model parameters
real(kind=c_double), dimension(nt,12), intent(in) :: forcing ! array containing all temporally varying forcing data (rows: time steps; columns: 1=air temperature, 2=rainfall, 3=vpd, 4=ppfd, 5=net radiation, 6=sunshine fraction, 7=snowfall, 8=co2, 9=fapar, 10=patm, 11=tmin, 12=tmax)
real(kind=c_double), dimension(nt,18), intent(out) :: output
real(kind=c_double), dimension(nt,19), intent(out) :: output

! local variables
type(outtype_biosphere) :: out_biosphere ! holds all the output used for calculating the cost or maximum likelihood function
Expand Down Expand Up @@ -218,6 +218,7 @@ subroutine pmodel_f( &
output(idx_start:idx_end,16) = dble(out_biosphere%netrad(:))
output(idx_start:idx_end,17) = dble(out_biosphere%wcont(:))
output(idx_start:idx_end,18) = dble(out_biosphere%snow(:))
output(idx_start:idx_end,19) = dble(out_biosphere%cond(:))

end if

Expand Down
2 changes: 1 addition & 1 deletion src/wrappersc.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ extern SEXP pmodel_f_C(

// Specify output
// 2nd agument to allocMatrix is number of rows, 3rd is number of columns
SEXP output = PROTECT( allocMatrix(REALSXP, nt, 18) );
SEXP output = PROTECT( allocMatrix(REALSXP, nt, 19) );

// Fortran subroutine call
F77_CALL(pmodel_f)(
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-quantitative-validation.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test_that("p-model quantitative check", {
mean(abs(gpp), na.rm = TRUE)

# test for correctly returned values
expect_equal(tolerance, 0.3050983, tolerance = 0.03)
expect_equal(tolerance, 0.4201191, tolerance = 0.04)
})

# test_that("p-model consistency R vs Fortran (rpmodel vs rsofun)", {
Expand Down

0 comments on commit 199e55e

Please sign in to comment.