-
Notifications
You must be signed in to change notification settings - Fork 312
/
clmfates_paraminterfaceMod.F90
279 lines (212 loc) · 10.1 KB
/
clmfates_paraminterfaceMod.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
module CLMFatesParamInterfaceMod
! NOTE(bja, 2017-01) this code can not go into the main clm-fates
! interface module because of circular dependancies with pftvarcon.
use shr_kind_mod, only : r8 => shr_kind_r8, SHR_KIND_CL
use FatesGlobals, only : fates_log
use FatesParametersInterface, only : fates_parameters_type
use FatesParametersInterface, only : fates_param_reader_type
use EDParamsMod, only : FatesRegisterParams, FatesReceiveParams
use SFParamsMod, only : SpitFireRegisterParams, SpitFireReceiveParams
use PRTInitParamsFATESMod, only : PRTRegisterParams, PRTReceiveParams
use FatesSynchronizedParamsMod, only : FatesSynchronizedParamsInst
implicit none
public :: fates_param_reader_ctsm_impl
!
type, extends(fates_param_reader_type) :: fates_param_reader_ctsm_impl
private
! !PRIVATE MEMBER DATA:
contains
! !PUBLIC MEMBER FUNCTIONS:
procedure, public :: Read ! Read params from disk
end type fates_param_reader_ctsm_impl
! NOTE(bja, 2017-01) these methods can NOT be part of the clm-fates
! interface type because they are called before the instance is
! initialized.
public :: FatesReadParameters
public :: FatesReadPFTs
private :: ParametersFromNetCDF
private :: SetParameterDimensions
private :: GetUsedDimensionSizes
logical :: debug = .false.
character(len=*), parameter, private :: sourcefile = &
__FILE__
contains
!-----------------------------------------------------------------------
subroutine FatesReadParameters()
use clm_varctl, only : use_fates, paramfile, fates_paramfile
use spmdMod, only : masterproc
implicit none
character(len=32) :: subname = 'FatesReadParameters'
class(fates_parameters_type), allocatable :: fates_params
logical :: is_host_file
if (masterproc) then
write(fates_log(), *) 'clmfates_interfaceMod.F90::'//trim(subname)//' :: CLM reading ED/FATES '//' parameters '
end if
allocate(fates_params)
call fates_params%Init() ! fates_params class, in FatesParameterInterfaceMod
call FatesRegisterParams(fates_params) !EDParamsMod, only operates on fates_params class
call SpitFireRegisterParams(fates_params) !SpitFire Mod, only operates of fates_params class
call PRTRegisterParams(fates_params) ! PRT mod, only operates on fates_params class
call FatesSynchronizedParamsInst%RegisterParams(fates_params) !Synchronized params class in Synchronized params mod, only operates on fates_params class
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 FatesReceiveParams(fates_params)
call SpitFireReceiveParams(fates_params)
call PRTReceiveParams(fates_params)
call FatesSynchronizedParamsInst%ReceiveParams(fates_params)
call fates_params%Destroy()
deallocate(fates_params)
end subroutine FatesReadParameters
!-----------------------------------------------------------------------
subroutine FatesReadPFTs()
use clm_varctl, only : use_fates, paramfile, fates_paramfile
use spmdMod, only : masterproc
use FatesParametersInterface, only : fates_parameters_type
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 spmdMod , only : masterproc
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=32) :: 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 (masterproc) 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, is_host_file, fates_params )
!
! !DESCRIPTION:
! Read 'fates_params' parameters from appropriate filename given 'is_host_file'.
!
! USES
use clm_varctl, only : fname_len, paramfile, fates_paramfile
! !ARGUMENTS:
class(fates_param_reader_ctsm_impl) :: this
logical, intent(in) :: is_host_file
class(fates_parameters_type), intent(inout) :: fates_params
!-----------------------------------------------------------------------
character(len=fname_len) :: filename ! file to read
filename = fates_paramfile
if (is_host_file) then
filename = paramfile
endif
call ParametersFromNetCDF(filename, is_host_file, fates_params)
end subroutine Read
!-----------------------------------------------------------------------
end module CLMFatesParamInterfaceMod