forked from NGEET/fates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFatesHistoryVariableType.F90
345 lines (280 loc) · 11.2 KB
/
FatesHistoryVariableType.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
module FatesHistoryVariableType
use FatesConstantsMod, only : r8 => fates_r8
use FatesGlobals, only : fates_log
use FatesIODimensionsMod, only : fates_io_dimension_type
use FatesIOVariableKindMod, only : fates_io_variable_kind_type
use FatesIOVariableKindMod, only : patch_r8, patch_ground_r8, patch_size_pft_r8
use FatesIOVariableKindMod, only : site_r8, site_ground_r8, site_size_pft_r8
use FatesIOVariableKindMod, only : site_size_r8, site_pft_r8, site_age_r8
use FatesIOVariableKindMod, only : site_coage_r8, site_coage_pft_r8
use FatesIOVariableKindMod, only : site_height_r8, patch_int
use FatesIOVariableKindMod, only : site_fuel_r8, site_cwdsc_r8, site_scag_r8
use FatesIOVariableKindMod, only : site_scagpft_r8, site_agepft_r8
use FatesIOVariableKindMod, only : site_can_r8, site_cnlf_r8, site_cnlfpft_r8
use FatesIOVariableKindMod, only : site_elem_r8, site_elpft_r8
use FatesIOVariableKindMod, only : site_elcwd_r8, site_elage_r8
use FatesIOVariableKindMod, only : iotype_index, site_agefuel_r8
implicit none
private ! By default everything is private
! Make public necessary subroutines and functions
! This type is instanteated in the HLM-FATES interface (clmfates_interfaceMod.F90)
type, public :: fates_history_variable_type
character(len=32) :: vname
character(len=24) :: units
character(len=128) :: long
character(len=24) :: use_default ! States whether a variable should be turned
! on the output files by default (active/inactive)
! It is a good idea to set inactive for very large
! or infrequently used output datasets
character(len=24) :: vtype
character(len=1) :: avgflag
integer :: upfreq ! Update frequency (this is for checks and flushing)
! 1 = dynamics "dyn" (daily)
! 2 = production "prod" (prob model tstep)
real(r8) :: flushval
integer :: dim_kinds_index
! Pointers (only one of these is allocated per variable)
real(r8), pointer :: r81d(:)
real(r8), pointer :: r82d(:,:)
real(r8), pointer :: r83d(:,:,:)
integer, pointer :: int1d(:)
integer, pointer :: int2d(:,:)
integer, pointer :: int3d(:,:,:)
contains
procedure :: Init
procedure :: Flush
procedure, private :: GetBounds
end type fates_history_variable_type
contains
subroutine Init(this, vname, units, long, use_default, &
vtype, avgflag, flushval, upfreq, num_dim_kinds, dim_kinds, dim_bounds)
implicit none
class(fates_history_variable_type), intent(inout) :: this
character(len=*), intent(in) :: vname
character(len=*), intent(in) :: units
character(len=*), intent(in) :: long
character(len=*), intent(in) :: use_default
character(len=*), intent(in) :: vtype
character(len=*), intent(in) :: avgflag
real(r8), intent(in) :: flushval ! If the type is an int we will round with nint
integer, intent(in) :: upfreq
integer, intent(in) :: num_dim_kinds
type(fates_io_dimension_type), intent(in) :: dim_bounds(:)
type(fates_io_variable_kind_type), intent(inout) :: dim_kinds(:)
integer :: dk_index
integer :: lb1, ub1, lb2, ub2
this%vname = vname
this%units = units
this%long = long
this%use_default = use_default
this%vtype = vtype
this%avgflag = avgflag
this%flushval = flushval
this%upfreq = upfreq
nullify(this%r81d)
nullify(this%r82d)
nullify(this%r83d)
nullify(this%int1d)
nullify(this%int2d)
nullify(this%int3d)
dk_index = iotype_index(trim(vtype), num_dim_kinds, dim_kinds)
this%dim_kinds_index = dk_index
call dim_kinds(dk_index)%set_active()
call this%GetBounds(0, dim_bounds, dim_kinds, lb1, ub1, lb2, ub2)
! NOTE(rgk, 2016-09) currently, all array spaces are flushed each
! time the update is called. The flush here on the initialization
! may be redundant, but will prevent issues in the future if we
! have host models where not all threads are updating the HHistory
! array spaces.
select case(trim(vtype))
case(patch_r8)
allocate(this%r81d(lb1:ub1))
this%r81d(:) = flushval
case(site_r8)
allocate(this%r81d(lb1:ub1))
this%r81d(:) = flushval
case(patch_ground_r8)
allocate(this%r82d(lb1:ub1, lb2:ub2))
this%r82d(:,:) = flushval
case(patch_size_pft_r8)
allocate(this%r82d(lb1:ub1, lb2:ub2))
this%r82d(:,:) = flushval
case(site_ground_r8)
allocate(this%r82d(lb1:ub1, lb2:ub2))
this%r82d(:,:) = flushval
case(site_size_pft_r8)
allocate(this%r82d(lb1:ub1, lb2:ub2))
this%r82d(:,:) = flushval
case(site_size_r8)
allocate(this%r82d(lb1:ub1, lb2:ub2))
this%r82d(:,:) = flushval
case(site_coage_r8)
allocate(this%r82d(lb1:ub1, lb2:ub2))
this%r82d(:,:) = flushval
case(site_coage_pft_r8)
allocate(this%r82d(lb1:ub1, lb2:ub2))
this%r82d(:,:) = flushval
case(site_pft_r8)
allocate(this%r82d(lb1:ub1, lb2:ub2))
this%r82d(:,:) = flushval
case(site_age_r8)
allocate(this%r82d(lb1:ub1, lb2:ub2))
this%r82d(:,:) = flushval
case(site_height_r8)
allocate(this%r82d(lb1:ub1, lb2:ub2))
this%r82d(:,:) = flushval
case(site_fuel_r8)
allocate(this%r82d(lb1:ub1, lb2:ub2))
this%r82d(:,:) = flushval
case(site_cwdsc_r8)
allocate(this%r82d(lb1:ub1, lb2:ub2))
this%r82d(:,:) = flushval
case(site_can_r8)
allocate(this%r82d(lb1:ub1, lb2:ub2))
this%r82d(:,:) = flushval
case(site_cnlf_r8)
allocate(this%r82d(lb1:ub1, lb2:ub2))
this%r82d(:,:) = flushval
case(site_cnlfpft_r8)
allocate(this%r82d(lb1:ub1, lb2:ub2))
this%r82d(:,:) = flushval
case(site_scag_r8)
allocate(this%r82d(lb1:ub1, lb2:ub2))
this%r82d(:,:) = flushval
case(site_scagpft_r8)
allocate(this%r82d(lb1:ub1, lb2:ub2))
this%r82d(:,:) = flushval
case(site_agepft_r8)
allocate(this%r82d(lb1:ub1, lb2:ub2))
this%r82d(:,:) = flushval
case(site_elem_r8)
allocate(this%r82d(lb1:ub1, lb2:ub2))
this%r82d(:,:) = flushval
case(site_elpft_r8)
allocate(this%r82d(lb1:ub1, lb2:ub2))
this%r82d(:,:) = flushval
case(site_elcwd_r8)
allocate(this%r82d(lb1:ub1, lb2:ub2))
this%r82d(:,:) = flushval
case(site_elage_r8)
allocate(this%r82d(lb1:ub1, lb2:ub2))
this%r82d(:,:) = flushval
case(site_agefuel_r8)
allocate(this%r82d(lb1:ub1, lb2:ub2))
this%r82d(:,:) = flushval
case default
write(fates_log(),*) 'Incompatible vtype passed to set_history_var'
write(fates_log(),*) 'vtype = ',trim(vtype),' ?'
stop
! end_run
end select
end subroutine Init
! =====================================================================================
subroutine GetBounds(this, thread, dim_bounds, dim_kinds, lb1, ub1, lb2, ub2)
use FatesIODimensionsMod, only : fates_io_dimension_type
implicit none
class(fates_history_variable_type), intent(inout) :: this
integer, intent(in) :: thread
type(fates_io_dimension_type), intent(in) :: dim_bounds(:)
type(fates_io_variable_kind_type), intent(in) :: dim_kinds(:)
integer, intent(out) :: lb1
integer, intent(out) :: ub1
integer, intent(out) :: lb2
integer, intent(out) :: ub2
! local
integer :: ndims
integer :: d_index
lb1 = 0
ub1 = 0
lb2 = 0
ub2 = 0
ndims = dim_kinds(this%dim_kinds_index)%ndims
! The thread = 0 case is the boundaries for the whole proc/node
if (thread==0) then
d_index = dim_kinds(this%dim_kinds_index)%dim1_index
lb1 = dim_bounds(d_index)%lower_bound
ub1 = dim_bounds(d_index)%upper_bound
if(ndims>1)then
d_index = dim_kinds(this%dim_kinds_index)%dim2_index
lb2 = dim_bounds(d_index)%lower_bound
ub2 = dim_bounds(d_index)%upper_bound
end if
else
d_index = dim_kinds(this%dim_kinds_index)%dim1_index
lb1 = dim_bounds(d_index)%clump_lower_bound(thread)
ub1 = dim_bounds(d_index)%clump_upper_bound(thread)
if(ndims>1)then
d_index = dim_kinds(this%dim_kinds_index)%dim2_index
lb2 = dim_bounds(d_index)%clump_lower_bound(thread)
ub2 = dim_bounds(d_index)%clump_upper_bound(thread)
end if
end if
end subroutine GetBounds
subroutine Flush(this, thread, dim_bounds, dim_kinds)
implicit none
class(fates_history_variable_type), intent(inout) :: this
integer, intent(in) :: thread
type(fates_io_dimension_type), intent(in) :: dim_bounds(:)
type(fates_io_variable_kind_type), intent(in) :: dim_kinds(:)
integer :: lb1, ub1, lb2, ub2
call this%GetBounds(thread, dim_bounds, dim_kinds, lb1, ub1, lb2, ub2)
select case(trim(dim_kinds(this%dim_kinds_index)%name))
case(patch_r8)
this%r81d(lb1:ub1) = this%flushval
case(site_r8)
this%r81d(lb1:ub1) = this%flushval
case(patch_ground_r8)
this%r82d(lb1:ub1, lb2:ub2) = this%flushval
case(patch_size_pft_r8)
this%r82d(lb1:ub1, lb2:ub2) = this%flushval
case(site_ground_r8)
this%r82d(lb1:ub1, lb2:ub2) = this%flushval
case(site_size_pft_r8)
this%r82d(lb1:ub1, lb2:ub2) = this%flushval
case(site_size_r8)
this%r82d(lb1:ub1, lb2:ub2) = this%flushval
case(site_coage_pft_r8)
this%r82d(lb1:ub1, lb2:ub2) = this%flushval
case(site_coage_r8)
this%r82d(lb1:ub1, lb2:ub2) = this%flushval
case(site_pft_r8)
this%r82d(lb1:ub1, lb2:ub2) = this%flushval
case(site_age_r8)
this%r82d(lb1:ub1, lb2:ub2) = this%flushval
case(site_height_r8)
this%r82d(lb1:ub1, lb2:ub2) = this%flushval
case(site_fuel_r8)
this%r82d(lb1:ub1, lb2:ub2) = this%flushval
case(site_cwdsc_r8)
this%r82d(lb1:ub1, lb2:ub2) = this%flushval
case(site_can_r8)
this%r82d(lb1:ub1, lb2:ub2) = this%flushval
case(site_cnlf_r8)
this%r82d(lb1:ub1, lb2:ub2) = this%flushval
case(site_cnlfpft_r8)
this%r82d(lb1:ub1, lb2:ub2) = this%flushval
case(site_scag_r8)
this%r82d(lb1:ub1, lb2:ub2) = this%flushval
case(site_scagpft_r8)
this%r82d(lb1:ub1, lb2:ub2) = this%flushval
case(site_agepft_r8)
this%r82d(lb1:ub1, lb2:ub2) = this%flushval
case(patch_int)
this%int1d(lb1:ub1) = nint(this%flushval)
case(site_elem_r8)
this%r82d(lb1:ub1, lb2:ub2) = this%flushval
case(site_elpft_r8)
this%r82d(lb1:ub1, lb2:ub2) = this%flushval
case(site_elcwd_r8)
this%r82d(lb1:ub1, lb2:ub2) = this%flushval
case(site_elage_r8)
this%r82d(lb1:ub1, lb2:ub2) = this%flushval
case(site_agefuel_r8)
this%r82d(lb1:ub1, lb2:ub2) = this%flushval
case default
write(fates_log(),*) 'fates history variable type undefined while flushing history variables'
stop
!end_run
end select
end subroutine Flush
end module FatesHistoryVariableType