Skip to content

Commit

Permalink
Fix to the restart order issue
Browse files Browse the repository at this point in the history
  • Loading branch information
rgknox committed Jun 23, 2023
1 parent 8e34f39 commit 5211412
Showing 1 changed file with 65 additions and 65 deletions.
130 changes: 65 additions & 65 deletions main/FatesRestartInterfaceMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -2032,6 +2032,8 @@ subroutine set_restart_vectors(this,nc,nsites,sites)
io_idx_si_cacls= io_idx_co_1st
io_idx_si_cdsc = io_idx_co_1st
io_idx_si_cdpf = io_idx_co_1st
io_idx_si_scpf = io_idx_co_1st
io_idx_si_pft = io_idx_co_1st

! recruitment rate
do i_pft = 1,numpft
Expand All @@ -2046,6 +2048,32 @@ subroutine set_restart_vectors(this,nc,nsites,sites)
rio_area_pft_sift(io_idx_co_1st+i_pft-1) = sites(s)%area_pft(i_pft)
end do

do i_scls = 1, nlevsclass
do i_pft = 1, numpft
rio_fmortrate_cano_siscpf(io_idx_si_scpf) = sites(s)%fmort_rate_canopy(i_scls, i_pft)
rio_fmortrate_usto_siscpf(io_idx_si_scpf) = sites(s)%fmort_rate_ustory(i_scls, i_pft)
rio_imortrate_siscpf(io_idx_si_scpf) = sites(s)%imort_rate(i_scls, i_pft)
rio_fmortrate_crown_siscpf(io_idx_si_scpf) = sites(s)%fmort_rate_crown(i_scls, i_pft)
rio_fmortrate_cambi_siscpf(io_idx_si_scpf) = sites(s)%fmort_rate_cambial(i_scls, i_pft)
rio_termnindiv_cano_siscpf(io_idx_si_scpf) = sites(s)%term_nindivs_canopy(i_scls,i_pft)
rio_termnindiv_usto_siscpf(io_idx_si_scpf) = sites(s)%term_nindivs_ustory(i_scls,i_pft)
rio_growflx_fusion_siscpf(io_idx_si_scpf) = sites(s)%growthflux_fusion(i_scls, i_pft)
rio_abg_term_flux_siscpf(io_idx_si_scpf) = sites(s)%term_abg_flux(i_scls, i_pft)
rio_abg_imort_flux_siscpf(io_idx_si_scpf) = sites(s)%imort_abg_flux(i_scls, i_pft)
rio_abg_fmort_flux_siscpf(io_idx_si_scpf) = sites(s)%fmort_abg_flux(i_scls, i_pft)
io_idx_si_scpf = io_idx_si_scpf + 1
end do
end do

do i_pft = 1, numpft
rio_termcflux_cano_sipft(io_idx_si_pft) = sites(s)%term_carbonflux_canopy(i_pft)
rio_termcflux_usto_sipft(io_idx_si_pft) = sites(s)%term_carbonflux_ustory(i_pft)
rio_fmortcflux_cano_sipft(io_idx_si_pft) = sites(s)%fmort_carbonflux_canopy(i_pft)
rio_fmortcflux_usto_sipft(io_idx_si_pft) = sites(s)%fmort_carbonflux_ustory(i_pft)
rio_imortcflux_sipft(io_idx_si_pft) = sites(s)%imort_carbonflux(i_pft)
io_idx_si_pft = io_idx_si_pft + 1
end do


if(hlm_use_sp.eq.ifalse)then
do el = 1, num_elements
Expand Down Expand Up @@ -2073,6 +2101,8 @@ subroutine set_restart_vectors(this,nc,nsites,sites)
end do
end if



! canopy spread term
rio_spread_si(io_idx_si) = sites(s)%spread

Expand All @@ -2081,7 +2111,7 @@ subroutine set_restart_vectors(this,nc,nsites,sites)
! new column, reset num patches
patchespersite = 0

do while(associated(cpatch))
do_patch: do while(associated(cpatch))

! found patch, increment
patchespersite = patchespersite + 1
Expand Down Expand Up @@ -2356,31 +2386,12 @@ subroutine set_restart_vectors(this,nc,nsites,sites)

cpatch => cpatch%younger

enddo ! cpatch do while

io_idx_si_scpf = io_idx_co_1st
enddo do_patch ! cpatch do while

! Fill the site level diagnostics arrays
do i_scls = 1, nlevsclass
do i_pft = 1, numpft

rio_fmortrate_cano_siscpf(io_idx_si_scpf) = sites(s)%fmort_rate_canopy(i_scls, i_pft)
rio_fmortrate_usto_siscpf(io_idx_si_scpf) = sites(s)%fmort_rate_ustory(i_scls, i_pft)
rio_imortrate_siscpf(io_idx_si_scpf) = sites(s)%imort_rate(i_scls, i_pft)
rio_fmortrate_crown_siscpf(io_idx_si_scpf) = sites(s)%fmort_rate_crown(i_scls, i_pft)
rio_fmortrate_cambi_siscpf(io_idx_si_scpf) = sites(s)%fmort_rate_cambial(i_scls, i_pft)
rio_termnindiv_cano_siscpf(io_idx_si_scpf) = sites(s)%term_nindivs_canopy(i_scls,i_pft)
rio_termnindiv_usto_siscpf(io_idx_si_scpf) = sites(s)%term_nindivs_ustory(i_scls,i_pft)
rio_growflx_fusion_siscpf(io_idx_si_scpf) = sites(s)%growthflux_fusion(i_scls, i_pft)

rio_abg_term_flux_siscpf(io_idx_si_scpf) = sites(s)%term_abg_flux(i_scls, i_pft)
rio_abg_imort_flux_siscpf(io_idx_si_scpf) = sites(s)%imort_abg_flux(i_scls, i_pft)
rio_abg_fmort_flux_siscpf(io_idx_si_scpf) = sites(s)%fmort_abg_flux(i_scls, i_pft)

io_idx_si_scpf = io_idx_si_scpf + 1
end do

rio_demorate_sisc(io_idx_si_sc) = sites(s)%demotion_rate(i_scls)
rio_demorate_sisc(io_idx_si_sc) = sites(s)%demotion_rate(i_scls)
rio_promrate_sisc(io_idx_si_sc) = sites(s)%promotion_rate(i_scls)

io_idx_si_sc = io_idx_si_sc + 1
Expand Down Expand Up @@ -2421,16 +2432,6 @@ subroutine set_restart_vectors(this,nc,nsites,sites)
rio_democflux_si(io_idx_si) = sites(s)%demotion_carbonflux
rio_promcflux_si(io_idx_si) = sites(s)%promotion_carbonflux

io_idx_si_pft = io_idx_co_1st
do i_pft = 1, numpft
rio_termcflux_cano_sipft(io_idx_si_pft) = sites(s)%term_carbonflux_canopy(i_pft)
rio_termcflux_usto_sipft(io_idx_si_pft) = sites(s)%term_carbonflux_ustory(i_pft)
rio_fmortcflux_cano_sipft(io_idx_si_pft) = sites(s)%fmort_carbonflux_canopy(i_pft)
rio_fmortcflux_usto_sipft(io_idx_si_pft) = sites(s)%fmort_carbonflux_ustory(i_pft)
rio_imortcflux_sipft(io_idx_si_pft) = sites(s)%imort_carbonflux(i_pft)
io_idx_si_pft = io_idx_si_pft + 1
end do

rio_imortcarea_si(io_idx_si) = sites(s)%imort_crownarea
rio_fmortcarea_cano_si(io_idx_si) = sites(s)%fmort_crownarea_canopy
rio_fmortcarea_usto_si(io_idx_si) = sites(s)%fmort_crownarea_ustory
Expand Down Expand Up @@ -2922,6 +2923,8 @@ subroutine get_restart_vectors(this, nc, nsites, sites)
io_idx_si_cacls= io_idx_co_1st
io_idx_si_cdsc = io_idx_co_1st
io_idx_si_cdpf = io_idx_co_1st
io_idx_si_scpf = io_idx_co_1st
io_idx_si_pft = io_idx_co_1st

! read seed_bank info(site-level, but PFT-resolved)
do i_pft = 1,numpft
Expand All @@ -2943,6 +2946,33 @@ subroutine get_restart_vectors(this, nc, nsites, sites)
endif
endif

do i_scls = 1,nlevsclass
do i_pft = 1, numpft
sites(s)%fmort_rate_canopy(i_scls, i_pft) = rio_fmortrate_cano_siscpf(io_idx_si_scpf)
sites(s)%fmort_rate_ustory(i_scls, i_pft) = rio_fmortrate_usto_siscpf(io_idx_si_scpf)
sites(s)%imort_rate(i_scls, i_pft) = rio_imortrate_siscpf(io_idx_si_scpf)
sites(s)%fmort_rate_crown(i_scls, i_pft) = rio_fmortrate_crown_siscpf(io_idx_si_scpf)
sites(s)%fmort_rate_cambial(i_scls, i_pft) = rio_fmortrate_cambi_siscpf(io_idx_si_scpf)
sites(s)%term_nindivs_canopy(i_scls,i_pft) = rio_termnindiv_cano_siscpf(io_idx_si_scpf)
sites(s)%term_nindivs_ustory(i_scls,i_pft) = rio_termnindiv_usto_siscpf(io_idx_si_scpf)
sites(s)%growthflux_fusion(i_scls, i_pft) = rio_growflx_fusion_siscpf(io_idx_si_scpf)
sites(s)%term_abg_flux(i_scls,i_pft) = rio_abg_term_flux_siscpf(io_idx_si_scpf)
sites(s)%imort_abg_flux(i_scls,i_pft) = rio_abg_imort_flux_siscpf(io_idx_si_scpf)
sites(s)%fmort_abg_flux(i_scls,i_pft) = rio_abg_fmort_flux_siscpf(io_idx_si_scpf)
io_idx_si_scpf = io_idx_si_scpf + 1
end do
end do

do i_pft = 1, numpft
sites(s)%term_carbonflux_canopy(i_pft) = rio_termcflux_cano_sipft(io_idx_si_pft)
sites(s)%term_carbonflux_ustory(i_pft) = rio_termcflux_usto_sipft(io_idx_si_pft)
sites(s)%fmort_carbonflux_canopy(i_pft) = rio_fmortcflux_cano_sipft(io_idx_si_pft)
sites(s)%fmort_carbonflux_ustory(i_pft) = rio_fmortcflux_usto_sipft(io_idx_si_pft)
sites(s)%imort_carbonflux(i_pft) = rio_imortcflux_sipft(io_idx_si_pft)
io_idx_si_pft = io_idx_si_pft + 1
end do


! Mass balance and diagnostics across elements at the site level
if(hlm_use_sp.eq.ifalse)then
do el = 1, num_elements
Expand Down Expand Up @@ -2975,7 +3005,7 @@ subroutine get_restart_vectors(this, nc, nsites, sites)
patchespersite = 0

cpatch => sites(s)%oldest_patch
do while(associated(cpatch))
do_patch: do while(associated(cpatch))

patchespersite = patchespersite + 1

Expand Down Expand Up @@ -3244,8 +3274,7 @@ subroutine get_restart_vectors(this, nc, nsites, sites)
end if

cpatch => cpatch%younger

enddo ! patch do while
enddo do_patch

if(patchespersite .ne. rio_npatch_si(io_idx_si)) then
write(fates_log(),*) 'Number of patches per site during retrieval does not match allocation'
Expand Down Expand Up @@ -3299,30 +3328,11 @@ subroutine get_restart_vectors(this, nc, nsites, sites)

! Fill the site level diagnostics arrays
! -----------------------------------------------------------------------------

io_idx_si_scpf = io_idx_co_1st

do i_scls = 1,nlevsclass
do i_pft = 1, numpft
sites(s)%fmort_rate_canopy(i_scls, i_pft) = rio_fmortrate_cano_siscpf(io_idx_si_scpf)
sites(s)%fmort_rate_ustory(i_scls, i_pft) = rio_fmortrate_usto_siscpf(io_idx_si_scpf)
sites(s)%imort_rate(i_scls, i_pft) = rio_imortrate_siscpf(io_idx_si_scpf)
sites(s)%fmort_rate_crown(i_scls, i_pft) = rio_fmortrate_crown_siscpf(io_idx_si_scpf)
sites(s)%fmort_rate_cambial(i_scls, i_pft) = rio_fmortrate_cambi_siscpf(io_idx_si_scpf)
sites(s)%term_nindivs_canopy(i_scls,i_pft) = rio_termnindiv_cano_siscpf(io_idx_si_scpf)
sites(s)%term_nindivs_ustory(i_scls,i_pft) = rio_termnindiv_usto_siscpf(io_idx_si_scpf)
sites(s)%growthflux_fusion(i_scls, i_pft) = rio_growflx_fusion_siscpf(io_idx_si_scpf)

sites(s)%term_abg_flux(i_scls,i_pft) = rio_abg_term_flux_siscpf(io_idx_si_scpf)
sites(s)%imort_abg_flux(i_scls,i_pft) = rio_abg_imort_flux_siscpf(io_idx_si_scpf)
sites(s)%fmort_abg_flux(i_scls,i_pft) = rio_abg_fmort_flux_siscpf(io_idx_si_scpf)

io_idx_si_scpf = io_idx_si_scpf + 1
end do

sites(s)%demotion_rate(i_scls) = rio_demorate_sisc(io_idx_si_sc)
sites(s)%promotion_rate(i_scls) = rio_promrate_sisc(io_idx_si_sc)

io_idx_si_sc = io_idx_si_sc + 1
end do

Expand Down Expand Up @@ -3360,16 +3370,6 @@ subroutine get_restart_vectors(this, nc, nsites, sites)
sites(s)%demotion_carbonflux = rio_democflux_si(io_idx_si)
sites(s)%promotion_carbonflux = rio_promcflux_si(io_idx_si)

io_idx_si_pft = io_idx_co_1st
do i_pft = 1, numpft
sites(s)%term_carbonflux_canopy(i_pft) = rio_termcflux_cano_sipft(io_idx_si_pft)
sites(s)%term_carbonflux_ustory(i_pft) = rio_termcflux_usto_sipft(io_idx_si_pft)
sites(s)%fmort_carbonflux_canopy(i_pft) = rio_fmortcflux_cano_sipft(io_idx_si_pft)
sites(s)%fmort_carbonflux_ustory(i_pft) = rio_fmortcflux_usto_sipft(io_idx_si_pft)
sites(s)%imort_carbonflux(i_pft) = rio_imortcflux_sipft(io_idx_si_pft)
io_idx_si_pft = io_idx_si_pft + 1
end do

! Site level phenology status flags

sites(s)%cstatus = rio_cd_status_si(io_idx_si)
Expand Down

0 comments on commit 5211412

Please sign in to comment.