-
Notifications
You must be signed in to change notification settings - Fork 92
/
FatesHistoryInterfaceMod.F90
6474 lines (5252 loc) · 357 KB
/
FatesHistoryInterfaceMod.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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
module FatesHistoryInterfaceMod
use FatesConstantsMod , only : r8 => fates_r8
use FatesConstantsMod , only : fates_avg_flag_length
use FatesConstantsMod , only : fates_short_string_length
use FatesConstantsMod , only : fates_long_string_length
use FatesConstantsMod , only : itrue,ifalse
use FatesConstantsMod , only : calloc_abs_error
use FatesConstantsMod , only : mg_per_kg
use FatesConstantsMod , only : pi_const
use FatesConstantsMod , only : nearzero
use FatesGlobals , only : fates_log
use FatesGlobals , only : endrun => fates_endrun
use EDTypesMod , only : nclmax
use EDTypesMod , only : ican_upper
use PRTGenericMod , only : element_pos
use PRTGenericMod , only : num_elements
use EDTypesMod , only : site_fluxdiags_type
use EDtypesMod , only : ed_site_type
use EDtypesMod , only : ed_cohort_type
use EDtypesMod , only : ed_patch_type
use EDtypesMod , only : AREA
use EDtypesMod , only : AREA_INV
use EDTypesMod , only : numWaterMem
use EDTypesMod , only : num_vegtemp_mem
use EDTypesMod , only : site_massbal_type
use PRTGenericMod , only : element_list
use EDTypesMod , only : N_DIST_TYPES
use EDTypesMod , only : dtype_ifall
use EDTypesMod , only : dtype_ifire
use EDTypesMod , only : dtype_ilog
use FatesIODimensionsMod , only : fates_io_dimension_type
use FatesIOVariableKindMod , only : fates_io_variable_kind_type
use FatesHistoryVariableType , only : fates_history_variable_type
use FatesInterfaceTypesMod , only : hlm_hio_ignore_val
use FatesInterfaceTypesMod , only : hlm_use_planthydro
use FatesInterfaceTypesMod , only : hlm_use_ed_st3
use FatesInterfaceTypesMod , only : hlm_use_cohort_age_tracking
use FatesInterfaceTypesMod , only : numpft
use FatesInterfaceTypesMod , only : hlm_freq_day
use FatesInterfaceTypesMod , only : hlm_parteh_mode
use EDParamsMod , only : ED_val_comp_excln
use EDParamsMod , only : ED_val_phen_coldtemp
use FatesInterfaceTypesMod , only : nlevsclass, nlevage
use FatesInterfaceTypesMod , only : nlevheight
use FatesInterfaceTypesMod , only : bc_in_type
use FatesInterfaceTypesMod , only : hlm_model_day
use FatesInterfaceTypesMod , only : nlevcoage
use FatesAllometryMod , only : CrownDepth
use EDPftvarcon , only : EDPftvarcon_inst
use PRTParametersMod , only : prt_params
! CIME Globals
use shr_log_mod , only : errMsg => shr_log_errMsg
use shr_infnan_mod , only : isnan => shr_infnan_isnan
use FatesConstantsMod , only : g_per_kg
use FatesConstantsMod , only : ha_per_m2
use FatesConstantsMod , only : days_per_sec
use FatesConstantsMod , only : sec_per_day
use FatesConstantsMod , only : days_per_year
use FatesConstantsMod , only : years_per_day
use FatesLitterMod , only : litter_type
use FatesConstantsMod , only : secondaryforest
use PRTGenericMod , only : leaf_organ, fnrt_organ, sapw_organ
use PRTGenericMod , only : struct_organ, store_organ, repro_organ
use PRTGenericMod , only : all_carbon_elements
use PRTGenericMod , only : carbon12_element
use PRTGenericMod , only : nitrogen_element, phosphorus_element
use PRTGenericMod , only : prt_carbon_allom_hyp
implicit none
private ! By default everything is private
! These variables hold the index of the history output structure so we don't
! have to constantly do name lookup when we want to populate the dataset
! These indices are set during "define_history_vars()" call to "set_history_var()"
! during the initialize phase. Definitions are not provided, for an explanation of
! the variable go to its registry. (IH_ signifies "index history")
!
! Because of the complex sub-gridscale structure of FATES, in which multiple patches and cohorts
! exist within a gridcell, along with vertical gradients within and between canopy layers, as well
! as distinct classes such as PFTs or fuel size bins, there are multiple different dimensions in
! which it is possible to output history variables to better understand what's going on.
!
! a key point is that, while the number of patches or cohorts can in principle be large, and
! the age and size indices of a given patch or cohort can be finely resolved, we collapse these
! continuously varying indices into bins of time-invariant width for the purposes of history
! outputting. This is because a given patch or cohort may not persist across a given interval
! of history averaging, so it is better to output all patches of cohorts whose index is within
! a given interval along the size or age bin.
!
! Another particularity of the issue of FATES shifting its subgrid structure frequently
! and possibly having multiple (or zero) patches or cohorts within a given bin is that, if you
! want to output an average quantities across some dimension, such as a mean carbon flux across
! patch area of a given age, in general it is better to output both the numerator and denominator
! of the averaging calculation separately, rather than the average itself, and then calculate
! the average in post-processing. So, e.g. this means outputting both the patch area and the
! product of the flux within each patch and the patch area as separate variables. Doing this
! allows conservation even when the weights are changing rapidly and simplifies the logic when
! the number of patches or cohorts may be anywhere from zero to a large number.
!
! So what this means is that anything that is disaggregated at the patch area requires
! outputting the patch age distribution (in units of patch area / site area) as the denominator
! of the average and then calculating the numerator of the average as XXX times the patch
! area so (so in units of XXX * patch area / site area). For cohort-level quantities,
! this requires outputting the number density (in units of individuals per site area), etc.
!
! For reference, some standardized abbreviations of the FATES dimensions are listed here:
! scls = size-class dimension
! cacls = cohort age-class dimension
! pft = the pft dimension
! age = the age bin dimension
! height = the height bin dimension
! cwdsc = the coarse woody debris size class dimension
!
! Since the netcdf interface can only handle variables with a certain number of dimensions,
! we have create some "multiplexed" dimensions that combine two or more dimensions into a
! single dimension. Examples of these are the following:
! scpf = size class x PFT
! cacpf = cohort age class x PFT
! cnlf = canopy layer x leaf layer
! cnlfpft = canopy layer x leaf layer x PFT
! scag = size class bin x age bin
! scagpft = size class bin x age bin x PFT
! agepft = age bin x PFT
! agefuel = age bin x fuel size class
! A recipe for adding a new history variable to this module:
! (1) decide what time frequency it makes sense to update the variable at, and what dimension(s)
! you want to output the variable on
! (2) add the ih_ integer variable in the immediately following section of the module.
! use the suffix as outlined above for the dimension you are using.
! (3) define a corresponding hio_ variable by associating it to the ih_ variable
! in the associate section of the subroutine that corresponds to the time-updating
! frequency that you've chosen
! (i.e. if half-hourly, then work in subroutine update_history_prod; if daily,
! then work in subroutine update_history_dyn)
! (4) within that subroutine, add the logic that passes the information from the
! fates-native variable (possibly on a patch or cohort structure) to the history
! hio_ variable that you've associated to.
! (5) add the variable name, metadata, units, dimension, updating frequency, the ih_ variable
! index, etc via a call to the set_history_var method in the subroutine define_history_vars.
!
! Indices to 1D Patch variables
integer :: ih_storec_si
integer :: ih_leafc_si
integer :: ih_sapwc_si
integer :: ih_fnrtc_si
integer :: ih_reproc_si
integer :: ih_totvegc_si
integer :: ih_storen_si
integer :: ih_storentfrac_si
integer :: ih_leafn_si
integer :: ih_sapwn_si
integer :: ih_fnrtn_si
integer :: ih_repron_si
integer :: ih_totvegn_si
integer :: ih_storep_si
integer :: ih_storeptfrac_si
integer :: ih_leafp_si
integer :: ih_sapwp_si
integer :: ih_fnrtp_si
integer :: ih_reprop_si
integer :: ih_totvegp_si
integer,public :: ih_nh4uptake_si
integer,public :: ih_no3uptake_si
integer,public :: ih_puptake_si
integer :: ih_cefflux_si
integer :: ih_nefflux_si
integer :: ih_pefflux_si
integer :: ih_nneed_si
integer :: ih_pneed_si
integer :: ih_trimming_si
integer :: ih_area_plant_si
integer :: ih_area_trees_si
integer :: ih_cwd_elcwd
integer :: ih_litter_in_si ! carbon only
integer :: ih_litter_out_si ! carbon only
integer :: ih_seed_bank_si ! carbon only
integer :: ih_seeds_in_si ! carbon only
integer :: ih_litter_in_elem
integer :: ih_litter_out_elem
integer :: ih_seed_bank_elem
integer :: ih_seeds_in_local_elem
integer :: ih_seeds_in_extern_elem
integer :: ih_seed_decay_elem
integer :: ih_seed_germ_elem
integer :: ih_fines_ag_elem
integer :: ih_fines_bg_elem
integer :: ih_cwd_ag_elem
integer :: ih_cwd_bg_elem
integer :: ih_burn_flux_elem
! Size-class x PFT mass states
integer :: ih_bstor_canopy_si_scpf
integer :: ih_bstor_understory_si_scpf
integer :: ih_bleaf_canopy_si_scpf
integer :: ih_bleaf_understory_si_scpf
integer :: ih_totvegn_scpf
integer :: ih_leafn_scpf
integer :: ih_fnrtn_scpf
integer :: ih_storen_scpf
integer :: ih_storentfrac_canopy_scpf
integer :: ih_storentfrac_understory_scpf
integer :: ih_sapwn_scpf
integer :: ih_repron_scpf
integer,public :: ih_nh4uptake_scpf
integer,public :: ih_no3uptake_scpf
integer :: ih_nefflux_scpf
integer :: ih_nneed_scpf
integer :: ih_totvegc_scpf
integer :: ih_leafc_scpf
integer :: ih_fnrtc_scpf
integer :: ih_storec_scpf
integer :: ih_sapwc_scpf
integer :: ih_reproc_scpf
integer :: ih_cefflux_scpf
integer :: ih_totvegp_scpf
integer :: ih_leafp_scpf
integer :: ih_fnrtp_scpf
integer :: ih_reprop_scpf
integer :: ih_storep_scpf
integer :: ih_storeptfrac_canopy_scpf
integer :: ih_storeptfrac_understory_scpf
integer :: ih_sapwp_scpf
integer,public :: ih_puptake_scpf
integer :: ih_pefflux_scpf
integer :: ih_pneed_scpf
integer :: ih_daily_temp
integer :: ih_daily_rh
integer :: ih_daily_prec
integer :: ih_bstore_si
integer :: ih_bdead_si
integer :: ih_balive_si
integer :: ih_bleaf_si
integer :: ih_bsapwood_si
integer :: ih_bfineroot_si
integer :: ih_btotal_si
integer :: ih_agb_si
integer :: ih_npp_si
integer :: ih_gpp_si
integer :: ih_aresp_si
integer :: ih_maint_resp_si
integer :: ih_growth_resp_si
integer :: ih_ar_canopy_si
integer :: ih_gpp_canopy_si
integer :: ih_ar_understory_si
integer :: ih_gpp_understory_si
integer :: ih_canopy_biomass_si
integer :: ih_understory_biomass_si
integer :: ih_primaryland_fusion_error_si
integer :: ih_disturbance_rate_p2p_si
integer :: ih_disturbance_rate_p2s_si
integer :: ih_disturbance_rate_s2s_si
integer :: ih_fire_disturbance_rate_si
integer :: ih_logging_disturbance_rate_si
integer :: ih_fall_disturbance_rate_si
integer :: ih_potential_disturbance_rate_si
integer :: ih_harvest_carbonflux_si
! Indices to site by size-class by age variables
integer :: ih_nplant_si_scag
integer :: ih_nplant_canopy_si_scag
integer :: ih_nplant_understory_si_scag
integer :: ih_ddbh_canopy_si_scag
integer :: ih_ddbh_understory_si_scag
integer :: ih_mortality_canopy_si_scag
integer :: ih_mortality_understory_si_scag
! Indices to site by size-class by age by pft variables
integer :: ih_nplant_si_scagpft
! Indices to site by patch age by pft variables
integer :: ih_biomass_si_agepft
integer :: ih_npp_si_agepft
integer :: ih_scorch_height_si_agepft
! Indices to (site) variables
integer :: ih_nep_si
integer :: ih_hr_si
integer :: ih_c_stomata_si
integer :: ih_c_lblayer_si
integer :: ih_fire_c_to_atm_si
integer :: ih_cbal_err_fates_si
integer :: ih_err_fates_si
integer :: ih_npatches_si
integer :: ih_ncohorts_si
integer :: ih_demotion_carbonflux_si
integer :: ih_promotion_carbonflux_si
integer :: ih_canopy_mortality_carbonflux_si
integer :: ih_understory_mortality_carbonflux_si
integer :: ih_canopy_spread_si
integer :: ih_npp_leaf_si
integer :: ih_npp_seed_si
integer :: ih_npp_stem_si
integer :: ih_npp_froot_si
integer :: ih_npp_croot_si
integer :: ih_npp_stor_si
integer :: ih_leaf_mr_si
integer :: ih_froot_mr_si
integer :: ih_livestem_mr_si
integer :: ih_livecroot_mr_si
integer :: ih_fraction_secondary_forest_si
integer :: ih_biomass_secondary_forest_si
integer :: ih_woodproduct_si
integer :: ih_h2oveg_si
integer :: ih_h2oveg_dead_si
integer :: ih_h2oveg_recruit_si
integer :: ih_h2oveg_growturn_err_si
integer :: ih_h2oveg_hydro_err_si
integer :: ih_site_cstatus_si
integer :: ih_site_dstatus_si
integer :: ih_gdd_si
integer :: ih_site_nchilldays_si
integer :: ih_site_ncolddays_si
integer :: ih_cleafoff_si
integer :: ih_cleafon_si
integer :: ih_dleafoff_si
integer :: ih_dleafon_si
integer :: ih_meanliqvol_si
integer :: ih_nesterov_fire_danger_si
integer :: ih_fire_nignitions_si
integer :: ih_fire_fdi_si
integer :: ih_fire_intensity_area_product_si
integer :: ih_spitfire_ros_si
integer :: ih_fire_ros_area_product_si
integer :: ih_effect_wspeed_si
integer :: ih_tfc_ros_si
integer :: ih_tfc_ros_area_product_si
integer :: ih_fire_intensity_si
integer :: ih_fire_area_si
integer :: ih_fire_fuel_bulkd_si
integer :: ih_fire_fuel_eff_moist_si
integer :: ih_fire_fuel_sav_si
integer :: ih_fire_fuel_mef_si
integer :: ih_sum_fuel_si
integer :: ih_fragmentation_scaler_sl
integer :: ih_nplant_si_scpf
integer :: ih_gpp_si_scpf
integer :: ih_npp_totl_si_scpf
integer :: ih_npp_leaf_si_scpf
integer :: ih_npp_seed_si_scpf
integer :: ih_npp_fnrt_si_scpf
integer :: ih_npp_bgsw_si_scpf
integer :: ih_npp_bgdw_si_scpf
integer :: ih_npp_agsw_si_scpf
integer :: ih_npp_agdw_si_scpf
integer :: ih_npp_stor_si_scpf
integer :: ih_mortality_canopy_si_scpf
integer :: ih_mortality_understory_si_scpf
integer :: ih_nplant_canopy_si_scpf
integer :: ih_nplant_understory_si_scpf
integer :: ih_ddbh_canopy_si_scpf
integer :: ih_ddbh_understory_si_scpf
integer :: ih_gpp_canopy_si_scpf
integer :: ih_gpp_understory_si_scpf
integer :: ih_ar_canopy_si_scpf
integer :: ih_ar_understory_si_scpf
integer :: ih_ddbh_si_scpf
integer :: ih_growthflux_si_scpf
integer :: ih_growthflux_fusion_si_scpf
integer :: ih_ba_si_scpf
integer :: ih_agb_si_scpf
integer :: ih_m1_si_scpf
integer :: ih_m2_si_scpf
integer :: ih_m3_si_scpf
integer :: ih_m4_si_scpf
integer :: ih_m5_si_scpf
integer :: ih_m6_si_scpf
integer :: ih_m7_si_scpf
integer :: ih_m8_si_scpf
integer :: ih_m9_si_scpf
integer :: ih_m10_si_scpf
integer :: ih_crownfiremort_si_scpf
integer :: ih_cambialfiremort_si_scpf
integer :: ih_m10_si_capf
integer :: ih_nplant_si_capf
integer :: ih_ar_si_scpf
integer :: ih_ar_grow_si_scpf
integer :: ih_ar_maint_si_scpf
integer :: ih_ar_darkm_si_scpf
integer :: ih_ar_agsapm_si_scpf
integer :: ih_ar_crootm_si_scpf
integer :: ih_ar_frootm_si_scpf
integer :: ih_c13disc_si_scpf
! indices to (site x scls [size class bins]) variables
integer :: ih_ba_si_scls
integer :: ih_nplant_si_scls
integer :: ih_nplant_canopy_si_scls
integer :: ih_nplant_understory_si_scls
integer :: ih_lai_canopy_si_scls
integer :: ih_lai_understory_si_scls
integer :: ih_sai_canopy_si_scls
integer :: ih_sai_understory_si_scls
integer :: ih_mortality_canopy_si_scls
integer :: ih_mortality_understory_si_scls
integer :: ih_demotion_rate_si_scls
integer :: ih_promotion_rate_si_scls
integer :: ih_trimming_canopy_si_scls
integer :: ih_trimming_understory_si_scls
integer :: ih_crown_area_canopy_si_scls
integer :: ih_crown_area_understory_si_scls
integer :: ih_ddbh_canopy_si_scls
integer :: ih_ddbh_understory_si_scls
integer :: ih_agb_si_scls
integer :: ih_biomass_si_scls
! mortality vars
integer :: ih_m1_si_scls
integer :: ih_m2_si_scls
integer :: ih_m3_si_scls
integer :: ih_m4_si_scls
integer :: ih_m5_si_scls
integer :: ih_m6_si_scls
integer :: ih_m7_si_scls
integer :: ih_m8_si_scls
integer :: ih_m9_si_scls
integer :: ih_m10_si_scls
integer :: ih_m10_si_cacls
integer :: ih_nplant_si_cacls
! lots of non-default diagnostics for understanding canopy versus understory carbon balances
integer :: ih_rdark_canopy_si_scls
integer :: ih_livestem_mr_canopy_si_scls
integer :: ih_livecroot_mr_canopy_si_scls
integer :: ih_froot_mr_canopy_si_scls
integer :: ih_resp_g_canopy_si_scls
integer :: ih_resp_m_canopy_si_scls
integer :: ih_leaf_md_canopy_si_scls
integer :: ih_root_md_canopy_si_scls
integer :: ih_carbon_balance_canopy_si_scls
integer :: ih_bstore_md_canopy_si_scls
integer :: ih_bdead_md_canopy_si_scls
integer :: ih_bsw_md_canopy_si_scls
integer :: ih_seed_prod_canopy_si_scls
integer :: ih_npp_leaf_canopy_si_scls
integer :: ih_npp_fnrt_canopy_si_scls
integer :: ih_npp_sapw_canopy_si_scls
integer :: ih_npp_dead_canopy_si_scls
integer :: ih_npp_seed_canopy_si_scls
integer :: ih_npp_stor_canopy_si_scls
integer :: ih_rdark_understory_si_scls
integer :: ih_livestem_mr_understory_si_scls
integer :: ih_livecroot_mr_understory_si_scls
integer :: ih_froot_mr_understory_si_scls
integer :: ih_resp_g_understory_si_scls
integer :: ih_resp_m_understory_si_scls
integer :: ih_leaf_md_understory_si_scls
integer :: ih_root_md_understory_si_scls
integer :: ih_carbon_balance_understory_si_scls
integer :: ih_bsw_md_understory_si_scls
integer :: ih_bdead_md_understory_si_scls
integer :: ih_bstore_md_understory_si_scls
integer :: ih_seed_prod_understory_si_scls
integer :: ih_npp_leaf_understory_si_scls
integer :: ih_npp_fnrt_understory_si_scls
integer :: ih_npp_sapw_understory_si_scls
integer :: ih_npp_dead_understory_si_scls
integer :: ih_npp_seed_understory_si_scls
integer :: ih_npp_stor_understory_si_scls
integer :: ih_yesterdaycanopylevel_canopy_si_scls
integer :: ih_yesterdaycanopylevel_understory_si_scls
! indices to (site x pft) variables
integer :: ih_biomass_si_pft
integer :: ih_leafbiomass_si_pft
integer :: ih_storebiomass_si_pft
integer :: ih_nindivs_si_pft
integer :: ih_recruitment_si_pft
integer :: ih_mortality_si_pft
integer :: ih_crownarea_si_pft
integer :: ih_canopycrownarea_si_pft
integer :: ih_gpp_si_pft
integer :: ih_npp_si_pft
! indices to (site x patch-age) variables
integer :: ih_area_si_age
integer :: ih_lai_si_age
integer :: ih_canopy_area_si_age
integer :: ih_gpp_si_age
integer :: ih_npp_si_age
integer :: ih_ncl_si_age
integer :: ih_npatches_si_age
integer :: ih_zstar_si_age
integer :: ih_biomass_si_age
integer :: ih_c_stomata_si_age
integer :: ih_c_lblayer_si_age
integer :: ih_agesince_anthrodist_si_age
integer :: ih_secondaryforest_area_si_age
integer :: ih_area_burnt_si_age
! integer :: ih_fire_rate_of_spread_front_si_age
integer :: ih_fire_intensity_si_age
integer :: ih_fire_sum_fuel_si_age
! indices to (site x height) variables
integer :: ih_canopy_height_dist_si_height
integer :: ih_leaf_height_dist_si_height
! Indices to hydraulics variables
integer :: ih_errh2o_scpf
integer :: ih_tran_scpf
! integer :: ih_h2osoi_si_scagpft ! hijacking the scagpft dimension instead of creating a new shsl dimension
integer :: ih_sapflow_scpf
integer :: ih_sapflow_si
integer :: ih_iterh1_scpf
integer :: ih_iterh2_scpf
integer :: ih_supsub_scpf
integer :: ih_ath_scpf
integer :: ih_tth_scpf
integer :: ih_sth_scpf
integer :: ih_lth_scpf
integer :: ih_awp_scpf
integer :: ih_twp_scpf
integer :: ih_swp_scpf
integer :: ih_lwp_scpf
integer :: ih_aflc_scpf
integer :: ih_tflc_scpf
integer :: ih_sflc_scpf
integer :: ih_lflc_scpf
integer :: ih_btran_scpf
! Hydro: Soil water states
integer :: ih_rootwgt_soilvwc_si
integer :: ih_rootwgt_soilvwcsat_si
integer :: ih_rootwgt_soilmatpot_si
! Hydro: Soil water state by layer
integer :: ih_soilmatpot_sl
integer :: ih_soilvwc_sl
integer :: ih_soilvwcsat_sl
! Hydro: Root water Uptake rates
integer :: ih_rootuptake_si
integer :: ih_rootuptake_sl
integer :: ih_rootuptake0_scpf
integer :: ih_rootuptake10_scpf
integer :: ih_rootuptake50_scpf
integer :: ih_rootuptake100_scpf
! indices to (site x fuel class) variables
integer :: ih_litter_moisture_si_fuel
integer :: ih_burnt_frac_litter_si_fuel
integer :: ih_fuel_amount_si_fuel
! indices to (site x cwd size class) variables
integer :: ih_cwd_ag_si_cwdsc
integer :: ih_cwd_bg_si_cwdsc
integer :: ih_cwd_ag_in_si_cwdsc
integer :: ih_cwd_bg_in_si_cwdsc
integer :: ih_cwd_ag_out_si_cwdsc
integer :: ih_cwd_bg_out_si_cwdsc
! indices to (site x [canopy layer x leaf layer]) variables
integer :: ih_parsun_z_si_cnlf
integer :: ih_parsha_z_si_cnlf
integer :: ih_laisun_z_si_cnlf
integer :: ih_laisha_z_si_cnlf
integer :: ih_fabd_sun_si_cnlf
integer :: ih_fabd_sha_si_cnlf
integer :: ih_fabi_sun_si_cnlf
integer :: ih_fabi_sha_si_cnlf
integer :: ih_ts_net_uptake_si_cnlf
integer :: ih_crownarea_si_cnlf
integer :: ih_parprof_dir_si_cnlf
integer :: ih_parprof_dif_si_cnlf
! indices to (site x [canopy layer x leaf layer x pft]) variables
integer :: ih_parsun_z_si_cnlfpft
integer :: ih_parsha_z_si_cnlfpft
integer :: ih_laisun_z_si_cnlfpft
integer :: ih_laisha_z_si_cnlfpft
integer :: ih_fabd_sun_si_cnlfpft
integer :: ih_fabd_sha_si_cnlfpft
integer :: ih_fabi_sun_si_cnlfpft
integer :: ih_fabi_sha_si_cnlfpft
integer :: ih_parprof_dir_si_cnlfpft
integer :: ih_parprof_dif_si_cnlfpft
! indices to (site x canopy layer) variables
integer :: ih_parsun_top_si_can
integer :: ih_parsha_top_si_can
integer :: ih_laisun_top_si_can
integer :: ih_laisha_top_si_can
integer :: ih_fabd_sun_top_si_can
integer :: ih_fabd_sha_top_si_can
integer :: ih_fabi_sun_top_si_can
integer :: ih_fabi_sha_top_si_can
integer :: ih_crownarea_si_can
! indices to (patch age x fuel size class) variables
integer :: ih_fuel_amount_age_fuel
! The number of variable dim/kind types we have defined (static)
integer, parameter, public :: fates_history_num_dimensions = 50
integer, parameter, public :: fates_history_num_dim_kinds = 50
type, public :: fates_history_interface_type
! Instance of the list of history output varialbes
type(fates_history_variable_type), allocatable :: hvars(:)
integer, private :: num_history_vars_
! Instanteat one registry of the different dimension/kinds (dk)
! All output variables will have a pointer to one of these dk's
type(fates_io_variable_kind_type) :: dim_kinds(fates_history_num_dim_kinds)
! This is a structure that explains where FATES patch boundaries
! on each thread point to in the host IO array, this structure is
! allocated by number of threads. This could be dynamically
! allocated, but is unlikely to change...?
type(fates_io_dimension_type) :: dim_bounds(fates_history_num_dimensions)
!! THESE WERE EXPLICITLY PRIVATE WHEN TYPE WAS PUBLIC
integer, private :: patch_index_, column_index_, levgrnd_index_, levscpf_index_
integer, private :: levscls_index_, levpft_index_, levage_index_
integer, private :: levfuel_index_, levcwdsc_index_, levscag_index_
integer, private :: levcan_index_, levcnlf_index_, levcnlfpft_index_
integer, private :: levscagpft_index_, levagepft_index_
integer, private :: levheight_index_, levagefuel_index_
integer, private :: levelem_index_, levelpft_index_
integer, private :: levelcwd_index_, levelage_index_
integer, private :: levcacls_index_, levcapf_index_
contains
procedure :: Init
procedure :: SetThreadBoundsEach
procedure :: initialize_history_vars
procedure :: assemble_history_output_types
procedure :: update_history_dyn
procedure :: update_history_hifrq
procedure :: update_history_hydraulics
! 'get' methods used by external callers to access private read only data
procedure :: num_history_vars
procedure :: patch_index
procedure :: column_index
procedure :: levgrnd_index
procedure :: levscpf_index
procedure :: levscls_index
procedure :: levcapf_index
procedure :: levcacls_index
procedure :: levpft_index
procedure :: levage_index
procedure :: levfuel_index
procedure :: levcwdsc_index
procedure :: levcan_index
procedure :: levcnlf_index
procedure :: levcnlfpft_index
procedure :: levscag_index
procedure :: levscagpft_index
procedure :: levagepft_index
procedure :: levheight_index
procedure :: levelem_index
procedure :: levelpft_index
procedure :: levelcwd_index
procedure :: levelage_index
procedure :: levagefuel_index
! private work functions
procedure, private :: define_history_vars
procedure, private :: set_history_var
procedure, private :: init_dim_kinds_maps
procedure, private :: set_dim_indices
procedure, private :: set_patch_index
procedure, private :: set_column_index
procedure, private :: set_levgrnd_index
procedure, private :: set_levscpf_index
procedure, private :: set_levcacls_index
procedure, private :: set_levcapf_index
procedure, private :: set_levscls_index
procedure, private :: set_levpft_index
procedure, private :: set_levage_index
procedure, private :: set_levfuel_index
procedure, private :: set_levcwdsc_index
procedure, private :: set_levcan_index
procedure, private :: set_levcnlf_index
procedure, private :: set_levcnlfpft_index
procedure, private :: set_levscag_index
procedure, private :: set_levscagpft_index
procedure, private :: set_levagepft_index
procedure, private :: set_levheight_index
procedure, private :: set_levagefuel_index
procedure, private :: set_levelem_index
procedure, private :: set_levelpft_index
procedure, private :: set_levelcwd_index
procedure, private :: set_levelage_index
procedure, public :: flush_hvars
end type fates_history_interface_type
character(len=*), parameter :: sourcefile = &
__FILE__
! The instance of the type
type(fates_history_interface_type), public :: fates_hist
contains
! ======================================================================
subroutine Init(this, num_threads, fates_bounds)
use FatesIODimensionsMod, only : patch, column, levgrnd, levscpf
use FatesIODimensionsMod, only : levscls, levpft, levage
use FatesIODimensionsMod, only : levcacls, levcapf
use FatesIODimensionsMod, only : levfuel, levcwdsc, levscag
use FatesIODimensionsMod, only : levscagpft, levagepft
use FatesIODimensionsMod, only : levcan, levcnlf, levcnlfpft
use FatesIODimensionsMod, only : fates_bounds_type
use FatesIODimensionsMod, only : levheight, levagefuel
use FatesIODimensionsMod, only : levelem, levelpft
use FatesIODimensionsMod, only : levelcwd, levelage
implicit none
class(fates_history_interface_type), intent(inout) :: this
integer, intent(in) :: num_threads
type(fates_bounds_type), intent(in) :: fates_bounds
integer :: dim_count = 0
dim_count = dim_count + 1
call this%set_patch_index(dim_count)
call this%dim_bounds(dim_count)%Init(patch, num_threads, &
fates_bounds%patch_begin, fates_bounds%patch_end)
dim_count = dim_count + 1
call this%set_column_index(dim_count)
call this%dim_bounds(dim_count)%Init(column, num_threads, &
fates_bounds%column_begin, fates_bounds%column_end)
dim_count = dim_count + 1
call this%set_levgrnd_index(dim_count)
call this%dim_bounds(dim_count)%Init(levgrnd, num_threads, &
fates_bounds%ground_begin, fates_bounds%ground_end)
dim_count = dim_count + 1
call this%set_levscpf_index(dim_count)
call this%dim_bounds(dim_count)%Init(levscpf, num_threads, &
fates_bounds%sizepft_class_begin, fates_bounds%sizepft_class_end)
dim_count = dim_count + 1
call this%set_levscls_index(dim_count)
call this%dim_bounds(dim_count)%Init(levscls, num_threads, &
fates_bounds%size_class_begin, fates_bounds%size_class_end)
dim_count = dim_count + 1
call this%set_levcacls_index(dim_count)
call this%dim_bounds(dim_count)%Init(levcacls, num_threads, &
fates_bounds%coage_class_begin, fates_bounds%coage_class_end)
dim_count = dim_count + 1
call this%set_levcapf_index(dim_count)
call this%dim_bounds(dim_count)%Init(levcapf, num_threads, &
fates_bounds%coagepf_class_begin, fates_bounds%coagepf_class_end)
dim_count = dim_count + 1
call this%set_levpft_index(dim_count)
call this%dim_bounds(dim_count)%Init(levpft, num_threads, &
fates_bounds%pft_class_begin, fates_bounds%pft_class_end)
dim_count = dim_count + 1
call this%set_levage_index(dim_count)
call this%dim_bounds(dim_count)%Init(levage, num_threads, &
fates_bounds%age_class_begin, fates_bounds%age_class_end)
dim_count = dim_count + 1
call this%set_levfuel_index(dim_count)
call this%dim_bounds(dim_count)%Init(levfuel, num_threads, &
fates_bounds%fuel_begin, fates_bounds%fuel_end)
dim_count = dim_count + 1
call this%set_levcwdsc_index(dim_count)
call this%dim_bounds(dim_count)%Init(levcwdsc, num_threads, &
fates_bounds%cwdsc_begin, fates_bounds%cwdsc_end)
dim_count = dim_count + 1
call this%set_levcan_index(dim_count)
call this%dim_bounds(dim_count)%Init(levcan, num_threads, &
fates_bounds%can_begin, fates_bounds%can_end)
dim_count = dim_count + 1
call this%set_levcnlf_index(dim_count)
call this%dim_bounds(dim_count)%Init(levcnlf, num_threads, &
fates_bounds%cnlf_begin, fates_bounds%cnlf_end)
dim_count = dim_count + 1
call this%set_levcnlfpft_index(dim_count)
call this%dim_bounds(dim_count)%Init(levcnlfpft, num_threads, &
fates_bounds%cnlfpft_begin, fates_bounds%cnlfpft_end)
dim_count = dim_count + 1
call this%set_levscag_index(dim_count)
call this%dim_bounds(dim_count)%Init(levscag, num_threads, &
fates_bounds%sizeage_class_begin, fates_bounds%sizeage_class_end)
dim_count = dim_count + 1
call this%set_levscagpft_index(dim_count)
call this%dim_bounds(dim_count)%Init(levscagpft, num_threads, &
fates_bounds%sizeagepft_class_begin, fates_bounds%sizeagepft_class_end)
dim_count = dim_count + 1
call this%set_levagepft_index(dim_count)
call this%dim_bounds(dim_count)%Init(levagepft, num_threads, &
fates_bounds%agepft_class_begin, fates_bounds%agepft_class_end)
dim_count = dim_count + 1
call this%set_levheight_index(dim_count)
call this%dim_bounds(dim_count)%Init(levheight, num_threads, &
fates_bounds%height_begin, fates_bounds%height_end)
dim_count = dim_count + 1
call this%set_levelem_index(dim_count)
call this%dim_bounds(dim_count)%Init(levelem, num_threads, &
fates_bounds%elem_begin, fates_bounds%elem_end)
dim_count = dim_count + 1
call this%set_levelpft_index(dim_count)
call this%dim_bounds(dim_count)%Init(levelpft, num_threads, &
fates_bounds%elpft_begin, fates_bounds%elpft_end)
dim_count = dim_count + 1
call this%set_levelcwd_index(dim_count)
call this%dim_bounds(dim_count)%Init(levelcwd, num_threads, &
fates_bounds%elcwd_begin, fates_bounds%elcwd_end)
dim_count = dim_count + 1
call this%set_levelage_index(dim_count)
call this%dim_bounds(dim_count)%Init(levelage, num_threads, &
fates_bounds%elage_begin, fates_bounds%elage_end)
dim_count = dim_count + 1
call this%set_levagefuel_index(dim_count)
call this%dim_bounds(dim_count)%Init(levagefuel, num_threads, &
fates_bounds%agefuel_begin, fates_bounds%agefuel_end)
end subroutine Init
! ======================================================================
subroutine SetThreadBoundsEach(this, thread_index, thread_bounds)
use FatesIODimensionsMod, only : fates_bounds_type
implicit none
class(fates_history_interface_type), intent(inout) :: this
integer, intent(in) :: thread_index
type(fates_bounds_type), intent(in) :: thread_bounds
integer :: index
index = this%patch_index()
call this%dim_bounds(index)%SetThreadBounds(thread_index, &
thread_bounds%patch_begin, thread_bounds%patch_end)
index = this%column_index()
call this%dim_bounds(index)%SetThreadBounds(thread_index, &
thread_bounds%column_begin, thread_bounds%column_end)
index = this%levgrnd_index()
call this%dim_bounds(index)%SetThreadBounds(thread_index, &
thread_bounds%ground_begin, thread_bounds%ground_end)
index = this%levscpf_index()
call this%dim_bounds(index)%SetThreadBounds(thread_index, &
thread_bounds%sizepft_class_begin, thread_bounds%sizepft_class_end)
index = this%levscls_index()
call this%dim_bounds(index)%SetThreadBounds(thread_index, &
thread_bounds%size_class_begin, thread_bounds%size_class_end)
index = this%levcacls_index()
call this%dim_bounds(index)%SetThreadBounds(thread_index, &
thread_bounds%coage_class_begin, thread_bounds%coage_class_end)
index = this%levcapf_index()
call this%dim_bounds(index)%SetThreadBounds(thread_index, &
thread_bounds%coagepf_class_begin, thread_bounds%coagepf_class_end)
index = this%levpft_index()
call this%dim_bounds(index)%SetThreadBounds(thread_index, &
thread_bounds%pft_class_begin, thread_bounds%pft_class_end)
index = this%levage_index()
call this%dim_bounds(index)%SetThreadBounds(thread_index, &
thread_bounds%age_class_begin, thread_bounds%age_class_end)
index = this%levfuel_index()
call this%dim_bounds(index)%SetThreadBounds(thread_index, &
thread_bounds%fuel_begin, thread_bounds%fuel_end)
index = this%levcwdsc_index()
call this%dim_bounds(index)%SetThreadBounds(thread_index, &
thread_bounds%cwdsc_begin, thread_bounds%cwdsc_end)
index = this%levcan_index()
call this%dim_bounds(index)%SetThreadBounds(thread_index, &
thread_bounds%can_begin, thread_bounds%can_end)
index = this%levcnlf_index()
call this%dim_bounds(index)%SetThreadBounds(thread_index, &
thread_bounds%cnlf_begin, thread_bounds%cnlf_end)
index = this%levcnlfpft_index()
call this%dim_bounds(index)%SetThreadBounds(thread_index, &
thread_bounds%cnlfpft_begin, thread_bounds%cnlfpft_end)
index = this%levscag_index()
call this%dim_bounds(index)%SetThreadBounds(thread_index, &
thread_bounds%sizeage_class_begin, thread_bounds%sizeage_class_end)
index = this%levscagpft_index()
call this%dim_bounds(index)%SetThreadBounds(thread_index, &
thread_bounds%sizeagepft_class_begin, thread_bounds%sizeagepft_class_end)
index = this%levagepft_index()
call this%dim_bounds(index)%SetThreadBounds(thread_index, &
thread_bounds%agepft_class_begin, thread_bounds%agepft_class_end)
index = this%levheight_index()
call this%dim_bounds(index)%SetThreadBounds(thread_index, &
thread_bounds%height_begin, thread_bounds%height_end)
index = this%levelem_index()
call this%dim_bounds(index)%SetThreadBounds(thread_index, &
thread_bounds%elem_begin, thread_bounds%elem_end)
index = this%levelpft_index()
call this%dim_bounds(index)%SetThreadBounds(thread_index, &
thread_bounds%elpft_begin, thread_bounds%elpft_end)
index = this%levelcwd_index()
call this%dim_bounds(index)%SetThreadBounds(thread_index, &
thread_bounds%elcwd_begin, thread_bounds%elcwd_end)
index = this%levelage_index()
call this%dim_bounds(index)%SetThreadBounds(thread_index, &
thread_bounds%elage_begin, thread_bounds%elage_end)
index = this%levagefuel_index()
call this%dim_bounds(index)%SetThreadBounds(thread_index, &
thread_bounds%agefuel_begin, thread_bounds%agefuel_end)