Skip to content

Commit

Permalink
Merge pull request ESCOMP#766 from rgknox/rgknox-parteh-api-v2
Browse files Browse the repository at this point in the history
interface changes for fates-parteh (nutrients)
  • Loading branch information
rgknox authored Aug 26, 2019
2 parents 08fc948 + 320a80d commit 9c12e40
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 204 deletions.
2 changes: 1 addition & 1 deletion Externals_CLM.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
local_path = src/fates
protocol = git
repo_url = https://github.com/NGEET/fates
tag = sci.1.27.1_api.7.3.0
tag = sci.1.30.0_api.8.0.0
required = True

[PTCLM]
Expand Down
8 changes: 5 additions & 3 deletions cime_config/testdefs/testmods_dirs/clm/Fates/user_nl_clm
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ hist_mfilt = 365
hist_nhtfrq = -24
hist_empty_htapes = .true.
use_fates_spitfire= .true.
hist_fincl1 = 'NPP','GPP','BTRAN','H2OSOI','TLAI','LITTER_IN','LITTER_OUT',
hist_fincl1 = 'NPP','GPP','BTRAN','H2OSOI','TLAI','LITTER_IN_ELEM','LITTER_OUT_ELEM',
'FIRE_AREA','SCORCH_HEIGHT','FIRE_INTENSITY','FIRE_TFC_ROS','fire_fuel_mef',
'fire_fuel_bulkd','fire_fuel_sav','FIRE_NESTEROV_INDEX','PFTbiomass',
'PFTleafbiomass','FIRE_ROS','WIND','AREA_TREES','AREA_PLANT',
'TOTSOMC','TOTLITC','T_SCALAR','NEP','NBP','HR','TOTECOSYSC','NPLANT_SCAG','NPLANT_SCPF',
'BA_SCLS','NPP_BY_AGE','CWD_AG_CWDSC','PARSUN_Z_CNLF','PARSUN_Z_CNLFPFT','PARSHA_Z_CAN'
'TOTSOMC','TOTLITC','T_SCALAR','NEP','HR','NPLANT_SCAG','NPLANT_SCPF',
'BA_SCLS','NPP_BY_AGE','CWD_AG_CWDSC','PARSUN_Z_CNLF','PARSUN_Z_CNLFPFT','PARSHA_Z_CAN',
'LITTER_FINES_AG_ELEM','LITTER_FINES_BG_ELEM','LITTER_CWD_AG_ELEM','LITTER_CWD_BG_ELEM',
'SEED_BANK'
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ hist_fincl1 = 'NCL_BY_AGE','NPATCH_BY_AGE','BIOMASS_BY_AGE','NPP_BY_AGE','
'NPP_LEAF_UNDERSTORY_SCLS','NPP_FROOT_UNDERSTORY_SCLS','NPP_BSW_UNDERSTORY_SCLS',
'NPP_BDEAD_UNDERSTORY_SCLS','NPP_BSEED_UNDERSTORY_SCLS','NPP_STORE_UNDERSTORY_SCLS','RDARK_UNDERSTORY_SCLS',
'LIVESTEM_MR_UNDERSTORY_SCLS','LIVECROOT_MR_UNDERSTORY_SCLS','FROOT_MR_UNDERSTORY_SCLS','RESP_G_UNDERSTORY_SCLS',
'RESP_M_UNDERSTORY_SCLS'
'RESP_M_UNDERSTORY_SCLS','LITTER_IN_ELEM','LITTER_OUT_ELEM','SEED_BANK_ELEM','SEEDS_IN_LOCAL_ELEM','SEEDS_IN_EXTERN_ELEM',
'SEED_GERM_ELEM','SEED_DECAY','CBALANCE_ERROR_FATES','ERROR_FATES','LITTER_FINES_AG_ELEM','LITTER_FINES_BG_ELEM','LITTER_CWD_BG_ELEM',
'LITTER_CWD_AG_ELEM','LITTER_CWD'
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ hist_fincl1 = 'NPP','GPP','BTRAN','H2OSOI','TLAI','LITTER_IN','LITTER_OUT'
'FIRE_AREA','SCORCH_HEIGHT','FIRE_INTENSITY','FIRE_TFC_ROS','fire_fuel_mef',
'fire_fuel_bulkd','fire_fuel_sav','FIRE_NESTEROV_INDEX','PFTbiomass',
'PFTleafbiomass','FIRE_ROS','WIND','AREA_TREES','AREA_PLANT',
'TOTSOMC','TOTLITC','T_SCALAR','NEP','NBP','HR','TOTECOSYSC','NPLANT_SCAG','NPLANT_SCPF',
'TOTSOMC','TOTLITC','T_SCALAR','NEP','HR','NPLANT_SCAG','NPLANT_SCPF',
'BA_SCLS','NPP_BY_AGE','CWD_AG_CWDSC','PARSUN_Z_CNLF','PARSUN_Z_CNLFPFT','PARSHA_Z_CAN'
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ hist_fincl1 = 'NPP','GPP','BTRAN','H2OSOI','TLAI','LITTER_IN','LITTER_OUT'
'FIRE_AREA','SCORCH_HEIGHT','FIRE_INTENSITY','FIRE_TFC_ROS','fire_fuel_mef',
'fire_fuel_bulkd','fire_fuel_sav','FIRE_NESTEROV_INDEX','PFTbiomass',
'PFTleafbiomass','FIRE_ROS','WIND','AREA_TREES','AREA_PLANT',
'TOTSOMC','TOTLITC','T_SCALAR','NEP','NBP','HR','TOTECOSYSC'
'TOTSOMC','TOTLITC','T_SCALAR','NEP','HR'
117 changes: 86 additions & 31 deletions src/main/histFileMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ module histFileMod
use EDTypesMod , only : nlevleaf
use FatesInterfaceMod , only : nlevsclass, nlevage
use FatesInterfaceMod , only : nlevheight
use EDTypesMod , only : nfsc, ncwd
use FatesInterfaceMod , only : numpft_ed => numpft
use EDTypesMod , only : nfsc
use FatesLitterMod , only : ncwd
use EDTypesMod , only : num_elements_fates => num_elements
use FatesInterfaceMod , only : numpft_fates => numpft
use ncdio_pio

!
Expand Down Expand Up @@ -191,6 +193,9 @@ module histFileMod
integer :: beg1d_out ! on-node 1d hbuf pointer start index
integer :: end1d_out ! on-node 1d hbuf pointer end index
integer :: num1d_out ! size of hbuf first dimension (all nodes)
integer :: numdims ! the actual number of dimensions, this allows
! for 2D arrays, where the second dimension is allowed
! to be 1
integer :: num2d ! size of hbuf second dimension (e.g. number of vertical levels)
integer :: hpindex ! history pointer index
character(len=scale_type_strlen) :: p2c_scale_type ! scale factor when averaging patch to column
Expand Down Expand Up @@ -306,7 +311,7 @@ subroutine hist_printflds()
end subroutine hist_printflds

!-----------------------------------------------------------------------
subroutine masterlist_addfld (fname, type1d, type1d_out, &
subroutine masterlist_addfld (fname, numdims, type1d, type1d_out, &
type2d, num2d, units, avgflag, long_name, hpindex, &
p2c_scale_type, c2l_scale_type, l2g_scale_type, &
no_snow_behavior)
Expand All @@ -322,6 +327,7 @@ subroutine masterlist_addfld (fname, type1d, type1d_out, &
!
! !ARGUMENTS:
character(len=*), intent(in) :: fname ! field name
integer , intent(in) :: numdims ! number of dimensions
character(len=*), intent(in) :: type1d ! 1d data type
character(len=*), intent(in) :: type1d_out ! 1d output type
character(len=*), intent(in) :: type2d ! 2d output type
Expand Down Expand Up @@ -400,6 +406,7 @@ subroutine masterlist_addfld (fname, type1d, type1d_out, &
masterlist(f)%field%type1d = type1d
masterlist(f)%field%type1d_out = type1d_out
masterlist(f)%field%type2d = type2d
masterlist(f)%field%numdims = numdims
masterlist(f)%field%num2d = num2d
masterlist(f)%field%hpindex = hpindex
masterlist(f)%field%p2c_scale_type = p2c_scale_type
Expand Down Expand Up @@ -1054,17 +1061,20 @@ subroutine hist_update_hbuf(bounds)
integer :: t ! tape index
integer :: f ! field index
integer :: num2d ! size of second dimension (e.g. number of vertical levels)
integer :: numdims ! number of dimensions
character(len=*),parameter :: subname = 'hist_update_hbuf'
character(len=hist_dim_name_length) :: type2d ! hbuf second dimension type ["levgrnd","levlak","numrad","ltype","natpft","cft","glc_nec","elevclas","subname(n)"]
!-----------------------------------------------------------------------

do t = 1,ntapes
!$OMP PARALLEL DO PRIVATE (f, num2d)
do f = 1,tape(t)%nflds
num2d = tape(t)%hlist(f)%field%num2d
if ( num2d == 1) then
numdims = tape(t)%hlist(f)%field%numdims

if ( numdims == 1) then
call hist_update_hbuf_field_1d (t, f, bounds)
else
num2d = tape(t)%hlist(f)%field%num2d
call hist_update_hbuf_field_2d (t, f, bounds, num2d)
end if
end do
Expand Down Expand Up @@ -2056,18 +2066,22 @@ subroutine htape_create (t, histrest)

if(use_fates)then
call ncd_defdim(lnfid, 'fates_levscag', nlevsclass * nlevage, dimid)
call ncd_defdim(lnfid, 'fates_levscagpf', nlevsclass * nlevage * numpft_ed, dimid)
call ncd_defdim(lnfid, 'fates_levagepft', nlevage * numpft_ed, dimid)
call ncd_defdim(lnfid, 'fates_levscagpf', nlevsclass * nlevage * numpft_fates, dimid)
call ncd_defdim(lnfid, 'fates_levagepft', nlevage * numpft_fates, dimid)
call ncd_defdim(lnfid, 'fates_levscls', nlevsclass, dimid)
call ncd_defdim(lnfid, 'fates_levpft', numpft_ed, dimid)
call ncd_defdim(lnfid, 'fates_levpft', numpft_fates, dimid)
call ncd_defdim(lnfid, 'fates_levage', nlevage, dimid)
call ncd_defdim(lnfid, 'fates_levheight', nlevheight, dimid)
call ncd_defdim(lnfid, 'fates_levfuel', nfsc, dimid)
call ncd_defdim(lnfid, 'fates_levcwdsc', ncwd, dimid)
call ncd_defdim(lnfid, 'fates_levscpf', nlevsclass*numpft_ed, dimid)
call ncd_defdim(lnfid, 'fates_levscpf', nlevsclass*numpft_fates, dimid)
call ncd_defdim(lnfid, 'fates_levcan', nclmax, dimid)
call ncd_defdim(lnfid, 'fates_levcnlf', nlevleaf * nclmax, dimid)
call ncd_defdim(lnfid, 'fates_levcnlfpf', nlevleaf * nclmax * numpft_ed, dimid)
call ncd_defdim(lnfid, 'fates_levcnlfpf', nlevleaf * nclmax * numpft_fates, dimid)
call ncd_defdim(lnfid, 'fates_levelem', num_elements_fates, dimid)
call ncd_defdim(lnfid, 'fates_levelpft', num_elements_fates * numpft_fates, dimid)
call ncd_defdim(lnfid, 'fates_levelcwd', num_elements_fates * ncwd, dimid)
call ncd_defdim(lnfid, 'fates_levelage', num_elements_fates * nlevage, dimid)
end if

if ( .not. lhistrest )then
Expand Down Expand Up @@ -2502,6 +2516,15 @@ subroutine htape_timeconst(t, mode)
use FatesInterfaceMod, only : fates_hdim_canmap_levcnlfpf
use FatesInterfaceMod, only : fates_hdim_lfmap_levcnlfpf
use FatesInterfaceMod, only : fates_hdim_pftmap_levcnlfpf
use FatesInterfaceMod, only : fates_hdim_levelem
use FatesInterfaceMod, only : fates_hdim_elmap_levelpft
use FatesInterfaceMod, only : fates_hdim_pftmap_levelpft
use FatesInterfaceMod, only : fates_hdim_elmap_levelcwd
use FatesInterfaceMod, only : fates_hdim_cwdmap_levelcwd
use FatesInterfaceMod, only : fates_hdim_elmap_levelage
use FatesInterfaceMod, only : fates_hdim_agemap_levelage


!
! !ARGUMENTS:
integer, intent(in) :: t ! tape index
Expand Down Expand Up @@ -2598,6 +2621,20 @@ subroutine htape_timeconst(t, mode)
long_name='FATES pft map into patch age x pft', units='-', ncid=nfid(t))
call ncd_defvar(varname='fates_agmap_levagepft', xtype=ncd_int, dim1name='fates_levagepft', &
long_name='FATES age-class map into patch age x pft', units='-', ncid=nfid(t))
call ncd_defvar(varname='fates_levelem',xtype=ncd_int, dim1name='fates_levelem', &
long_name='FATES element (C,N,P,...) identifier', units='-', ncid=nfid(t))
call ncd_defvar(varname='fates_elmap_levelpft', xtype=ncd_int, dim1name='fates_levelpft', &
long_name='FATES element map into element x pft ', units='-', ncid=nfid(t))
call ncd_defvar(varname='fates_pftmap_levelpft', xtype=ncd_int, dim1name='fates_levelpft', &
long_name='FATES pft map into element x pft', units='-', ncid=nfid(t))
call ncd_defvar(varname='fates_elmap_levelcwd', xtype=ncd_int, dim1name='fates_levelcwd', &
long_name='FATES element map into element x cwd', units='-', ncid=nfid(t))
call ncd_defvar(varname='fates_cwdmap_levelcwd', xtype=ncd_int, dim1name='fates_levelcwd', &
long_name='FATES cwd map into element x cwd', units='-', ncid=nfid(t))
call ncd_defvar(varname='fates_elmap_levelage', xtype=ncd_int, dim1name='fates_levelage', &
long_name='FATES element map into age x pft', units='-', ncid=nfid(t))
call ncd_defvar(varname='fates_agemap_levelage', xtype=ncd_int, dim1name='fates_levelage', &
long_name='FATES element map into age x pft', units='-', ncid=nfid(t))

end if

Expand Down Expand Up @@ -2633,7 +2670,14 @@ subroutine htape_timeconst(t, mode)
call ncd_io(varname='fates_agmap_levscagpft',data=fates_hdim_agmap_levscagpft, ncid=nfid(t), flag='write')
call ncd_io(varname='fates_pftmap_levscagpft',data=fates_hdim_pftmap_levscagpft, ncid=nfid(t), flag='write')
call ncd_io(varname='fates_pftmap_levagepft',data=fates_hdim_pftmap_levagepft, ncid=nfid(t), flag='write')
call ncd_io(varname='fates_agmap_levagepft',data=fates_hdim_agmap_levagepft, ncid=nfid(t), flag='write')
call ncd_io(varname='fates_agmap_levagepft',data=fates_hdim_agmap_levagepft, ncid=nfid(t), flag='write')
call ncd_io(varname='fates_levelem',data=fates_hdim_levelem, ncid=nfid(t),flag='write')
call ncd_io(varname='fates_elmap_levelpft',data=fates_hdim_elmap_levelpft, ncid=nfid(t),flag='write')
call ncd_io(varname='fates_pftmap_levelpft',data=fates_hdim_pftmap_levelpft, ncid=nfid(t),flag='write')
call ncd_io(varname='fates_elmap_levelcwd',data=fates_hdim_elmap_levelcwd, ncid=nfid(t),flag='write')
call ncd_io(varname='fates_cwdmap_levelcwd',data=fates_hdim_cwdmap_levelcwd, ncid=nfid(t),flag='write')
call ncd_io(varname='fates_elmap_levelage',data=fates_hdim_elmap_levelage, ncid=nfid(t),flag='write')
call ncd_io(varname='fates_agemap_levelage',data=fates_hdim_agemap_levelage, ncid=nfid(t),flag='write')
end if

endif
Expand Down Expand Up @@ -2879,6 +2923,7 @@ subroutine hfields_write(t, mode)
integer :: num2d ! hbuf second dimension size
integer :: nt ! time index
integer :: ier ! error status
integer :: numdims ! number of dimensions
character(len=avgflag_strlen) :: avgflag ! time averaging flag
character(len=max_chars) :: long_name! long name
character(len=max_chars) :: units ! units
Expand Down Expand Up @@ -2922,6 +2967,7 @@ subroutine hfields_write(t, mode)
end1d_out = tape(t)%hlist(f)%field%end1d_out
num1d_out = tape(t)%hlist(f)%field%num1d_out
type2d = tape(t)%hlist(f)%field%type2d
numdims = tape(t)%hlist(f)%field%numdims
num2d = tape(t)%hlist(f)%field%num2d
nt = tape(t)%ntimes

Expand Down Expand Up @@ -2954,7 +3000,7 @@ subroutine hfields_write(t, mode)
endif

if (dim2name == 'undefined') then
if (num2d == 1) then
if (numdims == 1) then
call ncd_defvar(ncid=nfid(t), varname=varname, xtype=tape(t)%ncprec, &
dim1name=dim1name, dim2name='time', &
long_name=long_name, units=units, cell_method=avgstr, &
Expand All @@ -2966,7 +3012,7 @@ subroutine hfields_write(t, mode)
missing_value=spval, fill_value=spval)
end if
else
if (num2d == 1) then
if (numdims == 1) then
call ncd_defvar(ncid=nfid(t), varname=varname, xtype=tape(t)%ncprec, &
dim1name=dim1name, dim2name=dim2name, dim3name='time', &
long_name=long_name, units=units, cell_method=avgstr, &
Expand All @@ -2987,7 +3033,7 @@ subroutine hfields_write(t, mode)

! Allocate dynamic memory

if (num2d == 1) then
if (numdims == 1) then
allocate(hist1do(beg1d_out:end1d_out), stat=ier)
if (ier /= 0) then
write(iulog,*) trim(subname),' ERROR: allocation'
Expand All @@ -2998,7 +3044,7 @@ subroutine hfields_write(t, mode)

! Write history output. Always output land and ocean runoff on xy grid.

if (num2d == 1) then
if (numdims == 1) then
call ncd_io(flag='write', varname=varname, &
dim1name=type1d_out, data=hist1do, ncid=nfid(t), nt=nt)
else
Expand All @@ -3009,7 +3055,7 @@ subroutine hfields_write(t, mode)

! Deallocate dynamic memory

if (num2d == 1) then
if (numdims == 1) then
deallocate(hist1do)
end if

Expand Down Expand Up @@ -4667,10 +4713,11 @@ subroutine hist_addfld1d (fname, units, avgflag, long_name, type1d_out, &

! Add field to masterlist

call masterlist_addfld (fname=trim(fname), type1d=l_type1d, type1d_out=l_type1d_out, &
type2d='unset', num2d=1, &
units=units, avgflag=avgflag, long_name=long_name, hpindex=hpindex, &
p2c_scale_type=scale_type_p2c, c2l_scale_type=scale_type_c2l, l2g_scale_type=scale_type_l2g)
call masterlist_addfld (fname=trim(fname), numdims=1, type1d=l_type1d, &
type1d_out=l_type1d_out, type2d='unset', num2d=1, &
units=units, avgflag=avgflag, long_name=long_name, hpindex=hpindex, &
p2c_scale_type=scale_type_p2c, c2l_scale_type=scale_type_c2l, &
l2g_scale_type=scale_type_l2g)

l_default = 'active'
if (present(default)) then
Expand Down Expand Up @@ -4786,7 +4833,7 @@ subroutine hist_addfld2d (fname, type2d, units, avgflag, long_name, type1d_out,
case ('fates_levscls')
num2d = nlevsclass
case ('fates_levpft')
num2d = numpft_ed
num2d = numpft_fates
case ('fates_levage')
num2d = nlevage
case ('fates_levheight')
Expand All @@ -4796,23 +4843,31 @@ subroutine hist_addfld2d (fname, type2d, units, avgflag, long_name, type1d_out,
case ('fates_levcwdsc')
num2d = ncwd
case ('fates_levscpf')
num2d = nlevsclass*numpft_ed
num2d = nlevsclass*numpft_fates
case ('fates_levscag')
num2d = nlevsclass*nlevage
case ('fates_levscagpf')
num2d = nlevsclass*nlevage*numpft_ed
num2d = nlevsclass*nlevage*numpft_fates
case ('fates_levagepft')
num2d = nlevage*numpft_ed
num2d = nlevage*numpft_fates
case ('fates_levcan')
num2d = nclmax
case ('fates_levcnlf')
num2d = nlevleaf * nclmax
case ('fates_levcnlfpf')
num2d = nlevleaf * nclmax * numpft_ed
num2d = nlevleaf * nclmax * numpft_fates
case ('ltype')
num2d = max_lunit
case ('natpft')
num2d = natpft_size
case ('fates_levelem')
num2d = num_elements_fates
case ('fates_levelpft')
num2d = num_elements_fates*numpft_fates
case ('fates_levelcwd')
num2d = num_elements_fates*ncwd
case ('fates_levelage')
num2d = num_elements_fates*nlevage
case('cft')
if (cft_size > 0) then
num2d = cft_size
Expand Down Expand Up @@ -4974,12 +5029,12 @@ subroutine hist_addfld2d (fname, type2d, units, avgflag, long_name, type1d_out,

! Add field to masterlist

call masterlist_addfld (fname=trim(fname), type1d=l_type1d, type1d_out=l_type1d_out, &
type2d=type2d, num2d=num2d, &
units=units, avgflag=avgflag, long_name=long_name, hpindex=hpindex, &
p2c_scale_type=scale_type_p2c, c2l_scale_type=scale_type_c2l, l2g_scale_type=scale_type_l2g, &
no_snow_behavior=no_snow_behavior)

call masterlist_addfld (fname=trim(fname), numdims=2, type1d=l_type1d, &
type1d_out=l_type1d_out, type2d=type2d, num2d=num2d, &
units=units, avgflag=avgflag, long_name=long_name, hpindex=hpindex, &
p2c_scale_type=scale_type_p2c, c2l_scale_type=scale_type_c2l, &
l2g_scale_type=scale_type_l2g, no_snow_behavior=no_snow_behavior)
l_default = 'active'
if (present(default)) then
l_default = default
Expand Down
Loading

0 comments on commit 9c12e40

Please sign in to comment.