From 9f71626e87306dadc39558c7a2323402737a642a Mon Sep 17 00:00:00 2001 From: Beni Stocker Date: Wed, 1 May 2024 09:54:56 +0200 Subject: [PATCH 1/4] tested Ensheng's suggestion - all failed --- analysis/demo_bug.R | 122 +++++++++++++++++++++++++++++ src/vegetation_biomee.mod.f90 | 141 ++++++++++++++++++++-------------- 2 files changed, 206 insertions(+), 57 deletions(-) create mode 100644 analysis/demo_bug.R diff --git a/analysis/demo_bug.R b/analysis/demo_bug.R new file mode 100644 index 00000000..a105bcdf --- /dev/null +++ b/analysis/demo_bug.R @@ -0,0 +1,122 @@ +library(rsofun) +library(dplyr) +library(ggplot2) +library(purrr) + +nruns <- 3 + +test_biomee <- function(){ + # run the model + biomee_gs_leuning_output <- runread_biomee_f( + biomee_gs_leuning_drivers, + makecheck = TRUE, + parallel = FALSE + ) + + # split out the annual data + any(!is.na(biomee_gs_leuning_output$data[[1]]$output_annual_tile$GPP) & biomee_gs_leuning_output$data[[1]]$output_annual_tile$GPP > 0.0) +} + +# TRUE if simulation passed +vec_test <- purrr::map_lgl( + 1:nruns, + ~test_biomee() +) + +# did any simulation fail? +if (any(!vec_test)){ + stop( + "At least one BiomeE simulation failed." + ) +} else { + message( + "All BiomeE simulations passed." + ) +} + +# OLD BUG RELATED TO NET RADIATION AND EVAPOTRANSPIRATION - SOLVED BY NOT USING PRESCRIBED NET RADIATION IN COMBINATION WITH SPLASH +# library(rsofun) +# library(dplyr) +# library(ggplot2) +# +# params_modl <- list( +# kphio = 0.04998, # setup ORG in Stocker et al. 2020 GMD +# kphio_par_a = 0.0, # set to zero to disable temperature-dependence of kphio +# kphio_par_b = 1.0, +# soilm_thetastar = 0.6 * 240, # to recover old setup with soil moisture stress +# soilm_betao = 0.0, +# beta_unitcostratio = 146.0, +# rd_to_vcmax = 0.014, # value from Atkin et al. 2015 for C3 herbaceous +# tau_acclim = 30.0, +# kc_jmax = 0.41 +# ) +# +# # run the model for these parameters +# output <- rsofun::runread_pmodel_f( +# p_model_drivers, +# par = params_modl +# ) +# +# # problem with AET +# ggplot(aes(x = date), +# data = output$data[[1]] |> +# slice(1:365)) + +# geom_line(aes(y = aet), color = "royalblue") + +# geom_line(aes(y = pet), color = "tomato") +# +# # net radiation in forcing +# p_model_drivers$forcing[[1]] |> +# slice(1:365) |> +# ggplot(aes(date, netrad)) + +# geom_line() + +# labs(title = "in forcing") +# +# # net radiation in output +# output$data[[1]] |> +# slice(1:365) |> +# ggplot(aes(date, netrad)) + +# geom_line() + +# labs(title = "in output") +# +# # they are identical - so far so good +# +# # pet scales nicely with netrad +# output$data[[1]] |> +# slice(1:365) |> +# ggplot(aes(netrad, pet)) + +# geom_point() +# +# # where the heck is the weird AET coming from??? +# +# # try with internally simulated net radiation +# output <- rsofun::runread_pmodel_f( +# p_model_drivers |> +# mutate(forcing = purrr::map(forcing, ~mutate(., netrad = NA))), +# par = params_modl +# ) +# +# # problem with AET +# ggplot(aes(x = date), +# data = output$data[[1]] |> +# slice(1:365)) + +# geom_line(aes(y = aet), color = "royalblue") + +# geom_line(aes(y = pet), color = "tomato") +# +# # compare observed and splash netrad +# +# ggplot() + +# geom_line(aes(date, netrad), +# data = p_model_drivers$forcing[[1]] |> +# slice(1:365)) + +# geom_line(aes(date, netrad), +# data = output$data[[1]] |> +# slice(1:365), +# color = "red") +# +# # when using prescirbed, splash-internal netrad is -2.51781612E+10 +# # when internally calculating, splash-internal netrad is 4283690.50 +# # interstingly, PET is still ok and seems to use correct net radiation +# +# # tau, tile_fluxes(:)%canopy%rnl 0.755406737 98.3971481 +# # tau, tile_fluxes(:)%canopy%rnl 0.755406737 98.3971481 + diff --git a/src/vegetation_biomee.mod.f90 b/src/vegetation_biomee.mod.f90 index 9968b4ac..47ff1673 100755 --- a/src/vegetation_biomee.mod.f90 +++ b/src/vegetation_biomee.mod.f90 @@ -1346,9 +1346,34 @@ subroutine relayer_cohorts( vegn ) enddo + !--------------------------------- + ! THIS CREATES WEIRD BUG: SOMETIMES ZERO SOLUTION ! replace the array of cohorts deallocate(vegn%cohorts) vegn%cohorts => new + !--------------------------------- + + ! !--------------------------------- + ! ! Ensheng's suggested modification (email 29 Apr 2024) + ! ! THIS CREATES WEIRD BUG: SOMETIMES ZERO SOLUTION + ! ! replace the array of cohorts + ! deallocate(vegn%cohorts) + ! vegn%cohorts => new + ! ! Let new points to null() + ! new => null() + ! !--------------------------------- + + ! !--------------------------------- + ! ! Ensheng's ALTERNATIVE suggested modification (email 29 Apr 2024) + ! ! THIS ALSO CREATES WEIRD BUG: SOMETIMES ZERO SOLUTION + ! ! replace the array of cohorts + ! vegn%cohorts => new + ! deallocate(cc) ! Release the memory of the old cohort array + ! ! Let new and cc point to null + ! new => null() + ! cc => null() + ! !--------------------------------- + vegn%n_cohorts = i ! update layer fraction for each cohort @@ -2260,62 +2285,64 @@ subroutine initialize_vegn_tile( vegn, nCohorts ) ! Read parameters from the parameter file (namelist) -! xxx seems new from d-ben - missing if? - ! Initialize plant cohorts - init_n_cohorts = myinterface%init_cohort(1)%init_n_cohorts !nCohorts !Weng,2018-11-21 - allocate(cc(1:init_n_cohorts), STAT = istat) - vegn%cohorts => cc - vegn%n_cohorts = init_n_cohorts - cc => null() + ! xxx seems new from d-ben - missing if? + ! Initialize plant cohorts + init_n_cohorts = myinterface%init_cohort(1)%init_n_cohorts !nCohorts !Weng,2018-11-21 + allocate(cc(1:init_n_cohorts), STAT = istat) + vegn%cohorts => cc + vegn%n_cohorts = init_n_cohorts + cc => null() - do i=1,init_n_cohorts - cx => vegn%cohorts(i) - cx%status = LEAF_OFF ! ON=1, OFF=0 ! ON - cx%layer = 1 - cx%age = 0 - cx%species = INT(myinterface%init_cohort(i)%init_cohort_species) - cx%ccID = i - cx%plabl%c%c12 = myinterface%init_cohort(i)%init_cohort_nsc - cx%nindivs = myinterface%init_cohort(i)%init_cohort_nindivs ! trees/m2 - cx%psapw%c%c12 = myinterface%init_cohort(i)%init_cohort_bsw - cx%pwood%c%c12 = myinterface%init_cohort(i)%init_cohort_bHW - btotal = cx%psapw%c%c12 + cx%pwood%c%c12 ! kgC /tree - call initialize_cohort_from_biomass(cx,btotal) - enddo - MaxCohortID = cx%ccID - - ! Sorting these cohorts - call relayer_cohorts( vegn ) - - ! Initial Soil pools and environmental conditions - vegn%psoil_fs%c%c12 = myinterface%init_soil%init_fast_soil_C ! kgC m-2 - vegn%psoil_sl%c%c12 = myinterface%init_soil%init_slow_soil_C ! slow soil carbon pool, (kg C/m2) - vegn%psoil_fs%n%n14 = vegn%psoil_fs%c%c12 / CN0metabolicL ! fast soil nitrogen pool, (kg N/m2) - vegn%psoil_sl%n%n14 = vegn%psoil_sl%c%c12 / CN0structuralL ! slow soil nitrogen pool, (kg N/m2) - vegn%N_input = myinterface%init_soil%N_input ! kgN m-2 yr-1, N input to soil - vegn%ninorg%n14 = myinterface%init_soil%init_Nmineral ! Mineral nitrogen pool, (kg N/m2) - vegn%previousN = vegn%ninorg%n14 - - ! Soil water parameters - vegn%soiltype = myinterface%params_tile%soiltype - vegn%FLDCAP = myinterface%params_tile%FLDCAP - vegn%WILTPT = myinterface%params_tile%WILTPT - - ! Initialize soil volumetric water conent with field capacity (maximum soil moisture to start with) - vegn%wcl = myinterface%params_tile%FLDCAP - ! Update soil water - vegn%SoilWater = 0.0 - do i=1, max_lev - vegn%SoilWater = vegn%SoilWater + vegn%wcl(i)*thksl(i)*1000.0 - enddo - vegn%thetaS = 1.0 - ! tile - call summarize_tile( vegn ) - vegn%initialN0 = vegn%plabl%n%n14 + vegn%pseed%n%n14 + vegn%pleaf%n%n14 + & - vegn%proot%n%n14 + vegn%psapw%n%n14 + vegn%pwood%n%n14 + & - vegn%pmicr%n%n14 + vegn%psoil_fs%n%n14 + & - vegn%psoil_sl%n%n14 + vegn%ninorg%n14 - vegn%totN = vegn%initialN0 + do i=1,init_n_cohorts + cx => vegn%cohorts(i) + cx%status = LEAF_OFF ! ON=1, OFF=0 ! ON + cx%layer = 1 + cx%age = 0 + cx%species = INT(myinterface%init_cohort(i)%init_cohort_species) + cx%ccID = i + cx%plabl%c%c12 = myinterface%init_cohort(i)%init_cohort_nsc + cx%nindivs = myinterface%init_cohort(i)%init_cohort_nindivs ! trees/m2 + cx%psapw%c%c12 = myinterface%init_cohort(i)%init_cohort_bsw + cx%pwood%c%c12 = myinterface%init_cohort(i)%init_cohort_bHW + btotal = cx%psapw%c%c12 + cx%pwood%c%c12 ! kgC /tree + call initialize_cohort_from_biomass(cx,btotal) + enddo + MaxCohortID = cx%ccID + + ! Sorting these cohorts + call relayer_cohorts( vegn ) + + ! Initial Soil pools and environmental conditions + vegn%psoil_fs%c%c12 = myinterface%init_soil%init_fast_soil_C ! kgC m-2 + vegn%psoil_sl%c%c12 = myinterface%init_soil%init_slow_soil_C ! slow soil carbon pool, (kg C/m2) + vegn%psoil_fs%n%n14 = vegn%psoil_fs%c%c12 / CN0metabolicL ! fast soil nitrogen pool, (kg N/m2) + vegn%psoil_sl%n%n14 = vegn%psoil_sl%c%c12 / CN0structuralL ! slow soil nitrogen pool, (kg N/m2) + vegn%N_input = myinterface%init_soil%N_input ! kgN m-2 yr-1, N input to soil + vegn%ninorg%n14 = myinterface%init_soil%init_Nmineral ! Mineral nitrogen pool, (kg N/m2) + vegn%previousN = vegn%ninorg%n14 + + ! Soil water parameters + vegn%soiltype = myinterface%params_tile%soiltype + vegn%FLDCAP = myinterface%params_tile%FLDCAP + vegn%WILTPT = myinterface%params_tile%WILTPT + + ! Initialize soil volumetric water conent with field capacity (maximum soil moisture to start with) + vegn%wcl = myinterface%params_tile%FLDCAP + + ! Update soil water + vegn%SoilWater = 0.0 + do i=1, max_lev + vegn%SoilWater = vegn%SoilWater + vegn%wcl(i)*thksl(i)*1000.0 + enddo + vegn%thetaS = 1.0 + + ! tile + call summarize_tile( vegn ) + vegn%initialN0 = vegn%plabl%n%n14 + vegn%pseed%n%n14 + vegn%pleaf%n%n14 + & + vegn%proot%n%n14 + vegn%psapw%n%n14 + vegn%pwood%n%n14 + & + vegn%pmicr%n%n14 + vegn%psoil_fs%n%n14 + & + vegn%psoil_sl%n%n14 + vegn%ninorg%n14 + vegn%totN = vegn%initialN0 ! For reset: Keep initial plant cohorts allocate(cc(1:init_n_cohorts), STAT = istat) @@ -2323,9 +2350,9 @@ subroutine initialize_vegn_tile( vegn, nCohorts ) vegn%initialCC => cc vegn%n_initialCC = init_n_cohorts cc => null() - + ! xxx up to here new from d-ben - + end subroutine initialize_vegn_tile end module md_vegetation_biomee From 43a19b495c528c82cd807ecd12fdee30c509c54d Mon Sep 17 00:00:00 2001 From: Beni Stocker Date: Fri, 17 May 2024 13:10:00 +0200 Subject: [PATCH 2/4] set n_deadtrees, c_deadtrees, and corrected output_annual_cohorts_dBA for BiomeE otuput. --- DESCRIPTION | 2 +- analysis/demo_bug.R | 44 ++++++++++-- src/biosphere_biomee.mod.f90 | 7 +- src/datatypes.mod.f90 | 8 +-- src/sofun_r.f90 | 9 +-- src/vegetation_biomee.mod.f90 | 130 +++++++++++++++------------------- src/waterbal_splash.mod.f90 | 2 +- 7 files changed, 108 insertions(+), 94 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index d3872774..2f9e0e15 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -61,7 +61,7 @@ LazyData: true LazyDataCompression: xz ByteCompile: true NeedsCompilation: yes -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 Suggests: covr, rcmdcheck, diff --git a/analysis/demo_bug.R b/analysis/demo_bug.R index a105bcdf..1ec08939 100644 --- a/analysis/demo_bug.R +++ b/analysis/demo_bug.R @@ -3,16 +3,16 @@ library(dplyr) library(ggplot2) library(purrr) +## BiomeE (original with gs-leuning) ----------- nruns <- 3 - -test_biomee <- function(){ +test_biomee_gs_leuning <- function(){ # run the model biomee_gs_leuning_output <- runread_biomee_f( biomee_gs_leuning_drivers, makecheck = TRUE, parallel = FALSE ) - + # split out the annual data any(!is.na(biomee_gs_leuning_output$data[[1]]$output_annual_tile$GPP) & biomee_gs_leuning_output$data[[1]]$output_annual_tile$GPP > 0.0) } @@ -20,20 +20,52 @@ test_biomee <- function(){ # TRUE if simulation passed vec_test <- purrr::map_lgl( 1:nruns, - ~test_biomee() + ~test_biomee_gs_leuning() +) + +# did any simulation fail? +if (any(!vec_test)){ + stop( + "At least one BiomeE-gs-leuning simulation failed." + ) +} else { + message( + "All BiomeE-gs-leuning simulations passed." + ) +} + +## BiomeEP ------------------- +nruns <- 10 +test_biomeep <- function(){ + # run the model + biomee_p_model_output <- runread_biomee_f( + biomee_p_model_drivers, + makecheck = TRUE, + parallel = FALSE + ) + + # split out the annual data + any(!is.na(biomee_p_model_output$data[[1]]$output_annual_tile$GPP) & biomee_p_model_output$data[[1]]$output_annual_tile$GPP > 0.0) +} + +# TRUE if simulation passed +vec_test <- purrr::map_lgl( + 1:nruns, + ~test_biomeep() ) # did any simulation fail? if (any(!vec_test)){ stop( - "At least one BiomeE simulation failed." + "At least one BiomeEP simulation failed." ) } else { message( - "All BiomeE simulations passed." + "All BiomeEP simulations passed." ) } + # OLD BUG RELATED TO NET RADIATION AND EVAPOTRANSPIRATION - SOLVED BY NOT USING PRESCRIBED NET RADIATION IN COMBINATION WITH SPLASH # library(rsofun) # library(dplyr) diff --git a/src/biosphere_biomee.mod.f90 b/src/biosphere_biomee.mod.f90 index 4ee64b84..51cbb38e 100644 --- a/src/biosphere_biomee.mod.f90 +++ b/src/biosphere_biomee.mod.f90 @@ -38,14 +38,11 @@ subroutine biosphere_annual(out_biosphere) !---------------------------------------------------------------- ! Biome-E stuff !---------------------------------------------------------------- - ! integer, parameter :: rand_seed = 86456 - ! integer, parameter :: totalyears = 10 - integer, parameter :: nCohorts = 1 real :: tsoil, soil_theta integer :: year0 integer :: i integer :: idata - !integer :: nfrequency + !integer :: nfrequency ! disturbances integer, save :: simu_steps !, datalines integer, save :: iyears integer, save :: idays @@ -61,7 +58,7 @@ subroutine biosphere_annual(out_biosphere) ! Initialize vegetation tile and plant cohorts allocate( vegn ) - call initialize_vegn_tile( vegn, nCohorts) + call initialize_vegn_tile( vegn ) ! Sort and relayer cohorts call relayer_cohorts( vegn ) diff --git a/src/datatypes.mod.f90 b/src/datatypes.mod.f90 index 86321281..5f47e8d6 100644 --- a/src/datatypes.mod.f90 +++ b/src/datatypes.mod.f90 @@ -763,8 +763,8 @@ subroutine Zero_diagnostics(vegn) vegn%annualN = 0.0 vegn%Nloss_yr = 0.0 vegn%annualNup = 0.0 - ! vegn%n_deadtrees = 0.0 !xxx - ! vegn%c_deadtrees = 0.0 + vegn%n_deadtrees = 0.0 + vegn%c_deadtrees = 0.0 do i = 1, vegn%n_cohorts cc => vegn%cohorts(i) @@ -801,8 +801,8 @@ subroutine Zero_diagnostics(vegn) cc%BA_ys = cc%BA cc%Vol_ys = cc%Volume cc%ABG_ys = cc%psapw%c%c12 + cc%pwood%c%c12 - ! cc%n_deadtrees = 0.0 - ! cc%c_deadtrees = 0.0 + cc%n_deadtrees = 0.0 + cc%c_deadtrees = 0.0 cc%m_turnover = 0.0 enddo diff --git a/src/sofun_r.f90 b/src/sofun_r.f90 index 0d0ce793..bfef6410 100644 --- a/src/sofun_r.f90 +++ b/src/sofun_r.f90 @@ -768,7 +768,6 @@ subroutine biomee_f( & !---------------------------------------------------------------- ! Output output_annual_cohorts (without subroutine) !---------------------------------------------------------------- - ! To get outputs only after spinupyears make if below and ! also in run_biomee_f_bysite.R make n_annual_cohorts = as.integer(params_siml$nyeartrend) @@ -776,10 +775,6 @@ subroutine biomee_f( & idx = yr - myinterface%params_siml%spinupyears - ! To get outputs for all runyears idx=yr and also in run_biomee_f_bysite.R make n_annual_cohorts = as.integer(runyears) - - !idx = yr - output_annual_cohorts_year(idx, :) = dble(out_biosphere%annual_cohorts(:)%year) output_annual_cohorts_cID(idx, :) = dble(out_biosphere%annual_cohorts(:)%cID) output_annual_cohorts_PFT(idx, :) = dble(out_biosphere%annual_cohorts(:)%PFT) @@ -791,7 +786,7 @@ subroutine biomee_f( & output_annual_cohorts_height(idx, :) = dble(out_biosphere%annual_cohorts(:)%height) output_annual_cohorts_age(idx, :) = dble(out_biosphere%annual_cohorts(:)%age) output_annual_cohorts_BA(idx, :) = dble(out_biosphere%annual_cohorts(:)%BA) - output_annual_cohorts_BA(idx, :) = dble(out_biosphere%annual_cohorts(:)%dBA) + output_annual_cohorts_dBA(idx, :) = dble(out_biosphere%annual_cohorts(:)%dBA) output_annual_cohorts_Acrown(idx, :) = dble(out_biosphere%annual_cohorts(:)%Acrown) output_annual_cohorts_Aleaf(idx, :) = dble(out_biosphere%annual_cohorts(:)%Aleaf) output_annual_cohorts_nsc(idx, :) = dble(out_biosphere%annual_cohorts(:)%nsc) @@ -812,6 +807,8 @@ subroutine biomee_f( & output_annual_cohorts_Nupt(idx, :) = dble(out_biosphere%annual_cohorts(:)%Nupt) output_annual_cohorts_Nfix(idx, :) = dble(out_biosphere%annual_cohorts(:)%Nfix) output_annual_cohorts_deathrate(idx, :) = dble(out_biosphere%annual_cohorts(:)%deathrate) + output_annual_cohorts_n_deadtrees(idx, :) = dble(out_biosphere%annual_cohorts(:)%n_deadtrees) + output_annual_cohorts_c_deadtrees(idx, :) = dble(out_biosphere%annual_cohorts(:)%c_deadtrees) end if diff --git a/src/vegetation_biomee.mod.f90 b/src/vegetation_biomee.mod.f90 index 47ff1673..ba1625d3 100755 --- a/src/vegetation_biomee.mod.f90 +++ b/src/vegetation_biomee.mod.f90 @@ -494,7 +494,6 @@ subroutine vegn_phenology( vegn ) integer :: i ! real :: grassdensity ! for grasses only ! real :: BL_u,BL_c - integer :: GrassMaxL = 3 real :: ccNSC, ccNSN logical :: cc_firstday = .false. logical :: TURN_ON_life = .false., TURN_OFF_life @@ -983,18 +982,6 @@ subroutine plant2soil(vegn, cc, deadtrees) cc%m_turnover = cc%m_turnover + loss_coarse + loss_fine !cc%m_turnover = cc%m_turnover + deadtrees * (cc%pwood%c%c12 + cc%psapw%c%c12) - ! cc%c_deadtrees = deadtrees * (cc%plabl%c%c12 + cc%pseed%c%c12 + cc%pleaf%c%c12 + cc%proot%c%c12 + cc%psapw%c%c12 + cc%pwood%c%c12) - - ! vegn%n_deadtrees = vegn%n_deadtrees + deadtrees - ! vegn%c_deadtrees = vegn%c_deadtrees + deadtrees * (cc%plabl%c%c12 + cc%pseed%c%c12 + cc%pleaf%c%c12 + cc%proot%c%c12 + cc%psapw%c%c12 + cc%pwood%c%c12) - - ! ! print*, "vegn%n_deadtrees", vegn%n_deadtrees - ! print*, "deadtrees", deadtrees - ! print*, "cc%n_deadtrees", cc%n_deadtrees - ! print*, "vegn%n_deadtrees", vegn%n_deadtrees - ! print*, "vegn%n_deadtrees", vegn%n_deadtrees - ! print*, "vegn%c_deadtrees", vegn%c_deadtrees - end associate end subroutine plant2soil @@ -1350,7 +1337,7 @@ subroutine relayer_cohorts( vegn ) ! THIS CREATES WEIRD BUG: SOMETIMES ZERO SOLUTION ! replace the array of cohorts deallocate(vegn%cohorts) - vegn%cohorts => new + vegn%cohorts => new !--------------------------------- ! !--------------------------------- @@ -1897,52 +1884,54 @@ subroutine kill_lowdensity_cohorts( vegn ) end subroutine kill_lowdensity_cohorts subroutine kill_old_grass(vegn) - ! kill old grass cohorts - ! Weng, 01/22/2023 - type(vegn_tile_type), intent(inout) :: vegn - - ! ---- local vars - type(cohort_type), pointer :: cx, cc(:) ! array to hold new cohorts - logical :: merged(vegn%n_cohorts) ! mask to skip cohorts that were already merged - real, parameter :: mindensity = 0.25E-4 - logical :: OldGrass - integer :: i,j,k - - ! calculate the number of cohorts that are not old grass - k = 0 - do i = 1, vegn%n_cohorts - cx =>vegn%cohorts(i) - associate(sp=>spdata(cx%species)) - OldGrass = (sp%lifeform ==0 .and. cx%age > 3.0) - if (.not. OldGrass) k=k+1 - end associate - enddo - ! if (k==0)then - ! write(*,*)'in kill_old_grass: All cohorts are old grass, No action!' - ! !stop - ! endif - - ! exclude cohorts that are old grass - if (k>0 .and. kvegn%cohorts(i) + associate(sp=>spdata(cx%species)) + OldGrass = (sp%lifeform ==0 .and. cx%age > 3.0) + if (.not. OldGrass) k=k+1 + end associate + enddo + + ! if (k==0)then + ! write(*,*)'in kill_old_grass: All cohorts are old grass, No action!' + ! !stop + ! endif + + ! exclude cohorts that are old grass + if (k>0 .and. kvegn%cohorts(i) associate(sp=>spdata(cx%species)) - OldGrass = (sp%lifeform ==0 .and. cx%age > 3.0) - if (.not. OldGrass) then - j=j+1 - cc(j) = cx - else - ! Carbon and Nitrogen from plants to soil pools - call plant2soil(vegn,cx,cx%nindivs) - endif + OldGrass = (sp%lifeform ==0 .and. cx%age > 3.0) + if (.not. OldGrass) then + j=j+1 + cc(j) = cx + else + ! Carbon and Nitrogen from plants to soil pools + call plant2soil(vegn,cx,cx%nindivs) + endif end associate - enddo - vegn%n_cohorts = j - deallocate (vegn%cohorts) - vegn%cohorts=>cc - endif + enddo + vegn%n_cohorts = j + deallocate (vegn%cohorts) + vegn%cohorts=>cc + endif + end subroutine kill_old_grass subroutine merge_cohorts(c1, c2) @@ -2247,12 +2236,11 @@ function leaf_area_from_biomass(bl,species) result (area) !==================== Vegetation initializations ======================= !======================================================================= - subroutine initialize_vegn_tile( vegn, nCohorts ) + subroutine initialize_vegn_tile( vegn ) !//////////////////////////////////////////////////////////////// ! Code from BiomeE-Allocation !--------------------------------------------------------------- type(vegn_tile_type), intent(inout), pointer :: vegn - integer, intent(in) :: nCohorts ! -local vars ------- type(cohort_type), dimension(:), pointer :: cc type(cohort_type), pointer :: cx @@ -2287,7 +2275,7 @@ subroutine initialize_vegn_tile( vegn, nCohorts ) ! xxx seems new from d-ben - missing if? ! Initialize plant cohorts - init_n_cohorts = myinterface%init_cohort(1)%init_n_cohorts !nCohorts !Weng,2018-11-21 + init_n_cohorts = myinterface%init_cohort(1)%init_n_cohorts allocate(cc(1:init_n_cohorts), STAT = istat) vegn%cohorts => cc vegn%n_cohorts = init_n_cohorts @@ -2295,17 +2283,17 @@ subroutine initialize_vegn_tile( vegn, nCohorts ) do i=1,init_n_cohorts cx => vegn%cohorts(i) - cx%status = LEAF_OFF ! ON=1, OFF=0 ! ON - cx%layer = 1 - cx%age = 0 - cx%species = INT(myinterface%init_cohort(i)%init_cohort_species) - cx%ccID = i - cx%plabl%c%c12 = myinterface%init_cohort(i)%init_cohort_nsc - cx%nindivs = myinterface%init_cohort(i)%init_cohort_nindivs ! trees/m2 - cx%psapw%c%c12 = myinterface%init_cohort(i)%init_cohort_bsw - cx%pwood%c%c12 = myinterface%init_cohort(i)%init_cohort_bHW - btotal = cx%psapw%c%c12 + cx%pwood%c%c12 ! kgC /tree - call initialize_cohort_from_biomass(cx,btotal) + cx%status = LEAF_OFF ! ON=1, OFF=0 ! ON + cx%layer = 1 + cx%age = 0 + cx%species = INT(myinterface%init_cohort(i)%init_cohort_species) + cx%ccID = i + cx%plabl%c%c12 = myinterface%init_cohort(i)%init_cohort_nsc + cx%nindivs = myinterface%init_cohort(i)%init_cohort_nindivs ! trees/m2 + cx%psapw%c%c12 = myinterface%init_cohort(i)%init_cohort_bsw + cx%pwood%c%c12 = myinterface%init_cohort(i)%init_cohort_bHW + btotal = cx%psapw%c%c12 + cx%pwood%c%c12 ! kgC /tree + call initialize_cohort_from_biomass(cx, btotal) enddo MaxCohortID = cx%ccID diff --git a/src/waterbal_splash.mod.f90 b/src/waterbal_splash.mod.f90 index 3355fe2f..d0c52255 100644 --- a/src/waterbal_splash.mod.f90 +++ b/src/waterbal_splash.mod.f90 @@ -310,7 +310,7 @@ subroutine calc_et( tile_fluxes, grid, climate, sw ) ! Eq. 51, SPLASH 2.0 Documentation ! out_evap%econ = 1.0 / ( lv * rho_water ) ! this is to convert energy into mass (water) - tile_fluxes%canopy%econ = sat_slope / (lv * rho_water * (sat_slope + gamma)) ! MORE PRECISELY - this is to convert energy into mass (water) + tile_fluxes%canopy%econ = sat_slope / (lv * rho_water * (sat_slope + gamma)) ! MORE PRECISELY - this is to convert energy into mass (water) !--------------------------------------------------------- ! Daily condensation, mm d-1 From 22f03f7a7eb7b936c64de16d682645dff52b710f Mon Sep 17 00:00:00 2001 From: Beni Stocker Date: Fri, 17 May 2024 13:33:55 +0200 Subject: [PATCH 3/4] separated out_biosphere in biomee (avoid it being too large an array) --- src/biosphere_biomee.mod.f90 | 26 ++-- src/interface_biosphere_biomee.mod.f90 | 16 +-- src/sofun_r.f90 | 157 ++++++++++++++----------- vignettes/biomee_use.Rmd | 10 +- 4 files changed, 120 insertions(+), 89 deletions(-) diff --git a/src/biosphere_biomee.mod.f90 b/src/biosphere_biomee.mod.f90 index 51cbb38e..4a5f8b6c 100644 --- a/src/biosphere_biomee.mod.f90 +++ b/src/biosphere_biomee.mod.f90 @@ -20,15 +20,27 @@ module md_biosphere_biomee contains - subroutine biosphere_annual(out_biosphere) + subroutine biosphere_annual( & + out_biosphere_daily_tile, & + out_biosphere_daily_cohorts, & + out_biosphere_annual_tile, & + out_biosphere_annual_cohorts & + ) !//////////////////////////////////////////////////////////////// ! Calculates one year of vegetation dynamics. !---------------------------------------------------------------- - use md_interface_biomee, only: myinterface, outtype_biosphere + use md_interface_biomee, only: myinterface, & + outtype_daily_tile, & + outtype_daily_cohorts, & + outtype_annual_tile, & + outtype_annual_cohorts use md_gpp_biomee, only: getpar_modl_gpp - ! return variable - type(outtype_biosphere) :: out_biosphere + ! return variables + type(outtype_daily_tile), dimension(ndayyear) , intent(out) :: out_biosphere_daily_tile + type(outtype_daily_cohorts), dimension(ndayyear,out_max_cohorts), intent(out) :: out_biosphere_daily_cohorts + type(outtype_annual_tile) , intent(out) :: out_biosphere_annual_tile + type(outtype_annual_cohorts), dimension(out_max_cohorts) , intent(out) :: out_biosphere_annual_cohorts ! ! local variables integer :: dm, moy, doy @@ -116,7 +128,7 @@ subroutine biosphere_annual(out_biosphere) !---------------------------------------------------------------- call vegn_CNW_budget( vegn, myinterface%climate(idata), init ) - call hourly_diagnostics( vegn, myinterface%climate(idata) ) !, iyears, idoy, i, out_biosphere%hourly_tile(idata) + call hourly_diagnostics( vegn, myinterface%climate(idata) ) init = .false. @@ -132,7 +144,7 @@ subroutine biosphere_annual(out_biosphere) soil_theta = vegn%thetaS ! sum over fast time steps and cohorts - call daily_diagnostics( vegn, iyears, idoy, out_biosphere%daily_cohorts(doy,:), out_biosphere%daily_tile(doy) ) + call daily_diagnostics( vegn, iyears, idoy, out_biosphere_daily_cohorts(doy,:), out_biosphere_daily_tile(doy) ) ! Determine start and end of season and maximum leaf (root) mass call vegn_phenology( vegn ) @@ -158,7 +170,7 @@ subroutine biosphere_annual(out_biosphere) ! cohorts again and we want annual output and daily ! output to be consistent with cohort identities. !--------------------------------------------- - call annual_diagnostics( vegn, iyears, out_biosphere%annual_cohorts(:), out_biosphere%annual_tile ) + call annual_diagnostics( vegn, iyears, out_biosphere_annual_cohorts(:), out_biosphere_annual_tile ) !--------------------------------------------- ! Reproduction and mortality diff --git a/src/interface_biosphere_biomee.mod.f90 b/src/interface_biosphere_biomee.mod.f90 index 8e0cee3a..4e494110 100644 --- a/src/interface_biosphere_biomee.mod.f90 +++ b/src/interface_biosphere_biomee.mod.f90 @@ -13,7 +13,7 @@ module md_interface_biomee implicit none private - public myinterface, interfacetype_biosphere, outtype_biosphere, outtype_hourly_tile, & + public myinterface, interfacetype_biosphere, outtype_hourly_tile, & outtype_annual_cohorts, outtype_daily_cohorts, outtype_daily_tile, outtype_annual_tile type paramstype_tile @@ -328,13 +328,13 @@ module md_interface_biomee real :: deathrate end type outtype_annual_cohorts - type outtype_biosphere - ! type(outtype_hourly_tile), dimension(:), allocatable :: hourly_tile !fn01 - type(outtype_daily_tile), dimension(ndayyear) :: daily_tile !fno4 - type(outtype_daily_cohorts), dimension(ndayyear,out_max_cohorts) :: daily_cohorts !fno3 - type(outtype_annual_tile) :: annual_tile !fno5 - type(outtype_annual_cohorts), dimension(out_max_cohorts) :: annual_cohorts !fno2 - end type outtype_biosphere + ! type outtype_biosphere + ! ! type(outtype_hourly_tile), dimension(:), allocatable :: hourly_tile !fn01 + ! type(outtype_daily_tile), dimension(ndayyear) :: daily_tile !fno4 + ! type(outtype_daily_cohorts), dimension(ndayyear,out_max_cohorts) :: daily_cohorts !fno3 + ! type(outtype_annual_tile) :: annual_tile !fno5 + ! type(outtype_annual_cohorts), dimension(out_max_cohorts) :: annual_cohorts !fno2 + ! end type outtype_biosphere contains diff --git a/src/sofun_r.f90 b/src/sofun_r.f90 index bfef6410..ac41f96c 100644 --- a/src/sofun_r.f90 +++ b/src/sofun_r.f90 @@ -351,8 +351,15 @@ subroutine biomee_f( & !---------------------------------------------------------------- use md_params_siml_biomee, only: getsteering ! use md_params_soil_biomee, only: getsoil - use md_forcing_biomee, only: getclimate, getco2, climate_type !, forcingData - use md_interface_biomee, only: interfacetype_biosphere, outtype_biosphere, myinterface + use md_forcing_biomee, only: getclimate, & + getco2, & + climate_type + use md_interface_biomee, only: interfacetype_biosphere, & + myinterface, & + outtype_daily_tile, & + outtype_daily_cohorts, & + outtype_annual_tile, & + outtype_annual_cohorts use md_params_core use md_biosphere_biomee, only: biosphere_annual @@ -489,7 +496,12 @@ subroutine biomee_f( & real(kind=c_double), dimension(nt_annual_cohorts,out_max_cohorts), intent(out) :: output_annual_cohorts_deathrate ! local variables - type(outtype_biosphere) :: out_biosphere ! holds all the output used for calculating the cost or maximum likelihood function + ! type(outtype_biosphere) :: out_biosphere ! holds all the output used for calculating the cost or maximum likelihood function + type(outtype_daily_tile), dimension(ndayyear) :: out_biosphere_daily_tile + type(outtype_daily_cohorts), dimension(ndayyear,out_max_cohorts) :: out_biosphere_daily_cohorts + type(outtype_annual_tile) :: out_biosphere_annual_tile + type(outtype_annual_cohorts), dimension(out_max_cohorts) :: out_biosphere_annual_cohorts + real :: timestep, timestep_d integer :: yr @@ -678,7 +690,7 @@ subroutine biomee_f( & allocate(myinterface%climate(ntstepsyear)) allocate(myinterface%pco2(ntstepsyear)) - ! allocate(out_biosphere%hourly_tile(ntstepsyear)) + ! allocate(out_biosphere_hourly_tile(ntstepsyear)) yearloop: do yr=1, myinterface%params_siml%runyears !---------------------------------------------------------------- @@ -701,7 +713,12 @@ subroutine biomee_f( & !---------------------------------------------------------------- ! Call biosphere (wrapper for all modules, contains time loops) !---------------------------------------------------------------- - call biosphere_annual( out_biosphere ) + call biosphere_annual( & + out_biosphere_daily_tile, & + out_biosphere_daily_cohorts, & + out_biosphere_annual_tile, & + out_biosphere_annual_cohorts & + ) !---------------------------------------------------------------- ! Populate big output arrays @@ -713,7 +730,7 @@ subroutine biomee_f( & ! if (.not. myinterface%steering%spinup) then ! idx_hourly_start = (yr - myinterface%params_siml%spinupyears - 1) * ntstepsyear + 1 ! To exclude the spinup years and include only the transient years ! idx_hourly_end = idx_hourly_start + ntstepsyear - 1 - ! ! call populate_outarray_hourly_tile( out_biosphere%hourly_tile(:), output_hourly_tile(idx_hourly_start:idx_hourly_end,:)) !xxx commented out for calibration! + ! ! call populate_outarray_hourly_tile( out_biosphere_hourly_tile(:), output_hourly_tile(idx_hourly_start:idx_hourly_end,:)) !xxx commented out for calibration! ! end if !---------------------------------------------------------------- @@ -725,45 +742,45 @@ subroutine biomee_f( & idx_daily_start = (yr - myinterface%params_siml%spinupyears - 1) * ndayyear + 1 idx_daily_end = idx_daily_start + ndayyear - 1 - call populate_outarray_daily_tile( out_biosphere%daily_tile(:), output_daily_tile(idx_daily_start:idx_daily_end,:)) + call populate_outarray_daily_tile( out_biosphere_daily_tile(:), output_daily_tile(idx_daily_start:idx_daily_end,:)) !---------------------------------------------------------------- ! Output out_daily_cohorts (without subroutine) !---------------------------------------------------------------- - output_daily_cohorts_year(idx_daily_start:idx_daily_end,:) = dble(out_biosphere%daily_cohorts(:,:)%year) - output_daily_cohorts_doy(idx_daily_start:idx_daily_end,:) = dble(out_biosphere%daily_cohorts(:,:)%doy) - output_daily_cohorts_hour(idx_daily_start:idx_daily_end,:) = dble(out_biosphere%daily_cohorts(:,:)%hour) - output_daily_cohorts_cID(idx_daily_start:idx_daily_end,:) = dble(out_biosphere%daily_cohorts(:,:)%cID) - output_daily_cohorts_PFT(idx_daily_start:idx_daily_end,:) = dble(out_biosphere%daily_cohorts(:,:)%PFT) - output_daily_cohorts_layer(idx_daily_start:idx_daily_end,:) = dble(out_biosphere%daily_cohorts(:,:)%layer) - output_daily_cohorts_density(idx_daily_start:idx_daily_end,:) = dble(out_biosphere%daily_cohorts(:,:)%density) - output_daily_cohorts_f_layer(idx_daily_start:idx_daily_end,:) = dble(out_biosphere%daily_cohorts(:,:)%f_layer) - output_daily_cohorts_LAI(idx_daily_start:idx_daily_end,:) = dble(out_biosphere%daily_cohorts(:,:)%LAI) - output_daily_cohorts_gpp(idx_daily_start:idx_daily_end,:) = dble(out_biosphere%daily_cohorts(:,:)%gpp) - output_daily_cohorts_resp(idx_daily_start:idx_daily_end,:) = dble(out_biosphere%daily_cohorts(:,:)%resp) - output_daily_cohorts_transp(idx_daily_start:idx_daily_end,:) = dble(out_biosphere%daily_cohorts(:,:)%transp) - output_daily_cohorts_NPPleaf(idx_daily_start:idx_daily_end,:) = dble(out_biosphere%daily_cohorts(:,:)%NPPleaf) - output_daily_cohorts_NPProot(idx_daily_start:idx_daily_end,:) = dble(out_biosphere%daily_cohorts(:,:)%NPProot) - output_daily_cohorts_NPPwood(idx_daily_start:idx_daily_end,:) = dble(out_biosphere%daily_cohorts(:,:)%NPPwood) - output_daily_cohorts_NSC(idx_daily_start:idx_daily_end,:) = dble(out_biosphere%daily_cohorts(:,:)%NSC) - output_daily_cohorts_seedC(idx_daily_start:idx_daily_end,:) = dble(out_biosphere%daily_cohorts(:,:)%seedC) - output_daily_cohorts_leafC(idx_daily_start:idx_daily_end,:) = dble(out_biosphere%daily_cohorts(:,:)%leafC) - output_daily_cohorts_rootC(idx_daily_start:idx_daily_end,:) = dble(out_biosphere%daily_cohorts(:,:)%rootC) - output_daily_cohorts_SW_C(idx_daily_start:idx_daily_end,:) = dble(out_biosphere%daily_cohorts(:,:)%SW_C) - output_daily_cohorts_HW_C(idx_daily_start:idx_daily_end,:) = dble(out_biosphere%daily_cohorts(:,:)%HW_C) - output_daily_cohorts_NSN(idx_daily_start:idx_daily_end,:) = dble(out_biosphere%daily_cohorts(:,:)%NSN) - output_daily_cohorts_seedN(idx_daily_start:idx_daily_end,:) = dble(out_biosphere%daily_cohorts(:,:)%seedN) - output_daily_cohorts_leafN(idx_daily_start:idx_daily_end,:) = dble(out_biosphere%daily_cohorts(:,:)%leafN) - output_daily_cohorts_rootN(idx_daily_start:idx_daily_end,:) = dble(out_biosphere%daily_cohorts(:,:)%rootN) - output_daily_cohorts_SW_N(idx_daily_start:idx_daily_end,:) = dble(out_biosphere%daily_cohorts(:,:)%SW_N) - output_daily_cohorts_HW_N(idx_daily_start:idx_daily_end,:) = dble(out_biosphere%daily_cohorts(:,:)%HW_N) + output_daily_cohorts_year(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%year) + output_daily_cohorts_doy(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%doy) + output_daily_cohorts_hour(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%hour) + output_daily_cohorts_cID(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%cID) + output_daily_cohorts_PFT(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%PFT) + output_daily_cohorts_layer(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%layer) + output_daily_cohorts_density(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%density) + output_daily_cohorts_f_layer(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%f_layer) + output_daily_cohorts_LAI(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%LAI) + output_daily_cohorts_gpp(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%gpp) + output_daily_cohorts_resp(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%resp) + output_daily_cohorts_transp(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%transp) + output_daily_cohorts_NPPleaf(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%NPPleaf) + output_daily_cohorts_NPProot(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%NPProot) + output_daily_cohorts_NPPwood(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%NPPwood) + output_daily_cohorts_NSC(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%NSC) + output_daily_cohorts_seedC(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%seedC) + output_daily_cohorts_leafC(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%leafC) + output_daily_cohorts_rootC(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%rootC) + output_daily_cohorts_SW_C(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%SW_C) + output_daily_cohorts_HW_C(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%HW_C) + output_daily_cohorts_NSN(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%NSN) + output_daily_cohorts_seedN(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%seedN) + output_daily_cohorts_leafN(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%leafN) + output_daily_cohorts_rootN(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%rootN) + output_daily_cohorts_SW_N(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%SW_N) + output_daily_cohorts_HW_N(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%HW_N) end if !---------------------------------------------------------------- ! Output out_annual_tile (calling subroutine) !---------------------------------------------------------------- - call populate_outarray_annual_tile( out_biosphere%annual_tile, output_annual_tile(yr,:) ) + call populate_outarray_annual_tile( out_biosphere_annual_tile, output_annual_tile(yr,:) ) !---------------------------------------------------------------- ! Output output_annual_cohorts (without subroutine) @@ -775,40 +792,40 @@ subroutine biomee_f( & idx = yr - myinterface%params_siml%spinupyears - output_annual_cohorts_year(idx, :) = dble(out_biosphere%annual_cohorts(:)%year) - output_annual_cohorts_cID(idx, :) = dble(out_biosphere%annual_cohorts(:)%cID) - output_annual_cohorts_PFT(idx, :) = dble(out_biosphere%annual_cohorts(:)%PFT) - output_annual_cohorts_layer(idx, :) = dble(out_biosphere%annual_cohorts(:)%layer) - output_annual_cohorts_density(idx, :) = dble(out_biosphere%annual_cohorts(:)%density) - output_annual_cohorts_flayer(idx, :) = dble(out_biosphere%annual_cohorts(:)%flayer) - output_annual_cohorts_dbh(idx, :) = dble(out_biosphere%annual_cohorts(:)%DBH) - output_annual_cohorts_dDBH(idx, :) = dble(out_biosphere%annual_cohorts(:)%dDBH) - output_annual_cohorts_height(idx, :) = dble(out_biosphere%annual_cohorts(:)%height) - output_annual_cohorts_age(idx, :) = dble(out_biosphere%annual_cohorts(:)%age) - output_annual_cohorts_BA(idx, :) = dble(out_biosphere%annual_cohorts(:)%BA) - output_annual_cohorts_dBA(idx, :) = dble(out_biosphere%annual_cohorts(:)%dBA) - output_annual_cohorts_Acrown(idx, :) = dble(out_biosphere%annual_cohorts(:)%Acrown) - output_annual_cohorts_Aleaf(idx, :) = dble(out_biosphere%annual_cohorts(:)%Aleaf) - output_annual_cohorts_nsc(idx, :) = dble(out_biosphere%annual_cohorts(:)%nsc) - output_annual_cohorts_nsn(idx, :) = dble(out_biosphere%annual_cohorts(:)%nsn) - output_annual_cohorts_seedC(idx, :) = dble(out_biosphere%annual_cohorts(:)%seedC) - output_annual_cohorts_leafC(idx, :) = dble(out_biosphere%annual_cohorts(:)%leafC) - output_annual_cohorts_rootC(idx, :) = dble(out_biosphere%annual_cohorts(:)%rootC) - output_annual_cohorts_sapwC(idx, :) = dble(out_biosphere%annual_cohorts(:)%sapwC) - output_annual_cohorts_woodC(idx, :) = dble(out_biosphere%annual_cohorts(:)%woodC) - output_annual_cohorts_treeG(idx, :) = dble(out_biosphere%annual_cohorts(:)%treeG) - output_annual_cohorts_fseed(idx, :) = dble(out_biosphere%annual_cohorts(:)%fseed) - output_annual_cohorts_fleaf(idx, :) = dble(out_biosphere%annual_cohorts(:)%fleaf) - output_annual_cohorts_froot(idx, :) = dble(out_biosphere%annual_cohorts(:)%froot) - output_annual_cohorts_fwood(idx, :) = dble(out_biosphere%annual_cohorts(:)%fwood) - output_annual_cohorts_GPP(idx, :) = dble(out_biosphere%annual_cohorts(:)%GPP) - output_annual_cohorts_NPP(idx, :) = dble(out_biosphere%annual_cohorts(:)%NPP) - output_annual_cohorts_Rauto(idx, :) = dble(out_biosphere%annual_cohorts(:)%Rauto) - output_annual_cohorts_Nupt(idx, :) = dble(out_biosphere%annual_cohorts(:)%Nupt) - output_annual_cohorts_Nfix(idx, :) = dble(out_biosphere%annual_cohorts(:)%Nfix) - output_annual_cohorts_deathrate(idx, :) = dble(out_biosphere%annual_cohorts(:)%deathrate) - output_annual_cohorts_n_deadtrees(idx, :) = dble(out_biosphere%annual_cohorts(:)%n_deadtrees) - output_annual_cohorts_c_deadtrees(idx, :) = dble(out_biosphere%annual_cohorts(:)%c_deadtrees) + output_annual_cohorts_year(idx, :) = dble(out_biosphere_annual_cohorts(:)%year) + output_annual_cohorts_cID(idx, :) = dble(out_biosphere_annual_cohorts(:)%cID) + output_annual_cohorts_PFT(idx, :) = dble(out_biosphere_annual_cohorts(:)%PFT) + output_annual_cohorts_layer(idx, :) = dble(out_biosphere_annual_cohorts(:)%layer) + output_annual_cohorts_density(idx, :) = dble(out_biosphere_annual_cohorts(:)%density) + output_annual_cohorts_flayer(idx, :) = dble(out_biosphere_annual_cohorts(:)%flayer) + output_annual_cohorts_dbh(idx, :) = dble(out_biosphere_annual_cohorts(:)%DBH) + output_annual_cohorts_dDBH(idx, :) = dble(out_biosphere_annual_cohorts(:)%dDBH) + output_annual_cohorts_height(idx, :) = dble(out_biosphere_annual_cohorts(:)%height) + output_annual_cohorts_age(idx, :) = dble(out_biosphere_annual_cohorts(:)%age) + output_annual_cohorts_BA(idx, :) = dble(out_biosphere_annual_cohorts(:)%BA) + output_annual_cohorts_dBA(idx, :) = dble(out_biosphere_annual_cohorts(:)%dBA) + output_annual_cohorts_Acrown(idx, :) = dble(out_biosphere_annual_cohorts(:)%Acrown) + output_annual_cohorts_Aleaf(idx, :) = dble(out_biosphere_annual_cohorts(:)%Aleaf) + output_annual_cohorts_nsc(idx, :) = dble(out_biosphere_annual_cohorts(:)%nsc) + output_annual_cohorts_nsn(idx, :) = dble(out_biosphere_annual_cohorts(:)%nsn) + output_annual_cohorts_seedC(idx, :) = dble(out_biosphere_annual_cohorts(:)%seedC) + output_annual_cohorts_leafC(idx, :) = dble(out_biosphere_annual_cohorts(:)%leafC) + output_annual_cohorts_rootC(idx, :) = dble(out_biosphere_annual_cohorts(:)%rootC) + output_annual_cohorts_sapwC(idx, :) = dble(out_biosphere_annual_cohorts(:)%sapwC) + output_annual_cohorts_woodC(idx, :) = dble(out_biosphere_annual_cohorts(:)%woodC) + output_annual_cohorts_treeG(idx, :) = dble(out_biosphere_annual_cohorts(:)%treeG) + output_annual_cohorts_fseed(idx, :) = dble(out_biosphere_annual_cohorts(:)%fseed) + output_annual_cohorts_fleaf(idx, :) = dble(out_biosphere_annual_cohorts(:)%fleaf) + output_annual_cohorts_froot(idx, :) = dble(out_biosphere_annual_cohorts(:)%froot) + output_annual_cohorts_fwood(idx, :) = dble(out_biosphere_annual_cohorts(:)%fwood) + output_annual_cohorts_GPP(idx, :) = dble(out_biosphere_annual_cohorts(:)%GPP) + output_annual_cohorts_NPP(idx, :) = dble(out_biosphere_annual_cohorts(:)%NPP) + output_annual_cohorts_Rauto(idx, :) = dble(out_biosphere_annual_cohorts(:)%Rauto) + output_annual_cohorts_Nupt(idx, :) = dble(out_biosphere_annual_cohorts(:)%Nupt) + output_annual_cohorts_Nfix(idx, :) = dble(out_biosphere_annual_cohorts(:)%Nfix) + output_annual_cohorts_deathrate(idx, :) = dble(out_biosphere_annual_cohorts(:)%deathrate) + output_annual_cohorts_n_deadtrees(idx, :) = dble(out_biosphere_annual_cohorts(:)%n_deadtrees) + output_annual_cohorts_c_deadtrees(idx, :) = dble(out_biosphere_annual_cohorts(:)%c_deadtrees) end if @@ -816,7 +833,7 @@ subroutine biomee_f( & deallocate(myinterface%climate) deallocate(myinterface%pco2) - ! deallocate(out_biosphere%hourly_tile) + ! deallocate(out_biosphere_hourly_tile) end subroutine biomee_f diff --git a/vignettes/biomee_use.Rmd b/vignettes/biomee_use.Rmd index a1ff41c6..b1417e3e 100644 --- a/vignettes/biomee_use.Rmd +++ b/vignettes/biomee_use.Rmd @@ -92,9 +92,9 @@ biomee_gs_leuning_output |> theme_classic()+labs(x = "Year", y = "plantC") ``` -## Running the BiomeE model with P-model photosynthesis +## Running the BiomeEP model -Running the fast P-model implementation. +Running the fast P-model implementation with P-model photosynthesis. ```{r} # print parameter settings @@ -135,12 +135,14 @@ We can now visualize the model output. biomee_p_model_output %>% ggplot() + geom_line(aes(x = year, y = GPP)) + - theme_classic()+labs(x = "Year", y = "GPP") + theme_classic() + + labs(x = "Year", y = "GPP") biomee_p_model_output %>% ggplot() + geom_line(aes(x = year, y = plantC)) + - theme_classic()+labs(x = "Year", y = "plantC") + theme_classic() + + labs(x = "Year", y = "plantC") ``` ## Calibrating model parameters From b177d490b797622c83d614c765593aa8312ed914 Mon Sep 17 00:00:00 2001 From: Beni Stocker Date: Fri, 17 May 2024 14:03:18 +0200 Subject: [PATCH 4/4] commented out daily cohort-level output --- R/run_biomee_f_bysite.R | 258 ++++++++++++++++++++++--------- src/biosphere_biomee.mod.f90 | 8 +- src/datatypes.mod.f90 | 120 +++++++------- src/sofun_r.f90 | 166 ++++++++++---------- src/wrappersc.c | 292 +++++++++++++++++------------------ 5 files changed, 474 insertions(+), 370 deletions(-) diff --git a/R/run_biomee_f_bysite.R b/R/run_biomee_f_bysite.R index f476b27f..c78988e4 100644 --- a/R/run_biomee_f_bysite.R +++ b/R/run_biomee_f_bysite.R @@ -610,44 +610,108 @@ run_biomee_f_bysite <- function( if (size_of_object_gb < 5){ output_daily_tile <- as.data.frame(biomeeout[[1]], stringAsFactor = FALSE) colnames(output_daily_tile) <- c( - "year", "doy", "Tc", - "Prcp", "totWs", "Trsp", - "Evap", "Runoff", "ws1", - "ws2", "ws3", "LAI", - "GPP", "Rauto", "Rh", - "NSC", "seedC", "leafC", - "rootC", "SW_C", "HW_C", - "NSN", "seedN", "leafN", - "rootN", "SW_N", "HW_N", - "McrbC", "fastSOM", "slowSOM", - "McrbN", "fastSoilN", "slowSoilN", - "mineralN", "N_uptk") + "year", + "doy", + "Tc", + "Prcp", + "totWs", + "Trsp", + "Evap", + "Runoff", + "ws1", + "ws2", + "ws3", + "LAI", + "GPP", + "Rauto", + "Rh", + "NSC", + "seedC", + "leafC", + "rootC", + "SW_C", + "HW_C", + "NSN", + "seedN", + "leafN", + "rootN", + "SW_N", + "HW_N", + "McrbC", + "fastSOM", + "slowSOM", + "McrbN", + "fastSoilN", + "slowSoilN", + "mineralN", + "N_uptk") } else { output_daily_tile <- NA } # annual tile - output_annual_tile <- as.data.frame(biomeeout[[29]], stringAsFactor = FALSE) - colnames(output_annual_tile) <- c("year", "CAI", "LAI", - "Density", "DBH", "Density12", - "DBH12", "QMD", "NPP", - "GPP", "Rauto", "Rh", - "rain", "SoilWater","Transp", - "Evap", "Runoff", "plantC", - "soilC", "plantN", "soilN", - "totN", "NSC", "SeedC", "leafC", - "rootC", "SapwoodC", "WoodC", - "NSN", "SeedN", "leafN", - "rootN", "SapwoodN", "WoodN", - "McrbC", "fastSOM", "SlowSOM", - "McrbN", "fastSoilN", "slowSoilN", - "mineralN", "N_fxed", "N_uptk", - "N_yrMin", "N_P2S", "N_loss", - "totseedC", "totseedN", "Seedling_C", - "Seedling_N", "MaxAge", "MaxVolume", - "MaxDBH", "NPPL", "NPPW", - "n_deadtrees", "c_deadtrees", "m_turnover", - "c_turnover_time") + output_annual_tile <- as.data.frame(biomeeout[[2]], stringAsFactor = FALSE) + colnames(output_annual_tile) <- c( + "year", + "CAI", + "LAI", + "Density", + "DBH", + "Density12", + "DBH12", + "QMD", + "NPP", + "GPP", + "Rauto", + "Rh", + "rain", + "SoilWater"," + Transp", + "Evap", + "Runoff", + "plantC", + "soilC", + "plantN", + "soilN", + "totN", + "NSC", + "SeedC", + "leafC", + "rootC", + "SapwoodC", + "WoodC", + "NSN", + "SeedN", + "leafN", + "rootN", + "SapwoodN", + "WoodN", + "McrbC", + "fastSOM", + "SlowSOM", + "McrbN", + "fastSoilN", + "slowSoilN", + "mineralN", + "N_fxed", + "N_uptk", + "N_yrMin", + "N_P2S", + "N_loss", + "totseedC", + "totseedN", + "Seedling_C", + "Seedling_N", + "MaxAge", + "MaxVolume", + "MaxDBH", + "NPPL", + "NPPW", + "n_deadtrees", + "c_deadtrees", + "m_turnover", + "c_turnover_time" + ) #---- Multi-level output, multiple matrices to be combined ---- @@ -661,57 +725,97 @@ run_biomee_f_bysite <- function( # as vector() #---- daily cohorts ---- - if (size_of_object_gb < 5){ - daily_values <- c( - "year","doy","hour", - "cID", "PFT", "layer", - "density","f_layer", "LAI", - "gpp","resp","transp", - "NPPleaf","NPProot", "NPPwood", "NSC", - "seedC", "leafC", "rootC", - "SW_C", "HW_C", "NSN", - "seedN", "leafN", "rootN", - "SW_N", "HW_N" - ) - output_daily_cohorts <- lapply(1:length(daily_values), function(x){ - loc <- 1 + x - v <- data.frame( - as.vector(biomeeout[[loc]]), - stringsAsFactors = FALSE) - names(v) <- daily_values[x] - return(v) - }) + # if (size_of_object_gb < 5){ + # daily_values <- c( + # "year"," + # doy"," + # hour" + # "cID", + # "PFT", + # "layer" + # "density"," + # f_layer", + # "LAI" + # "gpp"," + # resp"," + # transp" + # "NPPleaf"," + # NPProot", + # "NPPwood", + # "NSC" + # "seedC", + # "leafC", + # "rootC" + # "SW_C", + # "HW_C", + # "NSN" + # "seedN", + # "leafN", + # "rootN" + # "SW_N", + # "HW_N" + # ) + # output_daily_cohorts <- lapply(1:length(daily_values), function(x){ + # loc <- 1 + x + # v <- data.frame( + # as.vector(biomeeout[[loc]]), + # stringsAsFactors = FALSE) + # names(v) <- daily_values[x] + # return(v) + # }) - output_daily_cohorts <- do.call("cbind", output_daily_cohorts) + # output_daily_cohorts <- do.call("cbind", output_daily_cohorts) - cohort <- sort(rep(1:ncol(biomeeout[[3]]),nrow(biomeeout[[3]]))) - output_daily_cohorts <- cbind(cohort, output_daily_cohorts) + # cohort <- sort(rep(1:ncol(biomeeout[[3]]),nrow(biomeeout[[3]]))) + # output_daily_cohorts <- cbind(cohort, output_daily_cohorts) - # drop rows (cohorts) with no values - output_daily_cohorts$year[output_daily_cohorts$year == -9999 | - output_daily_cohorts$year == 0] <- NA - output_daily_cohorts <- - output_daily_cohorts[!is.na(output_daily_cohorts$year),] - } else { - output_daily_cohorts <- NA - } + # # drop rows (cohorts) with no values + # output_daily_cohorts$year[output_daily_cohorts$year == -9999 | + # output_daily_cohorts$year == 0] <- NA + # output_daily_cohorts <- output_daily_cohorts[!is.na(output_daily_cohorts$year),] + # } else { + # output_daily_cohorts <- NA + # } #--- annual cohorts ---- annual_values <- c( - "year","cID", - "PFT","layer","density", - "flayer","DBH","dDBH","height", - "age","BA","dBA","Acrown","Aleaf", - "nsc","seedC","leafC","rootC", - "sapwC","woodC","nsn","treeG", - "fseed","fleaf","froot","fwood", - "GPP","NPP","Rauto", - "Nupt","Nfix","n_deadtrees", - "c_deadtrees","deathrate" + "year", + "cID", + "PFT", + "layer", + "density", + "flayer", + "DBH", + "dDBH", + "height", + "age", + "BA", + "dBA", + "Acrown", + "Aleaf", + "nsc", + "seedC", + "leafC", + "rootC", + "sapwC", + "woodC", + "nsn", + "treeG", + "fseed", + "fleaf", + "froot", + "fwood", + "GPP", + "NPP", + "Rauto", + "Nupt", + "Nfix", + "n_deadtrees", + "c_deadtrees", + "deathrate" ) - output_annual_cohorts <- lapply(1:length(annual_values), function(x){ - loc <- 29 + x + loc <- 2 + x v <- data.frame( as.vector(biomeeout[[loc]]), stringsAsFactors = FALSE) @@ -735,7 +839,7 @@ run_biomee_f_bysite <- function( out <- list( # output_hourly_tile = output_hourly_tile, output_daily_tile = output_daily_tile, - output_daily_cohorts = output_daily_cohorts, + # output_daily_cohorts = output_daily_cohorts, output_annual_tile = output_annual_tile, output_annual_cohorts = output_annual_cohorts) diff --git a/src/biosphere_biomee.mod.f90 b/src/biosphere_biomee.mod.f90 index 4a5f8b6c..fe66c834 100644 --- a/src/biosphere_biomee.mod.f90 +++ b/src/biosphere_biomee.mod.f90 @@ -22,7 +22,7 @@ module md_biosphere_biomee subroutine biosphere_annual( & out_biosphere_daily_tile, & - out_biosphere_daily_cohorts, & + ! out_biosphere_daily_cohorts, & out_biosphere_annual_tile, & out_biosphere_annual_cohorts & ) @@ -31,14 +31,14 @@ subroutine biosphere_annual( & !---------------------------------------------------------------- use md_interface_biomee, only: myinterface, & outtype_daily_tile, & - outtype_daily_cohorts, & + ! outtype_daily_cohorts, & outtype_annual_tile, & outtype_annual_cohorts use md_gpp_biomee, only: getpar_modl_gpp ! return variables type(outtype_daily_tile), dimension(ndayyear) , intent(out) :: out_biosphere_daily_tile - type(outtype_daily_cohorts), dimension(ndayyear,out_max_cohorts), intent(out) :: out_biosphere_daily_cohorts + ! type(outtype_daily_cohorts), dimension(ndayyear,out_max_cohorts), intent(out) :: out_biosphere_daily_cohorts type(outtype_annual_tile) , intent(out) :: out_biosphere_annual_tile type(outtype_annual_cohorts), dimension(out_max_cohorts) , intent(out) :: out_biosphere_annual_cohorts @@ -144,7 +144,7 @@ subroutine biosphere_annual( & soil_theta = vegn%thetaS ! sum over fast time steps and cohorts - call daily_diagnostics( vegn, iyears, idoy, out_biosphere_daily_cohorts(doy,:), out_biosphere_daily_tile(doy) ) + call daily_diagnostics( vegn, iyears, idoy, out_biosphere_daily_tile(doy) ) ! , out_biosphere_daily_cohorts(doy,:) ! Determine start and end of season and maximum leaf (root) mass call vegn_phenology( vegn ) diff --git a/src/datatypes.mod.f90 b/src/datatypes.mod.f90 index 5f47e8d6..3240fc1f 100644 --- a/src/datatypes.mod.f90 +++ b/src/datatypes.mod.f90 @@ -956,7 +956,7 @@ subroutine hourly_diagnostics(vegn, forcing) !, iyears, idoy, ihour, out_hourly end subroutine hourly_diagnostics - subroutine daily_diagnostics( vegn , iyears, idoy, out_daily_cohorts, out_daily_tile) + subroutine daily_diagnostics( vegn , iyears, idoy, out_daily_tile ) ! , out_daily_cohorts !//////////////////////////////////////////////////////////////////////// ! Updates daily tile-level variables and takes running annual sums !------------------------------------------------------------------------ @@ -965,76 +965,76 @@ subroutine daily_diagnostics( vegn , iyears, idoy, out_daily_cohorts, out_daily_ type(vegn_tile_type), intent(inout) :: vegn integer, intent(in) :: iyears, idoy - type(outtype_daily_cohorts), dimension(out_max_cohorts), intent(out) :: out_daily_cohorts + ! type(outtype_daily_cohorts), dimension(out_max_cohorts), intent(out) :: out_daily_cohorts type(outtype_daily_tile), intent(out) :: out_daily_tile ! local variables type(cohort_type), pointer :: cc ! current cohort integer :: i - if (.not. myinterface%steering%spinup) then - out_daily_cohorts(:)%year = dummy - out_daily_cohorts(:)%doy = dummy - out_daily_cohorts(:)%hour = dummy - out_daily_cohorts(:)%cID = dummy - out_daily_cohorts(:)%PFT = dummy - out_daily_cohorts(:)%layer = dummy - out_daily_cohorts(:)%density = dummy - out_daily_cohorts(:)%f_layer = dummy - out_daily_cohorts(:)%LAI = dummy - out_daily_cohorts(:)%gpp = dummy - out_daily_cohorts(:)%resp = dummy - out_daily_cohorts(:)%transp = dummy - out_daily_cohorts(:)%NPPleaf = dummy - out_daily_cohorts(:)%NPProot = dummy - out_daily_cohorts(:)%NPPwood = dummy - out_daily_cohorts(:)%NSC = dummy - out_daily_cohorts(:)%seedC = dummy - out_daily_cohorts(:)%leafC = dummy - out_daily_cohorts(:)%rootC = dummy - out_daily_cohorts(:)%SW_C = dummy - out_daily_cohorts(:)%HW_C = dummy - out_daily_cohorts(:)%NSN = dummy - out_daily_cohorts(:)%seedN = dummy - out_daily_cohorts(:)%leafN = dummy - out_daily_cohorts(:)%rootN = dummy - out_daily_cohorts(:)%SW_N = dummy - out_daily_cohorts(:)%HW_N = dummy - endif + ! if (.not. myinterface%steering%spinup) then + ! out_daily_cohorts(:)%year = dummy + ! out_daily_cohorts(:)%doy = dummy + ! out_daily_cohorts(:)%hour = dummy + ! out_daily_cohorts(:)%cID = dummy + ! out_daily_cohorts(:)%PFT = dummy + ! out_daily_cohorts(:)%layer = dummy + ! out_daily_cohorts(:)%density = dummy + ! out_daily_cohorts(:)%f_layer = dummy + ! out_daily_cohorts(:)%LAI = dummy + ! out_daily_cohorts(:)%gpp = dummy + ! out_daily_cohorts(:)%resp = dummy + ! out_daily_cohorts(:)%transp = dummy + ! out_daily_cohorts(:)%NPPleaf = dummy + ! out_daily_cohorts(:)%NPProot = dummy + ! out_daily_cohorts(:)%NPPwood = dummy + ! out_daily_cohorts(:)%NSC = dummy + ! out_daily_cohorts(:)%seedC = dummy + ! out_daily_cohorts(:)%leafC = dummy + ! out_daily_cohorts(:)%rootC = dummy + ! out_daily_cohorts(:)%SW_C = dummy + ! out_daily_cohorts(:)%HW_C = dummy + ! out_daily_cohorts(:)%NSN = dummy + ! out_daily_cohorts(:)%seedN = dummy + ! out_daily_cohorts(:)%leafN = dummy + ! out_daily_cohorts(:)%rootN = dummy + ! out_daily_cohorts(:)%SW_N = dummy + ! out_daily_cohorts(:)%HW_N = dummy + ! endif ! cohorts output do i = 1, vegn%n_cohorts cc => vegn%cohorts(i) - if (.not. myinterface%steering%spinup) then - out_daily_cohorts(i)%year = iyears - out_daily_cohorts(i)%doy = idoy - out_daily_cohorts(i)%hour = i !1.0 - out_daily_cohorts(i)%cID = cc%ccID - out_daily_cohorts(i)%PFT = cc%species - out_daily_cohorts(i)%layer = cc%layer - out_daily_cohorts(i)%density = cc%nindivs * 10000 - out_daily_cohorts(i)%f_layer = cc%layerfrac - out_daily_cohorts(i)%LAI = cc%LAI - out_daily_cohorts(i)%gpp = cc%dailygpp - out_daily_cohorts(i)%resp = cc%dailyresp - out_daily_cohorts(i)%transp = cc%dailytrsp - out_daily_cohorts(i)%NPPleaf = cc%NPPleaf - out_daily_cohorts(i)%NPProot = cc%NPProot - out_daily_cohorts(i)%NPPwood = cc%NPPwood - out_daily_cohorts(i)%NSC = cc%plabl%c%c12 - out_daily_cohorts(i)%seedC = cc%pseed%c%c12 - out_daily_cohorts(i)%leafC = cc%pleaf%c%c12 - out_daily_cohorts(i)%rootC = cc%proot%c%c12 - out_daily_cohorts(i)%SW_C = cc%psapw%c%c12 - out_daily_cohorts(i)%HW_C = cc%pwood%c%c12 - out_daily_cohorts(i)%NSN = cc%plabl%n%n14 * 1000 - out_daily_cohorts(i)%seedN = cc%pseed%n%n14 * 1000 - out_daily_cohorts(i)%leafN = cc%pleaf%n%n14 * 1000 - out_daily_cohorts(i)%rootN = cc%proot%n%n14 * 1000 - out_daily_cohorts(i)%SW_N = cc%psapw%n%n14 * 1000 - out_daily_cohorts(i)%HW_N = cc%pwood%n%n14 * 1000 - endif + ! if (.not. myinterface%steering%spinup) then + ! out_daily_cohorts(i)%year = iyears + ! out_daily_cohorts(i)%doy = idoy + ! out_daily_cohorts(i)%hour = i !1.0 + ! out_daily_cohorts(i)%cID = cc%ccID + ! out_daily_cohorts(i)%PFT = cc%species + ! out_daily_cohorts(i)%layer = cc%layer + ! out_daily_cohorts(i)%density = cc%nindivs * 10000 + ! out_daily_cohorts(i)%f_layer = cc%layerfrac + ! out_daily_cohorts(i)%LAI = cc%LAI + ! out_daily_cohorts(i)%gpp = cc%dailygpp + ! out_daily_cohorts(i)%resp = cc%dailyresp + ! out_daily_cohorts(i)%transp = cc%dailytrsp + ! out_daily_cohorts(i)%NPPleaf = cc%NPPleaf + ! out_daily_cohorts(i)%NPProot = cc%NPProot + ! out_daily_cohorts(i)%NPPwood = cc%NPPwood + ! out_daily_cohorts(i)%NSC = cc%plabl%c%c12 + ! out_daily_cohorts(i)%seedC = cc%pseed%c%c12 + ! out_daily_cohorts(i)%leafC = cc%pleaf%c%c12 + ! out_daily_cohorts(i)%rootC = cc%proot%c%c12 + ! out_daily_cohorts(i)%SW_C = cc%psapw%c%c12 + ! out_daily_cohorts(i)%HW_C = cc%pwood%c%c12 + ! out_daily_cohorts(i)%NSN = cc%plabl%n%n14 * 1000 + ! out_daily_cohorts(i)%seedN = cc%pseed%n%n14 * 1000 + ! out_daily_cohorts(i)%leafN = cc%pleaf%n%n14 * 1000 + ! out_daily_cohorts(i)%rootN = cc%proot%n%n14 * 1000 + ! out_daily_cohorts(i)%SW_N = cc%psapw%n%n14 * 1000 + ! out_daily_cohorts(i)%HW_N = cc%pwood%n%n14 * 1000 + ! endif ! running annual sum cc%annualGPP = cc%annualGPP + cc%dailyGPP diff --git a/src/sofun_r.f90 b/src/sofun_r.f90 index ac41f96c..e0d69eeb 100644 --- a/src/sofun_r.f90 +++ b/src/sofun_r.f90 @@ -279,33 +279,33 @@ subroutine biomee_f( & forcing, & ! output_hourly_tile, & output_daily_tile, & - output_daily_cohorts_year, & - output_daily_cohorts_doy, & - output_daily_cohorts_hour, & - output_daily_cohorts_cID, & - output_daily_cohorts_PFT, & - output_daily_cohorts_layer, & - output_daily_cohorts_density, & - output_daily_cohorts_f_layer, & - output_daily_cohorts_LAI, & - output_daily_cohorts_gpp, & - output_daily_cohorts_resp, & - output_daily_cohorts_transp, & - output_daily_cohorts_NPPleaf, & - output_daily_cohorts_NPProot, & - output_daily_cohorts_NPPwood, & - output_daily_cohorts_NSC, & - output_daily_cohorts_seedC, & - output_daily_cohorts_leafC, & - output_daily_cohorts_rootC, & - output_daily_cohorts_SW_C, & - output_daily_cohorts_HW_C, & - output_daily_cohorts_NSN, & - output_daily_cohorts_seedN, & - output_daily_cohorts_leafN, & - output_daily_cohorts_rootN, & - output_daily_cohorts_SW_N, & - output_daily_cohorts_HW_N, & + ! output_daily_cohorts_year, & + ! output_daily_cohorts_doy, & + ! output_daily_cohorts_hour, & + ! output_daily_cohorts_cID, & + ! output_daily_cohorts_PFT, & + ! output_daily_cohorts_layer, & + ! output_daily_cohorts_density, & + ! output_daily_cohorts_f_layer, & + ! output_daily_cohorts_LAI, & + ! output_daily_cohorts_gpp, & + ! output_daily_cohorts_resp, & + ! output_daily_cohorts_transp, & + ! output_daily_cohorts_NPPleaf, & + ! output_daily_cohorts_NPProot, & + ! output_daily_cohorts_NPPwood, & + ! output_daily_cohorts_NSC, & + ! output_daily_cohorts_seedC, & + ! output_daily_cohorts_leafC, & + ! output_daily_cohorts_rootC, & + ! output_daily_cohorts_SW_C, & + ! output_daily_cohorts_HW_C, & + ! output_daily_cohorts_NSN, & + ! output_daily_cohorts_seedN, & + ! output_daily_cohorts_leafN, & + ! output_daily_cohorts_rootN, & + ! output_daily_cohorts_SW_N, & + ! output_daily_cohorts_HW_N, & output_annual_tile, & output_annual_cohorts_year, & output_annual_cohorts_cID, & @@ -430,33 +430,33 @@ subroutine biomee_f( & ! real(kind=c_double), dimension(nt,nvars_hourly_tile), intent(out) :: output_hourly_tile ! nvars_hourly_tile = 15 real(kind=c_double), dimension(nt_daily,nvars_daily_tile), intent(out) :: output_daily_tile ! nvars_daily_tile = 35 - real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_year - real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_doy - real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_hour - real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_cID - real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_PFT - real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_layer - real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_density - real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_f_layer - real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_LAI - real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_gpp - real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_resp - real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_transp - real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_NPPleaf - real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_NPProot - real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_NPPwood - real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_NSC - real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_seedC - real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_leafC - real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_rootC - real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_SW_C - real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_HW_C - real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_NSN - real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_seedN - real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_leafN - real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_rootN - real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_SW_N - real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_HW_N + ! real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_year + ! real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_doy + ! real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_hour + ! real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_cID + ! real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_PFT + ! real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_layer + ! real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_density + ! real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_f_layer + ! real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_LAI + ! real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_gpp + ! real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_resp + ! real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_transp + ! real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_NPPleaf + ! real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_NPProot + ! real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_NPPwood + ! real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_NSC + ! real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_seedC + ! real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_leafC + ! real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_rootC + ! real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_SW_C + ! real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_HW_C + ! real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_NSN + ! real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_seedN + ! real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_leafN + ! real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_rootN + ! real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_SW_N + ! real(kind=c_double), dimension(nt_daily,out_max_cohorts), intent(out) :: output_daily_cohorts_HW_N real(kind=c_double), dimension(nt_annual,nvars_annual_tile), intent(out) :: output_annual_tile ! nvars_annual_tile = 51 @@ -498,7 +498,7 @@ subroutine biomee_f( & ! local variables ! type(outtype_biosphere) :: out_biosphere ! holds all the output used for calculating the cost or maximum likelihood function type(outtype_daily_tile), dimension(ndayyear) :: out_biosphere_daily_tile - type(outtype_daily_cohorts), dimension(ndayyear,out_max_cohorts) :: out_biosphere_daily_cohorts + ! type(outtype_daily_cohorts), dimension(ndayyear,out_max_cohorts) :: out_biosphere_daily_cohorts type(outtype_annual_tile) :: out_biosphere_annual_tile type(outtype_annual_cohorts), dimension(out_max_cohorts) :: out_biosphere_annual_cohorts @@ -715,7 +715,7 @@ subroutine biomee_f( & !---------------------------------------------------------------- call biosphere_annual( & out_biosphere_daily_tile, & - out_biosphere_daily_cohorts, & + ! out_biosphere_daily_cohorts, & out_biosphere_annual_tile, & out_biosphere_annual_cohorts & ) @@ -747,33 +747,33 @@ subroutine biomee_f( & !---------------------------------------------------------------- ! Output out_daily_cohorts (without subroutine) !---------------------------------------------------------------- - output_daily_cohorts_year(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%year) - output_daily_cohorts_doy(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%doy) - output_daily_cohorts_hour(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%hour) - output_daily_cohorts_cID(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%cID) - output_daily_cohorts_PFT(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%PFT) - output_daily_cohorts_layer(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%layer) - output_daily_cohorts_density(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%density) - output_daily_cohorts_f_layer(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%f_layer) - output_daily_cohorts_LAI(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%LAI) - output_daily_cohorts_gpp(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%gpp) - output_daily_cohorts_resp(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%resp) - output_daily_cohorts_transp(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%transp) - output_daily_cohorts_NPPleaf(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%NPPleaf) - output_daily_cohorts_NPProot(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%NPProot) - output_daily_cohorts_NPPwood(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%NPPwood) - output_daily_cohorts_NSC(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%NSC) - output_daily_cohorts_seedC(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%seedC) - output_daily_cohorts_leafC(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%leafC) - output_daily_cohorts_rootC(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%rootC) - output_daily_cohorts_SW_C(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%SW_C) - output_daily_cohorts_HW_C(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%HW_C) - output_daily_cohorts_NSN(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%NSN) - output_daily_cohorts_seedN(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%seedN) - output_daily_cohorts_leafN(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%leafN) - output_daily_cohorts_rootN(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%rootN) - output_daily_cohorts_SW_N(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%SW_N) - output_daily_cohorts_HW_N(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%HW_N) + ! output_daily_cohorts_year(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%year) + ! output_daily_cohorts_doy(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%doy) + ! output_daily_cohorts_hour(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%hour) + ! output_daily_cohorts_cID(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%cID) + ! output_daily_cohorts_PFT(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%PFT) + ! output_daily_cohorts_layer(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%layer) + ! output_daily_cohorts_density(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%density) + ! output_daily_cohorts_f_layer(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%f_layer) + ! output_daily_cohorts_LAI(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%LAI) + ! output_daily_cohorts_gpp(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%gpp) + ! output_daily_cohorts_resp(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%resp) + ! output_daily_cohorts_transp(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%transp) + ! output_daily_cohorts_NPPleaf(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%NPPleaf) + ! output_daily_cohorts_NPProot(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%NPProot) + ! output_daily_cohorts_NPPwood(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%NPPwood) + ! output_daily_cohorts_NSC(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%NSC) + ! output_daily_cohorts_seedC(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%seedC) + ! output_daily_cohorts_leafC(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%leafC) + ! output_daily_cohorts_rootC(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%rootC) + ! output_daily_cohorts_SW_C(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%SW_C) + ! output_daily_cohorts_HW_C(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%HW_C) + ! output_daily_cohorts_NSN(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%NSN) + ! output_daily_cohorts_seedN(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%seedN) + ! output_daily_cohorts_leafN(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%leafN) + ! output_daily_cohorts_rootN(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%rootN) + ! output_daily_cohorts_SW_N(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%SW_N) + ! output_daily_cohorts_HW_N(idx_daily_start:idx_daily_end,:) = dble(out_biosphere_daily_cohorts(:,:)%HW_N) end if diff --git a/src/wrappersc.c b/src/wrappersc.c index 4d9b5fbb..cc3c7369 100644 --- a/src/wrappersc.c +++ b/src/wrappersc.c @@ -161,33 +161,33 @@ void F77_NAME(biomee_f)( double *forcing, // double *output_hourly_tile, double *output_daily_tile, - double *output_daily_cohorts_year, - double *output_daily_cohorts_doy, - double *output_daily_cohorts_hour, - double *output_daily_cohorts_cID, - double *output_daily_cohorts_PFT, - double *output_daily_cohorts_layer, - double *output_daily_cohorts_density, - double *output_daily_cohorts_f_layer, - double *output_daily_cohorts_LAI, - double *output_daily_cohorts_gpp, - double *output_daily_cohorts_resp, - double *output_daily_cohorts_transp, - double *output_daily_cohorts_NPPleaf, - double *output_daily_cohorts_NPProot, - double *output_daily_cohorts_NPPwood, - double *output_daily_cohorts_NSC, - double *output_daily_cohorts_seedC, - double *output_daily_cohorts_leafC, - double *output_daily_cohorts_rootC, - double *output_daily_cohorts_SW_C, - double *output_daily_cohorts_HW_C, - double *output_daily_cohorts_NSN, - double *output_daily_cohorts_seedN, - double *output_daily_cohorts_leafN, - double *output_daily_cohorts_rootN, - double *output_daily_cohorts_SW_N, - double *output_daily_cohorts_HW_N, + // double *output_daily_cohorts_year, + // double *output_daily_cohorts_doy, + // double *output_daily_cohorts_hour, + // double *output_daily_cohorts_cID, + // double *output_daily_cohorts_PFT, + // double *output_daily_cohorts_layer, + // double *output_daily_cohorts_density, + // double *output_daily_cohorts_f_layer, + // double *output_daily_cohorts_LAI, + // double *output_daily_cohorts_gpp, + // double *output_daily_cohorts_resp, + // double *output_daily_cohorts_transp, + // double *output_daily_cohorts_NPPleaf, + // double *output_daily_cohorts_NPProot, + // double *output_daily_cohorts_NPPwood, + // double *output_daily_cohorts_NSC, + // double *output_daily_cohorts_seedC, + // double *output_daily_cohorts_leafC, + // double *output_daily_cohorts_rootC, + // double *output_daily_cohorts_SW_C, + // double *output_daily_cohorts_HW_C, + // double *output_daily_cohorts_NSN, + // double *output_daily_cohorts_seedN, + // double *output_daily_cohorts_leafN, + // double *output_daily_cohorts_rootN, + // double *output_daily_cohorts_SW_N, + // double *output_daily_cohorts_HW_N, double *output_annual_tile, double *output_annual_cohorts_year, double *output_annual_cohorts_cID, @@ -286,33 +286,33 @@ extern SEXP biomee_f_C( // // Specify output // SEXP output_hourly_tile = PROTECT( allocMatrix(REALSXP, nt, 15) ); // 2nd agument to allocMatrix is number of rows, 3rd is number of columns. xxx todo SEXP output_daily_tile = PROTECT( allocMatrix(REALSXP, nt_daily, 35) ); // 2nd agument to allocMatrix is number of rows, 3rd is number of columns. xxx todo - SEXP output_daily_cohorts_year = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); - SEXP output_daily_cohorts_doy = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); - SEXP output_daily_cohorts_hour = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); - SEXP output_daily_cohorts_cID = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); - SEXP output_daily_cohorts_PFT = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); - SEXP output_daily_cohorts_layer = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); - SEXP output_daily_cohorts_density = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); - SEXP output_daily_cohorts_f_layer = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); - SEXP output_daily_cohorts_LAI = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); - SEXP output_daily_cohorts_gpp = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); - SEXP output_daily_cohorts_resp = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); - SEXP output_daily_cohorts_transp = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); - SEXP output_daily_cohorts_NPPleaf = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); - SEXP output_daily_cohorts_NPProot = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); - SEXP output_daily_cohorts_NPPwood = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); - SEXP output_daily_cohorts_NSC = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); - SEXP output_daily_cohorts_seedC = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); - SEXP output_daily_cohorts_leafC = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); - SEXP output_daily_cohorts_rootC = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); - SEXP output_daily_cohorts_SW_C = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); - SEXP output_daily_cohorts_HW_C = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); - SEXP output_daily_cohorts_NSN = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); - SEXP output_daily_cohorts_seedN = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); - SEXP output_daily_cohorts_leafN = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); - SEXP output_daily_cohorts_rootN = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); - SEXP output_daily_cohorts_SW_N = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); - SEXP output_daily_cohorts_HW_N = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); + // SEXP output_daily_cohorts_year = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); + // SEXP output_daily_cohorts_doy = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); + // SEXP output_daily_cohorts_hour = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); + // SEXP output_daily_cohorts_cID = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); + // SEXP output_daily_cohorts_PFT = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); + // SEXP output_daily_cohorts_layer = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); + // SEXP output_daily_cohorts_density = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); + // SEXP output_daily_cohorts_f_layer = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); + // SEXP output_daily_cohorts_LAI = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); + // SEXP output_daily_cohorts_gpp = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); + // SEXP output_daily_cohorts_resp = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); + // SEXP output_daily_cohorts_transp = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); + // SEXP output_daily_cohorts_NPPleaf = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); + // SEXP output_daily_cohorts_NPProot = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); + // SEXP output_daily_cohorts_NPPwood = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); + // SEXP output_daily_cohorts_NSC = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); + // SEXP output_daily_cohorts_seedC = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); + // SEXP output_daily_cohorts_leafC = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); + // SEXP output_daily_cohorts_rootC = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); + // SEXP output_daily_cohorts_SW_C = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); + // SEXP output_daily_cohorts_HW_C = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); + // SEXP output_daily_cohorts_NSN = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); + // SEXP output_daily_cohorts_seedN = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); + // SEXP output_daily_cohorts_leafN = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); + // SEXP output_daily_cohorts_rootN = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); + // SEXP output_daily_cohorts_SW_N = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); + // SEXP output_daily_cohorts_HW_N = PROTECT( allocMatrix(REALSXP, nt_daily, 50) ); SEXP output_annual_tile = PROTECT( allocMatrix(REALSXP, nt_annual, 59) ); // 2nd agument to allocMatrix is number of rows, 3rd is number of columns. xxx todo SEXP output_annual_cohorts_year = PROTECT( allocMatrix(REALSXP, nt_annual_cohorts, 50) ); SEXP output_annual_cohorts_cID = PROTECT( allocMatrix(REALSXP, nt_annual_cohorts, 50) ); @@ -401,33 +401,33 @@ extern SEXP biomee_f_C( REAL(forcing), // REAL(output_hourly_tile), REAL(output_daily_tile), - REAL(output_daily_cohorts_year), - REAL(output_daily_cohorts_doy), - REAL(output_daily_cohorts_hour), - REAL(output_daily_cohorts_cID), - REAL(output_daily_cohorts_PFT), - REAL(output_daily_cohorts_layer), - REAL(output_daily_cohorts_density), - REAL(output_daily_cohorts_f_layer), - REAL(output_daily_cohorts_LAI), - REAL(output_daily_cohorts_gpp), - REAL(output_daily_cohorts_resp), - REAL(output_daily_cohorts_transp), - REAL(output_daily_cohorts_NPPleaf), - REAL(output_daily_cohorts_NPProot), - REAL(output_daily_cohorts_NPPwood), - REAL(output_daily_cohorts_NSC), - REAL(output_daily_cohorts_seedC), - REAL(output_daily_cohorts_leafC), - REAL(output_daily_cohorts_rootC), - REAL(output_daily_cohorts_SW_C), - REAL(output_daily_cohorts_HW_C), - REAL(output_daily_cohorts_NSN), - REAL(output_daily_cohorts_seedN), - REAL(output_daily_cohorts_leafN), - REAL(output_daily_cohorts_rootN), - REAL(output_daily_cohorts_SW_N), - REAL(output_daily_cohorts_HW_N), + // REAL(output_daily_cohorts_year), + // REAL(output_daily_cohorts_doy), + // REAL(output_daily_cohorts_hour), + // REAL(output_daily_cohorts_cID), + // REAL(output_daily_cohorts_PFT), + // REAL(output_daily_cohorts_layer), + // REAL(output_daily_cohorts_density), + // REAL(output_daily_cohorts_f_layer), + // REAL(output_daily_cohorts_LAI), + // REAL(output_daily_cohorts_gpp), + // REAL(output_daily_cohorts_resp), + // REAL(output_daily_cohorts_transp), + // REAL(output_daily_cohorts_NPPleaf), + // REAL(output_daily_cohorts_NPProot), + // REAL(output_daily_cohorts_NPPwood), + // REAL(output_daily_cohorts_NSC), + // REAL(output_daily_cohorts_seedC), + // REAL(output_daily_cohorts_leafC), + // REAL(output_daily_cohorts_rootC), + // REAL(output_daily_cohorts_SW_C), + // REAL(output_daily_cohorts_HW_C), + // REAL(output_daily_cohorts_NSN), + // REAL(output_daily_cohorts_seedN), + // REAL(output_daily_cohorts_leafN), + // REAL(output_daily_cohorts_rootN), + // REAL(output_daily_cohorts_SW_N), + // REAL(output_daily_cohorts_HW_N), REAL(output_annual_tile), REAL(output_annual_cohorts_year), REAL(output_annual_cohorts_cID), @@ -466,74 +466,74 @@ extern SEXP biomee_f_C( ); // // Output as list - SEXP out_list = PROTECT( allocVector(VECSXP, 63) ); // maybe try STRSXP instead of VECSXP + SEXP out_list = PROTECT( allocVector(VECSXP, 36) ); // maybe try STRSXP instead of VECSXP // SET_VECTOR_ELT(out_list, 0, output_hourly_tile); SET_VECTOR_ELT(out_list, 0, output_daily_tile); - SET_VECTOR_ELT(out_list, 1, output_daily_cohorts_year ); - SET_VECTOR_ELT(out_list, 2, output_daily_cohorts_doy ); - SET_VECTOR_ELT(out_list, 3, output_daily_cohorts_hour ); - SET_VECTOR_ELT(out_list, 4, output_daily_cohorts_cID ); - SET_VECTOR_ELT(out_list, 5, output_daily_cohorts_PFT ); - SET_VECTOR_ELT(out_list, 6, output_daily_cohorts_layer ); - SET_VECTOR_ELT(out_list, 7, output_daily_cohorts_density ); - SET_VECTOR_ELT(out_list, 8, output_daily_cohorts_f_layer ); - SET_VECTOR_ELT(out_list, 9, output_daily_cohorts_LAI ); - SET_VECTOR_ELT(out_list, 10, output_daily_cohorts_gpp ); - SET_VECTOR_ELT(out_list, 11, output_daily_cohorts_resp ); - SET_VECTOR_ELT(out_list, 12, output_daily_cohorts_transp ); - SET_VECTOR_ELT(out_list, 13, output_daily_cohorts_NPPleaf ); - SET_VECTOR_ELT(out_list, 14, output_daily_cohorts_NPProot ); - SET_VECTOR_ELT(out_list, 15, output_daily_cohorts_NPPwood ); - SET_VECTOR_ELT(out_list, 16, output_daily_cohorts_NSC ); - SET_VECTOR_ELT(out_list, 17, output_daily_cohorts_seedC ); - SET_VECTOR_ELT(out_list, 18, output_daily_cohorts_leafC ); - SET_VECTOR_ELT(out_list, 19, output_daily_cohorts_rootC ); - SET_VECTOR_ELT(out_list, 20, output_daily_cohorts_SW_C ); - SET_VECTOR_ELT(out_list, 21, output_daily_cohorts_HW_C ); - SET_VECTOR_ELT(out_list, 22, output_daily_cohorts_NSN ); - SET_VECTOR_ELT(out_list, 23, output_daily_cohorts_seedN ); - SET_VECTOR_ELT(out_list, 24, output_daily_cohorts_leafN ); - SET_VECTOR_ELT(out_list, 25, output_daily_cohorts_rootN ); - SET_VECTOR_ELT(out_list, 26, output_daily_cohorts_SW_N ); - SET_VECTOR_ELT(out_list, 27, output_daily_cohorts_HW_N ); - SET_VECTOR_ELT(out_list, 28, output_annual_tile); - SET_VECTOR_ELT(out_list, 29, output_annual_cohorts_year); - SET_VECTOR_ELT(out_list, 30, output_annual_cohorts_cID); - SET_VECTOR_ELT(out_list, 31, output_annual_cohorts_PFT); - SET_VECTOR_ELT(out_list, 32, output_annual_cohorts_layer); - SET_VECTOR_ELT(out_list, 33, output_annual_cohorts_density); - SET_VECTOR_ELT(out_list, 34, output_annual_cohorts_flayer); - SET_VECTOR_ELT(out_list, 35, output_annual_cohorts_DBH); - SET_VECTOR_ELT(out_list, 36, output_annual_cohorts_dDBH); - SET_VECTOR_ELT(out_list, 37, output_annual_cohorts_height); - SET_VECTOR_ELT(out_list, 38, output_annual_cohorts_age); - SET_VECTOR_ELT(out_list, 39, output_annual_cohorts_BA); - SET_VECTOR_ELT(out_list, 40, output_annual_cohorts_dBA); - SET_VECTOR_ELT(out_list, 41, output_annual_cohorts_Acrown); - SET_VECTOR_ELT(out_list, 42, output_annual_cohorts_Aleaf); - SET_VECTOR_ELT(out_list, 43, output_annual_cohorts_nsc); - SET_VECTOR_ELT(out_list, 44, output_annual_cohorts_nsn); - SET_VECTOR_ELT(out_list, 45, output_annual_cohorts_seedC); - SET_VECTOR_ELT(out_list, 46, output_annual_cohorts_leafC); - SET_VECTOR_ELT(out_list, 47, output_annual_cohorts_rootC); - SET_VECTOR_ELT(out_list, 48, output_annual_cohorts_sapwC); - SET_VECTOR_ELT(out_list, 49, output_annual_cohorts_woodC); - SET_VECTOR_ELT(out_list, 50, output_annual_cohorts_treeG); - SET_VECTOR_ELT(out_list, 51, output_annual_cohorts_fseed); - SET_VECTOR_ELT(out_list, 52, output_annual_cohorts_fleaf); - SET_VECTOR_ELT(out_list, 53, output_annual_cohorts_froot); - SET_VECTOR_ELT(out_list, 54, output_annual_cohorts_fwood); - SET_VECTOR_ELT(out_list, 55, output_annual_cohorts_GPP); - SET_VECTOR_ELT(out_list, 56, output_annual_cohorts_NPP); - SET_VECTOR_ELT(out_list, 57, output_annual_cohorts_Rauto); - SET_VECTOR_ELT(out_list, 58, output_annual_cohorts_Nupt); - SET_VECTOR_ELT(out_list, 59, output_annual_cohorts_Nfix); - SET_VECTOR_ELT(out_list, 60, output_annual_cohorts_n_deadtrees); - SET_VECTOR_ELT(out_list, 61, output_annual_cohorts_c_deadtrees); - SET_VECTOR_ELT(out_list, 62, output_annual_cohorts_deathrate); + // SET_VECTOR_ELT(out_list, 1, output_daily_cohorts_year ); + // SET_VECTOR_ELT(out_list, 2, output_daily_cohorts_doy ); + // SET_VECTOR_ELT(out_list, 3, output_daily_cohorts_hour ); + // SET_VECTOR_ELT(out_list, 4, output_daily_cohorts_cID ); + // SET_VECTOR_ELT(out_list, 5, output_daily_cohorts_PFT ); + // SET_VECTOR_ELT(out_list, 6, output_daily_cohorts_layer ); + // SET_VECTOR_ELT(out_list, 7, output_daily_cohorts_density ); + // SET_VECTOR_ELT(out_list, 8, output_daily_cohorts_f_layer ); + // SET_VECTOR_ELT(out_list, 9, output_daily_cohorts_LAI ); + // SET_VECTOR_ELT(out_list, 10, output_daily_cohorts_gpp ); + // SET_VECTOR_ELT(out_list, 11, output_daily_cohorts_resp ); + // SET_VECTOR_ELT(out_list, 12, output_daily_cohorts_transp ); + // SET_VECTOR_ELT(out_list, 13, output_daily_cohorts_NPPleaf ); + // SET_VECTOR_ELT(out_list, 14, output_daily_cohorts_NPProot ); + // SET_VECTOR_ELT(out_list, 15, output_daily_cohorts_NPPwood ); + // SET_VECTOR_ELT(out_list, 16, output_daily_cohorts_NSC ); + // SET_VECTOR_ELT(out_list, 17, output_daily_cohorts_seedC ); + // SET_VECTOR_ELT(out_list, 18, output_daily_cohorts_leafC ); + // SET_VECTOR_ELT(out_list, 19, output_daily_cohorts_rootC ); + // SET_VECTOR_ELT(out_list, 20, output_daily_cohorts_SW_C ); + // SET_VECTOR_ELT(out_list, 21, output_daily_cohorts_HW_C ); + // SET_VECTOR_ELT(out_list, 22, output_daily_cohorts_NSN ); + // SET_VECTOR_ELT(out_list, 23, output_daily_cohorts_seedN ); + // SET_VECTOR_ELT(out_list, 24, output_daily_cohorts_leafN ); + // SET_VECTOR_ELT(out_list, 25, output_daily_cohorts_rootN ); + // SET_VECTOR_ELT(out_list, 26, output_daily_cohorts_SW_N ); + // SET_VECTOR_ELT(out_list, 27, output_daily_cohorts_HW_N ); + SET_VECTOR_ELT(out_list, 1, output_annual_tile); + SET_VECTOR_ELT(out_list, 2, output_annual_cohorts_year); + SET_VECTOR_ELT(out_list, 3, output_annual_cohorts_cID); + SET_VECTOR_ELT(out_list, 4, output_annual_cohorts_PFT); + SET_VECTOR_ELT(out_list, 5, output_annual_cohorts_layer); + SET_VECTOR_ELT(out_list, 6, output_annual_cohorts_density); + SET_VECTOR_ELT(out_list, 7, output_annual_cohorts_flayer); + SET_VECTOR_ELT(out_list, 8, output_annual_cohorts_DBH); + SET_VECTOR_ELT(out_list, 9, output_annual_cohorts_dDBH); + SET_VECTOR_ELT(out_list, 10, output_annual_cohorts_height); + SET_VECTOR_ELT(out_list, 11, output_annual_cohorts_age); + SET_VECTOR_ELT(out_list, 12, output_annual_cohorts_BA); + SET_VECTOR_ELT(out_list, 13, output_annual_cohorts_dBA); + SET_VECTOR_ELT(out_list, 14, output_annual_cohorts_Acrown); + SET_VECTOR_ELT(out_list, 15, output_annual_cohorts_Aleaf); + SET_VECTOR_ELT(out_list, 16, output_annual_cohorts_nsc); + SET_VECTOR_ELT(out_list, 17, output_annual_cohorts_nsn); + SET_VECTOR_ELT(out_list, 18, output_annual_cohorts_seedC); + SET_VECTOR_ELT(out_list, 19, output_annual_cohorts_leafC); + SET_VECTOR_ELT(out_list, 20, output_annual_cohorts_rootC); + SET_VECTOR_ELT(out_list, 21, output_annual_cohorts_sapwC); + SET_VECTOR_ELT(out_list, 22, output_annual_cohorts_woodC); + SET_VECTOR_ELT(out_list, 23, output_annual_cohorts_treeG); + SET_VECTOR_ELT(out_list, 24, output_annual_cohorts_fseed); + SET_VECTOR_ELT(out_list, 25, output_annual_cohorts_fleaf); + SET_VECTOR_ELT(out_list, 26, output_annual_cohorts_froot); + SET_VECTOR_ELT(out_list, 27, output_annual_cohorts_fwood); + SET_VECTOR_ELT(out_list, 28, output_annual_cohorts_GPP); + SET_VECTOR_ELT(out_list, 29, output_annual_cohorts_NPP); + SET_VECTOR_ELT(out_list, 30, output_annual_cohorts_Rauto); + SET_VECTOR_ELT(out_list, 31, output_annual_cohorts_Nupt); + SET_VECTOR_ELT(out_list, 32, output_annual_cohorts_Nfix); + SET_VECTOR_ELT(out_list, 33, output_annual_cohorts_n_deadtrees); + SET_VECTOR_ELT(out_list, 34, output_annual_cohorts_c_deadtrees); + SET_VECTOR_ELT(out_list, 35, output_annual_cohorts_deathrate); - UNPROTECT(64); + UNPROTECT(37); return out_list; } @@ -543,7 +543,7 @@ extern SEXP biomee_f_C( ///////////////////////////////////////////////////////////// static const R_CallMethodDef CallEntries[] = { {"pmodel_f_C", (DL_FUNC) &pmodel_f_C, 23}, // Specify number of arguments to C wrapper as the last number here - {"biomee_f_C", (DL_FUNC) &biomee_f_C, 48}, // Number of the SEXP variables (not the output) + {"biomee_f_C", (DL_FUNC) &biomee_f_C, 48}, // Number of arguments of the C wrapper function for biomee (the SEXP variables, not the output) {NULL, NULL, 0} };