From 76b815b3dbda4eb37fc9ca2f1100b58ce9e6723b Mon Sep 17 00:00:00 2001 From: Ryan Knox Date: Wed, 17 Dec 2025 16:40:32 -0500 Subject: [PATCH 1/3] fates json file handling and argument passing --- components/elm/bld/ELMBuildNamelist.pm | 30 ++- .../bld/namelist_files/namelist_defaults.xml | 8 +- .../namelist_files/namelist_definition.xml | 2 +- components/elm/src/main/elm_initializeMod.F90 | 9 - .../elm/src/main/elmfates_interfaceMod.F90 | 17 +- .../src/main/elmfates_paraminterfaceMod.F90 | 225 ------------------ 6 files changed, 29 insertions(+), 262 deletions(-) delete mode 100644 components/elm/src/main/elmfates_paraminterfaceMod.F90 diff --git a/components/elm/bld/ELMBuildNamelist.pm b/components/elm/bld/ELMBuildNamelist.pm index ebde3a5d0093..f080424d463e 100755 --- a/components/elm/bld/ELMBuildNamelist.pm +++ b/components/elm/bld/ELMBuildNamelist.pm @@ -3764,20 +3764,26 @@ sub add_default { # query the definition to find out if the variable is an input pathname my $is_input_pathname = $definition->is_input_pathname($var); + - # The default values for input pathnames are relative. If the namelist - # variable is defined to be an absolute pathname, then prepend - # the E3SM inputdata root directory. - if (not defined $settings{'no_abspath'}) { - if (defined $settings{'set_abspath'}) { - $val = set_abs_filepath($val, $settings{'set_abspath'}); - } else { - if ($is_input_pathname eq 'abs') { - $val = set_abs_filepath($val, $inputdata_rootdir); - } - } + if ($is_input_pathname eq 'landroot') { + my $landroot = abs_path("$ProgDir/.."); + $val = set_abs_filepath($val,$landroot); + } else { + # The default values for input pathnames are relative. If the namelist + # variable is defined to be an absolute pathname, then prepend + # the E3SM inputdata root directory. + if (not defined $settings{'no_abspath'}) { + if (defined $settings{'set_abspath'}) { + $val = set_abs_filepath($val, $settings{'set_abspath'}); + } else { + if ($is_input_pathname eq 'abs') { + $val = set_abs_filepath($val, $inputdata_rootdir); + } + } + } } - + # query the definition to find out if the variable takes a string value. # The returned string length will be >0 if $var is a string, and 0 if not. my $str_len = $definition->get_str_len($var); diff --git a/components/elm/bld/namelist_files/namelist_defaults.xml b/components/elm/bld/namelist_files/namelist_defaults.xml index aebc38a9c978..a817b1f491a1 100644 --- a/components/elm/bld/namelist_files/namelist_defaults.xml +++ b/components/elm/bld/namelist_files/namelist_defaults.xml @@ -131,10 +131,10 @@ attributes from the config_cache.xml file (with keys converted to upper-case). lnd/clm2/paramdata/clm_params_c180524_phs.nc - - - -lnd/clm2/paramdata/fates_params_api.41.0.0_14pft_c250813.nc + + + +src/external_models/fates/parameter_files/fates_params_default.json lnd/clm2/paramdata/CNP_parameters_c131108.nc diff --git a/components/elm/bld/namelist_files/namelist_definition.xml b/components/elm/bld/namelist_files/namelist_definition.xml index 89bef37719a2..00cb5f017f08 100644 --- a/components/elm/bld/namelist_files/namelist_definition.xml +++ b/components/elm/bld/namelist_files/namelist_definition.xml @@ -532,7 +532,7 @@ constants for biogeochem modules + input_pathname="landroot" group="elm_inparm" valid_values="" > Full pathname datafile with fates parameters diff --git a/components/elm/src/main/elm_initializeMod.F90 b/components/elm/src/main/elm_initializeMod.F90 index 715621cd2911..2839e2225894 100644 --- a/components/elm/src/main/elm_initializeMod.F90 +++ b/components/elm/src/main/elm_initializeMod.F90 @@ -21,7 +21,6 @@ module elm_initializeMod use readParamsMod , only : readSharedParameters, readPrivateParameters use ncdio_pio , only : file_desc_t use ELMFatesInterfaceMod , only : ELMFatesGlobals1,ELMFatesGlobals2 - use ELMFatesParamInterfaceMod, only: FatesReadPFTs use BeTRSimulationELM, only : create_betr_simulation_elm use SoilLittVertTranspMod, only : CreateLitterTransportList use iso_c_binding @@ -345,14 +344,6 @@ subroutine initialize1( ) call soilorder_conrd() - ! Read in FATES parameter values early in the call sequence as well - ! The PFT file, specifically, will dictate how many pfts are used - ! in fates, and this will influence the amount of memory we - ! request from the model, which is relevant in set_fates_global_elements() - if (use_fates) then - call FatesReadPFTs() - end if - ! Read surface dataset and set up subgrid weight arrays call surfrd_get_data(begg, endg, ldomain, fsurdat) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 7c7643404d56..9911879bbcfa 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -77,6 +77,7 @@ module ELMFatesInterfaceMod use elm_varctl , only : use_lch4 use elm_varctl , only : use_century_decomp use elm_varctl , only : carbon_only,carbonnitrogen_only,carbonphosphorus_only + use elm_varctl , only : fates_paramfile use elm_varcon , only : tfrz use elm_varcon , only : spval use elm_varcon , only : denice @@ -207,9 +208,6 @@ module ELMFatesInterfaceMod use FatesInterfaceTypesMod , only : bc_in_type, bc_out_type - use ELMFatesParamInterfaceMod, only : fates_param_reader_ctsm_impl - use FatesParametersInterface, only : fates_param_reader_type - use FatesParametersInterface, only : fates_parameters_type use perf_mod , only : t_startf, t_stopf @@ -331,7 +329,7 @@ subroutine ELMFatesGlobals1() integer :: pass_use_luh2 integer :: pass_masterproc logical :: verbose_output - type(fates_param_reader_ctsm_impl) :: var_reader + if (use_fates) then @@ -378,6 +376,8 @@ subroutine ELMFatesGlobals1() end if call set_fates_ctrlparms('masterproc',ival=pass_masterproc) + call set_fates_ctrlparms('parteh_mode',ival=fates_parteh_mode) + end if ! The following call reads in the parameter file @@ -394,8 +394,8 @@ subroutine ELMFatesGlobals1() ! want fates to handle crops, so again, it should be ignored. ! (RGK 07-2022) - call SetFatesGlobalElements1(use_fates,natpft_size,0,var_reader) - + call SetFatesGlobalElements1(use_fates,natpft_size,0,fates_paramfile) + natpft_size = fates_maxPatchesPerSite max_patch_per_col= max(natpft_size, numcft, maxpatch_urb) @@ -476,7 +476,6 @@ subroutine ELMFatesGlobals2() call set_fates_ctrlparms('hlm_name',cval='ELM') call set_fates_ctrlparms('hio_ignore_val',rval=spval) call set_fates_ctrlparms('soilwater_ipedof',ival=get_ipedof(0)) - call set_fates_ctrlparms('parteh_mode',ival=fates_parteh_mode) call set_fates_ctrlparms('seeddisp_cadence',ival=fates_seeddisp_cadence) call set_fates_ctrlparms('hist_hifrq_dimlevel',ival=fates_history_dimlevel(1)) @@ -842,7 +841,6 @@ subroutine init(this, bounds_proc, flandusepftdat) use spmdMod, only : npes use decompMod, only : procinfo - use FatesInterfaceMod, only : FatesReportParameters use FatesParameterDerivedMod, only : param_derived use FatesInterfaceTypesMod, only : numpft_fates => numpft use elm_varsur, only : wt_nat_patch @@ -1079,9 +1077,6 @@ subroutine init(this, bounds_proc, flandusepftdat) call this%init_history_io(bounds_proc) - ! Report Fates Parameters (debug flag in lower level routines) - call FatesReportParameters(masterproc) - ! Fire data to send to FATES call create_fates_fire_data_method( this%fates_fire_data_method ) diff --git a/components/elm/src/main/elmfates_paraminterfaceMod.F90 b/components/elm/src/main/elmfates_paraminterfaceMod.F90 deleted file mode 100644 index deb069260835..000000000000 --- a/components/elm/src/main/elmfates_paraminterfaceMod.F90 +++ /dev/null @@ -1,225 +0,0 @@ -module ELMFatesParamInterfaceMod - ! NOTE(bja, 2017-01) this code can not go into the main clm-fates - ! interface module because of circular dependancies with pftvarcon. - - use FatesGlobals, only : fates_log - use FatesParametersInterface, only : fates_parameters_type - use FatesParametersInterface, only : fates_param_reader_type - use shr_kind_mod, only : r8 => shr_kind_r8 - - implicit none - private - - ! Extend the fates parameter reader type with Read parameter function - type, extends(fates_param_reader_type) :: fates_param_reader_ctsm_impl - ! !PRIVATE MEMBER DATA: - contains - ! !PUBLIC MEMBER FUNCTIONS: - procedure, public :: Read ! Read params from disk - end type - - public :: fates_param_reader_ctsm_impl - - ! NOTE(bja, 2017-01) these methods can NOT be part of the hlm-fates - ! interface type because they are called before the instance is - ! initialized. - public :: FatesReadPFTs - - logical :: DEBUG = .false. - - character(len=*), parameter, private :: sourcefile = & - __FILE__ - -contains - - - !----------------------------------------------------------------------- - subroutine FatesReadPFTs() - - use elm_varctl, only : use_fates, paramfile, fates_paramfile - use spmdMod, only : masterproc - - use EDPftvarcon , only : EDPftvarcon_inst - - use fileutils , only : getfil - use ncdio_pio , only : file_desc_t, ncd_pio_closefile, ncd_pio_openfile - - implicit none - - character(len=32) :: subname = 'FatesReadPFTs' - class(fates_parameters_type), allocatable :: fates_params - logical :: is_host_file - - character(len=256) :: locfn ! local file name - type(file_desc_t) :: ncid ! pio netCDF file id - - if (use_fates) then - if (masterproc) then - write(fates_log(), *) 'clmfates_interfaceMod.F90::'//trim(subname)//' :: CLM reading ED/FATES '//' PFTs ' - end if - - allocate(fates_params) - call fates_params%Init() - call EDPftvarcon_inst%Init() - - call EDPftvarcon_inst%Register(fates_params) - - is_host_file = .false. - call ParametersFromNetCDF(fates_paramfile, is_host_file, fates_params) - - is_host_file = .true. - call ParametersFromNetCDF(paramfile, is_host_file, fates_params) - - call EDPftvarcon_inst%Receive(fates_params) - - call fates_params%Destroy() - deallocate(fates_params) - end if - - end subroutine FatesReadPFTs - - !----------------------------------------------------------------------- - subroutine SetParameterDimensions(ncid, is_host_file, fates_params) - ! Get the list of dimensions used by the fates parameters, - ! retreive them from the parameter file, then give the information - ! back to fates. - use FatesParametersInterface, only : fates_parameters_type, param_string_length, max_dimensions, max_used_dimensions - use ncdio_pio , only : file_desc_t - - implicit none - - type(file_desc_t), intent(inout) :: ncid - logical, intent(in) :: is_host_file - class(fates_parameters_type), intent(inout) :: fates_params - - integer :: num_used_dimensions - character(len=param_string_length) :: used_dimension_names(max_used_dimensions) - integer :: used_dimension_sizes(max_used_dimensions) - - call fates_params%GetUsedDimensions(is_host_file, num_used_dimensions, used_dimension_names) - - call GetUsedDimensionSizes(ncid, num_used_dimensions, used_dimension_names, used_dimension_sizes) - - call fates_params%SetDimensionSizes(is_host_file, num_used_dimensions, used_dimension_names, used_dimension_sizes) - - end subroutine SetParameterDimensions - - !----------------------------------------------------------------------- - subroutine GetUsedDimensionSizes(ncid, num_used_dimensions, dimension_names, dimension_sizes) - - use ncdio_pio , only : ncd_inqdid, ncd_inqdlen - use FatesParametersInterface, only : param_string_length - use ncdio_pio, only : file_desc_t - - - implicit none - - type(file_desc_t), intent(inout) :: ncid - integer, intent(in) :: num_used_dimensions - character(len=param_string_length), intent(in) :: dimension_names(:) - integer, intent(out) :: dimension_sizes(:) - - integer :: d, max_dim_size, num_dims - integer :: dim_len, dim_id - - dimension_sizes(:) = 0 - max_dim_size = 0 - - do d = 1, num_used_dimensions - call ncd_inqdid(ncid, dimension_names(d), dim_id) - call ncd_inqdlen(ncid, dim_id, dim_len) - dimension_sizes(d) = dim_len - !write(*, *) '--> ', trim(dimension_names(d)), ' setting size ', dimension_sizes(d) - end do - - end subroutine GetUsedDimensionSizes - - !----------------------------------------------------------------------- - subroutine ParametersFromNetCDF(filename, is_host_file, fates_params) - - use abortutils, only : endrun - use fileutils , only : getfil - use ncdio_pio , only : file_desc_t, ncd_pio_closefile, ncd_pio_openfile - use paramUtilMod, only : readNcdio - - use FatesParametersInterface, only : fates_parameters_type - use FatesParametersInterface, only : param_string_length, max_dimensions, max_used_dimensions - use FatesParametersInterface, only : dimension_shape_scalar, dimension_shape_1d, dimension_shape_2d - - implicit none - - character(len=*), intent(in) :: filename - logical, intent(in) :: is_host_file - class(fates_parameters_type), intent(inout) :: fates_params - - character(len=40) :: subname = 'clmfates_interface::ReadParameters' - character(len=256) :: locfn ! local file name - type(file_desc_t) :: ncid ! pio netCDF file id - integer :: dimid ! netCDF dimension id - integer :: i, num_params, dimension_shape - integer :: max_dim_size - real(r8), allocatable :: data(:, :) - character(len=param_string_length) :: name - integer :: dimension_sizes(max_dimensions) - character(len=param_string_length) :: dimension_names(max_dimensions) - integer :: size_dim_1, size_dim_2 - logical :: is_host_param - - call getfil (filename, locfn, 0) - call ncd_pio_openfile (ncid, trim(locfn), 0) - - call SetParameterDimensions(ncid, is_host_file, fates_params) - max_dim_size = fates_params%GetMaxDimensionSize() - allocate(data(max_dim_size, max_dim_size)) - - num_params = fates_params%num_params() - do i = 1, num_params - call fates_params%GetMetaData(i, name, dimension_shape, dimension_sizes, dimension_names, is_host_param) - if (is_host_file .eqv. is_host_param) then - select case(dimension_shape) - case(dimension_shape_scalar) - size_dim_1 = 1 - size_dim_2 = 1 - case(dimension_shape_1d) - size_dim_1 = dimension_sizes(1) - size_dim_2 = 1 - case(dimension_shape_2d) - size_dim_1 = dimension_sizes(1) - size_dim_2 = dimension_sizes(2) - case default - write(fates_log(),*) 'dimension shape:',dimension_shape - call endrun(msg='unsupported number of dimensions reading parameters.') - end select - if(DEBUG) then - write(fates_log(), *) 'clmfates_interfaceMod.F90:: reading '//trim(name) - end if - call readNcdio(ncid, name, dimension_shape, dimension_names, subname, data(1:size_dim_1, 1:size_dim_2)) - call fates_params%SetData(i, data(1:size_dim_1, 1:size_dim_2)) - end if - end do - deallocate(data) - call ncd_pio_closefile(ncid) - end subroutine ParametersFromNetCDF - - !----------------------------------------------------------------------- - - subroutine Read(this, fates_params ) - ! - ! !DESCRIPTION: - ! Read 'fates_params' parameters from storage. - ! - ! USES - use elm_varctl, only : fname_len, paramfile, fates_paramfile - ! !ARGUMENTS: - class(fates_param_reader_ctsm_impl) :: this - class(fates_parameters_type), intent(inout) :: fates_params - !----------------------------------------------------------------------- - logical :: is_host_file = .false. - - call ParametersFromNetCDF(fates_paramfile, is_host_file, fates_params) - - end subroutine Read - - !----------------------------------------------------------------------- - -end module ELMFatesParamInterfaceMod From 79f1841d166e15cab7e817613a89759ef40c5311 Mon Sep 17 00:00:00 2001 From: Ryan Knox Date: Wed, 17 Dec 2025 18:32:38 -0800 Subject: [PATCH 2/3] updating fates pointer to json feature branch --- components/elm/src/external_models/fates | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/elm/src/external_models/fates b/components/elm/src/external_models/fates index 5bb36cba29b9..47e12c60bdda 160000 --- a/components/elm/src/external_models/fates +++ b/components/elm/src/external_models/fates @@ -1 +1 @@ -Subproject commit 5bb36cba29b95295aca5aedc13f348ef1e001b99 +Subproject commit 47e12c60bdda05db25d7e6ccc94a45ab0d26fd2c From 1c210d6992682e709cb55005993a545e34f774ec Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 17 Feb 2026 12:04:58 -0800 Subject: [PATCH 3/3] update fates to sci.1.90.1_api.43.1.0 --- components/elm/src/external_models/fates | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/elm/src/external_models/fates b/components/elm/src/external_models/fates index 47e12c60bdda..55ec6c776806 160000 --- a/components/elm/src/external_models/fates +++ b/components/elm/src/external_models/fates @@ -1 +1 @@ -Subproject commit 47e12c60bdda05db25d7e6ccc94a45ab0d26fd2c +Subproject commit 55ec6c7768061148fc107a0810d3690763d85320