Skip to content

Commit

Permalink
Write LANDFRAC_MKSURFDATA to surface dataset and landuse timeseries
Browse files Browse the repository at this point in the history
  • Loading branch information
billsacks committed Dec 2, 2022
1 parent 344c12a commit d482393
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
11 changes: 11 additions & 0 deletions tools/mksurfdata_esmf/src/mkfileMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,17 @@ subroutine mkfile_define_vars(pioid, dynlanduse)
call mkpio_def_spatial_var(pioid=pioid, varname='LANDFRAC_PFT', xtype=xtype, &
long_name='land fraction from pft dataset (DIFF FROM landfrac USED IN SIMULATION, SHOWN IN HISTORY)', units='unitless')

if (.not. dynlanduse) then
call mkpio_def_spatial_var(pioid=pioid, varname='LANDFRAC_MKSURFDATA', xtype=xtype, &
long_name='land fraction used for renormalization of areas in mksurfdata (DIFF FROM landfrac USED IN SIMULATION)', &
units='unitless')
else
call mkpio_def_spatial_var(pioid=pioid, varname='LANDFRAC_MKSURFDATA', xtype=xtype, &
lev1name='time', &
long_name='land fraction used for renormalization of areas in mksurfdata (DIFF FROM landfrac USED IN SIMULATION)', &
units='unitless')
end if

if (.not. dynlanduse) then
call mkpio_def_spatial_var(pioid=pioid, varname='PCT_NATVEG', xtype=xtype, &
long_name='total percent natural vegetation landunit', units='unitless')
Expand Down
20 changes: 19 additions & 1 deletion tools/mksurfdata_esmf/src/mksurfdata.F90
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ program mksurfdata
real(r8), allocatable :: pctwet_orig(:) ! percent wetland of gridcell before dynamic land use adjustments
real(r8), allocatable :: pctgla_orig(:) ! percent glacier of gridcell before dynamic land use adjustments

! other variables written to file
real(r8), allocatable :: landfrac_mksurfdata(:) ! land fraction used for renormalization of areas

! pio/esmf variables
type(file_desc_t) :: pioid
type(var_desc_t) :: pio_varid
Expand Down Expand Up @@ -595,6 +598,7 @@ program mksurfdata

! Normalize land use and make sure things add up to 100% as well as
! checking that things are as they should be.
allocate(landfrac_mksurfdata(lsize_o))
call normalize_and_check_landuse(lsize_o)

! Write out sum of PFT's
Expand Down Expand Up @@ -692,6 +696,10 @@ program mksurfdata
call mkfile_output(pioid, mesh_model, 'PCT_CFT', pct_cft, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) call shr_sys_abort('error in calling mkfile_output for PCT_CFT')
end if

if (root_task) write(ndiag, '(a)') trim(subname)//" writing LANDFRAC_MKSURFDATA"
call mkfile_output(pioid, mesh_model, 'LANDFRAC_MKSURFDATA', landfrac_mksurfdata, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) call shr_sys_abort('error in calling mkfile_output for LANDFRAC_MKSURFDATA')
end if

! ----------------------------------------------------------------------
Expand Down Expand Up @@ -779,7 +787,7 @@ program mksurfdata
! landfrac_pft was calculated ABOVE
if (root_task) write(ndiag, '(a)') trim(subname)//" writing land fraction calculated in fsurdata calc)"
call mkfile_output(pioid, mesh_model, 'LANDFRAC_PFT', landfrac_pft, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) call shr_sys_abort('error in calling mkfile_output')
if (ChkErr(rc,__LINE__,u_FILE_u)) call shr_sys_abort('error in calling mkfile_output for LANDFRAC_PFT')

! -----------------------------------------
! Read in each dynamic pft landuse dataset
Expand Down Expand Up @@ -993,6 +1001,13 @@ program mksurfdata
call pio_syncfile(pioid)
end if

if (root_task) write(ndiag, '(a,i8)') trim(subname)//" writing LANDFRAC_MKSURFDATA for year ",year
rcode = pio_inq_varid(pioid, 'LANDFRAC_MKSURFDATA', pio_varid)
call pio_setframe(pioid, pio_varid, int(ntim, kind=Pio_Offset_Kind))
call mkfile_output(pioid, mesh_model, 'LANDFRAC_MKSURFDATA', landfrac_mksurfdata, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) call shr_sys_abort('error in calling mkfile_output for LANDFRAC_MKSURFDATA')
call pio_syncfile(pioid)

if (root_task) then
write(ndiag,'(1x,80a1)') ('=',k=1,80)
write(ndiag,*)
Expand Down Expand Up @@ -1232,6 +1247,9 @@ subroutine normalize_and_check_landuse(ns_o)
call pctnatpft(n)%set_pct_l2g(new_total_natveg_pct)
end if

! Save landfrac for output to file
landfrac_mksurfdata(n) = frac_land

! Confirm that we have done the rescaling correctly: now the sum of all landunits
! should be 100% within tol_loose
suma = pctlak(n) + pctwet(n) + pctgla(n) + pcturb(n) + pctcft(n)%get_pct_l2g()
Expand Down

0 comments on commit d482393

Please sign in to comment.