Skip to content

Commit

Permalink
Merge pull request #209 from stineb/master
Browse files Browse the repository at this point in the history
corrected issues after PR from DBEN
  • Loading branch information
stineb authored Apr 30, 2024
2 parents 4949652 + 078d94c commit d1c5cff
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 120 deletions.
46 changes: 20 additions & 26 deletions src/biosphere_biomee.mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -196,39 +196,33 @@ subroutine biosphere_annual(out_biosphere)
! update the years of model run
iyears = iyears + 1

!---------------------------------------------
! Reset vegetation to initial conditions
!---------------------------------------------
! !---------------------------------------------
! ! Reset vegetation to initial conditions
! !---------------------------------------------

!if (iyears > myinterface%params_siml%spinupyears+31 .and. rand(0)<0.40) &
! call reset_vegn_initial(vegn) ! 0.01, 0.02, 0.04, 0.08, 0.20, 0.40
! !if (iyears > myinterface%params_siml%spinupyears+31 .and. rand(0)<0.40) &
! ! call reset_vegn_initial(vegn) ! 0.01, 0.02, 0.04, 0.08, 0.20, 0.40

!if (iyears == 700 .or. iyears == 800) &
! call reset_vegn_initial(vegn)

if (myinterface%steering%finalize) then
!----------------------------------------------------------------
! Finazlize run: deallocating memory
!----------------------------------------------------------------
deallocate( vegn )
! !if (iyears == 700 .or. iyears == 800) &
! ! call reset_vegn_initial(vegn)

if(myinterface%params_siml%do_reset_veg) then
! if(myinterface%params_siml%do_reset_veg) then

if (iyears==myinterface%params_siml%spinupyears + 31) then
call reset_vegn_initial(vegn)
endif
! if (iyears==myinterface%params_siml%spinupyears + 31) then
! call reset_vegn_initial(vegn)
! endif

! nfrequency = 50 ! 100,75,50,25,15,10
! ! nfrequency = 50 ! 100,75,50,25,15,10

if(myinterface%params_siml%dist_frequency > 0) then
do i = myinterface%params_siml%spinupyears + 31 + myinterface%params_siml%dist_frequency, &
myinterface%params_siml%spinupyears + myinterface%params_siml%nyeartrend, &
myinterface%params_siml%dist_frequency
if (iyears == i) call reset_vegn_initial(vegn)
enddo
endif
! if(myinterface%params_siml%dist_frequency > 0) then
! do i = myinterface%params_siml%spinupyears + 31 + myinterface%params_siml%dist_frequency, &
! myinterface%params_siml%spinupyears + myinterface%params_siml%nyeartrend, &
! myinterface%params_siml%dist_frequency
! if (iyears == i) call reset_vegn_initial(vegn)
! enddo
! endif

endif
! endif

!----------------------------------------------------------------
! Finalize run: deallocating memory
Expand Down
24 changes: 9 additions & 15 deletions src/sofun_r.f90
Original file line number Diff line number Diff line change
Expand Up @@ -768,17 +768,11 @@ 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)
if (.not. myinterface%steering%spinup) then ! To get outputs only after spinupyears

!if (.not. myinterface%steering%spinup) then ! To get outputs only after spinupyears
!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
idx = yr - myinterface%params_siml%spinupyears

output_annual_cohorts_year(idx, :) = dble(out_biosphere%annual_cohorts(:)%year) !xxx commented out for calibration!
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)
Expand All @@ -794,11 +788,11 @@ subroutine biomee_f( &
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_nsn(idx, :) = dble(out_biosphere%annual_cohorts(:)%seedC)
output_annual_cohorts_nsn(idx, :) = dble(out_biosphere%annual_cohorts(:)%leafC)
output_annual_cohorts_nsn(idx, :) = dble(out_biosphere%annual_cohorts(:)%rootC)
output_annual_cohorts_nsn(idx, :) = dble(out_biosphere%annual_cohorts(:)%sapwC)
output_annual_cohorts_nsn(idx, :) = dble(out_biosphere%annual_cohorts(:)%woodC)
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)
Expand All @@ -811,7 +805,7 @@ subroutine biomee_f( &
output_annual_cohorts_Nfix(idx, :) = dble(out_biosphere%annual_cohorts(:)%Nfix)
output_annual_cohorts_deathrate(idx, :) = dble(out_biosphere%annual_cohorts(:)%deathrate)

!end if
end if

end do yearloop

Expand Down
8 changes: 4 additions & 4 deletions src/vegetation_biomee.mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1892,10 +1892,10 @@ subroutine kill_old_grass(vegn)
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
! 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. k<vegn%n_cohorts)then
Expand Down
134 changes: 66 additions & 68 deletions src/wrappersc.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,76 +466,74 @@ extern SEXP biomee_f_C(
);

// // Output as list
SEXP out_list = PROTECT( allocVector(VECSXP, 64) ); // maybe try STRSXP instead of VECSXP
SEXP out_list = PROTECT( allocVector(VECSXP, 63) ); // maybe try STRSXP instead of VECSXP

SET_VECTOR_ELT(out_list, 0, output_hourly_tile);
SET_VECTOR_ELT(out_list, 1, output_daily_tile);
SET_VECTOR_ELT(out_list, 2, output_daily_cohorts_year );
SET_VECTOR_ELT(out_list, 3, output_daily_cohorts_doy );
SET_VECTOR_ELT(out_list, 4, output_daily_cohorts_hour );
SET_VECTOR_ELT(out_list, 5, output_daily_cohorts_cID );
SET_VECTOR_ELT(out_list, 6, output_daily_cohorts_PFT );
SET_VECTOR_ELT(out_list, 7, output_daily_cohorts_layer );
SET_VECTOR_ELT(out_list, 8, output_daily_cohorts_density );
SET_VECTOR_ELT(out_list, 9, output_daily_cohorts_f_layer );
SET_VECTOR_ELT(out_list, 10, output_daily_cohorts_LAI );
SET_VECTOR_ELT(out_list, 11, output_daily_cohorts_gpp );
SET_VECTOR_ELT(out_list, 12, output_daily_cohorts_resp );
SET_VECTOR_ELT(out_list, 13, output_daily_cohorts_transp );
SET_VECTOR_ELT(out_list, 14, output_daily_cohorts_NPPleaf );
SET_VECTOR_ELT(out_list, 15, output_daily_cohorts_NPProot );
SET_VECTOR_ELT(out_list, 16, output_daily_cohorts_NPPwood );
SET_VECTOR_ELT(out_list, 17, output_daily_cohorts_NSC );
SET_VECTOR_ELT(out_list, 18, output_daily_cohorts_seedC );
SET_VECTOR_ELT(out_list, 19, output_daily_cohorts_leafC );
SET_VECTOR_ELT(out_list, 20, output_daily_cohorts_rootC );
SET_VECTOR_ELT(out_list, 21, output_daily_cohorts_SW_C );
SET_VECTOR_ELT(out_list, 22, output_daily_cohorts_HW_C );
SET_VECTOR_ELT(out_list, 23, output_daily_cohorts_NSN );
SET_VECTOR_ELT(out_list, 24, output_daily_cohorts_seedN );
SET_VECTOR_ELT(out_list, 25, output_daily_cohorts_leafN );
SET_VECTOR_ELT(out_list, 26, output_daily_cohorts_rootN );
SET_VECTOR_ELT(out_list, 27, output_daily_cohorts_SW_N );
SET_VECTOR_ELT(out_list, 28, output_daily_cohorts_HW_N );

SET_VECTOR_ELT(out_list, 29, output_annual_tile);

SET_VECTOR_ELT(out_list, 30, output_annual_cohorts_year);
SET_VECTOR_ELT(out_list, 31, output_annual_cohorts_cID);
SET_VECTOR_ELT(out_list, 32, output_annual_cohorts_PFT);
SET_VECTOR_ELT(out_list, 33, output_annual_cohorts_layer);
SET_VECTOR_ELT(out_list, 34, output_annual_cohorts_density);
SET_VECTOR_ELT(out_list, 35, output_annual_cohorts_flayer);
SET_VECTOR_ELT(out_list, 36, output_annual_cohorts_DBH);
SET_VECTOR_ELT(out_list, 37, output_annual_cohorts_dDBH);
SET_VECTOR_ELT(out_list, 38, output_annual_cohorts_height);
SET_VECTOR_ELT(out_list, 39, output_annual_cohorts_age);
SET_VECTOR_ELT(out_list, 40, output_annual_cohorts_BA);
SET_VECTOR_ELT(out_list, 41, output_annual_cohorts_dBA);
SET_VECTOR_ELT(out_list, 42, output_annual_cohorts_Acrown);
SET_VECTOR_ELT(out_list, 43, output_annual_cohorts_Aleaf);
SET_VECTOR_ELT(out_list, 44, output_annual_cohorts_nsc);
SET_VECTOR_ELT(out_list, 45, output_annual_cohorts_nsn);
SET_VECTOR_ELT(out_list, 46, output_annual_cohorts_seedC);
SET_VECTOR_ELT(out_list, 47, output_annual_cohorts_leafC);
SET_VECTOR_ELT(out_list, 48, output_annual_cohorts_rootC);
SET_VECTOR_ELT(out_list, 49, output_annual_cohorts_sapwC);
SET_VECTOR_ELT(out_list, 50, output_annual_cohorts_woodC);
SET_VECTOR_ELT(out_list, 51, output_annual_cohorts_treeG);
SET_VECTOR_ELT(out_list, 52, output_annual_cohorts_fseed);
SET_VECTOR_ELT(out_list, 53, output_annual_cohorts_fleaf);
SET_VECTOR_ELT(out_list, 54, output_annual_cohorts_froot);
SET_VECTOR_ELT(out_list, 55, output_annual_cohorts_fwood);
SET_VECTOR_ELT(out_list, 56, output_annual_cohorts_GPP);
SET_VECTOR_ELT(out_list, 57, output_annual_cohorts_NPP);
SET_VECTOR_ELT(out_list, 58, output_annual_cohorts_Rauto);
SET_VECTOR_ELT(out_list, 59, output_annual_cohorts_Nupt);
SET_VECTOR_ELT(out_list, 60, output_annual_cohorts_Nfix);
SET_VECTOR_ELT(out_list, 61, output_annual_cohorts_n_deadtrees);
SET_VECTOR_ELT(out_list, 62, output_annual_cohorts_c_deadtrees);
SET_VECTOR_ELT(out_list, 63, output_annual_cohorts_deathrate);
// 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);

UNPROTECT(65);
UNPROTECT(64);

return out_list;
}
Expand Down
10 changes: 3 additions & 7 deletions vignettes/biomee_use.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The `rsofun` package and framework includes two main models. The `pmodel` and `b

## Demo data

The package includes two demo datasets to run and validate pmodel output. These files can be directly loaded into your workspace by typing:
The package includes two demo datasets to run. These files can be directly loaded into your workspace by typing:

```{r eval = FALSE}
library(rsofun)
Expand Down Expand Up @@ -218,9 +218,7 @@ ggplot() +
aes(x = year, y = GPP),
color = "grey50") +
theme_classic() +
labs(x = "Year", y = "GPP") +
geom_hline(yintercept = biomee_validation_2$data[[1]]$targets_obs[1],
lty=2) # plot observation
labs(x = "Year", y = "GPP")
ggplot() +
geom_line(data = biomee_p_model_output,
Expand All @@ -229,7 +227,5 @@ ggplot() +
aes(x = year, y = plantC),
color = "grey50") +
theme_classic() +
labs(x = "Year", y = "plantC") +
geom_hline(yintercept = biomee_validation_2$data[[1]]$targets_obs[4],
lty = 2) # plot observation
labs(x = "Year", y = "plantC")
```

0 comments on commit d1c5cff

Please sign in to comment.