Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writes/reads C budget related variables in history file #6273

Merged
merged 6 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions components/elm/src/biogeochem/CNPBudgetMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1193,37 +1193,28 @@ subroutine CBudget_SetEndingMonthlyStates(bounds, col_cs, grc_cs)
type(gridcell_carbon_state), intent(inout) :: grc_cs
!
! !LOCAL VARIABLES:
integer :: year_prev, month_prev, day_prev, sec_prev
integer :: year_curr, month_curr, day_curr, sec_curr
integer :: year, month, day, sec
!-----------------------------------------------------------------------

associate( &
begcb => col_cs%begcb , & ! Input : [real(r8) (:) ] carbon mass begining of the time step
endcb => col_cs%endcb , & ! Input : [real(r8) (:) ] carbon mass begining of the time step
tcs_month_end_grc => grc_cs%tcs_month_beg & ! Output: [real(r8) (:) ] grid-level carbon mass at the begining of a month
tcs_month_end_grc => grc_cs%tcs_month_end & ! Output: [real(r8) (:) ] grid-level carbon mass at the ending of a month
)

! Get current and previous dates to determine if a new month started
call get_prev_date(year_curr, month_curr, day_curr, sec_curr);
call get_prev_date(year_prev, month_prev, day_prev, sec_prev)

! If at the beginning of a simulation, save grid-level TCS based on
! 'begcb' from the current time step
if ( day_curr == 1 .and. sec_curr == 0 .and. get_nstep() <= 1 ) then
call c2g( bounds, &
begcb(bounds%begc:bounds%endc), &
tcs_month_end_grc(bounds%begg:bounds%endg), &
c2l_scale_type= 'unity', l2g_scale_type='unity' )
endif
! Get current dates to determine if a new month started
call get_curr_date(year, month, day, sec);

! If multiple steps into a simulation and the last time step was the
! end of a month, save grid-level TCS based on 'endcb' from the last
! time step
if (get_nstep() > 1 .and. day_prev == 1 .and. sec_prev == 0) then
if (get_nstep() > 1 .and. day == 1 .and. sec == 0) then
call c2g( bounds, &
endcb(bounds%begc:bounds%endc), &
tcs_month_end_grc(bounds%begg:bounds%endg), &
c2l_scale_type= 'unity', l2g_scale_type='unity' )
else
tcs_month_end_grc(bounds%begg:bounds%endg) = spval
endif

end associate
Expand Down
4 changes: 4 additions & 0 deletions components/elm/src/data_types/GridcellDataType.F90
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,10 @@ subroutine grc_cs_restart(this, bounds, ncid, flag)
long_name='total carbon storage at the beginning of a month', units='gC/m^2', &
interpinic_flag='interp', readvar=readvar, data=this%tcs_month_beg)

call restartvar(ncid=ncid, flag=flag, varname='TCS_MONTH_END', xtype=ncd_double, &
dim1name='gridcell', &
long_name='total carbon storage at the end of a month', units='gC/m^2', &
interpinic_flag='interp', readvar=readvar, data=this%tcs_month_end)
end subroutine grc_cs_restart

!------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions components/elm/src/main/restFileMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ subroutine restFile_write( bounds, file, &
call veg_ps%Restart(bounds, ncid, flag='write')
call veg_pf%Restart(bounds, ncid, flag='write')
call crop_vars%Restart(bounds, ncid, flag='write')

call grc_cs%Restart(bounds, ncid, flag='write')
end if


Expand Down Expand Up @@ -627,6 +629,8 @@ subroutine restFile_read( bounds, file, &
call veg_ps%Restart(bounds, ncid, flag='read')
call veg_pf%Restart(bounds, ncid, flag='read')
call crop_vars%Restart(bounds, ncid, flag='read')

call grc_cs%Restart(bounds, ncid, flag='read')
end if

if (use_fates) then
Expand Down