-
Notifications
You must be signed in to change notification settings - Fork 92
/
FatesRestartInterfaceMod.F90
3655 lines (2892 loc) · 177 KB
/
FatesRestartInterfaceMod.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 FatesRestartInterfaceMod
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
use FatesConstantsMod, only : ifalse
use FatesConstantsMod, only : fates_unset_r8, fates_unset_int
use FatesConstantsMod, only : primaryforest
use FatesConstantsMod, only : nearzero
use FatesConstantsMod, only : default_regeneration
use FatesConstantsMod, only : TRS_regeneration
use FatesGlobals, only : fates_log
use FatesGlobals, only : endrun => fates_endrun
use FatesIODimensionsMod, only : fates_io_dimension_type
use FatesIOVariableKindMod, only : fates_io_variable_kind_type
use FatesRestartVariableMod, only : fates_restart_variable_type
use FatesInterfaceTypesMod, only : nlevcoage
use FatesInterfaceTypesMod, only : bc_in_type
use FatesInterfaceTypesMod, only : bc_out_type
use FatesInterfaceTypesMod, only : hlm_use_planthydro
use FatesInterfaceTypesMod, only : hlm_parteh_mode
use FatesInterfaceTypesMod, only : hlm_use_sp
use FatesInterfaceTypesMod, only : hlm_use_nocomp, hlm_use_fixed_biogeog
use FatesInterfaceTypesMod, only : fates_maxElementsPerSite
use FatesInterfaceTypesMod, only : hlm_use_tree_damage
use FatesHydraulicsMemMod, only : nshell
use FatesHydraulicsMemMod, only : n_hypool_ag
use FatesHydraulicsMemMod, only : n_hypool_troot
use FatesHydraulicsMemMod, only : nlevsoi_hyd_max
use FatesPlantHydraulicsMod, only : UpdatePlantPsiFTCFromTheta
use PRTGenericMod, only : prt_global
use PRTGenericMod, only : prt_cnp_flex_allom_hyp
use EDCohortDynamicsMod, only : InitPRTObject
use FatesPlantHydraulicsMod, only : InitHydrCohort
use FatesInterfaceTypesMod, only : nlevsclass
use FatesInterfaceTypesMod, only : nlevdamage
use FatesLitterMod, only : litter_type
use FatesLitterMod, only : ncwd, nfsc
use FatesLitterMod, only : ndcmpy
use EDTypesMod, only : area
use EDParamsMod, only : nlevleaf
use PRTGenericMod, only : prt_global
use PRTGenericMod, only : num_elements
use FatesRunningMeanMod, only : rmean_type
use FatesRunningMeanMod, only : ema_lpa
use EDParamsMod, only : regeneration_model
! CIME GLOBALS
use shr_log_mod , only : errMsg => shr_log_errMsg
implicit none
private ! Modules are private by default
! ------------------------------------------------------------
! A note on variable naming conventions.
! Many variables in this restart IO portion of the code will
! follow the conventions:
!
! <use_case>_<description>_<dimension>
!
! For instance we use an index for restart variable "ir_"
! to point the object that contains the number of patches per
! site "npatch" and this value is relevant to all sites "si"
! thus: ir_npatch_si
!
! We also use associations to the data arrays of restart IO
! variables "rio", for example the leaf litter "leaf_litter"
! is retrieved for every patch and every functional type "paft"
! thus: rio_leaf_litter_paft
!
! si: site dimension
! pa: patch dimension
! co: cohort dimension
! ft: functional type dimension
! cl: canopy layer dimension (upper, lower, etc)
! ls: layer sublayer dimension (fine discretization of upper,lower)
! wm: the number of memory slots for water (currently 10)
! -------------------------------------------------------------
! Indices to the restart variable object
integer :: ir_npatch_si
integer :: ir_cd_status_si
integer :: ir_nchill_days_si
integer :: ir_ncold_days_si
integer :: ir_cleafondate_si
integer :: ir_cleafoffdate_si
integer :: ir_cndaysleafon_si
integer :: ir_cndaysleafoff_si
integer :: ir_phenmodeldate_si
integer :: ir_acc_ni_si
integer :: ir_gdd_si
integer :: ir_snow_depth_si
integer :: ir_trunk_product_si
integer :: ir_ncohort_pa
integer :: ir_canopy_layer_co
integer :: ir_canopy_layer_yesterday_co
integer :: ir_crowndamage_co
integer :: ir_canopy_trim_co
integer :: ir_l2fr_co
integer :: ir_cx_int_co
integer :: ir_emadcxdt_co
integer :: ir_cx0_co
integer :: ir_cnplimiter_co
integer :: ir_daily_nh4_uptake_co
integer :: ir_daily_no3_uptake_co
integer :: ir_daily_n_fixation_co
integer :: ir_daily_p_uptake_co
integer :: ir_daily_n_demand_co
integer :: ir_daily_p_demand_co
integer :: ir_size_class_lasttimestep_co
integer :: ir_dbh_co
integer :: ir_coage_co
integer :: ir_g_sb_laweight_co
integer :: ir_height_co
integer :: ir_nplant_co
integer :: ir_gpp_acc_co
integer :: ir_npp_acc_co
integer :: ir_resp_acc_co
integer :: ir_gpp_acc_hold_co
integer :: ir_npp_acc_hold_co
integer :: ir_resp_acc_hold_co
integer :: ir_resp_excess_co
integer :: ir_bmort_co
integer :: ir_hmort_co
integer :: ir_cmort_co
integer :: ir_frmort_co
integer :: ir_smort_co
integer :: ir_asmort_co
integer :: ir_dgmort_co
integer :: ir_c_area_co
integer :: ir_treelai_co
integer :: ir_treesai_co
integer :: ir_canopy_layer_tlai_pa
!Logging
integer :: ir_lmort_direct_co
integer :: ir_lmort_collateral_co
integer :: ir_lmort_infra_co
! Radiation
integer :: ir_fcansno_pa
integer :: ir_solar_zenith_flag_pa
integer :: ir_solar_zenith_angle_pa
integer :: ir_gnd_alb_dif_pasb
integer :: ir_gnd_alb_dir_pasb
! Running Means
integer :: ir_tveg24_pa
integer :: ir_tveglpa_pa
integer :: ir_seedling_layer_par24_pa
integer :: ir_sdlng_emerg_smp_pa
integer :: ir_sdlng_mort_par_pa
integer :: ir_sdlng2sap_par_pa
integer :: ir_sdlng_mdd_pa
integer :: ir_tveglongterm_pa
! (Keeping as an example)
!!integer :: ir_tveglpa_co
integer :: ir_ddbhdt_co
integer :: ir_resp_tstep_co
integer :: ir_pft_co
integer :: ir_status_co
integer :: ir_efleaf_co
integer :: ir_effnrt_co
integer :: ir_efstem_co
integer :: ir_isnew_co
! Litter
integer :: ir_agcwd_litt
integer :: ir_bgcwd_litt
integer :: ir_leaf_litt
integer :: ir_fnrt_litt
integer :: ir_seed_litt
integer :: ir_seedgerm_litt
integer :: ir_seed_decay_litt
integer :: ir_seedgerm_decay_litt
integer :: ir_seed_prod_co
integer :: ir_livegrass_pa
integer :: ir_age_pa
integer :: ir_area_pa
integer :: ir_agesinceanthrodist_pa
integer :: ir_patchdistturbcat_pa
integer :: ir_nocomp_pft_label_pa
! Litter Fluxes (needed to restart
! with nutrient dynamics on, restarting
! mid-day
integer :: ir_agcwd_frag_litt
integer :: ir_bgcwd_frag_litt
integer :: ir_lfines_frag_litt
integer :: ir_rfines_frag_litt
integer :: ir_scorch_ht_pa_pft
integer :: ir_litter_moisture_pa_nfsc
! Site level
integer :: ir_dd_status_sift
integer :: ir_dleafondate_sift
integer :: ir_dleafoffdate_sift
integer :: ir_dndaysleafon_sift
integer :: ir_dndaysleafoff_sift
integer :: ir_elong_factor_sift
integer :: ir_liqvolmem_siwmft
integer :: ir_smpmem_siwmft
integer :: ir_recl2fr_sipfcl
integer :: ir_vegtempmem_sitm
integer :: ir_seed_bank_sift
integer :: ir_spread_si
integer :: ir_recrate_sift
integer :: ir_use_this_pft_sift
integer :: ir_area_pft_sift
integer :: ir_fmortrate_cano_siscpf
integer :: ir_fmortrate_usto_siscpf
integer :: ir_imortrate_siscpf
integer :: ir_fmortrate_crown_siscpf
integer :: ir_fmortrate_cambi_siscpf
integer :: ir_termnindiv_cano_siscpf
integer :: ir_termnindiv_usto_siscpf
integer :: ir_growflx_fusion_siscpf
integer :: ir_demorate_sisc
integer :: ir_promrate_sisc
integer :: ir_termcarea_cano_si
integer :: ir_termcarea_usto_si
integer :: ir_imortcarea_si
integer :: ir_fmortcarea_cano_si
integer :: ir_fmortcarea_usto_si
integer :: ir_termcflux_cano_sipft
integer :: ir_termcflux_usto_sipft
integer :: ir_democflux_si
integer :: ir_promcflux_si
integer :: ir_imortcflux_sipft
integer :: ir_fmortcflux_cano_sipft
integer :: ir_fmortcflux_usto_sipft
integer :: ir_abg_term_flux_siscpf
integer :: ir_abg_imort_flux_siscpf
integer :: ir_abg_fmort_flux_siscpf
integer :: ir_cwdagin_flxdg
integer :: ir_cwdbgin_flxdg
integer :: ir_leaflittin_flxdg
integer :: ir_rootlittin_flxdg
integer :: ir_oldstock_mbal
integer :: ir_errfates_mbal
integer :: ir_woodprod_mbal
integer :: ir_prt_base ! Base index for all PRT variables
! Damage x damage or damage x size
integer :: ir_imortrate_sicdpf
integer :: ir_termnindiv_cano_sicdpf
integer :: ir_termnindiv_usto_sicdpf
integer :: ir_fmortrate_cano_sicdpf
integer :: ir_fmortrate_usto_sicdpf
integer :: ir_imortcflux_sicdsc
integer :: ir_termcflux_cano_sicdsc
integer :: ir_termcflux_usto_sicdsc
integer :: ir_fmortcflux_cano_sicdsc
integer :: ir_fmortcflux_usto_sicdsc
integer :: ir_crownarea_cano_si
integer :: ir_crownarea_usto_si
integer :: ir_emanpp_si
! Hydraulic indices
integer :: ir_hydro_th_ag_covec
integer :: ir_hydro_th_troot
integer :: ir_hydro_th_aroot_covec
integer :: ir_hydro_liqvol_shell_si
integer :: ir_hydro_recruit_si
integer :: ir_hydro_dead_si
integer :: ir_hydro_growturn_err_si
integer :: ir_hydro_hydro_err_si
integer :: ir_hydro_errh2o
! The number of variable dim/kind types we have defined (static)
integer, parameter, public :: fates_restart_num_dimensions = 2 !(cohort,column)
integer, parameter, public :: fates_restart_num_dim_kinds = 4 !(cohort-int,cohort-r8,site-int,site-r8)
! integer constants for storing logical data
integer, parameter, public :: old_cohort = 0
integer, parameter, public :: new_cohort = 1
real(r8), parameter, public :: flushinvalid = -9999.0
real(r8), parameter, public :: flushzero = 0.0
real(r8), parameter, public :: flushone = 1.0
! Local debug flag
logical, parameter, public :: debug=.false.
character(len=*), parameter :: sourcefile = &
__FILE__
! This structure is allocated by thread, and must be calculated after the FATES
! sites are allocated, and their mapping to the HLM is identified. This structure
! is not combined with iovar_bounds, because that one is multi-instanced. This
! structure is used more during the update phase, wherease _bounds is used
! more for things like flushing
type, public :: restart_map_type
integer, allocatable :: site_index(:) ! maps site indexes to the HIO site position
integer, allocatable :: cohort1_index(:) ! maps site index to the HIO cohort 1st position
end type restart_map_type
type, public :: fates_restart_interface_type
type(fates_restart_variable_type),allocatable :: rvars(:)
integer,private :: num_restart_vars_
! Instanteate 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_restart_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...?
! Note: history io also instanteates fates_io_dimension_type
type(fates_io_dimension_type) :: dim_bounds(fates_restart_num_dimensions)
type(restart_map_type), pointer :: restart_map(:)
integer, private :: cohort_index_, column_index_
contains
! public functions
procedure :: Init
procedure :: SetThreadBoundsEach
procedure :: assemble_restart_output_types
procedure :: initialize_restart_vars
procedure :: num_restart_vars
procedure :: column_index
procedure :: cohort_index
procedure :: set_restart_vectors
procedure :: create_patchcohort_structure
procedure :: get_restart_vectors
procedure :: update_3dpatch_radiation
! private work functions
procedure, private :: init_dim_kinds_maps
procedure, private :: set_dim_indices
procedure, private :: set_cohort_index
procedure, private :: set_column_index
procedure, private :: flush_rvars
procedure, private :: define_restart_vars
procedure, private :: set_restart_var
procedure, private :: DefinePRTRestartVars
procedure, private :: GetCohortRealVector
procedure, private :: SetCohortRealVector
procedure, private :: RegisterCohortVector
procedure, private :: DefineRMeanRestartVar
procedure, private :: GetRMeanRestartVar
procedure, private :: SetRMeanRestartVar
end type fates_restart_interface_type
contains
! =====================================================================================
subroutine Init(this, num_threads, fates_bounds)
use FatesIODimensionsMod, only : fates_bounds_type, column, cohort
implicit none
class(fates_restart_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_cohort_index(dim_count)
call this%dim_bounds(dim_count)%Init(cohort, num_threads, &
fates_bounds%cohort_begin, fates_bounds%cohort_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)
! FIXME(bja, 2016-10) assert(dim_count == FatesIOdimensionsmod::num_dimension_types)
! Allocate the mapping between FATES indices and the IO indices
allocate(this%restart_map(num_threads))
end subroutine Init
! ======================================================================
subroutine SetThreadBoundsEach(this, thread_index, thread_bounds)
use FatesIODimensionsMod, only : fates_bounds_type
implicit none
class(fates_restart_interface_type), intent(inout) :: this
integer, intent(in) :: thread_index
type(fates_bounds_type), intent(in) :: thread_bounds
integer :: index
index = this%cohort_index()
call this%dim_bounds(index)%SetThreadBounds(thread_index, &
thread_bounds%cohort_begin, thread_bounds%cohort_end)
index = this%column_index()
call this%dim_bounds(index)%SetThreadBounds(thread_index, &
thread_bounds%column_begin, thread_bounds%column_end)
end subroutine SetThreadBoundsEach
! ===================================================================================
subroutine assemble_restart_output_types(this)
use FatesIOVariableKindMod, only : site_r8, site_int, cohort_r8, cohort_int
implicit none
class(fates_restart_interface_type), intent(inout) :: this
call this%init_dim_kinds_maps()
call this%set_dim_indices(cohort_r8, 1, this%cohort_index())
call this%set_dim_indices(cohort_int, 1, this%cohort_index())
call this%set_dim_indices(site_r8, 1, this%column_index())
call this%set_dim_indices(site_int, 1, this%column_index())
end subroutine assemble_restart_output_types
! ===================================================================================
subroutine set_dim_indices(this, dk_name, idim, dim_index)
use FatesIOVariableKindMod , only : iotype_index
implicit none
! arguments
class(fates_restart_interface_type), intent(inout) :: this
character(len=*), intent(in) :: dk_name
integer, intent(in) :: idim ! dimension index
integer, intent(in) :: dim_index
! local
integer :: ityp
ityp = iotype_index(trim(dk_name), fates_restart_num_dim_kinds, this%dim_kinds)
! First check to see if the dimension is allocated
if (this%dim_kinds(ityp)%ndims < idim) then
write(fates_log(), *) 'Trying to define dimension size to a dim-type structure'
write(fates_log(), *) 'but the dimension index does not exist'
write(fates_log(), *) 'type: ',dk_name,' ndims: ',this%dim_kinds(ityp)%ndims,' input dim:',idim
call endrun(msg=errMsg(sourcefile, __LINE__))
end if
if (idim == 1) then
this%dim_kinds(ityp)%dim1_index = dim_index
else if (idim == 2) then
this%dim_kinds(ityp)%dim2_index = dim_index
end if
! With the map, we can set the dimension size
this%dim_kinds(ityp)%dimsize(idim) = this%dim_bounds(dim_index)%upper_bound - &
this%dim_bounds(dim_index)%lower_bound + 1
end subroutine set_dim_indices
! =======================================================================
subroutine set_cohort_index(this, index)
implicit none
class(fates_restart_interface_type), intent(inout) :: this
integer, intent(in) :: index
this%cohort_index_ = index
end subroutine set_cohort_index
integer function cohort_index(this)
implicit none
class(fates_restart_interface_type), intent(in) :: this
cohort_index = this%cohort_index_
end function cohort_index
! =======================================================================
subroutine set_column_index(this, index)
implicit none
class(fates_restart_interface_type), intent(inout) :: this
integer, intent(in) :: index
this%column_index_ = index
end subroutine set_column_index
integer function column_index(this)
implicit none
class(fates_restart_interface_type), intent(in) :: this
column_index = this%column_index_
end function column_index
! =======================================================================
subroutine init_dim_kinds_maps(this)
! ----------------------------------------------------------------------------------
! This subroutine simply initializes the structures that define the different
! array and type formats for different IO variables
!
! CO_R8 : 1D cohort scale 8-byte reals
! SI_R8 : 1D site scale 8-byte reals
! CO_INT : 1D cohort scale integers
! SI_INT : 1D site scale integers
!
! The allocation on the structures is not dynamic and should only add up to the
! number of entries listed here.
!
! ----------------------------------------------------------------------------------
use FatesIOVariableKindMod, only : site_r8, site_int, cohort_r8, cohort_int
implicit none
! Arguments
class(fates_restart_interface_type), intent(inout) :: this
integer :: index
! 1d cohort r8
index = 1
call this%dim_kinds(index)%Init(cohort_r8, 1)
! 1d Site r8
index = index + 1
call this%dim_kinds(index)%Init(site_r8, 1)
! cohort int
index = index + 1
call this%dim_kinds(index)%Init(cohort_int, 1)
! site int
index = index + 1
call this%dim_kinds(index)%Init(site_int, 1)
! FIXME(bja, 2016-10) assert(index == fates_num_dim_kinds)
end subroutine init_dim_kinds_maps
! ====================================================================================
integer function num_restart_vars(this)
implicit none
class(fates_restart_interface_type), intent(in) :: this
num_restart_vars = this%num_restart_vars_
end function num_restart_vars
! ====================================================================================
subroutine initialize_restart_vars(this)
implicit none
class(fates_restart_interface_type), intent(inout) :: this
! Determine how many of the restart IO variables registered in FATES
! are going to be allocated
call this%define_restart_vars(initialize_variables=.false.)
! Allocate the list of restart output variable objects
allocate(this%rvars(this%num_restart_vars()))
! construct the object that defines all of the IO variables
call this%define_restart_vars(initialize_variables=.true.)
end subroutine initialize_restart_vars
! ======================================================================================
subroutine flush_rvars(this,nc)
class(fates_restart_interface_type) :: this
integer,intent(in) :: nc
integer :: ivar
type(fates_restart_variable_type),pointer :: rvar
integer :: lb1,ub1,lb2,ub2
do ivar=1,ubound(this%rvars,1)
associate( rvar => this%rvars(ivar) )
call rvar%Flush(nc, this%dim_bounds, this%dim_kinds)
end associate
end do
end subroutine flush_rvars
! ====================================================================================
subroutine define_restart_vars(this, initialize_variables)
! ---------------------------------------------------------------------------------
!
! REGISTRY OF RESTART OUTPUT VARIABLES
!
! Please add any restart variables to this registry. This registry will handle
! all variables that can make use of 1D column dimensioned or 1D cohort dimensioned
! variables. Note that restarts are only using 1D vectors in ALM and CLM. If you
! have a multi-dimensional variable that is below the cohort scale, then pack
! that variable into a cohort-sized output array by giving it a vtype "cohort_r8"
! or "cohort_int".
!
! Unlike history variables, restarts flush to zero.
! ---------------------------------------------------------------------------------
use FatesIOVariableKindMod, only : site_r8, site_int, cohort_int, cohort_r8
implicit none
class(fates_restart_interface_type), intent(inout) :: this
logical, intent(in) :: initialize_variables ! are we 'count'ing or 'initializ'ing?
integer :: ivar
ivar=0
! -----------------------------------------------------------------------------------
! Site level variables
! -----------------------------------------------------------------------------------
call this%set_restart_var(vname='fates_PatchesPerSite', vtype=site_int, &
long_name='Total number of FATES patches per column', units='none', flushval = flushinvalid, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_npatch_si )
call this%set_restart_var(vname='fates_cold_dec_status', vtype=site_int, &
long_name='status flag for cold deciduous plants', units='unitless', flushval = flushinvalid, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_cd_status_si )
call this%set_restart_var(vname='fates_chilling_days', vtype=site_int, &
long_name='chilling day counter', units='unitless', flushval = flushinvalid, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_nchill_days_si )
call this%set_restart_var(vname='fates_cold_days', vtype=site_int, &
long_name='cold day counter', units='unitless', flushval = flushinvalid, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_ncold_days_si )
call this%set_restart_var(vname='fates_cold_leafondate', vtype=site_int, &
long_name='the model day of last cold leaf on', units='absolute integer day', flushval = flushinvalid, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_cleafondate_si )
call this%set_restart_var(vname='fates_cold_leafoffdate', vtype=site_int, &
long_name='the model day last cold leaf off', units='absolute integer day', flushval = flushinvalid, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_cleafoffdate_si )
call this%set_restart_var(vname='fates_cold_ndaysleafon', vtype=site_int, &
long_name='number of days since leaf on (cold deciduous)', units='days', flushval = flushinvalid, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_cndaysleafon_si )
call this%set_restart_var(vname='fates_cold_ndaysleafoff', vtype=site_int, &
long_name='number of days since leaf off (cold deciduous)', units='days', flushval = flushinvalid, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_cndaysleafoff_si )
call this%set_restart_var(vname='fates_phen_model_date', vtype=site_int, &
long_name='integer model day used for phen timing', units='absolute integer day', flushval = flushinvalid, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_phenmodeldate_si )
call this%set_restart_var(vname='fates_acc_nesterov_id', vtype=site_r8, &
long_name='a nesterov index accumulator', units='unitless', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_acc_ni_si )
call this%set_restart_var(vname='fates_gdd_site', vtype=site_r8, &
long_name='growing degree days at each site', units='degC days', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_gdd_si )
call this%set_restart_var(vname='fates_snow_depth_site', vtype=site_r8, &
long_name='average snow depth', units='m', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_snow_depth_si )
call this%set_restart_var(vname='fates_trunk_product_site', vtype=site_r8, &
long_name='Accumulate trunk product flux at site', &
units='kgC/m2', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_trunk_product_si )
! -----------------------------------------------------------------------------------
! Variables stored within cohort vectors
! Note: Some of these are multi-dimensional variables in the patch/site dimension
! that are collapsed into the cohort vectors for storage and transfer
! -----------------------------------------------------------------------------------
! This variable may be confusing, because it is a patch level variables
! but it is using the cohort IO vector to hold data
call this%set_restart_var(vname='fates_CohortsPerPatch', vtype=cohort_int, &
long_name='the number of cohorts per patch', units='unitless', flushval = flushinvalid, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_ncohort_pa )
call this%set_restart_var(vname='fates_fcansno_pa', vtype=cohort_r8, &
long_name='Fraction of canopy covered in snow', units='unitless', flushval = flushinvalid, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_fcansno_pa )
call this%set_restart_var(vname='fates_solar_zenith_flag_pa', vtype=cohort_int, &
long_name='switch specifying if zenith is positive', units='unitless', flushval = flushinvalid, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_solar_zenith_flag_pa )
call this%set_restart_var(vname='fates_solar_zenith_angle_pa', vtype=cohort_r8, &
long_name='the angle of the solar zenith for each patch', units='radians', flushval = flushinvalid, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_solar_zenith_angle_pa )
! 1D cohort Variables
! -----------------------------------------------------------------------------------
call this%set_restart_var(vname='fates_seed_prod', vtype=cohort_r8, &
long_name='fates cohort - seed production', units='kgC/plant', flushval = flushinvalid, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_seed_prod_co )
call this%set_restart_var(vname='fates_canopy_layer', vtype=cohort_int, &
long_name='ed cohort - canopy_layer', units='unitless', flushval = flushinvalid, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_canopy_layer_co )
call this%set_restart_var(vname='fates_canopy_layer_yesterday', vtype=cohort_r8, &
long_name='ed cohort - canopy_layer_yesterday', units='unitless', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_canopy_layer_yesterday_co )
call this%set_restart_var(vname='fates_crowndamage', vtype=cohort_int, &
long_name='ed cohort - crowndamage class', units='unitless', flushval = flushinvalid, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_crowndamage_co )
call this%set_restart_var(vname='fates_canopy_trim', vtype=cohort_r8, &
long_name='ed cohort - canopy_trim', units='fraction', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_canopy_trim_co )
call this%set_restart_var(vname='fates_l2fr', vtype=cohort_r8, &
long_name='ed cohort - l2fr', units='fraction', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_l2fr_co )
if(hlm_parteh_mode .eq. prt_cnp_flex_allom_hyp) then
call this%set_restart_var(vname='fates_cx_int', vtype=cohort_r8, &
long_name='ed cohort - emacx', units='fraction', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_cx_int_co )
call this%set_restart_var(vname='fates_emadcxdt', vtype=cohort_r8, &
long_name='ed cohort - emadcxdt', units='fraction', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_emadcxdt_co )
call this%set_restart_var(vname='fates_cx0', vtype=cohort_r8, &
long_name='ed cohort - cx0', units='fraction', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_cx0_co )
call this%set_restart_var(vname='fates_cnplimiter', vtype=cohort_r8, &
long_name='ed cohort - cnp limiter index', units='index', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_cnplimiter_co )
call this%set_restart_var(vname='fates_daily_nh4_uptake', vtype=cohort_r8, &
long_name='fates cohort- daily ammonium [NH4] uptake', &
units='kg/plant/day', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_daily_nh4_uptake_co )
call this%set_restart_var(vname='fates_daily_no3_uptake', vtype=cohort_r8, &
long_name='fates cohort- daily ammonium [NO3] uptake', &
units='kg/plant/day', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_daily_no3_uptake_co )
call this%set_restart_var(vname='fates_daily_n_fixation', vtype=cohort_r8, &
long_name='fates cohort- daily N symbiotic fixation', &
units='kg/plant/day', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_daily_n_fixation_co )
call this%set_restart_var(vname='fates_daily_p_uptake', vtype=cohort_r8, &
long_name='fates cohort- daily phosphorus uptake', &
units='kg/plant/day', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_daily_p_uptake_co )
call this%set_restart_var(vname='fates_daily_p_demand', vtype=cohort_r8, &
long_name='fates cohort- daily phosphorus demand', &
units='kgP/plant/day', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_daily_p_demand_co )
call this%set_restart_var(vname='fates_daily_n_demand', vtype=cohort_r8, &
long_name='fates cohort- daily nitrogen demand', &
units='kgN/plant/day', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_daily_n_demand_co )
end if
call this%set_restart_var(vname='fates_size_class_lasttimestep', vtype=cohort_int, &
long_name='ed cohort - size-class last timestep', units='index', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_size_class_lasttimestep_co )
call this%set_restart_var(vname='fates_dbh', vtype=cohort_r8, &
long_name='ed cohort - diameter at breast height', units='cm', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_dbh_co )
call this%set_restart_var(vname='fates_coage', vtype=cohort_r8, &
long_name='ed cohort - age in days', units='days', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_coage_co )
call this%set_restart_var(vname='fates_height', vtype=cohort_r8, &
long_name='ed cohort - plant height', units='m', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_height_co )
call this%set_restart_var(vname='fates_nplant', vtype=cohort_r8, &
long_name='ed cohort - number of plants in the cohort', &
units='/patch', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_nplant_co )
call this%set_restart_var(vname='fates_gpp_acc', vtype=cohort_r8, &
long_name='ed cohort - accumulated gpp over dynamics step', &
units='kgC/indiv', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_gpp_acc_co )
call this%set_restart_var(vname='fates_npp_acc', vtype=cohort_r8, &
long_name='ed cohort - accumulated npp over dynamics step', &
units='kgC/indiv', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_npp_acc_co )
call this%set_restart_var(vname='fates_resp_acc', vtype=cohort_r8, &
long_name='ed cohort - accumulated respiration over dynamics step', &
units='kgC/indiv', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_resp_acc_co )
call this%set_restart_var(vname='fates_gpp_acc_hold', vtype=cohort_r8, &
long_name='ed cohort - current step gpp', &
units='kgC/indiv/year', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_gpp_acc_hold_co )
call this%set_restart_var(vname='fates_npp_acc_hold', vtype=cohort_r8, &
long_name='ed cohort - current step npp', &
units='kgC/indiv/year', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_npp_acc_hold_co )
call this%set_restart_var(vname='fates_resp_acc_hold', vtype=cohort_r8, &
long_name='ed cohort - current step resp', &
units='kgC/indiv/year', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_resp_acc_hold_co )
call this%set_restart_var(vname='fates_resp_excess', vtype=cohort_r8, &
long_name='ed cohort - maintenance respiration deficit', &
units='kgC/indiv', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_resp_excess_co )
call this%set_restart_var(vname='fates_bmort', vtype=cohort_r8, &
long_name='ed cohort - background mortality rate', &
units='/year', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_bmort_co )
call this%set_restart_var(vname='fates_hmort', vtype=cohort_r8, &
long_name='ed cohort - hydraulic mortality rate', &
units='/year', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_hmort_co )
call this%set_restart_var(vname='fates_cmort', vtype=cohort_r8, &
long_name='ed cohort - carbon starvation mortality rate', &
units='/year', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_cmort_co )
call this%set_restart_var(vname='fates_frmort', vtype=cohort_r8, &
long_name='ed cohort - freezing mortality rate', &
units='/year', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_frmort_co )
call this%set_restart_var(vname='fates_smort', vtype=cohort_r8, &
long_name='ed cohort - senescence mortality rate', &
units='/year', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_smort_co )
call this%set_restart_var(vname='fates_asmort', vtype=cohort_r8, &
long_name='ed cohort - age senescence mortality rate', &
units = '/year', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_asmort_co )
call this%set_restart_var(vname='fates_dgmort', vtype=cohort_r8, &
long_name='ed cohort - damage mortality rate', &
units = '/year', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_dgmort_co )
call this%set_restart_var(vname='fates_lmort_direct', vtype=cohort_r8, &
long_name='ed cohort - directly logging mortality rate', &
units='%/event', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_lmort_direct_co )
call this%set_restart_var(vname='fates_lmort_collateral', vtype=cohort_r8, &
long_name='ed cohort - collateral mortality rate', &
units='%/event', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_lmort_collateral_co )
call this%set_restart_var(vname='fates_lmort_in', vtype=cohort_r8, &
long_name='ed cohort - mechanical mortality rate', &
units='%/event', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_lmort_infra_co )
call this%set_restart_var(vname='fates_ddbhdt', vtype=cohort_r8, &
long_name='ed cohort - differential: ddbh/dt', &
units='cm/year', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_ddbhdt_co )
call this%set_restart_var(vname='fates_resp_tstep', vtype=cohort_r8, &
long_name='ed cohort - autotrophic respiration over timestep', &
units='kgC/indiv/timestep', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_resp_tstep_co )
call this%set_restart_var(vname='fates_pft', vtype=cohort_int, &
long_name='ed cohort - plant functional type', units='index', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_pft_co )
call this%set_restart_var(vname='fates_status_coh', vtype=cohort_int, &
long_name='ed cohort - plant phenology status', units='unitless', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_status_co )
call this%set_restart_var(vname='fates_efleaf_coh', vtype=cohort_r8, &
long_name='ed cohort - leaf elongation factor', units='unitless', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_efleaf_co )
call this%set_restart_var(vname='fates_effnrt_coh', vtype=cohort_r8, &
long_name='ed cohort - fine-root elongation factor', units='unitless', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_effnrt_co )
call this%set_restart_var(vname='fates_efstem_coh', vtype=cohort_r8, &
long_name='ed cohort - stem elongation factor', units='unitless', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_efstem_co )
call this%set_restart_var(vname='fates_isnew', vtype=cohort_int, &
long_name='ed cohort - binary flag specifying if a plant has experienced a full day cycle', &
units='0/1', flushval = flushone, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_isnew_co )
call this%set_restart_var(vname='fates_gsblaweight',vtype=cohort_r8, &
long_name='ed cohort - leaf-area weighted total stomatal+blayer conductance', &
units='[m/s]*[m2]', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_g_sb_laweight_co)
! Mixed dimension variables using the cohort vector
! -----------------------------------------------------------------------------------
call this%set_restart_var(vname='fates_gnd_alb_dif', vtype=cohort_r8, &
long_name='ground albedo of diffuse radiation vis and ir', &
units='fraction', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_gnd_alb_dif_pasb )
call this%set_restart_var(vname='fates_gnd_alb_dir', vtype=cohort_r8, &
long_name='ground albedo of direct radiation vis and ir', &
units='fraction', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_gnd_alb_dir_pasb )
call this%set_restart_var(vname='fates_spread', vtype=site_r8, &
long_name='dynamic ratio of dbh to canopy area, by patch x canopy-layer', &
units='cm/m2', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_spread_si )
call this%set_restart_var(vname='fates_livegrass', vtype=cohort_r8, &
long_name='total AGB from grass, by patch', &
units='kgC/m2', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_livegrass_pa )
call this%set_restart_var(vname='fates_age', vtype=cohort_r8, &
long_name='age of the ED patch', units='yr', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_age_pa )
call this%set_restart_var(vname='fates_age_since_anthro_dist', vtype=cohort_r8, &
long_name='age of the ED patch since last anthropogenic disturbance', &
units='yr', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, &
index = ir_agesinceanthrodist_pa )
call this%set_restart_var(vname='fates_patchdistturbcat', vtype=cohort_int, &
long_name='Disturbance label of patch', units='yr', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_patchdistturbcat_pa )
call this%set_restart_var(vname='fates_nocomp_pft_label', vtype=cohort_int, &
long_name='PFT label of patch in nocomp mode', units='none', flushval = flushzero, &
hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_nocomp_pft_label_pa )
call this%set_restart_var(vname='fates_area', vtype=cohort_r8, &
long_name='are of the ED patch', units='m2', flushval = flushzero, &